]> git.saurik.com Git - wxWidgets.git/blobdiff - utils/framelayout/samples/demo/fl_demo.cpp
fixed the bug with the order of 2 size events when the scrollbar[s] (dis)appear in...
[wxWidgets.git] / utils / framelayout / samples / demo / fl_demo.cpp
index eb083f57c105df1e23246ab5e321f442b2b717c6..ccea06bdc5f4bbca8fe172115af5c2c799fc9073 100644 (file)
 #include "barhintspl.h"
 #include "hintanimpl.h"
 #include "controlarea.h"
-#include "objstore.h"
 
 #include "dyntbar.h"
 #include "dyntbarhnd.h"  // fl-dimension-handler for dynamic toolbar
 
 #include "wxinfo.h"
 
+#ifdef __WXGTK__
+#include "start95_dp.xpm"
+#include "start95_pr.xpm"
+#include "bookmarks.xpm"
+#include "class_icon.xpm"
+#include "class_icon1.xpm"
+#include "copy.xpm"
+#include "cut.xpm"
+#include "file_icon.xpm"
+#include "folder_icon.xpm"
+#include "help_icon.xpm"
+#include "new.xpm"
+#include "nextmark.xpm"
+#include "open.xpm"
+#include "paste.xpm"
+#include "prevmark.xpm"
+#include "res_icon.xpm"
+#include "save.xpm"
+#include "saveall.xpm"
+#include "search.xpm"
+#endif
 // ADDED by alex (linker complaints...):
+#ifndef wxDUMMY_OBJ_INCLUDED
 char wxDummyChar=0;
+#endif
 
 /***** Implementation for class MyApp *****/
 
@@ -76,8 +98,6 @@ bool MyApp::OnInit(void)
     wxMenu *file_menu = new wxMenu;
     wxMenu *active_menu = new wxMenu;
 
-    file_menu->Append( ID_LOAD,  "&Load layouts"  );
-    file_menu->Append( ID_STORE, "&Store layouts" );
     file_menu->AppendSeparator();
         
     file_menu->Append( ID_AUTOSAVE, "&Auto Save Layouts", "save layouts on exit", TRUE );
@@ -190,17 +210,30 @@ void StartButton95::OnPaint( wxPaintEvent& event )
 
     if ( mPressed )
     {
-        if ( !mPBmp.Ok() && wxFileExists( "start95_pr.bmp" ) )
+#ifdef __WXMSW__
+        if ( !mPBmp.Ok()  )
     
-            mPBmp.LoadFile( "start95_pr.bmp", wxBITMAP_TYPE_BMP );
+            mPBmp.LoadFile( "start95_pr_icon", wxBITMAP_TYPE_BMP_RESOURCE );
+#else
+        if ( !mPBmp.Ok() )
+    
+            mPBmp = wxBitmap( start95_pr_xpm);
+#endif
 
         pBmp = &mPBmp;
     }
     else
     {
-        if ( !mDBmp.Ok() && wxFileExists( "start95_dp.bmp" ) )
+#ifdef __WXMSW__
+        if ( !mDBmp.Ok()  )
+                                   
+            mDBmp.LoadFile( "start95_dp_icon", wxBITMAP_TYPE_BMP_RESOURCE );
+
+#else
+        if ( !mDBmp.Ok() )
                                    
-            mDBmp.LoadFile( "start95_dp.bmp", wxBITMAP_TYPE_BMP );
+            mDBmp = wxBitmap(start95_dp_xpm);
+#endif
 
         pBmp = &mDBmp;
     }
@@ -222,9 +255,6 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame)
     EVT_MENU( MINIMAL_QUIT,  MyFrame::OnQuit  )
     EVT_MENU( MINIMAL_ABOUT, MyFrame::OnAbout )
 
