1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #define INCL_WINWINDOWMGR
8 #define INCL_WINSHELLDATA
10 #define INCL_DOSERRORS
14 #include "nsLookAndFeel.h"
17 #include "nsStyleConsts.h"
20 static bool bIsDBCSSet
= false;
22 nsLookAndFeel::nsLookAndFeel() : nsXPLookAndFeel()
26 nsLookAndFeel::~nsLookAndFeel()
31 nsLookAndFeel::NativeGetColor(ColorID aID
, nscolor
&aColor
)
37 case eColorID_WindowBackground
:
40 case eColorID_WindowForeground
:
41 idx
= SYSCLR_WINDOWTEXT
;
43 case eColorID_WidgetBackground
:
44 idx
= SYSCLR_BUTTONMIDDLE
;
46 case eColorID_WidgetForeground
:
47 idx
= SYSCLR_WINDOWTEXT
;
49 case eColorID_WidgetSelectBackground
:
50 idx
= SYSCLR_HILITEBACKGROUND
;
52 case eColorID_WidgetSelectForeground
:
53 idx
= SYSCLR_HILITEFOREGROUND
;
55 case eColorID_Widget3DHighlight
:
56 idx
= SYSCLR_BUTTONLIGHT
;
58 case eColorID_Widget3DShadow
:
59 idx
= SYSCLR_BUTTONDARK
;
61 case eColorID_TextBackground
:
64 case eColorID_TextForeground
:
65 idx
= SYSCLR_WINDOWTEXT
;
67 case eColorID_TextSelectBackground
:
68 case eColorID_IMESelectedRawTextBackground
:
69 case eColorID_IMESelectedConvertedTextBackground
:
70 idx
= SYSCLR_HILITEBACKGROUND
;
72 case eColorID_TextSelectForeground
:
73 case eColorID_IMESelectedRawTextForeground
:
74 case eColorID_IMESelectedConvertedTextForeground
:
75 idx
= SYSCLR_HILITEFOREGROUND
;
77 case eColorID_IMERawInputBackground
:
78 case eColorID_IMEConvertedTextBackground
:
79 aColor
= NS_TRANSPARENT
;
81 case eColorID_IMERawInputForeground
:
82 case eColorID_IMEConvertedTextForeground
:
83 aColor
= NS_SAME_AS_FOREGROUND_COLOR
;
85 case eColorID_IMERawInputUnderline
:
86 case eColorID_IMEConvertedTextUnderline
:
87 aColor
= NS_SAME_AS_FOREGROUND_COLOR
;
89 case eColorID_IMESelectedRawTextUnderline
:
90 case eColorID_IMESelectedConvertedTextUnderline
:
91 aColor
= NS_TRANSPARENT
;
93 case eColorID_SpellCheckerUnderline
:
94 aColor
= NS_RGB(0xff, 0, 0);
97 // New CSS 2 Color definitions
98 case eColorID_activeborder
:
99 idx
= SYSCLR_ACTIVEBORDER
;
101 case eColorID_activecaption
:
102 idx
= SYSCLR_ACTIVETITLETEXT
;
104 case eColorID_appworkspace
:
105 idx
= SYSCLR_APPWORKSPACE
;
107 case eColorID_background
:
108 idx
= SYSCLR_BACKGROUND
;
110 case eColorID_buttonface
:
111 case eColorID__moz_buttonhoverface
:
112 idx
= SYSCLR_BUTTONMIDDLE
;
114 case eColorID_buttonhighlight
:
115 idx
= SYSCLR_BUTTONLIGHT
;
117 case eColorID_buttonshadow
:
118 idx
= SYSCLR_BUTTONDARK
;
120 case eColorID_buttontext
:
121 case eColorID__moz_buttonhovertext
:
122 idx
= SYSCLR_MENUTEXT
;
124 case eColorID_captiontext
:
125 idx
= SYSCLR_WINDOWTEXT
;
127 case eColorID_graytext
:
128 idx
= SYSCLR_MENUDISABLEDTEXT
;
130 case eColorID_highlight
:
131 case eColorID__moz_html_cellhighlight
:
132 idx
= SYSCLR_HILITEBACKGROUND
;
134 case eColorID_highlighttext
:
135 case eColorID__moz_html_cellhighlighttext
:
136 idx
= SYSCLR_HILITEFOREGROUND
;
138 case eColorID_inactiveborder
:
139 idx
= SYSCLR_INACTIVEBORDER
;
141 case eColorID_inactivecaption
:
142 idx
= SYSCLR_INACTIVETITLE
;
144 case eColorID_inactivecaptiontext
:
145 idx
= SYSCLR_INACTIVETITLETEXT
;
147 case eColorID_infobackground
:
148 aColor
= NS_RGB( 255, 255, 228);
150 case eColorID_infotext
:
151 idx
= SYSCLR_WINDOWTEXT
;
156 case eColorID_menutext
:
157 case eColorID__moz_menubartext
:
158 idx
= SYSCLR_MENUTEXT
;
160 case eColorID_scrollbar
:
161 idx
= SYSCLR_SCROLLBAR
;
163 case eColorID_threeddarkshadow
:
164 idx
= SYSCLR_BUTTONDARK
;
166 case eColorID_threedface
:
167 idx
= SYSCLR_BUTTONMIDDLE
;
169 case eColorID_threedhighlight
:
170 idx
= SYSCLR_BUTTONLIGHT
;
172 case eColorID_threedlightshadow
:
173 idx
= SYSCLR_BUTTONMIDDLE
;
175 case eColorID_threedshadow
:
176 idx
= SYSCLR_BUTTONDARK
;
178 case eColorID_window
:
181 case eColorID_windowframe
:
182 idx
= SYSCLR_WINDOWFRAME
;
184 case eColorID_windowtext
:
185 idx
= SYSCLR_WINDOWTEXT
;
187 case eColorID__moz_eventreerow
:
188 case eColorID__moz_oddtreerow
:
189 case eColorID__moz_field
:
190 case eColorID__moz_combobox
:
191 idx
= SYSCLR_ENTRYFIELD
;
193 case eColorID__moz_fieldtext
:
194 case eColorID__moz_comboboxtext
:
195 idx
= SYSCLR_WINDOWTEXT
;
197 case eColorID__moz_dialog
:
198 case eColorID__moz_cellhighlight
:
199 idx
= SYSCLR_DIALOGBACKGROUND
;
201 case eColorID__moz_dialogtext
:
202 case eColorID__moz_cellhighlighttext
:
203 idx
= SYSCLR_WINDOWTEXT
;
205 case eColorID__moz_buttondefault
:
206 idx
= SYSCLR_BUTTONDEFAULT
;
208 case eColorID__moz_menuhover
:
209 if (WinQuerySysColor(HWND_DESKTOP
, SYSCLR_MENUHILITEBGND
, 0) ==
210 WinQuerySysColor(HWND_DESKTOP
, SYSCLR_MENU
, 0)) {
211 // if this happens, we would paint menu selections unreadable
212 // (we are most likely on Warp3), so let's fake a dark grey
213 // background for the selected menu item
214 aColor
= NS_RGB( 132, 130, 132);
217 idx
= SYSCLR_MENUHILITEBGND
;
220 case eColorID__moz_menuhovertext
:
221 case eColorID__moz_menubarhovertext
:
222 if (WinQuerySysColor(HWND_DESKTOP
, SYSCLR_MENUHILITEBGND
, 0) ==
223 WinQuerySysColor(HWND_DESKTOP
, SYSCLR_MENU
, 0)) {
224 // white text to be readable on dark grey
225 aColor
= NS_RGB( 255, 255, 255);
228 idx
= SYSCLR_MENUHILITE
;
231 case eColorID__moz_nativehyperlinktext
:
232 aColor
= NS_RGB( 0, 0, 255);
239 long lColor
= WinQuerySysColor( HWND_DESKTOP
, idx
, 0);
241 int iRed
= (lColor
& RGB_RED
) >> 16;
242 int iGreen
= (lColor
& RGB_GREEN
) >> 8;
243 int iBlue
= (lColor
& RGB_BLUE
);
245 aColor
= NS_RGB( iRed
, iGreen
, iBlue
);
251 nsLookAndFeel::GetIntImpl(IntID aID
, int32_t &aResult
)
253 nsresult res
= nsXPLookAndFeel::GetIntImpl(aID
, aResult
);
254 if (NS_SUCCEEDED(res
))
259 case eIntID_CaretBlinkTime
:
260 aResult
= WinQuerySysValue( HWND_DESKTOP
, SV_CURSORRATE
);
262 case eIntID_CaretWidth
:
265 case eIntID_ShowCaretDuringSelection
:
268 case eIntID_SelectTextfieldsOnKeyFocus
:
269 // Do not select textfield content when focused by kbd
270 // used by nsEventStateManager::sTextfieldSelectModel
273 case eIntID_SubmenuDelay
:
276 case eIntID_TooltipDelay
:
279 case eIntID_MenusCanOverlapOSBar
:
280 // we want XUL popups to be able to overlap the task bar.
283 case eIntID_ScrollArrowStyle
:
284 aResult
= eScrollArrowStyle_Single
;
286 case eIntID_ScrollSliderStyle
:
287 aResult
= eScrollThumbStyle_Proportional
;
289 case eIntID_TreeOpenDelay
:
292 case eIntID_TreeCloseDelay
:
295 case eIntID_TreeLazyScrollDelay
:
298 case eIntID_TreeScrollDelay
:
301 case eIntID_TreeScrollLinesMax
:
304 case eIntID_DWMCompositor
:
305 case eIntID_WindowsClassic
:
306 case eIntID_WindowsDefaultTheme
:
307 case eIntID_TouchEnabled
:
308 case eIntID_WindowsThemeIdentifier
:
309 case eIntID_OperatingSystemVersionIdentifier
:
311 res
= NS_ERROR_NOT_IMPLEMENTED
;
313 case eIntID_MacGraphiteTheme
:
314 case eIntID_MacLionTheme
:
316 res
= NS_ERROR_NOT_IMPLEMENTED
;
318 case eIntID_IMERawInputUnderlineStyle
:
319 case eIntID_IMEConvertedTextUnderlineStyle
:
320 aResult
= NS_STYLE_TEXT_DECORATION_STYLE_SOLID
;
322 case eIntID_IMESelectedRawTextUnderlineStyle
:
323 case eIntID_IMESelectedConvertedTextUnderline
:
324 aResult
= NS_STYLE_TEXT_DECORATION_STYLE_NONE
;
326 case eIntID_SpellCheckerUnderlineStyle
:
327 aResult
= NS_STYLE_TEXT_DECORATION_STYLE_WAVY
;
329 case eIntID_ScrollbarButtonAutoRepeatBehavior
:
332 case eIntID_SwipeAnimationEnabled
:
338 res
= NS_ERROR_FAILURE
;
344 nsLookAndFeel::GetFloatImpl(FloatID aID
, float &aResult
)
346 nsresult res
= nsXPLookAndFeel::GetFloatImpl(aID
, aResult
);
347 if (NS_SUCCEEDED(res
))
352 case eFloatID_IMEUnderlineRelativeSize
:
355 case eFloatID_SpellCheckerUnderlineRelativeSize
:
360 res
= NS_ERROR_FAILURE
;
365 /* Helper function to determine if we are running on DBCS */
371 COUNTRYCODE ctrycodeInfo
= {0};
372 CHAR achDBCSInfo
[12] = {0}; // DBCS environmental vector
373 ctrycodeInfo
.country
= 0; // current country
374 ctrycodeInfo
.codepage
= 0; // current codepage
376 rc
= DosQueryDBCSEnv(sizeof(achDBCSInfo
), &ctrycodeInfo
, achDBCSInfo
);
377 if (rc
== NO_ERROR
) {
378 // DBCS countries will have at least one nonzero byte in the
379 // first four bytes of the DBCS environmental vector
380 bIsDBCS
= (achDBCSInfo
[0] != 0 || achDBCSInfo
[1] != 0 ||
381 achDBCSInfo
[2] != 0 || achDBCSInfo
[3] != 0);
390 /* Helper function to query font from INI file */
392 QueryFontFromINI(char* fontType
, char* fontName
, ULONG ulLength
)
394 ULONG ulMaxNameL
= ulLength
;
396 // We must use PrfQueryProfileData here, because some users have
397 // binary font data in their INI files.
398 if (PrfQueryProfileData(HINI_USER
,
399 (PCSZ
)"PM_SystemFonts",
401 fontName
, &ulMaxNameL
)) {
402 // PrfQueryProfileData does not nul-terminate for us.
403 fontName
[ulMaxNameL
] = '\0';
405 // If there was no entry in the INI, default to something sensible.
406 // Make sure to use a DBCS-capable font in a DBCS-capable environment.
408 strcpy(fontName
, "9.WarpSans Combined");
410 strcpy(fontName
, "9.WarpSans");
416 * Query the font used for various CSS properties (aID) from the system.
417 * For OS/2, only very few fonts are defined in the system, so most of the IDs
418 * resolve to the same system font.
419 * The font queried will give back a string like
421 * 12.Times New Roman Bold Italic
422 * 10.Times New Roman.Strikeout.Underline
423 * 20.Bitstream Vera Sans Mono Obli
424 * (always restricted to 32 chars, at least before the second dot)
425 * We use the value before the dot as the font size (in pt, and convert it to
426 * px using the screen resolution) and then try to use the rest of the string
427 * to determine the font style from it.
430 nsLookAndFeel::GetFont(FontID aID
, nsString
& aFontName
,
431 gfxFontStyle
& aFontStyle
)
433 char szFontNameSize
[MAXNAMEL
];
438 QueryFontFromINI("IconText", szFontNameSize
, MAXNAMEL
);
442 QueryFontFromINI("Menus", szFontNameSize
, MAXNAMEL
);
446 case eFont_MessageBox
:
447 case eFont_SmallCaption
:
448 case eFont_StatusBar
:
452 case eFont_Window
: // css3
454 case eFont_Workspace
:
459 case eFont_PullDownMenu
:
462 QueryFontFromINI("WindowText", szFontNameSize
, MAXNAMEL
);
466 NS_WARNING("None of the listed font types, using WarpSans");
468 strcpy(szFontNameSize
, "9.WarpSans");
470 strcpy(szFontNameSize
, "9.WarpSans Combined");
474 char *szFacename
= strchr(szFontNameSize
, '.');
475 if (!szFacename
|| (*(szFacename
++) == '\0'))
478 // local DPI for size will be taken into account below
479 aFontStyle
.size
= atof(szFontNameSize
);
481 // determine DPI resolution of screen device to compare compute
482 // font size in pixels
483 HPS ps
= WinGetScreenPS(HWND_DESKTOP
);
484 HDC dc
= GpiQueryDevice(ps
);
485 // effective vertical resolution in DPI
486 LONG vertScreenRes
= 120; // assume 120 dpi as default
487 DevQueryCaps(dc
, CAPS_VERTICAL_FONT_RES
, 1, &vertScreenRes
);
490 // now scale to make pixels from points (1 pt = 1/72in)
491 aFontStyle
.size
*= vertScreenRes
/ 72.0;
493 NS_ConvertUTF8toUTF16
fontFace(szFacename
);
496 // this is a system font in any case
497 aFontStyle
.systemFont
= true;
499 // bold fonts should have " Bold" in their names, at least we hope that they
500 // do, otherwise it's bad luck
501 NS_NAMED_LITERAL_CSTRING(spcBold
, " Bold");
502 if ((pos
= fontFace
.Find(spcBold
.get(), false, 0, -1)) > -1) {
503 aFontStyle
.weight
= NS_FONT_WEIGHT_BOLD
;
504 // strip the attribute, now that we have set it in the gfxFontStyle
505 fontFace
.Cut(pos
, spcBold
.Length());
507 aFontStyle
.weight
= NS_FONT_WEIGHT_NORMAL
;
510 // FIXME: Set aFontStyle.stretch correctly!
511 aFontStyle
.stretch
= NS_FONT_STRETCH_NORMAL
;
513 // similar hopes for italic and oblique fonts...
514 NS_NAMED_LITERAL_CSTRING(spcItalic
, " Italic");
515 NS_NAMED_LITERAL_CSTRING(spcOblique
, " Oblique");
516 NS_NAMED_LITERAL_CSTRING(spcObli
, " Obli");
517 if ((pos
= fontFace
.Find(spcItalic
.get(), false, 0, -1)) > -1) {
518 aFontStyle
.style
= NS_FONT_STYLE_ITALIC
;
519 fontFace
.Cut(pos
, spcItalic
.Length());
520 } else if ((pos
= fontFace
.Find(spcOblique
.get(), false, 0, -1)) > -1) {
521 // oblique fonts are rare on OS/2 and not specially supported by
522 // the GPI system, but at least we are trying...
523 aFontStyle
.style
= NS_FONT_STYLE_OBLIQUE
;
524 fontFace
.Cut(pos
, spcOblique
.Length());
525 } else if ((pos
= fontFace
.Find(spcObli
.get(), false, 0, -1)) > -1) {
526 // especially oblique often gets cut by the 32 char limit to "Obli",
527 // so search for that, too (anything shorter would be ambiguous)
528 aFontStyle
.style
= NS_FONT_STYLE_OBLIQUE
;
529 // In this case, assume that this is the last property in the line
530 // and cut off everything else, too
531 // This is needed in case it was really Obliq or Obliqu...
532 fontFace
.Cut(pos
, fontFace
.Length());
534 aFontStyle
.style
= NS_FONT_STYLE_NORMAL
;
537 // just throw away any modifiers that are separated by dots (which are either
538 // .Strikeout, .Underline, or .Outline, none of which have a corresponding
540 if ((pos
= fontFace
.Find(".", false, 0, -1)) > -1) {
541 fontFace
.Cut(pos
, fontFace
.Length());
544 // seems like we need quotes around the font name
545 NS_NAMED_LITERAL_STRING(quote
, "\"");
546 aFontName
= quote
+ fontFace
+ quote
;