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