0024858: Convert class V3d_ListOfTransient to non-CDL
[occt.git] / src / InterfaceGraphic / InterfaceGraphic_Palette.c
CommitLineData
b311480e 1/*
2 Copyright (c) 1991-1999 Matra Datavision
973c2be1 3 Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 4
973c2be1 5 This file is part of Open CASCADE Technology software library.
b311480e 6
d5f74e42 7 This library is free software; you can redistribute it and/or modify it under
8 the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 9 by the Free Software Foundation, with special exception defined in the file
10 OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 distribution for complete text of the license and disclaimer of any warranty.
b311480e 12
973c2be1 13 Alternatively, this file may be used under the terms of Open CASCADE
14 commercial license or contractual agreement.
b311480e 15*/
7fd59977 16
17#ifndef WNT
18
19int _a_horreur_du_vide_a_la_compilation;
20
21#else
22
23#define STRICT
24#include <windows.h>
25
26#pragma comment( lib, "user32.lib" )
27#pragma comment( lib, "gdi32.lib" )
28
29#if WINVER >= 0x0400
30# define NB_STATIC_COLORS ( COLOR_INFOBK - COLOR_SCROLLBAR + 1 )
31#else
32# define NB_STATIC_COLORS ( COLOR_BTNHIGHLIGHT - COLOR_SCROLLBAR + 1 )
33#endif /* WINVER . . . */
34
35#define BLACK RGB( 0, 0, 0 )
36#define WHITE RGB( 255, 255, 255 )
37
38static int s_sysPalIdx[ NB_STATIC_COLORS ] = {
39
40 COLOR_SCROLLBAR,
41 COLOR_BACKGROUND,
42 COLOR_ACTIVECAPTION,
43 COLOR_INACTIVECAPTION,
44 COLOR_MENU,
45 COLOR_WINDOW,
46 COLOR_WINDOWFRAME,
47 COLOR_MENUTEXT,
48 COLOR_WINDOWTEXT,
49 COLOR_CAPTIONTEXT,
50 COLOR_ACTIVEBORDER,
51 COLOR_INACTIVEBORDER,
52 COLOR_APPWORKSPACE,
53 COLOR_HIGHLIGHT,
54 COLOR_HIGHLIGHTTEXT,
55 COLOR_BTNFACE,
56 COLOR_BTNSHADOW,
57 COLOR_GRAYTEXT,
58 COLOR_BTNTEXT,
59 COLOR_INACTIVECAPTIONTEXT,
60 COLOR_BTNHIGHLIGHT
61#if WINVER >= 0x0400
62 ,COLOR_3DDKSHADOW,
63 COLOR_3DLIGHT,
64 COLOR_INFOTEXT,
65 COLOR_INFOBK
66#endif /* WINVER . . . */
67};
68
69static COLORREF s_sysPalBW[ NB_STATIC_COLORS ] = {
70
71 WHITE, /* COLOR_SCROLLBAR */
72 BLACK, /* COLOR_BACKGROUND */
73 BLACK, /* COLOR_ACTIVECAPTION */
74 WHITE, /* COLOR_INACTIVECAPTION */
75 WHITE, /* COLOR_MENU */
76 WHITE, /* COLOR_WINDOW */
77 BLACK, /* COLOR_WINDOWFRAME */
78 BLACK, /* COLOR_MENUTEXT */
79 BLACK, /* COLOR_WINDOWTEXT */
80 WHITE, /* COLOR_CAPTIONTEXT */
81 WHITE, /* COLOR_ACTIVEBORDER */
82 WHITE, /* COLOR_INACTIVEBORDER */
83 WHITE, /* COLOR_APPWORKSPACE */
84 BLACK, /* COLOR_HIGHLIGHT */
85 WHITE, /* COLOR_HIGHLIGHTTEXT */
86 WHITE, /* COLOR_BTNFACE */
87 BLACK, /* COLOR_BTNSHADOW */
88 BLACK, /* COLOR_GRAYTEXT */
89 BLACK, /* COLOR_BTNTEXT */
90 BLACK, /* COLOR_INACTIVECAPTIONTEXT */
91 BLACK /* COLOR_BTNHIGHLIGHT */
92#if WINVER >= 0x0400
93 ,BLACK, /* BLACKCOLOR_3DDKSHADOW */
94 BLACK, /* COLOR_3DLIGHT */
95 BLACK, /* COLOR_INFOTEXT */
96 BLACK /* COLOR_INFOBK */
97#endif /* WINVER . . . */
98};
99
100static BOOL s_sysUse;
101static COLORREF s_sysPal[ NB_STATIC_COLORS ];
102
103__declspec( dllexport ) long InterfaceGraphic_RealizePalette ( HDC hdc, HPALETTE hPal, BOOL fBkg, BOOL fUseStatic ) {
104
105 int i;
106 long retVal = 0;
107
108 if ( fUseStatic ) {
109
110 if ( !s_sysUse )
111
112 for ( i = 0; i < NB_STATIC_COLORS; ++i ) s_sysPal[ i ] = GetSysColor ( s_sysPalIdx[ i ] );
113
114 SetSystemPaletteUse ( hdc, fBkg ? SYSPAL_STATIC : SYSPAL_NOSTATIC );
115
116 if ( UnrealizeObject ( hPal ) && SelectPalette ( hdc, hPal, fBkg ) ) retVal = RealizePalette ( hdc );
117
118 if ( fBkg ) {
119
120 SetSysColors ( NB_STATIC_COLORS, s_sysPalIdx, s_sysPal );
121 s_sysUse = FALSE;
122
123 } else {
124
125 SetSysColors ( NB_STATIC_COLORS, s_sysPalIdx, s_sysPalBW );
126 s_sysUse = TRUE;
127
128 } // end else
129
7dc9e047 130#pragma warning(push)
131#pragma warning(disable:4306) /* level 4 warning on cast of int to HWND in HWND_BROADCAST macro */
7fd59977 132 PostMessage ( HWND_BROADCAST, WM_SYSCOLORCHANGE, 0, 0 );
7dc9e047 133#pragma warning(pop)
7fd59977 134
135 } else {
136
137 SelectPalette ( hdc, hPal, FALSE );
138 retVal = RealizePalette ( hdc );
139
140 } // end else
141
142 return retVal;
143} // end RealizePaletteNow
144
145#endif /* WNT */