FrameAui.cpp 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038
  1. // Copyright 2009 Dolphin Emulator Project
  2. // Licensed under GPLv2+
  3. // Refer to the license.txt file included.
  4. #include <cstddef>
  5. #include <string>
  6. #include <vector>
  7. #include <wx/frame.h>
  8. #include <wx/list.h>
  9. #include <wx/menu.h>
  10. #include <wx/msgdlg.h>
  11. #include <wx/panel.h>
  12. #include <wx/rtti.h>
  13. #include <wx/sizer.h>
  14. #include <wx/statusbr.h>
  15. #include <wx/textdlg.h>
  16. #include <wx/toplevel.h>
  17. #include <wx/aui/auibar.h>
  18. #include <wx/aui/auibook.h>
  19. #include <wx/aui/framemanager.h>
  20. #include "Common/CommonTypes.h"
  21. #include "Common/FileUtil.h"
  22. #include "Common/IniFile.h"
  23. #include "Common/MathUtil.h"
  24. #include "Common/StringUtil.h"
  25. #include "Common/Logging/ConsoleListener.h"
  26. #include "Core/ConfigManager.h"
  27. #include "DolphinWX/Frame.h"
  28. #include "DolphinWX/Globals.h"
  29. #include "DolphinWX/LogConfigWindow.h"
  30. #include "DolphinWX/LogWindow.h"
  31. #include "DolphinWX/WxUtils.h"
  32. #include "DolphinWX/Debugger/CodeWindow.h"
  33. // ------------
  34. // Aui events
  35. void CFrame::OnManagerResize(wxAuiManagerEvent& event)
  36. {
  37. if (!g_pCodeWindow && m_LogWindow &&
  38. m_Mgr->GetPane("Pane 1").IsShown() &&
  39. !m_Mgr->GetPane("Pane 1").IsFloating())
  40. {
  41. m_LogWindow->x = m_Mgr->GetPane("Pane 1").rect.GetWidth();
  42. m_LogWindow->y = m_Mgr->GetPane("Pane 1").rect.GetHeight();
  43. m_LogWindow->winpos = m_Mgr->GetPane("Pane 1").dock_direction;
  44. }
  45. event.Skip();
  46. }
  47. void CFrame::OnPaneClose(wxAuiManagerEvent& event)
  48. {
  49. event.Veto();
  50. wxAuiNotebook * nb = (wxAuiNotebook*)event.pane->window;
  51. if (!nb) return;
  52. if (!g_pCodeWindow)
  53. {
  54. if (nb->GetPage(0)->GetId() == IDM_LOG_WINDOW ||
  55. nb->GetPage(0)->GetId() == IDM_LOG_CONFIG_WINDOW)
  56. {
  57. SConfig::GetInstance().m_InterfaceLogWindow = false;
  58. SConfig::GetInstance().m_InterfaceLogConfigWindow = false;
  59. ToggleLogWindow(false);
  60. ToggleLogConfigWindow(false);
  61. }
  62. }
  63. else
  64. {
  65. if (GetNotebookCount() == 1)
  66. {
  67. wxMessageBox(_("At least one pane must remain open."),
  68. _("Notice"), wxOK, this);
  69. }
  70. else if (nb->GetPageCount() != 0 && !nb->GetPageText(0).IsSameAs("<>"))
  71. {
  72. wxMessageBox(_("You can't close panes that have pages in them."),
  73. _("Notice"), wxOK, this);
  74. }
  75. else
  76. {
  77. // Detach and delete the empty notebook
  78. event.pane->DestroyOnClose(true);
  79. m_Mgr->ClosePane(*event.pane);
  80. }
  81. }
  82. m_Mgr->Update();
  83. }
  84. void CFrame::ToggleLogWindow(bool bShow)
  85. {
  86. if (!m_LogWindow)
  87. return;
  88. GetMenuBar()->FindItem(IDM_LOG_WINDOW)->Check(bShow);
  89. if (bShow)
  90. {
  91. // Create a new log window if it doesn't exist.
  92. if (!m_LogWindow)
  93. {
  94. m_LogWindow = new CLogWindow(this, IDM_LOG_WINDOW);
  95. }
  96. m_LogWindow->Enable();
  97. DoAddPage(m_LogWindow,
  98. g_pCodeWindow ? g_pCodeWindow->iNbAffiliation[0] : 0,
  99. g_pCodeWindow ? bFloatWindow[0] : false);
  100. }
  101. else
  102. {
  103. // Hiding the log window, so disable it and remove it.
  104. m_LogWindow->Disable();
  105. DoRemovePage(m_LogWindow, true);
  106. }
  107. // Hide or Show the pane
  108. if (!g_pCodeWindow)
  109. TogglePane();
  110. }
  111. void CFrame::ToggleLogConfigWindow(bool bShow)
  112. {
  113. GetMenuBar()->FindItem(IDM_LOG_CONFIG_WINDOW)->Check(bShow);
  114. if (bShow)
  115. {
  116. if (!m_LogConfigWindow)
  117. m_LogConfigWindow = new LogConfigWindow(this, m_LogWindow, IDM_LOG_CONFIG_WINDOW);
  118. const int nbIndex = IDM_LOG_CONFIG_WINDOW - IDM_LOG_WINDOW;
  119. DoAddPage(m_LogConfigWindow,
  120. g_pCodeWindow ? g_pCodeWindow->iNbAffiliation[nbIndex] : 0,
  121. g_pCodeWindow ? bFloatWindow[nbIndex] : false);
  122. }
  123. else
  124. {
  125. DoRemovePage(m_LogConfigWindow, false);
  126. m_LogConfigWindow = nullptr;
  127. }
  128. // Hide or Show the pane
  129. if (!g_pCodeWindow)
  130. TogglePane();
  131. }
  132. void CFrame::OnToggleWindow(wxCommandEvent& event)
  133. {
  134. bool bShow = GetMenuBar()->IsChecked(event.GetId());
  135. switch (event.GetId())
  136. {
  137. case IDM_LOG_WINDOW:
  138. if (!g_pCodeWindow)
  139. SConfig::GetInstance().m_InterfaceLogWindow = bShow;
  140. ToggleLogWindow(bShow);
  141. break;
  142. case IDM_LOG_CONFIG_WINDOW:
  143. if (!g_pCodeWindow)
  144. SConfig::GetInstance().m_InterfaceLogConfigWindow = bShow;
  145. ToggleLogConfigWindow(bShow);
  146. break;
  147. case IDM_REGISTER_WINDOW:
  148. g_pCodeWindow->ToggleRegisterWindow(bShow);
  149. break;
  150. case IDM_WATCH_WINDOW:
  151. g_pCodeWindow->ToggleWatchWindow(bShow);
  152. break;
  153. case IDM_BREAKPOINT_WINDOW:
  154. g_pCodeWindow->ToggleBreakPointWindow(bShow);
  155. break;
  156. case IDM_MEMORY_WINDOW:
  157. g_pCodeWindow->ToggleMemoryWindow(bShow);
  158. break;
  159. case IDM_JIT_WINDOW:
  160. g_pCodeWindow->ToggleJitWindow(bShow);
  161. break;
  162. case IDM_SOUND_WINDOW:
  163. g_pCodeWindow->ToggleSoundWindow(bShow);
  164. break;
  165. case IDM_VIDEO_WINDOW:
  166. g_pCodeWindow->ToggleVideoWindow(bShow);
  167. break;
  168. }
  169. }
  170. // Notebooks
  171. // ---------------------
  172. void CFrame::ClosePages()
  173. {
  174. ToggleLogWindow(false);
  175. ToggleLogConfigWindow(false);
  176. if (g_pCodeWindow)
  177. {
  178. g_pCodeWindow->ToggleCodeWindow(false);
  179. g_pCodeWindow->ToggleRegisterWindow(false);
  180. g_pCodeWindow->ToggleWatchWindow(false);
  181. g_pCodeWindow->ToggleBreakPointWindow(false);
  182. g_pCodeWindow->ToggleMemoryWindow(false);
  183. g_pCodeWindow->ToggleJitWindow(false);
  184. g_pCodeWindow->ToggleSoundWindow(false);
  185. g_pCodeWindow->ToggleVideoWindow(false);
  186. }
  187. }
  188. void CFrame::OnNotebookPageChanged(wxAuiNotebookEvent& event)
  189. {
  190. event.Skip();
  191. if (!g_pCodeWindow)
  192. return;
  193. // Remove the blank page if any
  194. AddRemoveBlankPage();
  195. // Update the notebook affiliation
  196. for (int i = IDM_LOG_WINDOW; i <= IDM_CODE_WINDOW; i++)
  197. {
  198. if (GetNotebookAffiliation(i) >= 0)
  199. g_pCodeWindow->iNbAffiliation[i - IDM_LOG_WINDOW] = GetNotebookAffiliation(i);
  200. }
  201. }
  202. void CFrame::OnNotebookPageClose(wxAuiNotebookEvent& event)
  203. {
  204. // Override event
  205. event.Veto();
  206. wxAuiNotebook* Ctrl = (wxAuiNotebook*)event.GetEventObject();
  207. if (Ctrl->GetPage(event.GetSelection())->GetId() == IDM_LOG_WINDOW)
  208. ToggleLogWindow(false);
  209. if (Ctrl->GetPage(event.GetSelection())->GetId() == IDM_LOG_CONFIG_WINDOW)
  210. ToggleLogConfigWindow(false);
  211. if (Ctrl->GetPage(event.GetSelection())->GetId() == IDM_REGISTER_WINDOW)
  212. g_pCodeWindow->ToggleRegisterWindow(false);
  213. if (Ctrl->GetPage(event.GetSelection())->GetId() == IDM_WATCH_WINDOW)
  214. g_pCodeWindow->ToggleWatchWindow(false);
  215. if (Ctrl->GetPage(event.GetSelection())->GetId() == IDM_BREAKPOINT_WINDOW)
  216. g_pCodeWindow->ToggleBreakPointWindow(false);
  217. if (Ctrl->GetPage(event.GetSelection())->GetId() == IDM_JIT_WINDOW)
  218. g_pCodeWindow->ToggleJitWindow(false);
  219. if (Ctrl->GetPage(event.GetSelection())->GetId() == IDM_MEMORY_WINDOW)
  220. g_pCodeWindow->ToggleMemoryWindow(false);
  221. if (Ctrl->GetPage(event.GetSelection())->GetId() == IDM_SOUND_WINDOW)
  222. g_pCodeWindow->ToggleSoundWindow(false);
  223. if (Ctrl->GetPage(event.GetSelection())->GetId() == IDM_VIDEO_WINDOW)
  224. g_pCodeWindow->ToggleVideoWindow(false);
  225. }
  226. void CFrame::OnFloatingPageClosed(wxCloseEvent& event)
  227. {
  228. ToggleFloatWindow(event.GetId() - IDM_LOG_WINDOW_PARENT + IDM_FLOAT_LOG_WINDOW);
  229. }
  230. void CFrame::OnFloatingPageSize(wxSizeEvent& event)
  231. {
  232. event.Skip();
  233. }
  234. void CFrame::OnFloatWindow(wxCommandEvent& event)
  235. {
  236. ToggleFloatWindow(event.GetId());
  237. }
  238. void CFrame::ToggleFloatWindow(int Id)
  239. {
  240. wxWindowID WinId = Id - IDM_FLOAT_LOG_WINDOW + IDM_LOG_WINDOW;
  241. if (GetNotebookPageFromId(WinId))
  242. {
  243. DoFloatNotebookPage(WinId);
  244. bFloatWindow[WinId - IDM_LOG_WINDOW] = true;
  245. }
  246. else
  247. {
  248. if (FindWindowById(WinId))
  249. DoUnfloatPage(WinId - IDM_LOG_WINDOW + IDM_LOG_WINDOW_PARENT);
  250. bFloatWindow[WinId - IDM_LOG_WINDOW] = false;
  251. }
  252. }
  253. void CFrame::DoFloatNotebookPage(wxWindowID Id)
  254. {
  255. wxPanel *Win = (wxPanel*)FindWindowById(Id);
  256. if (!Win) return;
  257. for (int i = 0; i < GetNotebookCount(); i++)
  258. {
  259. wxAuiNotebook *nb = GetNotebookFromId(i);
  260. if (nb->GetPageIndex(Win) != wxNOT_FOUND)
  261. {
  262. nb->RemovePage(nb->GetPageIndex(Win));
  263. // Create the parent frame and reparent the window
  264. CreateParentFrame(Win->GetId() + IDM_LOG_WINDOW_PARENT - IDM_LOG_WINDOW,
  265. Win->GetName(), Win);
  266. if (nb->GetPageCount() == 0)
  267. AddRemoveBlankPage();
  268. }
  269. }
  270. }
  271. void CFrame::DoUnfloatPage(int Id)
  272. {
  273. wxFrame * Win = (wxFrame*)FindWindowById(Id);
  274. if (!Win) return;
  275. wxWindow * Child = Win->GetChildren().Item(0)->GetData();
  276. Child->Reparent(this);
  277. DoAddPage(Child, g_pCodeWindow->iNbAffiliation[Child->GetId() - IDM_LOG_WINDOW], false);
  278. Win->Destroy();
  279. }
  280. void CFrame::OnTab(wxAuiNotebookEvent& event)
  281. {
  282. event.Skip();
  283. if (!g_pCodeWindow) return;
  284. // Create the popup menu
  285. wxMenu MenuPopup;
  286. wxMenuItem* Item = new wxMenuItem(&MenuPopup, wxID_ANY, _("Select floating windows"));
  287. MenuPopup.Append(Item);
  288. Item->Enable(false);
  289. MenuPopup.Append(new wxMenuItem(&MenuPopup));
  290. for (int i = IDM_LOG_WINDOW; i <= IDM_CODE_WINDOW; i++)
  291. {
  292. wxWindow *Win = FindWindowById(i);
  293. if (Win && Win->IsEnabled())
  294. {
  295. Item = new wxMenuItem(&MenuPopup, i + IDM_FLOAT_LOG_WINDOW - IDM_LOG_WINDOW,
  296. Win->GetName(), "", wxITEM_CHECK);
  297. MenuPopup.Append(Item);
  298. Item->Check(!!FindWindowById(i + IDM_LOG_WINDOW_PARENT - IDM_LOG_WINDOW));
  299. }
  300. }
  301. // Line up our menu with the cursor
  302. wxPoint Pt = ::wxGetMousePosition();
  303. Pt = ScreenToClient(Pt);
  304. // Show
  305. PopupMenu(&MenuPopup, Pt);
  306. }
  307. void CFrame::OnAllowNotebookDnD(wxAuiNotebookEvent& event)
  308. {
  309. event.Skip();
  310. event.Allow();
  311. }
  312. void CFrame::ShowResizePane()
  313. {
  314. if (!m_LogWindow) return;
  315. // Make sure the size is sane
  316. if (m_LogWindow->x > GetClientRect().GetWidth())
  317. m_LogWindow->x = GetClientRect().GetWidth() / 2;
  318. if (m_LogWindow->y > GetClientRect().GetHeight())
  319. m_LogWindow->y = GetClientRect().GetHeight() / 2;
  320. wxAuiPaneInfo &pane = m_Mgr->GetPane("Pane 1");
  321. // Hide first otherwise a resize doesn't work
  322. pane.Hide();
  323. m_Mgr->Update();
  324. pane.BestSize(m_LogWindow->x, m_LogWindow->y)
  325. .MinSize(m_LogWindow->x, m_LogWindow->y)
  326. .Direction(m_LogWindow->winpos).Show();
  327. m_Mgr->Update();
  328. // Reset the minimum size of the pane
  329. pane.MinSize(-1, -1);
  330. m_Mgr->Update();
  331. }
  332. void CFrame::TogglePane()
  333. {
  334. // Get the first notebook
  335. wxAuiNotebook * NB = nullptr;
  336. for (u32 i = 0; i < m_Mgr->GetAllPanes().GetCount(); i++)
  337. {
  338. if (m_Mgr->GetAllPanes()[i].window->IsKindOf(CLASSINFO(wxAuiNotebook)))
  339. NB = (wxAuiNotebook*)m_Mgr->GetAllPanes()[i].window;
  340. }
  341. if (NB)
  342. {
  343. if (NB->GetPageCount() == 0)
  344. {
  345. m_Mgr->GetPane("Pane 1").Hide();
  346. m_Mgr->Update();
  347. }
  348. else
  349. {
  350. ShowResizePane();
  351. }
  352. }
  353. }
  354. void CFrame::DoRemovePage(wxWindow *Win, bool bHide)
  355. {
  356. if (!Win) return;
  357. wxWindow *Parent = FindWindowById(Win->GetId() +
  358. IDM_LOG_WINDOW_PARENT - IDM_LOG_WINDOW);
  359. if (Parent)
  360. {
  361. if (bHide)
  362. {
  363. Win->Hide();
  364. Win->Reparent(this);
  365. }
  366. else
  367. {
  368. Win->Destroy();
  369. }
  370. Parent->Destroy();
  371. }
  372. else
  373. {
  374. for (int i = 0; i < GetNotebookCount(); i++)
  375. {
  376. int PageIndex = GetNotebookFromId(i)->GetPageIndex(Win);
  377. if (PageIndex != wxNOT_FOUND)
  378. {
  379. GetNotebookFromId(i)->RemovePage(PageIndex);
  380. if (bHide)
  381. {
  382. Win->Hide();
  383. Win->Reparent(this);
  384. }
  385. else
  386. {
  387. Win->Destroy();
  388. }
  389. }
  390. }
  391. }
  392. if (g_pCodeWindow)
  393. AddRemoveBlankPage();
  394. }
  395. void CFrame::DoAddPage(wxWindow *Win, int i, bool Float)
  396. {
  397. if (!Win) return;
  398. // Ensure accessor remains within valid bounds.
  399. if (i < 0 || i > GetNotebookCount() - 1)
  400. i = 0;
  401. // The page was already previously added, no need to add it again.
  402. if (Win && GetNotebookFromId(i)->GetPageIndex(Win) != wxNOT_FOUND)
  403. return;
  404. if (!Float)
  405. GetNotebookFromId(i)->AddPage(Win, Win->GetName(), true);
  406. else
  407. CreateParentFrame(Win->GetId() + IDM_LOG_WINDOW_PARENT - IDM_LOG_WINDOW,
  408. Win->GetName(), Win);
  409. }
  410. void CFrame::PopulateSavedPerspectives()
  411. {
  412. // If the perspective submenu hasn't been created yet, return
  413. if (!m_SavedPerspectives) return;
  414. // Delete all saved perspective menu items
  415. while (m_SavedPerspectives->GetMenuItemCount() != 0)
  416. {
  417. // Delete the first menu item in the list (while there are menu items)
  418. m_SavedPerspectives->Delete(m_SavedPerspectives->FindItemByPosition(0));
  419. }
  420. if (Perspectives.size() > 0)
  421. {
  422. for (u32 i = 0; i < Perspectives.size(); i++)
  423. {
  424. wxMenuItem* mItem = new wxMenuItem(m_SavedPerspectives, IDM_PERSPECTIVES_0 + i,
  425. StrToWxStr(Perspectives[i].Name), "", wxITEM_CHECK);
  426. m_SavedPerspectives->Append(mItem);
  427. if (i == ActivePerspective)
  428. {
  429. mItem->Check(true);
  430. }
  431. }
  432. }
  433. }
  434. void CFrame::OnPerspectiveMenu(wxCommandEvent& event)
  435. {
  436. ClearStatusBar();
  437. switch (event.GetId())
  438. {
  439. case IDM_SAVE_PERSPECTIVE:
  440. if (Perspectives.size() == 0)
  441. {
  442. wxMessageBox(_("Please create a perspective before saving"),
  443. _("Notice"), wxOK, this);
  444. return;
  445. }
  446. SaveIniPerspectives();
  447. GetStatusBar()->SetStatusText(StrToWxStr(std::string
  448. ("Saved " + Perspectives[ActivePerspective].Name)), 0);
  449. break;
  450. case IDM_PERSPECTIVES_ADD_PANE_TOP:
  451. AddPane(ADD_PANE_TOP);
  452. break;
  453. case IDM_PERSPECTIVES_ADD_PANE_BOTTOM:
  454. AddPane(ADD_PANE_BOTTOM);
  455. break;
  456. case IDM_PERSPECTIVES_ADD_PANE_LEFT:
  457. AddPane(ADD_PANE_LEFT);
  458. break;
  459. case IDM_PERSPECTIVES_ADD_PANE_RIGHT:
  460. AddPane(ADD_PANE_RIGHT);
  461. break;
  462. case IDM_PERSPECTIVES_ADD_PANE_CENTER:
  463. AddPane(ADD_PANE_CENTER);
  464. break;
  465. case IDM_EDIT_PERSPECTIVES:
  466. m_bEdit = event.IsChecked();
  467. TogglePaneStyle(m_bEdit, IDM_EDIT_PERSPECTIVES);
  468. break;
  469. case IDM_ADD_PERSPECTIVE:
  470. {
  471. wxTextEntryDialog dlg(this,
  472. _("Enter a name for the new perspective:"),
  473. _("Create new perspective"));
  474. wxString DefaultValue = wxString::Format(_("Perspective %d"), (int)(Perspectives.size() + 1));
  475. dlg.SetValue(DefaultValue);
  476. int Return = 0;
  477. bool DlgOk = false;
  478. while (!DlgOk)
  479. {
  480. Return = dlg.ShowModal();
  481. if (Return == wxID_CANCEL)
  482. {
  483. return;
  484. }
  485. else if (dlg.GetValue().Find(",") != -1)
  486. {
  487. wxMessageBox(_("The name cannot contain the character ','"),
  488. _("Notice"), wxOK, this);
  489. wxString Str = dlg.GetValue();
  490. Str.Replace(",", "", true);
  491. dlg.SetValue(Str);
  492. }
  493. else if (dlg.GetValue().IsSameAs(""))
  494. {
  495. wxMessageBox(_("The name cannot be empty"),
  496. _("Notice"), wxOK, this);
  497. dlg.SetValue(DefaultValue);
  498. }
  499. else
  500. {
  501. DlgOk = true;
  502. }
  503. }
  504. SPerspectives Tmp;
  505. Tmp.Name = WxStrToStr(dlg.GetValue());
  506. Tmp.Perspective = m_Mgr->SavePerspective();
  507. ActivePerspective = (u32)Perspectives.size();
  508. Perspectives.push_back(Tmp);
  509. UpdateCurrentPerspective();
  510. PopulateSavedPerspectives();
  511. }
  512. break;
  513. case IDM_TAB_SPLIT:
  514. m_bTabSplit = event.IsChecked();
  515. ToggleNotebookStyle(m_bTabSplit, wxAUI_NB_TAB_SPLIT);
  516. break;
  517. case IDM_NO_DOCKING:
  518. m_bNoDocking = event.IsChecked();
  519. TogglePaneStyle(m_bNoDocking, IDM_NO_DOCKING);
  520. break;
  521. }
  522. }
  523. void CFrame::TogglePaneStyle(bool On, int EventId)
  524. {
  525. wxAuiPaneInfoArray& AllPanes = m_Mgr->GetAllPanes();
  526. for (u32 i = 0; i < AllPanes.GetCount(); ++i)
  527. {
  528. wxAuiPaneInfo& Pane = AllPanes[i];
  529. if (Pane.window->IsKindOf(CLASSINFO(wxAuiNotebook)))
  530. {
  531. // Default
  532. Pane.CloseButton(true);
  533. Pane.MaximizeButton(true);
  534. Pane.MinimizeButton(true);
  535. Pane.PinButton(true);
  536. Pane.Show();
  537. switch (EventId)
  538. {
  539. case IDM_EDIT_PERSPECTIVES:
  540. Pane.CaptionVisible(On);
  541. Pane.Movable(On);
  542. Pane.Floatable(On);
  543. Pane.Dockable(On);
  544. break;
  545. }
  546. Pane.Dockable(!m_bNoDocking);
  547. }
  548. }
  549. m_Mgr->Update();
  550. }
  551. void CFrame::ToggleNotebookStyle(bool On, long Style)
  552. {
  553. wxAuiPaneInfoArray& AllPanes = m_Mgr->GetAllPanes();
  554. for (int i = 0, Count = (int)AllPanes.GetCount(); i < Count; ++i)
  555. {
  556. wxAuiPaneInfo& Pane = AllPanes[i];
  557. if (Pane.window->IsKindOf(CLASSINFO(wxAuiNotebook)))
  558. {
  559. wxAuiNotebook* NB = (wxAuiNotebook*)Pane.window;
  560. if (On)
  561. NB->SetWindowStyleFlag(NB->GetWindowStyleFlag() | Style);
  562. else
  563. NB->SetWindowStyleFlag(NB->GetWindowStyleFlag() &~ Style);
  564. NB->Refresh();
  565. }
  566. }
  567. }
  568. void CFrame::OnSelectPerspective(wxCommandEvent& event)
  569. {
  570. u32 _Selection = event.GetId() - IDM_PERSPECTIVES_0;
  571. if (Perspectives.size() <= _Selection) _Selection = 0;
  572. ActivePerspective = _Selection;
  573. DoLoadPerspective();
  574. }
  575. void CFrame::SetPaneSize()
  576. {
  577. if (Perspectives.size() <= ActivePerspective)
  578. return;
  579. int iClientX = GetSize().GetX();
  580. int iClientY = GetSize().GetY();
  581. for (u32 i = 0, j = 0; i < m_Mgr->GetAllPanes().GetCount(); i++)
  582. {
  583. if (!m_Mgr->GetAllPanes()[i].window->IsKindOf(CLASSINFO(wxAuiToolBar)))
  584. {
  585. if (!m_Mgr->GetAllPanes()[i].IsOk())
  586. return;
  587. if (Perspectives[ActivePerspective].Width.size() <= j ||
  588. Perspectives[ActivePerspective].Height.size() <= j)
  589. continue;
  590. // Width and height of the active perspective
  591. u32 W = Perspectives[ActivePerspective].Width[j],
  592. H = Perspectives[ActivePerspective].Height[j];
  593. // Check limits
  594. MathUtil::Clamp<u32>(&W, 5, 95);
  595. MathUtil::Clamp<u32>(&H, 5, 95);
  596. // Convert percentages to pixel lengths
  597. W = (W * iClientX) / 100;
  598. H = (H * iClientY) / 100;
  599. m_Mgr->GetAllPanes()[i].BestSize(W, H).MinSize(W, H);
  600. j++;
  601. }
  602. }
  603. m_Mgr->Update();
  604. for (u32 i = 0; i < m_Mgr->GetAllPanes().GetCount(); i++)
  605. {
  606. if (!m_Mgr->GetAllPanes()[i].window->IsKindOf(CLASSINFO(wxAuiToolBar)))
  607. {
  608. m_Mgr->GetAllPanes()[i].MinSize(-1, -1);
  609. }
  610. }
  611. }
  612. void CFrame::ReloadPanes()
  613. {
  614. // Close all pages
  615. ClosePages();
  616. CloseAllNotebooks();
  617. // Create new panes with notebooks
  618. for (u32 i = 0; i < Perspectives[ActivePerspective].Width.size() - 1; i++)
  619. {
  620. wxString PaneName = wxString::Format("Pane %i", i + 1);
  621. m_Mgr->AddPane(CreateEmptyNotebook(), wxAuiPaneInfo().Hide()
  622. .CaptionVisible(m_bEdit).Dockable(!m_bNoDocking).Position(i)
  623. .Name(PaneName).Caption(PaneName));
  624. }
  625. // Perspectives
  626. m_Mgr->LoadPerspective(Perspectives[ActivePerspective].Perspective, false);
  627. // Restore settings
  628. TogglePaneStyle(m_bNoDocking, IDM_NO_DOCKING);
  629. TogglePaneStyle(m_bEdit, IDM_EDIT_PERSPECTIVES);
  630. // Load GUI settings
  631. g_pCodeWindow->Load();
  632. // Open notebook pages
  633. AddRemoveBlankPage();
  634. g_pCodeWindow->OpenPages();
  635. // Repopulate perspectives
  636. PopulateSavedPerspectives();
  637. }
  638. void CFrame::DoLoadPerspective()
  639. {
  640. ReloadPanes();
  641. // Restore the exact window sizes, which LoadPerspective doesn't always do
  642. SetPaneSize();
  643. m_Mgr->Update();
  644. }
  645. // Update the local perspectives array
  646. void CFrame::LoadIniPerspectives()
  647. {
  648. Perspectives.clear();
  649. std::vector<std::string> VPerspectives;
  650. std::string _Perspectives;
  651. IniFile ini;
  652. ini.Load(File::GetUserPath(F_DEBUGGERCONFIG_IDX));
  653. IniFile::Section* perspectives = ini.GetOrCreateSection("Perspectives");
  654. perspectives->Get("Perspectives", &_Perspectives, "Perspective 1");
  655. perspectives->Get("Active", &ActivePerspective, 0);
  656. SplitString(_Perspectives, ',', VPerspectives);
  657. for (auto& VPerspective : VPerspectives)
  658. {
  659. SPerspectives Tmp;
  660. std::string _Section, _Perspective, _Widths, _Heights;
  661. std::vector<std::string> _SWidth, _SHeight;
  662. Tmp.Name = VPerspective;
  663. // Don't save a blank perspective
  664. if (Tmp.Name.empty())
  665. {
  666. continue;
  667. }
  668. _Section = StringFromFormat("P - %s", Tmp.Name.c_str());
  669. IniFile::Section* perspec_section = ini.GetOrCreateSection(_Section);
  670. perspec_section->Get("Perspective", &_Perspective,
  671. "layout2|"
  672. "name=Pane 0;caption=Pane 0;state=768;dir=5;prop=100000;|"
  673. "name=Pane 1;caption=Pane 1;state=31458108;dir=4;prop=100000;|"
  674. "dock_size(5,0,0)=22|dock_size(4,0,0)=333|");
  675. perspec_section->Get("Width", &_Widths, "70,25");
  676. perspec_section->Get("Height", &_Heights, "80,80");
  677. Tmp.Perspective = StrToWxStr(_Perspective);
  678. SplitString(_Widths, ',', _SWidth);
  679. SplitString(_Heights, ',', _SHeight);
  680. for (auto& Width : _SWidth)
  681. {
  682. int _Tmp;
  683. if (TryParse(Width, &_Tmp))
  684. Tmp.Width.push_back(_Tmp);
  685. }
  686. for (auto& Height : _SHeight)
  687. {
  688. int _Tmp;
  689. if (TryParse(Height, &_Tmp))
  690. Tmp.Height.push_back(_Tmp);
  691. }
  692. Perspectives.push_back(Tmp);
  693. }
  694. }
  695. void CFrame::UpdateCurrentPerspective()
  696. {
  697. SPerspectives *current = &Perspectives[ActivePerspective];
  698. current->Perspective = m_Mgr->SavePerspective();
  699. // Get client size
  700. int iClientX = GetSize().GetX(), iClientY = GetSize().GetY();
  701. current->Width.clear();
  702. current->Height.clear();
  703. for (u32 i = 0; i < m_Mgr->GetAllPanes().GetCount(); i++)
  704. {
  705. if (!m_Mgr->GetAllPanes()[i].window->
  706. IsKindOf(CLASSINFO(wxAuiToolBar)))
  707. {
  708. // Save width and height as a percentage of the client width and height
  709. current->Width.push_back(
  710. (m_Mgr->GetAllPanes()[i].window->GetClientSize().GetX() * 100) /
  711. iClientX);
  712. current->Height.push_back(
  713. (m_Mgr->GetAllPanes()[i].window->GetClientSize().GetY() * 100) /
  714. iClientY);
  715. }
  716. }
  717. }
  718. void CFrame::SaveIniPerspectives()
  719. {
  720. if (Perspectives.size() == 0) return;
  721. if (ActivePerspective >= Perspectives.size()) ActivePerspective = 0;
  722. // Turn off edit before saving
  723. TogglePaneStyle(false, IDM_EDIT_PERSPECTIVES);
  724. UpdateCurrentPerspective();
  725. IniFile ini;
  726. ini.Load(File::GetUserPath(F_DEBUGGERCONFIG_IDX));
  727. // Save perspective names
  728. std::string STmp = "";
  729. for (auto& Perspective : Perspectives)
  730. {
  731. STmp += Perspective.Name + ",";
  732. }
  733. STmp = STmp.substr(0, STmp.length() - 1);
  734. IniFile::Section* perspectives = ini.GetOrCreateSection("Perspectives");
  735. perspectives->Set("Perspectives", STmp);
  736. perspectives->Set("Active", ActivePerspective);
  737. // Save the perspectives
  738. for (auto& Perspective : Perspectives)
  739. {
  740. std::string _Section = "P - " + Perspective.Name;
  741. IniFile::Section* perspec_section = ini.GetOrCreateSection(_Section);
  742. perspec_section->Set("Perspective", WxStrToStr(Perspective.Perspective));
  743. std::string SWidth = "", SHeight = "";
  744. for (u32 j = 0; j < Perspective.Width.size(); j++)
  745. {
  746. SWidth += StringFromFormat("%i,", Perspective.Width[j]);
  747. SHeight += StringFromFormat("%i,", Perspective.Height[j]);
  748. }
  749. // Remove the ending ","
  750. SWidth = SWidth.substr(0, SWidth.length() - 1);
  751. SHeight = SHeight.substr(0, SHeight.length() - 1);
  752. perspec_section->Set("Width", SWidth);
  753. perspec_section->Set("Height", SHeight);
  754. }
  755. ini.Save(File::GetUserPath(F_DEBUGGERCONFIG_IDX));
  756. // Save notebook affiliations
  757. g_pCodeWindow->Save();
  758. TogglePaneStyle(m_bEdit, IDM_EDIT_PERSPECTIVES);
  759. }
  760. void CFrame::AddPane(int dir)
  761. {
  762. int PaneNum = GetNotebookCount() + 1;
  763. wxString PaneName = wxString::Format("Pane %i", PaneNum);
  764. wxAuiPaneInfo PaneInfo = wxAuiPaneInfo()
  765. .CaptionVisible(m_bEdit).Dockable(!m_bNoDocking)
  766. .Name(PaneName).Caption(PaneName)
  767. .Position(GetNotebookCount());
  768. switch (dir)
  769. {
  770. case ADD_PANE_TOP:
  771. PaneInfo = PaneInfo.Top();
  772. break;
  773. case ADD_PANE_BOTTOM:
  774. PaneInfo = PaneInfo.Bottom();
  775. break;
  776. case ADD_PANE_LEFT:
  777. PaneInfo = PaneInfo.Left();
  778. break;
  779. case ADD_PANE_RIGHT:
  780. PaneInfo = PaneInfo.Right();
  781. break;
  782. case ADD_PANE_CENTER:
  783. PaneInfo = PaneInfo.Center();
  784. break;
  785. default:
  786. break;
  787. }
  788. m_Mgr->AddPane(CreateEmptyNotebook(), PaneInfo);
  789. AddRemoveBlankPage();
  790. m_Mgr->Update();
  791. }
  792. wxWindow * CFrame::GetNotebookPageFromId(wxWindowID Id)
  793. {
  794. for (u32 i = 0; i < m_Mgr->GetAllPanes().GetCount(); i++)
  795. {
  796. if (!m_Mgr->GetAllPanes()[i].window->IsKindOf(CLASSINFO(wxAuiNotebook)))
  797. continue;
  798. wxAuiNotebook * NB = (wxAuiNotebook*)m_Mgr->GetAllPanes()[i].window;
  799. for (u32 j = 0; j < NB->GetPageCount(); j++)
  800. {
  801. if (NB->GetPage(j)->GetId() == Id)
  802. return NB->GetPage(j);
  803. }
  804. }
  805. return nullptr;
  806. }
  807. wxFrame* CFrame::CreateParentFrame(wxWindowID Id, const wxString& Title, wxWindow* Child)
  808. {
  809. wxFrame* Frame = new wxFrame(this, Id, Title);
  810. Child->Reparent(Frame);
  811. wxBoxSizer* m_MainSizer = new wxBoxSizer(wxHORIZONTAL);
  812. m_MainSizer->Add(Child, 1, wxEXPAND);
  813. Frame->Bind(wxEVT_CLOSE_WINDOW, &CFrame::OnFloatingPageClosed, this);
  814. // Main sizer
  815. Frame->SetSizer(m_MainSizer);
  816. // Minimum frame size
  817. Frame->SetMinSize(wxSize(200, 200));
  818. Frame->Show();
  819. return Frame;
  820. }
  821. wxAuiNotebook* CFrame::CreateEmptyNotebook()
  822. {
  823. const long NOTEBOOK_STYLE = wxAUI_NB_TOP | wxAUI_NB_TAB_SPLIT |
  824. wxAUI_NB_TAB_MOVE |
  825. wxAUI_NB_TAB_EXTERNAL_MOVE | wxAUI_NB_SCROLL_BUTTONS |
  826. wxAUI_NB_WINDOWLIST_BUTTON | wxNO_BORDER;
  827. return new wxAuiNotebook(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, NOTEBOOK_STYLE);
  828. }
  829. void CFrame::AddRemoveBlankPage()
  830. {
  831. for (u32 i = 0; i < m_Mgr->GetAllPanes().GetCount(); i++)
  832. {
  833. if (!m_Mgr->GetAllPanes()[i].window->IsKindOf(CLASSINFO(wxAuiNotebook)))
  834. continue;
  835. wxAuiNotebook * NB = (wxAuiNotebook*)m_Mgr->GetAllPanes()[i].window;
  836. for (u32 j = 0; j < NB->GetPageCount(); j++)
  837. {
  838. if (NB->GetPageText(j).IsSameAs("<>") && NB->GetPageCount() > 1)
  839. NB->DeletePage(j);
  840. }
  841. if (NB->GetPageCount() == 0)
  842. NB->AddPage(new wxPanel(this, wxID_ANY), "<>", true);
  843. }
  844. }
  845. int CFrame::GetNotebookAffiliation(wxWindowID Id)
  846. {
  847. for (u32 i = 0, j = 0; i < m_Mgr->GetAllPanes().GetCount(); i++)
  848. {
  849. if (!m_Mgr->GetAllPanes()[i].window->IsKindOf(CLASSINFO(wxAuiNotebook)))
  850. continue;
  851. wxAuiNotebook * NB = (wxAuiNotebook*)m_Mgr->GetAllPanes()[i].window;
  852. for (u32 k = 0; k < NB->GetPageCount(); k++)
  853. {
  854. if (NB->GetPage(k)->GetId() == Id)
  855. return j;
  856. }
  857. j++;
  858. }
  859. return -1;
  860. }
  861. // Close all panes with notebooks
  862. void CFrame::CloseAllNotebooks()
  863. {
  864. wxAuiPaneInfoArray AllPanes = m_Mgr->GetAllPanes();
  865. for (u32 i = 0; i < AllPanes.GetCount(); i++)
  866. {
  867. if (AllPanes[i].window->IsKindOf(CLASSINFO(wxAuiNotebook)))
  868. {
  869. AllPanes[i].DestroyOnClose(true);
  870. m_Mgr->ClosePane(AllPanes[i]);
  871. }
  872. }
  873. }
  874. int CFrame::GetNotebookCount()
  875. {
  876. int Ret = 0;
  877. for (u32 i = 0; i < m_Mgr->GetAllPanes().GetCount(); i++)
  878. {
  879. if (m_Mgr->GetAllPanes()[i].window->IsKindOf(CLASSINFO(wxAuiNotebook)))
  880. Ret++;
  881. }
  882. return Ret;
  883. }
  884. wxAuiNotebook * CFrame::GetNotebookFromId(u32 NBId)
  885. {
  886. for (u32 i = 0, j = 0; i < m_Mgr->GetAllPanes().GetCount(); i++)
  887. {
  888. if (!m_Mgr->GetAllPanes()[i].window->IsKindOf(CLASSINFO(wxAuiNotebook)))
  889. continue;
  890. if (j == NBId)
  891. return (wxAuiNotebook*)m_Mgr->GetAllPanes()[i].window;
  892. j++;
  893. }
  894. return nullptr;
  895. }