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