merge the formfield patch from ooo-build
[ooovba.git] / vcl / unx / kde / salnativewidgets-kde.cxx
blobe19c5899757575bc193b928e4f508b8152650ee7
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: salnativewidgets-kde.cxx,v $
10 * $Revision: 1.26.86.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_vcl.hxx"
34 #define _SV_SALNATIVEWIDGETS_KDE_CXX
35 #include "kde_headers.h"
37 #include <salunx.h>
38 #include <saldata.hxx>
39 #include <saldisp.hxx>
41 #ifndef _SV_SALGDI_HXX
42 #include <salgdi.h>
43 #endif
45 #ifndef _SV_SALGDI_HXX
46 #include <salframe.h>
47 #endif
48 #include <vcl/settings.hxx>
49 #include <rtl/ustrbuf.hxx>
50 #include <plugins/kde/kdedata.hxx>
51 #include <iostream>
53 #include <pspgraphics.h>
55 using namespace ::rtl;
57 /** Cached native widgets.
59 A class which caches and paints the native widgets.
61 class WidgetPainter
63 protected:
64 /** Cached push button.
66 It is necessary for the QStyle::drawControl(). The buttons are created
67 on demand and they are still hidden (no QWidget::show() is called).
69 QPushButton *m_pPushButton;
71 /** Cached radio button.
73 @see m_pPushButton
75 QRadioButton *m_pRadioButton;
77 /** Cached check box.
79 @see m_pPushButton
81 QCheckBox *m_pCheckBox;
83 /** Cached combo box.
85 @see m_pPushButton
87 QComboBox *m_pComboBox;
89 /** Cached editable combo box.
91 Needed, because some styles do not like dynamic changes
92 (QComboBox::setEditable()).
94 @see m_pPushButton
96 QComboBox *m_pEditableComboBox;
98 /** Cached line edit box.
100 @see m_pPushButton
102 QLineEdit *m_pLineEdit;
104 /** Cached spin box.
106 @see m_pPushButton
108 QSpinWidget *m_pSpinWidget;
110 /** Cached spin box'es line edit.
112 @see m_pPushButton
114 QLineEdit *m_pSpinEdit;
116 /** Cached tab.
118 Left, middle, right tab and a tab which is alone.
120 @see m_pPushButton
122 QTab *m_pTabLeft, *m_pTabMiddle, *m_pTabRight, *m_pTabAlone;
124 /** Cached tab bar's parent widget.
126 Needed, because the Qt windows style checks for the availability
127 of tab bar's parent. We cannot use m_pTabWidget, because
128 TabWidget::setTabBar() and TabWidget::tabBar() methods are
129 protected.
131 @see m_pPushButton, m_pTabWidget
133 QWidget *m_pTabBarParent;
135 /** Cached tab bar widget.
137 @see m_pPushButton
139 QTabBar *m_pTabBar;
141 /** Cached tab widget.
143 We need it to draw the tab page. It cannot be used to draw the
144 tabs themselves, because the drawing has to be tweaked a little
145 due to not enough information from VCL.
147 @see m_pPushButton, m_pTabBarParent
149 QTabWidget *m_pTabWidget;
151 /** Cached list view.
153 @see m_pPushButton
155 QListView *m_pListView;
157 /** Cached scroll bar.
159 @see m_pPushButton
161 QScrollBar *m_pScrollBar;
163 /** Cached dock area. Needed for proper functionality of tool bars.
165 @see m_pPushButton
167 QMainWindow *m_pMainWindow;
169 /** Cached tool bar.
171 @see m_pPushButton
173 QToolBar *m_pToolBarHoriz, *m_pToolBarVert;
175 /** Cached tool button.
177 @see m_pPushButton
179 QToolButton *m_pToolButton;
181 /** Cached menu bar.
183 @see m_pPushButton
185 QMenuBar *m_pMenuBar;
187 /** Identifiers of menu bar items.
189 int m_nMenuBarEnabledItem, m_nMenuBarDisabledItem;
191 /** Cached popup menu.
193 @see m_pPushButton
195 QPopupMenu *m_pPopupMenu;
197 /** Identifiers of popup menu items.
199 int m_nPopupMenuEnabledItem, m_nPopupMenuDisabledItem;
201 /** cached progress bar
203 QProgressBar *m_pProgressBar;
205 // TODO other widgets
207 public:
208 /** Implicit constructor.
210 It creates an empty WidgetPainter with all the cached widgets initialized
211 to NULL. The widgets are created on demand and they are still hidden
212 (no QWidget::show()), because they are needed just as a parameter for
213 QStyle::drawControl().
215 @see m_pPushButton
217 WidgetPainter( void );
219 /** Destructor.
221 Destruct all the cached widgets.
223 virtual ~WidgetPainter( void );
225 /** Paints the specified widget to the X window.
227 Use X calls to bitblt (bit block transfer) the widget qWidget to
228 the window specified by drawable with the style defined by nStyle.
230 @param qWidget
231 A pointer to the cached widget.
233 @param nState
234 The state of the control (focused, on/off, ...)
236 @param aValue
237 The value (true/false, ...)
239 @param dpy
240 The display to be used by the X calls.
242 @param drawable
243 The destination X window.
245 @param gc
246 The graphics context.
248 BOOL drawStyledWidget( QWidget *pWidget,
249 ControlState nState, const ImplControlValue& aValue,
250 Display *dpy, XLIB_Window drawable, int nScreen, int nDepth, GC gc,
251 ControlPart nPart = PART_ENTIRE_CONTROL );
253 /** 'Get' method for push button.
255 The method returns the cached push button. It is constructed if it
256 does not exist. It has NULL as a parent and it stays hidden, but it
257 is necessary for the drawStyledWidget() method.
259 @return valid push button.
261 QPushButton *pushButton( const Region& rControlRegion, BOOL bDefault );
263 /** 'Get' method for radio button.
265 @see pushButton()
267 QRadioButton *radioButton( const Region& rControlRegion );
269 /** 'Get' method for check box.
271 @see pushButton()
273 QCheckBox *checkBox( const Region& rControlRegion );
275 /** 'Get' method for combo box.
277 It returns m_pComboBox or m_pEditableComboBox according to
278 bEditable.
280 @see pushButton(), m_pEditableComboBox
282 QComboBox *comboBox( const Region& rControlRegion, BOOL bEditable );
284 /** 'Get' method for line edit box.
286 @see pushButton()
288 QLineEdit *lineEdit( const Region& rControlRegion );
290 /** 'Get' method for spin box.
292 @see pushButton()
294 QSpinWidget *spinWidget( const Region& rControlRegion );
296 /** 'Get' method for tab bar.
298 @see pushButton()
300 QTabBar *tabBar( const Region& rControlRegion );
302 /** 'Get' method for tab widget.
304 @see pushButton()
306 QTabWidget *tabWidget( const Region& rControlRegion );
308 /** 'Get' method for list view.
310 @see pushButton()
312 QListView *listView( const Region& rControlRegion );
314 /** 'Get' method for scroll bar.
316 @see pushButton()
318 QScrollBar *scrollBar( const Region& rControlRegion,
319 BOOL bHorizontal, const ImplControlValue& aValue );
321 /** 'Get' method for tool bar.
323 @see pushButton()
325 QToolBar *toolBar( const Region& rControlRegion, BOOL bHorizontal );
327 /** 'Get' method for tool button.
329 @see pushButton()
331 QToolButton *toolButton( const Region& rControlRegion );
333 /** 'Get' method for menu bar.
335 @see pushButton()
337 QMenuBar *menuBar( const Region& rControlRegion );
339 /** 'Get' method for popup menu.
341 @see pushButton()
343 QPopupMenu *popupMenu( const Region& rControlRegion );
345 /** 'Get' method for progress bar
347 @see pushButton()
349 QProgressBar *progressBar( const Region& rControlRegion );
351 // TODO other widgets
353 protected:
354 /** Style conversion function.
356 Conversion function between VCL ControlState together with
357 ImplControlValue and Qt state flags.
359 @param nState
360 State of the widget (default, focused, ...) as defined in Native
361 Widget Framework.
363 @param aValue
364 Value held by the widget (on, off, ...)
366 QStyle::SFlags vclStateValue2SFlags( ControlState nState, const ImplControlValue& aValue );
368 public:
369 /** Convert VCL Region to QRect.
371 @param rControlRegion
372 The region to convert.
374 @return
375 The bounding box of the region.
377 static QRect region2QRect( const Region& rControlRegion );
380 WidgetPainter::WidgetPainter( void )
381 : m_pPushButton( NULL ),
382 m_pRadioButton( NULL ),
383 m_pCheckBox( NULL ),
384 m_pComboBox( NULL ),
385 m_pEditableComboBox( NULL ),
386 m_pLineEdit( NULL ),
387 m_pSpinWidget( NULL ),
388 m_pSpinEdit( NULL ),
389 m_pTabLeft( NULL ),
390 m_pTabMiddle( NULL ),
391 m_pTabRight( NULL ),
392 m_pTabAlone( NULL ),
393 m_pTabBarParent( NULL ),
394 m_pTabBar( NULL ),
395 m_pTabWidget( NULL ),
396 m_pListView( NULL ),
397 m_pScrollBar( NULL ),
398 m_pMainWindow( NULL ),
399 m_pToolBarHoriz( NULL ),
400 m_pToolBarVert( NULL ),
401 m_pToolButton( NULL ),
402 m_pMenuBar( NULL ),
403 m_pPopupMenu( NULL ),
404 m_pProgressBar( NULL )
408 WidgetPainter::~WidgetPainter( void )
410 delete m_pPushButton, m_pPushButton = NULL;
411 delete m_pRadioButton, m_pRadioButton = NULL;
412 delete m_pCheckBox, m_pCheckBox = NULL;
413 delete m_pComboBox, m_pComboBox = NULL;
414 delete m_pEditableComboBox, m_pEditableComboBox = NULL;
415 delete m_pLineEdit, m_pLineEdit = NULL;
416 delete m_pSpinWidget, m_pSpinWidget = NULL;
417 m_pSpinEdit = NULL; // Deleted in m_pSpinWidget's destructor
418 delete m_pTabAlone, m_pTabAlone = NULL;
419 delete m_pTabBarParent, m_pTabBarParent = NULL;
420 m_pTabBar = NULL; // Deleted in m_pTabBarParent's destructor
421 m_pTabLeft = NULL;
422 m_pTabMiddle = NULL;
423 m_pTabRight = NULL;
424 delete m_pTabWidget, m_pTabWidget = NULL;
425 delete m_pListView, m_pListView = NULL;
426 delete m_pScrollBar, m_pScrollBar = NULL;
427 delete m_pToolBarHoriz, m_pToolBarHoriz = NULL;
428 delete m_pToolBarVert, m_pToolBarVert = NULL;
429 delete m_pMainWindow, m_pMainWindow = NULL;
430 delete m_pToolButton, m_pToolButton = NULL;
431 delete m_pMenuBar, m_pMenuBar = NULL;
432 delete m_pPopupMenu, m_pPopupMenu = NULL;
433 delete m_pProgressBar, m_pProgressBar = NULL;
436 BOOL WidgetPainter::drawStyledWidget( QWidget *pWidget,
437 ControlState nState, const ImplControlValue& aValue,
438 Display *dpy, XLIB_Window drawable, int nScreen, int nDepth, GC gc,
439 ControlPart nPart )
441 if ( !pWidget )
442 return FALSE;
444 // Normalize the widget
445 QPoint qWidgetPos( pWidget->pos() );
446 pWidget->move( 0, 0 );
448 // Enable/disable the widget
449 pWidget->setEnabled( nState & CTRL_STATE_ENABLED );
451 // Create pixmap to paint to
452 QPixmap qPixmap( pWidget->width(), pWidget->height() );
453 QPainter qPainter( &qPixmap );
454 QRect qRect( 0, 0, pWidget->width(), pWidget->height() );
456 // Use the background of the widget
457 qPixmap.fill( pWidget, QPoint(0, 0) );
459 // Convert the flags
460 QStyle::SFlags nStyle = vclStateValue2SFlags( nState, aValue );
462 // Store the widget class
463 const char *pClassName = pWidget->className();
465 // Draw the widget to the pixmap
466 if ( strcmp( "QPushButton", pClassName ) == 0 )
468 // Workaround for the Platinum style.
469 // Platinum takes the state directly from the widget, not from SFlags.
470 QPushButton *pPushButton = static_cast<QPushButton *>( pWidget->qt_cast( "QPushButton" ) );
471 if ( pPushButton )
473 pPushButton->setDown ( nStyle & QStyle::Style_Down );
474 pPushButton->setOn ( nStyle & QStyle::Style_On );
475 pPushButton->setEnabled( nStyle & QStyle::Style_Enabled );
478 kapp->style().drawControl( QStyle::CE_PushButton,
479 &qPainter, pWidget, qRect,
480 pWidget->colorGroup(), nStyle );
482 else if ( strcmp( "QRadioButton", pClassName ) == 0 )
484 // Bitblt from the screen, because the radio buttons are usually not
485 // rectangular, and there could be a bitmap under them
486 GC aTmpGC = XCreateGC( dpy, qPixmap.handle(), 0, NULL );
487 X11SalGraphics::CopyScreenArea( dpy,
488 drawable, nScreen, nDepth,
489 qPixmap.handle(), qPixmap.x11Screen(), qPixmap.x11Depth(),
490 aTmpGC,
491 qWidgetPos.x(), qWidgetPos.y(), qRect.width(), qRect.height(),
492 0, 0 );
493 XFreeGC( dpy, aTmpGC );
495 kapp->style().drawControl( QStyle::CE_RadioButton,
496 &qPainter, pWidget, qRect,
497 pWidget->colorGroup(), nStyle );
499 else if ( strcmp( "QCheckBox", pClassName ) == 0 )
501 kapp->style().drawControl( QStyle::CE_CheckBox,
502 &qPainter, pWidget, qRect,
503 pWidget->colorGroup(), nStyle );
505 else if ( strcmp( "QComboBox", pClassName ) == 0 )
507 kapp->style().drawComplexControl( QStyle::CC_ComboBox,
508 &qPainter, pWidget, qRect,
509 pWidget->colorGroup(), nStyle );
511 // Editable combo box uses the background of the associated edit box
512 QComboBox *pComboBox = static_cast<QComboBox *>( pWidget->qt_cast( "QComboBox" ) );
513 if ( pComboBox && pComboBox->editable() && pComboBox->lineEdit() )
515 QColorGroup::ColorRole eColorRole = ( pComboBox->isEnabled() )?
516 QColorGroup::Base: QColorGroup::Background;
517 qPainter.fillRect(
518 kapp->style().querySubControlMetrics( QStyle::CC_ComboBox,
519 pComboBox, QStyle::SC_ComboBoxEditField ),
520 pComboBox->lineEdit()->colorGroup().brush( eColorRole ) );
523 else if ( strcmp( "QLineEdit", pClassName ) == 0 )
525 kapp->style().drawPrimitive( QStyle::PE_PanelLineEdit,
526 &qPainter, qRect,
527 pWidget->colorGroup(), nStyle | QStyle::Style_Sunken );
529 else if ( strcmp( "QSpinWidget", pClassName ) == 0 )
531 SpinbuttonValue *pValue = static_cast<SpinbuttonValue *> ( aValue.getOptionalVal() );
533 // Is any of the buttons pressed?
534 QStyle::SCFlags eActive = QStyle::SC_None;
535 if ( pValue )
537 if ( pValue->mnUpperState & CTRL_STATE_PRESSED )
538 eActive = QStyle::SC_SpinWidgetUp;
539 else if ( pValue->mnLowerState & CTRL_STATE_PRESSED )
540 eActive = QStyle::SC_SpinWidgetDown;
542 // Update the enable/disable state of the widget
543 if ( ( nState & CTRL_STATE_ENABLED ) ||
544 ( pValue->mnUpperState & CTRL_STATE_ENABLED ) ||
545 ( pValue->mnLowerState & CTRL_STATE_ENABLED ) )
547 pWidget->setEnabled( true );
548 nStyle |= QStyle::Style_Enabled;
550 else
551 pWidget->setEnabled( false );
553 // Mouse-over effect
554 if ( (pValue->mnUpperState & CTRL_STATE_ROLLOVER) ||
555 (pValue->mnLowerState & CTRL_STATE_ROLLOVER) )
556 nStyle |= QStyle::Style_MouseOver;
559 // Spin widget uses the background of the associated edit box
560 QSpinWidget *pSpinWidget = static_cast<QSpinWidget *>( pWidget->qt_cast( "QSpinWidget" ) );
561 if ( pSpinWidget && pSpinWidget->editWidget() )
563 QColorGroup::ColorRole eColorRole = ( pSpinWidget->isEnabled() )?
564 QColorGroup::Base: QColorGroup::Background;
565 qPainter.fillRect(
566 kapp->style().querySubControlMetrics( QStyle::CC_SpinWidget,
567 pSpinWidget, QStyle::SC_SpinWidgetEditField ),
568 pSpinWidget->editWidget()->colorGroup().brush( eColorRole ) );
571 // Adjust the frame (needed for Motif Plus style)
572 QRect qFrameRect = kapp->style().querySubControlMetrics( QStyle::CC_SpinWidget,
573 pWidget, QStyle::SC_SpinWidgetFrame );
575 kapp->style().drawComplexControl( QStyle::CC_SpinWidget,
576 &qPainter, pWidget, qFrameRect,
577 pWidget->colorGroup(), nStyle,
578 QStyle::SC_All, eActive );
580 else if ( strcmp( "QTabBar", pClassName ) == 0 )
582 TabitemValue *pValue = static_cast<TabitemValue *> ( aValue.getOptionalVal() );
584 QTab *pTab = NULL;
585 if ( pValue )
587 if ( ( pValue->isFirst() || pValue->isLeftAligned() ) && ( pValue->isLast() || pValue->isRightAligned() ) )
588 pTab = m_pTabAlone;
589 else if ( pValue->isFirst() || pValue->isLeftAligned() )
590 pTab = m_pTabLeft;
591 else if ( pValue->isLast() || pValue->isRightAligned() )
592 pTab = m_pTabRight;
593 else
594 pTab = m_pTabMiddle;
596 if ( !pTab )
597 return FALSE;
599 pTab->setRect( qRect );
601 kapp->style().drawControl( QStyle::CE_TabBarTab,
602 &qPainter, pWidget, qRect,
603 pWidget->colorGroup(), nStyle,
604 QStyleOption( pTab ) );
606 else if ( strcmp( "QTabWidget", pClassName ) == 0 )
608 kapp->style().drawPrimitive( QStyle::PE_PanelTabWidget,
609 &qPainter, qRect,
610 pWidget->colorGroup(), nStyle );
612 else if ( strcmp( "QListView", pClassName ) == 0 )
614 kapp->style().drawPrimitive( QStyle::PE_Panel,
615 &qPainter, qRect,
616 pWidget->colorGroup(), nStyle | QStyle::Style_Sunken );
618 else if ( strcmp( "QScrollBar", pClassName ) == 0 )
620 ScrollbarValue *pValue = static_cast<ScrollbarValue *> ( aValue.getOptionalVal() );
622 QStyle::SCFlags eActive = QStyle::SC_None;
623 if ( pValue )
625 // Workaround for Style_MouseOver-aware themes.
626 // Quite ugly, but I do not know about a better solution.
627 const char *pStyleName = kapp->style().className();
628 if ( strcmp( "QMotifPlusStyle", pStyleName ) == 0 )
630 nStyle |= QStyle::Style_MouseOver;
631 if ( pValue->mnThumbState & CTRL_STATE_ROLLOVER )
632 eActive = QStyle::SC_ScrollBarSlider;
634 else if ( strcmp( "QSGIStyle", pStyleName ) == 0 )
636 nStyle |= QStyle::Style_MouseOver;
637 if ( pValue->mnButton1State & CTRL_STATE_ROLLOVER )
638 eActive = QStyle::SC_ScrollBarSubLine;
639 else if ( pValue->mnButton2State & CTRL_STATE_ROLLOVER )
640 eActive = QStyle::SC_ScrollBarAddLine;
641 else if ( pValue->mnThumbState & CTRL_STATE_ROLLOVER )
642 eActive = QStyle::SC_ScrollBarSlider;
645 if ( pValue->mnButton1State & CTRL_STATE_PRESSED )
646 eActive = QStyle::SC_ScrollBarSubLine;
647 else if ( pValue->mnButton2State & CTRL_STATE_PRESSED )
648 eActive = QStyle::SC_ScrollBarAddLine;
649 else if ( pValue->mnThumbState & CTRL_STATE_PRESSED )
650 eActive = QStyle::SC_ScrollBarSlider;
651 else if ( pValue->mnPage1State & CTRL_STATE_PRESSED )
652 eActive = QStyle::SC_ScrollBarSubPage;
653 else if ( pValue->mnPage2State & CTRL_STATE_PRESSED )
654 eActive = QStyle::SC_ScrollBarAddPage;
656 // Update the enable/disable state of the widget
657 if ( ( nState & CTRL_STATE_ENABLED ) ||
658 ( pValue->mnButton1State & CTRL_STATE_ENABLED ) ||
659 ( pValue->mnButton2State & CTRL_STATE_ENABLED ) ||
660 ( pValue->mnThumbState & CTRL_STATE_ENABLED ) ||
661 ( pValue->mnPage1State & CTRL_STATE_ENABLED ) ||
662 ( pValue->mnPage2State & CTRL_STATE_ENABLED ) )
664 pWidget->setEnabled( true );
665 nStyle |= QStyle::Style_Enabled;
667 else
668 pWidget->setEnabled( false );
671 // Is it a horizontal scroll bar?
672 QScrollBar *pScrollBar = static_cast<QScrollBar *> ( pWidget->qt_cast( "QScrollBar" ) );
673 QStyle::StyleFlags eHoriz = QStyle::Style_Default;
674 if ( pScrollBar && pScrollBar->orientation() == Qt::Horizontal )
675 eHoriz = QStyle::Style_Horizontal;
677 kapp->style().drawComplexControl( QStyle::CC_ScrollBar,
678 &qPainter, pWidget, qRect,
679 pWidget->colorGroup(), nStyle | eHoriz,
680 QStyle::SC_All, eActive );
682 else if ( strcmp( "QToolBar", pClassName ) == 0 )
684 QToolBar *pToolBar = static_cast< QToolBar * >( pWidget->qt_cast( "QToolBar" ) );
685 bool bIsHorizontal = false;
686 if ( pToolBar && pToolBar->orientation() == Qt::Horizontal )
688 nStyle |= QStyle::Style_Horizontal;
689 bIsHorizontal = true;
692 kapp->style().drawControl( QStyle::CE_DockWindowEmptyArea,
693 &qPainter, pWidget, qRect,
694 pWidget->colorGroup(), nStyle );
696 kapp->style().drawPrimitive( QStyle::PE_PanelDockWindow,
697 &qPainter, qRect, pWidget->colorGroup(), nStyle );
699 if ( nPart == PART_THUMB_HORZ || nPart == PART_THUMB_VERT )
701 ToolbarValue *pValue = static_cast< ToolbarValue * >( aValue.getOptionalVal() );
703 QRect qThumbRect = region2QRect( pValue->maGripRect );
704 qThumbRect.moveBy( -qWidgetPos.x(), -qWidgetPos.y() );
705 if ( bIsHorizontal )
706 qThumbRect.addCoords( 0, 2, 0, -3 ); // make the thumb a bit nicer
707 else
708 qThumbRect.addCoords( 2, 0, -3, 0 ); // make the thumb a bit nicer
710 if ( kapp->style().inherits( "HighColorStyle" ) ||
711 kapp->style().inherits( "HighContrastStyle" ) ||
712 kapp->style().inherits( "KeramikStyle" ) ||
713 kapp->style().inherits( "KThemeStyle" ) ||
714 kapp->style().inherits( "ThinKeramikStyle" ) )
716 // Workaround for the workaround in KStyle::drawPrimitive()
717 KStyle *pStyle = static_cast< KStyle * >( &kapp->style() );
718 pStyle->drawKStylePrimitive( KStyle::KPE_ToolBarHandle,
719 &qPainter, pToolBar, qThumbRect,
720 pWidget->colorGroup(), nStyle );
722 else
723 kapp->style().drawPrimitive( QStyle::PE_DockWindowHandle,
724 &qPainter, qThumbRect, pWidget->colorGroup(), nStyle );
727 else if ( strcmp( "QToolButton", pClassName ) == 0 )
729 if( (nStyle & QStyle::Style_MouseOver) )
730 nStyle &= ~QStyle::Style_Off;
731 kapp->style().drawComplexControl( QStyle::CC_ToolButton,
732 &qPainter, pWidget, qRect,
733 pWidget->colorGroup(), nStyle,
734 QStyle::SC_ToolButton );
736 else if ( strcmp( "QMenuBar", pClassName ) == 0 )
738 if ( nPart == PART_ENTIRE_CONTROL )
740 kapp->style().drawControl( QStyle::CE_MenuBarEmptyArea,
741 &qPainter, pWidget, qRect,
742 pWidget->colorGroup(), nStyle );
744 else if ( nPart == PART_MENU_ITEM )
746 int nMenuItem = ( nStyle & QStyle::Style_Enabled )? m_nMenuBarEnabledItem: m_nMenuBarDisabledItem;
747 QMenuItem *pMenuItem = static_cast<QMenuBar*>( pWidget )->findItem( nMenuItem );
749 if ( nStyle & QStyle::Style_Selected )
750 nStyle |= QStyle::Style_Active | QStyle::Style_Down | QStyle::Style_HasFocus;
752 kapp->style().drawControl( QStyle::CE_MenuBarItem,
753 &qPainter, pWidget, qRect,
754 pWidget->colorGroup(), nStyle,
755 QStyleOption( pMenuItem ) );
758 else if ( strcmp( "QPopupMenu", pClassName ) == 0 )
760 int nMenuItem = ( nStyle & QStyle::Style_Enabled )? m_nPopupMenuEnabledItem: m_nPopupMenuDisabledItem;
761 QMenuItem *pMenuItem = static_cast<QPopupMenu*>( pWidget )->findItem( nMenuItem );
763 if ( nStyle & QStyle::Style_Selected )
764 nStyle |= QStyle::Style_Active;
766 kapp->style().drawControl( QStyle::CE_PopupMenuItem,
767 &qPainter, pWidget, qRect,
768 pWidget->colorGroup(), nStyle,
769 QStyleOption( pMenuItem, 0, 0 ) );
771 else if ( strcmp( "QProgressBar", pClassName ) == 0 )
773 long nProgressWidth = aValue.getNumericVal();
774 QProgressBar* pProgress = static_cast<QProgressBar*>(pWidget);
775 pProgress->setProgress( nProgressWidth, qRect.width() );
777 kapp->style().drawControl( QStyle::CE_ProgressBarGroove,
778 &qPainter, pWidget, qRect,
779 pWidget->colorGroup(), nStyle );
780 kapp->style().drawControl( QStyle::CE_ProgressBarContents,
781 &qPainter, pWidget, qRect,
782 pWidget->colorGroup(), nStyle );
784 else
785 return FALSE;
787 // Bitblt it to the screen
788 X11SalGraphics::CopyScreenArea( dpy,
789 qPixmap.handle(), qPixmap.x11Screen(), qPixmap.x11Depth(),
790 drawable, nScreen, nDepth,
792 0, 0, qRect.width(), qRect.height(),
793 qWidgetPos.x(), qWidgetPos.y() );
795 // Restore widget's position
796 pWidget->move( qWidgetPos );
798 return TRUE;
801 QPushButton *WidgetPainter::pushButton( const Region& rControlRegion,
802 BOOL bDefault )
804 if ( !m_pPushButton )
805 m_pPushButton = new QPushButton( NULL, "push_button" );
807 QRect qRect = region2QRect( rControlRegion );
809 // Workaround for broken styles which do not add
810 // QStyle::PM_ButtonDefaultIndicator to the size of the default button
811 // (for example Keramik)
812 // FIXME Fix Keramik style to be consistant with Qt built-in styles. Aargh!
813 if ( bDefault )
815 QSize qContentsSize( 50, 50 );
816 m_pPushButton->setDefault( false );
817 QSize qNormalSize = kapp->style().sizeFromContents( QStyle::CT_PushButton,
818 m_pPushButton, qContentsSize );
819 m_pPushButton->setDefault( true );
820 QSize qDefSize = kapp->style().sizeFromContents( QStyle::CT_PushButton,
821 m_pPushButton, qContentsSize );
823 int nIndicatorSize = kapp->style().pixelMetric(
824 QStyle::PM_ButtonDefaultIndicator, m_pPushButton );
825 if ( qNormalSize.width() == qDefSize.width() )
826 qRect.addCoords( nIndicatorSize, 0, -nIndicatorSize, 0 );
827 if ( qNormalSize.height() == qDefSize.height() )
828 qRect.addCoords( 0, nIndicatorSize, 0, -nIndicatorSize );
831 m_pPushButton->move( qRect.topLeft() );
832 m_pPushButton->resize( qRect.size() );
833 m_pPushButton->setDefault( bDefault );
835 return m_pPushButton;
838 QRadioButton *WidgetPainter::radioButton( const Region& rControlRegion )
840 if ( !m_pRadioButton )
841 m_pRadioButton = new QRadioButton( NULL, "radio_button" );
843 QRect qRect = region2QRect( rControlRegion );
845 // Workaround for broken themes which do not honor the given size.
846 // Quite ugly, but I do not know about a better solution.
847 const char *pStyleName = kapp->style().className();
848 if ( strcmp( "KThemeStyle", pStyleName ) == 0 )
850 QRect qOldRect( qRect );
852 qRect.setWidth( kapp->style().pixelMetric(
853 QStyle::PM_ExclusiveIndicatorWidth, m_pRadioButton ) );
854 qRect.setHeight( kapp->style().pixelMetric(
855 QStyle::PM_ExclusiveIndicatorHeight, m_pRadioButton ) );
857 qRect.moveBy( ( qOldRect.width() - qRect.width() ) / 2,
858 ( qOldRect.height() - qRect.height() ) / 2 );
861 m_pRadioButton->move( qRect.topLeft() );
862 m_pRadioButton->resize( qRect.size() );
864 return m_pRadioButton;
867 QCheckBox *WidgetPainter::checkBox( const Region& rControlRegion )
869 if ( !m_pCheckBox )
870 m_pCheckBox = new QCheckBox( NULL, "check_box" );
872 QRect qRect = region2QRect( rControlRegion );
874 // Workaround for broken themes which do not honor the given size.
875 // Quite ugly, but I do not know about a better solution.
876 const char *pStyleName = kapp->style().className();
877 if ( strcmp( "KThemeStyle", pStyleName ) == 0 )
879 QRect qOldRect( qRect );
881 qRect.setWidth( kapp->style().pixelMetric(
882 QStyle::PM_IndicatorWidth, m_pCheckBox ) );
883 qRect.setHeight( kapp->style().pixelMetric(
884 QStyle::PM_IndicatorHeight, m_pCheckBox ) );
886 qRect.moveBy( ( qOldRect.width() - qRect.width() ) / 2,
887 ( qOldRect.height() - qRect.height() ) / 2 );
890 m_pCheckBox->move( qRect.topLeft() );
891 m_pCheckBox->resize( qRect.size() );
893 return m_pCheckBox;
896 QComboBox *WidgetPainter::comboBox( const Region& rControlRegion,
897 BOOL bEditable )
899 QComboBox *pComboBox = NULL;
900 if ( bEditable )
902 if ( !m_pEditableComboBox )
903 m_pEditableComboBox = new QComboBox( true, NULL, "combo_box_edit" );
904 pComboBox = m_pEditableComboBox;
906 else
908 if ( !m_pComboBox )
909 m_pComboBox = new QComboBox( false, NULL, "combo_box" );
910 pComboBox = m_pComboBox;
913 QRect qRect = region2QRect( rControlRegion );
915 pComboBox->move( qRect.topLeft() );
916 pComboBox->resize( qRect.size() );
918 return pComboBox;
921 QLineEdit *WidgetPainter::lineEdit( const Region& rControlRegion )
923 if ( !m_pLineEdit )
924 m_pLineEdit = new QLineEdit( NULL, "line_edit" );
926 QRect qRect = region2QRect( rControlRegion );
928 m_pLineEdit->move( qRect.topLeft() );
929 m_pLineEdit->resize( qRect.size() );
931 return m_pLineEdit;
934 QSpinWidget *WidgetPainter::spinWidget( const Region& rControlRegion )
936 if ( !m_pSpinWidget )
938 m_pSpinWidget = new QSpinWidget( NULL, "spin_widget" );
940 m_pSpinEdit = new QLineEdit( NULL, "line_edit_spin" );
941 m_pSpinWidget->setEditWidget( m_pSpinEdit );
944 QRect qRect = region2QRect( rControlRegion );
946 m_pSpinWidget->move( qRect.topLeft() );
947 m_pSpinWidget->resize( qRect.size() );
948 m_pSpinWidget->arrange();
950 return m_pSpinWidget;
953 QTabBar *WidgetPainter::tabBar( const Region& rControlRegion )
955 if ( !m_pTabBar )
957 if ( !m_pTabBarParent )
958 m_pTabBarParent = new QWidget( NULL, "tab_bar_parent" );
960 m_pTabBar = new QTabBar( m_pTabBarParent, "tab_bar" );
962 m_pTabLeft = new QTab();
963 m_pTabMiddle = new QTab();
964 m_pTabRight = new QTab();
965 m_pTabAlone = new QTab();
967 m_pTabBar->addTab( m_pTabLeft );
968 m_pTabBar->addTab( m_pTabMiddle );
969 m_pTabBar->addTab( m_pTabRight );
972 QRect qRect = region2QRect( rControlRegion );
974 m_pTabBar->move( qRect.topLeft() );
975 m_pTabBar->resize( qRect.size() );
977 m_pTabBar->setShape( QTabBar::RoundedAbove );
979 return m_pTabBar;
982 QTabWidget *WidgetPainter::tabWidget( const Region& rControlRegion )
984 if ( !m_pTabWidget )
985 m_pTabWidget = new QTabWidget( NULL, "tab_widget" );
987 QRect qRect = region2QRect( rControlRegion );
988 --qRect.rTop();
990 m_pTabWidget->move( qRect.topLeft() );
991 m_pTabWidget->resize( qRect.size() );
993 return m_pTabWidget;
996 QListView *WidgetPainter::listView( const Region& rControlRegion )
998 if ( !m_pListView )
999 m_pListView = new QListView( NULL, "list_view" );
1001 QRect qRect = region2QRect( rControlRegion );
1003 m_pListView->move( qRect.topLeft() );
1004 m_pListView->resize( qRect.size() );
1006 return m_pListView;
1009 QScrollBar *WidgetPainter::scrollBar( const Region& rControlRegion,
1010 BOOL bHorizontal, const ImplControlValue& aValue )
1012 if ( !m_pScrollBar )
1014 m_pScrollBar = new QScrollBar( NULL, "scroll_bar" );
1015 m_pScrollBar->setTracking( false );
1016 m_pScrollBar->setLineStep( 1 );
1019 QRect qRect = region2QRect( rControlRegion );
1021 m_pScrollBar->move( qRect.topLeft() );
1022 m_pScrollBar->resize( qRect.size() );
1023 m_pScrollBar->setOrientation( bHorizontal? Qt::Horizontal: Qt::Vertical );
1025 ScrollbarValue *pValue = static_cast<ScrollbarValue *> ( aValue.getOptionalVal() );
1026 if ( pValue )
1028 m_pScrollBar->setMinValue( pValue->mnMin );
1029 m_pScrollBar->setMaxValue( pValue->mnMax - pValue->mnVisibleSize );
1030 m_pScrollBar->setValue( pValue->mnCur );
1031 m_pScrollBar->setPageStep( pValue->mnVisibleSize );
1034 return m_pScrollBar;
1037 QToolBar *WidgetPainter::toolBar( const Region& rControlRegion, BOOL bHorizontal )
1039 if ( !m_pMainWindow )
1040 m_pMainWindow = new QMainWindow( NULL, "main_window" );
1042 QToolBar *pToolBar;
1043 if ( bHorizontal )
1045 if ( !m_pToolBarHoriz )
1047 m_pToolBarHoriz = new QToolBar( m_pMainWindow, "tool_bar_horiz" );
1048 m_pMainWindow->moveDockWindow( m_pToolBarHoriz, Qt::DockTop );
1050 pToolBar = m_pToolBarHoriz;
1052 else
1054 if ( !m_pToolBarVert )
1056 m_pToolBarVert = new QToolBar( m_pMainWindow, "tool_bar_horiz" );
1057 m_pMainWindow->moveDockWindow( m_pToolBarVert, Qt::DockLeft );
1059 pToolBar = m_pToolBarVert;
1062 QRect qRect = region2QRect( rControlRegion );
1064 pToolBar->move( qRect.topLeft() );
1065 pToolBar->resize( qRect.size() );
1067 return pToolBar;
1070 QToolButton *WidgetPainter::toolButton( const Region& rControlRegion)
1072 if ( !m_pToolButton )
1073 m_pToolButton = new QToolButton( NULL, "tool_button" );
1075 QRect qRect = region2QRect( rControlRegion );
1077 m_pToolButton->move( qRect.topLeft() );
1078 m_pToolButton->resize( qRect.size() );
1080 return m_pToolButton;
1083 QMenuBar *WidgetPainter::menuBar( const Region& rControlRegion)
1085 if ( !m_pMenuBar )
1087 m_pMenuBar = new QMenuBar( NULL, "menu_bar" );
1089 m_nMenuBarEnabledItem = m_pMenuBar->insertItem( "" );
1090 m_nMenuBarDisabledItem = m_pMenuBar->insertItem( "" );
1092 m_pMenuBar->setItemEnabled( m_nMenuBarEnabledItem, true );
1093 m_pMenuBar->setItemEnabled( m_nMenuBarDisabledItem, false );
1096 QRect qRect = region2QRect( rControlRegion );
1098 m_pMenuBar->move( qRect.topLeft() );
1099 m_pMenuBar->resize( qRect.size() );
1101 return m_pMenuBar;
1104 QPopupMenu *WidgetPainter::popupMenu( const Region& rControlRegion)
1106 if ( !m_pPopupMenu )
1108 m_pPopupMenu = new QPopupMenu( NULL, "popup_menu" );
1110 m_nPopupMenuEnabledItem = m_pPopupMenu->insertItem( "" );
1111 m_nPopupMenuDisabledItem = m_pPopupMenu->insertItem( "" );
1113 m_pPopupMenu->setItemEnabled( m_nPopupMenuEnabledItem, true );
1114 m_pPopupMenu->setItemEnabled( m_nPopupMenuDisabledItem, false );
1117 QRect qRect = region2QRect( rControlRegion );
1119 m_pPopupMenu->move( qRect.topLeft() );
1120 m_pPopupMenu->resize( qRect.size() );
1122 return m_pPopupMenu;
1125 QProgressBar *WidgetPainter::progressBar( const Region& rControlRegion )
1127 if ( !m_pProgressBar )
1128 m_pProgressBar = new QProgressBar( NULL, "progress_bar" );
1130 QRect qRect = region2QRect( rControlRegion );
1132 m_pProgressBar->move( qRect.topLeft() );
1133 m_pProgressBar->resize( qRect.size() );
1135 return m_pProgressBar;
1138 QStyle::SFlags WidgetPainter::vclStateValue2SFlags( ControlState nState,
1139 const ImplControlValue& aValue )
1141 QStyle::SFlags nStyle =
1142 ( (nState & CTRL_STATE_DEFAULT)? QStyle::Style_ButtonDefault: QStyle::Style_Default ) |
1143 ( (nState & CTRL_STATE_ENABLED)? QStyle::Style_Enabled: QStyle::Style_Default ) |
1144 ( (nState & CTRL_STATE_FOCUSED)? QStyle::Style_HasFocus: QStyle::Style_Default ) |
1145 ( (nState & CTRL_STATE_PRESSED)? QStyle::Style_Down: QStyle::Style_Raised ) |
1146 ( (nState & CTRL_STATE_SELECTED)? QStyle::Style_Selected : QStyle::Style_Default ) |
1147 ( (nState & CTRL_STATE_ROLLOVER)? QStyle::Style_MouseOver: QStyle::Style_Default );
1148 //TODO ( (nState & CTRL_STATE_HIDDEN)? QStyle::Style_: QStyle::Style_Default ) |
1150 switch ( aValue.getTristateVal() )
1152 case BUTTONVALUE_ON: nStyle |= QStyle::Style_On; break;
1153 case BUTTONVALUE_OFF: nStyle |= QStyle::Style_Off; break;
1154 case BUTTONVALUE_MIXED: nStyle |= QStyle::Style_NoChange; break;
1155 default: break;
1158 return nStyle;
1161 QRect WidgetPainter::region2QRect( const Region& rControlRegion )
1163 Rectangle aRect = rControlRegion.GetBoundRect();
1165 return QRect( QPoint( aRect.Left(), aRect.Top() ),
1166 QPoint( aRect.Right(), aRect.Bottom() ) );
1169 /** Instance of WidgetPainter.
1171 It is used to paint the widgets requested by NWF.
1173 static WidgetPainter *pWidgetPainter;
1175 class KDESalGraphics : public X11SalGraphics
1177 public:
1178 KDESalGraphics() {}
1179 virtual ~KDESalGraphics() {}
1180 virtual BOOL IsNativeControlSupported( ControlType nType, ControlPart nPart );
1181 virtual BOOL hitTestNativeControl( ControlType nType, ControlPart nPart,
1182 const Region& rControlRegion, const Point& aPos,
1183 SalControlHandle& rControlHandle, BOOL& rIsInside );
1184 virtual BOOL drawNativeControl( ControlType nType, ControlPart nPart,
1185 const Region& rControlRegion, ControlState nState,
1186 const ImplControlValue& aValue, SalControlHandle& rControlHandle,
1187 const OUString& aCaption );
1188 virtual BOOL drawNativeControlText( ControlType nType, ControlPart nPart,
1189 const Region& rControlRegion, ControlState nState,
1190 const ImplControlValue& aValue, SalControlHandle& rControlHandle,
1191 const OUString& aCaption );
1192 virtual BOOL getNativeControlRegion( ControlType nType, ControlPart nPart,
1193 const Region& rControlRegion, ControlState nState,
1194 const ImplControlValue& aValue, SalControlHandle& rControlHandle,
1195 const OUString& aCaption,
1196 Region &rNativeBoundingRegion, Region &rNativeContentRegion );
1199 /** What widgets can be drawn the native way.
1201 @param nType
1202 Type of the widget.
1204 @param nPart
1205 Specification of the widget's part if it consists of more than one.
1207 @return TRUE if the platform supports native drawing of the widget nType
1208 defined by nPart.
1210 BOOL KDESalGraphics::IsNativeControlSupported( ControlType nType, ControlPart nPart )
1212 return
1213 ( (nType == CTRL_PUSHBUTTON) && (nPart == PART_ENTIRE_CONTROL) ) ||
1214 ( (nType == CTRL_RADIOBUTTON) && (nPart == PART_ENTIRE_CONTROL) ) ||
1215 ( (nType == CTRL_CHECKBOX) && (nPart == PART_ENTIRE_CONTROL) ) ||
1216 ( (nType == CTRL_COMBOBOX) && (nPart == PART_ENTIRE_CONTROL || nPart == HAS_BACKGROUND_TEXTURE) ) ||
1217 ( (nType == CTRL_EDITBOX) && (nPart == PART_ENTIRE_CONTROL || nPart == HAS_BACKGROUND_TEXTURE) ) ||
1218 ( (nType == CTRL_LISTBOX) && (nPart == PART_ENTIRE_CONTROL || nPart == PART_WINDOW || nPart == HAS_BACKGROUND_TEXTURE ) ) ||
1219 ( (nType == CTRL_SPINBOX) && (nPart == PART_ENTIRE_CONTROL || nPart == HAS_BACKGROUND_TEXTURE) ) ||
1220 // no CTRL_SPINBUTTONS for KDE
1221 ( (nType == CTRL_TAB_ITEM) && (nPart == PART_ENTIRE_CONTROL) ) ||
1222 ( (nType == CTRL_TAB_PANE) && (nPart == PART_ENTIRE_CONTROL) ) ||
1223 // no CTRL_TAB_BODY for KDE
1224 ( (nType == CTRL_SCROLLBAR) && (nPart == PART_ENTIRE_CONTROL || nPart == PART_DRAW_BACKGROUND_HORZ || nPart == PART_DRAW_BACKGROUND_VERT) ) ||
1225 ( (nType == CTRL_SCROLLBAR) && (nPart == HAS_THREE_BUTTONS) ) || // TODO small optimization is possible here: return this only if the style really has 3 buttons
1226 // CTRL_GROUPBOX not supported
1227 // CTRL_FIXEDLINE not supported
1228 // CTRL_FIXEDBORDER not supported
1229 ( (nType == CTRL_TOOLBAR) && (nPart == PART_ENTIRE_CONTROL ||
1230 nPart == PART_DRAW_BACKGROUND_HORZ || nPart == PART_DRAW_BACKGROUND_VERT ||
1231 nPart == PART_THUMB_HORZ || nPart == PART_THUMB_VERT ||
1232 nPart == PART_BUTTON) ) ||
1233 ( (nType == CTRL_MENUBAR) && (nPart == PART_ENTIRE_CONTROL || nPart == PART_MENU_ITEM) ) ||
1234 ( (nType == CTRL_MENU_POPUP) && (nPart == PART_ENTIRE_CONTROL || nPart == PART_MENU_ITEM) ) ||
1235 ( (nType == CTRL_PROGRESS) && (nPart == PART_ENTIRE_CONTROL) )
1240 /** Test whether the position is in the native widget.
1242 If the return value is TRUE, bIsInside contains information whether
1243 aPos was or was not inside the native widget specified by the
1244 nType/nPart combination.
1246 BOOL KDESalGraphics::hitTestNativeControl( ControlType nType, ControlPart nPart,
1247 const Region& rControlRegion, const Point& rPos,
1248 SalControlHandle&, BOOL& rIsInside )
1250 if ( nType == CTRL_SCROLLBAR )
1252 // make position relative to rControlRegion
1253 Point aPos = rPos - rControlRegion.GetBoundRect().TopLeft();
1254 rIsInside = FALSE;
1256 BOOL bHorizontal = ( nPart == PART_BUTTON_LEFT || nPart == PART_BUTTON_RIGHT );
1258 QScrollBar *pScrollBar = pWidgetPainter->scrollBar( rControlRegion,
1259 bHorizontal, ImplControlValue() );
1260 QRect qRectSubLine = kapp->style().querySubControlMetrics(
1261 QStyle::CC_ScrollBar, pScrollBar, QStyle::SC_ScrollBarSubLine );
1262 QRect qRectAddLine = kapp->style().querySubControlMetrics(
1263 QStyle::CC_ScrollBar, pScrollBar, QStyle::SC_ScrollBarAddLine );
1265 // There are 2 buttons on the right/bottom side of the scrollbar
1266 BOOL bTwoSubButtons = FALSE;
1268 // It is a Platinum style scroll bar
1269 BOOL bPlatinumStyle = FALSE;
1271 // Workaround for Platinum and 3 button style scroll bars.
1272 // It makes the right/down button bigger.
1273 if ( bHorizontal )
1275 qRectAddLine.setLeft( kapp->style().querySubControlMetrics(
1276 QStyle::CC_ScrollBar, pScrollBar,
1277 QStyle::SC_ScrollBarAddPage ).right() + 1 );
1278 if ( qRectAddLine.width() > qRectSubLine.width() )
1279 bTwoSubButtons = TRUE;
1280 if ( qRectSubLine.left() > kapp->style().querySubControlMetrics( QStyle::CC_ScrollBar, pScrollBar, QStyle::SC_ScrollBarSubPage ).left() )
1281 bPlatinumStyle = TRUE;
1283 else
1285 qRectAddLine.setTop( kapp->style().querySubControlMetrics(
1286 QStyle::CC_ScrollBar, pScrollBar,
1287 QStyle::SC_ScrollBarAddPage ).bottom() + 1 );
1288 if ( qRectAddLine.height() > qRectSubLine.height() )
1289 bTwoSubButtons = TRUE;
1290 if ( qRectSubLine.top() > kapp->style().querySubControlMetrics( QStyle::CC_ScrollBar, pScrollBar, QStyle::SC_ScrollBarSubPage ).top() )
1291 bPlatinumStyle = TRUE;
1294 switch ( nPart )
1296 case PART_BUTTON_LEFT:
1297 if ( !bPlatinumStyle && qRectSubLine.contains( aPos.getX(), aPos.getY() ) )
1298 rIsInside = TRUE;
1299 else if ( bTwoSubButtons )
1301 qRectAddLine.setWidth( qRectAddLine.width() / 2 );
1302 rIsInside = qRectAddLine.contains( aPos.getX(), aPos.getY() );
1304 break;
1306 case PART_BUTTON_UP:
1307 if ( !bPlatinumStyle && qRectSubLine.contains( aPos.getX(), aPos.getY() ) )
1308 rIsInside = TRUE;
1309 else if ( bTwoSubButtons )
1311 qRectAddLine.setHeight( qRectAddLine.height() / 2 );
1312 rIsInside = qRectAddLine.contains( aPos.getX(), aPos.getY() );
1314 break;
1316 case PART_BUTTON_RIGHT:
1317 if ( bTwoSubButtons )
1318 qRectAddLine.setLeft( qRectAddLine.left() + qRectAddLine.width() / 2 );
1320 rIsInside = qRectAddLine.contains( aPos.getX(), aPos.getY() );
1321 break;
1323 case PART_BUTTON_DOWN:
1324 if ( bTwoSubButtons )
1325 qRectAddLine.setTop( qRectAddLine.top() + qRectAddLine.height() / 2 );
1327 rIsInside = qRectAddLine.contains( aPos.getX(), aPos.getY() );
1328 break;
1330 // cases PART_TRACK_HORZ_AREA and PART_TRACK_VERT_AREA
1331 default:
1332 return FALSE;
1335 return TRUE;
1338 return FALSE;
1342 /** Draw the requested control described by nPart/nState.
1344 @param rControlRegion
1345 The bounding region of the complete control in VCL frame coordinates.
1347 @param aValue
1348 An optional value (tristate/numerical/string).
1350 @param rControlHandle
1351 Carries platform dependent data and is maintained by the SalFrame implementation.
1353 @param aCaption
1354 A caption or title string (like button text etc.)
1356 BOOL KDESalGraphics::drawNativeControl( ControlType nType, ControlPart nPart,
1357 const Region& rControlRegion, ControlState nState,
1358 const ImplControlValue& aValue, SalControlHandle&,
1359 const OUString& )
1361 BOOL bReturn = FALSE;
1363 Display *dpy = GetXDisplay();
1364 XLIB_Window drawable = GetDrawable();
1365 GC gc = SelectPen(); //SelectFont(); // GC with current clipping region set
1367 if ( (nType == CTRL_PUSHBUTTON) && (nPart == PART_ENTIRE_CONTROL) )
1369 bReturn = pWidgetPainter->drawStyledWidget(
1370 pWidgetPainter->pushButton( rControlRegion, (nState & CTRL_STATE_DEFAULT) ),
1371 nState, aValue,
1372 dpy, drawable, GetScreenNumber(), GetVisual().GetDepth(), gc );
1374 else if ( (nType == CTRL_RADIOBUTTON) && (nPart == PART_ENTIRE_CONTROL) )
1376 bReturn = pWidgetPainter->drawStyledWidget(
1377 pWidgetPainter->radioButton( rControlRegion ),
1378 nState, aValue,
1379 dpy, drawable, GetScreenNumber(), GetVisual().GetDepth(), gc );
1381 else if ( (nType == CTRL_CHECKBOX) && (nPart == PART_ENTIRE_CONTROL) )
1383 bReturn = pWidgetPainter->drawStyledWidget(
1384 pWidgetPainter->checkBox( rControlRegion ),
1385 nState, aValue,
1386 dpy, drawable, GetScreenNumber(), GetVisual().GetDepth(), gc );
1388 else if ( (nType == CTRL_COMBOBOX) && (nPart == PART_ENTIRE_CONTROL) )
1390 bReturn = pWidgetPainter->drawStyledWidget(
1391 pWidgetPainter->comboBox( rControlRegion, TRUE ),
1392 nState, aValue,
1393 dpy, drawable, GetScreenNumber(), GetVisual().GetDepth(), gc );
1395 else if ( (nType == CTRL_EDITBOX) && (nPart == PART_ENTIRE_CONTROL) )
1397 bReturn = pWidgetPainter->drawStyledWidget(
1398 pWidgetPainter->lineEdit( rControlRegion ),
1399 nState, aValue,
1400 dpy, drawable, GetScreenNumber(), GetVisual().GetDepth(), gc );
1402 else if ( (nType == CTRL_LISTBOX) && (nPart == PART_ENTIRE_CONTROL) )
1404 bReturn = pWidgetPainter->drawStyledWidget(
1405 pWidgetPainter->comboBox( rControlRegion, FALSE ),
1406 nState, aValue,
1407 dpy, drawable, GetScreenNumber(), GetVisual().GetDepth(), gc );
1409 else if ( (nType == CTRL_LISTBOX) && (nPart == PART_WINDOW) )
1411 bReturn = pWidgetPainter->drawStyledWidget(
1412 pWidgetPainter->listView( rControlRegion ),
1413 nState, aValue,
1414 dpy, drawable, GetScreenNumber(), GetVisual().GetDepth(), gc );
1416 else if ( (nType == CTRL_SPINBOX) && (nPart == PART_ENTIRE_CONTROL) )
1418 bReturn = pWidgetPainter->drawStyledWidget(
1419 pWidgetPainter->spinWidget( rControlRegion ),
1420 nState, aValue,
1421 dpy, drawable, GetScreenNumber(), GetVisual().GetDepth(), gc );
1423 else if ( (nType==CTRL_TAB_ITEM) && (nPart == PART_ENTIRE_CONTROL) )
1425 bReturn = pWidgetPainter->drawStyledWidget(
1426 pWidgetPainter->tabBar( rControlRegion ),
1427 nState, aValue,
1428 dpy, drawable, GetScreenNumber(), GetVisual().GetDepth(), gc );
1430 else if ( (nType==CTRL_TAB_PANE) && (nPart == PART_ENTIRE_CONTROL) )
1432 bReturn = pWidgetPainter->drawStyledWidget(
1433 pWidgetPainter->tabWidget( rControlRegion ),
1434 nState, aValue,
1435 dpy, drawable, GetScreenNumber(), GetVisual().GetDepth(), gc );
1437 else if ( (nType == CTRL_SCROLLBAR) && (nPart == PART_DRAW_BACKGROUND_HORZ || nPart == PART_DRAW_BACKGROUND_VERT) )
1439 bReturn = pWidgetPainter->drawStyledWidget(
1440 pWidgetPainter->scrollBar( rControlRegion, nPart == PART_DRAW_BACKGROUND_HORZ, aValue ),
1441 nState, aValue,
1442 dpy, drawable, GetScreenNumber(), GetVisual().GetDepth(), gc );
1444 else if ( (nType == CTRL_TOOLBAR) && (nPart == PART_DRAW_BACKGROUND_HORZ || nPart == PART_DRAW_BACKGROUND_VERT || nPart == PART_THUMB_HORZ || nPart == PART_THUMB_VERT) )
1446 bReturn = pWidgetPainter->drawStyledWidget(
1447 pWidgetPainter->toolBar( rControlRegion, nPart == PART_DRAW_BACKGROUND_HORZ || nPart == PART_THUMB_VERT ),
1448 nState, aValue,
1449 dpy, drawable, GetScreenNumber(), GetVisual().GetDepth(), gc, nPart );
1451 else if ( (nType == CTRL_TOOLBAR) && (nPart == PART_BUTTON) )
1453 bReturn = pWidgetPainter->drawStyledWidget(
1454 pWidgetPainter->toolButton( rControlRegion ),
1455 nState, aValue,
1456 dpy, drawable, GetScreenNumber(), GetVisual().GetDepth(), gc, nPart );
1458 else if ( (nType == CTRL_MENUBAR) && (nPart == PART_ENTIRE_CONTROL || nPart == PART_MENU_ITEM) )
1460 bReturn = pWidgetPainter->drawStyledWidget(
1461 pWidgetPainter->menuBar( rControlRegion ),
1462 nState, aValue,
1463 dpy, drawable, GetScreenNumber(), GetVisual().GetDepth(), gc, nPart );
1465 else if ( (nType == CTRL_MENU_POPUP) && (nPart == PART_ENTIRE_CONTROL || nPart == PART_MENU_ITEM) )
1467 bReturn = pWidgetPainter->drawStyledWidget(
1468 pWidgetPainter->popupMenu( rControlRegion ),
1469 nState, aValue,
1470 dpy, drawable, GetScreenNumber(), GetVisual().GetDepth(), gc );
1472 else if ( (nType == CTRL_PROGRESS) && (nPart == PART_ENTIRE_CONTROL) )
1474 bReturn = pWidgetPainter->drawStyledWidget(
1475 pWidgetPainter->progressBar( rControlRegion ),
1476 nState, aValue,
1477 dpy, drawable, GetScreenNumber(), GetVisual().GetDepth(), gc );
1480 return bReturn;
1484 /** Draw text on the widget.
1486 OPTIONAL. Draws the requested text for the control described by nPart/nState.
1487 Used if text is not drawn by DrawNativeControl().
1489 @param rControlRegion
1490 The bounding region of the complete control in VCL frame coordinates.
1492 @param aValue
1493 An optional value (tristate/numerical/string)
1495 @param rControlHandle
1496 Carries platform dependent data and is maintained by the SalFrame implementation.
1498 @param aCaption
1499 A caption or title string (like button text etc.)
1501 BOOL KDESalGraphics::drawNativeControlText( ControlType, ControlPart,
1502 const Region&, ControlState,
1503 const ImplControlValue&, SalControlHandle&,
1504 const OUString& )
1506 return FALSE;
1509 /** Check if the bounding regions match.
1511 If the return value is TRUE, rNativeBoundingRegion
1512 contains the true bounding region covered by the control
1513 including any adornment, while rNativeContentRegion contains the area
1514 within the control that can be safely drawn into without drawing over
1515 the borders of the control.
1517 @param rControlRegion
1518 The bounding region of the control in VCL frame coordinates.
1520 @param aValue
1521 An optional value (tristate/numerical/string)
1523 @param rControlHandle
1524 Carries platform dependent data and is maintained by the SalFrame implementation.
1526 @param aCaption
1527 A caption or title string (like button text etc.)
1529 BOOL KDESalGraphics::getNativeControlRegion( ControlType nType, ControlPart nPart,
1530 const Region& rControlRegion, ControlState nState,
1531 const ImplControlValue&, SalControlHandle&,
1532 const OUString&,
1533 Region &rNativeBoundingRegion, Region &rNativeContentRegion )
1535 BOOL bReturn = FALSE;
1536 QRect qBoundingRect = WidgetPainter::region2QRect( rControlRegion );
1537 QRect qRect;
1539 QWidget *pWidget = NULL;
1540 switch ( nType )
1542 // Metrics of the push button
1543 case CTRL_PUSHBUTTON:
1544 pWidget = pWidgetPainter->pushButton( rControlRegion, ( nState & CTRL_STATE_DEFAULT ) );
1546 switch ( nPart )
1548 case PART_ENTIRE_CONTROL:
1549 qRect = qBoundingRect;
1551 if ( nState & CTRL_STATE_DEFAULT )
1553 int nIndicatorSize = kapp->style().pixelMetric(
1554 QStyle::PM_ButtonDefaultIndicator, pWidget );
1555 qBoundingRect.addCoords( -nIndicatorSize, -nIndicatorSize,
1556 nIndicatorSize, nIndicatorSize );
1557 bReturn = TRUE;
1559 break;
1561 break;
1563 // Metrics of the radio button
1564 case CTRL_RADIOBUTTON:
1565 pWidget = pWidgetPainter->radioButton( rControlRegion );
1567 if ( nPart == PART_ENTIRE_CONTROL )
1569 qRect.setWidth( kapp->style().pixelMetric( QStyle::PM_ExclusiveIndicatorWidth, pWidget ) );
1570 qRect.setHeight( kapp->style().pixelMetric( QStyle::PM_ExclusiveIndicatorHeight, pWidget ) );
1572 bReturn = TRUE;
1574 break;
1576 // Metrics of the check box
1577 case CTRL_CHECKBOX:
1578 pWidget = pWidgetPainter->checkBox( rControlRegion );
1580 if ( nPart == PART_ENTIRE_CONTROL )
1582 qRect.setWidth( kapp->style().pixelMetric( QStyle::PM_IndicatorWidth, pWidget ) );
1583 qRect.setHeight( kapp->style().pixelMetric( QStyle::PM_IndicatorHeight, pWidget ) );
1585 bReturn = TRUE;
1587 break;
1589 // Metrics of the combo box
1590 case CTRL_COMBOBOX:
1591 case CTRL_LISTBOX:
1592 pWidget = pWidgetPainter->comboBox( rControlRegion, ( nType == CTRL_COMBOBOX ) );
1593 switch ( nPart )
1595 case PART_BUTTON_DOWN:
1596 qRect = kapp->style().querySubControlMetrics(
1597 QStyle::CC_ComboBox, pWidget, QStyle::SC_ComboBoxArrow );
1598 qRect.setLeft( kapp->style().querySubControlMetrics(
1599 QStyle::CC_ComboBox, pWidget,
1600 QStyle::SC_ComboBoxEditField ).right() + 1 );
1601 qRect.moveBy( qBoundingRect.left(), qBoundingRect.top() );
1602 bReturn = TRUE;
1603 break;
1605 case PART_SUB_EDIT:
1606 qRect = kapp->style().querySubControlMetrics(
1607 QStyle::CC_ComboBox, pWidget, QStyle::SC_ComboBoxEditField );
1608 qRect.moveBy( qBoundingRect.left(), qBoundingRect.top() );
1609 bReturn = TRUE;
1610 break;
1612 break;
1614 // Metrics of the spin box
1615 case CTRL_SPINBOX:
1616 pWidget = pWidgetPainter->spinWidget( rControlRegion );
1617 switch ( nPart )
1619 case PART_BUTTON_UP:
1620 qRect = kapp->style().querySubControlMetrics(
1621 QStyle::CC_SpinWidget, pWidget, QStyle::SC_SpinWidgetUp );
1622 bReturn = TRUE;
1623 qRect.moveBy( qBoundingRect.left(), qBoundingRect.top() );
1624 break;
1626 case PART_BUTTON_DOWN:
1627 qRect = kapp->style().querySubControlMetrics(
1628 QStyle::CC_SpinWidget, pWidget, QStyle::SC_SpinWidgetDown );
1629 bReturn = TRUE;
1630 qRect.moveBy( qBoundingRect.left(), qBoundingRect.top() );
1631 break;
1633 case PART_SUB_EDIT:
1634 qRect = kapp->style().querySubControlMetrics(
1635 QStyle::CC_SpinWidget, pWidget, QStyle::SC_SpinWidgetEditField );
1636 qRect.moveBy( qBoundingRect.left(), qBoundingRect.top() );
1637 bReturn = TRUE;
1638 break;
1640 break;
1642 // Metrics of the scroll bar
1643 case CTRL_SCROLLBAR:
1644 pWidget = pWidgetPainter->scrollBar( rControlRegion,
1645 ( nPart == PART_BUTTON_LEFT || nPart == PART_BUTTON_RIGHT ),
1646 ImplControlValue() );
1647 switch ( nPart )
1649 case PART_BUTTON_LEFT:
1650 case PART_BUTTON_UP:
1651 qRect = kapp->style().querySubControlMetrics(
1652 QStyle::CC_ScrollBar, pWidget, QStyle::SC_ScrollBarSubLine );
1654 // Workaround for Platinum style scroll bars. It makes the
1655 // left/up button invisible.
1656 if ( nPart == PART_BUTTON_LEFT )
1658 if ( qRect.left() > kapp->style().querySubControlMetrics(
1659 QStyle::CC_ScrollBar, pWidget,
1660 QStyle::SC_ScrollBarSubPage ).left() )
1662 qRect.setLeft( 0 );
1663 qRect.setRight( 0 );
1666 else
1668 if ( qRect.top() > kapp->style().querySubControlMetrics(
1669 QStyle::CC_ScrollBar, pWidget,
1670 QStyle::SC_ScrollBarSubPage ).top() )
1672 qRect.setTop( 0 );
1673 qRect.setBottom( 0 );
1677 qRect.moveBy( qBoundingRect.left(), qBoundingRect.top() );
1679 bReturn = TRUE;
1680 break;
1682 case PART_BUTTON_RIGHT:
1683 case PART_BUTTON_DOWN:
1684 qRect = kapp->style().querySubControlMetrics(
1685 QStyle::CC_ScrollBar, pWidget, QStyle::SC_ScrollBarAddLine );
1687 // Workaround for Platinum and 3 button style scroll bars.
1688 // It makes the right/down button bigger.
1689 if ( nPart == PART_BUTTON_RIGHT )
1690 qRect.setLeft( kapp->style().querySubControlMetrics(
1691 QStyle::CC_ScrollBar, pWidget,
1692 QStyle::SC_ScrollBarAddPage ).right() + 1 );
1693 else
1694 qRect.setTop( kapp->style().querySubControlMetrics(
1695 QStyle::CC_ScrollBar, pWidget,
1696 QStyle::SC_ScrollBarAddPage ).bottom() + 1 );
1698 qRect.moveBy( qBoundingRect.left(), qBoundingRect.top() );
1700 bReturn = TRUE;
1701 break;
1703 break;
1706 // Fill rNativeBoundingRegion and rNativeContentRegion
1707 if ( bReturn )
1709 // Bounding region
1710 Point aBPoint( qBoundingRect.x(), qBoundingRect.y() );
1711 Size aBSize( qBoundingRect.width(), qBoundingRect.height() );
1712 rNativeBoundingRegion = Region( Rectangle( aBPoint, aBSize ) );
1714 // Region of the content
1715 Point aPoint( qRect.x(), qRect.y() );
1716 Size aSize( qRect.width(), qRect.height() );
1717 rNativeContentRegion = Region( Rectangle( aPoint, aSize ) );
1720 return bReturn;
1723 // -----------------------------------------------------------------------
1724 // KDESalFrame implementation
1725 // -----------------------------------------------------------------------
1727 KDESalFrame::KDESalFrame( SalFrame* pParent, ULONG nStyle ) :
1728 X11SalFrame( pParent, nStyle )
1732 void KDESalFrame::Show( BOOL bVisible, BOOL bNoActivate )
1734 if ( !GetParent() && ! (GetStyle() & SAL_FRAME_STYLE_INTRO) )
1736 KDEXLib* pXLib = static_cast<KDEXLib*>(GetDisplay()->GetXLib());
1737 pXLib->doStartup();
1739 X11SalFrame::Show( bVisible, bNoActivate );
1742 /** Helper function to convert colors.
1744 static Color toColor( const QColor &rColor )
1746 return Color( rColor.red(), rColor.green(), rColor.blue() );
1749 /** Helper function to read untranslated text entry from KConfig configuration repository.
1751 static OUString readEntryUntranslated( KConfig *pConfig, const char *pKey )
1753 return OUString::createFromAscii( pConfig->readEntryUntranslated( pKey ).ascii() );
1756 /** Helper function to read color from KConfig configuration repository.
1758 static Color readColor( KConfig *pConfig, const char *pKey )
1760 return toColor( pConfig->readColorEntry( pKey ) );
1763 /** Helper function to add information to Font from QFont.
1765 Mostly grabbed from the Gtk+ vclplug (salnativewidgets-gtk.cxx).
1767 static Font toFont( const QFont &rQFont, const ::com::sun::star::lang::Locale& rLocale )
1769 psp::FastPrintFontInfo aInfo;
1770 QFontInfo qFontInfo( rQFont );
1772 // set family name
1773 aInfo.m_aFamilyName = String( rQFont.family().utf8(), RTL_TEXTENCODING_UTF8 );
1775 // set italic
1776 aInfo.m_eItalic = ( qFontInfo.italic()? psp::italic::Italic: psp::italic::Upright );
1778 // set weight
1779 int nWeight = qFontInfo.weight();
1780 if ( nWeight <= QFont::Light )
1781 aInfo.m_eWeight = psp::weight::Light;
1782 else if ( nWeight <= QFont::Normal )
1783 aInfo.m_eWeight = psp::weight::Normal;
1784 else if ( nWeight <= QFont::DemiBold )
1785 aInfo.m_eWeight = psp::weight::SemiBold;
1786 else if ( nWeight <= QFont::Bold )
1787 aInfo.m_eWeight = psp::weight::Bold;
1788 else
1789 aInfo.m_eWeight = psp::weight::UltraBold;
1791 // set width
1792 int nStretch = rQFont.stretch();
1793 if ( nStretch <= QFont::UltraCondensed )
1794 aInfo.m_eWidth = psp::width::UltraCondensed;
1795 else if ( nStretch <= QFont::ExtraCondensed )
1796 aInfo.m_eWidth = psp::width::ExtraCondensed;
1797 else if ( nStretch <= QFont::Condensed )
1798 aInfo.m_eWidth = psp::width::Condensed;
1799 else if ( nStretch <= QFont::SemiCondensed )
1800 aInfo.m_eWidth = psp::width::SemiCondensed;
1801 else if ( nStretch <= QFont::Unstretched )
1802 aInfo.m_eWidth = psp::width::Normal;
1803 else if ( nStretch <= QFont::SemiExpanded )
1804 aInfo.m_eWidth = psp::width::SemiExpanded;
1805 else if ( nStretch <= QFont::Expanded )
1806 aInfo.m_eWidth = psp::width::Expanded;
1807 else if ( nStretch <= QFont::ExtraExpanded )
1808 aInfo.m_eWidth = psp::width::ExtraExpanded;
1809 else
1810 aInfo.m_eWidth = psp::width::UltraExpanded;
1812 #if OSL_DEBUG_LEVEL > 1
1813 fprintf( stderr, "font name BEFORE system match: \"%s\"\n", OUStringToOString( aInfo.m_aFamilyName, RTL_TEXTENCODING_ISO_8859_1 ).getStr() );
1814 #endif
1816 // match font to e.g. resolve "Sans"
1817 psp::PrintFontManager::get().matchFont( aInfo, rLocale );
1819 #if OSL_DEBUG_LEVEL > 1
1820 fprintf( stderr, "font match %s, name AFTER: \"%s\"\n",
1821 aInfo.m_nID != 0 ? "succeeded" : "failed",
1822 OUStringToOString( aInfo.m_aFamilyName, RTL_TEXTENCODING_ISO_8859_1 ).getStr() );
1823 #endif
1825 // font height
1826 int nPointHeight = qFontInfo.pointSize();
1827 if ( nPointHeight <= 0 )
1828 nPointHeight = rQFont.pointSize();
1830 // Create the font
1831 Font aFont( aInfo.m_aFamilyName, Size( 0, nPointHeight ) );
1832 if( aInfo.m_eWeight != psp::weight::Unknown )
1833 aFont.SetWeight( PspGraphics::ToFontWeight( aInfo.m_eWeight ) );
1834 if( aInfo.m_eWidth != psp::width::Unknown )
1835 aFont.SetWidthType( PspGraphics::ToFontWidth( aInfo.m_eWidth ) );
1836 if( aInfo.m_eItalic != psp::italic::Unknown )
1837 aFont.SetItalic( PspGraphics::ToFontItalic( aInfo.m_eItalic ) );
1838 if( aInfo.m_ePitch != psp::pitch::Unknown )
1839 aFont.SetPitch( PspGraphics::ToFontPitch( aInfo.m_ePitch ) );
1841 return aFont;
1844 /** Implementation of KDE integration's main method.
1846 void KDESalFrame::UpdateSettings( AllSettings& rSettings )
1848 StyleSettings aStyleSettings( rSettings.GetStyleSettings() );
1849 bool bSetTitleFont = false;
1851 // WM settings
1852 KConfig *pConfig = KGlobal::config();
1853 if ( pConfig )
1855 pConfig->setGroup( "WM" );
1856 const char *pKey;
1858 pKey = "activeBackground";
1859 if ( pConfig->hasKey( pKey ) )
1860 aStyleSettings.SetActiveColor( readColor( pConfig, pKey ) );
1862 pKey = "activeBlend";
1863 if ( pConfig->hasKey( pKey ) )
1864 aStyleSettings.SetActiveColor2( readColor( pConfig, pKey ) );
1866 pKey = "inactiveBackground";
1867 if ( pConfig->hasKey( pKey ) )
1868 aStyleSettings.SetDeactiveColor( readColor( pConfig, pKey ) );
1870 pKey = "inactiveBlend";
1871 if ( pConfig->hasKey( pKey ) )
1872 aStyleSettings.SetDeactiveColor2( readColor( pConfig, pKey ) );
1874 pKey = "inactiveForeground";
1875 if ( pConfig->hasKey( pKey ) )
1876 aStyleSettings.SetDeactiveTextColor( readColor( pConfig, pKey ) );
1878 pKey = "activeForeground";
1879 if ( pConfig->hasKey( pKey ) )
1880 aStyleSettings.SetActiveTextColor( readColor( pConfig, pKey ) );
1882 pKey = "titleFont";
1883 if ( pConfig->hasKey( pKey ) )
1885 Font aFont = toFont( pConfig->readFontEntry( pKey ), rSettings.GetUILocale() );
1886 aStyleSettings.SetTitleFont( aFont );
1887 bSetTitleFont = true;
1890 pConfig->setGroup( "Icons" );
1892 pKey = "Theme";
1893 if ( pConfig->hasKey( pKey ) )
1894 aStyleSettings.SetPreferredSymbolsStyleName( readEntryUntranslated( pConfig, pKey ) );
1897 // General settings
1898 QColorGroup qColorGroup = kapp->palette().active();
1900 Color aFore = toColor( qColorGroup.foreground() );
1901 Color aBack = toColor( qColorGroup.background() );
1902 Color aText = toColor( qColorGroup.text() );
1903 Color aBase = toColor( qColorGroup.base() );
1905 // Foreground
1906 aStyleSettings.SetRadioCheckTextColor( aFore );
1907 aStyleSettings.SetLabelTextColor( aFore );
1908 aStyleSettings.SetInfoTextColor( aFore );
1909 aStyleSettings.SetDialogTextColor( aFore );
1910 aStyleSettings.SetGroupTextColor( aFore );
1912 // Text
1913 aStyleSettings.SetFieldTextColor( aText );
1914 aStyleSettings.SetFieldRolloverTextColor( aText );
1915 aStyleSettings.SetWindowTextColor( aText );
1916 aStyleSettings.SetHelpTextColor( aText );
1918 // Base
1919 aStyleSettings.SetFieldColor( aBase );
1920 aStyleSettings.SetHelpColor( aBase );
1921 aStyleSettings.SetWindowColor( aBase );
1922 aStyleSettings.SetActiveTabColor( aBase );
1924 // Buttons
1925 aStyleSettings.SetButtonTextColor( toColor( qColorGroup.buttonText() ) );
1926 aStyleSettings.SetButtonRolloverTextColor( toColor( qColorGroup.buttonText() ) );
1928 // Disable color
1929 aStyleSettings.SetDisableColor( toColor( qColorGroup.mid() ) );
1931 // Workspace
1932 aStyleSettings.SetWorkspaceColor( toColor( qColorGroup.mid() ) );
1934 // Background
1935 aStyleSettings.Set3DColors( aBack );
1936 aStyleSettings.SetFaceColor( aBack );
1937 aStyleSettings.SetInactiveTabColor( aBack );
1938 aStyleSettings.SetDialogColor( aBack );
1939 if( aBack == COL_LIGHTGRAY )
1940 aStyleSettings.SetCheckedColor( Color( 0xCC, 0xCC, 0xCC ) );
1941 else
1943 Color aColor2 = aStyleSettings.GetLightColor();
1944 aStyleSettings.
1945 SetCheckedColor( Color( (BYTE)(((USHORT)aBack.GetRed()+(USHORT)aColor2.GetRed())/2),
1946 (BYTE)(((USHORT)aBack.GetGreen()+(USHORT)aColor2.GetGreen())/2),
1947 (BYTE)(((USHORT)aBack.GetBlue()+(USHORT)aColor2.GetBlue())/2)
1948 ) );
1951 // Selection
1952 aStyleSettings.SetHighlightColor( toColor( qColorGroup.highlight() ) );
1953 aStyleSettings.SetHighlightTextColor( toColor( qColorGroup.highlightedText() ) );
1955 // Font
1956 Font aFont = toFont( kapp->font(), rSettings.GetUILocale() );
1958 aStyleSettings.SetAppFont( aFont );
1959 aStyleSettings.SetHelpFont( aFont );
1960 if( !bSetTitleFont )
1961 aStyleSettings.SetTitleFont( aFont );
1962 aStyleSettings.SetFloatTitleFont( aFont );
1963 aStyleSettings.SetMenuFont( aFont ); // will be changed according to pMenuBar
1964 aStyleSettings.SetToolFont( aFont ); // will be changed according to pToolBar
1965 aStyleSettings.SetLabelFont( aFont );
1966 aStyleSettings.SetInfoFont( aFont );
1967 aStyleSettings.SetRadioCheckFont( aFont );
1968 aStyleSettings.SetPushButtonFont( aFont );
1969 aStyleSettings.SetFieldFont( aFont );
1970 aStyleSettings.SetIconFont( aFont );
1971 aStyleSettings.SetGroupFont( aFont );
1972 int flash_time = QApplication::cursorFlashTime();
1973 aStyleSettings.SetCursorBlinkTime( flash_time != 0 ? flash_time/2 : STYLE_CURSOR_NOBLINKTIME );
1975 KMainWindow qMainWindow;
1976 qMainWindow.createGUI( "/dev/null" ); // hack
1978 // Menu
1979 aStyleSettings.SetSkipDisabledInMenus( TRUE );
1980 KMenuBar *pMenuBar = qMainWindow.menuBar();
1981 if ( pMenuBar )
1983 // Color
1984 QColorGroup qMenuCG = pMenuBar->colorGroup();
1986 // Menu text and background color, theme specific
1987 Color aMenuFore = toColor( qMenuCG.foreground() );
1988 Color aMenuBack = toColor( qMenuCG.background() );
1989 if ( kapp->style().inherits( "LightStyleV2" ) ||
1990 kapp->style().inherits( "LightStyleV3" ) ||
1991 ( kapp->style().inherits( "QMotifStyle" ) && !kapp->style().inherits( "QSGIStyle" ) ) ||
1992 kapp->style().inherits( "QWindowsStyle" ) )
1994 aMenuFore = toColor( qMenuCG.buttonText() );
1995 aMenuBack = toColor( qMenuCG.button() );
1998 aStyleSettings.SetMenuTextColor( aMenuFore );
1999 aStyleSettings.SetMenuBarTextColor( aMenuFore );
2000 aStyleSettings.SetMenuColor( aMenuBack );
2001 aStyleSettings.SetMenuBarColor( aMenuBack );
2003 aStyleSettings.SetMenuHighlightColor( toColor ( qMenuCG.highlight() ) );
2005 // Menu items higlight text color, theme specific
2006 if ( kapp->style().inherits( "HighContrastStyle" ) ||
2007 kapp->style().inherits( "KeramikStyle" ) ||
2008 kapp->style().inherits( "QWindowsStyle" ) ||
2009 kapp->style().inherits( "ThinKeramikStyle" ) ||
2010 kapp->style().inherits( "PlastikStyle" ) )
2012 aStyleSettings.SetMenuHighlightTextColor( toColor ( qMenuCG.highlightedText() ) );
2014 else
2015 aStyleSettings.SetMenuHighlightTextColor( aMenuFore );
2017 // set special menubar higlight text color
2018 if ( kapp->style().inherits( "HighContrastStyle" ) )
2019 ImplGetSVData()->maNWFData.maMenuBarHighlightTextColor = toColor( qMenuCG.highlightedText() );
2020 else
2021 ImplGetSVData()->maNWFData.maMenuBarHighlightTextColor = aMenuFore;
2023 // Font
2024 aFont = toFont( pMenuBar->font(), rSettings.GetUILocale() );
2025 aStyleSettings.SetMenuFont( aFont );
2028 // Tool bar
2029 KToolBar *pToolBar = qMainWindow.toolBar();
2030 if ( pToolBar )
2032 aFont = toFont( pToolBar->font(), rSettings.GetUILocale() );
2033 aStyleSettings.SetToolFont( aFont );
2036 // Scroll bar size
2037 aStyleSettings.SetScrollBarSize( kapp->style().pixelMetric( QStyle::PM_ScrollBarExtent ) );
2039 rSettings.SetStyleSettings( aStyleSettings );
2042 SalGraphics* KDESalFrame::GetGraphics()
2044 if( GetWindow() )
2046 for( int i = 0; i < nMaxGraphics; i++ )
2048 if( ! m_aGraphics[i].bInUse )
2050 m_aGraphics[i].bInUse = true;
2051 if( ! m_aGraphics[i].pGraphics )
2053 m_aGraphics[i].pGraphics = new KDESalGraphics();
2054 m_aGraphics[i].pGraphics->Init( this, GetWindow(), GetScreenNumber() );
2056 return m_aGraphics[i].pGraphics;
2061 return NULL;
2064 void KDESalFrame::ReleaseGraphics( SalGraphics *pGraphics )
2066 for( int i = 0; i < nMaxGraphics; i++ )
2068 if( m_aGraphics[i].pGraphics == pGraphics )
2070 m_aGraphics[i].bInUse = false;
2071 break;
2076 void KDESalFrame::updateGraphics()
2078 for( int i = 0; i < nMaxGraphics; i++ )
2080 if( m_aGraphics[i].bInUse )
2081 m_aGraphics[i].pGraphics->SetDrawable( GetWindow(), GetScreenNumber() );
2085 KDESalFrame::~KDESalFrame()
2089 KDESalFrame::GraphicsHolder::~GraphicsHolder()
2091 delete pGraphics;
2094 // -----------------------------------------------------------------------
2095 // KDESalInstance implementation
2096 // -----------------------------------------------------------------------
2098 SalFrame *
2099 KDESalInstance::CreateFrame( SalFrame *pParent, ULONG nStyle )
2101 return new KDESalFrame( pParent, nStyle );
2104 // -----------------------------------------------------------------------
2105 // KDESalData pieces
2106 // -----------------------------------------------------------------------
2108 // Create the widget painter so we have some control over
2109 // the destruction sequence, so Qt doesn't die in action.
2111 void KDEData::initNWF()
2113 ImplSVData *pSVData = ImplGetSVData();
2114 // draw toolbars on separate lines
2115 pSVData->maNWFData.mbDockingAreaSeparateTB = true;
2117 pWidgetPainter = new WidgetPainter();
2120 void KDEData::deInitNWF()
2122 delete pWidgetPainter;
2123 pWidgetPainter = NULL;
2125 // We have to destroy the style early
2126 kapp->setStyle( NULL );