예제 #1
0
wxPoint wxControl::GTKGetEntryMargins(GtkEntry* entry) const
{
    wxPoint marg(0, 0);

#ifndef __WXGTK3__
#if GTK_CHECK_VERSION(2,10,0)
    // The margins we have previously set
    const GtkBorder* border = NULL;
    if (gtk_check_version(2,10,0) == NULL)
        border = gtk_entry_get_inner_border(entry);

    if ( border )
    {
        marg.x = border->left + border->right;
        marg.y = border->top + border->bottom;
    }
#endif // GTK+ 2.10+
#else // GTK+ 3
    // Gtk3 does not use inner border, but StyleContext and CSS
    // TODO: implement it, starting with wxTextEntry::DoSetMargins()
#endif // GTK+ 2/3

    int x, y;
    gtk_entry_get_layout_offsets(entry, &x, &y);
    // inner borders are included. Substract them so we can get other margins
    x -= marg.x;
    y -= marg.y;
    marg.x += 2 * x + 2;
    marg.y += 2 * y + 2;

    return marg;
}
예제 #2
0
bool wxTextEntry::DoSetMargins(const wxPoint& margins)
{
#if GTK_CHECK_VERSION(2,10,0)
    GtkEntry* entry = GetEntry();

    if ( !entry )
        return false;

    const GtkBorder* oldBorder = gtk_entry_get_inner_border(entry);
    GtkBorder* newBorder;

    if ( oldBorder )
    {
        newBorder = gtk_border_copy(oldBorder);
    }
    else
    {
    #if GTK_CHECK_VERSION(2,14,0)
        newBorder = gtk_border_new();
    #else
        newBorder = g_slice_new0(GtkBorder);
    #endif
        // Use some reasonable defaults for initial margins
        newBorder->left = 2;
        newBorder->right = 2;

        // These numbers seem to let the text remain vertically centered
        // in common use scenarios when margins.y == -1.
        newBorder->top = 3;
        newBorder->bottom = 3;
    }

    if ( margins.x != -1 )
        newBorder->left = (gint) margins.x;

    if ( margins.y != -1 )
        newBorder->top = (gint) margins.y;

    gtk_entry_set_inner_border(entry, newBorder);

#if GTK_CHECK_VERSION(2,14,0)
    gtk_border_free(newBorder);
#else
    g_slice_free(GtkBorder, newBorder);
#endif

    return true;
#else
    wxUnusedVar(margins);
    return false;
#endif
}
예제 #3
0
wxPoint wxTextEntry::DoGetMargins() const
{
#if GTK_CHECK_VERSION(2,10,0)
    GtkEntry* entry = GetEntry();

    if ( !entry )
        return wxPoint(-1, -1);

    const GtkBorder* border = gtk_entry_get_inner_border(entry);

    if ( !border )
        return wxPoint(-1, -1);

    return wxPoint((wxCoord) border->left, (wxCoord) border->top);
#else
    return wxPoint(-1, -1);
#endif
}
예제 #4
0
bool wxTextEntry::DoSetMargins(const wxPoint& margins)
{
#if GTK_CHECK_VERSION(2,10,0)
    GtkEntry* entry = GetEntry();

    if ( !entry )
        return false;
#ifndef __WXGTK3__
    if (gtk_check_version(2,10,0))
        return false;
#endif

    const GtkBorder* oldBorder = gtk_entry_get_inner_border(entry);
    GtkBorder newBorder;

    if ( oldBorder )
        newBorder = *oldBorder;
    else
    {
        // Use some reasonable defaults for initial margins
        newBorder.left = 2;
        newBorder.right = 2;

        // These numbers seem to let the text remain vertically centered
        // in common use scenarios when margins.y == -1.
        newBorder.top = 3;
        newBorder.bottom = 3;
    }

    if ( margins.x != -1 )
        newBorder.left = margins.x;

    if ( margins.y != -1 )
        newBorder.top = margins.y;

    gtk_entry_set_inner_border(entry, &newBorder);

    return true;
#else
    wxUnusedVar(margins);
    return false;
#endif
}
예제 #5
0
wxPoint wxTextEntry::DoGetMargins() const
{
    wxPoint point(-1, -1);
#if GTK_CHECK_VERSION(2,10,0)
    GtkEntry* entry = GetEntry();
    if (entry)
    {
#ifndef __WXGTK3__
        if (gtk_check_version(2,10,0) == NULL)
#endif
        {
            const GtkBorder* border = gtk_entry_get_inner_border(entry);
            if (border)
            {
                point.x = border->left;
                point.y = border->top;
            }
        }
    }
#endif
    return point;
}