Fix popup management, and save drawing context when running a style method.

[GB.GTK]
* BUG: Fix popup management.
* BUG: Save drawing context when running a style method.

[GB.GTK3]
* BUG: Fix popup management.
* BUG: Save drawing context when running a style method.
This commit is contained in:
gambas 2020-08-03 02:22:02 +02:00
parent ff5541cdb9
commit 0720b6763d
6 changed files with 369 additions and 379 deletions

View file

@ -9,7 +9,7 @@ Component=gb.gui
Component=gb.form
Component=gb.db
Authors="Benoît Minisini"
Environment="GB_GUI=gb.gtk3"
Environment="GB_GUI=gb.qt5"
TabSize=2
Translate=1
Language=en

View file

@ -295,6 +295,7 @@ Private Sub SetValue(vVal As Variant)
Dim I As Integer
Dim hView As TableView
Dim iAlign As Integer
LoadPopup
If IsNull(vVal) Then
@ -318,7 +319,17 @@ Private Sub SetValue(vVal As Variant)
For I = 0 To $aText.Max
$aText[I] = hView[hView.Row, I].Text
$aWidth[I] = hView.Columns[I].Width
$aAlign[I] = hView[hView.Row, I].Alignment
iAlign = hView[hView.Row, I].Alignment
If Align.IsLeft(iAlign) Then
$aAlign[I] = Align.Left
Else If Align.IsRight(iAlign) Then
$aAlign[I] = Align.Right
Else
$aAlign[I] = Align.Center
Endif
Next
$hDrawingArea.Refresh
@ -405,33 +416,6 @@ Public Sub DrawingArea_MouseDown()
End
' Public Sub DrawingArea_MouseMove()
'
' Dim bPressed As Boolean
'
' bPressed = $hDrawingArea.Hovered
'
' If $bPressed <> bPressed Then
' $bPressed = bPressed
' $hDrawingArea.Refresh
' Endif
'
' End
'
'
' Public Sub DrawingArea_MouseUp()
'
' If Not Mouse.Left Then Return
' If Not Me.Enabled Then Return
' If Not $bPressed Then Return
'
' $bPressed = False
' $hDrawingArea.Refresh
'
' 'If Not $bInsideArrow Then Button_Click
'
' End
Public Sub DrawingArea_Draw()
Dim X As Integer
@ -454,8 +438,9 @@ Public Sub DrawingArea_Draw()
Paint.ClipRect = Rect(0, 0, Me.W - Desktop.Scale * 3, Me.H)
For I = 0 To $aText.Max
If I > 0 And If $hView.Grid Then Paint.FillRect(X, 0, 1, Me.H, Color.LightForeground)
X2 = X + $aWidth[I]
Paint.DrawText($aText[I], X + 4, 0, X2 - X - 5, Me.H, $aAlign[I])
Paint.DrawText($aText[I], X + 4, 0, X2 - X - 6, Me.H, $aAlign[I])
X = X2
Next

View file

@ -41,6 +41,7 @@
{ DataComboView1 DataComboView
MoveScaled(2,30,50,4)
Table = "user"
Grid = True
}
}
}

View file

