1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxMiniFrame sample
4 // Author: Robert Roebling
8 // Copyright: (c) Julian Smart and Robert Roebling
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"
26 #if !defined(__WXMSW__) && !defined(__WXPM__)
27 #include "mondrian.xpm"
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"
46 MyMainFrame
*main_frame
= (MyMainFrame
*) NULL
;
47 MyMiniFrame
*mini_frame
= (MyMiniFrame
*) NULL
;
48 bool mini_frame_exists
= false;
49 wxButton
*button
= (wxButton
*) NULL
;
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
56 // The `main program' equivalent, creating the windows and returning the
60 // Create the main frame window
61 main_frame
= new MyMainFrame((wxFrame
*) NULL
, wxID_ANY
, _T("wxFrame sample"),
62 wxPoint(100, 100), wxSize(300, 200));
64 main_frame
->SetSizeHints( 100,100, 400,400 );
66 wxMenu
*file_menu
= new wxMenu
;
67 file_menu
->Append(wxID_EXIT
, _T("E&xit\tAlt-Q"));
68 file_menu
->Append(ID_SET_SIZE_TO_150_150
, _T("Set frame size to 150,150\tF2"));
69 file_menu
->Append(ID_SET_SIZE_TO_200_200
, _T("Set frame size to 200,200\tF3"));
70 file_menu
->Append(ID_SET_MAX_SIZE_TO_150_150
, _T("Set frame max size to 150,150\tF4"));
71 file_menu
->Append(ID_SET_MAX_SIZE_TO_300_300
, _T("Set frame max size to 300,300\tF5"));
73 wxMenuBar
*menu_bar
= new wxMenuBar
;
74 menu_bar
->Append(file_menu
, _T("&File"));
75 main_frame
->SetMenuBar(menu_bar
);
77 main_frame
->Connect( ID_SET_SIZE_TO_150_150
, wxID_ANY
,
78 wxEVT_COMMAND_MENU_SELECTED
, wxCommandEventHandler(MyMainFrame::OnSetSize_150_150
) );
79 main_frame
->Connect( ID_SET_SIZE_TO_200_200
, wxID_ANY
,
80 wxEVT_COMMAND_MENU_SELECTED
, wxCommandEventHandler(MyMainFrame::OnSetSize_200_200
) );
81 main_frame
->Connect( ID_SET_MAX_SIZE_TO_150_150
, wxID_ANY
,
82 wxEVT_COMMAND_MENU_SELECTED
, wxCommandEventHandler(MyMainFrame::OnSetMaxSize_150_150
) );
83 main_frame
->Connect( ID_SET_MAX_SIZE_TO_300_300
, wxID_ANY
,
84 wxEVT_COMMAND_MENU_SELECTED
, wxCommandEventHandler(MyMainFrame::OnSetMaxSize_300_300
) );
86 main_frame
->CreateToolBar(wxNO_BORDER
|wxTB_VERTICAL
, ID_TOOLBAR
);
87 InitToolbar(main_frame
->GetToolBar());
89 button
= new wxButton( main_frame
, ID_REPARENT
, _T("Press to reparent!") );
91 // Create the mini frame window
92 mini_frame
= new MyMiniFrame( main_frame
, wxID_ANY
, _T("wxMiniFrame sample"),
93 wxPoint(100, 100), wxSize(220, 100));
94 mini_frame_exists
= true;
96 mini_frame
->CreateToolBar(wxNO_BORDER
|wxTB_HORIZONTAL
|wxTB_FLAT
, ID_TOOLBAR
);
97 InitToolbar(mini_frame
->GetToolBar());
99 main_frame
->SetIcon(wxICON(mondrian
));
100 mini_frame
->SetIcon(wxICON(mondrian
));
102 SetTopWindow(main_frame
);
104 main_frame
->Show(true);
105 mini_frame
->Show(true);
110 bool MyApp::InitToolbar(wxToolBar
* toolBar
)
112 toolBar
->SetMargins(5, 5);
115 wxBitmap
* toolBarBitmaps
[8];
117 toolBarBitmaps
[0] = new wxBitmap( new_xpm
);
118 toolBarBitmaps
[1] = new wxBitmap( open_xpm
);
119 toolBarBitmaps
[2] = new wxBitmap( save_xpm
);
120 toolBarBitmaps
[3] = new wxBitmap( copy_xpm
);
121 toolBarBitmaps
[4] = new wxBitmap( cut_xpm
);
122 // toolBarBitmaps[5] = new wxBitmap( paste_xpm );
123 toolBarBitmaps
[5] = new wxBitmap( preview_xpm
);
124 toolBarBitmaps
[6] = new wxBitmap( print_xpm
);
125 toolBarBitmaps
[7] = new wxBitmap( help_xpm
);
130 toolBar
->AddTool(wxID_NEW
, *(toolBarBitmaps
[0]), wxNullBitmap
, false, currentX
, wxDefaultCoord
, (wxObject
*) NULL
, _T("New file"));
131 currentX
+= width
+ 5;
132 toolBar
->AddTool(wxID_OPEN
, *(toolBarBitmaps
[1]), wxNullBitmap
, false, currentX
, wxDefaultCoord
, (wxObject
*) NULL
, _T("Open file"));
133 currentX
+= width
+ 5;
134 toolBar
->AddTool(wxID_SAVE
, *(toolBarBitmaps
[2]), wxNullBitmap
, false, currentX
, wxDefaultCoord
, (wxObject
*) NULL
, _T("Save file"));
135 currentX
+= width
+ 5;
136 toolBar
->AddSeparator();
137 toolBar
->AddTool(wxID_COPY
, *(toolBarBitmaps
[3]), wxNullBitmap
, false, currentX
, wxDefaultCoord
, (wxObject
*) NULL
, _T("Copy"));
138 currentX
+= width
+ 5;
139 toolBar
->AddTool(wxID_CUT
, *(toolBarBitmaps
[4]), wxNullBitmap
, false, currentX
, wxDefaultCoord
, (wxObject
*) NULL
, _T("Cut"));
140 currentX
+= width
+ 5;
141 toolBar
->AddTool(wxID_PASTE
, *(toolBarBitmaps
[5]), wxNullBitmap
, false, currentX
, wxDefaultCoord
, (wxObject
*) NULL
, _T("Paste"));
142 currentX
+= width
+ 5;
143 toolBar
->AddSeparator();
144 toolBar
->AddTool(wxID_PRINT
, *(toolBarBitmaps
[6]), wxNullBitmap
, false, currentX
, wxDefaultCoord
, (wxObject
*) NULL
, _T("Reparent the button"));
145 currentX
+= width
+ 5;
146 toolBar
->AddSeparator();
147 toolBar
->AddTool(wxID_HELP
, *(toolBarBitmaps
[7]), wxNullBitmap
, false, currentX
, wxDefaultCoord
, (wxObject
*) NULL
, _T("Help"));
151 toolBar
->EnableTool( wxID_HELP
, false );
153 // Can delete the bitmaps since they're reference counted
155 for (i
= 0; i
< 8; i
++)
156 delete toolBarBitmaps
[i
];
163 BEGIN_EVENT_TABLE(MyMiniFrame
, wxMiniFrame
)
164 EVT_CLOSE ( MyMiniFrame::OnCloseWindow
)
165 EVT_BUTTON (ID_REPARENT
, MyMiniFrame::OnReparent
)
166 EVT_MENU (wxID_PRINT
, MyMiniFrame::OnReparent
)
169 MyMiniFrame::MyMiniFrame(wxFrame
* parent
, wxWindowID id
, const wxString
& title
, const wxPoint
& pos
,
170 const wxSize
& size
) :
171 wxMiniFrame(parent
, id
, title
, pos
, size
)
175 void MyMiniFrame::OnCloseWindow(wxCloseEvent
& WXUNUSED(event
))
177 // make it known that the miniframe is no more
178 mini_frame_exists
= false;
182 void MyMiniFrame::OnReparent(wxCommandEvent
& WXUNUSED(event
))
184 button
->Reparent( main_frame
);
186 // we need to force the frame to size its (new) child correctly
187 main_frame
->SendSizeEvent();
192 BEGIN_EVENT_TABLE(MyMainFrame
, wxFrame
)
193 EVT_CLOSE ( MyMainFrame::OnCloseWindow
)
194 EVT_BUTTON (ID_REPARENT
, MyMainFrame::OnReparent
)
195 EVT_MENU (wxID_PRINT
, MyMainFrame::OnReparent
)
198 MyMainFrame::MyMainFrame(wxFrame
* parent
, wxWindowID id
, const wxString
& title
, const wxPoint
& pos
,
199 const wxSize
& size
) :
200 wxFrame(parent
, id
, title
, pos
, size
)
204 void MyMainFrame::OnCloseWindow(wxCloseEvent
& WXUNUSED(event
))
209 void MyMainFrame::OnReparent(wxCommandEvent
& WXUNUSED(event
))
211 // practical jokers might find satisfaction in reparenting the button
212 // after closing the mini_frame. We'll have the last laugh.
213 if (! mini_frame_exists
)
214 wxMessageBox(_T("The miniframe no longer exists.\n")
215 _T("You don't want to make this button an orphan, do you?"),
216 _T("You got to be kidding"));
219 button
->Reparent( mini_frame
);
222 mini_frame
->SendSizeEvent();
226 void MyMainFrame::OnSetSize_150_150(wxCommandEvent
& WXUNUSED(event
))
231 void MyMainFrame::OnSetSize_200_200(wxCommandEvent
& WXUNUSED(event
))
236 void MyMainFrame::OnSetMaxSize_150_150(wxCommandEvent
& WXUNUSED(event
))
238 SetSizeHints( -1, -1, 150, 150 );
241 void MyMainFrame::OnSetMaxSize_300_300(wxCommandEvent
& WXUNUSED(event
))
243 SetSizeHints( -1, -1, 300, 300 );