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...):
38 #ifndef wxDUMMY_OBJ_INCLUDED
46 #define LAYOUT_FILE "layouts.dat"
48 class MyApp
: public wxApp
54 class MyFrame
: public wxFrame
57 wxFrameLayout
* mpLayout
;
58 wxWindow
* mpClientWnd
;
59 wxPanel
* mpInternalFrm
;
61 void SerializeMe( wxObjectStorage
& store
);
63 wxTextCtrl
* CreateTextCtrl( const wxString
& value
);
67 MyFrame( wxWindow
* parent
, char *title
);
70 void OnLoad( wxCommandEvent
& event
);
71 void OnStore( wxCommandEvent
& event
);
72 void OnQuit( wxCommandEvent
& event
);
74 bool OnClose(void) { return TRUE
; }
79 /***** Implementation for class MyApp *****/
83 bool MyApp::OnInit(void)
85 // wxWindows boiler-plate:
87 MyFrame
*frame
= new MyFrame(NULL
, "wxFrameLayout sample");
89 wxMenu
*file_menu
= new wxMenu
;
91 file_menu
->Append( ID_LOAD
, "&Load layout" );
92 file_menu
->Append( ID_STORE
, "&Store layout" );
93 file_menu
->AppendSeparator();
95 file_menu
->Append( ID_QUIT
, "E&xit" );
97 wxMenuBar
*menu_bar
= new wxMenuBar
;
99 menu_bar
->Append(file_menu
, "&File");
101 frame
->CreateStatusBar(3);
102 frame
->SetMenuBar(menu_bar
);
111 /***** Immlementation for class MyFrame *****/
113 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
115 EVT_MENU( ID_LOAD
, MyFrame::OnLoad
)
116 EVT_MENU( ID_STORE
, MyFrame::OnStore
)
117 EVT_MENU( ID_QUIT
, MyFrame::OnQuit
)
121 MyFrame::MyFrame( wxWindow
* parent
, char *title
)
123 : wxFrame( parent
, -1, "NewTest-II", wxDefaultPosition
,
125 wxCLIP_CHILDREN
| wxMINIMIZE_BOX
| wxMAXIMIZE_BOX
|
126 wxTHICK_FRAME
| wxSYSTEM_MENU
| wxCAPTION
,
130 mpInternalFrm
= (wxPanel
*)this;
132 mpInternalFrm
= new wxPanel( this, -1 );
135 mpClientWnd
= CreateTextCtrl( "Client window" );
137 // btw, creation of internal frame is needed for wxGtk version
138 // to act correctly (since menu-bar is a separate window there..)
140 mpLayout
= new wxFrameLayout( mpInternalFrm
, mpClientWnd
);
144 // real-time dosn't work well under wxGtk yet
145 cbCommonPaneProperties props
;
146 mpLayout
->GetPaneProperties( props
);
148 props
.mRealTimeUpdatesOn
= FALSE
; // off
150 mpLayout
->SetPaneProperties( props
, wxALL_PANES
);
154 mpLayout
->PushDefaultPlugins();
155 mpLayout
->AddPlugin( CLASSINFO( cbBarHintsPlugin
) ); // facny "X"es and beveal for barso
156 //mpLayout->AddPlugin( CLASSINFO( cbHintAnimationPlugin ) );
158 cbDimInfo
sizes( 80,65, // when docked horizontally
159 80,65, // when docked vertically
160 80,30, // when floated
161 TRUE
, // the bar is fixed-size
162 5, // vertical gap (bar border)
163 5 // horizontal gap (bar border)
168 for( int i
= 1; i
<= 10; ++i
)
171 sprintf( buf
, "%d", i
);
172 wxString name
= wxString("Bar-");
175 sizes
.mIsFixed
= i
% 5 > 0; // every fifth bar is not fixed-size
177 if ( !sizes
.mIsFixed
) name
+= " (flexible)";
179 mpLayout
->AddBar( CreateTextCtrl(name
),// bar window
180 sizes
, i
% MAX_PANES
,// alignment ( 0-top,1-bottom, etc)
181 0, // insert into 0th row (vert. position)
182 0, // offset from the start of row (in pixels)
183 name
// name to refere in customization pop-ups
190 // layout is not a window, should be released manually
192 if ( mpLayout
) delete mpLayout
;
195 wxTextCtrl
* MyFrame::CreateTextCtrl( const wxString
& value
)
199 new wxTextCtrl( mpInternalFrm
, -1, value
,
200 wxPoint(0,0), wxSize(1,1), wxTE_MULTILINE
);
202 pCtrl
->SetBackgroundColour( wxColour( 255,255,255 ) );
207 void MyFrame::OnLoad( wxCommandEvent
& event
)
209 if ( !wxFileExists( LAYOUT_FILE
) )
211 wxMessageBox( "layout data file `layout.dat' not found\n\n store layout first" );
216 mpLayout
->HideBarWindows(); // hide first, to avoid flickered destruction
217 mpLayout
->DestroyBarWindows();
221 mpClientWnd
->Destroy();
227 wxIOStreamWrapper stm
;
228 stm
.CreateForInput( LAYOUT_FILE
); // TRUE - create stream for input
230 wxObjectStorage
store( stm
);
232 SerializeMe( store
);
234 mpLayout
->Activate();
237 void MyFrame::OnStore( wxCommandEvent
& event
)
239 wxIOStreamWrapper stm
;
240 stm
.CreateForOutput( LAYOUT_FILE
); // FALSE - create stream for output
242 wxObjectStorage
store( stm
);
244 SerializeMe( store
);
247 void MyFrame::OnQuit( wxCommandEvent
& event
)
249 Show( FALSE
); // TRICK:: hide it, to avoid flickered destruction
254 void MyFrame::SerializeMe( wxObjectStorage
& store
)
256 // mark contaienr-frames as not serializable
258 store
.AddInitialRef( mpInternalFrm
);
259 store
.AddInitialRef( this );
261 // does all the rest for as
263 store
.XchgObjPtr( (wxObject
**) &(mpLayout
) );
264 store
.XchgObjPtr( (wxObject
**) &(mpClientWnd
) );
266 store
.Finalize(); // finish serialization
269 #ifdef __HACK_MY_MSDEV40__
271 ////////////// new 2.0-magic (linker errors...) ////////////////
273 wxToolBar
* wxFrame::CreateToolBar(long style
, wxWindowID id
, const wxString
& name
)
275 wxCHECK_MSG( m_frameToolBar
== NULL
, FALSE
,
276 "recreating toolbar in wxFrame" );
278 wxToolBar
* toolBar
= OnCreateToolBar(style
, id
, name
);
291 wxToolBar
* wxFrame::OnCreateToolBar(long style
, wxWindowID id
, const wxString
& name
)
293 return new wxToolBar(this, id
, wxDefaultPosition
, wxDefaultSize
, style
, name
);