home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / wxos2233.zip / wxOS2-2_3_3.zip / wxWindows-2.3.3 / contrib / samples / fl / fl_sample3 / fl_sample3.cpp < prev    next >
C/C++ Source or Header  |  2001-07-24  |  11KB  |  338 lines

  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name:        fl_sample3.cpp
  3. // Purpose:     Contrib. demo
  4. // Author:      Aleksandras Gluchovas
  5. // Modified by: Sebastian Haase (June 21, 2001)
  6. // Created:     24/11/98     
  7. // RCS-ID:      $Id: fl_sample3.cpp,v 1.1 2001/07/24 15:27:12 JS Exp $
  8. // Copyright:   (c) Aleksandras Gluchovas
  9. // Licence:     wxWindows license
  10. /////////////////////////////////////////////////////////////////////////////
  11.  
  12. // For compilers that support precompilation, includes "wx/wx.h".
  13. #include "wx/wxprec.h"
  14.  
  15. #ifdef __BORLANDC__
  16. #pragma hdrstop
  17. #endif
  18.  
  19. #ifndef WX_PRECOMP
  20. #include "wx/wx.h"
  21. #endif
  22.  
  23. #include "wx/textctrl.h"
  24.  
  25. // fl headers
  26. #include "wx/fl/controlbar.h"
  27.  
  28. // plugins used
  29. #include "wx/fl/barhintspl.h"
  30. #include "wx/fl/hintanimpl.h"
  31.  
  32. #define ID_LOAD  102
  33. #define ID_STORE 103
  34. #define ID_QUIT  104
  35.  
  36. #define ID_BUTT 145
  37. #define ID_BUTT2 146
  38.  
  39. class MyApp: public wxApp
  40. public:
  41.     bool OnInit(void);
  42. };
  43.  
  44. class MyFrame: public wxFrame
  45. {
  46. protected:
  47.     wxFrameLayout* mpLayout;
  48.     wxWindow*      mpClientWnd;
  49.     
  50.     wxButton * my_butt;
  51.     
  52.     wxTextCtrl* CreateTextCtrl( const wxString& value );
  53. public:
  54.     MyFrame( wxWindow* parent, char *title );
  55.     ~MyFrame();
  56.     
  57.     void OnLoad( wxCommandEvent& event );
  58.     void OnStore( wxCommandEvent& event );
  59.     void OnQuit( wxCommandEvent& event );
  60.     
  61.     void OnButt( wxCommandEvent& event );
  62.     void OnButt2( wxCommandEvent& event );
  63.     bool OnClose(void) { return TRUE; }
  64.     
  65.     DECLARE_EVENT_TABLE()
  66. };
  67.  
  68. /***** Implementation for class MyApp *****/
  69.  
  70. IMPLEMENT_APP    (MyApp)
  71.  
  72. bool MyApp::OnInit(void)
  73. {
  74.     // wxWindows boiler-plate:
  75.     
  76.     MyFrame *frame = new MyFrame(NULL, "wxFrameLayout sample");
  77.     
  78.     wxMenu *file_menu = new wxMenu;
  79.     
  80.     file_menu->Append( ID_LOAD,  "&Load layout"  );
  81.     file_menu->Append( ID_STORE, "&Store layout"  );
  82.     file_menu->AppendSeparator();
  83.     
  84.     file_menu->Append( ID_QUIT, "E&xit" );
  85.     
  86.     wxMenuBar *menu_bar = new wxMenuBar;
  87.     
  88.     menu_bar->Append(file_menu, "&File");
  89.     
  90.     frame->CreateStatusBar(3);
  91.     frame->SetMenuBar(menu_bar);
  92.     
  93.     frame->Show(TRUE);
  94.     SetTopWindow(frame);
  95.     
  96.     return TRUE;
  97. }
  98.  
  99. /***** Immlementation for class MyFrame *****/
  100.  
  101. BEGIN_EVENT_TABLE(MyFrame, wxFrame)
  102.     EVT_MENU( ID_LOAD,  MyFrame::OnLoad  )
  103.     EVT_MENU( ID_STORE, MyFrame::OnStore )
  104.     EVT_MENU( ID_QUIT,  MyFrame::OnQuit  )
  105.     EVT_BUTTON( ID_BUTT, MyFrame::OnButt )
  106.     EVT_BUTTON( ID_BUTT2, MyFrame::OnButt2 )
  107. END_EVENT_TABLE()
  108.  
  109. MyFrame::MyFrame( wxWindow* parent, char *title )
  110.     : wxFrame( parent, -1, "NewTest-II", wxDefaultPosition,
  111.           wxSize( 700, 500 ),
  112.           wxCLIP_CHILDREN | wxMINIMIZE_BOX | wxMAXIMIZE_BOX |
  113.           wxTHICK_FRAME   | wxSYSTEM_MENU  | wxCAPTION,
  114.           "freimas" )
  115. {
  116.     
  117.     mpClientWnd = new wxWindow(this, -1);    
  118.     mpLayout = new wxFrameLayout( this, mpClientWnd );
  119.     
  120.     ///  mpLayout->PushDefaultPlugins();
  121.     ///  mpLayout->AddPlugin( CLASSINFO( cbBarHintsPlugin ) ); // facny "X"es and beveal for barso
  122.     ///  //mpLayout->AddPlugin( CLASSINFO( cbHintAnimationPlugin ) );
  123.     
  124.     cbDimInfo sizes( 80,65,     // when docked horizontally      
  125.                      80,165,    // when docked vertically        
  126.                      180,30,    // when floated                  
  127.                      TRUE,      // the bar is fixed-size
  128.                      5,         // vertical gap (bar border)
  129.                      5          // horizontal gap (bar border)
  130.                    ); 
  131.     
  132.     
  133.     // drop-in some bars
  134.     
  135.     for( int i = 1; i <= 11; ++i )
  136.     {
  137.         char buf[4];
  138.         sprintf( buf, "%d", i );
  139.         wxString name = wxString("Bar-");
  140.         name += buf;
  141.         
  142.         sizes.mIsFixed = (i !=3); // every fifth bar is not fixed-size
  143.         
  144.         if ( !sizes.mIsFixed ) name += " (flexible)";
  145.         //      mpLayout->AddBar( CreateTextCtrl(name),// bar window
  146.         if(i != 4 && i!= 5 && i!=11) {
  147.             mpLayout->AddBar( new wxTextCtrl(this, -1, name),// bar window
  148.                               sizes, 
  149.                               i % MAX_PANES,// alignment ( 0-top,1-bottom, etc)
  150.                               0,            // insert into 0th row (vert. position)
  151.                               0,            // offset from the start of row (in pixels)
  152.                               name          // name to refere in customization pop-ups
  153.                             );
  154.         } else if(i==4){
  155.             mpLayout->AddBar( new wxTextCtrl(this, -1, name),// bar window
  156.                               cbDimInfo( 100,100, 100,100, 100,100, TRUE, 5, 5), 
  157.                               i % MAX_PANES,// alignment ( 0-top,1-bottom, etc)
  158.                               0,            // insert into 0th row (vert. position)
  159.                               0,            // offset from the start of row (in pixels)
  160.                               name          // name to refere in customization pop-ups
  161.                             );
  162.         } else if(i==5) {
  163.             my_butt = new wxButton(this, ID_BUTT, name);
  164.             mpLayout->AddBar( my_butt,// bar window
  165.                               cbDimInfo( 100,100, 200,200, 400,400, TRUE, 5, 5), 
  166.                               i % MAX_PANES,// alignment ( 0-top,1-bottom, etc)
  167.                               0,            // insert into 0th row (vert. position)
  168.                               0,            // offset from the start of row (in pixels)
  169.                               name          // name to refere in customization pop-ups
  170.                             );
  171.         } else if(i==11) {
  172.             mpLayout->AddBar( new wxButton(this, ID_BUTT2, name+"_2"),
  173.                               cbDimInfo( 100,100, 200,200, 400,400, TRUE, 5, 5), 
  174.                               i % MAX_PANES,// alignment ( 0-top,1-bottom, etc)
  175.                               0,            // insert into 0th row (vert. position)
  176.                               0,            // offset from the start of row (in pixels)
  177.                               name          // name to refere in customization pop-ups
  178.                             );
  179.         }
  180.         
  181.         //      mpLayout->RecalcLayout(true);
  182.         //        Layout();
  183.         //        Refresh();
  184.     }
  185. }
  186.  
  187. MyFrame::~MyFrame()
  188. {
  189.     // layout is not a window, should be released manually
  190.     if ( mpLayout ) 
  191.         delete mpLayout;
  192. }
  193.  
  194. wxTextCtrl* MyFrame::CreateTextCtrl( const wxString& value )
  195. {
  196.     wxTextCtrl* pCtrl = new wxTextCtrl( this, -1, value, 
  197.                                 wxPoint(0,0), wxSize(1,1), wxTE_MULTILINE );
  198.     
  199.     pCtrl->SetBackgroundColour( wxColour( 255,255,255 ) );
  200.     
  201.     return pCtrl;
  202. }
  203.  
  204. void MyFrame::OnLoad( wxCommandEvent& event )
  205. {
  206.     wxMessageBox("Hey - you found a BIG question-mark !!");
  207. }
  208.  
  209. void MyFrame::OnStore( wxCommandEvent& event )
  210. {
  211.     wxMessageBox("Hey - you found another BIG question-mark !!");
  212. }
  213.  
  214. void MyFrame::OnQuit( wxCommandEvent& event )
  215. {
  216.     Show( FALSE ); // TRICK:: hide it, to avoid flickered destruction
  217.     
  218.     Close(TRUE);
  219. }
  220.  
  221. void MyFrame::OnButt( wxCommandEvent& event )
  222. {
  223.     static int i =0;
  224.     
  225.     // cbBarInfo* FindBarByName( const wxString& name ); 
  226.     
  227.     switch(i % 2) {
  228.     case 0: 
  229.         {
  230.             cbBarInfo* x = mpLayout->FindBarByName(wxString("Bar-1"));
  231.             if(x) 
  232.                 mpLayout->InverseVisibility(x); 
  233.             else    
  234.                 wxBell();
  235.             break;
  236.         }
  237.     case 1:
  238.         {
  239.             cbBarInfo* x = mpLayout->FindBarByName(wxString("Bar-6"));
  240.             if(x) 
  241.             {
  242.                 if(i % 4 == 1) 
  243.                 {
  244.                     mpLayout->SetBarState(x, wxCBAR_FLOATING, TRUE);
  245.                     //mpLayout->RecalcLayout(true);
  246.                     mpLayout->RepositionFloatedBar(x);
  247.                 } 
  248.                 else 
  249.                 {
  250.                     mpLayout->SetBarState(x, 0, TRUE);
  251.                     //mpLayout->RecalcLayout(true);
  252.                     //mpLayout->RepositionFloatedBar(x);
  253.                 }
  254.                 //  //  //          x->mState = wxCBAR_FLOATING;
  255.                 //  //  //          mpLayout->ApplyBarProperties(x);
  256.             } 
  257.             else 
  258.             {
  259.                 wxBell();
  260.             }
  261.             
  262.             break;
  263.         }
  264.     }
  265.     i++;
  266. }
  267.  
  268. void MyFrame::OnButt2( wxCommandEvent& event )
  269. {
  270.     static int i =0;
  271.     
  272.     // cbBarInfo* FindBarByName( const wxString& name ); 
  273.     
  274.     switch(i % 2) {
  275.     case 0: 
  276.         {
  277.             cbBarInfo* x = mpLayout->FindBarByName(wxString("Bar-1"));
  278.             if(x) 
  279.             {
  280.                 for(int a=0;a<MAX_BAR_STATES;a++)
  281.                 {
  282.                     x->mDimInfo.mSizes[a].x = 200;
  283.                     x->mDimInfo.mSizes[a].y = 200;
  284.                 }
  285.                 x->mpBarWnd->SetSize(200,200);
  286.                 mpLayout->SetBarState(x, wxCBAR_FLOATING, TRUE);  // HACK !!!
  287.                 mpLayout->SetBarState(x, 0, TRUE);                  // HACK !!!
  288.                 wxYield();                                        // HACK !!! needed to resize BEFORE redraw 
  289.                 mpLayout->RefreshNow( TRUE );                     // HACK !!! needed to trigger redraw
  290.             }
  291.             else    
  292.             {
  293.                 wxBell();
  294.             }
  295.  
  296.             break;
  297.         }
  298.     case 1:
  299.         {
  300.             cbBarInfo* x = mpLayout->FindBarByName(wxString("Bar-1"));
  301.             if(x) 
  302.             {
  303.                 //mpLayout->InverseVisibility(x); 
  304.                 for(int a=0;a<MAX_BAR_STATES;a++)
  305.                 {
  306.                     // see cbPaneDrawPlugin::OnSizeBarWindow( cbSizeBarWndEvent& event ) 
  307.                     x->mDimInfo.mSizes[a].x = 10 + 2 + 2*x->mDimInfo.mHorizGap;
  308.                     x->mDimInfo.mSizes[a].y = 10 + 2 + 2*x->mDimInfo.mVertGap;
  309.                 }
  310.                 x->mpBarWnd->SetSize(10,10);
  311.                 mpLayout->SetBarState(x, wxCBAR_FLOATING, TRUE);  // HACK !!!
  312.                 mpLayout->SetBarState(x, 0, TRUE);                  // HACK !!!
  313.                 wxYield();                                        // HACK !!! needed to resize BEFORE redraw 
  314.                 mpLayout->RefreshNow( TRUE );                     // HACK !!! needed to trigger redraw
  315.                 
  316.                 //  //          mpLayout->SetBarState(x, wxCBAR_FLOATING, TRUE);
  317.                 //  //          mpLayout->RecalcLayout(true);
  318.                 //  //          //        mpLayout->RepositionFloatedBar(x);
  319.                 //  //          mpLayout->RecalcLayout(true);
  320.                 //  //          mpLayout->RepositionFloatedBar(x);
  321.                 //  //            mpLayout->SetBarState(x, 0, TRUE);    
  322.                 //  //            wxYield();
  323.                 //  //            mpLayout->RefreshNow( TRUE );
  324.                 //  //            mpLayout->RecalcLayout(true);
  325.             }
  326.             else    
  327.             {
  328.                 wxBell();
  329.             }
  330.  
  331.             break;
  332.         }
  333.     }
  334.     i++;
  335. }
  336.  
  337.