]>
git.saurik.com Git - wxWidgets.git/blob - samples/toolbar/test.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxToolBar sample
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx/wx.h".
13 #include "wx/wxprec.h"
23 #include "wx/toolbar.h"
29 // TODO: include XBM or XPM icons for X apps
32 // The `main program' equivalent, creating the windows and returning the
34 bool MyApp::OnInit(void)
36 // Create the main frame window
37 MyFrame
* frame
= new MyFrame(NULL
, -1, "wxToolBar Sample", wxPoint(100, 100), wxSize(450, 300));
39 // Give it a status line
40 frame
->CreateStatusBar();
44 frame
->SetIcon(wxIcon("mondrian"));
47 frame
->SetIcon(wxIcon("mondrian.xbm"));
51 wxMenu
*fileMenu
= new wxMenu
;
52 fileMenu
->Append(wxID_EXIT
, "E&xit");
54 wxMenu
*helpMenu
= new wxMenu
;
55 helpMenu
->Append(wxID_HELP
, "&About");
57 wxMenuBar
* menuBar
= new wxMenuBar
;
59 menuBar
->Append(fileMenu
, "&File");
60 menuBar
->Append(helpMenu
, "&Help");
62 // Associate the menu bar with the frame
63 frame
->SetMenuBar(menuBar
);
66 wxToolBar
* toolBar
= new wxToolBar(frame
, -1, wxPoint(0, 0), wxSize(100, 30),
67 wxNO_BORDER
|wxTB_FLAT
, wxVERTICAL
, 1);
68 toolBar
->SetMargins(5, 5);
72 // Tell the frame about it
73 frame
->SetToolBar(toolBar
);
75 // Force a resize. This should probably be replaced by a call to a wxFrame
76 // function that lays out default decorations and the remaining content window.
77 frame
->OnSize(wxSizeEvent(wxSize(-1, -1), frame
->GetId()));
80 frame
->SetStatusText("Hello, wxWindows");
87 bool MyApp::InitToolbar(wxToolBar
* toolBar
)
90 wxBitmap
* toolBarBitmaps
[8];
93 toolBarBitmaps
[0] = new wxBitmap("icon1");
94 toolBarBitmaps
[1] = new wxBitmap("icon2");
95 toolBarBitmaps
[2] = new wxBitmap("icon3");
96 toolBarBitmaps
[3] = new wxBitmap("icon4");
97 toolBarBitmaps
[4] = new wxBitmap("icon5");
98 toolBarBitmaps
[5] = new wxBitmap("icon6");
99 toolBarBitmaps
[6] = new wxBitmap("icon7");
100 toolBarBitmaps
[7] = new wxBitmap("icon8");
104 toolBarBitmaps
[0] = new wxBitmap(...);
105 toolBarBitmaps
[1] = new wxBitmap(...);
106 toolBarBitmaps
[2] = new wxBitmap(...);
107 toolBarBitmaps
[3] = new wxBitmap(...);
108 toolBarBitmaps
[4] = new wxBitmap(...);
109 toolBarBitmaps
[5] = new wxBitmap(...);
110 toolBarBitmaps
[6] = new wxBitmap(...);
111 toolBarBitmaps
[7] = new wxBitmap(...);
122 toolBar
->AddTool(wxID_NEW
, *(toolBarBitmaps
[0]), wxNullBitmap
, FALSE
, (float)currentX
, -1, NULL
, "New file");
123 currentX
+= width
+ 5;
124 toolBar
->AddTool(wxID_OPEN
, *(toolBarBitmaps
[1]), wxNullBitmap
, FALSE
, (float)currentX
, -1, NULL
, "Open file");
125 currentX
+= width
+ 5;
126 toolBar
->AddTool(wxID_SAVE
, *(toolBarBitmaps
[2]), wxNullBitmap
, FALSE
, (float)currentX
, -1, NULL
, "Save file");
127 currentX
+= width
+ 5;
128 toolBar
->AddSeparator();
129 toolBar
->AddTool(wxID_COPY
, *(toolBarBitmaps
[3]), wxNullBitmap
, FALSE
, (float)currentX
, -1, NULL
, "Copy");
130 currentX
+= width
+ 5;
131 toolBar
->AddTool(wxID_CUT
, *(toolBarBitmaps
[4]), wxNullBitmap
, FALSE
, (float)currentX
, -1, NULL
, "Cut");
132 currentX
+= width
+ 5;
133 toolBar
->AddTool(wxID_PASTE
, *(toolBarBitmaps
[5]), wxNullBitmap
, FALSE
, (float)currentX
, -1, NULL
, "Paste");
134 currentX
+= width
+ 5;
135 toolBar
->AddSeparator();
136 toolBar
->AddTool(wxID_PRINT
, *(toolBarBitmaps
[6]), wxNullBitmap
, FALSE
, (float)currentX
, -1, NULL
, "Print");
137 currentX
+= width
+ 5;
138 toolBar
->AddSeparator();
139 toolBar
->AddTool(wxID_HELP
, *(toolBarBitmaps
[7]), wxNullBitmap
, FALSE
, currentX
, -1, NULL
, "Help");
141 toolBar
->CreateTools();
143 // Can delete the bitmaps since they're reference counted
145 for (i
= 0; i
< 8; i
++)
146 delete toolBarBitmaps
[i
];
151 // wxID_HELP will be processed for the 'About' menu and the toolbar help button.
153 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
154 EVT_MENU(wxID_EXIT
, MyFrame::OnQuit
)
155 EVT_MENU(wxID_HELP
, MyFrame::OnAbout
)
156 EVT_CLOSE(MyFrame::OnCloseWindow
)
157 EVT_TOOL_RANGE(wxID_OPEN
, wxID_PASTE
, MyFrame::OnToolLeftClick
)
158 EVT_TOOL_ENTER_RANGE(wxID_OPEN
, wxID_PASTE
, MyFrame::OnToolEnter
)
161 // Define my frame constructor
162 MyFrame::MyFrame(wxFrame
* parent
, wxWindowID id
, const wxString
& title
, const wxPoint
& pos
,
163 const wxSize
& size
, long style
):
164 wxFrame(parent
, id
, title
, pos
, size
, style
)
166 m_textWindow
= new wxTextCtrl(this, -1, "", wxPoint(0, 0), wxSize(-1, -1), wxTE_MULTILINE
);
169 void MyFrame::OnQuit(wxCommandEvent
& event
)
174 void MyFrame::OnAbout(wxCommandEvent
& event
)
176 (void)wxMessageBox("wxWindows wxToolBar demo\n", "About wxToolBar");
179 // Define the behaviour for the frame closing
180 // - must delete all frames except for the main one.
181 void MyFrame::OnCloseWindow(wxCloseEvent
& event
)
186 void MyFrame::OnToolLeftClick(wxCommandEvent
& event
)
189 str
.Printf("Clicked on tool %d", event
.GetId());
193 void MyFrame::OnToolEnter(wxCommandEvent
& event
)
195 if (event
.GetId() > -1)
198 str
.Printf("This is tool number %d", event
.GetId());