Help me on toolbar problem

Sam Hu samhu.samhu at gmail.com
Fri Aug 8 18:59:44 PDT 2008


Again,I can not download the file I uploaded.So I post here:
/****************************************************/
module ToolBarApp;

import dwt.widgets.Widget;
import dwt.widgets.Shell;
import dwt.widgets.Display;
import dwt.widgets.Menu;
import dwt.widgets.MenuItem;
import dwt.widgets.ToolBar;
import dwt.widgets.ToolItem;
import dwt.widgets.MessageBox;
import dwt.DWT;
import dwt.events.SelectionEvent;
import dwt.events.SelectionListener;


import tango.io.Stdout;

public class Form
{
	private:
	Display display;
	Shell shell;
	Menu menu;
	MenuItem checkItem;
	
	ToolBar bar;
	ToolItem checkBarItem;
	
	
	public:
	this()
	{
		initializeComponents;
	}
	
	void initializeComponents()
	{
		display=new Display;
		shell =new Shell(display);
		
		shell.setSize(500,500);
		
		shell.setText("Example 01");
		
		//ToolBar:
		bar=createToolBar(checkBarItem);
		
		//main menu:
		menu=createMainMenu;
		shell.setMenuBar(menu);

		shell.open;
	
		while(!shell.isDisposed)
		{
			if(!display.readAndDispatch)
			display.sleep;
		}
		display.dispose;

		
	}
	
	private:
	Menu createMainMenu()
	{
		//Menu-->Option-->Checkd Option
		menu=new Menu(shell,DWT.BAR);
	
		final MenuItem options=new MenuItem(menu,DWT.CASCADE);
		options.setText("Options");
		final Menu optionMenu=new Menu(shell,DWT.DROP_DOWN);
		
		final MenuItem checkItem=new MenuItem(optionMenu,DWT.CHECK);
		checkItem.setText("Checked Option");
		checkItem.setAccelerator(DWT.CTRL+'C');
		checkItem.setSelection(true);
		options.setMenu(optionMenu);

	
		checkItem.addSelectionListener(new checkMenuClickListener(checkItem));	
		
		return menu;
	}
	
	ToolBar createToolBar(ref ToolItem checkBarItem)
	{
		
		final ToolBar bar =new ToolBar(shell,DWT.HORIZONTAL);
		bar.setSize(300,70);
		bar.setLocation(0,0);
		
		
		checkBarItem=new ToolItem(bar,DWT.CHECK);
		
		checkBarItem.setText("Check Bar");
		
		checkBarItem.addSelectionListener(new checkMenuClickListener(checkBarItem));
		
		
		return bar;
	}
	
	
	class checkMenuClickListener:SelectionListener
	{
		private:
		MenuItem item;
		ToolItem toolItem;
		public:
		this(MenuItem item)
		{
			
			this.item=item;
			
		}
		this(ToolItem toolItem)
		{
			this.toolItem=toolItem;
		}
		
		public void widgetSelected(SelectionEvent e)
		{
			if(checkItem.getSelection||checkBarItem.getSelection)
			{
				MessageBox.showInfo("Checked","HAHA");
			}
			else
				
				MessageBox.showInfo("Unchecked","HAHA");
			
			
				
		}
		public void widgetDefaultSelected(SelectionEvent e)
		{
			//leave blank
		}
	}
}

	int main(char[][] args)
	{
		scope Form form=new Form;
		
		return 0;
	}

/****************************************************/


More information about the Digitalmars-d-dwt mailing list