Mercurial > dwindows
comparison dw.hpp @ 2880:2ba0959eb3cf
C++: Implement Slider, Scrollbar, SpinButton, and MLE.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Tue, 20 Dec 2022 20:23:02 +0000 |
parents | ec7f6e28166d |
children | 99311a9091af |
comparison
equal
deleted
inserted
replaced
2879:ec7f6e28166d | 2880:2ba0959eb3cf |
---|---|
510 Listbox(unsigned long id) { SetHWND(dw_listbox_new(id, FALSE)); } | 510 Listbox(unsigned long id) { SetHWND(dw_listbox_new(id, FALSE)); } |
511 Listbox(int multi) { SetHWND(dw_listbox_new(0, multi)); } | 511 Listbox(int multi) { SetHWND(dw_listbox_new(0, multi)); } |
512 Listbox() { SetHWND(dw_listbox_new(0, FALSE)); } | 512 Listbox() { SetHWND(dw_listbox_new(0, FALSE)); } |
513 }; | 513 }; |
514 | 514 |
515 // Base class for several ranged type widgets | |
516 class Ranged : virtual public Widget | |
517 { | |
518 private: | |
519 static int _OnValueChanged(HWND window, int value, void *data) { return reinterpret_cast<Ranged *>(data)->OnValueChanged(value); } | |
520 protected: | |
521 void Setup() { | |
522 if(IsOverridden(Ranged::OnValueChanged, this)) | |
523 dw_signal_connect(hwnd, DW_SIGNAL_VALUE_CHANGED, DW_SIGNAL_FUNC(_OnValueChanged), this); | |
524 } | |
525 // Our signal handler functions to be overriden... | |
526 // If they are not overridden and an event is generated, remove the unused handler | |
527 virtual int OnValueChanged(int value) { dw_signal_disconnect_by_name(hwnd, DW_SIGNAL_VALUE_CHANGED); return FALSE; } | |
528 }; | |
529 | |
530 class Slider : public Ranged | |
531 { | |
532 public: | |
533 // Constructors | |
534 Slider(int orient, int increments, unsigned long id) { SetHWND(dw_slider_new(orient, increments, id)); Setup(); } | |
535 Slider(int orient, int increments) { SetHWND(dw_slider_new(orient, increments, 0)); Setup(); } | |
536 | |
537 // User functions | |
538 unsigned int GetPos() { return dw_slider_get_pos(hwnd); } | |
539 void SetPos(unsigned int position) { dw_slider_set_pos(hwnd, position); } | |
540 }; | |
541 | |
542 class Scrollbar : public Ranged | |
543 { | |
544 public: | |
545 // Constructors | |
546 Scrollbar(int orient, unsigned long id) { SetHWND(dw_scrollbar_new(orient, id)); Setup(); } | |
547 Scrollbar(int orient) { SetHWND(dw_scrollbar_new(orient, 0)); Setup(); } | |
548 | |
549 // User functions | |
550 unsigned int GetPos() { return dw_scrollbar_get_pos(hwnd); } | |
551 void SetPos(unsigned int position) { dw_scrollbar_set_pos(hwnd, position); } | |
552 void SetRange(unsigned int range, unsigned int visible) { dw_scrollbar_set_range(hwnd, range, visible); } | |
553 }; | |
554 | |
555 class SpinButton : public Ranged, public TextEntry | |
556 { | |
557 public: | |
558 // Constructors | |
559 SpinButton(const char *text, unsigned long id) { SetHWND(dw_spinbutton_new(text, id)); Setup(); } | |
560 SpinButton(unsigned long id) { SetHWND(dw_spinbutton_new("", id)); Setup(); } | |
561 SpinButton(const char *text) { SetHWND(dw_spinbutton_new(text, 0)); Setup(); } | |
562 SpinButton() { SetHWND(dw_spinbutton_new("", 0)); Setup(); } | |
563 | |
564 // User functions | |
565 long GetPos() { return dw_spinbutton_get_pos(hwnd); } | |
566 void SetPos(long position) { dw_spinbutton_set_pos(hwnd, position); } | |
567 void SetLimits(long upper, long lower) { dw_spinbutton_set_limits(hwnd, upper, lower); } | |
568 }; | |
569 | |
570 // Multi-line Edit widget | |
571 class MLE : public Focusable | |
572 { | |
573 public: | |
574 // Constructors | |
575 MLE(unsigned long id) { SetHWND(dw_mle_new(id)); } | |
576 MLE() { SetHWND(dw_mle_new(0)); } | |
577 | |
578 // User functions | |
579 void Freeze() { dw_mle_freeze(hwnd); } | |
580 void Thaw() { dw_mle_thaw(hwnd); } | |
581 void Clear() { dw_mle_clear(hwnd); } | |
582 void Delete(int startpoint, int length) { dw_mle_delete(hwnd, startpoint, length); } | |
583 void Export(char *buffer, int startpoint, int length) { dw_mle_export(hwnd, buffer, startpoint, length); } | |
584 void Import(const char *buffer, int startpoint) { dw_mle_import(hwnd, buffer, startpoint); } | |
585 void GetSize(unsigned long *bytes, unsigned long *lines) { dw_mle_get_size(hwnd, bytes, lines); } | |
586 void Search(const char *text, int point, unsigned long flags) { dw_mle_search(hwnd, text, point, flags); } | |
587 void SetAutoComplete(int state) { dw_mle_set_auto_complete(hwnd, state); } | |
588 void SetCursor(int point) { dw_mle_set_cursor(hwnd, point); } | |
589 void SetEditable(int state) { dw_mle_set_editable(hwnd, state); } | |
590 void SetVisible(int line) { dw_mle_set_visible(hwnd, line); } | |
591 void SetWordWrap(int state) { dw_mle_set_word_wrap(hwnd, state); } | |
592 }; | |
593 | |
515 class App | 594 class App |
516 { | 595 { |
517 protected: | 596 protected: |
518 App() { } | 597 App() { } |
519 static App *_app; | 598 static App *_app; |