-    EVT_MENU( ID_LOAD,      MyFrame::OnLoad      )
-    EVT_MENU( ID_STORE,     MyFrame::OnStore     )
-    EVT_MENU( ID_AUTOSAVE,  MyFrame::OnAutoSave  )
     EVT_MENU( ID_SETTINGS,  MyFrame::OnSettings  )
     EVT_MENU( ID_REMOVE,    MyFrame::OnRemove    )
     EVT_MENU( ID_REMOVEALL, MyFrame::OnRemoveAll )
@@ -276,48 +306,38 @@ MyFrame::MyFrame(wxFrame *frame, char *title, int x, int y, int w, int h)
     // and use it as initial reference (IR)
 
     wxBitmap bmp1,bmp2;
-
-    if ( wxFileExists( "folder_icon.bmp" ) )
-        bmp1.LoadFile( "folder_icon.bmp", wxBITMAP_TYPE_BMP );
-
-    if ( wxFileExists( "class_icon1.bmp" ) )
-        bmp2.LoadFile( "class_icon1.bmp", wxBITMAP_TYPE_BMP );
-
+#ifdef __WXMSW__
+    bmp1.LoadFile( "folder_icon", wxBITMAP_TYPE_BMP_RESOURCE );
+    bmp2.LoadFile( "class_icon1", wxBITMAP_TYPE_BMP_RESOURCE );
+#else
+    bmp1 = wxBitmap( folder_icon_xpm);
+    bmp2 = wxBitmap( class_icon1_xpm );
+#endif
     int idx1 = mImageList.Add( bmp1 );
     int idx2 = mImageList.Add( bmp2 );
 
-    // load configuation if present      
+    InitAboutBox();
 
-    if ( wxFileExists( "layouts_for_demo.dat" ) )
-    {
-        wxCommandEvent evt;
-        this->OnLoad( evt );
-    }
-    else
-    {
-        InitAboutBox();
+    // create multiple layouts
 
-        // create multiple layouts
+    mpNestedLayout = 0;
 
-        mpNestedLayout = 0;
+    mpClntWindow = CreateTxtCtrl("client window");
 
-        mpClntWindow = CreateTxtCtrl("client window");
+    for( i = 0; i != MAX_LAYOUTS; ++i )
 
-        for( i = 0; i != MAX_LAYOUTS; ++i )
-                    
-            CreateLayout( i );
+       CreateLayout( i );
 
-        for( i = SECOND_LAYOUT; i != MAX_LAYOUTS; ++i )
+    for( i = SECOND_LAYOUT; i != MAX_LAYOUTS; ++i )
 
-            // hide others
-            mLayouts[i]->HideBarWindows();
+       // hide others
+       mLayouts[i]->HideBarWindows();
 
-        // activate first one 
+    // activate first one 
 
-        mLayouts[FIRST_LAYOUT]->Activate();
+    mLayouts[FIRST_LAYOUT]->Activate();
 
-        mActiveLayoutNo = FIRST_LAYOUT;
-    }
+    mActiveLayoutNo = FIRST_LAYOUT;
 }
 
 /*** event handlers ***/
@@ -330,65 +350,11 @@ bool MyFrame::OnClose(void)
     this->Show(FALSE);
 
 
-    if ( (mAutoSave && mSavedAlready) || !mAutoSave );
-               else
-               {
-                       wxCommandEvent evt;
-                       this->OnStore(evt);
-               }
-
-       mAboutBox.Destroy();
-       this->Destroy();
 
