home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / wxos2240.zip / wxWindows-2.4.0 / contrib / samples / gizmos / multicell / mtest.cpp < prev    next >
C/C++ Source or Header  |  2002-12-16  |  6KB  |  216 lines

  1. /*
  2.  * File:    mtest.cpp
  3.  * Purpose:    wxMultiCellSizer and wxMultiCellCanvas test
  4.  * Author:    Alex Andruschak
  5.  * Created:    2000
  6.  * Updated:    
  7.  * Copyright:
  8.  */
  9.  
  10. static const char sccsid[] = "%W% %G%";
  11.  
  12. #if defined(__GNUG__) && !defined(__APPLE__)
  13.     #pragma implementation
  14.     #pragma interface
  15. #endif
  16.  
  17. #include "wx/wxprec.h"
  18.  
  19. #ifdef __BORLANDC__
  20.     #pragma hdrstop
  21. #endif
  22.  
  23. #ifndef WX_PRECOMP
  24.     #include "wx/wx.h"
  25. #endif
  26.  
  27. #include "wx/gizmos/multicell.h"
  28.  
  29. class MyApp: public wxApp
  30. {public:
  31.     bool OnInit(void);
  32. };
  33.  
  34. class MyFrame: public wxFrame
  35. {
  36.  
  37. public:
  38.     MyFrame(int type, wxFrame *frame, const wxString& title, const wxPoint& pos, const wxSize& size);
  39.  
  40.     void OnCloseWindow(wxCloseEvent& event);
  41.     void OnPaint(wxPaintEvent& event);
  42.     wxMultiCellSizer *sizer;
  43.  
  44.     DECLARE_EVENT_TABLE()
  45. };
  46.  
  47. IMPLEMENT_APP(MyApp)
  48.  
  49. bool MyApp::OnInit(void)
  50. {
  51.     MyFrame *frame = new MyFrame(1, (wxFrame *) NULL, (char *) "wxMultiCellSizer Sample", wxPoint(50, 50), wxDefaultSize); //, wxSize(600, 500));
  52.  
  53.     frame->Show(TRUE);
  54.  
  55.     SetTopWindow(frame);
  56.     frame = new MyFrame(2, (wxFrame *) NULL, (char *) "wxMultiCellCanvas Sample", wxPoint(100, 100), wxSize(600, 500));
  57.  
  58.     frame->Show(TRUE);
  59.  
  60.     SetTopWindow(frame);
  61.     return TRUE;
  62. }
  63.  
  64.  
  65.  
  66. MyFrame::MyFrame(int type, wxFrame *frame, const wxString& title, const wxPoint& pos, const wxSize& size):
  67. wxFrame(frame, -1, title, pos, size, wxDEFAULT_FRAME_STYLE | wxVSCROLL | wxHSCROLL)
  68. {
  69.     CreateStatusBar(1);
  70.     sizer = NULL;
  71.     if (type == 1)
  72.     {
  73.         // create sizer 4 columns 5 rows
  74.         wxSize aa(4,9);
  75.         sizer = new wxMultiCellSizer(aa);
  76.         sizer->SetDefaultCellSize(wxSize(15,15));
  77.         sizer->SetRowHeight(7,5,TRUE);
  78.         sizer->SetRowHeight(8,5,FALSE);
  79.         // add first row
  80.         sizer->Add(
  81.                   new wxButton( this, -1, "B1 - 0,0, horizontal resizable" ),
  82.                   0, 0, 0, new wxMultiCellItemHandle(0,0,1,1, wxDefaultSize, wxHORIZONTAL_RESIZABLE, wxSize(2,2)));
  83.         sizer->Add(
  84.                   new wxButton( this, -1, "B2 - 0,1, vertical resizable" ),
  85.                   0, 0, 0, new wxMultiCellItemHandle(0,1,1,1, wxDefaultSize, wxVERTICAL_RESIZABLE, wxSize(2, 2)));
  86.         sizer->Add(
  87.                   new wxButton( this, -1, "B3 - 0,2" ),
  88.                   0, 0, 0, new wxMultiCellItemHandle(0,2,1,1, wxDefaultSize, wxNOT_RESIZABLE, wxSize(1,1), wxALIGN_CENTER_HORIZONTAL)); //, wxALIGN_CENTER));
  89.         sizer->Add(
  90.                   new wxStaticText(this, -1, "jbb 0,3, lower-right"),
  91.                   0, 0, 0, new wxMultiCellItemHandle(0,3,1,1, wxDefaultSize, wxNOT_RESIZABLE, wxSize(1,1), wxALIGN_BOTTOM | wxALIGN_RIGHT));
  92.  
  93.         // add button for secord row
  94.         sizer->Add(
  95.                   new wxTextCtrl(this, -1, "Text control - 1,0, 4 cols wide"),
  96.                   0, 0, 0, new wxMultiCellItemHandle(1,0,1,4));
  97.  
  98.         // add buttons for next row
  99.         sizer->Add(
  100.                   new wxButton( this, -1, "B6 - 2,0, 2 cols wide" ),
  101.                   0, 0, 0, new wxMultiCellItemHandle(2,0,1,2));
  102.         sizer->Add(
  103.                   new wxButton( this, -1, "B7 - 2,3" ),
  104.                   0, 0, 0, new wxMultiCellItemHandle(2,3,1,1));
  105.  
  106.         // and last additions
  107.         sizer->Add(
  108.                   new wxButton( this, -1, "B8 - 3,0, 4 rows high, vert resizable" ),
  109.                   0, 0, 0, new wxMultiCellItemHandle(3,0,4,1,wxDefaultSize, wxVERTICAL_RESIZABLE));
  110.         sizer->Add(
  111.                   new wxButton( this, -1, "B9 - 3,2, 2 cols wide, vert resizable" ),
  112.                   0, 0, 0, new wxMultiCellItemHandle(3,2,1,2,wxDefaultSize, wxVERTICAL_RESIZABLE));
  113.         sizer->Add(
  114.                   new wxButton( this, -1, "B10 - 4,1, 3 cols wide, vert resizable" ),
  115.                   0, 0, 0, new wxMultiCellItemHandle(4,1,1,3,wxDefaultSize, wxVERTICAL_RESIZABLE));
  116.  
  117.         sizer->Add(
  118.                   new wxButton( this, -1, "B11 - 5,1, 3 cols wide" ),
  119.                   0, 0, 0, new wxMultiCellItemHandle(5,1,1,3));
  120.  
  121.         sizer->Add(
  122.                   new wxButton( this, -1, "B12 - 6,1, 3 cols wide" ),
  123.                   0, 0, 0, new wxMultiCellItemHandle(6,1,1,3));
  124.  
  125.         sizer->Add(
  126.                   new wxButton( this, -1, "B13 - 7,1, 2 cols wide" ),
  127.                   0, 0, 0, new wxMultiCellItemHandle(7,1,1,2));
  128.  
  129.         sizer->Add(
  130.                   new wxButton( this, -1, "B14 - 8,1, 3 cols wide" ),
  131.                   0, 0, 0, new wxMultiCellItemHandle(8,1,1,3));
  132.  
  133.         SetAutoLayout( TRUE );
  134. //    sizer->SetMinSize(sizer->CalcMin());
  135.         SetSizer( sizer );
  136.         wxSize s = sizer->CalcMin();
  137.         wxSize c = GetSize() - GetClientSize();
  138.         SetSizeHints(s.GetWidth() + c.GetWidth() , s.GetHeight() + c.GetHeight());
  139.         sizer->EnableGridLines(this);
  140.     }
  141.     else
  142.     {
  143.         // create sizer 4 columns 5 rows
  144.         wxMultiCellCanvas *sizer = new wxMultiCellCanvas(this, 5,5);
  145.  
  146.         // add first row
  147.         sizer->Add(
  148.                   new wxButton( this, -1, "Button 1" ),
  149.                   0, 0);
  150.         sizer->Add(
  151.                   new wxButton( this, -1, "Button 2" ),
  152.                   0, 1);
  153.         sizer->Add(
  154.                   new wxButton( this, -1, "Button 3" ),
  155.                   0, 2);
  156.         sizer->Add(
  157.                   new wxStaticText(this, -1, "jbb test"),
  158.                   0, 3);
  159.  
  160.         sizer->Add(
  161.                   new wxStaticText(this, -1, "jbb test 2"),
  162.                   0, 4);
  163.  
  164.         // add button for secord row
  165.         sizer->Add(
  166.                   new wxTextCtrl(this, -1, "Text control"),
  167.                   1, 0);
  168.  
  169.         // add buttons for next row
  170.         sizer->Add(
  171.                   new wxButton( this, -1, "Button 6" ),
  172.                   2, 0);
  173.         sizer->Add(
  174.                   new wxButton( this, -1, "Button 7" ),
  175.                   2, 3);
  176.  
  177.         // and last additions
  178.         sizer->Add(
  179.                   new wxButton( this, -1, "Button 8" ),
  180.                   3, 0);
  181.         sizer->Add(
  182.                   new wxButton( this, -1, "Button 9" ),
  183.                   3, 1);
  184.         sizer->Add(
  185.                   new wxButton( this, -1, "Button 10" ),
  186.                   4, 1);
  187.  
  188.         sizer->CalculateConstraints();
  189.         SetSizer( sizer );
  190.         SetAutoLayout( TRUE );
  191.     }
  192. }
  193. // Define the repainting behaviour
  194.  
  195.  
  196. BEGIN_EVENT_TABLE(MyFrame, wxFrame)
  197.    EVT_PAINT(MyFrame::OnPaint)
  198.    EVT_CLOSE(MyFrame::OnCloseWindow)
  199.    END_EVENT_TABLE()
  200.  
  201. void MyFrame::OnPaint(wxPaintEvent& WXUNUSED(event) )
  202. {
  203.     wxPaintDC dc(this);
  204.  
  205.     if (sizer)
  206.     {
  207.         sizer->OnPaint(dc);
  208.     }
  209. }
  210.  
  211. void MyFrame::OnCloseWindow(wxCloseEvent& event)
  212. {
  213.     Destroy();
  214. }
  215.  
  216.