Branch libreoffice-5-0-4
[LibreOffice.git] / vcl / unx / kde / salnativewidgets-kde.cxx
blob6ee56003a328aee5ac91e3bbccf57365a8887b6f
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 #include <shell/kde_headers.h>
22 #include "UnxFilePicker.hxx"
24 #include <unx/salunx.h>
25 #include <unx/saldata.hxx>
26 #include <unx/saldisp.hxx>
27 #include <unx/salgdi.h>
28 #include <unx/kde/kdedata.hxx>
29 #include "unx/pixmap.hxx"
31 #include <vcl/settings.hxx>
32 #include "fontmanager.hxx"
33 #include <vcl/vclenum.hxx>
34 #include <rtl/ustrbuf.hxx>
36 #include <config_vclplug.h>
38 #if ENABLE_TDE
39 #define QPushButton_String "TQPushButton"
40 #define QRadioButton_String "TQRadioButton"
41 #define QCheckBox_String "TQCheckBox"
42 #define QComboBox_String "TQComboBox"
43 #define QLineEdit_String "TQLineEdit"
44 #define QSpinWidget_String "TQSpinWidget"
45 #define QTabBar_String "TQTabBar"
46 #define QTabWidget_String "TQTabWidget"
47 #define QListView_String "TQListView"
48 #define QScrollBar_String "TQScrollBar"
49 #define QMotifPlusStyle_String "TQMotifPlusStyle"
50 #define QSGIStyle_String "TQSGIStyle"
51 #define QToolBar_String "TQToolBar"
52 #define QToolButton_String "TQToolButton"
53 #define QMenuBar_String "TQMenuBar"
54 #define QPopupMenu_String "TQPopupMenu"
55 #define QProgressBar_String "TQProgressBar"
56 #define QMotifStyle_String "TQMotifStyle"
57 #define QWindowsStyle_String "TQWindowsStyle"
58 #else // ENABLE_TDE
59 #define QPushButton_String "QPushButton"
60 #define QRadioButton_String "QRadioButton"
61 #define QCheckBox_String "QCheckBox"
62 #define QComboBox_String "QComboBox"
63 #define QLineEdit_String "QLineEdit"
64 #define QSpinWidget_String "QSpinWidget"
65 #define QTabBar_String "QTabBar"
66 #define QTabWidget_String "QTabWidget"
67 #define QListView_String "QListView"
68 #define QScrollBar_String "QScrollBar"
69 #define QMotifPlusStyle_String "QMotifPlusStyle"
70 #define QSGIStyle_String "QSGIStyle"
71 #define QToolBar_String "QToolBar"
72 #define QToolButton_String "QToolButton"
73 #define QMenuBar_String "QMenuBar"
74 #define QPopupMenu_String "QPopupMenu"
75 #define QProgressBar_String "QProgressBar"
76 #define QMotifStyle_String "QMotifStyle"
77 #define QWindowsStyle_String "QWindowsStyle"
78 #endif // ENABLE_TDE
80 using namespace ::com::sun::star;
82 namespace {
84 /** Style conversion function.
86 Conversion function between VCL ControlState together with ImplControlValue
87 and Qt state flags.
89 @param nState
90 State of the widget (default, focused, ...) as defined in Native Widget
91 Framework.
93 @param aValue
94 Value held by the widget (on, off, ...)
96 QStyle::SFlags vclStateValue2SFlags( ControlState nState,
97 const ImplControlValue& aValue )
99 QStyle::SFlags nStyle =
100 ( (nState & ControlState::DEFAULT)? QStyle::Style_ButtonDefault: QStyle::Style_Default ) |
101 ( (nState & ControlState::ENABLED)? QStyle::Style_Enabled: QStyle::Style_Default ) |
102 ( (nState & ControlState::FOCUSED)? QStyle::Style_HasFocus: QStyle::Style_Default ) |
103 ( (nState & ControlState::PRESSED)? QStyle::Style_Down: QStyle::Style_Raised ) |
104 ( (nState & ControlState::SELECTED)? QStyle::Style_Selected : QStyle::Style_Default ) |
105 ( (nState & ControlState::ROLLOVER)? QStyle::Style_MouseOver: QStyle::Style_Default );
106 //TODO ( (nState & ControlState::HIDDEN)? QStyle::Style_: QStyle::Style_Default ) |
108 switch ( aValue.getTristateVal() )
110 case BUTTONVALUE_ON: nStyle |= QStyle::Style_On; break;
111 case BUTTONVALUE_OFF: nStyle |= QStyle::Style_Off; break;
112 case BUTTONVALUE_MIXED: nStyle |= QStyle::Style_NoChange; break;
113 default: break;
116 return nStyle;
121 /** Qt implementation of X11Pixmap
123 Wrapper around a QPixmap.
126 class KDEX11Pixmap : public X11Pixmap
128 public:
129 KDEX11Pixmap( int nWidth, int nHeight );
130 virtual ~KDEX11Pixmap() {};
132 virtual int GetDepth() const SAL_OVERRIDE;
133 virtual SalX11Screen GetScreen() const SAL_OVERRIDE;
134 virtual Pixmap GetPixmap() const SAL_OVERRIDE;
135 QPixmap GetQPixmap() const;
137 protected:
138 QPixmap mqPixmap;
141 KDEX11Pixmap::KDEX11Pixmap( int nWidth, int nHeight )
142 : X11Pixmap( nWidth, nHeight )
143 , mqPixmap( nWidth, nHeight )
147 int KDEX11Pixmap::GetDepth() const
149 return mqPixmap.x11Depth();
152 SalX11Screen KDEX11Pixmap::GetScreen() const
154 return SalX11Screen( mqPixmap.x11Screen() );
157 Pixmap KDEX11Pixmap::GetPixmap() const
159 return mqPixmap.handle();
162 QPixmap KDEX11Pixmap::GetQPixmap() const
164 return mqPixmap;
168 /** Cached native widgets.
170 A class which caches and paints the native widgets.
172 class WidgetPainter
174 protected:
175 /** Cached push button.
177 It is necessary for the QStyle::drawControl(). The buttons are created
178 on demand and they are still hidden (no QWidget::show() is called).
180 QPushButton *m_pPushButton;
182 /** Cached radio button.
184 @see m_pPushButton
186 QRadioButton *m_pRadioButton;
188 /** Cached check box.
190 @see m_pPushButton
192 QCheckBox *m_pCheckBox;
194 /** Cached combo box.
196 @see m_pPushButton
198 QComboBox *m_pComboBox;
200 /** Cached editable combo box.
202 Needed, because some styles do not like dynamic changes
203 (QComboBox::setEditable()).
205 @see m_pPushButton
207 QComboBox *m_pEditableComboBox;
209 /** Cached line edit box.
211 @see m_pPushButton
213 QLineEdit *m_pLineEdit;
215 /** Cached spin box.
217 @see m_pPushButton
219 QSpinWidget *m_pSpinWidget;
221 /** Cached spin box'es line edit.
223 @see m_pPushButton
225 QLineEdit *m_pSpinEdit;
227 /** Cached tab.
229 Left, middle, right tab and a tab which is alone.
231 @see m_pPushButton
233 QTab *m_pTabLeft, *m_pTabMiddle, *m_pTabRight, *m_pTabAlone;
235 /** Cached tab bar's parent widget.
237 Needed, because the Qt windows style checks for the availability
238 of tab bar's parent. We cannot use m_pTabWidget, because
239 TabWidget::setTabBar() and TabWidget::tabBar() methods are
240 protected.
242 @see m_pPushButton, m_pTabWidget
244 QWidget *m_pTabBarParent;
246 /** Cached tab bar widget.
248 @see m_pPushButton
250 QTabBar *m_pTabBar;
252 /** Cached tab widget.
254 We need it to draw the tab page. It cannot be used to draw the
255 tabs themselves, because the drawing has to be tweaked a little
256 due to not enough information from VCL.
258 @see m_pPushButton, m_pTabBarParent
260 QTabWidget *m_pTabWidget;
262 /** Cached list view.
264 @see m_pPushButton
266 QListView *m_pListView;
268 /** Cached scroll bar.
270 @see m_pPushButton
272 QScrollBar *m_pScrollBar;
274 /** Cached dock area. Needed for proper functionality of tool bars.
276 @see m_pPushButton
278 QMainWindow *m_pMainWindow;
280 /** Cached tool bar.
282 @see m_pPushButton
284 QToolBar *m_pToolBarHoriz, *m_pToolBarVert;
286 /** Cached tool button.
288 @see m_pPushButton
290 QToolButton *m_pToolButton;
292 /** Cached menu bar.
294 @see m_pPushButton
296 QMenuBar *m_pMenuBar;
298 /** Identifiers of menu bar items.
300 int m_nMenuBarEnabledItem, m_nMenuBarDisabledItem;
302 /** Cached popup menu.
304 @see m_pPushButton
306 QPopupMenu *m_pPopupMenu;
308 /** Identifiers of popup menu items.
310 int m_nPopupMenuEnabledItem, m_nPopupMenuDisabledItem;
312 /** cached progress bar
314 QProgressBar *m_pProgressBar;
316 // TODO other widgets
318 public:
319 /** Implicit constructor.
321 It creates an empty WidgetPainter with all the cached widgets initialized
322 to NULL. The widgets are created on demand and they are still hidden
323 (no QWidget::show()), because they are needed just as a parameter for
324 QStyle::drawControl().
326 @see m_pPushButton
328 WidgetPainter();
330 /** Destructor.
332 Destruct all the cached widgets.
334 virtual ~WidgetPainter();
336 /** Paints the specified widget to the X window.
338 Use X calls to bitblt (bit block transfer) the widget qWidget to
339 the window specified by drawable with the style defined by nStyle.
341 @param qWidget
342 A pointer to the cached widget.
344 @param nState
345 The state of the control (focused, on/off, ...)
347 @param aValue
348 The value (true/false, ...)
350 @param pGraphics
351 The SalGraphics instance to read/write screen.
353 bool drawStyledWidget( QWidget *pWidget,
354 ControlState nState, const ImplControlValue& aValue,
355 X11SalGraphics* pGraphics,
356 ControlPart nPart = PART_ENTIRE_CONTROL );
358 /** 'Get' method for push button.
360 The method returns the cached push button. It is constructed if it
361 does not exist. It has NULL as a parent and it stays hidden, but it
362 is necessary for the drawStyledWidget() method.
364 @return valid push button.
366 QPushButton *pushButton( const Rectangle& rControlRegion, bool bDefault );
368 /** 'Get' method for radio button.
370 @see pushButton()
372 QRadioButton *radioButton( const Rectangle& rControlRegion );
374 /** 'Get' method for check box.
376 @see pushButton()
378 QCheckBox *checkBox( const Rectangle& rControlRegion );
380 /** 'Get' method for combo box.
382 It returns m_pComboBox or m_pEditableComboBox according to
383 bEditable.
385 @see pushButton(), m_pEditableComboBox
387 QComboBox *comboBox( const Rectangle& rControlRegion, bool bEditable );
389 /** 'Get' method for line edit box.
391 @see pushButton()
393 QLineEdit *lineEdit( const Rectangle& rControlRegion );
395 /** 'Get' method for spin box.
397 @see pushButton()
399 QSpinWidget *spinWidget( const Rectangle& rControlRegion );
401 /** 'Get' method for tab bar.
403 @see pushButton()
405 QTabBar *tabBar( const Rectangle& rControlRegion );
407 /** 'Get' method for tab widget.
409 @see pushButton()
411 QTabWidget *tabWidget( const Rectangle& rControlRegion );
413 /** 'Get' method for list view.
415 @see pushButton()
417 QListView *listView( const Rectangle& rControlRegion );
419 /** 'Get' method for scroll bar.
421 @see pushButton()
423 QScrollBar *scrollBar( const Rectangle& rControlRegion,
424 bool bHorizontal, const ImplControlValue& aValue );
426 /** 'Get' method for tool bar.
428 @see pushButton()
430 QToolBar *toolBar( const Rectangle& rControlRegion, bool bHorizontal );
432 /** 'Get' method for tool button.
434 @see pushButton()
436 QToolButton *toolButton( const Rectangle& rControlRegion );
438 /** 'Get' method for menu bar.
440 @see pushButton()
442 QMenuBar *menuBar( const Rectangle& rControlRegion );
444 /** 'Get' method for popup menu.
446 @see pushButton()
448 QPopupMenu *popupMenu( const Rectangle& rControlRegion );
450 /** 'Get' method for progress bar
452 @see pushButton()
454 QProgressBar *progressBar( const Rectangle& rControlRegion );
456 // TODO other widgets
458 public:
459 /** Convert VCL Rectangle to QRect.
461 @param rControlRegion
462 The region to convert.
464 @return
465 The bounding box of the region.
467 static QRect region2QRect( const Rectangle& rControlRegion );
470 WidgetPainter::WidgetPainter()
471 : m_pPushButton( NULL ),
472 m_pRadioButton( NULL ),
473 m_pCheckBox( NULL ),
474 m_pComboBox( NULL ),
475 m_pEditableComboBox( NULL ),
476 m_pLineEdit( NULL ),
477 m_pSpinWidget( NULL ),
478 m_pSpinEdit( NULL ),
479 m_pTabLeft( NULL ),
480 m_pTabMiddle( NULL ),
481 m_pTabRight( NULL ),
482 m_pTabAlone( NULL ),
483 m_pTabBarParent( NULL ),
484 m_pTabBar( NULL ),
485 m_pTabWidget( NULL ),
486 m_pListView( NULL ),
487 m_pScrollBar( NULL ),
488 m_pMainWindow( NULL ),
489 m_pToolBarHoriz( NULL ),
490 m_pToolBarVert( NULL ),
491 m_pToolButton( NULL ),
492 m_pMenuBar( NULL ),
493 m_nMenuBarEnabledItem( 0 ),
494 m_nMenuBarDisabledItem( 0 ),
495 m_pPopupMenu( NULL ),
496 m_nPopupMenuEnabledItem( 0 ),
497 m_nPopupMenuDisabledItem( 0 ),
498 m_pProgressBar( NULL )
502 WidgetPainter::~WidgetPainter()
504 delete m_pPushButton, m_pPushButton = NULL;
505 delete m_pRadioButton, m_pRadioButton = NULL;
506 delete m_pCheckBox, m_pCheckBox = NULL;
507 delete m_pComboBox, m_pComboBox = NULL;
508 delete m_pEditableComboBox, m_pEditableComboBox = NULL;
509 delete m_pLineEdit, m_pLineEdit = NULL;
510 delete m_pSpinWidget, m_pSpinWidget = NULL;
511 m_pSpinEdit = NULL; // Deleted in m_pSpinWidget's destructor
512 delete m_pTabAlone, m_pTabAlone = NULL;
513 delete m_pTabBarParent, m_pTabBarParent = NULL;
514 m_pTabBar = NULL; // Deleted in m_pTabBarParent's destructor
515 m_pTabLeft = NULL;
516 m_pTabMiddle = NULL;
517 m_pTabRight = NULL;
518 delete m_pTabWidget, m_pTabWidget = NULL;
519 delete m_pListView, m_pListView = NULL;
520 delete m_pScrollBar, m_pScrollBar = NULL;
521 delete m_pToolBarHoriz, m_pToolBarHoriz = NULL;
522 delete m_pToolBarVert, m_pToolBarVert = NULL;
523 delete m_pMainWindow, m_pMainWindow = NULL;
524 delete m_pToolButton, m_pToolButton = NULL;
525 delete m_pMenuBar, m_pMenuBar = NULL;
526 delete m_pPopupMenu, m_pPopupMenu = NULL;
527 delete m_pProgressBar, m_pProgressBar = NULL;
530 bool WidgetPainter::drawStyledWidget( QWidget *pWidget,
531 ControlState nState, const ImplControlValue& aValue,
532 X11SalGraphics* pGraphics, ControlPart nPart )
534 if ( !pWidget )
535 return false;
537 // Normalize the widget
538 QPoint qWidgetPos( pWidget->pos() );
539 pWidget->move( 0, 0 );
541 // Enable/disable the widget
542 pWidget->setEnabled( bool(nState & ControlState::ENABLED) );
544 // Create pixmap to paint to
545 KDEX11Pixmap xPixmap( pWidget->width(), pWidget->height() );
546 QPixmap qPixmap( xPixmap.GetQPixmap() );
547 QPainter qPainter( &qPixmap );
548 QRect qRect( 0, 0, pWidget->width(), pWidget->height() );
550 // Use the background of the widget
551 qPixmap.fill( pWidget, QPoint(0, 0) );
553 // Convert the flags
554 QStyle::SFlags nStyle = vclStateValue2SFlags( nState, aValue );
556 // Store the widget class
557 const char *pClassName = pWidget->className();
559 // Draw the widget to the pixmap
560 if ( strcmp( QPushButton_String, pClassName ) == 0 )
562 // Workaround for the Platinum style.
563 // Platinum takes the state directly from the widget, not from SFlags.
564 QPushButton *pPushButton = static_cast<QPushButton *>( pWidget->qt_cast( QPushButton_String ) );
565 if ( pPushButton )
567 pPushButton->setDown ( nStyle & QStyle::Style_Down );
568 pPushButton->setOn ( nStyle & QStyle::Style_On );
569 pPushButton->setEnabled( nStyle & QStyle::Style_Enabled );
572 QApplication::style().drawControl( QStyle::CE_PushButton,
573 &qPainter, pWidget, qRect,
574 pWidget->colorGroup(), nStyle );
576 else if ( strcmp( QRadioButton_String, pClassName ) == 0 )
578 // Bitblt from the screen, because the radio buttons are usually not
579 // rectangular, and there could be a bitmap under them
580 pGraphics->FillPixmapFromScreen( &xPixmap, qWidgetPos.x(), qWidgetPos.y() );
582 QApplication::style().drawControl( QStyle::CE_RadioButton,
583 &qPainter, pWidget, qRect,
584 pWidget->colorGroup(), nStyle );
586 else if ( strcmp( QCheckBox_String, pClassName ) == 0 )
588 QApplication::style().drawControl( QStyle::CE_CheckBox,
589 &qPainter, pWidget, qRect,
590 pWidget->colorGroup(), nStyle );
592 else if ( strcmp( QComboBox_String, pClassName ) == 0 )
594 QApplication::style().drawComplexControl( QStyle::CC_ComboBox,
595 &qPainter, pWidget, qRect,
596 pWidget->colorGroup(), nStyle );
598 // Editable combo box uses the background of the associated edit box
599 QComboBox *pComboBox = static_cast<QComboBox *>( pWidget->qt_cast( QComboBox_String ) );
600 if ( pComboBox && pComboBox->editable() && pComboBox->lineEdit() )
602 QColorGroup::ColorRole eColorRole = ( pComboBox->isEnabled() )?
603 QColorGroup::Base: QColorGroup::Background;
604 qPainter.fillRect(
605 QApplication::style().querySubControlMetrics( QStyle::CC_ComboBox,
606 pComboBox, QStyle::SC_ComboBoxEditField ),
607 pComboBox->lineEdit()->colorGroup().brush( eColorRole ) );
610 else if ( strcmp( QLineEdit_String, pClassName ) == 0 )
612 QApplication::style().drawPrimitive( QStyle::PE_PanelLineEdit,
613 &qPainter, qRect,
614 pWidget->colorGroup(), nStyle | QStyle::Style_Sunken );
616 else if ( strcmp( QSpinWidget_String, pClassName ) == 0 )
618 const SpinbuttonValue* pValue = (aValue.getType() == CTRL_SPINBUTTONS) ? static_cast<const SpinbuttonValue*>(&aValue) : NULL;
620 // Is any of the buttons pressed?
621 QStyle::SCFlags eActive = QStyle::SC_None;
622 if ( pValue )
624 if ( pValue->mnUpperState & ControlState::PRESSED )
625 eActive = QStyle::SC_SpinWidgetUp;
626 else if ( pValue->mnLowerState & ControlState::PRESSED )
627 eActive = QStyle::SC_SpinWidgetDown;
629 // Update the enable/disable state of the widget
630 if ( ( nState & ControlState::ENABLED ) ||
631 ( pValue->mnUpperState & ControlState::ENABLED ) ||
632 ( pValue->mnLowerState & ControlState::ENABLED ) )
634 pWidget->setEnabled( true );
635 nStyle |= QStyle::Style_Enabled;
637 else
638 pWidget->setEnabled( false );
640 // Mouse-over effect
641 if ( (pValue->mnUpperState & ControlState::ROLLOVER) ||
642 (pValue->mnLowerState & ControlState::ROLLOVER) )
643 nStyle |= QStyle::Style_MouseOver;
646 // Spin widget uses the background of the associated edit box
647 QSpinWidget *pSpinWidget = static_cast<QSpinWidget *>( pWidget->qt_cast( QSpinWidget_String ) );
648 if ( pSpinWidget && pSpinWidget->editWidget() )
650 QColorGroup::ColorRole eColorRole = ( pSpinWidget->isEnabled() )?
651 QColorGroup::Base: QColorGroup::Background;
652 qPainter.fillRect(
653 QApplication::style().querySubControlMetrics( QStyle::CC_SpinWidget,
654 pSpinWidget, QStyle::SC_SpinWidgetEditField ),
655 pSpinWidget->editWidget()->colorGroup().brush( eColorRole ) );
658 // Adjust the frame (needed for Motif Plus style)
659 QRect qFrameRect = QApplication::style().querySubControlMetrics( QStyle::CC_SpinWidget,
660 pWidget, QStyle::SC_SpinWidgetFrame );
662 QApplication::style().drawComplexControl( QStyle::CC_SpinWidget,
663 &qPainter, pWidget, qFrameRect,
664 pWidget->colorGroup(), nStyle,
665 QStyle::SC_All, eActive );
667 else if ( strcmp( QTabBar_String, pClassName ) == 0 )
669 const TabitemValue *pValue = static_cast<const TabitemValue *> ( &aValue );
671 QTab *pTab = NULL;
672 if ( pValue )
674 if ( ( pValue->isFirst() || pValue->isLeftAligned() ) && ( pValue->isLast() || pValue->isRightAligned() ) )
675 pTab = m_pTabAlone;
676 else if ( pValue->isFirst() || pValue->isLeftAligned() )
677 pTab = m_pTabLeft;
678 else if ( pValue->isLast() || pValue->isRightAligned() )
679 pTab = m_pTabRight;
680 else
681 pTab = m_pTabMiddle;
683 if ( !pTab )
684 return false;
686 pTab->setRect( qRect );
688 QApplication::style().drawControl( QStyle::CE_TabBarTab,
689 &qPainter, pWidget, qRect,
690 pWidget->colorGroup(), nStyle,
691 QStyleOption( pTab ) );
693 else if ( strcmp( QTabWidget_String, pClassName ) == 0 )
695 QApplication::style().drawPrimitive( QStyle::PE_PanelTabWidget,
696 &qPainter, qRect,
697 pWidget->colorGroup(), nStyle );
699 else if ( strcmp( QListView_String, pClassName ) == 0 )
701 QApplication::style().drawPrimitive( QStyle::PE_Panel,
702 &qPainter, qRect,
703 pWidget->colorGroup(), nStyle | QStyle::Style_Sunken );
705 else if ( strcmp( QScrollBar_String, pClassName ) == 0 )
707 const ScrollbarValue* pValue = (aValue.getType() == CTRL_SCROLLBAR) ? static_cast<const ScrollbarValue*>(&aValue) : NULL;
709 QStyle::SCFlags eActive = QStyle::SC_None;
710 if ( pValue )
712 // Workaround for Style_MouseOver-aware themes.
713 // Quite ugly, but I do not know about a better solution.
714 const char *pStyleName = QApplication::style().className();
715 if ( strcmp( QMotifPlusStyle_String, pStyleName ) == 0 )
717 nStyle |= QStyle::Style_MouseOver;
718 if ( pValue->mnThumbState & ControlState::ROLLOVER )
719 eActive = QStyle::SC_ScrollBarSlider;
721 else if ( strcmp( QSGIStyle_String, pStyleName ) == 0 )
723 nStyle |= QStyle::Style_MouseOver;
724 if ( pValue->mnButton1State & ControlState::ROLLOVER )
725 eActive = QStyle::SC_ScrollBarSubLine;
726 else if ( pValue->mnButton2State & ControlState::ROLLOVER )
727 eActive = QStyle::SC_ScrollBarAddLine;
728 else if ( pValue->mnThumbState & ControlState::ROLLOVER )
729 eActive = QStyle::SC_ScrollBarSlider;
732 if ( pValue->mnButton1State & ControlState::PRESSED )
733 eActive = QStyle::SC_ScrollBarSubLine;
734 else if ( pValue->mnButton2State & ControlState::PRESSED )
735 eActive = QStyle::SC_ScrollBarAddLine;
736 else if ( pValue->mnThumbState & ControlState::PRESSED )
737 eActive = QStyle::SC_ScrollBarSlider;
738 else if ( pValue->mnPage1State & ControlState::PRESSED )
739 eActive = QStyle::SC_ScrollBarSubPage;
740 else if ( pValue->mnPage2State & ControlState::PRESSED )
741 eActive = QStyle::SC_ScrollBarAddPage;
743 // Update the enable/disable state of the widget
744 if ( ( nState & ControlState::ENABLED ) ||
745 ( pValue->mnButton1State & ControlState::ENABLED ) ||
746 ( pValue->mnButton2State & ControlState::ENABLED ) ||
747 ( pValue->mnThumbState & ControlState::ENABLED ) ||
748 ( pValue->mnPage1State & ControlState::ENABLED ) ||
749 ( pValue->mnPage2State & ControlState::ENABLED ) )
751 pWidget->setEnabled( true );
752 nStyle |= QStyle::Style_Enabled;
754 else
755 pWidget->setEnabled( false );
758 // Is it a horizontal scroll bar?
759 QScrollBar *pScrollBar = static_cast<QScrollBar *> ( pWidget->qt_cast( QScrollBar_String ) );
760 QStyle::StyleFlags eHoriz = QStyle::Style_Default;
761 if ( pScrollBar && pScrollBar->orientation() == Qt::Horizontal )
762 eHoriz = QStyle::Style_Horizontal;
764 QApplication::style().drawComplexControl( QStyle::CC_ScrollBar,
765 &qPainter, pWidget, qRect,
766 pWidget->colorGroup(), nStyle | eHoriz,
767 QStyle::SC_All, eActive );
769 else if ( strcmp( QToolBar_String, pClassName ) == 0 )
771 QToolBar *pToolBar = static_cast< QToolBar * >( pWidget->qt_cast( QToolBar_String ) );
772 bool bIsHorizontal = false;
773 if ( pToolBar && pToolBar->orientation() == Qt::Horizontal )
775 nStyle |= QStyle::Style_Horizontal;
776 bIsHorizontal = true;
779 QApplication::style().drawControl( QStyle::CE_DockWindowEmptyArea,
780 &qPainter, pWidget, qRect,
781 pWidget->colorGroup(), nStyle );
783 QApplication::style().drawPrimitive( QStyle::PE_PanelDockWindow,
784 &qPainter, qRect, pWidget->colorGroup(), nStyle );
786 if ( nPart == PART_THUMB_HORZ || nPart == PART_THUMB_VERT )
788 const ToolbarValue *pValue = static_cast< const ToolbarValue * >( &aValue );
790 QRect qThumbRect = region2QRect( pValue->maGripRect );
791 qThumbRect.moveBy( -qWidgetPos.x(), -qWidgetPos.y() );
792 if ( bIsHorizontal )
793 qThumbRect.addCoords( 0, 2, 0, -3 ); // make the thumb a bit nicer
794 else
795 qThumbRect.addCoords( 2, 0, -3, 0 ); // make the thumb a bit nicer
797 if ( QApplication::style().inherits( "HighColorStyle" ) ||
798 QApplication::style().inherits( "HighContrastStyle" ) ||
799 QApplication::style().inherits( "KeramikStyle" ) ||
800 QApplication::style().inherits( "KThemeStyle" ) ||
801 QApplication::style().inherits( "ThinKeramikStyle" ) )
803 // Workaround for the workaround in KStyle::drawPrimitive()
804 KStyle *pStyle = static_cast< KStyle * >( &QApplication::style() );
805 pStyle->drawKStylePrimitive( KStyle::KPE_ToolBarHandle,
806 &qPainter, pToolBar, qThumbRect,
807 pWidget->colorGroup(), nStyle );
809 else
810 QApplication::style().drawPrimitive( QStyle::PE_DockWindowHandle,
811 &qPainter, qThumbRect, pWidget->colorGroup(), nStyle );
814 else if ( strcmp( QToolButton_String, pClassName ) == 0 )
816 if( (nStyle & QStyle::Style_MouseOver) )
817 nStyle &= ~QStyle::Style_Off;
818 QApplication::style().drawComplexControl( QStyle::CC_ToolButton,
819 &qPainter, pWidget, qRect,
820 pWidget->colorGroup(), nStyle,
821 QStyle::SC_ToolButton );
823 else if ( strcmp( QMenuBar_String, pClassName ) == 0 )
825 if ( nPart == PART_ENTIRE_CONTROL )
827 QApplication::style().drawControl( QStyle::CE_MenuBarEmptyArea,
828 &qPainter, pWidget, qRect,
829 pWidget->colorGroup(), nStyle );
831 else if ( nPart == PART_MENU_ITEM )
833 int nMenuItem = ( nStyle & QStyle::Style_Enabled )? m_nMenuBarEnabledItem: m_nMenuBarDisabledItem;
834 QMenuItem *pMenuItem = static_cast<QMenuBar*>( pWidget )->findItem( nMenuItem );
836 if ( ( nStyle & QStyle::Style_MouseOver )
837 && QApplication::style().styleHint( QStyle::SH_MenuBar_MouseTracking ) )
838 nStyle |= QStyle::Style_Active;
840 if ( nStyle & QStyle::Style_Selected )
841 nStyle |= QStyle::Style_Active | QStyle::Style_Down | QStyle::Style_HasFocus;
843 QApplication::style().drawControl( QStyle::CE_MenuBarItem,
844 &qPainter, pWidget, qRect,
845 pWidget->colorGroup(), nStyle,
846 QStyleOption( pMenuItem ) );
849 else if ( strcmp( QPopupMenu_String, pClassName ) == 0 )
851 int nMenuItem = ( nStyle & QStyle::Style_Enabled )? m_nPopupMenuEnabledItem: m_nPopupMenuDisabledItem;
852 QMenuItem *pMenuItem = static_cast<QPopupMenu*>( pWidget )->findItem( nMenuItem );
854 if ( nStyle & QStyle::Style_Selected )
855 nStyle |= QStyle::Style_Active;
857 QApplication::style().drawControl( QStyle::CE_PopupMenuItem,
858 &qPainter, pWidget, qRect,
859 pWidget->colorGroup(), nStyle,
860 QStyleOption( pMenuItem, 0, 0 ) );
862 else if ( strcmp( QProgressBar_String, pClassName ) == 0 )
864 long nProgressWidth = aValue.getNumericVal();
865 QProgressBar* pProgress = static_cast<QProgressBar*>(pWidget);
866 pProgress->setProgress( nProgressWidth, qRect.width() );
868 QApplication::style().drawControl( QStyle::CE_ProgressBarGroove,
869 &qPainter, pWidget, qRect,
870 pWidget->colorGroup(), nStyle );
871 QApplication::style().drawControl( QStyle::CE_ProgressBarContents,
872 &qPainter, pWidget, qRect,
873 pWidget->colorGroup(), nStyle );
875 else
876 return false;
878 // Bitblt it to the screen
879 pGraphics->RenderPixmapToScreen( &xPixmap, NULL, qWidgetPos.x(), qWidgetPos.y() );
881 // Restore widget's position
882 pWidget->move( qWidgetPos );
884 return true;
887 QPushButton *WidgetPainter::pushButton( const Rectangle& rControlRegion,
888 bool bDefault )
890 if ( !m_pPushButton )
891 m_pPushButton = new QPushButton( NULL, "push_button" );
893 QRect qRect = region2QRect( rControlRegion );
895 // Workaround for broken styles which do not add
896 // QStyle::PM_ButtonDefaultIndicator to the size of the default button
897 // (for example Keramik)
898 // FIXME Fix Keramik style to be consistent with Qt built-in styles. Aargh!
899 if ( bDefault )
901 QSize qContentsSize( 50, 50 );
902 m_pPushButton->setDefault( false );
903 QSize qNormalSize = QApplication::style().sizeFromContents( QStyle::CT_PushButton,
904 m_pPushButton, qContentsSize );
905 m_pPushButton->setDefault( true );
906 QSize qDefSize = QApplication::style().sizeFromContents( QStyle::CT_PushButton,
907 m_pPushButton, qContentsSize );
909 int nIndicatorSize = QApplication::style().pixelMetric(
910 QStyle::PM_ButtonDefaultIndicator, m_pPushButton );
911 if ( qNormalSize.width() == qDefSize.width() )
912 qRect.addCoords( nIndicatorSize, 0, -nIndicatorSize, 0 );
913 if ( qNormalSize.height() == qDefSize.height() )
914 qRect.addCoords( 0, nIndicatorSize, 0, -nIndicatorSize );
917 m_pPushButton->move( qRect.topLeft() );
918 m_pPushButton->resize( qRect.size() );
919 m_pPushButton->setDefault( bDefault );
921 return m_pPushButton;
924 QRadioButton *WidgetPainter::radioButton( const Rectangle& rControlRegion )
926 if ( !m_pRadioButton )
927 m_pRadioButton = new QRadioButton( NULL, "radio_button" );
929 QRect qRect = region2QRect( rControlRegion );
931 // Workaround for broken themes which do not honor the given size.
932 // Quite ugly, but I do not know about a better solution.
933 const char *pStyleName = QApplication::style().className();
934 if ( strcmp( "KThemeStyle", pStyleName ) == 0 )
936 QRect qOldRect( qRect );
938 qRect.setWidth( QApplication::style().pixelMetric(
939 QStyle::PM_ExclusiveIndicatorWidth, m_pRadioButton ) );
940 qRect.setHeight( QApplication::style().pixelMetric(
941 QStyle::PM_ExclusiveIndicatorHeight, m_pRadioButton ) );
943 qRect.moveBy( ( qOldRect.width() - qRect.width() ) / 2,
944 ( qOldRect.height() - qRect.height() ) / 2 );
947 m_pRadioButton->move( qRect.topLeft() );
948 m_pRadioButton->resize( qRect.size() );
950 return m_pRadioButton;
953 QCheckBox *WidgetPainter::checkBox( const Rectangle& rControlRegion )
955 if ( !m_pCheckBox )
956 m_pCheckBox = new QCheckBox( NULL, "check_box" );
958 QRect qRect = region2QRect( rControlRegion );
960 // Workaround for broken themes which do not honor the given size.
961 // Quite ugly, but I do not know about a better solution.
962 const char *pStyleName = QApplication::style().className();
963 if ( strcmp( "KThemeStyle", pStyleName ) == 0 )
965 QRect qOldRect( qRect );
967 qRect.setWidth( QApplication::style().pixelMetric(
968 QStyle::PM_IndicatorWidth, m_pCheckBox ) );
969 qRect.setHeight( QApplication::style().pixelMetric(
970 QStyle::PM_IndicatorHeight, m_pCheckBox ) );
972 qRect.moveBy( ( qOldRect.width() - qRect.width() ) / 2,
973 ( qOldRect.height() - qRect.height() ) / 2 );
976 m_pCheckBox->move( qRect.topLeft() );
977 m_pCheckBox->resize( qRect.size() );
979 return m_pCheckBox;
982 QComboBox *WidgetPainter::comboBox( const Rectangle& rControlRegion,
983 bool bEditable )
985 QComboBox *pComboBox = NULL;
986 if ( bEditable )
988 if ( !m_pEditableComboBox )
989 m_pEditableComboBox = new QComboBox( true, NULL, "combo_box_edit" );
990 pComboBox = m_pEditableComboBox;
992 else
994 if ( !m_pComboBox )
995 m_pComboBox = new QComboBox( false, NULL, "combo_box" );
996 pComboBox = m_pComboBox;
999 QRect qRect = region2QRect( rControlRegion );
1001 pComboBox->move( qRect.topLeft() );
1002 pComboBox->resize( qRect.size() );
1004 return pComboBox;
1007 QLineEdit *WidgetPainter::lineEdit( const Rectangle& rControlRegion )
1009 if ( !m_pLineEdit )
1010 m_pLineEdit = new QLineEdit( NULL, "line_edit" );
1012 QRect qRect = region2QRect( rControlRegion );
1014 m_pLineEdit->move( qRect.topLeft() );
1015 m_pLineEdit->resize( qRect.size() );
1017 return m_pLineEdit;
1020 QSpinWidget *WidgetPainter::spinWidget( const Rectangle& rControlRegion )
1022 if ( !m_pSpinWidget )
1024 m_pSpinWidget = new QSpinWidget( NULL, "spin_widget" );
1025 m_pSpinEdit = new QLineEdit( NULL, "line_edit_spin" );
1026 m_pSpinWidget->setEditWidget( m_pSpinEdit );
1029 QRect qRect = region2QRect( rControlRegion );
1031 m_pSpinWidget->move( qRect.topLeft() );
1032 m_pSpinWidget->resize( qRect.size() );
1033 m_pSpinWidget->arrange();
1035 return m_pSpinWidget;
1038 QTabBar *WidgetPainter::tabBar( const Rectangle& rControlRegion )
1040 if ( !m_pTabBar )
1042 if ( !m_pTabBarParent )
1043 m_pTabBarParent = new QWidget( NULL, "tab_bar_parent" );
1045 m_pTabBar = new QTabBar( m_pTabBarParent, "tab_bar" );
1047 m_pTabLeft = new QTab();
1048 m_pTabMiddle = new QTab();
1049 m_pTabRight = new QTab();
1050 m_pTabAlone = new QTab();
1052 m_pTabBar->addTab( m_pTabLeft );
1053 m_pTabBar->addTab( m_pTabMiddle );
1054 m_pTabBar->addTab( m_pTabRight );
1057 QRect qRect = region2QRect( rControlRegion );
1059 m_pTabBar->move( qRect.topLeft() );
1060 m_pTabBar->resize( qRect.size() );
1062 m_pTabBar->setShape( QTabBar::RoundedAbove );
1064 return m_pTabBar;
1067 QTabWidget *WidgetPainter::tabWidget( const Rectangle& rControlRegion )
1069 if ( !m_pTabWidget )
1070 m_pTabWidget = new QTabWidget( NULL, "tab_widget" );
1072 QRect qRect = region2QRect( rControlRegion );
1073 --qRect.rTop();
1075 m_pTabWidget->move( qRect.topLeft() );
1076 m_pTabWidget->resize( qRect.size() );
1078 return m_pTabWidget;
1081 QListView *WidgetPainter::listView( const Rectangle& rControlRegion )
1083 if ( !m_pListView )
1084 m_pListView = new QListView( NULL, "list_view" );
1086 QRect qRect = region2QRect( rControlRegion );
1088 m_pListView->move( qRect.topLeft() );
1089 m_pListView->resize( qRect.size() );
1091 return m_pListView;
1094 QScrollBar *WidgetPainter::scrollBar( const Rectangle& rControlRegion,
1095 bool bHorizontal, const ImplControlValue& aValue )
1097 if ( !m_pScrollBar )
1099 m_pScrollBar = new QScrollBar( NULL, "scroll_bar" );
1100 m_pScrollBar->setTracking( false );
1101 m_pScrollBar->setLineStep( 1 );
1104 QRect qRect = region2QRect( rControlRegion );
1106 m_pScrollBar->move( qRect.topLeft() );
1107 m_pScrollBar->resize( qRect.size() );
1108 m_pScrollBar->setOrientation( bHorizontal? Qt::Horizontal: Qt::Vertical );
1110 const ScrollbarValue* pValue = (aValue.getType() == CTRL_SCROLLBAR) ? static_cast<const ScrollbarValue*>(&aValue) : NULL;
1111 if ( pValue )
1113 m_pScrollBar->setMinValue( pValue->mnMin );
1114 m_pScrollBar->setMaxValue( pValue->mnMax - pValue->mnVisibleSize );
1115 m_pScrollBar->setValue( pValue->mnCur );
1116 m_pScrollBar->setPageStep( pValue->mnVisibleSize );
1119 return m_pScrollBar;
1122 QToolBar *WidgetPainter::toolBar( const Rectangle& rControlRegion, bool bHorizontal )
1124 if ( !m_pMainWindow )
1125 m_pMainWindow = new QMainWindow( NULL, "main_window" );
1127 QToolBar *pToolBar;
1128 if ( bHorizontal )
1130 if ( !m_pToolBarHoriz )
1132 m_pToolBarHoriz = new QToolBar( m_pMainWindow, "tool_bar_horiz" );
1133 m_pMainWindow->moveDockWindow( m_pToolBarHoriz, Qt::DockTop );
1135 pToolBar = m_pToolBarHoriz;
1137 else
1139 if ( !m_pToolBarVert )
1141 m_pToolBarVert = new QToolBar( m_pMainWindow, "tool_bar_horiz" );
1142 m_pMainWindow->moveDockWindow( m_pToolBarVert, Qt::DockLeft );
1144 pToolBar = m_pToolBarVert;
1147 QRect qRect = region2QRect( rControlRegion );
1149 pToolBar->move( qRect.topLeft() );
1150 pToolBar->resize( qRect.size() );
1152 return pToolBar;
1155 QToolButton *WidgetPainter::toolButton( const Rectangle& rControlRegion)
1157 if ( !m_pToolButton )
1158 m_pToolButton = new QToolButton( NULL, "tool_button" );
1160 QRect qRect = region2QRect( rControlRegion );
1162 m_pToolButton->move( qRect.topLeft() );
1163 m_pToolButton->resize( qRect.size() );
1165 return m_pToolButton;
1168 QMenuBar *WidgetPainter::menuBar( const Rectangle& rControlRegion)
1170 if ( !m_pMenuBar )
1172 m_pMenuBar = new QMenuBar( NULL, "menu_bar" );
1174 m_nMenuBarEnabledItem = m_pMenuBar->insertItem( "" );
1175 m_nMenuBarDisabledItem = m_pMenuBar->insertItem( "" );
1177 m_pMenuBar->setItemEnabled( m_nMenuBarEnabledItem, true );
1178 m_pMenuBar->setItemEnabled( m_nMenuBarDisabledItem, false );
1181 QRect qRect = region2QRect( rControlRegion );
1183 m_pMenuBar->move( qRect.topLeft() );
1184 m_pMenuBar->resize( qRect.size() );
1186 return m_pMenuBar;
1189 QPopupMenu *WidgetPainter::popupMenu( const Rectangle& rControlRegion)
1191 if ( !m_pPopupMenu )
1193 m_pPopupMenu = new QPopupMenu( NULL, "popup_menu" );
1195 m_nPopupMenuEnabledItem = m_pPopupMenu->insertItem( "" );
1196 m_nPopupMenuDisabledItem = m_pPopupMenu->insertItem( "" );
1198 m_pPopupMenu->setItemEnabled( m_nPopupMenuEnabledItem, true );
1199 m_pPopupMenu->setItemEnabled( m_nPopupMenuDisabledItem, false );
1202 QRect qRect = region2QRect( rControlRegion );
1204 m_pPopupMenu->move( qRect.topLeft() );
1205 m_pPopupMenu->resize( qRect.size() );
1207 return m_pPopupMenu;
1210 QProgressBar *WidgetPainter::progressBar( const Rectangle& rControlRegion )
1212 if ( !m_pProgressBar )
1213 m_pProgressBar = new QProgressBar( NULL, "progress_bar" );
1215 QRect qRect = region2QRect( rControlRegion );
1217 m_pProgressBar->move( qRect.topLeft() );
1218 m_pProgressBar->resize( qRect.size() );
1220 return m_pProgressBar;
1223 QRect WidgetPainter::region2QRect( const Rectangle& rControlRegion )
1225 return QRect( QPoint( rControlRegion.Left(), rControlRegion.Top() ),
1226 QPoint( rControlRegion.Right(), rControlRegion.Bottom() ) );
1229 /** Instance of WidgetPainter.
1231 It is used to paint the widgets requested by NWF.
1233 static WidgetPainter *pWidgetPainter;
1235 class KDESalGraphics : public X11SalGraphics
1237 public:
1238 KDESalGraphics() {}
1239 virtual ~KDESalGraphics() {}
1240 virtual bool IsNativeControlSupported( ControlType nType, ControlPart nPart ) SAL_OVERRIDE;
1241 virtual bool hitTestNativeControl( ControlType nType, ControlPart nPart,
1242 const Rectangle& rControlRegion, const Point& aPos,
1243 bool& rIsInside ) SAL_OVERRIDE;
1244 virtual bool drawNativeControl( ControlType nType, ControlPart nPart,
1245 const Rectangle& rControlRegion, ControlState nState,
1246 const ImplControlValue& aValue,
1247 const OUString& aCaption ) SAL_OVERRIDE;
1248 virtual bool getNativeControlRegion( ControlType nType, ControlPart nPart,
1249 const Rectangle& rControlRegion, ControlState nState,
1250 const ImplControlValue& aValue,
1251 const OUString& aCaption,
1252 Rectangle &rNativeBoundingRegion, Rectangle &rNativeContentRegion ) SAL_OVERRIDE;
1255 /** What widgets can be drawn the native way.
1257 @param nType
1258 Type of the widget.
1260 @param nPart
1261 Specification of the widget's part if it consists of more than one.
1263 @return true if the platform supports native drawing of the widget nType
1264 defined by nPart.
1266 bool KDESalGraphics::IsNativeControlSupported( ControlType nType, ControlPart nPart )
1268 return
1269 ( (nType == CTRL_PUSHBUTTON) && (nPart == PART_ENTIRE_CONTROL) ) ||
1270 ( (nType == CTRL_RADIOBUTTON) && (nPart == PART_ENTIRE_CONTROL) ) ||
1271 ( (nType == CTRL_CHECKBOX) && (nPart == PART_ENTIRE_CONTROL) ) ||
1272 ( (nType == CTRL_COMBOBOX) && (nPart == PART_ENTIRE_CONTROL || nPart == HAS_BACKGROUND_TEXTURE) ) ||
1273 ( (nType == CTRL_EDITBOX) && (nPart == PART_ENTIRE_CONTROL || nPart == HAS_BACKGROUND_TEXTURE) ) ||
1274 ( (nType == CTRL_LISTBOX) && (nPart == PART_ENTIRE_CONTROL || nPart == PART_WINDOW || nPart == HAS_BACKGROUND_TEXTURE ) ) ||
1275 ( (nType == CTRL_SPINBOX) && (nPart == PART_ENTIRE_CONTROL || nPart == HAS_BACKGROUND_TEXTURE) ) ||
1276 // no CTRL_SPINBUTTONS for KDE
1277 ( (nType == CTRL_TAB_ITEM) && (nPart == PART_ENTIRE_CONTROL) ) ||
1278 ( (nType == CTRL_TAB_PANE) && (nPart == PART_ENTIRE_CONTROL) ) ||
1279 // no CTRL_TAB_BODY for KDE
1280 ( (nType == CTRL_SCROLLBAR) && (nPart == PART_ENTIRE_CONTROL || nPart == PART_DRAW_BACKGROUND_HORZ || nPart == PART_DRAW_BACKGROUND_VERT) ) ||
1281 ( (nType == CTRL_SCROLLBAR) && (nPart == HAS_THREE_BUTTONS) ) || // TODO small optimization is possible here: return this only if the style really has 3 buttons
1282 // CTRL_GROUPBOX not supported
1283 // CTRL_FIXEDLINE not supported
1284 ( (nType == CTRL_TOOLBAR) && (nPart == PART_ENTIRE_CONTROL ||
1285 nPart == PART_DRAW_BACKGROUND_HORZ || nPart == PART_DRAW_BACKGROUND_VERT ||
1286 nPart == PART_THUMB_HORZ || nPart == PART_THUMB_VERT ||
1287 nPart == PART_BUTTON) ) ||
1288 ( (nType == CTRL_MENUBAR) && (nPart == PART_ENTIRE_CONTROL || nPart == PART_MENU_ITEM) ) ||
1289 ( (nType == CTRL_MENU_POPUP) && (nPart == PART_ENTIRE_CONTROL || nPart == PART_MENU_ITEM) ) ||
1290 ( (nType == CTRL_PROGRESS) && (nPart == PART_ENTIRE_CONTROL) )
1294 /** Test whether the position is in the native widget.
1296 If the return value is true, bIsInside contains information whether
1297 aPos was or was not inside the native widget specified by the
1298 nType/nPart combination.
1300 bool KDESalGraphics::hitTestNativeControl( ControlType nType, ControlPart nPart,
1301 const Rectangle& rControlRegion, const Point& rPos,
1302 bool& rIsInside )
1304 if ( nType == CTRL_SCROLLBAR )
1306 // make position relative to rControlRegion
1307 Point aPos = rPos - rControlRegion.TopLeft();
1308 rIsInside = false;
1310 bool bHorizontal = ( nPart == PART_BUTTON_LEFT || nPart == PART_BUTTON_RIGHT );
1312 QScrollBar *pScrollBar = pWidgetPainter->scrollBar( rControlRegion,
1313 bHorizontal, ImplControlValue() );
1314 QRect qRectSubLine = QApplication::style().querySubControlMetrics(
1315 QStyle::CC_ScrollBar, pScrollBar, QStyle::SC_ScrollBarSubLine );
1316 QRect qRectAddLine = QApplication::style().querySubControlMetrics(
1317 QStyle::CC_ScrollBar, pScrollBar, QStyle::SC_ScrollBarAddLine );
1319 // There are 2 buttons on the right/bottom side of the scrollbar
1320 bool bTwoSubButtons = false;
1322 // It is a Platinum style scroll bar
1323 bool bPlatinumStyle = false;
1325 // Workaround for Platinum and 3 button style scroll bars.
1326 // It makes the right/down button bigger.
1327 if ( bHorizontal )
1329 qRectAddLine.setLeft( QApplication::style().querySubControlMetrics(
1330 QStyle::CC_ScrollBar, pScrollBar,
1331 QStyle::SC_ScrollBarAddPage ).right() + 1 );
1332 if ( qRectAddLine.width() > qRectSubLine.width() )
1333 bTwoSubButtons = true;
1334 if ( qRectSubLine.left() > QApplication::style().querySubControlMetrics( QStyle::CC_ScrollBar, pScrollBar, QStyle::SC_ScrollBarSubPage ).left() )
1335 bPlatinumStyle = true;
1337 else
1339 qRectAddLine.setTop( QApplication::style().querySubControlMetrics(
1340 QStyle::CC_ScrollBar, pScrollBar,
1341 QStyle::SC_ScrollBarAddPage ).bottom() + 1 );
1342 if ( qRectAddLine.height() > qRectSubLine.height() )
1343 bTwoSubButtons = true;
1344 if ( qRectSubLine.top() > QApplication::style().querySubControlMetrics( QStyle::CC_ScrollBar, pScrollBar, QStyle::SC_ScrollBarSubPage ).top() )
1345 bPlatinumStyle = true;
1348 switch ( nPart )
1350 case PART_BUTTON_LEFT:
1351 if ( !bPlatinumStyle && qRectSubLine.contains( aPos.getX(), aPos.getY() ) )
1352 rIsInside = true;
1353 else if ( bTwoSubButtons )
1355 qRectAddLine.setWidth( qRectAddLine.width() / 2 );
1356 rIsInside = qRectAddLine.contains( aPos.getX(), aPos.getY() );
1358 break;
1360 case PART_BUTTON_UP:
1361 if ( !bPlatinumStyle && qRectSubLine.contains( aPos.getX(), aPos.getY() ) )
1362 rIsInside = true;
1363 else if ( bTwoSubButtons )
1365 qRectAddLine.setHeight( qRectAddLine.height() / 2 );
1366 rIsInside = qRectAddLine.contains( aPos.getX(), aPos.getY() );
1368 break;
1370 case PART_BUTTON_RIGHT:
1371 if ( bTwoSubButtons )
1372 qRectAddLine.setLeft( qRectAddLine.left() + qRectAddLine.width() / 2 );
1374 rIsInside = qRectAddLine.contains( aPos.getX(), aPos.getY() );
1375 break;
1377 case PART_BUTTON_DOWN:
1378 if ( bTwoSubButtons )
1379 qRectAddLine.setTop( qRectAddLine.top() + qRectAddLine.height() / 2 );
1381 rIsInside = qRectAddLine.contains( aPos.getX(), aPos.getY() );
1382 break;
1384 // cases PART_TRACK_HORZ_AREA and PART_TRACK_VERT_AREA
1385 default:
1386 return false;
1389 return true;
1392 return false;
1395 /** Draw the requested control described by nPart/nState.
1397 @param rControlRegion
1398 The bounding region of the complete control in VCL frame coordinates.
1400 @param aValue
1401 An optional value (tristate/numerical/string).
1403 @param aCaption
1404 A caption or title string (like button text etc.)
1406 bool KDESalGraphics::drawNativeControl( ControlType nType, ControlPart nPart,
1407 const Rectangle& rControlRegion, ControlState nState,
1408 const ImplControlValue& aValue,
1409 const OUString& )
1411 bool bReturn = false;
1413 if ( (nType == CTRL_PUSHBUTTON) && (nPart == PART_ENTIRE_CONTROL) )
1415 bReturn = pWidgetPainter->drawStyledWidget(
1416 pWidgetPainter->pushButton( rControlRegion, bool(nState & ControlState::DEFAULT) ),
1417 nState, aValue, this );
1419 else if ( (nType == CTRL_RADIOBUTTON) && (nPart == PART_ENTIRE_CONTROL) )
1421 bReturn = pWidgetPainter->drawStyledWidget(
1422 pWidgetPainter->radioButton( rControlRegion ),
1423 nState, aValue, this );
1425 else if ( (nType == CTRL_CHECKBOX) && (nPart == PART_ENTIRE_CONTROL) )
1427 bReturn = pWidgetPainter->drawStyledWidget(
1428 pWidgetPainter->checkBox( rControlRegion ),
1429 nState, aValue, this );
1431 else if ( (nType == CTRL_COMBOBOX) && (nPart == PART_ENTIRE_CONTROL) )
1433 bReturn = pWidgetPainter->drawStyledWidget(
1434 pWidgetPainter->comboBox( rControlRegion, true ),
1435 nState, aValue, this );
1437 else if ( (nType == CTRL_EDITBOX) && (nPart == PART_ENTIRE_CONTROL) )
1439 bReturn = pWidgetPainter->drawStyledWidget(
1440 pWidgetPainter->lineEdit( rControlRegion ),
1441 nState, aValue, this );
1443 else if ( (nType == CTRL_LISTBOX) && (nPart == PART_ENTIRE_CONTROL) )
1445 bReturn = pWidgetPainter->drawStyledWidget(
1446 pWidgetPainter->comboBox( rControlRegion, false ),
1447 nState, aValue, this );
1449 else if ( (nType == CTRL_LISTBOX) && (nPart == PART_WINDOW) )
1451 bReturn = pWidgetPainter->drawStyledWidget(
1452 pWidgetPainter->listView( rControlRegion ),
1453 nState, aValue, this );
1455 else if ( (nType == CTRL_SPINBOX) && (nPart == PART_ENTIRE_CONTROL) )
1457 bReturn = pWidgetPainter->drawStyledWidget(
1458 pWidgetPainter->spinWidget( rControlRegion ),
1459 nState, aValue, this );
1461 else if ( (nType==CTRL_TAB_ITEM) && (nPart == PART_ENTIRE_CONTROL) )
1463 bReturn = pWidgetPainter->drawStyledWidget(
1464 pWidgetPainter->tabBar( rControlRegion ),
1465 nState, aValue, this );
1467 else if ( (nType==CTRL_TAB_PANE) && (nPart == PART_ENTIRE_CONTROL) )
1469 bReturn = pWidgetPainter->drawStyledWidget(
1470 pWidgetPainter->tabWidget( rControlRegion ),
1471 nState, aValue, this );
1473 else if ( (nType == CTRL_SCROLLBAR) && (nPart == PART_DRAW_BACKGROUND_HORZ || nPart == PART_DRAW_BACKGROUND_VERT) )
1475 bReturn = pWidgetPainter->drawStyledWidget(
1476 pWidgetPainter->scrollBar( rControlRegion, nPart == PART_DRAW_BACKGROUND_HORZ, aValue ),
1477 nState, aValue, this );
1479 else if ( (nType == CTRL_TOOLBAR) && (nPart == PART_DRAW_BACKGROUND_HORZ || nPart == PART_DRAW_BACKGROUND_VERT || nPart == PART_THUMB_HORZ || nPart == PART_THUMB_VERT) )
1481 bReturn = pWidgetPainter->drawStyledWidget(
1482 pWidgetPainter->toolBar( rControlRegion, nPart == PART_DRAW_BACKGROUND_HORZ || nPart == PART_THUMB_VERT ),
1483 nState, aValue, this, nPart );
1485 else if ( (nType == CTRL_TOOLBAR) && (nPart == PART_BUTTON) )
1487 bReturn = pWidgetPainter->drawStyledWidget(
1488 pWidgetPainter->toolButton( rControlRegion ),
1489 nState, aValue, this, nPart );
1491 else if ( (nType == CTRL_MENUBAR) && (nPart == PART_ENTIRE_CONTROL || nPart == PART_MENU_ITEM) )
1493 bReturn = pWidgetPainter->drawStyledWidget(
1494 pWidgetPainter->menuBar( rControlRegion ),
1495 nState, aValue, this, nPart );
1497 else if ( (nType == CTRL_MENU_POPUP) && (nPart == PART_ENTIRE_CONTROL || nPart == PART_MENU_ITEM) )
1499 bReturn = pWidgetPainter->drawStyledWidget(
1500 pWidgetPainter->popupMenu( rControlRegion ),
1501 nState, aValue, this );
1503 else if ( (nType == CTRL_PROGRESS) && (nPart == PART_ENTIRE_CONTROL) )
1505 bReturn = pWidgetPainter->drawStyledWidget(
1506 pWidgetPainter->progressBar( rControlRegion ),
1507 nState, aValue, this );
1510 return bReturn;
1513 /** Check if the bounding regions match.
1515 If the return value is true, rNativeBoundingRegion
1516 contains the true bounding region covered by the control
1517 including any adornment, while rNativeContentRegion contains the area
1518 within the control that can be safely drawn into without drawing over
1519 the borders of the control.
1521 @param rControlRegion
1522 The bounding region of the control in VCL frame coordinates.
1524 @param aValue
1525 An optional value (tristate/numerical/string)
1527 @param aCaption
1528 A caption or title string (like button text etc.)
1530 bool KDESalGraphics::getNativeControlRegion( ControlType nType, ControlPart nPart,
1531 const Rectangle& rControlRegion, ControlState nState,
1532 const ImplControlValue&,
1533 const OUString&,
1534 Rectangle &rNativeBoundingRegion, Rectangle &rNativeContentRegion )
1536 bool bReturn = false;
1537 QRect qBoundingRect = WidgetPainter::region2QRect( rControlRegion );
1538 QRect qRect;
1540 QWidget *pWidget = NULL;
1541 switch ( nType )
1543 // Metrics of the push button
1544 case CTRL_PUSHBUTTON:
1545 pWidget = pWidgetPainter->pushButton( rControlRegion, bool( nState & ControlState::DEFAULT ) );
1547 switch ( nPart )
1549 case PART_ENTIRE_CONTROL:
1550 qRect = qBoundingRect;
1552 if ( nState & ControlState::DEFAULT )
1554 int nIndicatorSize = QApplication::style().pixelMetric(
1555 QStyle::PM_ButtonDefaultIndicator, pWidget );
1556 qBoundingRect.addCoords( -nIndicatorSize, -nIndicatorSize,
1557 nIndicatorSize, nIndicatorSize );
1558 bReturn = true;
1560 break;
1562 break;
1564 // Metrics of the radio button
1565 case CTRL_RADIOBUTTON:
1566 pWidget = pWidgetPainter->radioButton( rControlRegion );
1568 if ( nPart == PART_ENTIRE_CONTROL )
1570 qRect.setWidth( QApplication::style().pixelMetric( QStyle::PM_ExclusiveIndicatorWidth, pWidget ) );
1571 qRect.setHeight( QApplication::style().pixelMetric( QStyle::PM_ExclusiveIndicatorHeight, pWidget ) );
1573 bReturn = true;
1575 break;
1577 // Metrics of the check box
1578 case CTRL_CHECKBOX:
1579 pWidget = pWidgetPainter->checkBox( rControlRegion );
1581 if ( nPart == PART_ENTIRE_CONTROL )
1583 qRect.setWidth( QApplication::style().pixelMetric( QStyle::PM_IndicatorWidth, pWidget ) );
1584 qRect.setHeight( QApplication::style().pixelMetric( QStyle::PM_IndicatorHeight, pWidget ) );
1586 bReturn = true;
1588 break;
1590 // Metrics of the combo box
1591 case CTRL_COMBOBOX:
1592 case CTRL_LISTBOX:
1593 pWidget = pWidgetPainter->comboBox( rControlRegion, ( nType == CTRL_COMBOBOX ) );
1594 switch ( nPart )
1596 case PART_BUTTON_DOWN:
1597 qRect = QApplication::style().querySubControlMetrics(
1598 QStyle::CC_ComboBox, pWidget, QStyle::SC_ComboBoxArrow );
1599 qRect.setLeft( QApplication::style().querySubControlMetrics(
1600 QStyle::CC_ComboBox, pWidget,
1601 QStyle::SC_ComboBoxEditField ).right() + 1 );
1602 qRect.moveBy( qBoundingRect.left(), qBoundingRect.top() );
1603 bReturn = true;
1604 break;
1606 case PART_SUB_EDIT:
1607 qRect = QApplication::style().querySubControlMetrics(
1608 QStyle::CC_ComboBox, pWidget, QStyle::SC_ComboBoxEditField );
1609 qRect.moveBy( qBoundingRect.left(), qBoundingRect.top() );
1610 bReturn = true;
1611 break;
1613 break;
1615 // Metrics of the spin box
1616 case CTRL_SPINBOX:
1617 pWidget = pWidgetPainter->spinWidget( rControlRegion );
1618 switch ( nPart )
1620 case PART_BUTTON_UP:
1621 qRect = QApplication::style().querySubControlMetrics(
1622 QStyle::CC_SpinWidget, pWidget, QStyle::SC_SpinWidgetUp );
1623 bReturn = true;
1624 qRect.moveBy( qBoundingRect.left(), qBoundingRect.top() );
1625 break;
1627 case PART_BUTTON_DOWN:
1628 qRect = QApplication::style().querySubControlMetrics(
1629 QStyle::CC_SpinWidget, pWidget, QStyle::SC_SpinWidgetDown );
1630 bReturn = true;
1631 qRect.moveBy( qBoundingRect.left(), qBoundingRect.top() );
1632 break;
1634 case PART_SUB_EDIT:
1635 qRect = QApplication::style().querySubControlMetrics(
1636 QStyle::CC_SpinWidget, pWidget, QStyle::SC_SpinWidgetEditField );
1637 qRect.moveBy( qBoundingRect.left(), qBoundingRect.top() );
1638 bReturn = true;
1639 break;
1641 break;
1643 // Metrics of the scroll bar
1644 case CTRL_SCROLLBAR:
1645 pWidget = pWidgetPainter->scrollBar( rControlRegion,
1646 ( nPart == PART_BUTTON_LEFT || nPart == PART_BUTTON_RIGHT ),
1647 ImplControlValue() );
1648 switch ( nPart )
1650 case PART_BUTTON_LEFT:
1651 case PART_BUTTON_UP:
1652 qRect = QApplication::style().querySubControlMetrics(
1653 QStyle::CC_ScrollBar, pWidget, QStyle::SC_ScrollBarSubLine );
1655 // Workaround for Platinum style scroll bars. It makes the
1656 // left/up button invisible.
1657 if ( nPart == PART_BUTTON_LEFT )
1659 if ( qRect.left() > QApplication::style().querySubControlMetrics(
1660 QStyle::CC_ScrollBar, pWidget,
1661 QStyle::SC_ScrollBarSubPage ).left() )
1663 qRect.setLeft( 0 );
1664 qRect.setRight( 0 );
1667 else
1669 if ( qRect.top() > QApplication::style().querySubControlMetrics(
1670 QStyle::CC_ScrollBar, pWidget,
1671 QStyle::SC_ScrollBarSubPage ).top() )
1673 qRect.setTop( 0 );
1674 qRect.setBottom( 0 );
1678 qRect.moveBy( qBoundingRect.left(), qBoundingRect.top() );
1680 bReturn = true;
1681 break;
1683 case PART_BUTTON_RIGHT:
1684 case PART_BUTTON_DOWN:
1685 qRect = QApplication::style().querySubControlMetrics(
1686 QStyle::CC_ScrollBar, pWidget, QStyle::SC_ScrollBarAddLine );
1688 // Workaround for Platinum and 3 button style scroll bars.
1689 // It makes the right/down button bigger.
1690 if ( nPart == PART_BUTTON_RIGHT )
1691 qRect.setLeft( QApplication::style().querySubControlMetrics(
1692 QStyle::CC_ScrollBar, pWidget,
1693 QStyle::SC_ScrollBarAddPage ).right() + 1 );
1694 else
1695 qRect.setTop( QApplication::style().querySubControlMetrics(
1696 QStyle::CC_ScrollBar, pWidget,
1697 QStyle::SC_ScrollBarAddPage ).bottom() + 1 );
1699 qRect.moveBy( qBoundingRect.left(), qBoundingRect.top() );
1701 bReturn = true;
1702 break;
1704 break;
1707 // Fill rNativeBoundingRegion and rNativeContentRegion
1708 if ( bReturn )
1710 // Bounding region
1711 Point aBPoint( qBoundingRect.x(), qBoundingRect.y() );
1712 Size aBSize( qBoundingRect.width(), qBoundingRect.height() );
1713 rNativeBoundingRegion = Rectangle( aBPoint, aBSize );
1715 // vcl::Region of the content
1716 Point aPoint( qRect.x(), qRect.y() );
1717 Size aSize( qRect.width(), qRect.height() );
1718 rNativeContentRegion = Rectangle( aPoint, aSize );
1721 return bReturn;
1724 // KDESalFrame implementation
1726 KDESalFrame::KDESalFrame( SalFrame* pParent, sal_uLong nStyle ) :
1727 X11SalFrame( pParent, nStyle )
1731 void KDESalFrame::Show( bool bVisible, bool bNoActivate )
1733 if ( !GetParent() && ! (GetStyle() & SAL_FRAME_STYLE_INTRO) )
1735 KDEXLib* pXLib = static_cast<KDEXLib*>(GetDisplay()->GetXLib());
1736 pXLib->doStartup();
1738 X11SalFrame::Show( bVisible, bNoActivate );
1741 /** Helper function to convert colors.
1743 static Color toColor( const QColor &rColor )
1745 return Color( rColor.red(), rColor.green(), rColor.blue() );
1748 /** Helper function to read untranslated text entry from KConfig configuration repository.
1750 static OUString readEntryUntranslated( KConfig *pConfig, const char *pKey )
1752 return OUString::createFromAscii( pConfig->readEntryUntranslated( pKey ).ascii() );
1755 /** Helper function to read color from KConfig configuration repository.
1757 static Color readColor( KConfig *pConfig, const char *pKey )
1759 return toColor( pConfig->readColorEntry( pKey ) );
1762 /** Helper function to add information to Font from QFont.
1764 Mostly grabbed from the Gtk+ vclplug (salnativewidgets-gtk.cxx).
1766 static vcl::Font toFont( const QFont &rQFont, const ::com::sun::star::lang::Locale& rLocale )
1768 psp::FastPrintFontInfo aInfo;
1769 QFontInfo qFontInfo( rQFont );
1771 // set family name
1772 aInfo.m_aFamilyName = OUString( rQFont.family().utf8(), strlen( rQFont.family().utf8() ), RTL_TEXTENCODING_UTF8 );
1774 // set italic
1775 aInfo.m_eItalic = ( qFontInfo.italic()? ITALIC_NORMAL: ITALIC_NONE );
1777 // set weight
1778 int nWeight = qFontInfo.weight();
1779 if ( nWeight <= QFont::Light )
1780 aInfo.m_eWeight = WEIGHT_LIGHT;
1781 else if ( nWeight <= QFont::Normal )
1782 aInfo.m_eWeight = WEIGHT_NORMAL;
1783 else if ( nWeight <= QFont::DemiBold )
1784 aInfo.m_eWeight = WEIGHT_SEMIBOLD;
1785 else if ( nWeight <= QFont::Bold )
1786 aInfo.m_eWeight = WEIGHT_BOLD;
1787 else
1788 aInfo.m_eWeight = WEIGHT_ULTRABOLD;
1790 // set width
1791 int nStretch = rQFont.stretch();
1792 if ( nStretch <= QFont::UltraCondensed )
1793 aInfo.m_eWidth = WIDTH_ULTRA_CONDENSED;
1794 else if ( nStretch <= QFont::ExtraCondensed )
1795 aInfo.m_eWidth = WIDTH_EXTRA_CONDENSED;
1796 else if ( nStretch <= QFont::Condensed )
1797 aInfo.m_eWidth = WIDTH_CONDENSED;
1798 else if ( nStretch <= QFont::SemiCondensed )
1799 aInfo.m_eWidth = WIDTH_SEMI_CONDENSED;
1800 else if ( nStretch <= QFont::Unstretched )
1801 aInfo.m_eWidth = WIDTH_NORMAL;
1802 else if ( nStretch <= QFont::SemiExpanded )
1803 aInfo.m_eWidth = WIDTH_SEMI_EXPANDED;
1804 else if ( nStretch <= QFont::Expanded )
1805 aInfo.m_eWidth = WIDTH_EXPANDED;
1806 else if ( nStretch <= QFont::ExtraExpanded )
1807 aInfo.m_eWidth = WIDTH_EXTRA_EXPANDED;
1808 else
1809 aInfo.m_eWidth = WIDTH_ULTRA_EXPANDED;
1811 SAL_INFO( "vcl.kde", "font name BEFORE system match: \"" << aInfo.m_aFamilyName << "\"" );
1813 // match font to e.g. resolve "Sans"
1814 psp::PrintFontManager::get().matchFont( aInfo, rLocale );
1816 SAL_INFO( "vcl.kde", "font match " <<
1817 (aInfo.m_nID != 0 ? "succeeded" : "failed") <<
1818 ", name AFTER: \"" << aInfo.m_aFamilyName << "\"" );
1820 // font height
1821 int nPointHeight = qFontInfo.pointSize();
1822 if ( nPointHeight <= 0 )
1823 nPointHeight = rQFont.pointSize();
1825 // Create the font
1826 vcl::Font aFont( aInfo.m_aFamilyName, Size( 0, nPointHeight ) );
1827 if( aInfo.m_eWeight != WEIGHT_DONTKNOW )
1828 aFont.SetWeight( aInfo.m_eWeight );
1829 if( aInfo.m_eWidth != WIDTH_DONTKNOW )
1830 aFont.SetWidthType( aInfo.m_eWidth );
1831 if( aInfo.m_eItalic != ITALIC_DONTKNOW )
1832 aFont.SetItalic( aInfo.m_eItalic );
1833 if( aInfo.m_ePitch != PITCH_DONTKNOW )
1834 aFont.SetPitch( aInfo.m_ePitch );
1836 return aFont;
1839 /** Implementation of KDE integration's main method.
1841 void KDESalFrame::UpdateSettings( AllSettings& rSettings )
1843 StyleSettings aStyleSettings( rSettings.GetStyleSettings() );
1844 bool bSetTitleFont = false;
1846 aStyleSettings.SetToolbarIconSize( ToolbarIconSize::Large );
1848 // WM settings
1849 KConfig *pConfig = KGlobal::config();
1850 if ( pConfig )
1852 pConfig->setGroup( "WM" );
1853 const char *pKey;
1855 pKey = "activeBackground";
1856 if ( pConfig->hasKey( pKey ) )
1857 aStyleSettings.SetActiveColor( readColor( pConfig, pKey ) );
1859 pKey = "inactiveBackground";
1860 if ( pConfig->hasKey( pKey ) )
1861 aStyleSettings.SetDeactiveColor( readColor( pConfig, pKey ) );
1863 pKey = "inactiveForeground";
1864 if ( pConfig->hasKey( pKey ) )
1865 aStyleSettings.SetDeactiveTextColor( readColor( pConfig, pKey ) );
1867 pKey = "activeForeground";
1868 if ( pConfig->hasKey( pKey ) )
1869 aStyleSettings.SetActiveTextColor( readColor( pConfig, pKey ) );
1871 pKey = "titleFont";
1872 if ( pConfig->hasKey( pKey ) )
1874 vcl::Font aFont = toFont( pConfig->readFontEntry( pKey ), rSettings.GetUILanguageTag().getLocale() );
1875 aStyleSettings.SetTitleFont( aFont );
1876 bSetTitleFont = true;
1879 pConfig->setGroup( "Icons" );
1881 pKey = "Theme";
1882 if ( pConfig->hasKey( pKey ) )
1883 aStyleSettings.SetPreferredIconTheme( readEntryUntranslated( pConfig, pKey ) );
1886 // General settings
1887 QColorGroup qColorGroup = QApplication::palette().active();
1889 Color aFore = toColor( qColorGroup.foreground() );
1890 Color aBack = toColor( qColorGroup.background() );
1891 Color aText = toColor( qColorGroup.text() );
1892 Color aBase = toColor( qColorGroup.base() );
1894 // Foreground
1895 aStyleSettings.SetRadioCheckTextColor( aFore );
1896 aStyleSettings.SetLabelTextColor( aFore );
1897 aStyleSettings.SetInfoTextColor( aFore );
1898 aStyleSettings.SetDialogTextColor( aFore );
1899 aStyleSettings.SetGroupTextColor( aFore );
1901 // Text
1902 aStyleSettings.SetFieldTextColor( aText );
1903 aStyleSettings.SetFieldRolloverTextColor( aText );
1904 aStyleSettings.SetWindowTextColor( aText );
1905 aStyleSettings.SetHelpTextColor( aText );
1907 // Base
1908 aStyleSettings.SetFieldColor( aBase );
1909 aStyleSettings.SetHelpColor( aBase );
1910 aStyleSettings.SetWindowColor( aBase );
1911 aStyleSettings.SetActiveTabColor( aBase );
1913 // Buttons
1914 aStyleSettings.SetButtonTextColor( toColor( qColorGroup.buttonText() ) );
1915 aStyleSettings.SetButtonRolloverTextColor( toColor( qColorGroup.buttonText() ) );
1917 // Tabs
1918 aStyleSettings.SetTabTextColor( toColor( qColorGroup.buttonText() ) );
1919 aStyleSettings.SetTabRolloverTextColor( toColor( qColorGroup.buttonText() ) );
1920 aStyleSettings.SetTabHighlightTextColor( toColor( qColorGroup.buttonText() ) );
1922 // Disable color
1923 aStyleSettings.SetDisableColor( toColor( qColorGroup.mid() ) );
1925 // Workspace
1926 aStyleSettings.SetWorkspaceColor( toColor( qColorGroup.mid() ) );
1928 // Background
1929 aStyleSettings.Set3DColors( aBack );
1930 aStyleSettings.SetFaceColor( aBack );
1931 aStyleSettings.SetInactiveTabColor( aBack );
1932 aStyleSettings.SetDialogColor( aBack );
1933 aStyleSettings.SetCheckedColorSpecialCase( );
1935 // Selection
1936 aStyleSettings.SetHighlightColor( toColor( qColorGroup.highlight() ) );
1937 aStyleSettings.SetHighlightTextColor( toColor( qColorGroup.highlightedText() ) );
1939 // Font
1940 vcl::Font aFont = toFont( QApplication::font(), rSettings.GetUILanguageTag().getLocale() );
1942 aStyleSettings.SetAppFont( aFont );
1943 aStyleSettings.SetHelpFont( aFont );
1944 aStyleSettings.SetMenuFont( aFont ); // will be changed according to pMenuBar
1945 aStyleSettings.SetToolFont( aFont ); // will be changed according to pToolBar
1946 aStyleSettings.SetLabelFont( aFont );
1947 aStyleSettings.SetInfoFont( aFont );
1948 aStyleSettings.SetRadioCheckFont( aFont );
1949 aStyleSettings.SetPushButtonFont( aFont );
1950 aStyleSettings.SetFieldFont( aFont );
1951 aStyleSettings.SetIconFont( aFont );
1952 aStyleSettings.SetTabFont( aFont );
1953 aStyleSettings.SetGroupFont( aFont );
1955 aFont.SetWeight( WEIGHT_BOLD );
1956 if( !bSetTitleFont )
1957 aStyleSettings.SetTitleFont( aFont );
1958 aStyleSettings.SetFloatTitleFont( aFont );
1960 int flash_time = QApplication::cursorFlashTime();
1961 aStyleSettings.SetCursorBlinkTime( flash_time != 0 ? flash_time/2 : STYLE_CURSOR_NOBLINKTIME );
1963 KMainWindow qMainWindow;
1964 qMainWindow.createGUI( "/dev/null" ); // hack
1966 // Menu
1967 aStyleSettings.SetSkipDisabledInMenus( true );
1968 KMenuBar *pMenuBar = qMainWindow.menuBar();
1969 if ( pMenuBar )
1971 // Color
1972 QColorGroup qMenuCG = pMenuBar->colorGroup();
1974 // Menu text and background color, theme specific
1975 Color aMenuFore = toColor( qMenuCG.foreground() );
1976 Color aMenuBack = toColor( qMenuCG.background() );
1977 if ( QApplication::style().inherits( "LightStyleV2" ) ||
1978 QApplication::style().inherits( "LightStyleV3" ) ||
1979 ( QApplication::style().inherits( QMotifStyle_String ) && !QApplication::style().inherits( QSGIStyle_String ) ) ||
1980 QApplication::style().inherits( QWindowsStyle_String ) )
1982 aMenuFore = toColor( qMenuCG.buttonText() );
1983 aMenuBack = toColor( qMenuCG.button() );
1986 aStyleSettings.SetMenuTextColor( aMenuFore );
1987 aStyleSettings.SetMenuBarTextColor( aStyleSettings.GetPersonaMenuBarTextColor().get_value_or( aMenuFore ) );
1988 aStyleSettings.SetMenuColor( aMenuBack );
1989 aStyleSettings.SetMenuBarColor( aMenuBack );
1990 aStyleSettings.SetMenuHighlightColor( toColor ( qMenuCG.highlight() ) );
1992 // Menu items higlight text color, theme specific
1993 if ( QApplication::style().inherits( "HighContrastStyle" ) ||
1994 QApplication::style().inherits( "KeramikStyle" ) ||
1995 QApplication::style().inherits( QWindowsStyle_String ) ||
1996 QApplication::style().inherits( "ThinKeramikStyle" ) ||
1997 QApplication::style().inherits( "PlastikStyle" ) )
1999 aStyleSettings.SetMenuHighlightTextColor( toColor ( qMenuCG.highlightedText() ) );
2001 else
2002 aStyleSettings.SetMenuHighlightTextColor( aMenuFore );
2004 // set special menubar higlight text color
2005 if ( QApplication::style().inherits( "HighContrastStyle" ) )
2006 ImplGetSVData()->maNWFData.maMenuBarHighlightTextColor = toColor( qMenuCG.highlightedText() );
2007 else
2008 ImplGetSVData()->maNWFData.maMenuBarHighlightTextColor = aMenuFore;
2010 // set menubar rollover color
2011 if ( QApplication::style().styleHint( QStyle::SH_MenuBar_MouseTracking ) )
2013 aStyleSettings.SetMenuBarRolloverColor( toColor ( qMenuCG.highlight() ) );
2014 aStyleSettings.SetMenuBarRolloverTextColor( ImplGetSVData()->maNWFData.maMenuBarHighlightTextColor );
2016 else
2018 aStyleSettings.SetMenuBarRolloverColor( aMenuBack );
2019 aStyleSettings.SetMenuBarRolloverTextColor( aMenuFore );
2021 aStyleSettings.SetMenuBarHighlightTextColor(aStyleSettings.GetMenuHighlightTextColor());
2023 // Font
2024 aFont = toFont( pMenuBar->font(), rSettings.GetUILanguageTag().getLocale() );
2025 aStyleSettings.SetMenuFont( aFont );
2028 // Tool bar
2029 KToolBar *pToolBar = qMainWindow.toolBar();
2030 if ( pToolBar )
2032 aFont = toFont( pToolBar->font(), rSettings.GetUILanguageTag().getLocale() );
2033 aStyleSettings.SetToolFont( aFont );
2036 // Scroll bar size
2037 aStyleSettings.SetScrollBarSize( QApplication::style().pixelMetric( QStyle::PM_ScrollBarExtent ) );
2039 rSettings.SetStyleSettings( aStyleSettings );
2042 SalGraphics* KDESalFrame::AcquireGraphics()
2044 if( GetWindow() )
2046 for( int i = 0; i < nMaxGraphics; i++ )
2048 if( ! m_aGraphics[i].bInUse )
2050 m_aGraphics[i].bInUse = true;
2051 if( ! m_aGraphics[i].pGraphics )
2053 m_aGraphics[i].pGraphics = new KDESalGraphics();
2054 m_aGraphics[i].pGraphics->Init( this, GetWindow(), GetScreenNumber() );
2056 return m_aGraphics[i].pGraphics;
2061 return NULL;
2064 void KDESalFrame::ReleaseGraphics( SalGraphics *pGraphics )
2066 for( int i = 0; i < nMaxGraphics; i++ )
2068 if( m_aGraphics[i].pGraphics == pGraphics )
2070 m_aGraphics[i].bInUse = false;
2071 break;
2076 void KDESalFrame::updateGraphics( bool bClear )
2078 Drawable aDrawable = bClear ? None : GetWindow();
2079 for( int i = 0; i < nMaxGraphics; i++ )
2081 if( m_aGraphics[i].bInUse )
2082 m_aGraphics[i].pGraphics->SetDrawable( aDrawable, GetScreenNumber() );
2086 KDESalFrame::~KDESalFrame()
2090 KDESalFrame::GraphicsHolder::~GraphicsHolder()
2092 delete pGraphics;
2095 // KDESalInstance implementation
2097 SalFrame *
2098 KDESalInstance::CreateFrame( SalFrame *pParent, sal_uLong nStyle )
2100 return new KDESalFrame( pParent, nStyle );
2103 uno::Reference< ui::dialogs::XFilePicker2 > KDESalInstance::createFilePicker(
2104 const uno::Reference< uno::XComponentContext >& xMSF )
2106 return uno::Reference< ui::dialogs::XFilePicker2 >(
2107 new UnxFilePicker( xMSF ) );
2110 // KDESalData pieces
2112 // Create the widget painter so we have some control over
2113 // the destruction sequence, so Qt doesn't die in action.
2115 void KDEData::initNWF()
2117 ImplSVData *pSVData = ImplGetSVData();
2118 // draw toolbars on separate lines
2119 pSVData->maNWFData.mbDockingAreaSeparateTB = true;
2121 pWidgetPainter = new WidgetPainter();
2124 void KDEData::deInitNWF()
2126 delete pWidgetPainter;
2127 pWidgetPainter = NULL;
2129 // We have to destroy the style early
2130 QApplication::setStyle( NULL );
2133 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */