1998-07-23 10:39:46 -04:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
1999-12-13 18:05:56 -05:00
|
|
|
// Name: toolbar.cpp
|
1998-07-23 10:39:46 -04:00
|
|
|
// Purpose: wxToolBar sample
|
|
|
|
// Author: Julian Smart
|
|
|
|
// Modified by:
|
|
|
|
// Created: 04/01/98
|
|
|
|
// RCS-ID: $Id$
|
|
|
|
// Copyright: (c) Julian Smart
|
1999-10-26 19:38:33 -04:00
|
|
|
// Licence: wxWindows licence
|
1998-07-23 10:39:46 -04:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
1999-10-26 19:38:33 -04:00
|
|
|
// ============================================================================
|
|
|
|
// declarations
|
|
|
|
// ============================================================================
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// headers
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
1998-07-23 10:39:46 -04:00
|
|
|
// For compilers that support precompilation, includes "wx/wx.h".
|
1999-10-26 19:38:33 -04:00
|
|
|
#include <wx/wxprec.h>
|
1998-07-23 10:39:46 -04:00
|
|
|
|
|
|
|
#ifdef __BORLANDC__
|
1999-10-26 19:38:33 -04:00
|
|
|
#pragma hdrstop
|
1998-07-23 10:39:46 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef WX_PRECOMP
|
1999-10-26 19:38:33 -04:00
|
|
|
#include <wx/wx.h>
|
1998-07-23 10:39:46 -04:00
|
|
|
#endif
|
|
|
|
|
1999-10-26 19:38:33 -04:00
|
|
|
#include <wx/toolbar.h>
|
1998-12-09 12:30:17 -05:00
|
|
|
#include <wx/log.h>
|
|
|
|
|
1999-12-15 13:02:44 -05:00
|
|
|
// define this to 1 to use wxToolBarSimple instead of the native one
|
1999-12-16 12:39:07 -05:00
|
|
|
#define USE_GENERIC_TBAR 0
|
1999-12-15 13:02:44 -05:00
|
|
|
|
|
|
|
#if USE_GENERIC_TBAR
|
|
|
|
#if !wxUSE_TOOLBAR_SIMPLE
|
1999-12-16 12:39:07 -05:00
|
|
|
#error wxToolBarSimple is not compiled in, set wxUSE_TOOLBAR_SIMPLE \
|
|
|
|
to 1 in setup.h and recompile the library.
|
1999-12-15 13:02:44 -05:00
|
|
|
#else
|
|
|
|
#include <wx/tbarsmpl.h>
|
|
|
|
#endif
|
|
|
|
#endif // USE_GENERIC_TBAR
|
|
|
|
|
1999-10-26 19:38:33 -04:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// resources
|
|
|
|
// ----------------------------------------------------------------------------
|
1998-07-23 10:39:46 -04:00
|
|
|
|
1998-10-18 18:31:48 -04:00
|
|
|
#if defined(__WXGTK__) || defined(__WXMOTIF__)
|
1999-10-26 19:38:33 -04:00
|
|
|
#include "mondrian.xpm"
|
|
|
|
#include "bitmaps/new.xpm"
|
|
|
|
#include "bitmaps/open.xpm"
|
|
|
|
#include "bitmaps/save.xpm"
|
|
|
|
#include "bitmaps/copy.xpm"
|
|
|
|
#include "bitmaps/cut.xpm"
|
1999-12-13 21:02:09 -05:00
|
|
|
#include "bitmaps/preview.xpm" // paste XPM
|
1999-10-26 19:38:33 -04:00
|
|
|
#include "bitmaps/print.xpm"
|
|
|
|
#include "bitmaps/help.xpm"
|
|
|
|
#endif // GTK or Motif
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// classes
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// Define a new application
|
1999-12-13 21:02:09 -05:00
|
|
|
class MyApp : public wxApp
|
1999-10-26 19:38:33 -04:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
bool OnInit();
|
|
|
|
};
|
1998-07-31 16:04:04 -04:00
|
|
|
|
1999-10-26 19:38:33 -04:00
|
|
|
// Define a new frame
|
|
|
|
class MyFrame: public wxFrame
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
MyFrame(wxFrame *parent,
|
|
|
|
wxWindowID id = -1,
|
|
|
|
const wxString& title = "wxToolBar Sample",
|
|
|
|
const wxPoint& pos = wxDefaultPosition,
|
|
|
|
const wxSize& size = wxDefaultSize,
|
|
|
|
long style = wxDEFAULT_FRAME_STYLE);
|
1998-07-23 10:39:46 -04:00
|
|
|
|
1999-12-13 21:02:09 -05:00
|
|
|
void RecreateToolbar();
|
|
|
|
|
1999-10-26 19:38:33 -04:00
|
|
|
void OnQuit(wxCommandEvent& event);
|
|
|
|
void OnAbout(wxCommandEvent& event);
|
|
|
|
|
1999-12-13 21:02:09 -05:00
|
|
|
void OnToggleToolbarSize(wxCommandEvent& event);
|
|
|
|
void OnToggleToolbarOrient(wxCommandEvent& event);
|
1999-12-14 20:54:39 -05:00
|
|
|
void OnToggleToolbarRows(wxCommandEvent& event);
|
1999-12-13 21:02:09 -05:00
|
|
|
|
1999-12-15 13:02:44 -05:00
|
|
|
void OnEnablePrint(wxCommandEvent& WXUNUSED(event)) { DoEnablePrint(); }
|
|
|
|
void OnDeletePrint(wxCommandEvent& WXUNUSED(event)) { DoDeletePrint(); }
|
1999-12-04 17:34:54 -05:00
|
|
|
void OnInsertPrint(wxCommandEvent& event);
|
1999-12-15 13:02:44 -05:00
|
|
|
void OnToggleHelp(wxCommandEvent& WXUNUSED(event)) { DoToggleHelp(); }
|
1999-10-26 19:38:33 -04:00
|
|
|
|
|
|
|
void OnToolLeftClick(wxCommandEvent& event);
|
|
|
|
void OnToolEnter(wxCommandEvent& event);
|
|
|
|
|
1999-11-11 21:17:44 -05:00
|
|
|
void OnCombo(wxCommandEvent& event);
|
|
|
|
|
1999-12-13 21:02:09 -05:00
|
|
|
void OnUpdateCopyAndCut(wxUpdateUIEvent& event);
|
|
|
|
|
1999-12-15 13:02:44 -05:00
|
|
|
#if USE_GENERIC_TBAR
|
|
|
|
virtual wxToolBar *OnCreateToolBar(long style,
|
|
|
|
wxWindowID id,
|
|
|
|
const wxString& name );
|
|
|
|
#endif // USE_GENERIC_TBAR
|
|
|
|
|
1999-10-26 19:38:33 -04:00
|
|
|
private:
|
|
|
|
void DoEnablePrint();
|
1999-11-18 10:58:35 -05:00
|
|
|
void DoDeletePrint();
|
1999-10-26 19:38:33 -04:00
|
|
|
void DoToggleHelp();
|
|
|
|
|
1999-12-13 21:02:09 -05:00
|
|
|
bool m_smallToolbar,
|
|
|
|
m_horzToolbar;
|
1999-12-14 20:54:39 -05:00
|
|
|
size_t m_rows; // 1 or 2 only
|
|
|
|
|
1999-10-26 19:38:33 -04:00
|
|
|
wxTextCtrl* m_textWindow;
|
|
|
|
|
|
|
|
DECLARE_EVENT_TABLE()
|
|
|
|
};
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// constants
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
const int ID_TOOLBAR = 500;
|
|
|
|
|
|
|
|
enum
|
1998-07-23 10:39:46 -04:00
|
|
|
{
|
1999-12-13 21:02:09 -05:00
|
|
|
IDM_TOOLBAR_TOGGLETOOLBARSIZE = 200,
|
|
|
|
IDM_TOOLBAR_TOGGLETOOLBARORIENT,
|
1999-12-14 20:54:39 -05:00
|
|
|
IDM_TOOLBAR_TOGGLETOOLBARROWS,
|
1999-10-26 19:38:33 -04:00
|
|
|
IDM_TOOLBAR_ENABLEPRINT,
|
1999-11-18 10:58:35 -05:00
|
|
|
IDM_TOOLBAR_DELETEPRINT,
|
1999-12-04 17:34:54 -05:00
|
|
|
IDM_TOOLBAR_INSERTPRINT,
|
1999-11-11 21:17:44 -05:00
|
|
|
IDM_TOOLBAR_TOGGLEHELP,
|
|
|
|
|
|
|
|
ID_COMBO = 1000
|
1999-10-26 19:38:33 -04:00
|
|
|
};
|
1998-07-23 10:39:46 -04:00
|
|
|
|
1999-10-26 19:38:33 -04:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// event tables
|
|
|
|
// ----------------------------------------------------------------------------
|
1998-07-23 10:39:46 -04:00
|
|
|
|
1999-10-26 19:38:33 -04:00
|
|
|
// Notice that wxID_HELP will be processed for the 'About' menu and the toolbar
|
|
|
|
// help button.
|
1998-07-23 10:39:46 -04:00
|
|
|
|
1999-10-26 19:38:33 -04:00
|
|
|
BEGIN_EVENT_TABLE(MyFrame, wxFrame)
|
|
|
|
EVT_MENU(wxID_EXIT, MyFrame::OnQuit)
|
|
|
|
EVT_MENU(wxID_HELP, MyFrame::OnAbout)
|
1998-07-23 10:39:46 -04:00
|
|
|
|
1999-12-13 21:02:09 -05:00
|
|
|
EVT_MENU(IDM_TOOLBAR_TOGGLETOOLBARSIZE, MyFrame::OnToggleToolbarSize)
|
|
|
|
EVT_MENU(IDM_TOOLBAR_TOGGLETOOLBARORIENT, MyFrame::OnToggleToolbarOrient)
|
1999-12-14 20:54:39 -05:00
|
|
|
EVT_MENU(IDM_TOOLBAR_TOGGLETOOLBARROWS, MyFrame::OnToggleToolbarRows)
|
1999-12-13 21:02:09 -05:00
|
|
|
|
1999-10-26 19:38:33 -04:00
|
|
|
EVT_MENU(IDM_TOOLBAR_ENABLEPRINT, MyFrame::OnEnablePrint)
|
1999-11-18 10:58:35 -05:00
|
|
|
EVT_MENU(IDM_TOOLBAR_DELETEPRINT, MyFrame::OnDeletePrint)
|
1999-12-04 17:34:54 -05:00
|
|
|
EVT_MENU(IDM_TOOLBAR_INSERTPRINT, MyFrame::OnInsertPrint)
|
1999-10-26 19:38:33 -04:00
|
|
|
EVT_MENU(IDM_TOOLBAR_TOGGLEHELP, MyFrame::OnToggleHelp)
|
1998-07-23 10:39:46 -04:00
|
|
|
|
1999-10-26 19:38:33 -04:00
|
|
|
EVT_MENU(-1, MyFrame::OnToolLeftClick)
|
1998-07-23 10:39:46 -04:00
|
|
|
|
1999-11-11 21:17:44 -05:00
|
|
|
EVT_COMBOBOX(ID_COMBO, MyFrame::OnCombo)
|
|
|
|
|
1999-10-26 19:38:33 -04:00
|
|
|
EVT_TOOL_ENTER(ID_TOOLBAR, MyFrame::OnToolEnter)
|
1999-12-13 21:02:09 -05:00
|
|
|
|
|
|
|
EVT_UPDATE_UI(wxID_COPY, MyFrame::OnUpdateCopyAndCut)
|
|
|
|
EVT_UPDATE_UI(wxID_CUT, MyFrame::OnUpdateCopyAndCut)
|
1999-10-26 19:38:33 -04:00
|
|
|
END_EVENT_TABLE()
|
1998-07-23 10:39:46 -04:00
|
|
|
|
1999-10-26 19:38:33 -04:00
|
|
|
// ============================================================================
|
|
|
|
// implementation
|
|
|
|
// ============================================================================
|
1998-07-23 10:39:46 -04:00
|
|
|
|
1999-10-26 19:38:33 -04:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// MyApp
|
|
|
|
// ----------------------------------------------------------------------------
|
1998-07-23 10:39:46 -04:00
|
|
|
|
1999-10-26 19:38:33 -04:00
|
|
|
IMPLEMENT_APP(MyApp)
|
1998-07-23 10:39:46 -04:00
|
|
|
|
1999-10-26 19:38:33 -04:00
|
|
|
// The `main program' equivalent, creating the windows and returning the
|
|
|
|
// main frame
|
|
|
|
bool MyApp::OnInit()
|
|
|
|
{
|
|
|
|
// Create the main frame window
|
|
|
|
MyFrame* frame = new MyFrame((wxFrame *) NULL, -1,
|
|
|
|
"wxToolBar Sample",
|
|
|
|
wxPoint(100, 100), wxSize(450, 300));
|
1998-07-23 10:39:46 -04:00
|
|
|
|
1999-09-15 12:15:50 -04:00
|
|
|
frame->Show(TRUE);
|
|
|
|
|
|
|
|
frame->SetStatusText("Hello, wxWindows");
|
|
|
|
|
|
|
|
SetTopWindow(frame);
|
|
|
|
|
|
|
|
return TRUE;
|
1998-07-23 10:39:46 -04:00
|
|
|
}
|
|
|
|
|
1999-12-13 21:02:09 -05:00
|
|
|
void MyFrame::RecreateToolbar()
|
1998-07-23 10:39:46 -04:00
|
|
|
{
|
1999-12-13 21:02:09 -05:00
|
|
|
// delete and recreate the toolbar
|
1999-12-15 13:02:44 -05:00
|
|
|
wxToolBarBase *toolBar = GetToolBar();
|
1999-12-13 21:02:09 -05:00
|
|
|
delete toolBar;
|
1998-07-23 10:39:46 -04:00
|
|
|
|
1999-12-13 21:02:09 -05:00
|
|
|
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);
|
|
|
|
}
|
1998-07-23 10:39:46 -04:00
|
|
|
|
|
|
|
#ifdef __WXMSW__
|
1999-12-13 21:02:09 -05:00
|
|
|
int width = 24;
|
1998-07-23 10:39:46 -04:00
|
|
|
#else
|
1999-12-13 21:02:09 -05:00
|
|
|
int width = 16;
|
1998-07-23 10:39:46 -04:00
|
|
|
#endif
|
1999-11-11 22:12:51 -05:00
|
|
|
|
1999-12-13 21:02:09 -05:00
|
|
|
int currentX = 5;
|
1999-09-15 12:15:50 -04:00
|
|
|
|
1999-12-13 21:02:09 -05:00
|
|
|
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");
|
1998-07-23 10:39:46 -04:00
|
|
|
|
1999-12-15 13:02:44 -05:00
|
|
|
// neither the generic nor Motif native toolbars really support this
|
|
|
|
#if (wxUSE_TOOLBAR_NATIVE && !USE_GENERIC_TBAR) && !defined(__WXMOTIF__)
|
1999-12-13 21:02:09 -05:00
|
|
|
// 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);
|
|
|
|
}
|
1999-12-15 13:02:44 -05:00
|
|
|
#endif // toolbars which don't support controls
|
1998-07-23 10:39:46 -04:00
|
|
|
|
1999-12-13 21:02:09 -05:00
|
|
|
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");
|
|
|
|
}
|
1998-07-24 11:43:03 -04:00
|
|
|
|
1999-12-13 21:02:09 -05:00
|
|
|
// after adding the buttons to the toolbar, must call Realize() to reflect
|
|
|
|
// the changes
|
|
|
|
toolBar->Realize();
|
1999-12-14 20:54:39 -05:00
|
|
|
|
|
|
|
toolBar->SetRows(m_horzToolbar ? m_rows : 10 / m_rows);
|
1998-07-23 10:39:46 -04:00
|
|
|
}
|
|
|
|
|
1999-10-26 19:38:33 -04:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// MyFrame
|
|
|
|
// ----------------------------------------------------------------------------
|
1998-07-24 11:43:03 -04:00
|
|
|
|
|
|
|
// Define my frame constructor
|
1999-09-15 12:15:50 -04:00
|
|
|
MyFrame::MyFrame(wxFrame* parent,
|
|
|
|
wxWindowID id,
|
|
|
|
const wxString& title,
|
|
|
|
const wxPoint& pos,
|
|
|
|
const wxSize& size,
|
|
|
|
long style)
|
|
|
|
: wxFrame(parent, id, title, pos, size, style)
|
1998-07-23 10:39:46 -04:00
|
|
|
{
|
1999-07-25 08:59:58 -04:00
|
|
|
m_textWindow = new wxTextCtrl(this, -1, "", wxPoint(0, 0), wxSize(-1, -1), wxTE_MULTILINE);
|
1999-12-14 20:54:39 -05:00
|
|
|
|
1999-09-15 12:15:50 -04:00
|
|
|
m_smallToolbar = FALSE;
|
1999-12-14 20:54:39 -05:00
|
|
|
m_horzToolbar = TRUE;
|
|
|
|
m_rows = 1;
|
1999-10-26 19:38:33 -04:00
|
|
|
|
|
|
|
// Give it a status line
|
|
|
|
CreateStatusBar();
|
|
|
|
|
|
|
|
// Give it an icon
|
|
|
|
SetIcon(wxICON(mondrian));
|
|
|
|
|
|
|
|
// Make a menubar
|
|
|
|
wxMenu *tbarMenu = new wxMenu;
|
1999-12-13 21:02:09 -05:00
|
|
|
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);
|
1999-12-14 20:54:39 -05:00
|
|
|
tbarMenu->Append(IDM_TOOLBAR_TOGGLETOOLBARROWS,
|
|
|
|
"Toggle number of &rows\tCtrl-R",
|
|
|
|
"Toggle number of toolbar rows between 1 and 2",
|
|
|
|
TRUE);
|
1999-12-13 21:02:09 -05:00
|
|
|
|
|
|
|
tbarMenu->AppendSeparator();
|
|
|
|
|
1999-12-13 18:05:56 -05:00
|
|
|
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", "");
|
|
|
|
tbarMenu->Append(IDM_TOOLBAR_TOGGLEHELP, "Toggle &help button\tCtrl-T", "");
|
1999-10-26 19:38:33 -04:00
|
|
|
|
|
|
|
wxMenu *fileMenu = new wxMenu;
|
|
|
|
fileMenu->Append(wxID_EXIT, "E&xit", "Quit toolbar sample" );
|
|
|
|
|
|
|
|
wxMenu *helpMenu = new wxMenu;
|
|
|
|
helpMenu->Append(wxID_HELP, "&About", "About toolbar sample");
|
|
|
|
|
|
|
|
wxMenuBar* menuBar = new wxMenuBar( wxMB_DOCKABLE );
|
|
|
|
|
|
|
|
menuBar->Append(fileMenu, "&File");
|
|
|
|
menuBar->Append(tbarMenu, "&Toolbar");
|
|
|
|
menuBar->Append(helpMenu, "&Help");
|
|
|
|
|
|
|
|
// Associate the menu bar with the frame
|
|
|
|
SetMenuBar(menuBar);
|
|
|
|
|
|
|
|
// Create the toolbar
|
1999-12-13 21:02:09 -05:00
|
|
|
RecreateToolbar();
|
|
|
|
}
|
1999-10-26 19:38:33 -04:00
|
|
|
|
1999-12-15 13:02:44 -05:00
|
|
|
#if USE_GENERIC_TBAR
|
|
|
|
|
|
|
|
wxToolBar* MyFrame::OnCreateToolBar(long style,
|
|
|
|
wxWindowID id,
|
|
|
|
const wxString& name)
|
|
|
|
{
|
|
|
|
return (wxToolBar *)new wxToolBarSimple(this, id,
|
|
|
|
wxDefaultPosition, wxDefaultSize,
|
|
|
|
style, name);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // USE_GENERIC_TBAR
|
|
|
|
|
1999-12-13 21:02:09 -05:00
|
|
|
void MyFrame::OnToggleToolbarSize(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
|
|
|
m_smallToolbar = !m_smallToolbar;
|
1999-10-26 19:38:33 -04:00
|
|
|
|
1999-12-13 21:02:09 -05:00
|
|
|
RecreateToolbar();
|
1999-09-15 12:15:50 -04:00
|
|
|
}
|
|
|
|
|
1999-12-14 20:54:39 -05:00
|
|
|
void MyFrame::OnToggleToolbarRows(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
|
|
|
// m_rows may be only 1 or 2
|
|
|
|
m_rows = 3 - m_rows;
|
|
|
|
|
|
|
|
GetToolBar()->SetRows(m_horzToolbar ? m_rows : 10 / m_rows);
|
|
|
|
|
1999-12-16 12:39:07 -05:00
|
|
|
//RecreateToolbar(); -- this is unneeded
|
1999-12-14 20:54:39 -05:00
|
|
|
}
|
|
|
|
|
1999-12-13 21:02:09 -05:00
|
|
|
void MyFrame::OnToggleToolbarOrient(wxCommandEvent& WXUNUSED(event))
|
1999-09-15 12:15:50 -04:00
|
|
|
{
|
1999-12-13 21:02:09 -05:00
|
|
|
m_horzToolbar = !m_horzToolbar;
|
1999-09-15 12:15:50 -04:00
|
|
|
|
1999-12-13 21:02:09 -05:00
|
|
|
RecreateToolbar();
|
1998-07-23 10:39:46 -04:00
|
|
|
}
|
|
|
|
|
1998-07-31 16:04:04 -04:00
|
|
|
void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
|
1998-07-23 10:39:46 -04:00
|
|
|
{
|
1998-07-24 11:43:03 -04:00
|
|
|
Close(TRUE);
|
1998-07-23 10:39:46 -04:00
|
|
|
}
|
|
|
|
|
1998-07-31 16:04:04 -04:00
|
|
|
void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
|
1998-07-23 10:39:46 -04:00
|
|
|
{
|
1999-01-12 18:51:13 -05:00
|
|
|
(void)wxMessageBox("wxWindows toolbar sample", "About wxToolBar");
|
1998-07-24 11:43:03 -04:00
|
|
|
}
|
1998-07-23 10:39:46 -04:00
|
|
|
|
1998-07-24 11:43:03 -04:00
|
|
|
void MyFrame::OnToolLeftClick(wxCommandEvent& event)
|
|
|
|
{
|
1999-07-25 08:59:58 -04:00
|
|
|
wxString str;
|
|
|
|
str.Printf( _T("Clicked on tool %d\n"), event.GetId());
|
|
|
|
m_textWindow->WriteText( str );
|
1999-10-26 19:38:33 -04:00
|
|
|
|
1999-07-25 08:59:58 -04:00
|
|
|
if (event.GetId() == wxID_HELP)
|
|
|
|
{
|
1999-10-26 19:38:33 -04:00
|
|
|
if ( event.GetExtraLong() != 0 )
|
1999-07-25 08:59:58 -04:00
|
|
|
m_textWindow->WriteText( _T("Help button down now.\n") );
|
|
|
|
else
|
|
|
|
m_textWindow->WriteText( _T("Help button up now.\n") );
|
|
|
|
}
|
1999-10-26 19:38:33 -04:00
|
|
|
|
1999-07-25 08:59:58 -04:00
|
|
|
if (event.GetId() == wxID_COPY)
|
|
|
|
{
|
1999-09-15 12:15:50 -04:00
|
|
|
DoEnablePrint();
|
1999-07-25 08:59:58 -04:00
|
|
|
}
|
1999-10-26 19:38:33 -04:00
|
|
|
|
1999-07-25 08:59:58 -04:00
|
|
|
if (event.GetId() == wxID_CUT)
|
|
|
|
{
|
1999-09-15 12:15:50 -04:00
|
|
|
DoToggleHelp();
|
1999-07-25 08:59:58 -04:00
|
|
|
}
|
1999-12-01 10:23:56 -05:00
|
|
|
|
1999-11-18 10:58:35 -05:00
|
|
|
if (event.GetId() == wxID_PRINT)
|
|
|
|
{
|
|
|
|
DoDeletePrint();
|
|
|
|
}
|
1998-07-23 10:39:46 -04:00
|
|
|
}
|
|
|
|
|
1999-11-11 21:17:44 -05:00
|
|
|
void MyFrame::OnCombo(wxCommandEvent& event)
|
|
|
|
{
|
|
|
|
wxLogStatus(_T("Combobox string '%s' selected"), event.GetString().c_str());
|
|
|
|
}
|
|
|
|
|
1999-09-15 12:15:50 -04:00
|
|
|
void MyFrame::DoEnablePrint()
|
|
|
|
{
|
1999-12-15 13:02:44 -05:00
|
|
|
wxToolBarBase *tb = GetToolBar();
|
1999-09-15 12:15:50 -04:00
|
|
|
if (tb->GetToolEnabled(wxID_PRINT))
|
|
|
|
tb->EnableTool( wxID_PRINT, FALSE );
|
|
|
|
else
|
|
|
|
tb->EnableTool( wxID_PRINT, TRUE );
|
|
|
|
}
|
|
|
|
|
1999-11-18 10:58:35 -05:00
|
|
|
void MyFrame::DoDeletePrint()
|
|
|
|
{
|
1999-12-15 13:02:44 -05:00
|
|
|
wxToolBarBase *tb = GetToolBar();
|
1999-12-01 10:23:56 -05:00
|
|
|
|
1999-11-18 10:58:35 -05:00
|
|
|
tb->DeleteTool( wxID_PRINT );
|
|
|
|
}
|
|
|
|
|
1999-09-15 12:15:50 -04:00
|
|
|
void MyFrame::DoToggleHelp()
|
|
|
|
{
|
1999-12-15 13:02:44 -05:00
|
|
|
wxToolBarBase *tb = GetToolBar();
|
1999-09-15 12:15:50 -04:00
|
|
|
tb->ToggleTool( wxID_HELP, !tb->GetToolState( wxID_HELP ) );
|
|
|
|
}
|
|
|
|
|
1999-12-13 21:02:09 -05:00
|
|
|
void MyFrame::OnUpdateCopyAndCut(wxUpdateUIEvent& event)
|
|
|
|
{
|
|
|
|
event.Enable( m_textWindow->CanCopy() );
|
|
|
|
}
|
|
|
|
|
1999-12-04 17:34:54 -05:00
|
|
|
void MyFrame::OnInsertPrint(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
1999-12-13 21:02:09 -05:00
|
|
|
wxBitmap bmp = wxBITMAP(print);
|
1999-12-04 17:34:54 -05:00
|
|
|
|
1999-12-13 18:05:56 -05:00
|
|
|
GetToolBar()->InsertTool(0, wxID_PRINT, bmp, wxNullBitmap,
|
1999-12-13 21:02:09 -05:00
|
|
|
FALSE, (wxObject *) NULL,
|
|
|
|
"Delete this tool",
|
|
|
|
"This button was inserted into the toolbar");
|
1999-12-04 17:34:54 -05:00
|
|
|
|
|
|
|
GetToolBar()->Realize();
|
|
|
|
}
|
|
|
|
|
1998-07-24 11:43:03 -04:00
|
|
|
void MyFrame::OnToolEnter(wxCommandEvent& event)
|
|
|
|
{
|
1999-12-15 13:02:44 -05:00
|
|
|
if (event.GetSelection() > -1)
|
|
|
|
{
|
|
|
|
wxString str;
|
|
|
|
str.Printf(_T("This is tool number %d"), event.GetSelection());
|
|
|
|
SetStatusText(str);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
SetStatusText("");
|
1998-07-24 11:43:03 -04:00
|
|
|
}
|
1998-07-23 10:39:46 -04:00
|
|
|
|