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)
51 #ifndef wxDUMMY_OBJ_INCLUDED
58 bool MyApp::OnInit(void)
60 MyFrame
*frame
= new MyFrame(NULL
);
62 frame
->SetBackgroundColour( wxColour(192,192,192) );
64 wxMenu
*file_menu
= new wxMenu
;
66 file_menu
->Append( NEW_TEST_LOAD
, "&Load layouts" );
67 file_menu
->Append( NEW_TEST_SAVE
, "&Store layouts" );
68 file_menu
->Append( NEW_TEST_EXIT
, "E&xit" );
70 wxMenuBar
*menu_bar
= new wxMenuBar
;
72 menu_bar
->Append(file_menu
, "&File");
74 frame
->SetMenuBar(menu_bar
);
76 frame
->CreateStatusBar(3);
80 frame
->mpClientWnd
->Refresh();
87 wxMessageBox("Hello, this demo has a bunch of yet-not-fixed-bugs and misssing functionality\n\
88 The ONLY purpose is to demostrate self-layouting toolbars,\n flat-bitmapped-buttons and 2-new FL-plugins\
89 (cbRowDragPlugin & cbBarHintsPlugin)\n\n\
90 BTW, disabled images and label-text are rendered at run-time" );
97 /***** Implementation for class MyFrame *****/
99 BEGIN_EVENT_TABLE( MyFrame
, wxFrame
)
101 // EVT_CHAR_HOOK(MyFrame::OnKeyDown)
102 // EVT_PAINT( MyFrame::OnPaint )
103 EVT_MENU( NEW_TEST_SAVE
, MyFrame::OnSave
)
104 EVT_MENU( NEW_TEST_LOAD
, MyFrame::OnLoad
)
105 EVT_MENU( NEW_TEST_EXIT
, MyFrame::OnExit
)
109 void MyFrame::OnLoad( wxCommandEvent
& event
)
111 mpLayout
->HideBarWindows();
112 mpLayout
->DestroyBarWindows();
117 mpClientWnd
->Destroy();
123 wxIOStreamWrapper
& stm
= *(new wxIOStreamWrapper());
125 stm
.CreateForInput( "layouts1.dat" );
127 mStore
.SetDataStream( stm
);
129 mStore
.XchgObjPtr( (wxObject
**) &mpLayout
);
131 mStore
.Finalize(); // finish serialization
133 mpLayout
->Activate();
136 void MyFrame::OnSave( wxCommandEvent
& event
)
138 wxIOStreamWrapper
& stm
= *(new wxIOStreamWrapper());
140 stm
.CreateForOutput( "layouts1.dat" );
142 mStore
.SetDataStream( stm
);
144 mStore
.XchgObjPtr( (wxObject
**) &mpLayout
);
146 mStore
.Finalize(); // finish serialization
149 void MyFrame::OnExit( wxCommandEvent
& event
)
154 wxTextCtrl
* MyFrame::CreateTextCtrl( const wxString
& value
)
158 new wxTextCtrl( mpInternalFrm
, -1, value
,
159 wxDefaultPosition
, wxSize(0,0), wxTE_MULTILINE
);
161 pCtrl
->SetBackgroundColour( wxColour( 255,255,255 ) );
166 MyFrame::MyFrame(wxFrame
*frame
)
168 : wxFrame( frame
, -1, "wxWindows 2.0 wxFrameLayout Test Application", wxDefaultPosition
,
170 wxCLIP_CHILDREN
| wxMINIMIZE_BOX
| wxMAXIMIZE_BOX
|
171 wxTHICK_FRAME
| wxSYSTEM_MENU
| wxCAPTION
,
175 mpInternalFrm
= (wxPanel
*)this;
177 mpInternalFrm
= new wxPanel( this, -1 );
181 mpClientWnd
= CreateTextCtrl( "Client window" );
183 mStore
.AddInitialRef( this );
184 mStore
.AddInitialRef( mpInternalFrm
);
185 //mStore.AddInitialRef( mpClientWnd );
187 mpLayout
= new wxFrameLayout( mpInternalFrm
, mpClientWnd
);
192 cbCommonPaneProperties props
;
193 mpLayout
->GetPaneProperties( props
);
195 props
.mRealTimeUpdatesOn
= FALSE
; // real-time OFF!!!
197 mpLayout
->SetPaneProperties( props
, wxALL_PANES
);
201 mpLayout
->SetUpdatesManager( new cbGCUpdatesMgr() );
203 // this is now default...
204 //mpLayout->SetMargins( 1,1,1,1 ); // gaps for vertical/horizontal/right/left panes
206 // setup plugins for testing
208 mpLayout
->PushDefaultPlugins();
210 mpLayout
->AddPlugin( CLASSINFO( cbBarHintsPlugin
) ); // facny "X"es and beveal for bars
212 mpLayout
->AddPlugin( CLASSINFO( cbHintAnimationPlugin
) );
213 mpLayout
->AddPlugin( CLASSINFO( cbRowDragPlugin
) );
214 mpLayout
->AddPlugin( CLASSINFO( cbAntiflickerPlugin
) );
215 mpLayout
->AddPlugin( CLASSINFO( cbSimpleCustomizationPlugin
) );
219 cbDimInfo
sizes0(200,45, // when docked horizontally
220 200,85, // when docked vertically
221 175,35, // when floated
222 FALSE
, // the bar is not fixed-size
223 4, // vertical gap (bar border)
224 4 // horizontal gap (bar border)
227 cbDimInfo
sizes1(150,35, // when docked horizontally
228 150,85, // when docked vertically
229 175,35, // when floated
230 TRUE
, // the bar is not fixed-size
231 4, // vertical gap (bar border)
232 4 // horizontal gap (bar border)
235 cbDimInfo
sizes2(175,45, // when docked horizontally
236 175,37, // when docked vertically
237 170,35, // when floated
238 TRUE
, // the bar is not fixed-size
239 4, // vertical gap (bar border)
240 4, // horizontal gap (bar border)
241 new cbDynToolBarDimHandler()
244 mpLayout
->AddBar( CreateTextCtrl("Hello"), // bar window
245 sizes0
, wxTOP
, // alignment ( 0-top,1-bottom, etc)
246 0, // insert into 0th row (vert. position)
247 0, // offset from the start of row (in pixels)
248 "InfoViewer1", // name to refere in customization pop-ups
252 mpLayout
->AddBar( CreateTextCtrl("Bye"), // bar window
253 sizes0
, wxTOP
, // alignment ( 0-top,1-bottom, etc)
254 1, // insert into 0th row (vert. position)
255 0, // offset from the start of row (in pixels)
256 "InfoViewer2", // name to refere in customization pop-ups
260 mpLayout
->AddBar( CreateTextCtrl("Fixed0"), // bar window
261 sizes1
, wxTOP
, // alignment ( 0-top,1-bottom, etc)
262 0, // insert into 0th row (vert. position)
263 0, // offset from the start of row (in pixels)
264 "ToolBar1", // name to refere in customization pop-ups
268 wxDynamicToolBar
* pToolBar
= new wxDynamicToolBar();
270 pToolBar
->Create( mpInternalFrm
, -1 );
272 // 1001-1006 ids of command events fired by added tool-buttons
274 pToolBar
->AddTool( 1001, "new.bmp" );
275 pToolBar
->AddTool( 1002, "open.bmp" );
276 pToolBar
->AddTool( 1003, "save.bmp" );
278 pToolBar
->AddTool( 1004, "cut.bmp" );
279 pToolBar
->AddTool( 1005, "copy.bmp" );
280 pToolBar
->AddTool( 1006, "paste.bmp" );
283 mpLayout
->AddBar( pToolBar
, // bar window (can be NULL)
284 sizes2
, wxTOP
, // alignment ( 0-top,1-bottom, etc)
285 0, // insert into 0th row (vert. position)
286 0, // offset from the start of row (in pixels)
287 "ToolBar2", // name to refere in customization pop-ups
291 mpLayout
->EnableFloating( TRUE
); // off, thinking bout wxGtk...
296 if ( mpLayout
) delete mpLayout
; // should be destroyed manually
299 #ifdef __HACK_MY_MSDEV40__
301 ////////////// new 2.0-magic (linker errors...) ////////////////
303 wxToolBar
* wxFrame::CreateToolBar(long style
, wxWindowID id
, const wxString
& name
)
305 wxCHECK_MSG( m_frameToolBar
== NULL
, FALSE
,
306 "recreating toolbar in wxFrame" );
308 wxToolBar
* toolBar
= OnCreateToolBar(style
, id
, name
);
321 wxToolBar
* wxFrame::OnCreateToolBar(long style
, wxWindowID id
, const wxString
& name
)
323 return new wxToolBar(this, id
, wxDefaultPosition
, wxDefaultSize
, style
, name
);