]>
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",
38 wxPoint(100, 100), wxSize(450, 300));
40 // Give it a status line
41 frame
->CreateStatusBar();
45 frame
->SetIcon(wxIcon("mondrian"));
48 frame
->SetIcon(wxIcon("mondrian.xbm"));
52 wxMenu
*fileMenu
= new wxMenu
;
53 fileMenu
->Append(wxID_EXIT
, "E&xit");
55 wxMenu
*helpMenu
= new wxMenu
;
56 helpMenu
->Append(wxID_HELP
, "&About");
58 wxMenuBar
* menuBar
= new wxMenuBar
;
60 menuBar
->Append(fileMenu
, "&File");
61 menuBar
->Append(helpMenu
, "&Help");
63 // Associate the menu bar with the frame
64 frame
->SetMenuBar(menuBar
);
67 frame
->CreateToolBar(wxNO_BORDER
|wxHORIZONTAL
|wxTB_FLAT
, ID_TOOLBAR
);
69 InitToolbar(frame
->GetToolBar());
71 // Force a resize. This should probably be replaced by a call to a wxFrame
72 // function that lays out default decorations and the remaining content window.
73 frame
->OnSize(wxSizeEvent(wxSize(-1, -1), frame
->GetId()));
76 frame
->SetStatusText("Hello, wxWindows");
83 bool MyApp::InitToolbar(wxToolBar
* toolBar
)
85 toolBar
->SetMargins(5, 5);
88 wxBitmap
* toolBarBitmaps
[8];
91 toolBarBitmaps
[0] = new wxBitmap("icon1");
92 toolBarBitmaps
[1] = new wxBitmap("icon2");
93 toolBarBitmaps
[2] = new wxBitmap("icon3");
94 toolBarBitmaps
[3] = new wxBitmap("icon4");
95 toolBarBitmaps
[4] = new wxBitmap("icon5");
96 toolBarBitmaps
[5] = new wxBitmap("icon6");
97 toolBarBitmaps
[6] = new wxBitmap("icon7");
98 toolBarBitmaps
[7] = new wxBitmap("icon8");
102 toolBarBitmaps
[0] = new wxBitmap(...);
103 toolBarBitmaps
[1] = new wxBitmap(...);
104 toolBarBitmaps
[2] = new wxBitmap(...);
105 toolBarBitmaps
[3] = new wxBitmap(...);
106 toolBarBitmaps
[4] = new wxBitmap(...);
107 toolBarBitmaps
[5] = new wxBitmap(...);
108 toolBarBitmaps
[6] = new wxBitmap(...);
109 toolBarBitmaps
[7] = new wxBitmap(...);
120 toolBar
->AddTool(wxID_NEW
, *(toolBarBitmaps
[0]), wxNullBitmap
, FALSE
, (float)currentX
, -1, NULL
, "New file");
121 currentX
+= width
+ 5;
122 toolBar
->AddTool(wxID_OPEN
, *(toolBarBitmaps
[1]), wxNullBitmap
, FALSE
, (float)currentX
, -1, NULL
, "Open file");
123 currentX
+= width
+ 5;
124 toolBar
->AddTool(wxID_SAVE
, *(toolBarBitmaps
[2]), wxNullBitmap
, FALSE
, (float)currentX
, -1, NULL
, "Save file");
125 currentX
+= width
+ 5;
126 toolBar
->AddSeparator();
127 toolBar
->AddTool(wxID_COPY
, *(toolBarBitmaps
[3]), wxNullBitmap
, FALSE
, (float)currentX
, -1, NULL
, "Copy");
128 currentX
+= width
+ 5;
129 toolBar
->AddTool(wxID_CUT
, *(toolBarBitmaps
[4]), wxNullBitmap
, FALSE
, (float)currentX
, -1, NULL
, "Cut");
130 currentX
+= width
+ 5;
131 toolBar
->AddTool(wxID_PASTE
, *(toolBarBitmaps
[5]), wxNullBitmap
, FALSE
, (float)currentX
, -1, NULL
, "Paste");
132 currentX
+= width
+ 5;
133 toolBar
->AddSeparator();
134 toolBar
->AddTool(wxID_PRINT
, *(toolBarBitmaps
[6]), wxNullBitmap
, FALSE
, (float)currentX
, -1, NULL
, "Print");
135 currentX
+= width
+ 5;
136 toolBar
->AddSeparator();
137 toolBar
->AddTool(wxID_HELP
, *(toolBarBitmaps
[7]), wxNullBitmap
, FALSE
, currentX
, -1, NULL
, "Help");
141 // Can delete the bitmaps since they're reference counted
143 for (i
= 0; i
< 8; i
++)
144 delete toolBarBitmaps
[i
];
149 // wxID_HELP will be processed for the 'About' menu and the toolbar help button.
151 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
152 EVT_MENU(wxID_EXIT
, MyFrame::OnQuit
)
153 EVT_MENU(wxID_HELP
, MyFrame::OnAbout
)
154 EVT_CLOSE(MyFrame::OnCloseWindow
)
155 EVT_TOOL_RANGE(wxID_OPEN
, wxID_PASTE
, MyFrame::OnToolLeftClick
)
156 EVT_TOOL_ENTER(ID_TOOLBAR
, MyFrame::OnToolEnter
)
159 // Define my frame constructor
160 MyFrame::MyFrame(wxFrame
* parent
, wxWindowID id
, const wxString
& title
, const wxPoint
& pos
,
161 const wxSize
& size
, long style
):
162 wxFrame(parent
, id
, title
, pos
, size
, style
)
164 m_textWindow
= new wxTextCtrl(this, -1, "", wxPoint(0, 0), wxSize(-1, -1), wxTE_MULTILINE
);
167 void MyFrame::OnQuit(wxCommandEvent
& event
)
172 void MyFrame::OnAbout(wxCommandEvent
& event
)
174 (void)wxMessageBox("wxWindows wxToolBar demo\n", "About wxToolBar");
177 // Define the behaviour for the frame closing
178 // - must delete all frames except for the main one.
179 void MyFrame::OnCloseWindow(wxCloseEvent
& event
)
184 void MyFrame::OnToolLeftClick(wxCommandEvent
& event
)
187 str
.Printf("Clicked on tool %d", event
.GetId());
191 void MyFrame::OnToolEnter(wxCommandEvent
& event
)
193 if (event
.GetSelection() > -1)
196 str
.Printf("This is tool number %d", event
.GetSelection());