Fix a segmentation fault when changing perspectives.
[dolphin.git] / Source / Core / DolphinWX / Src / Frame.h
blob68d0f1cf1c1dbbecc29ba9ce364489ae1eb3f2e0
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 #ifndef __FRAME_H_
20 #define __FRAME_H_
22 #include <wx/wx.h> // wxWidgets
23 #include <wx/busyinfo.h>
24 #include <wx/mstream.h>
25 #include <wx/listctrl.h>
26 #include <wx/artprov.h>
27 #if defined(__APPLE__)
28 //id is an objective-c++ type, wx team need to change this
29 #define id toolid
30 #endif
31 #include <wx/aui/aui.h>
32 #include <string>
33 #include <vector>
35 #include "CDUtils.h"
36 #include "CodeWindow.h"
37 #include "LogWindow.h"
38 #if defined(HAVE_X11) && HAVE_X11
39 #include "X11Utils.h"
40 #endif
42 // A shortcut to access the bitmaps
43 #define wxGetBitmapFromMemory(name) _wxGetBitmapFromMemory(name, sizeof(name))
44 inline wxBitmap _wxGetBitmapFromMemory(const unsigned char* data, int length)
46 wxMemoryInputStream is(data, length);
47 return(wxBitmap(wxImage(is, wxBITMAP_TYPE_ANY, -1), -1));
50 // Class declarations
51 class CGameListCtrl;
52 class CLogWindow;
54 // The CPanel class to receive MSWWindowProc messages from the video plugin.
55 class CPanel : public wxPanel
57 public:
58 CPanel(
59 wxWindow* parent,
60 wxWindowID id = wxID_ANY
63 private:
64 DECLARE_EVENT_TABLE();
66 #ifdef _WIN32
67 // Receive WndProc messages
68 WXLRESULT MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam);
69 #endif
72 class CRenderFrame : public wxFrame
74 public:
75 CRenderFrame(wxFrame* parent,
76 wxWindowID id = wxID_ANY,
77 const wxString& title = wxT("Dolphin"),
78 const wxPoint& pos = wxDefaultPosition,
79 const wxSize& size = wxDefaultSize,
80 long style = wxDEFAULT_FRAME_STYLE | wxNO_FULL_REPAINT_ON_RESIZE);
82 private:
83 #ifdef _WIN32
84 // Receive WndProc messages
85 WXLRESULT MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam);
86 #endif
89 class CFrame : public CRenderFrame
91 public:
92 CFrame(wxFrame* parent,
93 wxWindowID id = wxID_ANY,
94 const wxString& title = wxT("Dolphin"),
95 const wxPoint& pos = wxDefaultPosition,
96 const wxSize& size = wxDefaultSize,
97 bool _UseDebugger = false,
98 bool _BatchMode = false,
99 bool ShowLogWindow = false,
100 long style = wxDEFAULT_FRAME_STYLE | wxNO_FULL_REPAINT_ON_RESIZE);
102 virtual ~CFrame();
104 void* GetRenderHandle()
106 #ifdef _WIN32
107 return (void *)m_RenderParent->GetHandle();
108 #elif defined(HAVE_X11) && HAVE_X11
109 return (void *)X11Utils::XWindowFromHandle(m_RenderParent->GetHandle());
110 #else
111 return m_RenderParent;
112 #endif
115 // These have to be public
116 CCodeWindow* g_pCodeWindow;
117 wxMenuBar* m_MenuBar;
118 wxBitmap aNormalFile;
119 void InitBitmaps();
120 void DoPause();
121 void DoStop();
122 bool bRenderToMain;
123 bool bNoWiimoteMsg;
124 void UpdateGUI();
125 void UpdateGameList();
126 void ToggleLogWindow(bool, int i = -1);
127 void ToggleConsole(bool, int i = -1);
128 void PostEvent(wxCommandEvent& event);
129 void StatusBarMessage(const char * Text, ...);
130 void ClearStatusBar();
131 void OnSizeRequest(int& x, int& y, int& width, int& height);
132 void BootGame(const std::string& filename);
133 void OnRenderParentClose(wxCloseEvent& event);
134 void OnRenderParentMove(wxMoveEvent& event);
135 bool RendererHasFocus();
136 void DoFullscreen(bool bF);
137 void ToggleDisplayMode (bool bFullscreen);
139 #if defined(HAVE_XRANDR) && HAVE_XRANDR
140 X11Utils::XRRConfiguration *m_XRRConfig;
141 #endif
143 // AUI
144 wxAuiManager *m_Mgr;
145 wxAuiToolBar *m_ToolBar, *m_ToolBarDebug, *m_ToolBarAui;
146 long NOTEBOOK_STYLE, TOOLBAR_STYLE;
147 int iLeftWidth[2], iMidWidth[2];
148 bool bFloatWindow[IDM_VIDEOWINDOW - IDM_LOGWINDOW + 1];
150 // Utility
151 wxWindow * GetNotebookPageFromId(wxWindowID Id);
152 wxAuiNotebook * GetNotebookFromId(u32);
153 int GetNotebookCount();
154 int Limit(int,int,int);
155 int PercentageToPixels(int,int);
156 int PixelsToPercentage(int,int);
157 wxString GetMenuLabel(int Id);
159 // Perspectives
160 void AddRemoveBlankPage();
161 void OnNotebookPageClose(wxAuiNotebookEvent& event);
162 void OnAllowNotebookDnD(wxAuiNotebookEvent& event);
163 void OnNotebookPageChanged(wxAuiNotebookEvent& event);
164 void OnFloatWindow(wxCommandEvent& event);
165 void ToggleFloatWindow(int Id);
166 void OnTab(wxAuiNotebookEvent& event);
167 int GetNotebookAffiliation(wxWindowID Id);
168 void ClosePages();
169 void ShowAllNotebooks(bool Window = false);
170 void HideAllNotebooks(bool Window = false);
171 void CloseAllNotebooks();
172 void DoAddPage(wxWindow *, int, bool);
173 void DoRemovePage(wxWindow *, bool Hide = true);
174 void DoRemovePageId(wxWindowID Id, bool bHide, bool bDestroy);
175 void TogglePane();
176 void SetSimplePaneSize();
177 void SetPaneSize();
178 void ResetToolbarStyle();
179 void TogglePaneStyle(bool On, int EventId);
180 void ToggleNotebookStyle(bool On, long Style);
181 void ResizeConsole();
182 // Float window
183 void DoUnfloatPage(int Id);
184 void OnFloatingPageClosed(wxCloseEvent& event);
185 void OnFloatingPageSize(wxSizeEvent& event);
186 void DoFloatNotebookPage(wxWindowID Id);
187 wxFrame * CreateParentFrame(wxWindowID Id = wxID_ANY, const wxString& title = wxT(""), wxWindow * = NULL);
188 // User perspectives. Should find a way to make these private.
189 struct SPerspectives
191 std::string Name;
192 wxString Perspective;
193 std::vector<int> Width, Height;
195 std::vector<SPerspectives> Perspectives;
196 wxString AuiFullscreen, AuiCurrent;
197 wxArrayString AuiPerspective;
198 u32 ActivePerspective;
199 void NamePanes();
200 void AddPane();
201 void Save();
202 void SaveLocal();
203 void OnPaneClose(wxAuiManagerEvent& evt);
204 void ReloadPanes();
205 void DoLoadPerspective();
206 void OnDropDownToolbarSelect(wxCommandEvent& event);
207 void OnDropDownSettingsToolbar(wxAuiToolBarEvent& event);
208 void OnDropDownToolbarItem(wxAuiToolBarEvent& event);
209 void OnSelectPerspective(wxCommandEvent& event);
211 private:
212 wxStatusBar* m_pStatusBar;
213 wxBoxSizer* sizerPanel;
214 wxBoxSizer* sizerFrame;
215 CGameListCtrl* m_GameListCtrl;
216 wxPanel* m_Panel;
217 CRenderFrame* m_RenderFrame;
218 wxPanel* m_RenderParent;
219 wxToolBarToolBase* m_ToolPlay;
220 CLogWindow* m_LogWindow;
221 bool UseDebugger;
222 bool m_bBatchMode;
223 bool m_bEdit;
224 bool m_bTabSplit;
225 bool m_bNoDocking;
226 bool m_bControlsCreated;
227 bool m_bGameLoading;
228 char newDiscpath[2048];
229 wxMessageDialog *m_StopDlg;
231 std::vector<std::string> drives;
233 enum EToolbar
235 Toolbar_FileOpen,
236 Toolbar_Refresh,
237 Toolbar_Browse,
238 Toolbar_Play,
239 Toolbar_Stop,
240 Toolbar_Pause,
241 Toolbar_Screenshot,
242 Toolbar_FullScreen,
243 Toolbar_PluginOptions,
244 Toolbar_PluginGFX,
245 Toolbar_PluginDSP,
246 Toolbar_PluginPAD,
247 Toolbar_Wiimote,
248 Toolbar_Help,
249 EToolbar_Max
252 enum EBitmapsThemes
254 BOOMY,
255 VISTA,
256 XPLASTIK,
257 KDE,
258 THEMES_MAX
261 wxBitmap m_Bitmaps[EToolbar_Max];
262 wxBitmap m_BitmapsMenu[EToolbar_Max];
264 void PopulateToolbar(wxAuiToolBar* toolBar);
265 void PopulateToolbarAui(wxAuiToolBar* toolBar);
266 void RecreateToolbar();
267 void CreateMenu();
268 wxAuiNotebook *CreateEmptyNotebook();
270 #ifdef _WIN32
271 // Override window proc for tricks like screensaver disabling
272 WXLRESULT MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam);
273 #endif
274 // Event functions
275 void OnQuit(wxCommandEvent& event);
276 void OnHelp(wxCommandEvent& event);
277 void OnToolBar(wxCommandEvent& event);
278 void OnAuiToolBar(wxAuiToolBarEvent& event);
280 void OnOpen(wxCommandEvent& event); // File menu
281 void DoOpen(bool Boot);
282 void OnRefresh(wxCommandEvent& event);
283 void OnBrowse(wxCommandEvent& event);
284 void OnBootDrive(wxCommandEvent& event);
286 void OnPlay(wxCommandEvent& event); // Emulation
287 void OnStop(wxCommandEvent& event);
288 void OnReset(wxCommandEvent& event);
289 void OnRecord(wxCommandEvent& event);
290 void OnPlayRecording(wxCommandEvent& event);
291 void OnChangeDisc(wxCommandEvent& event);
292 void OnScreenshot(wxCommandEvent& event);
293 void OnActive(wxActivateEvent& event);
294 void OnClose(wxCloseEvent &event);
295 void OnLoadState(wxCommandEvent& event);
296 void OnSaveState(wxCommandEvent& event);
297 void OnLoadStateFromFile(wxCommandEvent& event);
298 void OnSaveStateToFile(wxCommandEvent& event);
299 void OnLoadLastState(wxCommandEvent& event);
300 void OnUndoLoadState(wxCommandEvent& event);
301 void OnUndoSaveState(wxCommandEvent& event);
303 void OnFrameSkip(wxCommandEvent& event);
304 void OnFrameStep(wxCommandEvent& event);
306 void OnConfigMain(wxCommandEvent& event); // Options
307 void OnPluginGFX(wxCommandEvent& event);
308 void OnPluginDSP(wxCommandEvent& event);
309 void OnPluginPAD(wxCommandEvent& event);
310 void OnPluginWiimote(wxCommandEvent& event);
312 void OnToggleFullscreen(wxCommandEvent& event);
313 void OnToggleDualCore(wxCommandEvent& event);
314 void OnToggleSkipIdle(wxCommandEvent& event);
315 void OnToggleThrottle(wxCommandEvent& event);
316 void OnManagerResize(wxAuiManagerEvent& event);
317 void OnMove(wxMoveEvent& event);
318 void OnResize(wxSizeEvent& event);
319 void OnToggleToolbar(wxCommandEvent& event);
320 void DoToggleToolbar(bool);
321 void OnToggleStatusbar(wxCommandEvent& event);
322 void OnToggleLogWindow(wxCommandEvent& event);
323 void OnToggleConsole(wxCommandEvent& event);
324 void OnKeyDown(wxKeyEvent& event);
325 void OnKeyUp(wxKeyEvent& event);
327 void OnHostMessage(wxCommandEvent& event);
329 void OnMemcard(wxCommandEvent& event); // Misc
330 void OnImportSave(wxCommandEvent& event);
331 void OnOpenLuaWindow(wxCommandEvent& event);
333 void OnNetPlay(wxCommandEvent& event);
335 void OnShow_CheatsWindow(wxCommandEvent& event);
336 void OnLoadWiiMenu(wxCommandEvent& event);
337 void OnConnectWiimote(wxCommandEvent& event);
338 void GameListChanged(wxCommandEvent& event);
340 void OnGameListCtrl_ItemActivated(wxListEvent& event);
341 void OnRenderParentResize(wxSizeEvent& event);
342 bool RendererIsFullscreen();
343 void StartGame(const std::string& filename);
345 // MenuBar
346 // File - Drive
347 wxMenuItem* m_pSubMenuDrive;
349 // Emulation
350 wxMenuItem* m_pSubMenuLoad;
351 wxMenuItem* m_pSubMenuSave;
352 wxMenuItem* m_pSubMenuFrameSkipping;
354 #if wxUSE_TIMER
355 // Used to process command events
356 void OnTimer(wxTimerEvent& WXUNUSED(event));
357 wxTimer m_timer;
358 #endif
360 // Event table
361 DECLARE_EVENT_TABLE();
365 #endif // __FRAME_H_