Release 971130
[wine/hacks.git] / misc / tweak.c
blob0d88d0b7c51000abc61ea77f53cb41784c6247a4
1 /******************************************************************************
3 * tweak.c
5 * Windows 95 style interface tweaks.
6 * Copyright (c) 1997 Dave Cuthbert.
8 * FIXME: This file is, unfortunately, aptly named: the method of
9 * displaying Win95 style windows is a tweak. Lots of stuff does not yet
10 * work -- and probably never will unless some of this code is
11 * incorporated into the mainstream Wine code.
13 * DEVELOPERS, PLEASE NOTE: Before delving into the mainstream code and
14 * altering it, consider how your changes will affect the Win3.1 interface
15 * (which has taken a major effort to create!). After you make any sort of
16 * non-trivial change, *test* the Wine code running in Win3.1 mode! The
17 * object here is to make it so that the person who tests the latest version
18 * of Wine without adding the tweaks into wine.conf notices nothing out of
19 * the ordinary.
21 * Revision history
22 * 03-Jul-1997 Dave Cuthbert (dacut@ece.cmu.edu)
23 * Original implementation.
25 *****************************************************************************/
27 #include <stdio.h>
28 #include <malloc.h>
29 #include <X11/Xlib.h>
30 #include <string.h>
31 #include "dc.h"
32 #include "debug.h"
33 #include "graphics.h"
34 #include "options.h"
35 #include "stackframe.h"
36 #include "syscolor.h"
37 #include "tweak.h"
38 #include "windows.h"
40 /* Parameters for windows/nonclient.c */
41 extern int NC_CaptionLeftNudge;
42 extern int NC_CaptionTopNudge;
43 extern int NC_SysControlNudge;
44 extern int NC_MaxControlNudge;
45 extern int NC_MinControlNudge;
46 extern UINT32 NC_CaptionTextFlags;
47 extern HBRUSH32 NC_WinHighlight95;
48 extern HBRUSH32 NC_WinShadow95;
50 /* Parameters for controls/menu.c */
51 extern UINT32 MENU_BarItemTopNudge;
52 extern UINT32 MENU_BarItemLeftNudge;
53 extern UINT32 MENU_ItemTopNudge;
54 extern UINT32 MENU_ItemLeftNudge;
55 extern UINT32 MENU_HighlightTopNudge;
56 extern UINT32 MENU_HighlightLeftNudge;
57 extern UINT32 MENU_HighlightBottomNudge;
58 extern UINT32 MENU_HighlightRightNudge;
60 /* General options */
61 HPEN32 TWEAK_PenFF95;
62 HPEN32 TWEAK_PenE095;
63 HPEN32 TWEAK_PenC095;
64 HPEN32 TWEAK_Pen8095;
65 HPEN32 TWEAK_Pen0095;
67 #if defined(WIN_95_LOOK)
68 int TWEAK_Win95Look = 1;
69 #else
70 int TWEAK_Win95Look = 0;
71 #endif
73 int TWEAK_WineInitialized = 0;
76 /******************************************************************************
78 * int TWEAK_MenuInit()
80 * Initializes the Win95 tweaks to the menu code. See controls/menu.c.
81 * Return value indicates success (non-zero) or failure.
83 * Revision history
84 * 06-Jul-1997 Dave Cuthbert (dacut@ece.cmu.edu)
85 * Original implementation.
87 *****************************************************************************/
89 static int TWEAK_MenuInit()
91 MENU_BarItemTopNudge =
92 PROFILE_GetWineIniInt("Tweak.Layout", "MenuBarItemTopNudge", 0);
93 MENU_BarItemLeftNudge =
94 PROFILE_GetWineIniInt("Tweak.Layout", "MenuBarItemLeftNudge", 0);
95 MENU_ItemTopNudge =
96 PROFILE_GetWineIniInt("Tweak.Layout", "MenuItemTopNudge", 0);
97 MENU_ItemLeftNudge =
98 PROFILE_GetWineIniInt("Tweak.Layout", "MenuItemLeftNudge", 0);
99 MENU_HighlightTopNudge =
100 PROFILE_GetWineIniInt("Tweak.Layout", "MenuHighlightTopNudge", 0);
101 MENU_HighlightLeftNudge =
102 PROFILE_GetWineIniInt("Tweak.Layout", "MenuHighlightLeftNudge", 0);
103 MENU_HighlightBottomNudge =
104 PROFILE_GetWineIniInt("Tweak.Layout", "MenuHighlightBottomNudge", 0);
105 MENU_HighlightRightNudge =
106 PROFILE_GetWineIniInt("Tweak.Layout", "MenuHighlightRightNudge", 0);
108 return 1;
112 /******************************************************************************
114 * int TWEAK_NonClientInit()
116 * Initializes the Win95 tweaks to the non-client drawing functions. See
117 * windows/nonclient.c. Return value indicates success (non-zero) or
118 * failure.
120 * Revision history
121 * 05-Jul-1997 Dave Cuthbert (dacut@ece.cmu.edu)
122 * Original implementation.
124 *****************************************************************************/
126 static int TWEAK_NonClientInit()
128 char key_value[2];
130 NC_CaptionLeftNudge =
131 PROFILE_GetWineIniInt("Tweak.Layout", "CaptionLeftNudge", 0);
132 NC_CaptionTopNudge =
133 PROFILE_GetWineIniInt("Tweak.Layout", "CaptionTopNudge", 0);
134 NC_SysControlNudge =
135 PROFILE_GetWineIniInt("Tweak.Layout", "SysControlNudge", 0);
136 NC_MaxControlNudge =
137 PROFILE_GetWineIniInt("Tweak.Layout", "MaxControlNudge", 0);
138 NC_MinControlNudge =
139 PROFILE_GetWineIniInt("Tweak.Layout", "MinControlNudge", 0);
141 NC_WinHighlight95 = CreateSolidBrush32(RGB(0xc0, 0xc0, 0xc0));
142 NC_WinShadow95 = CreateSolidBrush32(RGB(0x00, 0x00, 0x00));
144 NC_CaptionTextFlags = DT_SINGLELINE | DT_VCENTER | DT_NOPREFIX;
146 PROFILE_GetWineIniString("Tweak.Layout", "CaptionAlignment",
147 TWEAK_Win95Look ? "l" : "c", key_value, 2);
149 switch(key_value[0]) {
150 case 'l':
151 case 'L':
152 NC_CaptionTextFlags |= DT_LEFT;
153 break;
155 case 'r':
156 case 'R':
157 NC_CaptionTextFlags |= DT_RIGHT;
158 break;
160 default:
161 NC_CaptionTextFlags |= DT_CENTER;
164 return 1;
168 /******************************************************************************
170 * int TWEAK_VarInit()
172 * Initializes the miscellaneous variables which are used in the tweak
173 * routines. Return value is non-zero on success.
175 * Revision history
176 * 07-Jul-1997 Dave Cuthbert (dacut@ece.cmu.edu)
177 * Original implementation.
179 *****************************************************************************/
181 static int TWEAK_VarInit()
183 TWEAK_Win95Look = PROFILE_GetWineIniBool("Tweak.Layout", "Win95Look", 0);
185 /* FIXME: Each color should really occupy a single entry in the wine.conf
186 file, but I couldn't settle on a good (intuitive!) format. */
188 TWEAK_PenFF95 = CreatePen32(
189 PS_SOLID, 1,
190 RGB(PROFILE_GetWineIniInt("Tweak.Colors", "PenFF95.Red", 0xff),
191 PROFILE_GetWineIniInt("Tweak.Colors", "PenFF95.Grn", 0xff),
192 PROFILE_GetWineIniInt("Tweak.Colors", "PenFF95.Blu", 0xff)));
193 TWEAK_PenE095 = CreatePen32(
194 PS_SOLID, 1,
195 RGB(PROFILE_GetWineIniInt("Tweak.Colors", "PenE095.Red", 0xe0),
196 PROFILE_GetWineIniInt("Tweak.Colors", "PenE095.Grn", 0xe0),
197 PROFILE_GetWineIniInt("Tweak.Colors", "PenE095.Blu", 0xe0)));
198 TWEAK_PenC095 = CreatePen32(
199 PS_SOLID, 1,
200 RGB(PROFILE_GetWineIniInt("Tweak.Colors", "PenC095.Red", 0xc0),
201 PROFILE_GetWineIniInt("Tweak.Colors", "PenC095.Grn", 0xc0),
202 PROFILE_GetWineIniInt("Tweak.Colors", "PenC095.Blu", 0xc0)));
203 TWEAK_Pen8095 = CreatePen32(
204 PS_SOLID, 1,
205 RGB(PROFILE_GetWineIniInt("Tweak.Colors", "Pen8095.Red", 0x80),
206 PROFILE_GetWineIniInt("Tweak.Colors", "Pen8095.Grn", 0x80),
207 PROFILE_GetWineIniInt("Tweak.Colors", "Pen8095.Blu", 0x80)));
208 TWEAK_Pen0095 = CreatePen32(
209 PS_SOLID, 1,
210 RGB(PROFILE_GetWineIniInt("Tweak.Colors", "Pen0095.Red", 0x00),
211 PROFILE_GetWineIniInt("Tweak.Colors", "Pen0095.Grn", 0x00),
212 PROFILE_GetWineIniInt("Tweak.Colors", "Pen0095.Blu", 0x00)));
214 dprintf_tweak(stddeb, "TWEAK_VarInit: Using %s look and feel.\n",
215 TWEAK_Win95Look ? "Win95" : "Win3.1");
216 return 1;
220 /******************************************************************************
222 * int TWEAK_Init()
224 * Does the full initialization of the Win95 tweak subsystem. Return value
225 * indicates success. Called by loader/main.c's MAIN_Init().
227 * Revision history
228 * 05-Jul-1997 Dave Cuthbert (dacut@ece.cmu.edu)
229 * Original implementation.
231 *****************************************************************************/
233 int TWEAK_Init()
235 TWEAK_VarInit();
236 TWEAK_NonClientInit();
237 TWEAK_MenuInit();
238 return 1;
242 /******************************************************************************
244 * int TWEAK_CheckConfiguration()
246 * Examines wine.conf for old/bad entries and recommends changes to the user.
248 * Revision history
249 * 05-Jul-1997 Dave Cuthbert (dacut@ece.cmu.edu)
250 * Original implementation.
252 *****************************************************************************/
254 int TWEAK_CheckConfiguration()
256 return 1;
260 /******************************************************************************
262 * Tweak graphic subsystem.
264 *****************************************************************************/
266 /******************************************************************************
268 * void TWEAK_DrawReliefRect95(
269 * HDC32 hdc, // Device context on which to draw
270 * RECT32 const *rect ) // Rectangle to use
272 * Draws the double-bordered Win95-style relief rectangle.
274 * Bugs
275 * There are some checks missing from this function. Perhaps the
276 * SelectObject32 calls should be examined? Hasn't failed on me (yet).
278 * Should I really be calling X functions directly from here? It is
279 * an optimization, but should I be optimizing alpha code? Probably
280 * not.
282 * Revision history
283 * 08-Jul-1997 Dave Cuthbert (dacut@ece.cmu.edu)
284 * Original implementation.
286 *****************************************************************************/
288 void TWEAK_DrawReliefRect95(
289 HDC32 hdc,
290 RECT32 const *rect )
292 DC *dc;
293 HPEN32 prevpen;
295 if((dc = (DC *)GDI_GetObjPtr(hdc, DC_MAGIC))) {
297 /* Draw the top/left lines first */
298 prevpen = SelectObject32(hdc, TWEAK_PenE095);
299 DC_SetupGCForPen(dc);
300 XDrawLine(display, dc->u.x.drawable, dc->u.x.gc, rect->left, rect->top,
301 rect->right - 1, rect->top);
302 XDrawLine(display, dc->u.x.drawable, dc->u.x.gc, rect->left, rect->top,
303 rect->left, rect->bottom - 1);
305 SelectObject32(hdc, TWEAK_PenFF95);
306 DC_SetupGCForPen(dc);
307 XDrawLine(display, dc->u.x.drawable, dc->u.x.gc, rect->left + 1,
308 rect->top + 1, rect->right - 2, rect->top + 1);
309 XDrawLine(display, dc->u.x.drawable, dc->u.x.gc, rect->left + 1,
310 rect->top + 1, rect->left + 1, rect->bottom - 2);
313 /* Now the bottom/right lines */
314 SelectObject32(hdc, TWEAK_Pen0095);
315 DC_SetupGCForPen(dc);
316 XDrawLine(display, dc->u.x.drawable, dc->u.x.gc, rect->left,
317 rect->bottom - 1, rect->right - 1, rect->bottom - 1);
318 XDrawLine(display, dc->u.x.drawable, dc->u.x.gc, rect->right - 1,
319 rect->top, rect->right - 1, rect->bottom - 1);
321 SelectObject32(hdc, TWEAK_Pen8095);
322 DC_SetupGCForPen(dc);
323 XDrawLine(display, dc->u.x.drawable, dc->u.x.gc, rect->left + 1,
324 rect->bottom - 2, rect->right - 2, rect->bottom - 2);
325 XDrawLine(display, dc->u.x.drawable, dc->u.x.gc, rect->right - 2,
326 rect->top + 1, rect->right - 2, rect->bottom - 2);
328 SelectObject32(hdc, prevpen);
331 return;
335 /******************************************************************************
337 * void TWEAK_DrawRevReliefRect95(
338 * HDC32 hdc, // Device context on which to draw
339 * RECT32 const *rect ) // Rectangle to use
341 * Draws the double-bordered Win95-style relief rectangle.
343 * Bugs
344 * There are some checks missing from this function. Perhaps the
345 * SelectObject32 calls should be examined? Hasn't failed on me (yet).
347 * Should I really be calling X functions directly from here? It is
348 * an optimization, but should I be optimizing alpha code? Probably
349 * not.
351 * Revision history
352 * 08-Jul-1997 Dave Cuthbert (dacut@ece.cmu.edu)
353 * Original implementation.
355 *****************************************************************************/
357 void TWEAK_DrawRevReliefRect95(
358 HDC32 hdc,
359 RECT32 const *rect )
361 DC *dc;
362 HPEN32 prevpen;
364 if((dc = (DC *)GDI_GetObjPtr(hdc, DC_MAGIC))) {
366 /* Draw the top/left lines first */
367 prevpen = SelectObject32(hdc, TWEAK_Pen8095);
368 DC_SetupGCForPen(dc);
369 XDrawLine(display, dc->u.x.drawable, dc->u.x.gc, rect->left, rect->top,
370 rect->right - 1, rect->top);
371 XDrawLine(display, dc->u.x.drawable, dc->u.x.gc, rect->left, rect->top,
372 rect->left, rect->bottom - 1);
374 SelectObject32(hdc, TWEAK_Pen0095);
375 DC_SetupGCForPen(dc);
376 XDrawLine(display, dc->u.x.drawable, dc->u.x.gc, rect->left + 1,
377 rect->top + 1, rect->right - 2, rect->top + 1);
378 XDrawLine(display, dc->u.x.drawable, dc->u.x.gc, rect->left + 1,
379 rect->top + 1, rect->left + 1, rect->bottom - 2);
382 /* Now the bottom/right lines */
383 SelectObject32(hdc, TWEAK_PenFF95);
384 DC_SetupGCForPen(dc);
385 XDrawLine(display, dc->u.x.drawable, dc->u.x.gc, rect->left,
386 rect->bottom - 1, rect->right - 1, rect->bottom - 1);
387 XDrawLine(display, dc->u.x.drawable, dc->u.x.gc, rect->right - 1,
388 rect->top, rect->right - 1, rect->bottom - 1);
390 SelectObject32(hdc, TWEAK_PenE095);
391 DC_SetupGCForPen(dc);
392 XDrawLine(display, dc->u.x.drawable, dc->u.x.gc, rect->left + 1,
393 rect->bottom - 2, rect->right - 2, rect->bottom - 2);
394 XDrawLine(display, dc->u.x.drawable, dc->u.x.gc, rect->right - 2,
395 rect->top + 1, rect->right - 2, rect->bottom - 2);
397 SelectObject32(hdc, prevpen);
400 return;
405 /******************************************************************************
407 * void TWEAK_DrawMenuSeparatorHoriz95(
408 * HDC32 hdc, // Device context on which to draw
409 * UINT32 xc1, // Left x-coordinate
410 * UINT32 yc, // Y-coordinate of the LOWER line
411 * UINT32 xc2 ) // Right x-coordinate
413 * Draws a horizontal menu separator bar Win 95 style.
415 * Bugs
416 * Same as those for DrawReliefRect95.
418 * Revision history
419 * 08-Jul-1997 Dave Cuthbert (dacut@ece.cmu.edu)
420 * Original implementation.
421 * 11-Jul-1997 Dave Cuthbert (dacut@ece.cmu.edu)
422 * Changed name from DrawMenuSeparator95
424 *****************************************************************************/
426 void TWEAK_DrawMenuSeparatorHoriz95(
427 HDC32 hdc,
428 UINT32 xc1,
429 UINT32 yc,
430 UINT32 xc2 )
432 DC *dc;
433 HPEN32 prevpen;
435 if((dc = (DC *)GDI_GetObjPtr(hdc, DC_MAGIC))) {
437 /* Draw the top line */
438 prevpen = SelectObject32(hdc, TWEAK_Pen8095);
439 DC_SetupGCForPen(dc);
440 XDrawLine(display, dc->u.x.drawable, dc->u.x.gc, xc1, yc - 1, xc2,
441 yc - 1);
443 /* And the bottom line */
444 SelectObject32(hdc, TWEAK_PenFF95);
445 DC_SetupGCForPen(dc);
446 XDrawLine(display, dc->u.x.drawable, dc->u.x.gc, xc1, yc, xc2, yc);
448 SelectObject32(hdc, prevpen);
451 return;
455 /******************************************************************************
457 * void TWEAK_DrawMenuSeparatorVert95(
458 * HDC32 hdc, // Device context on which to draw
459 * UINT32 xc, // X-coordinate of the RIGHT line
460 * UINT32 yc1, // top Y-coordinate
461 * UINT32 yc2 ) // bottom Y-coordinate
463 * Draws a vertical menu separator bar Win 95 style.
465 * Bugs
466 * Same as those for DrawReliefRect95.
468 * Revision history
469 * 11-Jul-1997 Dave Cuthbert (dacut@ece.cmu.edu)
470 * Original implementation.
472 *****************************************************************************/
474 void TWEAK_DrawMenuSeparatorVert95(
475 HDC32 hdc,
476 UINT32 xc,
477 UINT32 yc1,
478 UINT32 yc2 )
480 DC *dc;
481 HPEN32 prevpen;
483 if((dc = (DC *)GDI_GetObjPtr(hdc, DC_MAGIC))) {
485 /* Draw the top line */
486 prevpen = SelectObject32(hdc, TWEAK_Pen8095);
487 DC_SetupGCForPen(dc);
488 XDrawLine(display, dc->u.x.drawable, dc->u.x.gc, xc, yc1, xc,
489 yc2);
491 /* And the bottom line */
492 SelectObject32(hdc, TWEAK_PenFF95);
493 DC_SetupGCForPen(dc);
494 XDrawLine(display, dc->u.x.drawable, dc->u.x.gc, xc + 1, yc1, xc + 1,
495 yc2);
497 SelectObject32(hdc, prevpen);
500 return;