-       return TRUE;
-}
-
-void MyFrame::OnLoad( wxCommandEvent& event )
-{
-    if ( !wxFileExists( "layouts_for_demo.dat" ) )
-    {               
-        wxMessageBox( 
-            
-"File \"layouts_for_demo.dat\" was not found,\n select\
-(File|Store Layouts) menu item to store layout information first"
-                    );
-        return;
-    }
-
-    DestroyEverything();
-
-    wxIOStreamWrapper stm;
-    stm.CreateForInput( "layouts_for_demo.dat" );
-
-    wxObjectStorage store( stm );
-
-    SerializeMe( store );
-
-    if ( mLayouts[mActiveLayoutNo] )
-
-        mLayouts[mActiveLayoutNo]->Activate();
-}
-
-void MyFrame::OnStore( wxCommandEvent& event )
-{
-    wxIOStreamWrapper stm;
-    stm.CreateForOutput( "layouts_for_demo.dat" );
-
-    wxObjectStorage store( stm );
-
-    SerializeMe( store );
-
-    mSavedAlready = TRUE;
-}
-
-void MyFrame::OnAutoSave( wxCommandEvent& event )
-{
-    mAutoSave = !mAutoSave;
-
-    wxCommandEvent evt;
-    this->OnStore(evt);
+    mAboutBox.Destroy();
+    this->Destroy();
 
-    SyncMenuBarItems();
+    return TRUE;
 }
 
 void MyFrame::OnSettings( wxCommandEvent& event )
@@ -463,14 +429,8 @@ void MyFrame::OnQuit( wxCommandEvent& event )
 
     this->Show(FALSE);
 
-    if ( (mAutoSave && mSavedAlready) || !mAutoSave );
-               else
-               {
-                       wxCommandEvent evt;
-                       this->OnStore(evt);
-               }
 
-       Destroy();
+    Destroy();
 }
 
 void set_dlg_font( wxWindow* pParent, wxFont& font )
@@ -552,28 +512,21 @@ void MyFrame::OnChar( wxKeyEvent& event )
         // "AI" :-)
         wxMessageBox("There are only 3 layouts in this demo :-(");
     else
-    if ( event.m_keyCode == WXK_TAB )
+       if ( event.m_keyCode == WXK_TAB )
        {
-               //  USEFUL TRICK:: avoids flickering of application's frame 
-               //                 when closing NN windows on exit:
+           //  USEFUL TRICK:: avoids flickering of application's frame 
+           //                 when closing NN windows on exit:
 
-               this->Show(FALSE);
+           this->Show(FALSE);
 
-               if ( (mAutoSave && mSavedAlready) || !mAutoSave );
-                       else
-                       {
-                               wxCommandEvent evt;
-                               this->OnStore(evt);
-                       }
-
-               Destroy();
+           Destroy();
        }
-    else
-    if ( event.m_keyCode == WXK_CONTROL )
-    
-        this->OnSettings( evt );
-    else
-        event.Skip();
+       else
+           if ( event.m_keyCode == WXK_CONTROL )
+
+               this->OnSettings( evt );
+           else
+               event.Skip();
 }
 
 void MyFrame::OnSayItsOk( wxCommandEvent& event )
@@ -733,7 +686,7 @@ void MyFrame::AddSearchToolbars( wxFrameLayout& layout, wxWindow* pParent )
                                          new cbDynToolBarDimHandler()
                     ); 
 
