Skip to content

Commit

Permalink
New: support for GTK/GDK 3.
Browse files Browse the repository at this point in the history
  • Loading branch information
scuri committed Sep 18, 2012
1 parent 72e362c commit a22a71b
Show file tree
Hide file tree
Showing 13 changed files with 81 additions and 38 deletions.
1 change: 0 additions & 1 deletion mak.vc9/iupsample.vcproj
Expand Up @@ -630,7 +630,6 @@
>
<FileConfiguration
Name="Debug|Win32"
ExcludedFromBuild="true"
>
<Tool
Name="VCCLCompilerTool"
Expand Down
6 changes: 4 additions & 2 deletions src/config.mak
Expand Up @@ -50,8 +50,10 @@ endif

ifdef USE_GTK
CHECK_GTK = Yes
DEFINES += GTK_DISABLE_DEPRECATED GDK_DISABLE_DEPRECATED
DEFINES += GSEAL_ENABLE
DEFINES += GTK_DISABLE_DEPRECATED
ifdef USE_GTK3
DEFINES += GDK_DISABLE_DEPRECATED GSEAL_ENABLE
endif
INCLUDES += gtk
SRC += gtk/iupgtk_focus.c gtk/iupgtk_clipboard.c gtk/iupgtk_val.c \
gtk/iupgtk_globalattrib.c gtk/iupgtk_key.c gtk/iupgtk_tips.c \
Expand Down
4 changes: 2 additions & 2 deletions src/gtk/iupgtk_canvas.c
Expand Up @@ -220,7 +220,7 @@ static void gtkCanvasLayoutUpdateMethod(Ihandle *ih)
iupdrvBaseLayoutUpdateMethod(ih);

/* Force GdkWindow size update when not visible,
so when mapped before show the function gdk_drawable_get_size returns the correct value. */
so when mapped before show GDK returns the correct value. */
if (!iupdrvIsVisible(ih))
gdk_window_resize(window, ih->currentwidth, ih->currentheight);

Expand Down Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions src/gtk/iupgtk_common.c
Expand Up @@ -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
*/
26 changes: 16 additions & 10 deletions src/gtk/iupgtk_draw.c
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
1 change: 1 addition & 0 deletions src/gtk/iupgtk_font.c
Expand Up @@ -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 */
Expand Down
4 changes: 2 additions & 2 deletions src/gtk/iupgtk_image.c
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion src/gtk/iupgtk_open.c
Expand Up @@ -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
Expand Down
12 changes: 8 additions & 4 deletions src/iup_draw.h
Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/iup_layoutdlg.c
Expand Up @@ -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);
}
}

Expand Down
24 changes: 16 additions & 8 deletions src/mot/iupmot_draw.c
Expand Up @@ -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));
Expand Down Expand Up @@ -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 <Xm/XmP.h>
#include <Xm/DrawP.h>

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);
}
24 changes: 18 additions & 6 deletions src/win/iupwin_draw.c
Expand Up @@ -316,14 +316,14 @@ 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;
rect.right = x+w;
rect.bottom = y+h;

DrawFocusRect(hDC, &rect);
(void)ih;
}

void iupwinDrawParentBackground(Ihandle* ih, HDC hDC, RECT* rect)
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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);
}
2 changes: 1 addition & 1 deletion srccontrols/iup_cdutil.c
Expand Up @@ -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);
Expand Down

0 comments on commit a22a71b

Please sign in to comment.