]>
git.saurik.com Git - wxWidgets.git/blob - samples/minifram/minifram.cpp
96d41ad7e333e19523e63ba3dd65c203009e2738
   1 ///////////////////////////////////////////////////////////////////////////// 
   3 // Purpose:     wxMiniFrame sample 
   4 // Author:      Robert Roebling 
   8 // Copyright:   (c) Julian Smart and Robert Roebling 
   9 // Licence:     wxWindows licence 
  10 ///////////////////////////////////////////////////////////////////////////// 
  12 // For compilers that support precompilation, includes "wx/wx.h". 
  13 #include "wx/wxprec.h" 
  23 #include "wx/toolbar.h" 
  26 #if !defined(__WXMSW__) && !defined(__WXPM__) 
  27 #include "mondrian.xpm" 
  29 #include "bitmaps/new.xpm" 
  30 #include "bitmaps/open.xpm" 
  31 #include "bitmaps/save.xpm" 
  32 #include "bitmaps/copy.xpm" 
  33 #include "bitmaps/cut.xpm" 
  34 // #include "bitmaps/paste.xpm" 
  35 #include "bitmaps/print.xpm" 
  36 #include "bitmaps/preview.xpm" 
  37 #include "bitmaps/help.xpm" 
  46 MyMainFrame   
*main_frame 
= (MyMainFrame
*) NULL
; 
  47 MyMiniFrame   
*mini_frame 
= (MyMiniFrame
*) NULL
; 
  48 bool           mini_frame_exists 
= false; 
  49 wxButton      
*button     
= (wxButton
*) NULL
; 
  51 // The `main program' equivalent, creating the windows and returning the 
  55   // Create the main frame window 
  56   main_frame 
= new MyMainFrame((wxFrame 
*) NULL
, wxID_ANY
, _T("wxFrame sample"), 
  57      wxPoint(100, 100), wxSize(300, 200)); 
  59   main_frame
->CreateToolBar(wxNO_BORDER
|wxTB_VERTICAL
, ID_TOOLBAR
); 
  60   InitToolbar(main_frame
->GetToolBar()); 
  62   button 
= new wxButton( main_frame
, ID_REPARENT
, _T("Press to reparent!") ); 
  64   // Create the mini frame window 
  65   mini_frame 
= new MyMiniFrame( main_frame
, wxID_ANY
, _T("wxMiniFrame sample"), 
  66      wxPoint(100, 100), wxSize(220, 100)); 
  67   mini_frame_exists 
= true; 
  69   mini_frame
->CreateToolBar(wxNO_BORDER
|wxTB_HORIZONTAL
|wxTB_FLAT
, ID_TOOLBAR
); 
  70   InitToolbar(mini_frame
->GetToolBar()); 
  72   main_frame
->SetIcon(wxICON(mondrian
)); 
  73   mini_frame
->SetIcon(wxICON(mondrian
)); 
  75   SetTopWindow(main_frame
); 
  77   main_frame
->Show(true); 
  78   mini_frame
->Show(true); 
  83 bool MyApp::InitToolbar(wxToolBar
* toolBar
) 
  85   toolBar
->SetMargins(5, 5); 
  88   wxBitmap
* toolBarBitmaps
[8]; 
  90   toolBarBitmaps
[0] = new wxBitmap( new_xpm 
); 
  91   toolBarBitmaps
[1] = new wxBitmap( open_xpm 
); 
  92   toolBarBitmaps
[2] = new wxBitmap( save_xpm 
); 
  93   toolBarBitmaps
[3] = new wxBitmap( copy_xpm 
); 
  94   toolBarBitmaps
[4] = new wxBitmap( cut_xpm 
); 
  95 //  toolBarBitmaps[5] = new wxBitmap( paste_xpm ); 
  96   toolBarBitmaps
[5] = new wxBitmap( preview_xpm 
); 
  97   toolBarBitmaps
[6] = new wxBitmap( print_xpm 
); 
  98   toolBarBitmaps
[7] = new wxBitmap( help_xpm 
); 
 103   toolBar
->AddTool(wxID_NEW
, *(toolBarBitmaps
[0]), wxNullBitmap
, false, currentX
, wxDefaultCoord
, (wxObject 
*) NULL
, _T("New file")); 
 104   currentX 
+= width 
+ 5; 
 105   toolBar
->AddTool(wxID_OPEN
, *(toolBarBitmaps
[1]), wxNullBitmap
, false, currentX
, wxDefaultCoord
, (wxObject 
*) NULL
, _T("Open file")); 
 106   currentX 
