comparison src/device-msw.c @ 318:afd57c14dfc8 r21-0b57

Import from CVS: tag r21-0b57
author cvs
date Mon, 13 Aug 2007 10:45:36 +0200
parents 5a79be0ef6a8
children 7c94d56991e1
comparison
equal deleted inserted replaced
317:a2fc9afbef65 318:afd57c14dfc8
36 #include "console-stream.h" 36 #include "console-stream.h"
37 #include "events.h" 37 #include "events.h"
38 #include "faces.h" 38 #include "faces.h"
39 #include "frame.h" 39 #include "frame.h"
40 #include "sysdep.h" 40 #include "sysdep.h"
41
42 #ifndef __CYGWIN32__
43 #include <commctrl.h>
44 #else
45 #define FONTENUMPROC FONTENUMEXPROC
46 #define ntmTm ntmentm
47 #endif
48 41
49 /* win32 DDE management library globals */ 42 /* win32 DDE management library globals */
50 #ifdef HAVE_DRAGNDROP 43 #ifdef HAVE_DRAGNDROP
51 DWORD mswindows_dde_mlid; 44 DWORD mswindows_dde_mlid;
52 HSZ mswindows_dde_service; 45 HSZ mswindows_dde_service;
63 are supported on NTFS volumes, this is only relevant on NT. */ 56 are supported on NTFS volumes, this is only relevant on NT. */
64 Lisp_Object Vmswindows_get_true_file_attributes; 57 Lisp_Object Vmswindows_get_true_file_attributes;
65 58
66 Lisp_Object Qinit_pre_mswindows_win, Qinit_post_mswindows_win; 59 Lisp_Object Qinit_pre_mswindows_win, Qinit_post_mswindows_win;
67 60
68 struct font_enum_t
69 {
70 HDC hdc;
71 struct device *d;
72 };
73
74 61
75 /************************************************************************/ 62 /************************************************************************/
76 /* helpers */ 63 /* helpers */
77 /************************************************************************/ 64 /************************************************************************/
78
79 static int CALLBACK
80 font_enum_callback_2 (ENUMLOGFONTEX *lpelfe, NEWTEXTMETRICEX *lpntme,
81 int FontType, struct font_enum_t *font_enum)
82 {
83 struct mswindows_font_enum *fontlist, **fonthead;
84 char fontname[MSW_FONTSIZE];
85
86 /* The enumerated font weights are not to be trusted because:
87 * a) lpelfe->elfStyle is only filled in for TrueType fonts.
88 * b) Not all Bold and Italic styles of all fonts (inluding some Vector,
89 * Truetype and Raster fonts) are enumerated.
90 * I guess that fonts for which Bold and Italic styles are generated
91 * 'on-the-fly' are not enumerated. It would be overly restrictive to
92 * disallow Bold And Italic weights for these fonts, so we just leave
93 * weights unspecified. This means that we have to weed out duplicates of
94 * those fonts that do get enumerated with different weights. */
95
96 if (FontType == 0 /*vector*/ || FontType == TRUETYPE_FONTTYPE)
97 /* Scalable, so leave pointsize blank */
98 sprintf (fontname, "%s::::%s", lpelfe->elfLogFont.lfFaceName,
99 lpelfe->elfScript);
100 else
101 /* Formula for pointsize->height from LOGFONT docs in Platform SDK */
102 sprintf (fontname, "%s::%d::%s", lpelfe->elfLogFont.lfFaceName,
103 MulDiv (lpntme->ntmTm.tmHeight - lpntme->ntmTm.tmInternalLeading,
104 72, DEVICE_MSWINDOWS_LOGPIXELSY (font_enum->d)),
105 lpelfe->elfScript);
106
107 fonthead = &DEVICE_MSWINDOWS_FONTLIST (font_enum->d);
108 fontlist = *fonthead;
109 while (fontlist)
110 if (!strcmp (fontname, fontlist->fontname))
111 return 1; /* found a duplicate */
112 else
113 fontlist = fontlist->next;
114
115 /* Insert entry at head */
116 fontlist = *fonthead;
117 *fonthead = xmalloc (sizeof (struct mswindows_font_enum));
118 if (*fonthead == NULL)
119 {
120 *fonthead = fontlist;
121 return 0;
122 }
123 strcpy ((*fonthead)->fontname, fontname);
124 (*fonthead)->next = fontlist;
125 return 1;
126 }
127
128 static int CALLBACK
129 font_enum_callback_1 (ENUMLOGFONTEX *lpelfe, NEWTEXTMETRICEX *lpntme,
130 int FontType, struct font_enum_t *font_enum)
131 {
132 /* This function gets called once per facename per character set.
133 * We call a second callback to enumerate the fonts in each facename */
134 return EnumFontFamiliesEx (font_enum->hdc, &lpelfe->elfLogFont,
135 (FONTENUMPROC) font_enum_callback_2,
136 (LPARAM) font_enum, 0);
137 }
138 65
139 static Lisp_Object 66 static Lisp_Object
140 build_syscolor_string (int index) 67 build_syscolor_string (int index)
141 { 68 {
142 DWORD clr; 69 DWORD clr;
180 static void 107 static void
181 mswindows_init_device (struct device *d, Lisp_Object props) 108 mswindows_init_device (struct device *d, Lisp_Object props)
182 { 109 {
183 WNDCLASSEX wc; 110 WNDCLASSEX wc;
184 HDC hdc; 111 HDC hdc;
185 LOGFONT logfont;
186 struct font_enum_t font_enum;
187 112
188 DEVICE_CLASS (d) = Qcolor; 113 DEVICE_CLASS (d) = Qcolor;
189 DEVICE_INFD (d) = DEVICE_OUTFD (d) = -1; 114 DEVICE_INFD (d) = DEVICE_OUTFD (d) = -1;
190 init_baud_rate (d); 115 init_baud_rate (d);
191 init_one_device (d); 116 init_one_device (d);
202 DEVICE_MSWINDOWS_HORZRES(d) = GetDeviceCaps(hdc, HORZRES); 127 DEVICE_MSWINDOWS_HORZRES(d) = GetDeviceCaps(hdc, HORZRES);
203 DEVICE_MSWINDOWS_VERTRES(d) = GetDeviceCaps(hdc, VERTRES); 128 DEVICE_MSWINDOWS_VERTRES(d) = GetDeviceCaps(hdc, VERTRES);
204 DEVICE_MSWINDOWS_HORZSIZE(d) = GetDeviceCaps(hdc, HORZSIZE); 129 DEVICE_MSWINDOWS_HORZSIZE(d) = GetDeviceCaps(hdc, HORZSIZE);
205 DEVICE_MSWINDOWS_VERTSIZE(d) = GetDeviceCaps(hdc, VERTSIZE); 130 DEVICE_MSWINDOWS_VERTSIZE(d) = GetDeviceCaps(hdc, VERTSIZE);
206 DEVICE_MSWINDOWS_BITSPIXEL(d) = GetDeviceCaps(hdc, BITSPIXEL); 131 DEVICE_MSWINDOWS_BITSPIXEL(d) = GetDeviceCaps(hdc, BITSPIXEL);
207
208 DEVICE_MSWINDOWS_FONTLIST (d) = NULL;
209 logfont.lfCharSet = DEFAULT_CHARSET;
210 logfont.lfFaceName[0] = '\0';
211 logfont.lfPitchAndFamily = DEFAULT_PITCH;
212 font_enum.hdc = hdc;
213 font_enum.d = d;
214 EnumFontFamiliesEx (hdc, &logfont, (FONTENUMPROC) font_enum_callback_1,
215 (LPARAM) (&font_enum), 0);
216 DeleteDC (hdc); 132 DeleteDC (hdc);
133
134 mswindows_enumerate_fonts (d);
217 135
218 /* Register the main window class */ 136 /* Register the main window class */
219 wc.cbSize = sizeof (WNDCLASSEX); 137 wc.cbSize = sizeof (WNDCLASSEX);
220 wc.style = CS_OWNDC; /* One DC per window */ 138 wc.style = CS_OWNDC; /* One DC per window */
221 wc.lpfnWndProc = (WNDPROC) mswindows_wnd_proc; 139 wc.lpfnWndProc = (WNDPROC) mswindows_wnd_proc;