1 /* 2 * HT Editor 3 * htobj.h 4 * 5 * Copyright (C) 1999-2002 Stefan Weyergraf 6 * 7 * This program is free software; you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License version 2 as 9 * published by the Free Software Foundation. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program; if not, write to the Free Software 18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 19 */ 20 21 #ifndef __HTOBJ_H__ 22 #define __HTOBJ_H__ 23 24 class ht_view; 25 class ht_group; 26 27 #include "io/types.h" 28 #include "io/display.h" 29 #include "data.h" 30 31 struct palette { 32 uint size; 33 vcp *data; 34 }; 35 36 /* messages (like in "MESS of AGES") */ 37 #define msg_message 0x00000000 38 #define HT_MESSAGE(m) (msg_message+(m)) 39 40 #define msg_empty HT_MESSAGE(0) 41 #define msg_retval HT_MESSAGE(1) 42 #define msg_draw HT_MESSAGE(2) 43 #define msg_keypressed HT_MESSAGE(3) 44 #define msg_kill HT_MESSAGE(4) 45 #define msg_complete_init HT_MESSAGE(5) 46 #define msg_funcexec HT_MESSAGE(6) 47 #define msg_funcquery HT_MESSAGE(7) 48 #define msg_menucapquery HT_MESSAGE(8) 49 #define msg_menuquery HT_MESSAGE(9) 50 #define msg_button_pressed HT_MESSAGE(10) 51 #define msg_dirtyview HT_MESSAGE(11) 52 #define msg_config_changed HT_MESSAGE(12) 53 #define msg_accept_close HT_MESSAGE(13) 54 #define msg_file_changed HT_MESSAGE(14) 55 #define msg_get_scrollinfo HT_MESSAGE(15) 56 #define msg_get_pindicator HT_MESSAGE(16) 57 #define msg_get_analyser HT_MESSAGE(17) 58 #define msg_set_analyser HT_MESSAGE(18) // (Analyser *) 59 #define msg_postinit HT_MESSAGE(19) 60 #define msg_contextmenuquery HT_MESSAGE(20) 61 #define msg_project_changed HT_MESSAGE(21) 62 #define msg_vstate_save HT_MESSAGE(22) // (Object *data, ht_view *) 63 #define msg_vstate_restore HT_MESSAGE(23) // (Object *data) 64 #define msg_goto_offset HT_MESSAGE(24) // (FileOfs ofs) 65 66 #define msg_filesize_changed HT_MESSAGE(100) 67 #define msg_log_changed HT_MESSAGE(101) 68 69 #define gsi_hscrollbar 1 70 #define gsi_vscrollbar 2 71 72 struct gsi_scrollbar_t { 73 int pstart; 74 int psize; 75 }; 76 77 /* message types */ 78 #define mt_empty 0 79 #define mt_broadcast 1 80 #define mt_preprocess 2 81 #define mt_postprocess 3 82 83 /* 84 * CLASS ht_view 85 */ 86 87 /* options */ 88 #define VO_OWNBUFFER 1 89 #define VO_BROWSABLE 2 90 #define VO_SELECTABLE 4 91 #define VO_SELBOUND 8 92 #define VO_PREPROCESS 16 93 #define VO_POSTPROCESS 32 94 #define VO_MOVE 64 95 #define VO_RESIZE 128 96 #define VO_FORMAT_VIEW 256 97 #define VO_TRANSPARENT_CHARS 512 98 99 /* grow modes */ 100 101 #define VIEW_DEBUG_NAME(name) ht_view::view_debug_name=name; 102 103 #define GMV_TOP 0 104 #define GMV_BOTTOM 1 105 #define GMV_FIT 2 106 107 #define GMH_LEFT 0 108 #define GMH_RIGHT 1 109 #define GMH_FIT 2 110 111 #define GET_GM_H(gm) ((gm)>>16) 112 #define GET_GM_V(gm) ((gm)&0xffff) 113 114 #define MK_GM(gmh, gmv) ((gmv) | ((gmh)<<16)) 115 116 void clearmsg(htmsg *msg); 117 118 class ht_view: public Object { 119 protected: 120 bool view_is_dirty; 121 122 void cleanview(); 123 virtual const char *defaultpalette(); 124 virtual const char *defaultpaletteclass(); 125 virtual void reloadpalette(); 126 public: 127 bool focused; 128 bool enabled; 129 ht_group *group; 130 int options; 131 char *desc; 132 int browse_idx; 133 Display *buf; 134 ht_view *prev, *next; 135 136 Bounds size; 137 Bounds vsize; /* visual Bounds */ 138 uint growmode; 139 uint g_hdist, g_vdist; 140 141 palette pal; 142 const char *pal_class; 143 const char *pal_name; 144 145 /*debug:*/const char *view_debug_name; 146 ht_view()147 ht_view() {} ht_view(BuildCtorArg & a)148 ht_view(BuildCtorArg&a): Object(a) {}; 149 150 void init(Bounds *b, int options, const char *desc); 151 virtual void done(); 152 /* new */ 153 virtual int aclone(); 154 /* 155 int buf_lprint(int x, int y, int c, int l, const char *text, Codepage cp = CP_DEVICE); 156 int buf_lprintw(int x, int y, int c, int l, const AbstractChar *text, Codepage cp = CP_DEVICE); 157 int buf_print(int x, int y, int c, const char *text, Codepage cp = CP_DEVICE); 158 void buf_printchar(int x, int y, int c, int ch, Codepage cp = CP_DEVICE); 159 int buf_printf(int x, int y, int c, Codepage cp, const char *format, ...); 160 int buf_printw(int x, int y, int c, const AbstractChar *text, Codepage cp = CP_DEVICE); 161 */ 162 virtual int childcount() const; 163 void clear(int color); 164 virtual void clipbounds(Bounds *b); 165 virtual void config_changed(); 166 virtual int countselectables(); 167 void databuf_free(void *handle); 168 void *databuf_get(void *buf, int bufsize); 169 void databuf_set(void *buf, int bufsize); 170 virtual int datasize(); 171 void dirtyview(); 172 virtual void disable(); 173 void disable_buffering(); 174 virtual void draw(); 175 virtual void enable(); 176 void enable_buffering(); 177 virtual int enum_start(); 178 virtual ht_view *enum_next(int *handle); 179 bool exposed(); 180 void fill(int x, int y, int w, int h, int c, char chr, Codepage cp = CP_DEVICE); 181 virtual bool focus(ht_view *view); 182 void getbounds(Bounds *b); 183 virtual void getminbounds(int *width, int *height); 184 vcp getcolor(uint index); 185 virtual void getdata(ObjectStream &s); 186 virtual ht_view *getfirstchild(); 187 virtual uint getnumber(); 188 const char *getpalette(); 189 virtual ht_view *getselected(); 190 virtual void handlemsg(htmsg *msg); 191 void hidecursor(); 192 int isviewdirty(); 193 virtual int isaclone(ht_view *view); 194 virtual void load(ObjectStream &s); 195 virtual void move(int rx, int ry); 196 virtual ObjectID getObjectID() const; 197 bool pointvisible(int x, int y); 198 virtual void receivefocus(); 199 virtual void redraw(); 200 void relocate_to(ht_view *view); 201 virtual void resize(int rw, int rh); 202 virtual void releasefocus(); 203 virtual int select(ht_view *view); 204 virtual void selectfirst(); 205 virtual void selectlast(); 206 void sendmsg(htmsg *msg); 207 void sendmsg(int msg, int data1=0, int data2=0); 208 void sendmsg(int msg, void *data1, void *data2=0); 209 void setbounds(Bounds *b); 210 void setvisualbounds(Bounds *b); 211 void setcursor(int x, int y, CursorMode c=CURSOR_NORMAL); 212 virtual void setdata(ObjectStream &s); 213 virtual void setgroup(ht_group *group); 214 virtual void setnumber(uint number); 215 void setoptions(int options); 216 virtual void setpalette(const char *pal_name); 217 void setpalettefull(const char *pal_name, const char *pal_class); 218 virtual void store(ObjectStream &s) const; 219 void unrelocate_to(ht_view *view); 220 }; 221 222 /* 223 * Easier use of data buffers: 224 */ 225 226 class ViewDataBuf: public Object { 227 void *mBuf; 228 ht_view *mView; 229 public: ViewDataBuf(ht_view * view,void * buf,int bufsize)230 ViewDataBuf(ht_view *view, void *buf, int bufsize) 231 : mBuf(view->databuf_get(buf, bufsize)), mView(view) 232 { 233 } 234 ~ViewDataBuf()235 virtual ~ViewDataBuf() 236 { 237 mView->databuf_free(mBuf); 238 } 239 }; 240 241 class ht_dialog_widget: public ht_view { 242 public: 243 void getminbounds(int *width, int *height); 244 }; 245 246 /* 247 * CLASS ht_group 248 */ 249 250 class ht_group: public ht_view { 251 protected: 252 int view_count; 253 254 public: 255 ht_view *first, *current, *last; 256 void *shared_data; 257 ht_group()258 ht_group() {} ht_group(BuildCtorArg & a)259 ht_group(BuildCtorArg&a): ht_view(a) {}; 260 261 void init(Bounds *b, int options, const char *desc); 262 virtual void done(); 263 /* overwritten */ 264 virtual int childcount() const; 265 virtual int countselectables(); 266 virtual int datasize(); 267 virtual int enum_start(); 268 virtual ht_view *enum_next(int *handle); 269 virtual bool focus(ht_view *view); 270 virtual void getdata(ObjectStream &s); 271 virtual ht_view *getfirstchild(); 272 virtual void getminbounds(int *width, int *height); 273 virtual ht_view *getselected(); 274 virtual void handlemsg(htmsg *msg); 275 virtual int isaclone(ht_view *view); 276 int isviewdirty(); 277 virtual void load(ObjectStream &s); 278 virtual void move(int x, int y); 279 virtual ObjectID getObjectID() const; 280 void putontop(ht_view *view); 281 virtual void receivefocus(); 282 virtual void resize(int rw, int rh); 283 virtual void releasefocus(); 284 virtual int select(ht_view *view); 285 virtual void selectfirst(); 286 virtual void selectlast(); 287 virtual void setdata(ObjectStream &s); 288 virtual void setpalette(const char *pal_name); 289 virtual void store(ObjectStream &s) const; 290 /* new */ 291 virtual void reorder_view(ht_view *v, int rx, int ry); 292 void remove(ht_view *view); 293 virtual void insert(ht_view *view); 294 bool focusnext(); 295 bool focusprev(); 296 ht_view *get_by_browse_idx(int i); 297 }; 298 299 /* 300 * CLASS ht_xgroup 301 */ 302 303 class ht_xgroup: public ht_group { 304 public: ht_xgroup()305 ht_xgroup() {} ht_xgroup(BuildCtorArg & a)306 ht_xgroup(BuildCtorArg&a): ht_group(a) {}; 307 308 void init(Bounds *b, int options, const char *desc); 309 virtual void done(); 310 /* overwritten */ 311 virtual int countselectables(); 312 virtual void handlemsg(htmsg *msg); 313 virtual int isaclone(ht_view *view); 314 virtual void load(ObjectStream &s); 315 virtual ObjectID getObjectID() const; 316 virtual void redraw(); 317 virtual void selectfirst(); 318 virtual void selectlast(); 319 virtual void store(ObjectStream &s) const; 320 }; 321 322 /* 323 * CLASS ht_scrollbar 324 */ 325 326 class ht_scrollbar: public ht_view { 327 protected: 328 int pstart, psize; 329 palette *gpal; 330 bool isvertical; 331 public: ht_scrollbar()332 ht_scrollbar() {} ht_scrollbar(BuildCtorArg & a)333 ht_scrollbar(BuildCtorArg&a): ht_view(a) {}; 334 335 void init(Bounds *b, palette *gpal, bool isvertical); 336 virtual void done(); 337 /* overwritten */ 338 virtual void enable(); 339 virtual void disable(); 340 virtual void draw(); 341 virtual ObjectID getObjectID() const; 342 virtual void getminbounds(int *width, int *height); 343 /* new */ 344 virtual void setpos(int pstart, int psize); 345 }; 346 347 /* 348 * CLASS ht_text 349 */ 350 351 class ht_text: public ht_dialog_widget { 352 public: 353 /* new */ 354 virtual void settext(const char *text); 355 }; 356 357 /* 358 * CLASS ht_frame 359 */ 360 361 #define FS_KILLER 1 362 #define FS_TITLE 2 363 #define FS_NUMBER 4 364 #define FS_RESIZE 8 365 #define FS_MOVE 16 366 #define FS_THICK 32 367 368 #define FST_FOCUSED 0 369 #define FST_UNFOCUSED 1 370 #define FST_MOVE 2 371 #define FST_RESIZE 3 372 373 class ht_frame: public ht_text { 374 protected: 375 uint number; 376 uint style; 377 uint framestate; 378 379 /* new */ 380 virtual vcp getcurcol_normal(); 381 virtual vcp getcurcol_killer(); 382 public: 383 void init(Bounds *b, const char *desc, uint style, uint number=0); 384 virtual void done(); 385 /* overwritten */ 386 virtual void draw(); 387 virtual uint getnumber(); 388 virtual ObjectID getObjectID() const; 389 virtual void setnumber(uint number); 390 virtual void settext(const char *text); 391 /* new */ 392 uint getstyle(); 393 void setframestate(uint framestate); 394 void setstyle(uint style); 395 }; 396 397 /* 398 * CLASS ht_window 399 */ 400 401 #define WAC_NORMAL 0 402 #define WAC_MOVE 1 403 #define WAC_RESIZE 2 404 405 class ht_window: public ht_group { 406 protected: 407 ht_frame *frame; 408 ht_scrollbar *hscrollbar; 409 ht_scrollbar *vscrollbar; 410 ht_text *pindicator; 411 uint number; 412 413 int action_state; 414 415 bool next_action_state(); 416 public: ht_window()417 ht_window() {} ht_window(BuildCtorArg & a)418 ht_window(BuildCtorArg&a): ht_group(a) {}; 419 420 void init(Bounds *b, const char *desc, uint framestyle, uint number=0); 421 virtual void done(); 422 /* overwritten */ 423 virtual void draw(); 424 virtual uint getnumber(); 425 virtual void handlemsg(htmsg *msg); 426 virtual void insert(ht_view *view); 427 virtual void load(ObjectStream &s); 428 virtual ObjectID getObjectID() const; 429 virtual void receivefocus(); 430 virtual void releasefocus(); 431 virtual void redraw(); 432 virtual void setnumber(uint number); 433 virtual void store(ObjectStream &s) const; 434 /* new */ 435 void getclientarea(Bounds *b); 436 ht_frame *getframe(); 437 void setframe(ht_frame *frame); 438 void sethscrollbar(ht_scrollbar *scrollbar); 439 void setpindicator(ht_text *pindicator); 440 void settitle(char *title); 441 void setvscrollbar(ht_scrollbar *scrollbar); 442 }; 443 444 bool scrollbar_pos(sint64 start, sint64 size, sint64 all, int *pstart, int *psize); 445 446 /* 447 * CLASS ht_hbar 448 */ 449 450 class ht_hbar: public ht_view { 451 public: 452 /* overwritten */ 453 virtual void draw(); 454 }; 455 456 /* 457 * CLASS ht_vbar 458 */ 459 460 class ht_vbar: public ht_view { 461 public: 462 /* overwritten */ 463 virtual void draw(); 464 }; 465 466 /* 467 * INIT 468 */ 469 470 bool init_obj(); 471 472 /* 473 * DONE 474 */ 475 476 void done_obj(); 477 478 #endif /* !__HTOBJ_H__ */ 479