]> git.saurik.com Git - wxWidgets.git/blob - contrib/samples/fl/fl_demo1.cpp
define _HPUX_SOURCE under HP-UX, otherwise many things are not defined in standard...
[wxWidgets.git] / contrib / samples / fl / fl_demo1.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: No names yet.
3 // Purpose: Contrib. demo
4 // Author: Aleksandras Gluchovas
5 // Modified by: Sebastian Haase (June 21, 2001)
6 // Created: 04/11/98
7 // RCS-ID: $Id$
8 // Copyright: (c) Aleksandras Gluchovas
9 // Licence: wxWindows license
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/textctrl.h"
24
25 // fl headers
26 #include "wx/fl/controlbar.h" // core API
27
28 // extra plugins
29 #include "wx/fl/barhintspl.h" // bevel for bars with "X"s and grooves
30 #include "wx/fl/rowdragpl.h" // NC-look with draggable rows
31 #include "wx/fl/cbcustom.h" // customization plugin
32 #include "wx/fl/hintanimpl.h"
33
34 // beauty-care
35 #include "wx/fl/gcupdatesmgr.h" // smooth d&d
36 #include "wx/fl/antiflickpl.h" // double-buffered repaint of decorations
37 #include "wx/fl/dyntbar.h" // auto-layout toolbar
38 #include "wx/fl/dyntbarhnd.h" // control-bar dimension handler for it
39
40 #include "fl_demo1.h"
41
42 // comment it out if it breaks, (this is my workaround for MSDev 4.0 linker)
43
44 char wxDummyChar;
45
46
47 IMPLEMENT_APP (MyApp)
48
49 bool MyApp::OnInit(void)
50 {
51 MyFrame *frame = new MyFrame(NULL);
52
53 frame->SetBackgroundColour( wxColour(192,192,192) );
54
55 wxMenu *file_menu = new wxMenu;
56
57 file_menu->Append( NEW_TEST_LOAD, _("&Load layouts") );
58 file_menu->Append( NEW_TEST_SAVE, _("&Store layouts") );
59 file_menu->Append( NEW_TEST_EXIT, _("E&xit") );
60
61 wxMenuBar *menu_bar = new wxMenuBar;
62
63 menu_bar->Append(file_menu, _("&File"));
64
65 frame->SetMenuBar(menu_bar);
66
67 #if wxUSE_STATUSBAR
68 frame->CreateStatusBar(3);
69 #endif // wxUSE_STATUSBAR
70
71 frame->Show(true);
72
73 frame->mpClientWnd->Refresh();
74
75 SetTopWindow(frame);
76
77
78 wxMessageBox(_("Hello, this demo has a bunch of yet-not-fixed-bugs and missing functionality\n\
79 The ONLY purpose is to demonstrate self-layouting toolbars,\nflat-bitmapped-buttons and 2-new FL-plugins \
80 (cbRowDragPlugin & cbBarHintsPlugin)\n\n\
81 BTW, disabled images and label-text are rendered at run-time") );
82
83 return true;
84 }
85
86 /***** Implementation for class MyFrame *****/
87
88 BEGIN_EVENT_TABLE( MyFrame, wxFrame )
89 // EVT_CHAR_HOOK(MyFrame::OnKeyDown)
90 // EVT_PAINT( MyFrame::OnPaint )
91 EVT_MENU( NEW_TEST_SAVE, MyFrame::OnSave )
92 EVT_MENU( NEW_TEST_LOAD, MyFrame::OnLoad )
93 EVT_MENU( NEW_TEST_EXIT, MyFrame::OnExit )
94 END_EVENT_TABLE()
95
96 void MyFrame::OnLoad( wxCommandEvent& WXUNUSED(event) )
97 {
98 wxMessageBox(_T("Hey - you found a BIG question-mark !!"));
99 }
100
101 void MyFrame::OnSave( wxCommandEvent& WXUNUSED(event) )
102 {
103 wxMessageBox(_("Hey - you found another BIG question-mark !!"));
104 }
105
106 void MyFrame::OnExit( wxCommandEvent& WXUNUSED(event) )
107 {
108 Destroy();
109 }
110
111 wxTextCtrl* MyFrame::CreateTextCtrl( const wxString& value )
112 {
113 wxTextCtrl* pCtrl =
114
115 new wxTextCtrl( this, wxID_ANY, value,
116 wxDefaultPosition, wxSize(0,0), wxTE_MULTILINE );
117
118 pCtrl->SetBackgroundColour( wxColour( 255,255,255 ) );
119
120 return pCtrl;
121 }
122
123 MyFrame::MyFrame(wxFrame *frame)
124 : wxFrame( frame, wxID_ANY, _("wxWidgets 2.0 wxFrameLayout Test Application"), wxDefaultPosition,
125 wxSize( 700, 500 ),
126 wxCLIP_CHILDREN | wxMINIMIZE_BOX | wxMAXIMIZE_BOX |
127 wxTHICK_FRAME | wxSYSTEM_MENU | wxCAPTION | wxCLOSE_BOX,
128 wxT("freimas") )
129 {
130 mpClientWnd = CreateTextCtrl( _("Client window") );
131
132 mpLayout = new wxFrameLayout( this, mpClientWnd );
133
134 #if defined(__WXGTK__) || defined(__WXX11__)
135 cbCommonPaneProperties props;
136 mpLayout->GetPaneProperties( props );
137
138 props.mRealTimeUpdatesOn = false; // real-time OFF!!!
139
140 mpLayout->SetPaneProperties( props, wxALL_PANES );
141 #endif
142
143 mpLayout->SetUpdatesManager( new cbGCUpdatesMgr() );
144
145 // this is now default...
146 //mpLayout->SetMargins( 1,1,1,1 ); // gaps for vertical/horizontal/right/left panes
147
148 // setup plugins for testing
149 mpLayout->PushDefaultPlugins();
150
151 mpLayout->AddPlugin( CLASSINFO( cbBarHintsPlugin ) ); // fancy "X"es and bevel for bars
152 mpLayout->AddPlugin( CLASSINFO( cbHintAnimationPlugin ) );
153 mpLayout->AddPlugin( CLASSINFO( cbRowDragPlugin ) );
154 mpLayout->AddPlugin( CLASSINFO( cbAntiflickerPlugin ) );
155 mpLayout->AddPlugin( CLASSINFO( cbSimpleCustomizationPlugin ) );
156
157 // drop in some bars
158 cbDimInfo sizes0( 200,45, // when docked horizontally
159 200,85, // when docked vertically
160 175,35, // when floated
161 false, // the bar is not fixed-size
162 4, // vertical gap (bar border)
163 4 // horizontal gap (bar border)
164 );
165
166 cbDimInfo sizes1( 150,35, // when docked horizontally
167 150,85, // when docked vertically
168 175,35, // when floated
169 true, // the bar is not fixed-size
170 4, // vertical gap (bar border)
171 4 // horizontal gap (bar border)
172 );
173
174 cbDimInfo sizes2( 195,35, // when docked horizontally
175 185,37, // when docked vertically
176 195,35, // when floated
177 true, // the bar is not fixed-size
178 4, // vertical gap (bar border)
179 4, // horizontal gap (bar border)
180 new cbDynToolBarDimHandler()
181 );
182
183 mpLayout->AddBar( CreateTextCtrl(_("Hello")), // bar window
184 sizes0, FL_ALIGN_TOP, // alignment ( 0-top,1-bottom, etc)
185 0, // insert into 0th row (vert. position)
186 0, // offset from the start of row (in pixels)
187 _("InfoViewer1"), // name to refer in customization pop-ups
188 true
189 );
190
191 mpLayout->AddBar( CreateTextCtrl(_("Bye")), // bar window
192 sizes0, FL_ALIGN_TOP, // alignment ( 0-top,1-bottom, etc)
193 1, // insert into 0th row (vert. position)
194 0, // offset from the start of row (in pixels)
195 _("InfoViewer2"), // name to refer in customization pop-ups
196 true
197 );
198
199 mpLayout->AddBar( CreateTextCtrl(_("Fixed0")), // bar window
200 sizes1, FL_ALIGN_TOP, // alignment ( 0-top,1-bottom, etc)
201 0, // insert into 0th row (vert. position)
202 0, // offset from the start of row (in pixels)
203 _("ToolBar1"), // name to refer in customization pop-ups
204 true
205 );
206
207 wxDynamicToolBar* pToolBar = new wxDynamicToolBar();
208
209 pToolBar->Create( this, wxID_ANY );
210
211 // 1001-1006 ids of command events fired by added tool-buttons
212
213 pToolBar->AddTool( 1001, wxString(wxT(BMP_DIR)) + wxT("new.bmp") );
214 pToolBar->AddSeparator();
215 pToolBar->AddTool( 1002, wxString(wxT(BMP_DIR)) + wxT("open.bmp") );
216 pToolBar->AddTool( 1003, wxString(wxT(BMP_DIR)) + wxT("save.bmp") );
217 #if wxUSE_STATLINE
218 pToolBar->AddSeparator(new wxMySeparatorLine(pToolBar, wxID_ANY));
219 #endif // wxUSE_STATLINE
220 pToolBar->AddTool( 1004, wxString(wxT(BMP_DIR)) + wxT("cut.bmp") );
221 pToolBar->AddTool( 1005, wxString(wxT(BMP_DIR)) + wxT("copy.bmp") );
222 pToolBar->AddTool( 1006, wxString(wxT(BMP_DIR)) + wxT("paste.bmp") );
223
224
225 mpLayout->AddBar( pToolBar, // bar window (can be NULL)
226 sizes2, FL_ALIGN_TOP, // alignment ( 0-top,1-bottom, etc)
227 0, // insert into 0th row (vert. position)
228 0, // offset from the start of row (in pixels)
229 wxT("ToolBar2"), // name to refer in customization pop-ups
230 false
231 );
232
233 mpLayout->EnableFloating( true ); // off, thinking about wxGtk...
234 }
235
236 MyFrame::~MyFrame()
237 {
238 if ( mpLayout)
239 delete mpLayout; // should be destroyed manually
240 }
241
242 #define LINE_SIZE 3
243 #if wxUSE_STATLINE
244 void wxMySeparatorLine::DoSetSize( int x, int y,
245 int width, int height,
246 int sizeFlags)
247 {
248 if (width < height)
249 {
250 x += (width - LINE_SIZE) / 2;
251 width = LINE_SIZE;
252 }
253 else
254 {
255 y += (height - LINE_SIZE) / 2;
256 height = LINE_SIZE;
257 }
258
259 wxStaticLine::DoSetSize(x, y, width, height, sizeFlags);
260 }
261 #endif // wxUSE_STATLINE