From a22a71b41379f6f08848b59c5c9b6bf5afa15a6d Mon Sep 17 00:00:00 2001 From: scuri Date: Tue, 18 Sep 2012 23:07:32 +0000 Subject: [PATCH] New: support for GTK/GDK 3. --- mak.vc9/iupsample.vcproj | 1 - src/config.mak | 6 ++++-- src/gtk/iupgtk_canvas.c | 4 ++-- src/gtk/iupgtk_common.c | 6 ++++++ src/gtk/iupgtk_draw.c | 26 ++++++++++++++++---------- src/gtk/iupgtk_font.c | 1 + src/gtk/iupgtk_image.c | 4 ++-- src/gtk/iupgtk_open.c | 7 ++++++- src/iup_draw.h | 12 ++++++++---- src/iup_layoutdlg.c | 2 +- src/mot/iupmot_draw.c | 24 ++++++++++++++++-------- src/win/iupwin_draw.c | 24 ++++++++++++++++++------ srccontrols/iup_cdutil.c | 2 +- 13 files changed, 81 insertions(+), 38 deletions(-) diff --git a/mak.vc9/iupsample.vcproj b/mak.vc9/iupsample.vcproj index eede34b8..59e0e593 100644 --- a/mak.vc9/iupsample.vcproj +++ b/mak.vc9/iupsample.vcproj @@ -630,7 +630,6 @@ > currentwidth, ih->currentheight); @@ -526,7 +526,7 @@ static char* gtkCanvasGetDrawSizeAttrib(Ihandle *ih) if (window) { -#if GTK_CHECK_VERSION(3, 0, 0) +#if GTK_CHECK_VERSION(2, 24, 0) w = gdk_window_get_width(window); h = gdk_window_get_height(window); #else diff --git a/src/gtk/iupgtk_common.c b/src/gtk/iupgtk_common.c index 1b7a807c..857d3263 100644 --- a/src/gtk/iupgtk_common.c +++ b/src/gtk/iupgtk_common.c @@ -1092,3 +1092,9 @@ void iupgtkWindowGetPointer(GdkWindow *window, int *x, int *y, GdkModifierType * gdk_window_get_pointer(window, x, y, mask); #endif } + +/* Deprecated but still used for GTK2: + gdk_bitmap_create_from_data (since 2.22) + gdk_font_id + gdk_font_from_description +*/ diff --git a/src/gtk/iupgtk_draw.c b/src/gtk/iupgtk_draw.c index f75499ab..f9b157e1 100644 --- a/src/gtk/iupgtk_draw.c +++ b/src/gtk/iupgtk_draw.c @@ -91,16 +91,6 @@ void iupDrawParentBackground(IdrawCanvas* dc) iupDrawRectangle(dc, 0, 0, dc->w-1, dc->h-1, r, g, b, IUP_DRAW_FILL); } -void iupDrawRectangleInvert(IdrawCanvas* dc, int x1, int y1, int x2, int y2) -{ - GdkColor color; - iupgdkColorSet(&color, 255, 255, 255); - gdk_gc_set_rgb_fg_color(dc->pixmap_gc, &color); - gdk_gc_set_function(dc->pixmap_gc, GDK_XOR); - gdk_draw_rectangle(dc->pixmap, dc->pixmap_gc, TRUE, x1, y1, x2-x1+1, y2-y1+1); - gdk_gc_set_function(dc->pixmap_gc, GDK_COPY); -} - void iupDrawRectangle(IdrawCanvas* dc, int x1, int y1, int x2, int y2, unsigned char r, unsigned char g, unsigned char b, int style) { GdkColor color; @@ -213,3 +203,19 @@ void iupDrawImage(IdrawCanvas* dc, const char* name, int make_inactive, int x, i gdk_draw_pixbuf(dc->pixmap, dc->pixmap_gc, pixbuf, 0, 0, x, y, *img_w, *img_h, GDK_RGB_DITHER_NORMAL, 0, 0); } + +void iupDrawFocusRect(IdrawCanvas* dc, int x, int y, int w, int h) +{ + GtkStyle *style = gtk_widget_get_style(dc->ih->handle); + gtk_paint_focus(style, dc->pixmap, GTK_STATE_NORMAL, NULL, NULL, NULL, x, y, w, h); +} + +void iupDrawSelectRect(IdrawCanvas* dc, int x, int y, int w, int h) +{ + GdkColor color; + iupgdkColorSet(&color, 255, 255, 255); + gdk_gc_set_rgb_fg_color(dc->pixmap_gc, &color); + gdk_gc_set_function(dc->pixmap_gc, GDK_XOR); + gdk_draw_rectangle(dc->pixmap, dc->pixmap_gc, TRUE, x, y, w, h); + gdk_gc_set_function(dc->pixmap_gc, GDK_COPY); +} diff --git a/src/gtk/iupgtk_font.c b/src/gtk/iupgtk_font.c index 24a750cd..56ddb1fd 100644 --- a/src/gtk/iupgtk_font.c +++ b/src/gtk/iupgtk_font.c @@ -323,6 +323,7 @@ char* iupgtkGetFontIdAttrib(Ihandle *ih) #if GTK_CHECK_VERSION(3, 0, 0) return NULL; /* TODO: check gtkglarea for GTK3 support, not available yet. */ #else + /* both fucntions are marked as deprecated in GDK (since 2.22) */ GdkFont* gdk_font = gdk_font_from_description(gtkfont->fontdesc); return (char*)gdk_font_id(gdk_font); /* In UNIX will return an X Font ID, in Win32 will return an HFONT */ diff --git a/src/gtk/iupgtk_image.c b/src/gtk/iupgtk_image.c index 0a7214e6..2da21255 100644 --- a/src/gtk/iupgtk_image.c +++ b/src/gtk/iupgtk_image.c @@ -302,8 +302,8 @@ void* iupdrvImageCreateCursor(Ihandle *ih) cursor = gdk_cursor_new_from_pixmap(source, mask, &fg, &bg, hx, hy); - gdk_pixmap_unref(source); - gdk_pixmap_unref(mask); + g_object_unref(source); + g_object_unref(mask); free(sbits); } else diff --git a/src/gtk/iupgtk_open.c b/src/gtk/iupgtk_open.c index ccfeb218..bc5c4e7b 100644 --- a/src/gtk/iupgtk_open.c +++ b/src/gtk/iupgtk_open.c @@ -146,7 +146,12 @@ void iupgtkPushVisualAndColormap(void* visual, void* colormap) (void)colormap; #else GdkColormap* gdk_colormap; - GdkVisual *gdk_visual = gdkx_visual_get(XVisualIDFromVisual((Visual*)visual)); +#if GTK_CHECK_VERSION(2, 24, 0) + GdkScreen* screen = gdk_screen_get_default(); + GdkVisual* gdk_visual = gdk_x11_screen_lookup_visual(screen, XVisualIDFromVisual((Visual*)visual)); +#else + GdkVisual* gdk_visual = gdkx_visual_get(XVisualIDFromVisual((Visual*)visual)); +#endif if (colormap) gdk_colormap = gdk_x11_colormap_foreign_new(gdk_visual, (Colormap)colormap); else diff --git a/src/iup_draw.h b/src/iup_draw.h index b8ce923f..290bb455 100644 --- a/src/iup_draw.h +++ b/src/iup_draw.h @@ -58,10 +58,6 @@ void iupDrawLine(IdrawCanvas* dc, int x1, int y1, int x2, int y2, unsigned char * \ingroup draw */ void iupDrawRectangle(IdrawCanvas* dc, int x1, int y1, int x2, int y2, unsigned char r, unsigned char g, unsigned char b, int style); -/** Draws a rectangle inverting the color in the canvas. - * \ingroup draw */ -void iupDrawRectangleInvert(IdrawCanvas* dc, int x1, int y1, int x2, int y2); - /** Draws a filled/hollow arc. * \ingroup draw */ void iupDrawArc(IdrawCanvas* dc, int x1, int y1, int x2, int y2, double a1, double a2, unsigned char r, unsigned char g, unsigned char b, int style); @@ -90,6 +86,14 @@ void iupDrawSetClipRect(IdrawCanvas* dc, int x1, int y1, int x2, int y2); * \ingroup draw */ void iupDrawResetClip(IdrawCanvas* dc); +/** Draws a focus rectangle + * \ingroup draw */ +void iupDrawFocusRect(IdrawCanvas* dc, int x, int y, int w, int h); + +/** Draws a selection rectangle. + * \ingroup draw */ +void iupDrawSelectRect(IdrawCanvas* dc, int x, int y, int w, int h); + /* TO DO: - check position and size of primitives diff --git a/src/iup_layoutdlg.c b/src/iup_layoutdlg.c index 2ca2b53c..28479815 100644 --- a/src/iup_layoutdlg.c +++ b/src/iup_layoutdlg.c @@ -1191,7 +1191,7 @@ static void iLayoutDrawElement(IdrawCanvas* dc, Ihandle* ih, int marked, int nat if (w<=0) w=1; if (h<=0) h=1; - iupDrawRectangleInvert(dc, x, y, x+w-1, y+h-1); + iupDrawSelectRect(dc, x, y, w, h); } } diff --git a/src/mot/iupmot_draw.c b/src/mot/iupmot_draw.c index dc1a7d2c..be94331c 100644 --- a/src/mot/iupmot_draw.c +++ b/src/mot/iupmot_draw.c @@ -105,14 +105,6 @@ void iupDrawParentBackground(IdrawCanvas* dc) iupDrawRectangle(dc, 0, 0, dc->w-1, dc->h-1, r, g, b, IUP_DRAW_FILL); } -void iupDrawRectangleInvert(IdrawCanvas* dc, int x1, int y1, int x2, int y2) -{ - XSetFunction(iupmot_display, dc->pixmap_gc, GXxor); - XSetForeground(iupmot_display, dc->pixmap_gc, iupmotColorGetPixel(255, 255, 255)); - XFillRectangle(iupmot_display, dc->pixmap, dc->pixmap_gc, x1, y1, x2-x1+1, y2-y1+1); - XSetFunction(iupmot_display, dc->pixmap_gc, GXcopy); -} - void iupDrawRectangle(IdrawCanvas* dc, int x1, int y1, int x2, int y2, unsigned char r, unsigned char g, unsigned char b, int style) { XSetForeground(iupmot_display, dc->pixmap_gc, iupmotColorGetPixel(r, g, b)); @@ -233,3 +225,19 @@ void iupDrawImage(IdrawCanvas* dc, const char* name, int make_inactive, int x, i XCopyArea(iupmot_display, pixmap, dc->pixmap, dc->pixmap_gc, 0, 0, *img_w, *img_h, x, y); } + +#include +#include + +void iupDrawFocusRect(IdrawCanvas* dc, int x, int y, int w, int h) +{ + XmeDrawHighlight(iupmot_display, dc->pixmap, dc->pixmap_gc, x, y, w, h, 1); +} + +void iupDrawSelectRect(IdrawCanvas* dc, int x, int y, int w, int h) +{ + XSetFunction(iupmot_display, dc->pixmap_gc, GXxor); + XSetForeground(iupmot_display, dc->pixmap_gc, iupmotColorGetPixel(255, 255, 255)); + XFillRectangle(iupmot_display, dc->pixmap, dc->pixmap_gc, x, y, w, h); + XSetFunction(iupmot_display, dc->pixmap_gc, GXcopy); +} diff --git a/src/win/iupwin_draw.c b/src/win/iupwin_draw.c index 7a3b74f0..c59b9a66 100644 --- a/src/win/iupwin_draw.c +++ b/src/win/iupwin_draw.c @@ -316,7 +316,6 @@ void iupdrvDrawFocusRect(Ihandle* ih, void* gc, int x, int y, int w, int h) { HDC hDC = (HDC)gc; RECT rect; - (void)ih; rect.left = x; rect.top = y; @@ -324,6 +323,7 @@ void iupdrvDrawFocusRect(Ihandle* ih, void* gc, int x, int y, int w, int h) rect.bottom = y+h; DrawFocusRect(hDC, &rect); + (void)ih; } void iupwinDrawParentBackground(Ihandle* ih, HDC hDC, RECT* rect) @@ -453,11 +453,6 @@ void iupDrawParentBackground(IdrawCanvas* dc) iupDrawRectangle(dc, 0, 0, dc->w-1, dc->h-1, r, g, b, IUP_DRAW_FILL); } -void iupDrawRectangleInvert(IdrawCanvas* dc, int x1, int y1, int x2, int y2) -{ - BitBlt(dc->hBitmapDC, x1, y1, x2-x1+1, y2-y1+1, dc->hBitmapDC, x1, y1, DSTINVERT); -} - void iupDrawRectangle(IdrawCanvas* dc, int x1, int y1, int x2, int y2, unsigned char r, unsigned char g, unsigned char b, int style) { SetDCBrushColor(dc->hBitmapDC, RGB(r,g,b)); @@ -618,3 +613,20 @@ void iupDrawImage(IdrawCanvas* dc, const char* name, int make_inactive, int x, i if (hMask) DeleteObject(hMask); } + +void iupDrawFocusRect(IdrawCanvas* dc, int x, int y, int w, int h) +{ + RECT rect; + + rect.left = x; + rect.top = y; + rect.right = x+w; + rect.bottom = y+h; + + DrawFocusRect(dc->hBitmapDC, &rect); +} + +void iupDrawSelectRect(IdrawCanvas* dc, int x, int y, int w, int h) +{ + BitBlt(dc->hBitmapDC, x, y, w, h, dc->hBitmapDC, x, y, DSTINVERT); +} diff --git a/srccontrols/iup_cdutil.c b/srccontrols/iup_cdutil.c index b7a2820f..0f7fe304 100644 --- a/srccontrols/iup_cdutil.c +++ b/srccontrols/iup_cdutil.c @@ -123,7 +123,7 @@ void cdIupDrawFocusRect(Ihandle* ih, cdCanvas *canvas, int x1, int y1, int x2, i #ifdef WIN32 void* gc = cdCanvasGetAttribute(canvas, "HDC"); #else - void* gc = cdCanvasGetAttribute(canvas, "GC"); + void* gc = cdCanvasGetAttribute(canvas, "GC"); /* works for X11, GDK and Cairo */ #endif cdCanvasUpdateYAxis(canvas, &y1);