Blog
All Blog Posts | Next Post | Previous Post
Office 2003 / VS.NET 2005 / Office 2007 style docking toolbars & menus
Wednesday, January 21, 2009
TMS Advanced ToolBars & Menus support Office 2003 style docking toolbars & menus as well as Office 2007 ribbon style toolbars. Building applications with Office 2003 style docked toolbars starts by using TAdvDockPanel which is the component that holds one or more toolbars. For Office 2007 ribbon style toolbars, the toolbar container component is TAdvToolbarPager.Creating Office 2003 style applications
Getting started
To start creating an Office 2003 application, drop a TAdvDockPanel and TAdvToolbarOfficeStyler component on the form. Right-click on the TAdvDockPanel and choose "Add toolbar". By default the toolbar has a grip (left dots to drag the toolbar on the TAdvDockPanel or to undock the toolbar from the TAdvDockPanel) and a right handle. Different grip styles can be choosen from the TAdvToolbarOfficeStyler with the property DragGripStyle. The right handle, from where you can show an options or customize menu, can be shown with the toolbar property ShowRightHandle.
begin atb := TAdvToolbar.Create(advdockpanel1); atb.Parent := advdockpanel1; end;
Adding controls
The TAdvToolBar supports by default a number of different controls: TAdvToolBarButton, TAdvToolBarMenuButton, TAdvToolBarSeparator, TDBAdvToolBarButton, TAdvContainer. These default controls can be inserted by right-clicking the toolbar and selecting the desired control.
tasButton or tasCheck. In tasButton style, the toolbar button simply triggers the associated action or the OnClick event when clicked. With the style tasCheck, the button behaves as a checkbox. The checkbox state can be get or set with the Down property. Multiple toolbarbuttons can also behave as a radiobutton. To group buttons that should behave as radio buttons, set the GroupIndex to a value different from 0.
Controls can be easily programmatically inserted on the toolbar. This code snippet adds two TAdvToolBarButtons and a combobox on a TAdvToolBar and sets the behaviour to a radiogroup behaviour:
var atb: TAdvToolBarButton; combobox: TComboBox; begin atb := TAdvToolBarButton.Create(Advtoolbar1); atb.Caption := 'Option 1'; atb.ShowCaption := true; atb.GroupIndex := 1; advtoolbar1.AddToolBarControl(atb); atb := TAdvToolBarButton.Create(Advtoolbar1); atb.Caption := 'Option 2'; atb.ShowCaption := true; atb.GroupIndex := 1; advtoolbar1.AddToolBarControl(atb); combobox := TComboBox.Create(AdvToolBar1); advtoolbar1.AddToolBarControl(combobox); end;
The toolbar controls can be easily accessed with the property TAdvToolBar.ToolBarControls[controlindex]. The total number of controls on the TAdvToolBar is returned by ToolBarControlCount.
Adding a menu
By default a TAdvToolBar layout is preset to hold controls. A toolbar can also be used to host a menu. Typically, in Office 2003 style applications, the toolbar holding the menu automatically uses the full dockpanel width (or height for a vertically oriented dockpanel). To design such toolbar with a menu, set TAdvToolBar.FullSize = true. To add the menu, drop a TAdvMainMenu component on the form and design the menu with the design time menu designer. By default, the IDE will have attached the menu to the form. As the menu will be used by the toolbar, remove AdvMainMenu from the Form's Menu property and assign AdvMainMenu to TAdvToolBar.Menu. To use a styler component for the menu as well, drop a TAdvMenuOfficeStyler component on the form and assign it to the TAdvToolBarOfficeStyler.AdvMenuStyler property.
var rootmnu, mnu: TMenuItem; begin rootmnu := TMenuItem.Create(AdvMainMenu1); rootmnu.Caption := 'New'; AdvMainMenu1.Items.Add(rootmnu); mnu := TMenuItem.Create(AdvMainMenu1); mnu.Caption := 'New item'; rootmnu.Add(mnu); AdvToolBar1.UpdateMenu; end;
Creating Office 2007 style applications
Getting started
For Delphi 7, Delphi 2006, Delphi 2007 a wizard gets you started right-away. Choose File, New, Other and under "TMS Wizard", pick "TMS ToolBar Application Wizard". This will create a new application for you with a TAdvToolBarPager, TAdvPage, TAdvToolBar, TAdvPreviewMenu, TAdvShapeButton. This is generated in a form descending from TAdvToolBarForm that takes care of border size, painting, caption.To start an Office 2007 ribbon style toolbar application manually, drop the TAdvToolBarPager container and TAdvToolBarOfficeStyler component on the form.
Assign the TAdvToolBarOfficeStyler to TAdvToolBarPager.ToolBarStyler.
Right-click on the TAdvToolBarPager and choose "New Page" to insert pages in the pager. On the page, right-click and select "Add toolbar" to insert a toolbar.

Programmatically creating pages, toolbars, changing toolbars etc.. is made easy with a couple of TAdvToolBarPager methods. This code snippet programmatically inserts a new page and creates a new toolbar and sets the toolbar caption in the inserted page:
begin with AdvToolBarPager1 do begin AddAdvPage('New page'); ActivePage := AdvPages[AdvPageCount - 1]; AdvPages[AdvPageCount - 1].CreateAdvToolBar; AdvPages[AdvPageCount - 1].AdvToolBars[0].Caption := 'New toolbar'; end; end;
Using the TAdvToolBarPager to move, close, minimize and maximize a captionless form

Adding controls
TAdvToolBar supports a number of built-in controls that can be added on the toolbar. The Office 2003 toolbar controls can be used but for closer Office 2007 appearance, it is recommended to use the new TAdvGlowButton, TAdvGlowMenuButton, TDBAdvGlowButton controls. Inserting controls is done by right-click on the toolbar and choosing "Add AdvGlowButton", "Add AdvGlowMenuButton", ... The position of the controls in the TAdvToolBar are by default automatically controlled by the TAdvToolBar itself and will be inserted starting from left in the toolbar. To disable this automatic position control, set TAdvToolBar.AutoPositionControls = false. The controls can in this mode be positioned at exact coordinates in the toolbar.The TAdvGlowButton or TAdvGlowMenuButton are two control types that can be added to the TAdvToolBar and that can be used in different ways:


Tab groups
Toolbars that are in multiple pages that functionally belong together can be grouped with tabgroups. Tabgroups are managed on the level of the TAdvToolBarPager via the TabGroups property.
Compact mode toolbars
By default, a toolbar on a TAdvPage shows all controls on the toolbar. However, when a window gets too small to show all toolbars with all controls, a toolbar switches to compact mode. In this compact mode, a toolbar reverts to a single AdvGlowButton from where a click displays the full toolbar. The screenshots below show this in action. The first window is sufficiently wide to show all toolbars.


Office 2007 hints
All controls that are part of the advanced toolbars & menus feature an extended Office 2007 style hint. Office 2007 hints are more sophisticated than regular Delphi hints. An office 2007 hint has a title, an optional picture, help text and an optional help line.
Bruno Fierens

This blog post has not received any comments yet.
All Blog Posts | Next Post | Previous Post