1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #define Region QtXRegion
28 #include <kconfiggroup.h>
29 #include <kmainwindow.h>
30 #include <kapplication.h>
37 #include "KDESalFrame.hxx"
38 #include "KDEXLib.hxx"
39 #include "KDESalGraphics.hxx"
41 #include <tools/color.hxx>
43 #include <vcl/font.hxx>
44 #include <vcl/settings.hxx>
46 #include "fontmanager.hxx"
50 #if OSL_DEBUG_LEVEL > 1
54 KDESalFrame::KDESalFrame( SalFrame
* pParent
, sal_uLong nState
) :
55 X11SalFrame( pParent
, nState
)
59 void KDESalFrame::Show( bool bVisible
, bool bNoActivate
)
61 if ( !GetParent() && ! (GetStyle() & SAL_FRAME_STYLE_INTRO
) )
63 KDEXLib
* pXLib
= static_cast<KDEXLib
*>(GetDisplay()->GetXLib());
67 X11SalFrame::Show( bVisible
, bNoActivate
);
70 /** Helper function to convert colors.
72 static Color
toColor( const QColor
&rColor
)
74 return Color( rColor
.red(), rColor
.green(), rColor
.blue() );
77 /** Helper function to read untranslated text entry from KConfig configuration repository.
79 static OUString
readEntryUntranslated( KConfigGroup
*pGroup
, const char *pKey
)
81 return OUString::createFromAscii( (const char *) pGroup
->readEntryUntranslated( pKey
).toAscii() );
84 /** Helper function to add information to Font from QFont.
86 Mostly grabbed from the Gtk+ vclplug (salnativewidgets-gtk.cxx).
88 static Font
toFont( const QFont
&rQFont
, const ::com::sun::star::lang::Locale
& rLocale
)
90 psp::FastPrintFontInfo aInfo
;
91 QFontInfo
qFontInfo( rQFont
);
94 aInfo
.m_aFamilyName
= OUString( (const char *) rQFont
.family().toUtf8(), strlen( (const char *) rQFont
.family().toUtf8() ), RTL_TEXTENCODING_UTF8
);
97 aInfo
.m_eItalic
= ( qFontInfo
.italic()? ITALIC_NORMAL
: ITALIC_NONE
);
100 int nWeight
= qFontInfo
.weight();
101 if ( nWeight
<= QFont::Light
)
102 aInfo
.m_eWeight
= WEIGHT_LIGHT
;
103 else if ( nWeight
<= QFont::Normal
)
104 aInfo
.m_eWeight
= WEIGHT_NORMAL
;
105 else if ( nWeight
<= QFont::DemiBold
)
106 aInfo
.m_eWeight
= WEIGHT_SEMIBOLD
;
107 else if ( nWeight
<= QFont::Bold
)
108 aInfo
.m_eWeight
= WEIGHT_BOLD
;
110 aInfo
.m_eWeight
= WEIGHT_ULTRABOLD
;
113 int nStretch
= rQFont
.stretch();
114 if ( nStretch
<= QFont::UltraCondensed
)
115 aInfo
.m_eWidth
= WIDTH_ULTRA_CONDENSED
;
116 else if ( nStretch
<= QFont::ExtraCondensed
)
117 aInfo
.m_eWidth
= WIDTH_EXTRA_CONDENSED
;
118 else if ( nStretch
<= QFont::Condensed
)
119 aInfo
.m_eWidth
= WIDTH_CONDENSED
;
120 else if ( nStretch
<= QFont::SemiCondensed
)
121 aInfo
.m_eWidth
= WIDTH_SEMI_CONDENSED
;
122 else if ( nStretch
<= QFont::Unstretched
)
123 aInfo
.m_eWidth
= WIDTH_NORMAL
;
124 else if ( nStretch
<= QFont::SemiExpanded
)
125 aInfo
.m_eWidth
= WIDTH_SEMI_EXPANDED
;
126 else if ( nStretch
<= QFont::Expanded
)
127 aInfo
.m_eWidth
= WIDTH_EXPANDED
;
128 else if ( nStretch
<= QFont::ExtraExpanded
)
129 aInfo
.m_eWidth
= WIDTH_EXTRA_EXPANDED
;
131 aInfo
.m_eWidth
= WIDTH_ULTRA_EXPANDED
;
133 SAL_INFO( "vcl.kde4", "font name BEFORE system match: \"" << aInfo
.m_aFamilyName
<< "\"" );
135 // match font to e.g. resolve "Sans"
136 psp::PrintFontManager::get().matchFont( aInfo
, rLocale
);
138 SAL_INFO( "vcl.kde4", "font match " <<
139 (aInfo
.m_nID
!= 0 ? "succeeded" : "failed") <<
140 ", name AFTER: \"" << aInfo
.m_aFamilyName
<< "\"" );
143 int nPointHeight
= qFontInfo
.pointSize();
144 if ( nPointHeight
<= 0 )
145 nPointHeight
= rQFont
.pointSize();
148 Font
aFont( aInfo
.m_aFamilyName
, Size( 0, nPointHeight
) );
149 if( aInfo
.m_eWeight
!= WEIGHT_DONTKNOW
)
150 aFont
.SetWeight( aInfo
.m_eWeight
);
151 if( aInfo
.m_eWidth
!= WIDTH_DONTKNOW
)
152 aFont
.SetWidthType( aInfo
.m_eWidth
);
153 if( aInfo
.m_eItalic
!= ITALIC_DONTKNOW
)
154 aFont
.SetItalic( aInfo
.m_eItalic
);
155 if( aInfo
.m_ePitch
!= PITCH_DONTKNOW
)
156 aFont
.SetPitch( aInfo
.m_ePitch
);
161 /** Implementation of KDE integration's main method.
163 void KDESalFrame::UpdateSettings( AllSettings
& rSettings
)
165 StyleSettings
style( rSettings
.GetStyleSettings() );
166 bool bSetTitleFont
= false;
169 QPalette pal
= kapp
->palette();
171 style
.SetToolbarIconSize( STYLE_TOOLBAR_ICONSIZE_LARGE
);
173 style
.SetActiveColor(toColor(pal
.color(QPalette::Active
, QPalette::Window
)));
174 style
.SetDeactiveColor(toColor(pal
.color(QPalette::Inactive
, QPalette::Window
)));
176 style
.SetActiveColor2(toColor(pal
.color(QPalette::Active
, QPalette::Window
)));
177 style
.SetDeactiveColor2(toColor(pal
.color(QPalette::Inactive
, QPalette::Window
)));
179 style
.SetActiveTextColor(toColor(pal
.color(QPalette::Active
, QPalette::WindowText
)));
180 style
.SetDeactiveTextColor(toColor(pal
.color(QPalette::Inactive
, QPalette::WindowText
)));
183 KConfig
*pConfig
= KGlobal::config().data();
186 KConfigGroup aGroup
= pConfig
->group( "WM" );
190 if ( aGroup
.hasKey( pKey
) )
192 Font aFont
= toFont( aGroup
.readEntry( pKey
, QFont() ), rSettings
.GetUILanguageTag().getLocale() );
193 style
.SetTitleFont( aFont
);
194 bSetTitleFont
= true;
197 aGroup
= pConfig
->group( "Icons" );
200 if ( aGroup
.hasKey( pKey
) )
201 style
.SetPreferredIconTheme( readEntryUntranslated( &aGroup
, pKey
) );
204 pKey
= "toolbarFont";
205 if ( aGroup
.hasKey( pKey
) )
207 Font aFont
= toFont( aGroup
.readEntry( pKey
, QFont() ), rSettings
.GetUILanguageTag().getLocale() );
208 style
.SetToolFont( aFont
);
212 Color aFore
= toColor( pal
.color( QPalette::Active
, QPalette::WindowText
) );
213 Color aBack
= toColor( pal
.color( QPalette::Active
, QPalette::Window
) );
214 Color aText
= toColor( pal
.color( QPalette::Active
, QPalette::Text
) );
215 Color aBase
= toColor( pal
.color( QPalette::Active
, QPalette::Base
) );
216 Color aButn
= toColor( pal
.color( QPalette::Active
, QPalette::ButtonText
) );
217 Color aMid
= toColor( pal
.color( QPalette::Active
, QPalette::Mid
) );
218 Color aHigh
= toColor( pal
.color( QPalette::Active
, QPalette::Highlight
) );
221 style
.SetRadioCheckTextColor( aFore
);
222 style
.SetLabelTextColor( aFore
);
223 style
.SetInfoTextColor( aFore
);
224 style
.SetDialogTextColor( aFore
);
225 style
.SetGroupTextColor( aFore
);
228 style
.SetFieldTextColor( aText
);
229 style
.SetFieldRolloverTextColor( aText
);
230 style
.SetWindowTextColor( aText
);
233 style
.SetFieldColor( aBase
);
234 style
.SetWindowColor( aBase
);
235 style
.SetActiveTabColor( aBase
);
238 style
.SetButtonTextColor( aButn
);
239 style
.SetButtonRolloverTextColor( aButn
);
242 style
.SetDisableColor( aMid
);
245 style
.SetWorkspaceColor( aMid
);
248 style
.Set3DColors( aBack
);
249 style
.SetFaceColor( aBack
);
250 style
.SetInactiveTabColor( aBack
);
251 style
.SetDialogColor( aBack
);
252 style
.SetCheckedColorSpecialCase( );
255 style
.SetHighlightColor( aHigh
);
256 style
.SetHighlightTextColor( toColor(pal
.color( QPalette::HighlightedText
)) );
259 style
.SetHelpColor( toColor( QToolTip::palette().color( QPalette::Active
, QPalette::ToolTipBase
)));
260 style
.SetHelpTextColor( toColor( QToolTip::palette().color( QPalette::Active
, QPalette::ToolTipText
)));
263 Font aFont
= toFont( kapp
->font(), rSettings
.GetUILanguageTag().getLocale() );
265 style
.SetAppFont( aFont
);
267 style
.SetMenuFont( aFont
); // will be changed according to pMenuBar
268 //style.SetToolFont( aFont ); //already set above
269 style
.SetLabelFont( aFont
);
270 style
.SetInfoFont( aFont
);
271 style
.SetRadioCheckFont( aFont
);
272 style
.SetPushButtonFont( aFont
);
273 style
.SetFieldFont( aFont
);
274 style
.SetIconFont( aFont
);
275 style
.SetGroupFont( aFont
);
277 aFont
.SetWeight( WEIGHT_BOLD
);
280 style
.SetTitleFont( aFont
);
282 style
.SetFloatTitleFont( aFont
);
284 style
.SetHelpFont( toFont( QToolTip::font(), rSettings
.GetUILanguageTag().getLocale()));
286 int flash_time
= QApplication::cursorFlashTime();
287 style
.SetCursorBlinkTime( flash_time
!= 0 ? flash_time
/2 : STYLE_CURSOR_NOBLINKTIME
);
290 style
.SetSkipDisabledInMenus( TRUE
);
291 KMenuBar
* pMenuBar
= new KMenuBar();
295 QPalette qMenuCG
= pMenuBar
->palette();
297 // Menu text and background color, theme specific
298 Color aMenuFore
= toColor( qMenuCG
.color( QPalette::WindowText
) );
299 Color aMenuBack
= toColor( qMenuCG
.color( QPalette::Window
) );
301 style
.SetMenuTextColor( aMenuFore
);
302 style
.SetMenuBarTextColor( style
.GetPersonaMenuBarTextColor().get_value_or( aMenuFore
) );
303 style
.SetMenuColor( aMenuBack
);
304 style
.SetMenuBarColor( aMenuBack
);
305 style
.SetMenuHighlightColor( toColor ( qMenuCG
.color( QPalette::Highlight
) ) );
306 style
.SetMenuHighlightTextColor( aMenuFore
);
308 // set special menubar higlight text color
309 if ( kapp
->style()->inherits( "HighContrastStyle" ) )
310 ImplGetSVData()->maNWFData
.maMenuBarHighlightTextColor
= toColor( qMenuCG
.color( QPalette::HighlightedText
) );
312 ImplGetSVData()->maNWFData
.maMenuBarHighlightTextColor
= aMenuFore
;
314 // set menubar rollover color
315 if ( pMenuBar
->style()->styleHint( QStyle::SH_MenuBar_MouseTracking
) )
317 style
.SetMenuBarRolloverColor( toColor ( qMenuCG
.color( QPalette::Highlight
) ) );
318 style
.SetMenuBarRolloverTextColor( ImplGetSVData()->maNWFData
.maMenuBarHighlightTextColor
);
322 style
.SetMenuBarRolloverColor( aMenuBack
);
323 style
.SetMenuBarRolloverTextColor( aMenuFore
);
327 aFont
= toFont( pMenuBar
->font(), rSettings
.GetUILanguageTag().getLocale() );
328 style
.SetMenuFont( aFont
);
334 style
.SetScrollBarSize( kapp
->style()->pixelMetric( QStyle::PM_ScrollBarExtent
) );
335 style
.SetMinThumbSize( kapp
->style()->pixelMetric( QStyle::PM_ScrollBarSliderMin
));
337 rSettings
.SetStyleSettings( style
);
340 void KDESalFrame::ReleaseGraphics( SalGraphics
*pGraphics
)
342 for( int i
= 0; i
< nMaxGraphics
; i
++ )
344 if( m_aGraphics
[i
].pGraphics
== pGraphics
)
346 m_aGraphics
[i
].bInUse
= false;
352 void KDESalFrame::updateGraphics( bool bClear
)
354 Drawable aDrawable
= bClear
? None
: GetWindow();
355 for( int i
= 0; i
< nMaxGraphics
; i
++ )
357 if( m_aGraphics
[i
].bInUse
)
358 m_aGraphics
[i
].pGraphics
->SetDrawable( aDrawable
, GetScreenNumber() );
362 KDESalFrame::~KDESalFrame()
366 KDESalFrame::GraphicsHolder::~GraphicsHolder()
371 SalGraphics
* KDESalFrame::AcquireGraphics()
375 for( int i
= 0; i
< nMaxGraphics
; i
++ )
377 if( ! m_aGraphics
[i
].bInUse
)
379 m_aGraphics
[i
].bInUse
= true;
380 if( ! m_aGraphics
[i
].pGraphics
)
382 m_aGraphics
[i
].pGraphics
= new KDESalGraphics();
383 m_aGraphics
[i
].pGraphics
->Init( this, GetWindow(), GetScreenNumber() );
385 return m_aGraphics
[i
].pGraphics
;
393 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */