1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: cdeint.cxx,v $
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"
37 #include <saldisp.hxx>
39 #include <vcl/settings.hxx>
41 #include <tools/stream.hxx>
42 #include <tools/debug.hxx>
44 CDEIntegrator::CDEIntegrator()
49 CDEIntegrator::~CDEIntegrator()
53 static int getHexDigit( const char c
)
55 if( c
>= '0' && c
<= '9' )
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);
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
;
73 // get used palette from xrdb
74 char **ppStringList
= 0;
76 XTextProperty aTextProperty
;
77 aTextProperty
.value
= 0;
80 static Atom nResMgrAtom
= XInternAtom( mpDisplay
, "RESOURCE_MANAGER", False
);
82 if( XGetTextProperty( mpDisplay
,
83 RootWindow( mpDisplay
, 0 ),
86 && aTextProperty
.value
87 && XTextPropertyToStringList( &aTextProperty
, &ppStringList
, &nStringCount
)
90 // format of ColorPalette resource:
91 // *n*ColorPalette: palettefile
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
)
105 const char* pStr
= aLine
.GetBuffer() +nIndex
;
106 while( *pStr
&& isspace( *pStr
) && *pStr
!= ':' )
114 for( ; *pStr
&& isspace( *pStr
); pStr
++, nIndex
++ )
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
-- )
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
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() )
155 for( nIndex
= 0; nIndex
< 8; nIndex
++ )
157 aStream
.ReadLine( aBuffer
);
158 // format is "#RRRRGGGGBBBB"
160 DBG_TRACE1( "\t\"%s\".\n", aBuffer
.GetBuffer() );
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() );
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 );
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] );
205 aColors
[ 0 ].GetBlue() < 128 ||
206 aColors
[ 0 ].GetGreen() < 128 ||
207 aColors
[ 0 ].GetRed() < 128
208 ? Color( COL_WHITE
) : Color( COL_BLACK
);
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 ) );
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
);