Commit fe60d43a authored by Hans Breuer's avatar Hans Breuer Committed by Hans Breuer
Browse files

Fixed dashed line issues (#74441) to an IMO reasonable extend. That is:

2002-03-29  Hans Breuer  <hans@breuer.org>

	Fixed dashed line issues (#74441) to an IMO reasonable extend.
	That is: use PS_USERSTYLE on WinNT (the next GDI limit appears
	to be with lines width > 50); Render horizontal and vertical
	dashed lines on Win9x 'by hand'. Dotted selection rectangles
	and Dia look nice ...

	* gdk/win32/gdkprivate-win32.h : add pen_dashes pointer and
	num_pen_dashes to _GdkGCWin32
	* gdk/win32/gdkgc-win32.c : initialize pen_dashes and remove
	the guesses from dashes to windoze line styles.
	(predraw_set_forground) : always ExtCreatePen (PS_SOLID) on
	Win9x, which does not support PS_USERSTYLE.
	* gdk/win32/gdkdrawable-win32.c : new functions render_line_
	<horizontal|vertical>. Use them if not running on NT in
	gdk_win32_draw_<rectangle|segments|lines> ()

	* gdk/win32/gdkkeys-win32.c (gdk_keyval_name) : return NULL
	for keyval == 0 to avoid to have zeros in all menu entries
	without accelerator.
parent df10ebad
2002-03-29 Hans Breuer <hans@breuer.org>
Fixed dashed line issues (#74441) to an IMO reasonable extend.
That is: use PS_USERSTYLE on WinNT (the next GDI limit appears
to be with lines width > 50); Render horizontal and vertical
dashed lines on Win9x 'by hand'. Dotted selection rectangles
and Dia look nice ...
* gdk/win32/gdkprivate-win32.h : add pen_dashes pointer and
num_pen_dashes to _GdkGCWin32
* gdk/win32/gdkgc-win32.c : initialize pen_dashes and remove
the guesses from dashes to windoze line styles.
(predraw_set_forground) : always ExtCreatePen (PS_SOLID) on
Win9x, which does not support PS_USERSTYLE.
* gdk/win32/gdkdrawable-win32.c : new functions render_line_
<horizontal|vertical>. Use them if not running on NT in
gdk_win32_draw_<rectangle|segments|lines> ()
* gdk/win32/gdkkeys-win32.c (gdk_keyval_name) : return NULL
for keyval == 0 to avoid to have zeros in all menu entries
without accelerator.
2002-03-29 Jakub Steiner <jimmac@ximian.com>
* gtk/stock-icons/stock_add_24.png:
......
2002-03-29 Hans Breuer <hans@breuer.org>
Fixed dashed line issues (#74441) to an IMO reasonable extend.
That is: use PS_USERSTYLE on WinNT (the next GDI limit appears
to be with lines width > 50); Render horizontal and vertical
dashed lines on Win9x 'by hand'. Dotted selection rectangles
and Dia look nice ...
* gdk/win32/gdkprivate-win32.h : add pen_dashes pointer and
num_pen_dashes to _GdkGCWin32
* gdk/win32/gdkgc-win32.c : initialize pen_dashes and remove
the guesses from dashes to windoze line styles.
(predraw_set_forground) : always ExtCreatePen (PS_SOLID) on
Win9x, which does not support PS_USERSTYLE.
* gdk/win32/gdkdrawable-win32.c : new functions render_line_
<horizontal|vertical>. Use them if not running on NT in
gdk_win32_draw_<rectangle|segments|lines> ()
* gdk/win32/gdkkeys-win32.c (gdk_keyval_name) : return NULL
for keyval == 0 to avoid to have zeros in all menu entries
without accelerator.
2002-03-29 Jakub Steiner <jimmac@ximian.com>
* gtk/stock-icons/stock_add_24.png:
......
2002-03-29 Hans Breuer <hans@breuer.org>
Fixed dashed line issues (#74441) to an IMO reasonable extend.
That is: use PS_USERSTYLE on WinNT (the next GDI limit appears
to be with lines width > 50); Render horizontal and vertical
dashed lines on Win9x 'by hand'. Dotted selection rectangles
and Dia look nice ...
* gdk/win32/gdkprivate-win32.h : add pen_dashes pointer and
num_pen_dashes to _GdkGCWin32
* gdk/win32/gdkgc-win32.c : initialize pen_dashes and remove
the guesses from dashes to windoze line styles.
(predraw_set_forground) : always ExtCreatePen (PS_SOLID) on
Win9x, which does not support PS_USERSTYLE.
* gdk/win32/gdkdrawable-win32.c : new functions render_line_
<horizontal|vertical>. Use them if not running on NT in
gdk_win32_draw_<rectangle|segments|lines> ()
* gdk/win32/gdkkeys-win32.c (gdk_keyval_name) : return NULL
for keyval == 0 to avoid to have zeros in all menu entries
without accelerator.
2002-03-29 Jakub Steiner <jimmac@ximian.com>
* gtk/stock-icons/stock_add_24.png:
......
2002-03-29 Hans Breuer <hans@breuer.org>
Fixed dashed line issues (#74441) to an IMO reasonable extend.
That is: use PS_USERSTYLE on WinNT (the next GDI limit appears
to be with lines width > 50); Render horizontal and vertical
dashed lines on Win9x 'by hand'. Dotted selection rectangles
and Dia look nice ...
* gdk/win32/gdkprivate-win32.h : add pen_dashes pointer and
num_pen_dashes to _GdkGCWin32
* gdk/win32/gdkgc-win32.c : initialize pen_dashes and remove
the guesses from dashes to windoze line styles.
(predraw_set_forground) : always ExtCreatePen (PS_SOLID) on
Win9x, which does not support PS_USERSTYLE.
* gdk/win32/gdkdrawable-win32.c : new functions render_line_
<horizontal|vertical>. Use them if not running on NT in
gdk_win32_draw_<rectangle|segments|lines> ()
* gdk/win32/gdkkeys-win32.c (gdk_keyval_name) : return NULL
for keyval == 0 to avoid to have zeros in all menu entries
without accelerator.
2002-03-29 Jakub Steiner <jimmac@ximian.com>
* gtk/stock-icons/stock_add_24.png:
......
2002-03-29 Hans Breuer <hans@breuer.org>
Fixed dashed line issues (#74441) to an IMO reasonable extend.
That is: use PS_USERSTYLE on WinNT (the next GDI limit appears
to be with lines width > 50); Render horizontal and vertical
dashed lines on Win9x 'by hand'. Dotted selection rectangles
and Dia look nice ...
* gdk/win32/gdkprivate-win32.h : add pen_dashes pointer and
num_pen_dashes to _GdkGCWin32
* gdk/win32/gdkgc-win32.c : initialize pen_dashes and remove
the guesses from dashes to windoze line styles.
(predraw_set_forground) : always ExtCreatePen (PS_SOLID) on
Win9x, which does not support PS_USERSTYLE.
* gdk/win32/gdkdrawable-win32.c : new functions render_line_
<horizontal|vertical>. Use them if not running on NT in
gdk_win32_draw_<rectangle|segments|lines> ()
* gdk/win32/gdkkeys-win32.c (gdk_keyval_name) : return NULL
for keyval == 0 to avoid to have zeros in all menu entries
without accelerator.
2002-03-29 Jakub Steiner <jimmac@ximian.com>
* gtk/stock-icons/stock_add_24.png:
......
2002-03-29 Hans Breuer <hans@breuer.org>
Fixed dashed line issues (#74441) to an IMO reasonable extend.
That is: use PS_USERSTYLE on WinNT (the next GDI limit appears
to be with lines width > 50); Render horizontal and vertical
dashed lines on Win9x 'by hand'. Dotted selection rectangles
and Dia look nice ...
* gdk/win32/gdkprivate-win32.h : add pen_dashes pointer and
num_pen_dashes to _GdkGCWin32
* gdk/win32/gdkgc-win32.c : initialize pen_dashes and remove
the guesses from dashes to windoze line styles.
(predraw_set_forground) : always ExtCreatePen (PS_SOLID) on
Win9x, which does not support PS_USERSTYLE.
* gdk/win32/gdkdrawable-win32.c : new functions render_line_
<horizontal|vertical>. Use them if not running on NT in
gdk_win32_draw_<rectangle|segments|lines> ()
* gdk/win32/gdkkeys-win32.c (gdk_keyval_name) : return NULL
for keyval == 0 to avoid to have zeros in all menu entries
without accelerator.
2002-03-29 Jakub Steiner <jimmac@ximian.com>
* gtk/stock-icons/stock_add_24.png:
......
......@@ -250,6 +250,69 @@ gdk_win32_set_colormap (GdkDrawable *drawable,
/* Drawing
*/
/*
* Render a dashed line 'by hand' cause the Win9x GDI is
* too limited to do so
*/
static inline gboolean
render_line_horizontal (HDC hdc,
int x1,
int x2,
int y,
int pen_width,
int *dashes,
int num_dashes)
{
int n;
for (n = 0; x1 < x2; n++)
{
int len = dashes[n % num_dashes];
if (x1 + len > x2)
len = x2 - x1;
if (n % 2 == 0)
if (!PatBlt (hdc,
x1, y - pen_width / 2,
len, pen_width,
PATCOPY))
{
WIN32_GDI_FAILED ("PatBlt");
return FALSE;
}
x1 += dashes[n % num_dashes];
}
}
static inline gboolean
render_line_vertical (HDC hdc,
int x,
int y1,
int y2,
int pen_width,
int *dashes,
int num_dashes)
{
int n;
for (n = 0; y1 < y2; n++)
{
int len = dashes[n % num_dashes];
if (y1 + len > y2)
len = y2 - y1;
if (n % 2 == 0)
if (!PatBlt (hdc,
x - pen_width / 2, y1,
pen_width, len,
PATCOPY))
{
WIN32_GDI_FAILED ("PatBlt");
return FALSE;
}
y1 += dashes[n % num_dashes];
}
}
static void
gdk_win32_draw_rectangle (GdkDrawable *drawable,
GdkGC *gc,
......@@ -341,16 +404,38 @@ gdk_win32_draw_rectangle (GdkDrawable *drawable,
}
else
{
if (filled)
old_pen_or_brush = SelectObject (hdc, GetStockObject (NULL_PEN));
else
old_pen_or_brush = SelectObject (hdc, GetStockObject (HOLLOW_BRUSH));
if (old_pen_or_brush == NULL)
WIN32_GDI_FAILED ("SelectObject");
else if (!Rectangle (hdc, x, y, x+width+1, y+height+1))
WIN32_GDI_FAILED ("Rectangle");
if (!filled && gc_private->pen_dashes && !IS_WIN_NT ())
{
ok = ok && render_line_vertical (hdc, x, y, y+height+1,
gc_private->pen_width,
gc_private->pen_dashes,
gc_private->pen_num_dashes);
ok = ok && render_line_horizontal (hdc, x, x+width+1, y,
gc_private->pen_width,
gc_private->pen_dashes,
gc_private->pen_num_dashes);
ok = ok && render_line_vertical (hdc, x+width+1, y, y+height+1,
gc_private->pen_width,
gc_private->pen_dashes,
gc_private->pen_num_dashes);
ok = ok && render_line_horizontal (hdc, x, x+width+1, y+height+1,
gc_private->pen_width,
gc_private->pen_dashes,
gc_private->pen_num_dashes);
}
else
SelectObject (hdc, old_pen_or_brush);
{
if (filled)
old_pen_or_brush = SelectObject (hdc, GetStockObject (NULL_PEN));
else
old_pen_or_brush = SelectObject (hdc, GetStockObject (HOLLOW_BRUSH));
if (old_pen_or_brush == NULL)
WIN32_GDI_FAILED ("SelectObject");
if (!Rectangle (hdc, x, y, x+width+1, y+height+1))
WIN32_GDI_FAILED ("Rectangle");
if (old_pen_or_brush)
SelectObject (hdc, old_pen_or_brush);
}
}
gdk_win32_hdc_release (drawable, gc, mask);
......@@ -771,57 +856,112 @@ gdk_win32_draw_segments (GdkDrawable *drawable,
}
else
{
const gboolean maybe_patblt =
gc_private->rop2 == R2_COPYPEN &&
gc_private->pen_width <= 1 &&
(gc_private->pen_style & PS_STYLE_MASK) == PS_SOLID;
for (i = 0; ok && i < nsegs; i++)
{
/* PatBlt() is much faster than LineTo(), says
* jpe@archaeopteryx.com. Hmm. Use it if we have a solid
* colour pen, then we know that the brush is also solid and
* of the same colour.
*/
if (maybe_patblt && segs[i].x1 == segs[i].x2)
if (gc_private->pen_dashes && !IS_WIN_NT ())
{
/* code very similar to the IMHO questionable optimization
* below. This one draws dashed vertical/horizontal lines
* with the limited Win9x GDI. --hb
*/
for (i = 0; ok && i < nsegs; i++)
{
int y1, y2;
if (segs[i].y1 <= segs[i].y2)
y1 = segs[i].y1, y2 = segs[i].y2;
else
y1 = segs[i].y2, y2 = segs[i].y1;
if (!PatBlt (hdc, segs[i].x1, y1,
1, y2 - y1 + 1, PATCOPY))
WIN32_GDI_FAILED ("PatBlt"), ok = FALSE;
if (segs[i].x1 == segs[i].x2)
{
int y1, y2;
if (segs[i].y1 <= segs[i].y2)
y1 = segs[i].y1, y2 = segs[i].y2;
else
y1 = segs[i].y2, y2 = segs[i].y1;
ok = render_line_vertical (hdc,
segs[i].x1, y1, y2,
gc_private->pen_width,
gc_private->pen_dashes,
gc_private->pen_num_dashes);
}
else if (segs[i].y1 == segs[i].y2)
{
int x1, x2;
if (segs[i].x1 <= segs[i].x2)
x1 = segs[i].x1, x2 = segs[i].x2;
else
x1 = segs[i].x2, x2 = segs[i].x1;
ok = render_line_horizontal (hdc,
x1, x2, segs[i].y1,
gc_private->pen_width,
gc_private->pen_dashes,
gc_private->pen_num_dashes);
}
else
{
if (!MoveToEx (hdc, segs[i].x1, segs[i].y1, NULL))
WIN32_GDI_FAILED ("MoveToEx"), ok = FALSE;
if (ok && !LineTo (hdc, segs[i].x2, segs[i].y2))
WIN32_GDI_FAILED ("LineTo"), ok = FALSE;
/* Draw end pixel */
if (ok && gc_private->pen_width <= 1)
if (!LineTo (hdc, segs[i].x2 + 1, segs[i].y2))
WIN32_GDI_FAILED ("LineTo"), ok = FALSE;
}
}
else if (maybe_patblt && segs[i].y1 == segs[i].y2)
{
int x1, x2;
if (segs[i].x1 <= segs[i].x2)
x1 = segs[i].x1, x2 = segs[i].x2;
else
x1 = segs[i].x2, x2 = segs[i].x1;
}
else
{
const gboolean maybe_patblt =
gc_private->rop2 == R2_COPYPEN &&
gc_private->pen_width <= 1 &&
(gc_private->pen_style & PS_STYLE_MASK) == PS_SOLID;
if (!PatBlt (hdc, x1, segs[i].y1,
x2 - x1 + 1, 1, PATCOPY))
WIN32_GDI_FAILED ("PatBlt"), ok = FALSE;
}
else
for (i = 0; ok && i < nsegs; i++)
{
if (!MoveToEx (hdc, segs[i].x1, segs[i].y1, NULL))
WIN32_GDI_FAILED ("MoveToEx"), ok = FALSE;
if (ok && !LineTo (hdc, segs[i].x2, segs[i].y2))
WIN32_GDI_FAILED ("LineTo"), ok = FALSE;
/* Draw end pixel */
if (ok && gc_private->pen_width <= 1)
if (!LineTo (hdc, segs[i].x2 + 1, segs[i].y2))
WIN32_GDI_FAILED ("LineTo"), ok = FALSE;
/* PatBlt() is much faster than LineTo(), says
* jpe@archaeopteryx.com. Hmm. Use it if we have a solid
* colour pen, then we know that the brush is also solid and
* of the same colour.
*/
if (maybe_patblt && segs[i].x1 == segs[i].x2)
{
int y1, y2;
if (segs[i].y1 <= segs[i].y2)
y1 = segs[i].y1, y2 = segs[i].y2;
else
y1 = segs[i].y2, y2 = segs[i].y1;
if (!PatBlt (hdc, segs[i].x1, y1,
1, y2 - y1 + 1, PATCOPY))
WIN32_GDI_FAILED ("PatBlt"), ok = FALSE;
}
else if (maybe_patblt && segs[i].y1 == segs[i].y2)
{
int x1, x2;
if (segs[i].x1 <= segs[i].x2)
x1 = segs[i].x1, x2 = segs[i].x2;
else
x1 = segs[i].x2, x2 = segs[i].x1;
if (!PatBlt (hdc, x1, segs[i].y1,
x2 - x1 + 1, 1, PATCOPY))
WIN32_GDI_FAILED ("PatBlt"), ok = FALSE;
}
else
{
if (!MoveToEx (hdc, segs[i].x1, segs[i].y1, NULL))
WIN32_GDI_FAILED ("MoveToEx"), ok = FALSE;
if (ok && !LineTo (hdc, segs[i].x2, segs[i].y2))
WIN32_GDI_FAILED ("LineTo"), ok = FALSE;
/* Draw end pixel */
if (ok && gc_private->pen_width <= 1)
if (!LineTo (hdc, segs[i].x2 + 1, segs[i].y2))
WIN32_GDI_FAILED ("LineTo"), ok = FALSE;
}
}
}
}
}
gdk_win32_hdc_release (drawable, gc, mask);
}
......@@ -844,26 +984,69 @@ gdk_win32_draw_lines (GdkDrawable *drawable,
hdc = gdk_win32_hdc_get (drawable, gc, mask);
pts = g_new (POINT, npoints);
for (i = 0; i < npoints; i++)
if (gc_private->pen_dashes && !IS_WIN_NT ())
{
pts[i].x = points[i].x;
pts[i].y = points[i].y;
for (i = 0; i < npoints - 1; i++)
{
if (points[i].x == points[i+1].x)
{
int y1, y2;
if (points[i].y > points[i+1].y)
y1 = points[i+1].y, y2 = points[i].y;
else
y1 = points[i].y, y2 = points[i+1].y;
render_line_vertical (hdc, points[i].x, y1, y2,
gc_private->pen_width,
gc_private->pen_dashes,
gc_private->pen_num_dashes);
}
else if (points[i].y == points[i+1].y)
{
int x1, x2;
if (points[i].x > points[i+1].x)
x1 = points[i+1].x, x2 = points[i].x;
else
x1 = points[i].x, x2 = points[i+1].x;
render_line_horizontal (hdc, x1, x2, points[i].y,
gc_private->pen_width,
gc_private->pen_dashes,
gc_private->pen_num_dashes);
}
else
{
if (!MoveToEx (hdc, points[i].x, points[i].y, NULL))
WIN32_GDI_FAILED ("MoveToEx"), ok = FALSE;
if (ok && !LineTo (hdc, points[i+1].x, points[i+1].y))
WIN32_GDI_FAILED ("LineTo"), ok = FALSE;
}
}
}
else
{
pts = g_new (POINT, npoints);
for (i = 0; i < npoints; i++)
{
pts[i].x = points[i].x;
pts[i].y = points[i].y;
}
if (!Polyline (hdc, pts, npoints))
WIN32_GDI_FAILED ("Polyline"), ok = FALSE;
if (!Polyline (hdc, pts, npoints))
WIN32_GDI_FAILED ("Polyline"), ok = FALSE;
g_free (pts);
g_free (pts);
/* Draw end pixel */
if (ok && gc_private->pen_width <= 1)
{
MoveToEx (hdc, points[npoints-1].x, points[npoints-1].y, NULL);
if (!LineTo (hdc, points[npoints-1].x + 1, points[npoints-1].y))
WIN32_GDI_FAILED ("LineTo");
/* Draw end pixel */
if (ok && gc_private->pen_width <= 1)
{
MoveToEx (hdc, points[npoints-1].x, points[npoints-1].y, NULL);
if (!LineTo (hdc, points[npoints-1].x + 1, points[npoints-1].y))
WIN32_GDI_FAILED ("LineTo");
}
}
gdk_win32_hdc_release (drawable, gc, mask);
}
......
......@@ -107,6 +107,9 @@ gdk_gc_win32_finalize (GObject *object)
if (win32_gc->values_mask & GDK_GC_STIPPLE)
gdk_drawable_unref (win32_gc->stipple);
if (win32_gc->pen_dashes)
g_free (win32_gc->pen_dashes);
G_OBJECT_CLASS (parent_class)->finalize (object);
}
......@@ -363,23 +366,30 @@ gdk_win32_gc_values_to_win32values (GdkGCValues *values,
switch (values->line_style)
{
case GDK_LINE_SOLID:
win32_gc->pen_style &= ~(PS_STYLE_MASK);
if (win32_gc->pen_dashes)
{
g_free (win32_gc->pen_dashes);
win32_gc->pen_dashes = NULL;
win32_gc->pen_num_dashes = 0;
}
win32_gc->pen_style &= ~(PS_STYLE_MASK);
GDK_NOTE (GC, (g_print ("%sps|=LINE_SOLID", s),
s = ","));
win32_gc->pen_style |= PS_SOLID;
break;
case GDK_LINE_ON_OFF_DASH:
case GDK_LINE_DOUBLE_DASH: /* ??? */
/* Only set the linestyle here, if it isn't already set
* gdk_win32_gc_set_dashes () knows better
*/
if (0 == (win32_gc->values_mask & GDK_GC_LINE_STYLE))
case GDK_LINE_DOUBLE_DASH:
if (!win32_gc->pen_dashes)
{
/* setting to PS_DASH probably isn't correct. If I understand the
* xlib docs correctly it should influence the handling of
* line endings ? --hb
*/
win32_gc->pen_style &= ~(PS_STYLE_MASK);
GDK_NOTE (GC, (g_print ("%sps|=DASH", s),
s = ","));
win32_gc->pen_style |= PS_DASH;
}
GDK_NOTE (GC, (g_print ("%sps|=DASH", s),
s = ","));
win32_gc->pen_style |= PS_DASH;
}
break;
}
win32_gc->values_mask |= GDK_GC_LINE_STYLE;
......@@ -468,6 +478,8 @@ _gdk_win32_gc_new (GdkDrawable *drawable,
win32_gc->stipple = NULL;
win32_gc->pen_style = PS_GEOMETRIC|PS_ENDCAP_FLAT|PS_JOIN_MITER;
win32_gc->pen_width = 0;
win32_gc->pen_dashes = NULL;
win32_gc->pen_num_dashes = 0;
win32_gc->values_mask = GDK_GC_FUNCTION | GDK_GC_FILL;
......@@ -586,6 +598,7 @@ gdk_win32_gc_set_dashes (GdkGC *gc,
gint n)
{
GdkGCWin32 *win32_gc;
int i;
g_return_if_fail (GDK_IS_GC (gc));
g_return_if_fail (dash_list != NULL);
......@@ -597,61 +610,11 @@ gdk_win32_gc_set_dashes (GdkGC *gc,
win32_gc->pen_style &= ~(PS_STYLE_MASK);
/*
* Set the extended line style. This could be done by
* PS_USERSTYLE and ExtCreatePen; but ONLY on WinNT,
* so let's make a guess (based on the implementation
* in DIA). On Win9x this does only work for lines
* with width one ...
*
* More workarounds for Win9x descibed at:
* http://www.codeguru.com/gdi/dashed.shtml
*/
if (!IS_WIN_NT () && win32_gc->pen_width > 1)
{
GDK_NOTE (GC, g_print ("gdk_win32_gc_set_dashes: not fully supported\n"));
win32_gc->pen_style |= PS_SOLID;
return;
}
win32_gc->pen_style &= ~PS_STYLE_MASK;
switch (n)
{
case 2:
if ((dash_list[0] == dash_list[1]) && (dash_list[0] > 2))
{
win32_gc->pen_style |= PS_DASH;