MoveGadgetToToolBar(): Move Gadgets into the Toolbar

Share your advanced knowledge/code with the community.
User avatar
Peter
Posts: 1093
Joined: Mon Feb 24, 2014 10:17 pm
Location: 127.0.0.1:9080
Contact:

MoveGadgetToToolBar(): Move Gadgets into the Toolbar

Post by Peter »

Hello,

with the MoveGadgetToToolBar() - Procedure below you are able to move a gadget into the toolbar.

Image

Code: Select all

Procedure MoveGadgetToToolBar(Toolbar, Gadget)
  
  If IsToolBar(Toolbar) = 0 : ProcedureReturn : EndIf
  If IsGadget(Gadget) = 0 : ProcedureReturn : EndIf
  
  Protected TID = ToolBarID(Toolbar)
  Protected SID = GadgetID(Gadget)
  
  ! $(v_sid.div).addClass("dijit dijitReset dijitInline dijitLeft");

  ! $(v_sid.div).css("position", "").children().css("position", "");
  ! $(v_sid.div).css("top", "").children().css("top", "");
  ! $(v_sid.div).css("left", "").children().css("left", "");
  
  ! $(v_tid.containerNode).append(v_sid.div);
  
EndProcedure
Example:
(save this snippet into the examples-folder in order to load the correct images for the buttons)

Code: Select all

Procedure MoveGadgetToToolBar(Toolbar, Gadget)
  
  If IsToolBar(Toolbar) = 0 : ProcedureReturn : EndIf
  If IsGadget(Gadget) = 0 : ProcedureReturn : EndIf
  
  Protected TID = ToolBarID(Toolbar)
  Protected SID = GadgetID(Gadget)
  
  ! $(v_sid.div).addClass("dijit dijitReset dijitInline dijitLeft");

  ! $(v_sid.div).css("position", "").children().css("position", "");
  ! $(v_sid.div).css("position", "").children().css("top", "");
  ! $(v_sid.div).css("position", "").children().css("left", "");
  
  ! $(v_tid.containerNode).append(v_sid.div);
  
EndProcedure

Procedure Start()
  
  If OpenWindow(0, 0, 0, 295, 260, "MoveGadgetToToolBar example", #PB_Window_TitleBar | #PB_Window_SizeGadget | #PB_Window_ScreenCentered)
    
    If CreateToolBar(0, WindowID(0))
      ToolBarImageButton(0, ImageID(0))
      ToolBarImageButton(1, ImageID(1))
      ToolBarImageButton(2, ImageID(2))
    EndIf
    
    ToolBarSeparator()
    
    TextGadget(3, 0, 0, 40, ToolBarHeight(0) - 6, "Filter:", #PB_Text_VerticalCenter)
    MoveGadgetToToolBar(0, 3)
    
    StringGadget(4, 0, 0, 100, ToolBarHeight(0) - 6, "")
    MoveGadgetToToolBar(0, 4)
    
  EndIf
  
EndProcedure

Procedure Loading(Type, Filename$)
  Static NbLoadedElements
  NbLoadedElements + 1
  If NbLoadedElements = 3 ; Finished the loading of all images, we can start the application
    Start()
  EndIf
EndProcedure

Procedure LoadingError(Type, Filename$)
  Debug Filename$ + ": loading error"
EndProcedure

; Register the loading event before calling any resource load command
BindEvent(#PB_Event_Loading, @Loading())
BindEvent(#PB_Event_LoadingError, @LoadingError())

LoadImage(0, "Data/ToolBar/New.png")
LoadImage(1, "Data/ToolBar/Open.png")
LoadImage(2, "Data/ToolBar/Save.png")
Greetings ... Peter

// Edit: Unfortunately the Toolbar 'steals' the Cursor-Key-Events from the TextGadget...