added support for vertical toolbars for MSW - seems to work more or less

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@4936 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin 1999-12-14 02:02:09 +00:00
parent d9c8e68e58
commit 5ef2e6333e
6 changed files with 254 additions and 182 deletions

View File

@ -168,7 +168,7 @@ Adds a separator for spacing groups of tools.
\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 = ""}}
@ -177,7 +177,7 @@ Adds a tool to the toolbar.
\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
@ -198,11 +198,10 @@ as a pressed button (GTK). }
\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}
@ -212,45 +211,43 @@ order to have the tools appear.
\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.
Note that it is unnecessary to call \helpref{Realize}{wxtoolbarrealize} for the
change to take place, it will happen immediately.
Returns TRUE if the tool was deleted, FALSE otherwise.
\wxheading{See also}
\helpref{wxToolBar::AddTool}{wxtoolbaraddtool}, \helpref{wxToolBar::Realize}{wxtoolbarrealize}
\helpref{DeleteToolByPos}{wxtoolbardeletetoolbypos}
\membersection{wxToolBar::DrawTool}\label{wxtoolbardrawtool}
\membersection{wxToolBar::DeleteToolByPos}\label{wxtoolbardeletetoolbypos}
\func{void}{DrawTool}{\param{wxMemoryDC\& }{memDC}, \param{wxToolBarTool* }{tool}}
\func{bool}{DeleteToolByPos}{\param{size\_t }{pos}}
Draws the specified tool onto the window using the given memory device context.
\wxheading{Parameters}
\docparam{memDC}{A memory DC to be used for drawing the tool.}
\docparam{tool}{Tool to be drawn.}
\wxheading{Remarks}
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.}
@ -262,7 +259,6 @@ will change the visible state of the tool to indicate that it is disabled.
\wxheading{See also}
\helpref{wxToolBar::GetToolEnabled}{wxtoolbargettoolenabled},\rtfsp
%\helpref{wxToolBar::SetToolState}{wxtoolbarsettoolstate},\rtfsp
\helpref{wxToolBar::ToggleTool}{wxtoolbartoggletool}
\membersection{wxToolBar::FindToolForPosition}\label{wxtoolbarfindtoolforposition}
@ -323,22 +319,15 @@ Returns the left/right and top/bottom margins, which are also used for inter-too
\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}
@ -346,31 +335,31 @@ Client data, or NULL if there is none.
\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}
@ -399,7 +388,7 @@ Returns the default separator size.
\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.
@ -407,7 +396,7 @@ 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}
@ -416,41 +405,69 @@ Returns the long help for the given tool.
\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}
\func{void}{Layout}{\void}
\helpref{wxToolBar::ToggleTool}{wxtoolbartoggletool}
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.
\membersection{wxToolBar::InsertControl}\label{wxtoolbarinsertcontrol}
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.
\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.
\wxheading{See also}
\helpref{wxToolBar::AddTool}{wxtoolbaraddtool}, \helpref{wxToolBar::Realize}{wxtoolbarrealize}
\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}
\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.
You must call \helpref{Realize}{wxtoolbarrealize} for the change to take place.
\wxheading{See also}
\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.
@ -459,7 +476,7 @@ you should use the EVT\_MENU or EVT\_TOOL macro instead.
\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.}
@ -476,7 +493,7 @@ specifying that toggle operations are not permitted in some circumstances.
\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.
@ -486,7 +503,7 @@ you should use the EVT\_TOOL\_ENTER macro instead.
\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.}
@ -498,7 +515,7 @@ detect it. Therefore this function may not always be called when expected.
\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.
@ -508,7 +525,7 @@ you should use the EVT\_TOOL\_RCLICKED macro instead.
\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.}
@ -535,6 +552,20 @@ either \helpref{wxToolBar::CreateTools}{wxtoolbarcreatetools} or
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}}
@ -585,13 +616,13 @@ default (zero-size) margins are to be overridden.
\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.}
@ -625,13 +656,13 @@ and for spacing in the horizontal direction if the toolbar is vertical.
\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.}
@ -659,13 +690,13 @@ Sets the default separator size. The default value is 5.
\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.}

View File

@ -93,3 +93,24 @@ documents without much work. In fact, only few function calls are sufficient.
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}

View File

@ -610,6 +610,11 @@ MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h )
(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));

View File

@ -1,5 +1,5 @@
/* XPM */
static char *preview_xpm[] = {
static char *paste_xpm[] = {
/* columns rows colors chars-per-pixel */
"16 15 5 1",
" c Black",

View File

@ -42,9 +42,8 @@
#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
@ -53,11 +52,10 @@
// ----------------------------------------------------------------------------
// 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
@ -71,10 +69,14 @@ public:
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);
@ -85,12 +87,15 @@ public:
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()
@ -104,7 +109,8 @@ const int ID_TOOLBAR = 500;
enum
{
IDM_TOOLBAR_TOGGLETOOLBAR = 200,
IDM_TOOLBAR_TOGGLETOOLBARSIZE = 200,
IDM_TOOLBAR_TOGGLETOOLBARORIENT,
IDM_TOOLBAR_ENABLEPRINT,
IDM_TOOLBAR_DELETEPRINT,
IDM_TOOLBAR_INSERTPRINT,
@ -124,7 +130,9 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame)
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)
@ -135,6 +143,9 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame)
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()
// ============================================================================
@ -173,81 +184,79 @@ bool MyApp::OnInit()
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;
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__
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");
}
int width = 24;
#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 );
}
int width = 16;
#endif
#ifdef __WXMSW__
int width = 24;
#else
int width = 16;
#endif
int currentX = 5;
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");
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);
// 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);
}
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");
}
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");
}
toolBar->Realize();
// 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];
return TRUE;
// after adding the buttons to the toolbar, must call Realize() to reflect
// the changes
toolBar->Realize();
}
// ----------------------------------------------------------------------------
@ -265,6 +274,7 @@ MyFrame::MyFrame(wxFrame* parent,
{
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();
@ -274,7 +284,17 @@ MyFrame::MyFrame(wxFrame* parent,
// 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", "");
@ -296,28 +316,21 @@ MyFrame::MyFrame(wxFrame* parent,
SetMenuBar(menuBar);
// Create the toolbar
wxToolBar *tbar = CreateToolBar(wxNO_BORDER | wxTB_HORIZONTAL |
wxTB_FLAT | wxTB_DOCKABLE,
ID_TOOLBAR);
tbar->SetMargins( 4, 4 );
wxGetApp().InitToolbar(tbar);
RecreateToolbar();
}
void MyFrame::OnToggleToolbar(wxCommandEvent& WXUNUSED(event))
void MyFrame::OnToggleToolbarSize(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_smallToolbar = !m_smallToolbar;
wxGetApp().InitToolbar(tbar, m_smallToolbar);
RecreateToolbar();
}
void MyFrame::OnToggleToolbarOrient(wxCommandEvent& WXUNUSED(event))
{
m_horzToolbar = !m_horzToolbar;
RecreateToolbar();
}
void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
@ -387,16 +400,19 @@ void MyFrame::DoToggleHelp()
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();
}

View File

@ -1,13 +1,12 @@
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"