/** * This command returns the status of the user button on * Input - none * Returns - 1 if button is held down * 0 if button is not held down */ static int do_userbutton(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { int button = 0; button = get_button_state("button_dfu0", BOARD_DFU_BUTTON_GPIO); button |= get_button_state("button_dfu1", BOARD_DFU_BUTTON_GPIO); return button; }
static void OB_Paint( HWND hwnd, HDC hDC, UINT action ) { LONG state = get_button_state( hwnd ); DRAWITEMSTRUCT dis; LONG_PTR id = GetWindowLongPtrW( hwnd, GWLP_ID ); HWND parent; HFONT hFont, hPrevFont = 0; HRGN hrgn; dis.CtlType = ODT_BUTTON; dis.CtlID = id; dis.itemID = 0; dis.itemAction = action; dis.itemState = ((state & BST_FOCUS) ? ODS_FOCUS : 0) | ((state & BST_PUSHED) ? ODS_SELECTED : 0) | (IsWindowEnabled(hwnd) ? 0: ODS_DISABLED); dis.hwndItem = hwnd; dis.hDC = hDC; dis.itemData = 0; GetClientRect( hwnd, &dis.rcItem ); if ((hFont = get_button_font( hwnd ))) hPrevFont = SelectObject( hDC, hFont ); parent = GetParent(hwnd); if (!parent) parent = hwnd; GetControlColor( parent, hwnd, hDC, WM_CTLCOLORBTN); hrgn = set_control_clipping( hDC, &dis.rcItem ); SendMessageW( GetParent(hwnd), WM_DRAWITEM, id, (LPARAM)&dis ); if (hPrevFont) SelectObject(hDC, hPrevFont); SelectClipRgn( hDC, hrgn ); if (hrgn) DeleteObject( hrgn ); }
static void UB_Paint( HWND hwnd, HDC hDC, UINT action ) { RECT rc; HBRUSH hBrush; HFONT hFont; LONG state = get_button_state( hwnd ); HWND parent; if (action == ODA_SELECT) return; GetClientRect( hwnd, &rc); if ((hFont = get_button_font( hwnd ))) SelectObject( hDC, hFont ); parent = GetParent(hwnd); if (!parent) parent = hwnd; hBrush = (HBRUSH)SendMessageW(parent, WM_CTLCOLORBTN, (WPARAM)hDC, (LPARAM)hwnd); if (!hBrush) /* did the app forget to call defwindowproc ? */ hBrush = (HBRUSH)DefWindowProcW(parent, WM_CTLCOLORBTN, (WPARAM)hDC, (LPARAM)hwnd); FillRect( hDC, &rc, hBrush ); if ((action == ODA_FOCUS) || ((action == ODA_DRAWENTIRE) && (state & BUTTON_HASFOCUS))) DrawFocusRect( hDC, &rc ); BUTTON_NOTIFY_PARENT( hwnd, BN_PAINT ); }
/********************************************************************** * BUTTON_DrawLabel * * Common function for drawing button label. */ static void BUTTON_DrawLabel(HWND hwnd, HDC hdc, UINT dtFlags, const RECT *rc) { DRAWSTATEPROC lpOutputProc = NULL; LPARAM lp; WPARAM wp = 0; HBRUSH hbr = 0; UINT flags = IsWindowEnabled(hwnd) ? DSS_NORMAL : DSS_DISABLED; LONG state = get_button_state( hwnd ); LONG style = GetWindowLongPtrW( hwnd, GWL_STYLE ); WCHAR *text = NULL; /* FIXME: To draw disabled label in Win31 look-and-feel, we probably * must use DSS_MONO flag and COLOR_GRAYTEXT brush (or maybe DSS_UNION). * I don't have Win31 on hand to verify that, so I leave it as is. */ if ((style & BS_PUSHLIKE) && (state & BST_INDETERMINATE)) { hbr = GetSysColorBrush(COLOR_GRAYTEXT); flags |= DSS_MONO; } switch (style & (BS_ICON|BS_BITMAP)) { case BS_TEXT: /* DST_COMPLEX -- is 0 */ lpOutputProc = BUTTON_DrawTextCallback; if (!(text = get_button_text( hwnd ))) return; lp = (LPARAM)text; wp = (WPARAM)dtFlags; if (dtFlags & DT_HIDEPREFIX) flags |= DSS_HIDEPREFIX; break; case BS_ICON: flags |= DST_ICON; lp = GetWindowLongPtrW( hwnd, HIMAGE_GWL_OFFSET ); break; case BS_BITMAP: flags |= DST_BITMAP; lp = GetWindowLongPtrW( hwnd, HIMAGE_GWL_OFFSET ); break; default: return; } DrawStateW(hdc, hbr, lpOutputProc, lp, wp, rc->left, rc->top, rc->right - rc->left, rc->bottom - rc->top, flags); HeapFree( GetProcessHeap(), 0, text ); }
unsigned char get_button_event(void) { unsigned char s = get_button_state(); if (s && (s == button_state)) { unsigned long t = (millis() - button_time); switch (button_phase) { case 1: if (t >= DEBOUNCE_TIME) { button_phase = 2; button_time = millis(); return s | BUTTON_EVENT_TYPE_FIRST; } else { return 0; } break; case 2: if (t >= REPEAT_DELAY) { button_phase = 3; button_time = millis(); return s | BUTTON_EVENT_TYPE_REPEAT; } else { return s | BUTTON_EVENT_TYPE_DOWN; } break; case 3: if (t >= REPEAT_RATE) { button_time = millis(); return s | BUTTON_EVENT_TYPE_REPEAT; } else { return s | BUTTON_EVENT_TYPE_DOWN; } break; } } else { unsigned char re = (button_phase > 1) ? (button_state | BUTTON_EVENT_TYPE_RELEASE) : 0; button_state = s; button_phase = s ? 1 : 0; button_time = s ? millis() : 0; return re; } }
static void UB_Paint( HWND hwnd, HDC hDC, UINT action ) { RECT rc; HBRUSH hBrush; HFONT hFont; LONG state = get_button_state( hwnd ); HWND parent; GetClientRect( hwnd, &rc); if ((hFont = get_button_font( hwnd ))) SelectObject( hDC, hFont ); parent = GetParent(hwnd); if (!parent) parent = hwnd; hBrush = (HBRUSH)SendMessageW(parent, WM_CTLCOLORBTN, (WPARAM)hDC, (LPARAM)hwnd); if (!hBrush) /* did the app forget to call defwindowproc ? */ hBrush = (HBRUSH)DefWindowProcW(parent, WM_CTLCOLORBTN, (WPARAM)hDC, (LPARAM)hwnd); FillRect( hDC, &rc, hBrush ); if (action == ODA_FOCUS || (state & BST_FOCUS)) DrawFocusRect( hDC, &rc ); switch (action) { case ODA_FOCUS: BUTTON_NOTIFY_PARENT( hwnd, (state & BST_FOCUS) ? BN_SETFOCUS : BN_KILLFOCUS ); break; case ODA_SELECT: BUTTON_NOTIFY_PARENT( hwnd, (state & BST_PUSHED) ? BN_HILITE : BN_UNHILITE ); break; default: BUTTON_NOTIFY_PARENT( hwnd, BN_PAINT ); break; } }
static void UB_Paint( HWND hwnd, HDC hDC, UINT action ) { RECT rc; HBRUSH hBrush; HFONT hFont; LONG state = get_button_state( hwnd ); HWND parent; GetClientRect( hwnd, &rc); if ((hFont = get_button_font( hwnd ))) SelectObject( hDC, hFont ); parent = GetParent(hwnd); if (!parent) parent = hwnd; hBrush = GetControlColor( parent, hwnd, hDC, WM_CTLCOLORBTN); FillRect( hDC, &rc, hBrush ); if (action == ODA_FOCUS || (state & BST_FOCUS)) { if (!(get_ui_state(hwnd) & UISF_HIDEFOCUS)) DrawFocusRect( hDC, &rc ); } switch (action) { case ODA_FOCUS: BUTTON_NOTIFY_PARENT( hwnd, (state & BST_FOCUS) ? BN_SETFOCUS : BN_KILLFOCUS ); break; case ODA_SELECT: BUTTON_NOTIFY_PARENT( hwnd, (state & BST_PUSHED) ? BN_HILITE : BN_UNHILITE ); break; default: BUTTON_NOTIFY_PARENT( hwnd, BN_PAINT ); break; } }
BOOL BUTTON_PaintWithTheme(HTHEME theme, HWND hwnd, HDC hParamDC, LPARAM prfFlag) { DWORD dwStyle; DWORD dwStyleEx; DWORD type; UINT dtFlags; int state; ButtonState drawState; pfThemedPaint paint; /* Don't draw with themes on a button with BS_ICON or BS_BITMAP */ if (get_button_image(hwnd) != 0) return FALSE; dwStyle = GetWindowLongW(hwnd, GWL_STYLE); type = dwStyle & BUTTON_TYPE; if (type != BS_PUSHBUTTON && type != BS_DEFPUSHBUTTON && (dwStyle & BS_PUSHLIKE)) type = BS_PUSHBUTTON; paint = btnThemedPaintFunc[type]; if (!paint) return FALSE; dwStyleEx = GetWindowLongW(hwnd, GWL_EXSTYLE); dtFlags = get_drawtext_flags(dwStyle, dwStyleEx); state = get_button_state(hwnd); if(dwStyle & WS_DISABLED) drawState = STATE_DISABLED; else if(state & BST_PUSHED) drawState = STATE_PRESSED; else if ((dwStyle & BS_PUSHLIKE) && (state & (BST_CHECKED|BST_INDETERMINATE))) drawState = STATE_PRESSED; else if(state & BST_HOT) drawState = STATE_HOT; else if((state & BST_FOCUS) || (dwStyle & BS_DEFPUSHBUTTON)) drawState = STATE_DEFAULTED; else drawState = STATE_NORMAL; if (paint == PB_draw || paint == CB_draw) { HDC hdc; HBITMAP hbmp; RECT rc; GetClientRect(hwnd, &rc); hdc = CreateCompatibleDC(hParamDC); hbmp = CreateCompatibleBitmap(hParamDC, rc.right, rc.bottom); if (hdc && hbmp) { SelectObject(hdc, hbmp); paint(theme, hwnd, hdc, drawState, dtFlags, state & BST_FOCUS, prfFlag); BitBlt(hParamDC, 0, 0, rc.right, rc.bottom, hdc, 0, 0, SRCCOPY); DeleteObject(hbmp); DeleteDC(hdc); return TRUE; } else { ERR("Failed to create DC and bitmap for double buffering\n"); if (hbmp) DeleteObject(hbmp); if (hdc) DeleteDC(hdc); } } paint(theme, hwnd, hParamDC, drawState, dtFlags, state & BST_FOCUS, prfFlag); return TRUE; }
void Joypad::button_released(Button::Name b) { buttons[b] = false; memory.direct_io_write8(Memory::IO::JOYP, get_button_state()); }
static void CB_draw(HTHEME theme, HWND hwnd, HDC hDC, ButtonState drawState, UINT dtFlags, BOOL focused, LPARAM prfFlag) { static const int cb_states[3][5] = { { CBS_UNCHECKEDNORMAL, CBS_UNCHECKEDHOT, CBS_UNCHECKEDPRESSED, CBS_UNCHECKEDDISABLED, CBS_UNCHECKEDNORMAL }, { CBS_CHECKEDNORMAL, CBS_CHECKEDHOT, CBS_CHECKEDPRESSED, CBS_CHECKEDDISABLED, CBS_CHECKEDNORMAL }, { CBS_MIXEDNORMAL, CBS_MIXEDHOT, CBS_MIXEDPRESSED, CBS_MIXEDDISABLED, CBS_MIXEDNORMAL } }; static const int rb_states[2][5] = { { RBS_UNCHECKEDNORMAL, RBS_UNCHECKEDHOT, RBS_UNCHECKEDPRESSED, RBS_UNCHECKEDDISABLED, RBS_UNCHECKEDNORMAL }, { RBS_CHECKEDNORMAL, RBS_CHECKEDHOT, RBS_CHECKEDPRESSED, RBS_CHECKEDDISABLED, RBS_CHECKEDNORMAL } }; SIZE sz; RECT bgRect, textRect; HFONT font, hPrevFont = NULL; LRESULT checkState = get_button_state(hwnd) & 3; DWORD dwStyle = GetWindowLongW(hwnd, GWL_STYLE); int part = ((dwStyle & BUTTON_TYPE) == BS_RADIOBUTTON) || ((dwStyle & BUTTON_TYPE) == BS_AUTORADIOBUTTON) ? BP_RADIOBUTTON : BP_CHECKBOX; int state = (part == BP_CHECKBOX) ? cb_states[ checkState ][ drawState ] : rb_states[ checkState ][ drawState ]; WCHAR *text; LOGFONTW lf; BOOL created_font = FALSE; HWND parent; HBRUSH hBrush; DWORD cdrf; HRESULT hr = GetThemeFont(theme, hDC, part, state, TMT_FONT, &lf); if (SUCCEEDED(hr)) { font = CreateFontIndirectW(&lf); if (!font) TRACE("Failed to create font\n"); else { TRACE("font = %s\n", debugstr_w(lf.lfFaceName)); hPrevFont = SelectObject(hDC, font); created_font = TRUE; } } else { font = get_button_font(hwnd); hPrevFont = SelectObject(hDC, font); } if (FAILED(GetThemePartSize(theme, hDC, part, state, NULL, TS_DRAW, &sz))) sz.cx = sz.cy = 13; GetClientRect(hwnd, &bgRect); if (prfFlag == 0) { DrawThemeParentBackground(hwnd, hDC, NULL); } parent = GetParent(hwnd); if (!parent) parent = hwnd; hBrush = (HBRUSH)SendMessageW(parent, WM_CTLCOLORSTATIC, (WPARAM)hDC, (LPARAM)hwnd); if (!hBrush) /* did the app forget to call defwindowproc ? */ hBrush = (HBRUSH)DefWindowProcW(parent, WM_CTLCOLORSTATIC, (WPARAM)hDC, (LPARAM)hwnd ); FillRect( hDC, &bgRect, hBrush ); cdrf = BUTTON_SendCustomDraw(hwnd, hDC, CDDS_PREERASE, &bgRect); if (cdrf == CDRF_SKIPDEFAULT) goto cleanup; GetThemeBackgroundContentRect(theme, hDC, part, state, &bgRect, &textRect); if (dtFlags & DT_SINGLELINE) /* Center the checkbox / radio button to the text. */ bgRect.top = bgRect.top + (textRect.bottom - textRect.top - sz.cy) / 2; /* adjust for the check/radio marker */ bgRect.bottom = bgRect.top + sz.cy; bgRect.right = bgRect.left + sz.cx; textRect.left = bgRect.right + 6; DrawThemeBackground(theme, hDC, part, state, &bgRect, NULL); if (cdrf == CDRF_NOTIFYPOSTERASE) BUTTON_SendCustomDraw(hwnd, hDC, CDDS_POSTERASE, &bgRect); cdrf = BUTTON_SendCustomDraw(hwnd, hDC, CDDS_PREPAINT, &bgRect); if (cdrf == CDRF_SKIPDEFAULT) goto cleanup; text = get_button_text(hwnd); if (text) { DrawThemeText(theme, hDC, part, state, text, lstrlenW(text), dtFlags, 0, &textRect); if (focused) { RECT focusRect; focusRect = textRect; DrawTextW(hDC, text, lstrlenW(text), &focusRect, dtFlags | DT_CALCRECT); if (focusRect.right < textRect.right) focusRect.right++; focusRect.bottom = textRect.bottom; DrawFocusRect( hDC, &focusRect ); } HeapFree(GetProcessHeap(), 0, text); } if (cdrf == CDRF_NOTIFYPOSTPAINT) BUTTON_SendCustomDraw(hwnd, hDC, CDDS_POSTPAINT, &bgRect); cleanup: if (created_font) DeleteObject(font); if (hPrevFont) SelectObject(hDC, hPrevFont); }
static void CB_Paint( HWND hwnd, HDC hDC, UINT action ) { RECT rbox, rtext, client; HBRUSH hBrush; int delta; UINT dtFlags; HFONT hFont; LONG state = get_button_state( hwnd ); LONG style = GetWindowLongPtrW( hwnd, GWL_STYLE ); HWND parent; HRGN hrgn; if (style & BS_PUSHLIKE) { PB_Paint( hwnd, hDC, action ); return; } GetClientRect(hwnd, &client); rbox = rtext = client; if ((hFont = get_button_font( hwnd ))) SelectObject( hDC, hFont ); parent = GetParent(hwnd); if (!parent) parent = hwnd; hBrush = GetControlColor( parent, hwnd, hDC, WM_CTLCOLORSTATIC); hrgn = set_control_clipping( hDC, &client ); if (style & BS_LEFTTEXT) { /* magic +4 is what CTL3D expects */ rtext.right -= checkBoxWidth + 4; rbox.left = rbox.right - checkBoxWidth; } else { rtext.left += checkBoxWidth + 4; rbox.right = checkBoxWidth; } /* Since WM_ERASEBKGND does nothing, first prepare background */ if (action == ODA_SELECT) FillRect( hDC, &rbox, hBrush ); if (action == ODA_DRAWENTIRE) FillRect( hDC, &client, hBrush ); /* Draw label */ client = rtext; dtFlags = BUTTON_CalcLabelRect(hwnd, hDC, &rtext); /* Only adjust rbox when rtext is valid */ if (dtFlags != (UINT)-1L) { rbox.top = rtext.top; rbox.bottom = rtext.bottom; } /* Draw the check-box bitmap */ if (action == ODA_DRAWENTIRE || action == ODA_SELECT) { UINT flags; if ((get_button_type(style) == BS_RADIOBUTTON) || (get_button_type(style) == BS_AUTORADIOBUTTON)) flags = DFCS_BUTTONRADIO; else if (state & BST_INDETERMINATE) flags = DFCS_BUTTON3STATE; else flags = DFCS_BUTTONCHECK; if (state & (BST_CHECKED | BST_INDETERMINATE)) flags |= DFCS_CHECKED; if (state & BST_PUSHED) flags |= DFCS_PUSHED; if (style & WS_DISABLED) flags |= DFCS_INACTIVE; /* rbox must have the correct height */ delta = rbox.bottom - rbox.top - checkBoxHeight; if (style & BS_TOP) { if (delta > 0) { rbox.bottom = rbox.top + checkBoxHeight; } else { rbox.top -= -delta/2 + 1; rbox.bottom = rbox.top + checkBoxHeight; } } else if (style & BS_BOTTOM) { if (delta > 0) { rbox.top = rbox.bottom - checkBoxHeight; } else { rbox.bottom += -delta/2 + 1; rbox.top = rbox.bottom - checkBoxHeight; } } else { /* Default */ if (delta > 0) { int ofs = (delta / 2); rbox.bottom -= ofs + 1; rbox.top = rbox.bottom - checkBoxHeight; } else if (delta < 0) { int ofs = (-delta / 2); rbox.top -= ofs + 1; rbox.bottom = rbox.top + checkBoxHeight; } } DrawFrameControl( hDC, &rbox, DFC_BUTTON, flags ); } if (dtFlags == (UINT)-1L) /* Noting to draw */ return; if (action == ODA_DRAWENTIRE) BUTTON_DrawLabel(hwnd, hDC, dtFlags, &rtext); /* ... and focus */ if (action == ODA_FOCUS || (state & BST_FOCUS)) { if (!(get_ui_state(hwnd) & UISF_HIDEFOCUS)) { rtext.left--; rtext.right++; IntersectRect(&rtext, &rtext, &client); DrawFocusRect( hDC, &rtext ); } } SelectClipRgn( hDC, hrgn ); if (hrgn) DeleteObject( hrgn ); }
void Joypad::button_pressed(Button::Name b) { buttons[b] = true; memory.direct_io_write8(Memory::IO::JOYP, get_button_state()); }
void main(void) { initialize(); /* // test: write alphabet while (1) { for (int i = 'A'; i <= 'Z'+1; i++) { set_char_at(i, 0); set_char_at(i+1, 1); set_char_at(i+2, 2); set_char_at(i+3, 3); if (get_digits() == 6) { set_char_at(i+4, 4); set_char_at(i+5, 5); } _delay_ms(250); } } */ uint8_t hour = 0, min = 0, sec = 0; // Counters used when setting time int16_t time_to_set = 0; uint16_t button_released_timer = 0; uint16_t button_speed = 2; switch (shield) { case(SHIELD_IV6): set_string("IV-6"); break; case(SHIELD_IV17): set_string("IV17"); break; case(SHIELD_IV18): set_string("IV18"); break; case(SHIELD_IV22): set_string("IV22"); break; default: break; } // piezo_init(); // beep(440, 1); // beep(1320, 1); beep(440, 1); _delay_ms(500); //set_string("--------"); while (1) { // <<< ===================== MAIN LOOP ===================== >>> get_button_state(&buttons); // When alarming: // any button press cancels alarm if (g_alarming) { display_time(clock_mode); // read and display time (??) // fixme: if keydown is detected here, wait for keyup and clear state // this prevents going into the menu when disabling the alarm if (buttons.b1_keydown || buttons.b1_keyup || buttons.b2_keydown || buttons.b2_keyup) { buttons.b1_keyup = 0; // clear state buttons.b2_keyup = 0; // clear state g_alarming = false; } else { alarm(); } } // If both buttons are held: // * If the ALARM BUTTON SWITCH is on the LEFT, go into set time mode // * If the ALARM BUTTON SWITCH is on the RIGHT, go into set alarm mode else if (menu_state == STATE_CLOCK && buttons.both_held) { if (g_alarm_switch) { menu_state = STATE_SET_ALARM; show_set_alarm(); rtc_get_alarm_s(&alarm_hour, &alarm_min, &alarm_sec); time_to_set = alarm_hour*60 + alarm_min; } else { menu_state = STATE_SET_CLOCK; show_set_time(); rtc_get_time_s(&hour, &min, &sec); time_to_set = hour*60 + min; } set_blink(true); // wait until both buttons are released while (1) { _delay_ms(50); get_button_state(&buttons); if (buttons.none_held) break; } } // Set time or alarm else if (menu_state == STATE_SET_CLOCK || menu_state == STATE_SET_ALARM) { // Check if we should exit STATE_SET_CLOCK or STATE_SET_ALARM if (buttons.none_held) { set_blink(true); button_released_timer++; button_speed = 1; } else { set_blink(false); button_released_timer = 0; button_speed++; } // exit mode after no button has been touched for a while if (button_released_timer >= MENU_TIMEOUT) { set_blink(false); button_released_timer = 0; button_speed = 1; // fixme: should be different in 12h mode if (menu_state == STATE_SET_CLOCK) { rtc_set_time_s(time_to_set / 60, time_to_set % 60, 0); #if defined FEATURE_AUTO_DST g_DST_updated = false; // allow automatic DST adjustment again #endif } else { alarm_hour = time_to_set / 60; alarm_min = time_to_set % 60; alarm_sec = 0; rtc_set_alarm_s(alarm_hour, alarm_min, alarm_sec); } menu_state = STATE_CLOCK; } // Increase / Decrease time counter if (buttons.b1_repeat) time_to_set+=(button_speed/10); if (buttons.b1_keyup) time_to_set++; if (buttons.b2_repeat) time_to_set-=(button_speed/10); if (buttons.b2_keyup) time_to_set--; if (time_to_set >= 1440) time_to_set = 0; if (time_to_set < 0) time_to_set = 1439; show_time_setting(time_to_set / 60, time_to_set % 60, 0); } else if (menu_state == STATE_CLOCK && buttons.b2_keyup) { // Left button enters menu menu_state = STATE_MENU; // if (get_digits() < 8) // only set first time flag for 4 or 6 digit displays // menu_update = false; // set first time flag // show_setting_int("BRIT", "BRITE", g_brightness, false); menu(0); // show first menu item buttons.b2_keyup = 0; // clear state } // Right button toggles display mode else if (menu_state == STATE_CLOCK && buttons.b1_keyup) { clock_mode++; #ifdef FEATURE_FLW if (clock_mode == MODE_FLW && !g_has_eeprom) clock_mode++; if (clock_mode == MODE_FLW && !g_flw_enabled) clock_mode++; #endif #ifdef FEATURE_AUTO_DATE if (clock_mode == MODE_DATE) { g_show_special_cnt = g_autodisp; // show date for g_autodisp ms scroll_ctr = 0; // reset scroll position } #endif if (clock_mode == MODE_LAST) clock_mode = MODE_NORMAL; buttons.b1_keyup = 0; // clear state } else if (menu_state == STATE_MENU) { if (buttons.none_held) button_released_timer++; else button_released_timer = 0; if (button_released_timer >= MENU_TIMEOUT) { button_released_timer = 0; menu_state = STATE_CLOCK; } if (buttons.b1_keyup) { // right button menu(1); // right button buttons.b1_keyup = false; } // if (buttons.b1_keyup) if (buttons.b2_keyup) { // left button menu(2); // left button buttons.b2_keyup = 0; // clear state } } else { if (g_show_special_cnt>0) { g_show_special_cnt--; if (g_show_special_cnt == 0) { switch (clock_mode) { case MODE_ALARM_TEXT: clock_mode = MODE_ALARM_TIME; g_show_special_cnt = 10; break; case MODE_ALARM_TIME: clock_mode = MODE_NORMAL; break; #ifdef FEATURE_AUTO_DATE case MODE_DATE: clock_mode = save_mode; // 11oct12/wbp break; #endif default: clock_mode = MODE_NORMAL; } } } // read RTC & update display approx every 100ms (wm) display_time(clock_mode); // read RTC and display time } // fixme: alarm should not be checked when setting time or alarm // fixme: alarm will be missed if time goes by Second=0 while in menu if (g_alarm_switch && rtc_check_alarm_cached(tm_, alarm_hour, alarm_min, alarm_sec)) g_alarming = true; #ifdef FEATURE_AUTO_DIM if ((g_AutoDim) && (tm_->Minute == 0) && (tm_->Second == 0)) { // Auto Dim enabled? if (tm_->Hour == g_AutoDimHour) set_brightness(g_AutoDimLevel); else if (tm_->Hour == g_AutoBrtHour) set_brightness(g_AutoBrtLevel); } #endif #ifdef FEATURE_WmGPS if (g_gps_enabled) { if (gpsDataReady()) { parseGPSdata(gpsNMEA()); // get the GPS serial stream and possibly update the clock } else _delay_ms(2); } else _delay_ms(2); #endif _delay_ms(74); // tuned so loop runs 10 times a second } // while (1) } // main()
/********************************************************************** * Push Button Functions */ static void PB_Paint( HWND hwnd, HDC hDC, UINT action ) { RECT rc, r; UINT dtFlags, uState; HPEN hOldPen; HBRUSH hOldBrush; INT oldBkMode; COLORREF oldTxtColor; HFONT hFont; LONG state = get_button_state( hwnd ); LONG style = GetWindowLongPtrW( hwnd, GWL_STYLE ); BOOL pushedState = (state & BST_PUSHED); HWND parent; HRGN hrgn; GetClientRect( hwnd, &rc ); /* Send WM_CTLCOLOR to allow changing the font (the colors are fixed) */ if ((hFont = get_button_font( hwnd ))) SelectObject( hDC, hFont ); parent = GetParent(hwnd); if (!parent) parent = hwnd; GetControlColor( parent, hwnd, hDC, WM_CTLCOLORBTN); hrgn = set_control_clipping( hDC, &rc ); #ifdef __REACTOS__ hOldPen = SelectObject(hDC, GetStockObject(DC_PEN)); SetDCPenColor(hDC, GetSysColor(COLOR_WINDOWFRAME)); #else hOldPen = SelectObject(hDC, SYSCOLOR_GetPen(COLOR_WINDOWFRAME)); #endif hOldBrush = SelectObject(hDC,GetSysColorBrush(COLOR_BTNFACE)); oldBkMode = SetBkMode(hDC, TRANSPARENT); if (get_button_type(style) == BS_DEFPUSHBUTTON) { if (action != ODA_FOCUS) Rectangle(hDC, rc.left, rc.top, rc.right, rc.bottom); InflateRect( &rc, -1, -1 ); } /* completely skip the drawing if only focus has changed */ if (action == ODA_FOCUS) goto draw_focus; uState = DFCS_BUTTONPUSH; if (style & BS_FLAT) uState |= DFCS_MONO; else if (pushedState) { if (get_button_type(style) == BS_DEFPUSHBUTTON ) uState |= DFCS_FLAT; else uState |= DFCS_PUSHED; } if (state & (BST_CHECKED | BST_INDETERMINATE)) uState |= DFCS_CHECKED; DrawFrameControl( hDC, &rc, DFC_BUTTON, uState ); /* draw button label */ r = rc; dtFlags = BUTTON_CalcLabelRect(hwnd, hDC, &r); if (dtFlags == (UINT)-1L) goto cleanup; if (pushedState) OffsetRect(&r, 1, 1); oldTxtColor = SetTextColor( hDC, GetSysColor(COLOR_BTNTEXT) ); BUTTON_DrawLabel(hwnd, hDC, dtFlags, &r); SetTextColor( hDC, oldTxtColor ); draw_focus: if (action == ODA_FOCUS || (state & BST_FOCUS)) { if (!(get_ui_state(hwnd) & UISF_HIDEFOCUS)) { InflateRect( &rc, -2, -2 ); DrawFocusRect( hDC, &rc ); } } cleanup: SelectObject( hDC, hOldPen ); SelectObject( hDC, hOldBrush ); SetBkMode(hDC, oldBkMode); SelectClipRgn( hDC, hrgn ); if (hrgn) DeleteObject( hrgn ); }
/*********************************************************************** * ButtonWndProc_common */ LRESULT WINAPI ButtonWndProc_common(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL unicode ) { RECT rect; POINT pt; LONG style = GetWindowLongPtrW( hWnd, GWL_STYLE ); UINT btn_type = get_button_type( style ); LONG state; HANDLE oldHbitmap; #ifdef __REACTOS__ PWND pWnd; pWnd = ValidateHwnd(hWnd); if (pWnd) { if (!pWnd->fnid) { NtUserSetWindowFNID(hWnd, FNID_BUTTON); } else { if (pWnd->fnid != FNID_BUTTON) { ERR("Wrong window class for Button! fnId 0x%x\n",pWnd->fnid); return 0; } } } #endif pt.x = (short)LOWORD(lParam); pt.y = (short)HIWORD(lParam); switch (uMsg) { case WM_GETDLGCODE: switch(btn_type) { case BS_USERBUTTON: case BS_PUSHBUTTON: return DLGC_BUTTON | DLGC_UNDEFPUSHBUTTON; case BS_DEFPUSHBUTTON: return DLGC_BUTTON | DLGC_DEFPUSHBUTTON; case BS_RADIOBUTTON: case BS_AUTORADIOBUTTON: return DLGC_BUTTON | DLGC_RADIOBUTTON; case BS_GROUPBOX: return DLGC_STATIC; default: return DLGC_BUTTON; } case WM_ENABLE: paint_button( hWnd, btn_type, ODA_DRAWENTIRE ); break; case WM_CREATE: if (!hbitmapCheckBoxes) { BITMAP bmp; hbitmapCheckBoxes = LoadBitmapW(0, MAKEINTRESOURCEW(OBM_CHECKBOXES)); GetObjectW( hbitmapCheckBoxes, sizeof(bmp), &bmp ); checkBoxWidth = bmp.bmWidth / 4; checkBoxHeight = bmp.bmHeight / 3; } if (btn_type >= MAX_BTN_TYPE) return -1; /* abort */ /* XP turns a BS_USERBUTTON into BS_PUSHBUTTON */ if (btn_type == BS_USERBUTTON ) { #ifdef __REACTOS__ style = (style & ~BS_TYPEMASK) | BS_PUSHBUTTON; SetWindowLongPtrW( hWnd, GWL_STYLE, style ); #else style = (style & ~BS_TYPEMASK) | BS_PUSHBUTTON; WIN_SetStyle( hWnd, style, BS_TYPEMASK & ~style ); #endif } set_button_state( hWnd, BST_UNCHECKED ); button_update_uistate( hWnd, unicode ); return 0; #ifdef __REACTOS__ case WM_NCDESTROY: NtUserSetWindowFNID(hWnd, FNID_DESTROY); case WM_DESTROY: break; #endif case WM_ERASEBKGND: if (btn_type == BS_OWNERDRAW) { HDC hdc = (HDC)wParam; RECT rc; HBRUSH hBrush; HWND parent = GetParent(hWnd); if (!parent) parent = hWnd; hBrush = GetControlColor( parent, hWnd, hdc, WM_CTLCOLORBTN); GetClientRect(hWnd, &rc); FillRect(hdc, &rc, hBrush); } return 1; case WM_PRINTCLIENT: case WM_PAINT: if (btnPaintFunc[btn_type]) { PAINTSTRUCT ps; HDC hdc = wParam ? (HDC)wParam : BeginPaint( hWnd, &ps ); int nOldMode = SetBkMode( hdc, OPAQUE ); (btnPaintFunc[btn_type])( hWnd, hdc, ODA_DRAWENTIRE ); SetBkMode(hdc, nOldMode); /* reset painting mode */ if( !wParam ) EndPaint( hWnd, &ps ); } break; case WM_KEYDOWN: if (wParam == VK_SPACE) { SendMessageW( hWnd, BM_SETSTATE, TRUE, 0 ); set_button_state( hWnd, get_button_state( hWnd ) | BUTTON_BTNPRESSED ); SetCapture( hWnd ); } break; case WM_LBUTTONDBLCLK: if(style & BS_NOTIFY || btn_type == BS_RADIOBUTTON || btn_type == BS_USERBUTTON || btn_type == BS_OWNERDRAW) { BUTTON_NOTIFY_PARENT(hWnd, BN_DOUBLECLICKED); break; } /* fall through */ case WM_LBUTTONDOWN: SetCapture( hWnd ); SetFocus( hWnd ); set_button_state( hWnd, get_button_state( hWnd ) | BUTTON_BTNPRESSED ); SendMessageW( hWnd, BM_SETSTATE, TRUE, 0 ); break; case WM_KEYUP: if (wParam != VK_SPACE) break; /* fall through */ case WM_LBUTTONUP: state = get_button_state( hWnd ); if (!(state & BUTTON_BTNPRESSED)) break; state &= BUTTON_NSTATES; set_button_state( hWnd, state ); if (!(state & BST_PUSHED)) { ReleaseCapture(); break; } SendMessageW( hWnd, BM_SETSTATE, FALSE, 0 ); ReleaseCapture(); GetClientRect( hWnd, &rect ); if (uMsg == WM_KEYUP || PtInRect( &rect, pt )) { state = get_button_state( hWnd ); switch(btn_type) { case BS_AUTOCHECKBOX: SendMessageW( hWnd, BM_SETCHECK, !(state & BST_CHECKED), 0 ); break; case BS_AUTORADIOBUTTON: SendMessageW( hWnd, BM_SETCHECK, TRUE, 0 ); break; case BS_AUTO3STATE: SendMessageW( hWnd, BM_SETCHECK, (state & BST_INDETERMINATE) ? 0 : ((state & 3) + 1), 0 ); break; } BUTTON_NOTIFY_PARENT(hWnd, BN_CLICKED); } break; case WM_CAPTURECHANGED: TRACE("WM_CAPTURECHANGED %p\n", hWnd); state = get_button_state( hWnd ); if (state & BUTTON_BTNPRESSED) { state &= BUTTON_NSTATES; set_button_state( hWnd, state ); if (state & BST_PUSHED) SendMessageW( hWnd, BM_SETSTATE, FALSE, 0 ); } break; case WM_MOUSEMOVE: if ((wParam & MK_LBUTTON) && GetCapture() == hWnd) { GetClientRect( hWnd, &rect ); SendMessageW( hWnd, BM_SETSTATE, PtInRect(&rect, pt), 0 ); } break; case WM_SETTEXT: { /* Clear an old text here as Windows does */ // // wine Bug: http://bugs.winehq.org/show_bug.cgi?id=25790 // Patch: http://source.winehq.org/patches/data/70889 // By: Alexander LAW, Replicate Windows behavior of WM_SETTEXT handler regarding WM_CTLCOLOR* // if (style & WS_VISIBLE) { HDC hdc = GetDC(hWnd); HBRUSH hbrush; RECT client, rc; HWND parent = GetParent(hWnd); UINT ctlMessage=(btn_type == BS_PUSHBUTTON || btn_type == BS_DEFPUSHBUTTON || btn_type == BS_PUSHLIKE || btn_type == BS_USERBUTTON || btn_type == BS_OWNERDRAW) ? WM_CTLCOLORBTN : WM_CTLCOLORSTATIC; if (!parent) parent = hWnd; hbrush = GetControlColor( parent, hWnd, hdc, ctlMessage); GetClientRect(hWnd, &client); rc = client; BUTTON_CalcLabelRect(hWnd, hdc, &rc); /* Clip by client rect bounds */ if (rc.right > client.right) rc.right = client.right; if (rc.bottom > client.bottom) rc.bottom = client.bottom; FillRect(hdc, &rc, hbrush); ReleaseDC(hWnd, hdc); } //// if (unicode) DefWindowProcW( hWnd, WM_SETTEXT, wParam, lParam ); else DefWindowProcA( hWnd, WM_SETTEXT, wParam, lParam ); if (btn_type == BS_GROUPBOX) /* Yes, only for BS_GROUPBOX */ InvalidateRect( hWnd, NULL, TRUE ); else paint_button( hWnd, btn_type, ODA_DRAWENTIRE ); return 1; /* success. FIXME: check text length */ } case WM_SETFONT: set_button_font( hWnd, (HFONT)wParam ); if (lParam) InvalidateRect(hWnd, NULL, TRUE); break; case WM_GETFONT: return (LRESULT)get_button_font( hWnd ); case WM_SETFOCUS: TRACE("WM_SETFOCUS %p\n",hWnd); set_button_state( hWnd, get_button_state(hWnd) | BST_FOCUS ); paint_button( hWnd, btn_type, ODA_FOCUS ); if (style & BS_NOTIFY) BUTTON_NOTIFY_PARENT(hWnd, BN_SETFOCUS); break; case WM_KILLFOCUS: TRACE("WM_KILLFOCUS %p\n",hWnd); state = get_button_state( hWnd ); set_button_state( hWnd, state & ~BST_FOCUS ); paint_button( hWnd, btn_type, ODA_FOCUS ); if ((state & BUTTON_BTNPRESSED) && GetCapture() == hWnd) ReleaseCapture(); if (style & BS_NOTIFY) BUTTON_NOTIFY_PARENT(hWnd, BN_KILLFOCUS); InvalidateRect( hWnd, NULL, FALSE ); break; case WM_SYSCOLORCHANGE: InvalidateRect( hWnd, NULL, FALSE ); break; case BM_SETSTYLE: if ((wParam & BS_TYPEMASK) >= MAX_BTN_TYPE) break; btn_type = wParam & BS_TYPEMASK; style = (style & ~BS_TYPEMASK) | btn_type; SetWindowLongPtrW( hWnd, GWL_STYLE, style ); //WIN_SetStyle( hWnd, style, BS_TYPEMASK & ~style ); /* Only redraw if lParam flag is set.*/ if (lParam) InvalidateRect( hWnd, NULL, TRUE ); break; case BM_CLICK: //// ReactOS state = get_button_state( hWnd ); if (state & BUTTON_BMCLICK) break; set_button_state( hWnd, state | BUTTON_BMCLICK ); // Tracked in STATE_GWL_OFFSET. //// SendMessageW( hWnd, WM_LBUTTONDOWN, 0, 0 ); SendMessageW( hWnd, WM_LBUTTONUP, 0, 0 ); //// state = get_button_state( hWnd ); if (!(state & BUTTON_BMCLICK)) break; state &= ~BUTTON_BMCLICK; set_button_state( hWnd, state ); //// break; case BM_SETIMAGE: /* Check that image format matches button style */ switch (style & (BS_BITMAP|BS_ICON)) { case BS_BITMAP: if (wParam != IMAGE_BITMAP) return 0; break; case BS_ICON: if (wParam != IMAGE_ICON) return 0; break; default: return 0; } oldHbitmap = (HBITMAP)SetWindowLongPtrW( hWnd, HIMAGE_GWL_OFFSET, lParam ); InvalidateRect( hWnd, NULL, FALSE ); return (LRESULT)oldHbitmap; case BM_GETIMAGE: return GetWindowLongPtrW( hWnd, HIMAGE_GWL_OFFSET ); case BM_GETCHECK: return get_button_state( hWnd ) & 3; case BM_SETCHECK: if (wParam > maxCheckState[btn_type]) wParam = maxCheckState[btn_type]; state = get_button_state( hWnd ); if ((btn_type == BS_RADIOBUTTON) || (btn_type == BS_AUTORADIOBUTTON)) { #ifdef __REACTOS__ if (wParam) style |= WS_TABSTOP; else style &= ~WS_TABSTOP; SetWindowLongPtrW( hWnd, GWL_STYLE, style ); #else if (wParam) WIN_SetStyle( hWnd, WS_TABSTOP, 0 ); else WIN_SetStyle( hWnd, 0, WS_TABSTOP ); #endif } if ((state & 3) != wParam) { set_button_state( hWnd, (state & ~3) | wParam ); paint_button( hWnd, btn_type, ODA_SELECT ); } if ((btn_type == BS_AUTORADIOBUTTON) && (wParam == BST_CHECKED) && (style & WS_CHILD)) BUTTON_CheckAutoRadioButton( hWnd ); break; case BM_GETSTATE: return get_button_state( hWnd ); case BM_SETSTATE: state = get_button_state( hWnd ); if (wParam) set_button_state( hWnd, state | BST_PUSHED ); else set_button_state( hWnd, state & ~BST_PUSHED ); paint_button( hWnd, btn_type, ODA_SELECT ); break; case WM_UPDATEUISTATE: if (unicode) DefWindowProcW(hWnd, uMsg, wParam, lParam); else DefWindowProcA(hWnd, uMsg, wParam, lParam); if (button_update_uistate(hWnd, unicode)) paint_button( hWnd, btn_type, ODA_DRAWENTIRE ); break; case WM_NCHITTEST: if(btn_type == BS_GROUPBOX) return HTTRANSPARENT; /* fall through */ default: return unicode ? DefWindowProcW(hWnd, uMsg, wParam, lParam) : DefWindowProcA(hWnd, uMsg, wParam, lParam); } return 0; }
static void handle_motion_event (GdkWindow *window, const MirInputEvent *event) { const MirPointerEvent *pointer_event = mir_input_event_get_pointer_event (event); GdkMirWindowImpl *impl = GDK_MIR_WINDOW_IMPL (window->impl); gdouble x, y; gboolean cursor_inside; guint button_state; guint new_button_state; guint modifier_state; guint32 event_time; GdkEventType event_type; guint changed_button_state; if (!pointer_event) return; _gdk_mir_window_impl_get_cursor_state (impl, &x, &y, &cursor_inside, &button_state); new_button_state = get_button_state (pointer_event); modifier_state = get_modifier_state (mir_pointer_event_modifiers (pointer_event), new_button_state); event_time = NANO_TO_MILLI (mir_input_event_get_event_time (event)); if (window) { gdouble new_x; gdouble new_y; gdouble hscroll; gdouble vscroll; /* Update which window has focus */ _gdk_mir_pointer_set_location (get_pointer (window), x, y, window, modifier_state); switch (mir_pointer_event_action (pointer_event)) { case mir_pointer_action_button_up: case mir_pointer_action_button_down: event_type = mir_pointer_event_action (pointer_event) == mir_pointer_action_button_down ? GDK_BUTTON_PRESS : GDK_BUTTON_RELEASE; changed_button_state = button_state ^ new_button_state; if (changed_button_state == 0 || (changed_button_state & GDK_BUTTON1_MASK) != 0) generate_button_event (window, event_type, x, y, GDK_BUTTON_PRIMARY, modifier_state, event_time); if ((changed_button_state & GDK_BUTTON2_MASK) != 0) generate_button_event (window, event_type, x, y, GDK_BUTTON_MIDDLE, modifier_state, event_time); if ((changed_button_state & GDK_BUTTON3_MASK) != 0) generate_button_event (window, event_type, x, y, GDK_BUTTON_SECONDARY, modifier_state, event_time); button_state = new_button_state; break; case mir_pointer_action_motion: new_x = mir_pointer_event_axis_value (pointer_event, mir_pointer_axis_x); new_y = mir_pointer_event_axis_value (pointer_event, mir_pointer_axis_y); hscroll = mir_pointer_event_axis_value (pointer_event, mir_pointer_axis_hscroll); vscroll = mir_pointer_event_axis_value (pointer_event, mir_pointer_axis_vscroll); if (hscroll != 0.0 || vscroll != 0.0) generate_scroll_event (window, x, y, hscroll, vscroll, modifier_state, event_time); if (ABS (new_x - x) > 0.5 || ABS (new_y - y) > 0.5) { generate_motion_event (window, new_x, new_y, modifier_state, event_time); x = new_x; y = new_y; } break; case mir_pointer_action_enter: if (!cursor_inside) { cursor_inside = TRUE; generate_crossing_event (window, GDK_ENTER_NOTIFY, x, y, event_time); } break; case mir_pointer_action_leave: if (cursor_inside) { cursor_inside = FALSE; generate_crossing_event (window, GDK_LEAVE_NOTIFY, x, y, event_time); } break; default: break; } _gdk_mir_window_impl_set_cursor_state (impl, x, y, cursor_inside, button_state); } }
/********************************************************************** * Push Button Functions */ static void PB_Paint( HWND hwnd, HDC hDC, UINT action ) { RECT rc, focus_rect, r; UINT dtFlags, uState; HPEN hOldPen; HBRUSH hOldBrush; INT oldBkMode; COLORREF oldTxtColor; HFONT hFont; LONG state = get_button_state( hwnd ); LONG style = GetWindowLongW( hwnd, GWL_STYLE ); BOOL pushedState = (state & BUTTON_HIGHLIGHTED); HWND parent; GetClientRect( hwnd, &rc ); /* Send WM_CTLCOLOR to allow changing the font (the colors are fixed) */ if ((hFont = get_button_font( hwnd ))) SelectObject( hDC, hFont ); parent = GetParent(hwnd); if (!parent) parent = hwnd; SendMessageW( parent, WM_CTLCOLORBTN, (WPARAM)hDC, (LPARAM)hwnd ); setup_clipping( hwnd, hDC ); hOldPen = SelectObject(hDC, SYSCOLOR_GetPen(COLOR_WINDOWFRAME)); hOldBrush = SelectObject(hDC,GetSysColorBrush(COLOR_BTNFACE)); oldBkMode = SetBkMode(hDC, TRANSPARENT); if (get_button_type(style) == BS_DEFPUSHBUTTON) { if (action != ODA_FOCUS) Rectangle(hDC, rc.left, rc.top, rc.right, rc.bottom); InflateRect( &rc, -1, -1 ); } focus_rect = rc; /* completely skip the drawing if only focus has changed */ if (action == ODA_FOCUS) goto draw_focus; uState = DFCS_BUTTONPUSH | DFCS_ADJUSTRECT; if (style & BS_FLAT) uState |= DFCS_MONO; else if (pushedState) { if (get_button_type(style) == BS_DEFPUSHBUTTON ) uState |= DFCS_FLAT; else uState |= DFCS_PUSHED; } if (state & (BUTTON_CHECKED | BUTTON_3STATE)) uState |= DFCS_CHECKED; DrawFrameControl( hDC, &rc, DFC_BUTTON, uState ); /* draw button label */ r = rc; dtFlags = BUTTON_CalcLabelRect(hwnd, hDC, &r); if (dtFlags == (UINT)-1L) goto cleanup; if (pushedState) OffsetRect(&r, 1, 1); IntersectClipRect(hDC, rc.left, rc.top, rc.right, rc.bottom); oldTxtColor = SetTextColor( hDC, GetSysColor(COLOR_BTNTEXT) ); BUTTON_DrawLabel(hwnd, hDC, dtFlags, &r); SetTextColor( hDC, oldTxtColor ); draw_focus: if ((action == ODA_FOCUS) || ((action == ODA_DRAWENTIRE) && (state & BUTTON_HASFOCUS))) { InflateRect( &focus_rect, -1, -1 ); IntersectRect(&focus_rect, &focus_rect, &rc); DrawFocusRect( hDC, &focus_rect ); } cleanup: SelectObject( hDC, hOldPen ); SelectObject( hDC, hOldBrush ); SetBkMode(hDC, oldBkMode); }
/*********************************************************************** * ButtonWndProc_common */ LRESULT ButtonWndProc_common(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL unicode ) { RECT rect; POINT pt; LONG style = GetWindowLongW( hWnd, GWL_STYLE ); UINT btn_type = get_button_type( style ); LONG state; HANDLE oldHbitmap; if (!IsWindow( hWnd )) return 0; pt.x = (short)LOWORD(lParam); pt.y = (short)HIWORD(lParam); switch (uMsg) { case WM_GETDLGCODE: switch(btn_type) { case BS_USERBUTTON: case BS_PUSHBUTTON: return DLGC_BUTTON | DLGC_UNDEFPUSHBUTTON; case BS_DEFPUSHBUTTON: return DLGC_BUTTON | DLGC_DEFPUSHBUTTON; case BS_RADIOBUTTON: case BS_AUTORADIOBUTTON: return DLGC_BUTTON | DLGC_RADIOBUTTON; case BS_GROUPBOX: return DLGC_STATIC; default: return DLGC_BUTTON; } case WM_ENABLE: paint_button( hWnd, btn_type, ODA_DRAWENTIRE ); break; case WM_CREATE: if (!hbitmapCheckBoxes) { BITMAP bmp; hbitmapCheckBoxes = LoadBitmapW(0, MAKEINTRESOURCEW(OBM_CHECKBOXES)); GetObjectW( hbitmapCheckBoxes, sizeof(bmp), &bmp ); checkBoxWidth = bmp.bmWidth / 4; checkBoxHeight = bmp.bmHeight / 3; } if (btn_type >= MAX_BTN_TYPE) return -1; /* abort */ /* XP turns a BS_USERBUTTON into BS_PUSHBUTTON */ if (btn_type == BS_USERBUTTON ) { style = (style & ~BS_TYPEMASK) | BS_PUSHBUTTON; WIN_SetStyle( hWnd, style, BS_TYPEMASK & ~style ); } set_button_state( hWnd, BST_UNCHECKED ); return 0; case WM_ERASEBKGND: if (btn_type == BS_OWNERDRAW) { HDC hdc = (HDC)wParam; RECT rc; HBRUSH hBrush; HWND parent = GetParent(hWnd); if (!parent) parent = hWnd; hBrush = (HBRUSH)SendMessageW(parent, WM_CTLCOLORBTN, (WPARAM)hdc, (LPARAM)hWnd); if (!hBrush) /* did the app forget to call defwindowproc ? */ hBrush = (HBRUSH)DefWindowProcW(parent, WM_CTLCOLORBTN, (WPARAM)hdc, (LPARAM)hWnd); GetClientRect(hWnd, &rc); FillRect(hdc, &rc, hBrush); } return 1; case WM_PRINTCLIENT: case WM_PAINT: { PAINTSTRUCT ps; HDC hdc = wParam ? (HDC)wParam : BeginPaint( hWnd, &ps ); if (btnPaintFunc[btn_type]) { int nOldMode = SetBkMode( hdc, OPAQUE ); (btnPaintFunc[btn_type])( hWnd, hdc, ODA_DRAWENTIRE ); SetBkMode(hdc, nOldMode); /* reset painting mode */ } if ( !wParam ) EndPaint( hWnd, &ps ); break; } case WM_KEYDOWN: if (wParam == VK_SPACE) { SendMessageW( hWnd, BM_SETSTATE, TRUE, 0 ); set_button_state( hWnd, get_button_state( hWnd ) | BUTTON_BTNPRESSED ); SetCapture( hWnd ); } break; case WM_LBUTTONDBLCLK: if(style & BS_NOTIFY || btn_type == BS_RADIOBUTTON || btn_type == BS_USERBUTTON || btn_type == BS_OWNERDRAW) { BUTTON_NOTIFY_PARENT(hWnd, BN_DOUBLECLICKED); break; } /* fall through */ case WM_LBUTTONDOWN: SetCapture( hWnd ); SetFocus( hWnd ); set_button_state( hWnd, get_button_state( hWnd ) | BUTTON_BTNPRESSED ); SendMessageW( hWnd, BM_SETSTATE, TRUE, 0 ); break; case WM_KEYUP: if (wParam != VK_SPACE) break; /* fall through */ case WM_LBUTTONUP: state = get_button_state( hWnd ); if (!(state & BUTTON_BTNPRESSED)) break; state &= BUTTON_NSTATES; set_button_state( hWnd, state ); if (!(state & BST_PUSHED)) { ReleaseCapture(); break; } SendMessageW( hWnd, BM_SETSTATE, FALSE, 0 ); GetClientRect( hWnd, &rect ); if (uMsg == WM_KEYUP || PtInRect( &rect, pt )) { state = get_button_state( hWnd ); switch(btn_type) { case BS_AUTOCHECKBOX: SendMessageW( hWnd, BM_SETCHECK, !(state & BST_CHECKED), 0 ); break; case BS_AUTORADIOBUTTON: SendMessageW( hWnd, BM_SETCHECK, TRUE, 0 ); break; case BS_AUTO3STATE: SendMessageW( hWnd, BM_SETCHECK, (state & BST_INDETERMINATE) ? 0 : ((state & 3) + 1), 0 ); break; } ReleaseCapture(); BUTTON_NOTIFY_PARENT(hWnd, BN_CLICKED); } else { ReleaseCapture(); } break; case WM_CAPTURECHANGED: TRACE("WM_CAPTURECHANGED %p\n", hWnd); state = get_button_state( hWnd ); if (state & BUTTON_BTNPRESSED) { state &= BUTTON_NSTATES; set_button_state( hWnd, state ); if (state & BST_PUSHED) SendMessageW( hWnd, BM_SETSTATE, FALSE, 0 ); } break; case WM_MOUSEMOVE: if ((wParam & MK_LBUTTON) && GetCapture() == hWnd) { GetClientRect( hWnd, &rect ); SendMessageW( hWnd, BM_SETSTATE, PtInRect(&rect, pt), 0 ); } break; case WM_SETTEXT: { /* Clear an old text here as Windows does */ HDC hdc = GetDC(hWnd); HBRUSH hbrush; RECT client, rc; HWND parent = GetParent(hWnd); if (!parent) parent = hWnd; hbrush = (HBRUSH)SendMessageW(parent, WM_CTLCOLORSTATIC, (WPARAM)hdc, (LPARAM)hWnd); if (!hbrush) /* did the app forget to call DefWindowProc ? */ hbrush = (HBRUSH)DefWindowProcW(parent, WM_CTLCOLORSTATIC, (WPARAM)hdc, (LPARAM)hWnd); GetClientRect(hWnd, &client); rc = client; BUTTON_CalcLabelRect(hWnd, hdc, &rc); /* Clip by client rect bounds */ if (rc.right > client.right) rc.right = client.right; if (rc.bottom > client.bottom) rc.bottom = client.bottom; FillRect(hdc, &rc, hbrush); ReleaseDC(hWnd, hdc); if (unicode) DefWindowProcW( hWnd, WM_SETTEXT, wParam, lParam ); else DefWindowProcA( hWnd, WM_SETTEXT, wParam, lParam ); if (btn_type == BS_GROUPBOX) /* Yes, only for BS_GROUPBOX */ InvalidateRect( hWnd, NULL, TRUE ); else paint_button( hWnd, btn_type, ODA_DRAWENTIRE ); return 1; /* success. FIXME: check text length */ } case WM_SETFONT: set_button_font( hWnd, (HFONT)wParam ); if (lParam) InvalidateRect(hWnd, NULL, TRUE); break; case WM_GETFONT: return (LRESULT)get_button_font( hWnd ); case WM_SETFOCUS: TRACE("WM_SETFOCUS %p\n",hWnd); set_button_state( hWnd, get_button_state(hWnd) | BST_FOCUS ); paint_button( hWnd, btn_type, ODA_FOCUS ); if (style & BS_NOTIFY) BUTTON_NOTIFY_PARENT(hWnd, BN_SETFOCUS); break; case WM_KILLFOCUS: TRACE("WM_KILLFOCUS %p\n",hWnd); state = get_button_state( hWnd ); set_button_state( hWnd, state & ~BST_FOCUS ); paint_button( hWnd, btn_type, ODA_FOCUS ); if ((state & BUTTON_BTNPRESSED) && GetCapture() == hWnd) ReleaseCapture(); if (style & BS_NOTIFY) BUTTON_NOTIFY_PARENT(hWnd, BN_KILLFOCUS); InvalidateRect( hWnd, NULL, FALSE ); break; case WM_SYSCOLORCHANGE: InvalidateRect( hWnd, NULL, FALSE ); break; case BM_SETSTYLE: btn_type = wParam & BS_TYPEMASK; style = (style & ~BS_TYPEMASK) | btn_type; WIN_SetStyle( hWnd, style, BS_TYPEMASK & ~style ); /* Only redraw if lParam flag is set.*/ if (lParam) InvalidateRect( hWnd, NULL, TRUE ); break; case BM_CLICK: SendMessageW( hWnd, WM_LBUTTONDOWN, 0, 0 ); SendMessageW( hWnd, WM_LBUTTONUP, 0, 0 ); break; case BM_SETIMAGE: /* Check that image format matches button style */ switch (style & (BS_BITMAP|BS_ICON)) { case BS_BITMAP: if (wParam != IMAGE_BITMAP) return 0; break; case BS_ICON: if (wParam != IMAGE_ICON) return 0; break; default: return 0; } oldHbitmap = (HBITMAP)SetWindowLongPtrW( hWnd, HIMAGE_GWL_OFFSET, lParam ); InvalidateRect( hWnd, NULL, FALSE ); return (LRESULT)oldHbitmap; case BM_GETIMAGE: return GetWindowLongPtrW( hWnd, HIMAGE_GWL_OFFSET ); case BM_GETCHECK: return get_button_state( hWnd ) & 3; case BM_SETCHECK: if (wParam > maxCheckState[btn_type]) wParam = maxCheckState[btn_type]; state = get_button_state( hWnd ); if ((btn_type == BS_RADIOBUTTON) || (btn_type == BS_AUTORADIOBUTTON)) { if (wParam) WIN_SetStyle( hWnd, WS_TABSTOP, 0 ); else WIN_SetStyle( hWnd, 0, WS_TABSTOP ); } if ((state & 3) != wParam) { set_button_state( hWnd, (state & ~3) | wParam ); paint_button( hWnd, btn_type, ODA_SELECT ); } if ((btn_type == BS_AUTORADIOBUTTON) && (wParam == BST_CHECKED) && (style & WS_CHILD)) BUTTON_CheckAutoRadioButton( hWnd ); break; case BM_GETSTATE: return get_button_state( hWnd ); case BM_SETSTATE: state = get_button_state( hWnd ); if (wParam) set_button_state( hWnd, state | BST_PUSHED ); else set_button_state( hWnd, state & ~BST_PUSHED ); paint_button( hWnd, btn_type, ODA_SELECT ); break; case WM_NCHITTEST: if(btn_type == BS_GROUPBOX) return HTTRANSPARENT; /* fall through */ default: return unicode ? DefWindowProcW(hWnd, uMsg, wParam, lParam) : DefWindowProcA(hWnd, uMsg, wParam, lParam); } return 0; }
void main(void) { initialize(); /* // test: write alphabet while (1) { for (int i = 'A'; i <= 'Z'+1; i++) { set_char_at(i, 0); set_char_at(i+1, 1); set_char_at(i+2, 2); set_char_at(i+3, 3); if (get_digits() == 6) { set_char_at(i+4, 4); set_char_at(i+5, 5); } _delay_ms(250); } } */ uint8_t hour = 0, min = 0, sec = 0; // Counters used when setting time int16_t time_to_set = 0; uint16_t button_released_timer = 0; uint16_t button_speed = 25; set_string("--------"); piezo_init(); beep(500, 1); beep(1000, 1); beep(500, 1); while (1) { get_button_state(&buttons); // When alarming: // any button press cancels alarm if (g_alarming) { read_rtc(clock_mode); // fixme: if keydown is detected here, wait for keyup and clear state // this prevents going into the menu when disabling the alarm if (buttons.b1_keydown || buttons.b1_keyup || buttons.b2_keydown || buttons.b2_keyup) { buttons.b1_keyup = 0; // clear state buttons.b2_keyup = 0; // clear state g_alarming = false; } else { alarm(); } } // If both buttons are held: // * If the ALARM BUTTON SWITCH is on the LEFT, go into set time mode // * If the ALARM BUTTON SWITCH is on the RIGHT, go into set alarm mode else if (clock_state == STATE_CLOCK && buttons.both_held) { if (g_alarm_switch) { clock_state = STATE_SET_ALARM; show_set_alarm(); rtc_get_alarm_s(&hour, &min, &sec); time_to_set = hour*60 + min; } else { clock_state = STATE_SET_CLOCK; show_set_time(); rtc_get_time_s(&hour, &min, &sec); time_to_set = hour*60 + min; } set_blink(true); // wait until both buttons are released while (1) { _delay_ms(50); get_button_state(&buttons); if (buttons.none_held) break; } } // Set time or alarm else if (clock_state == STATE_SET_CLOCK || clock_state == STATE_SET_ALARM) { // Check if we should exit STATE_SET_CLOCK or STATE_SET_ALARM if (buttons.none_held) { set_blink(true); button_released_timer++; button_speed = 50; } else { set_blink(false); button_released_timer = 0; button_speed++; } // exit mode after no button has been touched for a while if (button_released_timer >= 160) { set_blink(false); button_released_timer = 0; button_speed = 1; // fixme: should be different in 12h mode if (clock_state == STATE_SET_CLOCK) rtc_set_time_s(time_to_set / 60, time_to_set % 60, 0); else rtc_set_alarm_s(time_to_set / 60, time_to_set % 60, 0); clock_state = STATE_CLOCK; } // Increase / Decrease time counter if (buttons.b1_repeat) time_to_set+=(button_speed/100); if (buttons.b1_keyup) time_to_set++; if (buttons.b2_repeat) time_to_set-=(button_speed/100); if (buttons.b2_keyup) time_to_set--; if (time_to_set >= 1440) time_to_set = 0; if (time_to_set < 0) time_to_set = 1439; show_time_setting(time_to_set / 60, time_to_set % 60, 0); } // Left button enters menu else if (clock_state == STATE_CLOCK && buttons.b2_keyup) { clock_state = STATE_MENU_BRIGHTNESS; show_setting_int("BRIT", "BRITE", g_brightness, false); buttons.b2_keyup = 0; // clear state } // Right button toggles display mode else if (clock_state == STATE_CLOCK && buttons.b1_keyup) { clock_mode++; if (clock_mode == MODE_LAST) clock_mode = MODE_NORMAL; buttons.b1_keyup = 0; // clear state } else if (clock_state >= STATE_MENU_BRIGHTNESS) { if (buttons.none_held) button_released_timer++; else button_released_timer = 0; if (button_released_timer >= 80) { button_released_timer = 0; clock_state = STATE_CLOCK; } switch (clock_state) { case STATE_MENU_BRIGHTNESS: if (buttons.b1_keyup) { g_brightness++; buttons.b1_keyup = false; if (g_brightness > 10) g_brightness = 1; eeprom_update_byte(&b_brightness, g_brightness); if (shield == SHIELD_IV17) show_setting_string("BRIT", "BRITE", (g_brightness % 2 == 0) ? " lo" : " hi", true); else show_setting_int("BRIT", "BRITE", g_brightness, true); set_brightness(g_brightness); } break; case STATE_MENU_24H: if (buttons.b1_keyup) { g_24h_clock = !g_24h_clock; eeprom_update_byte(&b_24h_clock, g_24h_clock); show_setting_string("24H", "24H", g_24h_clock ? " on" : " off", true); buttons.b1_keyup = false; } break; case STATE_MENU_VOL: if (buttons.b1_keyup) { g_volume = !g_volume; eeprom_update_byte(&b_volume, g_volume); show_setting_string("VOL", "VOL", g_volume ? " hi" : " lo", true); piezo_init(); beep(1000, 1); buttons.b1_keyup = false; } break; case STATE_MENU_TEMP: if (buttons.b1_keyup) { g_show_temp = !g_show_temp; eeprom_update_byte(&b_show_temp, g_show_temp); show_setting_string("TEMP", "TEMP", g_show_temp ? " on" : " off", true); buttons.b1_keyup = false; } break; case STATE_MENU_DOTS: if (buttons.b1_keyup) { g_show_dots = !g_show_dots; eeprom_update_byte(&b_show_dots, g_show_dots); show_setting_string("DOTS", "DOTS", g_show_dots ? " on" : " off", true); buttons.b1_keyup = false; } break; default: break; // do nothing } if (buttons.b2_keyup) { clock_state++; // show temperature setting only when running on a DS3231 if (clock_state == STATE_MENU_TEMP && !rtc_is_ds3231()) clock_state++; // don't show dots settings for shields that have no dots if (clock_state == STATE_MENU_DOTS && !g_has_dots) clock_state++; if (clock_state == STATE_MENU_LAST) clock_state = STATE_MENU_BRIGHTNESS; switch (clock_state) { case STATE_MENU_BRIGHTNESS: show_setting_int("BRIT", "BRITE", g_brightness, false); break; case STATE_MENU_VOL: show_setting_string("VOL", "VOL", g_volume ? " hi" : " lo", false); break; case STATE_MENU_24H: show_setting_string("24H", "24H", g_24h_clock ? " on" : " off", false); break; case STATE_MENU_DOTS: show_setting_string("DOTS", "DOTS", g_show_dots ? " on" : " off", false); break; case STATE_MENU_TEMP: show_setting_string("TEMP", "TEMP", g_show_temp ? " on" : " off", false); break; default: break; // do nothing } buttons.b2_keyup = 0; // clear state } } else { // read RTC only aprox every 15ms static uint16_t cnt = 0; if (cnt++ % 15 == 0) read_rtc(clock_mode); } // fixme: alarm should not be checked when setting time or alarm if (g_alarm_switch && rtc_check_alarm()) g_alarming = true; _delay_ms(10); } }