]>
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"
27 #include "mondrian.xpm"
28 #include "bitmaps/new.xpm"
29 #include "bitmaps/open.xpm"
30 #include "bitmaps/save.xpm"
31 #include "bitmaps/copy.xpm"
32 #include "bitmaps/cut.xpm"
33 // #include "bitmaps/paste.xpm"
34 #include "bitmaps/print.xpm"
35 #include "bitmaps/preview.xpm"
36 #include "bitmaps/help.xpm"
42 // The `main program' equivalent, creating the windows and returning the
44 bool MyApp::OnInit(void)
46 // Create the main frame window
47 MyFrame
* frame
= new MyFrame((wxFrame
*) NULL
, -1, (const wxString
) "wxToolBar Sample",
48 wxPoint(100, 100), wxSize(450, 300));
50 // Give it a status line
51 frame
->CreateStatusBar();
55 frame
->SetIcon(wxIcon("mondrian"));
57 frame
->SetIcon( wxIcon(mondrian_xpm
) );
61 wxMenu
*fileMenu
= new wxMenu
;
62 fileMenu
->Append(wxID_EXIT
, "E&xit");
64 wxMenu
*helpMenu
= new wxMenu
;
65 helpMenu
->Append(wxID_HELP
, "&About");
67 wxMenuBar
* menuBar
= new wxMenuBar
;
69 menuBar
->Append(fileMenu
, "&File");
70 menuBar
->Append(helpMenu
, "&Help");
72 // Associate the menu bar with the frame
73 frame
->SetMenuBar(menuBar
);
76 frame
->CreateToolBar(wxNO_BORDER
|wxHORIZONTAL
|wxTB_FLAT
, ID_TOOLBAR
);
78 InitToolbar(frame
->GetToolBar());
80 // Force a resize. This should probably be replaced by a call to a wxFrame
81 // function that lays out default decorations and the remaining content window.
82 frame
->OnSize(wxSizeEvent(wxSize(-1, -1), frame
->GetId()));
85 frame
->SetStatusText("Hello, wxWindows");
92 bool MyApp::InitToolbar(wxToolBar
* toolBar
)
94 toolBar
->SetMargins(5, 5);
97 wxBitmap
* toolBarBitmaps
[8];
100 toolBarBitmaps
[0] = new wxBitmap("icon1");
101 toolBarBitmaps
[1] = new wxBitmap("icon2");
102 toolBarBitmaps
[2] = new wxBitmap("icon3");
103 toolBarBitmaps
[3] = new wxBitmap("icon4");
104 toolBarBitmaps
[4] = new wxBitmap("icon5");
105 toolBarBitmaps
[5] = new wxBitmap("icon6");
106 toolBarBitmaps
[6] = new wxBitmap("icon7");
107 toolBarBitmaps
[7] = new wxBitmap("icon8");
109 toolBarBitmaps
[0] = new wxBitmap( new_xpm
);
110 toolBarBitmaps
[1] = new wxBitmap( open_xpm
);
111 toolBarBitmaps
[2] = new wxBitmap( save_xpm
);
112 toolBarBitmaps
[3] = new wxBitmap( copy_xpm
);
113 toolBarBitmaps
[4] = new wxBitmap( cut_xpm
);
114 // toolBarBitmaps[5] = new wxBitmap( paste_xpm );
115 toolBarBitmaps
[5] = new wxBitmap( preview_xpm
);
116 toolBarBitmaps
[6] = new wxBitmap( print_xpm
);
117 toolBarBitmaps
[7] = new wxBitmap( help_xpm
);
127 toolBar
->AddTool(wxID_NEW
, *(toolBarBitmaps
[0]), wxNullBitmap
, FALSE
, (float)currentX
, -1, (wxObject
*) NULL
, "New file");
128 currentX
+= width
+ 5;
129 toolBar
->AddTool(wxID_OPEN
, *(toolBarBitmaps
[1]), wxNullBitmap
, FALSE
, (float)currentX
, -1, (wxObject
*) NULL
, "Open file");
130 currentX
+= width
+ 5;
131 toolBar
->AddTool(wxID_SAVE
, *(toolBarBitmaps
[2]), wxNullBitmap
, FALSE
, (float)currentX
, -1, (wxObject
*) NULL
, "Save file");
132 currentX
+= width
+ 5;
133 toolBar
->AddSeparator();
134 toolBar
->AddTool(wxID_COPY
, *(toolBarBitmaps
[3]), wxNullBitmap
, FALSE
, (float)currentX
, -1, (wxObject
*) NULL
, "Copy");
135 currentX
+= width
+ 5;
136 toolBar
->AddTool(wxID_CUT
, *(toolBarBitmaps
[4]), wxNullBitmap
, FALSE
, (float)currentX
, -1, (wxObject
*) NULL
, "Cut");
137 currentX
+= width
+ 5;
138 toolBar
->AddTool(wxID_PASTE
, *(toolBarBitmaps
[5]), wxNullBitmap
, FALSE
, (float)currentX
, -1, (wxObject
*) NULL
, "Paste");
139 currentX
+= width
+ 5;
140 toolBar
->AddSeparator();
141 toolBar
->AddTool(wxID_PRINT
, *(toolBarBitmaps
[6]), wxNullBitmap
, FALSE
, (float)currentX
, -1, (wxObject
*) NULL
, "Print");
142 currentX
+= width
+ 5;
143 toolBar
->AddSeparator();
144 toolBar
->AddTool(wxID_HELP
, *(toolBarBitmaps
[7]), wxNullBitmap
, FALSE
, currentX
, -1, (wxObject
*) NULL
, "Help");
148 // Can delete the bitmaps since they're reference counted
150 for (i
= 0; i
< 8; i
++)
151 delete toolBarBitmaps
[i
];
156 // wxID_HELP will be processed for the 'About' menu and the toolbar help button.
158 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
159 EVT_MENU(wxID_EXIT
, MyFrame::OnQuit
)
160 EVT_MENU(wxID_HELP
, MyFrame::OnAbout
)
161 EVT_CLOSE(MyFrame::OnCloseWindow
)
162 EVT_TOOL_RANGE(wxID_OPEN
, wxID_PASTE
, MyFrame::OnToolLeftClick
)
163 EVT_TOOL_ENTER(ID_TOOLBAR
, MyFrame::OnToolEnter
)
166 // Define my frame constructor
167 MyFrame::MyFrame(wxFrame
* parent
, wxWindowID id
, const wxString
& title
, const wxPoint
& pos
,
168 const wxSize
& size
, long style
):
169 wxFrame(parent
, id
, title
, pos
, size
, style
)
171 m_textWindow
= new wxTextCtrl(this, -1, "", wxPoint(0, 0), wxSize(-1, -1), wxTE_MULTILINE
);
174 void MyFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
))
179 void MyFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
))
181 (void)wxMessageBox("wxWindows wxToolBar demo\n", "About wxToolBar");
184 // Define the behaviour for the frame closing
185 // - must delete all frames except for the main one.
186 void MyFrame::OnCloseWindow(wxCloseEvent
& WXUNUSED(event
))
191 void MyFrame::OnToolLeftClick(wxCommandEvent
& event
)
194 str
.Printf("Clicked on tool %d", event
.GetId());
198 void MyFrame::OnToolEnter(wxCommandEvent
& event
)
200 if (event
.GetSelection() > -1)
203 str
.Printf("This is tool number %d", event
.GetSelection());