1 | #ifndef __cmtw_utils_h__
|
---|
2 | #define __cmtw_utils_h__
|
---|
3 |
|
---|
4 | #include <windows.h>
|
---|
5 | #include "cmt.h"
|
---|
6 |
|
---|
7 | //-------------------------------------------------------------------
|
---|
8 | class WWindow
|
---|
9 | {
|
---|
10 | public:
|
---|
11 | WWindow ();
|
---|
12 |
|
---|
13 | void enable ();
|
---|
14 | void disable ();
|
---|
15 | void show ();
|
---|
16 | void hide ();
|
---|
17 |
|
---|
18 | protected:
|
---|
19 | HWND _window;
|
---|
20 | };
|
---|
21 | //-------------------------------------------------------------------
|
---|
22 |
|
---|
23 | //-------------------------------------------------------------------
|
---|
24 | class WEdit : public WWindow
|
---|
25 | {
|
---|
26 | public:
|
---|
27 | WEdit ();
|
---|
28 | WEdit (HWND edit);
|
---|
29 | WEdit (HWND container, int id);
|
---|
30 |
|
---|
31 | void init (HWND container, int id);
|
---|
32 | WEdit& operator = (HWND edit);
|
---|
33 | void set (const char* text);
|
---|
34 | void set (const cmt_string& text);
|
---|
35 | void clear ();
|
---|
36 | cmt_string get () const;
|
---|
37 | void copy (const WEdit& other);
|
---|
38 |
|
---|
39 | private:
|
---|
40 | HWND _edit;
|
---|
41 | };
|
---|
42 | //-------------------------------------------------------------------
|
---|
43 |
|
---|
44 | //-------------------------------------------------------------------
|
---|
45 | class WRadio : public WWindow
|
---|
46 | {
|
---|
47 | public:
|
---|
48 | WRadio ();
|
---|
49 | WRadio (HWND radio);
|
---|
50 | WRadio (HWND container, int id);
|
---|
51 |
|
---|
52 | void init (HWND container, int id);
|
---|
53 | WRadio& operator = (HWND radio);
|
---|
54 | void set (bool state);
|
---|
55 | bool get () const;
|
---|
56 | void copy (const WRadio& other);
|
---|
57 |
|
---|
58 | private:
|
---|
59 | HWND _radio;
|
---|
60 | };
|
---|
61 | //-------------------------------------------------------------------
|
---|
62 |
|
---|
63 | //-------------------------------------------------------------------
|
---|
64 | class WList : public WWindow
|
---|
65 | {
|
---|
66 | public:
|
---|
67 | WList ();
|
---|
68 | WList (HWND list);
|
---|
69 | WList (HWND container, int id);
|
---|
70 |
|
---|
71 | void init (HWND container, int id);
|
---|
72 | WList& operator = (HWND list);
|
---|
73 | void append (const char* text);
|
---|
74 | void append (const cmt_string& text);
|
---|
75 | void insert (int index, const cmt_string& text);
|
---|
76 | void modify (int index, const cmt_string& text);
|
---|
77 | void delete_item (int index);
|
---|
78 | void clear ();
|
---|
79 | void cancel_selection ();
|
---|
80 | int get_selected_index ();
|
---|
81 | void set_selected_index (int index);
|
---|
82 | cmt_string get_selected ();
|
---|
83 | int get_item_count () const;
|
---|
84 | cmt_string get_item (int index) const;
|
---|
85 | void get_item (int index, cmt_string& text) const;
|
---|
86 | int get_item_length (int index) const;
|
---|
87 | void copy (const WList& other);
|
---|
88 | void set (const CmtSystem::cmt_string_vector& v, int first = 0);
|
---|
89 | void set (const cmt_string& file_name);
|
---|
90 | void get (CmtSystem::cmt_string_vector& v) const;
|
---|
91 | void get (cmt_string& s) const;
|
---|
92 | void set_extent ();
|
---|
93 | int get_width () const;
|
---|
94 | int get_extent () const;
|
---|
95 |
|
---|
96 | private:
|
---|
97 | HWND _list;
|
---|
98 | int _selected_index;
|
---|
99 | int _width;
|
---|
100 | };
|
---|
101 | //-------------------------------------------------------------------
|
---|
102 |
|
---|
103 | //-------------------------------------------------------------------
|
---|
104 | class WTab
|
---|
105 | {
|
---|
106 | public:
|
---|
107 | void add (const cmt_string& key, WWindow& window, WRadio& radio);
|
---|
108 | void select (const cmt_string& key);
|
---|
109 |
|
---|
110 | private:
|
---|
111 | cmt_vector<cmt_string> _keys;
|
---|
112 | cmt_vector<WWindow*> _windows;
|
---|
113 | cmt_vector<WRadio*> _radios;
|
---|
114 | };
|
---|
115 | //-------------------------------------------------------------------
|
---|
116 |
|
---|
117 | /*---------------------------------------------------------------------*/
|
---|
118 | class mysb :public streambuf
|
---|
119 | {
|
---|
120 | public:
|
---|
121 | mysb (WList& list);
|
---|
122 | ~mysb ();
|
---|
123 |
|
---|
124 | private:
|
---|
125 | int_type overflow (int_type c);
|
---|
126 | int underflow ();
|
---|
127 |
|
---|
128 | streambuf* _old;
|
---|
129 | cmt_string* _buf;
|
---|
130 | WList& _list;
|
---|
131 | };
|
---|
132 | /*---------------------------------------------------------------------*/
|
---|
133 |
|
---|
134 | /*---------------------------------------------------------------------*/
|
---|
135 | class WDialog
|
---|
136 | {
|
---|
137 | public:
|
---|
138 | WDialog ();
|
---|
139 |
|
---|
140 | virtual void action (UINT message_type,
|
---|
141 | WPARAM parameter1,
|
---|
142 | LPARAM parameter2);
|
---|
143 | virtual void init_action ();
|
---|
144 | virtual void menu_action (int menu_item,
|
---|
145 | WPARAM parameter1,
|
---|
146 | LPARAM parameter2);
|
---|
147 |
|
---|
148 | protected:
|
---|
149 |
|
---|
150 | int run (HINSTANCE instance, HWND father, int id);
|
---|
151 |
|
---|
152 | HWND _dialog;
|
---|
153 |
|
---|
154 | private:
|
---|
155 |
|
---|
156 | static LRESULT CALLBACK proc (HWND dialog,
|
---|
157 | UINT message_type,
|
---|
158 | WPARAM parameter1,
|
---|
159 | LPARAM parameter2);
|
---|
160 | };
|
---|
161 | /*---------------------------------------------------------------------*/
|
---|
162 |
|
---|
163 | /*---------------------------------------------------------------------*/
|
---|
164 | class TextEditor : public WDialog
|
---|
165 | {
|
---|
166 | public:
|
---|
167 | TextEditor (cmt_string& ref);
|
---|
168 |
|
---|
169 | int run (HINSTANCE instance, HWND father);
|
---|
170 | virtual void action (UINT message_type,
|
---|
171 | WPARAM parameter1,
|
---|
172 | LPARAM parameter2);
|
---|
173 | void init_action ();
|
---|
174 | void menu_action (int menu_item, WPARAM parameter1, LPARAM parameter2);
|
---|
175 |
|
---|
176 | private:
|
---|
177 | cmt_string& _ref;
|
---|
178 | WEdit _edit;
|
---|
179 | };
|
---|
180 | /*---------------------------------------------------------------------*/
|
---|
181 |
|
---|
182 | /*---------------------------------------------------------------------*/
|
---|
183 | class ListEditor : public WDialog
|
---|
184 | {
|
---|
185 | public:
|
---|
186 | ListEditor (WList& list);
|
---|
187 |
|
---|
188 | int run (HINSTANCE instance, HWND father);
|
---|
189 | virtual void action (UINT message_type,
|
---|
190 | WPARAM parameter1,
|
---|
191 | LPARAM parameter2);
|
---|
192 | void set_position (int index);
|
---|
193 | void init_action ();
|
---|
194 | void menu_action (int menu_item, WPARAM parameter1, LPARAM parameter2);
|
---|
195 |
|
---|
196 | private:
|
---|
197 | WList& _ref_list;
|
---|
198 | WList _list;
|
---|
199 | HINSTANCE _instance;
|
---|
200 | int _selected_index;
|
---|
201 | int _last_index;
|
---|
202 | int _ref_selected_index;
|
---|
203 | };
|
---|
204 | /*---------------------------------------------------------------------*/
|
---|
205 |
|
---|
206 | /*---------------------------------------------------------------------*/
|
---|
207 | class CmtMutex
|
---|
208 | {
|
---|
209 | public:
|
---|
210 | CmtMutex ();
|
---|
211 | ~CmtMutex ();
|
---|
212 |
|
---|
213 | void lock ();
|
---|
214 | void unlock ();
|
---|
215 |
|
---|
216 | private:
|
---|
217 | CRITICAL_SECTION _section;
|
---|
218 | };
|
---|
219 | /*---------------------------------------------------------------------*/
|
---|
220 |
|
---|
221 | /*---------------------------------------------------------------------*/
|
---|
222 | class CmtThread
|
---|
223 | {
|
---|
224 | public:
|
---|
225 | CmtThread ();
|
---|
226 | virtual ~CmtThread ();
|
---|
227 |
|
---|
228 | virtual void run ();
|
---|
229 | bool is_running ();
|
---|
230 | void set_running ();
|
---|
231 | void reset_running ();
|
---|
232 | bool start ();
|
---|
233 | void stop ();
|
---|
234 |
|
---|
235 | private:
|
---|
236 | static void run_it (CmtThread* thread);
|
---|
237 |
|
---|
238 | HANDLE _thread;
|
---|
239 | DWORD _id;
|
---|
240 | CmtMutex _mutex;
|
---|
241 | bool _shutdown;
|
---|
242 | bool _running;
|
---|
243 | };
|
---|
244 | /*---------------------------------------------------------------------*/
|
---|
245 |
|
---|
246 |
|
---|
247 | #endif
|
---|