]>
Commit | Line | Data |
---|---|---|
b2b3ccc5 | 1 | ///////////////////////////////////////////////////////////////////////////// |
14057bf4 | 2 | // Name: minifram.cpp |
b2b3ccc5 RR |
3 | // Purpose: wxMiniFrame sample |
4 | // Author: Robert Roebling | |
5 | // Modified by: | |
6 | // Created: 04/01/98 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Julian Smart and Robert Roebling | |
9121bed2 | 9 | // Licence: wxWindows licence |
b2b3ccc5 RR |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
12 | // For compilers that support precompilation, includes "wx/wx.h". | |
13 | #include "wx/wxprec.h" | |
14 | ||
15 | #ifdef __BORLANDC__ | |
16 | #pragma hdrstop | |
17 | #endif | |
18 | ||
19 | #ifndef WX_PRECOMP | |
20 | #include "wx/wx.h" | |
21 | #endif | |
22 | ||
23 | #include "wx/toolbar.h" | |
14057bf4 | 24 | #include "minifram.h" |
b2b3ccc5 | 25 | |
5f4d35b8 | 26 | #if !defined(__WXMSW__) && !defined(__WXPM__) |
b2b3ccc5 | 27 | #include "mondrian.xpm" |
d440dda1 | 28 | #endif |
b2b3ccc5 RR |
29 | #include "bitmaps/new.xpm" |
30 | #include "bitmaps/open.xpm" | |
31 | #include "bitmaps/save.xpm" | |
32 | #include "bitmaps/copy.xpm" | |
33 | #include "bitmaps/cut.xpm" | |
34 | // #include "bitmaps/paste.xpm" | |
35 | #include "bitmaps/print.xpm" | |
36 | #include "bitmaps/preview.xpm" | |
37 | #include "bitmaps/help.xpm" | |
d440dda1 | 38 | |
b2b3ccc5 | 39 | |
be5a51fb | 40 | // start wxWidgets |
8ce63e9d | 41 | |
b2b3ccc5 RR |
42 | IMPLEMENT_APP(MyApp) |
43 | ||
8ce63e9d RR |
44 | // globas |
45 | ||
46 | MyMainFrame *main_frame = (MyMainFrame*) NULL; | |
47 | MyMiniFrame *mini_frame = (MyMiniFrame*) NULL; | |
0ff72086 | 48 | bool mini_frame_exists = false; |
8ce63e9d | 49 | wxButton *button = (wxButton*) NULL; |
b2b3ccc5 | 50 | |
a7db4235 RR |
51 | #define ID_SET_SIZE_TO_150_150 100 |
52 | #define ID_SET_SIZE_TO_200_200 101 | |
53 | #define ID_SET_MAX_SIZE_TO_150_150 102 | |
54 | #define ID_SET_MAX_SIZE_TO_300_300 103 | |
55 | ||
b2b3ccc5 RR |
56 | // The `main program' equivalent, creating the windows and returning the |
57 | // main frame | |
9121bed2 | 58 | bool MyApp::OnInit() |
b2b3ccc5 | 59 | { |
45e6e6f8 VZ |
60 | if ( !wxApp::OnInit() ) |
61 | return false; | |
62 | ||
b2b3ccc5 | 63 | // Create the main frame window |
0ff72086 | 64 | main_frame = new MyMainFrame((wxFrame *) NULL, wxID_ANY, _T("wxFrame sample"), |
8ce63e9d | 65 | wxPoint(100, 100), wxSize(300, 200)); |
a7db4235 | 66 | |
d4638e6b | 67 | main_frame->SetSizeHints( 100,100, 400,400 ); |
9121bed2 | 68 | |
a7db4235 RR |
69 | wxMenu *file_menu = new wxMenu; |
70 | file_menu->Append(wxID_EXIT, _T("E&xit\tAlt-Q")); | |
71 | file_menu->Append(ID_SET_SIZE_TO_150_150, _T("Set frame size to 150,150\tF2")); | |
72 | file_menu->Append(ID_SET_SIZE_TO_200_200, _T("Set frame size to 200,200\tF3")); | |
73 | file_menu->Append(ID_SET_MAX_SIZE_TO_150_150, _T("Set frame max size to 150,150\tF4")); | |
74 | file_menu->Append(ID_SET_MAX_SIZE_TO_300_300, _T("Set frame max size to 300,300\tF5")); | |
75 | ||
76 | wxMenuBar *menu_bar = new wxMenuBar; | |
77 | menu_bar->Append(file_menu, _T("&File")); | |
78 | main_frame->SetMenuBar(menu_bar); | |
79 | ||
80 | main_frame->Connect( ID_SET_SIZE_TO_150_150, wxID_ANY, | |
81 | wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MyMainFrame::OnSetSize_150_150) ); | |
82 | main_frame->Connect( ID_SET_SIZE_TO_200_200, wxID_ANY, | |
83 | wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MyMainFrame::OnSetSize_200_200) ); | |
84 | main_frame->Connect( ID_SET_MAX_SIZE_TO_150_150, wxID_ANY, | |
85 | wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MyMainFrame::OnSetMaxSize_150_150) ); | |
86 | main_frame->Connect( ID_SET_MAX_SIZE_TO_300_300, wxID_ANY, | |
87 | wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MyMainFrame::OnSetMaxSize_300_300) ); | |
88 | ||
5d5b3a40 | 89 | main_frame->CreateToolBar(wxNO_BORDER|wxTB_VERTICAL, ID_TOOLBAR); |
8ce63e9d | 90 | InitToolbar(main_frame->GetToolBar()); |
9121bed2 | 91 | |
600683ca | 92 | button = new wxButton( main_frame, ID_REPARENT, _T("Press to reparent!") ); |
b2b3ccc5 | 93 | |
a56fcaaf | 94 | // Create the mini frame window |
0ff72086 | 95 | mini_frame = new MyMiniFrame( main_frame, wxID_ANY, _T("wxMiniFrame sample"), |
a56fcaaf | 96 | wxPoint(100, 100), wxSize(220, 100)); |
0ff72086 | 97 | mini_frame_exists = true; |
a56fcaaf RR |
98 | |
99 | mini_frame->CreateToolBar(wxNO_BORDER|wxTB_HORIZONTAL|wxTB_FLAT, ID_TOOLBAR); | |
100 | InitToolbar(mini_frame->GetToolBar()); | |
101 | ||
d440dda1 CE |
102 | main_frame->SetIcon(wxICON(mondrian)); |
103 | mini_frame->SetIcon(wxICON(mondrian)); | |
b2b3ccc5 | 104 | |
8ce63e9d | 105 | SetTopWindow(main_frame); |
9121bed2 | 106 | |
0ff72086 WS |
107 | main_frame->Show(true); |
108 | mini_frame->Show(true); | |
b2b3ccc5 | 109 | |
0ff72086 | 110 | return true; |
b2b3ccc5 RR |
111 | } |
112 | ||
113 | bool MyApp::InitToolbar(wxToolBar* toolBar) | |
114 | { | |
115 | toolBar->SetMargins(5, 5); | |
116 | ||
117 | // Set up toolbar | |
118 | wxBitmap* toolBarBitmaps[8]; | |
119 | ||
b2b3ccc5 RR |
120 | toolBarBitmaps[0] = new wxBitmap( new_xpm ); |
121 | toolBarBitmaps[1] = new wxBitmap( open_xpm ); | |
122 | toolBarBitmaps[2] = new wxBitmap( save_xpm ); | |
123 | toolBarBitmaps[3] = new wxBitmap( copy_xpm ); | |
124 | toolBarBitmaps[4] = new wxBitmap( cut_xpm ); | |
125 | // toolBarBitmaps[5] = new wxBitmap( paste_xpm ); | |
126 | toolBarBitmaps[5] = new wxBitmap( preview_xpm ); | |
127 | toolBarBitmaps[6] = new wxBitmap( print_xpm ); | |
128 | toolBarBitmaps[7] = new wxBitmap( help_xpm ); | |
b2b3ccc5 | 129 | |
b2b3ccc5 | 130 | int width = 16; |
b2b3ccc5 RR |
131 | int currentX = 5; |
132 | ||
422d0ff0 | 133 | toolBar->AddTool(wxID_NEW, *(toolBarBitmaps[0]), wxNullBitmap, false, currentX, wxDefaultCoord, (wxObject *) NULL, _T("New file")); |
b2b3ccc5 | 134 | currentX += width + 5; |
422d0ff0 | 135 | toolBar->AddTool(wxID_OPEN, *(toolBarBitmaps[1]), wxNullBitmap, false, currentX, wxDefaultCoord, (wxObject *) NULL, _T("Open file")); |
b2b3ccc5 | 136 | currentX += width + 5; |
422d0ff0 | 137 | toolBar->AddTool(wxID_SAVE, *(toolBarBitmaps[2]), wxNullBitmap, false, currentX, wxDefaultCoord, (wxObject *) NULL, _T("Save file")); |
b2b3ccc5 RR |
138 | currentX += width + 5; |
139 | toolBar->AddSeparator(); | |
422d0ff0 | 140 | toolBar->AddTool(wxID_COPY, *(toolBarBitmaps[3]), wxNullBitmap, false, currentX, wxDefaultCoord, (wxObject *) NULL, _T("Copy")); |
b2b3ccc5 | 141 | currentX += width + 5; |
422d0ff0 | 142 | toolBar->AddTool(wxID_CUT, *(toolBarBitmaps[4]), wxNullBitmap, false, currentX, wxDefaultCoord, (wxObject *) NULL, _T("Cut")); |
b2b3ccc5 | 143 | currentX += width + 5; |
422d0ff0 | 144 | toolBar->AddTool(wxID_PASTE, *(toolBarBitmaps[5]), wxNullBitmap, false, currentX, wxDefaultCoord, (wxObject *) NULL, _T("Paste")); |
b2b3ccc5 RR |
145 | currentX += width + 5; |
146 | toolBar->AddSeparator(); | |
422d0ff0 | 147 | toolBar->AddTool(wxID_PRINT, *(toolBarBitmaps[6]), wxNullBitmap, false, currentX, wxDefaultCoord, (wxObject *) NULL, _T("Reparent the button")); |
b2b3ccc5 RR |
148 | currentX += width + 5; |
149 | toolBar->AddSeparator(); | |
422d0ff0 | 150 | toolBar->AddTool(wxID_HELP, *(toolBarBitmaps[7]), wxNullBitmap, false, currentX, wxDefaultCoord, (wxObject *) NULL, _T("Help")); |
b2b3ccc5 RR |
151 | |
152 | toolBar->Realize(); | |
9121bed2 | 153 | |
0ff72086 | 154 | toolBar->EnableTool( wxID_HELP, false ); |
b2b3ccc5 RR |
155 | |
156 | // Can delete the bitmaps since they're reference counted | |
157 | int i; | |
158 | for (i = 0; i < 8; i++) | |
159 | delete toolBarBitmaps[i]; | |
160 | ||
0ff72086 | 161 | return true; |
b2b3ccc5 RR |
162 | } |
163 | ||
8ce63e9d RR |
164 | // MyMiniFrame |
165 | ||
166 | BEGIN_EVENT_TABLE(MyMiniFrame, wxMiniFrame) | |
167 | EVT_CLOSE ( MyMiniFrame::OnCloseWindow) | |
168 | EVT_BUTTON (ID_REPARENT, MyMiniFrame::OnReparent) | |
5fd11f09 | 169 | EVT_MENU (wxID_PRINT, MyMiniFrame::OnReparent) |
b2b3ccc5 RR |
170 | END_EVENT_TABLE() |
171 | ||
8ce63e9d | 172 | MyMiniFrame::MyMiniFrame(wxFrame* parent, wxWindowID id, const wxString& title, const wxPoint& pos, |
b2b3ccc5 RR |
173 | const wxSize& size ) : |
174 | wxMiniFrame(parent, id, title, pos, size ) | |
175 | { | |
176 | } | |
177 | ||
8ce63e9d | 178 | void MyMiniFrame::OnCloseWindow(wxCloseEvent& WXUNUSED(event)) |
b2b3ccc5 | 179 | { |
5d55595c | 180 | // make it known that the miniframe is no more |
0ff72086 | 181 | mini_frame_exists = false; |
b2b3ccc5 RR |
182 | Destroy(); |
183 | } | |
184 | ||
8ce63e9d RR |
185 | void MyMiniFrame::OnReparent(wxCommandEvent& WXUNUSED(event)) |
186 | { | |
187 | button->Reparent( main_frame ); | |
33c8cf5e VZ |
188 | |
189 | // we need to force the frame to size its (new) child correctly | |
190 | main_frame->SendSizeEvent(); | |
8ce63e9d RR |
191 | } |
192 | ||
193 | // MyMainFrame | |
194 | ||
195 | BEGIN_EVENT_TABLE(MyMainFrame, wxFrame) | |
196 | EVT_CLOSE ( MyMainFrame::OnCloseWindow) | |
197 | EVT_BUTTON (ID_REPARENT, MyMainFrame::OnReparent) | |
5fd11f09 | 198 | EVT_MENU (wxID_PRINT, MyMainFrame::OnReparent) |
8ce63e9d RR |
199 | END_EVENT_TABLE() |
200 | ||
201 | MyMainFrame::MyMainFrame(wxFrame* parent, wxWindowID id, const wxString& title, const wxPoint& pos, | |
202 | const wxSize& size ) : | |
203 | wxFrame(parent, id, title, pos, size ) | |
204 | { | |
205 | } | |
206 | ||
207 | void MyMainFrame::OnCloseWindow(wxCloseEvent& WXUNUSED(event)) | |
208 | { | |
209 | Destroy(); | |
210 | } | |
211 | ||
212 | void MyMainFrame::OnReparent(wxCommandEvent& WXUNUSED(event)) | |
213 | { | |
5d55595c HH |
214 | // practical jokers might find satisfaction in reparenting the button |
215 | // after closing the mini_frame. We'll have the last laugh. | |
216 | if (! mini_frame_exists) | |
600683ca MB |
217 | wxMessageBox(_T("The miniframe no longer exists.\n") |
218 | _T("You don't want to make this button an orphan, do you?"), | |
219 | _T("You got to be kidding")); | |
5d55595c | 220 | else |
33c8cf5e | 221 | { |
5d55595c | 222 | button->Reparent( mini_frame ); |
33c8cf5e VZ |
223 | |
224 | // same as above | |
225 | mini_frame->SendSizeEvent(); | |
226 | } | |
8ce63e9d | 227 | } |
a7db4235 RR |
228 | |
229 | void MyMainFrame::OnSetSize_150_150(wxCommandEvent& WXUNUSED(event)) | |
230 | { | |
231 | SetSize( 150, 150 ); | |
232 | } | |
233 | ||
234 | void MyMainFrame::OnSetSize_200_200(wxCommandEvent& WXUNUSED(event)) | |
235 | { | |
236 | SetSize( 200, 200 ); | |
237 | } | |
238 | ||
239 | void MyMainFrame::OnSetMaxSize_150_150(wxCommandEvent& WXUNUSED(event)) | |
240 | { | |
2612a310 | 241 | SetSizeHints( -1, -1, 150, 150 ); |
a7db4235 RR |
242 | } |
243 | ||
244 | void MyMainFrame::OnSetMaxSize_300_300(wxCommandEvent& WXUNUSED(event)) | |
245 | { | |
2612a310 | 246 | SetSizeHints( -1, -1, 300, 300 ); |
a7db4235 | 247 | } |