@ -52,7 +52,7 @@ static STYLE_T *_stl = NULL;
static GtkStyleContext *get_style(GType type = G_TYPE_NONE)
{
GtkWidget *widget = NULL;
if (type == GTK_TYPE_BUTTON)
{
if (!_button) _button = gtk_button_new();
@ -65,7 +65,7 @@ static GtkStyleContext *get_style(GType type = G_TYPE_NONE)
}
else if (type == GTK_TYPE_ENTRY)
{
if (!_entry)
if (!_entry)
{
_entry = gtk_entry_new();
gtk_widget_set_name(_entry, "se");
@ -77,10 +77,10 @@ static GtkStyleContext *get_style(GType type = G_TYPE_NONE)
if (!_radio_button) _radio_button = gtk_radio_button_new(NULL);
widget = _radio_button;
}
if (!_css)
_css = GTK_STYLE_PROVIDER(gtk_css_provider_new());
return widget ? gtk_widget_get_style_context(widget) : NULL;
}
#else
@ -105,12 +105,12 @@ static GtkStyle *get_style(GType type = G_TYPE_NONE)
_stl = gtk_style_copy(gt_get_style(type));
else
_stl = gtk_style_copy(gtk_widget_get_default_style());
//_stl = gtk_style_attach(_stl, (GdkWindow*)_dr);
}
_stl = attach_style(_stl);
return _stl;
}
#endif
@ -123,6 +123,7 @@ static bool begin_draw(int *x, int *y)
return TRUE;
_cr = PAINT_get_current_context();
cairo_save(_cr);
if (GB.Is(device, CLASS_DrawingArea))
{
@ -149,14 +150,15 @@ static bool begin_draw(int *x, int *y)
void *device = PAINT_get_current_device();
if (!device)
return TRUE;
cairo_t *context = PAINT_get_current_context();
cairo_surface_flush(cairo_get_target(context));
cairo_save(context);
if (GB.Is(device, CLASS_DrawingArea))
{
gDrawingArea *wid = (gDrawingArea *)((CDRAWINGAREA *)device)->ob.widget;
if (wid->cached() || wid->inDrawEvent())
{
if (wid->cached())
@ -179,7 +181,7 @@ static bool begin_draw(int *x, int *y)
GB.Error("Cannot draw outside of 'Draw' event handler");
return TRUE;
}
_widget = wid->widget;
}
else if (GB.Is(device, CLASS_Picture))
@ -198,7 +200,7 @@ static bool begin_draw(int *x, int *y)
{
GB.Error("Device not supported");
}
return FALSE;
}
#endif
@ -206,6 +208,7 @@ static bool begin_draw(int *x, int *y)
static void end_draw()
{
#ifdef GTK3
cairo_restore(_cr);
_cr = NULL;
if (_stl)
{
@ -225,6 +228,7 @@ static void end_draw()
#ifndef GTK3
cairo_t *context = PAINT_get_current_context();
cairo_restore(context);
cairo_surface_mark_dirty(cairo_get_target(context));
#endif
}
@ -290,7 +294,7 @@ static STATE_T get_state(int state)
static GdkRectangle *get_area()
{
static GdkRectangle area;
if (PAINT_get_clip(&area.x, &area.y, &area.width, &area.height))
return NULL;
else
@ -319,7 +323,7 @@ static void style_arrow(int x, int y, int w, int h, int type, int state)
{
GtkArrowType arrow;
STYLE_T *style = get_style(GTK_TYPE_BUTTON);
switch (type)
{
case ALIGN_NORMAL: arrow = GB.System.IsRightToLeft() ? GTK_ARROW_LEFT : GTK_ARROW_RIGHT; break;
@ -330,7 +334,7 @@ static void style_arrow(int x, int y, int w, int h, int type, int state)
default:
return;
}
#ifdef GTK3
double angle;
@ -356,8 +360,8 @@ static void style_arrow(int x, int y, int w, int h, int type, int state)
set_state(style, state);
gtk_render_arrow(style, _cr, angle, x, y, w);
#else
gtk_paint_arrow(style, _dr, get_state(state),
GTK_SHADOW_NONE, get_area(), _widget, NULL,
gtk_paint_arrow(style, _dr, get_state(state),
GTK_SHADOW_NONE, get_area(), _widget, NULL,
arrow, TRUE, x, y, w, h);
#endif
}
@ -367,21 +371,21 @@ static void render_toggle(int x, int y, int w, int h, int value, int state, bool
{
static GtkCellRenderer *cell = NULL;
GdkRectangle area;
if (!cell)
{
cell = gtk_cell_renderer_toggle_new();
gtk_cell_renderer_toggle_set_radio(GTK_CELL_RENDERER_TOGGLE(cell), radio);
}
g_object_set(G_OBJECT(cell), "active", value < 0, NULL);
g_object_set(G_OBJECT(cell), "inconsistent", value > 0, NULL);
area.x = x;
area.y = y;
area.width = w;
area.height = h;
gtk_cell_renderer_render(cell, _cr, radio ? _radio_button : _check_button, &area, &area, get_cell_state(state));
}
#endif
@ -389,21 +393,21 @@ static void render_toggle(int x, int y, int w, int h, int value, int state, bool
static void style_check(int x, int y, int w, int h, int value, int state)
{
#ifdef GTK3
get_style(GTK_TYPE_CHECK_BUTTON);
render_toggle(x, y, w, h, value, state, FALSE);
#else
STYLE_T *style = get_style(GTK_TYPE_CHECK_BUTTON);
GtkShadowType shadow;
GtkStateType st = get_state(state);
if (value)
state |= GB_DRAW_STATE_ACTIVE;
//_dr->offset(&x, &y);
switch (value)
{
case -1: shadow = GTK_SHADOW_IN; break;
@ -416,27 +420,27 @@ static void style_check(int x, int y, int w, int h, int value, int state)
x, y, w, h);
if (state & GB_DRAW_STATE_FOCUS)
paint_focus(style, x, y, w, h, st, "checkbutton");
#endif
}
static void style_option(int x, int y, int w, int h, int value, int state)
{
#ifdef GTK3
get_style(GTK_TYPE_RADIO_BUTTON);
render_toggle(x, y, w, h, value, state, true);
#else
STYLE_T *style = get_style(GTK_TYPE_RADIO_BUTTON);
if (value)
state |= GB_DRAW_STATE_ACTIVE;
GtkShadowType shadow;
GtkStateType st = get_state(state | (value ? GB_DRAW_STATE_ACTIVE : 0));
shadow = value ? GTK_SHADOW_IN : GTK_SHADOW_OUT;
gtk_paint_option(style, _dr,
@ -444,7 +448,7 @@ static void style_option(int x, int y, int w, int h, int value, int state)
x, y, w, h);
if (state & GB_DRAW_STATE_FOCUS)
paint_focus(style, x, y, w, h, st, "radiobutton");
#endif
}
@ -496,7 +500,7 @@ static void style_button(int x, int y, int w, int h, int value, int state, int f
"focus-line-width", &focus_width,
"focus-padding", &focus_pad,
"interior-focus", &interior_focus,
(char *)NULL);
(char *)NULL);
/*if (default_outside_border)
{
@ -505,7 +509,7 @@ static void style_button(int x, int y, int w, int h, int value, int state, int f
w -= default_outside_border->left + default_outside_border->right;
h -= default_outside_border->top + default_outside_border->bottom;
}*/
if (default_border)
{
x += default_border->left;
@ -517,12 +521,12 @@ static void style_button(int x, int y, int w, int h, int value, int state, int f
if (inner_border) gtk_border_free(inner_border);
if (default_outside_border) gtk_border_free(default_outside_border);
if (default_border) gtk_border_free(default_border);
xf = x;
yf = y;
wf = w;
hf = h;
if (interior_focus)
{
df = focus_pad + style->xthickness;
@ -535,14 +539,14 @@ static void style_button(int x, int y, int w, int h, int value, int state, int f
else if (state & GB_DRAW_STATE_FOCUS)
{
df = focus_pad + focus_width;
x += df;
w -= df * 2;
y += df;
h -= df * 2;
}
#endif
if (flat && (state & GB_DRAW_STATE_HOVER) == 0)
{
/*gtk_paint_flat_box(style, _dr,
@ -575,7 +579,7 @@ static void style_button(int x, int y, int w, int h, int value, int state, int f
}
}
static void style_panel(int x, int y, int w, int h, int border, int state)
{
STYLE_T *style = get_style();
@ -602,7 +606,7 @@ static void style_panel(int x, int y, int w, int h, int border, int state)
case BORDER_ETCHED: shadow = GTK_SHADOW_ETCHED_IN; break;
default: shadow = GTK_SHADOW_NONE;
}
gtk_paint_shadow(style, _dr, st, shadow, get_area(), NULL, NULL, x, y, w, h);
if (border == BORDER_PLAIN)
@ -625,7 +629,7 @@ static void style_panel(int x, int y, int w, int h, int border, int state)
#endif
}
static void style_handle(int x, int y, int w, int h, int vertical, int state)
{
STYLE_T *style = get_style();
@ -652,21 +656,21 @@ static void style_box(int x, int y, int w, int h, int state, GB_COLOR color)
}
#ifdef GTK3
set_state(style, state);
if (color != GB_COLOR_DEFAULT)
{
char *css = NULL;
char buffer[256];
g_stradd(&css, "#se:not(:selected) { background-color:");
gt_to_css_color(buffer, color);
g_stradd(&css, buffer);
g_stradd(&css, "; background-image:none; }\n");
gtk_css_provider_load_from_data(GTK_CSS_PROVIDER(_css), css, -1, NULL);
gtk_style_context_add_provider(style, _css, GTK_STYLE_PROVIDER_PRIORITY_USER);
#if GTK_CHECK_VERSION(3, 12, 0)
#else
gtk_style_context_invalidate(style);
@ -682,15 +686,15 @@ static void style_box(int x, int y, int w, int h, int state, GB_COLOR color)
gtk_render_background(style, _cr, x, y, w, h);
gtk_render_frame(style, _cr, x, y, w, h);
if (color != GB_COLOR_DEFAULT)
gtk_style_context_remove_provider(style, _css);
#else
if (gApplication::fix_breeze)
state &= ~GB_DRAW_STATE_HOVER;
GtkStateType st = get_state(state);
if (color == GB_COLOR_DEFAULT)
@ -783,7 +787,7 @@ END_PROPERTY
return;
#define END_DRAW() end_draw()
BEGIN_METHOD(Style_PaintArrow, GB_INTEGER x; GB_INTEGER y; GB_INTEGER w; GB_INTEGER h; GB_INTEGER type; GB_INTEGER state)
BEGIN_DRAW();
@ -899,7 +903,7 @@ END_METHOD
GB_DESC StyleDesc[] =
{
GB_DECLARE("Style", 0), GB_VIRTUAL_CLASS(),
GB_STATIC_PROPERTY_READ("ScrollbarSize", "i", Style_ScrollbarSize),
GB_STATIC_PROPERTY_READ("ScrollbarSpacing", "i", Style_ScrollbarSpacing),
GB_STATIC_PROPERTY_READ("FrameWidth", "i", Style_FrameWidth),
@ -907,7 +911,7 @@ GB_DESC StyleDesc[] =
GB_STATIC_PROPERTY_READ("BoxFrameWidth", "i", Style_BoxFrameWidth),
GB_STATIC_PROPERTY_READ("BoxFrameHeight", "i", Style_BoxFrameHeight),
GB_STATIC_PROPERTY_READ("Name", "s", Style_Name),
GB_STATIC_METHOD("PaintArrow", NULL, Style_PaintArrow, "(X)i(Y)i(Width)i(Height)i(Type)i[(Flag)i]"),
GB_STATIC_METHOD("PaintCheck", NULL, Style_PaintCheck, "(X)i(Y)i(Width)i(Height)i(Value)i[(Flag)i]"),
GB_STATIC_METHOD("PaintOption", NULL, Style_PaintOption, "(X)i(Y)i(Width)i(Height)i(Value)b[(Flag)i]"),
@ -916,7 +920,7 @@ GB_DESC StyleDesc[] =
GB_STATIC_METHOD("PaintPanel", NULL, Style_PaintPanel, "(X)i(Y)i(Width)i(Height)i(Border)i[(Flag)i]"),
GB_STATIC_METHOD("PaintHandle", NULL, Style_PaintHandle, "(X)i(Y)i(Width)i(Height)i[(Vertical)b(Flag)i]"),
GB_STATIC_METHOD("PaintBox", NULL, Style_PaintBox, "(X)i(Y)i(Width)i(Height)i[(Flag)i(Color)i]"),
GB_CONSTANT("Normal", "i", GB_DRAW_STATE_NORMAL),
GB_CONSTANT("Disabled", "i", GB_DRAW_STATE_DISABLED),
GB_CONSTANT("HasFocus", "i", GB_DRAW_STATE_FOCUS),
@ -929,4 +933,3 @@ GB_DESC StyleDesc[] =
GB_END_DECLARE
};

View file

@ -55,7 +55,7 @@ static void *temp_image(GB_IMG *img)
if (!img->data)
image = NULL; // TODO: use a static small image surface
else
image = cairo_image_surface_create_for_data(img->data, CAIRO_FORMAT_ARGB32, img->width, img->height,
image = cairo_image_surface_create_for_data(img->data, CAIRO_FORMAT_ARGB32, img->width, img->height,
cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, img->width));
return image;
}
@ -126,28 +126,29 @@ static gFont *get_default_font(GB_PAINT *d)
return new gFont();
}
}
static bool init_painting(GB_PAINT *d, cairo_surface_t *target, double w, double h, int rx, int ry)
{
GB_PAINT_EXTRA *dx = EXTRA(d);
d->area.width = w;
d->area.height = h;
d->resolutionX = rx; //device->physicalDpiX();
d->resolutionY = ry; //device->physicalDpiY();
/*if (device->paintingActive())
{
GB.Error("Device already being painted");
return TRUE;
}*/
if (target)
{
dx->context = cairo_create(target);
cairo_surface_destroy(target);
}
cairo_set_source_rgba(CONTEXT(d), 0, 0, 0, 1);
cairo_set_line_width(CONTEXT(d), 1.0);
/*cairo_set_line_join(CONTEXT(d), CAIRO_LINE_JOIN_MITER);
cairo_set_miter_limit(CONTEXT(d), 10.0);
@ -155,9 +156,9 @@ static bool init_painting(GB_PAINT *d, cairo_surface_t *target, double w, double
dx->font = get_default_font(d);
dx->font_stack = NULL;
cairo_get_matrix(CONTEXT(d), &EXTRA(d)->init);
return FALSE;
}
@ -172,10 +173,10 @@ static void _gtk_print_context_rotate_according_to_orientation (GtkPrintContext
width = width * context->surface_dpi_x / context->pixels_per_unit_x;
height = gtk_paper_size_get_height (paper_size, GTK_UNIT_INCH);
height = height * context->surface_dpi_y / context->pixels_per_unit_y;*/
width = gtk_print_context_get_width(context);
height = gtk_print_context_get_height(context);
switch (gtk_page_setup_get_orientation (page))
{
default:
@ -216,10 +217,10 @@ static int Begin(GB_PAINT *d)
cairo_surface_t *target = NULL;
double w, h;
int rx = 96, ry = 96;
EXTRA(d)->print_context = NULL;
EXTRA(d)->dx = EXTRA(d)->dy = 0;
if (GB.Is(device, CLASS_Picture))
{
gPicture *picture = ((CPICTURE *)device)->picture;
@ -238,9 +239,9 @@ static int Begin(GB_PAINT *d)
cairo_surface_reference(target);
#else
GdkDrawable *pixmap = (GdkDrawable *)picture->getPixmap();
target =
cairo_xlib_surface_create(gdk_x11_drawable_get_xdisplay(pixmap), gdk_x11_drawable_get_xid(pixmap),
target =
cairo_xlib_surface_create(gdk_x11_drawable_get_xdisplay(pixmap), gdk_x11_drawable_get_xid(pixmap),
gdk_x11_visual_get_xvisual(gdk_drawable_get_visual(pixmap)), w, h);
#endif
}
@ -261,7 +262,7 @@ static int Begin(GB_PAINT *d)
{
gDrawingArea *wid = (gDrawingArea *)((CWIDGET *)device)->widget;
double dx = 0, dy = 0;
w = wid->width();
h = wid->height();
@ -277,7 +278,7 @@ static int Begin(GB_PAINT *d)
GB.Error("Cannot paint outside of Draw event handler");
return TRUE;
}
EXTRA(d)->context = ((CDRAWINGAREA *)device)->context;
cairo_reference(CONTEXT(d));
@ -306,7 +307,7 @@ static int Begin(GB_PAINT *d)
GB.Error("Cannot paint outside of Draw event handler");
return TRUE;
}
GtkAllocation *a = &wid->widget->allocation;
dx = a->x;
dy = a->y;
@ -315,7 +316,7 @@ static int Begin(GB_PAINT *d)
rx = gDesktop::resolution(); //device->physicalDpiX();
ry = gDesktop::resolution(); //device->physicalDpiY();
EXTRA(d)->context = gdk_cairo_create(dr);
#endif
@ -329,26 +330,26 @@ static int Begin(GB_PAINT *d)
CPRINTER *printer = (CPRINTER *)device;
GtkPrintContext *context = printer->context;
double pw, ph;
if (!context)
{
GB.Error("Printer is not printing");
return TRUE;
}
EXTRA(d)->print_context = context;
EXTRA(d)->context = gtk_print_context_get_cairo_context(context);
cairo_reference(CONTEXT(d));
cairo_surface_set_fallback_resolution(cairo_get_target(CONTEXT(d)), 1200, 1200);
w = gtk_print_context_get_width(context);
h = gtk_print_context_get_height(context);
rx = (int)gtk_print_context_get_dpi_x(context);
ry = (int)gtk_print_context_get_dpi_y(context);
printer->printer->getPaperSize(&pw, &ph);
d->fontScale = 25.4 * d->area.width / pw / printer->printer->resolution();
}
@ -358,7 +359,7 @@ static int Begin(GB_PAINT *d)
target = SVGIMAGE_begin(svgimage);
if (!target)
return TRUE;
cairo_surface_reference(target);
w = svgimage->width;
h = svgimage->height;
@ -366,7 +367,7 @@ static int Begin(GB_PAINT *d)
}
else
return TRUE;
return init_painting(d, target, w, h, rx, ry);
}
@ -377,7 +378,7 @@ static void End(GB_PAINT *d)
GB_PAINT_EXTRA *dx = EXTRA(d);
if (dx->layout)
g_object_unref(dx->layout);
g_object_unref(dx->layout);
if (dx->font_stack)
{
@ -386,9 +387,9 @@ static void End(GB_PAINT *d)
GB.FreeArray(POINTER(&dx->font_stack));
}
delete dx->font;
if (GB.Is(device, CLASS_Picture))
{
gPicture *picture = ((CPICTURE *)device)->picture;
@ -405,7 +406,7 @@ static void End(GB_PAINT *d)
CSVGIMAGE *svgimage = ((CSVGIMAGE *)device);
SVGIMAGE_end(svgimage);
}
cairo_destroy(dx->context);
}
@ -413,12 +414,12 @@ static void Save(GB_PAINT *d)
{
GB_PAINT_EXTRA *dx = EXTRA(d);
gFont **pfont;
cairo_save(dx->context);
if (!dx->font_stack)
GB.NewArray(POINTER(&dx->font_stack), sizeof(void *), 0);
pfont = (gFont **)GB.Add(POINTER(&dx->font_stack));
*pfont = dx->font->copy();
}
@ -426,9 +427,9 @@ static void Save(GB_PAINT *d)
static void Restore(GB_PAINT *d)
{
GB_PAINT_EXTRA *dx = EXTRA(d);
cairo_restore(dx->context);
if (dx->font_stack && GB.Count(dx->font_stack) > 0)
{
delete dx->font;
@ -450,14 +451,14 @@ static void _Font(GB_PAINT *d, int set, GB_FONT *font);
static void update_layout(GB_PAINT *d)
{
GB_PAINT_EXTRA *dx = EXTRA(d);
if (dx->layout)
{
gt_add_layout_from_font(dx->layout, dx->font, d->resolutionY);
dx->ascent = dx->font->ascentF();
pango_cairo_context_set_font_options(pango_layout_get_context(dx->layout), gdk_screen_get_font_options (gdk_screen_get_default()));
/*cairo_font_options_t *options = cairo_font_options_create(); //cairo_font_options_copy(pango_cairo_context_get_font_options(pango_layout_get_context(dx->layout)));
cairo_font_options_set_antialias(options, CAIRO_ANTIALIAS_GRAY);
cairo_font_options_set_hint_style(options, CAIRO_HINT_STYLE_MEDIUM);
@ -465,7 +466,7 @@ static void update_layout(GB_PAINT *d)
cairo_font_options_set_subpixel_order(options, CAIRO_SUBPIXEL_ORDER_RGB);
pango_cairo_context_set_font_options(pango_layout_get_context(dx->layout), options);
cairo_font_options_destroy(options);*/
pango_layout_context_changed(dx->layout);
}
}
@ -477,7 +478,7 @@ static void apply_font(gFont *font, void *object = 0)
GB_PAINT_EXTRA *dx = EXTRA(d);
font = font->copy();
scale = d->fontScale;
if (dx->print_context)
scale *= ((CPRINTER *)d->device)->printer->resolution() / 96.0;
@ -487,7 +488,7 @@ static void apply_font(gFont *font, void *object = 0)
delete dx->font;
dx->font = font;
update_layout(d);
}
@ -497,11 +498,11 @@ static void _Font(GB_PAINT *d, int set, GB_FONT *font)
GB_PAINT_EXTRA *dx = EXTRA(d);
gFont *f;
double scale;
scale = d->fontScale;
if (dx->print_context)
scale *= ((CPRINTER *)d->device)->printer->resolution() / 96.0;
if (set)
{
delete dx->font;
@ -509,21 +510,21 @@ static void _Font(GB_PAINT *d, int set, GB_FONT *font)
f = ((CFONT *)(*font))->font->copy();
else
f = get_default_font(d);
if (scale != 1)
f->setSize(f->size() * scale);
dx->font = f;
update_layout(d);
}
else
{
f = dx->font->copy();
if (scale != 1)
f->setSize(f->size() / scale);
*font = CFONT_create(f, apply_font);
}
}
@ -582,13 +583,13 @@ static void ClipExtents(GB_PAINT *d, GB_EXTENTS *ext)
{
double x1, y1, x2, y2;
cairo_clip_extents(CONTEXT(d), &x1, &y1, &x2, &y2);
ext->x1 = (float)x1 - DX(d);
ext->y1 = (float)y1 - DY(d);
ext->x2 = (float)x2;
ext->y2 = (float)y2;
}
static void Fill(GB_PAINT *d, int preserve)
{
if (preserve)
@ -604,12 +605,12 @@ static void Stroke(GB_PAINT *d, int preserve)
else
cairo_stroke(CONTEXT(d));
}
static void PathExtents(GB_PAINT *d, GB_EXTENTS *ext)
{
double x1, y1, x2, y2;
cairo_path_extents(CONTEXT(d), &x1, &y1, &x2, &y2);
ext->x1 = (float)x1 - DX(d);
ext->y1 = (float)y1 - DY(d);
ext->x2 = (float)x2;
@ -659,10 +660,10 @@ static void Dash(GB_PAINT *d, int set, float **dashes, int *count)
{
int i;
double lw;
lw = cairo_get_line_width(CONTEXT(d));
if (lw == 0) lw = 1;
if (set)
{
if (!*count)
@ -670,22 +671,22 @@ static void Dash(GB_PAINT *d, int set, float **dashes, int *count)
else
{
double dd[*count];
for (i = 0; i < *count; i++)
dd[i] = (*dashes)[i] * lw;
cairo_set_dash(CONTEXT(d), dd, *count, 0.0);
}
}
else
{
*count = cairo_get_dash_count(CONTEXT(d));
if (*count)
{
double dd[*count];
cairo_get_dash(CONTEXT(d), dd, NULL);
GB.Alloc(POINTER(dashes), sizeof(float) * *count);
for (int i = 0; i < *count; i++)
(*dashes)[i] = (float)dd[i] / lw;
@ -700,7 +701,7 @@ static void Dash(GB_PAINT *d, int set, float **dashes, int *count)
static void DashOffset(GB_PAINT *d, int set, float *offset)
{
double lw;
lw = cairo_get_line_width(CONTEXT(d));
if (lw == 0) lw = 1;
@ -719,19 +720,19 @@ static void DashOffset(GB_PAINT *d, int set, float *offset)
}
}
static void FillRule(GB_PAINT *d, int set, int *value)
{
if (set)
{
cairo_fill_rule_t v;
switch (*value)
{
case GB_PAINT_FILL_RULE_EVEN_ODD: v = CAIRO_FILL_RULE_EVEN_ODD; break;
case GB_PAINT_FILL_RULE_WINDING: default: v = CAIRO_FILL_RULE_WINDING;
}
cairo_set_fill_rule(CONTEXT(d), v);
}
else
@ -761,14 +762,14 @@ static void LineCap(GB_PAINT *d, int set, int *value)
if (set)
{
cairo_line_cap_t v;
switch (*value)
{
case GB_PAINT_LINE_CAP_ROUND: v = CAIRO_LINE_CAP_ROUND; break;
case GB_PAINT_LINE_CAP_SQUARE: v = CAIRO_LINE_CAP_SQUARE; break;
case GB_PAINT_LINE_CAP_BUTT: default: v = CAIRO_LINE_CAP_BUTT;
}
cairo_set_line_cap(CONTEXT(d), v);
}
else
@ -787,14 +788,14 @@ static void LineJoin(GB_PAINT *d, int set, int *value)
if (set)
{
cairo_line_join_t v;
switch (*value)
{
case GB_PAINT_LINE_JOIN_ROUND: v = CAIRO_LINE_JOIN_ROUND; break;
case GB_PAINT_LINE_JOIN_BEVEL: v = CAIRO_LINE_JOIN_BEVEL; break;
case GB_PAINT_LINE_JOIN_MITER: default: v = CAIRO_LINE_JOIN_MITER;
}
cairo_set_line_join(CONTEXT(d), v);
}
else
@ -815,12 +816,12 @@ static void LineWidth(GB_PAINT *d, int set, float *value)
float *dashes;
int count;
float offset;
Dash(d, FALSE, &dashes, &count);
DashOffset(d, FALSE, &offset);
cairo_set_line_width(CONTEXT(d), (double)*value);
Dash(d, TRUE, &dashes, &count);
DashOffset(d, TRUE, &offset);
GB.Free(POINTER(&dashes));
@ -843,7 +844,7 @@ static void Operator(GB_PAINT *d, int set, int *value)
if (set)
{
cairo_operator_t v;
switch (*value)
{
case GB_PAINT_OPERATOR_CLEAR: v = CAIRO_OPERATOR_CLEAR; break;
@ -861,7 +862,7 @@ static void Operator(GB_PAINT *d, int set, int *value)
case GB_PAINT_OPERATOR_SATURATE: v = CAIRO_OPERATOR_SATURATE; break;
case GB_PAINT_OPERATOR_OVER: default: v = CAIRO_OPERATOR_OVER; break;
}
cairo_set_operator(CONTEXT(d), v);
}
else
@ -897,17 +898,17 @@ static void ClosePath(GB_PAINT *d)
cairo_close_path(CONTEXT(d));
}
static void Arc(GB_PAINT *d, float xc, float yc, float radius, float angle, float length, bool pie)
{
xc += DX(d);
yc += DY(d);
cairo_new_sub_path(CONTEXT(d));
if (pie)
cairo_move_to(CONTEXT(d), 0, 0);
if (length < 0.0)
cairo_arc_negative(CONTEXT(d), xc, yc, radius, angle, angle + length);
else
@ -921,9 +922,9 @@ static void Ellipse(GB_PAINT *d, float x, float y, float width, float height, fl
{
x += DX(d);
y += DY(d);
cairo_new_sub_path(CONTEXT(d));
cairo_save(CONTEXT(d));
cairo_translate(CONTEXT(d), x + width / 2, y + height / 2);
@ -931,12 +932,12 @@ static void Ellipse(GB_PAINT *d, float x, float y, float width, float height, fl
if (pie)
cairo_move_to(CONTEXT(d), 0, 0);
if (length < 0.0)
cairo_arc_negative(CONTEXT(d), 0, 0, 1, angle, angle + length);
else
cairo_arc(CONTEXT(d), 0, 0, 1, angle, angle + length);
if (pie)
cairo_close_path(CONTEXT(d));
@ -960,7 +961,7 @@ static void ClipRect(GB_PAINT *d, int x, int y, int w, int h)
static void GetCurrentPoint(GB_PAINT *d, float *x, float *y)
{
double cx, cy;
cairo_get_current_point(CONTEXT(d), &cx, &cy);
*x = (float)cx - DX(d);
*y = (float)cy - DY(d);
@ -984,7 +985,7 @@ static void CurveTo(GB_PAINT *d, float x1, float y1, float x2, float y2, float x
static PangoLayout *create_pango_layout(GB_PAINT *d)
{
GB_PAINT_EXTRA *dx = EXTRA(d);
/*if (dx->print_context)
return gtk_print_context_create_pango_layout(dx->print_context);
else*/
@ -992,10 +993,10 @@ static PangoLayout *create_pango_layout(GB_PAINT *d)
if (!dx->layout)
{
dx->layout = pango_cairo_create_layout(dx->context);
update_layout(d);
}
return dx->layout;
}
@ -1006,7 +1007,7 @@ static void draw_text(GB_PAINT *d, bool rich, const char *text, int len, float w
float tw, th, offx, offy;
layout = create_pango_layout(d);
if (rich)
{
html = gt_html_to_pango_string(text, len, false);
@ -1022,10 +1023,10 @@ static void draw_text(GB_PAINT *d, bool rich, const char *text, int len, float w
pango_layout_set_text(layout, text, len);
pango_layout_set_width(layout, -1);
}
if (align == GB_DRAW_ALIGN_DEFAULT)
align = ALIGN_TOP_NORMAL;
if (w > 0 || h > 0)
{
gt_layout_alignment(layout, w, h, &tw, &th, align, &offx, &offy);
@ -1037,7 +1038,7 @@ static void draw_text(GB_PAINT *d, bool rich, const char *text, int len, float w
offx = 0;
offy = -(EXTRA(d)->ascent);
}
cairo_rel_move_to(CONTEXT(d), offx, offy);
if (draw)
pango_cairo_show_layout(CONTEXT(d), layout);
@ -1065,9 +1066,9 @@ static void get_text_extents(GB_PAINT *d, bool rich, const char *text, int len,
PangoLayout *layout;
PangoRectangle rect;
float x, y;
layout = create_pango_layout(d);
if (rich)
{
html = gt_html_to_pango_string(text, len, false);
@ -1083,14 +1084,14 @@ static void get_text_extents(GB_PAINT *d, bool rich, const char *text, int len,
pango_layout_set_width(layout, width * PANGO_SCALE);
pango_layout_get_extents(layout, &rect, NULL);
GetCurrentPoint(d, &x, &y);
ext->x1 = (float)rect.x / PANGO_SCALE + x;
ext->y1 = (float)rect.y / PANGO_SCALE + y - dx->ascent;
ext->x2 = ext->x1 + (float)rect.width / PANGO_SCALE;
ext->y2 = ext->y1 + (float)rect.height / PANGO_SCALE;
if (html) g_free(html);
}
@ -1108,9 +1109,9 @@ static void TextSize(GB_PAINT *d, const char *text, int len, float *w, float *h)
{
GB_PAINT_EXTRA *dx = EXTRA(d);
float scale;
scale = (float)d->resolutionY / gDesktop::resolution();
dx->font->textSize(text, len, w, h);
if (w) *w *= scale;
@ -1136,7 +1137,7 @@ static void RichTextSize(GB_PAINT *d, const char *text, int len, float sw, float
static void Matrix(GB_PAINT *d, int set, GB_TRANSFORM matrix)
{
cairo_matrix_t *t = (cairo_matrix_t *)matrix;
if (set)
{
if (t)
@ -1157,7 +1158,7 @@ static void Matrix(GB_PAINT *d, int set, GB_TRANSFORM matrix)
cairo_get_matrix(CONTEXT(d), t);
}
static void SetBrush(GB_PAINT *d, GB_BRUSH brush)
{
cairo_set_source(CONTEXT(d), (cairo_pattern_t *)brush);
@ -1169,13 +1170,13 @@ static void BrushOrigin(GB_PAINT *d, int set, float *x, float *y)
{
cairo_pattern_t *brush;
cairo_matrix_t matrix;
brush = cairo_get_source(CONTEXT(d));
cairo_pattern_get_matrix(brush, &matrix);
cairo_matrix_translate(&matrix, EXTRA(d)->bx, EXTRA(d)->by);
cairo_matrix_translate(&matrix, (- *x), (- *y));
cairo_pattern_set_matrix(brush, &matrix);
EXTRA(d)->bx = *x;
EXTRA(d)->by = *y;
}
@ -1206,19 +1207,19 @@ static void BrushImage(GB_BRUSH *brush, GB_IMAGE image)
cairo_pattern_t *pattern;
surface = gt_cairo_create_surface_from_pixbuf(picture->getPixbuf());
pattern = cairo_pattern_create_for_surface(surface);
cairo_surface_destroy(surface);
cairo_pattern_set_extend(pattern, CAIRO_EXTEND_REPEAT);
*brush = (GB_BRUSH)pattern;
}
static void handle_color_stop(cairo_pattern_t *pattern, int nstop, const double *positions, const GB_COLOR *colors)
{
int i, r, g, b, a;
for (i = 0; i < nstop; i++)
{
GB_COLOR_SPLIT(colors[i], r, g, b, a);
@ -1236,26 +1237,26 @@ static void set_pattern_extend(cairo_pattern_t *pattern, int extend)
case GB_PAINT_EXTEND_REFLECT: cext = CAIRO_EXTEND_REFLECT; break;
case GB_PAINT_EXTEND_PAD: default: cext = CAIRO_EXTEND_PAD;
}
cairo_pattern_set_extend(pattern, cext);
}
static void BrushLinearGradient(GB_BRUSH *brush, float x0, float y0, float x1, float y1, int nstop, double *positions, GB_COLOR *colors, int extend)
{
cairo_pattern_t *pattern;
pattern = cairo_pattern_create_linear(x0, y0, x1, y1);
handle_color_stop(pattern, nstop, positions, colors);
set_pattern_extend(pattern, extend);
*brush = (GB_BRUSH)pattern;
}
static void BrushRadialGradient(GB_BRUSH *brush, float cx, float cy, float r, float fx, float fy, int nstop, double *positions, GB_COLOR *colors, int extend)
{
cairo_pattern_t *pattern;
// I know that from librsvg sources
pattern = cairo_pattern_create_radial(fx, fy, 0.0, cx, cy, r);
@ -1272,7 +1273,7 @@ static void BrushMatrix(GB_BRUSH brush, int set, GB_TRANSFORM matrix)
cairo_matrix_t *t = (cairo_matrix_t *)matrix;
cairo_pattern_t *pattern = (cairo_pattern_t *)brush;
cairo_matrix_t actual;
if (set)
{
if (t)
@ -1282,7 +1283,7 @@ static void BrushMatrix(GB_BRUSH brush, int set, GB_TRANSFORM matrix)
}
else
cairo_matrix_init_identity(&actual);
cairo_pattern_set_matrix(pattern, &actual);
}
else
@ -1365,7 +1366,7 @@ static void DrawImage(GB_PAINT *d, GB_IMAGE image, float x, float y, float w, fl
cairo_pattern_t *pattern = NULL;
cairo_pattern_t *save;
cairo_matrix_t matrix;
save = cairo_get_source(cr);
cairo_pattern_reference(save);
cairo_save(cr);
@ -1375,10 +1376,10 @@ static void DrawImage(GB_PAINT *d, GB_IMAGE image, float x, float y, float w, fl
pattern = cairo_pattern_create_for_surface(surface);
cairo_pattern_set_extend(pattern, CAIRO_EXTEND_REPEAT);
if (source && w >= source->w && h >= source->h && w == (int)w && h == (int)h && ((int)w % source->w) == 0 && ((int)h % source->h) == 0)
cairo_pattern_set_filter(pattern, CAIRO_FILTER_NEAREST);
cairo_matrix_init_identity(&matrix);
cairo_matrix_translate(&matrix, x, y);
if (source)
@ -1388,13 +1389,13 @@ static void DrawImage(GB_PAINT *d, GB_IMAGE image, float x, float y, float w, fl
}
else if (w > 0 && h > 0)
cairo_matrix_scale(&matrix, w / cairo_image_surface_get_width(surface), h / cairo_image_surface_get_height(surface));
cairo_matrix_invert(&matrix);
cairo_pattern_set_matrix(pattern, &matrix);
cairo_set_source(cr, pattern);
cairo_rectangle(cr, x, y, w, h);
if (opacity == 1.0)
{
my_cairo_fill(cr);
@ -1404,11 +1405,11 @@ static void DrawImage(GB_PAINT *d, GB_IMAGE image, float x, float y, float w, fl
cairo_clip(cr);
cairo_paint_with_alpha(cr, opacity);
}
cairo_restore(cr);
cairo_set_source(cr, save);
cairo_pattern_destroy(save);
cairo_pattern_destroy(pattern);
}
@ -1466,39 +1467,39 @@ static void DrawPicture(GB_PAINT *d, GB_PICTURE picture, float x, float y, float
cairo_pattern_t *pattern, *save;
cairo_matrix_t matrix;
gPicture *pic = ((CPICTURE *)picture)->picture;
if (pic->type() != gPicture::PIXMAP || source)
{
gt_cairo_draw_pixbuf(CONTEXT(d), pic->getPixbuf(), x, y, w, h, 1.0, source);
return;
}
x += DX(d);
y += DY(d);
cairo_save(CONTEXT(d));
save = cairo_get_source(CONTEXT(d));
cairo_pattern_reference(save);
gdk_cairo_set_source_pixmap(CONTEXT(d), pic->getPixmap(), 0, 0);
pattern = cairo_get_source(CONTEXT(d));
cairo_pattern_set_extend(pattern, CAIRO_EXTEND_REPEAT);
/*if (source && w >= source->w && h >= source->h && w == (int)w && h == (int)h && ((int)w % source->w) == 0 && ((int)h % source->h) == 0)
cairo_pattern_set_filter(pattern, CAIRO_FILTER_NEAREST);*/
//gdk_cairo_set_source_pixbuf(CONTEXT(d), picture->getPixbuf(), x, y);
cairo_matrix_init_identity(&matrix);
cairo_matrix_translate(&matrix, x, y);
cairo_matrix_scale(&matrix, w / pic->width(), h / pic->height());
cairo_matrix_invert(&matrix);
cairo_pattern_set_matrix(pattern, &matrix);
cairo_rectangle(CONTEXT(d), x, y, w, h);
my_cairo_fill(CONTEXT(d));
cairo_set_source(CONTEXT(d), save);
cairo_pattern_destroy(save);
@ -1509,7 +1510,7 @@ static void DrawPicture(GB_PAINT *d, GB_PICTURE picture, float x, float y, float
static void GetPictureInfo(GB_PAINT *d, GB_PICTURE picture, GB_PICTURE_INFO *info)
{
gPicture *pic = ((CPICTURE *)picture)->picture;
info->width = pic->width();
info->height = pic->height();
}
@ -1517,23 +1518,23 @@ static void GetPictureInfo(GB_PAINT *d, GB_PICTURE picture, GB_PICTURE_INFO *inf
static void FillRect(GB_PAINT *d, float x, float y, float w, float h, GB_COLOR color)
{
cairo_pattern_t *save;
x += DX(d);
y += DY(d);
save = cairo_get_source(CONTEXT(d));
cairo_pattern_reference(save);
Background(d, TRUE, &color);
cairo_rectangle(CONTEXT(d), x, y, w, h);
my_cairo_fill(CONTEXT(d));
cairo_set_source(CONTEXT(d), save);
cairo_pattern_destroy(save);
}
GB_PAINT_DESC PAINT_Interface =
GB_PAINT_DESC PAINT_Interface =
{
sizeof(GB_PAINT_EXTRA),
Begin,
@ -1646,7 +1647,7 @@ cairo_t *PAINT_get_current_context()
GB_PAINT *d = (GB_PAINT *)DRAW.Paint.GetCurrent();
if (d)
return CONTEXT(d);
GB.Error("No current device");
return NULL;
}
@ -1656,7 +1657,7 @@ void *PAINT_get_current_device()
GB_PAINT *d = (GB_PAINT *)DRAW.Paint.GetCurrent();
if (d)
return d->device;
GB.Error("No current device");
return NULL;
}
@ -1665,14 +1666,14 @@ bool PAINT_get_clip(int *x, int *y, int *w, int *h)
{
GB_PAINT *d = (GB_PAINT *)DRAW.Paint.GetCurrent();
GB_EXTENTS ext;
ClipExtents(d, &ext);
*x = ceilf(ext.x1);
*y = ceilf(ext.y1);
*w = floorf(ext.x2) - *x;
*h = floorf(ext.y2) - *y;
return *w <= 0 || *h <= 0;
}

View file

@ -53,7 +53,7 @@ static gboolean cb_frame(GtkWidget *widget,GdkEventWindowState *event,gMainWindo
CHECK_STATE(_maximized, GDK_WINDOW_STATE_MAXIMIZED);
CHECK_STATE(sticky, GDK_WINDOW_STATE_STICKY);
CHECK_STATE(_fullscreen, GDK_WINDOW_STATE_FULLSCREEN);
if (event->changed_mask & GDK_WINDOW_STATE_ABOVE)
{
if (event->new_window_state & GDK_WINDOW_STATE_ABOVE)
@ -70,10 +70,10 @@ static gboolean cb_frame(GtkWidget *widget,GdkEventWindowState *event,gMainWindo
}
data->performArrange();
if (event->changed_mask & (GDK_WINDOW_STATE_ICONIFIED | GDK_WINDOW_STATE_MAXIMIZED | GDK_WINDOW_STATE_FULLSCREEN | GDK_WINDOW_STATE_STICKY | GDK_WINDOW_STATE_ABOVE | GDK_WINDOW_STATE_BELOW))
data->emit(SIGNAL(data->onState));
return false;
}
@ -84,9 +84,9 @@ static gboolean cb_show(GtkWidget *widget, gMainWindow *data)
data->_grab_on_show = FALSE;
gApplication::grabPopup();
}
data->emitOpen();
if (data->opened)
{
data->setGeometryHints();
@ -112,7 +112,7 @@ static gboolean cb_hide(GtkWidget *widget, gMainWindow *data)
data->emit(SIGNAL(data->onHide));
data->_not_spontaneous = false;
}
return false;
//if (data == gDesktop::activeWindow())
// gMainWindow::setActiveWindow(NULL);
@ -129,14 +129,14 @@ static gboolean cb_close(GtkWidget *widget,GdkEvent *event, gMainWindow *data)
{
if (!gMainWindow::_current || data == gMainWindow::_current)
data->doClose();
return true;
}
static gboolean cb_configure(GtkWidget *widget, GdkEventConfigure *event, gMainWindow *data)
{
gint x, y;
if (data->opened)
{
if (data->isTopLevel())
@ -148,16 +148,16 @@ static gboolean cb_configure(GtkWidget *widget, GdkEventConfigure *event, gMainW
x = event->x;
y = event->y;
}
//fprintf(stderr, "cb_configure: %s: (%d %d %d %d) -> (%d %d %d %d) window = %p resized = %d send_event = %d\n", data->name(), data->bufX, data->bufY, data->bufW, data->bufH, x, y, event->width, event->height, event->window, data->_resized, event->send_event);
if (x != data->bufX || y != data->bufY)
{
data->bufX = x;
data->bufY = y;
if (data->onMove) data->onMove(data);
}
if ((event->width != data->bufW) || (event->height != data->bufH) || (data->_resized) || !event->window)
{
//BREAKPOINT();
@ -167,7 +167,7 @@ static gboolean cb_configure(GtkWidget *widget, GdkEventConfigure *event, gMainW
data->emitResize();
}
}
return false;
}
@ -301,14 +301,14 @@ void gMainWindow::initialize()
onDeactivate = NULL;
onState = NULL;
onFontChange = NULL;
accel = gtk_accel_group_new();
}
void gMainWindow::initWindow()
{
//resize(200,150);
if (!isTopLevel())
{
g_signal_connect(G_OBJECT(border), "configure-event", G_CALLBACK(cb_configure), (gpointer)this);
@ -328,13 +328,13 @@ void gMainWindow::initWindow()
g_signal_connect(G_OBJECT(border), "configure-event", G_CALLBACK(cb_configure),(gpointer)this);
g_signal_connect(G_OBJECT(border), "delete-event", G_CALLBACK(cb_close),(gpointer)this);
g_signal_connect(G_OBJECT(border), "window-state-event", G_CALLBACK(cb_frame),(gpointer)this);
gtk_widget_add_events(widget,GDK_BUTTON_MOTION_MASK | GDK_STRUCTURE_MASK);
ON_DRAW_BEFORE(border, this, cb_expose, cb_draw);
}
gtk_window_add_accel_group(GTK_WINDOW(topLevel()->border), accel);
have_cursor = true; //parent() == 0 && !_xembed;
}
@ -361,17 +361,17 @@ gMainWindow::gMainWindow(int plug) : gContainer(NULL)
{
initialize();
g_typ = Type_gMainWindow;
windows = g_list_append(windows, (gpointer)this);
_xembed = plug != 0;
if (_xembed)
border = gtk_plug_new(plug);
else
border = gtk_window_new(GTK_WINDOW_TOPLEVEL);
widget = gtk_fixed_new(); //gtk_layout_new(0,0);
#if 0 //def GTK3
@ -395,10 +395,10 @@ gMainWindow::gMainWindow(int plug) : gContainer(NULL)
patch = true;
}
#endif
realize(false);
initWindow();
gtk_widget_realize(border);
gtk_widget_show(widget);
gtk_widget_set_size_request(border, 1, 1);
@ -410,7 +410,7 @@ gMainWindow::gMainWindow(gContainer *par) : gContainer(par)
{
initialize();
g_typ = Type_gMainWindow;
#ifdef GTK3
//border = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
border = gtk_fixed_new();
@ -418,7 +418,7 @@ gMainWindow::gMainWindow(gContainer *par) : gContainer(par)
border = gtk_alignment_new(0, 0, 1, 1);
#endif
widget = gtk_fixed_new();
realize(false);
initWindow();
@ -438,19 +438,19 @@ gMainWindow::~gMainWindow()
if (GTK_IS_WINDOW(border) && isModal())
gApplication::exitLoop(this);
}
gPicture::assign(&_picture);
gPicture::assign(&_icon);
if (_title) g_free(_title);
g_object_unref(accel);
if (_style) g_object_unref(_style);
if (_active == this)
_active = NULL;
if (gApplication::mainWindow() == this)
gApplication::setMainWindow(NULL);
windows = g_list_remove(windows, (gpointer)this);
}
@ -513,15 +513,15 @@ void gMainWindow::setRealForeground(gColor color)
void gMainWindow::move(int x, int y)
{
//gint ox, oy;
if (isTopLevel())
{
if (!_moved && (x || y))
_moved = true;
if (x == bufX && y == bufY)
if (x == bufX && y == bufY)
return;
/*#ifdef GDK_WINDOWING_X11
gdk_window_get_origin(gtk_widget_get_window(border), &ox, &oy);
ox = x + ox - bufX;
@ -537,7 +537,7 @@ void gMainWindow::move(int x, int y)
bufX = x;
bufY = y;
//#endif
gtk_window_move(GTK_WINDOW(border), x, y);
}
else
@ -551,21 +551,21 @@ void gMainWindow::resize(int w, int h)
{
if (w == bufW && h == bufH)
return;
_resized = true;
if (isTopLevel())
{
//fprintf(stderr, "gMainWindow::resize: %d %d %s\n", w, h, name());
//gdk_window_enable_synchronized_configure (border->window);
bufW = w < 0 ? 0 : w;
bufH = h < 0 ? 0 : h;
if (w < 1 || h < 1)
{
if (visible)
gtk_widget_hide(border);
gtk_widget_hide(border);
}
else
{
@ -598,12 +598,12 @@ void gMainWindow::moveResize(int x, int y, int w, int h)
void gMainWindow::emitOpen()
{
//fprintf(stderr, "emit Open: %p (%d %d) %d resizable = %d fullscreen = %d\n", this, width(), height(), opened, isResizable(), fullscreen());
if (!opened)
{
opened = true;
//_no_resize_event = true; // If the event loop is run during emitOpen(), some spurious configure events are received.
if (!_min_w && !_min_h)
{
_min_w = width();
@ -612,17 +612,17 @@ void gMainWindow::emitOpen()
gtk_widget_realize(border);
performArrange();
emit(SIGNAL(onOpen));
if (opened)
{
//fprintf(stderr, "emit Move & Resize: %p\n", this);
//fprintf(stderr, "emit Move & Resize: %p\n", this);
emit(SIGNAL(onMove));
emitResize();
}
}
//_no_resize_event = false;
}
@ -654,15 +654,15 @@ void gMainWindow::setVisible(bool vl)
if (vl)
{
bool arr = !isVisible();
emitOpen();
if (!opened)
return;
_not_spontaneous = !visible;
visible = true;
_hidden = false;
setTransparent(_transparent); // must not call gtk_window_present!
if (isTopLevel())
@ -673,7 +673,7 @@ void gMainWindow::setVisible(bool vl)
gtk_window_group_add_window(gApplication::currentGroup(), GTK_WINDOW(border));
fprintf(stderr, "-> %p\n", gtk_window_get_group(GTK_WINDOW(border)));
}*/
// Thanks for Ubuntu's GTK+ patching :-(
#ifndef GTK3
//gtk_window_set_has_resize_grip(GTK_WINDOW(border), false);
@ -682,30 +682,30 @@ void gMainWindow::setVisible(bool vl)
#endif
gtk_window_move(GTK_WINDOW(border), bufX, bufY);
if (isPopup())
/*if (isPopup())
{
gtk_widget_show_now(border);
gtk_widget_grab_focus(border);
}
else
{
{*/
present();
}
//}
if (!_title || !*_title)
gtk_window_set_title(GTK_WINDOW(border), gApplication::defaultTitle());
if (isUtility())
{
gMainWindow *parent = _current;
if (!parent && gApplication::mainWindow() && gApplication::mainWindow() != this)
parent = gApplication::mainWindow();
if (parent)
gtk_window_set_transient_for(GTK_WINDOW(border), GTK_WINDOW(parent->border));
if (!_no_take_focus)
present();
}
@ -721,21 +721,21 @@ void gMainWindow::setVisible(bool vl)
}
}
}
else
else
{
gtk_widget_show(border);
parent()->performArrange();
}
drawMask();
if (focus)
{
//fprintf(stderr, "focus = %s\n", focus->name());
focus->setFocus();
focus = 0;
}
if (skipTaskBar())
_activate = true;
@ -746,10 +746,10 @@ void gMainWindow::setVisible(bool vl)
{
if (this == _active)
focus = gApplication::activeControl();
_not_spontaneous = visible;
gContainer::setVisible(false);
if (_popup)
gApplication::exitLoop(this);
@ -762,7 +762,7 @@ void gMainWindow::setVisible(bool vl)
void gMainWindow::setMinimized(bool vl)
{
if (!isTopLevel()) return;
_minimized = vl;
if (vl) gtk_window_iconify(GTK_WINDOW(border));
else gtk_window_deiconify(GTK_WINDOW(border));
@ -774,7 +774,7 @@ void gMainWindow::setMaximized(bool vl)
return;
_maximized = vl;
if (vl)
gtk_window_maximize(GTK_WINDOW(border));
else
@ -785,9 +785,9 @@ void gMainWindow::setFullscreen(bool vl)
{
if (!isTopLevel())
return;
_fullscreen = vl;
if (vl)
{
gtk_window_fullscreen(GTK_WINDOW(border));
@ -802,14 +802,14 @@ void gMainWindow::center()
{
GdkRectangle rect;
int x, y;
if (!isTopLevel()) return;
gDesktop::availableGeometry(screen(), &rect);
x = rect.x + (rect.width - width()) / 2;
y = rect.y + (rect.height - height()) / 2;
move(x, y);
}
@ -824,17 +824,17 @@ void gMainWindow::showModal()
{
gMainWindow *save;
gMainWindow *parent;
if (!isTopLevel()) return;
if (isModal()) return;
//show();
gtk_window_set_modal(GTK_WINDOW(border), true);
center();
//show();
gtk_grab_add(border);
parent = _current;
if (!parent)
{
@ -842,17 +842,17 @@ void gMainWindow::showModal()
if (!parent)
parent = _active;
}
if (parent)
gtk_window_set_transient_for(GTK_WINDOW(border), GTK_WINDOW(parent->topLevel()->border));
save = _current;
_current = this;
gApplication::enterLoop(this, true);
_current = save;
gtk_grab_remove(border);
gtk_window_set_modal(GTK_WINDOW(border), false);
@ -868,40 +868,40 @@ void gMainWindow::showPopup(int x, int y)
bool has_border;
int oldx, oldy;
//int type;
if (!isTopLevel()) return;
if (isModal()) return;
//gtk_widget_unrealize(border);
//((GtkWindow *)border)->type = GTK_WINDOW_POPUP;
//gtk_widget_realize(border);
oldx = left();
oldy = top();
has_border = gtk_window_get_decorated(GTK_WINDOW(border));
//type = getType();
//setType(_NET_WM_WINDOW_TYPE_COMBO);
gtk_window_set_decorated(GTK_WINDOW(border), false);
//gtk_window_set_type_hint(GTK_WINDOW(border), GDK_WINDOW_TYPE_HINT_POPUP_MENU);
gtk_window_set_type_hint(GTK_WINDOW(border), GDK_WINDOW_TYPE_HINT_COMBO);
move(x, y);
gtk_window_resize(GTK_WINDOW(border), bufW, bufH);
raise();
setFocus();
//reparent(NULL, x, y, GTK_WINDOW_POPUP);
_popup = true;
save = _current;
_current = this;
gApplication::enterPopup(this);
_current = save;
_popup = false;
if (!persistent)
{
destroyNow();
@ -909,12 +909,12 @@ void gMainWindow::showPopup(int x, int y)
else
{
hide();
//gdk_window_set_override_redirect(gtk_widget_get_window(GTK_WINDOW(border)), false);
gtk_window_set_decorated(GTK_WINDOW(border), has_border);
//setType(type);
//gtk_window_set_type_hint(GTK_WINDOW(border), type);
move(oldx, oldy);
}
}
@ -956,7 +956,7 @@ const char* gMainWindow::text()
bool gMainWindow::skipTaskBar()
{
if (!isTopLevel())
if (!isTopLevel())
return false;
else
return _skip_taskbar;
@ -967,7 +967,7 @@ void gMainWindow::setText(const char *txt)
{
if (_title) g_free(_title);
_title = g_strdup(txt);
if (isTopLevel())
gtk_window_set_title(GTK_WINDOW(border), txt);
}
@ -990,9 +990,9 @@ bool gMainWindow::isResizable()
void gMainWindow::setBorder(bool b)
{
if (!isTopLevel())
if (!isTopLevel())
return;
gtk_window_set_decorated(GTK_WINDOW(border), b);
/*#ifdef GDK_WINDOWING_X11
XSetWindowAttributes attr;
@ -1003,9 +1003,9 @@ void gMainWindow::setBorder(bool b)
void gMainWindow::setResizable(bool b)
{
if (!isTopLevel())
if (!isTopLevel())
return;
if (b == isResizable())
return;
@ -1026,14 +1026,14 @@ void gMainWindow::setSkipTaskBar(bool b)
{
GdkPixbuf *buf;
gPicture *pic;
if (!isTopLevel()) return NULL;
buf=gtk_window_get_icon(GTK_WINDOW(border));
if (!buf) return NULL;
pic=gPicture::fromPixbuf(buf);
return pic;
}*/
@ -1048,7 +1048,7 @@ void gMainWindow::setIcon(gPicture *pic)
bool gMainWindow::topOnly()
{
if (!isTopLevel()) return false;
return top_only;
}
@ -1065,7 +1065,7 @@ void gMainWindow::setMask(bool vl)
{
if (_mask == vl)
return;
_mask = vl;
drawMask();
}
@ -1083,7 +1083,7 @@ void gMainWindow::remap()
gtk_widget_unmap(border);
gtk_widget_map(border);
if (_skip_taskbar) { setSkipTaskBar(false); setSkipTaskBar(true); }
if (top_only) { setTopOnly(false); setTopOnly(true); }
if (sticky) { setSticky(false); setSticky(true); }
@ -1094,10 +1094,10 @@ void gMainWindow::remap()
void gMainWindow::drawMask()
{
bool do_remap = false;
if (!isVisible())
return;
#ifdef GTK3
cairo_region_t *mask;
@ -1135,9 +1135,9 @@ void gMainWindow::drawMask()
gtk_widget_set_app_paintable(border, FALSE);
setRealBackground(background());
}
_masked = mask != NULL;
if (do_remap)
remap();
else
@ -1165,14 +1165,14 @@ bool gMainWindow::doClose()
{
if (_closing)
return false;
if (opened)
{
if (isModal() && !gApplication::hasLoop(this))
return true;
_closing = true;
if (onClose)
if (onClose)
{
if (!onClose(this))
opened = false;
@ -1180,16 +1180,16 @@ bool gMainWindow::doClose()
else
opened = false;
_closing = false;
if (!opened && isModal())
gApplication::exitLoop(this);
}
if (!opened) // && !modal())
{
if (_active == this)
setActiveWindow(NULL);
if (!isModal())
{
if (persistent)
@ -1213,7 +1213,7 @@ static void hide_hidden_children(gContainer *cont)
{
int i;
gControl *child;
for (i = 0;; i++)
{
child = cont->child(i);
@ -1231,24 +1231,24 @@ void gMainWindow::reparent(gContainer *newpr, int x, int y)
GtkWidget *new_border;
int w, h;
gColor fg, bg;
if (_xembed)
return;
bg = background();
fg = foreground();
if (isTopLevel() && newpr)
{
gtk_window_remove_accel_group(GTK_WINDOW(topLevel()->border), accel);
new_border = gtk_event_box_new();
gt_widget_reparent(widget, new_border);
embedMenuBar(new_border);
_no_delete = true;
gtk_widget_destroy(border);
_no_delete = false;
border = new_border;
registerControl();
setCanFocus(false);
@ -1256,19 +1256,19 @@ void gMainWindow::reparent(gContainer *newpr, int x, int y)
setParent(newpr);
connectParent();
borderSignals();
initWindow();
initWindow();
setBackground(bg);
setForeground(fg);
setFont(font());
checkMenuBar();
bufX = bufY = 0;
move(x, y);
gtk_widget_set_size_request(border, width(), height());
// Hidden children are incorrectly shown. Fix that!
hideHiddenChildren();
}
@ -1295,25 +1295,25 @@ void gMainWindow::reparent(gContainer *newpr, int x, int y)
parent()->arrange();
setParent(NULL);
}
initWindow();
initWindow();
borderSignals();
setBackground(bg);
setForeground(fg);
setFont(font());
move(x, y);
w = width();
h = height();
bufW = bufH = -1;
gtk_widget_set_size_request(border, 1, 1);
resize(w, h);
hideHiddenChildren();
_popup = false; //type == GTK_WINDOW_POPUP;
}
else
{
gContainer::reparent(newpr, x, y);
gContainer::reparent(newpr, x, y);
}
}
@ -1323,7 +1323,7 @@ int gMainWindow::controlCount()
GList *list = gControl::controlList();
gControl *ctrl;
int n = 0;
while (list)
{
ctrl = (gControl *)list->data;
@ -1331,7 +1331,7 @@ int gMainWindow::controlCount()
n++;
list = g_list_next(list);
}
return n;
}
@ -1339,7 +1339,7 @@ gControl *gMainWindow::getControl(char *name)
{
GList *list = gControl::controlList();
gControl *ctrl;
while (list)
{
ctrl = (gControl *)list->data;
@ -1347,7 +1347,7 @@ gControl *gMainWindow::getControl(char *name)
return ctrl;
list = g_list_next(list);
}
return NULL;
}
@ -1356,7 +1356,7 @@ gControl *gMainWindow::getControl(int index)
GList *list = gControl::controlList();
gControl *ctrl;
int i = 0;
while (list)
{
ctrl = (gControl *)list->data;
@ -1368,7 +1368,7 @@ gControl *gMainWindow::getControl(int index)
}
list = g_list_next(list);
}
return NULL;
}
@ -1420,7 +1420,7 @@ int gMainWindow::menuBarHeight()
#endif
//fprintf(stderr, "menuBarHeight: %d\n", h);
}
return h;
}
@ -1436,17 +1436,17 @@ void gMainWindow::setActiveWindow(gControl *control)
{
gMainWindow *window = control ? control->window() : NULL;
gMainWindow *old = _active;
if (window == _active)
return;
_active = window;
//fprintf(stderr, "setActiveWindow: %p %s\n", _active, _active ? _active->name() : "");
if (old)
old->emit(SIGNAL(old->onDeactivate));
if (window)
window->emit(SIGNAL(window->onActivate));
}
@ -1463,7 +1463,7 @@ void gMainWindow::setUtility(bool v)
if (!isTopLevel())
return;
// TODO: works only if the window is not mapped!
_utility = v;
@ -1500,14 +1500,14 @@ void gMainWindow::configure()
static GB_FUNCTION _init_menubar_shortcut_func;
int h;
if (bufW < 1 || bufH < 1)
return;
if (_initMenuBar != isMenuBarVisible())
{
_initMenuBar = !_initMenuBar;
if (!init)
{
GB.GetFunction(&_init_menubar_shortcut_func, (void *)GB.FindClass("_Gui"), "_InitMenuBarShortcut", NULL, NULL);
@ -1519,9 +1519,9 @@ void gMainWindow::configure()
}
h = menuBarHeight();
//fprintf(stderr, "configure: %s: %d %d - %d %d\n", name(), isMenuBarVisible(), h, width(), height());
if (isMenuBarVisible())
{
gtk_fixed_move(layout, GTK_WIDGET(menuBar), 0, 0);
@ -1546,15 +1546,15 @@ bool gMainWindow::setMenuBarVisible(bool v)
{
if (_showMenuBar == v)
return TRUE;
_showMenuBar = v;
if (!menuBar)
return TRUE;
configure();
performArrange();
return FALSE;
}
@ -1577,7 +1577,7 @@ void gMainWindow::checkMenuBar()
gMenu *menu;
//fprintf(stderr, "gMainWindow::checkMenuBar\n");
if (menuBar)
{
_hideMenuBar = true;
@ -1593,7 +1593,7 @@ void gMainWindow::checkMenuBar()
}
}
}
configure();
performArrange();
}
@ -1606,24 +1606,24 @@ void gMainWindow::embedMenuBar(GtkWidget *border)
layout = GTK_FIXED(gtk_fixed_new());
g_object_ref(G_OBJECT(menuBar));
if (gtk_widget_get_parent(GTK_WIDGET(menuBar)))
gtk_container_remove(GTK_CONTAINER(gtk_widget_get_parent(GTK_WIDGET(menuBar))), GTK_WIDGET(menuBar));
gtk_fixed_put(layout, GTK_WIDGET(menuBar), 0, 0);
g_object_unref(G_OBJECT(menuBar));
gt_widget_reparent(widget, GTK_WIDGET(layout));
gtk_container_add(GTK_CONTAINER(border), GTK_WIDGET(layout));
gtk_widget_show(GTK_WIDGET(menuBar));
gtk_widget_show(GTK_WIDGET(layout));
gtk_widget_show(GTK_WIDGET(widget));
gMenu::updateFont(this);
gMenu::updateColor(this);
checkMenuBar();
}
}
@ -1665,7 +1665,7 @@ void gMainWindow::emitResize()
{
if (bufW == _resize_last_w && bufH == _resize_last_h)
return;
_resize_last_w = bufW;
_resize_last_h = bufH;
configure();