Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members   Related Pages  

MainFrm.cpp

00001 /* QuestDesigner - Open Zelda's Project
00002    Copyright (C) 2003 Kronuz
00003    Copyright (C) 2001/2003 Open Zelda's Project
00004  
00005    This program is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU General Public License
00007    as published by the Free Software Foundation; either version 2
00008    of the License, or (at your option) any later version.
00009 
00010    This program is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013    GNU General Public License for more details.
00014 
00015    You should have received a copy of the GNU General Public License
00016    along with this program; if not, write to the Free Software
00017    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00018 */
00020 // MainFrm.cpp : implmentation of the CMainFrame class
00021 //
00022 
00023 #include "stdafx.h"
00024 #include "QuestDesigner.h"
00025 
00026 #include "aboutdlg.h"
00027 
00028 #include <ssfiledialog.h>
00029 
00030 static int nStatusBarPanes [] =
00031 {
00032     ID_DEFAULT_PANE,
00033     ID_POSITION_PANE,
00034     ID_OVERTYPE_PANE,
00035     ID_READONLY_PANE
00036 };
00037 
00038 static LPCTSTR lpcszQuestDesignerRegKey = _T ( "Software\\OpenZelda\\QuestDesigner" );
00039 
00040 BOOL CMainFrame::PreTranslateMessage(MSG* pMsg)
00041 {
00042     if(baseClass::PreTranslateMessage(pMsg))
00043         return TRUE;
00044 
00045     HWND hWndFocus = ::GetFocus();
00046     HWND hWndMDIActive = MDIGetActive();
00047 
00048     if((hWndMDIActive == hWndFocus) || (::IsChild(hWndMDIActive, hWndFocus))) {
00049         if(hWndMDIActive != NULL)
00050             return (BOOL)::SendMessage(hWndMDIActive, WM_FORWARDMSG, 0, (LPARAM)pMsg);
00051     } 
00052     else if(m_InfoFrame.IsWindow() && m_InfoFrame.IsChild(hWndFocus)) {
00053         if(m_InfoFrame.PreTranslateMessage(pMsg))
00054             return TRUE;
00055     }
00056     return FALSE;
00057 }
00058 
00059 BOOL CMainFrame::OnIdle()
00060 {
00061     // Update all the toolbar items
00062     UIUpdateToolBar();
00063     // Update all the menu items
00064     UIUpdateMenuItems ();
00065 
00066     return FALSE;
00067 }
00068 
00069 LRESULT CMainFrame::OnCreate(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
00070 {
00071     // We tell the compiler about our main frame
00072     m_SmallCompiler.m_shWnd = m_hWnd;
00073 
00074     // create command bar window
00075     HWND hWndCmdBar = m_CmdBar.Create(m_hWnd, rcDefault, NULL, ATL_SIMPLE_CMDBAR_PANE_STYLE);
00076     // attach the menu to the command bar
00077     m_CmdBar.AttachMenu(GetMenu());
00078     // load command bar images
00079     m_CmdBar.LoadImages(IDR_MAINFRAME);
00080     // remove the old style menu
00081     SetMenu(NULL);
00082 
00083     // create a toolbar
00084     HWND hWndToolBar = CreateSimpleToolBarCtrl(m_hWnd, IDR_MAINFRAME, FALSE, ATL_SIMPLE_TOOLBAR_PANE_STYLE);
00085     // add the toolbar to the UI update map
00086     UIAddToolBar(hWndToolBar);
00087 
00088     // create a rebat to hold both: the command bar and the toolbar
00089     CreateSimpleReBar(ATL_SIMPLE_REBAR_NOBORDER_STYLE);
00090     AddSimpleReBarBand(hWndCmdBar);
00091     AddSimpleReBarBand(hWndToolBar, NULL, TRUE);
00092 
00093     // create a status bar
00094     CreateSimpleStatusBar(_T ( "Ready" ) ) ||
00095          !m_wndStatusBar.SubclassWindow ( m_hWndStatusBar ) ||
00096          !m_wndStatusBar.SetPanes ( nStatusBarPanes, 
00097             sizeof ( nStatusBarPanes ) / sizeof ( int ), false);
00098 
00099     // finally we create the MDI client
00100     CreateMDIClient();
00101 
00102     m_tabbedClient.SetTabOwnerParent(m_hWnd);
00103     BOOL bSubclass = m_tabbedClient.SubclassWindow(m_hWndMDIClient);
00104     m_CmdBar.UseMaxChildDocIconAndFrameCaptionButtons(false);
00105     m_CmdBar.SetMDIClient(m_hWndMDIClient);
00106 
00107     UIAddToolBar(hWndToolBar);
00108     UISetCheck(ID_VIEW_TOOLBAR, TRUE);
00109     UISetCheck(ID_VIEW_STATUS_BAR, TRUE);
00110 
00111     // Update all the menu items
00112     UIUpdateMenuItems();
00113 
00114     // register object for message filtering and idle updates
00115     CMessageLoop* pLoop = _Module.GetMessageLoop();
00116     ATLASSERT(pLoop != NULL);
00117     pLoop->AddMessageFilter(this);
00118     pLoop->AddIdleHandler(this);
00119 
00120     InitializeDockingFrame();
00121     InitializeDefaultPanes();
00122 
00123     PostMessage(CWM_INITIALIZE);
00124 
00125     return 0;
00126 }
00127 void CMainFrame::InitializeDefaultPanes(void)
00128 {
00129     CRect rcClient;
00130     GetClientRect(&rcClient);
00131 
00132     CRect rcFloat(0,0,400,200);
00133     CRect rcDock(0,0,150,rcClient.Width()-200);
00134 
00135     DWORD dwStyle=WS_OVERLAPPEDWINDOW | WS_POPUP | WS_CLIPCHILDREN | WS_CLIPSIBLINGS;
00136     m_InfoFrame.Create(m_hWnd, rcFloat, _T("Information Window"), dwStyle);
00137     DockWindow(
00138         m_InfoFrame,
00139         dockwins::CDockingSide(dockwins::CDockingSide::sBottom),
00140         0 /*nBar*/,
00141         float(0.0)/*fPctPos*/,
00142         rcDock.Width() /* nWidth*/,
00143         rcDock.Height() /* nHeight*/);
00144 
00145     m_OutputView.Create(m_InfoFrame, rcDefault, NULL, WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_HSCROLL | WS_VSCROLL | ES_AUTOHSCROLL | ES_AUTOVSCROLL | ES_MULTILINE | ES_NOHIDESEL, WS_EX_CLIENTEDGE);
00146     m_TaskListView.Create(m_InfoFrame, rcDefault, NULL, WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_HSCROLL | WS_VSCROLL | ES_AUTOHSCROLL | ES_AUTOVSCROLL | ES_MULTILINE | ES_NOHIDESEL, WS_EX_CLIENTEDGE);
00147     m_DescriptionView.Create(m_InfoFrame, rcDefault, NULL, WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_HSCROLL | WS_VSCROLL | ES_AUTOHSCROLL | ES_AUTOVSCROLL | ES_MULTILINE | ES_NOHIDESEL, WS_EX_CLIENTEDGE);
00148     m_OutputView.m_pMainFrame = this;
00149 
00150     //m_InfoFrame.AddTab(m_LogView, _T("Log"), MAKEINTRESOURCE(IDI_LOG));
00151 
00152     int nFirstIndex = m_InfoFrame.AddBitmap(IDB_MSDEV_TAB_ICONS, RGB(0,255,0));
00153 
00154     m_InfoFrame.AddTab(m_DescriptionView,   _T("Project Description"),  1 + nFirstIndex);
00155     m_InfoFrame.AddTab(m_TaskListView,      _T("Thigs To Do"),          6 + nFirstIndex);
00156     m_InfoFrame.AddTab(m_OutputView,        _T("Output Window"),        3 + nFirstIndex);
00157 
00158 
00159     m_foldersDockWnd.Create(m_hWnd, rcDefault, _T("Folders"), dwStyle);
00160     DockWindow(m_foldersDockWnd,dockwins::CDockingSide(dockwins::CDockingSide::sLeft),
00161                     0/*nBar*/,float(0.0)/*fPctPos*/,200/*nWidth*/,100/* nHeight*/);
00162 }
00163 LRESULT CMainFrame::OnInitialize(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
00164 {
00165     sstate::CDockWndMgr mgrDockWnds;
00166 
00167     mgrDockWnds.Add(sstate::CDockingWindowStateAdapter<CTabbedDockingWindow>(m_InfoFrame));
00168 
00169     m_stateMgr.Initialize(lpcszQuestDesignerRegKey, m_hWnd);
00170     m_stateMgr.Add(sstate::CRebarStateAdapter(m_hWndToolBar));
00171     m_stateMgr.Add(sstate::CToggleWindowAdapter(m_hWndStatusBar));
00172     m_stateMgr.Add(mgrDockWnds);
00173     m_stateMgr.Restore();
00174     UpdateLayout();
00175     return 0;
00176 }
00177 LRESULT CMainFrame::OnDestroy(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled)
00178 {
00179     bHandled = FALSE;
00180     return 0;
00181 }
00182 
00183 LRESULT CMainFrame::OnFileExit(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
00184 {
00185     PostMessage(WM_CLOSE);
00186     return 0;
00187 }
00188 LRESULT CMainFrame::OnFileNew(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
00189 {
00190     // create a new MDI child window
00191 //  CreateNewChildWnd();
00192 
00193     CHtmlFrame *pChild = new CHtmlFrame(this);
00194     pChild->CreateEx(m_hWndClient);
00195 
00196     // TODO: add code to initialize document
00197 
00198     return 0;
00199 }
00200 LRESULT CMainFrame::OnFileOpen(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
00201 {
00202 
00203     static TCHAR szFilter[] = "OZ Script files (*.zes;*.inc)|*.zes; *.inc|All Files (*.*)|*.*||";
00204     CSSFileDialog wndFileDialog(TRUE, NULL, NULL, OFN_HIDEREADONLY, szFilter, m_hWnd);
00205     
00206     if(IDOK == wndFileDialog.DoModal()) {
00207         FileOpen(wndFileDialog.m_ofn.lpstrFile, 0, (wndFileDialog.m_ofn.Flags&OFN_READONLY)?TRUE:FALSE);
00208     }
00209     return TRUE;
00210 }
00211 LRESULT CMainFrame::OnViewToolBar(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
00212 {
00213     static BOOL bVisible = TRUE;    // initially visible
00214     bVisible = !bVisible;
00215     CReBarCtrl rebar = m_hWndToolBar;
00216     int nBandIndex = rebar.IdToIndex(ATL_IDW_BAND_FIRST + 1);   // toolbar is 2nd added band
00217     rebar.ShowBand(nBandIndex, bVisible);
00218     UISetCheck(ID_VIEW_TOOLBAR, bVisible);
00219     UpdateLayout();
00220     return 0;
00221 }
00222 LRESULT CMainFrame::OnViewStatusBar(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
00223 {
00224     BOOL bVisible = !::IsWindowVisible(m_hWndStatusBar);
00225     ::ShowWindow(m_hWndStatusBar, bVisible ? SW_SHOWNOACTIVATE : SW_HIDE);
00226     UISetCheck(ID_VIEW_STATUS_BAR, bVisible);
00227     UpdateLayout();
00228     return 0;
00229 }
00230 LRESULT CMainFrame::OnViewInfoWindow(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
00231 {
00232     BOOL bVisible = !m_InfoFrame.IsWindowVisible();
00233     m_InfoFrame.ShowWindow(bVisible ? SW_SHOWNOACTIVATE : SW_HIDE);
00234     UISetCheck(ID_VIEW_INFO, bVisible);
00235     UpdateLayout();
00236 
00237     return 0;
00238 }
00239 LRESULT CMainFrame::OnAppAbout(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
00240 {
00241     CAboutDlg dlg;
00242     dlg.DoModal();
00243     return 0;
00244 }
00245 LRESULT CMainFrame::OnWindowCascade(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
00246 {
00247     MDICascade();
00248     return 0;
00249 }
00250 LRESULT CMainFrame::OnWindowTile(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
00251 {
00252     MDITile();
00253     return 0;
00254 }
00255 LRESULT CMainFrame::OnWindowArrangeIcons(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
00256 {
00257     MDIIconArrange();
00258     return 0;
00259 }
00260 
00261 LRESULT CMainFrame::OnBuildProject(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
00262 {
00263     CString m_sIncludeDir = "C:\\Programming\\questdesigner-source\\compiler\\INCLUDE";
00264     CString m_sInputDir = "C:\\";
00265     CString m_sOutputDir = "C:\\";
00266 
00267     CString m_sInputFile = "_armos1.zes";
00268     CString m_sOutputFile = "_armos1.amx";
00269 
00270     m_InfoFrame.DisplayTab(m_OutputView.m_hWnd);
00271     m_OutputView.BeginBuildMsg("OpenZelda's Quest");
00272 
00273     m_SmallCompiler.Compile(m_sIncludeDir, m_sInputDir+m_sInputFile, m_sOutputDir+m_sOutputFile);
00274 
00275     m_OutputView.EndBuildMsg();
00276 
00277     return 0;
00278 }
00279 
00280 int CMainFrame::Select(LPCTSTR szFilename, LPARAM lParam)
00281 {
00282     CChildFrame *pChildFrame;
00283     for(int i=0; i<m_ChildList.GetSize(); i++) {
00284         pChildFrame = m_ChildList[i];
00285         if(pChildFrame->m_sChildName==szFilename) {
00286             pChildFrame->BringWindowToTop();
00287             if(lParam!=0) SendMessage(pChildFrame->m_hWnd, WMQD_SELECT, 0, lParam);
00288             return 1;
00289         }
00290     }
00291     return 0;
00292 }
00293 int CMainFrame::FileOpen(LPCTSTR szFilename, LPARAM lParam, BOOL bReadOnly)
00294 {
00295     // Searching for an open child with the same file:
00296     if(Select(szFilename, lParam)) return 1;
00297 
00298     // make the title for the child window
00299     TCHAR szTitle [ _MAX_FNAME ], szExt [ _MAX_FNAME ];
00300     _splitpath(szFilename, NULL, NULL, szTitle, szExt);
00301     lstrcat(szTitle, szExt);
00302 
00303     // create a hiden MDI child
00304     // create a new MDI child window
00305     CScriptEditorFrame *pChild = new CScriptEditorFrame(this);
00306     HWND hChildWnd = pChild->CreateEx(m_hWndClient);
00307 
00308     // get the child's 'view' (actually child's client control)
00309     CScriptEditorView *pView = pChild->GetView();
00310 
00311     // open the requested file
00312     if(!pView->DoFileOpen(szFilename, szTitle)) {
00313         // kill the failed window (will delete itself)
00314         pChild->DestroyWindow();
00315         return 0;
00316     } else {
00317         pChild->m_sChildName = szFilename;
00318         pView->SetReadOnly ( bReadOnly );
00319         if(lParam!=0) SendMessage(pChild->m_hWnd, WMQD_SELECT, 0, lParam);
00320     }
00321     return 1;
00322 }
00323 
00324 void CMainFrame::UIUpdateMenuItems ()
00325 {
00326     _child_type ActiveChildType = tUnknown;
00327     CChildFrame *pChildFrame;
00328     HWND hWndMDIActive = MDIGetActive();
00329     int OpenScripts=0;
00330     for(int i=0; i<m_ChildList.GetSize(); i++) {
00331         pChildFrame = m_ChildList[i];
00332         if(pChildFrame->m_ChildType == tScriptEditor) OpenScripts++;
00333         if(pChildFrame->m_hWnd==hWndMDIActive) ActiveChildType=tScriptEditor;
00334     }
00335     
00336     int nChildWindows = m_ChildList.GetSize();
00337 
00338     if( ActiveChildType!=tScriptEditor ) {
00339 
00340     /*
00341     for(int id=ID_VIEW_PANEFIRST; id<=ID_VIEW_PANELAST; id++)
00342         UIEnable(id,FALSE);
00343     UIEnable(ID_VIEW_INFO, TRUE);
00344     if(m_InfoFrame.IsWindow())
00345         UISetCheck(ID_VIEW_OUTPUT, m_InfoFrame.IsWindowVisible());
00346 */
00347 
00348         UIEnable ( ID_FILE_RELOAD, FALSE );
00349         UIEnable ( ID_FILE_SAVE, FALSE );
00350         UIEnable ( ID_FILE_SAVE_ALL, FALSE );
00351         UIEnable ( ID_FILE_SAVE_AS, FALSE );
00352         UIEnable ( ID_FILE_PRINT, FALSE );
00353         UIEnable ( ID_FILE_PRINT_SETUP, FALSE );
00354 
00355         UIEnable ( ID_EDIT_UNDO, FALSE );
00356         UIEnable ( ID_EDIT_REDO, FALSE );   
00357         UIEnable ( ID_EDIT_CUT, FALSE );
00358         UIEnable ( ID_EDIT_COPY, FALSE );
00359         UIEnable ( ID_EDIT_PASTE, FALSE );
00360         UIEnable ( ID_EDIT_CLEAR, FALSE );
00361 
00362         UIEnable ( ID_EDIT_TAB, FALSE );
00363         UIEnable ( ID_EDIT_UNTAB, FALSE );
00364         
00365         UIEnable ( ID_EDIT_FIND_SELECTION, FALSE );     
00366         
00367         UIEnable ( ID_EDIT_READ_ONLY, FALSE );
00368         UISetCheck ( ID_EDIT_READ_ONLY, 0 );
00369         
00370         UIEnable ( ID_EDIT_UPPERCASE, FALSE );
00371         UIEnable ( ID_EDIT_LOWERCASE, FALSE );
00372         UIEnable ( ID_EDIT_TABIFY, FALSE );
00373         UIEnable ( ID_EDIT_UNTABIFY, FALSE );
00374         
00375         UIEnable ( ID_EDIT_SHOW_WHITE_SPACE, FALSE );
00376         UISetCheck ( ID_EDIT_SHOW_WHITE_SPACE, 0 );
00377         
00378         UIEnable ( ID_EDIT_GOTO_NEXT_BOOKMARK, FALSE );
00379         UIEnable ( ID_EDIT_GOTO_PREV_BOOKMARK, FALSE );
00380         UIEnable ( ID_EDIT_CLEAR_ALL_BOOKMARKS, FALSE );    
00381     } 
00382     else {
00383         if(OpenScripts > 1) {
00384             UIEnable(ID_FILE_SAVE_ALL, TRUE);
00385         } else {
00386             UIEnable(ID_FILE_SAVE_ALL, FALSE);
00387         }
00388     }
00389 
00390 }

Generated on Wed Apr 16 19:12:22 2003 for QuestDesigner by doxygen1.2.18