+= width 
+ 5; 
 107   toolBar
->AddTool(wxID_SAVE
, *(toolBarBitmaps
[2]), wxNullBitmap
, false, currentX
, wxDefaultCoord
, (wxObject 
*) NULL
, _T("Save file")); 
 108   currentX 
+= width 
+ 5; 
 109   toolBar
->AddSeparator(); 
 110   toolBar
->AddTool(wxID_COPY
, *(toolBarBitmaps
[3]), wxNullBitmap
, false, currentX
, wxDefaultCoord
, (wxObject 
*) NULL
, _T("Copy")); 
 111   currentX 
+= width 
+ 5; 
 112   toolBar
->AddTool(wxID_CUT
, *(toolBarBitmaps
[4]), wxNullBitmap
, false, currentX
, wxDefaultCoord
, (wxObject 
*) NULL
, _T("Cut")); 
 113   currentX 
+= width 
+ 5; 
 114   toolBar
->AddTool(wxID_PASTE
, *(toolBarBitmaps
[5]), wxNullBitmap
, false, currentX
, wxDefaultCoord
, (wxObject 
*) NULL
, _T("Paste")); 
 115   currentX 
+= width 
+ 5; 
 116   toolBar
->AddSeparator(); 
 117   toolBar
->AddTool(wxID_PRINT
, *(toolBarBitmaps
[6]), wxNullBitmap
, false, currentX
, wxDefaultCoord
, (wxObject 
*) NULL
, _T("Reparent the button")); 
 118   currentX 
+= width 
+ 5; 
 119   toolBar
->AddSeparator(); 
 120   toolBar
->AddTool(wxID_HELP
, *(toolBarBitmaps
[7]), wxNullBitmap
, false, currentX
, wxDefaultCoord
, (wxObject 
*) NULL
, _T("Help")); 
 124   toolBar
->EnableTool( wxID_HELP
, false ); 
 126   // Can delete the bitmaps since they're reference counted 
 128   for (i 
= 0; i 
< 8; i
++) 
 129     delete toolBarBitmaps
[i
]; 
 136 BEGIN_EVENT_TABLE(MyMiniFrame
, wxMiniFrame
) 
 137     EVT_CLOSE  (              MyMiniFrame::OnCloseWindow
) 
 138     EVT_BUTTON (ID_REPARENT
,  MyMiniFrame::OnReparent
) 
 139     EVT_MENU   (wxID_PRINT
,   MyMiniFrame::OnReparent
) 
 142 MyMiniFrame::MyMiniFrame(wxFrame
* parent
, wxWindowID id
, const wxString
& title
, const wxPoint
& pos
, 
 143         const wxSize
& size 
) : 
 144   wxMiniFrame(parent
, id
, title
, pos
, size 
) 
 148 void MyMiniFrame::OnCloseWindow(wxCloseEvent
& WXUNUSED(event
)) 
 150   // make it known that the miniframe is no more 
 151   mini_frame_exists 
= false; 
 155 void MyMiniFrame::OnReparent(wxCommandEvent
& WXUNUSED(event
)) 
 157   button
->Reparent( main_frame 
); 
 159   // we need to force the frame to size its (new) child correctly 
 160   main_frame
->SendSizeEvent(); 
 165 BEGIN_EVENT_TABLE(MyMainFrame
, wxFrame
) 
 166     EVT_CLOSE  (              MyMainFrame::OnCloseWindow
) 
 167     EVT_BUTTON (ID_REPARENT
,  MyMainFrame::OnReparent
) 
 168     EVT_MENU   (wxID_PRINT
,   MyMainFrame::OnReparent
) 
 171 MyMainFrame::MyMainFrame(wxFrame
* parent
, wxWindowID id
, const wxString
& title
, const wxPoint
& pos
, 
 172         const wxSize
& size 
) : 
 173   wxFrame(parent
, id
, title
, pos
, size 
) 
 177 void MyMainFrame::OnCloseWindow(wxCloseEvent
& WXUNUSED(event
)) 
 182 void MyMainFrame::OnReparent(wxCommandEvent
& WXUNUSED(event
)) 
 184   // practical jokers might find satisfaction in reparenting the button 
 185   // after closing the mini_frame. We'll have the last laugh. 
 186   if (! mini_frame_exists
) 
 187     wxMessageBox(_T("The miniframe no longer exists.\n") 
 188                  _T("You don't want to make this button an orphan, do you?"), 
 189                  _T("You got to be kidding")); 
 192     button
->Reparent( mini_frame 
); 
 195     mini_frame
->SendSizeEvent();