merge the formfield patch from ooo-build
[ooovba.git] / vcl / unx / source / gdi / cdeint.cxx
blob2222f40d4c8dba1e29eff4e7412a5205f0f7b1fe
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: cdeint.cxx,v $
10 * $Revision: 1.15 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_vcl.hxx"
33 #include <stdlib.h>
34 #include <ctype.h>
35 #include <unistd.h>
36 #include <salunx.h>
37 #include <saldisp.hxx>
38 #include <cdeint.hxx>
39 #include <vcl/settings.hxx>
41 #include <tools/stream.hxx>
42 #include <tools/debug.hxx>
44 CDEIntegrator::CDEIntegrator()
46 meType = DtCDE;
49 CDEIntegrator::~CDEIntegrator()
53 static int getHexDigit( const char c )
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;
65 void CDEIntegrator::GetSystemLook( AllSettings& rSettings )
67 static Color aColors[ 8 ];
68 static sal_Bool bRead = sal_False;
69 static sal_Bool bValid = sal_False;
71 if( ! bRead )
73 // get used palette from xrdb
74 char **ppStringList = 0;
75 int nStringCount;
76 XTextProperty aTextProperty;
77 aTextProperty.value = 0;
78 int i;
80 static Atom nResMgrAtom = XInternAtom( mpDisplay, "RESOURCE_MANAGER", False );
82 if( XGetTextProperty( mpDisplay,
83 RootWindow( mpDisplay, 0 ),
84 &aTextProperty,
85 nResMgrAtom )
86 && aTextProperty.value
87 && XTextPropertyToStringList( &aTextProperty, &ppStringList, &nStringCount )
90 // format of ColorPalette resource:
91 // *n*ColorPalette: palettefile
93 ByteString aLines;
94 for( i=0; i < nStringCount; i++ )
95 aLines += ppStringList[i];
96 for( i = aLines.GetTokenCount( '\n' )-1; i >= 0; i-- )
98 ByteString aLine = aLines.GetToken( i, '\n' );
99 int nIndex = aLine.Search( "ColorPalette" );
100 if( nIndex != STRING_NOTFOUND )
102 int nPos = nIndex;
104 nIndex+=12;
105 const char* pStr = aLine.GetBuffer() +nIndex;
106 while( *pStr && isspace( *pStr ) && *pStr != ':' )
108 pStr++;
109 nIndex++;
111 if( *pStr != ':' )
112 continue;
113 pStr++, nIndex++;
114 for( ; *pStr && isspace( *pStr ); pStr++, nIndex++ )
116 if( ! *pStr )
117 continue;
118 int nIndex2 = nIndex;
119 for( ; *pStr && ! isspace( *pStr ); pStr++, nIndex2++ )
121 ByteString aPaletteFile( aLine.Copy( nIndex, nIndex2 - nIndex ) );
122 // extract number before ColorPalette;
123 for( ; nPos >= 0 && aLine.GetChar( nPos ) != '*'; nPos-- )
125 nPos--;
126 for( ; nPos >= 0 && aLine.GetChar( nPos ) != '*'; nPos-- )
128 int nNumber = aLine.Copy( ++nPos ).ToInt32();
130 DBG_TRACE2( "found palette %d in resource \"%s\"", nNumber, aLine.GetBuffer() );
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;
138 DBG_TRACE1( "Palette file is \"%s\".\n", aPaletteFile.GetBuffer() );
140 String aPath( aHomeDir );
141 aPath.AppendAscii( "/.dt/palettes/" );
142 aPath += String( aPaletteFile, gsl_getSystemTextEncoding() );
144 SvFileStream aStream( aPath, STREAM_READ );
145 if( ! aStream.IsOpen() )
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;
154 ByteString aBuffer;
155 for( nIndex = 0; nIndex < 8; nIndex++ )
157 aStream.ReadLine( aBuffer );
158 // format is "#RRRRGGGGBBBB"
160 DBG_TRACE1( "\t\"%s\".\n", aBuffer.GetBuffer() );
162 if( aBuffer.Len() )
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 )
174 DBG_TRACE1( "\t\t%lx\n", aColors[nIndex].GetColor() );
178 bValid = sal_True;
179 break;
184 if( ppStringList )
185 XFreeStringList( ppStringList );
186 if( aTextProperty.value )
187 XFree( aTextProperty.value );
191 StyleSettings aStyleSettings = rSettings.GetStyleSettings();
192 // #i48001# set a default blink rate
193 aStyleSettings.SetCursorBlinkTime( 500 );
194 if (bValid)
196 aStyleSettings.SetActiveColor( aColors[0] );
197 aStyleSettings.SetActiveColor2( aColors[0] );
198 aStyleSettings.SetActiveBorderColor( aColors[0] );
200 aStyleSettings.SetDeactiveColor( aColors[0] );
201 aStyleSettings.SetDeactiveColor2( aColors[0] );
202 aStyleSettings.SetDeactiveBorderColor( aColors[0] );
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 );
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 );
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
235 // calculate Checked color
236 Color aColor2 = aStyleSettings.GetLightColor();
237 BYTE nRed = (BYTE)(((USHORT)aColors[1].GetRed() + (USHORT)aColor2.GetRed())/2);
238 BYTE nGreen = (BYTE)(((USHORT)aColors[1].GetGreen() + (USHORT)aColor2.GetGreen())/2);
239 BYTE nBlue = (BYTE)(((USHORT)aColors[1].GetBlue() + (USHORT)aColor2.GetBlue())/2);
240 aStyleSettings.SetCheckedColor( Color( nRed, nGreen, nBlue ) );
243 rSettings.SetStyleSettings( aStyleSettings );