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