tagging release
[dasher.git] / trunk / Src / Win32 / Widgets / Edit.h
blob69854466ee32bc7bf152e22060c18d3a74493c2d
1 // Edit.h
2 //
3 /////////////////////////////////////////////////////////////////////////////
4 //
5 // Copyright (c) 2002 David Ward
6 //
7 /////////////////////////////////////////////////////////////////////////////
9 #ifndef __Edit_h__
10 #define __Edit_h__
12 #define _ATL_APARTMENT_THREADED
13 #include <atlbase.h>
15 //You may derive a class from CComModule and use it if you want to override something,
17 //but do not change the name of _Module
19 extern CComModule _Module;
21 #include <atlcom.h>
23 #include "../AppSettings.h"
24 #include "../DasherAction.h"
25 #include "../../DasherCore/DasherTypes.h"
27 #include <Oleacc.h>
29 class CCanvas;
30 class CFilenameGUI;
32 namespace Dasher {
33 class CDasherInterfaceBase;
34 class CEvent;
37 enum {
38 EDIT_FORWARDS,
39 EDIT_BACKWARDS
42 enum {
43 EDIT_CHAR,
44 EDIT_WORD,
45 EDIT_LINE,
46 EDIT_FILE
49 class CEdit : public ATL::CWindowImpl<CEdit>
51 public:
53 CEdit(CAppSettings *pAppSettings);
54 ~CEdit();
56 HWND Create(HWND hParent, bool bNewWithDate);
58 // Superclass the built-in EDIT window class
59 DECLARE_WND_SUPERCLASS(NULL, _T("EDIT") )
61 BEGIN_MSG_MAP( CEdit )
62 MESSAGE_HANDLER(WM_LBUTTONDOWN, OnLButtonDown)
63 MESSAGE_HANDLER(WM_LBUTTONUP, OnLButtonUp)
64 MESSAGE_HANDLER(WM_CHAR, OnChar)
65 MESSAGE_HANDLER(WM_KEYDOWN, OnKeyDown)
66 MESSAGE_HANDLER(WM_KEYUP, OnKeyUp)
67 MESSAGE_HANDLER(WM_COMMAND, OnCommand)
68 END_MSG_MAP()
71 HRESULT OnLButtonDown(UINT message, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
72 HRESULT OnLButtonUp(UINT message, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
73 HRESULT OnChar(UINT message, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
74 HRESULT OnKeyDown(UINT message, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
75 HRESULT OnKeyUp(UINT message, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
76 HRESULT OnCommand(UINT message, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
79 void Move(int x, int y, int Width, int Height);
80 HWND GetHwnd()
82 return m_hWnd;
85 // As EN_UPDATE message go to parent, need this. void UserSave(HANDLE FileHandle);
86 void UserOpen(HANDLE FileHandle);
88 void Move(int iDirection, int iDist);
89 void Delete(int iDirection, int iDist);
90 void SetKeyboardTarget(HWND hwnd);
92 // Overriding file virtual functions
93 //void TimeStampNewFiles(bool Value);
94 void New(const std::string & filename);
95 bool Open(const std::string & filename);
96 bool OpenAppendMode(const std::string & filename);
97 bool SaveAs(const std::string & filename);
98 bool Save();
99 // Functions for Windows GUI to call
100 void New();
101 void Open();
102 void OpenAppendMode();
103 void SaveAs();
104 std::string Import();
105 void SetDirty(); // Parent window gets notification Edit window has changed.
107 void Cut();
108 void Copy();
109 void CopyAll();
110 void Paste();
111 void SelectAll();
112 void Clear();
114 void SetEncoding(Dasher::Opts::FileEncodingFormats Encoding);
115 void SetFont(std::string Name, long Size);
117 void SetInterface(Dasher::CDasherInterfaceBase * DasherInterface);
119 // write some buffered output to file
120 void write_to_file();
122 // get the context from the current cursor position with max history
123 void get_new_context(std::string & str, int max);
125 // called when characters fall of the LHS of the screen
126 void output(const std::string & sText);
130 // remove the previous character
132 void deletetext(const std::string & sText);
134 // speak text
135 void speak(int what);
137 // set canvas
138 //void SetEditCanvas(CCanvas* canvas) {Canvas=canvas;}
140 void SetNewWithDate(bool bNewWithDate);
142 void HandleEvent(Dasher::CEvent *pEvent);
144 protected:
145 bool m_dirty;
146 LRESULT WndProc(HWND Window, UINT message, WPARAM wParam, LPARAM lParam);
148 private:
149 void HandleEditEvent(Dasher::CEvent *pEvent);
150 void HandleStop();
152 Dasher::CDasherInterfaceBase *m_pDasherInterface;
154 HWND Parent;
155 WNDPROC TextWndFunc;
157 HWND m_hTarget;
158 bool m_bForwardKeyboard;
160 HANDLE FileHandle; // Keeping a lock on files makes File I/O safer,
161 // especially for the append mode!
162 CFilenameGUI *m_FilenameGUI;
163 Tstring m_filename;
164 HWND textwindow;
165 bool AppendMode;
166 void TNew(const Tstring & filename);
167 bool TOpen(const Tstring & filename);
168 bool TOpenAppendMode(const Tstring & filename);
169 bool TSaveAs(const Tstring & filename);
171 HFONT m_Font;
172 std::string m_FontName;
173 long m_FontSize;
175 std::string m_Output; // UTF-8 to go to training file
176 UINT CodePage; // for font and possible for finding the encoding
177 Dasher::Opts::FileEncodingFormats m_Encoding; // file encoding option (may say to use codepage or user setting)
179 DWORD threadid;
180 HWND targetwindow;
181 bool textentry;
182 #ifdef _UNICODE
183 INPUT fakekey[2];
184 #endif
187 Tstring speech;
188 Tstring lastspeech;
189 Tstring newchar;
191 void InsertText(Tstring InsertText); // add symbol to edit control
193 CAppSettings *m_pAppSettings;
194 HWND m_hWnd;
196 // CCanvas* Canvas;
198 CDasherAction *m_pActionSpeech;
202 #endif /* #ifndef __Edit_h__ */