1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Minimal wxWindows sample
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
14 #pragma implementation "minimal.cpp"
15 #pragma interface "minimal.cpp"
18 // For compilers that support precompilation, includes "wx/wx.h".
19 #include "wx/wxprec.h"
31 #include "wx/textctrl.h"
33 #include "controlbar.h" // core API
37 #include "barhintspl.h" // beveal for bars with "X"s and grooves
38 #include "rowdragpl.h" // NC-look with dragable rows
39 #include "cbcustom.h" // customization plugin
40 #include "hintanimpl.h"
43 #include "gcupdatesmgr.h" // smooth d&d
44 #include "antiflickpl.h" // double-buffered repaint of decorations
46 #include "dyntbar.h" // auto-layouting toolbar
47 #include "dyntbarhnd.h" // control-bar dimension handler for it
49 // comment it out if it breaks, (this is my workaround for MSDev 4.0 linker)
56 bool MyApp::OnInit(void)
58 MyFrame
*frame
= new MyFrame(NULL
);
60 frame
->SetBackgroundColour( wxColour(192,192,192) );
62 wxMenu
*file_menu
= new wxMenu
;
64 file_menu
->Append( NEW_TEST_LOAD
, "&Load layouts" );
65 file_menu
->Append( NEW_TEST_SAVE
, "&Store layouts" );
66 file_menu
->Append( NEW_TEST_EXIT
, "E&xit" );
68 wxMenuBar
*menu_bar
= new wxMenuBar
;
70 menu_bar
->Append(file_menu
, "&File");
72 frame
->SetMenuBar(menu_bar
);
74 frame
->CreateStatusBar(3);
78 frame
->mpClientWnd
->Refresh();
85 wxMessageBox("Hello, this demo has a bunch of yet-not-fixed-bugs and misssing functionality\n\
86 The ONLY purpose is to demostrate self-layouting toolbars,\n flat-bitmapped-buttons and 2-new FL-plugins\
87 (cbRowDragPlugin & cbBarHintsPlugin)\n\n\
88 BTW, disabled images and label-text are rendered at run-time" );
95 /***** Implementation for class MyFrame *****/
97 BEGIN_EVENT_TABLE( MyFrame
, wxFrame
)
99 // EVT_CHAR_HOOK(MyFrame::OnKeyDown)
100 // EVT_PAINT( MyFrame::OnPaint )
101 EVT_MENU( NEW_TEST_SAVE
, MyFrame::OnSave
)
102 EVT_MENU( NEW_TEST_LOAD
, MyFrame::OnLoad
)
103 EVT_MENU( NEW_TEST_EXIT
, MyFrame::OnExit
)
107 void MyFrame::OnLoad( wxCommandEvent
& event
)
109 mpLayout
->HideBarWindows();
110 mpLayout
->DestroyBarWindows();
115 mpClientWnd
->Destroy();
121 wxIOStreamWrapper
& stm
= *(new wxIOStreamWrapper());
123 stm
.CreateForInput( "layouts1.dat" );
125 mStore
.SetDataStream( stm
);
127 mStore
.XchgObjPtr( (wxObject
**) &mpLayout
);
129 mStore
.Finalize(); // finish serialization
131 mpLayout
->Activate();
134 void MyFrame::OnSave( wxCommandEvent
& event
)
136 wxIOStreamWrapper
& stm
= *(new wxIOStreamWrapper());
138 stm
.CreateForOutput( "layouts1.dat" );
140 mStore
.SetDataStream( stm
);
142 mStore
.XchgObjPtr( (wxObject
**) &mpLayout
);
144 mStore
.Finalize(); // finish serialization
147 void MyFrame::OnExit( wxCommandEvent
& event
)
152 wxTextCtrl
* MyFrame::CreateTextCtrl( const wxString
& value
)
156 new wxTextCtrl( mpInternalFrm
, -1, value
,
157 wxDefaultPosition
, wxSize(0,0), wxTE_MULTILINE
);
159 pCtrl
->SetBackgroundColour( wxColour( 255,255,255 ) );
164 MyFrame::MyFrame(wxFrame
*frame
)
166 : wxFrame( frame
, -1, "wxWindows 2.0 wxFrameLayout Test Application", wxDefaultPosition
,
168 wxCLIP_CHILDREN
| wxMINIMIZE_BOX
| wxMAXIMIZE_BOX
|
169 wxTHICK_FRAME
| wxSYSTEM_MENU
| wxCAPTION
,
173 mpInternalFrm
= (wxPanel
*)this;
175 mpInternalFrm
= new wxPanel( this, -1 );
179 mpClientWnd
= CreateTextCtrl( "Client window" );
181 mStore
.AddInitialRef( this );
182 mStore
.AddInitialRef( mpInternalFrm
);
183 //mStore.AddInitialRef( mpClientWnd );
185 mpLayout
= new wxFrameLayout( mpInternalFrm
, mpClientWnd
);
190 cbCommonPaneProperties props
;
191 mpLayout
->GetPaneProperties( props
);
193 props
.mRealTimeUpdatesOn
= FALSE
; // real-time OFF!!!
195 mpLayout
->SetPaneProperties( props
, wxALL_PANES
);
199 mpLayout
->SetUpdatesManager( new cbGCUpdatesMgr() );
201 // this is now default...
202 //mpLayout->SetMargins( 1,1,1,1 ); // gaps for vertical/horizontal/right/left panes
204 // setup plugins for testing
206 mpLayout
->PushDefaultPlugins();
208 mpLayout
->AddPlugin( CLASSINFO( cbBarHintsPlugin
) ); // facny "X"es and beveal for bars
210 mpLayout
->AddPlugin( CLASSINFO( cbHintAnimationPlugin
) );
211 mpLayout
->AddPlugin( CLASSINFO( cbRowDragPlugin
) );
212 mpLayout
->AddPlugin( CLASSINFO( cbAntiflickerPlugin
) );
213 mpLayout
->AddPlugin( CLASSINFO( cbSimpleCustomizationPlugin
) );
217 cbDimInfo
sizes0(200,45, // when docked horizontally
218 200,85, // when docked vertically
219 175,35, // when floated
220 FALSE
, // the bar is not fixed-size
221 4, // vertical gap (bar border)
222 4 // horizontal gap (bar border)
225 cbDimInfo
sizes1(150,35, // when docked horizontally
226 150,85, // when docked vertically
227 175,35, // when floated
228 TRUE
, // the bar is not fixed-size
229 4, // vertical gap (bar border)
230 4 // horizontal gap (bar border)
233 cbDimInfo
sizes2(175,45, // when docked horizontally
234 175,37, // when docked vertically
235 170,35, // when floated
236 TRUE
, // the bar is not fixed-size
237 4, // vertical gap (bar border)
238 4, // horizontal gap (bar border)
239 new cbDynToolBarDimHandler()
242 mpLayout
->AddBar( CreateTextCtrl("Hello"), // bar window
243 sizes0
, wxTOP
, // alignment ( 0-top,1-bottom, etc)
244 0, // insert into 0th row (vert. position)
245 0, // offset from the start of row (in pixels)
246 "InfoViewer1", // name to refere in customization pop-ups
250 mpLayout
->AddBar( CreateTextCtrl("Bye"), // bar window
251 sizes0
, wxTOP
, // alignment ( 0-top,1-bottom, etc)
252 1, // insert into 0th row (vert. position)
253 0, // offset from the start of row (in pixels)
254 "InfoViewer2", // name to refere in customization pop-ups
258 mpLayout
->AddBar( CreateTextCtrl("Fixed0"), // bar window
259 sizes1
, wxTOP
, // alignment ( 0-top,1-bottom, etc)
260 0, // insert into 0th row (vert. position)
261 0, // offset from the start of row (in pixels)
262 "ToolBar1", // name to refere in customization pop-ups
266 wxDynamicToolBar
* pToolBar
= new wxDynamicToolBar();
268 pToolBar
->Create( mpInternalFrm
, -1 );
270 // 1001-1006 ids of command events fired by added tool-buttons
272 pToolBar
->AddTool( 1001, "new.bmp" );
273 pToolBar
->AddTool( 1002, "open.bmp" );
274 pToolBar
->AddTool( 1003, "save.bmp" );
276 pToolBar
->AddTool( 1004, "cut.bmp" );
277 pToolBar
->AddTool( 1005, "copy.bmp" );
278 pToolBar
->AddTool( 1006, "paste.bmp" );
281 mpLayout
->AddBar( pToolBar
, // bar window (can be NULL)
282 sizes2
, wxTOP
, // alignment ( 0-top,1-bottom, etc)
283 0, // insert into 0th row (vert. position)
284 0, // offset from the start of row (in pixels)
285 "ToolBar2", // name to refere in customization pop-ups
289 mpLayout
->EnableFloating( TRUE
); // off, thinking bout wxGtk...
294 if ( mpLayout
) delete mpLayout
; // should be destroyed manually
297 #ifdef __HACK_MY_MSDEV40__
299 ////////////// new 2.0-magic (linker errors...) ////////////////
301 wxToolBar
* wxFrame::CreateToolBar(long style
, wxWindowID id
, const wxString
& name
)
303 wxCHECK_MSG( m_frameToolBar
== NULL
, FALSE
,
304 "recreating toolbar in wxFrame" );
306 wxToolBar
* toolBar
= OnCreateToolBar(style
, id
, name
);
319 wxToolBar
* wxFrame::OnCreateToolBar(long style
, wxWindowID id
, const wxString
& name
)
321 return new wxToolBar(this, id
, wxDefaultPosition
, wxDefaultSize
, style
, name
);