]> git.saurik.com Git - wxWidgets.git/blame - utils/framelayout/samples/demo/fl_demo.cpp
Fixed wxApp::SendIdleEvents for Vadim's new wxWindowList wxTopLevelWindows
[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
49841b74 235#else
08973ff0 236 if ( !mDBmp.Ok() )
bd9396d5 237
08973ff0 238 mDBmp = wxBitmap(start95_dp_xpm);
49841b74 239#endif
bd9396d5
HH
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
256BEGIN_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
279END_EVENT_TABLE()
280
281// My frame constructor
282
283MyFrame::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;
da9531bf
RS
315#ifdef __WXMSW__
316 bmp1.LoadFile( "folder_icon", wxBITMAP_TYPE_BMP_RESOURCE );
317 bmp2.LoadFile( "class_icon1", wxBITMAP_TYPE_BMP_RESOURCE );
318#else
08973ff0
RS
319 bmp1 = wxBitmap( folder_icon_xpm);
320 bmp2 = wxBitmap( class_icon1_xpm );
da9531bf 321#endif
bd9396d5
HH
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
361bool 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
382void 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
408void 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
420void MyFrame::OnAutoSave( wxCommandEvent& event )
421{
422 mAutoSave = !mAutoSave;
423
424 wxCommandEvent evt;
425 this->OnStore(evt);
426
427 SyncMenuBarItems();
428}
429
430void 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
454void MyFrame::OnRemove( wxCommandEvent& event )
455{
456 RemoveLayout( mActiveLayoutNo );
457
458 Refresh();
459}
460
461void MyFrame::OnRemoveAll( wxCommandEvent& event )
462{
463 for( int i = 0; i != MAX_LAYOUTS; ++i )
464
465 RemoveLayout( i );
466
467 Refresh();
468}
469
470
471void MyFrame::OnRecreate( wxCommandEvent& event )
472{
473 OnRemove( event ); // first destroy active layout
474
475 CreateLayout( mActiveLayoutNo );
476
477 mLayouts[mActiveLayoutNo]->Activate();
478}
479
480void MyFrame::OnFirst( wxCommandEvent& event )
481{
482 ActivateLayout( FIRST_LAYOUT );
483}
484
485void MyFrame::OnSecond( wxCommandEvent& event )
486{
487 ActivateLayout( SECOND_LAYOUT );
488}
489
490void MyFrame::OnThird( wxCommandEvent& event )
491{
492 ActivateLayout( THIRD_LAYOUT );
493}
494
495void 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
512void 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
548void 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
571void 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
615void 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
620void MyFrame::OnBtnYes( wxCommandEvent& event )
621{
622 mAboutBox.Show(FALSE);
623}
624
625void MyFrame::OnBtnNo( wxCommandEvent& event )
626{
627 mAboutBox.Show(FALSE);
628}
629
630void MyFrame::OnBtnEsc( wxCommandEvent& event )
631{
632 mAboutBox.Show(FALSE);
633}
634
635/*** helper methods ***/
636
637void 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
688wxTextCtrl* 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
695wxButton* 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
702wxTreeCtrl* MyFrame::CreateTreeCtrl( const wxString& label )
703{
704 wxTreeCtrl* pTree = new wxTreeCtrl( mpInternalFrm, -1 );
705
6e0e2e9c 706 int rootid = pTree->AppendItem( (long)0, label, -1);
bd9396d5
HH
707
708 if ( label[0] != 'X' )
709 {
6e0e2e9c
HH
710 pTree->AppendItem(rootid, "Leaf1", -1);
711 pTree->AppendItem(rootid, "Leaf2", -1);
bd9396d5
HH
712 }
713 else
714 {
6e0e2e9c
HH
715 pTree->AppendItem(rootid, "Scully", -1);
716 pTree->AppendItem(rootid, "Mulder", -1);
bd9396d5
HH
717 }
718
719 return pTree;
720}
721
722wxChoice* 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
740static const char helloworld_src[] =
741
742"#include <iostream.h>\n\
743\n\
744void main()\n\
745{\n\
746 cout << \"Hello World\";\n\
747}\n\
748\n";
749
750// helper
751
752void 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
af11388a 772 cbDimInfo sizes4( 450,35, // when docked horizontally
bd9396d5
HH
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 );
da9531bf
RS
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
da9531bf
RS
793 wxDynamicToolBar* pTBar3 = new wxDynamicToolBar( mpInternalFrm, -1 );
794
795 pTBar3->AddTool( 1, wxBitmap("open_icon"), " Open " );
796 pTBar3->AddTool( 2, wxBitmap("save_icon"), " Save " );
797 pTBar3->AddTool( 3, wxBitmap("saveall_icon"), " Save All " );
798 //pTBar3->AddSeparator();
799 pTBar3->AddTool( 4, wxBitmap("cut_icon"), " Open " );
800 pTBar3->AddTool( 5, wxBitmap("copy_icon"), " Copy " );
801 pTBar3->AddTool( 6, wxBitmap("paste_icon")," Paste " );
802
803 pTBar3->EnableTool( 2, FALSE );
804
805 wxDynamicToolBar* pTBar4 = new wxDynamicToolBar( mpInternalFrm, -1 );
806
807 pTBar4->AddTool( 1, wxBitmap("bookmarks_icon"), "Bookmarks ", TRUE );
808 pTBar4->AddTool( 2, wxBitmap("nextmark_icon"), "Next bookmark ", TRUE );
809 pTBar4->AddTool( 3, wxBitmap("prevmark_icon"), "Prev bookmark ", TRUE );
810 //pTBar4->AddSeparator();
811 pTBar4->AddTool( 4, wxBitmap("search_icon"),"Search ", TRUE );
812
813 pTBar4->EnableTool( 4, FALSE );
814
815#else
08973ff0 816 pTBar2->AddTool( 2, search_xpm );
bd9396d5 817 //pTBar2->AddSeparator();
08973ff0
RS
818 pTBar2->AddTool( 3, bookmarks_xpm );
819 pTBar2->AddTool( 4, nextmark_xpm );
820 pTBar2->AddTool( 5, prevmark_xpm );
bd9396d5
HH
821
822 wxDynamicToolBar* pTBar3 = new wxDynamicToolBar( mpInternalFrm, -1 );
823
08973ff0
RS
824 pTBar3->AddTool( 1, wxBitmap(open_xpm), " Open " );
825 pTBar3->AddTool( 2, wxBitmap(save_xpm), " Save " );
826 pTBar3->AddTool( 3, wxBitmap(saveall_xpm), " Save All " );
bd9396d5 827 //pTBar3->AddSeparator();
08973ff0
RS
828 pTBar3->AddTool( 4, wxBitmap(cut_xpm), " Open " );
829 pTBar3->AddTool( 5, wxBitmap(copy_xpm), " Copy " );
830 pTBar3->AddTool( 6, wxBitmap(paste_xpm), " Paste " );
bd9396d5 831
af11388a
RS
832 pTBar3->EnableTool( 2, FALSE );
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 );
af11388a
RS
841
842 pTBar4->EnableTool( 4, FALSE );
bd9396d5
HH
843#endif
844
845 layout.AddBar( pTBar2,
846 sizes2, wxTOP,
847 0,
848 0,
849 "Search",
850 TRUE
851 );
852
853 layout.AddBar( pTBar3,
854 sizes3, wxBOTTOM,
855 0,
856 0,
857 "Titled",
858 TRUE
859 );
860
861 layout.AddBar( pTBar4,
862 sizes4, wxBOTTOM,
863 1,
864 0,
865 "Bookmarks",
866 TRUE
867 );
868}
869
870wxWindow* MyFrame::CreateDevLayout( wxFrameLayout& layout, wxWindow* pParent )
871{
872 bool isNested = pParent != mpInternalFrm;
873
874 // check if we're craeting nested layout
875 if ( isNested )
876 {
877 layout.mBorderPen.SetColour( 128,255,128 );
878
879 // if so, than make border smaller
08973ff0 880 for( int i = 0; i != MAX_PANES; ++i )
bd9396d5
HH
881 {
882 cbDockPane& pane = *layout.GetPane( i );
883
884 pane.mTopMargin = 5;
885 pane.mBottomMargin = 5;
886 pane.mLeftMargin = 5;
887 pane.mRightMargin = 5;
888 }
889 }
890
891 int cbWidth = 200;
892 int cbHeight = ( isNested ) ? 50 : 150;
893
894 cbDimInfo sizes4( cbWidth,cbHeight,
895 cbWidth,cbHeight,
896 cbWidth,cbHeight, FALSE );
897
898 cbWidth = 75;
899 cbHeight = 31;
900
901 cbDimInfo sizes5( cbWidth,cbHeight,
902 42,65,
903 cbWidth,cbHeight, TRUE,
904 3, // vertical gap (bar border)
905 3 // horizontal gap (bar border)
906 );
907
908 // create "workplace" window in the third layout
909
910 wxTabbedWindow* pMiniTabArea = new wxTabbedWindow();
911
912 pMiniTabArea->Create( pParent, -1 );
913
914 wxTreeCtrl* pClassView =
915 new wxTreeCtrl( pMiniTabArea, -1, wxDefaultPosition, wxDefaultSize,
916 wxTR_HAS_BUTTONS | wxTR_EDIT_LABELS );
917
918 pClassView->SetImageList( &mImageList );
919
920 wxTreeItemId rootId = pClassView->AddRoot( "wxWindows 2.0 classes", 0 );
921
922 wxTreeItemId cinfId = pClassView->AppendItem( rootId, "wxWin Dynamic classes (grabbed at run-time)", 0 );
923 wxTreeItemId serId = pClassView->AppendItem( rootId, "serializer-classes (grabbed at run-time)", 0 );
924
925 // functions from "wxinfo.h"
926 ::wxCreateClassInfoTree( pClassView, cinfId, 1 );
927 ::wxCreateSerializerInfoTree( pClassView, serId, 1 );
928
da9531bf
RS
929#ifdef __WXMSW__
930 // (default arg anyway)
931 pMiniTabArea->AddTab( pClassView, "ClassView", &wxBitmap("class_icon"));
932 pMiniTabArea->AddTab( new wxPanel(), "ResourceView",&wxBitmap("res_icon") );
933 pMiniTabArea->AddTab( new wxPanel(), "FileView", &wxBitmap("file_icon") );
934 pMiniTabArea->AddTab( new wxPanel(), "InfoView", &wxBitmap("help_icon") );
935 pMiniTabArea->AddTab( CreateTxtCtrl( helloworld_src,
936 pMiniTabArea), "HelloWorld", &wxBitmap("help_icon") );
937#else
08973ff0
RS
938 pMiniTabArea->AddTab( pClassView, "ClassView", &wxBitmap(class_icon_xpm));
939 pMiniTabArea->AddTab( new wxPanel(), "ResourceView",&wxBitmap(res_icon_xpm) );
940 pMiniTabArea->AddTab( new wxPanel(), "FileView", &wxBitmap(file_icon_xpm) );
941 pMiniTabArea->AddTab( new wxPanel(), "InfoView", &wxBitmap(help_icon_xpm) );
bd9396d5 942 pMiniTabArea->AddTab( CreateTxtCtrl( helloworld_src,
08973ff0 943 pMiniTabArea), "HelloWorld", &wxBitmap(help_icon_xpm) );
da9531bf 944#endif
bd9396d5
HH
945 // now create "output" window
946
947 wxPaggedWindow* pTabbedArea = new wxPaggedWindow();
948
949 pTabbedArea->Create( pParent, -1 );
950
951 wxPanel* pSheet3 = new wxPanel();
952 pSheet3->Create( pTabbedArea, -1 );
953 pSheet3->Show(FALSE);
954
955 pTabbedArea->AddTab( CreateTxtCtrl("build", pTabbedArea), "Build", "" );
956 pTabbedArea->AddTab( CreateTxtCtrl("debug", pTabbedArea), "Debug", "" );
08973ff0 957#ifdef __WXMSW__
da9531bf 958 pTabbedArea->AddTab( pSheet3, "Find in Files!", &wxBitmap("file_icon") );
08973ff0
RS
959#else
960 pTabbedArea->AddTab( pSheet3, "Find in Files!", &wxBitmap(file_icon_xpm) );
961#endif
bd9396d5
HH
962 pTabbedArea->AddTab( CreateTxtCtrl("profile", pTabbedArea), "Profile", "" );
963
964 layout.AddBar( new StartButton95(pParent), sizes5, wxTOP, 0, 0, "Start..." );
965 layout.AddBar( pMiniTabArea, sizes4, wxLEFT, 0, 0, "Project Workplace" );
966 layout.AddBar( pTabbedArea, sizes4, wxBOTTOM, 0, 50, "Output" );
967
968 return pSheet3;
969}
970
971void MyFrame::DropInSomeBars( int layoutNo )
972{
973 /* create once... and forget! */
974
975 // setup dimension infos for various bar shapes
976
977 int cbWidth = 90;
978 int cbHeight = 30;
979
980 if ( layoutNo == SECOND_LAYOUT ) cbHeight = 60;
981
982 wxFrameLayout& layout = *mLayouts[layoutNo];
983
984 cbDimInfo sizes( cbWidth,cbHeight, // when docked horizontally
985 cbWidth,cbHeight, // when docked vertically
986 cbWidth,cbHeight, // when floated
987 TRUE // true - bar is fixed-size
988 );
989
990 cbWidth = 120;
991
992 cbDimInfo sizes1( cbWidth,cbHeight,
993 cbWidth,cbHeight,
994 cbWidth,cbHeight, FALSE ); // false - bar is "flexible"
995
996
997 cbWidth = 120;
998 cbHeight = 40;
999
1000 cbDimInfo sizes3( cbWidth,cbHeight,
1001 cbWidth,cbHeight,
1002 cbWidth,cbHeight, TRUE ); // -/-
1003
1004 cbWidth = 200;
1005 cbHeight = 150;
1006
1007 cbDimInfo sizes4( cbWidth,cbHeight,
1008 cbWidth,cbHeight,
1009 cbWidth,cbHeight, FALSE ); // -/-
1010
1011 cbWidth = 63;
1012 cbHeight = 31;
1013
1014 cbDimInfo sizes5( cbWidth,cbHeight,
1015 cbHeight,cbWidth,
1016 cbWidth,cbHeight, TRUE,
1017 3, // vertical gap (bar border)
1018 3 // horizontal gap (bar border)
1019 ); // -/-
1020
1021
1022 if ( layoutNo == FIRST_LAYOUT )
1023 {
1024 // add 4 fixed-size bars (`sizes' dim-info) and one "flexible" (with `sizes1' dim-info)
1025
1026 wxWindow* pGreenOne = new MyTestPanel(mpInternalFrm);
1027
1028 pGreenOne->SetBackgroundColour( wxColour(128,255,128) );
1029
1030 layout.AddBar( pGreenOne, sizes, wxTOP, 0, 50, "Bar1", TRUE );
1031 layout.AddBar( new MyTestPanel(mpInternalFrm), sizes, wxTOP, 2, 50, "Bar2", TRUE );
1032 layout.AddBar( new MyTestPanel(mpInternalFrm), sizes, wxBOTTOM, 2, 50, "Bar3", TRUE );
1033 layout.AddBar( new MyTestPanel(mpInternalFrm), sizes, wxLEFT, 2, 50, "Bar4", TRUE );
1034 layout.AddBar( new MyTestPanel(mpInternalFrm), sizes1, wxCBAR_HIDDEN, 2, 50, "Super-Bar", TRUE );
1035 }
1036 else
1037 if ( layoutNo == SECOND_LAYOUT )
1038 {
1039 // show off various wx-controls in the second layout
1040
1041 layout.AddBar( CreateTxtCtrl(), sizes, wxTOP, 0, 50, "Fixed text Area&0" );
1042 layout.AddBar( CreateButton("OK"), sizes, wxTOP, 0, 100, "First Button" );
1043 layout.AddBar( CreateTxtCtrl(), sizes1, wxBOTTOM, 0, 50, "First Tree" );
1044 layout.AddBar( CreateTreeCtrl("Root"), sizes1, wxLEFT, 0, 0, "TreeCtrl Window" );
1045 layout.AddBar( CreateChoice("Choice 1"), sizes3, wxTOP, 0, 0, "Choice 1 (buggy)", FALSE, wxCBAR_HIDDEN );
1046 layout.AddBar( CreateChoice("Choice 2"), sizes3, wxTOP, 0, 0, "Choice 2 (buggy)", FALSE, wxCBAR_HIDDEN );
1047 layout.AddBar( CreateTreeCtrl("X-Files"), sizes1, wxRIGHT, 0, 100, "X-Files" );
1048 layout.AddBar( CreateTxtCtrl("smaller1"), sizes3, wxTOP, 0, 50, "smaller Area1" );
1049 layout.AddBar( CreateTxtCtrl("smaller2"), sizes3, wxTOP, 0, 50, "sm&ller Area2" );
1050 }
1051 else
1052 if ( layoutNo == THIRD_LAYOUT )
1053 {
1054#ifdef __WXGTK__
1055
1056 cbCommonPaneProperties props;
1057 layout.GetPaneProperties( props );
1058 props.mRealTimeUpdatesOn = FALSE; // real-time OFF for gtk!!!
1059 layout.SetPaneProperties( props, wxALL_PANES );
1060
1061#endif
1062
1063 layout.AddBar( CreateTxtCtrl("Tool1"), sizes3, wxTOP, 0, 50, "Fixed text Area1" );
1064 layout.AddBar( CreateTxtCtrl("Tool2"), sizes3, wxTOP, 0, 50, "Fixed text Area2" );
1065 layout.AddBar( CreateTxtCtrl("Tool3"), sizes3, wxTOP, 0, 50, "Fixed text Area3" );
1066 layout.AddBar( CreateTxtCtrl("Tool4"), sizes3, wxTOP, 1, 50, "Fixed text Area4" );
1067 layout.AddBar( CreateTxtCtrl("Tool5"), sizes3, wxTOP, 1, 50, "Fixed text Area5" );
1068 layout.AddBar( CreateTxtCtrl("Tool6"), sizes3, wxTOP, 1, 50, "Fixed text Area6" );
1069 layout.AddBar( CreateTxtCtrl("Tool7"), sizes3, wxTOP, 2, 250, "Fixed text Area7" );
1070
1071 cbDimInfo sizes10(175,35, // when docked horizontally
1072 175,38, // when docked vertically
1073 170,35, // when floated
1074 TRUE, // the bar is not fixed-size
1075 4, // vertical gap (bar border)
1076 4, // horizontal gap (bar border)
1077 new cbDynToolBarDimHandler()
1078 );
1079
1080 wxDynamicToolBar* pToolBar = new wxDynamicToolBar();
1081
1082 pToolBar->Create( mpInternalFrm, -1 );
1083
1084 // 1001-1006 ids of command events fired by added tool-buttons
49841b74 1085#ifdef __WXMSW__
da9531bf
RS
1086 pToolBar->AddTool( 1001, wxBitmap("new_icon") );
1087 pToolBar->AddTool( 1002, wxBitmap("open_icon") );
1088 pToolBar->AddTool( 1003, wxBitmap("save_icon") );
1089
1090 pToolBar->AddTool( 1004, wxBitmap("cut_icon") );
1091 pToolBar->AddTool( 1005, wxBitmap("copy_icon") );
1092 pToolBar->AddTool( 1006, wxBitmap("paste_icon") );
1093#else
08973ff0
RS
1094 pToolBar->AddTool( 1001, wxBitmap(new_xpm) );
1095 pToolBar->AddTool( 1002, wxBitmap(open_xpm) );
1096 pToolBar->AddTool( 1003, wxBitmap(save_xpm) );
bd9396d5 1097
08973ff0
RS
1098 pToolBar->AddTool( 1004, wxBitmap(cut_xpm) );
1099 pToolBar->AddTool( 1005, wxBitmap(copy_xpm) );
1100 pToolBar->AddTool( 1006, wxBitmap(paste_xpm) );
da9531bf 1101#endif
bd9396d5
HH
1102 layout.AddBar( pToolBar, // bar window (can be NULL)
1103 sizes10, wxTOP, // alignment ( 0-top,1-bottom, etc)
1104 0, // insert into 0th row (vert. position)
1105 0, // offset from the start of row (in pixels)
1106 "Real-Toolbar", // name to refere in customization pop-ups
1107 FALSE
1108 );
1109
1110
1111
1112 // create first "developement" layout
1113
1114 AddSearchToolbars( layout, mpInternalFrm);
1115
1116 wxWindow* pSheet3 = CreateDevLayout( layout, mpInternalFrm);
1117
1118 // create another ***secreat developement*** layout inside
1119 // the third sheet of the outter one's output bar
1120
1121 mpNestedLayout =
1122
1123 new wxFrameLayout( pSheet3,
1124 CreateTxtCtrl("\"Mobils in Mobile\" --C.Nemo",pSheet3), FALSE );
1125
1126 CreateDevLayout( *mpNestedLayout, pSheet3 );
1127
1128 mpNestedLayout->Activate();
1129 }
1130}
1131
1132void MyFrame::CreateLayout( int layoutNo )
1133{
1134 wxFrameLayout* pLayout = new wxFrameLayout( mpInternalFrm, mpClntWindow, FALSE );
1135
1136 if ( layoutNo == THIRD_LAYOUT )
1137 {
1138 pLayout->PushDefaultPlugins();
1139 pLayout->AddPlugin( CLASSINFO( cbBarHintsPlugin ) ); // facny "X"es and beveal for bars
1140#ifdef __WXGTK__
1141 pLayout->AddPlugin( CLASSINFO( cbHintAnimationPlugin ) );
1142#endif
1143 pLayout->AddPlugin( CLASSINFO( cbRowDragPlugin ) );
1144 }
1145
1146 mLayouts[layoutNo] = pLayout;
1147
1148 DropInSomeBars( layoutNo );
1149}
1150
1151void MyFrame::RemoveLayout( int layoutNo )
1152{
1153 wxFrameLayout* pLayout = mLayouts[layoutNo];
1154
1155 if ( !pLayout ) return;
1156
1157 pLayout->HideBarWindows();
1158
1159 // destroy nested layout first
1160
1161 if ( layoutNo == THIRD_LAYOUT )
1162 {
1163 if ( mpNestedLayout ) delete mpNestedLayout;
1164 mpNestedLayout = NULL;
1165 }
1166
1167 // NOTE:: bar windows are NOT destroyed automatically by frame-layout
1168
1169 pLayout->DestroyBarWindows();
1170
1171 delete pLayout;
1172
1173 mLayouts[layoutNo] = NULL;
1174
1175 Refresh();
1176}
1177
1178void MyFrame::DestroyEverything()
1179{
1180 for( int i = 0; i != MAX_LAYOUTS; ++i )
1181
1182 RemoveLayout( i );
1183
1184 if ( mpClntWindow )
1185 {
1186 mpClntWindow->Destroy();
1187
1188 mpClntWindow = NULL;
1189 }
1190}
1191
1192void MyFrame::SyncMenuBarItems()
1193{
1194 for( int i = 0; i != MAX_LAYOUTS; ++i )
1195
1196 GetMenuBar()->Check( ID_FIRST+i, mActiveLayoutNo == FIRST_LAYOUT+i );
1197
1198 GetMenuBar()->Check( ID_AUTOSAVE, mAutoSave );
1199}
1200
1201void MyFrame::ActivateLayout( int layoutNo )
1202{
1203 if ( layoutNo == mActiveLayoutNo ) return;
1204
1205 if ( mLayouts[mActiveLayoutNo] )
1206
1207 mLayouts[mActiveLayoutNo]->Deactivate();
1208
1209 mActiveLayoutNo = layoutNo;
1210
1211 if ( mLayouts[mActiveLayoutNo] )
1212
1213 mLayouts[mActiveLayoutNo]->Activate();
1214 else
1215 Refresh();
1216
1217 SyncMenuBarItems();
1218}
1219
1220void MyFrame::SerializeMe( wxObjectStorage& store )
1221{
1222 store.AddInitialRef( this );
1223 store.AddInitialRef( mpInternalFrm );
1224 store.AddInitialRef( &mAboutBox );
1225 store.AddInitialRef( &mImageList );
1226
1227 store.XchgInt ( mActiveLayoutNo );
1228 store.XchgBool( mAutoSave );
1229
1230 store.XchgObjPtr( (wxObject**) &mpClntWindow );
1231
1232 for( int i = 0; i != MAX_LAYOUTS; ++i )
1233 {
1234 if ( i == THIRD_LAYOUT )
1235
1236 store.XchgObjPtr( (wxObject**) &(mpNestedLayout) );
1237
1238 store.XchgObjPtr( (wxObject**) &(mLayouts[i]) );
1239 }
1240
1241 store.XchgObjPtr( (wxObject**) &(mpAboutBoxLayout) );
1242
1243 store.Finalize(); // finish serialization
1244}
1245
1246#ifdef __HACK_MY_MSDEV40__
1247
1248////////////// new 2.0-magic (linker errors...) ////////////////
1249
1250wxToolBar* wxFrame::CreateToolBar(long style, wxWindowID id, const wxString& name)
1251{
1252 wxCHECK_MSG( m_frameToolBar == NULL, FALSE,
1253 "recreating toolbar in wxFrame" );
1254
1255 wxToolBar* toolBar = OnCreateToolBar(style, id, name);
1256 if (toolBar)
1257 {
1258 SetToolBar(toolBar);
1259 PositionToolBar();
1260 return toolBar;
1261 }
1262 else
1263 {
1264 return NULL;
1265 }
1266}
1267
1268void foo( double& d )
1269{
1270 ++d;
1271}
1272
1273wxToolBar* wxFrame::OnCreateToolBar(long style, wxWindowID id, const wxString& name)
1274{
1275 double dd = 5;
1276
1277 return new wxToolBar(this, id, wxDefaultPosition, wxDefaultSize, style, name);
1278}
1279
1280#endif