/[pcsx2_0.9.7]/trunk/common/include/Utilities/pxEvents.h
ViewVC logotype

Annotation of /trunk/common/include/Utilities/pxEvents.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 31 - (hide annotations) (download)
Tue Sep 7 03:24:11 2010 UTC (9 years, 10 months ago) by william
File MIME type: text/plain
File size: 12417 byte(s)
committing r3113 initial commit again...
1 william 31 /* PCSX2 - PS2 Emulator for PCs
2     * Copyright (C) 2002-2010 PCSX2 Dev Team
3     *
4     * PCSX2 is free software: you can redistribute it and/or modify it under the terms
5     * of the GNU Lesser General Public License as published by the Free Software Found-
6     * ation, either version 3 of the License, or (at your option) any later version.
7     *
8     * PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
9     * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
10     * PURPOSE. See the GNU General Public License for more details.
11     *
12     * You should have received a copy of the GNU General Public License along with PCSX2.
13     * If not, see <http://www.gnu.org/licenses/>.
14     */
15    
16     #pragma once
17    
18     BEGIN_DECLARE_EVENT_TYPES()
19     DECLARE_EVENT_TYPE( pxEvt_StartIdleEventTimer, -1 )
20     DECLARE_EVENT_TYPE( pxEvt_DeleteObject, -1 )
21     DECLARE_EVENT_TYPE( pxEvt_DeleteThread, -1 )
22     DECLARE_EVENT_TYPE( pxEvt_InvokeAction, -1 )
23     DECLARE_EVENT_TYPE( pxEvt_SynchronousCommand, -1 )
24     END_DECLARE_EVENT_TYPES()
25    
26     typedef void FnType_Void();
27    
28     // --------------------------------------------------------------------------------------
29     // SynchronousActionState
30     // --------------------------------------------------------------------------------------
31     class SynchronousActionState
32     {
33     DeclareNoncopyableObject( SynchronousActionState );
34    
35     protected:
36     bool m_posted;
37     Threading::Semaphore m_sema;
38     ScopedPtr<BaseException> m_exception;
39    
40     public:
41     sptr return_value;
42    
43     SynchronousActionState()
44     {
45     m_posted = false;
46     return_value = 0;
47     }
48    
49     virtual ~SynchronousActionState() throw() {}
50    
51     void SetException( const BaseException& ex );
52     void SetException( BaseException* ex );
53    
54     Threading::Semaphore& GetSemaphore() { return m_sema; }
55     const Threading::Semaphore& GetSemaphore() const { return m_sema; }
56    
57     void RethrowException() const;
58     int WaitForResult();
59     int WaitForResult_NoExceptions();
60     void PostResult( int res );
61     void ClearResult();
62     void PostResult();
63     };
64    
65    
66     // --------------------------------------------------------------------------------------
67     // pxSimpleEvent - non-abstract implementation of wxEvent
68     // --------------------------------------------------------------------------------------
69     // Why? I mean, why is wxEvent abstract? Over-designed OO is such a bad habit. And while
70     // I'm on my high horse (and it's so very high!), why use 'private'? Ever? Seriously, it
71     // sucks. Stop using it, people.
72     //
73     class pxSimpleEvent : public wxEvent
74     {
75     DECLARE_DYNAMIC_CLASS_NO_ASSIGN(pxSimpleEvent)
76    
77     public:
78     pxSimpleEvent( int evtid=0 )
79     : wxEvent(0, evtid)
80     { }
81    
82     pxSimpleEvent( wxWindowID winId, int evtid )
83     : wxEvent(winId, evtid)
84     { }
85    
86     virtual wxEvent *Clone() const { return new pxSimpleEvent(*this); }
87     };
88    
89     // --------------------------------------------------------------------------------------
90     // pxInvokeActionEvent
91     // --------------------------------------------------------------------------------------
92     class pxInvokeActionEvent : public wxEvent
93     {
94     DECLARE_DYNAMIC_CLASS_NO_ASSIGN(pxInvokeActionEvent)
95    
96     protected:
97     SynchronousActionState* m_state;
98    
99     public:
100     virtual ~pxInvokeActionEvent() throw() { }
101     virtual pxInvokeActionEvent *Clone() const { return new pxInvokeActionEvent(*this); }
102    
103     explicit pxInvokeActionEvent( SynchronousActionState* sema=NULL, int msgtype=pxEvt_InvokeAction );
104     explicit pxInvokeActionEvent( SynchronousActionState& sema, int msgtype=pxEvt_InvokeAction );
105     pxInvokeActionEvent( const pxInvokeActionEvent& src );
106    
107     Threading::Semaphore* GetSemaphore() const { return m_state ? &m_state->GetSemaphore() : NULL; }
108    
109     const SynchronousActionState* GetSyncState() const { return m_state; }
110     SynchronousActionState* GetSyncState() { return m_state; }
111    
112     void SetSyncState( SynchronousActionState* obj ) { m_state = obj; }
113     void SetSyncState( SynchronousActionState& obj ) { m_state = &obj; }
114    
115     virtual void SetException( BaseException* ex );
116     void SetException( const BaseException& ex );
117    
118     virtual void _DoInvokeEvent();
119    
120     protected:
121     virtual void InvokeEvent() {}
122     };
123    
124    
125     // --------------------------------------------------------------------------------------
126     // pxExceptionEvent
127     // --------------------------------------------------------------------------------------
128     class pxExceptionEvent : public pxInvokeActionEvent
129     {
130     typedef pxInvokeActionEvent _parent;
131    
132     protected:
133     BaseException* m_except;
134    
135     public:
136     pxExceptionEvent( BaseException* ex=NULL )
137     {
138     m_except = ex;
139     }
140    
141     pxExceptionEvent( const BaseException& ex );
142    
143     virtual ~pxExceptionEvent() throw()
144     {
145     }
146    
147     virtual pxExceptionEvent *Clone() const { return new pxExceptionEvent(*this); }
148    
149     protected:
150     void InvokeEvent();
151     };
152    
153     // --------------------------------------------------------------------------------------
154     // pxSynchronousCommandEvent
155     // --------------------------------------------------------------------------------------
156    
157     class pxSynchronousCommandEvent : public wxCommandEvent
158     {
159     DECLARE_DYNAMIC_CLASS_NO_ASSIGN(pxSynchronousCommandEvent)
160    
161     protected:
162     SynchronousActionState* m_sync;
163     wxEventType m_realEvent;
164    
165     public:
166     virtual ~pxSynchronousCommandEvent() throw() { }
167     virtual pxSynchronousCommandEvent *Clone() const { return new pxSynchronousCommandEvent(*this); }
168    
169     pxSynchronousCommandEvent(SynchronousActionState* sema=NULL, wxEventType commandType = wxEVT_NULL, int winid = 0);
170     pxSynchronousCommandEvent(SynchronousActionState& sema, wxEventType commandType = wxEVT_NULL, int winid = 0);
171    
172     pxSynchronousCommandEvent(SynchronousActionState* sema, const wxCommandEvent& evt);
173     pxSynchronousCommandEvent(SynchronousActionState& sema, const wxCommandEvent& evt);
174    
175     pxSynchronousCommandEvent(const pxSynchronousCommandEvent& src);
176    
177     Threading::Semaphore* GetSemaphore() { return m_sync ? &m_sync->GetSemaphore() : NULL; }
178     wxEventType GetRealEventType() const { return m_realEvent; }
179    
180     void SetException( BaseException* ex );
181     void SetException( const BaseException& ex );
182     };
183    
184     // --------------------------------------------------------------------------------------
185     // BaseMessageBoxEvent
186     // --------------------------------------------------------------------------------------
187     class BaseMessageBoxEvent : public pxInvokeActionEvent
188     {
189     typedef pxInvokeActionEvent _parent;
190     DECLARE_DYNAMIC_CLASS_NO_ASSIGN(BaseMessageBoxEvent)
191    
192     protected:
193     wxString m_Content;
194    
195     public:
196     virtual ~BaseMessageBoxEvent() throw() { }
197     virtual BaseMessageBoxEvent *Clone() const { return new BaseMessageBoxEvent(*this); }
198    
199     explicit BaseMessageBoxEvent( const wxString& content=wxEmptyString, SynchronousActionState* instdata=NULL );
200     BaseMessageBoxEvent( const wxString& content, SynchronousActionState& instdata );
201     BaseMessageBoxEvent( const BaseMessageBoxEvent& event );
202    
203     protected:
204     virtual void InvokeEvent();
205     virtual int _DoDialog() const;
206     };
207    
208     // --------------------------------------------------------------------------------------
209     // MsgButtons
210     // --------------------------------------------------------------------------------------
211     class MsgButtons
212     {
213     protected:
214     BITFIELD32()
215     bool
216     m_OK :1,
217     m_Cancel :1,
218     m_Yes :1,
219     m_No :1,
220     m_AllowToAll:1,
221     m_Apply :1,
222     m_Abort :1,
223     m_Retry :1,
224     m_Ignore :1,
225     m_Reset :1,
226     m_Close :1;
227     BITFIELD_END
228    
229     wxString m_CustomLabel;
230    
231     public:
232     MsgButtons() { bitset = 0; }
233    
234     MsgButtons& OK() { m_OK = true; return *this; }
235     MsgButtons& Cancel() { m_Cancel = true; return *this; }
236     MsgButtons& Apply() { m_Apply = true; return *this; }
237     MsgButtons& Yes() { m_Yes = true; return *this; }
238     MsgButtons& No() { m_No = true; return *this; }
239     MsgButtons& ToAll() { m_AllowToAll = true; return *this; }
240    
241     MsgButtons& Abort() { m_Abort = true; return *this; }
242     MsgButtons& Retry() { m_Retry = true; return *this; }
243     MsgButtons& Ignore() { m_Ignore = true; return *this; }
244     MsgButtons& Reset() { m_Reset = true; return *this; }
245     MsgButtons& Close() { m_Close = true; return *this; }
246    
247     MsgButtons& Custom( const wxString& label)
248     {
249     m_CustomLabel = label;
250     return *this;
251     }
252    
253     MsgButtons& OKCancel() { m_OK = m_Cancel = true; return *this; }
254     MsgButtons& YesNo() { m_Yes = m_No = true; return *this; }
255    
256     bool HasOK() const { return m_OK; }
257     bool HasCancel() const { return m_Cancel; }
258     bool HasApply() const { return m_Apply; }
259     bool HasYes() const { return m_Yes; }
260     bool HasNo() const { return m_No; }
261     bool AllowsToAll() const{ return m_AllowToAll; }
262    
263     bool HasAbort() const { return m_Abort; }
264     bool HasRetry() const { return m_Retry; }
265     bool HasIgnore() const { return m_Ignore; }
266     bool HasReset() const { return m_Reset; }
267     bool HasClose() const { return m_Close; }
268    
269     bool HasCustom() const { return !m_CustomLabel.IsEmpty(); }
270     const wxString& GetCustomLabel() const { return m_CustomLabel; }
271    
272     bool Allows( wxWindowID id ) const;
273     void SetBestFocus( wxWindow* dialog ) const;
274     void SetBestFocus( wxWindow& dialog ) const;
275    
276     bool operator ==( const MsgButtons& right ) const
277     {
278     return OpEqu( bitset );
279     }
280    
281     bool operator !=( const MsgButtons& right ) const
282     {
283     return !OpEqu( bitset );
284     }
285     };
286    
287     // --------------------------------------------------------------------------------------
288     // pxMessageBoxEvent
289     // --------------------------------------------------------------------------------------
290     // This event type is used to transfer message boxes to the main UI thread, and return the
291     // result of the box. It's the only way a message box can be issued from non-main threads
292     // with complete safety in wx2.8.
293     //
294     // For simplicity sake this message box only supports two basic designs. The main design
295     // is a generic message box with confirmation buttons of your choosing. Additionally you
296     // can specify a "scrollableContent" text string, which is added into a read-only richtext
297     // control similar to the console logs and such.
298     //
299     // Future consideration: If wxWidgets 3.0 has improved thread safety, then it should probably
300     // be reasonable for it to work with a more flexable model where the dialog can be created
301     // on a child thread, passed to the main thread, where ShowModal() is run (keeping the nested
302     // message pumps on the main thread where they belong). But so far this is not possible,
303     // because of various subtle issues in wx2.8 design.
304     //
305     class pxMessageBoxEvent : public BaseMessageBoxEvent
306     {
307     typedef BaseMessageBoxEvent _parent;
308     DECLARE_DYNAMIC_CLASS_NO_ASSIGN(pxMessageBoxEvent)
309    
310     protected:
311     wxString m_Title;
312     MsgButtons m_Buttons;
313    
314     public:
315     virtual ~pxMessageBoxEvent() throw() { }
316     virtual pxMessageBoxEvent *Clone() const { return new pxMessageBoxEvent(*this); }
317    
318     pxMessageBoxEvent() {}
319     pxMessageBoxEvent( const wxString& title, const wxString& content, const MsgButtons& buttons, SynchronousActionState& instdata );
320     pxMessageBoxEvent( const wxString& title, const wxString& content, const MsgButtons& buttons, SynchronousActionState* instdata=NULL );
321     pxMessageBoxEvent( const pxMessageBoxEvent& event );
322    
323     protected:
324     int _DoDialog() const;
325     };
326    
327     // --------------------------------------------------------------------------------------
328     // pxAssertionEvent
329     // --------------------------------------------------------------------------------------
330     class pxAssertionEvent : public BaseMessageBoxEvent
331     {
332     typedef BaseMessageBoxEvent _parent;
333     DECLARE_DYNAMIC_CLASS_NO_ASSIGN( pxAssertionEvent )
334    
335     protected:
336     wxString m_Stacktrace;
337    
338     public:
339     virtual ~pxAssertionEvent() throw() { }
340     virtual pxAssertionEvent *Clone() const { return new pxAssertionEvent(*this); }
341    
342     pxAssertionEvent( const wxString& content=wxEmptyString, const wxString& trace=wxEmptyString, SynchronousActionState* instdata=NULL );
343     pxAssertionEvent( const wxString& content, const wxString& trace, SynchronousActionState& instdata );
344     pxAssertionEvent( const pxAssertionEvent& event );
345    
346     pxAssertionEvent& SetStacktrace( const wxString& trace );
347    
348     protected:
349     int _DoDialog() const;
350     };
351    
352    
353     typedef void (wxEvtHandler::*pxSyncronousEventFunction)(pxSynchronousCommandEvent&);
354    
355     #define pxSynchronousEventHandler(func) \
356     (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(pxSyncronousEventFunction, &func )

  ViewVC Help
Powered by ViewVC 1.1.22