core/vgui/impl/wx/vgui_wx_window.cxx
Go to the documentation of this file.
00001 // This is core/vgui/impl/wx/vgui_wx_window.cxx
00002 //=========================================================================
00003 //:
00004 // \file
00005 // \brief  wxWidgets implementation of vgui_window.
00006 //
00007 // See vgui_wx_window.h for details.
00008 //=========================================================================
00009 
00010 #include "vgui_wx_window.h"
00011 #include "vgui_wx_adaptor.h"
00012 #include "vgui_wx_menu.h"
00013 #include "vgui_wx_statusbar.h"
00014 
00015 #include <vgui/vgui.h>
00016 
00017 #include <wx/frame.h>
00018 #include <wx/statusbr.h>
00019 
00020 #include <vcl_cassert.h>
00021 
00022 //-------------------------------------------------------------------------
00023 // vgui_wx_window implementation - construction & destruction.
00024 //-------------------------------------------------------------------------
00025 //: Constructor - create a new window.
00026 vgui_wx_window::vgui_wx_window(int width, int height, const char* title)
00027   : frame_(new wxFrame(0, wxID_ANY, wxString(title,wxConvUTF8)))//, wxDefaultPosition, wxSize(width, height)))
00028   , menu_(0)
00029 {
00030   init_window();
00031   frame_->SetClientSize(width+3, height+3);
00032 }
00033 
00034 //: Constructor - create a new window with a menubar.
00035 vgui_wx_window::vgui_wx_window(int width,
00036                                int height,
00037                                const vgui_menu& menubar,
00038                                const char* title)
00039   : frame_(new wxFrame(0, wxID_ANY, wxString(title,wxConvUTF8), wxDefaultPosition, wxSize(width, height)))
00040   , menu_(0)
00041 {
00042   init_window();
00043   set_menubar(menubar);
00044 }
00045 
00046 //: Destructor.
00047 vgui_wx_window::~vgui_wx_window(void)
00048 {
00049   delete statusbar_;
00050 
00051   if (menu_)
00052   {
00053     frame_->PopEventHandler(true);
00054     // ***** delete the wxMenu, or does the frame do it?
00055     //       if so, I need to store a handle to it...
00056     // *****
00057   }
00058 }
00059 
00060 //: Catch all constructor.
00061 void vgui_wx_window::init_window(void)
00062 {
00063   adaptor_ = new vgui_wx_adaptor(frame_);
00064 
00065   statusbar_ = new vgui_wx_statusbar;
00066   statusbar_->set_widget(frame_->CreateStatusBar());
00067 
00068   // ***** if we support multiple windows, then i think we need to redirect
00069   //       vgui::out to the statusbar each time the window gets the focus
00070   //       (if the statusbar is enabled) and redirect it to standard output
00071   //       every time it loses the focus...
00072   // *****
00073   vgui::out.rdbuf(statusbar_->statusbuf());
00074 }
00075 
00076 //-------------------------------------------------------------------------
00077 // vgui_wx_window implementation.
00078 //-------------------------------------------------------------------------
00079 void vgui_wx_window::set_menubar(const vgui_menu& menubar)
00080 {
00081   if (menu_)
00082   {
00083     frame_->PopEventHandler(true);
00084     menu_ = 0;
00085     // ***** delete the wxMenu, or does the frame do it?
00086     //       if so, I need to store a handle to it...
00087     // *****
00088   }
00089 
00090   menu_ = new vgui_wx_menu;
00091   frame_->SetMenuBar(menu_->create_wx_menubar(menubar));
00092   frame_->PushEventHandler(menu_);
00093 }
00094 
00095 //: If true, activate the statusbar (if it exists).
00096 void vgui_wx_window::set_statusbar(bool activate)
00097 {
00098   activate ? frame_->GetStatusBar()->Show() : frame_->GetStatusBar()->Hide();
00099 }
00100 
00101 //: Set the default adaptor (if it exists) to the given vgui_adaptor.
00102 // These refer to the default/current adaptor, if that makes sense. It is
00103 // not a requirement that it should make sense.
00104 void vgui_wx_window::set_adaptor(vgui_adaptor* adaptor)
00105 {
00106   // ***** how do I replace the client canvas? like this?
00107   //delete adaptor_;
00108   frame_->RemoveChild(adaptor_);
00109   adaptor_ = new vgui_wx_adaptor(frame_);
00110 
00111   // ***** do I need to show it now?
00112 }
00113 
00114 //: Get the default adaptor (if it exists).
00115 vgui_adaptor* vgui_wx_window::get_adaptor(void)
00116 {
00117   return adaptor_;
00118 }
00119 
00120 //: Get the status bar (if it exists).
00121 vgui_statusbar* vgui_wx_window::get_statusbar(void)
00122 {
00123   return statusbar_;
00124 }
00125 
00126 //: If true, activate horizontal scrollbar (if it exists).
00127 void vgui_wx_window::enable_hscrollbar(bool show)
00128 {
00129   if (show)
00130   {
00131     frame_->SetScrollbar(wxHORIZONTAL, 0, 1, 100);
00132   }
00133   else
00134   {
00135     // ***** how do I hide it?
00136     assert(false);
00137   }
00138 }
00139 
00140 //: If true, activate vertical scrollbar (if it exists).
00141 void vgui_wx_window::enable_vscrollbar(bool show)
00142 {
00143   if (show)
00144   {
00145     frame_->SetScrollbar(wxVERTICAL, 0, 1, 100);
00146   }
00147   else
00148   {
00149     // ***** how do I hide it?
00150     assert(false);
00151   }
00152 }
00153 
00154 //: Change window shape to new given width and height.
00155 void vgui_wx_window::reshape(unsigned width, unsigned height)
00156 {
00157   // ***** should this resize the window, or the client area?
00158   //frame_->SetSize(width, height);
00159   frame_->SetClientSize(width, height);
00160 }
00161 
00162 //: Move the window to the new given x,y position.
00163 void vgui_wx_window::reposition(int x, int y)
00164 {
00165   frame_->SetSize(x, y, -1, -1);
00166 }
00167 
00168 //: Use the given text as the window title (if the window has a title).
00169 void vgui_wx_window::set_title(vcl_string const& title)
00170 {
00171   frame_->SetTitle( wxString(title.c_str(), wxConvUTF8) );
00172 }
00173 
00174 //: Set the position of the horizontal scrollbar, returns old position.
00175 int vgui_wx_window::set_hscrollbar(int pos)
00176 {
00177   int temp = frame_->GetScrollPos(wxHORIZONTAL);
00178   frame_->SetScrollPos(wxHORIZONTAL, pos);
00179   return temp;
00180 }
00181 
00182 //: Set the position of the vertical scrollbar, returns old position.
00183 int vgui_wx_window::set_vscrollbar(int pos)
00184 {
00185   int temp = frame_->GetScrollPos(wxVERTICAL);
00186   frame_->SetScrollPos(wxVERTICAL, pos);
00187   return temp;
00188 }