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