Version 4.2.0.1, tag libreoffice-4.2.0.1
[LibreOffice.git] / vcl / unx / kde / salnativewidgets-kde.cxx
blobdfbdb4293afbb8673824ec389dd3f58b93098aa9
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 <vcl/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 sal_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, sal_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, sal_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 sal_Bool bHorizontal, const ImplControlValue& aValue );
347 /** 'Get' method for tool bar.
349 @see pushButton()
351 QToolBar *toolBar( const Rectangle& rControlRegion, sal_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 sal_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 sal_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 sal_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 sal_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 sal_True;
836 QPushButton *WidgetPainter::pushButton( const Rectangle& rControlRegion,
837 sal_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 consistant 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 sal_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 sal_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, sal_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 sal_Bool IsNativeControlSupported( ControlType nType, ControlPart nPart );
1213 virtual sal_Bool hitTestNativeControl( ControlType nType, ControlPart nPart,
1214 const Rectangle& rControlRegion, const Point& aPos,
1215 sal_Bool& rIsInside );
1216 virtual sal_Bool drawNativeControl( ControlType nType, ControlPart nPart,
1217 const Rectangle& rControlRegion, ControlState nState,
1218 const ImplControlValue& aValue,
1219 const OUString& aCaption );
1220 virtual sal_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 );
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 sal_True if the platform supports native drawing of the widget nType
1236 defined by nPart.
1238 sal_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) )
1267 /** Test whether the position is in the native widget.
1269 If the return value is sal_True, bIsInside contains information whether
1270 aPos was or was not inside the native widget specified by the
1271 nType/nPart combination.
1273 sal_Bool KDESalGraphics::hitTestNativeControl( ControlType nType, ControlPart nPart,
1274 const Rectangle& rControlRegion, const Point& rPos,
1275 sal_Bool& rIsInside )
1277 if ( nType == CTRL_SCROLLBAR )
1279 // make position relative to rControlRegion
1280 Point aPos = rPos - rControlRegion.TopLeft();
1281 rIsInside = sal_False;
1283 sal_Bool bHorizontal = ( nPart == PART_BUTTON_LEFT || nPart == PART_BUTTON_RIGHT );
1285 QScrollBar *pScrollBar = pWidgetPainter->scrollBar( rControlRegion,
1286 bHorizontal, ImplControlValue() );
1287 QRect qRectSubLine = kapp->style().querySubControlMetrics(
1288 QStyle::CC_ScrollBar, pScrollBar, QStyle::SC_ScrollBarSubLine );
1289 QRect qRectAddLine = kapp->style().querySubControlMetrics(
1290 QStyle::CC_ScrollBar, pScrollBar, QStyle::SC_ScrollBarAddLine );
1292 // There are 2 buttons on the right/bottom side of the scrollbar
1293 sal_Bool bTwoSubButtons = sal_False;
1295 // It is a Platinum style scroll bar
1296 sal_Bool bPlatinumStyle = sal_False;
1298 // Workaround for Platinum and 3 button style scroll bars.
1299 // It makes the right/down button bigger.
1300 if ( bHorizontal )
1302 qRectAddLine.setLeft( kapp->style().querySubControlMetrics(
1303 QStyle::CC_ScrollBar, pScrollBar,
1304 QStyle::SC_ScrollBarAddPage ).right() + 1 );
1305 if ( qRectAddLine.width() > qRectSubLine.width() )
1306 bTwoSubButtons = sal_True;
1307 if ( qRectSubLine.left() > kapp->style().querySubControlMetrics( QStyle::CC_ScrollBar, pScrollBar, QStyle::SC_ScrollBarSubPage ).left() )
1308 bPlatinumStyle = sal_True;
1310 else
1312 qRectAddLine.setTop( kapp->style().querySubControlMetrics(
1313 QStyle::CC_ScrollBar, pScrollBar,
1314 QStyle::SC_ScrollBarAddPage ).bottom() + 1 );
1315 if ( qRectAddLine.height() > qRectSubLine.height() )
1316 bTwoSubButtons = sal_True;
1317 if ( qRectSubLine.top() > kapp->style().querySubControlMetrics( QStyle::CC_ScrollBar, pScrollBar, QStyle::SC_ScrollBarSubPage ).top() )
1318 bPlatinumStyle = sal_True;
1321 switch ( nPart )
1323 case PART_BUTTON_LEFT:
1324 if ( !bPlatinumStyle && qRectSubLine.contains( aPos.getX(), aPos.getY() ) )
1325 rIsInside = sal_True;
1326 else if ( bTwoSubButtons )
1328 qRectAddLine.setWidth( qRectAddLine.width() / 2 );
1329 rIsInside = qRectAddLine.contains( aPos.getX(), aPos.getY() );
1331 break;
1333 case PART_BUTTON_UP:
1334 if ( !bPlatinumStyle && qRectSubLine.contains( aPos.getX(), aPos.getY() ) )
1335 rIsInside = sal_True;
1336 else if ( bTwoSubButtons )
1338 qRectAddLine.setHeight( qRectAddLine.height() / 2 );
1339 rIsInside = qRectAddLine.contains( aPos.getX(), aPos.getY() );
1341 break;
1343 case PART_BUTTON_RIGHT:
1344 if ( bTwoSubButtons )
1345 qRectAddLine.setLeft( qRectAddLine.left() + qRectAddLine.width() / 2 );
1347 rIsInside = qRectAddLine.contains( aPos.getX(), aPos.getY() );
1348 break;
1350 case PART_BUTTON_DOWN:
1351 if ( bTwoSubButtons )
1352 qRectAddLine.setTop( qRectAddLine.top() + qRectAddLine.height() / 2 );
1354 rIsInside = qRectAddLine.contains( aPos.getX(), aPos.getY() );
1355 break;
1357 // cases PART_TRACK_HORZ_AREA and PART_TRACK_VERT_AREA
1358 default:
1359 return sal_False;
1362 return sal_True;
1365 return sal_False;
1369 /** Draw the requested control described by nPart/nState.
1371 @param rControlRegion
1372 The bounding region of the complete control in VCL frame coordinates.
1374 @param aValue
1375 An optional value (tristate/numerical/string).
1377 @param aCaption
1378 A caption or title string (like button text etc.)
1380 sal_Bool KDESalGraphics::drawNativeControl( ControlType nType, ControlPart nPart,
1381 const Rectangle& rControlRegion, ControlState nState,
1382 const ImplControlValue& aValue,
1383 const OUString& )
1385 sal_Bool bReturn = sal_False;
1387 Display *dpy = GetXDisplay();
1388 XLIB_Window drawable = GetDrawable();
1389 GC gc = SelectPen(); //SelectFont(); // GC with current clipping region set
1391 if ( (nType == CTRL_PUSHBUTTON) && (nPart == PART_ENTIRE_CONTROL) )
1393 bReturn = pWidgetPainter->drawStyledWidget(
1394 pWidgetPainter->pushButton( rControlRegion, (nState & CTRL_STATE_DEFAULT) ),
1395 nState, aValue,
1396 dpy, drawable, GetScreenNumber(), GetVisual().GetDepth(), gc );
1398 else if ( (nType == CTRL_RADIOBUTTON) && (nPart == PART_ENTIRE_CONTROL) )
1400 bReturn = pWidgetPainter->drawStyledWidget(
1401 pWidgetPainter->radioButton( rControlRegion ),
1402 nState, aValue,
1403 dpy, drawable, GetScreenNumber(), GetVisual().GetDepth(), gc );
1405 else if ( (nType == CTRL_CHECKBOX) && (nPart == PART_ENTIRE_CONTROL) )
1407 bReturn = pWidgetPainter->drawStyledWidget(
1408 pWidgetPainter->checkBox( rControlRegion ),
1409 nState, aValue,
1410 dpy, drawable, GetScreenNumber(), GetVisual().GetDepth(), gc );
1412 else if ( (nType == CTRL_COMBOBOX) && (nPart == PART_ENTIRE_CONTROL) )
1414 bReturn = pWidgetPainter->drawStyledWidget(
1415 pWidgetPainter->comboBox( rControlRegion, sal_True ),
1416 nState, aValue,
1417 dpy, drawable, GetScreenNumber(), GetVisual().GetDepth(), gc );
1419 else if ( (nType == CTRL_EDITBOX) && (nPart == PART_ENTIRE_CONTROL) )
1421 bReturn = pWidgetPainter->drawStyledWidget(
1422 pWidgetPainter->lineEdit( rControlRegion ),
1423 nState, aValue,
1424 dpy, drawable, GetScreenNumber(), GetVisual().GetDepth(), gc );
1426 else if ( (nType == CTRL_LISTBOX) && (nPart == PART_ENTIRE_CONTROL) )
1428 bReturn = pWidgetPainter->drawStyledWidget(
1429 pWidgetPainter->comboBox( rControlRegion, sal_False ),
1430 nState, aValue,
1431 dpy, drawable, GetScreenNumber(), GetVisual().GetDepth(), gc );
1433 else if ( (nType == CTRL_LISTBOX) && (nPart == PART_WINDOW) )
1435 bReturn = pWidgetPainter->drawStyledWidget(
1436 pWidgetPainter->listView( rControlRegion ),
1437 nState, aValue,
1438 dpy, drawable, GetScreenNumber(), GetVisual().GetDepth(), gc );
1440 else if ( (nType == CTRL_SPINBOX) && (nPart == PART_ENTIRE_CONTROL) )
1442 bReturn = pWidgetPainter->drawStyledWidget(
1443 pWidgetPainter->spinWidget( rControlRegion ),
1444 nState, aValue,
1445 dpy, drawable, GetScreenNumber(), GetVisual().GetDepth(), gc );
1447 else if ( (nType==CTRL_TAB_ITEM) && (nPart == PART_ENTIRE_CONTROL) )
1449 bReturn = pWidgetPainter->drawStyledWidget(
1450 pWidgetPainter->tabBar( rControlRegion ),
1451 nState, aValue,
1452 dpy, drawable, GetScreenNumber(), GetVisual().GetDepth(), gc );
1454 else if ( (nType==CTRL_TAB_PANE) && (nPart == PART_ENTIRE_CONTROL) )
1456 bReturn = pWidgetPainter->drawStyledWidget(
1457 pWidgetPainter->tabWidget( rControlRegion ),
1458 nState, aValue,
1459 dpy, drawable, GetScreenNumber(), GetVisual().GetDepth(), gc );
1461 else if ( (nType == CTRL_SCROLLBAR) && (nPart == PART_DRAW_BACKGROUND_HORZ || nPart == PART_DRAW_BACKGROUND_VERT) )
1463 bReturn = pWidgetPainter->drawStyledWidget(
1464 pWidgetPainter->scrollBar( rControlRegion, nPart == PART_DRAW_BACKGROUND_HORZ, aValue ),
1465 nState, aValue,
1466 dpy, drawable, GetScreenNumber(), GetVisual().GetDepth(), gc );
1468 else if ( (nType == CTRL_TOOLBAR) && (nPart == PART_DRAW_BACKGROUND_HORZ || nPart == PART_DRAW_BACKGROUND_VERT || nPart == PART_THUMB_HORZ || nPart == PART_THUMB_VERT) )
1470 bReturn = pWidgetPainter->drawStyledWidget(
1471 pWidgetPainter->toolBar( rControlRegion, nPart == PART_DRAW_BACKGROUND_HORZ || nPart == PART_THUMB_VERT ),
1472 nState, aValue,
1473 dpy, drawable, GetScreenNumber(), GetVisual().GetDepth(), gc, nPart );
1475 else if ( (nType == CTRL_TOOLBAR) && (nPart == PART_BUTTON) )
1477 bReturn = pWidgetPainter->drawStyledWidget(
1478 pWidgetPainter->toolButton( rControlRegion ),
1479 nState, aValue,
1480 dpy, drawable, GetScreenNumber(), GetVisual().GetDepth(), gc, nPart );
1482 else if ( (nType == CTRL_MENUBAR) && (nPart == PART_ENTIRE_CONTROL || nPart == PART_MENU_ITEM) )
1484 bReturn = pWidgetPainter->drawStyledWidget(
1485 pWidgetPainter->menuBar( rControlRegion ),
1486 nState, aValue,
1487 dpy, drawable, GetScreenNumber(), GetVisual().GetDepth(), gc, nPart );
1489 else if ( (nType == CTRL_MENU_POPUP) && (nPart == PART_ENTIRE_CONTROL || nPart == PART_MENU_ITEM) )
1491 bReturn = pWidgetPainter->drawStyledWidget(
1492 pWidgetPainter->popupMenu( rControlRegion ),
1493 nState, aValue,
1494 dpy, drawable, GetScreenNumber(), GetVisual().GetDepth(), gc );
1496 else if ( (nType == CTRL_PROGRESS) && (nPart == PART_ENTIRE_CONTROL) )
1498 bReturn = pWidgetPainter->drawStyledWidget(
1499 pWidgetPainter->progressBar( rControlRegion ),
1500 nState, aValue,
1501 dpy, drawable, GetScreenNumber(), GetVisual().GetDepth(), gc );
1504 return bReturn;
1507 /** Check if the bounding regions match.
1509 If the return value is sal_True, rNativeBoundingRegion
1510 contains the true bounding region covered by the control
1511 including any adornment, while rNativeContentRegion contains the area
1512 within the control that can be safely drawn into without drawing over
1513 the borders of the control.
1515 @param rControlRegion
1516 The bounding region of the control in VCL frame coordinates.
1518 @param aValue
1519 An optional value (tristate/numerical/string)
1521 @param aCaption
1522 A caption or title string (like button text etc.)
1524 sal_Bool KDESalGraphics::getNativeControlRegion( ControlType nType, ControlPart nPart,
1525 const Rectangle& rControlRegion, ControlState nState,
1526 const ImplControlValue&,
1527 const OUString&,
1528 Rectangle &rNativeBoundingRegion, Rectangle &rNativeContentRegion )
1530 sal_Bool bReturn = sal_False;
1531 QRect qBoundingRect = WidgetPainter::region2QRect( rControlRegion );
1532 QRect qRect;
1534 QWidget *pWidget = NULL;
1535 switch ( nType )
1537 // Metrics of the push button
1538 case CTRL_PUSHBUTTON:
1539 pWidget = pWidgetPainter->pushButton( rControlRegion, ( nState & CTRL_STATE_DEFAULT ) );
1541 switch ( nPart )
1543 case PART_ENTIRE_CONTROL:
1544 qRect = qBoundingRect;
1546 if ( nState & CTRL_STATE_DEFAULT )
1548 int nIndicatorSize = kapp->style().pixelMetric(
1549 QStyle::PM_ButtonDefaultIndicator, pWidget );
1550 qBoundingRect.addCoords( -nIndicatorSize, -nIndicatorSize,
1551 nIndicatorSize, nIndicatorSize );
1552 bReturn = sal_True;
1554 break;
1556 break;
1558 // Metrics of the radio button
1559 case CTRL_RADIOBUTTON:
1560 pWidget = pWidgetPainter->radioButton( rControlRegion );
1562 if ( nPart == PART_ENTIRE_CONTROL )
1564 qRect.setWidth( kapp->style().pixelMetric( QStyle::PM_ExclusiveIndicatorWidth, pWidget ) );
1565 qRect.setHeight( kapp->style().pixelMetric( QStyle::PM_ExclusiveIndicatorHeight, pWidget ) );
1567 bReturn = sal_True;
1569 break;
1571 // Metrics of the check box
1572 case CTRL_CHECKBOX:
1573 pWidget = pWidgetPainter->checkBox( rControlRegion );
1575 if ( nPart == PART_ENTIRE_CONTROL )
1577 qRect.setWidth( kapp->style().pixelMetric( QStyle::PM_IndicatorWidth, pWidget ) );
1578 qRect.setHeight( kapp->style().pixelMetric( QStyle::PM_IndicatorHeight, pWidget ) );
1580 bReturn = sal_True;
1582 break;
1584 // Metrics of the combo box
1585 case CTRL_COMBOBOX:
1586 case CTRL_LISTBOX:
1587 pWidget = pWidgetPainter->comboBox( rControlRegion, ( nType == CTRL_COMBOBOX ) );
1588 switch ( nPart )
1590 case PART_BUTTON_DOWN:
1591 qRect = kapp->style().querySubControlMetrics(
1592 QStyle::CC_ComboBox, pWidget, QStyle::SC_ComboBoxArrow );
1593 qRect.setLeft( kapp->style().querySubControlMetrics(
1594 QStyle::CC_ComboBox, pWidget,
1595 QStyle::SC_ComboBoxEditField ).right() + 1 );
1596 qRect.moveBy( qBoundingRect.left(), qBoundingRect.top() );
1597 bReturn = sal_True;
1598 break;
1600 case PART_SUB_EDIT:
1601 qRect = kapp->style().querySubControlMetrics(
1602 QStyle::CC_ComboBox, pWidget, QStyle::SC_ComboBoxEditField );
1603 qRect.moveBy( qBoundingRect.left(), qBoundingRect.top() );
1604 bReturn = sal_True;
1605 break;
1607 break;
1609 // Metrics of the spin box
1610 case CTRL_SPINBOX:
1611 pWidget = pWidgetPainter->spinWidget( rControlRegion );
1612 switch ( nPart )
1614 case PART_BUTTON_UP:
1615 qRect = kapp->style().querySubControlMetrics(
1616 QStyle::CC_SpinWidget, pWidget, QStyle::SC_SpinWidgetUp );
1617 bReturn = sal_True;
1618 qRect.moveBy( qBoundingRect.left(), qBoundingRect.top() );
1619 break;
1621 case PART_BUTTON_DOWN:
1622 qRect = kapp->style().querySubControlMetrics(
1623 QStyle::CC_SpinWidget, pWidget, QStyle::SC_SpinWidgetDown );
1624 bReturn = sal_True;
1625 qRect.moveBy( qBoundingRect.left(), qBoundingRect.top() );
1626 break;
1628 case PART_SUB_EDIT:
1629 qRect = kapp->style().querySubControlMetrics(
1630 QStyle::CC_SpinWidget, pWidget, QStyle::SC_SpinWidgetEditField );
1631 qRect.moveBy( qBoundingRect.left(), qBoundingRect.top() );
1632 bReturn = sal_True;
1633 break;
1635 break;
1637 // Metrics of the scroll bar
1638 case CTRL_SCROLLBAR:
1639 pWidget = pWidgetPainter->scrollBar( rControlRegion,
1640 ( nPart == PART_BUTTON_LEFT || nPart == PART_BUTTON_RIGHT ),
1641 ImplControlValue() );
1642 switch ( nPart )
1644 case PART_BUTTON_LEFT:
1645 case PART_BUTTON_UP:
1646 qRect = kapp->style().querySubControlMetrics(
1647 QStyle::CC_ScrollBar, pWidget, QStyle::SC_ScrollBarSubLine );
1649 // Workaround for Platinum style scroll bars. It makes the
1650 // left/up button invisible.
1651 if ( nPart == PART_BUTTON_LEFT )
1653 if ( qRect.left() > kapp->style().querySubControlMetrics(
1654 QStyle::CC_ScrollBar, pWidget,
1655 QStyle::SC_ScrollBarSubPage ).left() )
1657 qRect.setLeft( 0 );
1658 qRect.setRight( 0 );
1661 else
1663 if ( qRect.top() > kapp->style().querySubControlMetrics(
1664 QStyle::CC_ScrollBar, pWidget,
1665 QStyle::SC_ScrollBarSubPage ).top() )
1667 qRect.setTop( 0 );
1668 qRect.setBottom( 0 );
1672 qRect.moveBy( qBoundingRect.left(), qBoundingRect.top() );
1674 bReturn = sal_True;
1675 break;
1677 case PART_BUTTON_RIGHT:
1678 case PART_BUTTON_DOWN:
1679 qRect = kapp->style().querySubControlMetrics(
1680 QStyle::CC_ScrollBar, pWidget, QStyle::SC_ScrollBarAddLine );
1682 // Workaround for Platinum and 3 button style scroll bars.
1683 // It makes the right/down button bigger.
1684 if ( nPart == PART_BUTTON_RIGHT )
1685 qRect.setLeft( kapp->style().querySubControlMetrics(
1686 QStyle::CC_ScrollBar, pWidget,
1687 QStyle::SC_ScrollBarAddPage ).right() + 1 );
1688 else
1689 qRect.setTop( kapp->style().querySubControlMetrics(
1690 QStyle::CC_ScrollBar, pWidget,
1691 QStyle::SC_ScrollBarAddPage ).bottom() + 1 );
1693 qRect.moveBy( qBoundingRect.left(), qBoundingRect.top() );
1695 bReturn = sal_True;
1696 break;
1698 break;
1701 // Fill rNativeBoundingRegion and rNativeContentRegion
1702 if ( bReturn )
1704 // Bounding region
1705 Point aBPoint( qBoundingRect.x(), qBoundingRect.y() );
1706 Size aBSize( qBoundingRect.width(), qBoundingRect.height() );
1707 rNativeBoundingRegion = Rectangle( aBPoint, aBSize );
1709 // Region of the content
1710 Point aPoint( qRect.x(), qRect.y() );
1711 Size aSize( qRect.width(), qRect.height() );
1712 rNativeContentRegion = Rectangle( aPoint, aSize );
1715 return bReturn;
1718 // -----------------------------------------------------------------------
1719 // KDESalFrame implementation
1720 // -----------------------------------------------------------------------
1722 KDESalFrame::KDESalFrame( SalFrame* pParent, sal_uLong nStyle ) :
1723 X11SalFrame( pParent, nStyle )
1727 void KDESalFrame::Show( sal_Bool bVisible, sal_Bool bNoActivate )
1729 if ( !GetParent() && ! (GetStyle() & SAL_FRAME_STYLE_INTRO) )
1731 KDEXLib* pXLib = static_cast<KDEXLib*>(GetDisplay()->GetXLib());
1732 pXLib->doStartup();
1734 X11SalFrame::Show( bVisible, bNoActivate );
1737 /** Helper function to convert colors.
1739 static Color toColor( const QColor &rColor )
1741 return Color( rColor.red(), rColor.green(), rColor.blue() );
1744 /** Helper function to read untranslated text entry from KConfig configuration repository.
1746 static OUString readEntryUntranslated( KConfig *pConfig, const char *pKey )
1748 return OUString::createFromAscii( pConfig->readEntryUntranslated( pKey ).ascii() );
1751 /** Helper function to read color from KConfig configuration repository.
1753 static Color readColor( KConfig *pConfig, const char *pKey )
1755 return toColor( pConfig->readColorEntry( pKey ) );
1758 /** Helper function to add information to Font from QFont.
1760 Mostly grabbed from the Gtk+ vclplug (salnativewidgets-gtk.cxx).
1762 static Font toFont( const QFont &rQFont, const ::com::sun::star::lang::Locale& rLocale )
1764 psp::FastPrintFontInfo aInfo;
1765 QFontInfo qFontInfo( rQFont );
1767 // set family name
1768 aInfo.m_aFamilyName = OUString( rQFont.family().utf8(), strlen( rQFont.family().utf8() ), RTL_TEXTENCODING_UTF8 );
1770 // set italic
1771 aInfo.m_eItalic = ( qFontInfo.italic()? ITALIC_NORMAL: ITALIC_NONE );
1773 // set weight
1774 int nWeight = qFontInfo.weight();
1775 if ( nWeight <= QFont::Light )
1776 aInfo.m_eWeight = WEIGHT_LIGHT;
1777 else if ( nWeight <= QFont::Normal )
1778 aInfo.m_eWeight = WEIGHT_NORMAL;
1779 else if ( nWeight <= QFont::DemiBold )
1780 aInfo.m_eWeight = WEIGHT_SEMIBOLD;
1781 else if ( nWeight <= QFont::Bold )
1782 aInfo.m_eWeight = WEIGHT_BOLD;
1783 else
1784 aInfo.m_eWeight = WEIGHT_ULTRABOLD;
1786 // set width
1787 int nStretch = rQFont.stretch();
1788 if ( nStretch <= QFont::UltraCondensed )
1789 aInfo.m_eWidth = WIDTH_ULTRA_CONDENSED;
1790 else if ( nStretch <= QFont::ExtraCondensed )
1791 aInfo.m_eWidth = WIDTH_EXTRA_CONDENSED;
1792 else if ( nStretch <= QFont::Condensed )
1793 aInfo.m_eWidth = WIDTH_CONDENSED;
1794 else if ( nStretch <= QFont::SemiCondensed )
1795 aInfo.m_eWidth = WIDTH_SEMI_CONDENSED;
1796 else if ( nStretch <= QFont::Unstretched )
1797 aInfo.m_eWidth = WIDTH_NORMAL;
1798 else if ( nStretch <= QFont::SemiExpanded )
1799 aInfo.m_eWidth = WIDTH_SEMI_EXPANDED;
1800 else if ( nStretch <= QFont::Expanded )
1801 aInfo.m_eWidth = WIDTH_EXPANDED;
1802 else if ( nStretch <= QFont::ExtraExpanded )
1803 aInfo.m_eWidth = WIDTH_EXTRA_EXPANDED;
1804 else
1805 aInfo.m_eWidth = WIDTH_ULTRA_EXPANDED;
1807 SAL_INFO( "vcl.kde", "font name BEFORE system match: \"" << aInfo.m_aFamilyName << "\"" );
1809 // match font to e.g. resolve "Sans"
1810 psp::PrintFontManager::get().matchFont( aInfo, rLocale );
1812 SAL_INFO( "vcl.kde", "font match " <<
1813 (aInfo.m_nID != 0 ? "succeeded" : "failed") <<
1814 ", name AFTER: \"" << aInfo.m_aFamilyName << "\"" );
1816 // font height
1817 int nPointHeight = qFontInfo.pointSize();
1818 if ( nPointHeight <= 0 )
1819 nPointHeight = rQFont.pointSize();
1821 // Create the font
1822 Font aFont( aInfo.m_aFamilyName, Size( 0, nPointHeight ) );
1823 if( aInfo.m_eWeight != WEIGHT_DONTKNOW )
1824 aFont.SetWeight( aInfo.m_eWeight );
1825 if( aInfo.m_eWidth != WIDTH_DONTKNOW )
1826 aFont.SetWidthType( aInfo.m_eWidth );
1827 if( aInfo.m_eItalic != ITALIC_DONTKNOW )
1828 aFont.SetItalic( aInfo.m_eItalic );
1829 if( aInfo.m_ePitch != PITCH_DONTKNOW )
1830 aFont.SetPitch( aInfo.m_ePitch );
1832 return aFont;
1835 /** Implementation of KDE integration's main method.
1837 void KDESalFrame::UpdateSettings( AllSettings& rSettings )
1839 StyleSettings aStyleSettings( rSettings.GetStyleSettings() );
1840 bool bSetTitleFont = false;
1842 aStyleSettings.SetToolbarIconSize( STYLE_TOOLBAR_ICONSIZE_LARGE );
1844 // WM settings
1845 KConfig *pConfig = KGlobal::config();
1846 if ( pConfig )
1848 pConfig->setGroup( "WM" );
1849 const char *pKey;
1851 pKey = "activeBackground";
1852 if ( pConfig->hasKey( pKey ) )
1853 aStyleSettings.SetActiveColor( readColor( pConfig, pKey ) );
1855 pKey = "activeBlend";
1856 if ( pConfig->hasKey( pKey ) )
1857 aStyleSettings.SetActiveColor2( readColor( pConfig, pKey ) );
1859 pKey = "inactiveBackground";
1860 if ( pConfig->hasKey( pKey ) )
1861 aStyleSettings.SetDeactiveColor( readColor( pConfig, pKey ) );
1863 pKey = "inactiveBlend";
1864 if ( pConfig->hasKey( pKey ) )
1865 aStyleSettings.SetDeactiveColor2( readColor( pConfig, pKey ) );
1867 pKey = "inactiveForeground";
1868 if ( pConfig->hasKey( pKey ) )
1869 aStyleSettings.SetDeactiveTextColor( readColor( pConfig, pKey ) );
1871 pKey = "activeForeground";
1872 if ( pConfig->hasKey( pKey ) )
1873 aStyleSettings.SetActiveTextColor( readColor( pConfig, pKey ) );
1875 pKey = "titleFont";
1876 if ( pConfig->hasKey( pKey ) )
1878 Font aFont = toFont( pConfig->readFontEntry( pKey ), rSettings.GetUILanguageTag().getLocale() );
1879 aStyleSettings.SetTitleFont( aFont );
1880 bSetTitleFont = true;
1883 pConfig->setGroup( "Icons" );
1885 pKey = "Theme";
1886 if ( pConfig->hasKey( pKey ) )
1887 aStyleSettings.SetPreferredSymbolsStyleName( readEntryUntranslated( pConfig, pKey ) );
1890 // General settings
1891 QColorGroup qColorGroup = kapp->palette().active();
1893 Color aFore = toColor( qColorGroup.foreground() );
1894 Color aBack = toColor( qColorGroup.background() );
1895 Color aText = toColor( qColorGroup.text() );
1896 Color aBase = toColor( qColorGroup.base() );
1898 // Foreground
1899 aStyleSettings.SetRadioCheckTextColor( aFore );
1900 aStyleSettings.SetLabelTextColor( aFore );
1901 aStyleSettings.SetInfoTextColor( aFore );
1902 aStyleSettings.SetDialogTextColor( aFore );
1903 aStyleSettings.SetGroupTextColor( aFore );
1905 // Text
1906 aStyleSettings.SetFieldTextColor( aText );
1907 aStyleSettings.SetFieldRolloverTextColor( aText );
1908 aStyleSettings.SetWindowTextColor( aText );
1909 aStyleSettings.SetHelpTextColor( aText );
1911 // Base
1912 aStyleSettings.SetFieldColor( aBase );
1913 aStyleSettings.SetHelpColor( aBase );
1914 aStyleSettings.SetWindowColor( aBase );
1915 aStyleSettings.SetActiveTabColor( aBase );
1917 // Buttons
1918 aStyleSettings.SetButtonTextColor( toColor( qColorGroup.buttonText() ) );
1919 aStyleSettings.SetButtonRolloverTextColor( toColor( qColorGroup.buttonText() ) );
1921 // Disable color
1922 aStyleSettings.SetDisableColor( toColor( qColorGroup.mid() ) );
1924 // Workspace
1925 aStyleSettings.SetWorkspaceColor( toColor( qColorGroup.mid() ) );
1927 // Background
1928 aStyleSettings.Set3DColors( aBack );
1929 aStyleSettings.SetFaceColor( aBack );
1930 aStyleSettings.SetInactiveTabColor( aBack );
1931 aStyleSettings.SetDialogColor( aBack );
1932 aStyleSettings.SetCheckedColorSpecialCase( );
1934 // Selection
1935 aStyleSettings.SetHighlightColor( toColor( qColorGroup.highlight() ) );
1936 aStyleSettings.SetHighlightTextColor( toColor( qColorGroup.highlightedText() ) );
1938 // Font
1939 Font aFont = toFont( kapp->font(), rSettings.GetUILanguageTag().getLocale() );
1941 aStyleSettings.SetAppFont( aFont );
1942 aStyleSettings.SetHelpFont( aFont );
1943 aStyleSettings.SetMenuFont( aFont ); // will be changed according to pMenuBar
1944 aStyleSettings.SetToolFont( aFont ); // will be changed according to pToolBar
1945 aStyleSettings.SetLabelFont( aFont );
1946 aStyleSettings.SetInfoFont( aFont );
1947 aStyleSettings.SetRadioCheckFont( aFont );
1948 aStyleSettings.SetPushButtonFont( aFont );
1949 aStyleSettings.SetFieldFont( aFont );
1950 aStyleSettings.SetIconFont( aFont );
1951 aStyleSettings.SetGroupFont( aFont );
1953 aFont.SetWeight( WEIGHT_BOLD );
1954 if( !bSetTitleFont )
1955 aStyleSettings.SetTitleFont( aFont );
1956 aStyleSettings.SetFloatTitleFont( aFont );
1958 int flash_time = QApplication::cursorFlashTime();
1959 aStyleSettings.SetCursorBlinkTime( flash_time != 0 ? flash_time/2 : STYLE_CURSOR_NOBLINKTIME );
1961 KMainWindow qMainWindow;
1962 qMainWindow.createGUI( "/dev/null" ); // hack
1964 // Menu
1965 aStyleSettings.SetSkipDisabledInMenus( sal_True );
1966 KMenuBar *pMenuBar = qMainWindow.menuBar();
1967 if ( pMenuBar )
1969 // Color
1970 QColorGroup qMenuCG = pMenuBar->colorGroup();
1972 // Menu text and background color, theme specific
1973 Color aMenuFore = toColor( qMenuCG.foreground() );
1974 Color aMenuBack = toColor( qMenuCG.background() );
1975 if ( kapp->style().inherits( "LightStyleV2" ) ||
1976 kapp->style().inherits( "LightStyleV3" ) ||
1977 ( kapp->style().inherits( QMotifStyle_String ) && !kapp->style().inherits( QSGIStyle_String ) ) ||
1978 kapp->style().inherits( QWindowsStyle_String ) )
1980 aMenuFore = toColor( qMenuCG.buttonText() );
1981 aMenuBack = toColor( qMenuCG.button() );
1984 aStyleSettings.SetMenuTextColor( aMenuFore );
1985 aStyleSettings.SetMenuBarTextColor( aMenuFore );
1986 aStyleSettings.SetMenuColor( aMenuBack );
1987 aStyleSettings.SetMenuBarColor( aMenuBack );
1988 aStyleSettings.SetMenuHighlightColor( toColor ( qMenuCG.highlight() ) );
1990 // Menu items higlight text color, theme specific
1991 if ( kapp->style().inherits( "HighContrastStyle" ) ||
1992 kapp->style().inherits( "KeramikStyle" ) ||
1993 kapp->style().inherits( QWindowsStyle_String ) ||
1994 kapp->style().inherits( "ThinKeramikStyle" ) ||
1995 kapp->style().inherits( "PlastikStyle" ) )
1997 aStyleSettings.SetMenuHighlightTextColor( toColor ( qMenuCG.highlightedText() ) );
1999 else
2000 aStyleSettings.SetMenuHighlightTextColor( aMenuFore );
2002 // set special menubar higlight text color
2003 if ( kapp->style().inherits( "HighContrastStyle" ) )
2004 ImplGetSVData()->maNWFData.maMenuBarHighlightTextColor = toColor( qMenuCG.highlightedText() );
2005 else
2006 ImplGetSVData()->maNWFData.maMenuBarHighlightTextColor = aMenuFore;
2008 // set menubar rollover color
2009 if ( kapp->style().styleHint( QStyle::SH_MenuBar_MouseTracking ) )
2011 aStyleSettings.SetMenuBarRolloverColor( toColor ( qMenuCG.highlight() ) );
2012 aStyleSettings.SetMenuBarRolloverTextColor( ImplGetSVData()->maNWFData.maMenuBarHighlightTextColor );
2014 else
2016 aStyleSettings.SetMenuBarRolloverColor( aMenuBack );
2017 aStyleSettings.SetMenuBarRolloverTextColor( aMenuFore );
2020 // Font
2021 aFont = toFont( pMenuBar->font(), rSettings.GetUILanguageTag().getLocale() );
2022 aStyleSettings.SetMenuFont( aFont );
2025 // Tool bar
2026 KToolBar *pToolBar = qMainWindow.toolBar();
2027 if ( pToolBar )
2029 aFont = toFont( pToolBar->font(), rSettings.GetUILanguageTag().getLocale() );
2030 aStyleSettings.SetToolFont( aFont );
2033 // Scroll bar size
2034 aStyleSettings.SetScrollBarSize( kapp->style().pixelMetric( QStyle::PM_ScrollBarExtent ) );
2036 rSettings.SetStyleSettings( aStyleSettings );
2039 SalGraphics* KDESalFrame::GetGraphics()
2041 if( GetWindow() )
2043 for( int i = 0; i < nMaxGraphics; i++ )
2045 if( ! m_aGraphics[i].bInUse )
2047 m_aGraphics[i].bInUse = true;
2048 if( ! m_aGraphics[i].pGraphics )
2050 m_aGraphics[i].pGraphics = new KDESalGraphics();
2051 m_aGraphics[i].pGraphics->Init( this, GetWindow(), GetScreenNumber() );
2053 return m_aGraphics[i].pGraphics;
2058 return NULL;
2061 void KDESalFrame::ReleaseGraphics( SalGraphics *pGraphics )
2063 for( int i = 0; i < nMaxGraphics; i++ )
2065 if( m_aGraphics[i].pGraphics == pGraphics )
2067 m_aGraphics[i].bInUse = false;
2068 break;
2073 void KDESalFrame::updateGraphics( bool bClear )
2075 Drawable aDrawable = bClear ? None : GetWindow();
2076 for( int i = 0; i < nMaxGraphics; i++ )
2078 if( m_aGraphics[i].bInUse )
2079 m_aGraphics[i].pGraphics->SetDrawable( aDrawable, GetScreenNumber() );
2083 KDESalFrame::~KDESalFrame()
2087 KDESalFrame::GraphicsHolder::~GraphicsHolder()
2089 delete pGraphics;
2092 // -----------------------------------------------------------------------
2093 // KDESalInstance implementation
2094 // -----------------------------------------------------------------------
2096 SalFrame *
2097 KDESalInstance::CreateFrame( SalFrame *pParent, sal_uLong nStyle )
2099 return new KDESalFrame( pParent, nStyle );
2102 uno::Reference< ui::dialogs::XFilePicker2 > KDESalInstance::createFilePicker(
2103 const uno::Reference< uno::XComponentContext >& xMSF )
2105 return uno::Reference< ui::dialogs::XFilePicker2 >(
2106 new UnxFilePicker( xMSF ) );
2109 // -----------------------------------------------------------------------
2110 // KDESalData pieces
2111 // -----------------------------------------------------------------------
2113 // Create the widget painter so we have some control over
2114 // the destruction sequence, so Qt doesn't die in action.
2116 void KDEData::initNWF()
2118 ImplSVData *pSVData = ImplGetSVData();
2119 // draw toolbars on separate lines
2120 pSVData->maNWFData.mbDockingAreaSeparateTB = true;
2122 pWidgetPainter = new WidgetPainter();
2125 void KDEData::deInitNWF()
2127 delete pWidgetPainter;
2128 pWidgetPainter = NULL;
2130 // We have to destroy the style early
2131 kapp->setStyle( NULL );
2134 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */