xref: /aoo42x/main/vcl/unx/generic/gdi/cdeint.cxx (revision cdf0e10c)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_vcl.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include <stdlib.h>
32*cdf0e10cSrcweir #include <ctype.h>
33*cdf0e10cSrcweir #include <unistd.h>
34*cdf0e10cSrcweir 
35*cdf0e10cSrcweir #include <tools/stream.hxx>
36*cdf0e10cSrcweir #include <tools/debug.hxx>
37*cdf0e10cSrcweir 
38*cdf0e10cSrcweir #include <vcl/settings.hxx>
39*cdf0e10cSrcweir 
40*cdf0e10cSrcweir #include <unx/salunx.h>
41*cdf0e10cSrcweir #include <unx/saldisp.hxx>
42*cdf0e10cSrcweir #include <unx/cdeint.hxx>
43*cdf0e10cSrcweir 
44*cdf0e10cSrcweir CDEIntegrator::CDEIntegrator()
45*cdf0e10cSrcweir {
46*cdf0e10cSrcweir 	meType = DtCDE;
47*cdf0e10cSrcweir }
48*cdf0e10cSrcweir 
49*cdf0e10cSrcweir CDEIntegrator::~CDEIntegrator()
50*cdf0e10cSrcweir {
51*cdf0e10cSrcweir }
52*cdf0e10cSrcweir 
53*cdf0e10cSrcweir static int getHexDigit( const char c )
54*cdf0e10cSrcweir {
55*cdf0e10cSrcweir 	if( c >= '0' && c <= '9' )
56*cdf0e10cSrcweir 		return (int)(c-'0');
57*cdf0e10cSrcweir 	else if( c >= 'a' && c <= 'f' )
58*cdf0e10cSrcweir 		return (int)(c-'a'+10);
59*cdf0e10cSrcweir 	else if( c >= 'A' && c <= 'F' )
60*cdf0e10cSrcweir 		return (int)(c-'A'+10);
61*cdf0e10cSrcweir 	return -1;
62*cdf0e10cSrcweir }
63*cdf0e10cSrcweir 
64*cdf0e10cSrcweir 
65*cdf0e10cSrcweir void CDEIntegrator::GetSystemLook( AllSettings& rSettings )
66*cdf0e10cSrcweir {
67*cdf0e10cSrcweir 	static Color aColors[ 8 ];
68*cdf0e10cSrcweir 	static sal_Bool bRead  = sal_False;
69*cdf0e10cSrcweir     static sal_Bool bValid = sal_False;
70*cdf0e10cSrcweir 
71*cdf0e10cSrcweir 	if( ! bRead )
72*cdf0e10cSrcweir 	{
73*cdf0e10cSrcweir 		// get used palette from xrdb
74*cdf0e10cSrcweir 		char **ppStringList = 0;
75*cdf0e10cSrcweir 		int nStringCount;
76*cdf0e10cSrcweir 		XTextProperty aTextProperty;
77*cdf0e10cSrcweir 		aTextProperty.value = 0;
78*cdf0e10cSrcweir 		int i;
79*cdf0e10cSrcweir 
80*cdf0e10cSrcweir 		static Atom nResMgrAtom = XInternAtom( mpDisplay, "RESOURCE_MANAGER", False );
81*cdf0e10cSrcweir 
82*cdf0e10cSrcweir 		if( XGetTextProperty( mpDisplay,
83*cdf0e10cSrcweir 							  RootWindow( mpDisplay, 0 ),
84*cdf0e10cSrcweir 							  &aTextProperty,
85*cdf0e10cSrcweir 							  nResMgrAtom )
86*cdf0e10cSrcweir 			&& aTextProperty.value
87*cdf0e10cSrcweir 			&& XTextPropertyToStringList( &aTextProperty, &ppStringList, &nStringCount )
88*cdf0e10cSrcweir 			)
89*cdf0e10cSrcweir 		{
90*cdf0e10cSrcweir 			// format of ColorPalette resource:
91*cdf0e10cSrcweir 			// *n*ColorPalette: palettefile
92*cdf0e10cSrcweir 
93*cdf0e10cSrcweir 			ByteString aLines;
94*cdf0e10cSrcweir 			for( i=0; i < nStringCount; i++ )
95*cdf0e10cSrcweir 				aLines += ppStringList[i];
96*cdf0e10cSrcweir 			for( i = aLines.GetTokenCount( '\n' )-1; i >= 0; i-- )
97*cdf0e10cSrcweir 			{
98*cdf0e10cSrcweir 				ByteString aLine = aLines.GetToken( i, '\n' );
99*cdf0e10cSrcweir 				int nIndex = aLine.Search( "ColorPalette" );
100*cdf0e10cSrcweir 				if( nIndex != STRING_NOTFOUND )
101*cdf0e10cSrcweir 				{
102*cdf0e10cSrcweir 					int nPos = nIndex;
103*cdf0e10cSrcweir 
104*cdf0e10cSrcweir 					nIndex+=12;
105*cdf0e10cSrcweir 					const char* pStr = aLine.GetBuffer() +nIndex;
106*cdf0e10cSrcweir 					while( *pStr && isspace( *pStr ) && *pStr != ':' )
107*cdf0e10cSrcweir 					{
108*cdf0e10cSrcweir 						pStr++;
109*cdf0e10cSrcweir 						nIndex++;
110*cdf0e10cSrcweir 					}
111*cdf0e10cSrcweir 					if( *pStr != ':' )
112*cdf0e10cSrcweir 						continue;
113*cdf0e10cSrcweir 					pStr++, nIndex++;
114*cdf0e10cSrcweir 					for( ; *pStr && isspace( *pStr ); pStr++, nIndex++ )
115*cdf0e10cSrcweir 						;
116*cdf0e10cSrcweir 					if( ! *pStr )
117*cdf0e10cSrcweir 						continue;
118*cdf0e10cSrcweir 					int nIndex2 = nIndex;
119*cdf0e10cSrcweir 					for( ; *pStr && ! isspace( *pStr ); pStr++, nIndex2++ )
120*cdf0e10cSrcweir 						;
121*cdf0e10cSrcweir 					ByteString aPaletteFile( aLine.Copy( nIndex, nIndex2 - nIndex ) );
122*cdf0e10cSrcweir 					// extract number before ColorPalette;
123*cdf0e10cSrcweir 					for( ; nPos >= 0 && aLine.GetChar( nPos ) != '*'; nPos-- )
124*cdf0e10cSrcweir 						;
125*cdf0e10cSrcweir 					nPos--;
126*cdf0e10cSrcweir 					for( ; nPos >= 0 && aLine.GetChar( nPos ) != '*'; nPos-- )
127*cdf0e10cSrcweir 						;
128*cdf0e10cSrcweir 					int nNumber = aLine.Copy( ++nPos ).ToInt32();
129*cdf0e10cSrcweir 
130*cdf0e10cSrcweir 					DBG_TRACE2( "found palette %d in resource \"%s\"", nNumber, aLine.GetBuffer() );
131*cdf0e10cSrcweir 
132*cdf0e10cSrcweir 					// found no documentation what this number actually means;
133*cdf0e10cSrcweir 					// might be the screen number. 0 seems to be the right one
134*cdf0e10cSrcweir 					// in most cases.
135*cdf0e10cSrcweir 					if( nNumber )
136*cdf0e10cSrcweir 						continue;
137*cdf0e10cSrcweir 
138*cdf0e10cSrcweir 					DBG_TRACE1( "Palette file is \"%s\".\n", aPaletteFile.GetBuffer() );
139*cdf0e10cSrcweir 
140*cdf0e10cSrcweir 					String aPath( aHomeDir );
141*cdf0e10cSrcweir 					aPath.AppendAscii( "/.dt/palettes/" );
142*cdf0e10cSrcweir 					aPath += String( aPaletteFile, gsl_getSystemTextEncoding() );
143*cdf0e10cSrcweir 
144*cdf0e10cSrcweir 					SvFileStream aStream( aPath, STREAM_READ );
145*cdf0e10cSrcweir 					if( ! aStream.IsOpen() )
146*cdf0e10cSrcweir 					{
147*cdf0e10cSrcweir 						aPath = String::CreateFromAscii( "/usr/dt/palettes/" );
148*cdf0e10cSrcweir 						aPath += String( aPaletteFile, gsl_getSystemTextEncoding() );
149*cdf0e10cSrcweir 						aStream.Open( aPath, STREAM_READ );
150*cdf0e10cSrcweir 						if( ! aStream.IsOpen() )
151*cdf0e10cSrcweir 							continue;
152*cdf0e10cSrcweir 					}
153*cdf0e10cSrcweir 
154*cdf0e10cSrcweir 					ByteString aBuffer;
155*cdf0e10cSrcweir 					for( nIndex = 0; nIndex < 8; nIndex++ )
156*cdf0e10cSrcweir 					{
157*cdf0e10cSrcweir 						aStream.ReadLine( aBuffer );
158*cdf0e10cSrcweir 						// format is "#RRRRGGGGBBBB"
159*cdf0e10cSrcweir 
160*cdf0e10cSrcweir 						DBG_TRACE1( "\t\"%s\".\n", aBuffer.GetBuffer() );
161*cdf0e10cSrcweir 
162*cdf0e10cSrcweir 						if( aBuffer.Len() )
163*cdf0e10cSrcweir 						{
164*cdf0e10cSrcweir 							const char* pArr = (const char*)aBuffer.GetBuffer()+1;
165*cdf0e10cSrcweir 							aColors[nIndex] = Color(
166*cdf0e10cSrcweir 								getHexDigit( pArr[1] )
167*cdf0e10cSrcweir 								| ( getHexDigit( pArr[0] ) << 4 ),
168*cdf0e10cSrcweir 								getHexDigit( pArr[5] )
169*cdf0e10cSrcweir 								| ( getHexDigit( pArr[4] ) << 4 ),
170*cdf0e10cSrcweir 								getHexDigit( pArr[9] )
171*cdf0e10cSrcweir 								| ( getHexDigit( pArr[8] ) << 4 )
172*cdf0e10cSrcweir 								);
173*cdf0e10cSrcweir 
174*cdf0e10cSrcweir 							DBG_TRACE1( "\t\t%lx\n", aColors[nIndex].GetColor() );
175*cdf0e10cSrcweir 						}
176*cdf0e10cSrcweir 					}
177*cdf0e10cSrcweir 
178*cdf0e10cSrcweir                     bValid = sal_True;
179*cdf0e10cSrcweir 					break;
180*cdf0e10cSrcweir 				}
181*cdf0e10cSrcweir 			}
182*cdf0e10cSrcweir 		}
183*cdf0e10cSrcweir 
184*cdf0e10cSrcweir 		if( ppStringList )
185*cdf0e10cSrcweir 			XFreeStringList( ppStringList );
186*cdf0e10cSrcweir 		if( aTextProperty.value )
187*cdf0e10cSrcweir 			XFree( aTextProperty.value );
188*cdf0e10cSrcweir 	}
189*cdf0e10cSrcweir 
190*cdf0e10cSrcweir 
191*cdf0e10cSrcweir     StyleSettings aStyleSettings = rSettings.GetStyleSettings();
192*cdf0e10cSrcweir     // #i48001# set a default blink rate
193*cdf0e10cSrcweir     aStyleSettings.SetCursorBlinkTime( 500 );
194*cdf0e10cSrcweir     if (bValid)
195*cdf0e10cSrcweir 	{
196*cdf0e10cSrcweir         aStyleSettings.SetActiveColor( aColors[0] );
197*cdf0e10cSrcweir         aStyleSettings.SetActiveColor2( aColors[0] );
198*cdf0e10cSrcweir         aStyleSettings.SetActiveBorderColor( aColors[0] );
199*cdf0e10cSrcweir 
200*cdf0e10cSrcweir         aStyleSettings.SetDeactiveColor( aColors[0] );
201*cdf0e10cSrcweir         aStyleSettings.SetDeactiveColor2( aColors[0] );
202*cdf0e10cSrcweir         aStyleSettings.SetDeactiveBorderColor( aColors[0] );
203*cdf0e10cSrcweir 
204*cdf0e10cSrcweir         Color aActive =
205*cdf0e10cSrcweir             aColors[ 0 ].GetBlue() < 128		||
206*cdf0e10cSrcweir             aColors[ 0 ].GetGreen() < 128		||
207*cdf0e10cSrcweir             aColors[ 0 ].GetRed() < 128
208*cdf0e10cSrcweir             ? Color( COL_WHITE ) : Color( COL_BLACK );
209*cdf0e10cSrcweir         Color aDeactive =
210*cdf0e10cSrcweir             aColors[ 1 ].GetBlue() < 128		||
211*cdf0e10cSrcweir             aColors[ 1 ].GetGreen() < 128		||
212*cdf0e10cSrcweir             aColors[ 1 ].GetRed() < 128
213*cdf0e10cSrcweir             ? Color( COL_WHITE ) : Color( COL_BLACK );
214*cdf0e10cSrcweir         aStyleSettings.SetActiveTextColor( aActive );
215*cdf0e10cSrcweir         aStyleSettings.SetDeactiveTextColor( aDeactive );
216*cdf0e10cSrcweir 
217*cdf0e10cSrcweir         aStyleSettings.SetDialogTextColor( aDeactive );
218*cdf0e10cSrcweir         aStyleSettings.SetMenuTextColor( aDeactive );
219*cdf0e10cSrcweir         aStyleSettings.SetMenuBarTextColor( aDeactive );
220*cdf0e10cSrcweir         aStyleSettings.SetButtonTextColor( aDeactive );
221*cdf0e10cSrcweir         aStyleSettings.SetRadioCheckTextColor( aDeactive );
222*cdf0e10cSrcweir         aStyleSettings.SetGroupTextColor( aDeactive );
223*cdf0e10cSrcweir         aStyleSettings.SetLabelTextColor( aDeactive );
224*cdf0e10cSrcweir         aStyleSettings.SetInfoTextColor( aDeactive );
225*cdf0e10cSrcweir 
226*cdf0e10cSrcweir         aStyleSettings.Set3DColors( aColors[1] );
227*cdf0e10cSrcweir         aStyleSettings.SetFaceColor( aColors[1] );
228*cdf0e10cSrcweir         aStyleSettings.SetDialogColor( aColors[1] );
229*cdf0e10cSrcweir         aStyleSettings.SetMenuColor( aColors[1] );
230*cdf0e10cSrcweir         aStyleSettings.SetMenuBarColor( aColors[1] );
231*cdf0e10cSrcweir         if ( aStyleSettings.GetFaceColor() == COL_LIGHTGRAY )
232*cdf0e10cSrcweir             aStyleSettings.SetCheckedColor( Color( 0xCC, 0xCC, 0xCC ) );
233*cdf0e10cSrcweir         else
234*cdf0e10cSrcweir         {
235*cdf0e10cSrcweir             // calculate Checked color
236*cdf0e10cSrcweir             Color   aColor2 = aStyleSettings.GetLightColor();
237*cdf0e10cSrcweir             sal_uInt8    nRed    = (sal_uInt8)(((sal_uInt16)aColors[1].GetRed()   + (sal_uInt16)aColor2.GetRed())/2);
238*cdf0e10cSrcweir             sal_uInt8    nGreen  = (sal_uInt8)(((sal_uInt16)aColors[1].GetGreen() + (sal_uInt16)aColor2.GetGreen())/2);
239*cdf0e10cSrcweir             sal_uInt8    nBlue   = (sal_uInt8)(((sal_uInt16)aColors[1].GetBlue()  + (sal_uInt16)aColor2.GetBlue())/2);
240*cdf0e10cSrcweir             aStyleSettings.SetCheckedColor( Color( nRed, nGreen, nBlue ) );
241*cdf0e10cSrcweir         }
242*cdf0e10cSrcweir     }
243*cdf0e10cSrcweir     rSettings.SetStyleSettings( aStyleSettings );
244*cdf0e10cSrcweir }
245