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