-    cbDimInfo sizes4( 430,35, // when docked horizontally      
+    cbDimInfo sizes4( 450,35, // when docked horizontally      
                       44,375, // when docked vertically        
                       80,100, // when floated                  
                       TRUE, // the bar is fixed-size
@@ -747,35 +700,62 @@ void MyFrame::AddSearchToolbars( wxFrameLayout& layout, wxWindow* pParent )
     wxChoice* pChoice = new wxChoice( pTBar2, -1, wxDefaultPosition, wxSize( 140,25 ) );
 
     pTBar2->AddTool( 1, pChoice );
-    pTBar2->AddTool( 2, "search.bmp" );
+#ifdef __WXMSW__
+    pTBar2->AddTool( 2, wxBitmap("search_icon") );
     //pTBar2->AddSeparator();
-    pTBar2->AddTool( 3, "bookmarks.bmp" );
-    pTBar2->AddTool( 4, "nextmark.bmp" );
-    pTBar2->AddTool( 5, "prevmark.bmp" );
+    pTBar2->AddTool( 3, wxBitmap("bookmarks_icon") );
+    pTBar2->AddTool( 4, wxBitmap("nextmark_icon") );
+    pTBar2->AddTool( 5, wxBitmap("prevmark_icon") );
 
     wxDynamicToolBar* pTBar3 = new wxDynamicToolBar( mpInternalFrm, -1 );
 
-    pTBar3->AddTool( 1, "open.bmp", wxBITMAP_TYPE_BMP, " Open " );
-    pTBar3->AddTool( 2, "save.bmp", wxBITMAP_TYPE_BMP, " Save " );
-    pTBar3->AddTool( 3, "saveall.bmp", wxBITMAP_TYPE_BMP, " Save All " );
+    pTBar3->AddTool( 1, wxBitmap("open_icon"), " Open " );
+    pTBar3->AddTool( 2, wxBitmap("save_icon"), " Save " );
+    pTBar3->AddTool( 3, wxBitmap("saveall_icon"), " Save All " );
     //pTBar3->AddSeparator();
-    pTBar3->AddTool( 4, "cut.bmp",   wxBITMAP_TYPE_BMP, " Open " );
-    pTBar3->AddTool( 5, "copy.bmp",  wxBITMAP_TYPE_BMP, " Copy " );
-    pTBar3->AddTool( 6, "paste.bmp", wxBITMAP_TYPE_BMP, " Paste " );
+    pTBar3->AddTool( 4, wxBitmap("cut_icon"), " Open " );
+    pTBar3->AddTool( 5, wxBitmap("copy_icon"), " Copy " );
+    pTBar3->AddTool( 6, wxBitmap("paste_icon")," Paste " );
 
-#ifdef __WXMSW__
     pTBar3->EnableTool( 2, FALSE );
-#endif
 
     wxDynamicToolBar* pTBar4 = new wxDynamicToolBar( mpInternalFrm, -1 );
 
-    pTBar4->AddTool( 1, "bookmarks.bmp", wxBITMAP_TYPE_BMP, "Bookmarks ", TRUE );
-    pTBar4->AddTool( 2, "nextmark.bmp",  wxBITMAP_TYPE_BMP, "Next bookmark ", TRUE );
-    pTBar4->AddTool( 3, "prevmark.bmp",  wxBITMAP_TYPE_BMP, "Prev bookmark ", TRUE );
+    pTBar4->AddTool( 1, wxBitmap("bookmarks_icon"), "Bookmarks ", TRUE );
+    pTBar4->AddTool( 2, wxBitmap("nextmark_icon"), "Next bookmark ", TRUE );
+    pTBar4->AddTool( 3, wxBitmap("prevmark_icon"), "Prev bookmark ", TRUE );
     //pTBar4->AddSeparator();
-    pTBar4->AddTool( 4, "search.bmp", wxBITMAP_TYPE_BMP, "Search ", TRUE );
+    pTBar4->AddTool( 4, wxBitmap("search_icon"),"Search ", TRUE );
+
+    pTBar4->EnableTool( 4, FALSE );
+
+#else
+    pTBar2->AddTool( 2, search_xpm, "" );
+    //pTBar2->AddSeparator();
+    pTBar2->AddTool( 3, bookmarks_xpm, "" );
+    pTBar2->AddTool( 4, nextmark_xpm, "" );
+    pTBar2->AddTool( 5, prevmark_xpm, "" );
+
+    wxDynamicToolBar* pTBar3 = new wxDynamicToolBar( mpInternalFrm, -1 );
+
+    pTBar3->AddTool( 1, wxBitmap(open_xpm), " Open " );
+    pTBar3->AddTool( 2, wxBitmap(save_xpm), " Save " );
+    pTBar3->AddTool( 3, wxBitmap(saveall_xpm), " Save All " );
+    //pTBar3->AddSeparator();
+    pTBar3->AddTool( 4, wxBitmap(cut_xpm), " Open " );
+    pTBar3->AddTool( 5, wxBitmap(copy_xpm), " Copy " );
+    pTBar3->AddTool( 6, wxBitmap(paste_xpm), " Paste " );
+
+    pTBar3->EnableTool( 2, FALSE );
+
+    wxDynamicToolBar* pTBar4 = new wxDynamicToolBar( mpInternalFrm, -1 );
+
+    pTBar4->AddTool( 1, wxBitmap(bookmarks_xpm), "Bookmarks ", TRUE );
+    pTBar4->AddTool( 2, wxBitmap(nextmark_xpm), "Next bookmark ", TRUE );
+    pTBar4->AddTool( 3, wxBitmap(prevmark_xpm), "Prev bookmark ", TRUE );
+    //pTBar4->AddSeparator();
+    pTBar4->AddTool( 4, wxBitmap(search_xpm),"Search ", TRUE );
 
-#ifdef __WXMSW__
     pTBar4->EnableTool( 4, FALSE );
 #endif
 
@@ -814,7 +794,7 @@ wxWindow* MyFrame::CreateDevLayout( wxFrameLayout& layout, wxWindow* pParent )
         layout.mBorderPen.SetColour( 128,255,128 );
 
         // if so, than make border smaller
-        for( int i = 0; i != MAX_PANES; ++i  )
+        for( int i = 0; i != MAX_PANES; ++i )
         {
             cbDockPane& pane = *layout.GetPane( i );
 
@@ -861,15 +841,23 @@ wxWindow* MyFrame::CreateDevLayout( wxFrameLayout& layout, wxWindow* pParent )
 
     // functions from "wxinfo.h"
     ::wxCreateClassInfoTree( pClassView, cinfId,     1 );
-    ::wxCreateSerializerInfoTree( pClassView, serId, 1 );
 
-                                                                          // (default arg anyway)
-    pMiniTabArea->AddTab( pClassView,    "ClassView",   "class_icon.bmp", wxBITMAP_TYPE_BMP );
-    pMiniTabArea->AddTab( new wxPanel(), "ResourceView","res_icon.bmp"  );
-    pMiniTabArea->AddTab( new wxPanel(), "FileView",    "file_icon.bmp" );
-    pMiniTabArea->AddTab( new wxPanel(), "InfoView",    "help_icon.bmp" );
+#ifdef __WXMSW__
+                                                                         // (default arg anyway)
+    pMiniTabArea->AddTab( pClassView,    "ClassView",   &wxBitmap("class_icon"));
+    pMiniTabArea->AddTab( new wxPanel(), "ResourceView",&wxBitmap("res_icon") );
+    pMiniTabArea->AddTab( new wxPanel(), "FileView",    &wxBitmap("file_icon") );
+    pMiniTabArea->AddTab( new wxPanel(), "InfoView",    &wxBitmap("help_icon") );
+    pMiniTabArea->AddTab( CreateTxtCtrl( helloworld_src, 
+                                         pMiniTabArea), "HelloWorld", &wxBitmap("help_icon") );
+#else
+    pMiniTabArea->AddTab( pClassView,    "ClassView",   &wxBitmap(class_icon_xpm));
+    pMiniTabArea->AddTab( new wxPanel(), "ResourceView",&wxBitmap(res_icon_xpm)  );
+    pMiniTabArea->AddTab( new wxPanel(), "FileView",    &wxBitmap(file_icon_xpm) );
+    pMiniTabArea->AddTab( new wxPanel(), "InfoView",    &wxBitmap(help_icon_xpm) );
     pMiniTabArea->AddTab( CreateTxtCtrl( helloworld_src, 
-                                         pMiniTabArea), "HelloWorld", "help_icon.bmp" );
+                                         pMiniTabArea), "HelloWorld", &wxBitmap(help_icon_xpm) );
+#endif
     // now create "output" window
 
     wxPaggedWindow* pTabbedArea = new wxPaggedWindow();
@@ -882,7 +870,11 @@ wxWindow* MyFrame::CreateDevLayout( wxFrameLayout& layout, wxWindow* pParent )
 
     pTabbedArea->AddTab( CreateTxtCtrl("build",   pTabbedArea), "Build",  "" );
     pTabbedArea->AddTab( CreateTxtCtrl("debug",   pTabbedArea), "Debug",  "" );
-    pTabbedArea->AddTab( pSheet3,                               "Find in Files!", "file_icon.bmp" );
+#ifdef __WXMSW__
+    pTabbedArea->AddTab( pSheet3,                               "Find in Files!", &wxBitmap("file_icon") );
+#else
+    pTabbedArea->AddTab( pSheet3,                               "Find in Files!", &wxBitmap(file_icon_xpm) );
+#endif
     pTabbedArea->AddTab( CreateTxtCtrl("profile", pTabbedArea), "Profile", "" );
 
     layout.AddBar( new StartButton95(pParent), sizes5, wxTOP,    0, 0,  "Start..." );
@@ -1006,15 +998,23 @@ void MyFrame::DropInSomeBars( int layoutNo )
                pToolBar->Create( mpInternalFrm, -1 );
                                                                 
                // 1001-1006 ids of command events fired by added tool-buttons
-               
-               pToolBar->AddTool( 1001, "new.bmp" );
-               pToolBar->AddTool( 1002, "open.bmp" );
-               pToolBar->AddTool( 1003, "save.bmp" );
-
-               pToolBar->AddTool( 1004, "cut.bmp" );
-               pToolBar->AddTool( 1005, "copy.bmp" );
-               pToolBar->AddTool( 1006, "paste.bmp" );
+#ifdef __WXMSW__               
+               pToolBar->AddTool( 1001, wxBitmap("new_icon") );
+               pToolBar->AddTool( 1002, wxBitmap("open_icon") );
+               pToolBar->AddTool( 1003, wxBitmap("save_icon") );
+
+               pToolBar->AddTool( 1004, wxBitmap("cut_icon") );
+               pToolBar->AddTool( 1005, wxBitmap("copy_icon") );
+               pToolBar->AddTool( 1006, wxBitmap("paste_icon") );
+#else
+               pToolBar->AddTool( 1001, wxBitmap(new_xpm), "" );
+               pToolBar->AddTool( 1002, wxBitmap(open_xpm), "" );
+               pToolBar->AddTool( 1003, wxBitmap(save_xpm), "" );
 
+               pToolBar->AddTool( 1004, wxBitmap(cut_xpm), "" );
+               pToolBar->AddTool( 1005, wxBitmap(copy_xpm), "" );
+               pToolBar->AddTool( 1006, wxBitmap(paste_xpm), "" );
+#endif
                layout.AddBar( pToolBar,  // bar window (can be NULL)
                                           sizes10, wxTOP,         // alignment ( 0-top,1-bottom, etc)
                                           0,                     // insert into 0th row (vert. position)
@@ -1133,32 +1133,6 @@ void MyFrame::ActivateLayout( int layoutNo )
     SyncMenuBarItems();
 }
 
-void MyFrame::SerializeMe( wxObjectStorage& store )
-{
-    store.AddInitialRef( this );
-       store.AddInitialRef( mpInternalFrm );
-    store.AddInitialRef( &mAboutBox  );
-    store.AddInitialRef( &mImageList );
-
-    store.XchgInt ( mActiveLayoutNo );
-    store.XchgBool( mAutoSave );
-
-    store.XchgObjPtr( (wxObject**) &mpClntWindow );
-
-    for( int i = 0; i != MAX_LAYOUTS; ++i )
-    {
-        if ( i == THIRD_LAYOUT )
-
-            store.XchgObjPtr( (wxObject**) &(mpNestedLayout) );
-    
-        store.XchgObjPtr( (wxObject**) &(mLayouts[i]) );
-    }
-
-    store.XchgObjPtr( (wxObject**) &(mpAboutBoxLayout) );
-
-    store.Finalize(); // finish serialization
-}
-
 #ifdef __HACK_MY_MSDEV40__
 
 ////////////// new 2.0-magic (linker errors...) ////////////////