;+
;tool menu manage
;+
PRO sesToolBar::ChangeSize , type = type
	COMPILE_OPT IDL2
	oSystem = self.oSystem
	ImageClass = oSystem.CurrentPro
	ImageClass.oView->GetProperty, Location = oldLoc,dimensions = oldDim
	drawSize = [(oSystem.mainDraw).drawSize,ImageClass.imageX, ImageClass.imageY]

	sesViewSize, drawSize, Type = Type				 	       , $
						   ZoomRate = zoom			 	       , $
						   windowVD = windowVD		           , $
						   viewPlane = viewPlane	           , $
						   viewDim = viewDim		           , $
						   currentXY=currentXY                 , $
						   oDraw = (oSystem.mainDraw).drawID   , $
						   oView = ImageClass.oView            , $
						   oldDim = oldDim                     , $
						   new = new                           , $
						   oldLoc = oldLoc                     , $
						   viewLoc = viewLoc

	IF KeyWord_Set(viewDim) THEN ImageClass.oView->SetProperty, Dimensions = viewDim
	IF KeyWord_Set(viewLoc) THEN ImageClass.oView->SetProperty, Location = viewLoc
	IF KeyWord_Set(windowVD) THEN Widget_Control, (oSystem.mainDraw).drawID	, $
           Draw_XSize = windowVD[0], Draw_YSize = windowVD[1]

 	Widget_Control, (oSystem.mainDraw).drawID, Scr_XSize = (oSystem.mainDraw).drawSize[0], $
 						Scr_YSize = (oSystem.mainDraw).drawSize[1]

	ImageClass.oModel->Reset
	ImageClass.oModel->Scale, zoom, zoom, 1
	ImageClass.zoom = zoom
	ImageClass.oView->SetProperty, ViewPlane_Rect = viewPlane
	imageType = Size(image,/N_Dimensions)
	IF imageType EQ 2 THEN BEGIN
		ImageClass.oImage->Setproperty, Palette = ImageClass.oPalette
	ENDIF

	oSystem.oWindow -> Draw, oSystem.oScene
END
;+
;tool menu manage
;+
PRO sesToolBar::MenuManage , type
	COMPILE_OPT IDL2
	CASE type OF
		'begin':BEGIN
			drawObjs = self.objContainer->Get(/All, Count = dCount)
			FOR i=1, 14 DO drawObjs[i]->Sensitive , 0
			drawObjs[8]->Sensitive , 1
			FOR i=3, 7 DO drawObjs[i]->Recover
			drawObjs[3]->ButtonDown
		END
		'openhigh':BEGIN
			drawObjs = self.objContainer->Get(/All, Count = dCount)
			FOR i=1, 14 DO drawObjs[i]->Sensitive , 1
			FOR i=3, 7 DO drawObjs[i]->Recover
			drawObjs[3]->ButtonDown
		END
		'openlow':BEGIN
			drawObjs = self.objContainer->Get(/All, Count = dCount)
			FOR i=1, 14 DO drawObjs[i]->Sensitive , 1
			FOR i=3, 7 DO drawObjs[i]->Recover
			drawObjs[3]->ButtonDown
		END
		'openmulti':BEGIN
			drawObjs = self.objContainer->Get(/All, Count = dCount)
			FOR i=1, 3 DO drawObjs[i]->Sensitive , 1
			FOR i=4, 14 DO drawObjs[i]->Sensitive , 0
			FOR i=3, 7 DO drawObjs[i]->Recover
			drawObjs[3]->ButtonDown
		END
	ELSE:
	ENDCASE
END
;+
;Magnifier
;+
PRO sesToolBar::Magnifier
	COMPILE_OPT IDL2
	oSystem = self.oSystem
	IF ~Obj_Valid(self.Magnifier) THEN BEGIN
		Obj_Destroy , self.Magnifier
		menuBar = (oSystem.menuBar)
		menuBar.CurrentName = 'Magnifier'
		self.Magnifier = Obj_New('sesMagnifier'              , $
		                          oSystem = self.oSystem	       $
		                        )
	ENDIF

