home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / wxos2240.zip / wxWindows-2.4.0 / contrib / samples / fl / fl_sample2 / fl_sample2.cpp < prev    next >
C/C++ Source or Header  |  2001-07-24  |  5KB  |  195 lines

  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name:        fl_sample2.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_sample2.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.  
  37. class MyApp: public wxApp
  38. public:
  39.     bool OnInit(void);
  40. };
  41.  
  42. class MyFrame: public wxFrame
  43. {
  44. protected:
  45.     wxFrameLayout* mpLayout;
  46.     wxWindow*      mpClientWnd;
  47.     
  48.     wxTextCtrl* CreateTextCtrl( const wxString& value );
  49.         
  50. public:
  51.     MyFrame( wxWindow* parent, char *title );
  52.     ~MyFrame();
  53.     
  54.     void populateMyFrame();
  55.     void OnLoad( wxCommandEvent& event );
  56.     void OnStore( wxCommandEvent& event );
  57.     void OnQuit( wxCommandEvent& event );
  58.     
  59.     bool OnClose(void) { return TRUE; }
  60.     
  61.     DECLARE_EVENT_TABLE()
  62. };
  63.  
  64. /***** Implementation for class MyApp *****/
  65.  
  66. IMPLEMENT_APP    (MyApp)
  67.  
  68. bool MyApp::OnInit(void)
  69. {
  70.     // wxWindows boiler-plate:
  71.     
  72.     MyFrame *frame = new MyFrame(NULL, "wxFrameLayout sample");
  73.     
  74.     wxMenu *file_menu = new wxMenu;
  75.     
  76.     file_menu->Append( ID_LOAD,  "&Load layout"  );
  77.     file_menu->Append( ID_STORE, "&Store layout"  );
  78.     file_menu->AppendSeparator();
  79.     
  80.     file_menu->Append( ID_QUIT, "E&xit" );
  81.     
  82.     wxMenuBar *menu_bar = new wxMenuBar;
  83.     
  84.     menu_bar->Append(file_menu, "&File");
  85.     
  86.     frame->CreateStatusBar(3);
  87.     frame->SetMenuBar(menu_bar);
  88.     
  89.     frame->Show(TRUE);
  90.     SetTopWindow(frame);
  91.     frame->populateMyFrame();
  92.     
  93.     return TRUE;
  94. }
  95.  
  96. /***** Immlementation for class MyFrame *****/
  97.  
  98. BEGIN_EVENT_TABLE(MyFrame, wxFrame)
  99.     EVT_MENU( ID_LOAD,  MyFrame::OnLoad  )
  100.     EVT_MENU( ID_STORE, MyFrame::OnStore )
  101.     EVT_MENU( ID_QUIT,  MyFrame::OnQuit  )
  102. END_EVENT_TABLE()
  103.  
  104. MyFrame::MyFrame( wxWindow* parent, char *title )
  105.     : wxFrame( parent, -1, "NewTest-II", wxDefaultPosition,
  106.           wxSize( 700, 500 ),
  107.           wxCLIP_CHILDREN | wxMINIMIZE_BOX | wxMAXIMIZE_BOX |
  108.           wxTHICK_FRAME   | wxSYSTEM_MENU  | wxCAPTION,
  109.           "freimas" )
  110. {
  111. }
  112.  
  113. void MyFrame::populateMyFrame()
  114. {
  115.     mpClientWnd = CreateTextCtrl( "Client window" );
  116.     
  117.     mpLayout = new wxFrameLayout( this, mpClientWnd );
  118.         
  119.     ///  mpLayout->PushDefaultPlugins();
  120.     ///  mpLayout->AddPlugin( CLASSINFO( cbBarHintsPlugin ) ); // facny "X"es and beveal for barso
  121.     ///  //mpLayout->AddPlugin( CLASSINFO( cbHintAnimationPlugin ) );
  122.         
  123.     cbDimInfo sizes( 80,65,     // when docked horizontally      
  124.                      80,165,    // when docked vertically        
  125.                      180,30,    // when floated                  
  126.                      TRUE,      // the bar is fixed-size
  127.                      5,         // vertical gap (bar border)
  128.                      5          // horizontal gap (bar border)
  129.                    ); 
  130.         
  131.     // drop-in 20 bars    
  132.     for( int i = 1; i <= 10; ++i )
  133.     {
  134.         wxSleep(1);
  135.         wxYield(); // CHECK!
  136.         
  137.         char buf[4];
  138.         sprintf( buf, "%d", i );
  139.         wxString name = wxString("Bar-");
  140.         name += buf;
  141.         
  142.         //sizes.mIsFixed = i % 2 > 0; // every fifth bar is not fixed-size
  143.         
  144.         if ( !sizes.mIsFixed ) name += " (flexible)";
  145.         //      mpLayout->AddBar( CreateTextCtrl(name),// bar window
  146.         mpLayout->AddBar( new wxTextCtrl(this, -1, name),// bar window
  147.                           sizes, i % MAX_PANES,// alignment ( 0-top,1-bottom, etc)
  148.                           0,                   // insert into 0th row (vert. position)
  149.                           0,                   // offset from the start of row (in pixels)
  150.                           name                 // name to refere in customization pop-ups
  151.                         );
  152.  
  153.         mpLayout->RecalcLayout(true);
  154.         
  155.         // Layout();
  156.         // Refresh();
  157.     }
  158. }
  159.  
  160. MyFrame::~MyFrame()
  161. {
  162.     // layout is not a window, should be released manually
  163.     if ( mpLayout ) 
  164.         delete mpLayout;
  165. }
  166.  
  167. wxTextCtrl* MyFrame::CreateTextCtrl( const wxString& value )
  168. {
  169.     wxTextCtrl* pCtrl = new wxTextCtrl( this, -1, value, 
  170.                                 wxPoint(0,0), wxSize(1,1), wxTE_MULTILINE );
  171.     
  172.     pCtrl->SetBackgroundColour( wxColour( 255,255,255 ) );
  173.     
  174.     return pCtrl;
  175. }
  176.  
  177. void MyFrame::OnLoad( wxCommandEvent& event )
  178. {
  179.     wxMessageBox("Hey - you found a BIG question-mark !!");
  180. }
  181.  
  182. void MyFrame::OnStore( wxCommandEvent& event )
  183. {
  184.     wxMessageBox("Hey - you found another BIG question-mark !!");
  185. }
  186.  
  187. void MyFrame::OnQuit( wxCommandEvent& event )
  188. {
  189.     Show( FALSE ); // TRICK:: hide it, to avoid flickered destruction
  190.     
  191.     Close(TRUE);
  192. }
  193.  
  194.