static gboolean gtk_window_button_release_callback(GtkWidget* widget, GdkEventButton* gdk_event, wxMiniFrame* win) { if (gdk_event->window != gtk_widget_get_window(widget)) return false; if (g_blockEventsOnDrag) return TRUE; if (g_blockEventsOnScroll) return TRUE; if (!win->m_isDragging) return TRUE; win->m_isDragging = false; int x = (int)gdk_event->x; int y = (int)gdk_event->y; #ifdef __WXGTK4__ gdk_seat_ungrab(gdk_event_get_seat((GdkEvent*)gdk_event)); #elif defined(__WXGTK3__) wxGCC_WARNING_SUPPRESS(deprecated-declarations) gdk_device_ungrab(gdk_event->device, gdk_event->time); wxGCC_WARNING_RESTORE() #else gdk_pointer_ungrab(gdk_event->time); #endif int org_x = 0; int org_y = 0; gdk_window_get_origin(gtk_widget_get_window(widget), &org_x, &org_y); x += org_x - win->m_diffX; y += org_y - win->m_diffY; gtk_window_move( GTK_WINDOW(win->m_widget), x, y ); return TRUE; }
void wxColourButton::UpdateColour() { #ifdef __WXGTK4__ gtk_color_chooser_set_rgba(GTK_COLOR_CHOOSER(m_widget), m_colour); #elif defined(__WXGTK3__) wxGCC_WARNING_SUPPRESS(deprecated-declarations) gtk_color_button_set_rgba(GTK_COLOR_BUTTON(m_widget), m_colour); wxGCC_WARNING_RESTORE() #else gtk_color_button_set_color(GTK_COLOR_BUTTON(m_widget), m_colour.GetColor()); #endif }
bool wxTopLevelWindowGTK::SetTransparent(wxByte alpha) { if (m_widget == NULL) return false; #if GTK_CHECK_VERSION(2,12,0) #ifndef __WXGTK3__ if (gtk_check_version(2,12,0) == NULL) #endif { #if GTK_CHECK_VERSION(3,8,0) if(gtk_check_version(3,8,0) == NULL) { gtk_widget_set_opacity(m_widget, alpha / 255.0); } else #endif { // Can't avoid using this deprecated function with older GTK+. wxGCC_WARNING_SUPPRESS(deprecated-declarations); gtk_window_set_opacity(GTK_WINDOW(m_widget), alpha / 255.0); wxGCC_WARNING_RESTORE(); } return true; } #endif // GTK_CHECK_VERSION(2,12,0) #ifndef __WXGTK3__ #ifdef GDK_WINDOWING_X11 GdkWindow* window = gtk_widget_get_window(m_widget); if (window == NULL) return false; Display* dpy = GDK_WINDOW_XDISPLAY(window); Window win = GDK_WINDOW_XID(window); if (alpha == 0xff) XDeleteProperty(dpy, win, XInternAtom(dpy, "_NET_WM_WINDOW_OPACITY", False)); else { long opacity = alpha * 0x1010101L; XChangeProperty(dpy, win, XInternAtom(dpy, "_NET_WM_WINDOW_OPACITY", False), XA_CARDINAL, 32, PropModeReplace, (unsigned char *) &opacity, 1L); } XSync(dpy, False); return true; #else // !GDK_WINDOWING_X11 return false; #endif // GDK_WINDOWING_X11 / !GDK_WINDOWING_X11 #endif // !__WXGTK3__ }
wxString wxGTKMimeTypesManagerImpl::GetIconFromMimeType(const wxString& mime) { wxString icon; #if GTK_CHECK_VERSION(2,14,0) if (!wx_is_at_least_gtk2(14)) return icon; wxGtkString type(g_content_type_from_mime_type(mime.utf8_str())); wxGtkObject<GIcon> gicon(g_content_type_get_icon(type)); if ( !gicon ) return icon; GtkIconTheme *theme(gtk_icon_theme_get_default()); if ( !theme ) return icon; // Notice that we can't use wxGtkObject here because a special function // needs to be used for freeing this object prior to GTK+ 3.8. GtkIconInfo* const giconinfo = gtk_icon_theme_lookup_by_gicon ( theme, gicon, 256, GTK_ICON_LOOKUP_NO_SVG ); if ( giconinfo ) { icon = wxString::FromUTF8(gtk_icon_info_get_filename(giconinfo)); wxGCC_WARNING_SUPPRESS(deprecated-declarations) gtk_icon_info_free(giconinfo); wxGCC_WARNING_RESTORE() } #endif // GTK_CHECK_VERSION(2,14,0) return icon; }
static void gtk_clrbutton_setcolor_callback(GtkColorButton *widget, wxColourButton *p) { // update the m_colour member of the wxColourButton wxASSERT(p); #ifdef __WXGTK4__ GdkRGBA gdkColor; gtk_color_chooser_get_rgba(GTK_COLOR_CHOOSER(widget), &gdkColor); #elif defined(__WXGTK3__) wxGCC_WARNING_SUPPRESS(deprecated-declarations) GdkRGBA gdkColor; gtk_color_button_get_rgba(widget, &gdkColor); wxGCC_WARNING_RESTORE() #else GdkColor gdkColor; gtk_color_button_get_color(widget, &gdkColor); #endif p->GTKSetColour(gdkColor); // fire the colour-changed event wxColourPickerEvent event(p, p->GetId(), p->GetColour()); p->HandleWindowEvent(event); }
void GraphicsContextDrawingTestCase::DoFontDrawings (wxGraphicsContext *gc) { #ifdef __WXGTK__ wxGCC_WARNING_SUPPRESS(deprecated-declarations) g_type_init(); wxGCC_WARNING_RESTORE() #endif // This test is expected to treat about fonts/texts. Fonts are a bit special // because we cannot expect the same rendering by several engines, and the // dimensions of the same text in same font will vary. wxGraphicsBrush gbBackground = gc->CreateBrush( wxBrush ( wxColour ( 240, 240, 240 ) ) ); gc->SetBrush( gbBackground ); gc->DrawRectangle(0, 0, 800, 600); wxGraphicsBrush gbTextBackground = gc->CreateBrush( wxBrush ( wxColour ( 192, 192, 192 ) ) ); // set underlined font for testing gc->SetFont( wxFont(wxFontInfo(12).Family(wxFONTFAMILY_MODERN).Underlined()), *wxBLACK ); gc->DrawText( wxT("This is text"), 110, 10, gbTextBackground ); gc->DrawText( wxT("That is text"), 20, 10, wxDegToRad(-45), gbTextBackground ); // use wxSWISS_FONT and not wxNORMAL_FONT as the latter can't be rotated // under Win9x (it is not TrueType) gc->SetFont( wxFont(wxFontInfo(12).Family(wxFONTFAMILY_SWISS)), *wxBLACK ); wxString text; for ( int n = -180; n < 180; n += 30 ) { text.Printf(wxT(" %d rotated text"), n); gc->DrawText(text , 400, 400, wxDegToRad(n) ); } wxFont swissDcFont( wxFontInfo(18).Family(wxFONTFAMILY_SWISS) ); wxGraphicsFont swissFont = gc->CreateFont( swissDcFont, *wxBLACK ); gc->SetFont( swissFont ); gc->DrawText( wxT("This is Swiss 18pt text."), 110, 40 ); wxDouble length; wxDouble height; wxDouble descent; gc->GetTextExtent( wxT("This is Swiss 18pt text."), &length, &height, &descent ); text.Printf( wxT("Dimensions are length %f, height %f, descent %f"), length, height, descent ); gc->DrawText( text, 110, 80 ); // (did not find equivalent to CharHeight()) gc->SetBrush( *wxWHITE_BRUSH ); gc->DrawRectangle( 100, 40, 4, height ); // test the logical function effect wxCoord y = 150; // text drawing should ignore logical function gc->DrawText( wxT("There should be a text below"), 110, 150 ); gc->DrawRectangle( 110, y, 100, height ); y += height; gc->DrawText( wxT("Visible text"), 110, y ); gc->DrawRectangle( 110, y, 100, height ); gc->DrawText( wxT("Visible text"), 110, y ); gc->DrawRectangle( 110, y, 100, height ); y += height; gc->DrawRectangle( 110, y, 100, height ); gc->DrawText( wxT("Another visible text"), 110, y ); y += height; gc->DrawText("And\nmore\ntext on\nmultiple\nlines", 110, y); y += 5*height; gc->SetFont( swissDcFont, *wxBLUE ); gc->DrawText( "Rotated text\ncan have\nmultiple lines\nas well", 110, y, wxDegToRad(15) ); }
static gboolean gtk_window_button_press_callback(GtkWidget* widget, GdkEventButton* gdk_event, wxMiniFrame* win) { if (gdk_event->window != gtk_widget_get_window(widget)) return false; if (g_blockEventsOnDrag) return TRUE; if (g_blockEventsOnScroll) return TRUE; if (win->m_isDragging) return TRUE; int style = win->GetWindowStyle(); int y = (int)gdk_event->y; int x = (int)gdk_event->x; if ((style & wxRESIZE_BORDER) && (x > win->m_width-14) && (y > win->m_height-14)) { GtkWidget *ancestor = gtk_widget_get_toplevel( widget ); GdkWindow *source = gtk_widget_get_window(widget); int org_x = 0; int org_y = 0; gdk_window_get_origin( source, &org_x, &org_y ); gtk_window_begin_resize_drag (GTK_WINDOW (ancestor), GDK_WINDOW_EDGE_SOUTH_EAST, 1, org_x + x, org_y + y, 0); return TRUE; } if (win->m_miniTitle && (style & wxCLOSE_BOX)) { if ((y > 3) && (y < 19) && (x > win->m_width-19) && (x < win->m_width-3)) { win->Close(); return TRUE; } } if (y >= win->m_miniEdge + win->m_miniTitle) return true; gdk_window_raise(gtk_widget_get_window(win->m_widget)); #ifdef __WXGTK4__ gdk_seat_grab( gdk_event_get_seat((GdkEvent*)gdk_event), gdk_event_get_window((GdkEvent*)gdk_event), GDK_SEAT_CAPABILITY_POINTER, false, NULL, (GdkEvent*)gdk_event, NULL, 0); #else const GdkEventMask mask = GdkEventMask( GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_MOTION_MASK | GDK_BUTTON1_MOTION_MASK); #ifdef __WXGTK3__ wxGCC_WARNING_SUPPRESS(deprecated-declarations) gdk_device_grab( gdk_event->device, gdk_event->window, GDK_OWNERSHIP_NONE, false, mask, NULL, gdk_event->time); wxGCC_WARNING_RESTORE() #else gdk_pointer_grab(gdk_event->window, false, mask, NULL, NULL, gdk_event->time); #endif #endif // !__WXGTK4__ win->m_diffX = x; win->m_diffY = y; win->m_oldX = 0; win->m_oldY = 0; win->m_isDragging = true; return TRUE; }
bool wxPopupTransientWindow::Show( bool show ) { #ifdef __WXGTK__ if (!show) { #ifdef __WXGTK3__ GdkDisplay* display = gtk_widget_get_display(m_widget); #ifdef __WXGTK4__ gdk_seat_ungrab(gdk_display_get_default_seat(display)); #else wxGCC_WARNING_SUPPRESS(deprecated-declarations) GdkDeviceManager* manager = gdk_display_get_device_manager(display); GdkDevice* device = gdk_device_manager_get_client_pointer(manager); gdk_device_ungrab(device, unsigned(GDK_CURRENT_TIME)); wxGCC_WARNING_RESTORE() #endif #else gdk_pointer_ungrab( (guint32)GDK_CURRENT_TIME ); #endif gtk_grab_remove( m_widget ); } #endif #ifdef __WXX11__ if (!show) { XUngrabPointer( wxGlobalDisplay(), CurrentTime ); } #endif #if defined( __WXMSW__ ) || defined( __WXMAC__) if (!show && m_child && m_child->HasCapture()) { m_child->ReleaseMouse(); } #endif bool ret = wxPopupWindow::Show( show ); #ifdef __WXGTK__ if (show) { gtk_grab_add( m_widget ); GdkWindow* window = gtk_widget_get_window(m_widget); #ifdef __WXGTK4__ GdkDisplay* display = gdk_window_get_display(window); GdkSeat* seat = gdk_display_get_default_seat(display); gdk_seat_grab(seat, window, GDK_SEAT_CAPABILITY_POINTER, false, NULL, NULL, NULL, 0); #else const GdkEventMask mask = GdkEventMask( GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_POINTER_MOTION_MASK); #ifdef __WXGTK3__ GdkDisplay* display = gdk_window_get_display(window); wxGCC_WARNING_SUPPRESS(deprecated-declarations) GdkDeviceManager* manager = gdk_display_get_device_manager(display); GdkDevice* device = gdk_device_manager_get_client_pointer(manager); gdk_device_grab(device, window, GDK_OWNERSHIP_NONE, true, mask, NULL, unsigned(GDK_CURRENT_TIME)); wxGCC_WARNING_RESTORE() #else gdk_pointer_grab( window, true, mask, NULL, NULL, (guint32)GDK_CURRENT_TIME ); #endif #endif // !__WXGTK4__ } #endif #ifdef __WXX11__ if (show) { Window xwindow = (Window) m_clientWindow; /* int res =*/ XGrabPointer(wxGlobalDisplay(), xwindow, True, ButtonPressMask | ButtonReleaseMask | ButtonMotionMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask, GrabModeAsync, GrabModeAsync, None, None, CurrentTime ); } #endif #if defined( __WXMSW__ ) || defined( __WXMAC__) if (show && m_child) { // Assume that the mouse is outside the popup to begin with m_child->CaptureMouse(); } #endif return ret; }
bool wxButton::Create(wxWindow *parent, wxWindowID id, const wxString &label, const wxPoint& pos, const wxSize& size, long style, const wxValidator& validator, const wxString& name) { if (!PreCreation( parent, pos, size ) || !CreateBase( parent, id, pos, size, style, validator, name )) { wxFAIL_MSG( wxT("wxButton creation failed") ); return false; } // create either a standard button with text label (which may still contain // an image under GTK+ 2.6+) or a bitmap-only button if we don't have any // label const bool useLabel = !(style & wxBU_NOTEXT) && (!label.empty() || wxIsStockID(id)); if ( useLabel ) { m_widget = gtk_button_new_with_mnemonic(""); } else // no label, suppose we will have a bitmap { m_widget = gtk_button_new(); GtkWidget *image = gtk_image_new(); gtk_widget_show(image); gtk_container_add(GTK_CONTAINER(m_widget), image); } g_object_ref(m_widget); float x_alignment = 0.5; if (HasFlag(wxBU_LEFT)) x_alignment = 0.0; else if (HasFlag(wxBU_RIGHT)) x_alignment = 1.0; float y_alignment = 0.5; if (HasFlag(wxBU_TOP)) y_alignment = 0.0; else if (HasFlag(wxBU_BOTTOM)) y_alignment = 1.0; #ifdef __WXGTK4__ if (useLabel) { g_object_set(gtk_bin_get_child(GTK_BIN(m_widget)), "xalign", x_alignment, "yalign", y_alignment, NULL); } #else wxGCC_WARNING_SUPPRESS(deprecated-declarations) gtk_button_set_alignment(GTK_BUTTON(m_widget), x_alignment, y_alignment); wxGCC_WARNING_RESTORE() #endif if ( useLabel ) SetLabel(label); if (style & wxNO_BORDER) gtk_button_set_relief( GTK_BUTTON(m_widget), GTK_RELIEF_NONE ); g_signal_connect_after (m_widget, "clicked", G_CALLBACK (wxgtk_button_clicked_callback), this); g_signal_connect_after (m_widget, "style_set", G_CALLBACK (wxgtk_button_style_set_callback), this); m_parent->DoAddChild( this ); PostCreation(size); return true; }