static void set_buttons(int force) { if (play_state==button_state && !force) return; set_button_state(BUT_PAUSE, play_state==1); set_button_state(BUT_PLAY, play_state>1); }
void command_executor::show_menu(const std::vector<std::string>& items_arg, int xloc, int yloc, bool /*context_menu*/, display& gui) { std::vector<std::string> items = items_arg; if (items.empty()) return; std::vector<config> menu = get_menu_images(gui, items); int res = -1; { SDL_Rect pos = {xloc, yloc, 1, 1}; gui2::tdrop_down_list mmenu(pos, menu, -1, false); mmenu.show(gui.video()); if(mmenu.get_retval() == gui2::twindow::OK) { res = mmenu.selected_item(); } } // This will kill the dialog. if (res < 0 || size_t(res) >= items.size()) return; const theme::menu* submenu = gui.get_theme().get_menu_item(items[res]); if (submenu) { int y,x; SDL_GetMouseState(&x,&y); this->show_menu(submenu->items(), x, y, submenu->is_context(), gui); } else { const hotkey::hotkey_command& cmd = hotkey::get_hotkey_command(items[res]); hotkey::execute_command(cmd,this,res); set_button_state(); } }
static void NewCurrentClipContents(char *data, int len) { XawTextBlock textBlock; SaveClip (text, currentClip); /* append new clips at the end */ while (currentClip && currentClip->next) currentClip = currentClip->next; /* any trailing clips with no text get overwritten */ if (strlen (currentClip->clip) != 0) currentClip = NewClip (text, currentClip); textBlock.ptr = data; textBlock.firstPos = 0; textBlock.length = len; textBlock.format = FMT8BIT; if (XawTextReplace(text, 0, TextLength (text), &textBlock)) { #ifdef XKB XkbStdBell(XtDisplay(text), XtWindow(text), 0, XkbBI_Info); #else XBell( XtDisplay(text), 0); #endif } set_button_state (); }
void command_executor::show_menu(const std::vector<std::string>& items_arg, int xloc, int yloc, bool /*context_menu*/, display& gui) { std::vector<std::string> items = items_arg; if (items.empty()) return; std::vector<std::string> menu = get_menu_images(gui, items); int res = 0; { gui::dialog mmenu = gui::dialog(gui,"","", gui::MESSAGE, gui::dialog::hotkeys_style); mmenu.set_menu(menu); res = mmenu.show(xloc, yloc); } // This will kill the dialog. if (res < 0 || size_t(res) >= items.size()) return; const theme::menu* submenu = gui.get_theme().get_menu_item(items[res]); if (submenu) { int y,x; SDL_GetMouseState(&x,&y); this->show_menu(submenu->items(), x, y, submenu->is_context(), gui); } else { const hotkey::hotkey_command& cmd = hotkey::get_hotkey_command(items[res]); hotkey::execute_command(gui,cmd,this,res); set_button_state(gui); } }
/* ARGSUSED */ static void PrevCurrentClip(Widget w, XEvent *ev, String *parms, Cardinal *np) { if (currentClip->prev) { SaveClip (text, currentClip); currentClip = currentClip->prev; RestoreClip (text, currentClip); set_button_state (); } }
void playsingle_controller::init_gui() { LOG_NG << "Initializing GUI... " << (SDL_GetTicks() - ticks_) << "\n"; play_controller::init_gui(); if(gamestate_.first_human_team_ != -1) { gui_->scroll_to_tile(gamestate_.board_.map().starting_position(gamestate_.first_human_team_ + 1), game_display::WARP); } gui_->scroll_to_tile(gamestate_.board_.map().starting_position(1), game_display::WARP); update_locker lock_display(gui_->video(),recorder.is_skipping()); set_button_state(*gui_); events::raise_draw_event(); gui_->draw(); }
void x_gui_rep::emulate_leave_enter (widget old_widget, widget new_widget) { Window root, child; SI root_x, root_y, x, y; unsigned int mask; XQueryPointer (dpy, get_Window (old_widget), &root, &child, &root_x, &root_y, &x, &y, &mask); set_button_state (mask); x= (x * PIXEL); y= ((-y) * PIXEL); // cout << "\nLeave " << old_widget << "\n"; send_mouse (old_widget, "leave", x, y, state, 0); // cout << "Leave OK\n"; XQueryPointer (dpy, get_Window (new_widget), &root, &child, &root_x, &root_y, &x, &y, &mask); set_button_state (mask); x= (x * PIXEL); y= ((-y) * PIXEL); // cout << "Enter " << new_widget << "\n"; send_mouse (new_widget, "enter", x, y, state, 0); // cout << "Enter OK\n\n"; }
void command_executor::execute_action(const std::vector<std::string>& items_arg, int /*xloc*/, int /*yloc*/, bool /*context_menu*/, display&) { std::vector<std::string> items = items_arg; if (items.empty()) { return; } std::vector<std::string>::iterator i = items.begin(); while(i != items.end()) { const hotkey_command &command = hotkey::get_hotkey_command(*i); if (can_execute_command(command)) { hotkey::execute_command(command, this); set_button_state(); } ++i; } }
/* ARGSUSED */ static void DeleteCurrentClip(Widget w, XEvent *ev, String *parms, Cardinal *np) { ClipPtr newCurrent; if (currentClip->prev) newCurrent = currentClip->prev; else newCurrent = currentClip->next; if (newCurrent) { DeleteClip (text, currentClip); currentClip = newCurrent; RestoreClip (text, currentClip); } else EraseTextWidget (); set_button_state (); }
int main(int argc, char *argv[]) { Arg args[4]; Cardinal n; XtAppContext xtcontext; Widget parent; XtSetLanguageProc(NULL, NULL, NULL); top = XtAppInitialize( &xtcontext, "XClipboard", table, XtNumber(table), &argc, argv, fallback_resources, NULL, 0); XtGetApplicationResources(top, (XtPointer)&userOptions, resources, XtNumber(resources), NULL, 0); XtAppAddActions (xtcontext, xclipboard_actions, XtNumber (xclipboard_actions)); /* CLIPBOARD_MANAGER is a non-standard mechanism */ ManagerAtom = XInternAtom(XtDisplay(top), "CLIPBOARD_MANAGER", False); ClipboardAtom = XA_CLIPBOARD(XtDisplay(top)); if (XGetSelectionOwner(XtDisplay(top), ManagerAtom)) XtError("another clipboard is already running\n"); parent = XtCreateManagedWidget("form", formWidgetClass, top, NULL, ZERO); (void) XtCreateManagedWidget("quit", Command, parent, NULL, ZERO); (void) XtCreateManagedWidget("delete", Command, parent, NULL, ZERO); (void) XtCreateManagedWidget("new", Command, parent, NULL, ZERO); (void) XtCreateManagedWidget("save", Command, parent, NULL, ZERO); nextButton = XtCreateManagedWidget("next", Command, parent, NULL, ZERO); prevButton = XtCreateManagedWidget("prev", Command, parent, NULL, ZERO); indexLabel = XtCreateManagedWidget("index", Label, parent, NULL, ZERO); n=0; XtSetArg(args[n], XtNtype, XawAsciiString); n++; XtSetArg(args[n], XtNeditType, XawtextEdit); n++; if (userOptions.wrap) { XtSetArg(args[n], XtNwrap, XawtextWrapWord); n++; XtSetArg(args[n], XtNscrollHorizontal, False); n++; } text = XtCreateManagedWidget( "text", Text, parent, args, n); currentClip = NewClip (text, (ClipPtr) 0); set_button_state (); fileDialogShell = XtCreatePopupShell("fileDialogShell", transientShellWidgetClass, top, NULL, ZERO); fileDialog = XtCreateManagedWidget ("fileDialog", dialogWidgetClass, fileDialogShell, NULL, ZERO); XawDialogAddButton(fileDialog, "accept", NULL, NULL); XawDialogAddButton(fileDialog, "cancel", NULL, NULL); failDialogShell = XtCreatePopupShell("failDialogShell", transientShellWidgetClass, top, NULL, ZERO); failDialog = XtCreateManagedWidget ("failDialog", dialogWidgetClass, failDialogShell, NULL, ZERO); XawDialogAddButton (failDialog, "continue", NULL, NULL); XtRealizeWidget(top); XtRealizeWidget(fileDialogShell); XtRealizeWidget(failDialogShell); XtOwnSelection(top, ManagerAtom, CurrentTime, RefuseSelection, LoseManager, NULL); if (XGetSelectionOwner (XtDisplay(top), ClipboardAtom)) { LoseSelection (top, &ClipboardAtom); } else { XtOwnSelection(top, ClipboardAtom, CurrentTime, ConvertSelection, LoseSelection, NULL); } wm_delete_window = XInternAtom(XtDisplay(top), "WM_DELETE_WINDOW", False); wm_protocols = XInternAtom(XtDisplay(top), "WM_PROTOCOLS", False); (void) XSetWMProtocols(XtDisplay(top), XtWindow(top), &wm_delete_window,1); (void) XSetWMProtocols(XtDisplay(top), XtWindow(fileDialogShell), &wm_delete_window,1); (void) XSetWMProtocols(XtDisplay(top), XtWindow(failDialogShell), &wm_delete_window,1); XtAppMainLoop(xtcontext); exit(0); }
// ------------------------------------------------------------------- // dialog for purchasing buildings in town // create buttons for purchasing buildings. // ------------------------------------------------------------------- void t_buy_building_window::create_buttons( t_window* background ) { t_button_info button_info[k_max_buttons]; t_town_type town_type = m_town->get_type(); t_help_block const& help = get_help_block( "town_hall" ); int i; for (i = 0; i < k_max_buttons; i++) { button_info[i].id = -1; button_info[i].state = k_button_hidden; } set_button_state( button_info, m_town, k_common_buttons, ELEMENTS_OF( k_common_buttons )); set_button_state( button_info, m_town, k_button_maps[town_type].map, k_button_maps[town_type].count ); t_bitmap_layer const* layer; t_button* button; t_bitmap_layer const* frame = m_interface->find( "frame" ); t_screen_point frame_origin = frame->get_rect().top_left(); t_bitmap_layer const* thumbnail = m_interface->find( "thumbnail" ); t_screen_point thumbnail_origin = thumbnail->get_rect().top_left() - frame_origin; t_bitmap_layer const* x_mark = m_interface->find( "cannot build" ); t_bitmap_layer const* bars[6]; t_window* frame_window; t_window* window; t_town_building building; m_thumbnails = g_building_thumbnails[town_type]->get(); bars[k_button_disabled - 1] = m_interface->find( "gray bar" ); bars[k_button_built - 1] = m_interface->find( "gold bar" ); bars[k_button_cannot_build - 1] = m_interface->find( "red bar" ); bars[k_button_cannot_afford - 1] = bars[k_button_cannot_build - 1]; bars[k_button_not_owner - 1] = bars[k_button_cannot_build - 1]; bars[k_button_ok - 1] = m_interface->find( "green bar" ); // find row rectangles t_bitmap_layer const* rows[5]; int row_counts[5]; int row_spacing[5]; int row_start[5]; for (i = 0; i < 5; i++) { row_counts[i] = 0; rows[i] = m_interface->find( format_string( "row %i", i + 1 ) ); } // count # of buttons in each row for (i = 0; i < 20; i++) if (button_info[i].state != k_button_hidden) row_counts[i / 4]++; // compute row spacing int width_diff; for (i = 0; i < 5; i++) { // Diff. between row frame and sum of individual building frames. width_diff = (rows[i]->get_width() - k_building_columns * frame->get_width()); row_spacing[i] = width_diff / (k_building_columns - 1) + frame->get_width(); row_start[i] = (rows[i]->get_width() - frame->get_width() - row_spacing[i] * (row_counts[i] - 1)) / 2; } // create the buttons t_screen_point point; int row; t_window* bar; t_text_window* text_window; t_screen_rect rect; t_screen_rect text_rect = m_interface->find("building_text")->get_rect(); //t_screen_point thumbnail_offset; for (i = 0; i < k_max_buttons; i++) { if (button_info[i].state == k_button_hidden) continue; building = t_town_building( button_info[i].id ); t_building_traits const& traits = get_traits( town_type, building ); row = i / k_building_columns; point = rows[row]->get_rect().top_left(); point.x += row_start[row] + (i % k_building_columns ) * row_spacing[row]; button = new t_button( point, background ); rect = frame->get_rect() - frame->get_rect().top_left(); frame_window = new t_window ( rect, k_completely_transparent, button ); window = new t_bitmap_layer_window( frame, -frame->get_rect().top_left(), frame_window ); // add thumbnail layer = m_thumbnails->find( traits.keyword ); window = new t_bitmap_layer_window( layer, thumbnail_origin, frame_window ); // if cannot build, add X mark switch (button_info[i].state) { case k_button_disabled: case k_button_cannot_build: case k_button_cannot_afford: window = new t_bitmap_layer_window( x_mark, -frame_origin, frame_window ); break; } // add appropriate bar t_bitmap_layer const* bar_layer = bars[button_info[i].state - 1]; bar = new t_bitmap_layer_window( bar_layer, -frame_origin, frame_window ); // add name to bar text_window = new t_text_window( get_font( text_rect.height() / 2 ), text_rect - bar_layer->get_rect().top_left(), bar, traits.name, t_pixel_24(0, 0, 0) ); text_window->set_center_horizontal(); text_window->set_center_vertical(); //text_window->set_drop_shadow( true ); switch (button_info[i].state) { case k_button_built: set_help( button, help, "gold_bar" ); break; case k_button_disabled: set_help( button, help, "gray_bar" ); break; case k_button_cannot_build: set_help( button, help, "red_bar_x" ); break; case k_button_cannot_afford: set_help( button, help, "red_bar_$" ); break; case k_button_not_owner: set_help( button, help, "red_bar_owner" ); break; default : set_help( button, help, "green_bar" ); break; } // set image and handler frame_window->set_size_from_children(); button->set_released_image( frame_window ); if (button_info[i].state == k_button_disabled) { button->set_click_handler( add_2nd_argument( bound_handler( *this, &t_buy_building_window::disabled_building_click ), button_info[i].id )); } else { button->set_click_handler( add_2nd_argument( bound_handler( *this, &t_buy_building_window::building_click ), button_info[i].id )); } button->set_right_click_handler( add_2nd_argument( bound_handler( *this, &t_buy_building_window::describe_building ), button_info[i].id )); } }
void playsingle_controller::end_turn_enable(bool enable) { gui_->enable_menu("endturn", enable); set_button_state(*gui_); }
int main(int argc, char *argv[]) { int seed = time(NULL); srand(seed); int ret = 0; // only the application runs in a thread, all others don't allow SDL in thread std::thread t1( logic_thread ); /* Init SDL */ if( SDL_Init( SDL_INIT_TIMER | SDL_INIT_VIDEO ) < 0 ) { std::cerr << "Couldn't initialize SDL: " << SDL_GetError() << std::endl; exit( 1 ); } atexit( SDL_Quit ); /* Initialize the display */ SDL_Window *sdlWindow = SDL_CreateWindow( "HEXXX simulator", // SDL2 SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 400, 400, SDL_WINDOW_OPENGL ); SDL_Renderer *sdlRenderer = SDL_CreateRenderer(sdlWindow, -1, 0); int button_0_left_state = 1; int button_0_right_state = 1; int button_1_left_state = 1; int button_1_right_state = 1; int button_2_left_state = 1; int button_2_right_state = 1; while( 1 ) { // render HEXXX on screen SDL_SetRenderDrawColor(sdlRenderer, 64, 64, 64, 255); SDL_RenderClear(sdlRenderer); for( int i = 0; i < HEXAGON_LED_COUNT; i++ ) { // we'll simulate gamma error of ws2811 LEDs by applying "gamma error" functions which are inverted of gamma correction int red = applyGammaError( getRed( simulated_ledstring[ i ] ) ); int green = applyGammaError( getGreen( simulated_ledstring[ i ] ) ); int blue = applyGammaError( getBlue( simulated_ledstring[ i ] ) ); filledCircleRGBA( sdlRenderer, 200 + 180 * led2unitx(i), 200 - 180 * led2unity(i), 5, // radius red, green, blue, 255 ); } SDL_RenderPresent(sdlRenderer); // check for button presses SDL_Event event; while( SDL_PollEvent( &event ) ) { switch( event.type ) { case SDL_QUIT: exit(0); break; } } const Uint8 *keystate = SDL_GetKeyboardState(NULL); set_button_state( 0, !keystate[ SDL_SCANCODE_V ] ); set_button_state( 1, !keystate[ SDL_SCANCODE_B ] ); set_button_state( 2, !keystate[ SDL_SCANCODE_Q ] ); set_button_state( 3, !keystate[ SDL_SCANCODE_W ] ); set_button_state( 4, !keystate[ SDL_SCANCODE_O ] ); set_button_state( 5, !keystate[ SDL_SCANCODE_P ] ); if( keystate[ SDL_SCANCODE_ESCAPE ] ) exit( 0 ); usleep(15000); // slow down to about 50FPS on a raspberry pi 2 } return ret; }
/*********************************************************************** * 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; }
/*********************************************************************** * 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; }
static void highlight_dialog_buttons_win (HWND hwnd) { switch (globals.program_state) { case PROGRAM_STATE_STOPPED: set_button_state (hwnd, IDC_BUTTON_STOP, TRUE); set_button_state (hwnd, IDC_BUTTON_GRAB, FALSE); set_button_state (hwnd, IDC_BUTTON_REC, FALSE); set_button_state (hwnd, IDC_BUTTON_REPLAY, FALSE); EnableWindow (GetDlgItem(hwnd,IDC_BUTTON_REWBEG), TRUE); EnableWindow (GetDlgItem(hwnd,IDC_BUTTON_PAUSE), TRUE); EnableWindow (GetDlgItem(hwnd,IDC_BUTTON_REPLAY), TRUE); EnableWindow (GetDlgItem(hwnd,IDC_BUTTON_FF), TRUE); EnableWindow (GetDlgItem(hwnd,IDC_SLIDER_FRAME), TRUE); break; case PROGRAM_STATE_GRABBING: set_button_state (hwnd, IDC_BUTTON_STOP, FALSE); set_button_state (hwnd, IDC_BUTTON_GRAB, TRUE); set_button_state (hwnd, IDC_BUTTON_REC, FALSE); set_button_state (hwnd, IDC_BUTTON_REPLAY, FALSE); EnableWindow (GetDlgItem(hwnd,IDC_BUTTON_REWBEG), FALSE); EnableWindow (GetDlgItem(hwnd,IDC_BUTTON_PAUSE), FALSE); EnableWindow (GetDlgItem(hwnd,IDC_BUTTON_REPLAY), FALSE); EnableWindow (GetDlgItem(hwnd,IDC_BUTTON_FF), FALSE); EnableWindow (GetDlgItem(hwnd,IDC_SLIDER_FRAME), FALSE); break; case PROGRAM_STATE_RECORDING: set_button_state (hwnd, IDC_BUTTON_STOP, FALSE); set_button_state (hwnd, IDC_BUTTON_GRAB, TRUE); set_button_state (hwnd, IDC_BUTTON_REC, TRUE); set_button_state (hwnd, IDC_BUTTON_REPLAY, FALSE); EnableWindow (GetDlgItem(hwnd,IDC_BUTTON_REWBEG), FALSE); EnableWindow (GetDlgItem(hwnd,IDC_BUTTON_PAUSE), FALSE); EnableWindow (GetDlgItem(hwnd,IDC_BUTTON_REPLAY), FALSE); EnableWindow (GetDlgItem(hwnd,IDC_BUTTON_FF), FALSE); EnableWindow (GetDlgItem(hwnd,IDC_SLIDER_FRAME), FALSE); break; case PROGRAM_STATE_REPLAYING: set_button_state (hwnd, IDC_BUTTON_STOP, FALSE); set_button_state (hwnd, IDC_BUTTON_GRAB, FALSE); set_button_state (hwnd, IDC_BUTTON_REC, FALSE); set_button_state (hwnd, IDC_BUTTON_REPLAY, TRUE); EnableWindow (GetDlgItem(hwnd,IDC_BUTTON_REWBEG), TRUE); EnableWindow (GetDlgItem(hwnd,IDC_BUTTON_PAUSE), TRUE); EnableWindow (GetDlgItem(hwnd,IDC_BUTTON_REPLAY), TRUE); EnableWindow (GetDlgItem(hwnd,IDC_BUTTON_FF), TRUE); EnableWindow (GetDlgItem(hwnd,IDC_SLIDER_FRAME), TRUE); break; } highlight_source_menu (hwnd); if (globals.ig.write_dark_flag) { CheckMenuItem (GetMenu(hwnd), IDM_OPTIONS_WRITE_DARK, MF_BYCOMMAND | MF_CHECKED); } else { CheckMenuItem (GetMenu(hwnd), IDM_OPTIONS_WRITE_DARK, MF_BYCOMMAND | MF_UNCHECKED); } if (globals.auto_window_level) { set_button_state (hwnd, IDC_BUTTON_AWL, TRUE); EnableWindow (GetDlgItem(hwnd,IDC_SLIDER_TOP), FALSE); EnableWindow (GetDlgItem(hwnd,IDC_SLIDER_BOT), FALSE); } else { set_button_state (hwnd, IDC_BUTTON_AWL, FALSE); gdi_update_lut_slider (hwnd_to_idx(hwnd), 0, MAXGREY-1); update_lut (hwnd, 0, MAXGREY-1); EnableWindow (GetDlgItem(hwnd,IDC_SLIDER_TOP), TRUE); EnableWindow (GetDlgItem(hwnd,IDC_SLIDER_BOT), TRUE); } if (globals.hold_bright_frame) { CheckMenuItem (GetMenu(hwnd), IDM_OPTIONS_HOLD_BRIGHT, MF_BYCOMMAND | MF_CHECKED); } else { CheckMenuItem (GetMenu(hwnd), IDM_OPTIONS_HOLD_BRIGHT, MF_BYCOMMAND | MF_UNCHECKED); } if (globals.drop_dark_frames) { CheckMenuItem (GetMenu(hwnd), IDM_OPTIONS_DROP_DARK, MF_BYCOMMAND | MF_CHECKED); } else { CheckMenuItem (GetMenu(hwnd), IDM_OPTIONS_DROP_DARK, MF_BYCOMMAND | MF_UNCHECKED); } if (globals.tracking_flag) { set_button_state (hwnd, IDC_BUTTON_TRACK, TRUE); } else { set_button_state (hwnd, IDC_BUTTON_TRACK, FALSE); } if (globals.gating_flag) { set_button_state (hwnd, IDC_BUTTON_GATE, TRUE); } else { set_button_state (hwnd, IDC_BUTTON_GATE, FALSE); } UpdateWindow (hwnd); }