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