| File: | Source/Core/DolphinWX/Src/FrameAui.cpp |
| Location: | line 289, column 3 |
| Description: | Called C++ object pointer is null |
| 1 | // Copyright 2013 Dolphin Emulator Project | |||
| 2 | // Licensed under GPLv2 | |||
| 3 | // Refer to the license.txt file included. | |||
| 4 | ||||
| 5 | #include "Common.h" // Common | |||
| 6 | #include "ConsoleListener.h" | |||
| 7 | ||||
| 8 | #include "Globals.h" // Local | |||
| 9 | #include "Frame.h" | |||
| 10 | #include "LogWindow.h" | |||
| 11 | #include "WxUtils.h" | |||
| 12 | ||||
| 13 | #include "ConfigManager.h" // Core | |||
| 14 | ||||
| 15 | // ------------ | |||
| 16 | // Aui events | |||
| 17 | ||||
| 18 | void CFrame::OnManagerResize(wxAuiManagerEvent& event) | |||
| 19 | { | |||
| 20 | if (!g_pCodeWindow && m_LogWindow && | |||
| 21 | m_Mgr->GetPane(_T("Pane 1")L"Pane 1").IsShown() && | |||
| 22 | !m_Mgr->GetPane(_T("Pane 1")L"Pane 1").IsFloating()) | |||
| 23 | { | |||
| 24 | m_LogWindow->x = m_Mgr->GetPane(_T("Pane 1")L"Pane 1").rect.GetWidth(); | |||
| 25 | m_LogWindow->y = m_Mgr->GetPane(_T("Pane 1")L"Pane 1").rect.GetHeight(); | |||
| 26 | m_LogWindow->winpos = m_Mgr->GetPane(_T("Pane 1")L"Pane 1").dock_direction; | |||
| 27 | } | |||
| 28 | event.Skip(); | |||
| 29 | ResizeConsole(); | |||
| 30 | } | |||
| 31 | ||||
| 32 | void CFrame::OnPaneClose(wxAuiManagerEvent& event) | |||
| 33 | { | |||
| 34 | event.Veto(); | |||
| 35 | ||||
| 36 | wxAuiNotebook * nb = (wxAuiNotebook*)event.pane->window; | |||
| 37 | if (!nb) return; | |||
| 38 | ||||
| 39 | if (!g_pCodeWindow) | |||
| 40 | { | |||
| 41 | if (nb->GetPage(0)->GetId() == IDM_LOGWINDOW || | |||
| 42 | nb->GetPage(0)->GetId() == IDM_LOGCONFIGWINDOW || | |||
| 43 | nb->GetPage(0)->GetId() == IDM_CONSOLEWINDOW) | |||
| 44 | { | |||
| 45 | // Closing a pane containing the logwindow or a console closes both | |||
| 46 | SConfig::GetInstance().m_InterfaceConsole = false; | |||
| 47 | SConfig::GetInstance().m_InterfaceLogWindow = false; | |||
| 48 | SConfig::GetInstance().m_InterfaceLogConfigWindow = false; | |||
| 49 | ToggleConsole(false); | |||
| 50 | ToggleLogWindow(false); | |||
| 51 | ToggleLogConfigWindow(false); | |||
| 52 | } | |||
| 53 | } | |||
| 54 | else | |||
| 55 | { | |||
| 56 | if (GetNotebookCount() == 1) | |||
| 57 | { | |||
| 58 | wxMessageBox(_("At least one pane must remain open.")wxGetTranslation(("At least one pane must remain open.")), | |||
| 59 | _("Notice")wxGetTranslation(("Notice")), wxOK0x00000004, this); | |||
| 60 | } | |||
| 61 | else if (nb->GetPageCount() != 0 && !nb->GetPageText(0).IsSameAs(wxT("<>")L"<>")) | |||
| 62 | { | |||
| 63 | wxMessageBox(_("You can't close panes that have pages in them.")wxGetTranslation(("You can't close panes that have pages in them." )), | |||
| 64 | _("Notice")wxGetTranslation(("Notice")), wxOK0x00000004, this); | |||
| 65 | } | |||
| 66 | else | |||
| 67 | { | |||
| 68 | // Detach and delete the empty notebook | |||
| 69 | event.pane->DestroyOnClose(true); | |||
| 70 | m_Mgr->ClosePane(*event.pane); | |||
| 71 | } | |||
| 72 | } | |||
| 73 | ||||
| 74 | m_Mgr->Update(); | |||
| 75 | } | |||
| 76 | ||||
| 77 | void CFrame::ToggleLogWindow(bool bShow) | |||
| 78 | { | |||
| 79 | if (!m_LogWindow) | |||
| 80 | return; | |||
| 81 | ||||
| 82 | GetMenuBar()->FindItem(IDM_LOGWINDOW)->Check(bShow); | |||
| 83 | ||||
| 84 | if (bShow) | |||
| 85 | { | |||
| 86 | // Create a new log window if it doesn't exist. | |||
| 87 | if (!m_LogWindow) | |||
| 88 | { | |||
| 89 | m_LogWindow = new CLogWindow(this, IDM_LOGWINDOW); | |||
| 90 | } | |||
| 91 | ||||
| 92 | m_LogWindow->Enable(); | |||
| 93 | ||||
| 94 | DoAddPage(m_LogWindow, | |||
| 95 | g_pCodeWindow ? g_pCodeWindow->iNbAffiliation[0] : 0, | |||
| 96 | g_pCodeWindow ? bFloatWindow[0] : false); | |||
| 97 | } | |||
| 98 | else | |||
| 99 | { | |||
| 100 | // Hiding the log window, so disable it and remove it. | |||
| 101 | m_LogWindow->Disable(); | |||
| 102 | DoRemovePage(m_LogWindow, true); | |||
| 103 | } | |||
| 104 | ||||
| 105 | // Hide or Show the pane | |||
| 106 | if (!g_pCodeWindow) | |||
| 107 | TogglePane(); | |||
| 108 | } | |||
| 109 | ||||
| 110 | void CFrame::ToggleLogConfigWindow(bool bShow) | |||
| 111 | { | |||
| 112 | GetMenuBar()->FindItem(IDM_LOGCONFIGWINDOW)->Check(bShow); | |||
| 113 | ||||
| 114 | if (bShow) | |||
| 115 | { | |||
| 116 | if (!m_LogConfigWindow) | |||
| 117 | m_LogConfigWindow = new LogConfigWindow(this, m_LogWindow, IDM_LOGCONFIGWINDOW); | |||
| 118 | ||||
| 119 | const int nbIndex = IDM_LOGCONFIGWINDOW - IDM_LOGWINDOW; | |||
| 120 | DoAddPage(m_LogConfigWindow, | |||
| 121 | g_pCodeWindow ? g_pCodeWindow->iNbAffiliation[nbIndex] : 0, | |||
| 122 | g_pCodeWindow ? bFloatWindow[nbIndex] : false); | |||
| 123 | } | |||
| 124 | else | |||
| 125 | { | |||
| 126 | DoRemovePage(m_LogConfigWindow, false); | |||
| 127 | m_LogConfigWindow = NULL__null; | |||
| 128 | } | |||
| 129 | ||||
| 130 | // Hide or Show the pane | |||
| 131 | if (!g_pCodeWindow) | |||
| 132 | TogglePane(); | |||
| 133 | } | |||
| 134 | ||||
| 135 | void CFrame::ToggleConsole(bool bShow) | |||
| 136 | { | |||
| 137 | #ifdef _WIN32 | |||
| 138 | GetMenuBar()->FindItem(IDM_CONSOLEWINDOW)->Check(bShow); | |||
| 139 | ||||
| 140 | if (bShow) | |||
| 141 | { | |||
| 142 | // If the console doesn't exist, we create it | |||
| 143 | if (!GetConsoleWindow()) | |||
| 144 | { | |||
| 145 | ConsoleListener *Console = LogManager::GetInstance()->GetConsoleListener(); | |||
| 146 | Console->Open(); | |||
| 147 | } | |||
| 148 | else | |||
| 149 | { | |||
| 150 | ShowWindow(GetConsoleWindow(), SW_SHOW); | |||
| 151 | } | |||
| 152 | ||||
| 153 | // Create the parent window if it doesn't exist | |||
| 154 | wxPanel *ConsoleParent = (wxPanel*)FindWindowById(IDM_CONSOLEWINDOW); | |||
| 155 | if (!ConsoleParent) ConsoleParent = new wxPanel(this, IDM_CONSOLEWINDOW, | |||
| 156 | wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL0x00080000, _("Console")wxGetTranslation(("Console"))); | |||
| 157 | ||||
| 158 | wxWindow *ConsoleWin = new wxWindow(); | |||
| 159 | ConsoleWin->SetHWND((WXHWND)GetConsoleWindow()); | |||
| 160 | ConsoleWin->AdoptAttributesFromHWND(); | |||
| 161 | ConsoleWin->Reparent(ConsoleParent); | |||
| 162 | ||||
| 163 | ConsoleParent->Enable(); | |||
| 164 | const int nbIndex = IDM_CONSOLEWINDOW - IDM_LOGWINDOW; | |||
| 165 | DoAddPage(ConsoleParent, | |||
| 166 | g_pCodeWindow ? g_pCodeWindow->iNbAffiliation[nbIndex] : 0, | |||
| 167 | g_pCodeWindow ? bFloatWindow[nbIndex] : false); | |||
| 168 | } | |||
| 169 | else // Hide | |||
| 170 | { | |||
| 171 | if(GetConsoleWindow()) | |||
| 172 | ShowWindow(GetConsoleWindow(), SW_HIDE); // WIN32 | |||
| 173 | ||||
| 174 | wxPanel *ConsoleParent = (wxPanel*)FindWindowById(IDM_CONSOLEWINDOW); | |||
| 175 | if (ConsoleParent) | |||
| 176 | ConsoleParent->Disable(); | |||
| 177 | ||||
| 178 | // Then close the page | |||
| 179 | DoRemovePage(ConsoleParent, true); | |||
| 180 | } | |||
| 181 | ||||
| 182 | // Hide or Show the pane | |||
| 183 | if (!g_pCodeWindow) | |||
| 184 | TogglePane(); | |||
| 185 | #endif | |||
| 186 | } | |||
| 187 | ||||
| 188 | void CFrame::OnToggleWindow(wxCommandEvent& event) | |||
| 189 | { | |||
| 190 | bool bShow = GetMenuBar()->IsChecked(event.GetId()); | |||
| 191 | ||||
| 192 | switch(event.GetId()) | |||
| 193 | { | |||
| 194 | case IDM_LOGWINDOW: | |||
| 195 | if (!g_pCodeWindow) | |||
| 196 | SConfig::GetInstance().m_InterfaceLogWindow = bShow; | |||
| 197 | ToggleLogWindow(bShow); | |||
| 198 | break; | |||
| 199 | case IDM_LOGCONFIGWINDOW: | |||
| 200 | if (!g_pCodeWindow) | |||
| 201 | SConfig::GetInstance().m_InterfaceLogConfigWindow = bShow; | |||
| 202 | ToggleLogConfigWindow(bShow); | |||
| 203 | break; | |||
| 204 | case IDM_CONSOLEWINDOW: | |||
| 205 | if (!g_pCodeWindow) | |||
| 206 | SConfig::GetInstance().m_InterfaceConsole = bShow; | |||
| 207 | ToggleConsole(bShow); | |||
| 208 | break; | |||
| 209 | case IDM_REGISTERWINDOW: | |||
| 210 | g_pCodeWindow->ToggleRegisterWindow(bShow); | |||
| 211 | break; | |||
| 212 | case IDM_BREAKPOINTWINDOW: | |||
| 213 | g_pCodeWindow->ToggleBreakPointWindow(bShow); | |||
| 214 | break; | |||
| 215 | case IDM_MEMORYWINDOW: | |||
| 216 | g_pCodeWindow->ToggleMemoryWindow(bShow); | |||
| 217 | break; | |||
| 218 | case IDM_JITWINDOW: | |||
| 219 | g_pCodeWindow->ToggleJitWindow(bShow); | |||
| 220 | break; | |||
| 221 | case IDM_SOUNDWINDOW: | |||
| 222 | g_pCodeWindow->ToggleSoundWindow(bShow); | |||
| 223 | break; | |||
| 224 | case IDM_VIDEOWINDOW: | |||
| 225 | g_pCodeWindow->ToggleVideoWindow(bShow); | |||
| 226 | break; | |||
| 227 | } | |||
| 228 | } | |||
| 229 | ||||
| 230 | // Notebooks | |||
| 231 | // --------------------- | |||
| 232 | void CFrame::ClosePages() | |||
| 233 | { | |||
| 234 | ToggleLogWindow(false); | |||
| 235 | ToggleLogConfigWindow(false); | |||
| 236 | ToggleConsole(false); | |||
| 237 | if (g_pCodeWindow) | |||
| 238 | { | |||
| 239 | g_pCodeWindow->ToggleCodeWindow(false); | |||
| 240 | g_pCodeWindow->ToggleRegisterWindow(false); | |||
| 241 | g_pCodeWindow->ToggleBreakPointWindow(false); | |||
| 242 | g_pCodeWindow->ToggleMemoryWindow(false); | |||
| 243 | g_pCodeWindow->ToggleJitWindow(false); | |||
| 244 | g_pCodeWindow->ToggleSoundWindow(false); | |||
| 245 | g_pCodeWindow->ToggleVideoWindow(false); | |||
| 246 | } | |||
| 247 | } | |||
| 248 | ||||
| 249 | void CFrame::OnNotebookPageChanged(wxAuiNotebookEvent& event) | |||
| 250 | { | |||
| 251 | event.Skip(); | |||
| 252 | ||||
| 253 | if (!g_pCodeWindow) | |||
| 254 | return; | |||
| 255 | ||||
| 256 | // Remove the blank page if any | |||
| 257 | AddRemoveBlankPage(); | |||
| 258 | ||||
| 259 | // Update the notebook affiliation | |||
| 260 | for (int i = IDM_LOGWINDOW; i <= IDM_CODEWINDOW; i++) | |||
| 261 | { | |||
| 262 | if(GetNotebookAffiliation(i) >= 0) | |||
| 263 | g_pCodeWindow->iNbAffiliation[i - IDM_LOGWINDOW] = GetNotebookAffiliation(i); | |||
| 264 | } | |||
| 265 | } | |||
| 266 | ||||
| 267 | void CFrame::OnNotebookPageClose(wxAuiNotebookEvent& event) | |||
| 268 | { | |||
| 269 | // Override event | |||
| 270 | event.Veto(); | |||
| 271 | ||||
| 272 | wxAuiNotebook* Ctrl = (wxAuiNotebook*)event.GetEventObject(); | |||
| 273 | ||||
| 274 | if (Ctrl->GetPage(event.GetSelection())->GetId() == IDM_LOGWINDOW) | |||
| ||||
| 275 | ToggleLogWindow(false); | |||
| 276 | if (Ctrl->GetPage(event.GetSelection())->GetId() == IDM_LOGCONFIGWINDOW) | |||
| 277 | ToggleLogConfigWindow(false); | |||
| 278 | if (Ctrl->GetPage(event.GetSelection())->GetId() == IDM_CONSOLEWINDOW) | |||
| 279 | ToggleConsole(false); | |||
| 280 | if (Ctrl->GetPage(event.GetSelection())->GetId() == IDM_REGISTERWINDOW) | |||
| 281 | g_pCodeWindow->ToggleRegisterWindow(false); | |||
| 282 | if (Ctrl->GetPage(event.GetSelection())->GetId() == IDM_BREAKPOINTWINDOW) | |||
| 283 | g_pCodeWindow->ToggleBreakPointWindow(false); | |||
| 284 | if (Ctrl->GetPage(event.GetSelection())->GetId() == IDM_JITWINDOW) | |||
| 285 | g_pCodeWindow->ToggleJitWindow(false); | |||
| 286 | if (Ctrl->GetPage(event.GetSelection())->GetId() == IDM_MEMORYWINDOW) | |||
| 287 | g_pCodeWindow->ToggleMemoryWindow(false); | |||
| 288 | if (Ctrl->GetPage(event.GetSelection())->GetId() == IDM_SOUNDWINDOW) | |||
| 289 | g_pCodeWindow->ToggleSoundWindow(false); | |||
| ||||
| 290 | if (Ctrl->GetPage(event.GetSelection())->GetId() == IDM_VIDEOWINDOW) | |||
| 291 | g_pCodeWindow->ToggleVideoWindow(false); | |||
| 292 | } | |||
| 293 | ||||
| 294 | void CFrame::OnFloatingPageClosed(wxCloseEvent& event) | |||
| 295 | { | |||
| 296 | ToggleFloatWindow(event.GetId() - IDM_LOGWINDOW_PARENT + IDM_FLOAT_LOGWINDOW); | |||
| 297 | } | |||
| 298 | ||||
| 299 | void CFrame::OnFloatingPageSize(wxSizeEvent& event) | |||
| 300 | { | |||
| 301 | event.Skip(); | |||
| 302 | ResizeConsole(); | |||
| 303 | } | |||
| 304 | ||||
| 305 | void CFrame::OnFloatWindow(wxCommandEvent& event) | |||
| 306 | { | |||
| 307 | ToggleFloatWindow(event.GetId()); | |||
| 308 | } | |||
| 309 | ||||
| 310 | void CFrame::ToggleFloatWindow(int Id) | |||
| 311 | { | |||
| 312 | wxWindowID WinId = Id - IDM_FLOAT_LOGWINDOW + IDM_LOGWINDOW; | |||
| 313 | if (GetNotebookPageFromId(WinId)) | |||
| 314 | { | |||
| 315 | DoFloatNotebookPage(WinId); | |||
| 316 | bFloatWindow[WinId - IDM_LOGWINDOW] = true; | |||
| 317 | } | |||
| 318 | else | |||
| 319 | { | |||
| 320 | if (FindWindowById(WinId)) | |||
| 321 | DoUnfloatPage(WinId - IDM_LOGWINDOW + IDM_LOGWINDOW_PARENT); | |||
| 322 | bFloatWindow[WinId - IDM_LOGWINDOW] = false; | |||
| 323 | } | |||
| 324 | } | |||
| 325 | ||||
| 326 | void CFrame::DoFloatNotebookPage(wxWindowID Id) | |||
| 327 | { | |||
| 328 | wxPanel *Win = (wxPanel*)FindWindowById(Id); | |||
| 329 | if (!Win) return; | |||
| 330 | ||||
| 331 | for (int i = 0; i < GetNotebookCount(); i++) | |||
| 332 | { | |||
| 333 | wxAuiNotebook *nb = GetNotebookFromId(i); | |||
| 334 | if (nb->GetPageIndex(Win) != wxNOT_FOUND(-1)) | |||
| 335 | { | |||
| 336 | nb->RemovePage(nb->GetPageIndex(Win)); | |||
| 337 | // Create the parent frame and reparent the window | |||
| 338 | CreateParentFrame(Win->GetId() + IDM_LOGWINDOW_PARENT - IDM_LOGWINDOW, | |||
| 339 | Win->GetName(), Win); | |||
| 340 | if (nb->GetPageCount() == 0) | |||
| 341 | AddRemoveBlankPage(); | |||
| 342 | } | |||
| 343 | } | |||
| 344 | } | |||
| 345 | ||||
| 346 | void CFrame::DoUnfloatPage(int Id) | |||
| 347 | { | |||
| 348 | wxFrame * Win = (wxFrame*)FindWindowById(Id); | |||
| 349 | if (!Win) return; | |||
| 350 | ||||
| 351 | wxWindow * Child = Win->GetChildren().Item(0)->GetData(); | |||
| 352 | Child->Reparent(this); | |||
| 353 | DoAddPage(Child, g_pCodeWindow->iNbAffiliation[Child->GetId() - IDM_LOGWINDOW], false); | |||
| 354 | Win->Destroy(); | |||
| 355 | } | |||
| 356 | ||||
| 357 | void CFrame::OnTab(wxAuiNotebookEvent& event) | |||
| 358 | { | |||
| 359 | event.Skip(); | |||
| 360 | if (!g_pCodeWindow) return; | |||
| 361 | ||||
| 362 | // Create the popup menu | |||
| 363 | wxMenu* MenuPopup = new wxMenu; | |||
| 364 | ||||
| 365 | wxMenuItem* Item = new wxMenuItem(MenuPopup, wxID_ANY, | |||
| 366 | _("Select floating windows")wxGetTranslation(("Select floating windows"))); | |||
| 367 | MenuPopup->Append(Item); | |||
| 368 | Item->Enable(false); | |||
| 369 | MenuPopup->Append(new wxMenuItem(MenuPopup)); | |||
| 370 | ||||
| 371 | for (int i = IDM_LOGWINDOW; i <= IDM_CODEWINDOW; i++) | |||
| 372 | { | |||
| 373 | wxWindow *Win = FindWindowById(i); | |||
| 374 | if (Win && Win->IsEnabled()) | |||
| 375 | { | |||
| 376 | Item = new wxMenuItem(MenuPopup, i + IDM_FLOAT_LOGWINDOW - IDM_LOGWINDOW, | |||
| 377 | Win->GetName(), wxT("")L"", wxITEM_CHECK); | |||
| 378 | MenuPopup->Append(Item); | |||
| 379 | Item->Check(!!FindWindowById(i + IDM_LOGWINDOW_PARENT - IDM_LOGWINDOW)); | |||
| 380 | } | |||
| 381 | } | |||
| 382 | ||||
| 383 | // Line up our menu with the cursor | |||
| 384 | wxPoint Pt = ::wxGetMousePosition(); | |||
| 385 | Pt = ScreenToClient(Pt); | |||
| 386 | ||||
| 387 | // Show | |||
| 388 | PopupMenu(MenuPopup, Pt); | |||
| 389 | } | |||
| 390 | ||||
| 391 | void CFrame::OnAllowNotebookDnD(wxAuiNotebookEvent& event) | |||
| 392 | { | |||
| 393 | event.Skip(); | |||
| 394 | event.Allow(); | |||
| 395 | ResizeConsole(); | |||
| 396 | } | |||
| 397 | ||||
| 398 | void CFrame::ShowResizePane() | |||
| 399 | { | |||
| 400 | if (!m_LogWindow) return; | |||
| 401 | ||||
| 402 | // Make sure the size is sane | |||
| 403 | if (m_LogWindow->x > GetClientRect().GetWidth()) | |||
| 404 | m_LogWindow->x = GetClientRect().GetWidth() / 2; | |||
| 405 | if (m_LogWindow->y > GetClientRect().GetHeight()) | |||
| 406 | m_LogWindow->y = GetClientRect().GetHeight() / 2; | |||
| 407 | ||||
| 408 | wxAuiPaneInfo &pane = m_Mgr->GetPane(wxT("Pane 1")L"Pane 1"); | |||
| 409 | ||||
| 410 | // Hide first otherwise a resize doesn't work | |||
| 411 | pane.Hide(); | |||
| 412 | m_Mgr->Update(); | |||
| 413 | ||||
| 414 | pane.BestSize(m_LogWindow->x, m_LogWindow->y) | |||
| 415 | .MinSize(m_LogWindow->x, m_LogWindow->y) | |||
| 416 | .Direction(m_LogWindow->winpos).Show(); | |||
| 417 | m_Mgr->Update(); | |||
| 418 | ||||
| 419 | // Reset the minimum size of the pane | |||
| 420 | pane.MinSize(-1, -1); | |||
| 421 | m_Mgr->Update(); | |||
| 422 | } | |||
| 423 | ||||
| 424 | void CFrame::TogglePane() | |||
| 425 | { | |||
| 426 | // Get the first notebook | |||
| 427 | wxAuiNotebook * NB = NULL__null; | |||
| 428 | for (u32 i = 0; i < m_Mgr->GetAllPanes().GetCount(); i++) | |||
| 429 | { | |||
| 430 | if (m_Mgr->GetAllPanes()[i].window->IsKindOf(CLASSINFO(wxAuiNotebook)(&wxAuiNotebook::ms_classInfo))) | |||
| 431 | NB = (wxAuiNotebook*)m_Mgr->GetAllPanes()[i].window; | |||
| 432 | } | |||
| 433 | ||||
| 434 | if (NB) | |||
| 435 | { | |||
| 436 | if (NB->GetPageCount() == 0) | |||
| 437 | { | |||
| 438 | m_Mgr->GetPane(_T("Pane 1")L"Pane 1").Hide(); | |||
| 439 | m_Mgr->Update(); | |||
| 440 | } | |||
| 441 | else | |||
| 442 | { | |||
| 443 | ShowResizePane(); | |||
| 444 | } | |||
| 445 | } | |||
| 446 | } | |||
| 447 | ||||
| 448 | void CFrame::DoRemovePage(wxWindow *Win, bool bHide) | |||
| 449 | { | |||
| 450 | if (!Win) return; | |||
| 451 | ||||
| 452 | wxWindow *Parent = FindWindowById(Win->GetId() + | |||
| 453 | IDM_LOGWINDOW_PARENT - IDM_LOGWINDOW); | |||
| 454 | ||||
| 455 | if (Parent) | |||
| 456 | { | |||
| 457 | if (bHide) | |||
| 458 | { | |||
| 459 | Win->Hide(); | |||
| 460 | Win->Reparent(this); | |||
| 461 | } | |||
| 462 | else | |||
| 463 | { | |||
| 464 | Win->Destroy(); | |||
| 465 | } | |||
| 466 | ||||
| 467 | Parent->Destroy(); | |||
| 468 | } | |||
| 469 | else | |||
| 470 | { | |||
| 471 | for (int i = 0; i < GetNotebookCount(); i++) | |||
| 472 | { | |||
| 473 | int PageIndex = GetNotebookFromId(i)->GetPageIndex(Win); | |||
| 474 | if (PageIndex != wxNOT_FOUND(-1)) | |||
| 475 | { | |||
| 476 | GetNotebookFromId(i)->RemovePage(PageIndex); | |||
| 477 | if (bHide) | |||
| 478 | { | |||
| 479 | Win->Hide(); | |||
| 480 | Win->Reparent(this); | |||
| 481 | } | |||
| 482 | else | |||
| 483 | { | |||
| 484 | Win->Destroy(); | |||
| 485 | } | |||
| 486 | } | |||
| 487 | } | |||
| 488 | } | |||
| 489 | ||||
| 490 | if (g_pCodeWindow) | |||
| 491 | AddRemoveBlankPage(); | |||
| 492 | } | |||
| 493 | ||||
| 494 | void CFrame::DoAddPage(wxWindow *Win, int i, bool Float) | |||
| 495 | { | |||
| 496 | if (!Win) return; | |||
| 497 | ||||
| 498 | // Ensure accessor remains within valid bounds. | |||
| 499 | if (i < 0 || i > GetNotebookCount()-1) | |||
| 500 | i = 0; | |||
| 501 | ||||
| 502 | // The page was already previously added, no need to add it again. | |||
| 503 | if (Win && GetNotebookFromId(i)->GetPageIndex(Win) != wxNOT_FOUND(-1)) | |||
| 504 | return; | |||
| 505 | ||||
| 506 | if (!Float) | |||
| 507 | GetNotebookFromId(i)->AddPage(Win, Win->GetName(), true); | |||
| 508 | else | |||
| 509 | CreateParentFrame(Win->GetId() + IDM_LOGWINDOW_PARENT - IDM_LOGWINDOW, | |||
| 510 | Win->GetName(), Win); | |||
| 511 | } | |||
| 512 | ||||
| 513 | // Toolbar | |||
| 514 | void CFrame::OnDropDownSettingsToolbar(wxAuiToolBarEvent& event) | |||
| 515 | { | |||
| 516 | event.Skip(); | |||
| 517 | ClearStatusBar(); | |||
| 518 | ||||
| 519 | if (event.IsDropDownClicked()) | |||
| 520 | { | |||
| 521 | wxAuiToolBar* Tb = static_cast<wxAuiToolBar*>(event.GetEventObject()); | |||
| 522 | Tb->SetToolSticky(event.GetId(), true); | |||
| 523 | ||||
| 524 | // Create the popup menu | |||
| 525 | wxMenu* menuPopup = new wxMenu; | |||
| 526 | ||||
| 527 | wxMenuItem* Item = new wxMenuItem(menuPopup, IDM_PERSPECTIVES_ADD_PANE, | |||
| 528 | _("Add new pane")wxGetTranslation(("Add new pane"))); | |||
| 529 | menuPopup->Append(Item); | |||
| 530 | menuPopup->Append(new wxMenuItem(menuPopup)); | |||
| 531 | Item = new wxMenuItem(menuPopup, IDM_TAB_SPLIT, _("Tab split")wxGetTranslation(("Tab split")), | |||
| 532 | wxT("")L"", wxITEM_CHECK); | |||
| 533 | menuPopup->Append(Item); | |||
| 534 | Item->Check(m_bTabSplit); | |||
| 535 | Item = new wxMenuItem(menuPopup, IDM_NO_DOCKING, _("No docking")wxGetTranslation(("No docking")), | |||
| 536 | wxT("")L"", wxITEM_CHECK); | |||
| 537 | menuPopup->Append(Item); | |||
| 538 | Item->Check(m_bNoDocking); | |||
| 539 | ||||
| 540 | // Line up our menu with the button | |||
| 541 | wxRect rect = Tb->GetToolRect(event.GetId()); | |||
| 542 | wxPoint Pt = Tb->ClientToScreen(rect.GetBottomLeft()); | |||
| 543 | Pt = ScreenToClient(Pt); | |||
| 544 | ||||
| 545 | // Show | |||
| 546 | PopupMenu(menuPopup, Pt); | |||
| 547 | ||||
| 548 | // Make the button un-stuck again | |||
| 549 | if (!m_bEdit) | |||
| 550 | { | |||
| 551 | Tb->SetToolSticky(event.GetId(), false); | |||
| 552 | } | |||
| 553 | } | |||
| 554 | } | |||
| 555 | ||||
| 556 | void CFrame::OnDropDownToolbarItem(wxAuiToolBarEvent& event) | |||
| 557 | { | |||
| 558 | event.Skip(); | |||
| 559 | ClearStatusBar(); | |||
| 560 | ||||
| 561 | if (event.IsDropDownClicked()) | |||
| 562 | { | |||
| 563 | wxAuiToolBar* tb = static_cast<wxAuiToolBar*>(event.GetEventObject()); | |||
| 564 | tb->SetToolSticky(event.GetId(), true); | |||
| 565 | ||||
| 566 | // create the popup menu | |||
| 567 | wxMenu* menuPopup = new wxMenu; | |||
| 568 | wxMenuItem* Item = new wxMenuItem(menuPopup, IDM_ADD_PERSPECTIVE, | |||
| 569 | _("Create new perspective")wxGetTranslation(("Create new perspective"))); | |||
| 570 | menuPopup->Append(Item); | |||
| 571 | ||||
| 572 | if (Perspectives.size() > 0) | |||
| 573 | { | |||
| 574 | menuPopup->Append(new wxMenuItem(menuPopup)); | |||
| 575 | for (u32 i = 0; i < Perspectives.size(); i++) | |||
| 576 | { | |||
| 577 | wxMenuItem* mItem = new wxMenuItem(menuPopup, IDM_PERSPECTIVES_0 + i, | |||
| 578 | StrToWxStr(Perspectives[i].Name), | |||
| 579 | wxT("")L"", wxITEM_CHECK); | |||
| 580 | ||||
| 581 | menuPopup->Append(mItem); | |||
| 582 | ||||
| 583 | if (i == ActivePerspective) | |||
| 584 | { | |||
| 585 | mItem->Check(true); | |||
| 586 | } | |||
| 587 | } | |||
| 588 | } | |||
| 589 | ||||
| 590 | // line up our menu with the button | |||
| 591 | wxRect rect = tb->GetToolRect(event.GetId()); | |||
| 592 | wxPoint pt = tb->ClientToScreen(rect.GetBottomLeft()); | |||
| 593 | pt = ScreenToClient(pt); | |||
| 594 | ||||
| 595 | // show | |||
| 596 | PopupMenu(menuPopup, pt); | |||
| 597 | ||||
| 598 | // make sure the button is "un-stuck" | |||
| 599 | tb->SetToolSticky(event.GetId(), false); | |||
| 600 | } | |||
| 601 | } | |||
| 602 | ||||
| 603 | void CFrame::OnToolBar(wxCommandEvent& event) | |||
| 604 | { | |||
| 605 | ClearStatusBar(); | |||
| 606 | ||||
| 607 | switch (event.GetId()) | |||
| 608 | { | |||
| 609 | case IDM_SAVE_PERSPECTIVE: | |||
| 610 | if (Perspectives.size() == 0) | |||
| 611 | { | |||
| 612 | wxMessageBox(_("Please create a perspective before saving")wxGetTranslation(("Please create a perspective before saving" )), | |||
| 613 | _("Notice")wxGetTranslation(("Notice")), wxOK0x00000004, this); | |||
| 614 | return; | |||
| 615 | } | |||
| 616 | SaveIniPerspectives(); | |||
| 617 | GetStatusBar()->SetStatusText(StrToWxStr(std::string | |||
| 618 | ("Saved " + Perspectives[ActivePerspective].Name).c_str()), 0); | |||
| 619 | break; | |||
| 620 | case IDM_PERSPECTIVES_ADD_PANE: | |||
| 621 | AddPane(); | |||
| 622 | break; | |||
| 623 | case IDM_EDIT_PERSPECTIVES: | |||
| 624 | m_bEdit = !m_bEdit; | |||
| 625 | m_ToolBarAui->SetToolSticky(IDM_EDIT_PERSPECTIVES, m_bEdit); | |||
| 626 | TogglePaneStyle(m_bEdit, IDM_EDIT_PERSPECTIVES); | |||
| 627 | break; | |||
| 628 | } | |||
| 629 | } | |||
| 630 | ||||
| 631 | void CFrame::OnDropDownToolbarSelect(wxCommandEvent& event) | |||
| 632 | { | |||
| 633 | ClearStatusBar(); | |||
| 634 | ||||
| 635 | switch(event.GetId()) | |||
| 636 | { | |||
| 637 | case IDM_ADD_PERSPECTIVE: | |||
| 638 | { | |||
| 639 | wxTextEntryDialog dlg(this, | |||
| 640 | _("Enter a name for the new perspective:")wxGetTranslation(("Enter a name for the new perspective:")), | |||
| 641 | _("Create new perspective")wxGetTranslation(("Create new perspective"))); | |||
| 642 | wxString DefaultValue = wxString::Format(_("Perspective %d")wxGetTranslation(("Perspective %d")), | |||
| 643 | Perspectives.size() + 1); | |||
| 644 | dlg.SetValue(DefaultValue); | |||
| 645 | ||||
| 646 | int Return = 0; | |||
| 647 | bool DlgOk = false; | |||
| 648 | ||||
| 649 | while (!DlgOk) | |||
| 650 | { | |||
| 651 | Return = dlg.ShowModal(); | |||
| 652 | if (Return == wxID_CANCEL) | |||
| 653 | { | |||
| 654 | return; | |||
| 655 | } | |||
| 656 | else if (dlg.GetValue().Find(wxT(",")L",") != -1) | |||
| 657 | { | |||
| 658 | wxMessageBox(_("The name can not contain the character ','")wxGetTranslation(("The name can not contain the character ','" )), | |||
| 659 | _("Notice")wxGetTranslation(("Notice")), wxOK0x00000004, this); | |||
| 660 | wxString Str = dlg.GetValue(); | |||
| 661 | Str.Replace(wxT(",")L",", wxT("")L"", true); | |||
| 662 | dlg.SetValue(Str); | |||
| 663 | } | |||
| 664 | else if (dlg.GetValue().IsSameAs(wxT("")L"")) | |||
| 665 | { | |||
| 666 | wxMessageBox(_("The name can not be empty")wxGetTranslation(("The name can not be empty")), | |||
| 667 | _("Notice")wxGetTranslation(("Notice")), wxOK0x00000004, this); | |||
| 668 | dlg.SetValue(DefaultValue); | |||
| 669 | } | |||
| 670 | else | |||
| 671 | { | |||
| 672 | DlgOk = true; | |||
| 673 | } | |||
| 674 | } | |||
| 675 | ||||
| 676 | SPerspectives Tmp; | |||
| 677 | Tmp.Name = WxStrToStr(dlg.GetValue()); | |||
| 678 | Tmp.Perspective = m_Mgr->SavePerspective(); | |||
| 679 | ||||
| 680 | ActivePerspective = (u32)Perspectives.size(); | |||
| 681 | Perspectives.push_back(Tmp); | |||
| 682 | ||||
| 683 | UpdateCurrentPerspective(); | |||
| 684 | } | |||
| 685 | break; | |||
| 686 | case IDM_TAB_SPLIT: | |||
| 687 | m_bTabSplit = event.IsChecked(); | |||
| 688 | ToggleNotebookStyle(m_bTabSplit, wxAUI_NB_TAB_SPLIT); | |||
| 689 | break; | |||
| 690 | case IDM_NO_DOCKING: | |||
| 691 | m_bNoDocking = event.IsChecked(); | |||
| 692 | TogglePaneStyle(m_bNoDocking, IDM_NO_DOCKING); | |||
| 693 | break; | |||
| 694 | } | |||
| 695 | } | |||
| 696 | ||||
| 697 | void CFrame::ResetToolbarStyle() | |||
| 698 | { | |||
| 699 | wxAuiPaneInfoArray& AllPanes = m_Mgr->GetAllPanes(); | |||
| 700 | for (int i = 0, Count = (int)AllPanes.GetCount(); i < Count; ++i) | |||
| 701 | { | |||
| 702 | wxAuiPaneInfo& Pane = AllPanes[i]; | |||
| 703 | if (Pane.window->IsKindOf(CLASSINFO(wxAuiToolBar)(&wxAuiToolBar::ms_classInfo))) | |||
| 704 | { | |||
| 705 | Pane.Show(); | |||
| 706 | ||||
| 707 | // Show all of it | |||
| 708 | if (Pane.rect.GetLeft() > GetClientSize().GetX() - 50) | |||
| 709 | { | |||
| 710 | Pane.Position(GetClientSize().GetX() - Pane.window->GetClientSize().GetX()); | |||
| 711 | } | |||
| 712 | } | |||
| 713 | } | |||
| 714 | m_Mgr->Update(); | |||
| 715 | } | |||
| 716 | ||||
| 717 | void CFrame::TogglePaneStyle(bool On, int EventId) | |||
| 718 | { | |||
| 719 | wxAuiPaneInfoArray& AllPanes = m_Mgr->GetAllPanes(); | |||
| 720 | for (u32 i = 0; i < AllPanes.GetCount(); ++i) | |||
| 721 | { | |||
| 722 | wxAuiPaneInfo& Pane = AllPanes[i]; | |||
| 723 | if (Pane.window->IsKindOf(CLASSINFO(wxAuiNotebook)(&wxAuiNotebook::ms_classInfo))) | |||
| 724 | { | |||
| 725 | // Default | |||
| 726 | Pane.CloseButton(true); | |||
| 727 | Pane.MaximizeButton(true); | |||
| 728 | Pane.MinimizeButton(true); | |||
| 729 | Pane.PinButton(true); | |||
| 730 | Pane.Show(); | |||
| 731 | ||||
| 732 | switch(EventId) | |||
| 733 | { | |||
| 734 | case IDM_EDIT_PERSPECTIVES: | |||
| 735 | Pane.CaptionVisible(On); | |||
| 736 | Pane.Movable(On); | |||
| 737 | Pane.Floatable(On); | |||
| 738 | Pane.Dockable(On); | |||
| 739 | break; | |||
| 740 | } | |||
| 741 | Pane.Dockable(!m_bNoDocking); | |||
| 742 | } | |||
| 743 | } | |||
| 744 | m_Mgr->Update(); | |||
| 745 | } | |||
| 746 | ||||
| 747 | void CFrame::ToggleNotebookStyle(bool On, long Style) | |||
| 748 | { | |||
| 749 | wxAuiPaneInfoArray& AllPanes = m_Mgr->GetAllPanes(); | |||
| 750 | for (int i = 0, Count = (int)AllPanes.GetCount(); i < Count; ++i) | |||
| 751 | { | |||
| 752 | wxAuiPaneInfo& Pane = AllPanes[i]; | |||
| 753 | if (Pane.window->IsKindOf(CLASSINFO(wxAuiNotebook)(&wxAuiNotebook::ms_classInfo))) | |||
| 754 | { | |||
| 755 | wxAuiNotebook* NB = (wxAuiNotebook*)Pane.window; | |||
| 756 | ||||
| 757 | if (On) | |||
| 758 | NB->SetWindowStyleFlag(NB->GetWindowStyleFlag() | Style); | |||
| 759 | else | |||
| 760 | NB->SetWindowStyleFlag(NB->GetWindowStyleFlag() &~ Style); | |||
| 761 | ||||
| 762 | NB->Refresh(); | |||
| 763 | } | |||
| 764 | } | |||
| 765 | } | |||
| 766 | ||||
| 767 | void CFrame::OnSelectPerspective(wxCommandEvent& event) | |||
| 768 | { | |||
| 769 | u32 _Selection = event.GetId() - IDM_PERSPECTIVES_0; | |||
| 770 | if (Perspectives.size() <= _Selection) _Selection = 0; | |||
| 771 | ActivePerspective = _Selection; | |||
| 772 | DoLoadPerspective(); | |||
| 773 | } | |||
| 774 | ||||
| 775 | void CFrame::ResizeConsole() | |||
| 776 | { | |||
| 777 | #ifdef _WIN32 | |||
| 778 | // Get the console parent window | |||
| 779 | wxWindow * Win = FindWindowById(IDM_CONSOLEWINDOW); | |||
| 780 | if (!Win) return; | |||
| 781 | ||||
| 782 | const int wxBorder = 2, Border = 4, | |||
| 783 | MenuBar = 30, ScrollBar = 19; | |||
| 784 | ||||
| 785 | // Get the client size | |||
| 786 | int X = Win->GetSize().GetX(); | |||
| 787 | int Y = Win->GetSize().GetY(); | |||
| 788 | int InternalWidth = X - wxBorder*2 - ScrollBar; | |||
| 789 | int InternalHeight = Y - wxBorder*2; | |||
| 790 | int WindowWidth = InternalWidth + Border*2 + | |||
| 791 | /*max out the width in the word wrap mode*/ 100; | |||
| 792 | int WindowHeight = InternalHeight + MenuBar; | |||
| 793 | // Resize buffer | |||
| 794 | ConsoleListener* Console = LogManager::GetInstance()->GetConsoleListener(); | |||
| 795 | Console->PixelSpace(0,0, InternalWidth, InternalHeight, false); | |||
| 796 | // Move the window to hide the border | |||
| 797 | MoveWindow(GetConsoleWindow(), -Border-wxBorder, -MenuBar-wxBorder, | |||
| 798 | WindowWidth + 100, WindowHeight, true); | |||
| 799 | #endif | |||
| 800 | } | |||
| 801 | ||||
| 802 | static int Limit(int i, int Low, int High) | |||
| 803 | { | |||
| 804 | if (i < Low) return Low; | |||
| 805 | if (i > High) return High; | |||
| 806 | return i; | |||
| 807 | } | |||
| 808 | ||||
| 809 | void CFrame::SetPaneSize() | |||
| 810 | { | |||
| 811 | if (Perspectives.size() <= ActivePerspective) | |||
| 812 | return; | |||
| 813 | ||||
| 814 | int iClientX = GetSize().GetX(); | |||
| 815 | int iClientY = GetSize().GetY(); | |||
| 816 | ||||
| 817 | for (u32 i = 0, j = 0; i < m_Mgr->GetAllPanes().GetCount(); i++) | |||
| 818 | { | |||
| 819 | if (!m_Mgr->GetAllPanes()[i].window->IsKindOf(CLASSINFO(wxAuiToolBar)(&wxAuiToolBar::ms_classInfo))) | |||
| 820 | { | |||
| 821 | if (!m_Mgr->GetAllPanes()[i].IsOk()) | |||
| 822 | return; | |||
| 823 | ||||
| 824 | if (Perspectives[ActivePerspective].Width.size() <= j || | |||
| 825 | Perspectives[ActivePerspective].Height.size() <= j) | |||
| 826 | continue; | |||
| 827 | ||||
| 828 | // Width and height of the active perspective | |||
| 829 | u32 W = Perspectives[ActivePerspective].Width[j], | |||
| 830 | H = Perspectives[ActivePerspective].Height[j]; | |||
| 831 | ||||
| 832 | // Check limits | |||
| 833 | W = Limit(W, 5, 95); | |||
| 834 | H = Limit(H, 5, 95); | |||
| 835 | ||||
| 836 | // Convert percentages to pixel lengths | |||
| 837 | W = (W * iClientX) / 100; | |||
| 838 | H = (H * iClientY) / 100; | |||
| 839 | m_Mgr->GetAllPanes()[i].BestSize(W,H).MinSize(W,H); | |||
| 840 | ||||
| 841 | j++; | |||
| 842 | } | |||
| 843 | } | |||
| 844 | m_Mgr->Update(); | |||
| 845 | ||||
| 846 | for (u32 i = 0; i < m_Mgr->GetAllPanes().GetCount(); i++) | |||
| 847 | { | |||
| 848 | if (!m_Mgr->GetAllPanes()[i].window->IsKindOf(CLASSINFO(wxAuiToolBar)(&wxAuiToolBar::ms_classInfo))) | |||
| 849 | { | |||
| 850 | m_Mgr->GetAllPanes()[i].MinSize(-1,-1); | |||
| 851 | } | |||
| 852 | } | |||
| 853 | } | |||
| 854 | ||||
| 855 | void CFrame::ReloadPanes() | |||
| 856 | { | |||
| 857 | // Close all pages | |||
| 858 | ClosePages(); | |||
| 859 | ||||
| 860 | CloseAllNotebooks(); | |||
| 861 | ||||
| 862 | // Create new panes with notebooks | |||
| 863 | for (u32 i = 0; i < Perspectives[ActivePerspective].Width.size() - 1; i++) | |||
| 864 | { | |||
| 865 | wxString PaneName = wxString::Format(_T("Pane %i")L"Pane %i", i + 1); | |||
| 866 | m_Mgr->AddPane(CreateEmptyNotebook(), wxAuiPaneInfo().Hide() | |||
| 867 | .CaptionVisible(m_bEdit).Dockable(!m_bNoDocking).Position(i) | |||
| 868 | .Name(PaneName).Caption(PaneName)); | |||
| 869 | } | |||
| 870 | ||||
| 871 | // Perspectives | |||
| 872 | m_Mgr->LoadPerspective(Perspectives[ActivePerspective].Perspective, false); | |||
| 873 | // Reset toolbars | |||
| 874 | ResetToolbarStyle(); | |||
| 875 | // Restore settings | |||
| 876 | TogglePaneStyle(m_bNoDocking, IDM_NO_DOCKING); | |||
| 877 | TogglePaneStyle(m_bEdit, IDM_EDIT_PERSPECTIVES); | |||
| 878 | ||||
| 879 | // Load GUI settings | |||
| 880 | g_pCodeWindow->Load(); | |||
| 881 | // Open notebook pages | |||
| 882 | AddRemoveBlankPage(); | |||
| 883 | g_pCodeWindow->OpenPages(); | |||
| 884 | } | |||
| 885 | ||||
| 886 | void CFrame::DoLoadPerspective() | |||
| 887 | { | |||
| 888 | ReloadPanes(); | |||
| 889 | // Restore the exact window sizes, which LoadPerspective doesn't always do | |||
| 890 | SetPaneSize(); | |||
| 891 | ||||
| 892 | m_Mgr->Update(); | |||
| 893 | } | |||
| 894 | ||||
| 895 | // Update the local perspectives array | |||
| 896 | void CFrame::LoadIniPerspectives() | |||
| 897 | { | |||
| 898 | Perspectives.clear(); | |||
| 899 | std::vector<std::string> VPerspectives; | |||
| 900 | std::string _Perspectives; | |||
| 901 | ||||
| 902 | IniFile ini; | |||
| 903 | ini.Load(File::GetUserPath(F_DEBUGGERCONFIG_IDX)); | |||
| 904 | ini.Get("Perspectives", "Perspectives", &_Perspectives, "Perspective 1"); | |||
| 905 | ini.Get("Perspectives", "Active", &ActivePerspective, 0); | |||
| 906 | SplitString(_Perspectives, ',', VPerspectives); | |||
| 907 | ||||
| 908 | for (u32 i = 0; i < VPerspectives.size(); i++) | |||
| 909 | { | |||
| 910 | SPerspectives Tmp; | |||
| 911 | std::string _Section, _Perspective, _Width, _Height; | |||
| 912 | std::vector<std::string> _SWidth, _SHeight; | |||
| 913 | Tmp.Name = VPerspectives[i]; | |||
| 914 | ||||
| 915 | // Don't save a blank perspective | |||
| 916 | if (Tmp.Name.empty()) | |||
| 917 | continue; | |||
| 918 | ||||
| 919 | _Section = StringFromFormat("P - %s", Tmp.Name.c_str()); | |||
| 920 | ini.Get(_Section.c_str(), "Perspective", &_Perspective, | |||
| 921 | "layout2|" | |||
| 922 | "name=Pane 0;caption=Pane 0;state=768;dir=5;prop=100000;|" | |||
| 923 | "name=Pane 1;caption=Pane 1;state=31458108;dir=4;prop=100000;|" | |||
| 924 | "dock_size(5,0,0)=22|dock_size(4,0,0)=333|"); | |||
| 925 | ini.Get(_Section.c_str(), "Width", &_Width, "70,25"); | |||
| 926 | ini.Get(_Section.c_str(), "Height", &_Height, "80,80"); | |||
| 927 | ||||
| 928 | Tmp.Perspective = StrToWxStr(_Perspective); | |||
| 929 | ||||
| 930 | SplitString(_Width, ',', _SWidth); | |||
| 931 | SplitString(_Height, ',', _SHeight); | |||
| 932 | for (u32 j = 0; j < _SWidth.size(); j++) | |||
| 933 | { | |||
| 934 | int _Tmp; | |||
| 935 | if (TryParse(_SWidth[j].c_str(), &_Tmp)) Tmp.Width.push_back(_Tmp); | |||
| 936 | } | |||
| 937 | for (u32 j = 0; j < _SHeight.size(); j++) | |||
| 938 | { | |||
| 939 | int _Tmp; | |||
| 940 | if (TryParse(_SHeight[j].c_str(), &_Tmp)) Tmp.Height.push_back(_Tmp); | |||
| 941 | } | |||
| 942 | Perspectives.push_back(Tmp); | |||
| 943 | } | |||
| 944 | } | |||
| 945 | ||||
| 946 | void CFrame::UpdateCurrentPerspective() | |||
| 947 | { | |||
| 948 | SPerspectives *current = &Perspectives[ActivePerspective]; | |||
| 949 | current->Perspective = m_Mgr->SavePerspective(); | |||
| 950 | ||||
| 951 | // Get client size | |||
| 952 | int iClientX = GetSize().GetX(), iClientY = GetSize().GetY(); | |||
| 953 | current->Width.clear(); | |||
| 954 | current->Height.clear(); | |||
| 955 | for (u32 i = 0; i < m_Mgr->GetAllPanes().GetCount(); i++) | |||
| 956 | { | |||
| 957 | if (!m_Mgr->GetAllPanes()[i].window-> | |||
| 958 | IsKindOf(CLASSINFO(wxAuiToolBar)(&wxAuiToolBar::ms_classInfo))) | |||
| 959 | { | |||
| 960 | // Save width and height as a percentage of the client width and height | |||
| 961 | current->Width.push_back( | |||
| 962 | (m_Mgr->GetAllPanes()[i].window->GetClientSize().GetX() * 100) / | |||
| 963 | iClientX); | |||
| 964 | current->Height.push_back( | |||
| 965 | (m_Mgr->GetAllPanes()[i].window->GetClientSize().GetY() * 100) / | |||
| 966 | iClientY); | |||
| 967 | } | |||
| 968 | } | |||
| 969 | } | |||
| 970 | ||||
| 971 | void CFrame::SaveIniPerspectives() | |||
| 972 | { | |||
| 973 | if (Perspectives.size() == 0) return; | |||
| 974 | if (ActivePerspective >= Perspectives.size()) ActivePerspective = 0; | |||
| 975 | ||||
| 976 | // Turn off edit before saving | |||
| 977 | TogglePaneStyle(false, IDM_EDIT_PERSPECTIVES); | |||
| 978 | ||||
| 979 | UpdateCurrentPerspective(); | |||
| 980 | ||||
| 981 | IniFile ini; | |||
| 982 | ini.Load(File::GetUserPath(F_DEBUGGERCONFIG_IDX)); | |||
| 983 | ||||
| 984 | // Save perspective names | |||
| 985 | std::string STmp = ""; | |||
| 986 | for (u32 i = 0; i < Perspectives.size(); i++) | |||
| 987 | { | |||
| 988 | STmp += Perspectives[i].Name + ","; | |||
| 989 | } | |||
| 990 | STmp = STmp.substr(0, STmp.length()-1); | |||
| 991 | ini.Set("Perspectives", "Perspectives", STmp.c_str()); | |||
| 992 | ini.Set("Perspectives", "Active", ActivePerspective); | |||
| 993 | ||||
| 994 | // Save the perspectives | |||
| 995 | for (u32 i = 0; i < Perspectives.size(); i++) | |||
| 996 | { | |||
| 997 | std::string _Section = "P - " + Perspectives[i].Name; | |||
| 998 | ini.Set(_Section.c_str(), "Perspective", WxStrToStr(Perspectives[i].Perspective)); | |||
| 999 | ||||
| 1000 | std::string SWidth = "", SHeight = ""; | |||
| 1001 | for (u32 j = 0; j < Perspectives[i].Width.size(); j++) | |||
| 1002 | { | |||
| 1003 | SWidth += StringFromFormat("%i,", Perspectives[i].Width[j]); | |||
| 1004 | SHeight += StringFromFormat("%i,", Perspectives[i].Height[j]); | |||
| 1005 | } | |||
| 1006 | // Remove the ending "," | |||
| 1007 | SWidth = SWidth.substr(0, SWidth.length()-1); | |||
| 1008 | SHeight = SHeight.substr(0, SHeight.length()-1); | |||
| 1009 | ||||
| 1010 | ini.Set(_Section.c_str(), "Width", SWidth.c_str()); | |||
| 1011 | ini.Set(_Section.c_str(), "Height", SHeight.c_str()); | |||
| 1012 | } | |||
| 1013 | ||||
| 1014 | ini.Save(File::GetUserPath(F_DEBUGGERCONFIG_IDX)); | |||
| 1015 | ||||
| 1016 | // Save notebook affiliations | |||
| 1017 | g_pCodeWindow->Save(); | |||
| 1018 | ||||
| 1019 | TogglePaneStyle(m_bEdit, IDM_EDIT_PERSPECTIVES); | |||
| 1020 | } | |||
| 1021 | ||||
| 1022 | void CFrame::AddPane() | |||
| 1023 | { | |||
| 1024 | int PaneNum = GetNotebookCount() + 1; | |||
| 1025 | wxString PaneName = wxString::Format(_T("Pane %i")L"Pane %i", PaneNum); | |||
| 1026 | m_Mgr->AddPane(CreateEmptyNotebook(), wxAuiPaneInfo() | |||
| 1027 | .CaptionVisible(m_bEdit).Dockable(!m_bNoDocking) | |||
| 1028 | .Name(PaneName).Caption(PaneName) | |||
| 1029 | .Position(GetNotebookCount())); | |||
| 1030 | ||||
| 1031 | AddRemoveBlankPage(); | |||
| 1032 | m_Mgr->Update(); | |||
| 1033 | } | |||
| 1034 | ||||
| 1035 | wxWindow * CFrame::GetNotebookPageFromId(wxWindowID Id) | |||
| 1036 | { | |||
| 1037 | for (u32 i = 0; i < m_Mgr->GetAllPanes().GetCount(); i++) | |||
| 1038 | { | |||
| 1039 | if (!m_Mgr->GetAllPanes()[i].window->IsKindOf(CLASSINFO(wxAuiNotebook)(&wxAuiNotebook::ms_classInfo))) | |||
| 1040 | continue; | |||
| 1041 | ||||
| 1042 | wxAuiNotebook * NB = (wxAuiNotebook*)m_Mgr->GetAllPanes()[i].window; | |||
| 1043 | for(u32 j = 0; j < NB->GetPageCount(); j++) | |||
| 1044 | { | |||
| 1045 | if (NB->GetPage(j)->GetId() == Id) | |||
| 1046 | return NB->GetPage(j); | |||
| 1047 | } | |||
| 1048 | } | |||
| 1049 | return NULL__null; | |||
| 1050 | } | |||
| 1051 | ||||
| 1052 | wxFrame * CFrame::CreateParentFrame(wxWindowID Id, const wxString& Title, | |||
| 1053 | wxWindow * Child) | |||
| 1054 | { | |||
| 1055 | wxFrame * Frame = new wxFrame(this, Id, Title, | |||
| 1056 | wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_STYLE(0x0800 | 0x0040 | 0x0400 | 0x0200 | 0x1000 | 0x20000000 | 0x00400000 )); | |||
| 1057 | ||||
| 1058 | Child->Reparent(Frame); | |||
| 1059 | ||||
| 1060 | wxBoxSizer * m_MainSizer = new wxBoxSizer(wxHORIZONTAL); | |||
| 1061 | ||||
| 1062 | m_MainSizer->Add(Child, 1, wxEXPAND); | |||
| 1063 | ||||
| 1064 | Frame->Bind(wxEVT_CLOSE_WINDOW, &CFrame::OnFloatingPageClosed, this); | |||
| 1065 | ||||
| 1066 | if (Id == IDM_CONSOLEWINDOW_PARENT) | |||
| 1067 | { | |||
| 1068 | Frame->Bind(wxEVT_SIZE, &CFrame::OnFloatingPageSize, this); | |||
| 1069 | } | |||
| 1070 | ||||
| 1071 | // Main sizer | |||
| 1072 | Frame->SetSizer(m_MainSizer); | |||
| 1073 | // Minimum frame size | |||
| 1074 | Frame->SetMinSize(wxSize(200, 200)); | |||
| 1075 | Frame->Show(); | |||
| 1076 | return Frame; | |||
| 1077 | } | |||
| 1078 | ||||
| 1079 | wxAuiNotebook* CFrame::CreateEmptyNotebook() | |||
| 1080 | { | |||
| 1081 | const long NOTEBOOK_STYLE = wxAUI_NB_TOP | wxAUI_NB_TAB_SPLIT | | |||
| 1082 | wxAUI_NB_TAB_EXTERNAL_MOVE | wxAUI_NB_SCROLL_BUTTONS | | |||
| 1083 | wxAUI_NB_WINDOWLIST_BUTTON | wxNO_BORDERwxBORDER_NONE; | |||
| 1084 | wxAuiNotebook* NB = new wxAuiNotebook(this, wxID_ANY, | |||
| 1085 | wxDefaultPosition, wxDefaultSize, NOTEBOOK_STYLE); | |||
| 1086 | return NB; | |||
| 1087 | } | |||
| 1088 | ||||
| 1089 | void CFrame::AddRemoveBlankPage() | |||
| 1090 | { | |||
| 1091 | for (u32 i = 0; i < m_Mgr->GetAllPanes().GetCount(); i++) | |||
| 1092 | { | |||
| 1093 | if (!m_Mgr->GetAllPanes()[i].window->IsKindOf(CLASSINFO(wxAuiNotebook)(&wxAuiNotebook::ms_classInfo))) | |||
| 1094 | continue; | |||
| 1095 | ||||
| 1096 | wxAuiNotebook * NB = (wxAuiNotebook*)m_Mgr->GetAllPanes()[i].window; | |||
| 1097 | for(u32 j = 0; j < NB->GetPageCount(); j++) | |||
| 1098 | { | |||
| 1099 | if (NB->GetPageText(j).IsSameAs(wxT("<>")L"<>") && NB->GetPageCount() > 1) | |||
| 1100 | NB->DeletePage(j); | |||
| 1101 | } | |||
| 1102 | ||||
| 1103 | if (NB->GetPageCount() == 0) | |||
| 1104 | NB->AddPage(new wxPanel(this, wxID_ANY), wxT("<>")L"<>", true); | |||
| 1105 | } | |||
| 1106 | } | |||
| 1107 | ||||
| 1108 | int CFrame::GetNotebookAffiliation(wxWindowID Id) | |||
| 1109 | { | |||
| 1110 | for (u32 i = 0, j = 0; i < m_Mgr->GetAllPanes().GetCount(); i++) | |||
| 1111 | { | |||
| 1112 | if (!m_Mgr->GetAllPanes()[i].window->IsKindOf(CLASSINFO(wxAuiNotebook)(&wxAuiNotebook::ms_classInfo))) | |||
| 1113 | continue; | |||
| 1114 | ||||
| 1115 | wxAuiNotebook * NB = (wxAuiNotebook*)m_Mgr->GetAllPanes()[i].window; | |||
| 1116 | for(u32 k = 0; k < NB->GetPageCount(); k++) | |||
| 1117 | { | |||
| 1118 | if (NB->GetPage(k)->GetId() == Id) | |||
| 1119 | return j; | |||
| 1120 | } | |||
| 1121 | j++; | |||
| 1122 | } | |||
| 1123 | return -1; | |||
| 1124 | } | |||
| 1125 | ||||
| 1126 | // Close all panes with notebooks | |||
| 1127 | void CFrame::CloseAllNotebooks() | |||
| 1128 | { | |||
| 1129 | wxAuiPaneInfoArray AllPanes = m_Mgr->GetAllPanes(); | |||
| 1130 | for (u32 i = 0; i < AllPanes.GetCount(); i++) | |||
| 1131 | { | |||
| 1132 | if (AllPanes[i].window->IsKindOf(CLASSINFO(wxAuiNotebook)(&wxAuiNotebook::ms_classInfo))) | |||
| 1133 | { | |||
| 1134 | AllPanes[i].DestroyOnClose(true); | |||
| 1135 | m_Mgr->ClosePane(AllPanes[i]); | |||
| 1136 | } | |||
| 1137 | } | |||
| 1138 | } | |||
| 1139 | ||||
| 1140 | int CFrame::GetNotebookCount() | |||
| 1141 | { | |||
| 1142 | int Ret = 0; | |||
| 1143 | for (u32 i = 0; i < m_Mgr->GetAllPanes().GetCount(); i++) | |||
| 1144 | { | |||
| 1145 | if (m_Mgr->GetAllPanes()[i].window->IsKindOf(CLASSINFO(wxAuiNotebook)(&wxAuiNotebook::ms_classInfo))) | |||
| 1146 | Ret++; | |||
| 1147 | } | |||
| 1148 | return Ret; | |||
| 1149 | } | |||
| 1150 | ||||
| 1151 | wxAuiNotebook * CFrame::GetNotebookFromId(u32 NBId) | |||
| 1152 | { | |||
| 1153 | for (u32 i = 0, j = 0; i < m_Mgr->GetAllPanes().GetCount(); i++) | |||
| 1154 | { | |||
| 1155 | if (!m_Mgr->GetAllPanes()[i].window->IsKindOf(CLASSINFO(wxAuiNotebook)(&wxAuiNotebook::ms_classInfo))) | |||
| 1156 | continue; | |||
| 1157 | if (j == NBId) | |||
| 1158 | return (wxAuiNotebook*)m_Mgr->GetAllPanes()[i].window; | |||
| 1159 | j++; | |||
| 1160 | } | |||
| 1161 | return NULL__null; | |||
| 1162 | } |