bsp
|
00001 #ifndef _WUTIL_H_ 00002 #define _WUTIL_H_ 00003 00004 // 00005 // WProfile 00006 // 00007 class WProfile 00008 { 00009 public: 00010 char section[MAX_PATH]; 00011 char inifile[MAX_PATH]; 00012 00013 WProfile(const char *section,const char *inifile); 00014 ~WProfile(); 00015 00016 int GetInt(const char *key,int defvalue = 0); 00017 bool GetString(const char *key,char *buffer,int size,const char *defvalue = ""); 00018 COLORREF GetColor(const char *key, COLORREF defvalue); 00019 bool WriteInt(const char *key, int value); 00020 bool WriteString(const char *key, const char *value); 00021 bool WriteColor(const char *key, const COLORREF value); 00022 }; 00023 00024 // 00025 // GetFont 00026 // 00027 extern HFONT GetFont(const char *fontname,int fontsize,int width=0,int weight=FW_NORMAL); 00028 00029 // 00030 // WPath - manage a filename with path, and provide original name plus ".." expanded name 00031 // 00032 /* 00033 class WPath { 00034 char *sourcepath; 00035 char *fullpath; 00036 int fplen; 00037 char *partdir, *partfile, *partext; 00038 bool dir_only; 00039 public: 00040 WPath(char *path, bool dir_only); 00041 ~WPath(); 00042 void setPath(char *path, bool dir_only); 00043 char *sourcePath(); 00044 char *fullPath(); 00045 char *dir(); 00046 char *file(); 00047 char *ext(); 00048 protected: 00049 void clean(); 00050 }; 00051 */ 00052 00053 class Path 00054 { 00055 public: 00056 char _path[300]; 00057 bool valid; 00058 static char _curdir[300]; 00059 Path() : valid(false) 00060 { 00061 *_path=0; 00062 } 00063 Path(char *text, ...); 00064 static void ChangeDir(Path p); 00065 void SetPath(char *text, ...); 00066 void _setpath(char*text,va_list args); 00067 bool Exists(); 00068 char *ext(); 00069 operator char*(); 00070 char *operator =(char*rhs); 00071 }; 00072 00073 // 00074 // WImageList 00075 // 00076 // this class allows a 'big' and 'small' image list. 00077 #define WIL_BIG_CX 20 00078 #define WIL_BIG_CY 20 00079 #define WIL_SMALL_CX 16 00080 #define WIL_SMALL_CY 15 00081 #define WIL_SMALL 0 00082 #define WIL_BIG 1 00083 #define WIL_HASH_SIZE 300 00084 typedef struct wil_data_s 00085 { 00086 HIMAGELIST him; 00087 int index; 00088 int cmd; 00089 wil_data_s *hash_next; 00090 wil_data_s *next; 00091 } wil_data_t; 00092 class WImageList 00093 { 00094 public: 00095 HIMAGELIST imbig, imsmall; 00096 WImageList(); 00097 ~WImageList(); 00098 int Add(char *bmp, int cmd_id); 00099 int GetImage(int cmd_id); 00100 private: 00101 wil_data_t *head; 00102 wil_data_t *hash[WIL_HASH_SIZE]; 00103 int hash_key(int cmd_id); 00104 wil_data_t *find_img(int cmd_id); 00105 int add_img(HIMAGELIST im,HBITMAP bmp,int cmd_id); 00106 }; 00107 00108 // 00109 // ColorDialog 00110 // 00111 class ColorDialog 00112 { 00113 public: 00114 ColorDialog(HWND owner,COLORREF defcolor,char *title = 0); 00115 static UINT CALLBACK CCHookProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam); 00116 bool Show(); 00117 CHOOSECOLOR cc; 00118 COLORREF result; // shortcut for cc.rgbResult 00119 char caption[256]; 00120 static COLORREF custColors[16]; // custom colors 00121 }; 00122 00123 00124 // 00125 // Popup 00126 // 00127 class Popup 00128 { 00129 public: 00130 Popup(); // create with window that will receive WM 00131 ~Popup(); // destroys menu 00132 // methods 00133 void Separator(); // add separator 00134 void Add(const char *text, int id, bool check = false); // add item 00135 void Add(const char *text, Popup submenu); // add submenu 00136 void Check(); // check next item 00137 void Gray(); // gray and disable next item 00138 void Show(HWND hwnd); // display popup 00139 // var 00140 HMENU menu; 00141 HWND hwnd; 00142 POINT pt; 00143 int lastid; 00144 int flags; 00145 }; 00146 00147 00148 // 00149 // WScroll 00150 // 00151 class WScroll 00152 { 00153 public: 00154 WScroll(HWND owner); 00155 void Update(); 00156 void Sync(); 00157 bool VScroll(WPARAM wParam, int pagesize); 00158 SCROLLINFO X, Y; 00159 HWND hwnd; 00160 }; 00161 00162 00163 // 00164 // linked list class to pass data to dialog listboxes. 00165 // 00166 typedef struct ListDataItem 00167 { 00168 char *str; // item text 00169 bool sel; // selected 00170 ListDataItem *next; 00171 } t_ListDataItem; 00172 00173 //ListData 00174 class ListData 00175 { 00176 public: 00177 ListData(); 00178 ~ListData(); 00179 void Add(const char *str, bool sel = false); 00180 void Clear(); 00181 bool hasNext(); 00182 const char *Next(); 00183 void FillList(HWND listbox); 00184 void FillCombo(HWND combobox); 00185 int count; 00186 private: 00187 void clear_items(); 00188 void reset_ptrs(); 00189 ListDataItem *items; // list of items 00190 ListDataItem **tail; // where to add last item 00191 ListDataItem **cur; // for tracking iterator position 00192 }; 00193 00194 00195 00196 #define TB_BMP_WIDTH 20 00197 #define TB_BMP_HEIGHT 20 00198 #define TB_BTN_WIDTH 22 00199 #define TB_BTN_HEIGHT 24 00200 #define TB_CTRL_PADDING 4 00201 00202 // 00203 // WReBar 00204 // 00205 00206 class WRebar 00207 { 00208 public: 00209 WRebar(HWND parent); 00210 ~WRebar(); 00211 void AddBand(HWND child); 00212 void Show(int index); 00213 void Hide(int index); 00214 00215 HWND hwnd; 00216 }; 00217 00218 00219 // 00220 // WToolBar 00221 // 00222 class WToolbar 00223 { 00224 public: 00225 WToolbar(HWND parent, int bmpcx=TB_BMP_WIDTH, int bmpcy = TB_BMP_HEIGHT, 00226 int btncx=TB_BTN_WIDTH, int btncy=TB_BTN_HEIGHT); 00227 ~WToolbar(); 00228 void AddSeparator(); 00229 void AddButton(int imgId, int cmdId); 00230 void AddControl(HWND hwndchild); 00231 00232 HWND hwnd; 00233 int index; // zero-based index position of band in rebar 00234 bool visible; // parent band visibility 00235 }; 00236 00237 00238 00239 // 00240 // WStatus 00241 // 00242 #define SB_HEIGHT 18 00243 #define SB_SPACE 2 00244 #define SB_MAXTEXT 127 00245 class WStatus 00246 { 00247 public: 00248 typedef struct partinfo_s 00249 { 00250 int cx; //width of part 00251 int left; //calculated left coord 00252 bool ownerdraw; //dont draw if set 00253 int bmpid; //draw bitmap instead of text if >= 0 00254 char text[SB_MAXTEXT]; //text 00255 } partinfo_t; 00256 00257 WStatus(HWND parent, int numParts); 00258 ~WStatus(); 00259 void DrawStatusBar(); 00260 bool IsVisible(); 00261 void Show(bool visible, bool redraw = false); 00262 void GetRect(RECT *rc); 00263 void GetPartRect(int index, RECT *rc); 00264 void SetFont(HFONT font); 00265 void SetPart(int index, int width, bool charwidth=false, bool ownerdraw=false); 00266 void SizePartToText(int index); 00267 void SetText(int index, const char *text, bool redraw = false); 00268 void SetText(const char *text, bool redraw = false); //set first item 00269 void Redraw(); 00270 void SetPartBmp(int index, int bmpid); 00271 void SetBmp(HBITMAP bmp, int piece_width); 00272 00273 protected: 00274 void ConstructMemDC(); 00275 void RemoveMemDC(); 00276 void CheckMemDC(); 00277 00278 HWND parent; 00279 HDC sdc; 00280 HBITMAP sbmp; 00281 HFONT font; 00282 HBITMAP bmp_strip; 00283 int bmp_cx; 00284 RECT sbrc; 00285 int numParts; 00286 partinfo_t *parts; 00287 bool visible; 00288 }; 00289 00290 00291 // 00292 // Keyboard Settings 00293 // 00294 typedef struct KBAccel_s 00295 { 00296 ACCEL key; 00297 KBAccel_s *next; 00298 } KBAccel_t; 00299 00300 class KBSettings 00301 { 00302 public: 00303 KBSettings(); 00304 KBSettings(const KBSettings& kbs); 00305 ~KBSettings(); 00306 void ClearKeys(); // delete KBAccel_t list 00307 void CopyKeys(const KBSettings& source); //copy keys from source. keys must be cleared first!! 00308 // void LoadAccels(HACCEL accel); // load *keys from an existing table 00309 HACCEL CreateAccelTable(); // create table from *keys 00310 void OverwriteAndActivate(KBSettings *dest_kbset); // copy KBSettings and recreate main accel table 00311 void SaveToDisk(); // save keyboard settings 00312 void LoadFromDisk(char *filename); // load keyboard settings 00313 static void ShowKeys(HACCEL accel); // show all key mappings in help window 00314 static char* AccelToText(ACCEL k, char* buf); // convert ACCEL to text 00315 char* AccelToCfgText(ACCEL k, char* buf); // convert ACCEL to config line 00316 bool ParseCfgText(char *mod, char *key, char*cmd, ACCEL *ret); // convert config line to ACCEL 00317 //nowhere to load defaults from... - void RestoreDefaults(HACCEL defaccel); // reset keys to just those in resource 00318 void ShowAccelsForCommand(int cmd, char *out, int outlen); // return string of all shortcuts used by cmd 00319 ACCEL *FindAccel(ACCEL k, bool matchkey, bool matchcmd); // find ACCEL in *keys 00320 void AddAccel(ACCEL k); // add key to *keys 00321 bool AddReplaceAccel(ACCEL *k); // add key, replace if exists 00322 bool RemoveAccel(ACCEL k); // remove by shortcut, ignores cmd 00323 00324 protected: 00325 KBAccel_t *keys; 00326 }; 00327 00328 00329 00330 00331 /* 00332 // 00333 // Registry 00334 // 00335 #define REG_BASEPATH "software\\BSP Quake Editor" 00336 class Registry { 00337 public: 00338 Registry(const char *path); 00339 ~Registry(); 00340 void ChangePath(const char *path); 00341 00342 bool GetValue(const char *name, DWORD *value); 00343 bool GetValue(const char *name, char *value, int maxlen); 00344 00345 bool SetValue(const char *name, DWORD value); 00346 bool SetValue(const char *name, const char *value); 00347 private: 00348 HKEY key; 00349 char path[256]; 00350 }; 00351 */ 00352 00353 // 00354 // WindowPlacement 00355 // 00356 #define WP_REGNAME "Window Positions" 00357 class WindowPlacement 00358 { 00359 public: 00360 WindowPlacement() {}; 00361 virtual const char *WP_WindowName() = 0; 00362 virtual HWND WP_GetHwnd() = 0; 00363 00364 //functions per window, per slot 00365 void WP_GetPos(); //fill wp and zorder 00366 void WP_SetPos(); //set window position from wp (no zorder here) 00367 void WP_SavePos(int slot); //save to config 00368 void WP_LoadPos(int slot); //load from config 00369 00370 WINDOWPLACEMENT WP_wp; 00371 int WP_zorder; 00372 bool WP_isvalid; //set after changing WP_wp 00373 00374 //all windows, one slot 00375 static void SavePositions(int slot); //save slot to file 00376 static void LoadPositions(int slot); //load slot from file 00377 }; 00378 00379 // 00380 // DrawButton 00381 // 00382 00383 #define DRAWB_HIDE 0 00384 #define DRAWB_UP 1 00385 #define DRAWB_DOWN 2 00386 #define DRAWB_ELLIPSES 3 00387 class DrawButton 00388 { 00389 public: 00390 DrawButton(HWND parent, int id, int type, RECT *rc); 00391 00392 HWND parent; 00393 int id; 00394 int type; 00395 RECT rc; 00396 bool mdown, pushed, enabled, visible; 00397 00398 bool mousedown(POINT pt); 00399 bool mouseup(POINT pt); 00400 void mousemove(POINT pt); 00401 void redraw(); 00402 void redraw(HDC hdc); 00403 }; 00404 00405 00406 #endif //_WUTIL_H_