Fix an issue that caused the DSP-LLE window to be openned twice in windows. (Thanks...
[dolphin.git] / Source / Core / DolphinWX / Src / Frame.cpp
blob679b50c14191e94b6925b5e94cd52ce2a8f0362d
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
20 // the parent for the rendering window (when we render to the main window). In
21 // Windows the rendering window is created by giving CreateWindow()
22 // m_Panel->GetHandle() as parent window and creating a new child window to
23 // m_Panel. The new child window handle that is returned by CreateWindow() can
24 // be accessed from Core::GetWindowHandle().
26 #include "Common.h" // Common
27 #include "FileUtil.h"
28 #include "Timer.h"
29 #include "Setup.h"
31 #include "Globals.h" // Local
32 #include "Frame.h"
33 #include "ConfigMain.h"
34 #include "PluginManager.h"
35 #include "MemcardManager.h"
36 #include "CheatsWindow.h"
37 #include "AboutDolphin.h"
38 #include "GameListCtrl.h"
39 #include "BootManager.h"
40 #include "ConsoleListener.h"
42 #include "ConfigManager.h" // Core
43 #include "Core.h"
44 #include "HW/DVDInterface.h"
45 #include "HW/GCPad.h"
46 #include "IPC_HLE/WII_IPC_HLE_Device_usb.h"
47 #include "State.h"
48 #include "VolumeHandler.h"
50 #include <wx/datetime.h> // wxWidgets
52 // Resources
54 extern "C" {
55 #include "../resources/Dolphin.c" // Dolphin icon
56 #include "../resources/toolbar_browse.c"
57 #include "../resources/toolbar_file_open.c"
58 #include "../resources/toolbar_fullscreen.c"
59 #include "../resources/toolbar_help.c"
60 #include "../resources/toolbar_pause.c"
61 #include "../resources/toolbar_play.c"
62 #include "../resources/toolbar_plugin_dsp.c"
63 #include "../resources/toolbar_plugin_gfx.c"
64 #include "../resources/toolbar_plugin_options.c"
65 #include "../resources/toolbar_plugin_pad.c"
66 #include "../resources/toolbar_refresh.c"
67 #include "../resources/toolbar_stop.c"
68 #include "../resources/Boomy.h" // Theme packages
69 #include "../resources/Vista.h"
70 #include "../resources/X-Plastik.h"
71 #include "../resources/KDE.h"
75 // Windows functions. Setting the cursor with wxSetCursor() did not work in
76 // this instance. Probably because it's somehow reset from the WndProc() in
77 // the child window
78 #ifdef _WIN32
79 // Declare a blank icon and one that will be the normal cursor
80 HCURSOR hCursor = NULL, hCursorBlank = NULL;
82 // Create the default cursor
83 void CreateCursor()
85 hCursor = LoadCursor( NULL, IDC_ARROW );
88 void MSWSetCursor(bool Show)
90 if(Show)
91 SetCursor(hCursor);
92 else
94 SetCursor(hCursorBlank);
95 //wxSetCursor(wxCursor(wxNullCursor));
99 // I could not use FindItemByHWND() instead of this, it crashed on that occation I used it */
100 HWND MSWGetParent_(HWND Parent)
102 return GetParent(Parent);
104 #endif
106 // ---------------
107 // The CPanel class to receive MSWWindowProc messages from the video plugin.
109 extern CFrame* main_frame;
112 BEGIN_EVENT_TABLE(CPanel, wxPanel)
113 END_EVENT_TABLE()
115 CPanel::CPanel(
116 wxWindow *parent,
117 wxWindowID id
119 : wxPanel(parent, id)
123 #ifdef _WIN32
124 WXLRESULT CPanel::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam)
126 switch (nMsg)
128 case WM_USER:
129 switch(wParam)
131 // Pause
132 case WM_USER_PAUSE:
133 main_frame->DoPause();
134 break;
136 // Stop
137 case WM_USER_STOP:
138 main_frame->DoStop();
139 break;
141 case WM_USER_CREATE:
142 break;
144 case WM_USER_SETCURSOR:
145 if (SConfig::GetInstance().m_LocalCoreStartupParameter.bHideCursor &&
146 main_frame->RendererHasFocus() && Core::GetState() == Core::CORE_RUN)
147 MSWSetCursor(!SConfig::GetInstance().m_LocalCoreStartupParameter.bHideCursor);
148 else
149 MSWSetCursor(true);
150 break;
152 case WIIMOTE_DISCONNECT:
153 if (SConfig::GetInstance().m_LocalCoreStartupParameter.bWii)
155 if (main_frame->bNoWiimoteMsg)
156 main_frame->bNoWiimoteMsg = false;
157 else
159 int wiimote_idx = lParam;
160 int wiimote_num = wiimote_idx + 1;
161 //Auto reconnect if option is turned on.
162 //TODO: Make this only auto reconnect wiimotes that have the option activated.
163 SConfig::GetInstance().LoadSettingsWii();//Make sure we are using the newest settings.
164 if (SConfig::GetInstance().m_WiiAutoReconnect[wiimote_idx])
166 GetUsbPointer()->AccessWiiMote(wiimote_idx | 0x100)->Activate(true);
167 NOTICE_LOG(WIIMOTE, "Wiimote %i has been auto-reconnected...", wiimote_num);
169 else
171 // The Wiimote has been disconnected, we offer reconnect here.
172 wxMessageDialog *dlg = new wxMessageDialog(
173 this,
174 wxString::Format(wxT("Wiimote %i has been disconnected by system.\n")
175 wxT("Maybe this game doesn't support multi-wiimote,\n")
176 wxT("or maybe it is due to idle time out or other reason.\n\n")
177 wxT("Do you want to reconnect immediately?"), wiimote_num),
178 wxT("Reconnect Wiimote Confirm"),
179 wxYES_NO | wxSTAY_ON_TOP | wxICON_INFORMATION, //wxICON_QUESTION,
180 wxDefaultPosition);
182 if (dlg->ShowModal() == wxID_YES)
183 GetUsbPointer()->AccessWiiMote(wiimote_idx | 0x100)->Activate(true);
185 dlg->Destroy();
190 break;
191 default:
192 // By default let wxWidgets do what it normally does with this event
193 return wxPanel::MSWWindowProc(nMsg, wParam, lParam);
195 return 0;
197 #endif
199 CRenderFrame::CRenderFrame(wxFrame* parent, wxWindowID id, const wxString& title,
200 const wxPoint& pos, const wxSize& size, long style)
201 : wxFrame(parent, id, title, pos, size, style)
205 #ifdef _WIN32
206 WXLRESULT CRenderFrame::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam)
208 switch (nMsg)
210 case WM_SYSCOMMAND:
211 switch (wParam)
213 case SC_SCREENSAVE:
214 case SC_MONITORPOWER:
215 if (Core::GetState() == Core::CORE_RUN)
216 break;
217 default:
218 return wxFrame::MSWWindowProc(nMsg, wParam, lParam);
220 break;
221 default:
222 // By default let wxWidgets do what it normally does with this event
223 return wxFrame::MSWWindowProc(nMsg, wParam, lParam);
225 return 0;
227 #endif
229 // event tables
230 // Notice that wxID_HELP will be processed for the 'About' menu and the toolbar
231 // help button.
233 const wxEventType wxEVT_HOST_COMMAND = wxNewEventType();
235 BEGIN_EVENT_TABLE(CFrame, CRenderFrame)
237 // Menu bar
238 EVT_MENU(wxID_OPEN, CFrame::OnOpen)
239 EVT_MENU(wxID_EXIT, CFrame::OnQuit)
240 EVT_MENU(IDM_HELPWEBSITE, CFrame::OnHelp)
241 EVT_MENU(IDM_HELPGOOGLECODE, CFrame::OnHelp)
242 EVT_MENU(wxID_ABOUT, CFrame::OnHelp)
243 EVT_MENU(wxID_REFRESH, CFrame::OnRefresh)
244 EVT_MENU(IDM_PLAY, CFrame::OnPlay)
245 EVT_MENU(IDM_STOP, CFrame::OnStop)
246 EVT_MENU(IDM_RESET, CFrame::OnReset)
247 EVT_MENU(IDM_RECORD, CFrame::OnRecord)
248 EVT_MENU(IDM_PLAYRECORD, CFrame::OnPlayRecording)
249 EVT_MENU(IDM_FRAMESTEP, CFrame::OnFrameStep)
250 EVT_MENU(IDM_LUA, CFrame::OnOpenLuaWindow)
251 EVT_MENU(IDM_SCREENSHOT, CFrame::OnScreenshot)
252 EVT_MENU(wxID_PREFERENCES, CFrame::OnConfigMain)
253 EVT_MENU(IDM_CONFIG_GFX_PLUGIN, CFrame::OnPluginGFX)
254 EVT_MENU(IDM_CONFIG_DSP_PLUGIN, CFrame::OnPluginDSP)
255 EVT_MENU(IDM_CONFIG_PAD_PLUGIN, CFrame::OnPluginPAD)
256 EVT_MENU(IDM_CONFIG_WIIMOTE_PLUGIN, CFrame::OnPluginWiimote)
258 EVT_MENU(IDM_SAVE_PERSPECTIVE, CFrame::OnToolBar)
259 EVT_AUITOOLBAR_TOOL_DROPDOWN(IDM_SAVE_PERSPECTIVE, CFrame::OnDropDownToolbarItem)
260 EVT_MENU(IDM_EDIT_PERSPECTIVES, CFrame::OnToolBar)
261 EVT_AUITOOLBAR_TOOL_DROPDOWN(IDM_EDIT_PERSPECTIVES, CFrame::OnDropDownSettingsToolbar)
262 // Drop down
263 EVT_MENU(IDM_PERSPECTIVES_ADD_PANE, CFrame::OnToolBar)
264 EVT_MENU_RANGE(IDM_PERSPECTIVES_0, IDM_PERSPECTIVES_100, CFrame::OnSelectPerspective)
265 EVT_MENU(IDM_ADD_PERSPECTIVE, CFrame::OnDropDownToolbarSelect)
266 EVT_MENU(IDM_TAB_SPLIT, CFrame::OnDropDownToolbarSelect)
267 EVT_MENU(IDM_NO_DOCKING, CFrame::OnDropDownToolbarSelect)
268 // Drop down float
269 EVT_MENU_RANGE(IDM_FLOAT_LOGWINDOW, IDM_FLOAT_CODEWINDOW, CFrame::OnFloatWindow)
271 EVT_MENU(IDM_NETPLAY, CFrame::OnNetPlay)
272 EVT_MENU(IDM_BROWSE, CFrame::OnBrowse)
273 EVT_MENU(IDM_MEMCARD, CFrame::OnMemcard)
274 EVT_MENU(IDM_IMPORTSAVE, CFrame::OnImportSave)
275 EVT_MENU(IDM_CHEATS, CFrame::OnShow_CheatsWindow)
276 EVT_MENU(IDM_CHANGEDISC, CFrame::OnChangeDisc)
277 EVT_MENU(IDM_INSTALL_WII_MENU, CFrame::OnLoadWiiMenu)
278 EVT_MENU(IDM_LOAD_WII_MENU, CFrame::OnLoadWiiMenu)
280 EVT_MENU(IDM_TOGGLE_FULLSCREEN, CFrame::OnToggleFullscreen)
281 EVT_MENU(IDM_TOGGLE_DUALCORE, CFrame::OnToggleDualCore)
282 EVT_MENU(IDM_TOGGLE_SKIPIDLE, CFrame::OnToggleSkipIdle)
283 EVT_MENU(IDM_TOGGLE_TOOLBAR, CFrame::OnToggleToolbar)
284 EVT_MENU(IDM_TOGGLE_STATUSBAR, CFrame::OnToggleStatusbar)
285 EVT_MENU_RANGE(IDM_LOGWINDOW, IDM_VIDEOWINDOW, CFrame::OnToggleWindow)
287 EVT_MENU(IDM_PURGECACHE, CFrame::GameListChanged)
289 EVT_MENU(IDM_LOADLASTSTATE, CFrame::OnLoadLastState)
290 EVT_MENU(IDM_UNDOLOADSTATE, CFrame::OnUndoLoadState)
291 EVT_MENU(IDM_UNDOSAVESTATE, CFrame::OnUndoSaveState)
292 EVT_MENU(IDM_LOADSTATEFILE, CFrame::OnLoadStateFromFile)
293 EVT_MENU(IDM_SAVESTATEFILE, CFrame::OnSaveStateToFile)
295 EVT_MENU_RANGE(IDM_LOADSLOT1, IDM_LOADSLOT8, CFrame::OnLoadState)
296 EVT_MENU_RANGE(IDM_SAVESLOT1, IDM_SAVESLOT8, CFrame::OnSaveState)
297 EVT_MENU_RANGE(IDM_FRAMESKIP0, IDM_FRAMESKIP9, CFrame::OnFrameSkip)
298 EVT_MENU_RANGE(IDM_DRIVE1, IDM_DRIVE24, CFrame::OnBootDrive)
299 EVT_MENU_RANGE(IDM_CONNECT_WIIMOTE1, IDM_CONNECT_WIIMOTE4, CFrame::OnConnectWiimote)
300 EVT_MENU_RANGE(IDM_LISTWAD, IDM_LISTDRIVES, CFrame::GameListChanged)
302 // Other
303 EVT_ACTIVATE(CFrame::OnActive)
304 EVT_CLOSE(CFrame::OnClose)
305 EVT_SIZE(CFrame::OnResize)
306 EVT_MOVE(CFrame::OnMove)
307 EVT_LIST_ITEM_ACTIVATED(LIST_CTRL, CFrame::OnGameListCtrl_ItemActivated)
308 EVT_HOST_COMMAND(wxID_ANY, CFrame::OnHostMessage)
309 #if wxUSE_TIMER
310 EVT_TIMER(wxID_ANY, CFrame::OnTimer)
311 #endif
313 EVT_AUI_PANE_CLOSE(CFrame::OnPaneClose)
314 EVT_AUINOTEBOOK_PAGE_CLOSE(wxID_ANY, CFrame::OnNotebookPageClose)
315 EVT_AUINOTEBOOK_ALLOW_DND(wxID_ANY, CFrame::OnAllowNotebookDnD)
316 EVT_AUINOTEBOOK_PAGE_CHANGED(wxID_ANY, CFrame::OnNotebookPageChanged)
317 EVT_AUINOTEBOOK_TAB_RIGHT_UP(wxID_ANY, CFrame::OnTab)
319 // Post events to child panels
320 EVT_MENU_RANGE(IDM_INTERPRETER, IDM_ADDRBOX, CFrame::PostEvent)
321 EVT_TEXT(IDM_ADDRBOX, CFrame::PostEvent)
323 END_EVENT_TABLE()
325 // ---------------
326 // Creation and close, quit functions
328 CFrame::CFrame(wxFrame* parent,
329 wxWindowID id,
330 const wxString& title,
331 const wxPoint& pos,
332 const wxSize& size,
333 bool _UseDebugger,
334 bool _BatchMode,
335 bool ShowLogWindow,
336 long style)
337 : CRenderFrame(parent, id, title, pos, size, style)
338 , g_pCodeWindow(NULL)
339 , bRenderToMain(false), bNoWiimoteMsg(false)
340 , m_ToolBar(NULL), m_ToolBarDebug(NULL), m_ToolBarAui(NULL)
341 , m_pStatusBar(NULL), m_GameListCtrl(NULL), m_Panel(NULL)
342 , m_RenderFrame(NULL), m_RenderParent(NULL)
343 , m_LogWindow(NULL), UseDebugger(_UseDebugger)
344 , m_bBatchMode(_BatchMode), m_bEdit(false), m_bTabSplit(false), m_bNoDocking(false)
345 , m_bControlsCreated(false), m_bGameLoading(false), m_StopDlg(NULL)
346 #if wxUSE_TIMER
347 , m_timer(this)
348 #endif
350 for (int i = 0; i <= IDM_CODEWINDOW - IDM_LOGWINDOW; i++)
351 bFloatWindow[i] = false;
353 if (ShowLogWindow) SConfig::GetInstance().m_InterfaceLogWindow = true;
355 // Give it a console early to show potential messages from this onward
356 ConsoleListener *Console = LogManager::GetInstance()->getConsoleListener();
357 if (SConfig::GetInstance().m_InterfaceConsole) Console->Open();
358 m_LogWindow = new CLogWindow(this, IDM_LOGWINDOW);
359 m_LogWindow->Hide();
360 m_LogWindow->Disable();
362 // Start debugging mazimized
363 if (UseDebugger) this->Maximize(true);
364 // Debugger class
365 if (UseDebugger)
367 g_pCodeWindow = new CCodeWindow(SConfig::GetInstance().m_LocalCoreStartupParameter, this, IDM_CODEWINDOW);
368 LoadIniPerspectives();
369 g_pCodeWindow->Load();
370 g_pCodeWindow->Hide();
373 // Create timer
374 #if wxUSE_TIMER
375 int TimesPerSecond = 10; // We don't need more than this
376 m_timer.Start( floor((double)(1000 / TimesPerSecond)) );
377 #endif
379 // Create toolbar bitmaps
380 InitBitmaps();
382 // Give it an icon
383 wxIcon IconTemp;
384 IconTemp.CopyFromBitmap(wxGetBitmapFromMemory(dolphin_ico32x32));
385 SetIcon(IconTemp);
387 // Give it a status bar
388 m_pStatusBar = CreateStatusBar(2, wxST_SIZEGRIP, ID_STATUSBAR);
389 if (!SConfig::GetInstance().m_InterfaceStatusbar)
390 m_pStatusBar->Hide();
392 // Give it a menu bar
393 CreateMenu();
395 // ---------------
396 // Main panel
397 // This panel is the parent for rendering and it holds the gamelistctrl
398 m_Panel = new CPanel(this, IDM_MPANEL);
400 m_GameListCtrl = new CGameListCtrl(m_Panel, LIST_CTRL,
401 wxDefaultPosition, wxDefaultSize,
402 wxLC_REPORT | wxSUNKEN_BORDER | wxLC_ALIGN_LEFT);
404 wxBoxSizer *sizerPanel = new wxBoxSizer(wxHORIZONTAL);
405 sizerPanel->Add(m_GameListCtrl, 1, wxEXPAND | wxALL);
406 m_Panel->SetSizer(sizerPanel);
407 // ---------------
409 // Manager
410 // wxAUI_MGR_LIVE_RESIZE does not exist in the wxWidgets 2.8.9 that comes with Ubuntu 9.04
411 // Could just check for wxWidgets version if it becomes a problem.
412 m_Mgr = new wxAuiManager(this, wxAUI_MGR_DEFAULT | wxAUI_MGR_LIVE_RESIZE);
414 if (g_pCodeWindow)
416 m_Mgr->AddPane(m_Panel, wxAuiPaneInfo().Name(wxT("Pane 0")).Caption(wxT("Pane 0")).Show());
418 else
420 m_Mgr->AddPane(m_Panel, wxAuiPaneInfo().Name(wxT("Pane 0")).Caption(wxT("Pane 0")).Hide());
421 m_Mgr->AddPane(CreateEmptyNotebook(), wxAuiPaneInfo().Name(wxT("Pane 1")).Caption(wxT("Logging")).Hide());
424 // Setup perspectives
425 if (g_pCodeWindow)
427 m_Mgr->GetPane(wxT("Pane 0")).CenterPane().PaneBorder(false);
428 AuiFullscreen = m_Mgr->SavePerspective();
429 m_Mgr->GetPane(wxT("Pane 0")).CenterPane().PaneBorder(true);
431 else
433 m_Mgr->GetPane(wxT("Pane 0")).Show().PaneBorder(false).CaptionVisible(false).Layer(0).Center();
434 m_Mgr->GetPane(wxT("Pane 1")).Hide().PaneBorder(false).CaptionVisible(true).Layer(0)
435 .FloatingSize(wxSize(600, 350)).CloseButton(false);
436 AuiFullscreen = m_Mgr->SavePerspective();
439 // Create toolbar
440 RecreateToolbar();
441 if (!SConfig::GetInstance().m_InterfaceToolbar) DoToggleToolbar(false);
443 // Create list of available plugins for the configuration window
444 CPluginManager::GetInstance().ScanForPlugins();
446 // Setup perspectives
447 if (g_pCodeWindow)
449 // Load perspective
450 DoLoadPerspective();
452 else
454 if (SConfig::GetInstance().m_InterfaceLogWindow)
455 ToggleLogWindow(true);
456 if (SConfig::GetInstance().m_InterfaceConsole)
457 ToggleConsole(true);
460 // Show window
461 Show();
463 // Commit
464 m_Mgr->Update();
466 // Create cursors
467 #ifdef _WIN32
468 CreateCursor();
469 #endif
471 #if defined(HAVE_XRANDR) && HAVE_XRANDR
472 m_XRRConfig = new X11Utils::XRRConfiguration(X11Utils::XDisplayFromHandle(GetHandle()),
473 X11Utils::XWindowFromHandle(GetHandle()));
474 #endif
476 // -------------------------
477 // Connect event handlers
479 m_Mgr->Connect(wxID_ANY, wxEVT_AUI_RENDER, // Resize
480 wxAuiManagerEventHandler(CFrame::OnManagerResize),
481 (wxObject*)0, this);
482 // ----------
484 // Update controls
485 m_bControlsCreated = true;
486 UpdateGUI();
488 // If we are rerecording create the status bar now instead of later when a game starts
489 #ifdef RERECORDING
490 ModifyStatusBar();
491 // It's to early for the OnHostMessage(), we will update the status when Ctrl or Space is pressed
492 //Core::WriteStatus();
493 #endif
495 // Destructor
496 CFrame::~CFrame()
498 m_bControlsCreated = false;
500 drives.clear();
501 /* The statbar sample has this so I add this to, but I guess timer will be deleted after
502 this anyway */
503 #if wxUSE_TIMER
504 if (m_timer.IsRunning()) m_timer.Stop();
505 #endif
507 #if defined(HAVE_XRANDR) && HAVE_XRANDR
508 delete m_XRRConfig;
509 #endif
511 ClosePages();
513 delete m_Mgr;
516 bool CFrame::RendererIsFullscreen()
518 if (Core::GetState() == Core::CORE_RUN || Core::GetState() == Core::CORE_PAUSE)
520 return m_RenderFrame->IsFullScreen();
522 return false;
525 void CFrame::OnQuit(wxCommandEvent& WXUNUSED (event))
527 Close(true);
530 // --------
531 // Events
532 void CFrame::OnActive(wxActivateEvent& event)
534 if (Core::GetState() == Core::CORE_RUN || Core::GetState() == Core::CORE_PAUSE)
536 if (event.GetActive() && event.GetEventObject() == m_RenderFrame)
538 #ifdef _WIN32
539 ::SetFocus((HWND)m_RenderParent->GetHandle());
540 #else
541 m_RenderParent->SetFocus();
542 #endif
543 if (SConfig::GetInstance().m_LocalCoreStartupParameter.bHideCursor &&
544 Core::GetState() == Core::CORE_RUN)
545 m_RenderParent->SetCursor(wxCURSOR_BLANK);
547 else
549 if (SConfig::GetInstance().m_LocalCoreStartupParameter.bHideCursor)
550 m_RenderParent->SetCursor(wxCURSOR_ARROW);
553 event.Skip();
556 void CFrame::OnClose(wxCloseEvent& event)
558 //Stop Dolphin from saving the minimized Xpos and Ypos
559 if(main_frame->IsIconized())
560 main_frame->Iconize(false);
562 // Don't forget the skip or the window won't be destroyed
563 event.Skip();
564 // Save GUI settings
565 if (g_pCodeWindow) SaveIniPerspectives();
567 // Close the log window now so that its settings are saved
568 if (!g_pCodeWindow)
569 m_LogWindow->Close();
571 // Uninit
572 m_Mgr->UnInit();
574 if (Core::GetState() != Core::CORE_UNINITIALIZED)
576 DoStop();
577 UpdateGUI();
581 // Post events
583 // Warning: This may cause an endless loop if the event is propagated back to its parent
584 void CFrame::PostEvent(wxCommandEvent& event)
586 if (g_pCodeWindow &&
587 event.GetId() >= IDM_INTERPRETER &&
588 event.GetId() <= IDM_ADDRBOX)
590 event.StopPropagation();
591 g_pCodeWindow->GetEventHandler()->AddPendingEvent(event);
593 else
594 event.Skip();
597 void CFrame::OnMove(wxMoveEvent& event)
599 event.Skip();
601 if (!IsMaximized() &&
602 !(SConfig::GetInstance().m_LocalCoreStartupParameter.bRenderToMain && RendererIsFullscreen()))
604 SConfig::GetInstance().m_LocalCoreStartupParameter.iPosX = GetPosition().x;
605 SConfig::GetInstance().m_LocalCoreStartupParameter.iPosY = GetPosition().y;
609 void CFrame::OnResize(wxSizeEvent& event)
611 event.Skip();
612 if (!IsMaximized() &&
613 !(SConfig::GetInstance().m_LocalCoreStartupParameter.bRenderToMain && RendererIsFullscreen()))
615 SConfig::GetInstance().m_LocalCoreStartupParameter.iWidth = GetSize().GetWidth();
616 SConfig::GetInstance().m_LocalCoreStartupParameter.iHeight = GetSize().GetHeight();
620 // Host messages
622 #ifdef _WIN32
623 WXLRESULT CFrame::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam)
625 switch (nMsg)
627 case WM_SYSCOMMAND:
628 switch (wParam & 0xFFF0)
630 case SC_SCREENSAVE:
631 case SC_MONITORPOWER:
632 break;
633 default:
634 return wxFrame::MSWWindowProc(nMsg, wParam, lParam);
636 break;
637 default:
638 return wxFrame::MSWWindowProc(nMsg, wParam, lParam);
640 return 0;
642 #endif
644 #if wxUSE_TIMER
645 void CFrame::OnTimer(wxTimerEvent& WXUNUSED(event))
647 // Process events. Primarily to update the statusbar text.
648 if (wxGetApp().Pending())
649 wxGetApp().ProcessPendingEvents();
651 #endif
653 void CFrame::OnHostMessage(wxCommandEvent& event)
655 switch (event.GetId())
657 case IDM_UPDATEGUI:
658 UpdateGUI();
659 break;
661 case IDM_UPDATESTATUSBAR:
662 if (m_pStatusBar != NULL)
664 m_pStatusBar->SetStatusText(event.GetString(), event.GetInt());
666 break;
668 case IDM_UPDATETITLE:
669 if (!SConfig::GetInstance().m_LocalCoreStartupParameter.bRenderToMain && m_RenderFrame)
670 m_RenderFrame->SetTitle(event.GetString());
671 break;
673 case WM_USER_CREATE:
674 if (SConfig::GetInstance().m_LocalCoreStartupParameter.bHideCursor)
675 m_RenderParent->SetCursor(wxCURSOR_BLANK);
676 break;
678 #if defined(HAVE_X11) && HAVE_X11
679 case WM_USER_STOP:
680 DoStop();
681 break;
682 #endif
686 void CFrame::OnSizeRequest(int& x, int& y, int& width, int& height)
688 wxMutexGuiEnter();
689 m_RenderParent->GetSize(&width, &height);
690 m_RenderParent->GetPosition(&x, &y);
691 wxMutexGuiLeave();
694 bool CFrame::RendererHasFocus()
696 if (m_RenderParent == NULL)
697 return false;
698 #ifdef _WIN32
699 if (m_RenderParent->GetParent()->GetHWND() == GetForegroundWindow())
700 return true;
701 #else
702 if (wxWindow::FindFocus() == NULL)
703 return false;
704 // Why these different cases?
705 if (m_RenderParent == wxWindow::FindFocus() ||
706 m_RenderParent == wxWindow::FindFocus()->GetParent() ||
707 m_RenderParent->GetParent() == wxWindow::FindFocus()->GetParent())
708 return true;
709 #endif
710 return false;
713 void CFrame::OnGameListCtrl_ItemActivated(wxListEvent& WXUNUSED (event))
715 // Show all platforms and regions if...
716 // 1. All platforms are set to hide
717 // 2. All Regions are set to hide
718 // Otherwise call BootGame to either...
719 // 1. Boot the selected iso
720 // 2. Boot the default or last loaded iso.
721 // 3. Call BrowseForDirectory if the gamelist is empty
722 if (!m_GameListCtrl->GetGameNames().size() &&
723 !((SConfig::GetInstance().m_ListGC &&
724 SConfig::GetInstance().m_ListWii &&
725 SConfig::GetInstance().m_ListWad) &&
726 (SConfig::GetInstance().m_ListJap &&
727 SConfig::GetInstance().m_ListUsa &&
728 SConfig::GetInstance().m_ListPal &&
729 SConfig::GetInstance().m_ListFrance &&
730 SConfig::GetInstance().m_ListItaly &&
731 SConfig::GetInstance().m_ListKorea &&
732 SConfig::GetInstance().m_ListTaiwan &&
733 SConfig::GetInstance().m_ListUnknown)))
735 SConfig::GetInstance().m_ListGC = SConfig::GetInstance().m_ListWii =
736 SConfig::GetInstance().m_ListWad = SConfig::GetInstance().m_ListJap =
737 SConfig::GetInstance().m_ListUsa = SConfig::GetInstance().m_ListPal =
738 SConfig::GetInstance().m_ListFrance = SConfig::GetInstance().m_ListItaly =
739 SConfig::GetInstance().m_ListKorea = SConfig::GetInstance().m_ListTaiwan =
740 SConfig::GetInstance().m_ListUnknown= true;
742 GetMenuBar()->FindItem(IDM_LISTGC)->Check(true);
743 GetMenuBar()->FindItem(IDM_LISTWII)->Check(true);
744 GetMenuBar()->FindItem(IDM_LISTWAD)->Check(true);
745 GetMenuBar()->FindItem(IDM_LISTJAP)->Check(true);
746 GetMenuBar()->FindItem(IDM_LISTUSA)->Check(true);
747 GetMenuBar()->FindItem(IDM_LISTPAL)->Check(true);
748 GetMenuBar()->FindItem(IDM_LISTFRANCE)->Check(true);
749 GetMenuBar()->FindItem(IDM_LISTITALY)->Check(true);
750 GetMenuBar()->FindItem(IDM_LISTKOREA)->Check(true);
751 GetMenuBar()->FindItem(IDM_LISTTAIWAN)->Check(true);
752 GetMenuBar()->FindItem(IDM_LIST_UNK)->Check(true);
754 m_GameListCtrl->Update();
756 else
757 // Game started by double click
758 BootGame(std::string(""));
761 bool IsHotkey(wxKeyEvent &event, int Id)
763 return (event.GetKeyCode() == SConfig::GetInstance().m_LocalCoreStartupParameter.iHotkey[Id] &&
764 event.GetModifiers() == SConfig::GetInstance().m_LocalCoreStartupParameter.iHotkeyModifier[Id]);
767 void CFrame::OnKeyDown(wxKeyEvent& event)
769 if(Core::GetState() != Core::CORE_UNINITIALIZED)
771 int WiimoteId = -1;
772 // Toggle fullscreen
773 if (IsHotkey(event, HK_FULLSCREEN))
774 DoFullscreen(!RendererIsFullscreen());
775 // Pause and Unpause
776 else if (IsHotkey(event, HK_PLAY_PAUSE))
777 DoPause();
778 // Stop
779 else if (IsHotkey(event, HK_STOP))
780 DoStop();
781 // Wiimote connect and disconnect hotkeys
782 else if (IsHotkey(event, HK_WIIMOTE1_CONNECT))
783 WiimoteId = 0;
784 else if (IsHotkey(event, HK_WIIMOTE2_CONNECT))
785 WiimoteId = 1;
786 else if (IsHotkey(event, HK_WIIMOTE3_CONNECT))
787 WiimoteId = 2;
788 else if (IsHotkey(event, HK_WIIMOTE4_CONNECT))
789 WiimoteId = 3;
790 // state save and state load hotkeys
791 else if (event.GetKeyCode() >= WXK_F1 && event.GetKeyCode() <= WXK_F8)
793 int slot_number = event.GetKeyCode() - WXK_F1 + 1;
794 if (event.GetModifiers() == wxMOD_NONE)
795 State_Load(slot_number);
796 else if (event.GetModifiers() == wxMOD_SHIFT)
797 State_Save(slot_number);
798 else
799 event.Skip();
801 else if (event.GetKeyCode() == WXK_F11 && event.GetModifiers() == wxMOD_NONE)
802 State_LoadLastSaved();
803 else if (event.GetKeyCode() == WXK_F12)
805 if (event.GetModifiers() == wxMOD_NONE)
806 State_UndoSaveState();
807 else if (event.GetModifiers() == wxMOD_SHIFT)
808 State_UndoLoadState();
809 else
810 event.Skip();
812 // screenshot hotkeys
813 else if (event.GetKeyCode() == WXK_F9 && event.GetModifiers() == wxMOD_NONE)
814 Core::ScreenShot();
815 else
816 event.Skip();
818 // Actually perform the wiimote connection or disconnection
819 if (WiimoteId >= 0)
821 bNoWiimoteMsg = GetMenuBar()->IsChecked(IDM_CONNECT_WIIMOTE1 + WiimoteId);
822 GetMenuBar()->Check(IDM_CONNECT_WIIMOTE1 + WiimoteId, !bNoWiimoteMsg);
823 GetUsbPointer()->AccessWiiMote(WiimoteId | 0x100)->Activate(!bNoWiimoteMsg);
824 wxString msg(wxString::Format(wxT("Wiimote %i %s"), WiimoteId + 1,
825 bNoWiimoteMsg ? wxT("Disconnected") : wxT("Connected")));
826 Core::DisplayMessage(msg.ToAscii(), 3000);
829 // Send the OSD hotkeys to the video plugin
830 if (event.GetKeyCode() >= '3' && event.GetKeyCode() <= '7' && event.GetModifiers() == wxMOD_NONE)
832 #ifdef _WIN32
833 PostMessage((HWND)Core::GetWindowHandle(), WM_USER, WM_USER_KEYDOWN, event.GetKeyCode());
834 #elif defined(HAVE_X11) && HAVE_X11
835 X11Utils::SendKeyEvent(X11Utils::XDisplayFromHandle(GetHandle()), event.GetKeyCode());
836 #endif
838 #ifdef _WIN32
839 // Send the freelook hotkeys to the video plugin
840 if ((event.GetKeyCode() == '0', '9', 'W', 'S', 'A', 'D', 'R')
841 && event.GetModifiers() == wxMOD_SHIFT)
842 PostMessage((HWND)Core::GetWindowHandle(), WM_USER, WM_USER_KEYDOWN, event.GetKeyCode());
843 #endif
845 // Send the keyboard status to the Input plugins
846 CPluginManager::GetInstance().GetWiimote()->Wiimote_Input(event.GetKeyCode(), 1); // 1 = Down
848 else
849 event.Skip();
852 void CFrame::OnKeyUp(wxKeyEvent& event)
854 event.Skip();
856 if(Core::GetState() != Core::CORE_UNINITIALIZED) {
857 CPluginManager::GetInstance().GetWiimote()->Wiimote_Input(event.GetKeyCode(), 0); // 0 = Up
861 void CFrame::DoFullscreen(bool bF)
863 ToggleDisplayMode(bF);
865 m_RenderFrame->ShowFullScreen(bF, wxFULLSCREEN_ALL);
866 if (SConfig::GetInstance().m_LocalCoreStartupParameter.bRenderToMain)
868 if (bF)
870 // Save the current mode before going to fullscreen
871 AuiCurrent = m_Mgr->SavePerspective();
872 m_Mgr->LoadPerspective(AuiFullscreen, true);
874 else
876 // Restore saved perspective
877 m_Mgr->LoadPerspective(AuiCurrent, true);
880 else
881 m_RenderFrame->Raise();