blob: c0af04ec430e9f5542050124e40f044bc3fbfde1 [file] [log] [blame]
Alexandre Julliard349a9531997-02-02 19:01:52 +00001/*
Huw D M Davies9c68faa1998-11-25 12:36:03 +00002 * X11DRV pen objects
Alexandre Julliard349a9531997-02-02 19:01:52 +00003 *
4 * Copyright 1993 Alexandre Julliard
Alexandre Julliard0799c1a2002-03-09 23:29:33 +00005 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Alexandre Julliard349a9531997-02-02 19:01:52 +000019 */
20
Patrik Stridvallab121e71999-02-04 11:11:01 +000021#include "config.h"
22
Patrik Stridvallab121e71999-02-04 11:11:01 +000023#include "x11drv.h"
Alexandre Julliard0799c1a2002-03-09 23:29:33 +000024#include "wine/debug.h"
Alexandre Julliard349a9531997-02-02 19:01:52 +000025
Alexandre Julliard0799c1a2002-03-09 23:29:33 +000026WINE_DEFAULT_DEBUG_CHANNEL(x11drv);
Francois Gouget345acc92000-12-24 20:16:25 +000027
28static const char PEN_dash[] = { 16,8 };
29static const char PEN_dot[] = { 4,4 };
30static const char PEN_dashdot[] = { 12,8,4,8 };
31static const char PEN_dashdotdot[] = { 12,4,4,4,4,4 };
32static const char PEN_alternate[] = { 1,1 };
Alexandre Julliard349a9531997-02-02 19:01:52 +000033
34/***********************************************************************
Patrik Stridvall14c96c12002-04-03 02:37:09 +000035 * SelectPen (X11DRV.@)
Alexandre Julliard349a9531997-02-02 19:01:52 +000036 */
Alexandre Julliarde21c15e2002-03-28 22:22:05 +000037HPEN X11DRV_SelectPen( X11DRV_PDEVICE *physDev, HPEN hpen )
Alexandre Julliard349a9531997-02-02 19:01:52 +000038{
Alexandre Julliarde811f9c2001-08-16 19:13:52 +000039 LOGPEN logpen;
Alexandre Julliard349a9531997-02-02 19:01:52 +000040
Dmitry Timoshkoveb893bd2006-01-30 18:17:07 +010041 if (!GetObjectW( hpen, sizeof(logpen), &logpen ))
42 {
43 /* must be an extended pen */
Dmitry Timoshkov434a60b2006-03-09 15:12:43 +080044 EXTLOGPEN *elp;
45 INT size = GetObjectW( hpen, 0, NULL );
46
47 if (!size) return 0;
48
49 elp = HeapAlloc( GetProcessHeap(), 0, size );
50
51 GetObjectW( hpen, size, elp );
52 /* FIXME: add support for user style pens */
53 logpen.lopnStyle = elp->elpPenStyle;
54 logpen.lopnWidth.x = elp->elpWidth;
Dmitry Timoshkoveb893bd2006-01-30 18:17:07 +010055 logpen.lopnWidth.y = 0;
Dmitry Timoshkov434a60b2006-03-09 15:12:43 +080056 logpen.lopnColor = elp->elpColor;
57
58 HeapFree( GetProcessHeap(), 0, elp );
Dmitry Timoshkoveb893bd2006-01-30 18:17:07 +010059 }
Alexandre Julliard44ed71f1997-12-21 19:17:50 +000060
Alexandre Julliarde811f9c2001-08-16 19:13:52 +000061 physDev->pen.style = logpen.lopnStyle & PS_STYLE_MASK;
62 physDev->pen.type = logpen.lopnStyle & PS_TYPE_MASK;
63 physDev->pen.endcap = logpen.lopnStyle & PS_ENDCAP_MASK;
64 physDev->pen.linejoin = logpen.lopnStyle & PS_JOIN_MASK;
65
Dmitry Timoshkovef4fc8f2006-02-01 12:30:15 +010066 physDev->pen.width = logpen.lopnWidth.x;
Dmitry Timoshkov75e81662006-02-08 12:35:29 +010067 if ((logpen.lopnStyle & PS_GEOMETRIC) || (physDev->pen.width > 1))
Dmitry Timoshkovef4fc8f2006-02-01 12:30:15 +010068 {
69 physDev->pen.width = X11DRV_XWStoDS( physDev, physDev->pen.width );
70 if (physDev->pen.width < 0) physDev->pen.width = -physDev->pen.width;
71 }
72
Huw D M Davies9c68faa1998-11-25 12:36:03 +000073 if (physDev->pen.width == 1) physDev->pen.width = 0; /* Faster */
Ulrich Czekalla16ff6682003-11-05 01:43:57 +000074 if (hpen == GetStockObject( DC_PEN ))
Alexandre Julliard73423902004-01-15 06:19:35 +000075 logpen.lopnColor = GetDCPenColor( physDev->hdc );
Alexandre Julliarde21c15e2002-03-28 22:22:05 +000076 physDev->pen.pixel = X11DRV_PALETTE_ToPhysical( physDev, logpen.lopnColor );
Alexandre Julliarde811f9c2001-08-16 19:13:52 +000077 switch(logpen.lopnStyle & PS_STYLE_MASK)
Alexandre Julliard349a9531997-02-02 19:01:52 +000078 {
79 case PS_DASH:
Huw D M Davies9c68faa1998-11-25 12:36:03 +000080 physDev->pen.dashes = (char *)PEN_dash;
Francois Gouget5f74d672000-10-31 02:02:42 +000081 physDev->pen.dash_len = sizeof(PEN_dash)/sizeof(*PEN_dash);
Alexandre Julliard349a9531997-02-02 19:01:52 +000082 break;
83 case PS_DOT:
Huw D M Davies9c68faa1998-11-25 12:36:03 +000084 physDev->pen.dashes = (char *)PEN_dot;
Francois Gouget5f74d672000-10-31 02:02:42 +000085 physDev->pen.dash_len = sizeof(PEN_dot)/sizeof(*PEN_dot);
Alexandre Julliard349a9531997-02-02 19:01:52 +000086 break;
87 case PS_DASHDOT:
Huw D M Davies9c68faa1998-11-25 12:36:03 +000088 physDev->pen.dashes = (char *)PEN_dashdot;
Francois Gouget5f74d672000-10-31 02:02:42 +000089 physDev->pen.dash_len = sizeof(PEN_dashdot)/sizeof(*PEN_dashdot);
Alexandre Julliard349a9531997-02-02 19:01:52 +000090 break;
91 case PS_DASHDOTDOT:
Huw D M Davies9c68faa1998-11-25 12:36:03 +000092 physDev->pen.dashes = (char *)PEN_dashdotdot;
Francois Gouget5f74d672000-10-31 02:02:42 +000093 physDev->pen.dash_len = sizeof(PEN_dashdotdot)/sizeof(*PEN_dashdotdot);
Alexandre Julliard349a9531997-02-02 19:01:52 +000094 break;
Alexandre Julliard44ed71f1997-12-21 19:17:50 +000095 case PS_ALTERNATE:
Huw D M Davies9c68faa1998-11-25 12:36:03 +000096 physDev->pen.dashes = (char *)PEN_alternate;
Francois Gouget5f74d672000-10-31 02:02:42 +000097 physDev->pen.dash_len = sizeof(PEN_alternate)/sizeof(*PEN_alternate);
Alexandre Julliard44ed71f1997-12-21 19:17:50 +000098 break;
99 case PS_USERSTYLE:
Francois Gouget345acc92000-12-24 20:16:25 +0000100 FIXME("PS_USERSTYLE is not supported\n");
Alexandre Julliard44ed71f1997-12-21 19:17:50 +0000101 break;
Alexandre Julliard349a9531997-02-02 19:01:52 +0000102 }
Alexandre Julliarde21c15e2002-03-28 22:22:05 +0000103 return hpen;
Alexandre Julliard349a9531997-02-02 19:01:52 +0000104}
Ulrich Czekalla16ff6682003-11-05 01:43:57 +0000105
106
107/***********************************************************************
108 * SetDCPenColor (X11DRV.@)
109 */
110COLORREF X11DRV_SetDCPenColor( X11DRV_PDEVICE *physDev, COLORREF crColor )
111{
112 if (GetCurrentObject(physDev->hdc, OBJ_PEN) == GetStockObject( DC_PEN ))
113 physDev->pen.pixel = X11DRV_PALETTE_ToPhysical( physDev, crColor );
114
115 return crColor;
116}