Help me on toolbar problem

Sam Hu samhu.samhu at gmail.com
Fri Aug 8 19:18:43 PDT 2008


So sorry!!A mistake in the code,please refer to  below code:

/******************************************/
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);	
		
		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);
		
		
		return bar;
	}
	
	
	class checkMenuClickListener:SelectionListener
	{
		
		private:
		MenuItem checkItem;
		ToolItem toolItem;
		public:
		this(MenuItem item)
		{
			
			this.checkItem=checkItem;
			
		}
		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