]> git.saurik.com Git - wxWidgets.git/blob - contrib/samples/fl/fl_demo2.cpp
applied patch #935127: "wxDIALOG_MODAL and wxDIALOG_MODELESS cleaning"; some cosmetic...
[wxWidgets.git] / contrib / samples / fl / fl_demo2.cpp
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 #ifdef __GNUG__
13 #pragma implementation "fl_demo2.h"
14 #endif
15
16 // For compilers that support precompilation, includes "wx/wx.h".
17 #include "wx/wxprec.h"
18
19 #ifdef __BORLANDC__
20 #pragma hdrstop
21 #endif
22
23 #ifndef WX_PRECOMP
24 #include "wx/wx.h"
25 #endif
26
27 // wxWidgets headers.
28 #include "wx/treectrl.h"
29 #include "wx/imaglist.h"
30 #include "wx/notebook.h"
31
32 // fl headers.
33 #include "wx/fl/controlbar.h"
34 #include "wx/fl/rowlayoutpl.h"
35 #include "wx/fl/antiflickpl.h"
36 #include "wx/fl/bardragpl.h"
37 #include "wx/fl/cbcustom.h"
38 #include "wx/fl/rowdragpl.h"
39
40 // some extra fl plugins.
41 #include "wx/fl/barhintspl.h"
42 #include "wx/fl/hintanimpl.h"
43
44 #include "wx/fl/dyntbar.h"
45 #include "wx/fl/dyntbarhnd.h" // fl-dimension-handler for dynamic toolbar
46
47 #include "fl_demo2.h"
48
49 /***** Implementation for class MyApp *****/
50
51 // Create a new application object
52 IMPLEMENT_APP (MyApp)
53
54 // `Main program' equivalent, creating windows and returning main app frame
55 bool MyApp::OnInit(void)
56 {
57 // Create the main frame window
58 MyFrame *frame = new MyFrame(NULL, _("wxWidgets 2.0 wxFrameLayout demo"), 50, 50, 650, 540);
59
60 // Give it an icon
61 #ifdef __WINDOWS__
62 frame->SetIcon(wxIcon(wxT("mondrian")));
63 #endif
64 #ifdef __X__
65 frame->SetIcon(wxIcon(wxT("aiai.xbm")));
66 #endif
67
68 // Make a menubar
69 wxMenu *file_menu = new wxMenu;
70 wxMenu *active_menu = new wxMenu;
71
72 file_menu->Append( ID_LOAD, _("&Load layouts") );
73 file_menu->Append( ID_STORE, _("&Store layouts") );
74 file_menu->AppendSeparator();
75
76 file_menu->Append( ID_AUTOSAVE, _("&Auto Save Layouts"), _("save layouts on exit"), wxITEM_CHECK );
77 file_menu->AppendSeparator();
78
79 file_menu->Append(MINIMAL_ABOUT, _("A&bout !"));
80 file_menu->Append(MINIMAL_QUIT, _("E&xit\tTab"));
81
82 //active_menu->Append( ID_SETTINGS, _("&Settings...\tCtrl") );
83 //active_menu->AppendSeparator();
84
85 active_menu->Append( ID_REMOVE, _("&Remove Active") );
86 active_menu->Append( ID_REMOVEALL, _("Remove &All") );
87 active_menu->Append( ID_RECREATE, _("Re&create") );
88 active_menu->AppendSeparator();
89
90 active_menu->Append( ID_FIRST, _("Activate f&irst layout \tF1"), _("activate it"), wxITEM_CHECK );
91 active_menu->Append( ID_SECOND, _("Activate &second layout\tF2"), _("activate it"), wxITEM_CHECK );
92 active_menu->Append( ID_THIRD, _("Activate &third layout\tF3"), _("activate it"), wxITEM_CHECK );
93
94 wxMenuBar *menu_bar = new wxMenuBar;
95
96 menu_bar->Append(file_menu, _("&File"));
97 menu_bar->Append(active_menu, _("Active &Layout"));
98
99 frame->CreateStatusBar(3);
100
101 frame->SetMenuBar(menu_bar);
102
103 frame->SyncMenuBarItems();
104
105 // Show the frame
106 frame->Show(true);
107
108 SetTopWindow(frame);
109
110 return true;
111 }
112
113 MyFrame::~MyFrame()
114 {
115 // frame-layouts is not a windows (objects), thus should
116 // be cleaned up manually
117
118 for( int i = 0; i != MAX_LAYOUTS; ++i )
119 {
120 if ( mLayouts[i] )
121 delete mLayouts[i];
122 }
123
124 if ( mpNestedLayout )
125 delete mpNestedLayout;
126 if ( mpAboutBoxLayout )
127 delete mpAboutBoxLayout;
128 }
129
130 /***** Implementation for class MyFrame *****/
131
132 BEGIN_EVENT_TABLE(MyFrame, wxFrame)
133 EVT_MENU( MINIMAL_QUIT, MyFrame::OnQuit )
134 EVT_MENU( MINIMAL_ABOUT, MyFrame::OnAbout )
135
136 EVT_MENU( ID_LOAD, MyFrame::OnLoad )
137 EVT_MENU( ID_STORE, MyFrame::OnStore )
138 EVT_MENU( ID_AUTOSAVE, MyFrame::OnAutoSave )
139 //EVT_MENU( ID_SETTINGS, MyFrame::OnSettings )
140 EVT_MENU( ID_REMOVE, MyFrame::OnRemove )
141 EVT_MENU( ID_REMOVEALL, MyFrame::OnRemoveAll )
142 EVT_MENU( ID_RECREATE, MyFrame::OnRecreate )
143 EVT_MENU( ID_FIRST, MyFrame::OnFirst )
144 EVT_MENU( ID_SECOND, MyFrame::OnSecond )
145 EVT_MENU( ID_THIRD, MyFrame::OnThird )
146
147 EVT_BUTTON( ID_SAY_ITSOK, MyFrame::OnSayItsOk )
148 EVT_BUTTON( ID_BTN_YES, MyFrame::OnBtnYes )
149 EVT_BUTTON( ID_BTN_NO, MyFrame::OnBtnNo )
150 EVT_BUTTON( ID_BTN_ESC, MyFrame::OnBtnEsc )
151
152 EVT_CHAR_HOOK( MyFrame::OnChar )
153 END_EVENT_TABLE()
154
155 // My frame constructor
156
157 MyFrame::MyFrame(wxFrame *frame, const wxChar *title, int x, int y, int w, int h)
158 : wxFrame(frame, wxID_ANY, title, wxPoint(x, y), wxSize(w, h)),
159 mpNestedLayout( NULL ),
160 mpAboutBoxLayout( NULL ),
161
162 mActiveLayoutNo( FIRST_LAYOUT ),
163 mAutoSave( true ),
164 mSavedAlready( false ),
165 mpClntWindow( NULL ),
166
167 mImageList( 16,16, false, 2 )
168 {
169 int i;
170
171 mpInternalFrm = (wxPanel*)this;
172
173 mAboutBox.Create( this, wxID_ANY, _T("About box in wxWidgets style..."),
174 wxDefaultPosition,
175 wxSize( 385,220),
176 wxDEFAULT_DIALOG_STYLE | wxTAB_TRAVERSAL );
177
178 for( i = 0; i != MAX_LAYOUTS; ++i )
179 mLayouts[i] = NULL;
180
181 // image-list is one of the few objects which
182 // currently cannot be serialized, create it first
183 // and use it as initial reference (IR)
184
185 wxBitmap bmp1,bmp2;
186
187 if ( wxFileExists( wxString(wxT(BMP_DIR)) + wxT("folder_icon.bmp") ) )
188 bmp1.LoadFile( wxString(wxT(BMP_DIR)) + wxT("folder_icon.bmp"), wxBITMAP_TYPE_BMP );
189
190 if ( wxFileExists( wxString(wxT(BMP_DIR)) + wxT("class_icon1.bmp") ) )
191 bmp2.LoadFile( wxString(wxT(BMP_DIR)) + wxT("class_icon1.bmp"), wxBITMAP_TYPE_BMP );
192
193 mImageList.Add( bmp1 );
194 mImageList.Add( bmp2 );
195
196 InitAboutBox();
197
198 // create multiple layouts
199
200 mpNestedLayout = 0;
201
202 mpClntWindow = CreateTxtCtrl(wxT("client window"));
203
204 // Create all layouts
205 for( i = 0; i != MAX_LAYOUTS; ++i )
206 {
207 CreateLayout( i );
208 }
209 // hide others
210 for( i = SECOND_LAYOUT; i != MAX_LAYOUTS; ++i )
211 {
212 mLayouts[i]->HideBarWindows();
213 }
214
215 // activate first one
216 mLayouts[FIRST_LAYOUT]->Activate();
217 mActiveLayoutNo = FIRST_LAYOUT;
218 }
219
220 /*** event handlers ***/
221
222 bool MyFrame::OnClose(void)
223 {
224 // USEFUL TRICK:: avoids flickering of application's frame
225 // when closing NN windows on exit:
226
227 Show(false);
228
229 if ( (mAutoSave && mSavedAlready) || !mAutoSave )
230 {
231 }
232 else
233 {
234 wxCommandEvent evt;
235 OnStore(evt);
236 }
237
238 mAboutBox.Destroy();
239 Destroy();
240
241 return true;
242 }
243
244 void MyFrame::OnLoad( wxCommandEvent& WXUNUSED(event) )
245 {
246 wxMessageBox(_("Hey - you found a BIG question-mark !!"));
247 }
248
249 void MyFrame::OnStore( wxCommandEvent& WXUNUSED(event) )
250 {
251 wxMessageBox(_("Hey - you found another BIG question-mark !!"));
252 }
253
254 void MyFrame::OnAutoSave( wxCommandEvent& WXUNUSED(event) )
255 {
256 mAutoSave = !mAutoSave;
257
258 wxCommandEvent evt;
259 OnStore(evt);
260
261 SyncMenuBarItems();
262 }
263
264 void MyFrame::OnRemove( wxCommandEvent& WXUNUSED(event) )
265 {
266 RemoveLayout( mActiveLayoutNo );
267
268 Refresh();
269 }
270
271 void MyFrame::OnRemoveAll( wxCommandEvent& WXUNUSED(event) )
272 {
273 for( int i = 0; i != MAX_LAYOUTS; ++i )
274 {
275 RemoveLayout( i );
276 }
277
278 Refresh();
279 }
280
281
282 void MyFrame::OnRecreate( wxCommandEvent& event )
283 {
284 OnRemove( event ); // first destroy active layout
285
286 CreateLayout( mActiveLayoutNo );
287
288 mLayouts[mActiveLayoutNo]->Activate();
289 }
290
291 void MyFrame::OnFirst( wxCommandEvent& WXUNUSED(event) )
292 {
293 ActivateLayout( FIRST_LAYOUT );
294 }
295
296 void MyFrame::OnSecond( wxCommandEvent& WXUNUSED(event) )
297 {
298 ActivateLayout( SECOND_LAYOUT );
299 }
300
301 void MyFrame::OnThird( wxCommandEvent& WXUNUSED(event) )
302 {
303 ActivateLayout( THIRD_LAYOUT );
304 }
305
306 void MyFrame::OnQuit( wxCommandEvent& WXUNUSED(event) )
307 {
308 // USEFUL TRICK:: avoids flickering of application's frame
309 // when closing NN windows on exit:
310
311 Show(false);
312
313 if ( (mAutoSave && mSavedAlready) || !mAutoSave )
314 {
315 }
316 else
317 {
318 wxCommandEvent evt;
319 OnStore(evt);
320 }
321
322 Destroy();
323 }
324
325 void MyFrame::OnAbout( wxCommandEvent& WXUNUSED(event) )
326 {
327 wxFont font;
328 #ifdef __WXMSW__
329 font.SetFaceName(wxT("MS Sans Serif"));
330 #else
331 font.SetFamily( wxSWISS );
332 #endif
333
334 font.SetStyle( wxSLANT );
335 font.SetWeight( wxNORMAL );
336 font.SetPointSize( 8 );
337
338 #ifdef __WXMSW__
339 font.RealizeResource();
340 #endif
341
342 mAboutBox.Center( wxBOTH );
343 mAboutBox.Show(true);
344
345 }
346
347 void MyFrame::OnChar( wxKeyEvent& event )
348 {
349 wxCommandEvent evt;
350
351 if ( event.m_keyCode == WXK_F1 )
352 {
353 OnFirst( evt );
354 }
355 else
356 {
357 if ( event.m_keyCode == WXK_F2 )
358 {
359 OnSecond( evt );
360 }
361 else
362 {
363 if ( event.m_keyCode == WXK_F3 )
364 {
365 OnThird( evt );
366 }
367 if ( event.m_keyCode == WXK_F4 && !event.AltDown() )
368 {
369 // "AI" :-)
370 wxMessageBox(_("There are only 3 layouts in this demo :-("));
371 }
372 else
373 {
374 if ( event.m_keyCode == WXK_TAB )
375 {
376 // USEFUL TRICK:: avoids flickering of application's frame
377 // when closing NN windows on exit:
378
379 Show(false);
380
381 if ( (mAutoSave && mSavedAlready) || !mAutoSave )
382 {
383 }
384 else
385 {
386 wxCommandEvent evt;
387 OnStore(evt);
388 }
389
390 Destroy();
391 }
392 else
393 {
394 event.Skip();
395 }
396 }
397 }
398 }
399 }
400
401 void MyFrame::OnSayItsOk( wxCommandEvent& WXUNUSED(event) )
402 {
403 wxMessageBox(_("It's OK :-)\n\n now click on the border around the button\n and try dragging it!") );
404 }
405
406 void MyFrame::OnBtnYes( wxCommandEvent& WXUNUSED(event) )
407 {
408 mAboutBox.Show(false);
409 }
410
411 void MyFrame::OnBtnNo( wxCommandEvent& WXUNUSED(event) )
412 {
413 mAboutBox.Show(false);
414 }
415
416 void MyFrame::OnBtnEsc( wxCommandEvent& WXUNUSED(event) )
417 {
418 mAboutBox.Show(false);
419 }
420
421 /*** helper methods ***/
422
423 void MyFrame::InitAboutBox()
424 {
425 wxPanel* pArea = new wxPanel();
426
427 pArea->Create( &mAboutBox, wxID_ANY );
428
429 new wxStaticText(pArea, wxID_ANY, _("This is wxFrameLayout contribution demo."),
430 wxPoint(10, 10) );
431
432 new wxStaticText(pArea, wxID_ANY, _("Aleksandras Gluchovas (c) 1998"),
433 wxPoint(10, 30) );
434
435 new wxStaticText(pArea, wxID_ANY, _("<mailto:alex@soften.ktu.lt>"),
436 wxPoint(10, 50) );
437
438 mpAboutBoxLayout = new wxFrameLayout( &mAboutBox, pArea, true );
439
440 wxFrameLayout& layout = *mpAboutBoxLayout;
441
442 cbDimInfo sizes( 90,40, // when docked horizontally
443 45,55, // when docked vertically
444 90,40, // when floated
445 true, 4, 4 // true - bar is fixed-size
446 );
447
448
449 wxButton* pYes = CreateButton(_("&Yes"), &mAboutBox, ID_SAY_ITSOK );
450 wxButton* pNo = CreateButton(_("&No"), &mAboutBox, ID_BTN_NO );
451 wxButton* pEsc = CreateButton(_("Cancel"), &mAboutBox, ID_BTN_ESC );
452
453 layout.AddBar( pEsc, sizes, FL_ALIGN_BOTTOM, 0, 20, _("cancel button"));
454 layout.AddBar( pNo, sizes, FL_ALIGN_BOTTOM, 0, 20, _("no button"));
455 layout.AddBar( pYes, sizes, FL_ALIGN_BOTTOM, 0, 20, _("yes button"));
456
457 layout.mBorderPen.SetColour( 192, 192, 192 );
458 layout.SetMargins( 15, 15, 15, 15, wxALL_PANES );
459
460 cbCommonPaneProperties props;
461
462 layout.GetPaneProperties( props, FL_ALIGN_TOP );
463
464 props.mShow3DPaneBorderOn = false;
465
466 layout.SetPaneProperties( props, wxALL_PANES );
467
468 layout.Activate();
469
470 pYes->SetDefault();
471 pYes->SetFocus();
472 }
473
474 wxTextCtrl* MyFrame::CreateTxtCtrl( const wxString& txt, wxWindow* parent )
475 {
476 return new wxTextCtrl( (parent != NULL ) ? parent : mpInternalFrm,
477 wxID_ANY, txt, wxDefaultPosition, wxDefaultSize,
478 wxTE_MULTILINE );
479 }
480
481 wxButton* MyFrame::CreateButton( const wxString& label,
482 wxWindow* pParent, long id )
483 {
484 return new wxButton( (pParent)?pParent : mpInternalFrm, id,
485 label, wxPoint( 0,0 ), wxSize( 0,0 ) );
486 }
487
488 wxTreeCtrl* MyFrame::CreateTreeCtrl( const wxString& label )
489 {
490 wxTreeCtrl* pTree = new wxTreeCtrl( mpInternalFrm, wxID_ANY );
491
492 const wxTreeItemId rootid = pTree->AppendItem( (long)0, label, 0);
493
494 if ( label[0] != 'X' )
495 {
496 pTree->AppendItem(rootid, _("Leaf1"), 0);
497 pTree->AppendItem(rootid, _("Leaf2"), 0);
498 }
499 else
500 {
501 pTree->AppendItem(rootid, _("Scully"), 0);
502 pTree->AppendItem(rootid, _("Mulder"), 0);
503 }
504
505 return pTree;
506 }
507
508 wxChoice* MyFrame::CreateChoice( const wxString& txt )
509 {
510 wxString choice_strings[5];
511
512 choice_strings[0] = txt;
513 choice_strings[1] = _("Julian");
514 choice_strings[2] = _("Hattie");
515 choice_strings[3] = _("Ken");
516 choice_strings[4] = _("Dick");
517
518 wxChoice *choice = new wxChoice( mpInternalFrm, 301, wxDefaultPosition,
519 wxDefaultSize, 5, choice_strings);
520
521 choice->SetSelection(0);
522
523 return choice;
524 }
525
526 // helper
527
528 void MyFrame::AddSearchToolbars( wxFrameLayout& layout, wxWindow* WXUNUSED(pParent) )
529 {
530 cbDimInfo sizes2( 275,38, // when docked horizontally
531 45,275, // when docked vertically
532 80,30, // when floated
533 true, // the bar is fixed-size
534 4, // vertical gap (bar border)
535 4, // horizontal gap (bar border)
536 new cbDynToolBarDimHandler()
537 );
538
539 cbDimInfo sizes3( 275,55, // when docked horizontally
540 275,60, // when docked vertically
541 45,130, // when floated
542 true, // the bar is fixed-size
543 4, // vertical gap (bar border)
544 4, // horizontal gap (bar border)
545 new cbDynToolBarDimHandler()
546 );
547
548 cbDimInfo sizes4( 430,35, // when docked horizontally
549 44,375, // when docked vertically
550 80,100, // when floated
551 true, // the bar is fixed-size
552 4, // vertical gap (bar border)
553 4, // horizontal gap (bar border)
554 new cbDynToolBarDimHandler()
555 );
556
557 wxDynamicToolBar* pTBar2 = new wxDynamicToolBar( mpInternalFrm, wxID_ANY );
558
559 wxChoice* pChoice = new wxChoice( pTBar2, wxID_ANY, wxDefaultPosition, wxSize( 140,25 ) );
560
561 pTBar2->AddTool( 1, pChoice );
562 pTBar2->AddTool( 2, wxString(wxT(BMP_DIR)) + wxT("search.bmp") );
563 //pTBar2->AddSeparator();
564 pTBar2->AddTool( 3, wxString(wxT(BMP_DIR)) + wxT("bookmarks.bmp") );
565 pTBar2->AddTool( 4, wxString(wxT(BMP_DIR)) + wxT("nextmark.bmp") );
566 pTBar2->AddTool( 5, wxString(wxT(BMP_DIR)) + wxT("prevmark.bmp") );
567
568 wxDynamicToolBar* pTBar3 = new wxDynamicToolBar( mpInternalFrm, wxID_ANY );
569
570 pTBar3->AddTool( 1, wxString(wxT(BMP_DIR)) + wxT("open.bmp"), wxBITMAP_TYPE_BMP, wxString(_(" Open ")) );
571 pTBar3->AddTool( 2, wxString(wxT(BMP_DIR)) + wxT("save.bmp"), wxBITMAP_TYPE_BMP, wxString(_(" Save ")) );
572 pTBar3->AddTool( 3, wxString(wxT(BMP_DIR)) + wxT("saveall.bmp"), wxBITMAP_TYPE_BMP, wxString(_(" Save All ")) );
573 //pTBar3->AddSeparator();
574 pTBar3->AddTool( 4, wxString(wxT(BMP_DIR)) + wxT("cut.bmp"), wxBITMAP_TYPE_BMP, wxString(_(" Open ")) );
575 pTBar3->AddTool( 5, wxString(wxT(BMP_DIR)) + wxT("copy.bmp"), wxBITMAP_TYPE_BMP, wxString(_(" Copy ")) );
576 pTBar3->AddTool( 6, wxString(wxT(BMP_DIR)) + wxT("paste.bmp"), wxBITMAP_TYPE_BMP, wxString(_(" Paste ")) );
577
578 #ifdef __WXMSW__
579 pTBar3->EnableTool( 2, false );
580 #endif
581
582 wxDynamicToolBar* pTBar4 = new wxDynamicToolBar( mpInternalFrm, wxID_ANY );
583
584 pTBar4->AddTool( 1, wxString(wxT(BMP_DIR)) + wxT("bookmarks.bmp"), wxBITMAP_TYPE_BMP, wxString(_("Bookmarks ")), true );
585 pTBar4->AddTool( 2, wxString(wxT(BMP_DIR)) + wxT("nextmark.bmp"), wxBITMAP_TYPE_BMP, wxString(_("Next bookmark ")), true );
586 pTBar4->AddTool( 3, wxString(wxT(BMP_DIR)) + wxT("prevmark.bmp"), wxBITMAP_TYPE_BMP, wxString(_("Prev bookmark ")), true );
587 //pTBar4->AddSeparator();
588 pTBar4->AddTool( 4, wxString(wxT(BMP_DIR)) + wxT("search.bmp"), wxBITMAP_TYPE_BMP, wxString(_("Search ")), true );
589
590 #ifdef __WXMSW__
591 pTBar4->EnableTool( 4, false );
592 #endif
593
594 layout.AddBar( pTBar2,
595 sizes2, FL_ALIGN_TOP,
596 0,
597 0,
598 wxT("Search"),
599 true
600 );
601
602 layout.AddBar( pTBar3,
603 sizes3, FL_ALIGN_BOTTOM,
604 0,
605 0,
606 wxT("Titled"),
607 true
608 );
609
610 layout.AddBar( pTBar4,
611 sizes4, FL_ALIGN_BOTTOM,
612 1,
613 0,
614 wxT("Bookmarks"),
615 true
616 );
617 }
618
619 wxWindow* MyFrame::CreateDevLayout( wxFrameLayout& layout, wxWindow* pParent )
620 {
621 bool isNested = (pParent != mpInternalFrm);
622
623 // check if we're craeting nested layout
624 if ( isNested )
625 {
626 layout.mBorderPen.SetColour( 128,255,128 );
627
628 // if so, than make border smaller
629 for( int i = 0; i != MAX_PANES; ++i )
630 {
631 cbDockPane& pane = *layout.GetPane( i );
632
633 pane.mTopMargin = 5;
634 pane.mBottomMargin = 5;
635 pane.mLeftMargin = 5;
636 pane.mRightMargin = 5;
637 }
638 }
639
640 int cbWidth = 200;
641 int cbHeight = ( isNested ) ? 50 : 150;
642
643 cbDimInfo sizes4( cbWidth,cbHeight,
644 cbWidth,cbHeight,
645 cbWidth,cbHeight, false );
646
647 cbWidth = 75;
648 cbHeight = 31;
649
650 cbDimInfo sizes5( cbWidth,cbHeight,
651 42,65,
652 cbWidth,cbHeight, true,
653 3, // vertical gap (bar border)
654 3 // horizontal gap (bar border)
655 );
656
657 // create "workplace" window in the third layout
658 // SEB: originally here was a wxpp (wxWorkshop) class demotrated
659 // wxTabbedWindow* pMiniTabArea = new wxTabbedWindow();
660 // pMiniTabArea->Create( pParent, wxID_ANY );
661
662
663 wxTreeCtrl* pClassView = new wxTreeCtrl( pParent, wxID_ANY,
664 wxDefaultPosition, wxDefaultSize, wxTR_HAS_BUTTONS | wxTR_EDIT_LABELS );
665
666 pClassView->SetImageList( &mImageList );
667
668 wxTreeItemId rootId = pClassView->AddRoot( wxT("wxWidgets 2.0 classes"), 0 );
669
670 pClassView->AppendItem( rootId, _("wxWin Dynamic classes (grabbed at run-time)"), 0 );
671 pClassView->AppendItem( rootId, _("serializer-classes (grabbed at run-time)"), 0 );
672
673 // now create "output" window
674 wxNotebook* pTabbedArea = new wxNotebook(pParent, wxID_ANY);
675 // SEB: originally here was a wxpp (wxWorkshop) class used
676 // wxPaggedWindow* pTabbedArea = new wxPaggedWindow();
677 // pTabbedArea->Create( pParent, wxID_ANY );
678
679 wxPanel* pSheet3 = new wxPanel();
680 pSheet3->Create( pTabbedArea, wxID_ANY );
681 pSheet3->Show(false);
682
683 pTabbedArea->AddPage( CreateTxtCtrl(wxT("build"), pTabbedArea), wxT("Build"));
684 pTabbedArea->AddPage( CreateTxtCtrl(wxT("debug"), pTabbedArea), wxT("Debug"));
685 pTabbedArea->AddPage( pSheet3, wxT("is THIS recursive - or what !?"));
686 pTabbedArea->AddPage( CreateTxtCtrl(wxT("profile"), pTabbedArea), wxT("Profile"));
687
688 layout.AddBar( new StartButton95(pParent), sizes5, FL_ALIGN_TOP, 0, 0, wxT("Start...") );
689 layout.AddBar( pClassView, sizes4, FL_ALIGN_LEFT, 0, 0, wxT("Project Workplace") );
690 layout.AddBar( pTabbedArea, sizes4, FL_ALIGN_BOTTOM, 0, 50, wxT("Output") );
691
692 return pSheet3;
693 }
694
695 void MyFrame::DropInSomeBars( int layoutNo )
696 {
697 /* create once... and forget! */
698
699 // setup dimension infos for various bar shapes
700
701 int cbWidth = 90;
702 int cbHeight = 30;
703
704 if ( layoutNo == SECOND_LAYOUT )
705 cbHeight = 60;
706
707 wxFrameLayout& layout = *mLayouts[layoutNo];
708
709 cbDimInfo sizes( cbWidth,cbHeight, // when docked horizontally
710 cbWidth,cbHeight, // when docked vertically
711 cbWidth,cbHeight, // when floated
712 true // true - bar is fixed-size
713 );
714
715 cbWidth = 120;
716
717 cbDimInfo sizes1( cbWidth,cbHeight,
718 cbWidth,cbHeight,
719 cbWidth,cbHeight, false ); // false - bar is "flexible"
720
721 cbWidth = 120;
722 cbHeight = 40;
723
724 cbDimInfo sizes3( cbWidth,cbHeight,
725 cbWidth,cbHeight,
726 cbWidth,cbHeight, true ); // -/-
727
728 cbWidth = 200;
729 cbHeight = 150;
730
731 cbDimInfo sizes4( cbWidth,cbHeight,
732 cbWidth,cbHeight,
733 cbWidth,cbHeight, false ); // -/-
734
735 cbWidth = 63;
736 cbHeight = 31;
737
738 cbDimInfo sizes5( cbWidth,cbHeight,
739 cbHeight,cbWidth,
740 cbWidth,cbHeight, true,
741 3, // vertical gap (bar border)
742 3 // horizontal gap (bar border)
743 ); // -/-
744
745
746 if ( layoutNo == FIRST_LAYOUT )
747 {
748 // add 4 fixed-size bars (`sizes' dim-info) and one "flexible" (with `sizes1' dim-info)
749
750 wxWindow* pGreenOne = new MyTestPanel(mpInternalFrm);
751
752 pGreenOne->SetBackgroundColour( wxColour(128,255,128) );
753
754 layout.AddBar( pGreenOne, sizes, FL_ALIGN_TOP, 0, 50, wxT("Bar1"), true );
755 layout.AddBar( new MyTestPanel(mpInternalFrm), sizes, FL_ALIGN_TOP, 2, 50, wxT("Bar2"), true );
756 layout.AddBar( new MyTestPanel(mpInternalFrm), sizes, FL_ALIGN_BOTTOM, 2, 50, wxT("Bar3"), true );
757 layout.AddBar( new MyTestPanel(mpInternalFrm), sizes, FL_ALIGN_LEFT, 2, 50, wxT("Bar4"), true );
758 layout.AddBar( new MyTestPanel(mpInternalFrm), sizes1, wxCBAR_HIDDEN, 2, 50, wxT("Super-Bar"), true );
759 }
760 else
761 {
762 if ( layoutNo == SECOND_LAYOUT )
763 {
764 // show off various wx-controls in the second layout
765
766 layout.AddBar( CreateTxtCtrl(), sizes, FL_ALIGN_TOP, 0, 50, wxT("Fixed text Area&0") );
767 layout.AddBar( CreateButton(wxT("OK")), sizes, FL_ALIGN_TOP, 0, 100, wxT("First Button") );
768 layout.AddBar( CreateTxtCtrl(), sizes1, FL_ALIGN_BOTTOM, 0, 50, wxT("First Tree") );
769 layout.AddBar( CreateTreeCtrl(wxT("Root")), sizes1, FL_ALIGN_LEFT, 0, 0, wxT("TreeCtrl Window") );
770 layout.AddBar( CreateChoice(wxT("Choice 1")), sizes3, FL_ALIGN_TOP, 0, 0, wxT("Choice 1 (buggy)"), false, wxCBAR_HIDDEN );
771 layout.AddBar( CreateChoice(wxT("Choice 2")), sizes3, FL_ALIGN_TOP, 0, 0, wxT("Choice 2 (buggy)"), false, wxCBAR_HIDDEN );
772 layout.AddBar( CreateTreeCtrl(wxT("X-Files")), sizes1, FL_ALIGN_RIGHT, 0, 100, wxT("X-Files") );
773 layout.AddBar( CreateTxtCtrl(wxT("smaller1")), sizes3, FL_ALIGN_TOP, 0, 50, wxT("smaller Area1") );
774 layout.AddBar( CreateTxtCtrl(wxT("smaller2")), sizes3, FL_ALIGN_TOP, 0, 50, wxT("sm&ller Area2") );
775 }
776 else
777 {
778 if ( layoutNo == THIRD_LAYOUT )
779 {
780 #if defined(__WXGTK__) || defined(__WXX11__)
781 cbCommonPaneProperties props;
782 layout.GetPaneProperties( props );
783 props.mRealTimeUpdatesOn = false; // real-time OFF for gtk!!!
784 layout.SetPaneProperties( props, wxALL_PANES );
785 #endif
786
787 layout.AddBar( CreateTxtCtrl(wxT("Tool1")), sizes3, FL_ALIGN_TOP, 0, 50, wxT("Fixed text Area1") );
788 layout.AddBar( CreateTxtCtrl(wxT("Tool2")), sizes3, FL_ALIGN_TOP, 0, 50, wxT("Fixed text Area2") );
789 layout.AddBar( CreateTxtCtrl(wxT("Tool3")), sizes3, FL_ALIGN_TOP, 0, 50, wxT("Fixed text Area3") );
790 layout.AddBar( CreateTxtCtrl(wxT("Tool4")), sizes3, FL_ALIGN_TOP, 1, 50, wxT("Fixed text Area4") );
791 layout.AddBar( CreateTxtCtrl(wxT("Tool5")), sizes3, FL_ALIGN_TOP, 1, 50, wxT("Fixed text Area5") );
792 layout.AddBar( CreateTxtCtrl(wxT("Tool6")), sizes3, FL_ALIGN_TOP, 1, 50, wxT("Fixed text Area6") );
793 layout.AddBar( CreateTxtCtrl(wxT("Tool7")), sizes3, FL_ALIGN_TOP, 2,250, wxT("Fixed text Area7") );
794
795 cbDimInfo sizes10( 175,35, // when docked horizontally
796 175,38, // when docked vertically
797 170,35, // when floated
798 true, // the bar is not fixed-size
799 4, // vertical gap (bar border)
800 4, // horizontal gap (bar border)
801 new cbDynToolBarDimHandler()
802 );
803
804 wxDynamicToolBar* pToolBar = new wxDynamicToolBar();
805
806 pToolBar->Create( mpInternalFrm, wxID_ANY );
807
808 // 1001-1006 ids of command events fired by added tool-buttons
809
810 pToolBar->AddTool( 1001, wxString(wxT(BMP_DIR)) + wxT("new.bmp") );
811 pToolBar->AddTool( 1002, wxString(wxT(BMP_DIR)) + wxT("open.bmp") );
812 pToolBar->AddTool( 1003, wxString(wxT(BMP_DIR)) + wxT("save.bmp") );
813
814 pToolBar->AddTool( 1004, wxString(wxT(BMP_DIR)) + wxT("cut.bmp") );
815 pToolBar->AddTool( 1005, wxString(wxT(BMP_DIR)) + wxT("copy.bmp") );
816 pToolBar->AddTool( 1006, wxString(wxT(BMP_DIR)) + wxT("paste.bmp") );
817
818 layout.AddBar( pToolBar, // bar window (can be NULL)
819 sizes10, FL_ALIGN_TOP, // alignment ( 0-top,1-bottom, etc)
820 0, // insert into 0th row (vert. position)
821 0, // offset from the start of row (in pixels)
822 wxT("Real-Toolbar"), // name to refere in customization pop-ups
823 false
824 );
825
826 // create first "developement" layout
827 AddSearchToolbars( layout, mpInternalFrm);
828
829 wxWindow* pSheet3 = CreateDevLayout( layout, mpInternalFrm);
830
831 // create another ***secreat developement*** layout inside
832 // the third sheet of the outter one's output bar
833
834 mpNestedLayout = new wxFrameLayout( pSheet3,
835 CreateTxtCtrl(wxT("\"Mobils in Mobile\" --C.Nemo"),pSheet3), false );
836
837 CreateDevLayout( *mpNestedLayout, pSheet3 );
838
839 mpNestedLayout->Activate();
840 }
841 }
842 }
843 }
844
845 void MyFrame::CreateLayout( int layoutNo )
846 {
847 wxFrameLayout* pLayout = new wxFrameLayout( mpInternalFrm, mpClntWindow, false );
848
849 if ( layoutNo == THIRD_LAYOUT )
850 {
851 pLayout->PushDefaultPlugins();
852 pLayout->AddPlugin( CLASSINFO( cbBarHintsPlugin ) ); // facny "X"es and beveal for bars
853 #if defined(__WXGTK__) || defined(__WXX11__)
854 pLayout->AddPlugin( CLASSINFO( cbHintAnimationPlugin ) );
855 #endif
856 pLayout->AddPlugin( CLASSINFO( cbRowDragPlugin ) );
857 }
858
859 mLayouts[layoutNo] = pLayout;
860
861 DropInSomeBars( layoutNo );
862 }
863
864 void MyFrame::RemoveLayout( int layoutNo )
865 {
866 wxFrameLayout* pLayout = mLayouts[layoutNo];
867
868 if ( !pLayout )
869 return;
870
871 pLayout->HideBarWindows();
872
873 // destroy nested layout first
874
875 if ( layoutNo == THIRD_LAYOUT )
876 {
877 if ( mpNestedLayout )
878 delete mpNestedLayout;
879 mpNestedLayout = NULL;
880 }
881
882 // NOTE:: bar windows are NOT destroyed automatically by frame-layout
883
884 pLayout->DestroyBarWindows();
885
886 delete pLayout;
887
888 mLayouts[layoutNo] = NULL;
889
890 Refresh();
891 }
892
893 void MyFrame::SyncMenuBarItems()
894 {
895 for( int i = 0; i != MAX_LAYOUTS; ++i )
896 {
897 GetMenuBar()->Check( ID_FIRST+i, mActiveLayoutNo == FIRST_LAYOUT+i );
898 }
899
900 GetMenuBar()->Check( ID_AUTOSAVE, mAutoSave );
901 }
902
903 void MyFrame::ActivateLayout( int layoutNo )
904 {
905 if ( layoutNo == mActiveLayoutNo )
906 return;
907
908 if ( mLayouts[mActiveLayoutNo] )
909 mLayouts[mActiveLayoutNo]->Deactivate();
910
911 mActiveLayoutNo = layoutNo;
912
913 if ( mLayouts[mActiveLayoutNo] )
914 mLayouts[mActiveLayoutNo]->Activate();
915 else
916 Refresh();
917
918 SyncMenuBarItems();
919 }
920
921 /***** Implementation for class StartButton95 (just for fun) *****/
922
923 IMPLEMENT_DYNAMIC_CLASS( StartButton95, wxPanel )
924
925 BEGIN_EVENT_TABLE( StartButton95, wxPanel )
926 EVT_LEFT_DOWN( StartButton95::OnMouseDown )
927 EVT_LEFT_UP ( StartButton95::OnMouseUp )
928 EVT_PAINT ( StartButton95::OnPaint )
929 END_EVENT_TABLE()
930
931 void StartButton95::OnMouseDown( wxMouseEvent& WXUNUSED(event) )
932 {
933 m_bPressed = true;
934 Refresh();
935 CaptureMouse();
936 }
937
938 void StartButton95::OnMouseUp( wxMouseEvent& WXUNUSED(event) )
939 {
940 // "this is not a bug"
941
942 SetCursor( wxCURSOR_WAIT );
943 GetParent()->SetCursor( wxCURSOR_WAIT );
944 ::wxSetCursor( wxCURSOR_WAIT );
945 wxSleep(1);
946
947 for( int i = 1; i != 6; ++i )
948 {
949 m_bPressed = (i % 2) != 0;
950 Refresh();
951 wxSleep(1);
952 }
953 GetParent()->Close();
954 //*((char*)(i)-3) = 'X'; // Aleks what's the meaning of this???
955 }
956
957 void StartButton95::OnPaint( wxPaintEvent& WXUNUSED(event) )
958 {
959 wxBitmap* pBmp;
960
961 if ( m_bPressed )
962 {
963 if ( !m_PBmp.Ok() && wxFileExists( wxString(wxT(BMP_DIR)) + wxT("start95_pr.bmp") ) )
964
965 m_PBmp.LoadFile( wxString(wxT(BMP_DIR)) + wxT("start95_pr.bmp"), wxBITMAP_TYPE_BMP );
966
967 pBmp = &m_PBmp;
968 }
969 else
970 {
971 if ( !m_DBmp.Ok() && wxFileExists( wxString(wxT(BMP_DIR)) + wxT("start95_dp.bmp") ) )
972
973 m_DBmp.LoadFile( wxString(wxT(BMP_DIR)) + wxT("start95_dp.bmp"), wxBITMAP_TYPE_BMP );
974
975 pBmp = &m_DBmp;
976 }
977
978 if (!pBmp) return;
979 wxMemoryDC mdc;
980 wxPaintDC dc(this);
981 mdc.SelectObject( *pBmp );
982
983 dc.Blit( 0,0, pBmp->GetWidth(), pBmp->GetHeight(), &mdc, 0,0, wxCOPY );
984
985 mdc.SelectObject( wxNullBitmap );
986 }