Version 4.3.0.0.beta1, tag libreoffice-4.3.0.0.beta1
[LibreOffice.git] / vcl / unx / kde / salnativewidgets-kde.cxx
blob4034d6174b35ab865203a8703554701f5c923e6e
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>
30 #include <vcl/settings.hxx>
31 #include "fontmanager.hxx"
32 #include <vcl/vclenum.hxx>
33 #include <rtl/ustrbuf.hxx>
35 #include <config_vclplug.h>
37 #if ENABLE_TDE
38 #define QPushButton_String "TQPushButton"
39 #define QRadioButton_String "TQRadioButton"
40 #define QCheckBox_String "TQCheckBox"
41 #define QComboBox_String "TQComboBox"
42 #define QLineEdit_String "TQLineEdit"
43 #define QSpinWidget_String "TQSpinWidget"
44 #define QTabBar_String "TQTabBar"
45 #define QTabWidget_String "TQTabWidget"
46 #define QListView_String "TQListView"
47 #define QScrollBar_String "TQScrollBar"
48 #define QMotifPlusStyle_String "TQMotifPlusStyle"
49 #define QSGIStyle_String "TQSGIStyle"
50 #define QToolBar_String "TQToolBar"
51 #define QToolButton_String "TQToolButton"
52 #define QMenuBar_String "TQMenuBar"
53 #define QPopupMenu_String "TQPopupMenu"
54 #define QProgressBar_String "TQProgressBar"
55 #define QMotifStyle_String "TQMotifStyle"
56 #define QWindowsStyle_String "TQWindowsStyle"
57 #else // ENABLE_TDE
58 #define QPushButton_String "QPushButton"
59 #define QRadioButton_String "QRadioButton"
60 #define QCheckBox_String "QCheckBox"
61 #define QComboBox_String "QComboBox"
62 #define QLineEdit_String "QLineEdit"
63 #define QSpinWidget_String "QSpinWidget"
64 #define QTabBar_String "QTabBar"
65 #define QTabWidget_String "QTabWidget"
66 #define QListView_String "QListView"
67 #define QScrollBar_String "QScrollBar"
68 #define QMotifPlusStyle_String "QMotifPlusStyle"
69 #define QSGIStyle_String "QSGIStyle"
70 #define QToolBar_String "QToolBar"
71 #define QToolButton_String "QToolButton"
72 #define QMenuBar_String "QMenuBar"
73 #define QPopupMenu_String "QPopupMenu"
74 #define QProgressBar_String "QProgressBar"
75 #define QMotifStyle_String "QMotifStyle"
76 #define QWindowsStyle_String "QWindowsStyle"
77 #endif // ENABLE_TDE
79 using namespace ::com::sun::star;
80 using namespace ::rtl;
82 /** Cached native widgets.
84 A class which caches and paints the native widgets.
86 class WidgetPainter
88 protected:
89 /** Cached push button.
91 It is necessary for the QStyle::drawControl(). The buttons are created
92 on demand and they are still hidden (no QWidget::show() is called).
94 QPushButton *m_pPushButton;
96 /** Cached radio button.
98 @see m_pPushButton
100 QRadioButton *m_pRadioButton;
102 /** Cached check box.
104 @see m_pPushButton
106 QCheckBox *m_pCheckBox;
108 /** Cached combo box.
110 @see m_pPushButton
112 QComboBox *m_pComboBox;
114 /** Cached editable combo box.
116 Needed, because some styles do not like dynamic changes
117 (QComboBox::setEditable()).
119 @see m_pPushButton
121 QComboBox *m_pEditableComboBox;
123 /** Cached line edit box.
125 @see m_pPushButton
127 QLineEdit *m_pLineEdit;
129 /** Cached spin box.
131 @see m_pPushButton
133 QSpinWidget *m_pSpinWidget;
135 /** Cached spin box'es line edit.
137 @see m_pPushButton
139 QLineEdit *m_pSpinEdit;
141 /** Cached tab.
143 Left, middle, right tab and a tab which is alone.
145 @see m_pPushButton
147 QTab *m_pTabLeft, *m_pTabMiddle, *m_pTabRight, *m_pTabAlone;
149 /** Cached tab bar's parent widget.
151 Needed, because the Qt windows style checks for the availability
152 of tab bar's parent. We cannot use m_pTabWidget, because
153 TabWidget::setTabBar() and TabWidget::tabBar() methods are
154 protected.
156 @see m_pPushButton, m_pTabWidget
158 QWidget *m_pTabBarParent;
160 /** Cached tab bar widget.
162 @see m_pPushButton
164 QTabBar *m_pTabBar;
166 /** Cached tab widget.
168 We need it to draw the tab page. It cannot be used to draw the
169 tabs themselves, because the drawing has to be tweaked a little
170 due to not enough information from VCL.
172 @see m_pPushButton, m_pTabBarParent
174 QTabWidget *m_pTabWidget;
176 /** Cached list view.
178 @see m_pPushButton
180 QListView *m_pListView;
182 /** Cached scroll bar.
184 @see m_pPushButton
186 QScrollBar *m_pScrollBar;
188 /** Cached dock area. Needed for proper functionality of tool bars.
190 @see m_pPushButton
192 QMainWindow *m_pMainWindow;
194 /** Cached tool bar.
196 @see m_pPushButton
198 QToolBar *m_pToolBarHoriz, *m_pToolBarVert;
200 /** Cached tool button.
202 @see m_pPushButton
204 QToolButton *m_pToolButton;
206 /** Cached menu bar.
208 @see m_pPushButton
210 QMenuBar *m_pMenuBar;
212 /** Identifiers of menu bar items.
214 int m_nMenuBarEnabledItem, m_nMenuBarDisabledItem;
216 /** Cached popup menu.
218 @see m_pPushButton
220 QPopupMenu *m_pPopupMenu;
222 /** Identifiers of popup menu items.
224 int m_nPopupMenuEnabledItem, m_nPopupMenuDisabledItem;
226 /** cached progress bar
228 QProgressBar *m_pProgressBar;
230 // TODO other widgets
232 public:
233 /** Implicit constructor.
235 It creates an empty WidgetPainter with all the cached widgets initialized
236 to NULL. The widgets are created on demand and they are still hidden
237 (no QWidget::show()), because they are needed just as a parameter for
238 QStyle::drawControl().
240 @see m_pPushButton
242 WidgetPainter( void );
244 /** Destructor.
246 Destruct all the cached widgets.
248 virtual ~WidgetPainter( void );
250 /** Paints the specified widget to the X window.
252 Use X calls to bitblt (bit block transfer) the widget qWidget to
253 the window specified by drawable with the style defined by nStyle.
255 @param qWidget
256 A pointer to the cached widget.
258 @param nState
259 The state of the control (focused, on/off, ...)
261 @param aValue
262 The value (true/false, ...)
264 @param dpy
265 The display to be used by the X calls.
267 @param drawable
268 The destination X window.
270 @param gc
271 The graphics context.
273 bool drawStyledWidget( QWidget *pWidget,
274 ControlState nState, const ImplControlValue& aValue,
275 Display *dpy, XLIB_Window drawable, SalX11Screen nXScreen,
276 int nDepth, GC gc,
277 ControlPart nPart = PART_ENTIRE_CONTROL );
279 /** 'Get' method for push button.
281 The method returns the cached push button. It is constructed if it
282 does not exist. It has NULL as a parent and it stays hidden, but it
283 is necessary for the drawStyledWidget() method.
285 @return valid push button.
287 QPushButton *pushButton( const Rectangle& rControlRegion, bool bDefault );
289 /** 'Get' method for radio button.
291 @see pushButton()
293 QRadioButton *radioButton( const Rectangle& rControlRegion );
295 /** 'Get' method for check box.
297 @see pushButton()
299 QCheckBox *checkBox( const Rectangle& rControlRegion );
301 /** 'Get' method for combo box.
303 It returns m_pComboBox or m_pEditableComboBox according to
304 bEditable.
306 @see pushButton(), m_pEditableComboBox
308 QComboBox *comboBox( const Rectangle& rControlRegion, bool bEditable );
310 /** 'Get' method for line edit box.
312 @see pushButton()
314 QLineEdit *lineEdit( const Rectangle& rControlRegion );
316 /** 'Get' method for spin box.
318 @see pushButton()
320 QSpinWidget *spinWidget( const Rectangle& rControlRegion );
322 /** 'Get' method for tab bar.
324 @see pushButton()
326 QTabBar *tabBar( const Rectangle& rControlRegion );
328 /** 'Get' method for tab widget.
330 @see pushButton()
332 QTabWidget *tabWidget( const Rectangle& rControlRegion );
334 /** 'Get' method for list view.
336 @see pushButton()
338 QListView *listView( const Rectangle& rControlRegion );
340 /** 'Get' method for scroll bar.
342 @see pushButton()
344 QScrollBar *scrollBar( const Rectangle& rControlRegion,
345 bool bHorizontal, const ImplControlValue& aValue );
347 /** 'Get' method for tool bar.
349 @see pushButton()
351 QToolBar *toolBar( const Rectangle& rControlRegion, bool bHorizontal );
353 /** 'Get' method for tool button.
355 @see pushButton()
357 QToolButton *toolButton( const Rectangle& rControlRegion );
359 /** 'Get' method for menu bar.
361 @see pushButton()
363 QMenuBar *menuBar( const Rectangle& rControlRegion );
365 /** 'Get' method for popup menu.
367 @see pushButton()
369 QPopupMenu *popupMenu( const Rectangle& rControlRegion );
371 /** 'Get' method for progress bar
373 @see pushButton()
375 QProgressBar *progressBar( const Rectangle& rControlRegion );
377 // TODO other widgets
379 protected:
380 /** Style conversion function.
382 Conversion function between VCL ControlState together with
383 ImplControlValue and Qt state flags.
385 @param nState
386 State of the widget (default, focused, ...) as defined in Native
387 Widget Framework.
389 @param aValue
390 Value held by the widget (on, off, ...)
392 QStyle::SFlags vclStateValue2SFlags( ControlState nState, const ImplControlValue& aValue );
394 public:
395 /** Convert VCL Rectangle to QRect.
397 @param rControlRegion
398 The region to convert.
400 @return
401 The bounding box of the region.
403 static QRect region2QRect( const Rectangle& rControlRegion );
406 WidgetPainter::WidgetPainter( void )
407 : m_pPushButton( NULL ),
408 m_pRadioButton( NULL ),
409 m_pCheckBox( NULL ),
410 m_pComboBox( NULL ),
411 m_pEditableComboBox( NULL ),
412 m_pLineEdit( NULL ),
413 m_pSpinWidget( NULL ),
414 m_pSpinEdit( NULL ),
415 m_pTabLeft( NULL ),
416 m_pTabMiddle( NULL ),
417 m_pTabRight( NULL ),
418 m_pTabAlone( NULL ),
419 m_pTabBarParent( NULL ),
420 m_pTabBar( NULL ),
421 m_pTabWidget( NULL ),
422 m_pListView( NULL ),
423 m_pScrollBar( NULL ),
424 m_pMainWindow( NULL ),
425 m_pToolBarHoriz( NULL ),
426 m_pToolBarVert( NULL ),
427 m_pToolButton( NULL ),
428 m_pMenuBar( NULL ),
429 m_nMenuBarEnabledItem( 0 ),
430 m_nMenuBarDisabledItem( 0 ),
431 m_pPopupMenu( NULL ),
432 m_nPopupMenuEnabledItem( 0 ),
433 m_nPopupMenuDisabledItem( 0 ),
434 m_pProgressBar( NULL )
438 WidgetPainter::~WidgetPainter( void )
440 delete m_pPushButton, m_pPushButton = NULL;
441 delete m_pRadioButton, m_pRadioButton = NULL;
442 delete m_pCheckBox, m_pCheckBox = NULL;
443 delete m_pComboBox, m_pComboBox = NULL;
444 delete m_pEditableComboBox, m_pEditableComboBox = NULL;
445 delete m_pLineEdit, m_pLineEdit = NULL;
446 delete m_pSpinWidget, m_pSpinWidget = NULL;
447 m_pSpinEdit = NULL; // Deleted in m_pSpinWidget's destructor
448 delete m_pTabAlone, m_pTabAlone = NULL;
449 delete m_pTabBarParent, m_pTabBarParent = NULL;
450 m_pTabBar = NULL; // Deleted in m_pTabBarParent's destructor
451 m_pTabLeft = NULL;
452 m_pTabMiddle = NULL;
453 m_pTabRight = NULL;
454 delete m_pTabWidget, m_pTabWidget = NULL;
455 delete m_pListView, m_pListView = NULL;
456 delete m_pScrollBar, m_pScrollBar = NULL;
457 delete m_pToolBarHoriz, m_pToolBarHoriz = NULL;
458 delete m_pToolBarVert, m_pToolBarVert = NULL;
459 delete m_pMainWindow, m_pMainWindow = NULL;
460 delete m_pToolButton, m_pToolButton = NULL;
461 delete m_pMenuBar, m_pMenuBar = NULL;
462 delete m_pPopupMenu, m_pPopupMenu = NULL;
463 delete m_pProgressBar, m_pProgressBar = NULL;
466 bool WidgetPainter::drawStyledWidget( QWidget *pWidget,
467 ControlState nState, const ImplControlValue& aValue,
468 Display *dpy, XLIB_Window drawable, SalX11Screen nXScreen,
469 int nDepth, GC gc, ControlPart nPart )
471 if ( !pWidget )
472 return false;
474 // Normalize the widget
475 QPoint qWidgetPos( pWidget->pos() );
476 pWidget->move( 0, 0 );
478 // Enable/disable the widget
479 pWidget->setEnabled( nState & CTRL_STATE_ENABLED );
481 // Create pixmap to paint to
482 QPixmap qPixmap( pWidget->width(), pWidget->height() );
483 QPainter qPainter( &qPixmap );
484 QRect qRect( 0, 0, pWidget->width(), pWidget->height() );
486 // Use the background of the widget
487 qPixmap.fill( pWidget, QPoint(0, 0) );
489 // Convert the flags
490 QStyle::SFlags nStyle = vclStateValue2SFlags( nState, aValue );
492 // Store the widget class
493 const char *pClassName = pWidget->className();
495 // Draw the widget to the pixmap
496 if ( strcmp( QPushButton_String, pClassName ) == 0 )
498 // Workaround for the Platinum style.
499 // Platinum takes the state directly from the widget, not from SFlags.
500 QPushButton *pPushButton = static_cast<QPushButton *>( pWidget->qt_cast( QPushButton_String ) );
501 if ( pPushButton )
503 pPushButton->setDown ( nStyle & QStyle::Style_Down );
504 pPushButton->setOn ( nStyle & QStyle::Style_On );
505 pPushButton->setEnabled( nStyle & QStyle::Style_Enabled );
508 kapp->style().drawControl( QStyle::CE_PushButton,
509 &qPainter, pWidget, qRect,
510 pWidget->colorGroup(), nStyle );
512 else if ( strcmp( QRadioButton_String, pClassName ) == 0 )
514 // Bitblt from the screen, because the radio buttons are usually not
515 // rectangular, and there could be a bitmap under them
516 GC aTmpGC = XCreateGC( dpy, qPixmap.handle(), 0, NULL );
517 X11SalGraphics::CopyScreenArea(
518 dpy,
519 drawable, nXScreen, nDepth,
520 qPixmap.handle(), SalX11Screen( qPixmap.x11Screen() ), qPixmap.x11Depth(),
521 aTmpGC,
522 qWidgetPos.x(), qWidgetPos.y(), qRect.width(), qRect.height(),
523 0, 0 );
524 XFreeGC( dpy, aTmpGC );
526 kapp->style().drawControl( QStyle::CE_RadioButton,
527 &qPainter, pWidget, qRect,
528 pWidget->colorGroup(), nStyle );
530 else if ( strcmp( QCheckBox_String, pClassName ) == 0 )
532 kapp->style().drawControl( QStyle::CE_CheckBox,
533 &qPainter, pWidget, qRect,
534 pWidget->colorGroup(), nStyle );
536 else if ( strcmp( QComboBox_String, pClassName ) == 0 )
538 kapp->style().drawComplexControl( QStyle::CC_ComboBox,
539 &qPainter, pWidget, qRect,
540 pWidget->colorGroup(), nStyle );
542 // Editable combo box uses the background of the associated edit box
543 QComboBox *pComboBox = static_cast<QComboBox *>( pWidget->qt_cast( QComboBox_String ) );
544 if ( pComboBox && pComboBox->editable() && pComboBox->lineEdit() )
546 QColorGroup::ColorRole eColorRole = ( pComboBox->isEnabled() )?
547 QColorGroup::Base: QColorGroup::Background;
548 qPainter.fillRect(
549 kapp->style().querySubControlMetrics( QStyle::CC_ComboBox,
550 pComboBox, QStyle::SC_ComboBoxEditField ),
551 pComboBox->lineEdit()->colorGroup().brush( eColorRole ) );
554 else if ( strcmp( QLineEdit_String, pClassName ) == 0 )
556 kapp->style().drawPrimitive( QStyle::PE_PanelLineEdit,
557 &qPainter, qRect,
558 pWidget->colorGroup(), nStyle | QStyle::Style_Sunken );
560 else if ( strcmp( QSpinWidget_String, pClassName ) == 0 )
562 const SpinbuttonValue* pValue = (aValue.getType() == CTRL_SPINBUTTONS) ? static_cast<const SpinbuttonValue*>(&aValue) : NULL;
564 // Is any of the buttons pressed?
565 QStyle::SCFlags eActive = QStyle::SC_None;
566 if ( pValue )
568 if ( pValue->mnUpperState & CTRL_STATE_PRESSED )
569 eActive = QStyle::SC_SpinWidgetUp;
570 else if ( pValue->mnLowerState & CTRL_STATE_PRESSED )
571 eActive = QStyle::SC_SpinWidgetDown;
573 // Update the enable/disable state of the widget
574 if ( ( nState & CTRL_STATE_ENABLED ) ||
575 ( pValue->mnUpperState & CTRL_STATE_ENABLED ) ||
576 ( pValue->mnLowerState & CTRL_STATE_ENABLED ) )
578 pWidget->setEnabled( true );
579 nStyle |= QStyle::Style_Enabled;
581 else
582 pWidget->setEnabled( false );
584 // Mouse-over effect
585 if ( (pValue->mnUpperState & CTRL_STATE_ROLLOVER) ||
586 (pValue->mnLowerState & CTRL_STATE_ROLLOVER) )
587 nStyle |= QStyle::Style_MouseOver;
590 // Spin widget uses the background of the associated edit box
591 QSpinWidget *pSpinWidget = static_cast<QSpinWidget *>( pWidget->qt_cast( QSpinWidget_String ) );
592 if ( pSpinWidget && pSpinWidget->editWidget() )
594 QColorGroup::ColorRole eColorRole = ( pSpinWidget->isEnabled() )?
595 QColorGroup::Base: QColorGroup::Background;
596 qPainter.fillRect(
597 kapp->style().querySubControlMetrics( QStyle::CC_SpinWidget,
598 pSpinWidget, QStyle::SC_SpinWidgetEditField ),
599 pSpinWidget->editWidget()->colorGroup().brush( eColorRole ) );
602 // Adjust the frame (needed for Motif Plus style)
603 QRect qFrameRect = kapp->style().querySubControlMetrics( QStyle::CC_SpinWidget,
604 pWidget, QStyle::SC_SpinWidgetFrame );
606 kapp->style().drawComplexControl( QStyle::CC_SpinWidget,
607 &qPainter, pWidget, qFrameRect,
608 pWidget->colorGroup(), nStyle,
609 QStyle::SC_All, eActive );
611 else if ( strcmp( QTabBar_String, pClassName ) == 0 )
613 const TabitemValue *pValue = static_cast<const TabitemValue *> ( &aValue );
615 QTab *pTab = NULL;
616 if ( pValue )
618 if ( ( pValue->isFirst() || pValue->isLeftAligned() ) && ( pValue->isLast() || pValue->isRightAligned() ) )
619 pTab = m_pTabAlone;
620 else if ( pValue->isFirst() || pValue->isLeftAligned() )
621 pTab = m_pTabLeft;
622 else if ( pValue->isLast() || pValue->isRightAligned() )
623 pTab = m_pTabRight;
624 else
625 pTab = m_pTabMiddle;
627 if ( !pTab )
628 return false;
630 pTab->setRect( qRect );
632 kapp->style().drawControl( QStyle::CE_TabBarTab,
633 &qPainter, pWidget, qRect,
634 pWidget->colorGroup(), nStyle,
635 QStyleOption( pTab ) );
637 else if ( strcmp( QTabWidget_String, pClassName ) == 0 )
639 kapp->style().drawPrimitive( QStyle::PE_PanelTabWidget,
640 &qPainter, qRect,
641 pWidget->colorGroup(), nStyle );
643 else if ( strcmp( QListView_String, pClassName ) == 0 )
645 kapp->style().drawPrimitive( QStyle::PE_Panel,
646 &qPainter, qRect,
647 pWidget->colorGroup(), nStyle | QStyle::Style_Sunken );
649 else if ( strcmp( QScrollBar_String, pClassName ) == 0 )
651 const ScrollbarValue* pValue = (aValue.getType() == CTRL_SCROLLBAR) ? static_cast<const ScrollbarValue*>(&aValue) : NULL;
653 QStyle::SCFlags eActive = QStyle::SC_None;
654 if ( pValue )
656 // Workaround for Style_MouseOver-aware themes.
657 // Quite ugly, but I do not know about a better solution.
658 const char *pStyleName = kapp->style().className();
659 if ( strcmp( QMotifPlusStyle_String, pStyleName ) == 0 )
661 nStyle |= QStyle::Style_MouseOver;
662 if ( pValue->mnThumbState & CTRL_STATE_ROLLOVER )
663 eActive = QStyle::SC_ScrollBarSlider;
665 else if ( strcmp( QSGIStyle_String, pStyleName ) == 0 )
667 nStyle |= QStyle::Style_MouseOver;
668 if ( pValue->mnButton1State & CTRL_STATE_ROLLOVER )
669 eActive = QStyle::SC_ScrollBarSubLine;
670 else if ( pValue->mnButton2State & CTRL_STATE_ROLLOVER )
671 eActive = QStyle::SC_ScrollBarAddLine;
672 else if ( pValue->mnThumbState & CTRL_STATE_ROLLOVER )
673 eActive = QStyle::SC_ScrollBarSlider;
676 if ( pValue->mnButton1State & CTRL_STATE_PRESSED )
677 eActive = QStyle::SC_ScrollBarSubLine;
678 else if ( pValue->mnButton2State & CTRL_STATE_PRESSED )
679 eActive = QStyle::SC_ScrollBarAddLine;
680 else if ( pValue->mnThumbState & CTRL_STATE_PRESSED )
681 eActive = QStyle::SC_ScrollBarSlider;
682 else if ( pValue->mnPage1State & CTRL_STATE_PRESSED )
683 eActive = QStyle::SC_ScrollBarSubPage;
684 else if ( pValue->mnPage2State & CTRL_STATE_PRESSED )
685 eActive = QStyle::SC_ScrollBarAddPage;
687 // Update the enable/disable state of the widget
688 if ( ( nState & CTRL_STATE_ENABLED ) ||
689 ( pValue->mnButton1State & CTRL_STATE_ENABLED ) ||
690 ( pValue->mnButton2State & CTRL_STATE_ENABLED ) ||
691 ( pValue->mnThumbState & CTRL_STATE_ENABLED ) ||
692 ( pValue->mnPage1State & CTRL_STATE_ENABLED ) ||
693 ( pValue->mnPage2State & CTRL_STATE_ENABLED ) )
695 pWidget->setEnabled( true );
696 nStyle |= QStyle::Style_Enabled;
698 else
699 pWidget->setEnabled( false );
702 // Is it a horizontal scroll bar?
703 QScrollBar *pScrollBar = static_cast<QScrollBar *> ( pWidget->qt_cast( QScrollBar_String ) );
704 QStyle::StyleFlags eHoriz = QStyle::Style_Default;
705 if ( pScrollBar && pScrollBar->orientation() == Qt::Horizontal )
706 eHoriz = QStyle::Style_Horizontal;
708 kapp->style().drawComplexControl( QStyle::CC_ScrollBar,
709 &qPainter, pWidget, qRect,
710 pWidget->colorGroup(), nStyle | eHoriz,
711 QStyle::SC_All, eActive );
713 else if ( strcmp( QToolBar_String, pClassName ) == 0 )
715 QToolBar *pToolBar = static_cast< QToolBar * >( pWidget->qt_cast( QToolBar_String ) );
716 bool bIsHorizontal = false;
717 if ( pToolBar && pToolBar->orientation() == Qt::Horizontal )
719 nStyle |= QStyle::Style_Horizontal;
720 bIsHorizontal = true;
723 kapp->style().drawControl( QStyle::CE_DockWindowEmptyArea,
724 &qPainter, pWidget, qRect,
725 pWidget->colorGroup(), nStyle );
727 kapp->style().drawPrimitive( QStyle::PE_PanelDockWindow,
728 &qPainter, qRect, pWidget->colorGroup(), nStyle );
730 if ( nPart == PART_THUMB_HORZ || nPart == PART_THUMB_VERT )
732 const ToolbarValue *pValue = static_cast< const ToolbarValue * >( &aValue );
734 QRect qThumbRect = region2QRect( pValue->maGripRect );
735 qThumbRect.moveBy( -qWidgetPos.x(), -qWidgetPos.y() );
736 if ( bIsHorizontal )
737 qThumbRect.addCoords( 0, 2, 0, -3 ); // make the thumb a bit nicer
738 else
739 qThumbRect.addCoords( 2, 0, -3, 0 ); // make the thumb a bit nicer
741 if ( kapp->style().inherits( "HighColorStyle" ) ||
742 kapp->style().inherits( "HighContrastStyle" ) ||
743 kapp->style().inherits( "KeramikStyle" ) ||
744 kapp->style().inherits( "KThemeStyle" ) ||
745 kapp->style().inherits( "ThinKeramikStyle" ) )
747 // Workaround for the workaround in KStyle::drawPrimitive()
748 KStyle *pStyle = static_cast< KStyle * >( &kapp->style() );
749 pStyle->drawKStylePrimitive( KStyle::KPE_ToolBarHandle,
750 &qPainter, pToolBar, qThumbRect,
751 pWidget->colorGroup(), nStyle );
753 else
754 kapp->style().drawPrimitive( QStyle::PE_DockWindowHandle,
755 &qPainter, qThumbRect, pWidget->colorGroup(), nStyle );
758 else if ( strcmp( QToolButton_String, pClassName ) == 0 )
760 if( (nStyle & QStyle::Style_MouseOver) )
761 nStyle &= ~QStyle::Style_Off;
762 kapp->style().drawComplexControl( QStyle::CC_ToolButton,
763 &qPainter, pWidget, qRect,
764 pWidget->colorGroup(), nStyle,
765 QStyle::SC_ToolButton );
767 else if ( strcmp( QMenuBar_String, pClassName ) == 0 )
769 if ( nPart == PART_ENTIRE_CONTROL )
771 kapp->style().drawControl( QStyle::CE_MenuBarEmptyArea,
772 &qPainter, pWidget, qRect,
773 pWidget->colorGroup(), nStyle );
775 else if ( nPart == PART_MENU_ITEM )
777 int nMenuItem = ( nStyle & QStyle::Style_Enabled )? m_nMenuBarEnabledItem: m_nMenuBarDisabledItem;
778 QMenuItem *pMenuItem = static_cast<QMenuBar*>( pWidget )->findItem( nMenuItem );
780 if ( ( nStyle & QStyle::Style_MouseOver )
781 && kapp->style().styleHint( QStyle::SH_MenuBar_MouseTracking ) )
782 nStyle |= QStyle::Style_Active;
784 if ( nStyle & QStyle::Style_Selected )
785 nStyle |= QStyle::Style_Active | QStyle::Style_Down | QStyle::Style_HasFocus;
787 kapp->style().drawControl( QStyle::CE_MenuBarItem,
788 &qPainter, pWidget, qRect,
789 pWidget->colorGroup(), nStyle,
790 QStyleOption( pMenuItem ) );
793 else if ( strcmp( QPopupMenu_String, pClassName ) == 0 )
795 int nMenuItem = ( nStyle & QStyle::Style_Enabled )? m_nPopupMenuEnabledItem: m_nPopupMenuDisabledItem;
796 QMenuItem *pMenuItem = static_cast<QPopupMenu*>( pWidget )->findItem( nMenuItem );
798 if ( nStyle & QStyle::Style_Selected )
799 nStyle |= QStyle::Style_Active;
801 kapp->style().drawControl( QStyle::CE_PopupMenuItem,
802 &qPainter, pWidget, qRect,
803 pWidget->colorGroup(), nStyle,
804 QStyleOption( pMenuItem, 0, 0 ) );
806 else if ( strcmp( QProgressBar_String, pClassName ) == 0 )
808 long nProgressWidth = aValue.getNumericVal();
809 QProgressBar* pProgress = static_cast<QProgressBar*>(pWidget);
810 pProgress->setProgress( nProgressWidth, qRect.width() );
812 kapp->style().drawControl( QStyle::CE_ProgressBarGroove,
813 &qPainter, pWidget, qRect,
814 pWidget->colorGroup(), nStyle );
815 kapp->style().drawControl( QStyle::CE_ProgressBarContents,
816 &qPainter, pWidget, qRect,
817 pWidget->colorGroup(), nStyle );
819 else
820 return false;
822 // Bitblt it to the screen
823 X11SalGraphics::CopyScreenArea(
824 dpy, qPixmap.handle(), SalX11Screen( qPixmap.x11Screen() ), qPixmap.x11Depth(),
825 drawable, nXScreen, nDepth,
827 0, 0, qRect.width(), qRect.height(),
828 qWidgetPos.x(), qWidgetPos.y() );
830 // Restore widget's position
831 pWidget->move( qWidgetPos );
833 return true;
836 QPushButton *WidgetPainter::pushButton( const Rectangle& rControlRegion,
837 bool bDefault )
839 if ( !m_pPushButton )
840 m_pPushButton = new QPushButton( NULL, "push_button" );
842 QRect qRect = region2QRect( rControlRegion );
844 // Workaround for broken styles which do not add
845 // QStyle::PM_ButtonDefaultIndicator to the size of the default button
846 // (for example Keramik)
847 // FIXME Fix Keramik style to be consistent with Qt built-in styles. Aargh!
848 if ( bDefault )
850 QSize qContentsSize( 50, 50 );
851 m_pPushButton->setDefault( false );
852 QSize qNormalSize = kapp->style().sizeFromContents( QStyle::CT_PushButton,
853 m_pPushButton, qContentsSize );
854 m_pPushButton->setDefault( true );
855 QSize qDefSize = kapp->style().sizeFromContents( QStyle::CT_PushButton,
856 m_pPushButton, qContentsSize );
858 int nIndicatorSize = kapp->style().pixelMetric(
859 QStyle::PM_ButtonDefaultIndicator, m_pPushButton );
860 if ( qNormalSize.width() == qDefSize.width() )
861 qRect.addCoords( nIndicatorSize, 0, -nIndicatorSize, 0 );
862 if ( qNormalSize.height() == qDefSize.height() )
863 qRect.addCoords( 0, nIndicatorSize, 0, -nIndicatorSize );
866 m_pPushButton->move( qRect.topLeft() );
867 m_pPushButton->resize( qRect.size() );
868 m_pPushButton->setDefault( bDefault );
870 return m_pPushButton;
873 QRadioButton *WidgetPainter::radioButton( const Rectangle& rControlRegion )
875 if ( !m_pRadioButton )
876 m_pRadioButton = new QRadioButton( NULL, "radio_button" );
878 QRect qRect = region2QRect( rControlRegion );
880 // Workaround for broken themes which do not honor the given size.
881 // Quite ugly, but I do not know about a better solution.
882 const char *pStyleName = kapp->style().className();
883 if ( strcmp( "KThemeStyle", pStyleName ) == 0 )
885 QRect qOldRect( qRect );
887 qRect.setWidth( kapp->style().pixelMetric(
888 QStyle::PM_ExclusiveIndicatorWidth, m_pRadioButton ) );
889 qRect.setHeight( kapp->style().pixelMetric(
890 QStyle::PM_ExclusiveIndicatorHeight, m_pRadioButton ) );
892 qRect.moveBy( ( qOldRect.width() - qRect.width() ) / 2,
893 ( qOldRect.height() - qRect.height() ) / 2 );
896 m_pRadioButton->move( qRect.topLeft() );
897 m_pRadioButton->resize( qRect.size() );
899 return m_pRadioButton;
902 QCheckBox *WidgetPainter::checkBox( const Rectangle& rControlRegion )
904 if ( !m_pCheckBox )
905 m_pCheckBox = new QCheckBox( NULL, "check_box" );
907 QRect qRect = region2QRect( rControlRegion );
909 // Workaround for broken themes which do not honor the given size.
910 // Quite ugly, but I do not know about a better solution.
911 const char *pStyleName = kapp->style().className();
912 if ( strcmp( "KThemeStyle", pStyleName ) == 0 )
914 QRect qOldRect( qRect );
916 qRect.setWidth( kapp->style().pixelMetric(
917 QStyle::PM_IndicatorWidth, m_pCheckBox ) );
918 qRect.setHeight( kapp->style().pixelMetric(
919 QStyle::PM_IndicatorHeight, m_pCheckBox ) );
921 qRect.moveBy( ( qOldRect.width() - qRect.width() ) / 2,
922 ( qOldRect.height() - qRect.height() ) / 2 );
925 m_pCheckBox->move( qRect.topLeft() );
926 m_pCheckBox->resize( qRect.size() );
928 return m_pCheckBox;
931 QComboBox *WidgetPainter::comboBox( const Rectangle& rControlRegion,
932 bool bEditable )
934 QComboBox *pComboBox = NULL;
935 if ( bEditable )
937 if ( !m_pEditableComboBox )
938 m_pEditableComboBox = new QComboBox( true, NULL, "combo_box_edit" );
939 pComboBox = m_pEditableComboBox;
941 else
943 if ( !m_pComboBox )
944 m_pComboBox = new QComboBox( false, NULL, "combo_box" );
945 pComboBox = m_pComboBox;
948 QRect qRect = region2QRect( rControlRegion );
950 pComboBox->move( qRect.topLeft() );
951 pComboBox->resize( qRect.size() );
953 return pComboBox;
956 QLineEdit *WidgetPainter::lineEdit( const Rectangle& rControlRegion )
958 if ( !m_pLineEdit )
959 m_pLineEdit = new QLineEdit( NULL, "line_edit" );
961 QRect qRect = region2QRect( rControlRegion );
963 m_pLineEdit->move( qRect.topLeft() );
964 m_pLineEdit->resize( qRect.size() );
966 return m_pLineEdit;
969 QSpinWidget *WidgetPainter::spinWidget( const Rectangle& rControlRegion )
971 if ( !m_pSpinWidget )
973 m_pSpinWidget = new QSpinWidget( NULL, "spin_widget" );
974 m_pSpinEdit = new QLineEdit( NULL, "line_edit_spin" );
975 m_pSpinWidget->setEditWidget( m_pSpinEdit );
978 QRect qRect = region2QRect( rControlRegion );
980 m_pSpinWidget->move( qRect.topLeft() );
981 m_pSpinWidget->resize( qRect.size() );
982 m_pSpinWidget->arrange();
984 return m_pSpinWidget;
987 QTabBar *WidgetPainter::tabBar( const Rectangle& rControlRegion )
989 if ( !m_pTabBar )
991 if ( !m_pTabBarParent )
992 m_pTabBarParent = new QWidget( NULL, "tab_bar_parent" );
994 m_pTabBar = new QTabBar( m_pTabBarParent, "tab_bar" );
996 m_pTabLeft = new QTab();
997 m_pTabMiddle = new QTab();
998 m_pTabRight = new QTab();
999 m_pTabAlone = new QTab();
1001 m_pTabBar->addTab( m_pTabLeft );
1002 m_pTabBar->addTab( m_pTabMiddle );
1003 m_pTabBar->addTab( m_pTabRight );
1006 QRect qRect = region2QRect( rControlRegion );
1008 m_pTabBar->move( qRect.topLeft() );
1009 m_pTabBar->resize( qRect.size() );
1011 m_pTabBar->setShape( QTabBar::RoundedAbove );
1013 return m_pTabBar;
1016 QTabWidget *WidgetPainter::tabWidget( const Rectangle& rControlRegion )
1018 if ( !m_pTabWidget )
1019 m_pTabWidget = new QTabWidget( NULL, "tab_widget" );
1021 QRect qRect = region2QRect( rControlRegion );
1022 --qRect.rTop();
1024 m_pTabWidget->move( qRect.topLeft() );
1025 m_pTabWidget->resize( qRect.size() );
1027 return m_pTabWidget;
1030 QListView *WidgetPainter::listView( const Rectangle& rControlRegion )
1032 if ( !m_pListView )
1033 m_pListView = new QListView( NULL, "list_view" );
1035 QRect qRect = region2QRect( rControlRegion );
1037 m_pListView->move( qRect.topLeft() );
1038 m_pListView->resize( qRect.size() );
1040 return m_pListView;
1043 QScrollBar *WidgetPainter::scrollBar( const Rectangle& rControlRegion,
1044 bool bHorizontal, const ImplControlValue& aValue )
1046 if ( !m_pScrollBar )
1048 m_pScrollBar = new QScrollBar( NULL, "scroll_bar" );
1049 m_pScrollBar->setTracking( false );
1050 m_pScrollBar->setLineStep( 1 );
1053 QRect qRect = region2QRect( rControlRegion );
1055 m_pScrollBar->move( qRect.topLeft() );
1056 m_pScrollBar->resize( qRect.size() );
1057 m_pScrollBar->setOrientation( bHorizontal? Qt::Horizontal: Qt::Vertical );
1059 const ScrollbarValue* pValue = (aValue.getType() == CTRL_SCROLLBAR) ? static_cast<const ScrollbarValue*>(&aValue) : NULL;
1060 if ( pValue )
1062 m_pScrollBar->setMinValue( pValue->mnMin );
1063 m_pScrollBar->setMaxValue( pValue->mnMax - pValue->mnVisibleSize );
1064 m_pScrollBar->setValue( pValue->mnCur );
1065 m_pScrollBar->setPageStep( pValue->mnVisibleSize );
1068 return m_pScrollBar;
1071 QToolBar *WidgetPainter::toolBar( const Rectangle& rControlRegion, bool bHorizontal )
1073 if ( !m_pMainWindow )
1074 m_pMainWindow = new QMainWindow( NULL, "main_window" );
1076 QToolBar *pToolBar;
1077 if ( bHorizontal )
1079 if ( !m_pToolBarHoriz )
1081 m_pToolBarHoriz = new QToolBar( m_pMainWindow, "tool_bar_horiz" );
1082 m_pMainWindow->moveDockWindow( m_pToolBarHoriz, Qt::DockTop );
1084 pToolBar = m_pToolBarHoriz;
1086 else
1088 if ( !m_pToolBarVert )
1090 m_pToolBarVert = new QToolBar( m_pMainWindow, "tool_bar_horiz" );
1091 m_pMainWindow->moveDockWindow( m_pToolBarVert, Qt::DockLeft );
1093 pToolBar = m_pToolBarVert;
1096 QRect qRect = region2QRect( rControlRegion );
1098 pToolBar->move( qRect.topLeft() );
1099 pToolBar->resize( qRect.size() );
1101 return pToolBar;
1104 QToolButton *WidgetPainter::toolButton( const Rectangle& rControlRegion)
1106 if ( !m_pToolButton )
1107 m_pToolButton = new QToolButton( NULL, "tool_button" );
1109 QRect qRect = region2QRect( rControlRegion );
1111 m_pToolButton->move( qRect.topLeft() );
1112 m_pToolButton->resize( qRect.size() );
1114 return m_pToolButton;
1117 QMenuBar *WidgetPainter::menuBar( const Rectangle& rControlRegion)
1119 if ( !m_pMenuBar )
1121 m_pMenuBar = new QMenuBar( NULL, "menu_bar" );
1123 m_nMenuBarEnabledItem = m_pMenuBar->insertItem( "" );
1124 m_nMenuBarDisabledItem = m_pMenuBar->insertItem( "" );
1126 m_pMenuBar->setItemEnabled( m_nMenuBarEnabledItem, true );
1127 m_pMenuBar->setItemEnabled( m_nMenuBarDisabledItem, false );
1130 QRect qRect = region2QRect( rControlRegion );
1132 m_pMenuBar->move( qRect.topLeft() );
1133 m_pMenuBar->resize( qRect.size() );
1135 return m_pMenuBar;
1138 QPopupMenu *WidgetPainter::popupMenu( const Rectangle& rControlRegion)
1140 if ( !m_pPopupMenu )
1142 m_pPopupMenu = new QPopupMenu( NULL, "popup_menu" );
1144 m_nPopupMenuEnabledItem = m_pPopupMenu->insertItem( "" );
1145 m_nPopupMenuDisabledItem = m_pPopupMenu->insertItem( "" );
1147 m_pPopupMenu->setItemEnabled( m_nPopupMenuEnabledItem, true );
1148 m_pPopupMenu->setItemEnabled( m_nPopupMenuDisabledItem, false );
1151 QRect qRect = region2QRect( rControlRegion );
1153 m_pPopupMenu->move( qRect.topLeft() );
1154 m_pPopupMenu->resize( qRect.size() );
1156 return m_pPopupMenu;
1159 QProgressBar *WidgetPainter::progressBar( const Rectangle& rControlRegion )
1161 if ( !m_pProgressBar )
1162 m_pProgressBar = new QProgressBar( NULL, "progress_bar" );
1164 QRect qRect = region2QRect( rControlRegion );
1166 m_pProgressBar->move( qRect.topLeft() );
1167 m_pProgressBar->resize( qRect.size() );
1169 return m_pProgressBar;
1172 QStyle::SFlags WidgetPainter::vclStateValue2SFlags( ControlState nState,
1173 const ImplControlValue& aValue )
1175 QStyle::SFlags nStyle =
1176 ( (nState & CTRL_STATE_DEFAULT)? QStyle::Style_ButtonDefault: QStyle::Style_Default ) |
1177 ( (nState & CTRL_STATE_ENABLED)? QStyle::Style_Enabled: QStyle::Style_Default ) |
1178 ( (nState & CTRL_STATE_FOCUSED)? QStyle::Style_HasFocus: QStyle::Style_Default ) |
1179 ( (nState & CTRL_STATE_PRESSED)? QStyle::Style_Down: QStyle::Style_Raised ) |
1180 ( (nState & CTRL_STATE_SELECTED)? QStyle::Style_Selected : QStyle::Style_Default ) |
1181 ( (nState & CTRL_STATE_ROLLOVER)? QStyle::Style_MouseOver: QStyle::Style_Default );
1182 //TODO ( (nState & CTRL_STATE_HIDDEN)? QStyle::Style_: QStyle::Style_Default ) |
1184 switch ( aValue.getTristateVal() )
1186 case BUTTONVALUE_ON: nStyle |= QStyle::Style_On; break;
1187 case BUTTONVALUE_OFF: nStyle |= QStyle::Style_Off; break;
1188 case BUTTONVALUE_MIXED: nStyle |= QStyle::Style_NoChange; break;
1189 default: break;
1192 return nStyle;
1195 QRect WidgetPainter::region2QRect( const Rectangle& rControlRegion )
1197 return QRect( QPoint( rControlRegion.Left(), rControlRegion.Top() ),
1198 QPoint( rControlRegion.Right(), rControlRegion.Bottom() ) );
1201 /** Instance of WidgetPainter.
1203 It is used to paint the widgets requested by NWF.
1205 static WidgetPainter *pWidgetPainter;
1207 class KDESalGraphics : public X11SalGraphics
1209 public:
1210 KDESalGraphics() {}
1211 virtual ~KDESalGraphics() {}
1212 virtual bool IsNativeControlSupported( ControlType nType, ControlPart nPart ) SAL_OVERRIDE;
1213 virtual bool hitTestNativeControl( ControlType nType, ControlPart nPart,
1214 const Rectangle& rControlRegion, const Point& aPos,
1215 bool& rIsInside ) SAL_OVERRIDE;
1216 virtual bool drawNativeControl( ControlType nType, ControlPart nPart,
1217 const Rectangle& rControlRegion, ControlState nState,
1218 const ImplControlValue& aValue,
1219 const OUString& aCaption ) SAL_OVERRIDE;
1220 virtual bool getNativeControlRegion( ControlType nType, ControlPart nPart,
1221 const Rectangle& rControlRegion, ControlState nState,
1222 const ImplControlValue& aValue,
1223 const OUString& aCaption,
1224 Rectangle &rNativeBoundingRegion, Rectangle &rNativeContentRegion ) SAL_OVERRIDE;
1227 /** What widgets can be drawn the native way.
1229 @param nType
1230 Type of the widget.
1232 @param nPart
1233 Specification of the widget's part if it consists of more than one.
1235 @return true if the platform supports native drawing of the widget nType
1236 defined by nPart.
1238 bool KDESalGraphics::IsNativeControlSupported( ControlType nType, ControlPart nPart )
1240 return
1241 ( (nType == CTRL_PUSHBUTTON) && (nPart == PART_ENTIRE_CONTROL) ) ||
1242 ( (nType == CTRL_RADIOBUTTON) && (nPart == PART_ENTIRE_CONTROL) ) ||
1243 ( (nType == CTRL_CHECKBOX) && (nPart == PART_ENTIRE_CONTROL) ) ||
1244 ( (nType == CTRL_COMBOBOX) && (nPart == PART_ENTIRE_CONTROL || nPart == HAS_BACKGROUND_TEXTURE) ) ||
1245 ( (nType == CTRL_EDITBOX) && (nPart == PART_ENTIRE_CONTROL || nPart == HAS_BACKGROUND_TEXTURE) ) ||
1246 ( (nType == CTRL_LISTBOX) && (nPart == PART_ENTIRE_CONTROL || nPart == PART_WINDOW || nPart == HAS_BACKGROUND_TEXTURE ) ) ||
1247 ( (nType == CTRL_SPINBOX) && (nPart == PART_ENTIRE_CONTROL || nPart == HAS_BACKGROUND_TEXTURE) ) ||
1248 // no CTRL_SPINBUTTONS for KDE
1249 ( (nType == CTRL_TAB_ITEM) && (nPart == PART_ENTIRE_CONTROL) ) ||
1250 ( (nType == CTRL_TAB_PANE) && (nPart == PART_ENTIRE_CONTROL) ) ||
1251 // no CTRL_TAB_BODY for KDE
1252 ( (nType == CTRL_SCROLLBAR) && (nPart == PART_ENTIRE_CONTROL || nPart == PART_DRAW_BACKGROUND_HORZ || nPart == PART_DRAW_BACKGROUND_VERT) ) ||
1253 ( (nType == CTRL_SCROLLBAR) && (nPart == HAS_THREE_BUTTONS) ) || // TODO small optimization is possible here: return this only if the style really has 3 buttons
1254 // CTRL_GROUPBOX not supported
1255 // CTRL_FIXEDLINE not supported
1256 ( (nType == CTRL_TOOLBAR) && (nPart == PART_ENTIRE_CONTROL ||
1257 nPart == PART_DRAW_BACKGROUND_HORZ || nPart == PART_DRAW_BACKGROUND_VERT ||
1258 nPart == PART_THUMB_HORZ || nPart == PART_THUMB_VERT ||
1259 nPart == PART_BUTTON) ) ||
1260 ( (nType == CTRL_MENUBAR) && (nPart == PART_ENTIRE_CONTROL || nPart == PART_MENU_ITEM) ) ||
1261 ( (nType == CTRL_MENU_POPUP) && (nPart == PART_ENTIRE_CONTROL || nPart == PART_MENU_ITEM) ) ||
1262 ( (nType == CTRL_PROGRESS) && (nPart == PART_ENTIRE_CONTROL) )
1266 /** Test whether the position is in the native widget.
1268 If the return value is true, bIsInside contains information whether
1269 aPos was or was not inside the native widget specified by the
1270 nType/nPart combination.
1272 bool KDESalGraphics::hitTestNativeControl( ControlType nType, ControlPart nPart,
1273 const Rectangle& rControlRegion, const Point& rPos,
1274 bool& rIsInside )
1276 if ( nType == CTRL_SCROLLBAR )
1278 // make position relative to rControlRegion
1279 Point aPos = rPos - rControlRegion.TopLeft();
1280 rIsInside = false;
1282 bool bHorizontal = ( nPart == PART_BUTTON_LEFT || nPart == PART_BUTTON_RIGHT );
1284 QScrollBar *pScrollBar = pWidgetPainter->scrollBar( rControlRegion,
1285 bHorizontal, ImplControlValue() );
1286 QRect qRectSubLine = kapp->style().querySubControlMetrics(
1287 QStyle::CC_ScrollBar, pScrollBar, QStyle::SC_ScrollBarSubLine );
1288 QRect qRectAddLine = kapp->style().querySubControlMetrics(
1289 QStyle::CC_ScrollBar, pScrollBar, QStyle::SC_ScrollBarAddLine );
1291 // There are 2 buttons on the right/bottom side of the scrollbar
1292 bool bTwoSubButtons = false;
1294 // It is a Platinum style scroll bar
1295 bool bPlatinumStyle = false;
1297 // Workaround for Platinum and 3 button style scroll bars.
1298 // It makes the right/down button bigger.
1299 if ( bHorizontal )
1301 qRectAddLine.setLeft( kapp->style().querySubControlMetrics(
1302 QStyle::CC_ScrollBar, pScrollBar,
1303 QStyle::SC_ScrollBarAddPage ).right() + 1 );
1304 if ( qRectAddLine.width() > qRectSubLine.width() )
1305 bTwoSubButtons = true;
1306 if ( qRectSubLine.left() > kapp->style().querySubControlMetrics( QStyle::CC_ScrollBar, pScrollBar, QStyle::SC_ScrollBarSubPage ).left() )
1307 bPlatinumStyle = true;
1309 else
1311 qRectAddLine.setTop( kapp->style().querySubControlMetrics(
1312 QStyle::CC_ScrollBar, pScrollBar,
1313 QStyle::SC_ScrollBarAddPage ).bottom() + 1 );
1314 if ( qRectAddLine.height() > qRectSubLine.height() )
1315 bTwoSubButtons = true;
1316 if ( qRectSubLine.top() > kapp->style().querySubControlMetrics( QStyle::CC_ScrollBar, pScrollBar, QStyle::SC_ScrollBarSubPage ).top() )
1317 bPlatinumStyle = true;
1320 switch ( nPart )
1322 case PART_BUTTON_LEFT:
1323 if ( !bPlatinumStyle && qRectSubLine.contains( aPos.getX(), aPos.getY() ) )
1324 rIsInside = true;
1325 else if ( bTwoSubButtons )
1327 qRectAddLine.setWidth( qRectAddLine.width() / 2 );
1328 rIsInside = qRectAddLine.contains( aPos.getX(), aPos.getY() );
1330 break;
1332 case PART_BUTTON_UP:
1333 if ( !bPlatinumStyle && qRectSubLine.contains( aPos.getX(), aPos.getY() ) )
1334 rIsInside = true;
1335 else if ( bTwoSubButtons )
1337 qRectAddLine.setHeight( qRectAddLine.height() / 2 );
1338 rIsInside = qRectAddLine.contains( aPos.getX(), aPos.getY() );
1340 break;
1342 case PART_BUTTON_RIGHT:
1343 if ( bTwoSubButtons )
1344 qRectAddLine.setLeft( qRectAddLine.left() + qRectAddLine.width() / 2 );
1346 rIsInside = qRectAddLine.contains( aPos.getX(), aPos.getY() );
1347 break;
1349 case PART_BUTTON_DOWN:
1350 if ( bTwoSubButtons )
1351 qRectAddLine.setTop( qRectAddLine.top() + qRectAddLine.height() / 2 );
1353 rIsInside = qRectAddLine.contains( aPos.getX(), aPos.getY() );
1354 break;
1356 // cases PART_TRACK_HORZ_AREA and PART_TRACK_VERT_AREA
1357 default:
1358 return false;
1361 return true;
1364 return false;
1367 /** Draw the requested control described by nPart/nState.
1369 @param rControlRegion
1370 The bounding region of the complete control in VCL frame coordinates.
1372 @param aValue
1373 An optional value (tristate/numerical/string).
1375 @param aCaption
1376 A caption or title string (like button text etc.)
1378 bool KDESalGraphics::drawNativeControl( ControlType nType, ControlPart nPart,
1379 const Rectangle& rControlRegion, ControlState nState,
1380 const ImplControlValue& aValue,
1381 const OUString& )
1383 bool bReturn = false;
1385 Display *dpy = GetXDisplay();
1386 XLIB_Window drawable = GetDrawable();
1387 GC gc = SelectPen(); //SelectFont(); // GC with current clipping region set
1389 if ( (nType == CTRL_PUSHBUTTON) && (nPart == PART_ENTIRE_CONTROL) )
1391 bReturn = pWidgetPainter->drawStyledWidget(
1392 pWidgetPainter->pushButton( rControlRegion, (nState & CTRL_STATE_DEFAULT) ),
1393 nState, aValue,
1394 dpy, drawable, GetScreenNumber(), GetVisual().GetDepth(), gc );
1396 else if ( (nType == CTRL_RADIOBUTTON) && (nPart == PART_ENTIRE_CONTROL) )
1398 bReturn = pWidgetPainter->drawStyledWidget(
1399 pWidgetPainter->radioButton( rControlRegion ),
1400 nState, aValue,
1401 dpy, drawable, GetScreenNumber(), GetVisual().GetDepth(), gc );
1403 else if ( (nType == CTRL_CHECKBOX) && (nPart == PART_ENTIRE_CONTROL) )
1405 bReturn = pWidgetPainter->drawStyledWidget(
1406 pWidgetPainter->checkBox( rControlRegion ),
1407 nState, aValue,
1408 dpy, drawable, GetScreenNumber(), GetVisual().GetDepth(), gc );
1410 else if ( (nType == CTRL_COMBOBOX) && (nPart == PART_ENTIRE_CONTROL) )
1412 bReturn = pWidgetPainter->drawStyledWidget(
1413 pWidgetPainter->comboBox( rControlRegion, true ),
1414 nState, aValue,
1415 dpy, drawable, GetScreenNumber(), GetVisual().GetDepth(), gc );
1417 else if ( (nType == CTRL_EDITBOX) && (nPart == PART_ENTIRE_CONTROL) )
1419 bReturn = pWidgetPainter->drawStyledWidget(
1420 pWidgetPainter->lineEdit( rControlRegion ),
1421 nState, aValue,
1422 dpy, drawable, GetScreenNumber(), GetVisual().GetDepth(), gc );
1424 else if ( (nType == CTRL_LISTBOX) && (nPart == PART_ENTIRE_CONTROL) )
1426 bReturn = pWidgetPainter->drawStyledWidget(
1427 pWidgetPainter->comboBox( rControlRegion, false ),
1428 nState, aValue,
1429 dpy, drawable, GetScreenNumber(), GetVisual().GetDepth(), gc );
1431 else if ( (nType == CTRL_LISTBOX) && (nPart == PART_WINDOW) )
1433 bReturn = pWidgetPainter->drawStyledWidget(
1434 pWidgetPainter->listView( rControlRegion ),
1435 nState, aValue,
1436 dpy, drawable, GetScreenNumber(), GetVisual().GetDepth(), gc );
1438 else if ( (nType == CTRL_SPINBOX) && (nPart == PART_ENTIRE_CONTROL) )
1440 bReturn = pWidgetPainter->drawStyledWidget(
1441 pWidgetPainter->spinWidget( rControlRegion ),
1442 nState, aValue,
1443 dpy, drawable, GetScreenNumber(), GetVisual().GetDepth(), gc );
1445 else if ( (nType==CTRL_TAB_ITEM) && (nPart == PART_ENTIRE_CONTROL) )
1447 bReturn = pWidgetPainter->drawStyledWidget(
1448 pWidgetPainter->tabBar( rControlRegion ),
1449 nState, aValue,
1450 dpy, drawable, GetScreenNumber(), GetVisual().GetDepth(), gc );
1452 else if ( (nType==CTRL_TAB_PANE) && (nPart == PART_ENTIRE_CONTROL) )
1454 bReturn = pWidgetPainter->drawStyledWidget(
1455 pWidgetPainter->tabWidget( rControlRegion ),
1456 nState, aValue,
1457 dpy, drawable, GetScreenNumber(), GetVisual().GetDepth(), gc );
1459 else if ( (nType == CTRL_SCROLLBAR) && (nPart == PART_DRAW_BACKGROUND_HORZ || nPart == PART_DRAW_BACKGROUND_VERT) )
1461 bReturn = pWidgetPainter->drawStyledWidget(
1462 pWidgetPainter->scrollBar( rControlRegion, nPart == PART_DRAW_BACKGROUND_HORZ, aValue ),
1463 nState, aValue,
1464 dpy, drawable, GetScreenNumber(), GetVisual().GetDepth(), gc );
1466 else if ( (nType == CTRL_TOOLBAR) && (nPart == PART_DRAW_BACKGROUND_HORZ || nPart == PART_DRAW_BACKGROUND_VERT || nPart == PART_THUMB_HORZ || nPart == PART_THUMB_VERT) )
1468 bReturn = pWidgetPainter->drawStyledWidget(
1469 pWidgetPainter->toolBar( rControlRegion, nPart == PART_DRAW_BACKGROUND_HORZ || nPart == PART_THUMB_VERT ),
1470 nState, aValue,
1471 dpy, drawable, GetScreenNumber(), GetVisual().GetDepth(), gc, nPart );
1473 else if ( (nType == CTRL_TOOLBAR) && (nPart == PART_BUTTON) )
1475 bReturn = pWidgetPainter->drawStyledWidget(
1476 pWidgetPainter->toolButton( rControlRegion ),
1477 nState, aValue,
1478 dpy, drawable, GetScreenNumber(), GetVisual().GetDepth(), gc, nPart );
1480 else if ( (nType == CTRL_MENUBAR) && (nPart == PART_ENTIRE_CONTROL || nPart == PART_MENU_ITEM) )
1482 bReturn = pWidgetPainter->drawStyledWidget(
1483 pWidgetPainter->menuBar( rControlRegion ),
1484 nState, aValue,
1485 dpy, drawable, GetScreenNumber(), GetVisual().GetDepth(), gc, nPart );
1487 else if ( (nType == CTRL_MENU_POPUP) && (nPart == PART_ENTIRE_CONTROL || nPart == PART_MENU_ITEM) )
1489 bReturn = pWidgetPainter->drawStyledWidget(
1490 pWidgetPainter->popupMenu( rControlRegion ),
1491 nState, aValue,
1492 dpy, drawable, GetScreenNumber(), GetVisual().GetDepth(), gc );
1494 else if ( (nType == CTRL_PROGRESS) && (nPart == PART_ENTIRE_CONTROL) )
1496 bReturn = pWidgetPainter->drawStyledWidget(
1497 pWidgetPainter->progressBar( rControlRegion ),
1498 nState, aValue,
1499 dpy, drawable, GetScreenNumber(), GetVisual().GetDepth(), gc );
1502 return bReturn;
1505 /** Check if the bounding regions match.
1507 If the return value is true, rNativeBoundingRegion
1508 contains the true bounding region covered by the control
1509 including any adornment, while rNativeContentRegion contains the area
1510 within the control that can be safely drawn into without drawing over
1511 the borders of the control.
1513 @param rControlRegion
1514 The bounding region of the control in VCL frame coordinates.
1516 @param aValue
1517 An optional value (tristate/numerical/string)
1519 @param aCaption
1520 A caption or title string (like button text etc.)
1522 bool KDESalGraphics::getNativeControlRegion( ControlType nType, ControlPart nPart,
1523 const Rectangle& rControlRegion, ControlState nState,
1524 const ImplControlValue&,
1525 const OUString&,
1526 Rectangle &rNativeBoundingRegion, Rectangle &rNativeContentRegion )
1528 bool bReturn = false;
1529 QRect qBoundingRect = WidgetPainter::region2QRect( rControlRegion );
1530 QRect qRect;
1532 QWidget *pWidget = NULL;
1533 switch ( nType )
1535 // Metrics of the push button
1536 case CTRL_PUSHBUTTON:
1537 pWidget = pWidgetPainter->pushButton( rControlRegion, ( nState & CTRL_STATE_DEFAULT ) );
1539 switch ( nPart )
1541 case PART_ENTIRE_CONTROL:
1542 qRect = qBoundingRect;
1544 if ( nState & CTRL_STATE_DEFAULT )
1546 int nIndicatorSize = kapp->style().pixelMetric(
1547 QStyle::PM_ButtonDefaultIndicator, pWidget );
1548 qBoundingRect.addCoords( -nIndicatorSize, -nIndicatorSize,
1549 nIndicatorSize, nIndicatorSize );
1550 bReturn = true;
1552 break;
1554 break;
1556 // Metrics of the radio button
1557 case CTRL_RADIOBUTTON:
1558 pWidget = pWidgetPainter->radioButton( rControlRegion );
1560 if ( nPart == PART_ENTIRE_CONTROL )
1562 qRect.setWidth( kapp->style().pixelMetric( QStyle::PM_ExclusiveIndicatorWidth, pWidget ) );
1563 qRect.setHeight( kapp->style().pixelMetric( QStyle::PM_ExclusiveIndicatorHeight, pWidget ) );
1565 bReturn = true;
1567 break;
1569 // Metrics of the check box
1570 case CTRL_CHECKBOX:
1571 pWidget = pWidgetPainter->checkBox( rControlRegion );
1573 if ( nPart == PART_ENTIRE_CONTROL )
1575 qRect.setWidth( kapp->style().pixelMetric( QStyle::PM_IndicatorWidth, pWidget ) );
1576 qRect.setHeight( kapp->style().pixelMetric( QStyle::PM_IndicatorHeight, pWidget ) );
1578 bReturn = true;
1580 break;
1582 // Metrics of the combo box
1583 case CTRL_COMBOBOX:
1584 case CTRL_LISTBOX:
1585 pWidget = pWidgetPainter->comboBox( rControlRegion, ( nType == CTRL_COMBOBOX ) );
1586 switch ( nPart )
1588 case PART_BUTTON_DOWN:
1589 qRect = kapp->style().querySubControlMetrics(
1590 QStyle::CC_ComboBox, pWidget, QStyle::SC_ComboBoxArrow );
1591 qRect.setLeft( kapp->style().querySubControlMetrics(
1592 QStyle::CC_ComboBox, pWidget,
1593 QStyle::SC_ComboBoxEditField ).right() + 1 );
1594 qRect.moveBy( qBoundingRect.left(), qBoundingRect.top() );
1595 bReturn = true;
1596 break;
1598 case PART_SUB_EDIT:
1599 qRect = kapp->style().querySubControlMetrics(
1600 QStyle::CC_ComboBox, pWidget, QStyle::SC_ComboBoxEditField );
1601 qRect.moveBy( qBoundingRect.left(), qBoundingRect.top() );
1602 bReturn = true;
1603 break;
1605 break;
1607 // Metrics of the spin box
1608 case CTRL_SPINBOX:
1609 pWidget = pWidgetPainter->spinWidget( rControlRegion );
1610 switch ( nPart )
1612 case PART_BUTTON_UP:
1613 qRect = kapp->style().querySubControlMetrics(
1614 QStyle::CC_SpinWidget, pWidget, QStyle::SC_SpinWidgetUp );
1615 bReturn = true;
1616 qRect.moveBy( qBoundingRect.left(), qBoundingRect.top() );
1617 break;
1619 case PART_BUTTON_DOWN:
1620 qRect = kapp->style().querySubControlMetrics(
1621 QStyle::CC_SpinWidget, pWidget, QStyle::SC_SpinWidgetDown );
1622 bReturn = true;
1623 qRect.moveBy( qBoundingRect.left(), qBoundingRect.top() );
1624 break;
1626 case PART_SUB_EDIT:
1627 qRect = kapp->style().querySubControlMetrics(
1628 QStyle::CC_SpinWidget, pWidget, QStyle::SC_SpinWidgetEditField );
1629 qRect.moveBy( qBoundingRect.left(), qBoundingRect.top() );
1630 bReturn = true;
1631 break;
1633 break;
1635 // Metrics of the scroll bar
1636 case CTRL_SCROLLBAR:
1637 pWidget = pWidgetPainter->scrollBar( rControlRegion,
1638 ( nPart == PART_BUTTON_LEFT || nPart == PART_BUTTON_RIGHT ),
1639 ImplControlValue() );
1640 switch ( nPart )
1642 case PART_BUTTON_LEFT:
1643 case PART_BUTTON_UP:
1644 qRect = kapp->style().querySubControlMetrics(
1645 QStyle::CC_ScrollBar, pWidget, QStyle::SC_ScrollBarSubLine );
1647 // Workaround for Platinum style scroll bars. It makes the
1648 // left/up button invisible.
1649 if ( nPart == PART_BUTTON_LEFT )
1651 if ( qRect.left() > kapp->style().querySubControlMetrics(
1652 QStyle::CC_ScrollBar, pWidget,
1653 QStyle::SC_ScrollBarSubPage ).left() )
1655 qRect.setLeft( 0 );
1656 qRect.setRight( 0 );
1659 else
1661 if ( qRect.top() > kapp->style().querySubControlMetrics(
1662 QStyle::CC_ScrollBar, pWidget,
1663 QStyle::SC_ScrollBarSubPage ).top() )
1665 qRect.setTop( 0 );
1666 qRect.setBottom( 0 );
1670 qRect.moveBy( qBoundingRect.left(), qBoundingRect.top() );
1672 bReturn = true;
1673 break;
1675 case PART_BUTTON_RIGHT:
1676 case PART_BUTTON_DOWN:
1677 qRect = kapp->style().querySubControlMetrics(
1678 QStyle::CC_ScrollBar, pWidget, QStyle::SC_ScrollBarAddLine );
1680 // Workaround for Platinum and 3 button style scroll bars.
1681 // It makes the right/down button bigger.
1682 if ( nPart == PART_BUTTON_RIGHT )
1683 qRect.setLeft( kapp->style().querySubControlMetrics(
1684 QStyle::CC_ScrollBar, pWidget,
1685 QStyle::SC_ScrollBarAddPage ).right() + 1 );
1686 else
1687 qRect.setTop( kapp->style().querySubControlMetrics(
1688 QStyle::CC_ScrollBar, pWidget,
1689 QStyle::SC_ScrollBarAddPage ).bottom() + 1 );
1691 qRect.moveBy( qBoundingRect.left(), qBoundingRect.top() );
1693 bReturn = true;
1694 break;
1696 break;
1699 // Fill rNativeBoundingRegion and rNativeContentRegion
1700 if ( bReturn )
1702 // Bounding region
1703 Point aBPoint( qBoundingRect.x(), qBoundingRect.y() );
1704 Size aBSize( qBoundingRect.width(), qBoundingRect.height() );
1705 rNativeBoundingRegion = Rectangle( aBPoint, aBSize );
1707 // Region of the content
1708 Point aPoint( qRect.x(), qRect.y() );
1709 Size aSize( qRect.width(), qRect.height() );
1710 rNativeContentRegion = Rectangle( aPoint, aSize );
1713 return bReturn;
1716 // KDESalFrame implementation
1718 KDESalFrame::KDESalFrame( SalFrame* pParent, sal_uLong nStyle ) :
1719 X11SalFrame( pParent, nStyle )
1723 void KDESalFrame::Show( bool bVisible, bool bNoActivate )
1725 if ( !GetParent() && ! (GetStyle() & SAL_FRAME_STYLE_INTRO) )
1727 KDEXLib* pXLib = static_cast<KDEXLib*>(GetDisplay()->GetXLib());
1728 pXLib->doStartup();
1730 X11SalFrame::Show( bVisible, bNoActivate );
1733 /** Helper function to convert colors.
1735 static Color toColor( const QColor &rColor )
1737 return Color( rColor.red(), rColor.green(), rColor.blue() );
1740 /** Helper function to read untranslated text entry from KConfig configuration repository.
1742 static OUString readEntryUntranslated( KConfig *pConfig, const char *pKey )
1744 return OUString::createFromAscii( pConfig->readEntryUntranslated( pKey ).ascii() );
1747 /** Helper function to read color from KConfig configuration repository.
1749 static Color readColor( KConfig *pConfig, const char *pKey )
1751 return toColor( pConfig->readColorEntry( pKey ) );
1754 /** Helper function to add information to Font from QFont.
1756 Mostly grabbed from the Gtk+ vclplug (salnativewidgets-gtk.cxx).
1758 static Font toFont( const QFont &rQFont, const ::com::sun::star::lang::Locale& rLocale )
1760 psp::FastPrintFontInfo aInfo;
1761 QFontInfo qFontInfo( rQFont );
1763 // set family name
1764 aInfo.m_aFamilyName = OUString( rQFont.family().utf8(), strlen( rQFont.family().utf8() ), RTL_TEXTENCODING_UTF8 );
1766 // set italic
1767 aInfo.m_eItalic = ( qFontInfo.italic()? ITALIC_NORMAL: ITALIC_NONE );
1769 // set weight
1770 int nWeight = qFontInfo.weight();
1771 if ( nWeight <= QFont::Light )
1772 aInfo.m_eWeight = WEIGHT_LIGHT;
1773 else if ( nWeight <= QFont::Normal )
1774 aInfo.m_eWeight = WEIGHT_NORMAL;
1775 else if ( nWeight <= QFont::DemiBold )
1776 aInfo.m_eWeight = WEIGHT_SEMIBOLD;
1777 else if ( nWeight <= QFont::Bold )
1778 aInfo.m_eWeight = WEIGHT_BOLD;
1779 else
1780 aInfo.m_eWeight = WEIGHT_ULTRABOLD;
1782 // set width
1783 int nStretch = rQFont.stretch();
1784 if ( nStretch <= QFont::UltraCondensed )
1785 aInfo.m_eWidth = WIDTH_ULTRA_CONDENSED;
1786 else if ( nStretch <= QFont::ExtraCondensed )
1787 aInfo.m_eWidth = WIDTH_EXTRA_CONDENSED;
1788 else if ( nStretch <= QFont::Condensed )
1789 aInfo.m_eWidth = WIDTH_CONDENSED;
1790 else if ( nStretch <= QFont::SemiCondensed )
1791 aInfo.m_eWidth = WIDTH_SEMI_CONDENSED;
1792 else if ( nStretch <= QFont::Unstretched )
1793 aInfo.m_eWidth = WIDTH_NORMAL;
1794 else if ( nStretch <= QFont::SemiExpanded )
1795 aInfo.m_eWidth = WIDTH_SEMI_EXPANDED;
1796 else if ( nStretch <= QFont::Expanded )
1797 aInfo.m_eWidth = WIDTH_EXPANDED;
1798 else if ( nStretch <= QFont::ExtraExpanded )
1799 aInfo.m_eWidth = WIDTH_EXTRA_EXPANDED;
1800 else
1801 aInfo.m_eWidth = WIDTH_ULTRA_EXPANDED;
1803 SAL_INFO( "vcl.kde", "font name BEFORE system match: \"" << aInfo.m_aFamilyName << "\"" );
1805 // match font to e.g. resolve "Sans"
1806 psp::PrintFontManager::get().matchFont( aInfo, rLocale );
1808 SAL_INFO( "vcl.kde", "font match " <<
1809 (aInfo.m_nID != 0 ? "succeeded" : "failed") <<
1810 ", name AFTER: \"" << aInfo.m_aFamilyName << "\"" );
1812 // font height
1813 int nPointHeight = qFontInfo.pointSize();
1814 if ( nPointHeight <= 0 )
1815 nPointHeight = rQFont.pointSize();
1817 // Create the font
1818 Font aFont( aInfo.m_aFamilyName, Size( 0, nPointHeight ) );
1819 if( aInfo.m_eWeight != WEIGHT_DONTKNOW )
1820 aFont.SetWeight( aInfo.m_eWeight );
1821 if( aInfo.m_eWidth != WIDTH_DONTKNOW )
1822 aFont.SetWidthType( aInfo.m_eWidth );
1823 if( aInfo.m_eItalic != ITALIC_DONTKNOW )
1824 aFont.SetItalic( aInfo.m_eItalic );
1825 if( aInfo.m_ePitch != PITCH_DONTKNOW )
1826 aFont.SetPitch( aInfo.m_ePitch );
1828 return aFont;
1831 /** Implementation of KDE integration's main method.
1833 void KDESalFrame::UpdateSettings( AllSettings& rSettings )
1835 StyleSettings aStyleSettings( rSettings.GetStyleSettings() );
1836 bool bSetTitleFont = false;
1838 aStyleSettings.SetToolbarIconSize( STYLE_TOOLBAR_ICONSIZE_LARGE );
1840 // WM settings
1841 KConfig *pConfig = KGlobal::config();
1842 if ( pConfig )
1844 pConfig->setGroup( "WM" );
1845 const char *pKey;
1847 pKey = "activeBackground";
1848 if ( pConfig->hasKey( pKey ) )
1849 aStyleSettings.SetActiveColor( readColor( pConfig, pKey ) );
1851 pKey = "activeBlend";
1852 if ( pConfig->hasKey( pKey ) )
1853 aStyleSettings.SetActiveColor2( readColor( pConfig, pKey ) );
1855 pKey = "inactiveBackground";
1856 if ( pConfig->hasKey( pKey ) )
1857 aStyleSettings.SetDeactiveColor( readColor( pConfig, pKey ) );
1859 pKey = "inactiveBlend";
1860 if ( pConfig->hasKey( pKey ) )
1861 aStyleSettings.SetDeactiveColor2( 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 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 = kapp->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 // Disable color
1918 aStyleSettings.SetDisableColor( toColor( qColorGroup.mid() ) );
1920 // Workspace
1921 aStyleSettings.SetWorkspaceColor( toColor( qColorGroup.mid() ) );
1923 // Background
1924 aStyleSettings.Set3DColors( aBack );
1925 aStyleSettings.SetFaceColor( aBack );
1926 aStyleSettings.SetInactiveTabColor( aBack );
1927 aStyleSettings.SetDialogColor( aBack );
1928 aStyleSettings.SetCheckedColorSpecialCase( );
1930 // Selection
1931 aStyleSettings.SetHighlightColor( toColor( qColorGroup.highlight() ) );
1932 aStyleSettings.SetHighlightTextColor( toColor( qColorGroup.highlightedText() ) );
1934 // Font
1935 Font aFont = toFont( kapp->font(), rSettings.GetUILanguageTag().getLocale() );
1937 aStyleSettings.SetAppFont( aFont );
1938 aStyleSettings.SetHelpFont( aFont );
1939 aStyleSettings.SetMenuFont( aFont ); // will be changed according to pMenuBar
1940 aStyleSettings.SetToolFont( aFont ); // will be changed according to pToolBar
1941 aStyleSettings.SetLabelFont( aFont );
1942 aStyleSettings.SetInfoFont( aFont );
1943 aStyleSettings.SetRadioCheckFont( aFont );
1944 aStyleSettings.SetPushButtonFont( aFont );
1945 aStyleSettings.SetFieldFont( aFont );
1946 aStyleSettings.SetIconFont( aFont );
1947 aStyleSettings.SetGroupFont( aFont );
1949 aFont.SetWeight( WEIGHT_BOLD );
1950 if( !bSetTitleFont )
1951 aStyleSettings.SetTitleFont( aFont );
1952 aStyleSettings.SetFloatTitleFont( aFont );
1954 int flash_time = QApplication::cursorFlashTime();
1955 aStyleSettings.SetCursorBlinkTime( flash_time != 0 ? flash_time/2 : STYLE_CURSOR_NOBLINKTIME );
1957 KMainWindow qMainWindow;
1958 qMainWindow.createGUI( "/dev/null" ); // hack
1960 // Menu
1961 aStyleSettings.SetSkipDisabledInMenus( true );
1962 KMenuBar *pMenuBar = qMainWindow.menuBar();
1963 if ( pMenuBar )
1965 // Color
1966 QColorGroup qMenuCG = pMenuBar->colorGroup();
1968 // Menu text and background color, theme specific
1969 Color aMenuFore = toColor( qMenuCG.foreground() );
1970 Color aMenuBack = toColor( qMenuCG.background() );
1971 if ( kapp->style().inherits( "LightStyleV2" ) ||
1972 kapp->style().inherits( "LightStyleV3" ) ||
1973 ( kapp->style().inherits( QMotifStyle_String ) && !kapp->style().inherits( QSGIStyle_String ) ) ||
1974 kapp->style().inherits( QWindowsStyle_String ) )
1976 aMenuFore = toColor( qMenuCG.buttonText() );
1977 aMenuBack = toColor( qMenuCG.button() );
1980 aStyleSettings.SetMenuTextColor( aMenuFore );
1981 aStyleSettings.SetMenuBarTextColor( aStyleSettings.GetPersonaMenuBarTextColor().get_value_or( aMenuFore ) );
1982 aStyleSettings.SetMenuColor( aMenuBack );
1983 aStyleSettings.SetMenuBarColor( aMenuBack );
1984 aStyleSettings.SetMenuHighlightColor( toColor ( qMenuCG.highlight() ) );
1986 // Menu items higlight text color, theme specific
1987 if ( kapp->style().inherits( "HighContrastStyle" ) ||
1988 kapp->style().inherits( "KeramikStyle" ) ||
1989 kapp->style().inherits( QWindowsStyle_String ) ||
1990 kapp->style().inherits( "ThinKeramikStyle" ) ||
1991 kapp->style().inherits( "PlastikStyle" ) )
1993 aStyleSettings.SetMenuHighlightTextColor( toColor ( qMenuCG.highlightedText() ) );
1995 else
1996 aStyleSettings.SetMenuHighlightTextColor( aMenuFore );
1998 // set special menubar higlight text color
1999 if ( kapp->style().inherits( "HighContrastStyle" ) )
2000 ImplGetSVData()->maNWFData.maMenuBarHighlightTextColor = toColor( qMenuCG.highlightedText() );
2001 else
2002 ImplGetSVData()->maNWFData.maMenuBarHighlightTextColor = aMenuFore;
2004 // set menubar rollover color
2005 if ( kapp->style().styleHint( QStyle::SH_MenuBar_MouseTracking ) )
2007 aStyleSettings.SetMenuBarRolloverColor( toColor ( qMenuCG.highlight() ) );
2008 aStyleSettings.SetMenuBarRolloverTextColor( ImplGetSVData()->maNWFData.maMenuBarHighlightTextColor );
2010 else
2012 aStyleSettings.SetMenuBarRolloverColor( aMenuBack );
2013 aStyleSettings.SetMenuBarRolloverTextColor( aMenuFore );
2016 // Font
2017 aFont = toFont( pMenuBar->font(), rSettings.GetUILanguageTag().getLocale() );
2018 aStyleSettings.SetMenuFont( aFont );
2021 // Tool bar
2022 KToolBar *pToolBar = qMainWindow.toolBar();
2023 if ( pToolBar )
2025 aFont = toFont( pToolBar->font(), rSettings.GetUILanguageTag().getLocale() );
2026 aStyleSettings.SetToolFont( aFont );
2029 // Scroll bar size
2030 aStyleSettings.SetScrollBarSize( kapp->style().pixelMetric( QStyle::PM_ScrollBarExtent ) );
2032 rSettings.SetStyleSettings( aStyleSettings );
2035 SalGraphics* KDESalFrame::AcquireGraphics()
2037 if( GetWindow() )
2039 for( int i = 0; i < nMaxGraphics; i++ )
2041 if( ! m_aGraphics[i].bInUse )
2043 m_aGraphics[i].bInUse = true;
2044 if( ! m_aGraphics[i].pGraphics )
2046 m_aGraphics[i].pGraphics = new KDESalGraphics();
2047 m_aGraphics[i].pGraphics->Init( this, GetWindow(), GetScreenNumber() );
2049 return m_aGraphics[i].pGraphics;
2054 return NULL;
2057 void KDESalFrame::ReleaseGraphics( SalGraphics *pGraphics )
2059 for( int i = 0; i < nMaxGraphics; i++ )
2061 if( m_aGraphics[i].pGraphics == pGraphics )
2063 m_aGraphics[i].bInUse = false;
2064 break;
2069 void KDESalFrame::updateGraphics( bool bClear )
2071 Drawable aDrawable = bClear ? None : GetWindow();
2072 for( int i = 0; i < nMaxGraphics; i++ )
2074 if( m_aGraphics[i].bInUse )
2075 m_aGraphics[i].pGraphics->SetDrawable( aDrawable, GetScreenNumber() );
2079 KDESalFrame::~KDESalFrame()
2083 KDESalFrame::GraphicsHolder::~GraphicsHolder()
2085 delete pGraphics;
2088 // KDESalInstance implementation
2090 SalFrame *
2091 KDESalInstance::CreateFrame( SalFrame *pParent, sal_uLong nStyle )
2093 return new KDESalFrame( pParent, nStyle );
2096 uno::Reference< ui::dialogs::XFilePicker2 > KDESalInstance::createFilePicker(
2097 const uno::Reference< uno::XComponentContext >& xMSF )
2099 return uno::Reference< ui::dialogs::XFilePicker2 >(
2100 new UnxFilePicker( xMSF ) );
2103 // KDESalData pieces
2105 // Create the widget painter so we have some control over
2106 // the destruction sequence, so Qt doesn't die in action.
2108 void KDEData::initNWF()
2110 ImplSVData *pSVData = ImplGetSVData();
2111 // draw toolbars on separate lines
2112 pSVData->maNWFData.mbDockingAreaSeparateTB = true;
2114 pWidgetPainter = new WidgetPainter();
2117 void KDEData::deInitNWF()
2119 delete pWidgetPainter;
2120 pWidgetPainter = NULL;
2122 // We have to destroy the style early
2123 kapp->setStyle( NULL );
2126 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */