Beispiel #1
0
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;
}
Beispiel #2
0
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
}
Beispiel #3
0
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__
}
Beispiel #4
0
void wxStatusBarGeneric::OnPaint(wxPaintEvent& WXUNUSED(event) )
{
    wxPaintDC dc(this);

#ifdef __WXGTK20__
    // Draw grip first
    if ( ShowsSizeGrip() )
    {
        const wxRect& rc = GetSizeGripRect();
#ifdef __WXGTK3__
        GtkWidget* toplevel = gtk_widget_get_toplevel(m_widget);
        GdkRectangle rect;
        wxGCC_WARNING_SUPPRESS(deprecated-declarations)
        if (toplevel && (!gtk_window_get_resize_grip_area(GTK_WINDOW(toplevel), &rect) ||
            rect.width == 0 || rect.height == 0))
        wxGCC_WARNING_RESTORE()
        {
            GtkStyleContext* sc = gtk_widget_get_style_context(toplevel);
            gtk_style_context_save(sc);
            gtk_style_context_add_class(sc, GTK_STYLE_CLASS_GRIP);
            GtkJunctionSides sides = GTK_JUNCTION_CORNER_BOTTOMRIGHT;
            if (GetLayoutDirection() == wxLayout_RightToLeft)
                sides = GTK_JUNCTION_CORNER_BOTTOMLEFT;
            gtk_style_context_set_junction_sides(sc, sides);
            gtk_render_handle(sc,
                static_cast<cairo_t*>(dc.GetImpl()->GetCairoContext()),
                rc.x, rc.y, rc.width, rc.height);
            gtk_style_context_restore(sc);
        }
#else
        GdkWindowEdge edge =
            GetLayoutDirection() == wxLayout_RightToLeft ? GDK_WINDOW_EDGE_SOUTH_WEST :
                                                           GDK_WINDOW_EDGE_SOUTH_EAST;
        gtk_paint_resize_grip(gtk_widget_get_style(m_widget),
                            GTKGetDrawingWindow(),
                            gtk_widget_get_state(m_widget),
                            NULL,
                            m_widget,
                            "statusbar",
                            edge,
                            rc.x, rc.y, rc.width, rc.height );
#endif
    }
Beispiel #5
0
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);
}
Beispiel #6
0
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) );
}
Beispiel #7
0
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;
}
Beispiel #8
0
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;
}