END
;+
;mouse tool (zoomout zoomin pan )
;+
PRO sesToolBar::MouseTool , type
	COMPILE_OPT IDL2
	oSystem = self.oSystem
	IF Obj_Valid(self.Magnifier) THEN BEGIN
		Widget_Control, (self.Magnifier).cBase, /Destroy
		Obj_Destroy , (self.Magnifier).mContainer
		Obj_Destroy , self.Magnifier
	ENDIF
	Obj_Destroy , self.MouseTool
	menuBar = (oSystem.menuBar)
	CASE type OF
		'pan':BEGIN
			menuBar.CurrentName = 'Pan'
		END
		'zoomout':BEGIN
			menuBar.CurrentName = 'ZoomOut'
		END
		'zoomin':BEGIN
			menuBar.CurrentName = 'ZoomIn'
		END
	ELSE:
	ENDCASE
	self.MouseTool = Obj_New('sesMouseTool'              , $
							  type = type                , $
	                          oSystem = self.oSystem	   $
	                        )
END
;+
;change size
;+
PRO sesToolBar::Resize, xSize

	COMPILE_OPT IDL2

	Widget_Control, self.toolBase, XSize = xSize

END
;+
;handel event
;+
PRO sesToolBar::HandleEvent, UName, event
	COMPILE_OPT IDL2

	oSystem = self.oSystem
	drawObjs = self.objContainer->Get(/All, Count = dCount)
	tagName = Tag_Names(event, /Structure_Name)
	CASE UName OF
		'toolOpen':BEGIN
			Widget_Control, event.id, Get_UValue = nowDrawObj
			nowDrawObj->HandleEvent, event
   			IF tagName EQ 'WIDGET_DRAW' THEN BEGIN
				IF event.press EQ 1 THEN oSystem.menuBar->OpenImage
				nowDrawObj->Recover
			ENDIF
		END
		'toolSave':BEGIN
			Widget_Control, event.id, Get_UValue = nowDrawObj
			nowDrawObj->HandleEvent, event
   			IF tagName EQ 'WIDGET_DRAW' THEN BEGIN
				IF event.press EQ 1 THEN oSystem.menuBar->SaveImage , type = 'ps' , event = event
				nowDrawObj->Recover
			ENDIF
		END
		'toolPrint':BEGIN
			Widget_Control, event.id, Get_UValue = nowDrawObj
			nowDrawObj->HandleEvent, event
   			IF tagName EQ 'WIDGET_DRAW' THEN BEGIN
				IF event.press EQ 1 THEN BEGIN
					oSystem.menuBar->SetPrint
				ENDIF
				nowDrawObj->Recover
			ENDIF
		END
		'toolFinger':BEGIN
			Widget_Control, event.id, Get_UValue = nowDrawObj
			nowDrawObj->HandleEvent, event
			IF tagName EQ 'WIDGET_DRAW' THEN BEGIN
				IF event.press EQ 1 THEN BEGIN
					Class = oSystem.menuBar
					Class->FlowManage , type = type
					FOR i=3, 7 DO drawObjs[i]->Recover
					nowDrawObj->ButtonDown
				ENDIF
			ENDIF
		END
		'toolHand':BEGIN
			Widget_Control, event.id, Get_UValue = nowDrawObj
			nowDrawObj->HandleEvent, event
			IF tagName EQ 'WIDGET_DRAW' THEN BEGIN
				IF event.press EQ 1 THEN BEGIN
					Class = oSystem.menuBar
					Class->FlowManage , type = 'set'
					FOR i=3, 7 DO drawObjs[i]->Recover
					nowDrawObj->ButtonDown
					self->MouseTool , 'pan'
				ENDIF
			ENDIF
		END
		'toolZoomOut':BEGIN
			Widget_Control, event.id, Get_UValue = nowDrawObj
			nowDrawObj->HandleEvent, event
			IF tagName EQ 'WIDGET_DRAW' THEN BEGIN
				IF event.press EQ 1 THEN BEGIN
					Class = oSystem.menuBar
					Class->FlowManage , type = 'set'
					FOR i=3, 7 DO drawObjs[i]->Recover
					nowDrawObj->ButtonDown
					self->MouseTool , 'zoomout'
				ENDIF
			ENDIF
		END
		'toolZoomIn':BEGIN
			Widget_Control, event.id, Get_UValue = nowDrawObj
			nowDrawObj->HandleEvent, event
			IF tagName EQ 'WIDGET_DRAW' THEN BEGIN
				IF event.press EQ 1 THEN BEGIN
					Class = oSystem.menuBar
					Class->FlowManage , type = 'set'
					FOR i=3, 7 DO drawObjs[i]->Recover
					nowDrawObj->ButtonDown
					self->MouseTool , 'zoomin'
				ENDIF
			ENDIF
		END
		'toolMagnifier':BEGIN
			Widget_Control, event.id, Get_UValue = nowDrawObj
			nowDrawObj->HandleEvent, event
			IF tagName EQ 'WIDGET_DRAW' THEN BEGIN
				IF event.press EQ 1 THEN BEGIN
					Class = oSystem.menuBar
					Class->FlowManage , type = 'set'
					FOR i=3, 7 DO drawObjs[i]->Recover
					nowDrawObj->ButtonDown
					self->Magnifier
				ENDIF
			ENDIF
		END
		'toolScale':BEGIN
			Widget_Control, event.id, Get_UValue = nowDrawObj
			nowDrawObj->HandleEvent, event
   			IF tagName EQ 'WIDGET_DRAW' THEN BEGIN
				IF event.press EQ 1 THEN oSystem.menuBar->calibrat
				nowDrawObj->Recover
			ENDIF
		END
		'toolTransform':BEGIN
			Widget_Control, event.id, Get_UValue = nowDrawObj
			nowDrawObj->HandleEvent, event
   			IF tagName EQ 'WIDGET_DRAW' THEN BEGIN
				IF event.press EQ 1 THEN BEGIN
					Class = oSystem.menuBar
					Class->FlowManage
					mainBase = oSystem.mBase
					datatransform , mainBase , tBase
					Class.tBase = tBase
				ENDIF
				nowDrawObj->Recover
			ENDIF
		END
		'toolCut':BEGIN
			Widget_Control, event.id, Get_UValue = nowDrawObj
			nowDrawObj->HandleEvent, event
   			IF tagName EQ 'WIDGET_DRAW' THEN BEGIN
				IF event.press EQ 1 THEN oSystem.menuBar->CutImage
				nowDrawObj->Recover
			ENDIF
		END
		'toolPallette':BEGIN
			Widget_Control, event.id, Get_UValue = nowDrawObj
			nowDrawObj->HandleEvent, event
			IF tagName EQ 'WIDGET_DRAW' THEN BEGIN
				IF event.press EQ 1 THEN oSystem.menuBar->AddPallette
				nowDrawObj->Recover
			ENDIF
		END
		'toolSection':BEGIN
			Widget_Control, event.id, Get_UValue = nowDrawObj
			nowDrawObj->HandleEvent, event
			IF tagName EQ 'WIDGET_DRAW' THEN BEGIN
				IF event.press EQ 1 THEN oSystem.menuBar->PlotSection
				nowDrawObj->Recover
			ENDIF
		END
		'toolPlot':BEGIN
			Widget_Control, event.id, Get_UValue = nowDrawObj
			nowDrawObj->HandleEvent, event
		END
		'magnify_text':BEGIN

		END
		'toolFull':BEGIN
			Widget_Control, event.id, Get_UValue = nowDrawObj
			nowDrawObj->HandleEvent, event
   			IF tagName EQ 'WIDGET_DRAW' THEN BEGIN
				IF event.press EQ 1 THEN BEGIN
					nowDrawObj->ButtonDown
					self->ChangeSize , type = 'initSize'
				ENDIF
				nowDrawObj->Recover
			ENDIF
		END
		'toolReal':BEGIN
			Widget_Control, event.id, Get_UValue = nowDrawObj
			nowDrawObj->HandleEvent, event
   			IF tagName EQ 'WIDGET_DRAW' THEN BEGIN
				IF event.press EQ 1 THEN BEGIN
					nowDrawObj->ButtonDown
					self->ChangeSize , type = 'realSize'
				ENDIF
				nowDrawObj->Recover
			ENDIF
		END

	ELSE:
	ENDCASE

