1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2019 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
7 // This program is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU Affero General Public License as
9 // published by the Free Software Foundation, either version 3 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU Affero General Public License for more details.
17 // You should have received a copy of the GNU Affero General Public License
18 // along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #include "georges_edit.h"
22 #include "georges_edit_view.h"
23 #include "georges_edit_doc.h"
24 #include "settings_dialog.h"
25 #include "child_frm.h"
29 #include "nel/misc/debug.h"
31 using namespace NLMISC
;
34 /////////////////////////////////////////////////////////////////////////////
37 IMPLEMENT_DYNAMIC(CMainFrame
, CMDIFrameWnd
)
39 BEGIN_MESSAGE_MAP(CMainFrame
, CMDIFrameWnd
)
40 //{{AFX_MSG_MAP(CMainFrame)
42 ON_COMMAND(ID_VIEW_SETTINGS
, OnSettings
)
44 ON_COMMAND(ID_VIEW_DOCKINGDIALOGBAR
, OnViewDockingdialogbar
)
45 ON_UPDATE_COMMAND_UI(ID_VIEW_DOCKINGDIALOGBAR
, OnUpdateViewDockingdialogbar
)
47 ON_COMMAND(ID_VIEW_OUTPUT_CONSOLE
, OnViewOutputConsole
)
48 ON_UPDATE_COMMAND_UI(ID_VIEW_OUTPUT_CONSOLE
, OnUpdateViewOutputConsole
)
49 ON_COMMAND(ID_VIEW_GOTO_FILE_BROWSER
, OnViewGotoFileBrowser
)
50 ON_COMMAND(ID_VIEW_GOTO_OUTPUT_CONSOLE
, OnViewGotoOutputConsole
)
51 ON_COMMAND(ID_MODULES_0
, OnModules0
)
52 ON_UPDATE_COMMAND_UI(ID_MODULES_0
, OnUpdateModules0
)
53 ON_COMMAND(ID_MODULES_1
, OnModules1
)
54 ON_UPDATE_COMMAND_UI(ID_MODULES_1
, OnUpdateModules1
)
55 ON_COMMAND(ID_MODULES_2
, OnModules2
)
56 ON_UPDATE_COMMAND_UI(ID_MODULES_2
, OnUpdateModules2
)
57 ON_COMMAND(ID_MODULES_3
, OnModules3
)
58 ON_UPDATE_COMMAND_UI(ID_MODULES_3
, OnUpdateModules3
)
59 ON_UPDATE_COMMAND_UI(ID_VIEW_SETTINGS
, OnUpdateViewSettings
)
60 ON_COMMAND(ID_BROWSER_SORTED_BY_TYPE
, OnBrowserSortedByType
)
62 ON_UPDATE_COMMAND_UI(ID_BROWSER_SORTED_BY_TYPE
, OnUpdateBrowserSortedByType
)
64 // Global help commands
65 ON_COMMAND(ID_HELP_FINDER
, CMDIFrameWnd::OnHelpFinder
)
66 ON_COMMAND(ID_HELP
, CMDIFrameWnd::OnHelp
)
67 ON_COMMAND(ID_CONTEXT_HELP
, CMDIFrameWnd::OnContextHelp
)
68 ON_COMMAND(ID_DEFAULT_HELP
, CMDIFrameWnd::OnHelpFinder
)
71 static UINT indicators
[] =
73 ID_SEPARATOR
, // status line indicator
79 /////////////////////////////////////////////////////////////////////////////
80 // CMainFrame construction/destruction
82 CMainFrame::CMainFrame()
84 // m_bAutoMenuEnable = FALSE;
86 BrowserSortedByType
= false;
89 CMainFrame::~CMainFrame()
91 ErrorLog
->removeDisplayer (&Displayer
);
92 WarningLog
->removeDisplayer (&Displayer
);
93 InfoLog
->removeDisplayer (&Displayer
);
94 DebugLog
->removeDisplayer (&Displayer
);
95 AssertLog
->removeDisplayer (&Displayer
);
98 int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct
)
100 if (CMDIFrameWnd::OnCreate(lpCreateStruct
) == -1)
103 if (!m_wndToolBar
.Create(this) ||
104 !m_wndToolBar
.LoadToolBar(IDR_MAINFRAME
))
106 TRACE0("Failed to create toolbar\n");
107 return -1; // fail to create
110 if (!m_wndStatusBar
.Create(this) ||
111 !m_wndStatusBar
.SetIndicators(indicators
,
112 sizeof(indicators
)/sizeof(UINT
)))
114 TRACE0("Failed to create status bar\n");
115 return -1; // fail to create
119 m_wndToolBar
.SetBarStyle(m_wndToolBar
.GetBarStyle() |
120 CBRS_TOOLTIPS
| CBRS_FLYBY
| CBRS_SIZE_DYNAMIC
);
123 m_wndToolBar
.EnableDocking(CBRS_ALIGN_ANY
);
124 EnableDocking(CBRS_ALIGN_ANY
);
125 DockControlBar(&m_wndToolBar
);
127 // Create the file browser
128 if (!FileBrowser
.Create(this, &FileBrowserDlg
, CString("File browser"), IDD_FILE_BROWSER
))
130 TRACE0("Failed to create dialogbar\n");
131 return -1; // fail to create
135 ShowControlBar (&FileBrowser
, TRUE
, FALSE
);
136 FileBrowser
.SetBarStyle (FileBrowser
.GetBarStyle()|CBRS_TOOLTIPS
|CBRS_FLYBY
|CBRS_SIZE_DYNAMIC
);
137 FileBrowser
.EnableDocking (CBRS_ALIGN_ANY
);
138 DockControlBar (&FileBrowser
);
141 CMenu
*menu
= GetMenu();
142 menu
->CheckMenuItem(ID_VIEW_DOCKINGDIALOGBAR
, MF_CHECKED
);
144 // Create the output console
145 if (!OutputConsole
.Create(this, &OutputConsoleDlg
, CString("Output"), IDD_OUTPUT_CONSOLE
))
147 TRACE0("Failed to create dialogbar\n");
148 return -1; // fail to create
152 ShowControlBar (&OutputConsole
, TRUE
, FALSE
);
153 OutputConsole
.SetBarStyle (OutputConsole
.GetBarStyle()|CBRS_TOOLTIPS
|CBRS_FLYBY
|CBRS_SIZE_DYNAMIC
);
154 OutputConsole
.EnableDocking (CBRS_ALIGN_ANY
);
155 DockControlBar (&OutputConsole
, AFX_IDW_DOCKBAR_BOTTOM
);
159 menu
->CheckMenuItem(ID_VIEW_OUTPUT_CONSOLE
, MF_CHECKED
);
162 ErrorLog
->addDisplayer (&Displayer
);
163 WarningLog
->addDisplayer (&Displayer
);
164 InfoLog
->addDisplayer (&Displayer
);
165 DebugLog
->addDisplayer (&Displayer
);
166 AssertLog
->addDisplayer (&Displayer
);
168 // JC: added LoadBarState
169 LoadBarState(_T("Georges"));
174 BOOL
CMainFrame::PreCreateWindow(CREATESTRUCT
& cs
)
176 if( !CMDIFrameWnd::PreCreateWindow(cs
) )
191 /////////////////////////////////////////////////////////////////////////////
192 // CMainFrame diagnostics
195 void CMainFrame::AssertValid() const
197 CMDIFrameWnd::AssertValid();
200 void CMainFrame::Dump(CDumpContext
& dc
) const
202 CMDIFrameWnd::Dump(dc
);
207 /////////////////////////////////////////////////////////////////////////////
208 // CMainFrame message handlers
212 void CMainFrame::OnSettings()
214 if (theApp
.Superuser
)
216 CSettingsDialog
dialog (this);
218 theApp
.OnViewRefresh ();
222 bool CMainFrame::dataToClipboard (UINT format
, void *data
, uint len
)
224 // Open the clipboard
225 if (OpenClipboard ())
229 // Alloc a global memory
230 HGLOBAL hData
= GlobalAlloc (GMEM_MOVEABLE
|GMEM_DDESHARE
, len
);
234 LPVOID dataPtr
= GlobalLock (hData
);
236 memcpy (dataPtr
, data
, len
);
238 // Release the pointer
239 GlobalUnlock (hData
);
242 nlverify (SetClipboardData (format
, hData
));
244 // Close the clipboard
253 // Empty the clipboard
254 nlverify (EmptyClipboard());
258 // Close the clipboard
264 bool CMainFrame::dataFromClipboard (UINT format
, void *data
)
266 // Open the clipboard
267 if (OpenClipboard ())
269 // Get the clipboard data
270 HANDLE hData
= GetClipboardData (format
);
273 DWORD len
= GlobalSize (hData
);
276 LPVOID dataPtr
= GlobalLock (hData
);
280 memcpy (data
, dataPtr
, len
);
282 // Close the clipboard
289 // Close the clipboard
295 bool CMainFrame::clipboardSize (UINT format
, uint
&size
)
297 // Open the clipboard
298 if (OpenClipboard ())
300 // Get the clipboard data
301 HANDLE hData
= GetClipboardData (format
);
304 size
= GlobalSize (hData
);
306 // Close the clipboard
315 // Close the clipboard
321 void CMainFrame::OnClose()
323 if (m_bDontClose
) return;
325 if (theApp
.SaveAllModified())
327 // JC: added save bar state
328 SaveBarState(_T("Georges"));
332 theApp
.CloseAllDocuments (TRUE
);
335 theApp
.releasePlugins ();
341 void CMainFrame::OnViewDockingdialogbar()
343 CMenu
*menu
= GetMenu();
344 if(menu
->GetMenuState(ID_VIEW_DOCKINGDIALOGBAR
, MF_BYCOMMAND
) & MF_CHECKED
)
346 ShowControlBar (&FileBrowser
, FALSE
, FALSE
);
350 ShowControlBar (&FileBrowser
, TRUE
, FALSE
);
354 void CMainFrame::OnUpdateViewDockingdialogbar(CCmdUI
* pCmdUI
)
356 if(FileBrowser
.IsVisible())
357 pCmdUI
->SetCheck(TRUE
);
359 pCmdUI
->SetCheck(FALSE
);
362 void CMainFrame::OnSize(UINT nType
, int cx
, int cy
)
364 CMDIFrameWnd::OnSize(nType
, cx
, cy
);
369 void CMainFrame::OnViewOutputConsole()
371 CMenu
*menu
= GetMenu();
372 if(menu
->GetMenuState(ID_VIEW_OUTPUT_CONSOLE
, MF_BYCOMMAND
) & MF_CHECKED
)
374 ShowControlBar (&OutputConsole
, FALSE
, FALSE
);
378 ShowControlBar (&OutputConsole
, TRUE
, FALSE
);
382 void CMainFrame::OnUpdateViewOutputConsole(CCmdUI
* pCmdUI
)
384 if(OutputConsole
.IsVisible())
385 pCmdUI
->SetCheck(TRUE
);
387 pCmdUI
->SetCheck(FALSE
);
390 void CMainFrame::outputConsoleString (const char *message
)
392 OutputConsoleDlg
.outputString (message
);
395 void CMainFrame::OnViewGotoFileBrowser()
397 ShowControlBar (&FileBrowser
, TRUE
, FALSE
);
398 FileBrowserDlg
.SetFocus ();
401 void CMainFrame::OnViewGotoOutputConsole()
403 ShowControlBar (&OutputConsole
, TRUE
, FALSE
);
404 OutputConsoleDlg
.SetFocus ();
407 void CMainFrame::showOutputConsole (bool show
)
409 ShowControlBar (&OutputConsole
, show
?TRUE
:FALSE
, FALSE
);
412 BOOL
CMainFrame::PreTranslateMessage(MSG
* pMsg
)
416 for (i
=0; i
<theApp
.PluginArray
.size (); i
++)
417 if (theApp
.PluginArray
[i
].Activated
&& theApp
.PluginArray
[i
].PluginInterface
->pretranslateMessage (pMsg
))
420 return CMDIFrameWnd::PreTranslateMessage(pMsg
);
423 void CMainFrame::OnModules0()
425 theApp
.PluginArray
[0].Activated
^= true;
426 theApp
.PluginArray
[0].PluginInterface
->activate (theApp
.PluginArray
[0].Activated
);
427 CChildFrame
*pChild
= (CChildFrame
*)MDIGetActive ();
430 CGeorgesEditDoc
*doc
= (CGeorgesEditDoc
*)pChild
->GetActiveDocument();
431 doc
->onActivateView (true);
435 void CMainFrame::OnUpdateModules0(CCmdUI
* pCmdUI
)
437 if (theApp
.PluginArray
.size () > 0)
441 theApp
.PluginArray
[0].PluginInterface
->getPluginName (name
);
442 pCmdUI
->SetText(nlUtf8ToTStr(name
));
443 pCmdUI
->SetCheck (theApp
.PluginArray
[0].Activated
);
447 pCmdUI
->Enable (FALSE
);
451 void CMainFrame::OnModules1()
453 theApp
.PluginArray
[1].Activated
^= true;
454 theApp
.PluginArray
[1].PluginInterface
->activate (theApp
.PluginArray
[1].Activated
);
455 CChildFrame
*pChild
= (CChildFrame
*)MDIGetActive ();
458 CGeorgesEditDoc
*doc
= (CGeorgesEditDoc
*)pChild
->GetActiveDocument();
459 doc
->onActivateView (true);
463 void CMainFrame::OnUpdateModules1(CCmdUI
* pCmdUI
)
465 if (theApp
.PluginArray
.size () > 1)
469 theApp
.PluginArray
[1].PluginInterface
->getPluginName (name
);
470 pCmdUI
->SetText(nlUtf8ToTStr(name
));
471 pCmdUI
->SetCheck (theApp
.PluginArray
[1].Activated
);
475 pCmdUI
->Enable (FALSE
);
479 void CMainFrame::OnModules2()
481 theApp
.PluginArray
[2].Activated
^= true;
482 theApp
.PluginArray
[2].PluginInterface
->activate (theApp
.PluginArray
[2].Activated
);
483 CChildFrame
*pChild
= (CChildFrame
*)MDIGetActive ();
486 CGeorgesEditDoc
*doc
= (CGeorgesEditDoc
*)pChild
->GetActiveDocument();
487 doc
->onActivateView (true);
491 void CMainFrame::OnUpdateModules2(CCmdUI
* pCmdUI
)
493 if (theApp
.PluginArray
.size () > 2)
497 theApp
.PluginArray
[2].PluginInterface
->getPluginName (name
);
498 pCmdUI
->SetText(nlUtf8ToTStr(name
));
499 pCmdUI
->SetCheck (theApp
.PluginArray
[2].Activated
);
503 pCmdUI
->Enable (FALSE
);
507 void CMainFrame::OnModules3()
509 theApp
.PluginArray
[3].Activated
^= true;
510 theApp
.PluginArray
[3].PluginInterface
->activate (theApp
.PluginArray
[3].Activated
);
511 CChildFrame
*pChild
= (CChildFrame
*)MDIGetActive ();
514 CGeorgesEditDoc
*doc
= (CGeorgesEditDoc
*)pChild
->GetActiveDocument();
515 doc
->onActivateView (true);
519 void CMainFrame::OnUpdateModules3(CCmdUI
* pCmdUI
)
521 if (theApp
.PluginArray
.size () > 3)
525 theApp
.PluginArray
[3].PluginInterface
->getPluginName (name
);
526 pCmdUI
->SetText(nlUtf8ToTStr(name
));
527 pCmdUI
->SetCheck (theApp
.PluginArray
[3].Activated
);
531 pCmdUI
->Enable (FALSE
);
535 void CMainFrame::OnUpdateViewSettings(CCmdUI
* pCmdUI
)
537 pCmdUI
->Enable (theApp
.Superuser
);
540 void CMainFrame::OnBrowserSortedByType()
542 BrowserSortedByType
^= true;
543 FileBrowserDlg
.setSortedByType (BrowserSortedByType
);
546 void CMainFrame::OnUpdateBrowserSortedByType(CCmdUI
* pCmdUI
)
548 if(BrowserSortedByType
)
549 pCmdUI
->SetCheck(TRUE
);
551 pCmdUI
->SetCheck(FALSE
);