Wrapper classes for the emwin library
Dependents: app_emwin1 app_emwin2_pos lpc4088_ebb_gui_emwin
EwCheckBox.cpp@1:0b16165ada7c, 2014-04-14 (annotated)
- Committer:
- embeddedartists
- Date:
- Mon Apr 14 08:38:33 2014 +0000
- Revision:
- 1:0b16165ada7c
- Parent:
- 0:316c181e9b65
Initialize uninitialized touchState in EwGui
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
embeddedartists | 0:316c181e9b65 | 1 | #include "mbed.h" |
embeddedartists | 0:316c181e9b65 | 2 | |
embeddedartists | 0:316c181e9b65 | 3 | #include "EwCheckBox.h" |
embeddedartists | 0:316c181e9b65 | 4 | |
embeddedartists | 0:316c181e9b65 | 5 | |
embeddedartists | 0:316c181e9b65 | 6 | EwCheckBox::EwCheckBox(EwWindow* parent) : EwWindow(parent) { |
embeddedartists | 0:316c181e9b65 | 7 | init(0, 0, 0, 0, parent); |
embeddedartists | 0:316c181e9b65 | 8 | } |
embeddedartists | 0:316c181e9b65 | 9 | |
embeddedartists | 0:316c181e9b65 | 10 | EwCheckBox::EwCheckBox(int x, int y, int width, int height, EwWindow* parent) : |
embeddedartists | 0:316c181e9b65 | 11 | EwWindow(x, y, width, height, parent) { |
embeddedartists | 0:316c181e9b65 | 12 | |
embeddedartists | 0:316c181e9b65 | 13 | init(x, y, width, height, parent); |
embeddedartists | 0:316c181e9b65 | 14 | } |
embeddedartists | 0:316c181e9b65 | 15 | |
embeddedartists | 0:316c181e9b65 | 16 | |
embeddedartists | 0:316c181e9b65 | 17 | ewCheckBoxState_t EwCheckBox::getState() { |
embeddedartists | 0:316c181e9b65 | 18 | return (ewCheckBoxState_t)CHECKBOX_GetState(_hWnd); |
embeddedartists | 0:316c181e9b65 | 19 | } |
embeddedartists | 0:316c181e9b65 | 20 | |
embeddedartists | 0:316c181e9b65 | 21 | void EwCheckBox::setState(ewCheckBoxState_t state) { |
embeddedartists | 0:316c181e9b65 | 22 | ewCheckBoxState_t prev = getState(); |
embeddedartists | 0:316c181e9b65 | 23 | CHECKBOX_SetState(_hWnd, state); |
embeddedartists | 0:316c181e9b65 | 24 | |
embeddedartists | 0:316c181e9b65 | 25 | if (state != prev) { |
embeddedartists | 0:316c181e9b65 | 26 | handleStateChanged(); |
embeddedartists | 0:316c181e9b65 | 27 | } |
embeddedartists | 0:316c181e9b65 | 28 | } |
embeddedartists | 0:316c181e9b65 | 29 | |
embeddedartists | 0:316c181e9b65 | 30 | void EwCheckBox::setTristate(bool on) { |
embeddedartists | 0:316c181e9b65 | 31 | _isTristate = on; |
embeddedartists | 0:316c181e9b65 | 32 | if (on) { |
embeddedartists | 0:316c181e9b65 | 33 | CHECKBOX_SetNumStates(_hWnd, 3); |
embeddedartists | 0:316c181e9b65 | 34 | } |
embeddedartists | 0:316c181e9b65 | 35 | else { |
embeddedartists | 0:316c181e9b65 | 36 | CHECKBOX_SetNumStates(_hWnd, 2); |
embeddedartists | 0:316c181e9b65 | 37 | } |
embeddedartists | 0:316c181e9b65 | 38 | } |
embeddedartists | 0:316c181e9b65 | 39 | |
embeddedartists | 0:316c181e9b65 | 40 | bool EwCheckBox::isTristate() { |
embeddedartists | 0:316c181e9b65 | 41 | return _isTristate; |
embeddedartists | 0:316c181e9b65 | 42 | } |
embeddedartists | 0:316c181e9b65 | 43 | |
embeddedartists | 0:316c181e9b65 | 44 | void EwCheckBox::setText(const char* text) { |
embeddedartists | 0:316c181e9b65 | 45 | CHECKBOX_SetText(_hWnd, text); |
embeddedartists | 0:316c181e9b65 | 46 | } |
embeddedartists | 0:316c181e9b65 | 47 | |
embeddedartists | 0:316c181e9b65 | 48 | void EwCheckBox::getText(char* pBuf, int bufSz) { |
embeddedartists | 0:316c181e9b65 | 49 | CHECKBOX_GetText(_hWnd, pBuf, bufSz); |
embeddedartists | 0:316c181e9b65 | 50 | } |
embeddedartists | 0:316c181e9b65 | 51 | |
embeddedartists | 0:316c181e9b65 | 52 | void EwCheckBox::setBackgroundColor(ewColor_t c) { |
embeddedartists | 0:316c181e9b65 | 53 | CHECKBOX_SetBkColor(_hWnd, c); |
embeddedartists | 0:316c181e9b65 | 54 | } |
embeddedartists | 0:316c181e9b65 | 55 | |
embeddedartists | 0:316c181e9b65 | 56 | void EwCheckBox::setBoxBackgroundColor(ewColor_t c, ewCheckBoxColorIndex_t idx) { |
embeddedartists | 0:316c181e9b65 | 57 | CHECKBOX_SetBoxBkColor(_hWnd, c, idx); |
embeddedartists | 0:316c181e9b65 | 58 | } |
embeddedartists | 0:316c181e9b65 | 59 | |
embeddedartists | 0:316c181e9b65 | 60 | void EwCheckBox::setFont(const ewFont_t* pFont) { |
embeddedartists | 0:316c181e9b65 | 61 | CHECKBOX_SetFont(_hWnd, pFont); |
embeddedartists | 0:316c181e9b65 | 62 | } |
embeddedartists | 0:316c181e9b65 | 63 | |
embeddedartists | 0:316c181e9b65 | 64 | void EwCheckBox::setTextAlign(ewTextAlign_t align) { |
embeddedartists | 0:316c181e9b65 | 65 | CHECKBOX_SetTextAlign(_hWnd, align); |
embeddedartists | 0:316c181e9b65 | 66 | } |
embeddedartists | 0:316c181e9b65 | 67 | |
embeddedartists | 0:316c181e9b65 | 68 | void EwCheckBox::setTextColor(ewColor_t c) { |
embeddedartists | 0:316c181e9b65 | 69 | CHECKBOX_SetTextColor(_hWnd, c); |
embeddedartists | 0:316c181e9b65 | 70 | } |
embeddedartists | 0:316c181e9b65 | 71 | |
embeddedartists | 0:316c181e9b65 | 72 | void EwCheckBox::setFocusColor(ewColor_t c) { |
embeddedartists | 0:316c181e9b65 | 73 | CHECKBOX_SetFocusColor(_hWnd, c); |
embeddedartists | 0:316c181e9b65 | 74 | } |
embeddedartists | 0:316c181e9b65 | 75 | |
embeddedartists | 0:316c181e9b65 | 76 | void EwCheckBox::setImage(ewBitmap_t* pBitmap, ewCheckBoxBitmapIndex_t idx) { |
embeddedartists | 0:316c181e9b65 | 77 | CHECKBOX_SetImage(_hWnd, pBitmap, idx); |
embeddedartists | 0:316c181e9b65 | 78 | } |
embeddedartists | 0:316c181e9b65 | 79 | |
embeddedartists | 0:316c181e9b65 | 80 | void EwCheckBox::setSpacing(int32_t spacing) { |
embeddedartists | 0:316c181e9b65 | 81 | CHECKBOX_SetSpacing(_hWnd, spacing); |
embeddedartists | 0:316c181e9b65 | 82 | } |
embeddedartists | 0:316c181e9b65 | 83 | |
embeddedartists | 0:316c181e9b65 | 84 | void EwCheckBox::setChangedListener(void (*fptr)(EwWindow* w)) { |
embeddedartists | 0:316c181e9b65 | 85 | _changedListener.attach(fptr); |
embeddedartists | 0:316c181e9b65 | 86 | } |
embeddedartists | 0:316c181e9b65 | 87 | |
embeddedartists | 0:316c181e9b65 | 88 | ewColor_t EwCheckBox::getDefaultBackgroundColor() { |
embeddedartists | 0:316c181e9b65 | 89 | return CHECKBOX_GetDefaultBkColor(); |
embeddedartists | 0:316c181e9b65 | 90 | } |
embeddedartists | 0:316c181e9b65 | 91 | |
embeddedartists | 0:316c181e9b65 | 92 | void EwCheckBox::setDefaultBackgroundColor(ewColor_t c) { |
embeddedartists | 0:316c181e9b65 | 93 | CHECKBOX_SetDefaultBkColor(c); |
embeddedartists | 0:316c181e9b65 | 94 | } |
embeddedartists | 0:316c181e9b65 | 95 | |
embeddedartists | 0:316c181e9b65 | 96 | const ewFont_t* EwCheckBox::getDefaultFont() { |
embeddedartists | 0:316c181e9b65 | 97 | return CHECKBOX_GetDefaultFont(); |
embeddedartists | 0:316c181e9b65 | 98 | } |
embeddedartists | 0:316c181e9b65 | 99 | |
embeddedartists | 0:316c181e9b65 | 100 | void EwCheckBox::setDefaultFont(const ewFont_t* pFont) { |
embeddedartists | 0:316c181e9b65 | 101 | CHECKBOX_SetDefaultFont(pFont); |
embeddedartists | 0:316c181e9b65 | 102 | } |
embeddedartists | 0:316c181e9b65 | 103 | |
embeddedartists | 0:316c181e9b65 | 104 | ewColor_t EwCheckBox::getDefaultTextColor() { |
embeddedartists | 0:316c181e9b65 | 105 | return CHECKBOX_GetDefaultTextColor(); |
embeddedartists | 0:316c181e9b65 | 106 | } |
embeddedartists | 0:316c181e9b65 | 107 | |
embeddedartists | 0:316c181e9b65 | 108 | void EwCheckBox::setDefaultTextColor(ewColor_t c) { |
embeddedartists | 0:316c181e9b65 | 109 | CHECKBOX_SetDefaultTextColor(c); |
embeddedartists | 0:316c181e9b65 | 110 | } |
embeddedartists | 0:316c181e9b65 | 111 | |
embeddedartists | 0:316c181e9b65 | 112 | void EwCheckBox::setDefaultFocusColor(ewColor_t c) { |
embeddedartists | 0:316c181e9b65 | 113 | CHECKBOX_SetDefaultFocusColor(c); |
embeddedartists | 0:316c181e9b65 | 114 | } |
embeddedartists | 0:316c181e9b65 | 115 | |
embeddedartists | 0:316c181e9b65 | 116 | int32_t EwCheckBox::getDefaultSpacing() { |
embeddedartists | 0:316c181e9b65 | 117 | return CHECKBOX_GetDefaultSpacing(); |
embeddedartists | 0:316c181e9b65 | 118 | } |
embeddedartists | 0:316c181e9b65 | 119 | |
embeddedartists | 0:316c181e9b65 | 120 | void EwCheckBox::setDefaultSpacing(int32_t spacing) { |
embeddedartists | 0:316c181e9b65 | 121 | CHECKBOX_SetDefaultSpacing(spacing); |
embeddedartists | 0:316c181e9b65 | 122 | } |
embeddedartists | 0:316c181e9b65 | 123 | |
embeddedartists | 0:316c181e9b65 | 124 | void EwCheckBox::setDefaultImage(ewBitmap_t* pBitmap, ewCheckBoxBitmapIndex_t idx) { |
embeddedartists | 0:316c181e9b65 | 125 | CHECKBOX_SetDefaultImage(pBitmap, idx); |
embeddedartists | 0:316c181e9b65 | 126 | } |
embeddedartists | 0:316c181e9b65 | 127 | |
embeddedartists | 0:316c181e9b65 | 128 | |
embeddedartists | 0:316c181e9b65 | 129 | void EwCheckBox::init(int x, int y, int width, int height, EwWindow* parent) { |
embeddedartists | 0:316c181e9b65 | 130 | CHECKBOX_Handle h; |
embeddedartists | 0:316c181e9b65 | 131 | GUI_HWIN hWin = 0; |
embeddedartists | 0:316c181e9b65 | 132 | |
embeddedartists | 0:316c181e9b65 | 133 | _isTristate = false; |
embeddedartists | 0:316c181e9b65 | 134 | |
embeddedartists | 0:316c181e9b65 | 135 | if (parent) { |
embeddedartists | 0:316c181e9b65 | 136 | hWin = _getHandle(parent); |
embeddedartists | 0:316c181e9b65 | 137 | } |
embeddedartists | 0:316c181e9b65 | 138 | |
embeddedartists | 0:316c181e9b65 | 139 | h = CHECKBOX_CreateEx(x, y, width, height, hWin, (WM_CF_SHOW| WM_CF_MEMDEV), |
embeddedartists | 0:316c181e9b65 | 140 | 0, _guiWidgetId++); |
embeddedartists | 0:316c181e9b65 | 141 | _setNewHandle(h, _callback); |
embeddedartists | 0:316c181e9b65 | 142 | } |
embeddedartists | 0:316c181e9b65 | 143 | |
embeddedartists | 0:316c181e9b65 | 144 | void EwCheckBox::handleStateChanged() { |
embeddedartists | 0:316c181e9b65 | 145 | _changedListener.call(this); |
embeddedartists | 0:316c181e9b65 | 146 | } |
embeddedartists | 0:316c181e9b65 | 147 | |
embeddedartists | 0:316c181e9b65 | 148 | void EwCheckBox::_callback(WM_MESSAGE* pMsg, EwWindow* w) { |
embeddedartists | 0:316c181e9b65 | 149 | ewCheckBoxState_t prevState; |
embeddedartists | 0:316c181e9b65 | 150 | |
embeddedartists | 0:316c181e9b65 | 151 | EwCheckBox* b = (EwCheckBox*)w; |
embeddedartists | 0:316c181e9b65 | 152 | |
embeddedartists | 0:316c181e9b65 | 153 | // get state before message has been processed |
embeddedartists | 0:316c181e9b65 | 154 | if (pMsg->MsgId == WM_TOUCH) { |
embeddedartists | 0:316c181e9b65 | 155 | prevState = b->getState(); |
embeddedartists | 0:316c181e9b65 | 156 | } |
embeddedartists | 0:316c181e9b65 | 157 | |
embeddedartists | 0:316c181e9b65 | 158 | CHECKBOX_Callback(pMsg); |
embeddedartists | 0:316c181e9b65 | 159 | |
embeddedartists | 0:316c181e9b65 | 160 | // check if the state has changed after processing the message |
embeddedartists | 0:316c181e9b65 | 161 | if (pMsg->MsgId == WM_TOUCH) { |
embeddedartists | 0:316c181e9b65 | 162 | if (b->getState() != prevState) { |
embeddedartists | 0:316c181e9b65 | 163 | b->handleStateChanged(); |
embeddedartists | 0:316c181e9b65 | 164 | } |
embeddedartists | 0:316c181e9b65 | 165 | } |
embeddedartists | 0:316c181e9b65 | 166 | |
embeddedartists | 0:316c181e9b65 | 167 | |
embeddedartists | 0:316c181e9b65 | 168 | |
embeddedartists | 0:316c181e9b65 | 169 | } |
embeddedartists | 0:316c181e9b65 | 170 |