END
;+
;tv bmp file
;+
PRO sesToolBar::DrawSeparator, widgetID, bmp, XSize = xsize, YSize = ysize

	COMPILE_OPT IDL2

	Widget_Control, widgetID, Get_Value = separatorDraw

	WSet, separatorDraw
	separatorBmp = Congrid(bmp, 3, xsize, ysize)
	TV, separatorBmp, /True

END
;+
;create tool bar
;+
PRO sesToolBar::Create
	COMPILE_OPT IDL2
	sep = (self.oSystem).sep
	self.objContainer = Obj_New('IDL_Container')
	toolUName = StrArr(20)
	drawTip = StrArr(20)
	bmpFile = StrArr(4,20)
	toolUName[0:14] = ['sesTool_toolOpen','sesTool_toolSave','sesTool_toolPrint'            , $
	               	   'sesTool_toolFinger','sesTool_toolHand','sesTool_toolZoomOut'        , $
	                   'sesTool_toolZoomIn','sesTool_toolMagnifier','sesTool_toolTransform' , $
	                   'sesTool_toolCut','sesTool_toolPallette','sesTool_toolSection'       , $
	                   'sesTool_toolPlot','sesTool_toolFull','sesTool_toolReal'   ]

	drawTip[0:14]  =  ['Open','Save','Print','Finger','Hand','ZoomOut','ZoomIn', $
	                   'Magnifier','Transform Data','Cut'     , $
	                   'Pallette','Section','Plot','Full','Real']

	bmpFile[*,0:14] = [ ['tool_1_0.bmp', 'tool_1_1.bmp', 'tool_1_2.bmp', 'tool_1_3.bmp']		, $
						['tool_2_0.bmp', 'tool_2_1.bmp', 'tool_2_2.bmp', 'tool_2_3.bmp']		, $
						['tool_3_0.bmp', 'tool_3_1.bmp', 'tool_3_2.bmp', 'tool_3_3.bmp']		, $
						['tool_4_0.bmp', 'tool_4_1.bmp', 'tool_4_2.bmp', 'tool_4_3.bmp']		, $
						['tool_5_0.bmp', 'tool_5_1.bmp', 'tool_5_2.bmp', 'tool_5_3.bmp']	    , $
						['tool_6_0.bmp', 'tool_6_1.bmp', 'tool_6_2.bmp', 'tool_6_3.bmp']	    , $
						['tool_7_0.bmp', 'tool_7_1.bmp', 'tool_7_2.bmp', 'tool_7_3.bmp']	    , $
						['tool_8_0.bmp', 'tool_8_1.bmp', 'tool_8_2.bmp', 'tool_8_3.bmp']	    , $
						['tool_9_0.bmp', 'tool_9_1.bmp', 'tool_9_2.bmp', 'tool_9_3.bmp']	    , $
						['tool_10_0.bmp', 'tool_10_1.bmp', 'tool_10_2.bmp', 'tool_10_3.bmp']	, $
						['tool_11_0.bmp', 'tool_11_1.bmp', 'tool_11_2.bmp', 'tool_11_3.bmp']	, $
						['tool_12_0.bmp', 'tool_12_1.bmp', 'tool_12_2.bmp', 'tool_12_3.bmp']	, $
						['tool_13_0.bmp', 'tool_13_1.bmp', 'tool_13_2.bmp', 'tool_13_3.bmp']	, $
						['tool_14_0.bmp', 'tool_14_1.bmp', 'tool_14_2.bmp', 'tool_14_3.bmp']    , $
						['tool_15_0.bmp', 'tool_15_1.bmp', 'tool_15_2.bmp', 'tool_15_3.bmp']  ]

	separator = Read_Image(self.RootDir + sep+'resource'+sep+'bitmap'+sep+'separator'+sep+'separator.bmp')
	line      = Read_Image(self.RootDir + sep+'resource'+sep+'bitmap'+sep+'separator'+sep+'line.bmp')
	operator  = Read_Image(self.RootDir + sep+'resource'+sep+'bitmap'+sep+'separator'+sep+'operator.bmp')

	separator = AdjustBmp(separator, self.signColor, self.foreColor)
	line      = AdjustBmp(line, self.signColor, self.foreColor)
	operator  = AdjustBmp(operator , self.signColor , self.foreColor)

	toolBase = Widget_Base(self.mainBase  		 , $
                           /Column           	 , $
                           Space = 0         	 , $
                           XPad  = 0         	 , $
                           YPad  = 0         	 )

	Widget_Control, /Realize, toolBase

	self.toolBase = toolBase

	temp = Widget_Base(toolBase       		      , $
                       /Row	          	          , $
                       Space = 0         	      , $
                       XPad  = 0         	      , $
                       YPad  = 0         	      )

	;separator line
	baseDraw = Widget_Draw(temp 				      , $
					       Retain = 2				  , $
				           Scr_XSize = self.geom[0]   , $
					       Scr_YSize = 2			  )

	self->DrawSeparator, baseDraw, operator, XSize = self.geom[0], YSize = 2

	mainBase = Widget_Base(toolBase          				, $
	                        /Row	          				, $
	                        /Base_Align_Center				, $
	                        UName = 'mainBase'	            , $
	                        Space = 0         				, $
	                        XPad  = 0         				, $
	                        YPad  = 0         				)
	;file base in tool
	fileBase = Widget_Base(mainBase    						, $
                           /Row	          					, $
                           /Base_Align_Center				, $
                           UName = 'fileBase'	            , $
                           Space = 5         				, $
                           XPad  = 1         				, $
                           YPad  = 0         				)

	;mouse base in tool
	mouseBase = Widget_Base(mainBase      					    , $
	                         /Row	          					, $
	                         /Base_Align_Center					, $
	                         UName = 'mouseBase'	            , $
	                         Space = 5         					, $
	                         XPad  = 3         					, $
	                         YPad  = 0         					)

	;user base in tool
	userBase = Widget_Base(mainBase    					         , $
                           /Row	          				         , $
                           /Base_Align_Center				     , $
                           UName = 'userBase'	                 , $
                           Space = 5         				     , $
                           XPad  = 3         				     , $
                           YPad  = 0         				     )

	temp = Widget_Draw(fileBase				, $
						Retain = 2			, $
						Scr_XSize = 3		, $
						Scr_YSize = 20		)

	self->DrawSeparator, temp, separator, XSize = 3, YSize = 20

	temp = Widget_Label(fileBase, Value = '  ')
	;draw file picture
	FOR i=0, 2 DO BEGIN
		drawObj = Obj_New('sesDrawbutton'			         , $
						   fileBase						     , $
						   BmpFile = self.rootDir+sep+'resource'+sep+'bitmap'+sep+'tools'+sep+bmpFile[*,i] ,$
						   UName = toolUName[i]			     , $
						   Type = 'tool'					 , $
						   Tooltip = drawTip[i]			     , $
						   ForeColor = self.foreColor		 , $
						   SignColor = self.signColor		   )

		self.objContainer->Add, drawObj
	ENDFOR
	;separator
	temp = Widget_Draw(mouseBase				, $
						Retain = 2				, $
						Scr_XSize = 2			, $
						Scr_YSize = 15			)

	self->DrawSeparator, temp, line, XSize = 2, YSize = 15

	temp = Widget_Label(mouseBase, Value = ' ')
	;draw mouse base
	FOR i=3, 7 DO BEGIN
		drawObj = Obj_New('sesDrawbutton'			, $
							mouseBase						, $
							BmpFile = self.rootDir+sep+'resource'+sep+'bitmap'+sep+'tools'+sep+bmpFile[*,i] ,$
							UName = toolUName[i]			, $
							Type = 'mouse'					, $
							Tooltip = drawTip[i]			, $
							ForeColor = self.foreColor		, $
							SignColor = self.signColor		)

		self.objContainer->Add, drawObj
	ENDFOR
	;separator
	temp = Widget_Draw(userBase				, $
						Retain = 2				, $
						Scr_XSize = 2			, $
						Scr_YSize = 15			)

	self->DrawSeparator, temp, line, XSize = 2, YSize = 15

	temp = Widget_Label(userBase, Value = ' ')
	;draw userBase base
	FOR i=8, 12 DO BEGIN
		drawObj = Obj_New('sesDrawbutton'			, $
							userBase						, $
							BmpFile = self.rootDir+sep+'resource'+sep+'bitmap'+sep+'tools'+sep+bmpFile[*,i] ,$
							UName = toolUName[i]			, $
							Type = 'user'					, $
							Tooltip = drawTip[i]			, $
							ForeColor = self.foreColor		, $
							SignColor = self.signColor		)

		self.objContainer->Add, drawObj
	ENDFOR
	;separator
	temp = Widget_Draw(userBase				, $
						Retain = 2				, $
						Scr_XSize = 2			, $
						Scr_YSize = 15			)

	self->DrawSeparator, temp, line, XSize = 2, YSize = 15

	temp = Widget_Label(userBase, Value = ' ')
	;draw control image size
	FOR i=13, 14 DO BEGIN
		drawObj = Obj_New('sesDrawbutton'			, $
							userBase						, $
							BmpFile = self.rootDir+sep+'resource'+sep+'bitmap'+sep+'tools'+sep+bmpFile[*,i] ,$
							UName = toolUName[i]			, $
							Type = 'user'					, $
							Tooltip = drawTip[i]			, $
							ForeColor = self.foreColor		, $
							SignColor = self.signColor		)

		self.objContainer->Add, drawObj
	ENDFOR

