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