PRO SCROLL_EXAMPLE_RESIZE, event Widget_Control, event.top, Get_UValue=info ; What size is the TLB? s = [event.x, event.y] ; Create a draw widget with or without scroll bars ; as appropriate. IF s[0] GT 400 OR s[1] GT 400 THEN BEGIN ; With scroll bars. Widget_Control, info.drawbase, Map=0 Widget_Control, info.drawID, /Destroy info.drawID = Widget_Draw(info.drawbase, XSize=s[0], $ YSize=s[1], X_Scroll_Size=s[0] < 400, Y_Scroll_Size=s[1] < 400) Widget_Control, info.drawID, /Realize Widget_Control, info.drawID, Get_Value=wid WSet, wid info.wid = wid TVImage, *info.image Widget_Control, info.drawbase, Map=1 ENDIF ELSE BEGIN ; Without scroll bars. Widget_Control, info.drawbase, Map=0 Widget_Control, info.drawID, /Destroy info.drawID = Widget_Draw(info.drawbase, XSize=s[0], $ YSize=s[1]) Widget_Control, info.drawID, /Realize Widget_Control, info.drawID, Get_Value=wid WSet, wid info.wid = wid TVImage, *info.image Widget_Control, info.drawbase, Map=1 ENDELSE Widget_Control, event.top, Set_UValue=info END ;-------------------------------------------------------------- PRO SCROLL_EXAMPLE_LOAD, event ; Load a new image. If size is less than 400 by 400 ; put it in a draw widget without scroll bars. Otherwise, ; put it in a draw widget with scroll bars. Widget_Control, event.top, Get_UValue=info ; Select image. image = LoadData(Cancel=cancelled, Group_leader=event.top, /Images) IF cancelled THEN RETURN *info.image = image ; What size is it? s = Size(image, /Dimensions) ; Create a draw widget with or without scroll bars ; as appropriate. IF s[0] GT 400 OR s[1] GT 400 THEN BEGIN ; With scroll bars. Widget_Control, info.drawbase, Map=0 Widget_Control, info.drawID, /Destroy info.drawID = Widget_Draw(info.drawbase, XSize=s[0], $ YSize=s[1], X_Scroll_Size=s[0] < 400, Y_Scroll_Size=s[1] < 400) Widget_Control, info.drawID, /Realize Widget_Control, info.drawID, Get_Value=wid WSet, wid info.wid = wid TVImage, image Widget_Control, info.drawbase, Map=1 ENDIF ELSE BEGIN ; Without scroll bars. Widget_Control, info.drawbase, Map=0 Widget_Control, info.drawID, /Destroy info.drawID = Widget_Draw(info.drawbase, XSize=s[0], $ YSize=s[1]) Widget_Control, info.drawID, /Realize Widget_Control, info.drawID, Get_Value=wid WSet, wid info.wid = wid TVImage, image Widget_Control, info.drawbase, Map=1 ENDELSE Widget_Control, event.top, Set_UValue=info END ;====================================================================== PRO SCROLL_EXAMPLE_CLEANUP, tlb ; Cleanup routine. Free image pointer. Widget_Control, tlb, Get_UValue=info IF N_Elements(info) NE 0 THEN Ptr_Free, info.image END ;====================================================================== PRO SCROLL_EXAMPLE ; Example program to show how to create draw widget windows ; with or without scroll bars on the window. image = LoadData(Cancel=cancelled, /Images) IF cancelled THEN RETURN s = Size(image, /Dimensions) tlb = Widget_Base(Column=1, MBar=menuID, /TLB_Size_Events) controlID = Widget_Button(menuID, Value='Controls') button = Widget_Button(controlID, Value='Load Image', $ Event_Pro='Scroll_Example_Load') drawbase = Widget_Base(tlb) ; Draw widget with or without scroll bars based on ; image size. IF s[0] GT 400 OR s[1] GT 400 THEN BEGIN drawID = Widget_Draw(drawbase, XSize=s[0], YSize=s[1], $ X_Scroll_Size=s[0] < 400, Y_Scroll_Size=s[1] < 400) ENDIF ELSE BEGIN drawID = Widget_Draw(drawbase, XSize=s[0], YSize=s[1]) ENDELSE Widget_Control, tlb, /Realize Widget_Control, drawID, Get_Value=wid WSet, wid TVImage, image info = {image:Ptr_New(image), drawbase:drawbase, $ drawID:drawID, wid:wid} Widget_Control, tlb, Set_UValue=info XManager, 'scroll_example', tlb, Cleanup='Scroll_Example_Cleanup', $ Event_Handler='Scroll_Example_Resize', /No_Block END