comparison src/device-msw.c @ 294:4b85ae5eabfb r21-0b45

Import from CVS: tag r21-0b45
author cvs
date Mon, 13 Aug 2007 10:38:01 +0200
parents e11d67e05968
children 5a79be0ef6a8
comparison
equal deleted inserted replaced
293:403535bfea94 294:4b85ae5eabfb
60 are supported on NTFS volumes, this is only relevant on NT. */ 60 are supported on NTFS volumes, this is only relevant on NT. */
61 Lisp_Object Vmswindows_get_true_file_attributes; 61 Lisp_Object Vmswindows_get_true_file_attributes;
62 62
63 Lisp_Object Qinit_pre_mswindows_win, Qinit_post_mswindows_win; 63 Lisp_Object Qinit_pre_mswindows_win, Qinit_post_mswindows_win;
64 64
65 struct font_enum_t
66 {
67 HDC hdc;
68 struct device *d;
69 };
70
71
72 /************************************************************************/
73 /* helpers */
74 /************************************************************************/
75
76 static int CALLBACK
77 font_enum_callback_2 (ENUMLOGFONTEX *lpelfe, NEWTEXTMETRICEX *lpntme,
78 int FontType, struct font_enum_t *font_enum)
79 {
80 struct mswindows_font_enum *fontlist, **fonthead;
81 char fontname[MSW_FONTSIZE];
82
83 /* The enumerated font weights are not to be trusted because:
84 * a) lpelfe->elfStyle is only filled in for TrueType fonts.
85 * b) Not all Bold and Italic styles of all fonts (inluding some Vector,
86 * Truetype and Raster fonts) are enumerated.
87 * I guess that fonts for which Bold and Italic styles are generated
88 * 'on-the-fly' are not enumerated. It would be overly restrictive to
89 * disallow Bold And Italic weights for these fonts, so we just leave
90 * weights unspecified. This means that we have to weed out duplicates of
91 * those fonts that do get enumerated with different weights. */
92
93 if (FontType == 0 /*vector*/ || FontType == TRUETYPE_FONTTYPE)
94 /* Scalable, so leave pointsize blank */
95 sprintf (fontname, "%s::::%s", lpelfe->elfLogFont.lfFaceName,
96 lpelfe->elfScript);
97 else
98 /* Formula for pointsize->height from LOGFONT docs in Platform SDK */
99 sprintf (fontname, "%s::%d::%s", lpelfe->elfLogFont.lfFaceName,
100 MulDiv (lpntme->ntmTm.tmHeight - lpntme->ntmTm.tmInternalLeading,
101 72, DEVICE_MSWINDOWS_LOGPIXELSY (font_enum->d)),
102 lpelfe->elfScript);
103
104 fonthead = &DEVICE_MSWINDOWS_FONTLIST (font_enum->d);
105 fontlist = *fonthead;
106 while (fontlist)
107 if (!strcmp (fontname, fontlist->fontname))
108 return 1; /* found a duplicate */
109 else
110 fontlist = fontlist->next;
111
112 /* Insert entry at head */
113 fontlist = *fonthead;
114 *fonthead = xmalloc (sizeof (struct mswindows_font_enum));
115 if (*fonthead == NULL)
116 {
117 *fonthead = fontlist;
118 return 0;
119 }
120 strcpy ((*fonthead)->fontname, fontname);
121 (*fonthead)->next = fontlist;
122 return 1;
123 }
124
125 static int CALLBACK
126 font_enum_callback_1 (ENUMLOGFONTEX *lpelfe, NEWTEXTMETRICEX *lpntme,
127 int FontType, struct font_enum_t *font_enum)
128 {
129 /* This function gets called once per facename per character set.
130 * We call a second callback to enumerate the fonts in each facename */
131 return EnumFontFamiliesEx (font_enum->hdc, &lpelfe->elfLogFont,
132 (FONTENUMPROC) font_enum_callback_2,
133 (LPARAM) font_enum, 0);
134 }
135
136 static Lisp_Object
137 build_syscolor_string (int index)
138 {
139 DWORD clr;
140 char buf[16];
141
142 if (index < 0)
143 return Qnil;
144
145 clr = GetSysColor (index);
146 sprintf (buf, "#%02X%02X%02X",
147 GetRValue (clr),
148 GetGValue (clr),
149 GetBValue (clr));
150 return build_string (buf);
151 }
152
153 static Lisp_Object
154 build_syscolor_cons (int index1, int index2)
155 {
156 Lisp_Object color1, color2;
157 struct gcpro gcpro1;
158 GCPRO1 (color1);
159 color1 = build_syscolor_string (index1);
160 color2 = build_syscolor_string (index2);
161 RETURN_UNGCPRO (Fcons (color1, color2));
162 }
163
164 static Lisp_Object
165 build_sysmetrics_cons (int index1, int index2)
166 {
167 return Fcons (index1 < 0 ? Qnil : make_int (GetSystemMetrics (index1)),
168 index2 < 0 ? Qnil : make_int (GetSystemMetrics (index2)));
169 }
170
171
172
173 /************************************************************************/
174 /* methods */
175 /************************************************************************/
176
65 static void 177 static void
66 mswindows_init_device (struct device *d, Lisp_Object props) 178 mswindows_init_device (struct device *d, Lisp_Object props)
67 { 179 {
68 WNDCLASSEX wc; 180 WNDCLASSEX wc;
69 HWND desktop;
70 HDC hdc; 181 HDC hdc;
71 182 LOGFONT logfont;
183 struct font_enum_t font_enum;
184
185 DEVICE_CLASS (d) = Qcolor;
72 DEVICE_INFD (d) = DEVICE_OUTFD (d) = -1; 186 DEVICE_INFD (d) = DEVICE_OUTFD (d) = -1;
73 init_baud_rate (d); 187 init_baud_rate (d);
74 init_one_device (d); 188 init_one_device (d);
75 189
76 d->device_data = xnew_and_zero (struct mswindows_device); 190 d->device_data = xnew_and_zero (struct mswindows_device);
77 191 hdc = CreateCompatibleDC (NULL);
78 desktop = GetDesktopWindow(); 192 assert (hdc!=NULL);
79 hdc = GetDC(desktop);
80 DEVICE_MSWINDOWS_LOGPIXELSX(d) = GetDeviceCaps(hdc, LOGPIXELSX); 193 DEVICE_MSWINDOWS_LOGPIXELSX(d) = GetDeviceCaps(hdc, LOGPIXELSX);
81 DEVICE_MSWINDOWS_LOGPIXELSY(d) = GetDeviceCaps(hdc, LOGPIXELSY); 194 DEVICE_MSWINDOWS_LOGPIXELSY(d) = GetDeviceCaps(hdc, LOGPIXELSY);
82 DEVICE_MSWINDOWS_PLANES(d) = GetDeviceCaps(hdc, PLANES); 195 DEVICE_MSWINDOWS_PLANES(d) = GetDeviceCaps(hdc, PLANES);
83 /* FIXME: Only valid if RC_PALETTE bit set in RASTERCAPS, 196 /* #### SIZEPALETTE only valid if RC_PALETTE bit set in RASTERCAPS,
84 what should we return for a non-palette-based device? */ 197 what should we return for a non-palette-based device? */
85 DEVICE_MSWINDOWS_CELLS(d) = GetDeviceCaps(hdc, SIZEPALETTE); 198 DEVICE_MSWINDOWS_CELLS(d) = GetDeviceCaps(hdc, SIZEPALETTE);
86 DEVICE_MSWINDOWS_HORZRES(d) = GetDeviceCaps(hdc, HORZRES); 199 DEVICE_MSWINDOWS_HORZRES(d) = GetDeviceCaps(hdc, HORZRES);
87 DEVICE_MSWINDOWS_VERTRES(d) = GetDeviceCaps(hdc, VERTRES); 200 DEVICE_MSWINDOWS_VERTRES(d) = GetDeviceCaps(hdc, VERTRES);
88 DEVICE_MSWINDOWS_HORZSIZE(d) = GetDeviceCaps(hdc, HORZSIZE); 201 DEVICE_MSWINDOWS_HORZSIZE(d) = GetDeviceCaps(hdc, HORZSIZE);
89 DEVICE_MSWINDOWS_VERTSIZE(d) = GetDeviceCaps(hdc, VERTSIZE); 202 DEVICE_MSWINDOWS_VERTSIZE(d) = GetDeviceCaps(hdc, VERTSIZE);
90 DEVICE_MSWINDOWS_BITSPIXEL(d) = GetDeviceCaps(hdc, BITSPIXEL); 203 DEVICE_MSWINDOWS_BITSPIXEL(d) = GetDeviceCaps(hdc, BITSPIXEL);
91 ReleaseDC(desktop, hdc); 204
92 205 DEVICE_MSWINDOWS_FONTLIST (d) = NULL;
93 DEVICE_CLASS(d) = Qcolor; 206 logfont.lfCharSet = DEFAULT_CHARSET;
207 logfont.lfFaceName[0] = '\0';
208 logfont.lfPitchAndFamily = DEFAULT_PITCH;
209 font_enum.hdc = hdc;
210 font_enum.d = d;
211 EnumFontFamiliesEx (hdc, &logfont, (FONTENUMPROC) font_enum_callback_1,
212 (LPARAM) (&font_enum), 0);
213 DeleteDC (hdc);
94 214
95 /* Register the main window class */ 215 /* Register the main window class */
96 wc.cbSize = sizeof (WNDCLASSEX); 216 wc.cbSize = sizeof (WNDCLASSEX);
97 wc.style = CS_OWNDC; /* One DC per window */ 217 wc.style = CS_OWNDC; /* One DC per window */
98 wc.lpfnWndProc = (WNDPROC) mswindows_wnd_proc; 218 wc.lpfnWndProc = (WNDPROC) mswindows_wnd_proc;
135 } 255 }
136 256
137 static void 257 static void
138 mswindows_delete_device (struct device *d) 258 mswindows_delete_device (struct device *d)
139 { 259 {
260 struct mswindows_font_enum *fontlist, *next;
261
262 fontlist = DEVICE_MSWINDOWS_FONTLIST (d);
263 while (fontlist)
264 {
265 next = fontlist->next;
266 free (fontlist);
267 fontlist = next;
268 }
269
140 #ifdef HAVE_DRAGNDROP 270 #ifdef HAVE_DRAGNDROP
141 DdeNameService (mswindows_dde_mlid, 0L, 0L, DNS_REGISTER); 271 DdeNameService (mswindows_dde_mlid, 0L, 0L, DNS_REGISTER);
142 DdeUninitialize (mswindows_dde_mlid); 272 DdeUninitialize (mswindows_dde_mlid);
143 #endif 273 #endif
144 } 274
145 275 free (d->device_data);
146 static Lisp_Object
147 build_syscolor_string (int index)
148 {
149 DWORD clr;
150 char buf[16];
151
152 if (index < 0)
153 return Qnil;
154
155 clr = GetSysColor (index);
156 sprintf (buf, "#%02X%02X%02X",
157 GetRValue (clr),
158 GetGValue (clr),
159 GetBValue (clr));
160 return build_string (buf);
161 }
162
163 static Lisp_Object
164 build_syscolor_cons (int index1, int index2)
165 {
166 Lisp_Object color1, color2;
167 struct gcpro gcpro1;
168 GCPRO1 (color1);
169 color1 = build_syscolor_string (index1);
170 color2 = build_syscolor_string (index2);
171 RETURN_UNGCPRO (Fcons (color1, color2));
172 }
173
174 static Lisp_Object
175 build_sysmetrics_cons (int index1, int index2)
176 {
177 return Fcons (index1 < 0 ? Qnil : make_int (GetSystemMetrics (index1)),
178 index2 < 0 ? Qnil : make_int (GetSystemMetrics (index2)));
179 } 276 }
180 277
181 static Lisp_Object 278 static Lisp_Object
182 mswindows_device_system_metrics (struct device *d, 279 mswindows_device_system_metrics (struct device *d,
183 enum device_metrics m) 280 enum device_metrics m)
269 static unsigned int 366 static unsigned int
270 mswindows_device_implementation_flags (void) 367 mswindows_device_implementation_flags (void)
271 { 368 {
272 return XDEVIMPF_PIXEL_GEOMETRY; 369 return XDEVIMPF_PIXEL_GEOMETRY;
273 } 370 }
371
274 372
275 /************************************************************************/ 373 /************************************************************************/
276 /* initialization */ 374 /* initialization */
277 /************************************************************************/ 375 /************************************************************************/
278 376