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