1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2009 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
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.
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).
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.
26 ************************************************************************/
28 #define Region QtXRegion
36 #include <kconfiggroup.h>
37 #include <kmainwindow.h>
38 #include <kapplication.h>
43 #include "KDESalFrame.hxx"
44 #include "KDEXLib.hxx"
45 #include "KDESalGraphics.hxx"
47 #include <vcl/settings.hxx>
48 #include <vcl/font.hxx>
49 #include <tools/color.hxx>
51 #include <vcl/svdata.hxx>
53 #include <pspgraphics.h>
55 #if OSL_DEBUG_LEVEL > 1
59 KDESalFrame::KDESalFrame( SalFrame
* pParent
, ULONG nState
) :
60 X11SalFrame( pParent
, nState
)
64 void KDESalFrame::Show( BOOL bVisible
, BOOL bNoActivate
)
66 if ( !GetParent() && ! (GetStyle() & SAL_FRAME_STYLE_INTRO
) )
68 KDEXLib
* pXLib
= static_cast<KDEXLib
*>(GetDisplay()->GetXLib());
72 X11SalFrame::Show( bVisible
, bNoActivate
);
75 /** Helper function to convert colors.
77 static Color
toColor( const QColor
&rColor
)
79 return Color( rColor
.red(), rColor
.green(), rColor
.blue() );
82 /** Helper function to read untranslated text entry from KConfig configuration repository.
84 static OUString
readEntryUntranslated( KConfigGroup
*pGroup
, const char *pKey
)
86 return OUString::createFromAscii( (const char *) pGroup
->readEntryUntranslated( pKey
).toAscii() );
89 /** Helper function to read color from KConfig configuration repository.
91 static Color
readColor( KConfigGroup
*pGroup
, const char *pKey
)
93 return toColor( pGroup
->readEntry( pKey
, QColor(Qt::white
) ) );
96 /** Helper function to add information to Font from QFont.
98 Mostly grabbed from the Gtk+ vclplug (salnativewidgets-gtk.cxx).
100 static Font
toFont( const QFont
&rQFont
, const ::com::sun::star::lang::Locale
& rLocale
)
102 psp::FastPrintFontInfo aInfo
;
103 QFontInfo
qFontInfo( rQFont
);
106 aInfo
.m_aFamilyName
= String( (const char *) rQFont
.family().toUtf8(), RTL_TEXTENCODING_UTF8
);
109 aInfo
.m_eItalic
= ( qFontInfo
.italic()? psp::italic::Italic
: psp::italic::Upright
);
112 int nWeight
= qFontInfo
.weight();
113 if ( nWeight
<= QFont::Light
)
114 aInfo
.m_eWeight
= psp::weight::Light
;
115 else if ( nWeight
<= QFont::Normal
)
116 aInfo
.m_eWeight
= psp::weight::Normal
;
117 else if ( nWeight
<= QFont::DemiBold
)
118 aInfo
.m_eWeight
= psp::weight::SemiBold
;
119 else if ( nWeight
<= QFont::Bold
)
120 aInfo
.m_eWeight
= psp::weight::Bold
;
122 aInfo
.m_eWeight
= psp::weight::UltraBold
;
125 int nStretch
= rQFont
.stretch();
126 if ( nStretch
<= QFont::UltraCondensed
)
127 aInfo
.m_eWidth
= psp::width::UltraCondensed
;
128 else if ( nStretch
<= QFont::ExtraCondensed
)
129 aInfo
.m_eWidth
= psp::width::ExtraCondensed
;
130 else if ( nStretch
<= QFont::Condensed
)
131 aInfo
.m_eWidth
= psp::width::Condensed
;
132 else if ( nStretch
<= QFont::SemiCondensed
)
133 aInfo
.m_eWidth
= psp::width::SemiCondensed
;
134 else if ( nStretch
<= QFont::Unstretched
)
135 aInfo
.m_eWidth
= psp::width::Normal
;
136 else if ( nStretch
<= QFont::SemiExpanded
)
137 aInfo
.m_eWidth
= psp::width::SemiExpanded
;
138 else if ( nStretch
<= QFont::Expanded
)
139 aInfo
.m_eWidth
= psp::width::Expanded
;
140 else if ( nStretch
<= QFont::ExtraExpanded
)
141 aInfo
.m_eWidth
= psp::width::ExtraExpanded
;
143 aInfo
.m_eWidth
= psp::width::UltraExpanded
;
145 #if OSL_DEBUG_LEVEL > 1
146 fprintf( stderr
, "font name BEFORE system match: \"%s\"\n", OUStringToOString( aInfo
.m_aFamilyName
, RTL_TEXTENCODING_ISO_8859_1
).getStr() );
149 // match font to e.g. resolve "Sans"
150 psp::PrintFontManager::get().matchFont( aInfo
, rLocale
);
152 #if OSL_DEBUG_LEVEL > 1
153 fprintf( stderr
, "font match %s, name AFTER: \"%s\"\n",
154 aInfo
.m_nID
!= 0 ? "succeeded" : "failed",
155 OUStringToOString( aInfo
.m_aFamilyName
, RTL_TEXTENCODING_ISO_8859_1
).getStr() );
159 int nPointHeight
= qFontInfo
.pointSize();
160 if ( nPointHeight
<= 0 )
161 nPointHeight
= rQFont
.pointSize();
164 Font
aFont( aInfo
.m_aFamilyName
, Size( 0, nPointHeight
) );
165 if( aInfo
.m_eWeight
!= psp::weight::Unknown
)
166 aFont
.SetWeight( PspGraphics::ToFontWeight( aInfo
.m_eWeight
) );
167 if( aInfo
.m_eWidth
!= psp::width::Unknown
)
168 aFont
.SetWidthType( PspGraphics::ToFontWidth( aInfo
.m_eWidth
) );
169 if( aInfo
.m_eItalic
!= psp::italic::Unknown
)
170 aFont
.SetItalic( PspGraphics::ToFontItalic( aInfo
.m_eItalic
) );
171 if( aInfo
.m_ePitch
!= psp::pitch::Unknown
)
172 aFont
.SetPitch( PspGraphics::ToFontPitch( aInfo
.m_ePitch
) );
177 /** Implementation of KDE integration's main method.
179 void KDESalFrame::UpdateSettings( AllSettings
& rSettings
)
181 StyleSettings
style( rSettings
.GetStyleSettings() );
182 BOOL bSetTitleFont
= false;
185 QPalette pal
= kapp
->palette();
187 style
.SetActiveColor(toColor(pal
.color(QPalette::Active
, QPalette::Window
)));
188 style
.SetDeactiveColor(toColor(pal
.color(QPalette::Inactive
, QPalette::Window
)));
190 style
.SetActiveColor2(toColor(pal
.color(QPalette::Active
, QPalette::Window
)));
191 style
.SetDeactiveColor2(toColor(pal
.color(QPalette::Inactive
, QPalette::Window
)));
193 style
.SetActiveTextColor(toColor(pal
.color(QPalette::Active
, QPalette::WindowText
)));
194 style
.SetDeactiveTextColor(toColor(pal
.color(QPalette::Inactive
, QPalette::WindowText
)));
197 KConfig
*pConfig
= KGlobal::config().data();
200 KConfigGroup aGroup
= pConfig
->group( "WM" );
204 if ( aGroup
.hasKey( pKey
) )
206 Font aFont
= toFont( aGroup
.readEntry( pKey
, QFont() ), rSettings
.GetUILocale() );
207 style
.SetTitleFont( aFont
);
208 bSetTitleFont
= true;
211 aGroup
= pConfig
->group( "Icons" );
214 if ( aGroup
.hasKey( pKey
) )
215 style
.SetPreferredSymbolsStyleName( readEntryUntranslated( &aGroup
, pKey
) );
218 pKey
= "toolbarFont";
219 if ( aGroup
.hasKey( pKey
) )
221 Font aFont
= toFont( aGroup
.readEntry( pKey
, QFont() ), rSettings
.GetUILocale() );
222 style
.SetToolFont( aFont
);
226 Color aFore
= toColor( pal
.color( QPalette::Active
, QPalette::WindowText
) );
227 Color aBack
= toColor( pal
.color( QPalette::Active
, QPalette::Window
) );
228 Color aText
= toColor( pal
.color( QPalette::Active
, QPalette::Text
) );
229 Color aBase
= toColor( pal
.color( QPalette::Active
, QPalette::Base
) );
230 Color aButn
= toColor( pal
.color( QPalette::Active
, QPalette::ButtonText
) );
231 Color aMid
= toColor( pal
.color( QPalette::Active
, QPalette::Mid
) );
232 Color aHigh
= toColor( pal
.color( QPalette::Active
, QPalette::Highlight
) );
235 style
.SetRadioCheckTextColor( aFore
);
236 style
.SetLabelTextColor( aFore
);
237 style
.SetInfoTextColor( aFore
);
238 style
.SetDialogTextColor( aFore
);
239 style
.SetGroupTextColor( aFore
);
242 style
.SetFieldTextColor( aText
);
243 style
.SetFieldRolloverTextColor( aText
);
244 style
.SetWindowTextColor( aText
);
245 style
.SetHelpTextColor( aText
);
248 style
.SetFieldColor( aBase
);
249 style
.SetHelpColor( aBase
);
250 style
.SetWindowColor( aBase
);
251 style
.SetActiveTabColor( aBase
);
254 style
.SetButtonTextColor( aButn
);
255 style
.SetButtonRolloverTextColor( aButn
);
258 style
.SetDisableColor( aMid
);
261 style
.SetWorkspaceColor( aMid
);
264 style
.Set3DColors( aBack
);
265 style
.SetFaceColor( aBack
);
266 style
.SetInactiveTabColor( aBack
);
267 style
.SetDialogColor( aBack
);
269 if( aBack
== COL_LIGHTGRAY
)
270 style
.SetCheckedColor( Color( 0xCC, 0xCC, 0xCC ) );
273 Color aColor2
= style
.GetLightColor();
275 SetCheckedColor( Color( (BYTE
)(((USHORT
)aBack
.GetRed()+(USHORT
)aColor2
.GetRed())/2),
276 (BYTE
)(((USHORT
)aBack
.GetGreen()+(USHORT
)aColor2
.GetGreen())/2),
277 (BYTE
)(((USHORT
)aBack
.GetBlue()+(USHORT
)aColor2
.GetBlue())/2)
282 style
.SetHighlightColor( aHigh
);
283 style
.SetHighlightTextColor( toColor(pal
.color( QPalette::HighlightedText
)) );
286 Font aFont
= toFont( kapp
->font(), rSettings
.GetUILocale() );
288 style
.SetAppFont( aFont
);
289 style
.SetHelpFont( aFont
);
293 style
.SetTitleFont( aFont
);
296 style
.SetFloatTitleFont( aFont
);
297 style
.SetMenuFont( aFont
); // will be changed according to pMenuBar
298 //style.SetToolFont( aFont ); //already set above
299 style
.SetLabelFont( aFont
);
300 style
.SetInfoFont( aFont
);
301 style
.SetRadioCheckFont( aFont
);
302 style
.SetPushButtonFont( aFont
);
303 style
.SetFieldFont( aFont
);
304 style
.SetIconFont( aFont
);
305 style
.SetGroupFont( aFont
);
307 int flash_time
= QApplication::cursorFlashTime();
308 style
.SetCursorBlinkTime( flash_time
!= 0 ? flash_time
/2 : STYLE_CURSOR_NOBLINKTIME
);
311 style
.SetSkipDisabledInMenus( TRUE
);
312 KMenuBar
* pMenuBar
= new KMenuBar();
316 QPalette qMenuCG
= pMenuBar
->palette();
318 // Menu text and background color, theme specific
319 Color aMenuFore
= toColor( qMenuCG
.color( QPalette::WindowText
) );
320 Color aMenuBack
= toColor( qMenuCG
.color( QPalette::Window
) );
322 aMenuFore
= toColor( qMenuCG
.color( QPalette::ButtonText
) );
323 aMenuBack
= toColor( qMenuCG
.color( QPalette::Button
) );
325 style
.SetMenuTextColor( aMenuFore
);
326 style
.SetMenuBarTextColor( aMenuFore
);
327 style
.SetMenuColor( aMenuBack
);
328 style
.SetMenuBarColor( aMenuBack
);
330 style
.SetMenuHighlightColor( toColor ( qMenuCG
.color( QPalette::Highlight
) ) );
332 style
.SetMenuHighlightTextColor( aMenuFore
);
334 // set special menubar higlight text color
335 if ( kapp
->style()->inherits( "HighContrastStyle" ) )
336 ImplGetSVData()->maNWFData
.maMenuBarHighlightTextColor
= toColor( qMenuCG
.color( QPalette::HighlightedText
) );
338 ImplGetSVData()->maNWFData
.maMenuBarHighlightTextColor
= aMenuFore
;
341 aFont
= toFont( pMenuBar
->font(), rSettings
.GetUILocale() );
342 style
.SetMenuFont( aFont
);
348 style
.SetScrollBarSize( kapp
->style()->pixelMetric( QStyle::PM_ScrollBarExtent
) );
350 // #i59364# high contrast mode
351 BOOL bHC
= ( style
.GetFaceColor().IsDark() ||
352 style
.GetWindowColor().IsDark() );
353 style
.SetHighContrastMode( bHC
);
355 rSettings
.SetStyleSettings( style
);
359 void KDESalFrame::ReleaseGraphics( SalGraphics
*pGraphics
)
361 for( int i
= 0; i
< nMaxGraphics
; i
++ )
363 if( m_aGraphics
[i
].pGraphics
== pGraphics
)
365 m_aGraphics
[i
].bInUse
= false;
371 void KDESalFrame::updateGraphics()
373 for( int i
= 0; i
< nMaxGraphics
; i
++ )
375 if( m_aGraphics
[i
].bInUse
)
376 m_aGraphics
[i
].pGraphics
->SetDrawable( GetWindow(), GetScreenNumber() );
380 KDESalFrame::~KDESalFrame()
384 KDESalFrame::GraphicsHolder::~GraphicsHolder()
389 SalGraphics
* KDESalFrame::GetGraphics()
393 for( int i
= 0; i
< nMaxGraphics
; i
++ )
395 if( ! m_aGraphics
[i
].bInUse
)
397 m_aGraphics
[i
].bInUse
= true;
398 if( ! m_aGraphics
[i
].pGraphics
)
400 m_aGraphics
[i
].pGraphics
= new KDESalGraphics();
401 m_aGraphics
[i
].pGraphics
->Init( this, GetWindow(), GetScreenNumber() );
403 return m_aGraphics
[i
].pGraphics
;