comparison dw.hpp @ 2876:e201a984d855

C++: Implement Entryfield, EntryfieldPassword, Listbox and HTML widgets. Combobox is almost implemented, but getting issue since two parent classes both inherit from Widget.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Tue, 20 Dec 2022 01:44:15 +0000
parents 585d0053b766
children 6f31b7991fa0
comparison
equal deleted inserted replaced
2875:d15517b49638 2876:e201a984d855
137 { 137 {
138 private: 138 private:
139 static int _OnClicked(HWND window, void *data) { return reinterpret_cast<Buttons *>(data)->OnClicked(); } 139 static int _OnClicked(HWND window, void *data) { return reinterpret_cast<Buttons *>(data)->OnClicked(); }
140 protected: 140 protected:
141 void Setup() { 141 void Setup() {
142 if(IsOverridden(Window::OnClicked, this)) 142 if(IsOverridden(Buttons::OnClicked, this))
143 dw_signal_connect(hwnd, DW_SIGNAL_CLICKED, DW_SIGNAL_FUNC(_OnClicked), this); 143 dw_signal_connect(hwnd, DW_SIGNAL_CLICKED, DW_SIGNAL_FUNC(_OnClicked), this);
144 } 144 }
145 // Our signal handler functions to be overriden... 145 // Our signal handler functions to be overriden...
146 // If they are not overridden and an event is generated, remove the unused handler 146 // If they are not overridden and an event is generated, remove the unused handler
147 virtual int OnClicked() { dw_signal_disconnect_by_name(hwnd, DW_SIGNAL_CLICKED); return FALSE; } 147 virtual int OnClicked() { dw_signal_disconnect_by_name(hwnd, DW_SIGNAL_CLICKED); return FALSE; }
179 BitmapButton(const char *text, const char *data, int len) { SetHWND(dw_bitmapbutton_new_from_data(text, 0, data, len)); Setup(); } 179 BitmapButton(const char *text, const char *data, int len) { SetHWND(dw_bitmapbutton_new_from_data(text, 0, data, len)); Setup(); }
180 }; 180 };
181 181
182 class CheckBoxes : public TextButton 182 class CheckBoxes : public TextButton
183 { 183 {
184 public:
184 // User functions 185 // User functions
185 void Set(int value) { dw_checkbox_set(hwnd, value); } 186 void Set(int value) { dw_checkbox_set(hwnd, value); }
186 int Get() { return dw_checkbox_get(hwnd); } 187 int Get() { return dw_checkbox_get(hwnd); }
187 }; 188 };
188 189
261 262
262 class Render : public Drawable, public Widget 263 class Render : public Drawable, public Widget
263 { 264 {
264 private: 265 private:
265 void Setup() { 266 void Setup() {
266 if(IsOverridden(Window::OnExpose, this)) 267 if(IsOverridden(Render::OnExpose, this))
267 dw_signal_connect(hwnd, DW_SIGNAL_EXPOSE, DW_SIGNAL_FUNC(_OnExpose), this); 268 dw_signal_connect(hwnd, DW_SIGNAL_EXPOSE, DW_SIGNAL_FUNC(_OnExpose), this);
268 if(IsOverridden(Window::OnConfigure, this)) 269 if(IsOverridden(Render::OnConfigure, this))
269 dw_signal_connect(hwnd, DW_SIGNAL_CONFIGURE, DW_SIGNAL_FUNC(_OnConfigure), this); 270 dw_signal_connect(hwnd, DW_SIGNAL_CONFIGURE, DW_SIGNAL_FUNC(_OnConfigure), this);
270 } 271 }
271 static int _OnExpose(HWND window, DWExpose *exp, void *data) { return reinterpret_cast<Render *>(data)->OnExpose(exp); } 272 static int _OnExpose(HWND window, DWExpose *exp, void *data) { return reinterpret_cast<Render *>(data)->OnExpose(exp); }
272 static int _OnConfigure(HWND window, int width, int height, void *data) { return reinterpret_cast<Render *>(data)->OnConfigure(width, height); } 273 static int _OnConfigure(HWND window, int width, int height, void *data) { return reinterpret_cast<Render *>(data)->OnConfigure(width, height); }
273 public: 274 public:
289 void BitBlt(int xdest, int ydest, int width, int height, Render *src, int xsrc, int ysrc) { 290 void BitBlt(int xdest, int ydest, int width, int height, Render *src, int xsrc, int ysrc) {
290 return dw_pixmap_bitblt(hwnd, DW_NULL, xdest, ydest, width, height, src ? src->GetHWND() : DW_NOHWND, DW_NULL, xsrc, ysrc); 291 return dw_pixmap_bitblt(hwnd, DW_NULL, xdest, ydest, width, height, src ? src->GetHWND() : DW_NOHWND, DW_NULL, xsrc, ysrc);
291 } 292 }
292 void BitBlt(int xdest, int ydest, int width, int height, Pixmap *src, int xsrc, int ysrc); 293 void BitBlt(int xdest, int ydest, int width, int height, Pixmap *src, int xsrc, int ysrc);
293 int SetFont(const char *fontname) { return dw_window_set_font(hwnd, fontname); } 294 int SetFont(const char *fontname) { return dw_window_set_font(hwnd, fontname); }
295 void GetTextExtents(const char *text, int *width, int *height) { dw_font_text_extents_get(hwnd, DW_NULL, text, width, height); }
294 char *GetFont() { return dw_window_get_font(hwnd); } 296 char *GetFont() { return dw_window_get_font(hwnd); }
295 protected: 297 protected:
296 // Our signal handler functions to be overriden... 298 // Our signal handler functions to be overriden...
297 // If they are not overridden and an event is generated, remove the unused handler 299 // If they are not overridden and an event is generated, remove the unused handler
298 virtual int OnExpose(DWExpose *exp) { dw_signal_disconnect_by_name(hwnd, DW_SIGNAL_EXPOSE); return FALSE; } 300 virtual int OnExpose(DWExpose *exp) { dw_signal_disconnect_by_name(hwnd, DW_SIGNAL_EXPOSE); return FALSE; }
331 } 333 }
332 void BitBlt(int xdest, int ydest, int width, int height, Pixmap *src, int xsrc, int ysrc) { 334 void BitBlt(int xdest, int ydest, int width, int height, Pixmap *src, int xsrc, int ysrc) {
333 dw_pixmap_bitblt(DW_NOHWND, hpixmap, xdest, ydest, width, height, DW_NOHWND, src ? src->GetHPIXMAP() : DW_NULL, xsrc, ysrc); 335 dw_pixmap_bitblt(DW_NOHWND, hpixmap, xdest, ydest, width, height, DW_NOHWND, src ? src->GetHPIXMAP() : DW_NULL, xsrc, ysrc);
334 } 336 }
335 int SetFont(const char *fontname) { return dw_pixmap_set_font(hpixmap, fontname); } 337 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); }
339
336 }; 340 };
337 341
338 // Need to declare these here after Pixmap is defined 342 // Need to declare these here after Pixmap is defined
339 int Render::BitBltStretch(int xdest, int ydest, int width, int height, Pixmap *src, int xsrc, int ysrc, int srcwidth, int srcheight) 343 int Render::BitBltStretch(int xdest, int ydest, int width, int height, Pixmap *src, int xsrc, int ysrc, int srcwidth, int srcheight)
340 { 344 {
343 347
344 void Render::BitBlt(int xdest, int ydest, int width, int height, Pixmap *src, int xsrc, int ysrc) 348 void Render::BitBlt(int xdest, int ydest, int width, int height, Pixmap *src, int xsrc, int ysrc)
345 { 349 {
346 dw_pixmap_bitblt(hwnd, DW_NULL, xdest, ydest, width, height, DW_NOHWND, src ? src->GetHPIXMAP() : DW_NULL, xsrc, ysrc); 350 dw_pixmap_bitblt(hwnd, DW_NULL, xdest, ydest, width, height, DW_NOHWND, src ? src->GetHPIXMAP() : DW_NULL, xsrc, ysrc);
347 } 351 }
352
353 // Class for the HTML rendering widget
354 class HTML : public Widget
355 {
356 private:
357 void Setup() {
358 if(IsOverridden(HTML::OnChanged, this))
359 dw_signal_connect(hwnd, DW_SIGNAL_HTML_CHANGED, DW_SIGNAL_FUNC(_OnChanged), this);
360 if(IsOverridden(HTML::OnResult, this))
361 dw_signal_connect(hwnd, DW_SIGNAL_HTML_CHANGED, DW_SIGNAL_FUNC(_OnResult), this);
362 }
363 static int _OnChanged(HWND window, int status, char *url, void *data) { return reinterpret_cast<HTML *>(data)->OnChanged(status, url); }
364 static int _OnResult(HWND window, int status, char *result, void *scriptdata, void *data) { return reinterpret_cast<HTML *>(data)->OnResult(status, result, scriptdata); }
365 public:
366 // Constructors
367 HTML(unsigned long id) { SetHWND(dw_html_new(id)); Setup(); }
368 HTML() { SetHWND(dw_html_new(0)); Setup(); }
369
370 // User functions
371 void Action(int action) { dw_html_action(hwnd, action); }
372 int JavascriptRun(const char *script, void *scriptdata) { return dw_html_javascript_run(hwnd, script, scriptdata); }
373 int Raw(const char *buffer) { return dw_html_raw(hwnd, buffer); }
374 int URL(const char *url) { return dw_html_url(hwnd, url); }
375 protected:
376 // Our signal handler functions to be overriden...
377 // If they are not overridden and an event is generated, remove the unused handler
378 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; };
380 };
381
382 // Base class for several widgets that allow text entry
383 class TextEntry : public Widget
384 {
385 public:
386 // User functions
387 void SetText(const char *text) { dw_window_set_text(hwnd, text); }
388 char *GetText() { return dw_window_get_text(hwnd); }
389 };
390
391 class Entryfield : public TextEntry
392 {
393 public:
394 // Constructors
395 Entryfield(const char *text, unsigned long id) { SetHWND(dw_entryfield_new(text, id)); }
396 Entryfield(unsigned long id) { SetHWND(dw_entryfield_new("", id)); }
397 Entryfield(const char *text) { SetHWND(dw_entryfield_new(text, 0)); }
398 Entryfield() { SetHWND(dw_entryfield_new("", 0)); }
399 };
400
401 class EntryfieldPassword : public TextEntry
402 {
403 public:
404 // Constructors
405 EntryfieldPassword(const char *text, unsigned long id) { SetHWND(dw_entryfield_password_new(text, id)); }
406 EntryfieldPassword(unsigned long id) { SetHWND(dw_entryfield_password_new("", id)); }
407 EntryfieldPassword(const char *text) { SetHWND(dw_entryfield_password_new(text, 0)); }
408 EntryfieldPassword() { SetHWND(dw_entryfield_password_new("", 0)); }
409 };
410
411 // Base class for several widgets that have a list of elements
412 class ListBoxes : public Widget
413 {
414 private:
415 void Setup() {
416 if(IsOverridden(ListBoxes::OnListSelect, this))
417 dw_signal_connect(hwnd, DW_SIGNAL_LIST_SELECT, DW_SIGNAL_FUNC(_OnListSelect), this);
418 }
419 static int _OnListSelect(HWND window, int index, void *data) { return reinterpret_cast<ListBoxes *>(data)->OnListSelect(index); }
420 public:
421 // User functions
422 void Append(const char *text) { dw_listbox_append(hwnd, text); }
423 void Clear() { dw_listbox_clear(hwnd); }
424 int Count() { return dw_listbox_count(hwnd); }
425 void Delete(int index) { dw_listbox_delete(hwnd, index); }
426 void GetText(unsigned int index, char *buffer, unsigned int length) { dw_listbox_get_text(hwnd, index, buffer, length); }
427 void SetText(unsigned int index, char *buffer) { dw_listbox_set_text(hwnd, index, buffer); }
428 void Insert(const char *text, int pos) { dw_listbox_insert(hwnd, text, pos); }
429 void ListAppend(char **text, int count) { dw_listbox_list_append(hwnd, text, count); }
430 void Select(int index, int state) { dw_listbox_select(hwnd, index, state); }
431 int Selected() { return dw_listbox_selected(hwnd); }
432 int Selected(int where) { return dw_listbox_selected_multi(hwnd, where); }
433 void SetTop(int top) { dw_listbox_set_top(hwnd, top); }
434 protected:
435 // Our signal handler functions to be overriden...
436 // 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; }
438 };
439
440 #if 0
441 class Combobox : public TextEntry, public ListBoxes
442 {
443 public:
444 // Constructors
445 Combobox(const char *text, unsigned long id) { SetHWND(dw_combobox_new(text, id)); }
446 Combobox(unsigned long id) { SetHWND(dw_combobox_new("", id)); }
447 Combobox(const char *text) { SetHWND(dw_combobox_new(text, 0)); }
448 Combobox() { SetHWND(dw_combobox_new("", 0)); }
449 };
450 #endif
451
452 class Listbox : public ListBoxes
453 {
454 public:
455 // Constructors
456 Listbox(unsigned long id, int multi) { SetHWND(dw_listbox_new(id, multi)); }
457 Listbox(unsigned long id) { SetHWND(dw_listbox_new(id, FALSE)); }
458 Listbox(int multi) { SetHWND(dw_listbox_new(0, multi)); }
459 Listbox() { SetHWND(dw_listbox_new(0, FALSE)); }
460 };
348 461
349 class App 462 class App
350 { 463 {
351 protected: 464 protected:
352 App() { } 465 App() { }