kernel32: Fix LANGID for Korean resource.
[wine] / dlls / winex11.drv / pen.c
1 /*
2  * X11DRV pen objects
3  *
4  * Copyright 1993 Alexandre Julliard
5  *
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  */
20
21 #include "config.h"
22
23 #include "x11drv.h"
24 #include "wine/debug.h"
25
26 WINE_DEFAULT_DEBUG_CHANNEL(x11drv);
27
28 /***********************************************************************
29  *           SelectPen   (X11DRV.@)
30  */
31 HPEN X11DRV_SelectPen( X11DRV_PDEVICE *physDev, HPEN hpen )
32 {
33     LOGPEN logpen;
34     static char PEN_dash[]       = { 16,8 };
35     static char PEN_dot[]        = { 4,4 };
36     static char PEN_dashdot[]    = { 12,8,4,8 };
37     static char PEN_dashdotdot[] = { 12,4,4,4,4,4 };
38     static char PEN_alternate[]  = { 1,1 };
39
40     if (!GetObjectW( hpen, sizeof(logpen), &logpen ))
41     {
42         /* must be an extended pen */
43         EXTLOGPEN *elp;
44         INT size = GetObjectW( hpen, 0, NULL );
45
46         if (!size) return 0;
47
48         elp = HeapAlloc( GetProcessHeap(), 0, size );
49
50         GetObjectW( hpen, size, elp );
51         /* FIXME: add support for user style pens */
52         logpen.lopnStyle = elp->elpPenStyle;
53         logpen.lopnWidth.x = elp->elpWidth;
54         logpen.lopnWidth.y = 0;
55         logpen.lopnColor = elp->elpColor;
56
57         HeapFree( GetProcessHeap(), 0, elp );
58     }
59
60     physDev->pen.style = logpen.lopnStyle & PS_STYLE_MASK;
61     physDev->pen.type = logpen.lopnStyle & PS_TYPE_MASK;
62     physDev->pen.endcap = logpen.lopnStyle & PS_ENDCAP_MASK;
63     physDev->pen.linejoin = logpen.lopnStyle & PS_JOIN_MASK;
64
65     physDev->pen.width = logpen.lopnWidth.x;
66     if ((logpen.lopnStyle & PS_GEOMETRIC) || (physDev->pen.width > 1))
67     {
68         physDev->pen.width = X11DRV_XWStoDS( physDev, physDev->pen.width );
69         if (physDev->pen.width < 0) physDev->pen.width = -physDev->pen.width;
70     }
71
72     if (physDev->pen.width == 1) physDev->pen.width = 0;  /* Faster */
73     if (hpen == GetStockObject( DC_PEN ))
74         logpen.lopnColor = GetDCPenColor( physDev->hdc );
75     physDev->pen.pixel = X11DRV_PALETTE_ToPhysical( physDev, logpen.lopnColor );
76     switch(logpen.lopnStyle & PS_STYLE_MASK)
77     {
78       case PS_DASH:
79         physDev->pen.dashes = PEN_dash;
80         physDev->pen.dash_len = sizeof(PEN_dash)/sizeof(*PEN_dash);
81         break;
82       case PS_DOT:
83         physDev->pen.dashes = PEN_dot;
84         physDev->pen.dash_len = sizeof(PEN_dot)/sizeof(*PEN_dot);
85         break;
86       case PS_DASHDOT:
87         physDev->pen.dashes = PEN_dashdot;
88         physDev->pen.dash_len = sizeof(PEN_dashdot)/sizeof(*PEN_dashdot);
89         break;
90       case PS_DASHDOTDOT:
91         physDev->pen.dashes = PEN_dashdotdot;
92         physDev->pen.dash_len = sizeof(PEN_dashdotdot)/sizeof(*PEN_dashdotdot);
93         break;
94       case PS_ALTERNATE:
95         physDev->pen.dashes = PEN_alternate;
96         physDev->pen.dash_len = sizeof(PEN_alternate)/sizeof(*PEN_alternate);
97         break;
98       case PS_USERSTYLE:
99         FIXME("PS_USERSTYLE is not supported\n");
100         /* fall through */
101       default:
102         physDev->pen.dashes = NULL;
103         physDev->pen.dash_len = 0;
104         break;
105     }
106     return hpen;
107 }
108
109
110 /***********************************************************************
111  *           SetDCPenColor (X11DRV.@)
112  */
113 COLORREF X11DRV_SetDCPenColor( X11DRV_PDEVICE *physDev, COLORREF crColor )
114 {
115     if (GetCurrentObject(physDev->hdc, OBJ_PEN) == GetStockObject( DC_PEN ))
116         physDev->pen.pixel = X11DRV_PALETTE_ToPhysical( physDev, crColor );
117
118     return crColor;
119 }