Linux multi-monitor fullscreen support
[ryzomcore.git] / ryzom / tools / leveldesign / georges_dll / main_frm.cpp
blobaf19420fba21331b7a38f4f142b6e9a9625ff213
1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2019 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
6 //
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/>.
20 #include "stdafx.h"
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"
27 #include "main_frm.h"
29 #include "nel/misc/debug.h"
31 using namespace NLMISC;
32 using namespace std;
34 /////////////////////////////////////////////////////////////////////////////
35 // CMainFrame
37 IMPLEMENT_DYNAMIC(CMainFrame, CMDIFrameWnd)
39 BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd)
40 //{{AFX_MSG_MAP(CMainFrame)
41 ON_WM_CREATE()
42 ON_COMMAND(ID_VIEW_SETTINGS, OnSettings)
43 ON_WM_CLOSE()
44 ON_COMMAND(ID_VIEW_DOCKINGDIALOGBAR, OnViewDockingdialogbar)
45 ON_UPDATE_COMMAND_UI(ID_VIEW_DOCKINGDIALOGBAR, OnUpdateViewDockingdialogbar)
46 ON_WM_SIZE()
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)
61 ON_WM_KEYDOWN()
62 ON_UPDATE_COMMAND_UI(ID_BROWSER_SORTED_BY_TYPE, OnUpdateBrowserSortedByType)
63 //}}AFX_MSG_MAP
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)
69 END_MESSAGE_MAP()
71 static UINT indicators[] =
73 ID_SEPARATOR, // status line indicator
74 ID_INDICATOR_CAPS,
75 ID_INDICATOR_NUM,
76 ID_INDICATOR_SCRL,
79 /////////////////////////////////////////////////////////////////////////////
80 // CMainFrame construction/destruction
82 CMainFrame::CMainFrame()
84 // m_bAutoMenuEnable = FALSE;
85 m_bDontClose = 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)
101 return -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
118 // Icon bar
119 m_wndToolBar.SetBarStyle(m_wndToolBar.GetBarStyle() |
120 CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);
122 // Dockable
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
134 // Docking bar
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);
140 // Menu file browser
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
151 // Docking bar
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);
157 // Menu file browser
158 menu = GetMenu();
159 menu->CheckMenuItem(ID_VIEW_OUTPUT_CONSOLE, MF_CHECKED);
161 // Init displayer
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"));
171 return 0;
174 BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
176 if( !CMDIFrameWnd::PreCreateWindow(cs) )
177 return FALSE;
179 if (createX != -1)
180 cs.x = createX;
181 if (createY != -1)
182 cs.y = createY;
183 if (createCX != -1)
184 cs.cx = createCX;
185 if (createCY != -1)
186 cs.cy = createCY;
188 return TRUE;
191 /////////////////////////////////////////////////////////////////////////////
192 // CMainFrame diagnostics
194 #ifdef _DEBUG
195 void CMainFrame::AssertValid() const
197 CMDIFrameWnd::AssertValid();
200 void CMainFrame::Dump(CDumpContext& dc) const
202 CMDIFrameWnd::Dump(dc);
205 #endif //_DEBUG
207 /////////////////////////////////////////////////////////////////////////////
208 // CMainFrame message handlers
212 void CMainFrame::OnSettings()
214 if (theApp.Superuser)
216 CSettingsDialog dialog (this);
217 dialog.DoModal ();
218 theApp.OnViewRefresh ();
222 bool CMainFrame::dataToClipboard (UINT format, void *data, uint len)
224 // Open the clipboard
225 if (OpenClipboard ())
227 if (data)
229 // Alloc a global memory
230 HGLOBAL hData = GlobalAlloc (GMEM_MOVEABLE|GMEM_DDESHARE, len);
231 if (hData)
233 // Copy the string
234 LPVOID dataPtr = GlobalLock (hData);
235 nlverify (dataPtr);
236 memcpy (dataPtr, data, len);
238 // Release the pointer
239 GlobalUnlock (hData);
241 // Set the clipboard
242 nlverify (SetClipboardData (format, hData));
244 // Close the clipboard
245 CloseClipboard ();
247 // Ok
248 return true;
251 else
253 // Empty the clipboard
254 nlverify (EmptyClipboard());
258 // Close the clipboard
259 CloseClipboard ();
261 return false;
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);
271 if (hData)
273 DWORD len = GlobalSize (hData);
275 // Get the string
276 LPVOID dataPtr = GlobalLock (hData);
277 nlverify (dataPtr);
279 // Copy the string
280 memcpy (data, dataPtr, len);
282 // Close the clipboard
283 CloseClipboard ();
285 // Ok
286 return true;
289 // Close the clipboard
290 CloseClipboard ();
292 return false;
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);
302 if (hData)
304 size = GlobalSize (hData);
306 // Close the clipboard
307 CloseClipboard ();
309 // Ok
310 return true;
312 else
313 size = 0;
315 // Close the clipboard
316 CloseClipboard ();
318 return false;
321 void CMainFrame::OnClose()
323 if (m_bDontClose) return;
325 if (theApp.SaveAllModified())
327 // JC: added save bar state
328 SaveBarState(_T("Georges"));
329 // Save state
330 theApp.saveState ();
332 theApp.CloseAllDocuments (TRUE);
334 // Release plugins
335 theApp.releasePlugins ();
337 PostQuitMessage(0);
341 void CMainFrame::OnViewDockingdialogbar()
343 CMenu *menu = GetMenu();
344 if(menu->GetMenuState(ID_VIEW_DOCKINGDIALOGBAR, MF_BYCOMMAND) & MF_CHECKED)
346 ShowControlBar (&FileBrowser, FALSE, FALSE);
348 else
350 ShowControlBar (&FileBrowser, TRUE, FALSE);
354 void CMainFrame::OnUpdateViewDockingdialogbar(CCmdUI* pCmdUI)
356 if(FileBrowser.IsVisible())
357 pCmdUI->SetCheck(TRUE);
358 else
359 pCmdUI->SetCheck(FALSE);
362 void CMainFrame::OnSize(UINT nType, int cx, int cy)
364 CMDIFrameWnd::OnSize(nType, cx, cy);
366 RecalcLayout ();
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);
376 else
378 ShowControlBar (&OutputConsole, TRUE, FALSE);
382 void CMainFrame::OnUpdateViewOutputConsole(CCmdUI* pCmdUI)
384 if(OutputConsole.IsVisible())
385 pCmdUI->SetCheck(TRUE);
386 else
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)
414 // For each plugins
415 uint i;
416 for (i=0; i<theApp.PluginArray.size (); i++)
417 if (theApp.PluginArray[i].Activated && theApp.PluginArray[i].PluginInterface->pretranslateMessage (pMsg))
418 return TRUE;
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 ();
428 if (pChild)
430 CGeorgesEditDoc *doc = (CGeorgesEditDoc *)pChild->GetActiveDocument();
431 doc->onActivateView (true);
435 void CMainFrame::OnUpdateModules0(CCmdUI* pCmdUI)
437 if (theApp.PluginArray.size () > 0)
439 pCmdUI->Enable ();
440 string name;
441 theApp.PluginArray[0].PluginInterface->getPluginName (name);
442 pCmdUI->SetText(nlUtf8ToTStr(name));
443 pCmdUI->SetCheck (theApp.PluginArray[0].Activated);
445 else
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 ();
456 if (pChild)
458 CGeorgesEditDoc *doc = (CGeorgesEditDoc *)pChild->GetActiveDocument();
459 doc->onActivateView (true);
463 void CMainFrame::OnUpdateModules1(CCmdUI* pCmdUI)
465 if (theApp.PluginArray.size () > 1)
467 pCmdUI->Enable ();
468 string name;
469 theApp.PluginArray[1].PluginInterface->getPluginName (name);
470 pCmdUI->SetText(nlUtf8ToTStr(name));
471 pCmdUI->SetCheck (theApp.PluginArray[1].Activated);
473 else
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 ();
484 if (pChild)
486 CGeorgesEditDoc *doc = (CGeorgesEditDoc *)pChild->GetActiveDocument();
487 doc->onActivateView (true);
491 void CMainFrame::OnUpdateModules2(CCmdUI* pCmdUI)
493 if (theApp.PluginArray.size () > 2)
495 pCmdUI->Enable ();
496 string name;
497 theApp.PluginArray[2].PluginInterface->getPluginName (name);
498 pCmdUI->SetText(nlUtf8ToTStr(name));
499 pCmdUI->SetCheck (theApp.PluginArray[2].Activated);
501 else
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 ();
512 if (pChild)
514 CGeorgesEditDoc *doc = (CGeorgesEditDoc *)pChild->GetActiveDocument();
515 doc->onActivateView (true);
519 void CMainFrame::OnUpdateModules3(CCmdUI* pCmdUI)
521 if (theApp.PluginArray.size () > 3)
523 pCmdUI->Enable ();
524 string name;
525 theApp.PluginArray[3].PluginInterface->getPluginName (name);
526 pCmdUI->SetText(nlUtf8ToTStr(name));
527 pCmdUI->SetCheck (theApp.PluginArray[3].Activated);
529 else
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);
550 else
551 pCmdUI->SetCheck(FALSE);