Handle the CCS_NORESIZE style.
[wine] / objects / text.c
1 /*
2  * text functions
3  *
4  * Copyright 1993, 1994 Alexandre Julliard
5  *
6  */
7
8 #include <string.h>
9
10 #include "windef.h"
11 #include "wingdi.h"
12 #include "wine/winuser16.h"
13 #include "winbase.h"
14 #include "winerror.h"
15 #include "gdi.h"
16 #include "heap.h"
17 #include "debugtools.h"
18 #include "winnls.h"
19
20 DEFAULT_DEBUG_CHANNEL(text);
21
22
23 /***********************************************************************
24  *           ExtTextOut16    (GDI.351)
25  */
26 BOOL16 WINAPI ExtTextOut16( HDC16 hdc, INT16 x, INT16 y, UINT16 flags,
27                             const RECT16 *lprect, LPCSTR str, UINT16 count,
28                             const INT16 *lpDx )
29 {
30     BOOL        ret;
31     int         i;
32     RECT        rect32;
33     LPINT       lpdx32 = NULL;
34
35     if (lpDx) {
36         lpdx32 = (LPINT)HeapAlloc( GetProcessHeap(),0, sizeof(INT)*count );
37         if(lpdx32 == NULL) return FALSE;
38         for (i=count;i--;) lpdx32[i]=lpDx[i];
39     }    
40     if (lprect) CONV_RECT16TO32(lprect,&rect32);
41     ret = ExtTextOutA(hdc,x,y,flags,lprect?&rect32:NULL,str,count,lpdx32);
42     if (lpdx32) HeapFree( GetProcessHeap(), 0, lpdx32 );
43     return ret;
44 }
45
46
47 /***********************************************************************
48  *           ExtTextOutA    (GDI32.98)
49  */
50 BOOL WINAPI ExtTextOutA( HDC hdc, INT x, INT y, UINT flags,
51                              const RECT *lprect, LPCSTR str, UINT count,
52                              const INT *lpDx )
53 {
54     DC * dc = DC_GetDCUpdate( hdc );
55     LPWSTR p;
56     UINT codepage = CP_ACP; /* FIXME: get codepage of font charset */
57     BOOL ret = FALSE;
58     LPINT lpDxW = NULL;
59
60     if (!dc) return FALSE;
61
62     if (dc->funcs->pExtTextOut)
63     {
64         UINT wlen = MultiByteToWideChar(codepage,0,str,count,NULL,0);
65         if (lpDx)
66         {
67             unsigned int i = 0, j = 0;
68
69             lpDxW = (LPINT)HeapAlloc( GetProcessHeap(), 0, wlen*sizeof(INT));
70             while(i < count)
71             {
72                 if(IsDBCSLeadByteEx(codepage, str[i]))
73                 {
74                     lpDxW[j++] = lpDx[i] + lpDx[i+1];
75                     i = i + 2;
76                 }
77                 else
78                 {
79                     lpDxW[j++] = lpDx[i];
80                     i = i + 1;
81                 }
82             }
83         }
84         if ((p = HeapAlloc( GetProcessHeap(), 0, wlen * sizeof(WCHAR) )))
85         {
86             wlen = MultiByteToWideChar(codepage,0,str,count,p,wlen);
87             ret = dc->funcs->pExtTextOut( dc, x, y, flags, lprect, p, wlen, lpDxW );
88             HeapFree( GetProcessHeap(), 0, p );
89         }
90         if (lpDxW) HeapFree( GetProcessHeap(), 0, lpDxW );
91     }
92     GDI_ReleaseObj( hdc );
93     return ret;
94 }
95
96
97 /***********************************************************************
98  *           ExtTextOutW    (GDI32.99)
99  */
100 BOOL WINAPI ExtTextOutW( HDC hdc, INT x, INT y, UINT flags,
101                              const RECT *lprect, LPCWSTR str, UINT count,
102                              const INT *lpDx )
103 {
104     BOOL ret = FALSE;
105     DC * dc = DC_GetDCUpdate( hdc );
106     if (dc)
107     {
108         if(dc->funcs->pExtTextOut)
109             ret = dc->funcs->pExtTextOut(dc,x,y,flags,lprect,str,count,lpDx);
110         GDI_ReleaseObj( hdc );
111     }
112     return ret;
113 }
114
115
116 /***********************************************************************
117  *           TextOut16    (GDI.33)
118  */
119 BOOL16 WINAPI TextOut16( HDC16 hdc, INT16 x, INT16 y, LPCSTR str, INT16 count )
120 {
121     return ExtTextOut16( hdc, x, y, 0, NULL, str, count, NULL );
122 }
123
124
125 /***********************************************************************
126  *           TextOutA    (GDI32.355)
127  */
128 BOOL WINAPI TextOutA( HDC hdc, INT x, INT y, LPCSTR str, INT count )
129 {
130     return ExtTextOutA( hdc, x, y, 0, NULL, str, count, NULL );
131 }
132
133
134 /***********************************************************************
135  *           TextOutW    (GDI32.356)
136  */
137 BOOL WINAPI TextOutW(HDC hdc, INT x, INT y, LPCWSTR str, INT count)
138 {
139     return ExtTextOutW( hdc, x, y, 0, NULL, str, count, NULL );
140 }
141
142
143 /***********************************************************************
144  * GetTextCharset [GDI32.226]  Gets character set for font in DC
145  *
146  * NOTES
147  *    Should it return a UINT32 instead of an INT32?
148  *    => YES, as GetTextCharsetInfo returns UINT32
149  *
150  * RETURNS
151  *    Success: Character set identifier
152  *    Failure: DEFAULT_CHARSET
153  */
154 UINT WINAPI GetTextCharset(
155     HDC hdc) /* [in] Handle to device context */
156 {
157     /* MSDN docs say this is equivalent */
158     return GetTextCharsetInfo(hdc, NULL, 0);
159 }
160
161 /***********************************************************************
162  * GetTextCharset16 [GDI.612]
163  */
164 UINT16 WINAPI GetTextCharset16(HDC16 hdc)
165 {
166     return (UINT16)GetTextCharset(hdc);
167 }
168
169 /***********************************************************************
170  * GetTextCharsetInfo [GDI32.381]  Gets character set for font
171  *
172  * NOTES
173  *    Should csi be an LPFONTSIGNATURE instead of an LPCHARSETINFO?
174  *    Should it return a UINT32 instead of an INT32?
175  *    => YES and YES, from win32.hlp from Borland
176  *
177  * RETURNS
178  *    Success: Character set identifier
179  *    Failure: DEFAULT_CHARSET
180  */
181 UINT WINAPI GetTextCharsetInfo(
182     HDC hdc,            /* [in]  Handle to device context */
183     LPFONTSIGNATURE fs, /* [out] Pointer to struct to receive data */
184     DWORD flags)        /* [in]  Reserved - must be 0 */
185 {
186     HGDIOBJ hFont;
187     UINT charSet = DEFAULT_CHARSET;
188     LOGFONTW lf;
189     CHARSETINFO csinfo;
190
191     hFont = GetCurrentObject(hdc, OBJ_FONT);
192     if (hFont == 0)
193         return(DEFAULT_CHARSET);
194     if ( GetObjectW(hFont, sizeof(LOGFONTW), &lf) != 0 )
195         charSet = lf.lfCharSet;
196
197     if (fs != NULL) {
198       if (!TranslateCharsetInfo((LPDWORD)charSet, &csinfo, TCI_SRCCHARSET))
199            return  (DEFAULT_CHARSET);
200       memcpy(fs, &csinfo.fs, sizeof(FONTSIGNATURE));
201     }
202     return charSet;
203 }
204
205 /***********************************************************************
206  * PolyTextOutA [GDI.402]  Draw several Strings
207  */
208 BOOL WINAPI PolyTextOutA (
209                           HDC hdc,               /* [in] Handle to device context */                      
210                           PPOLYTEXTA pptxt,      /* [in] Array of strings */
211                           INT cStrings           /* [in] Number of strings in array */
212                           )
213 {
214   FIXME("stub!\n");
215   SetLastError ( ERROR_CALL_NOT_IMPLEMENTED );
216   return 0;
217 }
218
219
220
221 /***********************************************************************
222  * PolyTextOutW [GDI.403] Draw several Strings
223  */
224 BOOL WINAPI PolyTextOutW ( 
225                           HDC hdc,               /* [in] Handle to device context */                      
226                           PPOLYTEXTW pptxt,      /* [in] Array of strings */
227                           INT cStrings           /* [in] Number of strings in array */
228                           )
229 {
230   FIXME("stub!\n");
231   SetLastError ( ERROR_CALL_NOT_IMPLEMENTED );
232   return 0;
233 }