1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#define INCL_WIN
#define INCL_WINWINDOWMGR
#define INCL_WINSHELLDATA
#define INCL_DOSNLS
#define INCL_DOSERRORS
#include <os2.h>
#include <stdlib.h>
#include "nsLookAndFeel.h"
#include "nsFont.h"
#include "nsSize.h"
#include "nsStyleConsts.h"
static bool bIsDBCS;
static bool bIsDBCSSet = false;
nsLookAndFeel::nsLookAndFeel() : nsXPLookAndFeel()
{
}
nsLookAndFeel::~nsLookAndFeel()
{
}
nsresult
nsLookAndFeel::NativeGetColor(ColorID aID, nscolor &aColor)
{
nsresult res = NS_OK;
int idx;
switch (aID) {
case eColorID_WindowBackground:
idx = SYSCLR_WINDOW;
break;
case eColorID_WindowForeground:
idx = SYSCLR_WINDOWTEXT;
break;
case eColorID_WidgetBackground:
idx = SYSCLR_BUTTONMIDDLE;
break;
case eColorID_WidgetForeground:
idx = SYSCLR_WINDOWTEXT;
break;
case eColorID_WidgetSelectBackground:
idx = SYSCLR_HILITEBACKGROUND;
break;
case eColorID_WidgetSelectForeground:
idx = SYSCLR_HILITEFOREGROUND;
break;
case eColorID_Widget3DHighlight:
idx = SYSCLR_BUTTONLIGHT;
break;
case eColorID_Widget3DShadow:
idx = SYSCLR_BUTTONDARK;
break;
case eColorID_TextBackground:
idx = SYSCLR_WINDOW;
break;
case eColorID_TextForeground:
idx = SYSCLR_WINDOWTEXT;
break;
case eColorID_TextSelectBackground:
case eColorID_IMESelectedRawTextBackground:
case eColorID_IMESelectedConvertedTextBackground:
idx = SYSCLR_HILITEBACKGROUND;
break;
case eColorID_TextSelectForeground:
case eColorID_IMESelectedRawTextForeground:
case eColorID_IMESelectedConvertedTextForeground:
idx = SYSCLR_HILITEFOREGROUND;
break;
case eColorID_IMERawInputBackground:
case eColorID_IMEConvertedTextBackground:
aColor = NS_TRANSPARENT;
return NS_OK;
case eColorID_IMERawInputForeground:
case eColorID_IMEConvertedTextForeground:
aColor = NS_SAME_AS_FOREGROUND_COLOR;
return NS_OK;
case eColorID_IMERawInputUnderline:
case eColorID_IMEConvertedTextUnderline:
aColor = NS_SAME_AS_FOREGROUND_COLOR;
return NS_OK;
case eColorID_IMESelectedRawTextUnderline:
case eColorID_IMESelectedConvertedTextUnderline:
aColor = NS_TRANSPARENT;
return NS_OK;
case eColorID_SpellCheckerUnderline:
aColor = NS_RGB(0xff, 0, 0);
return NS_OK;
// New CSS 2 Color definitions
case eColorID_activeborder:
idx = SYSCLR_ACTIVEBORDER;
break;
case eColorID_activecaption:
idx = SYSCLR_ACTIVETITLETEXT;
break;
case eColorID_appworkspace:
idx = SYSCLR_APPWORKSPACE;
break;
case eColorID_background:
idx = SYSCLR_BACKGROUND;
break;
case eColorID_buttonface:
case eColorID__moz_buttonhoverface:
idx = SYSCLR_BUTTONMIDDLE;
break;
case eColorID_buttonhighlight:
idx = SYSCLR_BUTTONLIGHT;
break;
case eColorID_buttonshadow:
idx = SYSCLR_BUTTONDARK;
break;
case eColorID_buttontext:
case eColorID__moz_buttonhovertext:
idx = SYSCLR_MENUTEXT;
break;
case eColorID_captiontext:
idx = SYSCLR_WINDOWTEXT;
break;
case eColorID_graytext:
idx = SYSCLR_MENUDISABLEDTEXT;
break;
case eColorID_highlight:
case eColorID__moz_html_cellhighlight:
idx = SYSCLR_HILITEBACKGROUND;
break;
case eColorID_highlighttext:
case eColorID__moz_html_cellhighlighttext:
idx = SYSCLR_HILITEFOREGROUND;
break;
case eColorID_inactiveborder:
idx = SYSCLR_INACTIVEBORDER;
break;
case eColorID_inactivecaption:
idx = SYSCLR_INACTIVETITLE;
break;
case eColorID_inactivecaptiontext:
idx = SYSCLR_INACTIVETITLETEXT;
break;
case eColorID_infobackground:
aColor = NS_RGB( 255, 255, 228);
return res;
case eColorID_infotext:
idx = SYSCLR_WINDOWTEXT;
break;
case eColorID_menu:
idx = SYSCLR_MENU;
break;
case eColorID_menutext:
case eColorID__moz_menubartext:
idx = SYSCLR_MENUTEXT;
break;
case eColorID_scrollbar:
idx = SYSCLR_SCROLLBAR;
break;
case eColorID_threeddarkshadow:
idx = SYSCLR_BUTTONDARK;
break;
case eColorID_threedface:
idx = SYSCLR_BUTTONMIDDLE;
break;
case eColorID_threedhighlight:
idx = SYSCLR_BUTTONLIGHT;
break;
case eColorID_threedlightshadow:
idx = SYSCLR_BUTTONMIDDLE;
break;
case eColorID_threedshadow:
idx = SYSCLR_BUTTONDARK;
break;
case eColorID_window:
idx = SYSCLR_WINDOW;
break;
case eColorID_windowframe:
idx = SYSCLR_WINDOWFRAME;
break;
case eColorID_windowtext:
idx = SYSCLR_WINDOWTEXT;
break;
case eColorID__moz_eventreerow:
case eColorID__moz_oddtreerow:
case eColorID__moz_field:
case eColorID__moz_combobox:
idx = SYSCLR_ENTRYFIELD;
break;
case eColorID__moz_fieldtext:
case eColorID__moz_comboboxtext:
idx = SYSCLR_WINDOWTEXT;
break;
case eColorID__moz_dialog:
case eColorID__moz_cellhighlight:
idx = SYSCLR_DIALOGBACKGROUND;
break;
case eColorID__moz_dialogtext:
case eColorID__moz_cellhighlighttext:
idx = SYSCLR_WINDOWTEXT;
break;
case eColorID__moz_buttondefault:
idx = SYSCLR_BUTTONDEFAULT;
break;
case eColorID__moz_menuhover:
if (WinQuerySysColor(HWND_DESKTOP, SYSCLR_MENUHILITEBGND, 0) ==
WinQuerySysColor(HWND_DESKTOP, SYSCLR_MENU, 0)) {
// if this happens, we would paint menu selections unreadable
// (we are most likely on Warp3), so let's fake a dark grey
// background for the selected menu item
aColor = NS_RGB( 132, 130, 132);
return res;
} else {
idx = SYSCLR_MENUHILITEBGND;
}
break;
case eColorID__moz_menuhovertext:
case eColorID__moz_menubarhovertext:
if (WinQuerySysColor(HWND_DESKTOP, SYSCLR_MENUHILITEBGND, 0) ==
WinQuerySysColor(HWND_DESKTOP, SYSCLR_MENU, 0)) {
// white text to be readable on dark grey
aColor = NS_RGB( 255, 255, 255);
return res;
} else {
idx = SYSCLR_MENUHILITE;
}
break;
case eColorID__moz_nativehyperlinktext:
aColor = NS_RGB( 0, 0, 255);
return res;
default:
idx = SYSCLR_WINDOW;
break;
}
long lColor = WinQuerySysColor( HWND_DESKTOP, idx, 0);
int iRed = (lColor & RGB_RED) >> 16;
int iGreen = (lColor & RGB_GREEN) >> 8;
int iBlue = (lColor & RGB_BLUE);
aColor = NS_RGB( iRed, iGreen, iBlue);
return res;
}
nsresult
nsLookAndFeel::GetIntImpl(IntID aID, int32_t &aResult)
{
nsresult res = nsXPLookAndFeel::GetIntImpl(aID, aResult);
if (NS_SUCCEEDED(res))
return res;
res = NS_OK;
switch (aID) {
case eIntID_CaretBlinkTime:
aResult = WinQuerySysValue( HWND_DESKTOP, SV_CURSORRATE);
break;
case eIntID_CaretWidth:
aResult = 1;
break;
case eIntID_ShowCaretDuringSelection:
aResult = 0;
break;
case eIntID_SelectTextfieldsOnKeyFocus:
// Do not select textfield content when focused by kbd
// used by nsEventStateManager::sTextfieldSelectModel
aResult = 0;
break;
case eIntID_SubmenuDelay:
aResult = 300;
break;
case eIntID_TooltipDelay:
aResult = 500;
break;
case eIntID_MenusCanOverlapOSBar:
// we want XUL popups to be able to overlap the task bar.
aResult = 1;
break;
case eIntID_ScrollArrowStyle:
aResult = eScrollArrowStyle_Single;
break;
case eIntID_ScrollSliderStyle:
aResult = eScrollThumbStyle_Proportional;
break;
case eIntID_TreeOpenDelay:
aResult = 1000;
break;
case eIntID_TreeCloseDelay:
aResult = 0;
break;
case eIntID_TreeLazyScrollDelay:
aResult = 150;
break;
case eIntID_TreeScrollDelay:
aResult = 100;
break;
case eIntID_TreeScrollLinesMax:
aResult = 3;
break;
case eIntID_DWMCompositor:
case eIntID_WindowsClassic:
case eIntID_WindowsDefaultTheme:
case eIntID_TouchEnabled:
case eIntID_WindowsThemeIdentifier:
aResult = 0;
res = NS_ERROR_NOT_IMPLEMENTED;
break;
case eIntID_MacGraphiteTheme:
case eIntID_MacLionTheme:
case eIntID_MaemoClassic:
aResult = 0;
res = NS_ERROR_NOT_IMPLEMENTED;
break;
case eIntID_IMERawInputUnderlineStyle:
case eIntID_IMEConvertedTextUnderlineStyle:
aResult = NS_STYLE_TEXT_DECORATION_STYLE_SOLID;
break;
case eIntID_IMESelectedRawTextUnderlineStyle:
case eIntID_IMESelectedConvertedTextUnderline:
aResult = NS_STYLE_TEXT_DECORATION_STYLE_NONE;
break;
case eIntID_SpellCheckerUnderlineStyle:
aResult = NS_STYLE_TEXT_DECORATION_STYLE_WAVY;
break;
case eIntID_ScrollbarButtonAutoRepeatBehavior:
aResult = 0;
break;
case eIntID_SwipeAnimationEnabled:
aResult = 0;
break;
default:
aResult = 0;
res = NS_ERROR_FAILURE;
}
return res;
}
nsresult
nsLookAndFeel::GetFloatImpl(FloatID aID, float &aResult)
{
nsresult res = nsXPLookAndFeel::GetFloatImpl(aID, aResult);
if (NS_SUCCEEDED(res))
return res;
res = NS_OK;
switch (aID) {
case eFloatID_IMEUnderlineRelativeSize:
aResult = 1.0f;
break;
case eFloatID_SpellCheckerUnderlineRelativeSize:
aResult = 1.0f;
break;
default:
aResult = -1.0;
res = NS_ERROR_FAILURE;
}
return res;
}
/* Helper function to determine if we are running on DBCS */
static bool
IsDBCS()
{
if (!bIsDBCSSet) {
APIRET rc;
COUNTRYCODE ctrycodeInfo = {0};
CHAR achDBCSInfo[12] = {0}; // DBCS environmental vector
ctrycodeInfo.country = 0; // current country
ctrycodeInfo.codepage = 0; // current codepage
rc = DosQueryDBCSEnv(sizeof(achDBCSInfo), &ctrycodeInfo, achDBCSInfo);
if (rc == NO_ERROR) {
// DBCS countries will have at least one nonzero byte in the
// first four bytes of the DBCS environmental vector
bIsDBCS = (achDBCSInfo[0] != 0 || achDBCSInfo[1] != 0 ||
achDBCSInfo[2] != 0 || achDBCSInfo[3] != 0);
} else {
bIsDBCS = false;
}
bIsDBCSSet = true;
}
return bIsDBCS;
}
/* Helper function to query font from INI file */
static void
QueryFontFromINI(char* fontType, char* fontName, ULONG ulLength)
{
ULONG ulMaxNameL = ulLength;
// We must use PrfQueryProfileData here, because some users have
// binary font data in their INI files.
if (PrfQueryProfileData(HINI_USER,
(PCSZ)"PM_SystemFonts",
(PCSZ)fontType,
fontName, &ulMaxNameL)) {
// PrfQueryProfileData does not nul-terminate for us.
fontName[ulMaxNameL] = '\0';
} else {
// If there was no entry in the INI, default to something sensible.
// Make sure to use a DBCS-capable font in a DBCS-capable environment.
if (IsDBCS()) {
strcpy(fontName, "9.WarpSans Combined");
} else {
strcpy(fontName, "9.WarpSans");
}
}
}
/*
* Query the font used for various CSS properties (aID) from the system.
* For OS/2, only very few fonts are defined in the system, so most of the IDs
* resolve to the same system font.
* The font queried will give back a string like
* 9.WarpSans Bold
* 12.Times New Roman Bold Italic
* 10.Times New Roman.Strikeout.Underline
* 20.Bitstream Vera Sans Mono Obli
* (always restricted to 32 chars, at least before the second dot)
* We use the value before the dot as the font size (in pt, and convert it to
* px using the screen resolution) and then try to use the rest of the string
* to determine the font style from it.
*/
bool
nsLookAndFeel::GetFont(FontID aID, nsString& aFontName,
gfxFontStyle& aFontStyle)
{
char szFontNameSize[MAXNAMEL];
switch (aID)
{
case eFont_Icon:
QueryFontFromINI("IconText", szFontNameSize, MAXNAMEL);
break;
case eFont_Menu:
QueryFontFromINI("Menus", szFontNameSize, MAXNAMEL);
break;
case eFont_Caption:
case eFont_MessageBox:
case eFont_SmallCaption:
case eFont_StatusBar:
case eFont_Tooltips:
case eFont_Widget:
case eFont_Window: // css3
case eFont_Document:
case eFont_Workspace:
case eFont_Desktop:
case eFont_Info:
case eFont_Dialog:
case eFont_Button:
case eFont_PullDownMenu:
case eFont_List:
case eFont_Field:
QueryFontFromINI("WindowText", szFontNameSize, MAXNAMEL);
break;
default:
NS_WARNING("None of the listed font types, using WarpSans");
if (!IsDBCS()) {
strcpy(szFontNameSize, "9.WarpSans");
} else {
strcpy(szFontNameSize, "9.WarpSans Combined");
}
}
char *szFacename = strchr(szFontNameSize, '.');
if (!szFacename || (*(szFacename++) == '\0'))
return false;
// local DPI for size will be taken into account below
aFontStyle.size = atof(szFontNameSize);
// determine DPI resolution of screen device to compare compute
// font size in pixels
HPS ps = WinGetScreenPS(HWND_DESKTOP);
HDC dc = GpiQueryDevice(ps);
// effective vertical resolution in DPI
LONG vertScreenRes = 120; // assume 120 dpi as default
DevQueryCaps(dc, CAPS_VERTICAL_FONT_RES, 1, &vertScreenRes);
WinReleasePS(ps);
// now scale to make pixels from points (1 pt = 1/72in)
aFontStyle.size *= vertScreenRes / 72.0;
NS_ConvertUTF8toUTF16 fontFace(szFacename);
int pos = 0;
// this is a system font in any case
aFontStyle.systemFont = true;
// bold fonts should have " Bold" in their names, at least we hope that they
// do, otherwise it's bad luck
NS_NAMED_LITERAL_CSTRING(spcBold, " Bold");
if ((pos = fontFace.Find(spcBold.get(), false, 0, -1)) > -1) {
aFontStyle.weight = NS_FONT_WEIGHT_BOLD;
// strip the attribute, now that we have set it in the gfxFontStyle
fontFace.Cut(pos, spcBold.Length());
} else {
aFontStyle.weight = NS_FONT_WEIGHT_NORMAL;
}
// FIXME: Set aFontStyle.stretch correctly!
aFontStyle.stretch = NS_FONT_STRETCH_NORMAL;
// similar hopes for italic and oblique fonts...
NS_NAMED_LITERAL_CSTRING(spcItalic, " Italic");
NS_NAMED_LITERAL_CSTRING(spcOblique, " Oblique");
NS_NAMED_LITERAL_CSTRING(spcObli, " Obli");
if ((pos = fontFace.Find(spcItalic.get(), false, 0, -1)) > -1) {
aFontStyle.style = NS_FONT_STYLE_ITALIC;
fontFace.Cut(pos, spcItalic.Length());
} else if ((pos = fontFace.Find(spcOblique.get(), false, 0, -1)) > -1) {
// oblique fonts are rare on OS/2 and not specially supported by
// the GPI system, but at least we are trying...
aFontStyle.style = NS_FONT_STYLE_OBLIQUE;
fontFace.Cut(pos, spcOblique.Length());
} else if ((pos = fontFace.Find(spcObli.get(), false, 0, -1)) > -1) {
// especially oblique often gets cut by the 32 char limit to "Obli",
// so search for that, too (anything shorter would be ambiguous)
aFontStyle.style = NS_FONT_STYLE_OBLIQUE;
// In this case, assume that this is the last property in the line
// and cut off everything else, too
// This is needed in case it was really Obliq or Obliqu...
fontFace.Cut(pos, fontFace.Length());
} else {
aFontStyle.style = NS_FONT_STYLE_NORMAL;
}
// just throw away any modifiers that are separated by dots (which are either
// .Strikeout, .Underline, or .Outline, none of which have a corresponding
// gfxFont property)
if ((pos = fontFace.Find(".", false, 0, -1)) > -1) {
fontFace.Cut(pos, fontFace.Length());
}
// seems like we need quotes around the font name
NS_NAMED_LITERAL_STRING(quote, "\"");
aFontName = quote + fontFace + quote;
return true;
}
|