]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: test.cpp | |
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 | |
9 | // Licence: wxWindows licence | |
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" | |
24 | #include "test.h" | |
25 | ||
26 | #if defined(__WXGTK__) || defined(__WXMOTIF__) | |
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 | ||
39 | // start wxWindows | |
40 | ||
41 | IMPLEMENT_APP(MyApp) | |
42 | ||
43 | // globas | |
44 | ||
45 | MyMainFrame *main_frame = (MyMainFrame*) NULL; | |
46 | MyMiniFrame *mini_frame = (MyMiniFrame*) NULL; | |
47 | wxButton *button = (wxButton*) NULL; | |
48 | ||
49 | // The `main program' equivalent, creating the windows and returning the | |
50 | // main frame | |
51 | bool MyApp::OnInit(void) | |
52 | { | |
53 | // Create the mini frame window | |
54 | mini_frame = new MyMiniFrame((wxFrame *) NULL, -1, "wxMiniFrame sample", | |
55 | wxPoint(100, 100), wxSize(205, 100)); | |
56 | ||
57 | mini_frame->CreateToolBar(wxNO_BORDER|wxHORIZONTAL|wxTB_FLAT, ID_TOOLBAR); | |
58 | InitToolbar(mini_frame->GetToolBar()); | |
59 | ||
60 | // Create the main frame window | |
61 | main_frame = new MyMainFrame((wxFrame *) NULL, -1, "wxFrame sample", | |
62 | wxPoint(100, 100), wxSize(300, 200)); | |
63 | ||
64 | main_frame->CreateToolBar(wxNO_BORDER|wxHORIZONTAL, ID_TOOLBAR); | |
65 | InitToolbar(main_frame->GetToolBar()); | |
66 | ||
67 | button = new wxButton( main_frame, ID_REPARENT, "Press to reparent!" ); | |
68 | ||
69 | #ifdef __WXMSW__ | |
70 | main_frame->SetIcon(wxIcon("mondrian")); | |
71 | mini_frame->SetIcon(wxIcon("mondrian")); | |
72 | #else | |
73 | main_frame->SetIcon( wxIcon(mondrian_xpm) ); | |
74 | mini_frame->SetIcon( wxIcon(mondrian_xpm) ); | |
75 | #endif | |
76 | ||
77 | SetTopWindow(main_frame); | |
78 | ||
79 | main_frame->Show(TRUE); | |
80 | mini_frame->Show(TRUE); | |
81 | ||
82 | return TRUE; | |
83 | } | |
84 | ||
85 | bool MyApp::InitToolbar(wxToolBar* toolBar) | |
86 | { | |
87 | toolBar->SetMargins(5, 5); | |
88 | ||
89 | // Set up toolbar | |
90 | wxBitmap* toolBarBitmaps[8]; | |
91 | ||
92 | #ifdef __WXMSW__ | |
93 | toolBarBitmaps[0] = new wxBitmap("icon1"); | |
94 | toolBarBitmaps[1] = new wxBitmap("icon2"); | |
95 | toolBarBitmaps[2] = new wxBitmap("icon3"); | |
96 | toolBarBitmaps[3] = new wxBitmap("icon4"); | |
97 | toolBarBitmaps[4] = new wxBitmap("icon5"); | |
98 | toolBarBitmaps[5] = new wxBitmap("icon6"); | |
99 | toolBarBitmaps[6] = new wxBitmap("icon7"); | |
100 | toolBarBitmaps[7] = new wxBitmap("icon8"); | |
101 | #else | |
102 | toolBarBitmaps[0] = new wxBitmap( new_xpm ); | |
103 | toolBarBitmaps[1] = new wxBitmap( open_xpm ); | |
104 | toolBarBitmaps[2] = new wxBitmap( save_xpm ); | |
105 | toolBarBitmaps[3] = new wxBitmap( copy_xpm ); | |
106 | toolBarBitmaps[4] = new wxBitmap( cut_xpm ); | |
107 | // toolBarBitmaps[5] = new wxBitmap( paste_xpm ); | |
108 | toolBarBitmaps[5] = new wxBitmap( preview_xpm ); | |
109 | toolBarBitmaps[6] = new wxBitmap( print_xpm ); | |
110 | toolBarBitmaps[7] = new wxBitmap( help_xpm ); | |
111 | #endif | |
112 | ||
113 | #ifdef __WXMSW__ | |
114 | int width = 24; | |
115 | #else | |
116 | int width = 16; | |
117 | #endif | |
118 | int currentX = 5; | |
119 | ||
120 | toolBar->AddTool(wxID_NEW, *(toolBarBitmaps[0]), wxNullBitmap, FALSE, currentX, -1, (wxObject *) NULL, "New file"); | |
121 | currentX += width + 5; | |
122 | toolBar->AddTool(wxID_OPEN, *(toolBarBitmaps[1]), wxNullBitmap, FALSE, currentX, -1, (wxObject *) NULL, "Open file"); | |
123 | currentX += width + 5; | |
124 | toolBar->AddTool(wxID_SAVE, *(toolBarBitmaps[2]), wxNullBitmap, FALSE, currentX, -1, (wxObject *) NULL, "Save file"); | |
125 | currentX += width + 5; | |
126 | toolBar->AddSeparator(); | |
127 | toolBar->AddTool(wxID_COPY, *(toolBarBitmaps[3]), wxNullBitmap, FALSE, currentX, -1, (wxObject *) NULL, "Copy"); | |
128 | currentX += width + 5; | |
129 | toolBar->AddTool(wxID_CUT, *(toolBarBitmaps[4]), wxNullBitmap, FALSE, currentX, -1, (wxObject *) NULL, "Cut"); | |
130 | currentX += width + 5; | |
131 | toolBar->AddTool(wxID_PASTE, *(toolBarBitmaps[5]), wxNullBitmap, FALSE, currentX, -1, (wxObject *) NULL, "Paste"); | |
132 | currentX += width + 5; | |
133 | toolBar->AddSeparator(); | |
134 | toolBar->AddTool(wxID_PRINT, *(toolBarBitmaps[6]), wxNullBitmap, FALSE, currentX, -1, (wxObject *) NULL, "Print"); | |
135 | currentX += width + 5; | |
136 | toolBar->AddSeparator(); | |
137 | toolBar->AddTool(wxID_HELP, *(toolBarBitmaps[7]), wxNullBitmap, FALSE, currentX, -1, (wxObject *) NULL, "Help"); | |
138 | ||
139 | toolBar->Realize(); | |
140 | ||
141 | toolBar->EnableTool( wxID_HELP, FALSE ); | |
142 | ||
143 | // Can delete the bitmaps since they're reference counted | |
144 | int i; | |
145 | for (i = 0; i < 8; i++) | |
146 | delete toolBarBitmaps[i]; | |
147 | ||
148 | return TRUE; | |
149 | } | |
150 | ||
151 | // MyMiniFrame | |
152 | ||
153 | BEGIN_EVENT_TABLE(MyMiniFrame, wxMiniFrame) | |
154 | EVT_CLOSE ( MyMiniFrame::OnCloseWindow) | |
155 | EVT_BUTTON (ID_REPARENT, MyMiniFrame::OnReparent) | |
156 | END_EVENT_TABLE() | |
157 | ||
158 | MyMiniFrame::MyMiniFrame(wxFrame* parent, wxWindowID id, const wxString& title, const wxPoint& pos, | |
159 | const wxSize& size ) : | |
160 | wxMiniFrame(parent, id, title, pos, size ) | |
161 | { | |
162 | } | |
163 | ||
164 | void MyMiniFrame::OnCloseWindow(wxCloseEvent& WXUNUSED(event)) | |
165 | { | |
166 | Destroy(); | |
167 | } | |
168 | ||
169 | void MyMiniFrame::OnReparent(wxCommandEvent& WXUNUSED(event)) | |
170 | { | |
171 | button->Reparent( main_frame ); | |
172 | } | |
173 | ||
174 | // MyMainFrame | |
175 | ||
176 | BEGIN_EVENT_TABLE(MyMainFrame, wxFrame) | |
177 | EVT_CLOSE ( MyMainFrame::OnCloseWindow) | |
178 | EVT_BUTTON (ID_REPARENT, MyMainFrame::OnReparent) | |
179 | END_EVENT_TABLE() | |
180 | ||
181 | MyMainFrame::MyMainFrame(wxFrame* parent, wxWindowID id, const wxString& title, const wxPoint& pos, | |
182 | const wxSize& size ) : | |
183 | wxFrame(parent, id, title, pos, size ) | |
184 | { | |
185 | } | |
186 | ||
187 | void MyMainFrame::OnCloseWindow(wxCloseEvent& WXUNUSED(event)) | |
188 | { | |
189 | Destroy(); | |
190 | } | |
191 | ||
192 | void MyMainFrame::OnReparent(wxCommandEvent& WXUNUSED(event)) | |
193 | { | |
194 | button->Reparent( mini_frame ); | |
195 | } | |
196 | ||
197 |