19f62ea84SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
39f62ea84SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
49f62ea84SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
59f62ea84SAndrew Rist  * distributed with this work for additional information
69f62ea84SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
79f62ea84SAndrew Rist  * to you under the Apache License, Version 2.0 (the
89f62ea84SAndrew Rist  * "License"); you may not use this file except in compliance
99f62ea84SAndrew Rist  * with the License.  You may obtain a copy of the License at
109f62ea84SAndrew Rist  *
119f62ea84SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
129f62ea84SAndrew Rist  *
139f62ea84SAndrew Rist  * Unless required by applicable law or agreed to in writing,
149f62ea84SAndrew Rist  * software distributed under the License is distributed on an
159f62ea84SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
169f62ea84SAndrew Rist  * KIND, either express or implied.  See the License for the
179f62ea84SAndrew Rist  * specific language governing permissions and limitations
189f62ea84SAndrew Rist  * under the License.
199f62ea84SAndrew Rist  *
209f62ea84SAndrew Rist  *************************************************************/
219f62ea84SAndrew Rist 
229f62ea84SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_vcl.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #define _SV_SALNATIVEWIDGETS_KDE_CXX
28cdf0e10cSrcweir #include <shell/kde_headers.h>
29cdf0e10cSrcweir 
30cdf0e10cSrcweir #include <unx/salunx.h>
31cdf0e10cSrcweir #include <unx/saldata.hxx>
32cdf0e10cSrcweir #include <unx/saldisp.hxx>
33cdf0e10cSrcweir #include <unx/salgdi.h>
34cdf0e10cSrcweir #include <unx/pspgraphics.h>
35cdf0e10cSrcweir #include <unx/kde/kdedata.hxx>
36cdf0e10cSrcweir 
37cdf0e10cSrcweir #include <vcl/settings.hxx>
38cdf0e10cSrcweir #include <rtl/ustrbuf.hxx>
39cdf0e10cSrcweir 
40cdf0e10cSrcweir 
41cdf0e10cSrcweir using namespace ::rtl;
42cdf0e10cSrcweir 
43cdf0e10cSrcweir /** Cached native widgets.
44cdf0e10cSrcweir 
45cdf0e10cSrcweir     A class which caches and paints the native widgets.
46cdf0e10cSrcweir */
47cdf0e10cSrcweir class WidgetPainter
48cdf0e10cSrcweir {
49cdf0e10cSrcweir     protected:
50cdf0e10cSrcweir 	/** Cached push button.
51cdf0e10cSrcweir 
52cdf0e10cSrcweir 	    It is necessary for the QStyle::drawControl(). The buttons are created
53cdf0e10cSrcweir 	    on demand and they are still hidden (no QWidget::show() is called).
54cdf0e10cSrcweir 	*/
55cdf0e10cSrcweir 	QPushButton  *m_pPushButton;
56cdf0e10cSrcweir 
57cdf0e10cSrcweir 	/** Cached radio button.
58cdf0e10cSrcweir 
59cdf0e10cSrcweir 	    @see m_pPushButton
60cdf0e10cSrcweir 	*/
61cdf0e10cSrcweir 	QRadioButton *m_pRadioButton;
62cdf0e10cSrcweir 
63cdf0e10cSrcweir 	/** Cached check box.
64cdf0e10cSrcweir 
65cdf0e10cSrcweir 	    @see m_pPushButton
66cdf0e10cSrcweir 	*/
67cdf0e10cSrcweir 	QCheckBox    *m_pCheckBox;
68cdf0e10cSrcweir 
69cdf0e10cSrcweir 	/** Cached combo box.
70cdf0e10cSrcweir 
71cdf0e10cSrcweir 	    @see m_pPushButton
72cdf0e10cSrcweir 	*/
73cdf0e10cSrcweir 	QComboBox    *m_pComboBox;
74cdf0e10cSrcweir 
75cdf0e10cSrcweir 	/** Cached editable combo box.
76cdf0e10cSrcweir 
77cdf0e10cSrcweir 	    Needed, because some styles do not like dynamic changes
78cdf0e10cSrcweir 	    (QComboBox::setEditable()).
79cdf0e10cSrcweir 
80cdf0e10cSrcweir 	    @see m_pPushButton
81cdf0e10cSrcweir 	*/
82cdf0e10cSrcweir 	QComboBox    *m_pEditableComboBox;
83cdf0e10cSrcweir 
84cdf0e10cSrcweir 	/** Cached line edit box.
85cdf0e10cSrcweir 
86cdf0e10cSrcweir 	    @see m_pPushButton
87cdf0e10cSrcweir 	*/
88cdf0e10cSrcweir 	QLineEdit    *m_pLineEdit;
89cdf0e10cSrcweir 
90cdf0e10cSrcweir 	/** Cached spin box.
91cdf0e10cSrcweir 
92cdf0e10cSrcweir 	    @see m_pPushButton
93cdf0e10cSrcweir 	*/
94cdf0e10cSrcweir 	QSpinWidget  *m_pSpinWidget;
95cdf0e10cSrcweir 
96cdf0e10cSrcweir 	/** Cached spin box'es line edit.
97cdf0e10cSrcweir 
98cdf0e10cSrcweir 	    @see m_pPushButton
99cdf0e10cSrcweir 	*/
100cdf0e10cSrcweir 	QLineEdit    *m_pSpinEdit;
101cdf0e10cSrcweir 
102cdf0e10cSrcweir 	/** Cached tab.
103cdf0e10cSrcweir 
104cdf0e10cSrcweir 	    Left, middle, right tab and a tab which is alone.
105cdf0e10cSrcweir 
106cdf0e10cSrcweir 	    @see m_pPushButton
107cdf0e10cSrcweir 	*/
108cdf0e10cSrcweir 	QTab         *m_pTabLeft, *m_pTabMiddle, *m_pTabRight, *m_pTabAlone;
109cdf0e10cSrcweir 
110cdf0e10cSrcweir 	/** Cached tab bar's parent widget.
111cdf0e10cSrcweir 
112cdf0e10cSrcweir 	    Needed, because the Qt windows style checks for the availability
113cdf0e10cSrcweir 	    of tab bar's parent. We cannot use m_pTabWidget, because
114cdf0e10cSrcweir 	    TabWidget::setTabBar() and TabWidget::tabBar() methods are
115cdf0e10cSrcweir 	    protected.
116cdf0e10cSrcweir 
117cdf0e10cSrcweir 	    @see m_pPushButton, m_pTabWidget
118cdf0e10cSrcweir 	*/
119cdf0e10cSrcweir 	QWidget      *m_pTabBarParent;
120cdf0e10cSrcweir 
121cdf0e10cSrcweir 	/** Cached tab bar widget.
122cdf0e10cSrcweir 
123cdf0e10cSrcweir 	    @see m_pPushButton
124cdf0e10cSrcweir 	*/
125cdf0e10cSrcweir 	QTabBar      *m_pTabBar;
126cdf0e10cSrcweir 
127cdf0e10cSrcweir 	/** Cached tab widget.
128cdf0e10cSrcweir 
129cdf0e10cSrcweir 	    We need it to draw the tab page. It cannot be used to draw the
130cdf0e10cSrcweir 	    tabs themselves, because the drawing has to be tweaked a little
131cdf0e10cSrcweir 	    due to not enough information from VCL.
132cdf0e10cSrcweir 
133cdf0e10cSrcweir 	    @see m_pPushButton, m_pTabBarParent
134cdf0e10cSrcweir 	*/
135cdf0e10cSrcweir 	QTabWidget   *m_pTabWidget;
136cdf0e10cSrcweir 
137cdf0e10cSrcweir 	/** Cached list view.
138cdf0e10cSrcweir 
139cdf0e10cSrcweir 	    @see m_pPushButton
140cdf0e10cSrcweir 	*/
141cdf0e10cSrcweir 	QListView    *m_pListView;
142cdf0e10cSrcweir 
143cdf0e10cSrcweir 	/** Cached scroll bar.
144cdf0e10cSrcweir 
145cdf0e10cSrcweir 	    @see m_pPushButton
146cdf0e10cSrcweir 	*/
147cdf0e10cSrcweir 	QScrollBar   *m_pScrollBar;
148cdf0e10cSrcweir 
149cdf0e10cSrcweir     /** Cached dock area. Needed for proper functionality of tool bars.
150cdf0e10cSrcweir 
151cdf0e10cSrcweir       @see m_pPushButton
152cdf0e10cSrcweir       */
153cdf0e10cSrcweir     QMainWindow  *m_pMainWindow;
154cdf0e10cSrcweir 
155cdf0e10cSrcweir     /** Cached tool bar.
156cdf0e10cSrcweir 
157cdf0e10cSrcweir       @see m_pPushButton
158cdf0e10cSrcweir     */
159cdf0e10cSrcweir     QToolBar     *m_pToolBarHoriz, *m_pToolBarVert;
160cdf0e10cSrcweir 
161cdf0e10cSrcweir     /** Cached tool button.
162cdf0e10cSrcweir 
163cdf0e10cSrcweir       @see m_pPushButton
164cdf0e10cSrcweir     */
165cdf0e10cSrcweir     QToolButton  *m_pToolButton;
166cdf0e10cSrcweir 
167cdf0e10cSrcweir     /** Cached menu bar.
168cdf0e10cSrcweir 
169cdf0e10cSrcweir       @see m_pPushButton
170cdf0e10cSrcweir     */
171cdf0e10cSrcweir     QMenuBar     *m_pMenuBar;
172cdf0e10cSrcweir 
173cdf0e10cSrcweir     /** Identifiers of menu bar items.
174cdf0e10cSrcweir      */
175cdf0e10cSrcweir     int           m_nMenuBarEnabledItem, m_nMenuBarDisabledItem;
176cdf0e10cSrcweir 
177cdf0e10cSrcweir     /** Cached popup menu.
178cdf0e10cSrcweir 
179cdf0e10cSrcweir       @see m_pPushButton
180cdf0e10cSrcweir     */
181cdf0e10cSrcweir     QPopupMenu   *m_pPopupMenu;
182cdf0e10cSrcweir 
183cdf0e10cSrcweir     /** Identifiers of popup menu items.
184cdf0e10cSrcweir      */
185cdf0e10cSrcweir     int           m_nPopupMenuEnabledItem, m_nPopupMenuDisabledItem;
186cdf0e10cSrcweir 
187cdf0e10cSrcweir     /** cached progress bar
188cdf0e10cSrcweir       */
189cdf0e10cSrcweir     QProgressBar *m_pProgressBar;
190cdf0e10cSrcweir 
191cdf0e10cSrcweir 	// TODO other widgets
192cdf0e10cSrcweir 
193cdf0e10cSrcweir     public:
194cdf0e10cSrcweir 	/** Implicit constructor.
195cdf0e10cSrcweir 
196cdf0e10cSrcweir 	    It creates an empty WidgetPainter with all the cached widgets initialized
197cdf0e10cSrcweir 	    to NULL. The widgets are created on demand and they are still hidden
198cdf0e10cSrcweir 	    (no QWidget::show()), because they are needed just as a parameter for
199cdf0e10cSrcweir 	    QStyle::drawControl().
200cdf0e10cSrcweir 
201cdf0e10cSrcweir 	    @see m_pPushButton
202cdf0e10cSrcweir 	*/
203cdf0e10cSrcweir 	WidgetPainter( void );
204cdf0e10cSrcweir 
205cdf0e10cSrcweir 	/** Destructor.
206cdf0e10cSrcweir 
207cdf0e10cSrcweir 	    Destruct all the cached widgets.
208cdf0e10cSrcweir 	*/
209cdf0e10cSrcweir 	virtual ~WidgetPainter( void );
210cdf0e10cSrcweir 
211cdf0e10cSrcweir 	/** Paints the specified widget to the X window.
212cdf0e10cSrcweir 
213cdf0e10cSrcweir 	    Use X calls to bitblt (bit block transfer) the widget qWidget to
214cdf0e10cSrcweir 	    the window specified by drawable with the style defined by nStyle.
215cdf0e10cSrcweir 
216cdf0e10cSrcweir 	    @param qWidget
217cdf0e10cSrcweir 	    A pointer to the cached widget.
218cdf0e10cSrcweir 
219cdf0e10cSrcweir 	    @param nState
220cdf0e10cSrcweir 	    The state of the control (focused, on/off, ...)
221cdf0e10cSrcweir 
222cdf0e10cSrcweir 	    @param aValue
223cdf0e10cSrcweir 	    The value (true/false, ...)
224cdf0e10cSrcweir 
225cdf0e10cSrcweir 	    @param dpy
226cdf0e10cSrcweir 	    The display to be used by the X calls.
227cdf0e10cSrcweir 
228cdf0e10cSrcweir 	    @param drawable
229cdf0e10cSrcweir 	    The destination X window.
230cdf0e10cSrcweir 
231cdf0e10cSrcweir 	    @param gc
232cdf0e10cSrcweir 	    The graphics context.
233cdf0e10cSrcweir 	*/
234cdf0e10cSrcweir         sal_Bool drawStyledWidget( QWidget *pWidget,
235cdf0e10cSrcweir                 ControlState nState, const ImplControlValue& aValue,
236cdf0e10cSrcweir                 Display *dpy, XLIB_Window drawable, int nScreen, int nDepth, GC gc,
237cdf0e10cSrcweir                 ControlPart nPart = PART_ENTIRE_CONTROL );
238cdf0e10cSrcweir 
239cdf0e10cSrcweir 	/** 'Get' method for push button.
240cdf0e10cSrcweir 
241cdf0e10cSrcweir 	    The method returns the cached push button. It is constructed if it
242cdf0e10cSrcweir 	    does not exist. It has NULL as a parent and it stays hidden, but it
243cdf0e10cSrcweir 	    is necessary for the drawStyledWidget() method.
244cdf0e10cSrcweir 
245cdf0e10cSrcweir 	    @return valid push button.
246cdf0e10cSrcweir 	*/
247cdf0e10cSrcweir 	QPushButton  *pushButton( const Rectangle& rControlRegion, sal_Bool bDefault );
248cdf0e10cSrcweir 
249cdf0e10cSrcweir 	/** 'Get' method for radio button.
250cdf0e10cSrcweir 
251cdf0e10cSrcweir 	    @see pushButton()
252cdf0e10cSrcweir 	*/
253cdf0e10cSrcweir 	QRadioButton *radioButton( const Rectangle& rControlRegion );
254cdf0e10cSrcweir 
255cdf0e10cSrcweir 	/** 'Get' method for check box.
256cdf0e10cSrcweir 
257cdf0e10cSrcweir 	    @see pushButton()
258cdf0e10cSrcweir 	*/
259cdf0e10cSrcweir 	QCheckBox    *checkBox( const Rectangle& rControlRegion );
260cdf0e10cSrcweir 
261cdf0e10cSrcweir 	/** 'Get' method for combo box.
262cdf0e10cSrcweir 
263cdf0e10cSrcweir 	    It returns m_pComboBox or m_pEditableComboBox according to
264cdf0e10cSrcweir 	    bEditable.
265cdf0e10cSrcweir 
266cdf0e10cSrcweir 	    @see pushButton(), m_pEditableComboBox
267cdf0e10cSrcweir 	*/
268cdf0e10cSrcweir 	QComboBox    *comboBox( const Rectangle& rControlRegion, sal_Bool bEditable );
269cdf0e10cSrcweir 
270cdf0e10cSrcweir 	/** 'Get' method for line edit box.
271cdf0e10cSrcweir 
272cdf0e10cSrcweir 	    @see pushButton()
273cdf0e10cSrcweir 	*/
274cdf0e10cSrcweir 	QLineEdit    *lineEdit( const Rectangle& rControlRegion );
275cdf0e10cSrcweir 
276cdf0e10cSrcweir 	/** 'Get' method for spin box.
277cdf0e10cSrcweir 
278cdf0e10cSrcweir 	    @see pushButton()
279cdf0e10cSrcweir 	*/
280cdf0e10cSrcweir 	QSpinWidget  *spinWidget( const Rectangle& rControlRegion );
281cdf0e10cSrcweir 
282cdf0e10cSrcweir 	/** 'Get' method for tab bar.
283cdf0e10cSrcweir 
284cdf0e10cSrcweir 	    @see pushButton()
285cdf0e10cSrcweir 	*/
286cdf0e10cSrcweir 	QTabBar      *tabBar( const Rectangle& rControlRegion );
287cdf0e10cSrcweir 
288cdf0e10cSrcweir 	/** 'Get' method for tab widget.
289cdf0e10cSrcweir 
290cdf0e10cSrcweir 	    @see pushButton()
291cdf0e10cSrcweir 	*/
292cdf0e10cSrcweir 	QTabWidget   *tabWidget( const Rectangle& rControlRegion );
293cdf0e10cSrcweir 
294cdf0e10cSrcweir 	/** 'Get' method for list view.
295cdf0e10cSrcweir 
296cdf0e10cSrcweir 	    @see pushButton()
297cdf0e10cSrcweir 	*/
298cdf0e10cSrcweir 	QListView    *listView( const Rectangle& rControlRegion );
299cdf0e10cSrcweir 
300cdf0e10cSrcweir 	/** 'Get' method for scroll bar.
301cdf0e10cSrcweir 
302cdf0e10cSrcweir 	    @see pushButton()
303cdf0e10cSrcweir 	*/
304cdf0e10cSrcweir 	QScrollBar   *scrollBar( const Rectangle& rControlRegion,
305cdf0e10cSrcweir 		sal_Bool bHorizontal, const ImplControlValue& aValue );
306cdf0e10cSrcweir 
307cdf0e10cSrcweir     /** 'Get' method for tool bar.
308cdf0e10cSrcweir 
309cdf0e10cSrcweir       @see pushButton()
310cdf0e10cSrcweir     */
311cdf0e10cSrcweir     QToolBar     *toolBar( const Rectangle& rControlRegion, sal_Bool bHorizontal );
312cdf0e10cSrcweir 
313cdf0e10cSrcweir     /** 'Get' method for tool button.
314cdf0e10cSrcweir 
315cdf0e10cSrcweir       @see pushButton()
316cdf0e10cSrcweir     */
317cdf0e10cSrcweir     QToolButton  *toolButton( const Rectangle& rControlRegion );
318cdf0e10cSrcweir 
319cdf0e10cSrcweir     /** 'Get' method for menu bar.
320cdf0e10cSrcweir 
321cdf0e10cSrcweir       @see pushButton()
322cdf0e10cSrcweir     */
323cdf0e10cSrcweir     QMenuBar     *menuBar( const Rectangle& rControlRegion );
324cdf0e10cSrcweir 
325cdf0e10cSrcweir     /** 'Get' method for popup menu.
326cdf0e10cSrcweir 
327cdf0e10cSrcweir       @see pushButton()
328cdf0e10cSrcweir     */
329cdf0e10cSrcweir     QPopupMenu   *popupMenu( const Rectangle& rControlRegion );
330cdf0e10cSrcweir 
331cdf0e10cSrcweir     /** 'Get' method for progress bar
332cdf0e10cSrcweir 
333cdf0e10cSrcweir       @see pushButton()
334cdf0e10cSrcweir     */
335cdf0e10cSrcweir     QProgressBar *progressBar( const Rectangle& rControlRegion );
336cdf0e10cSrcweir 
337cdf0e10cSrcweir 	// TODO other widgets
338cdf0e10cSrcweir 
339cdf0e10cSrcweir     protected:
340cdf0e10cSrcweir 	/** Style conversion function.
341cdf0e10cSrcweir 
342cdf0e10cSrcweir 	    Conversion function between VCL ControlState together with
343cdf0e10cSrcweir 	    ImplControlValue and Qt state flags.
344cdf0e10cSrcweir 
345cdf0e10cSrcweir 	    @param nState
346cdf0e10cSrcweir 	    State of the widget (default, focused, ...) as defined in Native
347cdf0e10cSrcweir 	    Widget Framework.
348cdf0e10cSrcweir 
349cdf0e10cSrcweir 	    @param aValue
350cdf0e10cSrcweir 	    Value held by the widget (on, off, ...)
351cdf0e10cSrcweir 	*/
352cdf0e10cSrcweir 	QStyle::SFlags vclStateValue2SFlags( ControlState nState, const ImplControlValue& aValue );
353cdf0e10cSrcweir 
354cdf0e10cSrcweir     public:
355cdf0e10cSrcweir 	/** Convert VCL Rectangle to QRect.
356cdf0e10cSrcweir 
357cdf0e10cSrcweir 	    @param rControlRegion
358cdf0e10cSrcweir 	    The region to convert.
359cdf0e10cSrcweir 
360cdf0e10cSrcweir 	    @return
361cdf0e10cSrcweir 	    The bounding box of the region.
362cdf0e10cSrcweir 	*/
363cdf0e10cSrcweir 	static QRect region2QRect( const Rectangle& rControlRegion );
364cdf0e10cSrcweir };
365cdf0e10cSrcweir 
WidgetPainter(void)366cdf0e10cSrcweir WidgetPainter::WidgetPainter( void )
367cdf0e10cSrcweir     : m_pPushButton( NULL ),
368cdf0e10cSrcweir       m_pRadioButton( NULL ),
369cdf0e10cSrcweir       m_pCheckBox( NULL ),
370cdf0e10cSrcweir       m_pComboBox( NULL ),
371cdf0e10cSrcweir       m_pEditableComboBox( NULL ),
372cdf0e10cSrcweir       m_pLineEdit( NULL ),
373cdf0e10cSrcweir       m_pSpinWidget( NULL ),
374cdf0e10cSrcweir       m_pSpinEdit( NULL ),
375cdf0e10cSrcweir       m_pTabLeft( NULL ),
376cdf0e10cSrcweir       m_pTabMiddle( NULL ),
377cdf0e10cSrcweir       m_pTabRight( NULL ),
378cdf0e10cSrcweir       m_pTabAlone( NULL ),
379cdf0e10cSrcweir       m_pTabBarParent( NULL ),
380cdf0e10cSrcweir       m_pTabBar( NULL ),
381cdf0e10cSrcweir       m_pTabWidget( NULL ),
382cdf0e10cSrcweir       m_pListView( NULL ),
383cdf0e10cSrcweir       m_pScrollBar( NULL ),
384cdf0e10cSrcweir       m_pMainWindow( NULL ),
385cdf0e10cSrcweir       m_pToolBarHoriz( NULL ),
386cdf0e10cSrcweir       m_pToolBarVert( NULL ),
387cdf0e10cSrcweir       m_pToolButton( NULL ),
388cdf0e10cSrcweir       m_pMenuBar( NULL ),
389cdf0e10cSrcweir       m_pPopupMenu( NULL ),
390cdf0e10cSrcweir       m_pProgressBar( NULL )
391cdf0e10cSrcweir {
392cdf0e10cSrcweir }
393cdf0e10cSrcweir 
~WidgetPainter(void)394cdf0e10cSrcweir WidgetPainter::~WidgetPainter( void )
395cdf0e10cSrcweir {
396cdf0e10cSrcweir     delete m_pPushButton, m_pPushButton = NULL;
397cdf0e10cSrcweir     delete m_pRadioButton, m_pRadioButton = NULL;
398cdf0e10cSrcweir     delete m_pCheckBox, m_pCheckBox = NULL;
399cdf0e10cSrcweir     delete m_pComboBox, m_pComboBox = NULL;
400cdf0e10cSrcweir     delete m_pEditableComboBox, m_pEditableComboBox = NULL;
401cdf0e10cSrcweir     delete m_pLineEdit, m_pLineEdit = NULL;
402cdf0e10cSrcweir     delete m_pSpinWidget, m_pSpinWidget = NULL;
403cdf0e10cSrcweir     m_pSpinEdit = NULL; // Deleted in m_pSpinWidget's destructor
404cdf0e10cSrcweir     delete m_pTabAlone, m_pTabAlone = NULL;
405cdf0e10cSrcweir     delete m_pTabBarParent, m_pTabBarParent = NULL;
406cdf0e10cSrcweir     m_pTabBar = NULL;    // Deleted in m_pTabBarParent's destructor
407cdf0e10cSrcweir     m_pTabLeft = NULL;
408cdf0e10cSrcweir     m_pTabMiddle = NULL;
409cdf0e10cSrcweir     m_pTabRight = NULL;
410cdf0e10cSrcweir     delete m_pTabWidget, m_pTabWidget = NULL;
411cdf0e10cSrcweir     delete m_pListView, m_pListView = NULL;
412cdf0e10cSrcweir     delete m_pScrollBar, m_pScrollBar = NULL;
413cdf0e10cSrcweir     delete m_pToolBarHoriz, m_pToolBarHoriz = NULL;
414cdf0e10cSrcweir     delete m_pToolBarVert, m_pToolBarVert = NULL;
415cdf0e10cSrcweir     delete m_pMainWindow, m_pMainWindow = NULL;
416cdf0e10cSrcweir     delete m_pToolButton, m_pToolButton = NULL;
417cdf0e10cSrcweir     delete m_pMenuBar, m_pMenuBar = NULL;
418cdf0e10cSrcweir     delete m_pPopupMenu, m_pPopupMenu = NULL;
419cdf0e10cSrcweir     delete m_pProgressBar, m_pProgressBar = NULL;
420cdf0e10cSrcweir }
421cdf0e10cSrcweir 
drawStyledWidget(QWidget * pWidget,ControlState nState,const ImplControlValue & aValue,Display * dpy,XLIB_Window drawable,int nScreen,int nDepth,GC gc,ControlPart nPart)422cdf0e10cSrcweir sal_Bool WidgetPainter::drawStyledWidget( QWidget *pWidget,
423cdf0e10cSrcweir 	ControlState nState, const ImplControlValue& aValue,
424cdf0e10cSrcweir         Display *dpy, XLIB_Window drawable, int nScreen, int nDepth, GC gc,
425cdf0e10cSrcweir         ControlPart nPart )
426cdf0e10cSrcweir {
427cdf0e10cSrcweir     if ( !pWidget )
428cdf0e10cSrcweir 	return sal_False;
429cdf0e10cSrcweir 
430cdf0e10cSrcweir     // Normalize the widget
431cdf0e10cSrcweir     QPoint   qWidgetPos( pWidget->pos() );
432cdf0e10cSrcweir     pWidget->move( 0, 0 );
433cdf0e10cSrcweir 
434cdf0e10cSrcweir     // Enable/disable the widget
435cdf0e10cSrcweir     pWidget->setEnabled( nState & CTRL_STATE_ENABLED );
436cdf0e10cSrcweir 
437cdf0e10cSrcweir     // Create pixmap to paint to
438cdf0e10cSrcweir     QPixmap  qPixmap( pWidget->width(), pWidget->height() );
439cdf0e10cSrcweir     QPainter qPainter( &qPixmap );
440cdf0e10cSrcweir     QRect    qRect( 0, 0, pWidget->width(), pWidget->height() );
441cdf0e10cSrcweir 
442cdf0e10cSrcweir     // Use the background of the widget
443cdf0e10cSrcweir     qPixmap.fill( pWidget, QPoint(0, 0) );
444cdf0e10cSrcweir 
445cdf0e10cSrcweir     // Convert the flags
446cdf0e10cSrcweir     QStyle::SFlags nStyle = vclStateValue2SFlags( nState, aValue );
447cdf0e10cSrcweir 
448cdf0e10cSrcweir     // Store the widget class
449cdf0e10cSrcweir     const char *pClassName = pWidget->className();
450cdf0e10cSrcweir 
451cdf0e10cSrcweir     // Draw the widget to the pixmap
452cdf0e10cSrcweir     if ( strcmp( "QPushButton", pClassName ) == 0 )
453cdf0e10cSrcweir     {
454cdf0e10cSrcweir 	// Workaround for the Platinum style.
455cdf0e10cSrcweir 	// Platinum takes the state directly from the widget, not from SFlags.
456cdf0e10cSrcweir 	QPushButton *pPushButton = static_cast<QPushButton *>( pWidget->qt_cast( "QPushButton" ) );
457cdf0e10cSrcweir 	if ( pPushButton )
458cdf0e10cSrcweir 	{
459cdf0e10cSrcweir 	    pPushButton->setDown   ( nStyle & QStyle::Style_Down );
460cdf0e10cSrcweir 	    pPushButton->setOn     ( nStyle & QStyle::Style_On );
461cdf0e10cSrcweir 	    pPushButton->setEnabled( nStyle & QStyle::Style_Enabled );
462cdf0e10cSrcweir 	}
463cdf0e10cSrcweir 
464cdf0e10cSrcweir 	kapp->style().drawControl( QStyle::CE_PushButton,
465cdf0e10cSrcweir 		&qPainter, pWidget, qRect,
466cdf0e10cSrcweir 		pWidget->colorGroup(), nStyle );
467cdf0e10cSrcweir     }
468cdf0e10cSrcweir     else if ( strcmp( "QRadioButton", pClassName ) == 0 )
469cdf0e10cSrcweir     {
470cdf0e10cSrcweir 	// Bitblt from the screen, because the radio buttons are usually not
471cdf0e10cSrcweir 	// rectangular, and there could be a bitmap under them
472cdf0e10cSrcweir 	GC aTmpGC = XCreateGC( dpy, qPixmap.handle(), 0, NULL );
473cdf0e10cSrcweir     X11SalGraphics::CopyScreenArea( dpy,
474cdf0e10cSrcweir                               drawable, nScreen, nDepth,
475cdf0e10cSrcweir                               qPixmap.handle(), qPixmap.x11Screen(), qPixmap.x11Depth(),
476cdf0e10cSrcweir                               aTmpGC,
477cdf0e10cSrcweir                               qWidgetPos.x(), qWidgetPos.y(), qRect.width(), qRect.height(),
478cdf0e10cSrcweir                               0, 0 );
479cdf0e10cSrcweir 	XFreeGC( dpy, aTmpGC );
480cdf0e10cSrcweir 
481cdf0e10cSrcweir 	kapp->style().drawControl( QStyle::CE_RadioButton,
482cdf0e10cSrcweir 		&qPainter, pWidget, qRect,
483cdf0e10cSrcweir 		pWidget->colorGroup(), nStyle );
484cdf0e10cSrcweir     }
485cdf0e10cSrcweir     else if ( strcmp( "QCheckBox", pClassName ) == 0 )
486cdf0e10cSrcweir     {
487cdf0e10cSrcweir 	kapp->style().drawControl( QStyle::CE_CheckBox,
488cdf0e10cSrcweir 		&qPainter, pWidget, qRect,
489cdf0e10cSrcweir 		pWidget->colorGroup(), nStyle );
490cdf0e10cSrcweir     }
491cdf0e10cSrcweir     else if ( strcmp( "QComboBox", pClassName ) == 0 )
492cdf0e10cSrcweir     {
493cdf0e10cSrcweir 	kapp->style().drawComplexControl( QStyle::CC_ComboBox,
494cdf0e10cSrcweir 		&qPainter, pWidget, qRect,
495cdf0e10cSrcweir 		pWidget->colorGroup(), nStyle );
496cdf0e10cSrcweir 
497cdf0e10cSrcweir 	// Editable combo box uses the background of the associated edit box
498cdf0e10cSrcweir 	QComboBox *pComboBox = static_cast<QComboBox *>( pWidget->qt_cast( "QComboBox" ) );
499cdf0e10cSrcweir 	if ( pComboBox && pComboBox->editable() && pComboBox->lineEdit() )
500cdf0e10cSrcweir 	{
501cdf0e10cSrcweir 	    QColorGroup::ColorRole eColorRole = ( pComboBox->isEnabled() )?
502cdf0e10cSrcweir 		QColorGroup::Base: QColorGroup::Background;
503cdf0e10cSrcweir 	    qPainter.fillRect(
504cdf0e10cSrcweir 		    kapp->style().querySubControlMetrics( QStyle::CC_ComboBox,
505cdf0e10cSrcweir 			pComboBox, QStyle::SC_ComboBoxEditField ),
506cdf0e10cSrcweir 		    pComboBox->lineEdit()->colorGroup().brush( eColorRole ) );
507cdf0e10cSrcweir 	}
508cdf0e10cSrcweir     }
509cdf0e10cSrcweir     else if ( strcmp( "QLineEdit", pClassName ) == 0 )
510cdf0e10cSrcweir     {
511cdf0e10cSrcweir 	kapp->style().drawPrimitive( QStyle::PE_PanelLineEdit,
512cdf0e10cSrcweir 		&qPainter, qRect,
513cdf0e10cSrcweir 		pWidget->colorGroup(), nStyle | QStyle::Style_Sunken );
514cdf0e10cSrcweir     }
515cdf0e10cSrcweir     else if ( strcmp( "QSpinWidget", pClassName ) == 0 )
516cdf0e10cSrcweir     {
5173460f9c8SHerbert Dürr 	const SpinbuttonValue* pValue = (aValue.getType() == CTRL_SPINBUTTONS) ? static_cast<const SpinbuttonValue*>(&aValue) : NULL;
518cdf0e10cSrcweir 
519cdf0e10cSrcweir 	// Is any of the buttons pressed?
520cdf0e10cSrcweir 	QStyle::SCFlags eActive = QStyle::SC_None;
521cdf0e10cSrcweir 	if ( pValue )
522cdf0e10cSrcweir 	{
523cdf0e10cSrcweir 	    if ( pValue->mnUpperState & CTRL_STATE_PRESSED )
524cdf0e10cSrcweir 		eActive = QStyle::SC_SpinWidgetUp;
525cdf0e10cSrcweir 	    else if ( pValue->mnLowerState & CTRL_STATE_PRESSED )
526cdf0e10cSrcweir 		eActive = QStyle::SC_SpinWidgetDown;
527cdf0e10cSrcweir 
528cdf0e10cSrcweir 	    // Update the enable/disable state of the widget
529cdf0e10cSrcweir 	    if ( ( nState & CTRL_STATE_ENABLED ) ||
530cdf0e10cSrcweir 		    ( pValue->mnUpperState & CTRL_STATE_ENABLED ) ||
531cdf0e10cSrcweir 		    ( pValue->mnLowerState & CTRL_STATE_ENABLED ) )
532cdf0e10cSrcweir 	    {
533cdf0e10cSrcweir 		pWidget->setEnabled( true );
534cdf0e10cSrcweir 		nStyle |= QStyle::Style_Enabled;
535cdf0e10cSrcweir 	    }
536cdf0e10cSrcweir 	    else
537cdf0e10cSrcweir 		pWidget->setEnabled( false );
538cdf0e10cSrcweir 
539cdf0e10cSrcweir 	    // Mouse-over effect
540cdf0e10cSrcweir 	    if ( (pValue->mnUpperState & CTRL_STATE_ROLLOVER) ||
541cdf0e10cSrcweir 		    (pValue->mnLowerState & CTRL_STATE_ROLLOVER) )
542cdf0e10cSrcweir 		nStyle |= QStyle::Style_MouseOver;
543cdf0e10cSrcweir 	}
544cdf0e10cSrcweir 
545cdf0e10cSrcweir 	// Spin widget uses the background of the associated edit box
546cdf0e10cSrcweir 	QSpinWidget *pSpinWidget = static_cast<QSpinWidget *>( pWidget->qt_cast( "QSpinWidget" ) );
547cdf0e10cSrcweir 	if ( pSpinWidget && pSpinWidget->editWidget() )
548cdf0e10cSrcweir 	{
549cdf0e10cSrcweir 	    QColorGroup::ColorRole eColorRole = ( pSpinWidget->isEnabled() )?
550cdf0e10cSrcweir 		QColorGroup::Base: QColorGroup::Background;
551cdf0e10cSrcweir 	    qPainter.fillRect(
552cdf0e10cSrcweir 		    kapp->style().querySubControlMetrics( QStyle::CC_SpinWidget,
553cdf0e10cSrcweir 			pSpinWidget, QStyle::SC_SpinWidgetEditField ),
554cdf0e10cSrcweir 		    pSpinWidget->editWidget()->colorGroup().brush( eColorRole ) );
555cdf0e10cSrcweir 	}
556cdf0e10cSrcweir 
557cdf0e10cSrcweir 	// Adjust the frame (needed for Motif Plus style)
558cdf0e10cSrcweir 	QRect qFrameRect = kapp->style().querySubControlMetrics( QStyle::CC_SpinWidget,
559cdf0e10cSrcweir 		pWidget, QStyle::SC_SpinWidgetFrame );
560cdf0e10cSrcweir 
561cdf0e10cSrcweir 	kapp->style().drawComplexControl( QStyle::CC_SpinWidget,
562cdf0e10cSrcweir 		&qPainter, pWidget, qFrameRect,
563cdf0e10cSrcweir 		pWidget->colorGroup(), nStyle,
564cdf0e10cSrcweir 		QStyle::SC_All, eActive );
565cdf0e10cSrcweir     }
566cdf0e10cSrcweir     else if ( strcmp( "QTabBar", pClassName ) == 0 )
567cdf0e10cSrcweir     {
568cdf0e10cSrcweir 	const TabitemValue *pValue = static_cast<const TabitemValue *> ( &aValue );
569cdf0e10cSrcweir 
570cdf0e10cSrcweir 	QTab *pTab = NULL;
571cdf0e10cSrcweir 	if ( pValue )
572cdf0e10cSrcweir 	{
573cdf0e10cSrcweir 	    if ( ( pValue->isFirst() || pValue->isLeftAligned() ) && ( pValue->isLast() || pValue->isRightAligned() ) )
574cdf0e10cSrcweir 		pTab = m_pTabAlone;
575cdf0e10cSrcweir 	    else if ( pValue->isFirst() || pValue->isLeftAligned() )
576cdf0e10cSrcweir 		pTab = m_pTabLeft;
577cdf0e10cSrcweir 	    else if ( pValue->isLast() || pValue->isRightAligned() )
578cdf0e10cSrcweir 		pTab = m_pTabRight;
579cdf0e10cSrcweir 	    else
580cdf0e10cSrcweir 		pTab = m_pTabMiddle;
581cdf0e10cSrcweir 	}
582cdf0e10cSrcweir 	if ( !pTab )
583cdf0e10cSrcweir 	    return sal_False;
584cdf0e10cSrcweir 
585cdf0e10cSrcweir 	pTab->setRect( qRect );
586cdf0e10cSrcweir 
587cdf0e10cSrcweir 	kapp->style().drawControl( QStyle::CE_TabBarTab,
588cdf0e10cSrcweir 		&qPainter, pWidget, qRect,
589cdf0e10cSrcweir 		pWidget->colorGroup(), nStyle,
590cdf0e10cSrcweir 		QStyleOption( pTab ) );
591cdf0e10cSrcweir     }
592cdf0e10cSrcweir     else if ( strcmp( "QTabWidget", pClassName ) == 0 )
593cdf0e10cSrcweir     {
594cdf0e10cSrcweir 	kapp->style().drawPrimitive( QStyle::PE_PanelTabWidget,
595cdf0e10cSrcweir 		&qPainter, qRect,
596cdf0e10cSrcweir 		pWidget->colorGroup(), nStyle );
597cdf0e10cSrcweir     }
598cdf0e10cSrcweir     else if ( strcmp( "QListView", pClassName ) == 0 )
599cdf0e10cSrcweir     {
600cdf0e10cSrcweir 	kapp->style().drawPrimitive( QStyle::PE_Panel,
601cdf0e10cSrcweir 		&qPainter, qRect,
602cdf0e10cSrcweir 		pWidget->colorGroup(), nStyle | QStyle::Style_Sunken );
603cdf0e10cSrcweir     }
604cdf0e10cSrcweir     else if ( strcmp( "QScrollBar", pClassName ) == 0 )
605cdf0e10cSrcweir     {
6063460f9c8SHerbert Dürr 	const ScrollbarValue* pScrollbarVal = (aValue.getType() == CTRL_SCROLLBAR) ? static_cast<const ScrollbarValue*>(&aValue) : NULL;
607cdf0e10cSrcweir 
608cdf0e10cSrcweir 	QStyle::SCFlags eActive = QStyle::SC_None;
609cdf0e10cSrcweir 	if ( pValue )
610cdf0e10cSrcweir 	{
611cdf0e10cSrcweir 	    // Workaround for Style_MouseOver-aware themes.
612cdf0e10cSrcweir 	    // Quite ugly, but I do not know about a better solution.
613cdf0e10cSrcweir 	    const char *pStyleName = kapp->style().className();
614cdf0e10cSrcweir 	    if ( strcmp( "QMotifPlusStyle", pStyleName ) == 0 )
615cdf0e10cSrcweir 	    {
616cdf0e10cSrcweir 		nStyle |= QStyle::Style_MouseOver;
617cdf0e10cSrcweir 		if ( pValue->mnThumbState & CTRL_STATE_ROLLOVER )
618cdf0e10cSrcweir 		    eActive = QStyle::SC_ScrollBarSlider;
619cdf0e10cSrcweir 	    }
620cdf0e10cSrcweir 	    else if ( strcmp( "QSGIStyle", pStyleName ) == 0 )
621cdf0e10cSrcweir 	    {
622cdf0e10cSrcweir 		nStyle |= QStyle::Style_MouseOver;
623cdf0e10cSrcweir 		if ( pValue->mnButton1State & CTRL_STATE_ROLLOVER )
624cdf0e10cSrcweir 		    eActive = QStyle::SC_ScrollBarSubLine;
625cdf0e10cSrcweir 		else if ( pValue->mnButton2State & CTRL_STATE_ROLLOVER )
626cdf0e10cSrcweir 		    eActive = QStyle::SC_ScrollBarAddLine;
627cdf0e10cSrcweir 		else if ( pValue->mnThumbState & CTRL_STATE_ROLLOVER )
628cdf0e10cSrcweir 		    eActive = QStyle::SC_ScrollBarSlider;
629cdf0e10cSrcweir 	    }
630cdf0e10cSrcweir 
631cdf0e10cSrcweir 	    if ( pValue->mnButton1State & CTRL_STATE_PRESSED )
632cdf0e10cSrcweir 		eActive = QStyle::SC_ScrollBarSubLine;
633cdf0e10cSrcweir 	    else if ( pValue->mnButton2State & CTRL_STATE_PRESSED )
634cdf0e10cSrcweir 		eActive = QStyle::SC_ScrollBarAddLine;
635cdf0e10cSrcweir 	    else if ( pValue->mnThumbState & CTRL_STATE_PRESSED )
636cdf0e10cSrcweir 		eActive = QStyle::SC_ScrollBarSlider;
637cdf0e10cSrcweir 	    else if ( pValue->mnPage1State & CTRL_STATE_PRESSED )
638cdf0e10cSrcweir 		eActive = QStyle::SC_ScrollBarSubPage;
639cdf0e10cSrcweir 	    else if ( pValue->mnPage2State & CTRL_STATE_PRESSED )
640cdf0e10cSrcweir 		eActive = QStyle::SC_ScrollBarAddPage;
641cdf0e10cSrcweir 
642cdf0e10cSrcweir 	    // Update the enable/disable state of the widget
643cdf0e10cSrcweir 	    if ( ( nState & CTRL_STATE_ENABLED ) ||
644cdf0e10cSrcweir 		    ( pValue->mnButton1State & CTRL_STATE_ENABLED ) ||
645cdf0e10cSrcweir 		    ( pValue->mnButton2State & CTRL_STATE_ENABLED ) ||
646cdf0e10cSrcweir 		    ( pValue->mnThumbState & CTRL_STATE_ENABLED ) ||
647cdf0e10cSrcweir 		    ( pValue->mnPage1State & CTRL_STATE_ENABLED ) ||
648cdf0e10cSrcweir 		    ( pValue->mnPage2State & CTRL_STATE_ENABLED ) )
649cdf0e10cSrcweir 	    {
650cdf0e10cSrcweir 		pWidget->setEnabled( true );
651cdf0e10cSrcweir 		nStyle |= QStyle::Style_Enabled;
652cdf0e10cSrcweir 	    }
653cdf0e10cSrcweir 	    else
654cdf0e10cSrcweir 		pWidget->setEnabled( false );
655cdf0e10cSrcweir 	}
656cdf0e10cSrcweir 
657cdf0e10cSrcweir 	// Is it a horizontal scroll bar?
658cdf0e10cSrcweir 	QScrollBar *pScrollBar = static_cast<QScrollBar *> ( pWidget->qt_cast( "QScrollBar" ) );
659cdf0e10cSrcweir 	QStyle::StyleFlags eHoriz = QStyle::Style_Default;
660cdf0e10cSrcweir 	if ( pScrollBar && pScrollBar->orientation() == Qt::Horizontal )
661cdf0e10cSrcweir 	    eHoriz = QStyle::Style_Horizontal;
662cdf0e10cSrcweir 
663cdf0e10cSrcweir 	kapp->style().drawComplexControl( QStyle::CC_ScrollBar,
664cdf0e10cSrcweir 		&qPainter, pWidget, qRect,
665cdf0e10cSrcweir 		pWidget->colorGroup(), nStyle | eHoriz,
666cdf0e10cSrcweir 		QStyle::SC_All, eActive );
667cdf0e10cSrcweir     }
668cdf0e10cSrcweir     else if ( strcmp( "QToolBar", pClassName ) == 0 )
669cdf0e10cSrcweir     {
670cdf0e10cSrcweir         QToolBar *pToolBar = static_cast< QToolBar * >( pWidget->qt_cast( "QToolBar" ) );
671cdf0e10cSrcweir         bool bIsHorizontal = false;
672cdf0e10cSrcweir         if ( pToolBar && pToolBar->orientation() == Qt::Horizontal )
673cdf0e10cSrcweir         {
674cdf0e10cSrcweir             nStyle |= QStyle::Style_Horizontal;
675cdf0e10cSrcweir             bIsHorizontal = true;
676cdf0e10cSrcweir         }
677cdf0e10cSrcweir 
678cdf0e10cSrcweir         kapp->style().drawControl( QStyle::CE_DockWindowEmptyArea,
679cdf0e10cSrcweir                 &qPainter, pWidget, qRect,
680cdf0e10cSrcweir                 pWidget->colorGroup(), nStyle );
681cdf0e10cSrcweir 
682cdf0e10cSrcweir         kapp->style().drawPrimitive( QStyle::PE_PanelDockWindow,
683cdf0e10cSrcweir                 &qPainter, qRect, pWidget->colorGroup(), nStyle );
684cdf0e10cSrcweir 
685cdf0e10cSrcweir         if ( nPart == PART_THUMB_HORZ || nPart == PART_THUMB_VERT )
686cdf0e10cSrcweir         {
687cdf0e10cSrcweir             const ToolbarValue *pValue = static_cast< const ToolbarValue * >( &aValue );
688cdf0e10cSrcweir 
689cdf0e10cSrcweir             QRect qThumbRect = region2QRect( pValue->maGripRect );
690cdf0e10cSrcweir             qThumbRect.moveBy( -qWidgetPos.x(), -qWidgetPos.y() );
691cdf0e10cSrcweir             if ( bIsHorizontal )
692cdf0e10cSrcweir                 qThumbRect.addCoords( 0, 2, 0, -3 );    // make the thumb a bit nicer
693cdf0e10cSrcweir             else
694cdf0e10cSrcweir                 qThumbRect.addCoords( 2, 0, -3, 0 );    // make the thumb a bit nicer
695cdf0e10cSrcweir 
696cdf0e10cSrcweir             if ( kapp->style().inherits( "HighColorStyle" ) ||
697cdf0e10cSrcweir                  kapp->style().inherits( "HighContrastStyle" ) ||
698cdf0e10cSrcweir                  kapp->style().inherits( "KeramikStyle" ) ||
699cdf0e10cSrcweir                  kapp->style().inherits( "KThemeStyle" ) ||
700cdf0e10cSrcweir                  kapp->style().inherits( "ThinKeramikStyle" ) )
701cdf0e10cSrcweir             {
702cdf0e10cSrcweir                 // Workaround for the workaround in KStyle::drawPrimitive()
703cdf0e10cSrcweir                 KStyle *pStyle = static_cast< KStyle * >( &kapp->style() );
704cdf0e10cSrcweir                 pStyle->drawKStylePrimitive( KStyle::KPE_ToolBarHandle,
705cdf0e10cSrcweir                         &qPainter, pToolBar, qThumbRect,
706cdf0e10cSrcweir                         pWidget->colorGroup(), nStyle );
707cdf0e10cSrcweir             }
708cdf0e10cSrcweir             else
709cdf0e10cSrcweir                 kapp->style().drawPrimitive( QStyle::PE_DockWindowHandle,
710cdf0e10cSrcweir                         &qPainter, qThumbRect, pWidget->colorGroup(), nStyle );
711cdf0e10cSrcweir         }
712cdf0e10cSrcweir     }
713cdf0e10cSrcweir     else if ( strcmp( "QToolButton", pClassName ) == 0 )
714cdf0e10cSrcweir     {
715cdf0e10cSrcweir         if( (nStyle & QStyle::Style_MouseOver) )
716cdf0e10cSrcweir             nStyle &= ~QStyle::Style_Off;
717cdf0e10cSrcweir         kapp->style().drawComplexControl( QStyle::CC_ToolButton,
718cdf0e10cSrcweir                 &qPainter, pWidget, qRect,
719cdf0e10cSrcweir                 pWidget->colorGroup(), nStyle,
720cdf0e10cSrcweir                 QStyle::SC_ToolButton );
721cdf0e10cSrcweir     }
722cdf0e10cSrcweir     else if ( strcmp( "QMenuBar", pClassName ) == 0 )
723cdf0e10cSrcweir     {
724cdf0e10cSrcweir         if ( nPart == PART_ENTIRE_CONTROL )
725cdf0e10cSrcweir         {
726cdf0e10cSrcweir             kapp->style().drawControl( QStyle::CE_MenuBarEmptyArea,
727cdf0e10cSrcweir                     &qPainter, pWidget, qRect,
728cdf0e10cSrcweir                     pWidget->colorGroup(), nStyle );
729cdf0e10cSrcweir         }
730cdf0e10cSrcweir         else if ( nPart == PART_MENU_ITEM )
731cdf0e10cSrcweir         {
732cdf0e10cSrcweir             int nMenuItem = ( nStyle & QStyle::Style_Enabled )? m_nMenuBarEnabledItem: m_nMenuBarDisabledItem;
733cdf0e10cSrcweir             QMenuItem *pMenuItem = static_cast<QMenuBar*>( pWidget )->findItem( nMenuItem );
734cdf0e10cSrcweir 
735cdf0e10cSrcweir             if ( nStyle & QStyle::Style_Selected )
736cdf0e10cSrcweir                 nStyle |= QStyle::Style_Active | QStyle::Style_Down | QStyle::Style_HasFocus;
737cdf0e10cSrcweir 
738cdf0e10cSrcweir             kapp->style().drawControl( QStyle::CE_MenuBarItem,
739cdf0e10cSrcweir                     &qPainter, pWidget, qRect,
740cdf0e10cSrcweir                     pWidget->colorGroup(), nStyle,
741cdf0e10cSrcweir                     QStyleOption( pMenuItem ) );
742cdf0e10cSrcweir         }
743cdf0e10cSrcweir     }
744cdf0e10cSrcweir     else if ( strcmp( "QPopupMenu", pClassName ) == 0 )
745cdf0e10cSrcweir     {
746cdf0e10cSrcweir         int nMenuItem = ( nStyle & QStyle::Style_Enabled )? m_nPopupMenuEnabledItem: m_nPopupMenuDisabledItem;
747cdf0e10cSrcweir         QMenuItem *pMenuItem = static_cast<QPopupMenu*>( pWidget )->findItem( nMenuItem );
748cdf0e10cSrcweir 
749cdf0e10cSrcweir         if ( nStyle & QStyle::Style_Selected )
750cdf0e10cSrcweir             nStyle |= QStyle::Style_Active;
751cdf0e10cSrcweir 
752cdf0e10cSrcweir         kapp->style().drawControl( QStyle::CE_PopupMenuItem,
753cdf0e10cSrcweir                 &qPainter, pWidget, qRect,
754cdf0e10cSrcweir                 pWidget->colorGroup(), nStyle,
755cdf0e10cSrcweir                 QStyleOption( pMenuItem, 0, 0 ) );
756cdf0e10cSrcweir     }
757cdf0e10cSrcweir     else if ( strcmp( "QProgressBar", pClassName ) == 0 )
758cdf0e10cSrcweir     {
759cdf0e10cSrcweir         long nProgressWidth = aValue.getNumericVal();
760cdf0e10cSrcweir         QProgressBar* pProgress = static_cast<QProgressBar*>(pWidget);
761cdf0e10cSrcweir         pProgress->setProgress( nProgressWidth, qRect.width() );
762cdf0e10cSrcweir 
763cdf0e10cSrcweir         kapp->style().drawControl( QStyle::CE_ProgressBarGroove,
764cdf0e10cSrcweir             &qPainter, pWidget, qRect,
765cdf0e10cSrcweir             pWidget->colorGroup(), nStyle );
766cdf0e10cSrcweir         kapp->style().drawControl( QStyle::CE_ProgressBarContents,
767cdf0e10cSrcweir             &qPainter, pWidget, qRect,
768cdf0e10cSrcweir             pWidget->colorGroup(), nStyle );
769cdf0e10cSrcweir     }
770cdf0e10cSrcweir     else
771cdf0e10cSrcweir 	return sal_False;
772cdf0e10cSrcweir 
773cdf0e10cSrcweir     // Bitblt it to the screen
774cdf0e10cSrcweir     X11SalGraphics::CopyScreenArea( dpy,
775cdf0e10cSrcweir 	                          qPixmap.handle(), qPixmap.x11Screen(), qPixmap.x11Depth(),
776cdf0e10cSrcweir                               drawable, nScreen, nDepth,
777cdf0e10cSrcweir                               gc,
778cdf0e10cSrcweir                               0, 0, qRect.width(), qRect.height(),
779cdf0e10cSrcweir                               qWidgetPos.x(), qWidgetPos.y() );
780cdf0e10cSrcweir 
781cdf0e10cSrcweir     // Restore widget's position
782cdf0e10cSrcweir     pWidget->move( qWidgetPos );
783cdf0e10cSrcweir 
784cdf0e10cSrcweir     return sal_True;
785cdf0e10cSrcweir }
786cdf0e10cSrcweir 
pushButton(const Rectangle & rControlRegion,sal_Bool bDefault)787cdf0e10cSrcweir QPushButton *WidgetPainter::pushButton( const Rectangle& rControlRegion,
788cdf0e10cSrcweir 	sal_Bool bDefault )
789cdf0e10cSrcweir {
790cdf0e10cSrcweir     if ( !m_pPushButton )
791cdf0e10cSrcweir 	m_pPushButton = new QPushButton( NULL, "push_button" );
792cdf0e10cSrcweir 
793cdf0e10cSrcweir     QRect qRect = region2QRect( rControlRegion );
794cdf0e10cSrcweir 
795cdf0e10cSrcweir     // Workaround for broken styles which do not add
796cdf0e10cSrcweir     // QStyle::PM_ButtonDefaultIndicator to the size of the default button
797cdf0e10cSrcweir     // (for example Keramik)
798*86e1cf34SPedro Giffuni     // FIXME Fix Keramik style to be consistent with Qt built-in styles. Aargh!
799cdf0e10cSrcweir     if ( bDefault )
800cdf0e10cSrcweir     {
801cdf0e10cSrcweir 	QSize qContentsSize( 50, 50 );
802cdf0e10cSrcweir 	m_pPushButton->setDefault( false );
803cdf0e10cSrcweir 	QSize qNormalSize = kapp->style().sizeFromContents( QStyle::CT_PushButton,
804cdf0e10cSrcweir 		m_pPushButton, qContentsSize );
805cdf0e10cSrcweir 	m_pPushButton->setDefault( true );
806cdf0e10cSrcweir 	QSize qDefSize = kapp->style().sizeFromContents( QStyle::CT_PushButton,
807cdf0e10cSrcweir 		m_pPushButton, qContentsSize );
808cdf0e10cSrcweir 
809cdf0e10cSrcweir 	int nIndicatorSize = kapp->style().pixelMetric(
810cdf0e10cSrcweir 		QStyle::PM_ButtonDefaultIndicator, m_pPushButton );
811cdf0e10cSrcweir 	if ( qNormalSize.width() == qDefSize.width() )
812cdf0e10cSrcweir 	    qRect.addCoords( nIndicatorSize, 0, -nIndicatorSize, 0 );
813cdf0e10cSrcweir 	if ( qNormalSize.height() == qDefSize.height() )
814cdf0e10cSrcweir 	    qRect.addCoords( 0, nIndicatorSize, 0, -nIndicatorSize );
815cdf0e10cSrcweir     }
816cdf0e10cSrcweir 
817cdf0e10cSrcweir     m_pPushButton->move( qRect.topLeft() );
818cdf0e10cSrcweir     m_pPushButton->resize( qRect.size() );
819cdf0e10cSrcweir     m_pPushButton->setDefault( bDefault );
820cdf0e10cSrcweir 
821cdf0e10cSrcweir     return m_pPushButton;
822cdf0e10cSrcweir }
823cdf0e10cSrcweir 
radioButton(const Rectangle & rControlRegion)824cdf0e10cSrcweir QRadioButton *WidgetPainter::radioButton( const Rectangle& rControlRegion )
825cdf0e10cSrcweir {
826cdf0e10cSrcweir     if ( !m_pRadioButton )
827cdf0e10cSrcweir 	m_pRadioButton = new QRadioButton( NULL, "radio_button" );
828cdf0e10cSrcweir 
829cdf0e10cSrcweir     QRect qRect = region2QRect( rControlRegion );
830cdf0e10cSrcweir 
831cdf0e10cSrcweir     // Workaround for broken themes which do not honor the given size.
832cdf0e10cSrcweir     // Quite ugly, but I do not know about a better solution.
833cdf0e10cSrcweir     const char *pStyleName = kapp->style().className();
834cdf0e10cSrcweir     if ( strcmp( "KThemeStyle", pStyleName ) == 0 )
835cdf0e10cSrcweir     {
836cdf0e10cSrcweir 	QRect qOldRect( qRect );
837cdf0e10cSrcweir 
838cdf0e10cSrcweir 	qRect.setWidth( kapp->style().pixelMetric(
839cdf0e10cSrcweir 		QStyle::PM_ExclusiveIndicatorWidth, m_pRadioButton ) );
840cdf0e10cSrcweir 	qRect.setHeight( kapp->style().pixelMetric(
841cdf0e10cSrcweir 		QStyle::PM_ExclusiveIndicatorHeight, m_pRadioButton ) );
842cdf0e10cSrcweir 
843cdf0e10cSrcweir 	qRect.moveBy( ( qOldRect.width() - qRect.width() ) / 2,
844cdf0e10cSrcweir 		( qOldRect.height() - qRect.height() ) / 2 );
845cdf0e10cSrcweir     }
846cdf0e10cSrcweir 
847cdf0e10cSrcweir     m_pRadioButton->move( qRect.topLeft() );
848cdf0e10cSrcweir     m_pRadioButton->resize( qRect.size() );
849cdf0e10cSrcweir 
850cdf0e10cSrcweir     return m_pRadioButton;
851cdf0e10cSrcweir }
852cdf0e10cSrcweir 
checkBox(const Rectangle & rControlRegion)853cdf0e10cSrcweir QCheckBox *WidgetPainter::checkBox( const Rectangle& rControlRegion )
854cdf0e10cSrcweir {
855cdf0e10cSrcweir     if ( !m_pCheckBox )
856cdf0e10cSrcweir 	m_pCheckBox = new QCheckBox( NULL, "check_box" );
857cdf0e10cSrcweir 
858cdf0e10cSrcweir     QRect qRect = region2QRect( rControlRegion );
859cdf0e10cSrcweir 
860cdf0e10cSrcweir     // Workaround for broken themes which do not honor the given size.
861cdf0e10cSrcweir     // Quite ugly, but I do not know about a better solution.
862cdf0e10cSrcweir     const char *pStyleName = kapp->style().className();
863cdf0e10cSrcweir     if ( strcmp( "KThemeStyle", pStyleName ) == 0 )
864cdf0e10cSrcweir     {
865cdf0e10cSrcweir 	QRect qOldRect( qRect );
866cdf0e10cSrcweir 
867cdf0e10cSrcweir 	qRect.setWidth( kapp->style().pixelMetric(
868cdf0e10cSrcweir 		QStyle::PM_IndicatorWidth, m_pCheckBox ) );
869cdf0e10cSrcweir 	qRect.setHeight( kapp->style().pixelMetric(
870cdf0e10cSrcweir 		QStyle::PM_IndicatorHeight, m_pCheckBox ) );
871cdf0e10cSrcweir 
872cdf0e10cSrcweir 	qRect.moveBy( ( qOldRect.width() - qRect.width() ) / 2,
873cdf0e10cSrcweir 		( qOldRect.height() - qRect.height() ) / 2 );
874cdf0e10cSrcweir     }
875cdf0e10cSrcweir 
876cdf0e10cSrcweir     m_pCheckBox->move( qRect.topLeft() );
877cdf0e10cSrcweir     m_pCheckBox->resize( qRect.size() );
878cdf0e10cSrcweir 
879cdf0e10cSrcweir     return m_pCheckBox;
880cdf0e10cSrcweir }
881cdf0e10cSrcweir 
comboBox(const Rectangle & rControlRegion,sal_Bool bEditable)882cdf0e10cSrcweir QComboBox *WidgetPainter::comboBox( const Rectangle& rControlRegion,
883cdf0e10cSrcweir 	sal_Bool bEditable )
884cdf0e10cSrcweir {
885cdf0e10cSrcweir     QComboBox *pComboBox = NULL;
886cdf0e10cSrcweir     if ( bEditable )
887cdf0e10cSrcweir     {
888cdf0e10cSrcweir 	if ( !m_pEditableComboBox )
889cdf0e10cSrcweir 	    m_pEditableComboBox = new QComboBox( true, NULL, "combo_box_edit" );
890cdf0e10cSrcweir 	pComboBox = m_pEditableComboBox;
891cdf0e10cSrcweir     }
892cdf0e10cSrcweir     else
893cdf0e10cSrcweir     {
894cdf0e10cSrcweir 	if ( !m_pComboBox )
895cdf0e10cSrcweir 	    m_pComboBox = new QComboBox( false, NULL, "combo_box" );
896cdf0e10cSrcweir 	pComboBox = m_pComboBox;
897cdf0e10cSrcweir     }
898cdf0e10cSrcweir 
899cdf0e10cSrcweir     QRect qRect = region2QRect( rControlRegion );
900cdf0e10cSrcweir 
901cdf0e10cSrcweir     pComboBox->move( qRect.topLeft() );
902cdf0e10cSrcweir     pComboBox->resize( qRect.size() );
903cdf0e10cSrcweir 
904cdf0e10cSrcweir     return pComboBox;
905cdf0e10cSrcweir }
906cdf0e10cSrcweir 
lineEdit(const Rectangle & rControlRegion)907cdf0e10cSrcweir QLineEdit *WidgetPainter::lineEdit( const Rectangle& rControlRegion )
908cdf0e10cSrcweir {
909cdf0e10cSrcweir     if ( !m_pLineEdit )
910cdf0e10cSrcweir 	m_pLineEdit = new QLineEdit( NULL, "line_edit" );
911cdf0e10cSrcweir 
912cdf0e10cSrcweir     QRect qRect = region2QRect( rControlRegion );
913cdf0e10cSrcweir 
914cdf0e10cSrcweir     m_pLineEdit->move( qRect.topLeft() );
915cdf0e10cSrcweir     m_pLineEdit->resize( qRect.size() );
916cdf0e10cSrcweir 
917cdf0e10cSrcweir     return m_pLineEdit;
918cdf0e10cSrcweir }
919cdf0e10cSrcweir 
spinWidget(const Rectangle & rControlRegion)920cdf0e10cSrcweir QSpinWidget *WidgetPainter::spinWidget( const Rectangle& rControlRegion )
921cdf0e10cSrcweir {
922cdf0e10cSrcweir     if ( !m_pSpinWidget )
923cdf0e10cSrcweir     {
924cdf0e10cSrcweir 	m_pSpinWidget = new QSpinWidget( NULL, "spin_widget" );
925cdf0e10cSrcweir 
926cdf0e10cSrcweir 	m_pSpinEdit = new QLineEdit( NULL, "line_edit_spin" );
927cdf0e10cSrcweir 	m_pSpinWidget->setEditWidget( m_pSpinEdit );
928cdf0e10cSrcweir     }
929cdf0e10cSrcweir 
930cdf0e10cSrcweir     QRect qRect = region2QRect( rControlRegion );
931cdf0e10cSrcweir 
932cdf0e10cSrcweir     m_pSpinWidget->move( qRect.topLeft() );
933cdf0e10cSrcweir     m_pSpinWidget->resize( qRect.size() );
934cdf0e10cSrcweir     m_pSpinWidget->arrange();
935cdf0e10cSrcweir 
936cdf0e10cSrcweir     return m_pSpinWidget;
937cdf0e10cSrcweir }
938cdf0e10cSrcweir 
tabBar(const Rectangle & rControlRegion)939cdf0e10cSrcweir QTabBar *WidgetPainter::tabBar( const Rectangle& rControlRegion )
940cdf0e10cSrcweir {
941cdf0e10cSrcweir     if ( !m_pTabBar )
942cdf0e10cSrcweir     {
943cdf0e10cSrcweir 	if ( !m_pTabBarParent )
944cdf0e10cSrcweir 	    m_pTabBarParent = new QWidget( NULL, "tab_bar_parent" );
945cdf0e10cSrcweir 
946cdf0e10cSrcweir 	m_pTabBar = new QTabBar( m_pTabBarParent, "tab_bar" );
947cdf0e10cSrcweir 
948cdf0e10cSrcweir 	m_pTabLeft = new QTab();
949cdf0e10cSrcweir 	m_pTabMiddle = new QTab();
950cdf0e10cSrcweir 	m_pTabRight = new QTab();
951cdf0e10cSrcweir 	m_pTabAlone = new QTab();
952cdf0e10cSrcweir 
953cdf0e10cSrcweir 	m_pTabBar->addTab( m_pTabLeft );
954cdf0e10cSrcweir 	m_pTabBar->addTab( m_pTabMiddle );
955cdf0e10cSrcweir 	m_pTabBar->addTab( m_pTabRight );
956cdf0e10cSrcweir     }
957cdf0e10cSrcweir 
958cdf0e10cSrcweir     QRect qRect = region2QRect( rControlRegion );
959cdf0e10cSrcweir 
960cdf0e10cSrcweir     m_pTabBar->move( qRect.topLeft() );
961cdf0e10cSrcweir     m_pTabBar->resize( qRect.size() );
962cdf0e10cSrcweir 
963cdf0e10cSrcweir     m_pTabBar->setShape( QTabBar::RoundedAbove );
964cdf0e10cSrcweir 
965cdf0e10cSrcweir     return m_pTabBar;
966cdf0e10cSrcweir }
967cdf0e10cSrcweir 
tabWidget(const Rectangle & rControlRegion)968cdf0e10cSrcweir QTabWidget *WidgetPainter::tabWidget( const Rectangle& rControlRegion )
969cdf0e10cSrcweir {
970cdf0e10cSrcweir     if ( !m_pTabWidget )
971cdf0e10cSrcweir 	m_pTabWidget = new QTabWidget( NULL, "tab_widget" );
972cdf0e10cSrcweir 
973cdf0e10cSrcweir     QRect qRect = region2QRect( rControlRegion );
974cdf0e10cSrcweir     --qRect.rTop();
975cdf0e10cSrcweir 
976cdf0e10cSrcweir     m_pTabWidget->move( qRect.topLeft() );
977cdf0e10cSrcweir     m_pTabWidget->resize( qRect.size() );
978cdf0e10cSrcweir 
979cdf0e10cSrcweir     return m_pTabWidget;
980cdf0e10cSrcweir }
981cdf0e10cSrcweir 
listView(const Rectangle & rControlRegion)982cdf0e10cSrcweir QListView *WidgetPainter::listView( const Rectangle& rControlRegion )
983cdf0e10cSrcweir {
984cdf0e10cSrcweir     if ( !m_pListView )
985cdf0e10cSrcweir 	m_pListView = new QListView( NULL, "list_view" );
986cdf0e10cSrcweir 
987cdf0e10cSrcweir     QRect qRect = region2QRect( rControlRegion );
988cdf0e10cSrcweir 
989cdf0e10cSrcweir     m_pListView->move( qRect.topLeft() );
990cdf0e10cSrcweir     m_pListView->resize( qRect.size() );
991cdf0e10cSrcweir 
992cdf0e10cSrcweir     return m_pListView;
993cdf0e10cSrcweir }
994cdf0e10cSrcweir 
scrollBar(const Rectangle & rControlRegion,sal_Bool bHorizontal,const ImplControlValue & aValue)995cdf0e10cSrcweir QScrollBar *WidgetPainter::scrollBar( const Rectangle& rControlRegion,
996cdf0e10cSrcweir 	sal_Bool bHorizontal, const ImplControlValue& aValue )
997cdf0e10cSrcweir {
998cdf0e10cSrcweir     if ( !m_pScrollBar )
999cdf0e10cSrcweir     {
1000cdf0e10cSrcweir 	m_pScrollBar = new QScrollBar( NULL, "scroll_bar" );
1001cdf0e10cSrcweir 	m_pScrollBar->setTracking( false );
1002cdf0e10cSrcweir 	m_pScrollBar->setLineStep( 1 );
1003cdf0e10cSrcweir     }
1004cdf0e10cSrcweir 
1005cdf0e10cSrcweir     QRect qRect = region2QRect( rControlRegion );
1006cdf0e10cSrcweir 
1007cdf0e10cSrcweir     m_pScrollBar->move( qRect.topLeft() );
1008cdf0e10cSrcweir     m_pScrollBar->resize( qRect.size() );
1009cdf0e10cSrcweir     m_pScrollBar->setOrientation( bHorizontal? Qt::Horizontal: Qt::Vertical );
1010cdf0e10cSrcweir 
10113460f9c8SHerbert Dürr     const ScrollbarValue* pScrollbarVal = (aValue.getType() == CTRL_SCROLLBAR) ? static_cast<const ScrollbarValue*>(&aValue) : NULL;
1012cdf0e10cSrcweir     if ( pValue )
1013cdf0e10cSrcweir     {
1014cdf0e10cSrcweir 	m_pScrollBar->setMinValue( pValue->mnMin );
1015cdf0e10cSrcweir 	m_pScrollBar->setMaxValue( pValue->mnMax - pValue->mnVisibleSize );
1016cdf0e10cSrcweir 	m_pScrollBar->setValue( pValue->mnCur );
1017cdf0e10cSrcweir 	m_pScrollBar->setPageStep( pValue->mnVisibleSize );
1018cdf0e10cSrcweir     }
1019cdf0e10cSrcweir 
1020cdf0e10cSrcweir     return m_pScrollBar;
1021cdf0e10cSrcweir }
1022cdf0e10cSrcweir 
toolBar(const Rectangle & rControlRegion,sal_Bool bHorizontal)1023cdf0e10cSrcweir QToolBar *WidgetPainter::toolBar( const Rectangle& rControlRegion, sal_Bool bHorizontal )
1024cdf0e10cSrcweir {
1025cdf0e10cSrcweir     if ( !m_pMainWindow )
1026cdf0e10cSrcweir         m_pMainWindow = new QMainWindow( NULL, "main_window" );
1027cdf0e10cSrcweir 
1028cdf0e10cSrcweir     QToolBar *pToolBar;
1029cdf0e10cSrcweir     if ( bHorizontal )
1030cdf0e10cSrcweir     {
1031cdf0e10cSrcweir         if ( !m_pToolBarHoriz )
1032cdf0e10cSrcweir         {
1033cdf0e10cSrcweir             m_pToolBarHoriz = new QToolBar( m_pMainWindow, "tool_bar_horiz" );
1034cdf0e10cSrcweir             m_pMainWindow->moveDockWindow( m_pToolBarHoriz, Qt::DockTop );
1035cdf0e10cSrcweir         }
1036cdf0e10cSrcweir         pToolBar = m_pToolBarHoriz;
1037cdf0e10cSrcweir     }
1038cdf0e10cSrcweir     else
1039cdf0e10cSrcweir     {
1040cdf0e10cSrcweir         if ( !m_pToolBarVert )
1041cdf0e10cSrcweir         {
1042cdf0e10cSrcweir             m_pToolBarVert = new QToolBar( m_pMainWindow, "tool_bar_horiz" );
1043cdf0e10cSrcweir             m_pMainWindow->moveDockWindow( m_pToolBarVert, Qt::DockLeft );
1044cdf0e10cSrcweir         }
1045cdf0e10cSrcweir         pToolBar = m_pToolBarVert;
1046cdf0e10cSrcweir     }
1047cdf0e10cSrcweir 
1048cdf0e10cSrcweir     QRect qRect = region2QRect( rControlRegion );
1049cdf0e10cSrcweir 
1050cdf0e10cSrcweir     pToolBar->move( qRect.topLeft() );
1051cdf0e10cSrcweir     pToolBar->resize( qRect.size() );
1052cdf0e10cSrcweir 
1053cdf0e10cSrcweir     return pToolBar;
1054cdf0e10cSrcweir }
1055cdf0e10cSrcweir 
toolButton(const Rectangle & rControlRegion)1056cdf0e10cSrcweir QToolButton *WidgetPainter::toolButton( const Rectangle& rControlRegion)
1057cdf0e10cSrcweir {
1058cdf0e10cSrcweir     if ( !m_pToolButton )
1059cdf0e10cSrcweir 	m_pToolButton = new QToolButton( NULL, "tool_button" );
1060cdf0e10cSrcweir 
1061cdf0e10cSrcweir     QRect qRect = region2QRect( rControlRegion );
1062cdf0e10cSrcweir 
1063cdf0e10cSrcweir     m_pToolButton->move( qRect.topLeft() );
1064cdf0e10cSrcweir     m_pToolButton->resize( qRect.size() );
1065cdf0e10cSrcweir 
1066cdf0e10cSrcweir     return m_pToolButton;
1067cdf0e10cSrcweir }
1068cdf0e10cSrcweir 
menuBar(const Rectangle & rControlRegion)1069cdf0e10cSrcweir QMenuBar *WidgetPainter::menuBar( const Rectangle& rControlRegion)
1070cdf0e10cSrcweir {
1071cdf0e10cSrcweir     if ( !m_pMenuBar )
1072cdf0e10cSrcweir     {
1073cdf0e10cSrcweir         m_pMenuBar = new QMenuBar( NULL, "menu_bar" );
1074cdf0e10cSrcweir 
1075cdf0e10cSrcweir         m_nMenuBarEnabledItem = m_pMenuBar->insertItem( "" );
1076cdf0e10cSrcweir         m_nMenuBarDisabledItem = m_pMenuBar->insertItem( "" );
1077cdf0e10cSrcweir 
1078cdf0e10cSrcweir         m_pMenuBar->setItemEnabled( m_nMenuBarEnabledItem, true );
1079cdf0e10cSrcweir         m_pMenuBar->setItemEnabled( m_nMenuBarDisabledItem, false );
1080cdf0e10cSrcweir     }
1081cdf0e10cSrcweir 
1082cdf0e10cSrcweir     QRect qRect = region2QRect( rControlRegion );
1083cdf0e10cSrcweir 
1084cdf0e10cSrcweir     m_pMenuBar->move( qRect.topLeft() );
1085cdf0e10cSrcweir     m_pMenuBar->resize( qRect.size() );
1086cdf0e10cSrcweir 
1087cdf0e10cSrcweir     return m_pMenuBar;
1088cdf0e10cSrcweir }
1089cdf0e10cSrcweir 
popupMenu(const Rectangle & rControlRegion)1090cdf0e10cSrcweir QPopupMenu *WidgetPainter::popupMenu( const Rectangle& rControlRegion)
1091cdf0e10cSrcweir {
1092cdf0e10cSrcweir     if ( !m_pPopupMenu )
1093cdf0e10cSrcweir     {
1094cdf0e10cSrcweir         m_pPopupMenu = new QPopupMenu( NULL, "popup_menu" );
1095cdf0e10cSrcweir 
1096cdf0e10cSrcweir         m_nPopupMenuEnabledItem = m_pPopupMenu->insertItem( "" );
1097cdf0e10cSrcweir         m_nPopupMenuDisabledItem = m_pPopupMenu->insertItem( "" );
1098cdf0e10cSrcweir 
1099cdf0e10cSrcweir         m_pPopupMenu->setItemEnabled( m_nPopupMenuEnabledItem, true );
1100cdf0e10cSrcweir         m_pPopupMenu->setItemEnabled( m_nPopupMenuDisabledItem, false );
1101cdf0e10cSrcweir     }
1102cdf0e10cSrcweir 
1103cdf0e10cSrcweir     QRect qRect = region2QRect( rControlRegion );
1104cdf0e10cSrcweir 
1105cdf0e10cSrcweir     m_pPopupMenu->move( qRect.topLeft() );
1106cdf0e10cSrcweir     m_pPopupMenu->resize( qRect.size() );
1107cdf0e10cSrcweir 
1108cdf0e10cSrcweir     return m_pPopupMenu;
1109cdf0e10cSrcweir }
1110cdf0e10cSrcweir 
progressBar(const Rectangle & rControlRegion)1111cdf0e10cSrcweir QProgressBar *WidgetPainter::progressBar( const Rectangle& rControlRegion )
1112cdf0e10cSrcweir {
1113cdf0e10cSrcweir     if ( !m_pProgressBar )
1114cdf0e10cSrcweir 	m_pProgressBar = new QProgressBar( NULL, "progress_bar" );
1115cdf0e10cSrcweir 
1116cdf0e10cSrcweir     QRect qRect = region2QRect( rControlRegion );
1117cdf0e10cSrcweir 
1118cdf0e10cSrcweir     m_pProgressBar->move( qRect.topLeft() );
1119cdf0e10cSrcweir     m_pProgressBar->resize( qRect.size() );
1120cdf0e10cSrcweir 
1121cdf0e10cSrcweir     return m_pProgressBar;
1122cdf0e10cSrcweir }
1123cdf0e10cSrcweir 
vclStateValue2SFlags(ControlState nState,const ImplControlValue & aValue)1124cdf0e10cSrcweir QStyle::SFlags WidgetPainter::vclStateValue2SFlags( ControlState nState,
1125cdf0e10cSrcweir 	const ImplControlValue& aValue )
1126cdf0e10cSrcweir {
1127cdf0e10cSrcweir     QStyle::SFlags nStyle =
1128cdf0e10cSrcweir 	( (nState & CTRL_STATE_DEFAULT)?  QStyle::Style_ButtonDefault: QStyle::Style_Default ) |
1129cdf0e10cSrcweir 	( (nState & CTRL_STATE_ENABLED)?  QStyle::Style_Enabled:       QStyle::Style_Default ) |
1130cdf0e10cSrcweir 	( (nState & CTRL_STATE_FOCUSED)?  QStyle::Style_HasFocus:      QStyle::Style_Default ) |
1131cdf0e10cSrcweir 	( (nState & CTRL_STATE_PRESSED)?  QStyle::Style_Down:          QStyle::Style_Raised )  |
1132cdf0e10cSrcweir 	( (nState & CTRL_STATE_SELECTED)? QStyle::Style_Selected :     QStyle::Style_Default ) |
1133cdf0e10cSrcweir 	( (nState & CTRL_STATE_ROLLOVER)? QStyle::Style_MouseOver:     QStyle::Style_Default );
1134cdf0e10cSrcweir 	//TODO ( (nState & CTRL_STATE_HIDDEN)?   QStyle::Style_: QStyle::Style_Default ) |
1135cdf0e10cSrcweir 
1136cdf0e10cSrcweir     switch ( aValue.getTristateVal() )
1137cdf0e10cSrcweir     {
1138cdf0e10cSrcweir 	case BUTTONVALUE_ON:    nStyle |= QStyle::Style_On;       break;
1139cdf0e10cSrcweir 	case BUTTONVALUE_OFF:   nStyle |= QStyle::Style_Off;      break;
1140cdf0e10cSrcweir 	case BUTTONVALUE_MIXED: nStyle |= QStyle::Style_NoChange; break;
1141cdf0e10cSrcweir     default: break;
1142cdf0e10cSrcweir     }
1143cdf0e10cSrcweir 
1144cdf0e10cSrcweir     return nStyle;
1145cdf0e10cSrcweir }
1146cdf0e10cSrcweir 
region2QRect(const Rectangle & rControlRegion)1147cdf0e10cSrcweir QRect WidgetPainter::region2QRect( const Rectangle& rControlRegion )
1148cdf0e10cSrcweir {
1149cdf0e10cSrcweir     return QRect( QPoint( rControlRegion.Left(), rControlRegion.Top() ),
1150cdf0e10cSrcweir                   QPoint( rControlRegion.Right(), rControlRegion.Bottom() ) );
1151cdf0e10cSrcweir }
1152cdf0e10cSrcweir 
1153cdf0e10cSrcweir /** Instance of WidgetPainter.
1154cdf0e10cSrcweir 
1155cdf0e10cSrcweir     It is used to paint the widgets requested by NWF.
1156cdf0e10cSrcweir */
1157cdf0e10cSrcweir static WidgetPainter *pWidgetPainter;
1158cdf0e10cSrcweir 
1159cdf0e10cSrcweir class KDESalGraphics : public X11SalGraphics
1160cdf0e10cSrcweir {
1161cdf0e10cSrcweir   public:
KDESalGraphics()1162cdf0e10cSrcweir 	KDESalGraphics() {}
~KDESalGraphics()1163cdf0e10cSrcweir 	virtual ~KDESalGraphics() {}
1164cdf0e10cSrcweir 	virtual sal_Bool IsNativeControlSupported( ControlType nType, ControlPart nPart );
1165cdf0e10cSrcweir 	virtual sal_Bool hitTestNativeControl( ControlType nType, ControlPart nPart,
1166cdf0e10cSrcweir 									   const Rectangle& rControlRegion, const Point& aPos,
1167cdf0e10cSrcweir 									   sal_Bool& rIsInside );
1168cdf0e10cSrcweir 	virtual sal_Bool drawNativeControl( ControlType nType, ControlPart nPart,
1169cdf0e10cSrcweir 									const Rectangle& rControlRegion, ControlState nState,
1170cdf0e10cSrcweir 									const ImplControlValue& aValue,
1171cdf0e10cSrcweir 									const OUString& aCaption );
1172cdf0e10cSrcweir 	virtual sal_Bool drawNativeControlText( ControlType nType, ControlPart nPart,
1173cdf0e10cSrcweir 										const Rectangle& rControlRegion, ControlState nState,
1174cdf0e10cSrcweir 										const ImplControlValue& aValue,
1175cdf0e10cSrcweir 										const OUString& aCaption );
1176cdf0e10cSrcweir 	virtual sal_Bool getNativeControlRegion( ControlType nType, ControlPart nPart,
1177cdf0e10cSrcweir 										 const Rectangle& rControlRegion, ControlState nState,
1178cdf0e10cSrcweir 										 const ImplControlValue& aValue,
1179cdf0e10cSrcweir 										 const OUString& aCaption,
1180cdf0e10cSrcweir 										 Rectangle &rNativeBoundingRegion, Rectangle &rNativeContentRegion );
1181cdf0e10cSrcweir };
1182cdf0e10cSrcweir 
1183cdf0e10cSrcweir /** What widgets can be drawn the native way.
1184cdf0e10cSrcweir 
1185cdf0e10cSrcweir     @param nType
1186cdf0e10cSrcweir     Type of the widget.
1187cdf0e10cSrcweir 
1188cdf0e10cSrcweir     @param nPart
1189cdf0e10cSrcweir     Specification of the widget's part if it consists of more than one.
1190cdf0e10cSrcweir 
1191cdf0e10cSrcweir     @return sal_True if the platform supports native drawing of the widget nType
1192cdf0e10cSrcweir     defined by nPart.
1193cdf0e10cSrcweir */
IsNativeControlSupported(ControlType nType,ControlPart nPart)1194cdf0e10cSrcweir sal_Bool KDESalGraphics::IsNativeControlSupported( ControlType nType, ControlPart nPart )
1195cdf0e10cSrcweir {
1196cdf0e10cSrcweir     return
1197cdf0e10cSrcweir 	( (nType == CTRL_PUSHBUTTON)  && (nPart == PART_ENTIRE_CONTROL) ) ||
1198cdf0e10cSrcweir 	( (nType == CTRL_RADIOBUTTON) && (nPart == PART_ENTIRE_CONTROL) ) ||
1199cdf0e10cSrcweir 	( (nType == CTRL_CHECKBOX)    && (nPart == PART_ENTIRE_CONTROL) ) ||
1200cdf0e10cSrcweir 	( (nType == CTRL_COMBOBOX)    && (nPart == PART_ENTIRE_CONTROL || nPart == HAS_BACKGROUND_TEXTURE) ) ||
1201cdf0e10cSrcweir 	( (nType == CTRL_EDITBOX)     && (nPart == PART_ENTIRE_CONTROL || nPart == HAS_BACKGROUND_TEXTURE) ) ||
1202cdf0e10cSrcweir 	( (nType == CTRL_LISTBOX)     && (nPart == PART_ENTIRE_CONTROL || nPart == PART_WINDOW || nPart == HAS_BACKGROUND_TEXTURE ) ) ||
1203cdf0e10cSrcweir 	( (nType == CTRL_SPINBOX)     && (nPart == PART_ENTIRE_CONTROL || nPart == HAS_BACKGROUND_TEXTURE) ) ||
1204cdf0e10cSrcweir 	// no CTRL_SPINBUTTONS for KDE
1205cdf0e10cSrcweir 	( (nType == CTRL_TAB_ITEM)    && (nPart == PART_ENTIRE_CONTROL) ) ||
1206cdf0e10cSrcweir 	( (nType == CTRL_TAB_PANE)    && (nPart == PART_ENTIRE_CONTROL) ) ||
1207cdf0e10cSrcweir 	// no CTRL_TAB_BODY for KDE
1208cdf0e10cSrcweir 	( (nType == CTRL_SCROLLBAR)   && (nPart == PART_ENTIRE_CONTROL || nPart == PART_DRAW_BACKGROUND_HORZ || nPart == PART_DRAW_BACKGROUND_VERT) ) ||
1209cdf0e10cSrcweir 	( (nType == CTRL_SCROLLBAR)   && (nPart == HAS_THREE_BUTTONS) ) || // TODO small optimization is possible here: return this only if the style really has 3 buttons
1210cdf0e10cSrcweir 	// CTRL_GROUPBOX not supported
1211cdf0e10cSrcweir 	// CTRL_FIXEDLINE not supported
1212cdf0e10cSrcweir 	// CTRL_FIXEDBORDER not supported
1213cdf0e10cSrcweir     ( (nType == CTRL_TOOLBAR)     && (nPart == PART_ENTIRE_CONTROL ||
1214cdf0e10cSrcweir                                       nPart == PART_DRAW_BACKGROUND_HORZ || nPart == PART_DRAW_BACKGROUND_VERT ||
1215cdf0e10cSrcweir                                       nPart == PART_THUMB_HORZ || nPart == PART_THUMB_VERT ||
1216cdf0e10cSrcweir                                       nPart == PART_BUTTON) ) ||
1217cdf0e10cSrcweir     ( (nType == CTRL_MENUBAR)     && (nPart == PART_ENTIRE_CONTROL || nPart == PART_MENU_ITEM) ) ||
1218cdf0e10cSrcweir     ( (nType == CTRL_MENU_POPUP)  && (nPart == PART_ENTIRE_CONTROL || nPart == PART_MENU_ITEM) ) ||
1219cdf0e10cSrcweir 	( (nType == CTRL_PROGRESS)    && (nPart == PART_ENTIRE_CONTROL) )
1220cdf0e10cSrcweir         ;
1221cdf0e10cSrcweir }
1222cdf0e10cSrcweir 
1223cdf0e10cSrcweir 
1224cdf0e10cSrcweir /** Test whether the position is in the native widget.
1225cdf0e10cSrcweir 
1226cdf0e10cSrcweir     If the return value is sal_True, bIsInside contains information whether
1227cdf0e10cSrcweir     aPos was or was not inside the native widget specified by the
1228cdf0e10cSrcweir     nType/nPart combination.
1229cdf0e10cSrcweir */
hitTestNativeControl(ControlType nType,ControlPart nPart,const Rectangle & rControlRegion,const Point & rPos,sal_Bool & rIsInside)1230cdf0e10cSrcweir sal_Bool KDESalGraphics::hitTestNativeControl( ControlType nType, ControlPart nPart,
1231cdf0e10cSrcweir 										   const Rectangle& rControlRegion, const Point& rPos,
1232cdf0e10cSrcweir 										   sal_Bool& rIsInside )
1233cdf0e10cSrcweir {
1234cdf0e10cSrcweir     if ( nType == CTRL_SCROLLBAR )
1235cdf0e10cSrcweir     {
1236cdf0e10cSrcweir     // make position relative to rControlRegion
1237cdf0e10cSrcweir     Point aPos = rPos - rControlRegion.TopLeft();
1238cdf0e10cSrcweir 	rIsInside = sal_False;
1239cdf0e10cSrcweir 
1240cdf0e10cSrcweir 	sal_Bool bHorizontal = ( nPart == PART_BUTTON_LEFT || nPart == PART_BUTTON_RIGHT );
1241cdf0e10cSrcweir 
1242cdf0e10cSrcweir 	QScrollBar *pScrollBar = pWidgetPainter->scrollBar( rControlRegion,
1243cdf0e10cSrcweir 		bHorizontal, ImplControlValue() );
1244cdf0e10cSrcweir 	QRect qRectSubLine = kapp->style().querySubControlMetrics(
1245cdf0e10cSrcweir 		QStyle::CC_ScrollBar, pScrollBar, QStyle::SC_ScrollBarSubLine );
1246cdf0e10cSrcweir 	QRect qRectAddLine = kapp->style().querySubControlMetrics(
1247cdf0e10cSrcweir 		QStyle::CC_ScrollBar, pScrollBar, QStyle::SC_ScrollBarAddLine );
1248cdf0e10cSrcweir 
1249cdf0e10cSrcweir 	// There are 2 buttons on the right/bottom side of the scrollbar
1250cdf0e10cSrcweir 	sal_Bool bTwoSubButtons = sal_False;
1251cdf0e10cSrcweir 
1252cdf0e10cSrcweir 	// It is a Platinum style scroll bar
1253cdf0e10cSrcweir 	sal_Bool bPlatinumStyle = sal_False;
1254cdf0e10cSrcweir 
1255cdf0e10cSrcweir 	// Workaround for Platinum and 3 button style scroll bars.
1256cdf0e10cSrcweir 	// It makes the right/down button bigger.
1257cdf0e10cSrcweir 	if ( bHorizontal )
1258cdf0e10cSrcweir 	{
1259cdf0e10cSrcweir 	    qRectAddLine.setLeft( kapp->style().querySubControlMetrics(
1260cdf0e10cSrcweir 			QStyle::CC_ScrollBar, pScrollBar,
1261cdf0e10cSrcweir 			QStyle::SC_ScrollBarAddPage ).right() + 1 );
1262cdf0e10cSrcweir 	    if ( qRectAddLine.width() > qRectSubLine.width() )
1263cdf0e10cSrcweir 		bTwoSubButtons = sal_True;
1264cdf0e10cSrcweir 	    if ( qRectSubLine.left() > kapp->style().querySubControlMetrics( QStyle::CC_ScrollBar, pScrollBar, QStyle::SC_ScrollBarSubPage ).left() )
1265cdf0e10cSrcweir 		bPlatinumStyle = sal_True;
1266cdf0e10cSrcweir 	}
1267cdf0e10cSrcweir 	else
1268cdf0e10cSrcweir 	{
1269cdf0e10cSrcweir 	    qRectAddLine.setTop( kapp->style().querySubControlMetrics(
1270cdf0e10cSrcweir 			QStyle::CC_ScrollBar, pScrollBar,
1271cdf0e10cSrcweir 			QStyle::SC_ScrollBarAddPage ).bottom() + 1 );
1272cdf0e10cSrcweir 	    if ( qRectAddLine.height() > qRectSubLine.height() )
1273cdf0e10cSrcweir 		bTwoSubButtons = sal_True;
1274cdf0e10cSrcweir 	    if ( qRectSubLine.top() > kapp->style().querySubControlMetrics( QStyle::CC_ScrollBar, pScrollBar, QStyle::SC_ScrollBarSubPage ).top() )
1275cdf0e10cSrcweir 		bPlatinumStyle = sal_True;
1276cdf0e10cSrcweir 	}
1277cdf0e10cSrcweir 
1278cdf0e10cSrcweir 	switch ( nPart )
1279cdf0e10cSrcweir 	{
1280cdf0e10cSrcweir 	    case PART_BUTTON_LEFT:
1281cdf0e10cSrcweir 		if ( !bPlatinumStyle && qRectSubLine.contains( aPos.getX(), aPos.getY() ) )
1282cdf0e10cSrcweir 		    rIsInside = sal_True;
1283cdf0e10cSrcweir 		else if ( bTwoSubButtons )
1284cdf0e10cSrcweir 		{
1285cdf0e10cSrcweir 		    qRectAddLine.setWidth( qRectAddLine.width() / 2 );
1286cdf0e10cSrcweir 		    rIsInside = qRectAddLine.contains( aPos.getX(), aPos.getY() );
1287cdf0e10cSrcweir 		}
1288cdf0e10cSrcweir 		break;
1289cdf0e10cSrcweir 
1290cdf0e10cSrcweir 	    case PART_BUTTON_UP:
1291cdf0e10cSrcweir 		if ( !bPlatinumStyle && qRectSubLine.contains( aPos.getX(), aPos.getY() ) )
1292cdf0e10cSrcweir 		    rIsInside = sal_True;
1293cdf0e10cSrcweir 		else if ( bTwoSubButtons )
1294cdf0e10cSrcweir 		{
1295cdf0e10cSrcweir 		    qRectAddLine.setHeight( qRectAddLine.height() / 2 );
1296cdf0e10cSrcweir 		    rIsInside = qRectAddLine.contains( aPos.getX(), aPos.getY() );
1297cdf0e10cSrcweir 		}
1298cdf0e10cSrcweir 		break;
1299cdf0e10cSrcweir 
1300cdf0e10cSrcweir 	    case PART_BUTTON_RIGHT:
1301cdf0e10cSrcweir 		if ( bTwoSubButtons )
1302cdf0e10cSrcweir 		    qRectAddLine.setLeft( qRectAddLine.left() + qRectAddLine.width() / 2 );
1303cdf0e10cSrcweir 
1304cdf0e10cSrcweir 		rIsInside = qRectAddLine.contains( aPos.getX(), aPos.getY() );
1305cdf0e10cSrcweir 		break;
1306cdf0e10cSrcweir 
1307cdf0e10cSrcweir 	    case PART_BUTTON_DOWN:
1308cdf0e10cSrcweir 		if ( bTwoSubButtons )
1309cdf0e10cSrcweir 		    qRectAddLine.setTop( qRectAddLine.top() + qRectAddLine.height() / 2 );
1310cdf0e10cSrcweir 
1311cdf0e10cSrcweir 		rIsInside = qRectAddLine.contains( aPos.getX(), aPos.getY() );
1312cdf0e10cSrcweir 		break;
1313cdf0e10cSrcweir 
1314cdf0e10cSrcweir         // cases PART_TRACK_HORZ_AREA and PART_TRACK_VERT_AREA
1315cdf0e10cSrcweir         default:
1316cdf0e10cSrcweir         return sal_False;
1317cdf0e10cSrcweir 	}
1318cdf0e10cSrcweir 
1319cdf0e10cSrcweir 	return sal_True;
1320cdf0e10cSrcweir     }
1321cdf0e10cSrcweir 
1322cdf0e10cSrcweir     return sal_False;
1323cdf0e10cSrcweir }
1324cdf0e10cSrcweir 
1325cdf0e10cSrcweir 
1326cdf0e10cSrcweir /** Draw the requested control described by nPart/nState.
1327cdf0e10cSrcweir 
1328cdf0e10cSrcweir     @param rControlRegion
1329cdf0e10cSrcweir     The bounding region of the complete control in VCL frame coordinates.
1330cdf0e10cSrcweir 
1331cdf0e10cSrcweir     @param aValue
1332cdf0e10cSrcweir     An optional value (tristate/numerical/string).
1333cdf0e10cSrcweir 
1334cdf0e10cSrcweir     @param aCaption
1335cdf0e10cSrcweir     A caption or title string (like button text etc.)
1336cdf0e10cSrcweir */
drawNativeControl(ControlType nType,ControlPart nPart,const Rectangle & rControlRegion,ControlState nState,const ImplControlValue & aValue,const OUString &)1337cdf0e10cSrcweir sal_Bool KDESalGraphics::drawNativeControl( ControlType nType, ControlPart nPart,
1338cdf0e10cSrcweir 										const Rectangle& rControlRegion, ControlState nState,
1339cdf0e10cSrcweir 										const ImplControlValue& aValue,
1340cdf0e10cSrcweir 										const OUString& )
1341cdf0e10cSrcweir {
1342cdf0e10cSrcweir     sal_Bool bReturn = sal_False;
1343cdf0e10cSrcweir 
1344cdf0e10cSrcweir     Display *dpy = GetXDisplay();
1345cdf0e10cSrcweir     XLIB_Window drawable = GetDrawable();
1346cdf0e10cSrcweir     GC gc = SelectPen(); //SelectFont(); // GC with current clipping region set
1347cdf0e10cSrcweir 
1348cdf0e10cSrcweir     if ( (nType == CTRL_PUSHBUTTON) && (nPart == PART_ENTIRE_CONTROL) )
1349cdf0e10cSrcweir     {
1350cdf0e10cSrcweir 	bReturn = pWidgetPainter->drawStyledWidget(
1351cdf0e10cSrcweir 		pWidgetPainter->pushButton( rControlRegion, (nState & CTRL_STATE_DEFAULT) ),
1352cdf0e10cSrcweir 		nState, aValue,
1353cdf0e10cSrcweir 		dpy, drawable, GetScreenNumber(), GetVisual().GetDepth(), gc );
1354cdf0e10cSrcweir     }
1355cdf0e10cSrcweir     else if ( (nType == CTRL_RADIOBUTTON) && (nPart == PART_ENTIRE_CONTROL) )
1356cdf0e10cSrcweir     {
1357cdf0e10cSrcweir 	bReturn = pWidgetPainter->drawStyledWidget(
1358cdf0e10cSrcweir 		pWidgetPainter->radioButton( rControlRegion ),
1359cdf0e10cSrcweir 		nState, aValue,
1360cdf0e10cSrcweir 		dpy, drawable, GetScreenNumber(), GetVisual().GetDepth(), gc );
1361cdf0e10cSrcweir     }
1362cdf0e10cSrcweir     else if ( (nType == CTRL_CHECKBOX) && (nPart == PART_ENTIRE_CONTROL) )
1363cdf0e10cSrcweir     {
1364cdf0e10cSrcweir 	bReturn = pWidgetPainter->drawStyledWidget(
1365cdf0e10cSrcweir 		pWidgetPainter->checkBox( rControlRegion ),
1366cdf0e10cSrcweir 		nState, aValue,
1367cdf0e10cSrcweir 		dpy, drawable, GetScreenNumber(), GetVisual().GetDepth(), gc );
1368cdf0e10cSrcweir     }
1369cdf0e10cSrcweir     else if ( (nType == CTRL_COMBOBOX) && (nPart == PART_ENTIRE_CONTROL) )
1370cdf0e10cSrcweir     {
1371cdf0e10cSrcweir 	bReturn = pWidgetPainter->drawStyledWidget(
1372cdf0e10cSrcweir 		pWidgetPainter->comboBox( rControlRegion, sal_True ),
1373cdf0e10cSrcweir 		nState, aValue,
1374cdf0e10cSrcweir 		dpy, drawable, GetScreenNumber(), GetVisual().GetDepth(), gc );
1375cdf0e10cSrcweir     }
1376cdf0e10cSrcweir     else if ( (nType == CTRL_EDITBOX) && (nPart == PART_ENTIRE_CONTROL) )
1377cdf0e10cSrcweir     {
1378cdf0e10cSrcweir 	bReturn = pWidgetPainter->drawStyledWidget(
1379cdf0e10cSrcweir 		pWidgetPainter->lineEdit( rControlRegion ),
1380cdf0e10cSrcweir 		nState, aValue,
1381cdf0e10cSrcweir 		dpy, drawable, GetScreenNumber(), GetVisual().GetDepth(), gc );
1382cdf0e10cSrcweir     }
1383cdf0e10cSrcweir     else if ( (nType == CTRL_LISTBOX) && (nPart == PART_ENTIRE_CONTROL) )
1384cdf0e10cSrcweir     {
1385cdf0e10cSrcweir 	bReturn = pWidgetPainter->drawStyledWidget(
1386cdf0e10cSrcweir 		pWidgetPainter->comboBox( rControlRegion, sal_False ),
1387cdf0e10cSrcweir 		nState, aValue,
1388cdf0e10cSrcweir 		dpy, drawable, GetScreenNumber(), GetVisual().GetDepth(), gc );
1389cdf0e10cSrcweir     }
1390cdf0e10cSrcweir     else if ( (nType == CTRL_LISTBOX) && (nPart == PART_WINDOW) )
1391cdf0e10cSrcweir     {
1392cdf0e10cSrcweir 	bReturn = pWidgetPainter->drawStyledWidget(
1393cdf0e10cSrcweir 		pWidgetPainter->listView( rControlRegion ),
1394cdf0e10cSrcweir 		nState, aValue,
1395cdf0e10cSrcweir 		dpy, drawable, GetScreenNumber(), GetVisual().GetDepth(), gc );
1396cdf0e10cSrcweir     }
1397cdf0e10cSrcweir     else if ( (nType == CTRL_SPINBOX) && (nPart == PART_ENTIRE_CONTROL) )
1398cdf0e10cSrcweir     {
1399cdf0e10cSrcweir 	bReturn = pWidgetPainter->drawStyledWidget(
1400cdf0e10cSrcweir 		pWidgetPainter->spinWidget( rControlRegion ),
1401cdf0e10cSrcweir 		nState, aValue,
1402cdf0e10cSrcweir 		dpy, drawable, GetScreenNumber(), GetVisual().GetDepth(), gc );
1403cdf0e10cSrcweir     }
1404cdf0e10cSrcweir     else if ( (nType==CTRL_TAB_ITEM) && (nPart == PART_ENTIRE_CONTROL) )
1405cdf0e10cSrcweir     {
1406cdf0e10cSrcweir 	bReturn = pWidgetPainter->drawStyledWidget(
1407cdf0e10cSrcweir 		pWidgetPainter->tabBar( rControlRegion ),
1408cdf0e10cSrcweir 		nState, aValue,
1409cdf0e10cSrcweir 		dpy, drawable, GetScreenNumber(), GetVisual().GetDepth(), gc );
1410cdf0e10cSrcweir     }
1411cdf0e10cSrcweir     else if ( (nType==CTRL_TAB_PANE) && (nPart == PART_ENTIRE_CONTROL) )
1412cdf0e10cSrcweir     {
1413cdf0e10cSrcweir 	bReturn = pWidgetPainter->drawStyledWidget(
1414cdf0e10cSrcweir 		pWidgetPainter->tabWidget( rControlRegion ),
1415cdf0e10cSrcweir 		nState, aValue,
1416cdf0e10cSrcweir 		dpy, drawable, GetScreenNumber(), GetVisual().GetDepth(), gc );
1417cdf0e10cSrcweir     }
1418cdf0e10cSrcweir     else if ( (nType == CTRL_SCROLLBAR) && (nPart == PART_DRAW_BACKGROUND_HORZ || nPart == PART_DRAW_BACKGROUND_VERT) )
1419cdf0e10cSrcweir     {
1420cdf0e10cSrcweir 	bReturn = pWidgetPainter->drawStyledWidget(
1421cdf0e10cSrcweir 		pWidgetPainter->scrollBar( rControlRegion, nPart == PART_DRAW_BACKGROUND_HORZ, aValue ),
1422cdf0e10cSrcweir 		nState, aValue,
1423cdf0e10cSrcweir 		dpy, drawable, GetScreenNumber(), GetVisual().GetDepth(), gc );
1424cdf0e10cSrcweir     }
1425cdf0e10cSrcweir     else if ( (nType == CTRL_TOOLBAR) && (nPart == PART_DRAW_BACKGROUND_HORZ || nPart == PART_DRAW_BACKGROUND_VERT || nPart == PART_THUMB_HORZ || nPart == PART_THUMB_VERT) )
1426cdf0e10cSrcweir     {
1427cdf0e10cSrcweir         bReturn = pWidgetPainter->drawStyledWidget(
1428cdf0e10cSrcweir                 pWidgetPainter->toolBar( rControlRegion, nPart == PART_DRAW_BACKGROUND_HORZ || nPart == PART_THUMB_VERT ),
1429cdf0e10cSrcweir                 nState, aValue,
1430cdf0e10cSrcweir                 dpy, drawable, GetScreenNumber(), GetVisual().GetDepth(), gc, nPart );
1431cdf0e10cSrcweir     }
1432cdf0e10cSrcweir     else if ( (nType == CTRL_TOOLBAR) && (nPart == PART_BUTTON) )
1433cdf0e10cSrcweir     {
1434cdf0e10cSrcweir         bReturn = pWidgetPainter->drawStyledWidget(
1435cdf0e10cSrcweir                 pWidgetPainter->toolButton( rControlRegion ),
1436cdf0e10cSrcweir                 nState, aValue,
1437cdf0e10cSrcweir                 dpy, drawable, GetScreenNumber(), GetVisual().GetDepth(), gc, nPart );
1438cdf0e10cSrcweir     }
1439cdf0e10cSrcweir     else if ( (nType == CTRL_MENUBAR) && (nPart == PART_ENTIRE_CONTROL || nPart == PART_MENU_ITEM) )
1440cdf0e10cSrcweir     {
1441cdf0e10cSrcweir         bReturn = pWidgetPainter->drawStyledWidget(
1442cdf0e10cSrcweir                 pWidgetPainter->menuBar( rControlRegion ),
1443cdf0e10cSrcweir                 nState, aValue,
1444cdf0e10cSrcweir                 dpy, drawable, GetScreenNumber(), GetVisual().GetDepth(), gc, nPart );
1445cdf0e10cSrcweir     }
1446cdf0e10cSrcweir     else if ( (nType == CTRL_MENU_POPUP) && (nPart == PART_ENTIRE_CONTROL || nPart == PART_MENU_ITEM) )
1447cdf0e10cSrcweir     {
1448cdf0e10cSrcweir         bReturn = pWidgetPainter->drawStyledWidget(
1449cdf0e10cSrcweir                 pWidgetPainter->popupMenu( rControlRegion ),
1450cdf0e10cSrcweir                 nState, aValue,
1451cdf0e10cSrcweir                 dpy, drawable, GetScreenNumber(), GetVisual().GetDepth(), gc );
1452cdf0e10cSrcweir     }
1453cdf0e10cSrcweir     else if ( (nType == CTRL_PROGRESS) && (nPart == PART_ENTIRE_CONTROL) )
1454cdf0e10cSrcweir     {
1455cdf0e10cSrcweir         bReturn = pWidgetPainter->drawStyledWidget(
1456cdf0e10cSrcweir                 pWidgetPainter->progressBar( rControlRegion ),
1457cdf0e10cSrcweir                 nState, aValue,
1458cdf0e10cSrcweir                 dpy, drawable, GetScreenNumber(), GetVisual().GetDepth(), gc );
1459cdf0e10cSrcweir     }
1460cdf0e10cSrcweir 
1461cdf0e10cSrcweir     return bReturn;
1462cdf0e10cSrcweir }
1463cdf0e10cSrcweir 
1464cdf0e10cSrcweir 
1465cdf0e10cSrcweir /** Draw text on the widget.
1466cdf0e10cSrcweir 
1467cdf0e10cSrcweir     OPTIONAL. Draws the requested text for the control described by nPart/nState.
1468cdf0e10cSrcweir     Used if text is not drawn by DrawNativeControl().
1469cdf0e10cSrcweir 
1470cdf0e10cSrcweir     @param rControlRegion
1471cdf0e10cSrcweir     The bounding region of the complete control in VCL frame coordinates.
1472cdf0e10cSrcweir 
1473cdf0e10cSrcweir     @param aValue
1474cdf0e10cSrcweir     An optional value (tristate/numerical/string)
1475cdf0e10cSrcweir 
1476cdf0e10cSrcweir     @param aCaption
1477cdf0e10cSrcweir     A caption or title string (like button text etc.)
1478cdf0e10cSrcweir */
drawNativeControlText(ControlType,ControlPart,const Rectangle &,ControlState,const ImplControlValue &,const OUString &)1479cdf0e10cSrcweir sal_Bool KDESalGraphics::drawNativeControlText( ControlType, ControlPart,
1480cdf0e10cSrcweir 											const Rectangle&, ControlState,
1481cdf0e10cSrcweir 											const ImplControlValue&,
1482cdf0e10cSrcweir 											const OUString& )
1483cdf0e10cSrcweir {
1484cdf0e10cSrcweir     return sal_False;
1485cdf0e10cSrcweir }
1486cdf0e10cSrcweir 
1487cdf0e10cSrcweir /** Check if the bounding regions match.
1488cdf0e10cSrcweir 
1489cdf0e10cSrcweir     If the return value is sal_True, rNativeBoundingRegion
1490cdf0e10cSrcweir     contains the true bounding region covered by the control
1491cdf0e10cSrcweir     including any adornment, while rNativeContentRegion contains the area
1492cdf0e10cSrcweir     within the control that can be safely drawn into without drawing over
1493cdf0e10cSrcweir     the borders of the control.
1494cdf0e10cSrcweir 
1495cdf0e10cSrcweir     @param rControlRegion
1496cdf0e10cSrcweir     The bounding region of the control in VCL frame coordinates.
1497cdf0e10cSrcweir 
1498cdf0e10cSrcweir     @param aValue
1499cdf0e10cSrcweir     An optional value (tristate/numerical/string)
1500cdf0e10cSrcweir 
1501cdf0e10cSrcweir     @param aCaption
1502cdf0e10cSrcweir     A caption or title string (like button text etc.)
1503cdf0e10cSrcweir */
getNativeControlRegion(ControlType nType,ControlPart nPart,const Rectangle & rControlRegion,ControlState nState,const ImplControlValue &,const OUString &,Rectangle & rNativeBoundingRegion,Rectangle & rNativeContentRegion)1504cdf0e10cSrcweir sal_Bool KDESalGraphics::getNativeControlRegion( ControlType nType, ControlPart nPart,
1505cdf0e10cSrcweir 											 const Rectangle& rControlRegion, ControlState nState,
1506cdf0e10cSrcweir 											 const ImplControlValue&,
1507cdf0e10cSrcweir 											 const OUString&,
1508cdf0e10cSrcweir 											 Rectangle &rNativeBoundingRegion, Rectangle &rNativeContentRegion )
1509cdf0e10cSrcweir {
1510cdf0e10cSrcweir     sal_Bool bReturn = sal_False;
1511cdf0e10cSrcweir     QRect qBoundingRect = WidgetPainter::region2QRect( rControlRegion );
1512cdf0e10cSrcweir     QRect qRect;
1513cdf0e10cSrcweir 
1514cdf0e10cSrcweir     QWidget *pWidget = NULL;
1515cdf0e10cSrcweir     switch ( nType )
1516cdf0e10cSrcweir     {
1517cdf0e10cSrcweir 	// Metrics of the push button
1518cdf0e10cSrcweir 	case CTRL_PUSHBUTTON:
1519cdf0e10cSrcweir 	    pWidget = pWidgetPainter->pushButton( rControlRegion, ( nState & CTRL_STATE_DEFAULT ) );
1520cdf0e10cSrcweir 
1521cdf0e10cSrcweir 	    switch ( nPart )
1522cdf0e10cSrcweir 	    {
1523cdf0e10cSrcweir 		case PART_ENTIRE_CONTROL:
1524cdf0e10cSrcweir 		    qRect = qBoundingRect;
1525cdf0e10cSrcweir 
1526cdf0e10cSrcweir 		    if ( nState & CTRL_STATE_DEFAULT )
1527cdf0e10cSrcweir 		    {
1528cdf0e10cSrcweir 			int nIndicatorSize = kapp->style().pixelMetric(
1529cdf0e10cSrcweir 				QStyle::PM_ButtonDefaultIndicator, pWidget );
1530cdf0e10cSrcweir 			qBoundingRect.addCoords( -nIndicatorSize, -nIndicatorSize,
1531cdf0e10cSrcweir 				nIndicatorSize, nIndicatorSize );
1532cdf0e10cSrcweir 			bReturn = sal_True;
1533cdf0e10cSrcweir 		    }
1534cdf0e10cSrcweir 		    break;
1535cdf0e10cSrcweir 	    }
1536cdf0e10cSrcweir 	    break;
1537cdf0e10cSrcweir 
1538cdf0e10cSrcweir         // Metrics of the radio button
1539cdf0e10cSrcweir         case CTRL_RADIOBUTTON:
1540cdf0e10cSrcweir             pWidget = pWidgetPainter->radioButton( rControlRegion );
1541cdf0e10cSrcweir 
1542cdf0e10cSrcweir             if ( nPart == PART_ENTIRE_CONTROL )
1543cdf0e10cSrcweir             {
1544cdf0e10cSrcweir                 qRect.setWidth( kapp->style().pixelMetric( QStyle::PM_ExclusiveIndicatorWidth, pWidget ) );
1545cdf0e10cSrcweir                 qRect.setHeight( kapp->style().pixelMetric( QStyle::PM_ExclusiveIndicatorHeight, pWidget ) );
1546cdf0e10cSrcweir 
1547cdf0e10cSrcweir                 bReturn = sal_True;
1548cdf0e10cSrcweir             }
1549cdf0e10cSrcweir             break;
1550cdf0e10cSrcweir 
1551cdf0e10cSrcweir         // Metrics of the check box
1552cdf0e10cSrcweir         case CTRL_CHECKBOX:
1553cdf0e10cSrcweir             pWidget = pWidgetPainter->checkBox( rControlRegion );
1554cdf0e10cSrcweir 
1555cdf0e10cSrcweir             if ( nPart == PART_ENTIRE_CONTROL )
1556cdf0e10cSrcweir             {
1557cdf0e10cSrcweir                 qRect.setWidth( kapp->style().pixelMetric( QStyle::PM_IndicatorWidth, pWidget ) );
1558cdf0e10cSrcweir                 qRect.setHeight( kapp->style().pixelMetric( QStyle::PM_IndicatorHeight, pWidget ) );
1559cdf0e10cSrcweir 
1560cdf0e10cSrcweir                 bReturn = sal_True;
1561cdf0e10cSrcweir             }
1562cdf0e10cSrcweir             break;
1563cdf0e10cSrcweir 
1564cdf0e10cSrcweir 	// Metrics of the combo box
1565cdf0e10cSrcweir 	case CTRL_COMBOBOX:
1566cdf0e10cSrcweir 	case CTRL_LISTBOX:
1567cdf0e10cSrcweir 	    pWidget = pWidgetPainter->comboBox( rControlRegion, ( nType == CTRL_COMBOBOX ) );
1568cdf0e10cSrcweir 	    switch ( nPart )
1569cdf0e10cSrcweir 	    {
1570cdf0e10cSrcweir 		case PART_BUTTON_DOWN:
1571cdf0e10cSrcweir 		    qRect = kapp->style().querySubControlMetrics(
1572cdf0e10cSrcweir 			    QStyle::CC_ComboBox, pWidget, QStyle::SC_ComboBoxArrow );
1573cdf0e10cSrcweir 		    qRect.setLeft( kapp->style().querySubControlMetrics(
1574cdf0e10cSrcweir 			    QStyle::CC_ComboBox, pWidget,
1575cdf0e10cSrcweir 			    QStyle::SC_ComboBoxEditField ).right() + 1 );
1576cdf0e10cSrcweir             qRect.moveBy( qBoundingRect.left(), qBoundingRect.top() );
1577cdf0e10cSrcweir 		    bReturn = sal_True;
1578cdf0e10cSrcweir 		    break;
1579cdf0e10cSrcweir 
1580cdf0e10cSrcweir 		case PART_SUB_EDIT:
1581cdf0e10cSrcweir 		    qRect = kapp->style().querySubControlMetrics(
1582cdf0e10cSrcweir 			    QStyle::CC_ComboBox, pWidget, QStyle::SC_ComboBoxEditField );
1583cdf0e10cSrcweir             qRect.moveBy( qBoundingRect.left(), qBoundingRect.top() );
1584cdf0e10cSrcweir 		    bReturn = sal_True;
1585cdf0e10cSrcweir 		    break;
1586cdf0e10cSrcweir 	    }
1587cdf0e10cSrcweir 	    break;
1588cdf0e10cSrcweir 
1589cdf0e10cSrcweir 	// Metrics of the spin box
1590cdf0e10cSrcweir 	case CTRL_SPINBOX:
1591cdf0e10cSrcweir 	    pWidget = pWidgetPainter->spinWidget( rControlRegion );
1592cdf0e10cSrcweir 	    switch ( nPart )
1593cdf0e10cSrcweir 	    {
1594cdf0e10cSrcweir 		case PART_BUTTON_UP:
1595cdf0e10cSrcweir 		    qRect = kapp->style().querySubControlMetrics(
1596cdf0e10cSrcweir 			    QStyle::CC_SpinWidget, pWidget, QStyle::SC_SpinWidgetUp );
1597cdf0e10cSrcweir 		    bReturn = sal_True;
1598cdf0e10cSrcweir             qRect.moveBy( qBoundingRect.left(), qBoundingRect.top() );
1599cdf0e10cSrcweir 		    break;
1600cdf0e10cSrcweir 
1601cdf0e10cSrcweir 		case PART_BUTTON_DOWN:
1602cdf0e10cSrcweir 		    qRect = kapp->style().querySubControlMetrics(
1603cdf0e10cSrcweir 			    QStyle::CC_SpinWidget, pWidget, QStyle::SC_SpinWidgetDown );
1604cdf0e10cSrcweir 		    bReturn = sal_True;
1605cdf0e10cSrcweir             qRect.moveBy( qBoundingRect.left(), qBoundingRect.top() );
1606cdf0e10cSrcweir 		    break;
1607cdf0e10cSrcweir 
1608cdf0e10cSrcweir         case PART_SUB_EDIT:
1609cdf0e10cSrcweir 		    qRect = kapp->style().querySubControlMetrics(
1610cdf0e10cSrcweir 			    QStyle::CC_SpinWidget, pWidget, QStyle::SC_SpinWidgetEditField );
1611cdf0e10cSrcweir             qRect.moveBy( qBoundingRect.left(), qBoundingRect.top() );
1612cdf0e10cSrcweir 		    bReturn = sal_True;
1613cdf0e10cSrcweir 		    break;
1614cdf0e10cSrcweir 	    }
1615cdf0e10cSrcweir 	    break;
1616cdf0e10cSrcweir 
1617cdf0e10cSrcweir 	// Metrics of the scroll bar
1618cdf0e10cSrcweir 	case CTRL_SCROLLBAR:
1619cdf0e10cSrcweir 	    pWidget = pWidgetPainter->scrollBar( rControlRegion,
1620cdf0e10cSrcweir 		    ( nPart == PART_BUTTON_LEFT || nPart == PART_BUTTON_RIGHT ),
1621cdf0e10cSrcweir 		    ImplControlValue() );
1622cdf0e10cSrcweir 	    switch ( nPart )
1623cdf0e10cSrcweir 	    {
1624cdf0e10cSrcweir 		case PART_BUTTON_LEFT:
1625cdf0e10cSrcweir 		case PART_BUTTON_UP:
1626cdf0e10cSrcweir 		    qRect = kapp->style().querySubControlMetrics(
1627cdf0e10cSrcweir 			    QStyle::CC_ScrollBar, pWidget, QStyle::SC_ScrollBarSubLine );
1628cdf0e10cSrcweir 
1629cdf0e10cSrcweir 		    // Workaround for Platinum style scroll bars. It makes the
1630cdf0e10cSrcweir 		    // left/up button invisible.
1631cdf0e10cSrcweir 		    if ( nPart == PART_BUTTON_LEFT )
1632cdf0e10cSrcweir 		    {
1633cdf0e10cSrcweir 			if ( qRect.left() > kapp->style().querySubControlMetrics(
1634cdf0e10cSrcweir 				    QStyle::CC_ScrollBar, pWidget,
1635cdf0e10cSrcweir 				    QStyle::SC_ScrollBarSubPage ).left() )
1636cdf0e10cSrcweir 			{
1637cdf0e10cSrcweir 			    qRect.setLeft( 0 );
1638cdf0e10cSrcweir 			    qRect.setRight( 0 );
1639cdf0e10cSrcweir 			}
1640cdf0e10cSrcweir 		    }
1641cdf0e10cSrcweir 		    else
1642cdf0e10cSrcweir 		    {
1643cdf0e10cSrcweir 			if ( qRect.top() > kapp->style().querySubControlMetrics(
1644cdf0e10cSrcweir 				    QStyle::CC_ScrollBar, pWidget,
1645cdf0e10cSrcweir 				    QStyle::SC_ScrollBarSubPage ).top() )
1646cdf0e10cSrcweir 			{
1647cdf0e10cSrcweir 			    qRect.setTop( 0 );
1648cdf0e10cSrcweir 			    qRect.setBottom( 0 );
1649cdf0e10cSrcweir 			}
1650cdf0e10cSrcweir 		    }
1651cdf0e10cSrcweir 
1652cdf0e10cSrcweir             qRect.moveBy( qBoundingRect.left(), qBoundingRect.top() );
1653cdf0e10cSrcweir 
1654cdf0e10cSrcweir 		    bReturn = sal_True;
1655cdf0e10cSrcweir 		    break;
1656cdf0e10cSrcweir 
1657cdf0e10cSrcweir 		case PART_BUTTON_RIGHT:
1658cdf0e10cSrcweir 		case PART_BUTTON_DOWN:
1659cdf0e10cSrcweir 		    qRect = kapp->style().querySubControlMetrics(
1660cdf0e10cSrcweir 			    QStyle::CC_ScrollBar, pWidget, QStyle::SC_ScrollBarAddLine );
1661cdf0e10cSrcweir 
1662cdf0e10cSrcweir 		    // Workaround for Platinum and 3 button style scroll bars.
1663cdf0e10cSrcweir 		    // It makes the right/down button bigger.
1664cdf0e10cSrcweir 		    if ( nPart == PART_BUTTON_RIGHT )
1665cdf0e10cSrcweir 			qRect.setLeft( kapp->style().querySubControlMetrics(
1666cdf0e10cSrcweir 				    QStyle::CC_ScrollBar, pWidget,
1667cdf0e10cSrcweir 				    QStyle::SC_ScrollBarAddPage ).right() + 1 );
1668cdf0e10cSrcweir 		    else
1669cdf0e10cSrcweir 			qRect.setTop( kapp->style().querySubControlMetrics(
1670cdf0e10cSrcweir 				    QStyle::CC_ScrollBar, pWidget,
1671cdf0e10cSrcweir 				    QStyle::SC_ScrollBarAddPage ).bottom() + 1 );
1672cdf0e10cSrcweir 
1673cdf0e10cSrcweir             qRect.moveBy( qBoundingRect.left(), qBoundingRect.top() );
1674cdf0e10cSrcweir 
1675cdf0e10cSrcweir 		    bReturn = sal_True;
1676cdf0e10cSrcweir 		    break;
1677cdf0e10cSrcweir 	    }
1678cdf0e10cSrcweir             break;
1679cdf0e10cSrcweir     }
1680cdf0e10cSrcweir 
1681cdf0e10cSrcweir     // Fill rNativeBoundingRegion and rNativeContentRegion
1682cdf0e10cSrcweir     if ( bReturn )
1683cdf0e10cSrcweir     {
1684cdf0e10cSrcweir 	// Bounding region
1685cdf0e10cSrcweir 	Point aBPoint( qBoundingRect.x(), qBoundingRect.y() );
1686cdf0e10cSrcweir 	Size aBSize( qBoundingRect.width(), qBoundingRect.height() );
1687cdf0e10cSrcweir 	rNativeBoundingRegion = Rectangle( aBPoint, aBSize );
1688cdf0e10cSrcweir 
1689cdf0e10cSrcweir 	// Region of the content
1690cdf0e10cSrcweir 	Point aPoint( qRect.x(), qRect.y() );
1691cdf0e10cSrcweir 	Size  aSize( qRect.width(), qRect.height() );
1692cdf0e10cSrcweir 	rNativeContentRegion = Rectangle( aPoint, aSize );
1693cdf0e10cSrcweir     }
1694cdf0e10cSrcweir 
1695cdf0e10cSrcweir     return bReturn;
1696cdf0e10cSrcweir }
1697cdf0e10cSrcweir 
1698cdf0e10cSrcweir // -----------------------------------------------------------------------
1699cdf0e10cSrcweir // KDESalFrame implementation
1700cdf0e10cSrcweir // -----------------------------------------------------------------------
1701cdf0e10cSrcweir 
KDESalFrame(SalFrame * pParent,sal_uLong nStyle)1702cdf0e10cSrcweir KDESalFrame::KDESalFrame( SalFrame* pParent, sal_uLong nStyle ) :
1703cdf0e10cSrcweir     X11SalFrame( pParent, nStyle )
1704cdf0e10cSrcweir {
1705cdf0e10cSrcweir }
1706cdf0e10cSrcweir 
Show(sal_Bool bVisible,sal_Bool bNoActivate)1707cdf0e10cSrcweir void KDESalFrame::Show( sal_Bool bVisible, sal_Bool bNoActivate )
1708cdf0e10cSrcweir {
1709cdf0e10cSrcweir     if ( !GetParent() && ! (GetStyle() & SAL_FRAME_STYLE_INTRO) )
1710cdf0e10cSrcweir     {
1711cdf0e10cSrcweir         KDEXLib* pXLib = static_cast<KDEXLib*>(GetDisplay()->GetXLib());
1712cdf0e10cSrcweir         pXLib->doStartup();
1713cdf0e10cSrcweir     }
1714cdf0e10cSrcweir     X11SalFrame::Show( bVisible, bNoActivate );
1715cdf0e10cSrcweir }
1716cdf0e10cSrcweir 
1717cdf0e10cSrcweir /** Helper function to convert colors.
1718cdf0e10cSrcweir */
toColor(const QColor & rColor)1719cdf0e10cSrcweir static Color toColor( const QColor &rColor )
1720cdf0e10cSrcweir {
1721cdf0e10cSrcweir     return Color( rColor.red(), rColor.green(), rColor.blue() );
1722cdf0e10cSrcweir }
1723cdf0e10cSrcweir 
1724cdf0e10cSrcweir /** Helper function to read untranslated text entry from KConfig configuration repository.
1725cdf0e10cSrcweir */
readEntryUntranslated(KConfig * pConfig,const char * pKey)1726cdf0e10cSrcweir static OUString readEntryUntranslated( KConfig *pConfig, const char *pKey )
1727cdf0e10cSrcweir {
1728cdf0e10cSrcweir     return OUString::createFromAscii( pConfig->readEntryUntranslated( pKey ).ascii() );
1729cdf0e10cSrcweir }
1730cdf0e10cSrcweir 
1731cdf0e10cSrcweir /** Helper function to read color from KConfig configuration repository.
1732cdf0e10cSrcweir */
readColor(KConfig * pConfig,const char * pKey)1733cdf0e10cSrcweir static Color readColor( KConfig *pConfig, const char *pKey )
1734cdf0e10cSrcweir {
1735cdf0e10cSrcweir     return toColor( pConfig->readColorEntry( pKey ) );
1736cdf0e10cSrcweir }
1737cdf0e10cSrcweir 
1738cdf0e10cSrcweir /** Helper function to add information to Font from QFont.
1739cdf0e10cSrcweir 
1740cdf0e10cSrcweir     Mostly grabbed from the Gtk+ vclplug (salnativewidgets-gtk.cxx).
1741cdf0e10cSrcweir */
toFont(const QFont & rQFont,const::com::sun::star::lang::Locale & rLocale)1742cdf0e10cSrcweir static Font toFont( const QFont &rQFont, const ::com::sun::star::lang::Locale& rLocale )
1743cdf0e10cSrcweir {
1744cdf0e10cSrcweir     psp::FastPrintFontInfo aInfo;
1745cdf0e10cSrcweir     QFontInfo qFontInfo( rQFont );
1746cdf0e10cSrcweir 
1747cdf0e10cSrcweir     // set family name
1748cdf0e10cSrcweir     aInfo.m_aFamilyName = String( rQFont.family().utf8(), RTL_TEXTENCODING_UTF8 );
1749cdf0e10cSrcweir 
1750cdf0e10cSrcweir     // set italic
1751cdf0e10cSrcweir     aInfo.m_eItalic = ( qFontInfo.italic()? psp::italic::Italic: psp::italic::Upright );
1752cdf0e10cSrcweir 
1753cdf0e10cSrcweir     // set weight
1754cdf0e10cSrcweir     int nWeight = qFontInfo.weight();
1755cdf0e10cSrcweir     if ( nWeight <= QFont::Light )
1756cdf0e10cSrcweir         aInfo.m_eWeight = psp::weight::Light;
1757cdf0e10cSrcweir     else if ( nWeight <= QFont::Normal )
1758cdf0e10cSrcweir         aInfo.m_eWeight = psp::weight::Normal;
1759cdf0e10cSrcweir     else if ( nWeight <= QFont::DemiBold )
1760cdf0e10cSrcweir         aInfo.m_eWeight = psp::weight::SemiBold;
1761cdf0e10cSrcweir     else if ( nWeight <= QFont::Bold )
1762cdf0e10cSrcweir         aInfo.m_eWeight = psp::weight::Bold;
1763cdf0e10cSrcweir     else
1764cdf0e10cSrcweir         aInfo.m_eWeight = psp::weight::UltraBold;
1765cdf0e10cSrcweir 
1766cdf0e10cSrcweir     // set width
1767cdf0e10cSrcweir     int nStretch = rQFont.stretch();
1768cdf0e10cSrcweir     if ( nStretch <= QFont::UltraCondensed )
1769cdf0e10cSrcweir         aInfo.m_eWidth = psp::width::UltraCondensed;
1770cdf0e10cSrcweir     else if ( nStretch <= QFont::ExtraCondensed )
1771cdf0e10cSrcweir         aInfo.m_eWidth = psp::width::ExtraCondensed;
1772cdf0e10cSrcweir     else if ( nStretch <= QFont::Condensed )
1773cdf0e10cSrcweir         aInfo.m_eWidth = psp::width::Condensed;
1774cdf0e10cSrcweir     else if ( nStretch <= QFont::SemiCondensed )
1775cdf0e10cSrcweir         aInfo.m_eWidth = psp::width::SemiCondensed;
1776cdf0e10cSrcweir     else if ( nStretch <= QFont::Unstretched )
1777cdf0e10cSrcweir         aInfo.m_eWidth = psp::width::Normal;
1778cdf0e10cSrcweir     else if ( nStretch <= QFont::SemiExpanded )
1779cdf0e10cSrcweir         aInfo.m_eWidth = psp::width::SemiExpanded;
1780cdf0e10cSrcweir     else if ( nStretch <= QFont::Expanded )
1781cdf0e10cSrcweir         aInfo.m_eWidth = psp::width::Expanded;
1782cdf0e10cSrcweir     else if ( nStretch <= QFont::ExtraExpanded )
1783cdf0e10cSrcweir         aInfo.m_eWidth = psp::width::ExtraExpanded;
1784cdf0e10cSrcweir     else
1785cdf0e10cSrcweir         aInfo.m_eWidth = psp::width::UltraExpanded;
1786cdf0e10cSrcweir 
1787cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 1
1788cdf0e10cSrcweir     fprintf( stderr, "font name BEFORE system match: \"%s\"\n", OUStringToOString( aInfo.m_aFamilyName, RTL_TEXTENCODING_ISO_8859_1 ).getStr() );
1789cdf0e10cSrcweir #endif
1790cdf0e10cSrcweir 
1791cdf0e10cSrcweir     // match font to e.g. resolve "Sans"
1792cdf0e10cSrcweir     psp::PrintFontManager::get().matchFont( aInfo, rLocale );
1793cdf0e10cSrcweir 
1794cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 1
1795cdf0e10cSrcweir     fprintf( stderr, "font match %s, name AFTER: \"%s\"\n",
1796cdf0e10cSrcweir              aInfo.m_nID != 0 ? "succeeded" : "failed",
1797cdf0e10cSrcweir              OUStringToOString( aInfo.m_aFamilyName, RTL_TEXTENCODING_ISO_8859_1 ).getStr() );
1798cdf0e10cSrcweir #endif
1799cdf0e10cSrcweir 
1800cdf0e10cSrcweir     // font height
1801cdf0e10cSrcweir     int nPointHeight = qFontInfo.pointSize();
1802cdf0e10cSrcweir     if ( nPointHeight <= 0 )
1803cdf0e10cSrcweir         nPointHeight = rQFont.pointSize();
1804cdf0e10cSrcweir 
1805cdf0e10cSrcweir     // Create the font
1806cdf0e10cSrcweir     Font aFont( aInfo.m_aFamilyName, Size( 0, nPointHeight ) );
1807cdf0e10cSrcweir     if( aInfo.m_eWeight != psp::weight::Unknown )
1808cdf0e10cSrcweir         aFont.SetWeight( PspGraphics::ToFontWeight( aInfo.m_eWeight ) );
1809cdf0e10cSrcweir     if( aInfo.m_eWidth != psp::width::Unknown )
1810cdf0e10cSrcweir         aFont.SetWidthType( PspGraphics::ToFontWidth( aInfo.m_eWidth ) );
1811cdf0e10cSrcweir     if( aInfo.m_eItalic != psp::italic::Unknown )
1812cdf0e10cSrcweir         aFont.SetItalic( PspGraphics::ToFontItalic( aInfo.m_eItalic ) );
1813cdf0e10cSrcweir     if( aInfo.m_ePitch != psp::pitch::Unknown )
1814cdf0e10cSrcweir         aFont.SetPitch( PspGraphics::ToFontPitch( aInfo.m_ePitch ) );
1815cdf0e10cSrcweir 
1816cdf0e10cSrcweir     return aFont;
1817cdf0e10cSrcweir }
1818cdf0e10cSrcweir 
1819cdf0e10cSrcweir /** Implementation of KDE integration's main method.
1820cdf0e10cSrcweir */
UpdateSettings(AllSettings & rSettings)1821cdf0e10cSrcweir void KDESalFrame::UpdateSettings( AllSettings& rSettings )
1822cdf0e10cSrcweir {
1823cdf0e10cSrcweir     StyleSettings aStyleSettings( rSettings.GetStyleSettings() );
1824cdf0e10cSrcweir 	bool bSetTitleFont = false;
1825cdf0e10cSrcweir 
1826cdf0e10cSrcweir     // WM settings
1827cdf0e10cSrcweir     KConfig *pConfig = KGlobal::config();
1828cdf0e10cSrcweir     if ( pConfig )
1829cdf0e10cSrcweir     {
1830cdf0e10cSrcweir         pConfig->setGroup( "WM" );
1831cdf0e10cSrcweir         const char *pKey;
1832cdf0e10cSrcweir 
1833cdf0e10cSrcweir         pKey = "activeBackground";
1834cdf0e10cSrcweir         if ( pConfig->hasKey( pKey ) )
1835cdf0e10cSrcweir             aStyleSettings.SetActiveColor( readColor( pConfig, pKey ) );
1836cdf0e10cSrcweir 
1837cdf0e10cSrcweir         pKey = "activeBlend";
1838cdf0e10cSrcweir         if ( pConfig->hasKey( pKey ) )
1839cdf0e10cSrcweir             aStyleSettings.SetActiveColor2( readColor( pConfig, pKey ) );
1840cdf0e10cSrcweir 
1841cdf0e10cSrcweir         pKey = "inactiveBackground";
1842cdf0e10cSrcweir         if ( pConfig->hasKey( pKey ) )
1843cdf0e10cSrcweir             aStyleSettings.SetDeactiveColor( readColor( pConfig, pKey ) );
1844cdf0e10cSrcweir 
1845cdf0e10cSrcweir         pKey = "inactiveBlend";
1846cdf0e10cSrcweir         if ( pConfig->hasKey( pKey ) )
1847cdf0e10cSrcweir             aStyleSettings.SetDeactiveColor2( readColor( pConfig, pKey ) );
1848cdf0e10cSrcweir 
1849cdf0e10cSrcweir         pKey = "inactiveForeground";
1850cdf0e10cSrcweir         if ( pConfig->hasKey( pKey ) )
1851cdf0e10cSrcweir             aStyleSettings.SetDeactiveTextColor( readColor( pConfig, pKey ) );
1852cdf0e10cSrcweir 
1853cdf0e10cSrcweir         pKey = "activeForeground";
1854cdf0e10cSrcweir         if ( pConfig->hasKey( pKey ) )
1855cdf0e10cSrcweir             aStyleSettings.SetActiveTextColor( readColor( pConfig, pKey ) );
1856cdf0e10cSrcweir 
1857cdf0e10cSrcweir         pKey = "titleFont";
1858cdf0e10cSrcweir         if ( pConfig->hasKey( pKey ) )
1859cdf0e10cSrcweir         {
1860cdf0e10cSrcweir             Font aFont = toFont( pConfig->readFontEntry( pKey ), rSettings.GetUILocale() );
1861cdf0e10cSrcweir             aStyleSettings.SetTitleFont( aFont );
1862cdf0e10cSrcweir 			bSetTitleFont = true;
1863cdf0e10cSrcweir         }
1864cdf0e10cSrcweir 
1865cdf0e10cSrcweir         pConfig->setGroup( "Icons" );
1866cdf0e10cSrcweir 
1867cdf0e10cSrcweir         pKey = "Theme";
1868cdf0e10cSrcweir         if ( pConfig->hasKey( pKey ) )
1869cdf0e10cSrcweir             aStyleSettings.SetPreferredSymbolsStyleName( readEntryUntranslated( pConfig, pKey ) );
1870cdf0e10cSrcweir     }
1871cdf0e10cSrcweir 
1872cdf0e10cSrcweir     // General settings
1873cdf0e10cSrcweir     QColorGroup qColorGroup = kapp->palette().active();
1874cdf0e10cSrcweir 
1875cdf0e10cSrcweir     Color aFore = toColor( qColorGroup.foreground() );
1876cdf0e10cSrcweir     Color aBack = toColor( qColorGroup.background() );
1877cdf0e10cSrcweir     Color aText = toColor( qColorGroup.text() );
1878cdf0e10cSrcweir     Color aBase = toColor( qColorGroup.base() );
1879cdf0e10cSrcweir 
1880cdf0e10cSrcweir     // Foreground
1881cdf0e10cSrcweir     aStyleSettings.SetRadioCheckTextColor( aFore );
1882cdf0e10cSrcweir     aStyleSettings.SetLabelTextColor( aFore );
1883cdf0e10cSrcweir     aStyleSettings.SetInfoTextColor( aFore );
1884cdf0e10cSrcweir     aStyleSettings.SetDialogTextColor( aFore );
1885cdf0e10cSrcweir     aStyleSettings.SetGroupTextColor( aFore );
1886cdf0e10cSrcweir 
1887cdf0e10cSrcweir     // Text
1888cdf0e10cSrcweir     aStyleSettings.SetFieldTextColor( aText );
1889cdf0e10cSrcweir     aStyleSettings.SetFieldRolloverTextColor( aText );
1890cdf0e10cSrcweir     aStyleSettings.SetWindowTextColor( aText );
1891cdf0e10cSrcweir     aStyleSettings.SetHelpTextColor( aText );
1892cdf0e10cSrcweir 
1893cdf0e10cSrcweir     // Base
1894cdf0e10cSrcweir     aStyleSettings.SetFieldColor( aBase );
1895cdf0e10cSrcweir     aStyleSettings.SetHelpColor( aBase );
1896cdf0e10cSrcweir     aStyleSettings.SetWindowColor( aBase );
1897cdf0e10cSrcweir     aStyleSettings.SetActiveTabColor( aBase );
1898cdf0e10cSrcweir 
1899cdf0e10cSrcweir     // Buttons
1900cdf0e10cSrcweir     aStyleSettings.SetButtonTextColor( toColor( qColorGroup.buttonText() ) );
1901cdf0e10cSrcweir     aStyleSettings.SetButtonRolloverTextColor( toColor( qColorGroup.buttonText() ) );
1902cdf0e10cSrcweir 
1903cdf0e10cSrcweir     // Disable color
1904cdf0e10cSrcweir     aStyleSettings.SetDisableColor( toColor( qColorGroup.mid() ) );
1905cdf0e10cSrcweir 
1906cdf0e10cSrcweir     // Workspace
1907cdf0e10cSrcweir     aStyleSettings.SetWorkspaceColor( toColor( qColorGroup.mid() ) );
1908cdf0e10cSrcweir 
1909cdf0e10cSrcweir     // Background
1910cdf0e10cSrcweir     aStyleSettings.Set3DColors( aBack );
1911cdf0e10cSrcweir     aStyleSettings.SetFaceColor( aBack );
1912cdf0e10cSrcweir     aStyleSettings.SetInactiveTabColor( aBack );
1913cdf0e10cSrcweir     aStyleSettings.SetDialogColor( aBack );
1914cdf0e10cSrcweir     if( aBack == COL_LIGHTGRAY )
1915cdf0e10cSrcweir         aStyleSettings.SetCheckedColor( Color( 0xCC, 0xCC, 0xCC ) );
1916cdf0e10cSrcweir     else
1917cdf0e10cSrcweir     {
1918cdf0e10cSrcweir         Color aColor2 = aStyleSettings.GetLightColor();
1919cdf0e10cSrcweir         aStyleSettings.
1920cdf0e10cSrcweir             SetCheckedColor( Color( (sal_uInt8)(((sal_uInt16)aBack.GetRed()+(sal_uInt16)aColor2.GetRed())/2),
1921cdf0e10cSrcweir                         (sal_uInt8)(((sal_uInt16)aBack.GetGreen()+(sal_uInt16)aColor2.GetGreen())/2),
1922cdf0e10cSrcweir                         (sal_uInt8)(((sal_uInt16)aBack.GetBlue()+(sal_uInt16)aColor2.GetBlue())/2)
1923cdf0e10cSrcweir                         ) );
1924cdf0e10cSrcweir     }
1925cdf0e10cSrcweir 
1926cdf0e10cSrcweir     // Selection
1927cdf0e10cSrcweir     aStyleSettings.SetHighlightColor( toColor( qColorGroup.highlight() ) );
1928cdf0e10cSrcweir     aStyleSettings.SetHighlightTextColor( toColor( qColorGroup.highlightedText() ) );
1929cdf0e10cSrcweir 
1930cdf0e10cSrcweir     // Font
1931cdf0e10cSrcweir     Font aFont = toFont( kapp->font(), rSettings.GetUILocale() );
1932cdf0e10cSrcweir 
1933cdf0e10cSrcweir     aStyleSettings.SetAppFont( aFont );
1934cdf0e10cSrcweir     aStyleSettings.SetHelpFont( aFont );
1935cdf0e10cSrcweir 	if( !bSetTitleFont )
1936cdf0e10cSrcweir 		aStyleSettings.SetTitleFont( aFont );
1937cdf0e10cSrcweir 	aStyleSettings.SetFloatTitleFont( aFont );
1938cdf0e10cSrcweir     aStyleSettings.SetMenuFont( aFont ); // will be changed according to pMenuBar
1939cdf0e10cSrcweir     aStyleSettings.SetToolFont( aFont ); // will be changed according to pToolBar
1940cdf0e10cSrcweir     aStyleSettings.SetLabelFont( aFont );
1941cdf0e10cSrcweir     aStyleSettings.SetInfoFont( aFont );
1942cdf0e10cSrcweir     aStyleSettings.SetRadioCheckFont( aFont );
1943cdf0e10cSrcweir     aStyleSettings.SetPushButtonFont( aFont );
1944cdf0e10cSrcweir     aStyleSettings.SetFieldFont( aFont );
1945cdf0e10cSrcweir     aStyleSettings.SetIconFont( aFont );
1946cdf0e10cSrcweir     aStyleSettings.SetGroupFont( aFont );
1947cdf0e10cSrcweir     int flash_time = QApplication::cursorFlashTime();
1948cdf0e10cSrcweir     aStyleSettings.SetCursorBlinkTime( flash_time != 0 ? flash_time/2 : STYLE_CURSOR_NOBLINKTIME );
1949cdf0e10cSrcweir 
1950cdf0e10cSrcweir     KMainWindow qMainWindow;
1951cdf0e10cSrcweir     qMainWindow.createGUI( "/dev/null" ); // hack
1952cdf0e10cSrcweir 
1953cdf0e10cSrcweir     // Menu
1954cdf0e10cSrcweir     aStyleSettings.SetSkipDisabledInMenus( sal_True );
1955cdf0e10cSrcweir     KMenuBar *pMenuBar = qMainWindow.menuBar();
1956cdf0e10cSrcweir     if ( pMenuBar )
1957cdf0e10cSrcweir     {
1958cdf0e10cSrcweir         // Color
1959cdf0e10cSrcweir         QColorGroup qMenuCG = pMenuBar->colorGroup();
1960cdf0e10cSrcweir 
1961cdf0e10cSrcweir         // Menu text and background color, theme specific
1962cdf0e10cSrcweir         Color aMenuFore = toColor( qMenuCG.foreground() );
1963cdf0e10cSrcweir         Color aMenuBack = toColor( qMenuCG.background() );
1964cdf0e10cSrcweir         if ( kapp->style().inherits( "LightStyleV2" ) ||
1965cdf0e10cSrcweir              kapp->style().inherits( "LightStyleV3" ) ||
1966cdf0e10cSrcweir              ( kapp->style().inherits( "QMotifStyle" ) && !kapp->style().inherits( "QSGIStyle" ) ) ||
1967cdf0e10cSrcweir              kapp->style().inherits( "QWindowsStyle" ) )
1968cdf0e10cSrcweir         {
1969cdf0e10cSrcweir             aMenuFore = toColor( qMenuCG.buttonText() );
1970cdf0e10cSrcweir             aMenuBack = toColor( qMenuCG.button() );
1971cdf0e10cSrcweir         }
1972cdf0e10cSrcweir 
1973cdf0e10cSrcweir         aStyleSettings.SetMenuTextColor( aMenuFore );
1974cdf0e10cSrcweir         aStyleSettings.SetMenuBarTextColor( aMenuFore );
1975cdf0e10cSrcweir         aStyleSettings.SetMenuColor( aMenuBack );
1976cdf0e10cSrcweir         aStyleSettings.SetMenuBarColor( aMenuBack );
1977cdf0e10cSrcweir 
1978cdf0e10cSrcweir         aStyleSettings.SetMenuHighlightColor( toColor ( qMenuCG.highlight() ) );
1979cdf0e10cSrcweir 
1980cdf0e10cSrcweir         // Menu items higlight text color, theme specific
1981cdf0e10cSrcweir         if ( kapp->style().inherits( "HighContrastStyle" ) ||
1982cdf0e10cSrcweir              kapp->style().inherits( "KeramikStyle" ) ||
1983cdf0e10cSrcweir              kapp->style().inherits( "QWindowsStyle" ) ||
1984cdf0e10cSrcweir              kapp->style().inherits( "ThinKeramikStyle" ) ||
1985cdf0e10cSrcweir              kapp->style().inherits( "PlastikStyle" ) )
1986cdf0e10cSrcweir         {
1987cdf0e10cSrcweir             aStyleSettings.SetMenuHighlightTextColor( toColor ( qMenuCG.highlightedText() ) );
1988cdf0e10cSrcweir         }
1989cdf0e10cSrcweir         else
1990cdf0e10cSrcweir             aStyleSettings.SetMenuHighlightTextColor( aMenuFore );
1991cdf0e10cSrcweir 
1992cdf0e10cSrcweir         // set special menubar higlight text color
1993cdf0e10cSrcweir         if ( kapp->style().inherits( "HighContrastStyle" ) )
1994cdf0e10cSrcweir             ImplGetSVData()->maNWFData.maMenuBarHighlightTextColor = toColor( qMenuCG.highlightedText() );
1995cdf0e10cSrcweir         else
1996cdf0e10cSrcweir             ImplGetSVData()->maNWFData.maMenuBarHighlightTextColor = aMenuFore;
1997cdf0e10cSrcweir 
1998cdf0e10cSrcweir         // Font
1999cdf0e10cSrcweir         aFont = toFont( pMenuBar->font(), rSettings.GetUILocale() );
2000cdf0e10cSrcweir         aStyleSettings.SetMenuFont( aFont );
2001cdf0e10cSrcweir     }
2002cdf0e10cSrcweir 
2003cdf0e10cSrcweir     // Tool bar
2004cdf0e10cSrcweir     KToolBar *pToolBar = qMainWindow.toolBar();
2005cdf0e10cSrcweir     if ( pToolBar )
2006cdf0e10cSrcweir     {
2007cdf0e10cSrcweir         aFont = toFont( pToolBar->font(), rSettings.GetUILocale() );
2008cdf0e10cSrcweir         aStyleSettings.SetToolFont( aFont );
2009cdf0e10cSrcweir     }
2010cdf0e10cSrcweir 
2011cdf0e10cSrcweir     // Scroll bar size
2012cdf0e10cSrcweir     aStyleSettings.SetScrollBarSize( kapp->style().pixelMetric( QStyle::PM_ScrollBarExtent ) );
2013cdf0e10cSrcweir 
2014cdf0e10cSrcweir     rSettings.SetStyleSettings( aStyleSettings );
2015cdf0e10cSrcweir }
2016cdf0e10cSrcweir 
GetGraphics()2017cdf0e10cSrcweir SalGraphics* KDESalFrame::GetGraphics()
2018cdf0e10cSrcweir {
2019cdf0e10cSrcweir     if( GetWindow() )
2020cdf0e10cSrcweir     {
2021cdf0e10cSrcweir         for( int i = 0; i < nMaxGraphics; i++ )
2022cdf0e10cSrcweir         {
2023cdf0e10cSrcweir             if( ! m_aGraphics[i].bInUse )
2024cdf0e10cSrcweir             {
2025cdf0e10cSrcweir                 m_aGraphics[i].bInUse = true;
2026cdf0e10cSrcweir                 if( ! m_aGraphics[i].pGraphics )
2027cdf0e10cSrcweir                 {
2028cdf0e10cSrcweir                     m_aGraphics[i].pGraphics = new KDESalGraphics();
2029cdf0e10cSrcweir                     m_aGraphics[i].pGraphics->Init( this, GetWindow(), GetScreenNumber() );
2030cdf0e10cSrcweir                 }
2031cdf0e10cSrcweir                 return m_aGraphics[i].pGraphics;
2032cdf0e10cSrcweir             }
2033cdf0e10cSrcweir         }
2034cdf0e10cSrcweir     }
2035cdf0e10cSrcweir 
2036cdf0e10cSrcweir     return NULL;
2037cdf0e10cSrcweir }
2038cdf0e10cSrcweir 
ReleaseGraphics(SalGraphics * pGraphics)2039cdf0e10cSrcweir void KDESalFrame::ReleaseGraphics( SalGraphics *pGraphics )
2040cdf0e10cSrcweir {
2041cdf0e10cSrcweir     for( int i = 0; i < nMaxGraphics; i++ )
2042cdf0e10cSrcweir     {
2043cdf0e10cSrcweir         if( m_aGraphics[i].pGraphics == pGraphics )
2044cdf0e10cSrcweir         {
2045cdf0e10cSrcweir             m_aGraphics[i].bInUse = false;
2046cdf0e10cSrcweir             break;
2047cdf0e10cSrcweir         }
2048cdf0e10cSrcweir     }
2049cdf0e10cSrcweir }
2050cdf0e10cSrcweir 
updateGraphics(bool bClear)2051cdf0e10cSrcweir void KDESalFrame::updateGraphics( bool bClear )
2052cdf0e10cSrcweir {
2053cdf0e10cSrcweir     Drawable aDrawable = bClear ? None : GetWindow();
2054cdf0e10cSrcweir     for( int i = 0; i < nMaxGraphics; i++ )
2055cdf0e10cSrcweir     {
2056cdf0e10cSrcweir         if( m_aGraphics[i].bInUse )
2057cdf0e10cSrcweir             m_aGraphics[i].pGraphics->SetDrawable( aDrawable, GetScreenNumber() );
2058cdf0e10cSrcweir     }
2059cdf0e10cSrcweir }
2060cdf0e10cSrcweir 
~KDESalFrame()2061cdf0e10cSrcweir KDESalFrame::~KDESalFrame()
2062cdf0e10cSrcweir {
2063cdf0e10cSrcweir }
2064cdf0e10cSrcweir 
~GraphicsHolder()2065cdf0e10cSrcweir KDESalFrame::GraphicsHolder::~GraphicsHolder()
2066cdf0e10cSrcweir {
2067cdf0e10cSrcweir 	delete pGraphics;
2068cdf0e10cSrcweir }
2069cdf0e10cSrcweir 
2070cdf0e10cSrcweir // -----------------------------------------------------------------------
2071cdf0e10cSrcweir // KDESalInstance implementation
2072cdf0e10cSrcweir // -----------------------------------------------------------------------
2073cdf0e10cSrcweir 
2074cdf0e10cSrcweir SalFrame *
CreateFrame(SalFrame * pParent,sal_uLong nStyle)2075cdf0e10cSrcweir KDESalInstance::CreateFrame( SalFrame *pParent, sal_uLong nStyle )
2076cdf0e10cSrcweir {
2077cdf0e10cSrcweir 	return new KDESalFrame( pParent, nStyle );
2078cdf0e10cSrcweir }
2079cdf0e10cSrcweir 
2080cdf0e10cSrcweir // -----------------------------------------------------------------------
2081cdf0e10cSrcweir // KDESalData pieces
2082cdf0e10cSrcweir // -----------------------------------------------------------------------
2083cdf0e10cSrcweir 
2084cdf0e10cSrcweir // Create the widget painter so we have some control over
2085cdf0e10cSrcweir // the destruction sequence, so Qt doesn't die in action.
2086cdf0e10cSrcweir 
initNWF()2087cdf0e10cSrcweir void KDEData::initNWF()
2088cdf0e10cSrcweir {
2089cdf0e10cSrcweir     ImplSVData *pSVData = ImplGetSVData();
2090cdf0e10cSrcweir     // draw toolbars on separate lines
2091cdf0e10cSrcweir     pSVData->maNWFData.mbDockingAreaSeparateTB = true;
2092cdf0e10cSrcweir 
2093cdf0e10cSrcweir     pWidgetPainter = new WidgetPainter();
2094cdf0e10cSrcweir }
2095cdf0e10cSrcweir 
deInitNWF()2096cdf0e10cSrcweir void KDEData::deInitNWF()
2097cdf0e10cSrcweir {
2098cdf0e10cSrcweir     delete pWidgetPainter;
2099cdf0e10cSrcweir     pWidgetPainter = NULL;
2100cdf0e10cSrcweir 
2101cdf0e10cSrcweir     // We have to destroy the style early
2102cdf0e10cSrcweir     kapp->setStyle( NULL );
2103cdf0e10cSrcweir }
2104