1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Contrib. demo
4 // Author: Aleksandras Gluchovas
8 // Copyright: (c) Aleksandras Gluchovas
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "fl_sample.cpp"
14 #pragma interface "fl_sample.cpp"
17 // For compilers that support precompilation, includes "wx/wx.h".
18 #include "wx/wxprec.h"
28 #include "controlbar.h"
32 #include "barhintspl.h"
33 #include "hintanimpl.h"
35 #include "wx/textctrl.h"
37 // ADDED by alex (linker complaints...):
44 #define LAYOUT_FILE "layouts.dat"
46 class MyApp
: public wxApp
52 class MyFrame
: public wxFrame
55 wxFrameLayout
* mpLayout
;
56 wxWindow
* mpClientWnd
;
57 wxPanel
* mpInternalFrm
;
59 void SerializeMe( wxObjectStorage
& store
);
61 wxTextCtrl
* CreateTextCtrl( const wxString
& value
);
65 MyFrame( wxWindow
* parent
, char *title
);
68 void OnLoad( wxCommandEvent
& event
);
69 void OnStore( wxCommandEvent
& event
);
70 void OnQuit( wxCommandEvent
& event
);
72 bool OnClose(void) { return TRUE
; }
77 /***** Implementation for class MyApp *****/
81 bool MyApp::OnInit(void)
83 // wxWindows boiler-plate:
85 MyFrame
*frame
= new MyFrame(NULL
, "wxFrameLayout sample");
87 wxMenu
*file_menu
= new wxMenu
;
89 file_menu
->Append( ID_LOAD
, "&Load layout" );
90 file_menu
->Append( ID_STORE
, "&Store layout" );
91 file_menu
->AppendSeparator();
93 file_menu
->Append( ID_QUIT
, "E&xit" );
95 wxMenuBar
*menu_bar
= new wxMenuBar
;
97 menu_bar
->Append(file_menu
, "&File");
99 frame
->CreateStatusBar(3);
100 frame
->SetMenuBar(menu_bar
);
109 /***** Immlementation for class MyFrame *****/
111 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
113 EVT_MENU( ID_LOAD
, MyFrame::OnLoad
)
114 EVT_MENU( ID_STORE
, MyFrame::OnStore
)
115 EVT_MENU( ID_QUIT
, MyFrame::OnQuit
)
119 MyFrame::MyFrame( wxWindow
* parent
, char *title
)
121 : wxFrame( parent
, -1, "NewTest-II", wxDefaultPosition
,
123 wxCLIP_CHILDREN
| wxMINIMIZE_BOX
| wxMAXIMIZE_BOX
|
124 wxTHICK_FRAME
| wxSYSTEM_MENU
| wxCAPTION
,
128 mpInternalFrm
= (wxPanel
*)this;
130 mpInternalFrm
= new wxPanel( this, -1 );
133 mpClientWnd
= CreateTextCtrl( "Client window" );
135 // btw, creation of internal frame is needed for wxGtk version
136 // to act correctly (since menu-bar is a separate window there..)
138 mpLayout
= new wxFrameLayout( mpInternalFrm
, mpClientWnd
);
142 // real-time dosn't work well under wxGtk yet
143 cbCommonPaneProperties props
;
144 mpLayout
->GetPaneProperties( props
);
146 props
.mRealTimeUpdatesOn
= FALSE
; // off
148 mpLayout
->SetPaneProperties( props
, wxALL_PANES
);
152 mpLayout
->PushDefaultPlugins();
153 mpLayout
->AddPlugin( CLASSINFO( cbBarHintsPlugin
) ); // facny "X"es and beveal for barso
154 //mpLayout->AddPlugin( CLASSINFO( cbHintAnimationPlugin ) );
156 cbDimInfo
sizes( 80,65, // when docked horizontally
157 80,65, // when docked vertically
158 80,30, // when floated
159 TRUE
, // the bar is fixed-size
160 5, // vertical gap (bar border)
161 5 // horizontal gap (bar border)
166 for( int i
= 1; i
<= 10; ++i
)
169 sprintf( buf
, "%d", i
);
170 wxString name
= wxString("Bar-");
173 sizes
.mIsFixed
= i
% 5 > 0; // every fifth bar is not fixed-size
175 if ( !sizes
.mIsFixed
) name
+= " (flexible)";
177 mpLayout
->AddBar( CreateTextCtrl(name
),// bar window
178 sizes
, i
% MAX_PANES
,// alignment ( 0-top,1-bottom, etc)
179 0, // insert into 0th row (vert. position)
180 0, // offset from the start of row (in pixels)
181 name
// name to refere in customization pop-ups
188 // layout is not a window, should be released manually
190 if ( mpLayout
) delete mpLayout
;
193 wxTextCtrl
* MyFrame::CreateTextCtrl( const wxString
& value
)
197 new wxTextCtrl( mpInternalFrm
, -1, value
,
198 wxPoint(0,0), wxSize(1,1), wxTE_MULTILINE
);
200 pCtrl
->SetBackgroundColour( wxColour( 255,255,255 ) );
205 void MyFrame::OnLoad( wxCommandEvent
& event
)
207 if ( !wxFileExists( LAYOUT_FILE
) )
209 wxMessageBox( "layout data file `layout.dat' not found\n\n store layout first" );
214 mpLayout
->HideBarWindows(); // hide first, to avoid flickered destruction
215 mpLayout
->DestroyBarWindows();
219 mpClientWnd
->Destroy();
225 wxIOStreamWrapper stm
;
226 stm
.CreateForInput( LAYOUT_FILE
); // TRUE - create stream for input
228 wxObjectStorage
store( stm
);
230 SerializeMe( store
);
232 mpLayout
->Activate();
235 void MyFrame::OnStore( wxCommandEvent
& event
)
237 wxIOStreamWrapper stm
;
238 stm
.CreateForOutput( LAYOUT_FILE
); // FALSE - create stream for output
240 wxObjectStorage
store( stm
);
242 SerializeMe( store
);
245 void MyFrame::OnQuit( wxCommandEvent
& event
)
247 Show( FALSE
); // TRICK:: hide it, to avoid flickered destruction
252 void MyFrame::SerializeMe( wxObjectStorage
& store
)
254 // mark contaienr-frames as not serializable
256 store
.AddInitialRef( mpInternalFrm
);
257 store
.AddInitialRef( this );
259 // does all the rest for as
261 store
.XchgObjPtr( (wxObject
**) &(mpLayout
) );
262 store
.XchgObjPtr( (wxObject
**) &(mpClientWnd
) );
264 store
.Finalize(); // finish serialization
267 #ifdef __HACK_MY_MSDEV40__
269 ////////////// new 2.0-magic (linker errors...) ////////////////
271 wxToolBar
* wxFrame::CreateToolBar(long style
, wxWindowID id
, const wxString
& name
)
273 wxCHECK_MSG( m_frameToolBar
== NULL
, FALSE
,
274 "recreating toolbar in wxFrame" );
276 wxToolBar
* toolBar
= OnCreateToolBar(style
, id
, name
);
289 wxToolBar
* wxFrame::OnCreateToolBar(long style
, wxWindowID id
, const wxString
& name
)
291 return new wxToolBar(this, id
, wxDefaultPosition
, wxDefaultSize
, style
, name
);