]>
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 | |
e70d4ce8 | 26 | #if defined(__WXGTK__) || defined(__WXMOTIF__) || defined(__WXMAC__) |
b2b3ccc5 RR |
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" | |
37 | #endif | |
38 | ||
8ce63e9d RR |
39 | // start wxWindows |
40 | ||
b2b3ccc5 RR |
41 | IMPLEMENT_APP(MyApp) |
42 | ||
8ce63e9d RR |
43 | // globas |
44 | ||
45 | MyMainFrame *main_frame = (MyMainFrame*) NULL; | |
46 | MyMiniFrame *mini_frame = (MyMiniFrame*) NULL; | |
5d55595c | 47 | bool mini_frame_exists = FALSE; |
8ce63e9d | 48 | wxButton *button = (wxButton*) NULL; |
b2b3ccc5 RR |
49 | |
50 | // The `main program' equivalent, creating the windows and returning the | |
51 | // main frame | |
9121bed2 | 52 | bool MyApp::OnInit() |
b2b3ccc5 RR |
53 | { |
54 | // Create the main frame window | |
8ce63e9d RR |
55 | main_frame = new MyMainFrame((wxFrame *) NULL, -1, "wxFrame sample", |
56 | wxPoint(100, 100), wxSize(300, 200)); | |
9121bed2 | 57 | |
5d5b3a40 | 58 | main_frame->CreateToolBar(wxNO_BORDER|wxTB_VERTICAL, ID_TOOLBAR); |
8ce63e9d | 59 | InitToolbar(main_frame->GetToolBar()); |
9121bed2 | 60 | |
8ce63e9d | 61 | button = new wxButton( main_frame, ID_REPARENT, "Press to reparent!" ); |
b2b3ccc5 | 62 | |
a56fcaaf RR |
63 | // Create the mini frame window |
64 | mini_frame = new MyMiniFrame( main_frame, -1, "wxMiniFrame sample", | |
65 | wxPoint(100, 100), wxSize(220, 100)); | |
66 | mini_frame_exists = TRUE; | |
67 | ||
68 | mini_frame->CreateToolBar(wxNO_BORDER|wxTB_HORIZONTAL|wxTB_FLAT, ID_TOOLBAR); | |
69 | InitToolbar(mini_frame->GetToolBar()); | |
70 | ||
b2b3ccc5 | 71 | #ifdef __WXMSW__ |
8ce63e9d RR |
72 | main_frame->SetIcon(wxIcon("mondrian")); |
73 | mini_frame->SetIcon(wxIcon("mondrian")); | |
b2b3ccc5 | 74 | #else |
8ce63e9d RR |
75 | main_frame->SetIcon( wxIcon(mondrian_xpm) ); |
76 | mini_frame->SetIcon( wxIcon(mondrian_xpm) ); | |
b2b3ccc5 RR |
77 | #endif |
78 | ||
8ce63e9d | 79 | SetTopWindow(main_frame); |
9121bed2 | 80 | |
8ce63e9d RR |
81 | main_frame->Show(TRUE); |
82 | mini_frame->Show(TRUE); | |
b2b3ccc5 RR |
83 | |
84 | return TRUE; | |
85 | } | |
86 | ||
87 | bool MyApp::InitToolbar(wxToolBar* toolBar) | |
88 | { | |
89 | toolBar->SetMargins(5, 5); | |
90 | ||
91 | // Set up toolbar | |
92 | wxBitmap* toolBarBitmaps[8]; | |
93 | ||
94 | #ifdef __WXMSW__ | |
95 | toolBarBitmaps[0] = new wxBitmap("icon1"); | |
96 | toolBarBitmaps[1] = new wxBitmap("icon2"); | |
97 | toolBarBitmaps[2] = new wxBitmap("icon3"); | |
98 | toolBarBitmaps[3] = new wxBitmap("icon4"); | |
99 | toolBarBitmaps[4] = new wxBitmap("icon5"); | |
100 | toolBarBitmaps[5] = new wxBitmap("icon6"); | |
101 | toolBarBitmaps[6] = new wxBitmap("icon7"); | |
102 | toolBarBitmaps[7] = new wxBitmap("icon8"); | |
103 | #else | |
104 | toolBarBitmaps[0] = new wxBitmap( new_xpm ); | |
105 | toolBarBitmaps[1] = new wxBitmap( open_xpm ); | |
106 | toolBarBitmaps[2] = new wxBitmap( save_xpm ); | |
107 | toolBarBitmaps[3] = new wxBitmap( copy_xpm ); | |
108 | toolBarBitmaps[4] = new wxBitmap( cut_xpm ); | |
109 | // toolBarBitmaps[5] = new wxBitmap( paste_xpm ); | |
110 | toolBarBitmaps[5] = new wxBitmap( preview_xpm ); | |
111 | toolBarBitmaps[6] = new wxBitmap( print_xpm ); | |
112 | toolBarBitmaps[7] = new wxBitmap( help_xpm ); | |
113 | #endif | |
114 | ||
115 | #ifdef __WXMSW__ | |
116 | int width = 24; | |
117 | #else | |
118 | int width = 16; | |
119 | #endif | |
120 | int currentX = 5; | |
121 | ||
122 | toolBar->AddTool(wxID_NEW, *(toolBarBitmaps[0]), wxNullBitmap, FALSE, currentX, -1, (wxObject *) NULL, "New file"); | |
123 | currentX += width + 5; | |
124 | toolBar->AddTool(wxID_OPEN, *(toolBarBitmaps[1]), wxNullBitmap, FALSE, currentX, -1, (wxObject *) NULL, "Open file"); | |
125 | currentX += width + 5; | |
126 | toolBar->AddTool(wxID_SAVE, *(toolBarBitmaps[2]), wxNullBitmap, FALSE, currentX, -1, (wxObject *) NULL, "Save file"); | |
127 | currentX += width + 5; | |
128 | toolBar->AddSeparator(); | |
129 | toolBar->AddTool(wxID_COPY, *(toolBarBitmaps[3]), wxNullBitmap, FALSE, currentX, -1, (wxObject *) NULL, "Copy"); | |
130 | currentX += width + 5; | |
131 | toolBar->AddTool(wxID_CUT, *(toolBarBitmaps[4]), wxNullBitmap, FALSE, currentX, -1, (wxObject *) NULL, "Cut"); | |
132 | currentX += width + 5; | |
133 | toolBar->AddTool(wxID_PASTE, *(toolBarBitmaps[5]), wxNullBitmap, FALSE, currentX, -1, (wxObject *) NULL, "Paste"); | |
134 | currentX += width + 5; | |
135 | toolBar->AddSeparator(); | |
5fd11f09 | 136 | toolBar->AddTool(wxID_PRINT, *(toolBarBitmaps[6]), wxNullBitmap, FALSE, currentX, -1, (wxObject *) NULL, "Reparent the button"); |
b2b3ccc5 RR |
137 | currentX += width + 5; |
138 | toolBar->AddSeparator(); | |
139 | toolBar->AddTool(wxID_HELP, *(toolBarBitmaps[7]), wxNullBitmap, FALSE, currentX, -1, (wxObject *) NULL, "Help"); | |
140 | ||
141 | toolBar->Realize(); | |
9121bed2 | 142 | |
2b1c162e | 143 | toolBar->EnableTool( wxID_HELP, FALSE ); |
b2b3ccc5 RR |
144 | |
145 | // Can delete the bitmaps since they're reference counted | |
146 | int i; | |
147 | for (i = 0; i < 8; i++) | |
148 | delete toolBarBitmaps[i]; | |
149 | ||
150 | return TRUE; | |
151 | } | |
152 | ||
8ce63e9d RR |
153 | // MyMiniFrame |
154 | ||
155 | BEGIN_EVENT_TABLE(MyMiniFrame, wxMiniFrame) | |
156 | EVT_CLOSE ( MyMiniFrame::OnCloseWindow) | |
157 | EVT_BUTTON (ID_REPARENT, MyMiniFrame::OnReparent) | |
5fd11f09 | 158 | EVT_MENU (wxID_PRINT, MyMiniFrame::OnReparent) |
b2b3ccc5 RR |
159 | END_EVENT_TABLE() |
160 | ||
8ce63e9d | 161 | MyMiniFrame::MyMiniFrame(wxFrame* parent, wxWindowID id, const wxString& title, const wxPoint& pos, |
b2b3ccc5 RR |
162 | const wxSize& size ) : |
163 | wxMiniFrame(parent, id, title, pos, size ) | |
164 | { | |
165 | } | |
166 | ||
8ce63e9d | 167 | void MyMiniFrame::OnCloseWindow(wxCloseEvent& WXUNUSED(event)) |
b2b3ccc5 | 168 | { |
5d55595c HH |
169 | // make it known that the miniframe is no more |
170 | mini_frame_exists = FALSE; | |
b2b3ccc5 RR |
171 | Destroy(); |
172 | } | |
173 | ||
8ce63e9d RR |
174 | void MyMiniFrame::OnReparent(wxCommandEvent& WXUNUSED(event)) |
175 | { | |
176 | button->Reparent( main_frame ); | |
177 | } | |
178 | ||
179 | // MyMainFrame | |
180 | ||
181 | BEGIN_EVENT_TABLE(MyMainFrame, wxFrame) | |
182 | EVT_CLOSE ( MyMainFrame::OnCloseWindow) | |
183 | EVT_BUTTON (ID_REPARENT, MyMainFrame::OnReparent) | |
5fd11f09 | 184 | EVT_MENU (wxID_PRINT, MyMainFrame::OnReparent) |
8ce63e9d RR |
185 | END_EVENT_TABLE() |
186 | ||
187 | MyMainFrame::MyMainFrame(wxFrame* parent, wxWindowID id, const wxString& title, const wxPoint& pos, | |
188 | const wxSize& size ) : | |
189 | wxFrame(parent, id, title, pos, size ) | |
190 | { | |
191 | } | |
192 | ||
193 | void MyMainFrame::OnCloseWindow(wxCloseEvent& WXUNUSED(event)) | |
194 | { | |
195 | Destroy(); | |
196 | } | |
197 | ||
198 | void MyMainFrame::OnReparent(wxCommandEvent& WXUNUSED(event)) | |
199 | { | |
5d55595c HH |
200 | // practical jokers might find satisfaction in reparenting the button |
201 | // after closing the mini_frame. We'll have the last laugh. | |
202 | if (! mini_frame_exists) | |
203 | wxMessageBox("The miniframe no longer exists.\n" | |
9121bed2 VZ |
204 | "You don't want to make this button an orphan, do you?", |
205 | "You got to be kidding"); | |
5d55595c HH |
206 | else |
207 | button->Reparent( mini_frame ); | |
8ce63e9d RR |
208 | } |
209 | ||
210 |