comctl32: Invalidate before item is removed.
[wine/multimedia.git] / dlls / winex11.drv / pen.c
blob1fb2d42f8a458c08b446bafccb1aed071ffcc047
1 /*
2 * X11DRV pen objects
4 * Copyright 1993 Alexandre Julliard
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.
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.
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include "config.h"
23 #include "x11drv.h"
24 #include "wine/debug.h"
26 WINE_DEFAULT_DEBUG_CHANNEL(x11drv);
29 static DWORD get_user_dashes( char *res, const DWORD *style, DWORD len )
31 DWORD i, pos, dashes[MAX_DASHLEN];
33 len = min( len, MAX_DASHLEN );
34 memcpy( dashes, style, len * sizeof(DWORD) );
35 for (i = pos = 0; i < len; i++)
37 if (!dashes[i]) /* get rid of 0 entry */
39 if (i < len - 1)
41 i++;
42 if (pos) dashes[pos - 1] += dashes[i];
43 else dashes[len - 1] += dashes[i];
45 else if (pos)
47 dashes[0] += dashes[pos - 1];
48 pos--;
51 else dashes[pos++] = dashes[i];
53 for (i = 0; i < pos; i++) res[i] = min( dashes[i], 255 );
54 return pos;
57 /***********************************************************************
58 * SelectPen (X11DRV.@)
60 HPEN X11DRV_SelectPen( PHYSDEV dev, HPEN hpen, const struct brush_pattern *pattern )
62 static const char PEN_dash[] = { 16,8 };
63 static const char PEN_dot[] = { 4,4 };
64 static const char PEN_dashdot[] = { 12,8,4,8 };
65 static const char PEN_dashdotdot[] = { 12,4,4,4,4,4 };
66 static const char PEN_alternate[] = { 1,1 };
67 static const char EXTPEN_dash[] = { 3,1 };
68 static const char EXTPEN_dot[] = { 1,1 };
69 static const char EXTPEN_dashdot[] = { 3,1,1,1 };
70 static const char EXTPEN_dashdotdot[] = { 3,1,1,1,1,1 };
71 X11DRV_PDEVICE *physDev = get_x11drv_dev( dev );
72 LOGPEN logpen;
73 int i;
74 EXTLOGPEN *elp = NULL;
76 if (!GetObjectW( hpen, sizeof(logpen), &logpen ))
78 /* must be an extended pen */
79 INT size = GetObjectW( hpen, 0, NULL );
81 if (!size) return 0;
83 physDev->pen.ext = 1;
84 elp = HeapAlloc( GetProcessHeap(), 0, size );
86 GetObjectW( hpen, size, elp );
87 logpen.lopnStyle = elp->elpPenStyle;
88 logpen.lopnWidth.x = elp->elpWidth;
89 logpen.lopnWidth.y = 0;
90 logpen.lopnColor = elp->elpColor;
92 else
93 physDev->pen.ext = 0;
95 physDev->pen.style = logpen.lopnStyle & PS_STYLE_MASK;
96 physDev->pen.type = logpen.lopnStyle & PS_TYPE_MASK;
97 physDev->pen.endcap = logpen.lopnStyle & PS_ENDCAP_MASK;
98 physDev->pen.linejoin = logpen.lopnStyle & PS_JOIN_MASK;
100 physDev->pen.width = logpen.lopnWidth.x;
101 if ((logpen.lopnStyle & PS_GEOMETRIC) || (physDev->pen.width >= 1))
103 physDev->pen.width = X11DRV_XWStoDS( dev->hdc, physDev->pen.width );
104 if (physDev->pen.width < 0) physDev->pen.width = -physDev->pen.width;
107 if (physDev->pen.width == 1) physDev->pen.width = 0; /* Faster */
108 if (hpen == GetStockObject( DC_PEN ))
109 logpen.lopnColor = GetDCPenColor( dev->hdc );
110 physDev->pen.pixel = X11DRV_PALETTE_ToPhysical( physDev, logpen.lopnColor );
111 switch(logpen.lopnStyle & PS_STYLE_MASK)
113 case PS_DASH:
114 physDev->pen.dash_len = sizeof(PEN_dash)/sizeof(*PEN_dash);
115 memcpy(physDev->pen.dashes, physDev->pen.ext ? EXTPEN_dash : PEN_dash,
116 physDev->pen.dash_len);
117 break;
118 case PS_DOT:
119 physDev->pen.dash_len = sizeof(PEN_dot)/sizeof(*PEN_dot);
120 memcpy(physDev->pen.dashes, physDev->pen.ext ? EXTPEN_dot : PEN_dot,
121 physDev->pen.dash_len);
122 break;
123 case PS_DASHDOT:
124 physDev->pen.dash_len = sizeof(PEN_dashdot)/sizeof(*PEN_dashdot);
125 memcpy(physDev->pen.dashes, physDev->pen.ext ? EXTPEN_dashdot : PEN_dashdot,
126 physDev->pen.dash_len);
127 break;
128 case PS_DASHDOTDOT:
129 physDev->pen.dash_len = sizeof(PEN_dashdotdot)/sizeof(*PEN_dashdotdot);
130 memcpy(physDev->pen.dashes, physDev->pen.ext ? EXTPEN_dashdotdot : PEN_dashdotdot,
131 physDev->pen.dash_len);
132 break;
133 case PS_ALTERNATE:
134 physDev->pen.dash_len = sizeof(PEN_alternate)/sizeof(*PEN_alternate);
135 memcpy(physDev->pen.dashes, PEN_alternate, physDev->pen.dash_len);
136 break;
137 case PS_USERSTYLE:
138 physDev->pen.dash_len = get_user_dashes( physDev->pen.dashes,
139 elp->elpStyleEntry, elp->elpNumEntries );
140 break;
141 default:
142 physDev->pen.dash_len = 0;
143 break;
145 if(physDev->pen.ext && physDev->pen.dash_len && physDev->pen.width &&
146 (logpen.lopnStyle & PS_STYLE_MASK) != PS_USERSTYLE &&
147 (logpen.lopnStyle & PS_STYLE_MASK) != PS_ALTERNATE)
148 for(i = 0; i < physDev->pen.dash_len; i++)
149 physDev->pen.dashes[i] = min( physDev->pen.dashes[i] * physDev->pen.width, 255 );
151 HeapFree( GetProcessHeap(), 0, elp );
153 return hpen;
157 /***********************************************************************
158 * SetDCPenColor (X11DRV.@)
160 COLORREF X11DRV_SetDCPenColor( PHYSDEV dev, COLORREF crColor )
162 X11DRV_PDEVICE *physDev = get_x11drv_dev( dev );
164 if (GetCurrentObject(dev->hdc, OBJ_PEN) == GetStockObject( DC_PEN ))
165 physDev->pen.pixel = X11DRV_PALETTE_ToPhysical( physDev, crColor );
167 return crColor;