END
;+
;clean up
;+
PRO sesToolBar::CleanUp
	COMPILE_OPT IDL2
	Obj_Destroy , self.objContainer
	Obj_Destroy , self.Magnifier
	Obj_Destroy , self.MouseTool
END
;+
;initialize
;+
FUNCTION sesToolBar::Init , oSystem = oSystem
	COMPILE_OPT IDL2
	Device, Get_Screen_Size = screenSize
	self.geom = [screenSize[0], 36]
	self.oSystem = oSystem
	self.mainBase = oSystem.mBase
	self.RootDir = oSystem.RootDir
	self.foreColor = oSystem.foreColor
	self.signColor = oSystem.signColor
	self->Create
	self->MenuManage , 'begin'
	Return,1
END
;+
;menu bar class name
;+
PRO sesToolBar__Define
	COMPILE_OPT IDL2
	void = { sesToolBar                            , $
			;system parameter
			 mainBase          :    0              , $
			 toolBase          :    0              , $
			 RootDir           :    ''             , $
			 foreColor         :   IntArr(3)       , $
	         signColor         :   IntArr(3)       , $
	         geom              :   [0,0]           , $
			;system objct
	         objContainer      :    Obj_New()      , $
	         Magnifier         :    Obj_New()      , $
	         MouseTool         :    Obj_New()      , $
	         oSystem           :    Obj_New()        $

			}
END