BOOL window::on_event (HELEMENT he, HELEMENT target, BEHAVIOR_EVENTS type, UINT_PTR reason ) { if( type != BUTTON_CLICK) return FALSE; // handling only button clicks here. if( target == button_min) { ::ShowWindow(hwnd,SW_MINIMIZE); return TRUE; } if( target == button_max) { if( is_maximized()) ::ShowWindow(hwnd,SW_RESTORE); else ::ShowWindow(hwnd,SW_MAXIMIZE); return TRUE; } if( target == button_close) { ::PostMessage(hwnd, WM_CLOSE, 0,0); return TRUE; } // click on some other button dom::element button = target; //::MessageBoxW(button.get_element_hwnd(true) ,button.get_attribute("id"), L"Click on the button with id:", MB_OK); ::MessageBox(button.get_element_hwnd(true) ,"test", "Click on the button with id:", MB_OK); return TRUE; }
void X11Window::restore() { if (!is_window_mapped) log_event("debug", "clan::X11Window::restore(): Window is not yet mapped."); if (is_minimized()) { if (restore_to_maximized) { log_event("debug", "clan::X11Window::restore(): Restoring to maximized window."); maximize(); } else { log_event("debug", "clan::X11Window::restore(): Restoring minimized window."); map_window(); maximized = false; } } else if (is_maximized()) { log_event("debug", "clan::X11Window::restore(): Restoring window size."); atoms.modify_net_wm_state(handle.window, _NET_WM_STATE_REMOVE, "_NET_WM_STATE_MAXIMIZED_HORZ", "_NET_WM_STATE_MAXIMIZED_VERT"); maximized = false; } }
void X11Window::minimize() { if (!is_window_mapped) log_event("debug", "clan::X11Window::minimize(): Window is not yet mapped."); if (!is_minimized()) { log_event("debug", "clan::X11Window::minimize(): Minimizing."); restore_to_maximized = is_maximized(); XIconifyWindow(handle.display, handle.window, handle.screen); minimized = true; } else { log_event("debug", "clan::X11Window::minimize(): Window already minimized."); } }
// Danger: This function could delete "this" void X11Window::process_message(XEvent &event, X11Window *mouse_capture_window) { switch(event.type) { case ConfigureNotify: { // Resize or Move Rect new_client_area = (event.xany.send_event == 0) ? get_screen_position() : Rect::xywh( event.xconfigure.x + event.xconfigure.border_width, event.xconfigure.y + event.xconfigure.border_width, event.xconfigure.width, event.xconfigure.height ); process_window_resize(new_client_area); break; } case ClientMessage: { // handle window manager messages Atom WM_PROTOCOLS = atoms["WM_PROTOCOLS"]; if (WM_PROTOCOLS == None) { log_event("debug", "clan::X11Window::process_message: WM_PROTOCOLS not supported by WM."); break; } else if (event.xclient.message_type == WM_PROTOCOLS) { unsigned long protocol = event.xclient.data.l[0]; if (protocol == None) { log_event("debug", "clan::X11Window::process_message: WM_PROTOCOLS event protocol supplied is None."); break; } Atom WM_DELETE_WINDOW = atoms["WM_DELETE_WINDOW"]; Atom _NET_WM_PING = atoms["_NET_WM_PING"]; if (protocol == WM_DELETE_WINDOW && site) { (site->sig_window_close)(); } else if (protocol == _NET_WM_PING) { XSendEvent(handle.display, RootWindow(handle.display, handle.screen), False, SubstructureNotifyMask | SubstructureRedirectMask, &event); } } break; } case Expose: { // Window exposure repaint_request = true; break; } case FocusIn: if (site) (site->sig_got_focus)(); break; case FocusOut: if (site) { if (!has_focus()) // For an unknown reason, FocusOut is called when clicking on title bar of window { (site->sig_lost_focus)(); } } break; case PropertyNotify: { // Iconify, Maximized, ... if (!site) break; Atom _NET_WM_STATE = atoms["_NET_WM_STATE"]; Atom WM_STATE = atoms["WM_STATE"]; // legacy. if (_NET_WM_STATE != None && event.xproperty.atom == _NET_WM_STATE && event.xproperty.state == PropertyNewValue) { if (is_minimized()) { if (!minimized && site != nullptr) (site->sig_window_minimized)(); minimized = true; maximized = false; } else if (is_maximized()) { if (!maximized && site != nullptr) (site->sig_window_maximized)(); if (minimized && site != nullptr) { // generate resize events for minimized -> maximized transition Rectf rectf = get_geometry(); rectf.left /= pixel_ratio; rectf.top /= pixel_ratio; rectf.right /= pixel_ratio; rectf.bottom /= pixel_ratio; (site->sig_window_moved)(); if (site->func_window_resize) (site->func_window_resize)(rectf); if (callback_on_resized) callback_on_resized(); (site->sig_resize)(rectf.get_width(), rectf.get_height()); } minimized = false; maximized = true; } else { if ((minimized || maximized) && site != nullptr) (site->sig_window_restored)(); minimized = false; maximized = false; } } else if (WM_STATE != None && event.xproperty.atom == WM_STATE && event.xproperty.state == PropertyNewValue) { if (is_minimized()) { if (!minimized && site != nullptr) (site->sig_window_minimized)(); minimized = true; } else { if (minimized && site != nullptr) (site->sig_window_restored)(); minimized = false; } } break; } case KeyRelease: case KeyPress: if (get_keyboard_provider()) { get_keyboard_provider()->received_keyboard_input(keyboard, event.xkey); } break; case ButtonPress: case ButtonRelease: if (mouse_capture_window->get_mouse_provider() && event.xany.send_event==0) { if (callback_on_clicked) { // This callback is required for GL layered windows if (!callback_on_clicked(event.xbutton)) break; } if (this != mouse_capture_window) // This is so you can capture mouse events in another window, as if it was this window (Set by capture_mouse()) { Rect this_scr = client_area; Rect capture_scr = mouse_capture_window->client_area; event.xbutton.x += this_scr.left - capture_scr.left; event.xbutton.y += this_scr.top - capture_scr.top; } mouse_capture_window->get_mouse_provider()->received_mouse_input(mouse_capture_window->mouse, event.xbutton); } break; case MotionNotify: if (mouse_capture_window->get_mouse_provider() && event.xany.send_event == 0) { if (this != mouse_capture_window) // This is so you can capture mouse events in another window, as if it was this window (Set by capture_mouse()) { Rect this_scr = client_area; Rect capture_scr = mouse_capture_window->client_area; event.xmotion.x += this_scr.left - capture_scr.left; event.xmotion.y += this_scr.top - capture_scr.top; } mouse_capture_window->get_mouse_provider()->received_mouse_move(mouse_capture_window->mouse, event.xmotion); } break; case SelectionClear: // New clipboard selection owner clipboard.event_selection_clear(event.xselectionclear); break; case SelectionNotify: clipboard.event_selection_notify(); break; case SelectionRequest: // Clipboard requests clipboard.event_selection_request(event.xselectionrequest); break; default: break; } }