]>
git.saurik.com Git - wxWidgets.git/blob - samples/toolbar/test.cpp
80aaeff9c1913ab6a770b0a2bede2c588adc833b
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(TEST_QUIT
, "E&xit");
54 wxMenu
*helpMenu
= new wxMenu
;
55 helpMenu
->Append(TEST_ABOUT
, "&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 TestToolBar
* toolRibbon
= new TestToolBar(frame
, -1, wxPoint(0, 0), wxSize(100, 30),
67 wxNO_BORDER
|wxTB_FLAT
, wxVERTICAL
, 1);
68 toolRibbon
->SetMargins(5, 5);
70 // Tell the frame about it
71 frame
->SetToolBar(toolRibbon
);
73 // Force a resize, just in case.
74 frame
->OnSize(wxSizeEvent(wxSize(-1, -1), frame
->GetId()));
77 frame
->SetStatusText("Hello, wxWindows");
84 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
85 EVT_MENU(TEST_QUIT
, MyFrame::OnQuit
)
86 EVT_MENU(TEST_ABOUT
, MyFrame::OnAbout
)
87 EVT_MENU_HIGHLIGHT_ALL(MyFrame::OnMenuHighlight
)
88 EVT_CLOSE(MyFrame::OnCloseWindow
)
91 // Define my frame constructor
92 MyFrame::MyFrame(wxFrame
* parent
, wxWindowID id
, const wxString
& title
, const wxPoint
& pos
,
93 const wxSize
& size
, long style
):
94 wxFrame(parent
, id
, title
, pos
, size
, style
)
96 m_textWindow
= new wxTextCtrl(this, -1, "", wxPoint(0, 0), wxSize(-1, -1), wxTE_MULTILINE
);
99 void MyFrame::OnQuit(wxCommandEvent
& event
)
104 void MyFrame::OnAbout(wxCommandEvent
& event
)
106 (void)wxMessageBox("wxWindows wxToolBar demo\n", "About wxToolBar");
109 // Intercept menu item selection - only has an effect in Windows
110 void MyFrame::OnMenuHighlight(wxMenuEvent
& event
)
113 switch (event
.GetMenuId())
116 msg
= "Quit program";
126 // Define the behaviour for the frame closing
127 // - must delete all frames except for the main one.
128 void MyFrame::OnCloseWindow(wxCloseEvent
& event
)
133 BEGIN_EVENT_TABLE(TestToolBar
, wxToolBar95
)
134 EVT_PAINT(TestToolBar::OnPaint
)
137 TestToolBar::TestToolBar(wxFrame
* parent
, wxWindowID id
, const wxPoint
& pos
, const wxSize
& size
,
138 long style
, int direction
, int RowsOrColumns
):
139 wxToolBar(parent
, id
, pos
, size
, style
, direction
, RowsOrColumns
)
142 wxBitmap
* toolBarBitmaps
[8];
145 toolBarBitmaps
[0] = new wxBitmap("icon1");
146 toolBarBitmaps
[1] = new wxBitmap("icon2");
147 toolBarBitmaps
[2] = new wxBitmap("icon3");
148 toolBarBitmaps
[3] = new wxBitmap("icon4");
149 toolBarBitmaps
[4] = new wxBitmap("icon5");
150 toolBarBitmaps
[5] = new wxBitmap("icon6");
151 toolBarBitmaps
[6] = new wxBitmap("icon7");
152 toolBarBitmaps
[7] = new wxBitmap("icon8");
156 toolBarBitmaps
[0] = new wxBitmap(...);
157 toolBarBitmaps
[1] = new wxBitmap(...);
158 toolBarBitmaps
[2] = new wxBitmap(...);
159 toolBarBitmaps
[3] = new wxBitmap(...);
160 toolBarBitmaps
[4] = new wxBitmap(...);
161 toolBarBitmaps
[5] = new wxBitmap(...);
162 toolBarBitmaps
[6] = new wxBitmap(...);
163 toolBarBitmaps
[7] = new wxBitmap(...);
175 AddTool(0, *(toolBarBitmaps
[0]), wxNullBitmap
, FALSE
, (float)currentX
, -1, NULL
, "New file");
176 currentX
+= width
+ 5;
177 AddTool(1, *(toolBarBitmaps
[1]), wxNullBitmap
, FALSE
, (float)currentX
, -1, NULL
, "Open file");
178 currentX
+= width
+ 5;
179 AddTool(2, *(toolBarBitmaps
[2]), wxNullBitmap
, FALSE
, (float)currentX
, -1, NULL
, "Save file");
180 currentX
+= width
+ 5;
182 AddTool(3, *(toolBarBitmaps
[3]), wxNullBitmap
, FALSE
, (float)currentX
, -1, NULL
, "Copy");
183 currentX
+= width
+ 5;
184 AddTool(4, *(toolBarBitmaps
[4]), wxNullBitmap
, FALSE
, (float)currentX
, -1, NULL
, "Cut");
185 currentX
+= width
+ 5;
186 AddTool(5, *(toolBarBitmaps
[5]), wxNullBitmap
, FALSE
, (float)currentX
, -1, NULL
, "Paste");
187 currentX
+= width
+ 5;
189 AddTool(6, *(toolBarBitmaps
[6]), wxNullBitmap
, FALSE
, (float)currentX
, -1, NULL
, "Print");
190 currentX
+= width
+ 5;
192 AddTool(7, *(toolBarBitmaps
[7]), wxNullBitmap
, TRUE
, currentX
, -1, NULL
, "Help");
196 // Can delete the bitmaps since they're reference counted
198 for (i
= 0; i
< 8; i
++)
199 delete toolBarBitmaps
[i
];
202 bool TestToolBar::OnLeftClick(int toolIndex
, bool toggled
)
205 sprintf(buf
, "Clicked on tool %d", toolIndex
);
206 ((wxFrame
*) GetParent())->SetStatusText(buf
);
210 void TestToolBar::OnMouseEnter(int toolIndex
)
215 sprintf(buf
, "This is tool number %d", toolIndex
);
216 ((wxFrame
*)GetParent())->SetStatusText(buf
);
218 else ((wxFrame
*)GetParent())->SetStatusText("");
221 void TestToolBar::OnPaint(wxPaintEvent
& event
)
223 wxToolBar::OnPaint(event
);
229 dc
.SetPen(wxBLACK_PEN
);
230 dc
.SetBrush(wxTRANSPARENT_BRUSH
);
231 dc
.DrawLine(0, h
-1, w
, h
-1);