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