comparison dw.hpp @ 2877:6f31b7991fa0

C++: Fix Combobox class by making the parent classes virtual. Also some minor source code cleanup, make sure visibility is explicit.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Tue, 20 Dec 2022 04:45:13 +0000
parents e201a984d855
children a290573a8b7c
comparison
equal deleted inserted replaced
2876:e201a984d855 2877:6f31b7991fa0
48 HWND GetHWND() { return hwnd; } 48 HWND GetHWND() { return hwnd; }
49 int Unpack() { return dw_box_unpack(hwnd); } 49 int Unpack() { return dw_box_unpack(hwnd); }
50 void SetStyle(unsigned long style, unsigned long mask) { dw_window_set_style(hwnd, style, mask); } 50 void SetStyle(unsigned long style, unsigned long mask) { dw_window_set_style(hwnd, style, mask); }
51 void SetTooltip(char *bubbletext) { dw_window_set_tooltip(hwnd, bubbletext); } 51 void SetTooltip(char *bubbletext) { dw_window_set_tooltip(hwnd, bubbletext); }
52 int SetColor(unsigned long fore, unsigned long back) { return dw_window_set_color(hwnd, fore, back); } 52 int SetColor(unsigned long fore, unsigned long back) { return dw_window_set_color(hwnd, fore, back); }
53 void SetData(const char *dataname, void *data) { dw_window_set_data(hwnd, dataname, data); }
54 void *GetData(const char *dataname) { return dw_window_get_data(hwnd, dataname); }
53 }; 55 };
54 56
55 // Box class is a packable object 57 // Box class is a packable object
56 class Boxes : public Widget 58 class Boxes : virtual public Widget
57 { 59 {
58 public: 60 public:
59 // User functions 61 // User functions
60 void PackStart(Widget *item, int width, int height, int hsize, int vsize, int pad) { 62 void PackStart(Widget *item, int width, int height, int hsize, int vsize, int pad) {
61 dw_box_pack_start(hwnd, item ? item->GetHWND() : DW_NOHWND, width, height, hsize, vsize, pad); } 63 dw_box_pack_start(hwnd, item ? item->GetHWND() : DW_NOHWND, width, height, hsize, vsize, pad); }
69 } 71 }
70 }; 72 };
71 73
72 class Box : public Boxes 74 class Box : public Boxes
73 { 75 {
76 public:
74 // Constructors 77 // Constructors
75 Box(int type, int pad) { SetHWND(dw_box_new(type, pad)); } 78 Box(int type, int pad) { SetHWND(dw_box_new(type, pad)); }
76 Box(int type) { SetHWND(dw_box_new(type, 0)); } 79 Box(int type) { SetHWND(dw_box_new(type, 0)); }
77 }; 80 };
78 81
131 virtual int OnDelete() { dw_signal_disconnect_by_name(hwnd, DW_SIGNAL_DELETE); return FALSE; } 134 virtual int OnDelete() { dw_signal_disconnect_by_name(hwnd, DW_SIGNAL_DELETE); return FALSE; }
132 virtual int OnConfigure(int width, int height) { dw_signal_disconnect_by_name(hwnd, DW_SIGNAL_CONFIGURE); return FALSE; }; 135 virtual int OnConfigure(int width, int height) { dw_signal_disconnect_by_name(hwnd, DW_SIGNAL_CONFIGURE); return FALSE; };
133 }; 136 };
134 137
135 // Base class for several types of buttons 138 // Base class for several types of buttons
136 class Buttons : public Widget 139 class Buttons : virtual public Widget
137 { 140 {
138 private: 141 private:
139 static int _OnClicked(HWND window, void *data) { return reinterpret_cast<Buttons *>(data)->OnClicked(); } 142 static int _OnClicked(HWND window, void *data) { return reinterpret_cast<Buttons *>(data)->OnClicked(); }
140 protected: 143 protected:
141 void Setup() { 144 void Setup() {
177 BitmapButton(const char *text, const char *file) { SetHWND(dw_bitmapbutton_new_from_file(text, 0, file)); Setup(); } 180 BitmapButton(const char *text, const char *file) { SetHWND(dw_bitmapbutton_new_from_file(text, 0, file)); Setup(); }
178 BitmapButton(const char *text, unsigned long id, const char *data, int len) { SetHWND(dw_bitmapbutton_new_from_data(text, id, data, len)); Setup(); } 181 BitmapButton(const char *text, unsigned long id, const char *data, int len) { SetHWND(dw_bitmapbutton_new_from_data(text, id, data, len)); Setup(); }
179 BitmapButton(const char *text, const char *data, int len) { SetHWND(dw_bitmapbutton_new_from_data(text, 0, data, len)); Setup(); } 182 BitmapButton(const char *text, const char *data, int len) { SetHWND(dw_bitmapbutton_new_from_data(text, 0, data, len)); Setup(); }
180 }; 183 };
181 184
182 class CheckBoxes : public TextButton 185 class CheckBoxes : virtual public TextButton
183 { 186 {
184 public: 187 public:
185 // User functions 188 // User functions
186 void Set(int value) { dw_checkbox_set(hwnd, value); } 189 void Set(int value) { dw_checkbox_set(hwnd, value); }
187 int Get() { return dw_checkbox_get(hwnd); } 190 int Get() { return dw_checkbox_get(hwnd); }
188 }; 191 };
189 192
190 class CheckBox : public CheckBoxes 193 class CheckBox : public CheckBoxes
191 { 194 {
195 public:
192 // Constructors 196 // Constructors
193 CheckBox(const char *text, unsigned long id) { SetHWND(dw_checkbox_new(text, id)); Setup(); } 197 CheckBox(const char *text, unsigned long id) { SetHWND(dw_checkbox_new(text, id)); Setup(); }
194 CheckBox(unsigned long id) { SetHWND(dw_checkbox_new("", id)); Setup(); } 198 CheckBox(unsigned long id) { SetHWND(dw_checkbox_new("", id)); Setup(); }
195 CheckBox(const char *text) { SetHWND(dw_checkbox_new(text, 0)); Setup(); } 199 CheckBox(const char *text) { SetHWND(dw_checkbox_new(text, 0)); Setup(); }
196 CheckBox() { SetHWND(dw_checkbox_new("", 0)); Setup(); } 200 CheckBox() { SetHWND(dw_checkbox_new("", 0)); Setup(); }
197 }; 201 };
198 202
199 class RadioButton : public CheckBoxes 203 class RadioButton : public CheckBoxes
200 { 204 {
205 public:
201 // Constructors 206 // Constructors
202 RadioButton(const char *text, unsigned long id) { SetHWND(dw_radiobutton_new(text, id)); Setup(); } 207 RadioButton(const char *text, unsigned long id) { SetHWND(dw_radiobutton_new(text, id)); Setup(); }
203 RadioButton(unsigned long id) { SetHWND(dw_radiobutton_new("", id)); Setup(); } 208 RadioButton(unsigned long id) { SetHWND(dw_radiobutton_new("", id)); Setup(); }
204 RadioButton(const char *text) { SetHWND(dw_radiobutton_new(text, 0)); Setup(); } 209 RadioButton(const char *text) { SetHWND(dw_radiobutton_new(text, 0)); Setup(); }
205 RadioButton() { SetHWND(dw_radiobutton_new("", 0)); Setup(); } 210 RadioButton() { SetHWND(dw_radiobutton_new("", 0)); Setup(); }
301 virtual int OnConfigure(int width, int height) { dw_signal_disconnect_by_name(hwnd, DW_SIGNAL_CONFIGURE); return FALSE; }; 306 virtual int OnConfigure(int width, int height) { dw_signal_disconnect_by_name(hwnd, DW_SIGNAL_CONFIGURE); return FALSE; };
302 }; 307 };
303 308
304 class Pixmap : public Drawable, public Handle 309 class Pixmap : public Drawable, public Handle
305 { 310 {
306 protected: 311 private:
307 void SetHPIXMAP(HPIXMAP newpixmap) { 312 void SetHPIXMAP(HPIXMAP newpixmap) {
308 hpixmap = newpixmap; 313 hpixmap = newpixmap;
309 SetHandle(reinterpret_cast<void *>(newpixmap)); 314 SetHandle(reinterpret_cast<void *>(newpixmap));
310 } 315 }
311 HPIXMAP hpixmap; 316 HPIXMAP hpixmap;
334 void BitBlt(int xdest, int ydest, int width, int height, Pixmap *src, int xsrc, int ysrc) { 339 void BitBlt(int xdest, int ydest, int width, int height, Pixmap *src, int xsrc, int ysrc) {
335 dw_pixmap_bitblt(DW_NOHWND, hpixmap, xdest, ydest, width, height, DW_NOHWND, src ? src->GetHPIXMAP() : DW_NULL, xsrc, ysrc); 340 dw_pixmap_bitblt(DW_NOHWND, hpixmap, xdest, ydest, width, height, DW_NOHWND, src ? src->GetHPIXMAP() : DW_NULL, xsrc, ysrc);
336 } 341 }
337 int SetFont(const char *fontname) { return dw_pixmap_set_font(hpixmap, fontname); } 342 int SetFont(const char *fontname) { return dw_pixmap_set_font(hpixmap, fontname); }
338 void GetTextExtents(const char *text, int *width, int *height) { dw_font_text_extents_get(DW_NOHWND, hpixmap, text, width, height); } 343 void GetTextExtents(const char *text, int *width, int *height) { dw_font_text_extents_get(DW_NOHWND, hpixmap, text, width, height); }
339
340 }; 344 };
341 345
342 // Need to declare these here after Pixmap is defined 346 // Need to declare these here after Pixmap is defined
343 int Render::BitBltStretch(int xdest, int ydest, int width, int height, Pixmap *src, int xsrc, int ysrc, int srcwidth, int srcheight) 347 int Render::BitBltStretch(int xdest, int ydest, int width, int height, Pixmap *src, int xsrc, int ysrc, int srcwidth, int srcheight)
344 { 348 {
378 virtual int OnChanged(int status, char *url) { dw_signal_disconnect_by_name(hwnd, DW_SIGNAL_HTML_CHANGED); return FALSE; } 382 virtual int OnChanged(int status, char *url) { dw_signal_disconnect_by_name(hwnd, DW_SIGNAL_HTML_CHANGED); return FALSE; }
379 virtual int OnResult(int status, char *result, void *scriptdata) { dw_signal_disconnect_by_name(hwnd, DW_SIGNAL_HTML_RESULT); return FALSE; }; 383 virtual int OnResult(int status, char *result, void *scriptdata) { dw_signal_disconnect_by_name(hwnd, DW_SIGNAL_HTML_RESULT); return FALSE; };
380 }; 384 };
381 385
382 // Base class for several widgets that allow text entry 386 // Base class for several widgets that allow text entry
383 class TextEntry : public Widget 387 class TextEntry : virtual public Widget
384 { 388 {
385 public: 389 public:
386 // User functions 390 // User functions
387 void SetText(const char *text) { dw_window_set_text(hwnd, text); } 391 void SetText(const char *text) { dw_window_set_text(hwnd, text); }
388 char *GetText() { return dw_window_get_text(hwnd); } 392 char *GetText() { return dw_window_get_text(hwnd); }
407 EntryfieldPassword(const char *text) { SetHWND(dw_entryfield_password_new(text, 0)); } 411 EntryfieldPassword(const char *text) { SetHWND(dw_entryfield_password_new(text, 0)); }
408 EntryfieldPassword() { SetHWND(dw_entryfield_password_new("", 0)); } 412 EntryfieldPassword() { SetHWND(dw_entryfield_password_new("", 0)); }
409 }; 413 };
410 414
411 // Base class for several widgets that have a list of elements 415 // Base class for several widgets that have a list of elements
412 class ListBoxes : public Widget 416 class ListBoxes : virtual public Widget
413 { 417 {
414 private: 418 private:
415 void Setup() { 419 void Setup() {
416 if(IsOverridden(ListBoxes::OnListSelect, this)) 420 if(IsOverridden(ListBoxes::OnListSelect, this))
417 dw_signal_connect(hwnd, DW_SIGNAL_LIST_SELECT, DW_SIGNAL_FUNC(_OnListSelect), this); 421 dw_signal_connect(hwnd, DW_SIGNAL_LIST_SELECT, DW_SIGNAL_FUNC(_OnListSelect), this);
435 // Our signal handler functions to be overriden... 439 // Our signal handler functions to be overriden...
436 // If they are not overridden and an event is generated, remove the unused handler 440 // If they are not overridden and an event is generated, remove the unused handler
437 virtual int OnListSelect(int index) { dw_signal_disconnect_by_name(hwnd, DW_SIGNAL_LIST_SELECT); return FALSE; } 441 virtual int OnListSelect(int index) { dw_signal_disconnect_by_name(hwnd, DW_SIGNAL_LIST_SELECT); return FALSE; }
438 }; 442 };
439 443
440 #if 0
441 class Combobox : public TextEntry, public ListBoxes 444 class Combobox : public TextEntry, public ListBoxes
442 { 445 {
443 public: 446 public:
444 // Constructors 447 // Constructors
445 Combobox(const char *text, unsigned long id) { SetHWND(dw_combobox_new(text, id)); } 448 Combobox(const char *text, unsigned long id) { SetHWND(dw_combobox_new(text, id)); }
446 Combobox(unsigned long id) { SetHWND(dw_combobox_new("", id)); } 449 Combobox(unsigned long id) { SetHWND(dw_combobox_new("", id)); }
447 Combobox(const char *text) { SetHWND(dw_combobox_new(text, 0)); } 450 Combobox(const char *text) { SetHWND(dw_combobox_new(text, 0)); }
448 Combobox() { SetHWND(dw_combobox_new("", 0)); } 451 Combobox() { SetHWND(dw_combobox_new("", 0)); }
449 }; 452 };
450 #endif
451 453
452 class Listbox : public ListBoxes 454 class Listbox : public ListBoxes
453 { 455 {
454 public: 456 public:
455 // Constructors 457 // Constructors