Fix an issue that caused the DSP-LLE window to be openned twice in windows. (Thanks...
[dolphin.git] / Source / Core / DolphinWX / Src / FrameAui.cpp
blobf3356e8625fc11f88592c66bb858a59d06d191ee
1 // Copyright (C) 2003 Dolphin Project.
3 // This program is free software: you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation, version 2.0.
7 // This program is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 // GNU General Public License 2.0 for more details.
12 // A copy of the GPL 2.0 should have been included with the program.
13 // If not, see http://www.gnu.org/licenses/
15 // Official SVN repository and contact information can be found at
16 // http://code.google.com/p/dolphin-emu/
18 #include "Setup.h" // Common
20 #include "NetWindow.h"
22 #include "Common.h" // Common
23 #include "FileUtil.h"
24 #include "FileSearch.h"
25 #include "Timer.h"
27 #include "Globals.h" // Local
28 #include "Frame.h"
29 #include "ConfigMain.h"
30 #include "PluginManager.h"
31 #include "MemcardManager.h"
32 #include "CheatsWindow.h"
33 #include "AboutDolphin.h"
34 #include "GameListCtrl.h"
35 #include "BootManager.h"
36 #include "LogWindow.h"
37 #include "WxUtils.h"
39 #include "ConfigManager.h" // Core
40 #include "ConsoleListener.h"
41 #include "Core.h"
42 #include "OnFrame.h"
43 #include "HW/DVDInterface.h"
44 #include "State.h"
45 #include "VolumeHandler.h"
46 #include "NANDContentLoader.h"
48 #include <wx/datetime.h> // wxWidgets
50 // ------------
51 // Aui events
53 void CFrame::OnManagerResize(wxAuiManagerEvent& event)
55 event.Skip();
56 ResizeConsole();
59 void CFrame::OnPaneClose(wxAuiManagerEvent& event)
61 event.Veto();
63 wxAuiNotebook * nb = (wxAuiNotebook*)event.pane->window;
64 if (!nb) return;
66 if (!g_pCodeWindow)
68 if ((nb->GetPage(0)->GetId() == IDM_LOGWINDOW ||
69 nb->GetPage(0)->GetId() == IDM_CONSOLEWINDOW))
71 // Closing a pane containing the logwindow or a console closes both
72 SConfig::GetInstance().m_InterfaceConsole = false;
73 SConfig::GetInstance().m_InterfaceLogWindow = false;
74 ToggleConsole(false);
75 ToggleLogWindow(false);
78 else
80 if (GetNotebookCount() == 1)
81 wxMessageBox(wxT("At least one pane must remain open."),
82 wxT("Notice"), wxOK, this);
83 else if (nb->GetPageCount() != 0 && !nb->GetPageText(0).IsSameAs(wxT("<>")))
84 wxMessageBox(wxT("You can't close panes that have pages in them."),
85 wxT("Notice"), wxOK, this);
86 else
88 // Detach and delete the empty notebook
89 event.pane->DestroyOnClose(true);
90 m_Mgr->ClosePane(*event.pane);
94 m_Mgr->Update();
97 void CFrame::ToggleLogWindow(bool bShow)
99 GetMenuBar()->FindItem(IDM_LOGWINDOW)->Check(bShow);
101 if (bShow)
103 if (!m_LogWindow) m_LogWindow = new CLogWindow(this, IDM_LOGWINDOW);
104 m_LogWindow->Enable();
105 DoAddPage(m_LogWindow,
106 g_pCodeWindow ? g_pCodeWindow->iNbAffiliation[0] : 0,
107 g_pCodeWindow ? bFloatWindow[0] : false);
109 else
111 m_LogWindow->Disable();
112 DoRemovePage(m_LogWindow, true);
115 // Hide or Show the pane
116 if (!g_pCodeWindow)
117 TogglePane();
120 void CFrame::ToggleConsole(bool bShow)
122 #ifdef _WIN32
123 GetMenuBar()->FindItem(IDM_CONSOLEWINDOW)->Check(bShow);
125 if (bShow)
127 // If the console doesn't exist, we create it
128 if (!GetConsoleWindow())
130 ConsoleListener *Console = LogManager::GetInstance()->getConsoleListener();
131 Console->Open();
133 else
134 ShowWindow(GetConsoleWindow(), SW_SHOW);
136 // Create the parent window if it doesn't exist
137 wxPanel *ConsoleParent = (wxPanel*)FindWindowById(IDM_CONSOLEWINDOW);
138 if (!ConsoleParent) ConsoleParent = new wxPanel(this, IDM_CONSOLEWINDOW,
139 wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL, _("Console"));
141 wxWindow *ConsoleWin = new wxWindow();
142 ConsoleWin->SetHWND((WXHWND)GetConsoleWindow());
143 ConsoleWin->AdoptAttributesFromHWND();
144 ConsoleWin->Reparent(ConsoleParent);
146 ConsoleParent->Enable();
147 DoAddPage(ConsoleParent,
148 g_pCodeWindow ? g_pCodeWindow->iNbAffiliation[1] : 0,
149 g_pCodeWindow ? bFloatWindow[1] : false);
151 else // Hide
153 if(GetConsoleWindow())
154 ShowWindow(GetConsoleWindow(), SW_HIDE); // WIN32
156 wxPanel *ConsoleParent = (wxPanel*)FindWindowById(IDM_CONSOLEWINDOW);
157 if (ConsoleParent)
158 ConsoleParent->Disable();
160 // Then close the page
161 DoRemovePage(ConsoleParent, true);
164 // Hide or Show the pane
165 if (!g_pCodeWindow)
166 TogglePane();
167 #endif
170 void CFrame::OnToggleWindow(wxCommandEvent& event)
172 bool bShow = event.IsChecked();
174 switch(event.GetId())
176 case IDM_LOGWINDOW:
177 if (!g_pCodeWindow)
178 SConfig::GetInstance().m_InterfaceLogWindow = bShow;
179 ToggleLogWindow(bShow);
180 break;
181 case IDM_CONSOLEWINDOW:
182 if (!g_pCodeWindow)
183 SConfig::GetInstance().m_InterfaceConsole = bShow;
184 ToggleConsole(bShow);
185 break;
186 case IDM_REGISTERWINDOW:
187 g_pCodeWindow->ToggleRegisterWindow(bShow);
188 break;
189 case IDM_BREAKPOINTWINDOW:
190 g_pCodeWindow->ToggleBreakPointWindow(bShow);
191 break;
192 case IDM_MEMORYWINDOW:
193 g_pCodeWindow->ToggleMemoryWindow(bShow);
194 break;
195 case IDM_JITWINDOW:
196 g_pCodeWindow->ToggleJitWindow(bShow);
197 break;
198 case IDM_SOUNDWINDOW:
199 g_pCodeWindow->ToggleDLLWindow(IDM_SOUNDWINDOW, bShow);
200 break;
201 case IDM_VIDEOWINDOW:
202 g_pCodeWindow->ToggleDLLWindow(IDM_VIDEOWINDOW, bShow);
203 break;
207 // Notebooks
208 // ---------------------
209 void CFrame::ClosePages()
211 ToggleLogWindow(false);
212 ToggleConsole(false);
213 if (g_pCodeWindow)
215 g_pCodeWindow->ToggleCodeWindow(false);
216 g_pCodeWindow->ToggleRegisterWindow(false);
217 g_pCodeWindow->ToggleBreakPointWindow(false);
218 g_pCodeWindow->ToggleMemoryWindow(false);
219 g_pCodeWindow->ToggleJitWindow(false);
220 g_pCodeWindow->ToggleDLLWindow(IDM_SOUNDWINDOW, false);
221 g_pCodeWindow->ToggleDLLWindow(IDM_VIDEOWINDOW, false);
225 void CFrame::OnNotebookPageChanged(wxAuiNotebookEvent& event)
227 event.Skip();
228 if (!g_pCodeWindow) return;
230 // Remove the blank page if any
231 AddRemoveBlankPage();
233 // Update the notebook affiliation
234 for (int i = IDM_LOGWINDOW; i <= IDM_CODEWINDOW; i++)
236 if(GetNotebookAffiliation(i) >= 0)
237 g_pCodeWindow->iNbAffiliation[i - IDM_LOGWINDOW] = GetNotebookAffiliation(i);
241 void CFrame::OnNotebookPageClose(wxAuiNotebookEvent& event)
243 // Override event
244 event.Veto();
246 wxAuiNotebook* Ctrl = (wxAuiNotebook*)event.GetEventObject();
248 if (Ctrl->GetPage(event.GetSelection())->GetId() == IDM_LOGWINDOW)
249 ToggleLogWindow(false);
250 if (Ctrl->GetPage(event.GetSelection())->GetId() == IDM_CONSOLEWINDOW)
251 ToggleConsole(false);
252 if (Ctrl->GetPage(event.GetSelection())->GetId() == IDM_REGISTERWINDOW)
253 g_pCodeWindow->ToggleRegisterWindow(false);
254 if (Ctrl->GetPage(event.GetSelection())->GetId() == IDM_BREAKPOINTWINDOW)
255 g_pCodeWindow->ToggleBreakPointWindow(false);
256 if (Ctrl->GetPage(event.GetSelection())->GetId() == IDM_JITWINDOW)
257 g_pCodeWindow->ToggleJitWindow(false);
258 if (Ctrl->GetPage(event.GetSelection())->GetId() == IDM_MEMORYWINDOW)
259 g_pCodeWindow->ToggleMemoryWindow(false);
260 if (Ctrl->GetPage(event.GetSelection())->GetId() == IDM_SOUNDWINDOW)
261 g_pCodeWindow->ToggleDLLWindow(IDM_SOUNDWINDOW, false);
262 if (Ctrl->GetPage(event.GetSelection())->GetId() == IDM_VIDEOWINDOW)
263 g_pCodeWindow->ToggleDLLWindow(IDM_VIDEOWINDOW, false);
266 void CFrame::OnFloatingPageClosed(wxCloseEvent& event)
268 ToggleFloatWindow(event.GetId() - IDM_LOGWINDOW_PARENT + IDM_FLOAT_LOGWINDOW);
271 void CFrame::OnFloatingPageSize(wxSizeEvent& event)
273 event.Skip();
274 ResizeConsole();
277 void CFrame::OnFloatWindow(wxCommandEvent& event)
279 ToggleFloatWindow(event.GetId());
282 void CFrame::ToggleFloatWindow(int Id)
284 wxWindowID WinId = Id - IDM_FLOAT_LOGWINDOW + IDM_LOGWINDOW;
285 if (GetNotebookPageFromId(WinId))
287 DoFloatNotebookPage(WinId);
288 bFloatWindow[WinId - IDM_LOGWINDOW] = true;
290 else
292 if (FindWindowById(WinId))
293 DoUnfloatPage(WinId - IDM_LOGWINDOW + IDM_LOGWINDOW_PARENT);
294 bFloatWindow[WinId - IDM_LOGWINDOW] = false;
298 void CFrame::DoFloatNotebookPage(wxWindowID Id)
300 wxPanel *Win = (wxPanel*)FindWindowById(Id);
301 if (!Win) return;
303 for (int i = 0; i < GetNotebookCount(); i++)
305 wxAuiNotebook *nb = GetNotebookFromId(i);
306 if (nb->GetPageIndex(Win) != wxNOT_FOUND)
308 nb->RemovePage(nb->GetPageIndex(Win));
309 // Create the parent frame and reparent the window
310 CreateParentFrame(Win->GetId() + IDM_LOGWINDOW_PARENT - IDM_LOGWINDOW,
311 Win->GetName(), Win);
312 if (nb->GetPageCount() == 0)
313 AddRemoveBlankPage();
318 void CFrame::DoUnfloatPage(int Id)
320 wxFrame * Win = (wxFrame*)FindWindowById(Id);
321 if (!Win) return;
323 wxWindow * Child = Win->GetChildren().Item(0)->GetData();
324 Child->Reparent(this);
325 DoAddPage(Child, g_pCodeWindow->iNbAffiliation[Child->GetId() - IDM_LOGWINDOW], false);
326 Win->Destroy();
329 void CFrame::OnTab(wxAuiNotebookEvent& event)
331 event.Skip();
332 if (!g_pCodeWindow) return;
334 // Create the popup menu
335 wxMenu* MenuPopup = new wxMenu;
337 wxMenuItem* Item = new wxMenuItem(MenuPopup, wxID_ANY,
338 wxT("Select floating windows"));
339 MenuPopup->Append(Item);
340 Item->Enable(false);
341 MenuPopup->Append(new wxMenuItem(MenuPopup));
342 for (int i = IDM_LOGWINDOW; i <= IDM_CODEWINDOW; i++)
344 wxWindow *Win = FindWindowById(i);
345 if (Win && Win->IsEnabled())
347 Item = new wxMenuItem(MenuPopup, i + IDM_FLOAT_LOGWINDOW - IDM_LOGWINDOW,
348 Win->GetName(), wxT(""), wxITEM_CHECK);
349 MenuPopup->Append(Item);
350 Item->Check(!!FindWindowById(i + IDM_LOGWINDOW_PARENT - IDM_LOGWINDOW));
354 // Line up our menu with the cursor
355 wxPoint Pt = ::wxGetMousePosition();
356 Pt = ScreenToClient(Pt);
357 // Show
358 PopupMenu(MenuPopup, Pt);
361 void CFrame::OnAllowNotebookDnD(wxAuiNotebookEvent& event)
363 event.Skip();
364 event.Allow();
365 ResizeConsole();
368 void CFrame::TogglePane()
370 // Get the first notebook
371 wxAuiNotebook * NB = NULL;
372 for (size_t i = 0; i < m_Mgr->GetAllPanes().GetCount(); i++)
374 if (m_Mgr->GetAllPanes()[i].window->IsKindOf(CLASSINFO(wxAuiNotebook)))
375 NB = (wxAuiNotebook*)m_Mgr->GetAllPanes()[i].window;
377 if (NB)
379 if (NB->GetPageCount() == 0)
381 m_LogWindow->x = m_Mgr->GetPane(wxT("Pane 1")).rect.GetWidth();
382 m_LogWindow->y = m_Mgr->GetPane(wxT("Pane 1")).rect.GetHeight();
383 m_LogWindow->winpos = m_Mgr->GetPane(wxT("Pane 1")).dock_direction;
384 m_Mgr->GetPane(wxT("Pane 1")).Hide();
386 else
388 m_Mgr->GetPane(wxT("Pane 1")).BestSize(m_LogWindow->x, m_LogWindow->y)
389 .MinSize(m_LogWindow->x, m_LogWindow->y)
390 .Direction(m_LogWindow->winpos).Show();
391 m_Mgr->Update();
393 // Reset the minimum size of the pane
394 m_Mgr->GetPane(wxT("Pane 1")).MinSize(-1, -1);
396 m_Mgr->Update();
400 void CFrame::DoRemovePage(wxWindow *Win, bool bHide)
402 if (!Win) return;
404 wxWindow *Parent = FindWindowById(Win->GetId() +
405 IDM_LOGWINDOW_PARENT - IDM_LOGWINDOW);
407 if (Parent)
409 if (bHide)
411 Win->Hide();
412 Win->Reparent(this);
414 else
415 Win->Close();
416 Parent->Destroy();
418 else
420 for (int i = 0; i < GetNotebookCount(); i++)
422 int PageIndex = GetNotebookFromId(i)->GetPageIndex(Win);
423 if (PageIndex != wxNOT_FOUND)
425 GetNotebookFromId(i)->RemovePage(PageIndex);
426 if (bHide)
428 Win->Hide();
429 Win->Reparent(this);
431 else
432 Win->Close();
436 if (g_pCodeWindow)
437 AddRemoveBlankPage();
440 void CFrame::DoAddPage(wxWindow *Win, int i, bool Float)
442 if (!Win) return;
443 if (i < 0 || i > GetNotebookCount()-1) i = 0;
444 if (Win && GetNotebookFromId(i)->GetPageIndex(Win) != wxNOT_FOUND) return;
445 if (!Float)
446 GetNotebookFromId(i)->AddPage(Win, Win->GetName(), true);
447 else
448 CreateParentFrame(Win->GetId() + IDM_LOGWINDOW_PARENT - IDM_LOGWINDOW,
449 Win->GetName(), Win);
452 // Toolbar
453 void CFrame::OnDropDownSettingsToolbar(wxAuiToolBarEvent& event)
455 event.Skip();
456 ClearStatusBar();
458 if (event.IsDropDownClicked())
460 wxAuiToolBar* Tb = static_cast<wxAuiToolBar*>(event.GetEventObject());
461 Tb->SetToolSticky(event.GetId(), true);
463 // Create the popup menu
464 wxMenu* menuPopup = new wxMenu;
466 wxMenuItem* Item = new wxMenuItem(menuPopup, IDM_PERSPECTIVES_ADD_PANE,
467 wxT("Add new pane"));
468 menuPopup->Append(Item);
469 menuPopup->Append(new wxMenuItem(menuPopup));
470 Item = new wxMenuItem(menuPopup, IDM_TAB_SPLIT, wxT("Tab split"),
471 wxT(""), wxITEM_CHECK);
472 menuPopup->Append(Item);
473 Item->Check(m_bTabSplit);
474 Item = new wxMenuItem(menuPopup, IDM_NO_DOCKING, wxT("No docking"),
475 wxT(""), wxITEM_CHECK);
476 menuPopup->Append(Item);
477 Item->Check(m_bNoDocking);
479 // Line up our menu with the button
480 wxRect rect = Tb->GetToolRect(event.GetId());
481 wxPoint Pt = Tb->ClientToScreen(rect.GetBottomLeft());
482 Pt = ScreenToClient(Pt);
483 // Show
484 PopupMenu(menuPopup, Pt);
485 // Make the button un-stuck again
486 if (!m_bEdit) Tb->SetToolSticky(event.GetId(), false);
490 void CFrame::OnDropDownToolbarItem(wxAuiToolBarEvent& event)
492 event.Skip();
493 ClearStatusBar();
495 if (event.IsDropDownClicked())
497 wxAuiToolBar* tb = static_cast<wxAuiToolBar*>(event.GetEventObject());
498 tb->SetToolSticky(event.GetId(), true);
500 // create the popup menu
501 wxMenu* menuPopup = new wxMenu;
502 wxMenuItem* Item = new wxMenuItem(menuPopup, IDM_ADD_PERSPECTIVE,
503 wxT("Create new perspective"));
504 menuPopup->Append(Item);
506 if (Perspectives.size() > 0)
508 menuPopup->Append(new wxMenuItem(menuPopup));
509 for (size_t i = 0; i < Perspectives.size(); i++)
511 wxMenuItem* mItem = new wxMenuItem(menuPopup, IDM_PERSPECTIVES_0 + i,
512 wxString::FromAscii(Perspectives[i].Name.c_str()),
513 wxT(""), wxITEM_CHECK);
514 menuPopup->Append(mItem);
515 if (i == ActivePerspective) mItem->Check(true);
519 // line up our menu with the button
520 wxRect rect = tb->GetToolRect(event.GetId());
521 wxPoint pt = tb->ClientToScreen(rect.GetBottomLeft());
522 pt = ScreenToClient(pt);
523 // show
524 PopupMenu(menuPopup, pt);
525 // make sure the button is "un-stuck"
526 tb->SetToolSticky(event.GetId(), false);
530 void CFrame::OnToolBar(wxCommandEvent& event)
532 ClearStatusBar();
534 switch (event.GetId())
536 case IDM_SAVE_PERSPECTIVE:
537 if (Perspectives.size() == 0)
539 wxMessageBox(wxT("Please create a perspective before saving"),
540 wxT("Notice"), wxOK, this);
541 return;
543 SaveIniPerspectives();
544 GetStatusBar()->SetStatusText(wxString::FromAscii(std::string
545 ("Saved " + Perspectives[ActivePerspective].Name).c_str()), 0);
546 break;
547 case IDM_PERSPECTIVES_ADD_PANE:
548 AddPane();
549 break;
550 case IDM_EDIT_PERSPECTIVES:
551 m_bEdit = !m_bEdit;
552 m_ToolBarAui->SetToolSticky(IDM_EDIT_PERSPECTIVES, m_bEdit);
553 TogglePaneStyle(m_bEdit, IDM_EDIT_PERSPECTIVES);
554 break;
558 void CFrame::OnDropDownToolbarSelect(wxCommandEvent& event)
560 ClearStatusBar();
562 switch(event.GetId())
564 case IDM_ADD_PERSPECTIVE:
566 wxTextEntryDialog dlg(this,
567 wxT("Enter a name for the new perspective:"),
568 wxT("Create new perspective"));
569 wxString DefaultValue = wxString::Format(wxT("Perspective %d"),
570 Perspectives.size() + 1);
571 dlg.SetValue(DefaultValue);
572 bool DlgOk = false; int Return = 0;
573 while (!DlgOk)
575 Return = dlg.ShowModal();
576 if (Return == wxID_CANCEL)
577 return;
578 else if (dlg.GetValue().Find(wxT(",")) != -1)
580 wxMessageBox(wxT("The name can not contain the character ','"),
581 wxT("Notice"), wxOK, this);
582 wxString Str = dlg.GetValue();
583 Str.Replace(wxT(","), wxT(""), true);
584 dlg.SetValue(Str);
586 else if (dlg.GetValue().IsSameAs(wxT("")))
588 wxMessageBox(wxT("The name can not be empty"),
589 wxT("Notice"), wxOK, this);
590 dlg.SetValue(DefaultValue);
592 else
593 DlgOk = true;
596 SPerspectives Tmp;
597 Tmp.Name = dlg.GetValue().mb_str();
598 Tmp.Perspective = m_Mgr->SavePerspective();
600 ActivePerspective = Perspectives.size();
601 Perspectives.push_back(Tmp);
603 UpdateCurrentPerspective();
605 break;
606 case IDM_TAB_SPLIT:
607 m_bTabSplit = event.IsChecked();
608 ToggleNotebookStyle(m_bTabSplit, wxAUI_NB_TAB_SPLIT);
609 break;
610 case IDM_NO_DOCKING:
611 m_bNoDocking = event.IsChecked();
612 TogglePaneStyle(m_bNoDocking, IDM_NO_DOCKING);
613 break;
617 void CFrame::ResetToolbarStyle()
619 wxAuiPaneInfoArray& AllPanes = m_Mgr->GetAllPanes();
620 for (int i = 0, Count = (int)AllPanes.GetCount(); i < Count; ++i)
622 wxAuiPaneInfo& Pane = AllPanes[i];
623 if (Pane.window->IsKindOf(CLASSINFO(wxAuiToolBar)))
625 Pane.Show();
626 // Show all of it
627 if (Pane.rect.GetLeft() > GetClientSize().GetX() - 50)
628 Pane.Position(GetClientSize().GetX() - Pane.window->GetClientSize().GetX());
631 m_Mgr->Update();
634 void CFrame::TogglePaneStyle(bool On, int EventId)
636 wxAuiPaneInfoArray& AllPanes = m_Mgr->GetAllPanes();
637 for (size_t i = 0; i < AllPanes.GetCount(); ++i)
639 wxAuiPaneInfo& Pane = AllPanes[i];
640 if (Pane.window->IsKindOf(CLASSINFO(wxAuiNotebook)))
642 // Default
643 Pane.CloseButton(true);
644 Pane.MaximizeButton(true);
645 Pane.MinimizeButton(true);
646 Pane.PinButton(true);
647 Pane.Show();
649 switch(EventId)
651 case IDM_EDIT_PERSPECTIVES:
652 Pane.CaptionVisible(On);
653 Pane.Movable(On);
654 Pane.Floatable(On);
655 Pane.Dockable(On);
656 break;
658 Pane.Dockable(!m_bNoDocking);
661 m_Mgr->Update();
664 void CFrame::ToggleNotebookStyle(bool On, long Style)
666 wxAuiPaneInfoArray& AllPanes = m_Mgr->GetAllPanes();
667 for (int i = 0, Count = (int)AllPanes.GetCount(); i < Count; ++i)
669 wxAuiPaneInfo& Pane = AllPanes[i];
670 if (Pane.window->IsKindOf(CLASSINFO(wxAuiNotebook)))
672 wxAuiNotebook* NB = (wxAuiNotebook*)Pane.window;
674 if (On)
675 NB->SetWindowStyleFlag(NB->GetWindowStyleFlag() | Style);
676 else
677 NB->SetWindowStyleFlag(NB->GetWindowStyleFlag() &~ Style);
679 NB->Refresh();
684 void CFrame::OnSelectPerspective(wxCommandEvent& event)
686 size_t _Selection = event.GetId() - IDM_PERSPECTIVES_0;
687 if (Perspectives.size() <= _Selection) _Selection = 0;
688 ActivePerspective = _Selection;
689 DoLoadPerspective();
692 void CFrame::ResizeConsole()
694 #ifdef _WIN32
695 // Get the console parent window
696 wxWindow * Win = FindWindowById(IDM_CONSOLEWINDOW);
697 if (!Win) return;
699 const int wxBorder = 2, Border = 4, LowerBorder = 6,
700 MenuBar = 30, ScrollBar = 19;
701 const int WidthReduction = 30 - Border;
703 // Get the client size
704 int X = Win->GetClientSize().GetX();
705 int Y = Win->GetClientSize().GetY();
706 int InternalWidth = X - wxBorder*2 - ScrollBar;
707 int InternalHeight = Y - wxBorder*2;
708 int WindowWidth = InternalWidth + Border*2 +
709 /*max out the width in the word wrap mode*/ 100;
710 int WindowHeight = InternalHeight + MenuBar;
711 // Resize buffer
712 ConsoleListener* Console = LogManager::GetInstance()->getConsoleListener();
713 Console->PixelSpace(0,0, InternalWidth,InternalHeight, false);
714 // Move the window to hide the border
715 MoveWindow(GetConsoleWindow(), -Border-wxBorder, -MenuBar-wxBorder,
716 WindowWidth + 100,WindowHeight, true);
717 #endif
720 static int Limit(int i, int Low, int High)
722 if (i < Low) return Low;
723 if (i > High) return High;
724 return i;
727 void CFrame::SetPaneSize()
729 if (Perspectives.size() <= ActivePerspective) return;
730 int iClientX = GetSize().GetX(), iClientY = GetSize().GetY();
732 for (size_t i = 0, j = 0; i < m_Mgr->GetAllPanes().GetCount(); i++)
734 if (!m_Mgr->GetAllPanes()[i].window->IsKindOf(CLASSINFO(wxAuiToolBar)))
736 if (!m_Mgr->GetAllPanes()[i].IsOk()) return;
737 if (Perspectives[ActivePerspective].Width.size() <= j ||
738 Perspectives[ActivePerspective].Height.size() <= j)
739 continue;
740 size_t W = Perspectives[ActivePerspective].Width[j],
741 H = Perspectives[ActivePerspective].Height[j];
742 // Check limits
743 W = Limit(W, 5, 95);
744 H = Limit(H, 5, 95);
745 // Convert percentages to pixel lengths
746 W = (W * iClientX) / 100;
747 H = (H * iClientY) / 100;
748 m_Mgr->GetAllPanes()[i].BestSize(W,H).MinSize(W,H);
750 j++;
753 m_Mgr->Update();
755 for (size_t i = 0; i < m_Mgr->GetAllPanes().GetCount(); i++)
757 if (!m_Mgr->GetAllPanes()[i].window->IsKindOf(CLASSINFO(wxAuiToolBar)))
759 m_Mgr->GetAllPanes()[i].MinSize(-1,-1);
764 void CFrame::ReloadPanes()
766 // Close all pages
767 ClosePages();
769 CloseAllNotebooks();
771 // Create new panes with notebooks
772 for (size_t i = 0; i < Perspectives[ActivePerspective].Width.size() - 1; i++)
774 wxString PaneName = wxString::Format(wxT("Pane %i"), i + 1);
775 m_Mgr->AddPane(CreateEmptyNotebook(), wxAuiPaneInfo().Hide()
776 .CaptionVisible(m_bEdit).Dockable(!m_bNoDocking).Position(i)
777 .Name(PaneName).Caption(PaneName));
780 // Perspectives
781 m_Mgr->LoadPerspective(Perspectives[ActivePerspective].Perspective, false);
782 // Reset toolbars
783 ResetToolbarStyle();
784 // Restore settings
785 TogglePaneStyle(m_bNoDocking, IDM_NO_DOCKING);
786 TogglePaneStyle(m_bEdit, IDM_EDIT_PERSPECTIVES);
788 // Load GUI settings
789 g_pCodeWindow->Load();
790 // Open notebook pages
791 AddRemoveBlankPage();
792 g_pCodeWindow->OpenPages();
793 if (g_pCodeWindow->bShowOnStart[0]) ToggleLogWindow(true);
794 if (g_pCodeWindow->bShowOnStart[1]) ToggleConsole(true);
797 void CFrame::DoLoadPerspective()
799 ReloadPanes();
800 // Restore the exact window sizes, which LoadPerspective doesn't always do
801 SetPaneSize();
803 m_Mgr->Update();
806 // Update the local perspectives array
807 void CFrame::LoadIniPerspectives()
809 Perspectives.clear();
810 std::vector<std::string> VPerspectives;
811 std::string _Perspectives;
813 IniFile ini;
814 ini.Load(File::GetUserPath(F_DEBUGGERCONFIG_IDX));
815 ini.Get("Perspectives", "Perspectives", &_Perspectives, "Perspective 1");
816 ini.Get("Perspectives", "Active", &ActivePerspective, 0);
817 SplitString(_Perspectives, ",", VPerspectives);
819 for (size_t i = 0; i < VPerspectives.size(); i++)
821 SPerspectives Tmp;
822 std::string _Section, _Perspective, _Width, _Height;
823 std::vector<std::string> _SWidth, _SHeight;
824 Tmp.Name = VPerspectives[i];
825 // Don't save a blank perspective
826 if (Tmp.Name.empty()) continue;
828 _Section = StringFromFormat("P - %s", Tmp.Name.c_str());
829 ini.Get(_Section.c_str(), "Perspective", &_Perspective,
830 "layout2|"
831 "name=Pane 0;caption=Pane 0;state=768;dir=5;prop=100000;|"
832 "name=Pane 1;caption=Pane 1;state=31458108;dir=4;prop=100000;|"
833 "dock_size(5,0,0)=22|dock_size(4,0,0)=333|");
834 ini.Get(_Section.c_str(), "Width", &_Width, "70,25");
835 ini.Get(_Section.c_str(), "Height", &_Height, "80,80");
837 Tmp.Perspective = wxString::FromAscii(_Perspective.c_str());
839 SplitString(_Width, ",", _SWidth);
840 SplitString(_Height, ",", _SHeight);
841 for (size_t j = 0; j < _SWidth.size(); j++)
843 int _Tmp;
844 if (TryParseInt(_SWidth[j].c_str(), &_Tmp)) Tmp.Width.push_back(_Tmp);
846 for (size_t j = 0; j < _SHeight.size(); j++)
848 int _Tmp;
849 if (TryParseInt(_SHeight[j].c_str(), &_Tmp)) Tmp.Height.push_back(_Tmp);
851 Perspectives.push_back(Tmp);
855 void CFrame::UpdateCurrentPerspective()
857 SPerspectives *current = &Perspectives[ActivePerspective];
858 current->Perspective = m_Mgr->SavePerspective();
860 // Get client size
861 int iClientX = GetSize().GetX(), iClientY = GetSize().GetY();
862 current->Width.clear();
863 current->Height.clear();
864 for (size_t i = 0; i < m_Mgr->GetAllPanes().GetCount(); i++)
866 if (!m_Mgr->GetAllPanes()[i].window->
867 IsKindOf(CLASSINFO(wxAuiToolBar)))
869 // Save width and height as a percentage of the client width and height
870 current->Width.push_back(
871 (m_Mgr->GetAllPanes()[i].window->GetClientSize().GetX() * 100) /
872 iClientX);
873 current->Height.push_back(
874 (m_Mgr->GetAllPanes()[i].window->GetClientSize().GetY() * 100) /
875 iClientY);
880 void CFrame::SaveIniPerspectives()
882 if (Perspectives.size() == 0) return;
883 if (ActivePerspective >= Perspectives.size()) ActivePerspective = 0;
885 // Turn off edit before saving
886 TogglePaneStyle(false, IDM_EDIT_PERSPECTIVES);
888 UpdateCurrentPerspective();
890 IniFile ini;
891 ini.Load(File::GetUserPath(F_DEBUGGERCONFIG_IDX));
893 // Save perspective names
894 std::string STmp = "";
895 for (size_t i = 0; i < Perspectives.size(); i++)
897 STmp += Perspectives[i].Name + ",";
899 STmp = STmp.substr(0, STmp.length()-1);
900 ini.Set("Perspectives", "Perspectives", STmp.c_str());
901 ini.Set("Perspectives", "Active", ActivePerspective);
903 // Save the perspectives
904 for (size_t i = 0; i < Perspectives.size(); i++)
906 std::string _Section = "P - " + Perspectives[i].Name;
907 ini.Set(_Section.c_str(), "Perspective", Perspectives[i].Perspective.mb_str());
909 std::string SWidth = "", SHeight = "";
910 for (size_t j = 0; j < Perspectives[i].Width.size(); j++)
912 SWidth += StringFromFormat("%i,", Perspectives[i].Width[j]);
913 SHeight += StringFromFormat("%i,", Perspectives[i].Height[j]);
915 // Remove the ending ","
916 SWidth = SWidth.substr(0, SWidth.length()-1);
917 SHeight = SHeight.substr(0, SHeight.length()-1);
919 ini.Set(_Section.c_str(), "Width", SWidth.c_str());
920 ini.Set(_Section.c_str(), "Height", SHeight.c_str());
923 ini.Save(File::GetUserPath(F_DEBUGGERCONFIG_IDX));
925 // Save notebook affiliations
926 g_pCodeWindow->Save();
928 TogglePaneStyle(m_bEdit, IDM_EDIT_PERSPECTIVES);
931 void CFrame::AddPane()
933 int PaneNum = GetNotebookCount() + 1;
934 wxString PaneName = wxString::Format(wxT("Pane %i"), PaneNum);
935 m_Mgr->AddPane(CreateEmptyNotebook(), wxAuiPaneInfo()
936 .CaptionVisible(m_bEdit).Dockable(!m_bNoDocking)
937 .Name(PaneName).Caption(PaneName)
938 .Position(GetNotebookCount()));
940 AddRemoveBlankPage();
941 m_Mgr->Update();
944 wxWindow * CFrame::GetNotebookPageFromId(wxWindowID Id)
946 for (size_t i = 0; i < m_Mgr->GetAllPanes().GetCount(); i++)
948 if (!m_Mgr->GetAllPanes()[i].window->IsKindOf(CLASSINFO(wxAuiNotebook)))
949 continue;
950 wxAuiNotebook * NB = (wxAuiNotebook*)m_Mgr->GetAllPanes()[i].window;
951 for(size_t j = 0; j < NB->GetPageCount(); j++)
953 if (NB->GetPage(j)->GetId() == Id) return NB->GetPage(j);
956 return NULL;
959 wxFrame * CFrame::CreateParentFrame(wxWindowID Id, const wxString& Title,
960 wxWindow * Child)
962 wxFrame * Frame = new wxFrame(this, Id, Title,
963 wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_STYLE);
965 Child->Reparent(Frame);
967 wxBoxSizer * m_MainSizer = new wxBoxSizer(wxHORIZONTAL);
969 m_MainSizer->Add(Child, 1, wxEXPAND);
971 Frame->Connect(wxID_ANY, wxEVT_CLOSE_WINDOW,
972 wxCloseEventHandler(CFrame::OnFloatingPageClosed),
973 (wxObject*)0, this);
975 if (Id == IDM_CONSOLEWINDOW_PARENT)
977 Frame->Connect(wxID_ANY, wxEVT_SIZE,
978 wxSizeEventHandler(CFrame::OnFloatingPageSize),
979 (wxObject*)0, this);
982 // Main sizer
983 Frame->SetSizer(m_MainSizer);
984 // Minimum frame size
985 Frame->SetMinSize(wxSize(200, 200));
986 Frame->Show();
987 return Frame;
990 wxAuiNotebook* CFrame::CreateEmptyNotebook()
992 const long NOTEBOOK_STYLE = wxAUI_NB_TOP | wxAUI_NB_TAB_SPLIT |
993 wxAUI_NB_TAB_EXTERNAL_MOVE | wxAUI_NB_SCROLL_BUTTONS |
994 wxAUI_NB_WINDOWLIST_BUTTON | wxNO_BORDER;
995 wxAuiNotebook* NB = new wxAuiNotebook(this, wxID_ANY,
996 wxDefaultPosition, wxDefaultSize, NOTEBOOK_STYLE);
997 return NB;
1000 void CFrame::AddRemoveBlankPage()
1002 for (size_t i = 0; i < m_Mgr->GetAllPanes().GetCount(); i++)
1004 if (!m_Mgr->GetAllPanes()[i].window->IsKindOf(CLASSINFO(wxAuiNotebook)))
1005 continue;
1006 wxAuiNotebook * NB = (wxAuiNotebook*)m_Mgr->GetAllPanes()[i].window;
1007 for(size_t j = 0; j < NB->GetPageCount(); j++)
1009 if (NB->GetPageText(j).IsSameAs(wxT("<>")) && NB->GetPageCount() > 1)
1010 NB->DeletePage(j);
1012 if (NB->GetPageCount() == 0)
1013 NB->AddPage(new wxPanel(this, wxID_ANY), wxT("<>"), true);
1017 int CFrame::GetNotebookAffiliation(wxWindowID Id)
1019 for (size_t i = 0, j = 0; i < m_Mgr->GetAllPanes().GetCount(); i++)
1021 if (!m_Mgr->GetAllPanes()[i].window->IsKindOf(CLASSINFO(wxAuiNotebook)))
1022 continue;
1023 wxAuiNotebook * NB = (wxAuiNotebook*)m_Mgr->GetAllPanes()[i].window;
1024 for(size_t k = 0; k < NB->GetPageCount(); k++)
1026 if (NB->GetPage(k)->GetId() == Id)
1027 return j;
1029 j++;
1031 return -1;
1034 // Close all panes with notebooks
1035 void CFrame::CloseAllNotebooks()
1037 wxAuiPaneInfoArray AllPanes = m_Mgr->GetAllPanes();
1038 for (size_t i = 0; i < AllPanes.GetCount(); i++)
1040 if (AllPanes[i].window->IsKindOf(CLASSINFO(wxAuiNotebook)))
1042 AllPanes[i].DestroyOnClose(true);
1043 m_Mgr->ClosePane(AllPanes[i]);
1048 int CFrame::GetNotebookCount()
1050 int Ret = 0;
1051 for (size_t i = 0; i < m_Mgr->GetAllPanes().GetCount(); i++)
1053 if (m_Mgr->GetAllPanes()[i].window->IsKindOf(CLASSINFO(wxAuiNotebook)))
1054 Ret++;
1056 return Ret;
1059 wxAuiNotebook * CFrame::GetNotebookFromId(size_t NBId)
1061 for (size_t i = 0, j = 0; i < m_Mgr->GetAllPanes().GetCount(); i++)
1063 if (!m_Mgr->GetAllPanes()[i].window->IsKindOf(CLASSINFO(wxAuiNotebook)))
1064 continue;
1065 if (j == NBId)
1066 return (wxAuiNotebook*)m_Mgr->GetAllPanes()[i].window;
1067 j++;
1069 return NULL;