\membersection{wxToolBar::AddTool}\label{wxtoolbaraddtool}
-\func{wxToolBarTool*}{AddTool}{\param{int}{ toolIndex}, \param{const wxBitmap\&}{ bitmap1},\rtfsp
+\func{wxToolBarTool*}{AddTool}{\param{int}{ toolId}, \param{const wxBitmap\&}{ bitmap1},\rtfsp
\param{const wxBitmap\&}{ bitmap2 = wxNullBitmap}, \param{bool}{ isToggle = FALSE},\rtfsp
\param{long}{ xPos = -1}, \param{long}{ yPos = -1},\rtfsp
\param{wxObject* }{clientData = NULL}, \param{const wxString\& }{shortHelpString = ""}, \param{const wxString\& }{longHelpString = ""}}
\wxheading{Parameters}
-\docparam{toolIndex}{An integer by which
+\docparam{toolId}{An integer by which
the tool may be identified in subsequent operations.}
\docparam{isToggle}{Specifies whether the tool is a toggle or not: a toggle tool may be in
\docparam{clientData}{An optional pointer to client data which can be
retrieved later using \helpref{wxToolBar::GetToolClientData}{wxtoolbargettoolclientdata}.}
-\docparam{shortHelpString}{Used for displaying a tooltip for the tool in the
-Windows 95 implementation of wxButtonBar. Pass the empty string if this is not required.}
+\docparam{shortHelpString}{This string is used for the tools tooltip}
-\docparam{longHelpString}{Used to displayer longer help, such as status line help.
-Pass the empty string if this is not required.}
+\docparam{longHelpString}{This string is shown in the statusbar (if any) of the
+parent frame when the mouse pointer is inside the tool}
\wxheading{Remarks}
\wxheading{See also}
\helpref{wxToolBar::AddSeparator}{wxtoolbaraddseparator},
+\helpref{wxToolBar::InsertTool}{wxtoolbarinserttool},
+\helpref{wxToolBar::DeleteTool}{wxtoolbardeletetool},
\helpref{wxToolBar::Realize}{wxtoolbarrealize},
-\membersection{wxToolBar::CreateTools}\label{wxtoolbarcreatetools}
+\membersection{wxToolBar::DeleteTool}\label{wxtoolbardeletetool}
-\func{bool}{CreateTools}{\void}
+\func{bool}{DeleteTool}{\param{int }{toolId}}
-This function is implemented for some toolbar classes to create the tools and display them.
-The portable way of calling it is to call \helpref{wxToolBar::Realize}{wxtoolbarrealize} after
-you have added tools and separators.
+Removes the specified tool from the toolbar and deletes it. If you don't want
+to delete the tool, but just to remove it from the toolbar (to possibly add it
+back later), you may use \helpref{RemoveTool}{wxtoolbarremovetool} instead.
-\wxheading{See also}
-
-\helpref{wxToolBar::AddTool}{wxtoolbaraddtool}, \helpref{wxToolBar::Realize}{wxtoolbarrealize}
-
-\membersection{wxToolBar::DrawTool}\label{wxtoolbardrawtool}
+Note that it is unnecessary to call \helpref{Realize}{wxtoolbarrealize} for the
+change to take place, it will happen immediately.
-\func{void}{DrawTool}{\param{wxMemoryDC\& }{memDC}, \param{wxToolBarTool* }{tool}}
+Returns TRUE if the tool was deleted, FALSE otherwise.
-Draws the specified tool onto the window using the given memory device context.
-
-\wxheading{Parameters}
+\wxheading{See also}
-\docparam{memDC}{A memory DC to be used for drawing the tool.}
+\helpref{DeleteToolByPos}{wxtoolbardeletetoolbypos}
-\docparam{tool}{Tool to be drawn.}
+\membersection{wxToolBar::DeleteToolByPos}\label{wxtoolbardeletetoolbypos}
-\wxheading{Remarks}
+\func{bool}{DeleteToolByPos}{\param{size\_t }{pos}}
-For internal use only.
+This function behaves like \helpref{DeleteTool}{wxtoolbardeletetool} but it
+deletes the tool at the specified position and not the one with the given id.
\membersection{wxToolBar::EnableTool}\label{wxtoolbarenabletool}
-\func{void}{EnableTool}{\param{int }{toolIndex}, \param{const bool}{ enable}}
+\func{void}{EnableTool}{\param{int }{toolId}, \param{const bool}{ enable}}
Enables or disables the tool.
\wxheading{Parameters}
-\docparam{toolIndex}{Tool to enable or disable.}
+\docparam{toolId}{Tool to enable or disable.}
\docparam{enable}{If TRUE, enables the tool, otherwise disables it.}
\wxheading{See also}
\helpref{wxToolBar::GetToolEnabled}{wxtoolbargettoolenabled},\rtfsp
-%\helpref{wxToolBar::SetToolState}{wxtoolbarsettoolstate},\rtfsp
\helpref{wxToolBar::ToggleTool}{wxtoolbartoggletool}
\membersection{wxToolBar::FindToolForPosition}\label{wxtoolbarfindtoolforposition}
\helpref{wxToolBar::SetMargins}{wxtoolbarsetmargins}
-\membersection{wxToolBar::GetMaxSize}\label{wxtoolbargetmaxsize}
-
-\constfunc{wxSize}{GetMaxSize}{\void}
-
-Gets the maximum size taken up by the tools after layout, including margins.
-This can be used to size a frame around the toolbar window.
-
\membersection{wxToolBar::GetToolClientData}\label{wxtoolbargettoolclientdata}
-\constfunc{wxObject*}{GetToolClientData}{\param{int }{toolIndex}}
+\constfunc{wxObject*}{GetToolClientData}{\param{int }{toolId}}
Get any client data associated with the tool.
\wxheading{Parameters}
-\docparam{toolIndex}{Index of the tool, as passed to \helpref{wxToolBar::AddTool}{wxtoolbaraddtool}.}
+\docparam{toolId}{Id of the tool, as passed to \helpref{wxToolBar::AddTool}{wxtoolbaraddtool}.}
\wxheading{Return value}
\membersection{wxToolBar::GetToolEnabled}\label{wxtoolbargettoolenabled}
-\constfunc{bool}{GetToolEnabled}{\param{int }{toolIndex}}
+\constfunc{bool}{GetToolEnabled}{\param{int }{toolId}}
Called to determine whether a tool is enabled (responds to user input).
\wxheading{Parameters}
-\docparam{toolIndex}{Index of the tool in question.}
+\docparam{toolId}{Id of the tool in question.}
\wxheading{Return value}
TRUE if the tool is enabled, FALSE otherwise.
-%\wxheading{See also}
-%
-%\helpref{wxToolBar::SetToolEnabled}{wxtoolbarsettoolenabled}
-%
+\wxheading{See also}
+
+\helpref{wxToolBar::EnableTool}{wxtoolbarenabletool}
+
\membersection{wxToolBar::GetToolLongHelp}\label{wxtoolbargettoollonghelp}
-\constfunc{wxString}{GetToolLongHelp}{\param{int }{toolIndex}}
+\constfunc{wxString}{GetToolLongHelp}{\param{int }{toolId}}
Returns the long help for the given tool.
\wxheading{Parameters}
-\docparam{toolIndex}{The tool in question.}
+\docparam{toolId}{The tool in question.}
\wxheading{See also}
\membersection{wxToolBar::GetToolShortHelp}\label{wxtoolbargettoolshorthelp}
-\constfunc{wxString}{GetToolShortHelp}{\param{int }{toolIndex}}
+\constfunc{wxString}{GetToolShortHelp}{\param{int }{toolId}}
Returns the short help for the given tool.
\wxheading{Parameters}
-\docparam{toolIndex}{The tool in question.}
+\docparam{toolId}{The tool in question.}
\wxheading{See also}
\membersection{wxToolBar::GetToolState}\label{wxtoolbargettoolstate}
-\constfunc{bool}{GetToolState}{\param{int }{toolIndex}}
+\constfunc{bool}{GetToolState}{\param{int }{toolId}}
Gets the on/off state of a toggle tool.
\wxheading{Parameters}
-\docparam{toolIndex}{The tool in question.}
+\docparam{toolId}{The tool in question.}
\wxheading{Return value}
TRUE if the tool is toggled on, FALSE otherwise.
-%\wxheading{See also}
-%
-%\helpref{wxToolBar::SetToolState}{wxtoolbarsettoolstate}
-%
-\membersection{wxToolBar::Layout}\label{wxtoolbarlayout}
+\wxheading{See also}
+
+\helpref{wxToolBar::ToggleTool}{wxtoolbartoggletool}
+
+\membersection{wxToolBar::InsertControl}\label{wxtoolbarinsertcontrol}
+
+\func{wxToolBarTool *}{InsertControl}{\param{size\_t }{pos}, \param{wxControl *}{control}}
+
+Inserts the control into the toolbar at the given position.
+
+You must call \helpref{Realize}{wxtoolbarrealize} for the change to take place.
-\func{void}{Layout}{\void}
+\wxheading{See also}
+
+\helpref{AddControl}{wxtoolbaraddcontrol},\\
+\helpref{InsertTool}{wxtoolbarinserttool}
+
+\membersection{wxToolBar::InsertSeparator}\label{wxtoolbarinsertseparator}
+
+\func{wxToolBarTool *}{InsertSeparator}{\param{size\_t }{pos}}
+
+Inserts the separator into the toolbar at the given position.
+
+You must call \helpref{Realize}{wxtoolbarrealize} for the change to take place.
+
+\wxheading{See also}
+
+\helpref{AddSeparator}{wxtoolbaraddseparator},\\
+\helpref{InsertTool}{wxtoolbarinserttool}
+
+\membersection{wxToolBar::InsertTool}\label{wxtoolbarinserttool}
-Called by the application after the tools have been added to
-automatically lay the tools out on the window. If you have given
-absolute positions when adding the tools, do not call this.
+\func{wxToolBarTool *}{InsertTool}{\param{size\_t }{pos},\rtfsp
+{\param{int}{ toolId}, \param{const wxBitmap\&}{ bitmap1},\rtfsp
+\param{const wxBitmap\&}{ bitmap2 = wxNullBitmap}, \param{bool}{ isToggle = FALSE},\rtfsp
+\param{wxObject* }{clientData = NULL}, \param{const wxString\& }{shortHelpString = ""}, \param{const wxString\& }{longHelpString = ""}}
+
+Inserts the tool with the specified attributes into the toolbar at the given
+position.
-This function is only implemented for some toolbar classes.
-The portable way of calling it is to call \helpref{wxToolBar::Realize}{wxtoolbarrealize} after
-you have added tools and separators.
+You must call \helpref{Realize}{wxtoolbarrealize} for the change to take place.
\wxheading{See also}
-\helpref{wxToolBar::AddTool}{wxtoolbaraddtool}, \helpref{wxToolBar::Realize}{wxtoolbarrealize}
+\helpref{AddTool}{wxtoolbaraddtool},\\
+\helpref{InsertControl}{wxtoolbarinsertcontrol},\\
+\helpref{InsertSeparator}{wxtoolbarinsertseparator}
\membersection{wxToolBar::OnLeftClick}\label{wxtoolbaronleftclick}
-\func{bool}{OnLeftClick}{\param{int}{ toolIndex}, \param{bool}{ toggleDown}}
+\func{bool}{OnLeftClick}{\param{int}{ toolId}, \param{bool}{ toggleDown}}
Called when the user clicks on a tool with the left mouse button.
\wxheading{Parameters}
-\docparam{toolIndex}{The identifier passed to \helpref{wxToolBar::AddTool}{wxtoolbaraddtool}.}
+\docparam{toolId}{The identifier passed to \helpref{wxToolBar::AddTool}{wxtoolbaraddtool}.}
\docparam{toggleDown}{TRUE if the tool is a toggle and the toggle is down, otherwise is FALSE.}
\membersection{wxToolBar::OnMouseEnter}\label{wxtoolbaronmouseenter}
-\func{void}{OnMouseEnter}{\param{int}{ toolIndex}}
+\func{void}{OnMouseEnter}{\param{int}{ toolId}}
This is called when the mouse cursor moves into a tool or out of
the toolbar.
\wxheading{Parameters}
-\docparam{toolIndex}{Greater than -1 if the mouse cursor has moved into the tool,
+\docparam{toolId}{Greater than -1 if the mouse cursor has moved into the tool,
or -1 if the mouse cursor has moved. The
programmer can override this to provide extra information about the tool,
such as a short description on the status line.}
\membersection{wxToolBar::OnRightClick}\label{wxtoolbaronrightclick}
-\func{void}{OnRightClick}{\param{int}{ toolIndex}, \param{float}{ x}, \param{float}{ y}}
+\func{void}{OnRightClick}{\param{int}{ toolId}, \param{float}{ x}, \param{float}{ y}}
Called when the user clicks on a tool with the right mouse button. The
programmer should override this function to detect right tool clicks.
\wxheading{Parameters}
-\docparam{toolIndex}{The identifier passed to \helpref{wxToolBar::AddTool}{wxtoolbaraddtool}.}
+\docparam{toolId}{The identifier passed to \helpref{wxToolBar::AddTool}{wxtoolbaraddtool}.}
\docparam{x}{The x position of the mouse cursor.}
If you are using absolute positions for your tools when using a wxToolBarSimple object,
do not call this function. You must call it at all other times.
+\membersection{wxToolBar::RemoveTool}\label{wxtoolbarremovetool}
+
+\func{wxToolBarTool *}{RemoveTool}{\param{int }{id}}
+
+Removes the given tool from the toolbar but doesn't delete it. This allows to
+insert/add this tool back to this (or another) toolbar later.
+
+Note that it is unnecessary to call \helpref{Realize}{wxtoolbarrealize} for the
+change to take place, it will happen immediately.
+
+\wxheading{See also}
+
+\helpref{DeleteTool}{wxtoolbardeletetool}
+
\membersection{wxToolBar::SetToolBitmapSize}\label{wxtoolbarsettoolbitmapsize}
\func{void}{SetToolBitmapSize}{\param{const wxSize\&}{ size}}
\membersection{wxToolBar::SetToolLongHelp}\label{wxtoolbarsettoollonghelp}
-\func{void}{SetToolLongHelp}{\param{int }{toolIndex}, \param{const wxString\& }{helpString}}
+\func{void}{SetToolLongHelp}{\param{int }{toolId}, \param{const wxString\& }{helpString}}
Sets the long help for the given tool.
\wxheading{Parameters}
-\docparam{toolIndex}{The tool in question.}
+\docparam{toolId}{The tool in question.}
\docparam{helpString}{A string for the long help.}
\membersection{wxToolBar::SetToolShortHelp}\label{wxtoolbarsettoolshorthelp}
-\func{void}{SetToolShortHelp}{\param{int }{toolIndex}, \param{const wxString\& }{helpString}}
+\func{void}{SetToolShortHelp}{\param{int }{toolId}, \param{const wxString\& }{helpString}}
Sets the short help for the given tool.
\wxheading{Parameters}
-\docparam{toolIndex}{The tool in question.}
+\docparam{toolId}{The tool in question.}
\docparam{helpString}{The string for the short help.}
\membersection{wxToolBar::ToggleTool}\label{wxtoolbartoggletool}
-\func{void}{ToggleTool}{\param{int }{toolIndex}, \param{const bool}{ toggle}}
+\func{void}{ToggleTool}{\param{int }{toolId}, \param{const bool}{ toggle}}
Toggles a tool on or off. This does not cause any event to get emitted.
\wxheading{Parameters}
-\docparam{toolIndex}{Tool in question.}
+\docparam{toolId}{Tool in question.}
\docparam{toggle}{If TRUE, toggles the tool on, otherwise toggles it off.}
while {\it Helpview} is simple tool that only pops up help window and
displays help books given at command line.
+\subsection{Toolbar sample}\label{sampletoolbar}
+
+The toolbar sample shows the \helpref{wxToolBar}{wxtoolbar} class in action.
+
+The following things are demonstrated:
+
+\begin{itemize}
+
+\item Creating the toolbar using \helpref{wxToolBar::AddTool}{wxtoolbaraddtool}
+and \helpref{wxToolBar::AddControl}{wxtoolbaraddcontrol}: see
+MyApp::InitToolbar in the sample.
+
+\item Using {\tt EVT\_UPDATE\_UI} handler for automatically enabling/disabling
+toolbar buttons without having to explicitly call EnableTool. This is is done
+in MyFrame::OnUpdateCopyAndCut.
+
+\item Using \helpref{wxToolBar::DeleteTool}{wxtoolbardeletetool} and
+\helpref{wxToolBar::InsertTool}{wxtoolbarinserttool} to dynamically update the
+toolbar.
+
+\end{itemize}
(void)new wxBitmapButton(panel, -1, bitmap, wxPoint(100, 20));
+ bitmap = wxBitmap("../../utils/wxPython/tests/bitmaps/test2.bmp",
+ wxBITMAP_TYPE_BMP);
+ bitmap.SetMask(new wxMask(bitmap, *wxBLUE));
+ (void)new wxBitmapButton(panel, -1, bitmap, wxPoint(300, 120));
+
wxBitmap bmp1(wxTheApp->GetStdIcon(wxICON_INFORMATION)),
bmp2(wxTheApp->GetStdIcon(wxICON_WARNING)),
bmp3(wxTheApp->GetStdIcon(wxICON_QUESTION));
/* XPM */
-static char *preview_xpm[] = {
+static char *paste_xpm[] = {
/* columns rows colors chars-per-pixel */
"16 15 5 1",
" c Black",
#include "bitmaps/save.xpm"
#include "bitmaps/copy.xpm"
#include "bitmaps/cut.xpm"
- // #include "bitmaps/paste.xpm"
+ #include "bitmaps/preview.xpm" // paste XPM
#include "bitmaps/print.xpm"
- #include "bitmaps/preview.xpm"
#include "bitmaps/help.xpm"
#endif // GTK or Motif
// ----------------------------------------------------------------------------
// Define a new application
-class MyApp: public wxApp
+class MyApp : public wxApp
{
public:
bool OnInit();
- bool InitToolbar(wxToolBar* toolBar, bool smallicons = FALSE);
};
// Define a new frame
const wxSize& size = wxDefaultSize,
long style = wxDEFAULT_FRAME_STYLE);
+ void RecreateToolbar();
+
void OnQuit(wxCommandEvent& event);
void OnAbout(wxCommandEvent& event);
- void OnToggleToolbar(wxCommandEvent& event);
+ void OnToggleToolbarSize(wxCommandEvent& event);
+ void OnToggleToolbarOrient(wxCommandEvent& event);
+
void OnEnablePrint(wxCommandEvent& event) { DoEnablePrint(); }
void OnDeletePrint(wxCommandEvent& event) { DoDeletePrint(); }
void OnInsertPrint(wxCommandEvent& event);
void OnCombo(wxCommandEvent& event);
+ void OnUpdateCopyAndCut(wxUpdateUIEvent& event);
+
private:
void DoEnablePrint();
void DoDeletePrint();
void DoToggleHelp();
- bool m_smallToolbar;
+ bool m_smallToolbar,
+ m_horzToolbar;
wxTextCtrl* m_textWindow;
DECLARE_EVENT_TABLE()
enum
{
- IDM_TOOLBAR_TOGGLETOOLBAR = 200,
+ IDM_TOOLBAR_TOGGLETOOLBARSIZE = 200,
+ IDM_TOOLBAR_TOGGLETOOLBARORIENT,
IDM_TOOLBAR_ENABLEPRINT,
IDM_TOOLBAR_DELETEPRINT,
IDM_TOOLBAR_INSERTPRINT,
EVT_MENU(wxID_EXIT, MyFrame::OnQuit)
EVT_MENU(wxID_HELP, MyFrame::OnAbout)
- EVT_MENU(IDM_TOOLBAR_TOGGLETOOLBAR, MyFrame::OnToggleToolbar)
+ EVT_MENU(IDM_TOOLBAR_TOGGLETOOLBARSIZE, MyFrame::OnToggleToolbarSize)
+ EVT_MENU(IDM_TOOLBAR_TOGGLETOOLBARORIENT, MyFrame::OnToggleToolbarOrient)
+
EVT_MENU(IDM_TOOLBAR_ENABLEPRINT, MyFrame::OnEnablePrint)
EVT_MENU(IDM_TOOLBAR_DELETEPRINT, MyFrame::OnDeletePrint)
EVT_MENU(IDM_TOOLBAR_INSERTPRINT, MyFrame::OnInsertPrint)
EVT_COMBOBOX(ID_COMBO, MyFrame::OnCombo)
EVT_TOOL_ENTER(ID_TOOLBAR, MyFrame::OnToolEnter)
+
+ EVT_UPDATE_UI(wxID_COPY, MyFrame::OnUpdateCopyAndCut)
+ EVT_UPDATE_UI(wxID_CUT, MyFrame::OnUpdateCopyAndCut)
END_EVENT_TABLE()
// ============================================================================
return TRUE;
}
-bool MyApp::InitToolbar(wxToolBar* toolBar, bool smallicons)
+void MyFrame::RecreateToolbar()
{
- // Set up toolbar
- wxBitmap* toolBarBitmaps[8];
+ // delete and recreate the toolbar
+ wxToolBar *toolBar = GetToolBar();
+ delete toolBar;
-#ifdef __WXMSW__
- toolBarBitmaps[0] = new wxBitmap("icon1");
- toolBarBitmaps[1] = new wxBitmap("icon2");
- if ( !smallicons )
- {
- toolBarBitmaps[2] = new wxBitmap("icon3");
- toolBarBitmaps[3] = new wxBitmap("icon4");
- toolBarBitmaps[4] = new wxBitmap("icon5");
- toolBarBitmaps[5] = new wxBitmap("icon6");
- toolBarBitmaps[6] = new wxBitmap("icon7");
- toolBarBitmaps[7] = new wxBitmap("icon8");
- }
-#else
- toolBarBitmaps[0] = new wxBitmap( new_xpm );
- toolBarBitmaps[1] = new wxBitmap( open_xpm );
- if ( !smallicons )
- {
- toolBarBitmaps[2] = new wxBitmap( save_xpm );
- toolBarBitmaps[3] = new wxBitmap( copy_xpm );
- toolBarBitmaps[4] = new wxBitmap( cut_xpm );
- toolBarBitmaps[5] = new wxBitmap( preview_xpm );
- toolBarBitmaps[6] = new wxBitmap( print_xpm );
- toolBarBitmaps[7] = new wxBitmap( help_xpm );
- }
-#endif
+ SetToolBar(NULL);
+
+ long style = wxNO_BORDER | wxTB_FLAT | wxTB_DOCKABLE;
+ style |= m_horzToolbar ? wxTB_HORIZONTAL : wxTB_VERTICAL;
+
+ toolBar = CreateToolBar(style, ID_TOOLBAR);
+ toolBar->SetMargins( 4, 4 );
+
+ // Set up toolbar
+ wxBitmap toolBarBitmaps[8];
+
+ toolBarBitmaps[0] = wxBITMAP(new);
+ toolBarBitmaps[1] = wxBITMAP(open);
+ if ( !m_smallToolbar )
+ {
+ toolBarBitmaps[2] = wxBITMAP(save);
+ toolBarBitmaps[3] = wxBITMAP(copy);
+ toolBarBitmaps[4] = wxBITMAP(cut);
+ toolBarBitmaps[5] = wxBITMAP(paste);
+ toolBarBitmaps[6] = wxBITMAP(print);
+ toolBarBitmaps[7] = wxBITMAP(help);
+ }
#ifdef __WXMSW__
- int width = 24;
+ int width = 24;
#else
- int width = 16;
+ int width = 16;
#endif
- int currentX = 5;
-
- toolBar->AddTool(wxID_NEW, *(toolBarBitmaps[0]), wxNullBitmap, FALSE, currentX, -1, (wxObject *) NULL, "New file");
- currentX += width + 5;
- toolBar->AddTool(wxID_OPEN, *(toolBarBitmaps[1]), wxNullBitmap, FALSE, currentX, -1, (wxObject *) NULL, "Open file");
- wxComboBox *combo = new wxComboBox(toolBar, ID_COMBO);
- combo->Append("This");
- combo->Append("is a");
- combo->Append("combobox");
- combo->Append("in a");
- combo->Append("toolbar");
- toolBar->AddControl(combo);
+ int currentX = 5;
- if ( !smallicons )
- {
- currentX += width + 5;
- toolBar->AddTool(wxID_SAVE, *(toolBarBitmaps[2]), wxNullBitmap, TRUE, currentX, -1, (wxObject *) NULL, "Toggle button 1");
- currentX += width + 5;
- toolBar->AddTool(wxID_COPY, *(toolBarBitmaps[3]), wxNullBitmap, TRUE, currentX, -1, (wxObject *) NULL, "Toggle button 2");
- currentX += width + 5;
- toolBar->AddTool(wxID_CUT, *(toolBarBitmaps[4]), wxNullBitmap, FALSE, currentX, -1, (wxObject *) NULL, "Toggle/Untoggle help button");
- currentX += width + 5;
- toolBar->AddTool(wxID_PASTE, *(toolBarBitmaps[5]), wxNullBitmap, FALSE, currentX, -1, (wxObject *) NULL, "Paste");
- currentX += width + 5;
- toolBar->AddTool(wxID_PRINT, *(toolBarBitmaps[6]), wxNullBitmap, FALSE, currentX, -1, (wxObject *) NULL, "Delete this tool");
- currentX += width + 5;
- toolBar->AddSeparator();
- toolBar->AddTool(wxID_HELP, *(toolBarBitmaps[7]), wxNullBitmap, TRUE, currentX, -1, (wxObject *) NULL, "Help button");
- }
+ toolBar->AddTool(wxID_NEW, toolBarBitmaps[0], wxNullBitmap, FALSE, currentX, -1, (wxObject *) NULL, "New file");
+ currentX += width + 5;
+ toolBar->AddTool(wxID_OPEN, toolBarBitmaps[1], wxNullBitmap, FALSE, currentX, -1, (wxObject *) NULL, "Open file");
- toolBar->Realize();
+ // adding a combo to a vertical toolbar is not very smart
+ if ( m_horzToolbar )
+ {
+ wxComboBox *combo = new wxComboBox(toolBar, ID_COMBO);
+ combo->Append("This");
+ combo->Append("is a");
+ combo->Append("combobox");
+ combo->Append("in a");
+ combo->Append("toolbar");
+ toolBar->AddControl(combo);
+ }
- // Can delete the bitmaps since they're reference counted
- int i, max = smallicons ? 2 : WXSIZEOF(toolBarBitmaps);
- for (i = 0; i < max; i++)
- delete toolBarBitmaps[i];
+ if ( !m_smallToolbar )
+ {
+ currentX += width + 5;
+ toolBar->AddTool(wxID_SAVE, toolBarBitmaps[2], wxNullBitmap, TRUE, currentX, -1, (wxObject *) NULL, "Toggle button 1");
+ currentX += width + 5;
+ toolBar->AddTool(wxID_COPY, toolBarBitmaps[3], wxNullBitmap, TRUE, currentX, -1, (wxObject *) NULL, "Toggle button 2");
+ currentX += width + 5;
+ toolBar->AddTool(wxID_CUT, toolBarBitmaps[4], wxNullBitmap, FALSE, currentX, -1, (wxObject *) NULL, "Toggle/Untoggle help button");
+ currentX += width + 5;
+ toolBar->AddTool(wxID_PASTE, toolBarBitmaps[5], wxNullBitmap, FALSE, currentX, -1, (wxObject *) NULL, "Paste");
+ currentX += width + 5;
+ toolBar->AddTool(wxID_PRINT, toolBarBitmaps[6], wxNullBitmap, FALSE, currentX, -1, (wxObject *) NULL, "Delete this tool");
+ currentX += width + 5;
+ toolBar->AddSeparator();
+ toolBar->AddTool(wxID_HELP, toolBarBitmaps[7], wxNullBitmap, TRUE, currentX, -1, (wxObject *) NULL, "Help button");
+ }
- return TRUE;
+ // after adding the buttons to the toolbar, must call Realize() to reflect
+ // the changes
+ toolBar->Realize();
}
// ----------------------------------------------------------------------------
{
m_textWindow = new wxTextCtrl(this, -1, "", wxPoint(0, 0), wxSize(-1, -1), wxTE_MULTILINE);
m_smallToolbar = FALSE;
+ m_horzToolbar = FALSE;
// Give it a status line
CreateStatusBar();
// Make a menubar
wxMenu *tbarMenu = new wxMenu;
- tbarMenu->Append(IDM_TOOLBAR_TOGGLETOOLBAR, "&Toggle toolbar\tCtrl-T", "Change the toolbar kind");
+ tbarMenu->Append(IDM_TOOLBAR_TOGGLETOOLBARSIZE,
+ "&Toggle toolbar size\tCtrl-S",
+ "Toggle between big/small toolbar",
+ TRUE);
+ tbarMenu->Append(IDM_TOOLBAR_TOGGLETOOLBARORIENT,
+ "Toggle toolbar &orientation\tCtrl-O",
+ "Toggle toolbar orientation",
+ TRUE);
+
+ tbarMenu->AppendSeparator();
+
tbarMenu->Append(IDM_TOOLBAR_ENABLEPRINT, "&Enable print button\tCtrl-E", "");
tbarMenu->Append(IDM_TOOLBAR_DELETEPRINT, "&Delete print button\tCtrl-D", "");
tbarMenu->Append(IDM_TOOLBAR_INSERTPRINT, "&Insert print button\tCtrl-I", "");
SetMenuBar(menuBar);
// Create the toolbar
- wxToolBar *tbar = CreateToolBar(wxNO_BORDER | wxTB_HORIZONTAL |
- wxTB_FLAT | wxTB_DOCKABLE,
- ID_TOOLBAR);
+ RecreateToolbar();
+}
- tbar->SetMargins( 4, 4 );
+void MyFrame::OnToggleToolbarSize(wxCommandEvent& WXUNUSED(event))
+{
+ m_smallToolbar = !m_smallToolbar;
- wxGetApp().InitToolbar(tbar);
+ RecreateToolbar();
}
-void MyFrame::OnToggleToolbar(wxCommandEvent& WXUNUSED(event))
+void MyFrame::OnToggleToolbarOrient(wxCommandEvent& WXUNUSED(event))
{
- // delete and recreate the toolbar
- wxToolBar *tbar = GetToolBar();
- delete tbar;
-
- SetToolBar(NULL);
- tbar = CreateToolBar(wxNO_BORDER | wxTB_HORIZONTAL |
- wxTB_FLAT | wxTB_DOCKABLE,
- ID_TOOLBAR);
+ m_horzToolbar = !m_horzToolbar;
- m_smallToolbar = !m_smallToolbar;
- wxGetApp().InitToolbar(tbar, m_smallToolbar);
+ RecreateToolbar();
}
void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
tb->ToggleTool( wxID_HELP, !tb->GetToolState( wxID_HELP ) );
}
+void MyFrame::OnUpdateCopyAndCut(wxUpdateUIEvent& event)
+{
+ event.Enable( m_textWindow->CanCopy() );
+}
+
void MyFrame::OnInsertPrint(wxCommandEvent& WXUNUSED(event))
{
-#ifdef __WXMSW__
- wxBitmap bmp("icon7");
-#else
- wxBitmap bmp(print_xpm);
-#endif
+ wxBitmap bmp = wxBITMAP(print);
GetToolBar()->InsertTool(0, wxID_PRINT, bmp, wxNullBitmap,
- FALSE, (wxObject *) NULL, "Delete this tool");
+ FALSE, (wxObject *) NULL,
+ "Delete this tool",
+ "This button was inserted into the toolbar");
GetToolBar()->Realize();
}
mondrian ICON "mondrian.ico"
#include "wx/msw/wx.rc"
-icon1 BITMAP "bitmaps/new.bmp"
-icon2 BITMAP "bitmaps/open.bmp"
-icon3 BITMAP "bitmaps/save.bmp"
-icon4 BITMAP "bitmaps/copy.bmp"
-icon5 BITMAP "bitmaps/cut.bmp"
-icon6 BITMAP "bitmaps/paste.bmp"
-icon7 BITMAP "bitmaps/print.bmp"
-
-icon8 BITMAP "bitmaps/help.bmp"
+new BITMAP "bitmaps/new.bmp"
+open BITMAP "bitmaps/open.bmp"
+save BITMAP "bitmaps/save.bmp"
+copy BITMAP "bitmaps/copy.bmp"
+cut BITMAP "bitmaps/cut.bmp"
+paste BITMAP "bitmaps/paste.bmp"
+print BITMAP "bitmaps/print.bmp"
+help BITMAP "bitmaps/help.bmp"