![]() |
TAPs 0.7.7.3
|
00001 /****************************************************************************** 00002 TAPsWXFrame.hpp 00003 A main frame using wxWidgets Toolkit. 00004 00005 SUKITTI PUNAK (05/05/2006) 00006 UPDATE (05/05/2006) 00007 ******************************************************************************/ 00008 #include "TAPsWXFrame.hpp" 00009 // Using Inclusion Model (i.e. definitions are included in declarations) 00010 // (this name.cpp is included in name.hpp) 00011 // Each friend is defined directly inside its declaration. 00012 00013 //============================================================================= 00014 // REMARK: WXID is a namespace with defining enum for extra ids that that do 00015 // not included in wxID. 00016 // See <TAPs/wxWidgets/TAPsWXEnumList.hpp> 00017 //============================================================================= 00018 00019 BEGIN_NAMESPACE_TAPs 00020 //============================================================================= 00021 //----------------------------------------------------------------------------- 00022 BEGIN_EVENT_TABLE( WXFrame, wxFrame ) 00023 //--------------------------------------------------------------- 00024 // Menu File 00025 EVT_MENU( wxID_OPEN, WXFrame::OnFileOpen ) 00026 EVT_MENU( wxID_CLOSE, WXFrame::OnFileClose ) 00027 EVT_MENU( wxID_CLOSE, WXFrame::OnFileClose ) 00028 EVT_MENU( wxID_CLOSE, WXFrame::OnFileClose ) 00029 EVT_MENU( WXID::MENU_EXPORT, WXFrame::OnFileExport ) 00030 EVT_MENU( wxID_EXIT, WXFrame::OnFileExit ) 00031 //--------------------------------------------------------------- 00032 // Menu Edit 00033 EVT_MENU( wxID_UNDO, WXFrame::OnEditUndo ) 00034 EVT_MENU( wxID_REDO, WXFrame::OnEditRedo ) 00035 //--------------------------------------------------------------- 00036 // Menu View 00037 EVT_MENU( wxID_RESET, WXFrame::OnViewReset ) 00038 //--------------------------------------------------------------- 00039 // Menu Window 00040 EVT_MENU( WXID::MENU_NEW_WINDOW, WXFrame::OnWindowNewWindow ) 00041 //--------------------------------------------------------------- 00042 // Menu Help 00043 EVT_MENU( wxID_ABOUT, WXFrame::OnHelpAbout ) 00044 //--------------------------------------------------------------- 00045 END_EVENT_TABLE() 00046 //----------------------------------------------------------------------------- 00047 //============================================================================= 00048 00049 //============================================================================= 00050 // Static Fn for Creating WXFrame 00051 //----------------------------------------------------------------------------- 00052 WXFrame * WXFrame::Create ( 00053 WXFrame * parentFrame, 00054 bool isCloneWindow ) 00055 { 00056 wxString str = wxT( "Another wxWidgets Application" ); 00057 if ( isCloneWindow ) str += wxT( " - Clone" ); 00058 WXFrame * frame = 00059 new WXFrame( NULL, str, wxDefaultPosition, wxSize( 540, 560 ) ); 00060 //--------------------------------------------------------------- 00061 // Create Main Menu 00062 CreateMainMenu( frame ); 00063 //--------------------------------------------------------------- 00064 if ( parentFrame ) { 00065 } 00066 else { 00067 } 00068 //--------------------------------------------------------------- 00069 // Show the frame 00070 frame->Show( true ); 00071 //--------------------------------------------------------------- 00072 return frame; 00073 } 00074 //----------------------------------------------------------------------------- 00075 //============================================================================= 00076 00077 00078 //============================================================================= 00079 // Constructor for Class WXFrame 00080 //----------------------------------------------------------------------------- 00081 WXFrame::WXFrame ( 00082 wxWindow * parent, 00083 const wxString & title, 00084 const wxPoint & pos, 00085 const wxSize & size, 00086 long style ) 00087 : wxFrame( parent, wxID_ANY, title, pos, size, style ) 00088 { 00089 SetIcon( wxIcon( sample_xpm ) ); 00090 } 00091 //----------------------------------------------------------------------------- 00092 //============================================================================= 00093 00094 //============================================================================= 00095 // START MENU FILE 00096 //----------------------------------------------------------------------------- 00097 // Intercept Open File menu commands 00098 void WXFrame::OnFileOpen ( wxCommandEvent & WXUNUSED(event) ) 00099 { 00100 wxString caption = wxT("Choose a file"); 00101 wxString wildcard 00102 = wxT( "BMP files (*.bmp)|*.bmp|GIF files (*.gif)|*.gif"); 00103 //= wxT( " files (*.bmp)|*.bmp|GIF files (*.gif)|*.gif"); 00104 //wxString defaultDir = wxT( "d:\\" ); 00105 wxString defaultDir = wxEmptyString; 00106 wxString defaultFilename = wxEmptyString; 00107 wxFileDialog fileDialog( this, wxT("Open A Model File Dialog"), 00108 defaultDir, 00109 defaultFilename, wxT(""), wxOPEN ); 00110 //defaultFilename, wildcard, wxOPEN ); 00111 //--------------------------------------------------------------- 00112 if ( fileDialog.ShowModal() == wxID_OK ) { 00113 wxString info; 00114 info.Printf( wxT("Full file name: %s\n") 00115 wxT("Path: %s\n") 00116 wxT("Name: %s\n"), 00117 fileDialog.GetPath().c_str(), 00118 fileDialog.GetDirectory().c_str(), 00119 fileDialog.GetFilename().c_str() ); 00120 wxMessageDialog dialog ( this, info, wxT("Selected File") ); 00121 dialog.ShowModal(); 00122 wxString path = fileDialog.GetPath(); 00123 int filterIndex = fileDialog.GetFilterIndex(); 00124 } 00125 //--------------------------------------------------------------- 00126 // Repaint the OpenGL window 00127 //this->RetGLCanvasPtr()->OnPaint( wxPaintEvent() ); 00128 //--------------------------------------------------------------- 00129 } 00130 //----------------------------------------------------------------------------- 00131 // Intercept Close File menu commands 00132 void WXFrame::OnFileClose ( wxCommandEvent & WXUNUSED(event) ) 00133 { 00134 WX::Debug::DisplayDialog( wxString( "On File Close" ) ); 00135 //--------------------------------------------------------------- 00136 // Repaint the OpenGL window 00137 //this->RetGLCanvasPtr()->OnPaint( wxPaintEvent() ); 00138 //--------------------------------------------------------------- 00139 } 00140 //----------------------------------------------------------------------------- 00141 // Intercept Export File menu commands 00142 void WXFrame::OnFileExport ( wxCommandEvent & WXUNUSED(event) ) 00143 { 00144 WX::Debug::DisplayDialog( wxString( "On File Export" ) ); 00145 //--------------------------------------------------------------- 00146 // Repaint the OpenGL window 00147 //this->RetGLCanvasPtr()->OnPaint( wxPaintEvent() ); 00148 //--------------------------------------------------------------- 00149 } 00150 //----------------------------------------------------------------------------- 00151 // Intercept Exit menu commands 00152 void WXFrame::OnFileExit ( wxCommandEvent & WXUNUSED(event) ) 00153 { 00154 //WX::Debug::DisplayDialog( wxString( "On File Exit" ) ); 00155 //--------------------------------------------------------------- 00156 // True is to force the frame to close 00157 Close( true ); 00158 //ExitHandler(); // User defined function 00159 //--------------------------------------------------------------- 00160 } 00161 //----------------------------------------------------------------------------- 00162 // END MENU FILE 00163 //============================================================================= 00164 00165 //============================================================================= 00166 // START MENU EDIT 00167 //----------------------------------------------------------------------------- 00168 // Intercept Undo Edit menu commands 00169 void WXFrame::OnEditUndo ( wxCommandEvent & WXUNUSED(event) ) 00170 { 00171 WX::Debug::DisplayDialog( wxString( "On Edit Undo" ) ); 00172 //--------------------------------------------------------------- 00173 // Repaint the OpenGL window 00174 //this->RetGLCanvasPtr()->OnPaint( wxPaintEvent() ); 00175 //--------------------------------------------------------------- 00176 } 00177 //----------------------------------------------------------------------------- 00178 // Intercept Redo Edit menu commands 00179 void WXFrame::OnEditRedo ( wxCommandEvent & WXUNUSED(event) ) 00180 { 00181 WX::Debug::DisplayDialog( wxString( "On Edit Redo" ) ); 00182 //--------------------------------------------------------------- 00183 // Repaint the OpenGL window 00184 //this->RetGLCanvasPtr()->OnPaint( wxPaintEvent() ); 00185 //--------------------------------------------------------------- 00186 } 00187 //----------------------------------------------------------------------------- 00188 // END MENU EDIT 00189 //============================================================================= 00190 00191 //============================================================================= 00192 // START MENU VIEW 00193 //----------------------------------------------------------------------------- 00194 // Intercept Reset View menu commands 00195 void WXFrame::OnViewReset ( wxCommandEvent & WXUNUSED(event) ) 00196 { 00197 WX::Debug::DisplayDialog( wxString( "On View Reset" ) ); 00198 //--------------------------------------------------------------- 00199 // Repaint the OpenGL window 00200 //this->RetGLCanvasPtr()->OnPaint( wxPaintEvent() ); 00201 //--------------------------------------------------------------- 00202 } 00203 //----------------------------------------------------------------------------- 00204 // END MENU VIEW 00205 //============================================================================= 00206 00207 //============================================================================= 00208 // START MENU WINDOW 00209 //----------------------------------------------------------------------------- 00210 // Intercept New Window Window menu commands 00211 void WXFrame::OnWindowNewWindow ( wxCommandEvent & WXUNUSED(event) ) 00212 { 00213 WX::Debug::DisplayDialog( wxString( "On Window New Window" ) ); 00214 //--------------------------------------------------------------- 00215 // Repaint the OpenGL window 00216 //this->RetGLCanvasPtr()->OnPaint( wxPaintEvent() ); 00217 //--------------------------------------------------------------- 00218 } 00219 //----------------------------------------------------------------------------- 00220 // END MENU WINDOW 00221 //============================================================================= 00222 00223 //============================================================================= 00224 // START MENU HELP 00225 //----------------------------------------------------------------------------- 00226 // Intercept About Help menu commands 00227 void WXFrame::OnHelpAbout ( wxCommandEvent & WXUNUSED(event) ) 00228 { 00229 WX::Debug::DisplayDialog( wxString( "On Help About" ) ); 00230 //--------------------------------------------------------------- 00231 // Repaint the OpenGL window 00232 //this->RetGLCanvasPtr()->OnPaint( wxPaintEvent() ); 00233 //--------------------------------------------------------------- 00234 } 00235 //----------------------------------------------------------------------------- 00236 // END MENU HELP 00237 //============================================================================= 00238 00239 //============================================================================= 00240 // CREATE MENUS 00241 //----------------------------------------------------------------------------- 00242 void WXFrame::CreateMainMenu ( WXFrame * frame ) 00243 { 00244 //--------------------------------------------------------------- 00245 // Make MenuBar and Menus 00246 frame->CreateMenuBar(); 00247 //----------------------------------------------------- 00248 // Set MenuBar 00249 frame->SetMenuBar( frame->m_menuBar ); 00250 frame->CreateStatusBar(); 00251 frame->SetStatusText( "Another wxWidgets Application" ); 00252 } 00253 //----------------------------------------------------------------------------- 00254 void WXFrame::CreateMenuBar () 00255 { 00256 m_menuBar = new wxMenuBar; 00257 //--------------------------------------------------------------- 00258 CreateMenuFile(); 00259 CreateMenuEdit(); 00260 CreateMenuView(); 00261 CreateMenuWindow(); 00262 CreateMenuHelp(); 00263 //--------------------------------------------------------------- 00264 m_menuBar->Append( m_menuFile, wxT( "&File" ) ); 00265 m_menuBar->Append( m_menuEdit, wxT( "&Edit" ) ); 00266 m_menuBar->Append( m_menuView, wxT( "&View" ) ); 00267 m_menuBar->Append( m_menuWindow, wxT( "&Window" ) ); 00268 m_menuBar->Append( m_menuHelp, wxT( "&Help" ) ); 00269 //--------------------------------------------------------------- 00270 } 00271 //----------------------------------------------------------------------------- 00272 void WXFrame::CreateMenuFile () 00273 { 00274 //----------------------------------------------------- 00275 // Menu File 00276 m_menuFile = new wxMenu; 00277 m_menuFile->Append( wxID_OPEN, wxT("&Open Model...\tCtrl+O"), wxT("Opens a file") ); 00278 m_menuFile->Append( wxID_CLOSE, wxT("&Close Model\tCtrl+F4"), wxT("Closes the file") ); 00279 m_menuFile->AppendSeparator(); 00280 m_menuFile->Append( WXID::MENU_EXPORT, wxT("&Export..."), 00281 wxT("Export ...") ); 00282 m_menuFile->AppendSeparator(); 00283 m_menuFile->Append( wxID_EXIT, wxT("E&xit"), wxT("Quits the program") ); 00284 } 00285 //----------------------------------------------------------------------------- 00286 void WXFrame::CreateMenuEdit () 00287 { 00288 //----------------------------------------------------- 00289 // Menu Edit 00290 m_menuEdit = new wxMenu; 00291 m_menuEdit->Append( wxID_UNDO, wxT("&Undo\tCtrl+Z"), wxT("Undo") ); 00292 m_menuEdit->Append( wxID_REDO, wxT("&Redo\tCtrl+Y"), wxT("Redo") ); 00293 } 00294 //----------------------------------------------------------------------------- 00295 void WXFrame::CreateMenuView () 00296 { 00297 //----------------------------------------------------- 00298 // Menu View 00299 m_menuView = new wxMenu; 00300 m_menuView->Append( wxID_RESET, wxT("&Reset\tCtrl+R"), wxT("Reset") ); 00301 } 00302 //----------------------------------------------------------------------------- 00303 void WXFrame::CreateMenuWindow () 00304 { 00305 //----------------------------------------------------- 00306 // Menu View 00307 m_menuWindow = new wxMenu; 00308 m_menuWindow->Append( WXID::MENU_NEW_WINDOW, wxT("&New Window"), wxT("New Window") ); 00309 } 00310 //----------------------------------------------------------------------------- 00311 void WXFrame::CreateMenuHelp () 00312 { 00313 //----------------------------------------------------- 00314 // Menu Help 00315 m_menuHelp = new wxMenu; 00316 m_menuHelp->Append( wxID_ABOUT, wxT("&About"), wxT("About this application") ); 00317 } 00318 //----------------------------------------------------------------------------- 00319 //============================================================================= 00320 00321 //============================================================================= 00322 // UPDATE MENUS 00323 //----------------------------------------------------------------------------- 00324 void WXFrame::UpdateMenuFile () 00325 {} 00326 //----------------------------------------------------------------------------- 00327 void WXFrame::UpdateMenuEdit () 00328 {} 00329 //----------------------------------------------------------------------------- 00330 void WXFrame::UpdateMenuView () 00331 {} 00332 //----------------------------------------------------------------------------- 00333 void WXFrame::UpdateMenuWindow () 00334 {} 00335 //----------------------------------------------------------------------------- 00336 void WXFrame::UpdateMenuHelp () 00337 {} 00338 //----------------------------------------------------------------------------- 00339 //============================================================================= 00340 00341 //----------------------------------------------------------------------------- 00342 //============================================================================= 00343 END_NAMESPACE_TAPs 00344 //----------------------------------------------------------------------------- 00345 //345678901234567890123456789012345678901234567890123456789012345678901234567890 00346 //--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8