00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <stdio.h>
00022 #include <stdlib.h>
00023 #include "user32.h"
00024 #include "syscolor.h"
00025 #include "options.h"
00026 #include "oslibwin.h"
00027
00028 #define DBG_LOCALLOG DBG_syscolor
00029 #include "dbglocal.h"
00030
00031 #define CTLCOLOR_MAX CTLCOLOR_STATIC
00032
00033
00034 #define NUM_OPEN32_SYSCOLORS 21
00035
00036 #define NUM_SYS_COLORS (COLOR_GRADIENTINACTIVECAPTION+1)
00037
00038 BOOL USEWINCOLORS = 1;
00039
00040
00041
00042 static COLORREF SysColors[NUM_SYS_COLORS] =
00043 {
00044 RGB(198,195,198),
00045 RGB(0,0,0),
00046 RGB(0,0,128),
00047 RGB(128,128,128),
00048 RGB(198,195,198),
00049 RGB(255,255,255),
00050 RGB(0,0,0),
00051 RGB(0,0,0),
00052 RGB(0,0,0),
00053 RGB(255,255,255),
00054 RGB(198,195,198),
00055 RGB(198,195,198),
00056 RGB(128,128,128),
00057 RGB(0,0,128),
00058 RGB(255,255,255),
00059 RGB(198,195,198),
00060 RGB(128,128,128),
00061 RGB(128,128,128),
00062 RGB(0,0,0),
00063 RGB(198,195,198),
00064 RGB(255,255,255),
00065 RGB(0,0,0),
00066 RGB(198,195,198),
00067 RGB(0,0,0),
00068 RGB(255,255,255),
00069 RGB(198,195,198),
00070 RGB(0,0,255),
00071 RGB(16,136,208),
00072
00073 RGB(198,195,198)
00074 };
00075
00076 static char* ColorNames[NUM_SYS_COLORS] =
00077 {
00078 "SCROLLBAR",
00079 "COLOR_BACKGROUND",
00080 "ACTIVECAPTION",
00081 "INACTIVECAPTION",
00082 "MENU",
00083 "WINDOW",
00084 "WINDOWFRAME",
00085 "MENUTEXT",
00086 "WINDOWTEXT",
00087 "CAPTIONTEXT",
00088 "ACTIVEBORDER",
00089 "INACTIVEBORDER",
00090 "APPWORKSPACE",
00091 "HIGHLIGHT",
00092 "HIGHLIGHTTEXT",
00093 "BTNFACE",
00094 "BTNSHADOW",
00095 "GRAYTEXT",
00096 "BTNTEXT",
00097 "INACTIVECAPTIONTEXT",
00098 "BTNHIGHLIGHT",
00099 "3DDKSHADOW",
00100 "3DLIGHT",
00101 "INFOTEXT",
00102 "INFOBK",
00103 "ALTERNATEBTNFACE",
00104 "COLOR_HOTLIGHT",
00105 "GRADIENTACTIVECAPTION",
00106 "GRADIENTINACTIVECAPTION"
00107 };
00108
00109 static HPEN SysColorPens[NUM_SYS_COLORS] = {0};
00110 static HBRUSH SysColorBrushes[NUM_SYS_COLORS] = {0};
00111 static BOOL fColorInit = FALSE;
00112
00113 #define MAKE_SOLID(color) \
00114 (PALETTEINDEX(GetNearestPaletteIndex(STOCK_DEFAULT_PALETTE,(color))))
00115
00116 static const WORD wPattern55AA[] =
00117 {
00118 0x5555, 0xaaaa, 0x5555, 0xaaaa,
00119 0x5555, 0xaaaa, 0x5555, 0xaaaa
00120 };
00121
00122 static HBRUSH hPattern55AABrush = 0;
00123 static HBITMAP hPattern55AABitmap = 0;
00124
00125 static void SYSCOLOR_SetColor( int index, COLORREF color )
00126 {
00127 if (index < 0 || index >= NUM_SYS_COLORS || (SysColors[index] == color && fColorInit)) return;
00128 SysColors[index] = color;
00129
00130 if (SysColorPens[index]) DeleteObject(SysColorPens[index]);
00131 SysColorPens[index] = CreatePen(PS_SOLID, 1, color);
00132
00133 if (SysColorBrushes[index]) DeleteObject(SysColorBrushes[index]);
00134 SysColorBrushes[index] = CreateSolidBrush(color);
00135 }
00136
00137
00138 void SYSCOLOR_Load(void)
00139 {
00140 int i, r, g, b;
00141 const char * const *p;
00142 char buffer[100];
00143
00144 if (PROFILE_GetOdinIniBool(ODINCOLORS,"SaveColors",FALSE))
00145 {
00146 for (i = 0,p = ColorNames; i < NUM_SYS_COLORS; i++, p++)
00147 {
00148 if (PROFILE_GetOdinIniString(ODINCOLORS,(LPCSTR)*p,"",buffer,sizeof(buffer)))
00149 {
00150 if (sscanf(buffer,"%d %d %d",&r,&g,&b) == 3) SysColors[i] = RGB(r,g,b);
00151 }
00152 }
00153 }
00154 }
00155
00156
00157 void SYSCOLOR_Save(void)
00158 {
00159 INT x;
00160 const char * const *p;
00161 char buffer[100];
00162
00163 if (!fColorInit) return;
00164
00165 if (PROFILE_GetOdinIniBool(ODINCOLORS,"SaveColors",FALSE))
00166 {
00167 for (x = 0,p = ColorNames;x < NUM_SYS_COLORS;x++,p++)
00168 {
00169 INT color = SysColors[x];
00170
00171 sprintf(buffer,"%d %d %d",color & 0xFF,(color & 0xFF00) >> 8,(color & 0xFF0000) >> 16);
00172 PROFILE_SetOdinIniString(ODINCOLORS,(LPCSTR)*p,(LPCSTR)buffer);
00173 }
00174 }
00175 }
00176
00177
00178 void SYSCOLOR_Init(int fOverride)
00179 {
00180 INT x;
00181
00182 if(fOverride == -1) {
00183 USEWINCOLORS = PROFILE_GetOdinIniBool(ODINCOLORS,"UseWinColors",TRUE);
00184 }
00185 else USEWINCOLORS = fOverride;
00186
00187 SYSCOLOR_Load();
00188 if (USEWINCOLORS)
00189 for (x = 0;x < NUM_SYS_COLORS;x++) SYSCOLOR_SetColor(x,SysColors[x]);
00190 else
00191 for (x = 0;x < NUM_SYS_COLORS;x++) {
00192 if(x < NUM_OPEN32_SYSCOLORS)
00193 SYSCOLOR_SetColor(x,O32_GetSysColor(x));
00194 else SYSCOLOR_SetColor(x,SysColors[x]);
00195 }
00196 fColorInit = TRUE;
00197 }
00198
00199
00200 COLORREF WIN32API GetSysColor(INT nIndex)
00201 {
00202 if(fColorInit == FALSE)
00203 {
00204 SYSCOLOR_Init();
00205 fColorInit = TRUE;
00206 }
00207
00208 if ((nIndex >= 0) && (nIndex < NUM_SYS_COLORS))
00209 {
00210 if (USEWINCOLORS) return SysColors[nIndex];
00211 else
00212 if(nIndex < NUM_OPEN32_SYSCOLORS)
00213 return O32_GetSysColor(nIndex);
00214 else return SysColors[nIndex];
00215 }
00216 else return 0;
00217 }
00218
00219
00220 BOOL WIN32API SetSysColors(INT nChanges, const INT *lpSysColor,
00221 const COLORREF *lpColorValues)
00222 {
00223 int i;
00224
00225 if(fColorInit == FALSE)
00226 {
00227 SYSCOLOR_Init();
00228 fColorInit = TRUE;
00229 }
00230
00231 dprintf(("SetSysColors\n"));
00232
00233 O32_SetSysColors(nChanges, lpSysColor, lpColorValues);
00234
00235 for(i=0;i<nChanges;i++) {
00236 SYSCOLOR_SetColor(lpSysColor[i], lpColorValues[i]);
00237 }
00238
00239
00240
00241
00242
00243
00244 SendMessageA( HWND_BROADCAST, WM_SYSCOLORCHANGE, 0, 0 );
00245
00246
00247
00248 RedrawWindow( GetDesktopWindow(), NULL, 0,
00249 RDW_INVALIDATE | RDW_ERASE | RDW_UPDATENOW | RDW_ALLCHILDREN );
00250 return TRUE;
00251 }
00252
00253
00254 HBRUSH WIN32API GetSysColorBrush(int nIndex)
00255 {
00256 if (!fColorInit)
00257 {
00258 SYSCOLOR_Init();
00259 fColorInit = TRUE;
00260 }
00261 dprintf(("GetSysColorBrush %d returned %x ", nIndex, ((nIndex >= 0) && (nIndex < NUM_SYS_COLORS)) ? SysColorBrushes[nIndex]:0));
00262 if( ((nIndex >= 0) && (nIndex < NUM_SYS_COLORS)) )
00263 return SysColorBrushes[nIndex];
00264
00265
00266 dprintf2(("WARNING: Unknown index(%d)", nIndex ));
00267 return GetStockObject(LTGRAY_BRUSH);
00268 }
00269
00270 HBRUSH OS2SysColorBrush[PMSYSCLR_CSYSCOLORS] = {0};
00271
00272 HBRUSH WIN32API GetOS2ColorBrush(int nIndex)
00273 {
00274 dprintf(("GetOS2ColorBrush %d", nIndex));
00275 nIndex += PMSYSCLR_BASE;
00276 if( ((nIndex < 0) || (nIndex >= PMSYSCLR_CSYSCOLORS)) ) {
00277 DebugInt3();
00278 return 0;
00279 }
00280
00281 if(OS2SysColorBrush[nIndex]) return OS2SysColorBrush[nIndex];
00282
00283 ULONG color = OSLibWinQuerySysColor(nIndex-PMSYSCLR_BASE);
00284 dprintf(("color %x", color));
00285 OS2SysColorBrush[nIndex] = CreateSolidBrush(color);
00286
00287 return OS2SysColorBrush[nIndex];
00288 }
00289
00290
00291
00292
00293
00294 HPEN WIN32API GetSysColorPen(INT index)
00295 {
00296 if (!fColorInit)
00297 {
00298 SYSCOLOR_Init();
00299 fColorInit = TRUE;
00300 }
00301
00302 return ((index >= 0) && (index < NUM_SYS_COLORS)) ? SysColorPens[index]:0;
00303 }
00304
00305
00306 INT SYSCOLOR_GetLastColor(VOID)
00307 {
00308 return NUM_SYS_COLORS-1;
00309 }
00310
00311
00312 INT SYSCOLOR_GetNumColors(VOID)
00313 {
00314 return NUM_SYS_COLORS;
00315 }
00316
00317
00318 BOOL SYSCOLOR_GetUseWinColors(VOID)
00319 {
00320 return USEWINCOLORS;
00321 }
00322
00323
00324
00325 HBRUSH WIN32API GetPattern55AABrush(void)
00326 {
00327 if (!hPattern55AABrush)
00328 hPattern55AABrush = CreatePatternBrush(GetPattern55AABitmap());
00329 return hPattern55AABrush;
00330 }
00331
00332
00333
00334 HBITMAP WIN32API GetPattern55AABitmap(void)
00335 {
00336 if (!hPattern55AABitmap)
00337 hPattern55AABitmap = CreateBitmap( 8, 8, 1, 1, wPattern55AA );
00338 return hPattern55AABitmap;
00339 }
00340
00341
00342 HBRUSH WIN32API GetControlBrush(HWND hwnd, HDC hdc, DWORD ctlType)
00343 {
00344 HBRUSH bkgBrush = 0;
00345
00346 if(ctlType <= CTLCOLOR_MAX)
00347 {
00348 bkgBrush = (HBRUSH)SendMessageA(GetParent(hwnd), WM_CTLCOLORMSGBOX + ctlType,
00349 (WPARAM)hdc, (LPARAM)hwnd );
00350
00351 if(GetObjectType(bkgBrush) != OBJ_BRUSH)
00352 bkgBrush = DefWindowProcA(hwnd, WM_CTLCOLORMSGBOX + ctlType, hdc, ctlType);
00353 }
00354 return bkgBrush;
00355 }
00356
00357
00358 BOOL WIN32API IsSystemPen(HPEN hPen)
00359 {
00360 for(int i=0;i<NUM_SYS_COLORS;i++) {
00361 if(SysColorPens[i] == hPen) {
00362 return TRUE;
00363 }
00364 }
00365 return FALSE;
00366 }
00367
00368
00369 BOOL WIN32API IsSystemBrush(HBRUSH hBrush)
00370 {
00371 for(int i=0;i<NUM_SYS_COLORS;i++) {
00372 if(SysColorBrushes[i] == hBrush) {
00373 return TRUE;
00374 }
00375 }
00376 return FALSE;
00377 }
00378
00379