00001
00002
00003
00004
00005
00006
00007
00008
00009
00011
00012 #ifndef _AX_UI_ADAPTATION_H_
00013 #define _AX_UI_ADAPTATION_H_
00014
00015 #include "wx/dynarray.h"
00016 #include "ax/ax_speech.h"
00017
00018 class AxTextEvtHandler;
00019 class wxShortcutManager;
00020
00025 typedef enum {
00026 AxContentFull,
00027 AxContentSummary
00028 } AxContentLevel;
00029
00034 typedef enum {
00035 AxAdaptDefault = 0x0000,
00036 AxAdaptSetAccelerators = 0x0001
00037 };
00038
00051 class AxAdapter: public wxEvtHandler
00052 {
00053 DECLARE_CLASS( AxAdapter )
00054 DECLARE_EVENT_TABLE()
00055
00056 public:
00057
00058
00059 AxAdapter(wxWindow* window = NULL, AxSpeech* speech = NULL);
00060
00061 ~AxAdapter();
00062
00063
00064
00065 void Init();
00066
00068 virtual wxString GetName() = 0;
00069
00071 virtual wxString GetLabel();
00072
00076 void SetAlternateLabel(const wxString& label) { m_alternateLabel = label;}
00077
00079 const wxString& GetAlternateLabel() const { return m_alternateLabel;}
00080
00083 virtual wxString GetHelpText();
00084
00087 virtual wxString GetStateText(AxContentLevel level) = 0;
00088
00090 virtual wxString GetContent(AxContentLevel level) = 0;
00091
00094 virtual bool UpdateAppearance(int hints);
00095
00097 virtual bool PostUpdateAppearance(int WXUNUSED(hints)) { return false; }
00098
00101 virtual wxWindow* GetMainControl() const { return GetWindow(); }
00102
00105 virtual bool IsVoiced() const { return true; }
00106
00111 virtual bool DescribeControlContext(bool metaInfo = true, AxContentLevel level = AxContentSummary);
00112
00114 virtual bool DescribeContainerWindow(AxContentLevel level = AxContentSummary);
00115
00118 virtual bool DescribeWindowRecursively(wxWindow* window, AxContentLevel level, wxString& text);
00119
00121 virtual bool Say(const wxString& text, int flags = AxSpeechFlagsPurge, int verbosity = 2);
00122
00124 virtual bool Say(AxSpeechChannel channel, const wxString& text, int flags = AxSpeechFlagsPurge, int verbosity = 2);
00125
00127 virtual bool StopSpeech(AxSpeechChannel channel = AxSpeechDefaultChannel);
00128
00130 virtual bool PauseOrResumeSpeech(AxSpeechChannel channel = AxSpeechDefaultChannel);
00131
00133 virtual bool SkipForward(AxSpeechChannel channel = AxSpeechDefaultChannel);
00134
00136 virtual bool SkipBack(AxSpeechChannel channel = AxSpeechDefaultChannel);
00137
00139 virtual bool IsSpeaking(AxSpeechChannel channel = AxSpeechDefaultChannel) const;
00140
00142 virtual bool CanStop(AxSpeechChannel channel = AxSpeechDefaultChannel) const;
00143
00145 virtual bool CanPause(AxSpeechChannel channel = AxSpeechDefaultChannel) const;
00146
00148 virtual bool CanResume(AxSpeechChannel channel = AxSpeechDefaultChannel) const;
00149
00150 void SetSpeech(AxSpeech* speech) { m_speech = speech; }
00151 AxSpeech* GetSpeech() const { return m_speech; }
00152
00153 void SetWindow(wxWindow* win) { m_window = win; }
00154 wxWindow* GetWindow() const { return m_window; }
00155
00156 void SetShortcutManager(wxShortcutManager* shortcutManager) { m_shortcutManager = shortcutManager; }
00157 wxShortcutManager* GetShortcutManager() const { return m_shortcutManager; }
00158
00159 void OnKeyDown(wxKeyEvent& event);
00160 void OnChar(wxKeyEvent& event);
00161 void OnIdle(wxIdleEvent& event);
00162 void OnSetFocus(wxFocusEvent& event);
00163
00164
00165
00166
00167 static bool IsPunctuation(const wxChar& ch);
00168 static bool IsSentenceEnd(const wxChar& ch);
00169 static bool IsWhitespace(const wxChar& ch);
00170
00172 static bool RemoveTrailingPunctuation(wxString& str);
00173
00176 static bool AddStop(wxString& str, const wxString& punct = wxT("."));
00177
00180 static bool AddPause(wxString& str, const wxString& punct = wxT(";"));
00181
00183 static wxString GetSpokenTextForKeycode(int keycode);
00184
00186 virtual wxString GetStaticLabel();
00187
00189 virtual wxString GetControlLabel();
00190
00193 virtual AxAdapter* FindFocusedAdapter();
00194
00196 virtual bool ApplyFontSize();
00197
00199 virtual bool ApplyWindowColours();
00200
00202 void SetChannel(int channel) { m_channel = channel; }
00203
00205 AxSpeechChannel GetChannel(AxSpeechChannel channel = AxSpeechDefaultChannel) const;
00206
00207 void OnDescribeContext(wxCommandEvent& event);
00208 void OnDescribeContainer(wxCommandEvent& event);
00209 void OnStopSpeech(wxCommandEvent& event);
00210 void OnPauseResumeSpeech(wxCommandEvent& event);
00211 void OnSkipForward(wxCommandEvent& event);
00212 void OnSkipBack(wxCommandEvent& event);
00213 void OnContextHelp(wxCommandEvent& event);
00214 void OnSysColourChanged(wxSysColourChangedEvent& event);
00215 void OnGoHome(wxCommandEvent& event);
00216 void OnGoUp(wxCommandEvent& event);
00217
00218 protected:
00219
00220 wxWindow* m_window;
00221 AxSpeech* m_speech;
00222 wxShortcutManager* m_shortcutManager;
00223 AxSpeechChannel m_channel;
00224 wxString m_alternateLabel;
00225 };
00226
00236 class AxVoiceAdaptationHandler: public wxObject
00237 {
00238 DECLARE_CLASS( AxVoiceAdaptationHandler )
00239
00240 public:
00241 AxVoiceAdaptationHandler() {}
00242 ~AxVoiceAdaptationHandler() {}
00243
00245 virtual bool CanHandleWindow(wxWindow* win) = 0;
00246
00248 virtual AxAdapter* CreateEventHandler(wxWindow* win) = 0;
00249
00252 virtual bool Adapt(wxWindow* window, AxSpeech* speech, wxShortcutManager* shortcuts, wxArrayInt& ids);
00253
00255 virtual bool Unadapt(wxWindow* window, wxArrayInt& ids);
00256
00258 virtual bool CanRecursivelyAdapt(wxWindow* WXUNUSED(window)) const { return true; }
00259 };
00260
00261 WX_DEFINE_ARRAY_PTR(AxVoiceAdaptationHandler*, AxVoiceAdaptationHandlerArray);
00262
00276 class AxSelfVoicing: public wxEvtHandler
00277 {
00278 DECLARE_DYNAMIC_CLASS( AxSelfVoicing )
00279 DECLARE_EVENT_TABLE()
00280
00281 public:
00282
00283
00284 AxSelfVoicing(wxWindow* window = NULL, AxSpeech* speech = NULL, wxShortcutManager* shortcutManager = NULL);
00285
00286 ~AxSelfVoicing();
00287
00288
00289
00290 void Init();
00291
00299
00300 virtual bool Adapt(wxWindow* window = NULL, int flags = AxAdaptDefault);
00301
00303 virtual bool UndoAdaptation();
00304
00306 virtual bool AdaptWindow(wxWindow* window, bool recurse = true);
00307
00309 virtual bool UnadaptWindow(wxWindow* window, bool recurse = true);
00310
00311 void SetSpeech(AxSpeech* speech) { m_speech = speech; }
00312 AxSpeech* GetSpeech() const { return m_speech; }
00313
00314 void SetWindow(wxWindow* win) { m_window = win; }
00315 wxWindow* GetWindow() const { return m_window; }
00316
00317 void SetShortcutManager(wxShortcutManager* shortcutManager) { m_shortcutManager = shortcutManager; }
00318 wxShortcutManager* GetShortcutManager() const { return m_shortcutManager; }
00319
00320
00321 bool IsAdapted() const { return m_adapted; }
00322
00324 static AxVoiceAdaptationHandlerArray& GetAdaptationHandlers() { return m_voiceAdaptationHandlers; }
00325
00327 static void AddAdaptationHandler(AxVoiceAdaptationHandler* handler) { m_voiceAdaptationHandlers.Add(handler); }
00328
00330 static void InsertAdaptationHandler(AxVoiceAdaptationHandler* handler) { m_voiceAdaptationHandlers.Insert(handler, 0); }
00331
00333 static void AddStandardAdaptationHandlers();
00334
00336 static void ClearAdaptationHandlers();
00337
00339 static AxVoiceAdaptationHandler* FindAdaptationHandler(wxWindow* window);
00340
00342 static AxAdapter* FindAdapter(wxWindow* window);
00343
00345 static bool AddAdapter(wxWindow* window, AxAdapter* adapter);
00346
00348 static bool RemoveAdapter(wxWindow* window, AxAdapter* adapter = NULL);
00349
00350 protected:
00351
00352
00353 static AxVoiceAdaptationHandlerArray m_voiceAdaptationHandlers;
00354
00355 wxWindow* m_window;
00356 AxSpeech* m_speech;
00357 wxShortcutManager* m_shortcutManager;
00358
00359
00360 bool m_adapted;
00361
00362
00363
00364
00365 wxArrayInt m_adaptedCtrls;
00366 };
00367
00368 #endif
00369