[GB.GTK3]
* NEW: GTK+3 support continues. git-svn-id: svn://localhost/gambas/trunk@6039 867c0c6c-44f3-4631-809d-bfa615b0a4ec
This commit is contained in:
parent
184b1a2898
commit
8e7d6473d4
@ -71,11 +71,19 @@ gCursor::gCursor(gCursor *cursor)
|
||||
x = cursor->x;
|
||||
y = cursor->y;
|
||||
if (cur)
|
||||
#ifdef GTK3
|
||||
g_object_ref(cur);
|
||||
#else
|
||||
gdk_cursor_ref(cur);
|
||||
#endif
|
||||
}
|
||||
|
||||
gCursor::~gCursor()
|
||||
{
|
||||
if (cur)
|
||||
#ifdef GTK3
|
||||
g_object_unref(cur);
|
||||
#else
|
||||
gdk_cursor_unref(cur);
|
||||
#endif
|
||||
}
|
||||
|
@ -157,7 +157,7 @@ gColor gDesktop::buttonbgColor()
|
||||
|
||||
gColor gDesktop::fgColor()
|
||||
{
|
||||
return get_color(GTK_TYPE_LABEL, 0, STATE_NORMAL, true, false);
|
||||
return get_color(GTK_TYPE_LAYOUT, 0, STATE_NORMAL, true, false);
|
||||
}
|
||||
|
||||
gColor gDesktop::bgColor()
|
||||
|
@ -511,7 +511,6 @@ static void show_frame(gControl *control, int x, int y, int w, int h)
|
||||
int i;
|
||||
GdkWindowAttr attr = { 0 };
|
||||
GdkWindow *window;
|
||||
GdkColor color;
|
||||
GdkWindow *parent;
|
||||
GtkAllocation a;
|
||||
|
||||
@ -542,7 +541,13 @@ static void show_frame(gControl *control, int x, int y, int w, int h)
|
||||
|
||||
if (!_frame_visible)
|
||||
{
|
||||
#ifdef GTK3
|
||||
GdkRGBA rgba;
|
||||
gt_from_color(0, &rgba);
|
||||
#else
|
||||
GdkColor color;
|
||||
fill_gdk_color(&color, 0);
|
||||
#endif
|
||||
|
||||
attr.wclass = GDK_INPUT_OUTPUT;
|
||||
attr.window_type = GDK_WINDOW_CHILD;
|
||||
@ -550,7 +555,11 @@ static void show_frame(gControl *control, int x, int y, int w, int h)
|
||||
for (i = 0; i < 4; i++)
|
||||
{
|
||||
window = gdk_window_new(parent, &attr, 0);
|
||||
#ifdef GTK3
|
||||
gdk_window_set_background_rgba(window, &rgba);
|
||||
#else
|
||||
gdk_window_set_background(window, &color);
|
||||
#endif
|
||||
_frame[i] = window;
|
||||
}
|
||||
}
|
||||
|
@ -27,15 +27,15 @@
|
||||
#ifdef GTK3
|
||||
static gboolean cb_draw(GtkWidget *draw, cairo_t *cr, gLabel *d)
|
||||
{
|
||||
GtkStyle *style = gtk_widget_get_style(draw);
|
||||
GdkRGBA rgba;
|
||||
int vw, vh, lw, lh;
|
||||
int fw = Max(d->getFramePadding(), d->getFrameWidth());
|
||||
|
||||
//d->drawBackground(cr);
|
||||
d->drawBorder(cr);
|
||||
|
||||
if (style)
|
||||
gdk_cairo_set_source_color(cr, &style->fg[GTK_STATE_NORMAL]);
|
||||
gt_from_color(d->realForeground(), &rgba);
|
||||
gdk_cairo_set_source_rgba(cr, &rgba);
|
||||
|
||||
switch (d->lay_x)
|
||||
{
|
||||
|
@ -24,6 +24,7 @@
|
||||
#include "widgets.h"
|
||||
#include "gmainwindow.h"
|
||||
#include "gapplication.h"
|
||||
#include "gdesktop.h"
|
||||
#include "gmenu.h"
|
||||
|
||||
typedef
|
||||
@ -101,8 +102,8 @@ static gboolean cb_check_draw(GtkWidget *wid, cairo_t *cr, gMenu *menu)
|
||||
{
|
||||
GtkAllocation a;
|
||||
gtk_widget_get_allocation(wid, &a);
|
||||
x = a.x;
|
||||
y = a.y;
|
||||
x = 0; //a.x;
|
||||
y = 0; //a.y;
|
||||
w = a.width;
|
||||
h = a.height;
|
||||
|
||||
@ -120,10 +121,11 @@ static gboolean cb_check_draw(GtkWidget *wid, cairo_t *cr, gMenu *menu)
|
||||
|
||||
gtk_widget_set_state(check_menu_item, gtk_widget_get_state(wid));
|
||||
|
||||
gtk_paint_check(gtk_widget_get_style(wid), cr,
|
||||
gtk_widget_get_state(wid), GTK_SHADOW_IN,
|
||||
check_menu_item, "check",
|
||||
x + 1, y + 1, w - 2, h - 2);
|
||||
GtkStyleContext *style = gtk_widget_get_style_context(check_menu_item);
|
||||
gtk_style_context_set_state(style, GTK_STATE_FLAG_ACTIVE);
|
||||
|
||||
fprintf(stderr, "gtk_render_check: %d %d %d %d\n", x, y, w, h);
|
||||
gtk_render_check(style, cr, x, y, w, h);
|
||||
}
|
||||
|
||||
return false;
|
||||
@ -171,7 +173,6 @@ void gMenu::update()
|
||||
{
|
||||
GtkMenuShell *shell = NULL;
|
||||
gint pos;
|
||||
GtkRequisition req;
|
||||
|
||||
if (_no_update)
|
||||
return;
|
||||
@ -207,9 +208,13 @@ void gMenu::update()
|
||||
if (_style == SEPARATOR)
|
||||
{
|
||||
menu = (GtkMenuItem *)gtk_separator_menu_item_new();
|
||||
#ifdef GTK3
|
||||
#else
|
||||
GtkRequisition req;
|
||||
gtk_widget_size_request(GTK_WIDGET(menu), &req);
|
||||
if (req.height > 5)
|
||||
gtk_widget_set_size_request(GTK_WIDGET(menu), -1, 5);
|
||||
#endif
|
||||
//g_debug("%p: create new separator %p", this, menu);
|
||||
}
|
||||
else if (_style == MENU)
|
||||
@ -217,7 +222,7 @@ void gMenu::update()
|
||||
menu = (GtkMenuItem *)gtk_image_menu_item_new();
|
||||
//g_debug("%p: create new menu %p", this, menu);
|
||||
|
||||
hbox = gtk_hbox_new(false, 4);
|
||||
hbox = gtk_hbox_new(false, gDesktop::scale() * 2);
|
||||
//set_gdk_bg_color(hbox, 0xFF0000);
|
||||
gtk_container_add(GTK_CONTAINER(menu), GTK_WIDGET(hbox));
|
||||
|
||||
@ -239,7 +244,6 @@ void gMenu::update()
|
||||
ON_DRAW(check, this, cb_check_expose, cb_check_draw);
|
||||
//g_signal_connect_after(G_OBJECT(check), "expose-event", G_CALLBACK(cb_check_expose), (gpointer)this);
|
||||
|
||||
//gtk_box_pack_start(GTK_BOX(hbox), check, false, false, 0);
|
||||
//gtk_box_pack_start(GTK_BOX(hbox), image, false, false, 0);
|
||||
gtk_box_pack_start(GTK_BOX(hbox), label, false, false, 0);
|
||||
gtk_box_pack_end(GTK_BOX(hbox), aclbl, false, false, 0);
|
||||
@ -347,6 +351,7 @@ void gMenu::update()
|
||||
{
|
||||
gtk_image_set_from_pixbuf(GTK_IMAGE(image), NULL);
|
||||
gtk_image_menu_item_set_image((GtkImageMenuItem *)menu, image);
|
||||
gtk_widget_hide(check);
|
||||
}
|
||||
else if (_checked)
|
||||
{
|
||||
|
@ -117,8 +117,9 @@ guint custom_dialog(const gchar *icon,GtkButtonsType btn,char *sg)
|
||||
g_free(buf);
|
||||
}
|
||||
|
||||
hrz=gtk_hbox_new(FALSE, 16);
|
||||
gtk_container_set_border_width(GTK_CONTAINER(hrz), 16);
|
||||
hrz = gtk_hbox_new(FALSE, gDesktop::scale());
|
||||
gtk_container_set_border_width(GTK_CONTAINER(hrz), gDesktop::scale() * 2);
|
||||
gtk_widget_set_size_request(hrz, gDesktop::scale() * 32, -1);
|
||||
|
||||
gtk_container_add (GTK_CONTAINER(gtk_dialog_get_content_area(GTK_DIALOG(msg))),hrz);
|
||||
|
||||
@ -549,7 +550,42 @@ bool gDialog::selectFolder()
|
||||
|
||||
return run_file_dialog(msg);
|
||||
}
|
||||
|
||||
|
||||
#ifdef GTK3
|
||||
bool gDialog::selectFont()
|
||||
{
|
||||
GtkFontChooserDialog *dialog;
|
||||
PangoFontDescription *desc;
|
||||
gFont *font;
|
||||
|
||||
dialog = (GtkFontChooserDialog *)(DIALOG_title, NULL);
|
||||
|
||||
if (DIALOG_font)
|
||||
gtk_font_chooser_set_font_desc(GTK_FONT_CHOOSER(dialog), pango_context_get_font_description(DIALOG_font->ct));
|
||||
|
||||
if (run_dialog(GTK_DIALOG(dialog)) != GTK_RESPONSE_OK)
|
||||
{
|
||||
gtk_widget_destroy(GTK_WIDGET(dialog));
|
||||
gDialog::setTitle(NULL);
|
||||
return true;
|
||||
}
|
||||
|
||||
desc = gtk_font_chooser_get_font_desc(GTK_FONT_CHOOSER(dialog));
|
||||
|
||||
gtk_widget_destroy(GTK_WIDGET(dialog));
|
||||
gDialog::setTitle(NULL);
|
||||
|
||||
font = new gFont(desc);
|
||||
setFont(font);
|
||||
gFont::assign(&font);
|
||||
|
||||
pango_font_description_free(desc);
|
||||
|
||||
//printf("-> %s/%s/%s/%d\n", DIALOG_font->name(), DIALOG_font->bold() ? "BOLD" : "", DIALOG_font->italic() ? "ITALIC" : "", DIALOG_font->size());
|
||||
|
||||
return false;
|
||||
}
|
||||
#else
|
||||
bool gDialog::selectFont()
|
||||
{
|
||||
GtkFontSelectionDialog *msg;
|
||||
@ -561,7 +597,7 @@ bool gDialog::selectFont()
|
||||
msg=(GtkFontSelectionDialog*)gtk_font_selection_dialog_new (DIALOG_title);
|
||||
else
|
||||
msg=(GtkFontSelectionDialog*)gtk_font_selection_dialog_new ("Select Font");
|
||||
|
||||
|
||||
|
||||
if (DIALOG_font)
|
||||
{
|
||||
@ -595,6 +631,7 @@ bool gDialog::selectFont()
|
||||
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef GTK3
|
||||
bool gDialog::selectColor()
|
||||
|
@ -27,14 +27,6 @@
|
||||
#include "widgets.h"
|
||||
#include "gmouse.h"
|
||||
|
||||
#ifndef GAMBAS_DIRECTFB
|
||||
#ifdef GDK_WINDOWING_X11
|
||||
#include <gdk/gdkx.h>
|
||||
#include <X11/X.h>
|
||||
#include <X11/Xlib.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
int gMouse::_isValid = 0;
|
||||
int gMouse::_x;
|
||||
int gMouse::_y;
|
||||
@ -50,20 +42,21 @@ int gMouse::_dx = 0;
|
||||
int gMouse::_dy = 0;
|
||||
GdkEvent *gMouse::_event = 0;
|
||||
|
||||
#ifdef GTK3
|
||||
static GdkDevice *get_pointer()
|
||||
{
|
||||
return gdk_device_manager_get_client_pointer(gdk_display_get_device_manager(gdk_display_get_default()));
|
||||
}
|
||||
#endif
|
||||
|
||||
void gMouse::move(int x, int y)
|
||||
{
|
||||
GdkDisplay* dpy;
|
||||
GdkWindow* win = gdk_get_default_root_window();
|
||||
#ifdef GAMBAS_DIRECTFB
|
||||
stub("DIRECTFB/gMouse::move");
|
||||
#else
|
||||
#ifdef GDK_WINDOWING_X11
|
||||
dpy = gdk_display_get_default();
|
||||
XWarpPointer(GDK_DISPLAY_XDISPLAY(dpy), GDK_WINDOW_XID(win), GDK_WINDOW_XID(win), 0, 0, 0, 0, x, y);
|
||||
#else
|
||||
stub("no-X11/gMouse::move");
|
||||
#endif
|
||||
#endif
|
||||
GdkDisplay* dpy = gdk_display_get_default();
|
||||
#ifdef GTK3
|
||||
gdk_device_warp(get_pointer(), gdk_display_get_default_screen(dpy), x, y);
|
||||
#else
|
||||
gdk_display_warp_pointer(dpy, gdk_display_get_default_screen(dpy), x, y);
|
||||
#endif
|
||||
}
|
||||
|
||||
int gMouse::button()
|
||||
@ -135,7 +128,11 @@ void gMouse::getScreenPos(int *x, int *y)
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef GTK3
|
||||
gdk_device_get_position(get_pointer(), NULL, x, y);
|
||||
#else
|
||||
gdk_display_get_pointer(gdk_display_get_default(), NULL, x, y, NULL);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@ -146,7 +143,11 @@ int gMouse::screenX()
|
||||
if (_isValid)
|
||||
x = _screen_x;
|
||||
else
|
||||
#ifdef GTK3
|
||||
gdk_device_get_position(get_pointer(), NULL, &x, NULL);
|
||||
#else
|
||||
gdk_display_get_pointer(gdk_display_get_default(), NULL, &x, NULL, NULL);
|
||||
#endif
|
||||
|
||||
return x;
|
||||
}
|
||||
@ -158,7 +159,11 @@ int gMouse::screenY()
|
||||
if (_isValid)
|
||||
y = _screen_y;
|
||||
else
|
||||
#ifdef GTK3
|
||||
gdk_device_get_position(get_pointer(), NULL, NULL, &y);
|
||||
#else
|
||||
gdk_display_get_pointer(gdk_display_get_default(), NULL, NULL, &y, NULL);
|
||||
#endif
|
||||
|
||||
return y;
|
||||
}
|
||||
|
@ -315,7 +315,11 @@ int gSlider::getDefaultSize()
|
||||
{
|
||||
GtkRequisition req;
|
||||
|
||||
gtk_widget_size_request(GTK_WIDGET(widget), &req);
|
||||
#ifdef GTK3
|
||||
gtk_widget_get_preferred_size(widget, &req, NULL);
|
||||
#else
|
||||
gtk_widget_size_request(widget, &req);
|
||||
#endif
|
||||
|
||||
if (width() < height())
|
||||
return req.width;
|
||||
|
@ -255,15 +255,11 @@ void gTextBox::setBorder(bool vl)
|
||||
|
||||
gtk_entry_set_has_frame(GTK_ENTRY(entry), vl);
|
||||
|
||||
/*if (vl)
|
||||
gtk_entry_set_inner_border(GTK_ENTRY(entry), NULL);
|
||||
else
|
||||
{*/
|
||||
#ifndef GTK3
|
||||
GtkBorder *border = gtk_border_new();
|
||||
gtk_entry_set_inner_border(GTK_ENTRY(entry), border);
|
||||
gtk_border_free(border);
|
||||
//}
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
void gTextBox::insert(char *txt, int len)
|
||||
@ -426,7 +422,11 @@ void gTextBox::updateCursor(GdkCursor *cursor)
|
||||
{
|
||||
cursor = gdk_cursor_new_for_display(gtk_widget_get_display(widget), GDK_XTERM);
|
||||
gdk_window_set_cursor(win, cursor);
|
||||
#ifdef GTK3
|
||||
g_object_unref(cursor);
|
||||
#else
|
||||
gdk_cursor_unref(cursor);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1767,8 +1767,6 @@ void gt_cairo_draw_rect(cairo_t *cr, int x, int y, int w, int h, GB_COLOR color)
|
||||
cairo_fill(cr);
|
||||
}
|
||||
|
||||
#if GTK_CHECK_VERSION(3, 10, 0)
|
||||
#else
|
||||
// Function partially taken from the GTK+ source code.
|
||||
cairo_surface_t *gt_cairo_create_surface_from_pixbuf(const GdkPixbuf *pixbuf)
|
||||
{
|
||||
@ -1858,7 +1856,6 @@ cairo_surface_t *gt_cairo_create_surface_from_pixbuf(const GdkPixbuf *pixbuf)
|
||||
|
||||
return surface;
|
||||
}
|
||||
#endif
|
||||
|
||||
void gt_cairo_draw_pixbuf(cairo_t *cr, GdkPixbuf *pixbuf, float x, float y, float w, float h, float opacity, GB_RECT *source)
|
||||
{
|
||||
@ -1929,16 +1926,14 @@ void gt_cairo_draw_pixbuf(cairo_t *cr, GdkPixbuf *pixbuf, float x, float y, floa
|
||||
|
||||
#ifdef GTK3
|
||||
static int _style_context_loaded = 0;
|
||||
static GtkStyleContext *_style_context[10];
|
||||
static GtkStyleContext *_style_context[11];
|
||||
#endif
|
||||
static int _style_loaded = 0;
|
||||
static GtkStyle *_style[10];
|
||||
static GtkStyle *_style[11];
|
||||
|
||||
static int type_to_index(GType type)
|
||||
{
|
||||
if (type == GTK_TYPE_BUTTON)
|
||||
return 0;
|
||||
else if (type == GTK_TYPE_ENTRY)
|
||||
if (type == GTK_TYPE_ENTRY)
|
||||
return 1;
|
||||
else if (type == GTK_TYPE_LAYOUT)
|
||||
return 2;
|
||||
@ -1954,10 +1949,12 @@ static int type_to_index(GType type)
|
||||
return 7;
|
||||
else if (type == GTK_TYPE_FRAME)
|
||||
return 8;
|
||||
else if (type == GTK_TYPE_LABEL || type == GTK_TYPE_LAYOUT)
|
||||
else if (type == GTK_TYPE_LABEL)
|
||||
return 9;
|
||||
else if (type == GTK_TYPE_BUTTON)
|
||||
return 10;
|
||||
else
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef GTK3
|
||||
@ -1965,9 +1962,9 @@ static int type_to_index(GType type)
|
||||
const char *gt_get_style_class(GType type)
|
||||
{
|
||||
static const char *_class[] = {
|
||||
GTK_STYLE_CLASS_BUTTON, GTK_STYLE_CLASS_ENTRY, GTK_STYLE_CLASS_BACKGROUND, GTK_STYLE_CLASS_TOOLTIP,
|
||||
GTK_STYLE_CLASS_SCROLLBAR, NULL, GTK_STYLE_CLASS_CHECK, GTK_STYLE_CLASS_RADIO,
|
||||
GTK_STYLE_CLASS_FRAME, GTK_STYLE_CLASS_BACKGROUND
|
||||
GTK_STYLE_CLASS_DEFAULT, GTK_STYLE_CLASS_ENTRY, GTK_STYLE_CLASS_BACKGROUND, GTK_STYLE_CLASS_TOOLTIP,
|
||||
GTK_STYLE_CLASS_SCROLLBAR, GTK_STYLE_CLASS_DEFAULT, GTK_STYLE_CLASS_CHECK, GTK_STYLE_CLASS_RADIO,
|
||||
GTK_STYLE_CLASS_FRAME, GTK_STYLE_CLASS_BACKGROUND, GTK_STYLE_CLASS_BUTTON
|
||||
};
|
||||
|
||||
int index = type_to_index(type);
|
||||
|
@ -138,11 +138,7 @@ GtkWidget *gtk_window_group_get_current_grab(GtkWindowGroup *window_group);
|
||||
|
||||
// Cairo support
|
||||
|
||||
#if GTK_CHECK_VERSION(3, 10, 0)
|
||||
#define gt_cairo_create_surface_from_pixbuf gdk_cairo_surface_create_from_pixbuf
|
||||
#else
|
||||
cairo_surface_t *gt_cairo_create_surface_from_pixbuf(const GdkPixbuf *pixbuf);
|
||||
#endif
|
||||
|
||||
void gt_cairo_set_source_color(cairo_t *cr, GB_COLOR color);
|
||||
void gt_cairo_draw_rect(cairo_t *cr, int x, int y, int w, int h, GB_COLOR color);
|
||||
|
@ -136,6 +136,15 @@ typedef
|
||||
#define STATE_PRELIGHT GTK_STATE_FLAG_PRELIGHT
|
||||
#define STATE_SELECTED GTK_STATE_FLAG_SELECTED
|
||||
|
||||
#define gtk_hbox_new(_homogeneous, _spacing) gtk_box_new(GTK_ORIENTATION_HORIZONTAL, _spacing)
|
||||
#define gtk_vbox_new(_homogeneous, _spacing) gtk_box_new(GTK_ORIENTATION_VERTICAL, _spacing)
|
||||
|
||||
#define gtk_hscale_new(_adj) gtk_scale_new(GTK_ORIENTATION_HORIZONTAL, _adj)
|
||||
#define gtk_vscale_new(_adj) gtk_scale_new(GTK_ORIENTATION_VERTICAL, _adj)
|
||||
|
||||
#define gtk_hscrollbar_new(_adj) gtk_scrollbar_new(GTK_ORIENTATION_HORIZONTAL, _adj)
|
||||
#define gtk_vscrollbar_new(_adj) gtk_scrollbar_new(GTK_ORIENTATION_VERTICAL, _adj)
|
||||
|
||||
#else
|
||||
|
||||
#define STATE_T GtkStateType
|
||||
|
Loading…
x
Reference in New Issue
Block a user