Removed main configuration show/hide mouse options and associated wxTimer in
[dolphin.git] / Source / Core / DolphinWX / Src / Frame.cpp
blob76b2aa1c92f45ff99f414dce322d8c002e36ad84
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/
19 // CFrame is the main parent window. Inside CFrame there is an m_Panel that is the parent for
20 // the rendering window (when we render to the main window). In Windows the rendering window is
21 // created by giving CreateWindow() m_Panel->GetHandle() as parent window and creating a new
22 // child window to m_Panel. The new child window handle that is returned by CreateWindow() can
23 // be accessed from Core::GetWindowHandle().
25 // ----------
26 // Includes
28 #include "Common.h" // Common
29 #include "FileUtil.h"
30 #include "Timer.h"
31 #include "Setup.h"
33 #include "Globals.h" // Local
34 #include "Frame.h"
35 #include "ConfigMain.h"
36 #include "PluginManager.h"
37 #include "MemcardManager.h"
38 #include "CheatsWindow.h"
39 #include "AboutDolphin.h"
40 #include "GameListCtrl.h"
41 #include "BootManager.h"
42 #include "ConsoleListener.h"
44 #include "ConfigManager.h" // Core
45 #include "Core.h"
46 #include "HW/DVDInterface.h"
47 #include "IPC_HLE/WII_IPC_HLE_Device_usb.h"
48 #include "State.h"
49 #include "VolumeHandler.h"
51 #include <wx/datetime.h> // wxWidgets
53 // Resources
55 extern "C" {
56 #include "../resources/Dolphin.c" // Dolphin icon
57 #include "../resources/toolbar_browse.c"
58 #include "../resources/toolbar_file_open.c"
59 #include "../resources/toolbar_fullscreen.c"
60 #include "../resources/toolbar_help.c"
61 #include "../resources/toolbar_pause.c"
62 #include "../resources/toolbar_play.c"
63 #include "../resources/toolbar_plugin_dsp.c"
64 #include "../resources/toolbar_plugin_gfx.c"
65 #include "../resources/toolbar_plugin_options.c"
66 #include "../resources/toolbar_plugin_pad.c"
67 #include "../resources/toolbar_refresh.c"
68 #include "../resources/toolbar_stop.c"
69 #include "../resources/Boomy.h" // Theme packages
70 #include "../resources/Vista.h"
71 #include "../resources/X-Plastik.h"
72 #include "../resources/KDE.h"
76 // Windows functions. Setting the cursor with wxSetCursor() did not work in
77 // this instance. Probably because it's somehow reset from the WndProc() in
78 // the child window
79 #ifdef _WIN32
80 // Declare a blank icon and one that will be the normal cursor
81 HCURSOR hCursor = NULL, hCursorBlank = NULL;
83 // Create the default cursor
84 void CreateCursor()
86 hCursor = LoadCursor( NULL, IDC_ARROW );
89 void MSWSetCursor(bool Show)
91 if(Show)
92 SetCursor(hCursor);
93 else
95 SetCursor(hCursorBlank);
96 //wxSetCursor(wxCursor(wxNullCursor));
100 // I could not use FindItemByHWND() instead of this, it crashed on that occation I used it */
101 HWND MSWGetParent_(HWND Parent)
103 return GetParent(Parent);
105 #endif
107 // ---------------
108 // The CPanel class to receive MSWWindowProc messages from the video plugin.
110 extern CFrame* main_frame;
112 class CPanel : public wxPanel
114 public:
115 CPanel(
116 wxWindow* parent,
117 wxWindowID id = wxID_ANY
120 private:
121 DECLARE_EVENT_TABLE();
123 #ifdef _WIN32
124 // Receive WndProc messages
125 WXLRESULT MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam);
126 #endif
129 BEGIN_EVENT_TABLE(CPanel, wxPanel)
130 END_EVENT_TABLE()
132 CPanel::CPanel(
133 wxWindow *parent,
134 wxWindowID id
136 : wxPanel(parent, id)
140 #ifdef _WIN32
141 WXLRESULT CPanel::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam)
143 switch (nMsg)
145 case WM_USER:
146 switch(wParam)
148 // Stop
149 case WM_USER_STOP:
150 main_frame->DoStop();
151 return 0;
153 case WM_USER_CREATE:
154 // We don't have a local setting for bRenderToMain but we can detect it this way instead
155 //PanicAlert("main call %i %i %i %i", lParam, (HWND)Core::GetWindowHandle(), MSWGetParent_((HWND)Core::GetWindowHandle()), (HWND)this->GetHWND());
156 if (lParam == NULL)
157 main_frame->bRenderToMain = false;
158 else
159 main_frame->bRenderToMain = true;
160 return 0;
162 case WIIMOTE_DISCONNECT:
163 if (SConfig::GetInstance().m_LocalCoreStartupParameter.bWii)
165 if (main_frame->bNoWiimoteMsg)
166 main_frame->bNoWiimoteMsg = false;
167 else
169 // The Wiimote has been disconnect, we offer reconnect here
170 wxMessageDialog *dlg = new wxMessageDialog(
171 this,
172 wxString::Format(wxT("Wiimote %i has been disconnected by system.\n")
173 wxT("Maybe this game doesn't support multi-wiimote,\n")
174 wxT("or maybe it is due to idle time out or other reason.\n\n")
175 wxT("Do you want to reconnect immediately?"), lParam + 1),
176 wxT("Reconnect Wiimote Confirm"),
177 wxYES_NO | wxSTAY_ON_TOP | wxICON_INFORMATION, //wxICON_QUESTION,
178 wxDefaultPosition);
180 if (dlg->ShowModal() == wxID_YES)
181 GetUsbPointer()->AccessWiiMote(lParam | 0x100)->Activate(true);
183 dlg->Destroy();
186 return 0;
188 break;
191 // By default let wxWidgets do what it normally does with this event
192 return wxPanel::MSWWindowProc(nMsg, wParam, lParam);
194 #endif
196 // event tables
197 // Notice that wxID_HELP will be processed for the 'About' menu and the toolbar
198 // help button.
200 const wxEventType wxEVT_HOST_COMMAND = wxNewEventType();
202 BEGIN_EVENT_TABLE(CFrame, wxFrame)
204 // Menu bar
205 EVT_MENU(wxID_OPEN, CFrame::OnOpen)
206 EVT_MENU(wxID_EXIT, CFrame::OnQuit)
207 EVT_MENU(IDM_HELPWEBSITE, CFrame::OnHelp)
208 EVT_MENU(IDM_HELPGOOGLECODE, CFrame::OnHelp)
209 EVT_MENU(IDM_HELPABOUT, CFrame::OnHelp)
210 EVT_MENU(wxID_REFRESH, CFrame::OnRefresh)
211 EVT_MENU(IDM_PLAY, CFrame::OnPlay)
212 EVT_MENU(IDM_STOP, CFrame::OnStop)
213 EVT_MENU(IDM_RESET, CFrame::OnReset)
214 EVT_MENU(IDM_RECORD, CFrame::OnRecord)
215 EVT_MENU(IDM_PLAYRECORD, CFrame::OnPlayRecording)
216 EVT_MENU(IDM_FRAMESTEP, CFrame::OnFrameStep)
217 EVT_MENU(IDM_LUA, CFrame::OnOpenLuaWindow)
218 EVT_MENU(IDM_SCREENSHOT, CFrame::OnScreenshot)
219 EVT_MENU(IDM_CONFIG_MAIN, CFrame::OnConfigMain)
220 EVT_MENU(IDM_CONFIG_GFX_PLUGIN, CFrame::OnPluginGFX)
221 EVT_MENU(IDM_CONFIG_DSP_PLUGIN, CFrame::OnPluginDSP)
222 EVT_MENU(IDM_CONFIG_PAD_PLUGIN, CFrame::OnPluginPAD)
223 EVT_MENU(IDM_CONFIG_WIIMOTE_PLUGIN, CFrame::OnPluginWiimote)
225 EVT_MENU(IDM_SAVE_PERSPECTIVE, CFrame::OnToolBar)
226 EVT_AUITOOLBAR_TOOL_DROPDOWN(IDM_SAVE_PERSPECTIVE, CFrame::OnDropDownToolbarItem)
227 EVT_MENU(IDM_EDIT_PERSPECTIVES, CFrame::OnToolBar)
228 EVT_AUITOOLBAR_TOOL_DROPDOWN(IDM_EDIT_PERSPECTIVES, CFrame::OnDropDownSettingsToolbar)
229 // Drop down
230 EVT_MENU(IDM_PERSPECTIVES_ADD_PANE, CFrame::OnToolBar)
231 EVT_MENU_RANGE(IDM_PERSPECTIVES_0, IDM_PERSPECTIVES_100, CFrame::OnSelectPerspective)
232 EVT_MENU(IDM_ADD_PERSPECTIVE, CFrame::OnDropDownToolbarSelect)
233 EVT_MENU(IDM_TAB_SPLIT, CFrame::OnDropDownToolbarSelect)
234 EVT_MENU(IDM_NO_DOCKING, CFrame::OnDropDownToolbarSelect)
235 // Drop down float
236 EVT_MENU(IDM_FLOAT_LOGWINDOW, CFrame::OnFloatWindow)
237 EVT_MENU(IDM_FLOAT_CONSOLEWINDOW, CFrame::OnFloatWindow)
238 EVT_MENU(IDM_FLOAT_CODEWINDOW, CFrame::OnFloatWindow)
239 EVT_MENU(IDM_FLOAT_REGISTERWINDOW, CFrame::OnFloatWindow)
240 EVT_MENU(IDM_FLOAT_BREAKPOINTWINDOW, CFrame::OnFloatWindow)
241 EVT_MENU(IDM_FLOAT_MEMORYWINDOW, CFrame::OnFloatWindow)
242 EVT_MENU(IDM_FLOAT_JITWINDOW, CFrame::OnFloatWindow)
243 EVT_MENU(IDM_FLOAT_SOUNDWINDOW, CFrame::OnFloatWindow)
244 EVT_MENU(IDM_FLOAT_VIDEOWINDOW, CFrame::OnFloatWindow)
247 #if defined(HAVE_SFML) && HAVE_SFML
248 EVT_MENU(IDM_NETPLAY, CFrame::OnNetPlay)
249 #endif
251 EVT_MENU(IDM_BROWSE, CFrame::OnBrowse)
252 EVT_MENU(IDM_MEMCARD, CFrame::OnMemcard)
253 EVT_MENU(IDM_IMPORTSAVE, CFrame::OnImportSave)
254 EVT_MENU(IDM_CHEATS, CFrame::OnShow_CheatsWindow)
255 EVT_MENU(IDM_CHANGEDISC, CFrame::OnChangeDisc)
256 EVT_MENU(IDM_LOAD_WII_MENU, CFrame::OnLoadWiiMenu)
258 EVT_MENU(IDM_TOGGLE_FULLSCREEN, CFrame::OnToggleFullscreen)
259 EVT_MENU(IDM_TOGGLE_DUALCORE, CFrame::OnToggleDualCore)
260 EVT_MENU(IDM_TOGGLE_SKIPIDLE, CFrame::OnToggleSkipIdle)
261 EVT_MENU(IDM_TOGGLE_TOOLBAR, CFrame::OnToggleToolbar)
262 EVT_MENU(IDM_TOGGLE_STATUSBAR, CFrame::OnToggleStatusbar)
263 EVT_MENU(IDM_LOGWINDOW, CFrame::OnToggleLogWindow)
264 EVT_MENU(IDM_CONSOLEWINDOW, CFrame::OnToggleConsole)
266 EVT_MENU(IDM_PURGECACHE, CFrame::GameListChanged)
268 EVT_MENU(IDM_LOADLASTSTATE, CFrame::OnLoadLastState)
269 EVT_MENU(IDM_UNDOLOADSTATE, CFrame::OnUndoLoadState)
270 EVT_MENU(IDM_UNDOSAVESTATE, CFrame::OnUndoSaveState)
271 EVT_MENU(IDM_LOADSTATEFILE, CFrame::OnLoadStateFromFile)
272 EVT_MENU(IDM_SAVESTATEFILE, CFrame::OnSaveStateToFile)
274 EVT_MENU_RANGE(IDM_LOADSLOT1, IDM_LOADSLOT8, CFrame::OnLoadState)
275 EVT_MENU_RANGE(IDM_SAVESLOT1, IDM_SAVESLOT8, CFrame::OnSaveState)
276 EVT_MENU_RANGE(IDM_FRAMESKIP0, IDM_FRAMESKIP9, CFrame::OnFrameSkip)
277 EVT_MENU_RANGE(IDM_DRIVE1, IDM_DRIVE24, CFrame::OnBootDrive)
278 EVT_MENU_RANGE(IDM_CONNECT_WIIMOTE1, IDM_CONNECT_WIIMOTE4, CFrame::OnConnectWiimote)
279 EVT_MENU_RANGE(IDM_LISTWAD, IDM_LISTDRIVES, CFrame::GameListChanged)
281 // Other
282 EVT_ACTIVATE(CFrame::OnActive)
283 EVT_CLOSE(CFrame::OnClose)
284 EVT_SIZE(CFrame::OnResize)
285 EVT_MOVE(CFrame::OnMove)
286 EVT_LIST_ITEM_ACTIVATED(LIST_CTRL, CFrame::OnGameListCtrl_ItemActivated)
287 EVT_HOST_COMMAND(wxID_ANY, CFrame::OnHostMessage)
288 #if wxUSE_TIMER && defined _WIN32
289 EVT_TIMER(wxID_ANY, CFrame::OnTimer)
290 #endif
292 EVT_AUI_PANE_CLOSE(CFrame::OnPaneClose)
293 EVT_AUINOTEBOOK_PAGE_CLOSE(wxID_ANY, CFrame::OnNotebookPageClose)
294 EVT_AUINOTEBOOK_ALLOW_DND(wxID_ANY, CFrame::OnAllowNotebookDnD)
295 EVT_AUINOTEBOOK_PAGE_CHANGED(wxID_ANY, CFrame::OnNotebookPageChanged)
296 EVT_AUINOTEBOOK_TAB_RIGHT_UP(wxID_ANY, CFrame::OnTab)
298 // Post events to child panels
299 EVT_MENU(wxID_ANY, CFrame::PostEvent)
300 EVT_TEXT(wxID_ANY, CFrame::PostEvent)
301 //EVT_MENU_HIGHLIGHT_ALL(CFrame::PostMenuEvent)
302 //EVT_UPDATE_UI(wxID_ANY, CFrame::PostUpdateUIEvent)
304 END_EVENT_TABLE()
306 // ---------------
307 // Creation and close, quit functions
309 CFrame::CFrame(wxFrame* parent,
310 wxWindowID id,
311 const wxString& title,
312 const wxPoint& pos,
313 const wxSize& size,
314 bool _UseDebugger,
315 bool ShowLogWindow,
316 long style)
317 : wxFrame(parent, id, title, pos, size, style)
318 , g_pCodeWindow(NULL)
319 , m_MenuBar(NULL)
320 , m_LogWindow(NULL)
321 , m_ToolBar(NULL), m_ToolBarDebug(NULL), m_ToolBarAui(NULL)
322 , m_pStatusBar(NULL), m_GameListCtrl(NULL), m_Panel(NULL)
323 , UseDebugger(_UseDebugger), m_bEdit(false), m_bTabSplit(false), m_bNoDocking(false)
324 , bRenderToMain(false), bFloatLogWindow(false), bFloatConsoleWindow(false)
325 , HaveLeds(false), HaveSpeakers(false)
326 , m_bControlsCreated(false), bNoWiimoteMsg(false), m_StopDlg(NULL)
327 #if wxUSE_TIMER && defined _WIN32
328 , m_fLastClickTime(0), m_iLastMotionTime(0), LastMouseX(0), LastMouseY(0)
329 , m_timer(this)
330 #endif
333 if (ShowLogWindow) SConfig::GetInstance().m_InterfaceLogWindow = true;
335 // Give it a console early to show potential messages from this onward
336 ConsoleListener *Console = LogManager::GetInstance()->getConsoleListener();
337 if (SConfig::GetInstance().m_InterfaceConsole) Console->Open();
338 if (SConfig::GetInstance().m_InterfaceLogWindow) m_LogWindow = new CLogWindow(this, IDM_LOGWINDOW);
340 // Start debugging mazimized
341 if (UseDebugger) this->Maximize(true);
342 // Debugger class
343 if (UseDebugger)
345 g_pCodeWindow = new CCodeWindow(SConfig::GetInstance().m_LocalCoreStartupParameter, this, IDM_CODEWINDOW);
346 g_pCodeWindow->Hide();
347 g_pCodeWindow->Load();
350 // Create timer
351 #if wxUSE_TIMER && defined _WIN32
352 int TimesPerSecond = 10; // We don't need more than this
353 m_timer.Start( floor((double)(1000 / TimesPerSecond)) );
354 #endif
356 // Create toolbar bitmaps
357 InitBitmaps();
359 // Give it an icon
360 wxIcon IconTemp;
361 IconTemp.CopyFromBitmap(wxGetBitmapFromMemory(dolphin_ico32x32));
362 SetIcon(IconTemp);
364 // Give it a status bar
365 m_pStatusBar = CreateStatusBar(1, wxST_SIZEGRIP, ID_STATUSBAR);
366 if (!SConfig::GetInstance().m_InterfaceStatusbar)
367 m_pStatusBar->Hide();
369 // Give it a menu bar
370 CreateMenu();
372 // ---------------
373 // Main panel
374 // This panel is the parent for rendering and it holds the gamelistctrl
375 m_Panel = new CPanel(this, IDM_MPANEL);
377 m_GameListCtrl = new CGameListCtrl(m_Panel, LIST_CTRL,
378 wxDefaultPosition, wxDefaultSize,
379 wxLC_REPORT | wxSUNKEN_BORDER | wxLC_ALIGN_LEFT);
381 sizerPanel = new wxBoxSizer(wxHORIZONTAL);
382 sizerPanel->Add(m_GameListCtrl, 1, wxEXPAND | wxALL);
383 m_Panel->SetSizer(sizerPanel);
384 // ---------------
386 // Manager
387 #ifdef _WIN32
388 m_Mgr = new wxAuiManager(this, wxAUI_MGR_DEFAULT | wxAUI_MGR_LIVE_RESIZE);
389 #else
390 // wxAUI_MGR_LIVE_RESIZE does not exist in the wxWidgets 2.8 that comes with the latest ubuntu.
391 m_Mgr = new wxAuiManager(this, wxAUI_MGR_DEFAULT);
392 #endif
393 NOTEBOOK_STYLE = wxAUI_NB_TOP | wxAUI_NB_TAB_SPLIT | wxAUI_NB_TAB_EXTERNAL_MOVE | wxAUI_NB_SCROLL_BUTTONS | wxAUI_NB_WINDOWLIST_BUTTON | wxNO_BORDER;
394 TOOLBAR_STYLE = wxAUI_TB_DEFAULT_STYLE | wxAUI_TB_TEXT /*wxAUI_TB_OVERFLOW overflow visible*/;
395 wxBitmap aNormalFile = wxArtProvider::GetBitmap(wxART_NORMAL_FILE, wxART_OTHER, wxSize(16,16));
397 if (g_pCodeWindow)
399 m_Mgr->AddPane(m_Panel, wxAuiPaneInfo().Name(wxT("Pane 0")).Caption(wxT("Pane 0")).Show());
401 else
403 m_Mgr->AddPane(m_Panel, wxAuiPaneInfo().Name(wxT("Pane 0")).Caption(wxT("Pane 0")).Hide());
404 m_Mgr->AddPane(CreateEmptyNotebook(), wxAuiPaneInfo().Name(wxT("Pane 1")).Caption(wxT("Logging")).Hide());
407 // Setup perspectives
408 if (g_pCodeWindow)
410 m_Mgr->GetPane(wxT("Pane 0")).CenterPane().PaneBorder(false);
411 AuiFullscreen = m_Mgr->SavePerspective();
412 m_Mgr->GetPane(wxT("Pane 0")).CenterPane().PaneBorder(true);
414 else
416 IniFile ini; int pos;
417 ini.Load(File::GetUserPath(F_LOGGERCONFIG_IDX));
418 ini.Get("LogWindow", "pos", &pos, 2);
420 m_Mgr->GetPane(wxT("Pane 0")).Show().PaneBorder(false).CaptionVisible(false).Layer(0).Center();
421 m_Mgr->GetPane(wxT("Pane 1")).Hide().PaneBorder(false).CaptionVisible(true).Layer(0)
422 .FloatingSize(wxSize(600, 350)).CloseButton(false).Direction(pos);
423 AuiFullscreen = m_Mgr->SavePerspective();
426 // Create toolbar
427 RecreateToolbar();
428 if (!SConfig::GetInstance().m_InterfaceToolbar) DoToggleToolbar(false);
430 // Create list of available plugins for the configuration window
431 CPluginManager::GetInstance().ScanForPlugins();
433 // Setup perspectives
434 if (g_pCodeWindow)
436 // Load perspective
437 SaveLocal();
438 DoLoadPerspective();
440 else
442 SetSimplePaneSize();
443 if (SConfig::GetInstance().m_InterfaceLogWindow) DoToggleWindow(IDM_LOGWINDOW, true);
444 if (SConfig::GetInstance().m_InterfaceConsole) DoToggleWindow(IDM_CONSOLEWINDOW, true);
447 // Show window
448 Show();
450 // Commit
451 m_Mgr->Update();
453 // Create cursors
454 #ifdef _WIN32
455 CreateCursor();
456 #endif
458 // -------------------------
459 // Connect event handlers
461 wxTheApp->Connect(wxID_ANY, wxEVT_SIZE, // Keyboard
462 wxSizeEventHandler(CFrame::OnResizeAll),
463 (wxObject*)0, this);
465 wxTheApp->Connect(wxID_ANY, wxEVT_KEY_DOWN, // Keyboard
466 wxKeyEventHandler(CFrame::OnKeyDown),
467 (wxObject*)0, this);
468 wxTheApp->Connect(wxID_ANY, wxEVT_KEY_UP,
469 wxKeyEventHandler(CFrame::OnKeyUp),
470 (wxObject*)0, this);
472 m_Mgr->Connect(wxID_ANY, wxEVT_AUI_RENDER, // Resize
473 wxAuiManagerEventHandler(CFrame::OnManagerResize),
474 (wxObject*)0, this);
476 wxTheApp->Connect(wxID_ANY, wxEVT_LEFT_DCLICK,
477 wxMouseEventHandler(CFrame::OnDoubleClick),
478 (wxObject*)0, this);
479 #ifdef _WIN32 && defince _WIN32
480 wxTheApp->Connect(wxID_ANY, wxEVT_MOTION,
481 wxMouseEventHandler(CFrame::OnMotion),
482 (wxObject*)0, this);
483 #endif
484 // ----------
486 // Update controls
487 m_bControlsCreated = true;
488 UpdateGUI();
490 //if we are ever going back to optional iso caching:
491 //m_GameListCtrl->Update(SConfig::GetInstance().m_LocalCoreStartupParameter.bEnableIsoCache);
492 if (m_GameListCtrl) m_GameListCtrl->Update();
494 // If we are rerecording create the status bar now instead of later when a game starts
495 #ifdef RERECORDING
496 ModifyStatusBar();
497 // It's to early for the OnHostMessage(), we will update the status when Ctrl or Space is pressed
498 //Core::WriteStatus();
499 #endif
501 // Destructor
502 CFrame::~CFrame()
504 m_bControlsCreated = false;
506 cdio_free_device_list(drives);
507 /* The statbar sample has this so I add this to, but I guess timer will be deleted after
508 this anyway */
509 #if wxUSE_TIMER && defined _WIN32
510 if (m_timer.IsRunning()) m_timer.Stop();
511 #endif
513 ClosePages();
516 void CFrame::OnQuit(wxCommandEvent& WXUNUSED (event))
518 Close(true);
521 // --------
522 // Events
523 void CFrame::OnActive(wxActivateEvent& event)
525 event.Skip();
528 void CFrame::OnClose(wxCloseEvent& event)
530 //Stop Dolphin from saving the minimized Xpos and Ypos
531 if(main_frame->IsIconized())
532 main_frame->Iconize(false);
534 // Don't forget the skip or the window won't be destroyed
535 event.Skip();
536 // Save GUI settings
537 if (g_pCodeWindow) Save();
538 // Uninit
539 m_Mgr->UnInit();
541 if (Core::GetState() != Core::CORE_UNINITIALIZED)
543 Core::Stop();
544 UpdateGUI();
548 // Post events
550 // Warning: This may cause an endless loop if the event is propagated back to its parent
551 void CFrame::PostEvent(wxCommandEvent& event)
553 if (g_pCodeWindow
554 && event.GetId() >= IDM_INTERPRETER && event.GetId() <= IDM_ADDRBOX
555 //&& event.GetId() != IDM_JITUNLIMITED
558 event.StopPropagation();
559 g_pCodeWindow->GetEventHandler()->AddPendingEvent(event);
561 else
562 event.Skip();
564 void CFrame::PostMenuEvent(wxMenuEvent& event)
566 if (g_pCodeWindow) g_pCodeWindow->GetEventHandler()->AddPendingEvent(event);
568 void CFrame::PostUpdateUIEvent(wxUpdateUIEvent& event)
570 if (g_pCodeWindow) g_pCodeWindow->GetEventHandler()->AddPendingEvent(event);
573 void CFrame::OnMove(wxMoveEvent& event)
575 event.Skip();
577 SConfig::GetInstance().m_LocalCoreStartupParameter.iPosX = GetPosition().x;
578 SConfig::GetInstance().m_LocalCoreStartupParameter.iPosY = GetPosition().y;
580 void CFrame::OnResize(wxSizeEvent& event)
582 event.Skip();
584 SConfig::GetInstance().m_LocalCoreStartupParameter.iWidth = GetSize().GetWidth();
585 SConfig::GetInstance().m_LocalCoreStartupParameter.iHeight = GetSize().GetHeight();
587 DoMoveIcons(); // In FrameWiimote.cpp
589 void CFrame::OnResizeAll(wxSizeEvent& event)
591 event.Skip();
592 //wxWindow * Win = (wxWindow*)event.GetEventObject();
593 //NOTICE_LOG(CONSOLE, "OnResizeAll: %i", (HWND)Win->GetHWND());
596 // Host messages
598 #ifdef _WIN32
599 WXLRESULT CFrame::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam)
601 switch (nMsg)
603 case WM_SYSCOMMAND:
604 switch (wParam & 0xFFF0)
606 case SC_SCREENSAVE:
607 case SC_MONITORPOWER:
608 return 0;
611 return wxFrame::MSWWindowProc(nMsg, wParam, lParam);
613 #endif
615 void CFrame::OnHostMessage(wxCommandEvent& event)
617 switch (event.GetId())
619 case IDM_UPDATEGUI:
620 UpdateGUI();
621 break;
623 case IDM_UPDATESTATUSBAR:
624 if (m_pStatusBar != NULL)
626 // Linux doesn't like it since the message isn't coming from the GUI thread. We need to change this to post a message to the Frame.
627 #ifdef _WIN32
628 m_pStatusBar->SetStatusText(event.GetString(), event.GetInt());
629 #endif
631 break;
635 void CFrame::OnCustomHostMessage(int Id)
637 wxWindow *Win;
639 switch(Id)
641 // Destroy windows
642 case AUDIO_DESTROY:
643 Win = GetWxWindow(wxT("Sound"));
644 if (Win)
646 DoRemovePage(Win, false);
648 CPluginManager::GetInstance().OpenDebug(
649 GetHandle(),
650 SConfig::GetInstance().m_LocalCoreStartupParameter.m_strDSPPlugin.c_str(),
651 PLUGIN_TYPE_DSP, false
654 //Win->Reparent(NULL);
655 //g_pCodeWindow->OnToggleDLLWindow(false, 0);
656 GetMenuBar()->FindItem(IDM_SOUNDWINDOW)->Check(false);
657 NOTICE_LOG(CONSOLE, "%s", Core::StopMessage(true, "Sound debugging window closed").c_str());
659 break;
661 case VIDEO_DESTROY:
662 break;
666 void CFrame::OnGameListCtrl_ItemActivated(wxListEvent& WXUNUSED (event))
668 // Show all platforms and regions if...
669 // 1. All platforms are set to hide
670 // 2. All Regions are set to hide
671 // Otherwise call BootGame to either...
672 // 1. Boot the selected iso
673 // 2. Boot the default or last loaded iso.
674 // 3. Call BrowseForDirectory if the gamelist is empty
675 if (!m_GameListCtrl->GetGameNames().size() &&
676 !((SConfig::GetInstance().m_ListGC &&
677 SConfig::GetInstance().m_ListWii &&
678 SConfig::GetInstance().m_ListWad) &&
679 (SConfig::GetInstance().m_ListJap &&
680 SConfig::GetInstance().m_ListUsa &&
681 SConfig::GetInstance().m_ListPal &&
682 SConfig::GetInstance().m_ListFrance &&
683 SConfig::GetInstance().m_ListItaly &&
684 SConfig::GetInstance().m_ListKorea &&
685 SConfig::GetInstance().m_ListTaiwan &&
686 SConfig::GetInstance().m_ListUnknown)))
688 SConfig::GetInstance().m_ListGC = SConfig::GetInstance().m_ListWii =
689 SConfig::GetInstance().m_ListWad = SConfig::GetInstance().m_ListJap =
690 SConfig::GetInstance().m_ListUsa = SConfig::GetInstance().m_ListPal =
691 SConfig::GetInstance().m_ListFrance = SConfig::GetInstance().m_ListItaly =
692 SConfig::GetInstance().m_ListKorea = SConfig::GetInstance().m_ListTaiwan =
693 SConfig::GetInstance().m_ListUnknown= true;
695 GetMenuBar()->FindItem(IDM_LISTGC)->Check(true);
696 GetMenuBar()->FindItem(IDM_LISTWII)->Check(true);
697 GetMenuBar()->FindItem(IDM_LISTWAD)->Check(true);
698 GetMenuBar()->FindItem(IDM_LISTJAP)->Check(true);
699 GetMenuBar()->FindItem(IDM_LISTUSA)->Check(true);
700 GetMenuBar()->FindItem(IDM_LISTPAL)->Check(true);
701 GetMenuBar()->FindItem(IDM_LISTFRANCE)->Check(true);
702 GetMenuBar()->FindItem(IDM_LISTITALY)->Check(true);
703 GetMenuBar()->FindItem(IDM_LISTKOREA)->Check(true);
704 GetMenuBar()->FindItem(IDM_LISTTAIWAN)->Check(true);
705 GetMenuBar()->FindItem(IDM_LIST_UNK)->Check(true);
707 m_GameListCtrl->Update();
709 else
710 // Game started by double click
711 StartGame(std::string(""));
714 void CFrame::OnKeyDown(wxKeyEvent& event)
716 // Toggle fullscreen
717 if (event.GetKeyCode() == WXK_ESCAPE || (event.GetKeyCode() == WXK_RETURN && event.GetModifiers() == wxMOD_ALT))
719 DoFullscreen(!IsFullScreen());
721 // We do that to avoid the event to be double processed (which would cause the window to be stuck in fullscreen)
722 event.StopPropagation();
724 // event.Skip() allows the event to propagate to the gamelist for example
725 else if (! (Core::GetState() == Core::CORE_RUN && bRenderToMain && event.GetEventObject() == this))
726 event.Skip();
728 #ifdef _WIN32
729 if(event.GetKeyCode() == 'M', '3', '4', '5', '6', '7') // Send this to the video plugin WndProc
731 PostMessage((HWND)Core::GetWindowHandle(), WM_USER, WM_USER_KEYDOWN, event.GetKeyCode());
733 #endif
735 // Send the keyboard status to the Input plugin
736 if(Core::GetState() != Core::CORE_UNINITIALIZED)
737 CPluginManager::GetInstance().GetPad(0)->PAD_Input(event.GetKeyCode(), 1); // 1 = Down
740 void CFrame::OnKeyUp(wxKeyEvent& event)
742 event.Skip();
744 if(Core::GetState() != Core::CORE_UNINITIALIZED)
745 CPluginManager::GetInstance().GetPad(0)->PAD_Input(event.GetKeyCode(), 0); // 0 = Up
748 // ---------------
749 // Detect double click
751 void CFrame::OnDoubleClick(wxMouseEvent& event)
753 // Don't block the mouse click
754 event.Skip();
756 // Don't use this in Wii mode since we use the mouse as input to the game there
757 if (SConfig::GetInstance().m_LocalCoreStartupParameter.bWii) return;
759 // Only detect double clicks in the rendering window, and only use this when a game is running
760 if (! (Core::GetState() == Core::CORE_RUN && bRenderToMain && event.GetEventObject() == m_Panel)) return;
762 DoFullscreen(!IsFullScreen());
766 // Check for mouse motion. Here we process the bHideCursor setting.
768 #if wxUSE_TIMER && defined _WIN32
769 void CFrame::OnMotion(wxMouseEvent& event)
771 event.Skip();
773 // The following is only interesting when a game is running
774 if(Core::GetState() == Core::CORE_UNINITIALIZED) return;
776 /* For some reason WM_MOUSEMOVE events are sent from the plugin even when there is no movement
777 so we have to check that the cursor position has actually changed */
778 if(bRenderToMain) //
780 bool PositionIdentical = false;
781 if (event.GetX() == LastMouseX && event.GetY() == LastMouseY) PositionIdentical = true;
782 LastMouseX = event.GetX(); LastMouseY = event.GetY();
783 if(PositionIdentical) return;
786 // Now we know that we have an actual mouse movement event
788 // Update motion for the auto hide option and return
789 if(IsFullScreen() && SConfig::GetInstance().m_LocalCoreStartupParameter.bAutoHideCursor)
791 m_iLastMotionTime = Common::Timer::GetDoubleTime();
792 MSWSetCursor(true);
793 return;
796 if(SConfig::GetInstance().m_LocalCoreStartupParameter.bHideCursor && event.GetId() == IDM_MPANEL)
798 if(bRenderToMain) MSWSetCursor(false);
800 /* We only need to use this if we are rendering to a separate window. It does work
801 for rendering to the main window to, but in that case our MSWSetCursor() works to
802 so we can use that instead. If we one day determine that the separate window
803 rendering is superfluous we could do without this */
804 else PostMessage((HWND)Core::GetWindowHandle(), WM_USER, 10, 0);
807 // For some reason we need this to, otherwise the cursor can get stuck with the resizing arrows
808 else
810 if(bRenderToMain) MSWSetCursor(true);
811 else PostMessage((HWND)Core::GetWindowHandle(), WM_USER, 10, 1);
815 #endif
817 // Check for mouse status a couple of times per second for the auto hide option
818 #if wxUSE_TIMER && defined _WIN32
819 void CFrame::Update()
821 // Check if auto hide is on, or if we are already hiding the cursor all the time
822 if(!SConfig::GetInstance().m_LocalCoreStartupParameter.bAutoHideCursor
823 || SConfig::GetInstance().m_LocalCoreStartupParameter.bHideCursor) return;
825 if(IsFullScreen())
827 int HideDelay = 1; // Wait 1 second to hide the cursor, just like Windows Media Player
828 double TmpSeconds = Common::Timer::GetDoubleTime(); // Get timestamp
829 double CompareTime = TmpSeconds - HideDelay; // Compare it
831 if(m_iLastMotionTime < CompareTime) // Update cursor
832 MSWSetCursor(false);
835 #endif
838 // --------
839 // Functions
842 wxFrame * CFrame::CreateParentFrame(wxWindowID Id, const wxString& Title, wxWindow * Child)
844 wxFrame * Frame = new wxFrame(this, Id, Title, wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_STYLE);
846 Child->Reparent(Frame);
847 Child->Show();
849 wxBoxSizer * m_MainSizer = new wxBoxSizer(wxHORIZONTAL);
851 m_MainSizer->Add(Child, 1, wxEXPAND);
853 Frame->Connect(wxID_ANY, wxEVT_CLOSE_WINDOW,
854 wxCloseEventHandler(CFrame::OnFloatingPageClosed),
855 (wxObject*)0, this);
857 if (Id == IDM_CONSOLEWINDOW_PARENT)
859 Frame->Connect(wxID_ANY, wxEVT_SIZE,
860 wxSizeEventHandler(CFrame::OnFloatingPageSize),
861 (wxObject*)0, this);
864 // Main sizer
865 Frame->SetSizer( m_MainSizer );
866 // Minimum frame size
867 Frame->SetMinSize(wxSize(200, -1));
868 Frame->Show();
869 return Frame;
871 wxPanel* CFrame::CreateEmptyPanel(wxWindowID Id)
873 wxPanel* Panel = new wxPanel(this, Id);
874 return Panel;
876 wxAuiNotebook* CFrame::CreateEmptyNotebook()
878 wxAuiNotebook* NB = new wxAuiNotebook(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, NOTEBOOK_STYLE);
879 return NB;
883 void CFrame::DoFullscreen(bool bF)
885 // Only switch this to fullscreen if we're rendering to main AND if we're running a game
886 // plus if a modal dialog is open, this will still process the keyboard events, and may cause
887 // the main window to become unresponsive, so we have to avoid that.
888 if ((bRenderToMain && Core::GetState() == Core::CORE_RUN) && !m_bModalDialogOpen)
890 ShowFullScreen(bF);
892 if (bF)
894 // Save the current mode before going to fullscreen
895 AuiCurrent = m_Mgr->SavePerspective();
896 m_Mgr->LoadPerspective(AuiFullscreen, true);
898 else
900 // Restore saved perspective
901 m_Mgr->LoadPerspective(AuiCurrent, true);
904 // Show the cursor again, in case it was hidden
905 if (IsFullScreen())
907 #ifdef _WIN32
908 MSWSetCursor(true);
909 #endif
912 #ifdef _WIN32
913 else // Post the message to the separate rendering window which will then handle it.
914 PostMessage((HWND)Core::GetWindowHandle(), WM_USER, TOGGLE_FULLSCREEN, 0);
915 #endif
918 // Debugging, show loose windows
919 void CFrame::ListChildren()
921 ConsoleListener* Console = LogManager::GetInstance()->getConsoleListener();
922 wxAuiNotebook * NB = NULL;
924 Console->Log(LogTypes::LNOTICE, "--------------------------------------------------------------------\n");
926 for (u32 i = 0; i < this->GetChildren().size(); i++)
928 wxWindow * Win = this->GetChildren().Item(i)->GetData();
929 Console->Log(LogTypes::LNOTICE, StringFromFormat(
930 "%i: %s (%s) :: %s", i,
931 (const char*)Win->GetName().mb_str(), (const char*)Win->GetLabel().mb_str(), (const char*)Win->GetParent()->GetName().mb_str()).c_str());
932 //if (Win->GetName().IsSameAs(wxT("control")))
933 if (Win->IsKindOf(CLASSINFO(wxAuiNotebook)))
935 NB = (wxAuiNotebook*)Win;
936 Console->Log(LogTypes::LNOTICE, StringFromFormat(" :: NB", (const char*)NB->GetName().mb_str()).c_str());
938 else
940 NB = NULL;
942 Console->Log(LogTypes::LNOTICE, StringFromFormat("\n").c_str());
944 Win = this->GetChildren().Item(i)->GetData();
945 for (u32 j = 0; j < Win->GetChildren().size(); j++)
947 Console->Log(LogTypes::LNOTICE, StringFromFormat(
948 " %i.%i: %s (%s) :: %s", i, j,
949 (const char*)Win->GetName().mb_str(), (const char*)Win->GetLabel().mb_str(), (const char*)Win->GetParent()->GetName().mb_str()).c_str());
950 if (NB)
952 if (j < NB->GetPageCount())
953 Console->Log(LogTypes::LNOTICE, StringFromFormat(" :: %s", (const char*)NB->GetPage(j)->GetName().mb_str()).c_str());
955 Console->Log(LogTypes::LNOTICE, StringFromFormat("\n").c_str());
958 Win = this->GetChildren().Item(j)->GetData();
959 for (int k = 0; k < Win->GetChildren().size(); k++)
961 Console->Log(LogTypes::LNOTICE, StringFromFormat(
962 " %i.%i.%i: %s (%s) :: %s\n", i, j, k,
963 Win->GetName().mb_str(), Win->GetLabel().mb_str(), Win->GetParent()->GetName().mb_str()).c_str());
969 Console->Log(LogTypes::LNOTICE, "--------------------------------------------------------------------\n");
971 for (u32 i = 0; i < m_Mgr->GetAllPanes().GetCount(); i++)
973 if (!m_Mgr->GetAllPanes().Item(i).window->IsKindOf(CLASSINFO(wxAuiNotebook))) continue;
974 wxAuiNotebook * _NB = (wxAuiNotebook*)m_Mgr->GetAllPanes().Item(i).window;
975 Console->Log(LogTypes::LNOTICE, StringFromFormat("%i: %s\n", i, (const char *)m_Mgr->GetAllPanes().Item(i).name.mb_str()).c_str());
977 for (u32 j = 0; j < _NB->GetPageCount(); j++)
979 Console->Log(LogTypes::LNOTICE, StringFromFormat("%i.%i: %s\n", i, j, (const char *)_NB->GetPageText(j).mb_str()).c_str());
983 Console->Log(LogTypes::LNOTICE, "--------------------------------------------------------------------\n");
986 void CFrame::ListTopWindows()
988 wxWindowList::const_iterator i;
989 int j = 0;
990 const wxWindowList::const_iterator end = wxTopLevelWindows.end();
992 for (i = wxTopLevelWindows.begin(); i != end; ++i)
994 wxTopLevelWindow * const Win = wx_static_cast(wxTopLevelWindow *, *i);
995 NOTICE_LOG(CONSOLE, "%i: %i %s", j, Win, (const char *)Win->GetTitle().mb_str());
997 if ( win->ShouldPreventAppExit() )
999 // there remains at least one important TLW, don't exit
1000 return false;
1003 j++;
1005 NOTICE_LOG(CONSOLE, "\n");