]> git.saurik.com Git - wxWidgets.git/blame - docs/latex/wx/ttoolbar.tex
Configure now adds -D__WXDEBUG__ to the compiler switches if run with
[wxWidgets.git] / docs / latex / wx / ttoolbar.tex
CommitLineData
a660d684
KB
1\section{Toolbar overview}\label{wxtoolbaroverview}
2
3Classes: \helpref{wxToolBarBase}{wxtoolbarbase}, \helpref{wxToolBarSimple}{wxtoolbarsimple},\rtfsp
4\helpref{wxToolBarMSW}{wxtoolbarmsw}, \helpref{wxToolBar95}{wxtoolbar95}
5
6The toolbar family of classes allows an application to use toolbars
7in a variety of configurations and styles.
8
9The toolbar is a popular user interface component and contains a set of bitmap
10buttons or toggles. A toolbar gives faster access to an application's facilities than
11menus, which have to be popped up and selected rather laboriously.
12
13Instead of supplying one toolbar class with a number
14of different implementations depending on platform, wxWindows separates
15out the classes. This is because there are a number of different toolbar
16styles that you may wish to use simultaneously, and also, future
17toolbar implementations will emerge (for example, using the
18new-style Windows `coolbar' as seen in Microsoft applications) which
19cannot be shoe-horned into the one class.
20
21This does mean that if you wish to use a more sophisticated toolbar
22on one platform (say, wxToolBar95) and a simple toolbar on another
23platform (wxToolBarSimple), then you will need some simple ifdefing, such as:
24
25\begin{verbatim}
26 #ifdef wx_msw
27 # define wxToolBar wxToolBar95
28 #else
29 # define wxToolBar wxToolBarSimple
30 #endif
31\end{verbatim}
32
33Fortunately, the APIs of the toolbar classes are virtually identical.
34
35The following is a summary of the toolbar classes and their differences.
36
37\begin{itemize}\itemsep=0pt
38\item {\bf wxToolBarBase.} This is a base class with pure virtual functions,
39and should not be used directly.
40\item {\bf wxToolBarSimple.} A simple toolbar class written entirely with generic wxWindows
41functionality. A simply 3D effect for buttons is possible, but it is not consistent
42with the Windows look and feel. This toolbar can scroll, and you can have arbitrary
43numbers of rows and columns.
44\item {\bf wxToolBarMSW.} This class implements an old-style Windows toolbar, only on
45Windows. There are small, three-dimensional buttons, which do not (currently) reflect
46the current Windows colour settings: the buttons are grey.
47\item {\bf wxToolBar95.} Uses the native Windows 95 toolbar class. It dynamically adjusts its
48background and button colours according to user colour settings.
49CreateTools must be called after the tools have been added.
50No absolute positioning is supported but you can specify the number
51of rows, and add tool separators with {\bf AddSeparator}. {\bf Layout} does nothing.
52Tooltips are supported. {\bf OnRightClick} is not supported.
53For some reason, a wxToolBar95 control cannot be moved to any
54position other than the top-left of the frame.
55\end{itemize}
56
57A toolbar might appear as a single row of images under
58the menubar, or it might be in a separate frame layout in several rows
59and columns. The class handles the layout of the images, unless explicit
60positioning is requested.
61
62A tool is a bitmap which can either be a button (there is no `state',
63it just generates an event when clicked) or it can be a toggle. If a
64toggle, a second bitmap can be provided to depict the `on' state; if
65the second bitmap is omitted, either the inverse of the first bitmap
66will be used (for monochrome displays) or a thick border is drawn
67around the bitmap (for colour displays where inverting will not have
68the desired result).
69
70The Windows-specific toolbar classes expect 16-colour bitmaps that are 16 pixels wide and 15 pixels
71high. If you want to use a different size, call {\bf SetDefaultSize}\rtfsp
72as the demo shows, before adding tools to the button bar. Don't supply more than
73one bitmap for each tool, because the toolbar generates all three images (normal,
74depressed and checked) from the single bitmap you give it.
75
76Mouse click events for a given button are sent to a member called
77\rtfsp{\bf OnLeftClick}, and so an application must derive from wxToolBar in order
78to use it. The application can also handle {\bf OnMouseEnter} events for
79the tools, to give the user extra feedback about the tools as the mouse
80moves over them.
81
82\subsection{Using the toolbar library}
83
84Include one of the files {\tt tbarsmpl.h, tbar95.h, tbarmsw.h}.
85
86Example of toolbar use are given in the sample programs tbarsmpl,
87tbarmsw and tbar95.
88
89Each sample creates a main window, and two toolbars: a floating toolbar
fe604ccd 90with 24 tools, and a toolbar along the top of the main drawing window, divided into groups.
a660d684
KB
91
92The test program defines a general-purpose derived frame called
93\rtfsp{\bf wxFrameWithToolBar} which can manage a frame with one main subwindow
94and one horizontal toolbar.
95
96Note that one of the bitmaps on the floating toolbar is a small version of the
97main graphic: this demonstrates how a memory device context can be used to
98draw into a bitmap. An application which allowed the user to build up a symbol
99library dynamically might create this kind of bitmap.
100
101Left clicks and movements over the toolbars are intercepted and information
102is displayed on the status line.
103
104The following fragment illustrates the essence of creating a toolbar.
105
106\begin{verbatim}
107 toolBarBitmaps[0] = new wxBitmap("icon1");
108 toolBarBitmaps[1] = new wxBitmap("icon2");
109 toolBarBitmaps[2] = new wxBitmap("icon3");
110 ...
111
112 toolBarFrame = new wxFrame(NULL, "Tools", -1, wxPoint(0, 0), wxSize(300, 200),
113 wxDEFAULT_FRAME_STYLE | wxSTAY_ON_TOP);
114
115 // 5 rows
fe604ccd 116 toolBar = new TestToolBar(toolBarFrame, -1, wxPoint(10, 10), wxSize(-1, -1), 0, wxVERTICAL, 5);
a660d684
KB
117 toolBar->SetMargins(2, 2);
118
119 for (int i = 10; i < 25; i++)
120 toolBar->AddTool(i, toolBarBitmaps[i], NULL, TRUE);
121
122 toolBar->Layout();
123 float maxWidth, maxHeight;
124 wxSize size(toolBar->GetMaxSize());
125 toolBarFrame->SetClientSize(maxSize.x, maxSize.y);
126 toolBarFrame->Show(TRUE);
127\end{verbatim}
128