summaryrefslogtreecommitdiff
path: root/vcl/unx/kde4/KDESalGraphics.cxx
blob: 2e8f0dcad96b894bd188f7336dad9e971cc87cf1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
/*************************************************************************
 *
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * Copyright 2009 by Sun Microsystems, Inc.
 *
 * OpenOffice.org - a multi-platform office productivity suite
 *
 * This file is part of OpenOffice.org.
 *
 * OpenOffice.org is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License version 3
 * only, as published by the Free Software Foundation.
 *
 * OpenOffice.org is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License version 3 for more details
 * (a copy is included in the LICENSE file that accompanied this code).
 *
 * You should have received a copy of the GNU Lesser General Public License
 * version 3 along with OpenOffice.org.  If not, see
 * <http://www.openoffice.org/license.html>
 * for a copy of the LGPLv3 License.
 *
 ************************************************************************/

// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_vcl.hxx"

#define _SV_SALNATIVEWIDGETS_KDE_CXX

#define Region QtXRegion

#include <QStyle>
#include <QStyleOption>
#include <QPainter>
#include <QFrame>
#include <QLabel>

#include <kapplication.h>

#undef Region

#include "KDESalGraphics.hxx"

#include "vcl/settings.hxx"
#include "vcl/decoview.hxx"
#include "rtl/ustrbuf.hxx"

using namespace ::rtl;

/**
  Conversion function between VCL ControlState together with
  ImplControlValue and Qt state flags.
  @param nControlState State of the widget (default, focused, ...) in Native Widget Framework.
  @param aValue Value held by the widget (on, off, ...)
*/
QStyle::State vclStateValue2StateFlag( ControlState nControlState,
    const ImplControlValue& aValue )
{
    QStyle::State nState =
        ( (nControlState & CTRL_STATE_DEFAULT)?  QStyle::State_None:      QStyle::State_None ) |
        ( (nControlState & CTRL_STATE_ENABLED)?  QStyle::State_Enabled:   QStyle::State_None ) |
        ( (nControlState & CTRL_STATE_FOCUSED)?  QStyle::State_HasFocus:  QStyle::State_None ) |
        ( (nControlState & CTRL_STATE_PRESSED)?  QStyle::State_Sunken:    QStyle::State_None ) |
        ( (nControlState & CTRL_STATE_SELECTED)? QStyle::State_Selected : QStyle::State_None ) |
        ( (nControlState & CTRL_STATE_ROLLOVER)? QStyle::State_MouseOver: QStyle::State_None );
        //TODO ( (nControlState & CTRL_STATE_HIDDEN)?   QStyle::State_:   QStyle::State_None ) |

    switch ( aValue.getTristateVal() )
    {
        case BUTTONVALUE_ON:    nState |= QStyle::State_On;       break;
        case BUTTONVALUE_OFF:   nState |= QStyle::State_Off;      break;
        case BUTTONVALUE_MIXED: nState |= QStyle::State_NoChange; break;
        default: break;
    }

    return nState;
}

/**
 Convert VCL Region to QRect.
 @param rControlRegion The region to convert.
 @return The bounding box of the region.
*/
QRect region2QRect( const Region& rControlRegion )
{
    Rectangle aRect = rControlRegion.GetBoundRect();

    return QRect( QPoint( aRect.Left(), aRect.Top() ),
          QPoint( aRect.Right(), aRect.Bottom() ) );
}

BOOL KDESalGraphics::IsNativeControlSupported( ControlType type, ControlPart part )
{
    if (type == CTRL_PUSHBUTTON) return true;

    if (type == CTRL_MENUBAR) return true;

    if (type == CTRL_MENU_POPUP) return true;

    if (type == CTRL_EDITBOX) return true;

    if (type == CTRL_COMBOBOX) return true;

    if (type == CTRL_TOOLBAR) return true;

    if (type == CTRL_CHECKBOX) return true;

    if (type == CTRL_LISTBOX) return true;

    if (type == CTRL_LISTNODE) return true;

    if (type == CTRL_FRAME) return true;

    if (type == CTRL_SCROLLBAR) return true;

    if (type == CTRL_WINDOW_BACKGROUND) return true;

    if (type == CTRL_SPINBOX && (part == PART_ENTIRE_CONTROL || part == HAS_BACKGROUND_TEXTURE) ) return true;

    // no spinbuttons for KDE, paint spinbox complete
    //if (type == CTRL_SPINBUTTONS) return true;

    if (type == CTRL_GROUPBOX) return true;

    if (type == CTRL_FIXEDLINE) return true;

    if (type == CTRL_FIXEDBORDER) return true;

    if (type == CTRL_TOOLTIP) return true;

    if (type == CTRL_RADIOBUTTON) return true;

    return false;

    if ( (type == CTRL_TAB_ITEM) && (part == PART_ENTIRE_CONTROL) ) return true;
    if ( (type == CTRL_TAB_PANE) && (part == PART_ENTIRE_CONTROL) ) return true;
    // no CTRL_TAB_BODY for KDE
    if ( (type == CTRL_PROGRESS)    && (part == PART_ENTIRE_CONTROL) ) return true;

    return false;
}


BOOL KDESalGraphics::hitTestNativeControl( ControlType, ControlPart,
                                           const Region&, const Point&,
                                           SalControlHandle&, BOOL& )
{
    return FALSE;
}

void lcl_drawFrame( QRect& i_rRect, QPainter& i_rPainter, QStyle::PrimitiveElement i_nElement,
                    ControlState i_nState, const ImplControlValue& i_rValue )
{
    #if ( QT_VERSION >= QT_VERSION_CHECK( 4, 5, 0 ) )
    QStyleOptionFrameV3 styleOption;
    styleOption.frameShape = QFrame::StyledPanel;
    #else
    QStyleOptionFrame styleOption;
    QFrame aFrame( NULL );
    aFrame.setFrameRect( QRect(0, 0, i_rRect.width(), i_rRect.height()) );
    aFrame.setFrameStyle( QFrame::StyledPanel | QFrame::Sunken );
    aFrame.ensurePolished();
    styleOption.initFrom( &aFrame );
    styleOption.lineWidth = aFrame.lineWidth();
    styleOption.midLineWidth = aFrame.midLineWidth();
    #endif
    styleOption.rect = QRect(0, 0, i_rRect.width(), i_rRect.height());
    styleOption.state = vclStateValue2StateFlag( i_nState, i_rValue );
    #if ( QT_VERSION < QT_VERSION_CHECK( 4, 5, 0 ) )
    styleOption.state |= QStyle::State_Sunken;
    #endif
    kapp->style()->drawPrimitive(i_nElement, &styleOption, &i_rPainter);
}

BOOL KDESalGraphics::drawNativeControl( ControlType type, ControlPart part,
                                        const Region& rControlRegion, ControlState nControlState,
                                        const ImplControlValue& value, SalControlHandle&,
                                        const OUString& )
{
    // put not implemented types here
    if (type == CTRL_SPINBUTTONS)
    {
        return false;
    }

    BOOL returnVal = true;

    Display* dpy = GetXDisplay();
    XLIB_Window drawable = GetDrawable();
    GC gc = SelectPen();

    QRect widgetRect = region2QRect(rControlRegion);
    if( type == CTRL_SPINBOX && part == PART_ALL_BUTTONS )
        type = CTRL_SPINBUTTONS;
    if( type == CTRL_SPINBUTTONS )
    {
        SpinbuttonValue* pSpinVal = (SpinbuttonValue *)(value.getOptionalVal());
        Rectangle aButtonRect( pSpinVal->maUpperRect);
        aButtonRect.Union( pSpinVal->maLowerRect );;
        widgetRect = QRect( aButtonRect.Left(), aButtonRect.Top(),
                            aButtonRect.Right(), aButtonRect.Bottom() );
    }

    //draw right onto the window
    QPixmap pixmap(widgetRect.width(), widgetRect.height());

    if (pixmap.isNull())
    {
        return false;
    }

    QPainter painter(&pixmap);
    // painter.setBackgroundMode(Qt::OpaqueMode);

    //copy previous screen contents for proper blending
    #if ( QT_VERSION >= QT_VERSION_CHECK( 4, 5, 0 ) )
    QPixmap screen = QPixmap::fromX11Pixmap(drawable);
    painter.drawPixmap(0,0, screen, widgetRect.left(), widgetRect.top(), widgetRect.width(), widgetRect.height());
    #else
    const QX11Info& rX11Info( pixmap.x11Info() );
    X11SalGraphics::CopyScreenArea( dpy,
                              drawable, GetScreenNumber(), GetBitCount(),
                              pixmap.handle(), rX11Info.screen(), rX11Info.depth(),
                              GetDisplay()->GetCopyGC( GetScreenNumber() ),
                              widgetRect.left(), widgetRect.top(), widgetRect.width(), widgetRect.height(),
                              0, 0 );
    #endif

    if (type == CTRL_PUSHBUTTON)
    {
        QStyleOptionButton styleOption;

        styleOption.rect = QRect(0, 0, widgetRect.width(), widgetRect.height());
        styleOption.state =vclStateValue2StateFlag( nControlState, value );

        kapp->style()->drawControl( QStyle::CE_PushButton, &styleOption, &painter);
    }
    else if ( (type == CTRL_MENUBAR))
    {
        if (part == PART_MENU_ITEM)
        {
            QStyleOptionMenuItem styleOption;

            styleOption.rect = QRect(0, 0, widgetRect.width(), widgetRect.height());
            styleOption.state = vclStateValue2StateFlag( nControlState, value );

            kapp->style()->drawControl( QStyle::CE_MenuBarItem, &styleOption, &painter);
        }
        else
        {
            pixmap.fill(KApplication::palette().color(QPalette::Window));
        }
    }
    else if (type == CTRL_MENU_POPUP)
    {
        if (part == PART_MENU_ITEM)
        {
            QStyleOptionMenuItem styleOption;

            styleOption.rect = QRect(0, 0, widgetRect.width(), widgetRect.height());
            styleOption.state = vclStateValue2StateFlag( nControlState, value );

            kapp->style()->drawControl( QStyle::CE_MenuItem, &styleOption, &painter);
        }
        else if (part == PART_MENU_ITEM_CHECK_MARK)
        {
            QStyleOptionButton styleOption;

            styleOption.rect = QRect(0, 0, widgetRect.width(), widgetRect.height());
            styleOption.state = vclStateValue2StateFlag( nControlState, value );

            if (nControlState & CTRL_STATE_PRESSED)
            {
                kapp->style()->drawPrimitive( QStyle::PE_IndicatorMenuCheckMark, &styleOption, &painter);
            }
        }
        else if (part == PART_MENU_ITEM_RADIO_MARK)
        {
            QStyleOptionButton styleOption;

            styleOption.rect = QRect(0, 0, widgetRect.width(), widgetRect.height());
            styleOption.state = vclStateValue2StateFlag( nControlState, value );

            if (nControlState & CTRL_STATE_PRESSED)
            {
                kapp->style()->drawPrimitive( QStyle::PE_IndicatorRadioButton, &styleOption, &painter);
            }
        }
        else
        {
            pixmap.fill(KApplication::palette().color(QPalette::Window));

            #if ( QT_VERSION >= QT_VERSION_CHECK( 4, 5, 0 ) )
            QStyleOptionFrameV3 styleOption;
            #else
            QStyleOptionFrameV2 styleOption;
            #endif

            styleOption.rect = QRect(0, 0, widgetRect.width(), widgetRect.height());
            styleOption.state = vclStateValue2StateFlag( nControlState, value );
            #if ( QT_VERSION >= QT_VERSION_CHECK( 4, 5, 0 ) )
            styleOption.frameShape = QFrame::StyledPanel;
            #endif

            kapp->style()->drawPrimitive( QStyle::PE_FrameMenu, &styleOption, &painter);
        }
    }
    else if ( (type == CTRL_TOOLBAR) && (part == PART_BUTTON) )
    {
        QStyleOptionToolButton styleOption;

        styleOption.arrowType = Qt::NoArrow;
        styleOption.subControls = QStyle::SC_ToolButton;

        styleOption.rect = QRect(0, 0, widgetRect.width(), widgetRect.height());
        styleOption.state = vclStateValue2StateFlag( nControlState, value );
        styleOption.state |= QStyle::State_Raised | QStyle::State_Enabled | QStyle::State_AutoRaise;

        kapp->style()->drawComplexControl( QStyle::CC_ToolButton, &styleOption, &painter);
    }
    else if ( (type == CTRL_TOOLBAR) && (part == PART_ENTIRE_CONTROL) )
    {
        QStyleOptionToolBar styleOption;

        styleOption.rect = QRect(0, 0, widgetRect.width(), widgetRect.height());
        styleOption.state = vclStateValue2StateFlag( nControlState, value );

        kapp->style()->drawControl( QStyle::CE_ToolBar, &styleOption, &painter);
    }
    else if ( (type == CTRL_TOOLBAR) && (part == PART_THUMB_VERT) )
    {
        QStyleOption styleOption;

        int width = kapp->style()->pixelMetric(QStyle::PM_ToolBarHandleExtent);

        styleOption.rect = QRect(0, 0, width, widgetRect.height());
        styleOption.state = QStyle::State_Horizontal;

        kapp->style()->drawPrimitive( QStyle::PE_IndicatorToolBarHandle, &styleOption, &painter);
    }
    else if (type == CTRL_EDITBOX)
    {
        pixmap.fill(KApplication::palette().color(QPalette::Window));

        //TODO hover?? OO does not seem to do this for line edits

        #if ( QT_VERSION >= QT_VERSION_CHECK( 4, 5, 0 ) )
        QStyleOptionFrameV3 styleOption;
        #else
        QStyleOptionFrameV2 styleOption;
        #endif

        styleOption.state = vclStateValue2StateFlag( nControlState, value );

        //TODO...how does the line edit draw itself internally??
        styleOption.rect = QRect(2, 2, widgetRect.width()-4, widgetRect.height()-4);
        kapp->style()->drawPrimitive( QStyle::PE_PanelLineEdit, &styleOption, &painter);

        styleOption.rect = QRect(0, 0, widgetRect.width(), widgetRect.height());
        kapp->style()->drawPrimitive( QStyle::PE_FrameLineEdit, &styleOption, &painter);
    }
    else if (type == CTRL_COMBOBOX)
    {
        pixmap.fill(KApplication::palette().color(QPalette::Window));

        QStyleOptionComboBox styleOption;

        styleOption.rect = QRect(0, 0, widgetRect.width(), widgetRect.height());
        styleOption.state = vclStateValue2StateFlag( nControlState, value );

        styleOption.editable = true;

        kapp->style()->drawComplexControl(QStyle::CC_ComboBox, &styleOption, &painter);
    }
    else if (type == CTRL_LISTBOX)
    {
        if( part == PART_WINDOW )
        {
            lcl_drawFrame( widgetRect, painter, QStyle::PE_Frame, nControlState, value );
        }
        else
        {
            QStyleOptionComboBox styleOption;

            styleOption.rect = QRect(0, 0, widgetRect.width(), widgetRect.height());
            styleOption.state = vclStateValue2StateFlag( nControlState, value );

            if (part == PART_SUB_EDIT)
            {
                kapp->style()->drawControl(QStyle::CE_ComboBoxLabel, &styleOption, &painter);
            }
            else
            {
                kapp->style()->drawComplexControl(QStyle::CC_ComboBox, &styleOption, &painter);
            }
        }
    }
    else if (type == CTRL_LISTNODE)
    {
        QStyleOption styleOption;

        styleOption.rect = QRect(0, 0, widgetRect.width(), widgetRect.height());
        styleOption.state = vclStateValue2StateFlag( nControlState, value );

        styleOption.state |= QStyle::State_Item;
        styleOption.state |= QStyle::State_Children;

        if (nControlState & CTRL_STATE_PRESSED)
        {
            styleOption.state |= QStyle::State_Open;
        }

        kapp->style()->drawPrimitive(QStyle::PE_IndicatorBranch, &styleOption, &painter);
    }
    else if (type == CTRL_CHECKBOX)
    {
        QStyleOptionButton styleOption;

        styleOption.rect = QRect(0, 0, widgetRect.width(), widgetRect.height());
        styleOption.state = vclStateValue2StateFlag( nControlState, value );

        kapp->style()->drawControl(QStyle::CE_CheckBox, &styleOption, &painter);
    }
    else if (type == CTRL_SCROLLBAR)
    {
        pixmap.fill(KApplication::palette().color(QPalette::Window));

        if ((part == PART_DRAW_BACKGROUND_VERT) || (part == PART_DRAW_BACKGROUND_HORZ))
        {
            ScrollbarValue* sbVal = static_cast<ScrollbarValue *> ( value.getOptionalVal() );

            QStyleOptionSlider styleOption;
            styleOption.rect = QRect(0, 0, widgetRect.width(), widgetRect.height());

            //if the scroll bar is active (aka not degenrate...allow for hover events
            if (sbVal->mnVisibleSize < sbVal->mnMax)
            {
                styleOption.state = vclStateValue2StateFlag( nControlState, value );
                styleOption.state |= QStyle::State_MouseOver;
            }

            //horizontal or vertical
            if (part == PART_DRAW_BACKGROUND_VERT)
            {
                styleOption.orientation = Qt::Vertical;
            }
            else
            {
                styleOption.state |= QStyle::State_Horizontal;
            }

            //setup parameters from the OO values
            styleOption.minimum = sbVal->mnMin;
            styleOption.maximum = sbVal->mnMax - sbVal->mnVisibleSize;
            styleOption.sliderValue = sbVal->mnCur;
            styleOption.sliderPosition = sbVal->mnCur;
            styleOption.pageStep = sbVal->mnVisibleSize;

            //setup the active control...always the slider
            if (sbVal->mnThumbState & CTRL_STATE_ROLLOVER)
            {
                styleOption.activeSubControls = QStyle::SC_ScrollBarSlider;
            }

            kapp->style()->drawComplexControl(QStyle::CC_ScrollBar, &styleOption, &painter);
        }
    }
    else if (type == CTRL_SPINBOX)
    {
        pixmap.fill(KApplication::palette().color(QPalette::Window));

        QStyleOptionSpinBox styleOption;
        styleOption.rect = QRect(0, 0, widgetRect.width(), widgetRect.height());
        styleOption.state = vclStateValue2StateFlag( nControlState, value );
        // determine active control
        SpinbuttonValue* pSpinVal = (SpinbuttonValue *)(value.getOptionalVal());
        if( pSpinVal )
        {
            if( (pSpinVal->mnUpperState & CTRL_STATE_PRESSED) )
                styleOption.activeSubControls |= QStyle::SC_SpinBoxUp;
            if( (pSpinVal->mnLowerState & CTRL_STATE_PRESSED) )
                styleOption.activeSubControls |= QStyle::SC_SpinBoxDown;
        }

        kapp->style()->drawComplexControl(QStyle::CC_SpinBox, &styleOption, &painter);
    }
    else if (type == CTRL_GROUPBOX)
    {
        QStyleOptionGroupBox styleOption;
        styleOption.rect = QRect(0, 0, widgetRect.width(), widgetRect.height());
        styleOption.state = vclStateValue2StateFlag( nControlState, value );

        kapp->style()->drawComplexControl(QStyle::CC_GroupBox, &styleOption, &painter);
    }
    else if (type == CTRL_RADIOBUTTON)
    {
        QStyleOptionButton styleOption;
        styleOption.rect = QRect(0, 0, widgetRect.width(), widgetRect.height());
        styleOption.state = vclStateValue2StateFlag( nControlState, value );

        kapp->style()->drawControl(QStyle::CE_RadioButton, &styleOption, &painter);
    }
    else if (type == CTRL_TOOLTIP)
    {
        QStyleOption styleOption;
        styleOption.rect = QRect(0, 0, widgetRect.width(), widgetRect.height());
        styleOption.state = vclStateValue2StateFlag( nControlState, value );

        kapp->style()->drawPrimitive(QStyle::PE_PanelTipLabel, &styleOption, &painter);
    }
    else if (type == CTRL_FRAME)
    {
        lcl_drawFrame( widgetRect, painter, QStyle::PE_Frame, nControlState, value );
    }
    else if (type == CTRL_FIXEDBORDER)
    {
        lcl_drawFrame( widgetRect, painter, QStyle::PE_FrameWindow, nControlState, value );
    }
    else if (type == CTRL_WINDOW_BACKGROUND)
    {
        pixmap.fill(KApplication::palette().color(QPalette::Window));
    }
    else if (type == CTRL_FIXEDLINE)
    {
        QStyleOptionMenuItem styleOption;

        styleOption.rect = QRect(0, 0, widgetRect.width(), widgetRect.height());
        styleOption.state = vclStateValue2StateFlag( nControlState, value );
        styleOption.menuItemType = QStyleOptionMenuItem::Separator;
        styleOption.state |= QStyle::State_Item;

        kapp->style()->drawControl( QStyle::CE_MenuItem, &styleOption, &painter);
    }
    else
    {
        returnVal = false;
    }

    if (returnVal)
    {
        X11SalGraphics::CopyScreenArea( dpy,
            pixmap.handle(), pixmap.x11Info().screen(), pixmap.x11Info().depth(),
            drawable, GetScreenNumber(), GetVisual().GetDepth(), gc,
            0, 0, widgetRect.width(), widgetRect.height(), widgetRect.left(), widgetRect.top() );
    }

    return returnVal;
}

BOOL KDESalGraphics::getNativeControlRegion( ControlType type, ControlPart part,
                                             const Region& controlRegion, ControlState controlState,
                                             const ImplControlValue& val, SalControlHandle&,
                                             const OUString&,
                                             Region &nativeBoundingRegion, Region &nativeContentRegion )
{
    bool retVal = false;

    QRect boundingRect = region2QRect( controlRegion );
    QRect contentRect = boundingRect;
    QStyleOptionComplex styleOption;

    switch ( type )
    {
        // Metrics of the push button
        case CTRL_PUSHBUTTON:
            if (part == PART_ENTIRE_CONTROL)
            {
                styleOption.state = vclStateValue2StateFlag(controlState, val);

                if ( controlState & CTRL_STATE_DEFAULT )
                {
                    int size = kapp->style()->pixelMetric(
                        QStyle::PM_ButtonDefaultIndicator, &styleOption );

                    boundingRect.adjust( -size, -size, size, size );

                    retVal = true;
                }
            }
            break;
        case CTRL_EDITBOX:
        {
            int nFontHeight    = kapp->fontMetrics().height();
            //int nFrameSize     = kapp->style()->pixelMetric(QStyle::PM_DefaultFrameWidth);
            int nLayoutTop     = kapp->style()->pixelMetric(QStyle::PM_LayoutTopMargin);
            int nLayoutBottom  = kapp->style()->pixelMetric(QStyle::PM_LayoutBottomMargin);
            int nLayoutLeft    = kapp->style()->pixelMetric(QStyle::PM_LayoutLeftMargin);
            int nLayoutRight   = kapp->style()->pixelMetric(QStyle::PM_LayoutRightMargin);

            int nMinHeight = (nFontHeight + nLayoutTop + nLayoutBottom);
            if( boundingRect.height() < nMinHeight )
            {
                int delta = nMinHeight - boundingRect.height();
                boundingRect.adjust( 0, 0, 0, delta );
            }
            contentRect = boundingRect;
            contentRect.adjust( -nLayoutLeft+1, -nLayoutTop+1, nLayoutRight-1, nLayoutBottom-1 );
            retVal = true;

            break;
        }
        case CTRL_CHECKBOX:
            if (part == PART_ENTIRE_CONTROL)
            {
                styleOption.state = vclStateValue2StateFlag(controlState, val);

                contentRect.setWidth(kapp->style()->pixelMetric(
                    QStyle::PM_IndicatorWidth, &styleOption));
                contentRect.setHeight(kapp->style()->pixelMetric(
                    QStyle::PM_IndicatorHeight, &styleOption));

                contentRect.adjust(0, 0,
                    2 * kapp->style()->pixelMetric(
                        QStyle::PM_FocusFrameHMargin, &styleOption),
                    2 * kapp->style()->pixelMetric(
                        QStyle::PM_FocusFrameVMargin, &styleOption)
                    );

                boundingRect = contentRect;

                retVal = true;

                break;
            }
        case CTRL_COMBOBOX:
        case CTRL_LISTBOX:
        {
            QStyleOptionComboBox cbo;

            cbo.rect = QRect(0, 0, contentRect.width(), contentRect.height());
            cbo.state = vclStateValue2StateFlag(controlState, val);

            switch ( part )
            {
                case PART_ENTIRE_CONTROL:
                {
                    int size = kapp->style()->pixelMetric(QStyle::PM_ComboBoxFrameWidth) - 2;

                    // find out the minimum size that should be used
                    // assume contents is a text ling
                    int nHeight = kapp->fontMetrics().height();
                    QSize aContentSize( contentRect.width(), nHeight );
                    QSize aMinSize = kapp->style()->
                        sizeFromContents( QStyle::CT_ComboBox, &cbo, aContentSize );
                    if( aMinSize.height() > contentRect.height() )
                        contentRect.adjust( 0, 0, 0, aMinSize.height() - contentRect.height() );
                    boundingRect = contentRect;
                    // FIXME: why this difference between comboboxes and listboxes ?
                    // because a combobox has a sub edit and that is positioned
                    // inside the outer bordered control ?
                    if( type == CTRL_COMBOBOX )
                        contentRect.adjust(-size,-size,size,size);
                    retVal = true;
                    break;
                }
                case PART_BUTTON_DOWN:
                    //the entire control can be used as the "down" button
                    retVal = true;
                    break;
                case PART_SUB_EDIT:
                    contentRect = kapp->style()->subControlRect(
                        QStyle::CC_ComboBox, &cbo, QStyle::SC_ComboBoxEditField );

                    contentRect.translate( boundingRect.left(), boundingRect.top() );

                    retVal = true;
                    break;
                case PART_WINDOW:
                    retVal = true;
                    break;
            }
            break;
        }
        case CTRL_SPINBOX:
        {
            QStyleOptionSpinBox sbo;

            sbo.rect = QRect(0, 0, contentRect.width(), contentRect.height());
            sbo.state = vclStateValue2StateFlag(controlState, val);

            switch ( part )
            {
                case PART_BUTTON_UP:
                    contentRect = kapp->style()->subControlRect(
                        QStyle::CC_SpinBox, &sbo, QStyle::SC_SpinBoxUp );
                    contentRect.translate( boundingRect.left(), boundingRect.top() );
                    retVal = true;
                    boundingRect = QRect();
                    break;

                case PART_BUTTON_DOWN:
                    contentRect = kapp->style()->subControlRect(
                        QStyle::CC_SpinBox, &sbo, QStyle::SC_SpinBoxDown );
                    retVal = true;
                    contentRect.translate( boundingRect.left(), boundingRect.top() );
                    boundingRect = QRect();
                    break;

                case PART_SUB_EDIT:
                    contentRect = kapp->style()->subControlRect(
                        QStyle::CC_SpinBox, &sbo, QStyle::SC_SpinBoxEditField );
                    retVal = true;
                    contentRect.translate( boundingRect.left(), boundingRect.top() );
                    break;
                default:
                    retVal = true;
            }
            break;
        }
        case CTRL_MENU_POPUP:
            //just limit the widget of the menu items
            //OO isn't very flexible in all reguards with the menu
            //so we do the best we can
            if (part == PART_MENU_ITEM_CHECK_MARK)
            {
                contentRect.setWidth(contentRect.height());
                retVal = true;
            }
            else if (part == PART_MENU_ITEM_RADIO_MARK)
            {
                contentRect.setWidth(contentRect.height());
                retVal = true;
            }
            break;
        case CTRL_FRAME:
        {
            if( part == PART_BORDER )
            {
                int size = kapp->style()->pixelMetric(QStyle::PM_LayoutLeftMargin);
                USHORT nStyle = val.getNumericVal();
                if( nStyle & FRAME_DRAW_NODRAW )
                {
                    // in this case the question is: how thick would a frame be
                    // see brdwin.cxx, decoview.cxx
                    // most probably the behavior in decoview.cxx is wrong.
                    contentRect.adjust(size, size, -size, -size);
                }
                retVal = true;
            }
            break;
        }
        case CTRL_RADIOBUTTON:
        {
            const int h = kapp->style()->pixelMetric(QStyle::PM_ExclusiveIndicatorHeight);
            const int w = kapp->style()->pixelMetric(QStyle::PM_ExclusiveIndicatorWidth);

            contentRect = QRect(boundingRect.left(), boundingRect.top(), w, h);
            contentRect.adjust(0, 0,
                2 * kapp->style()->pixelMetric(
                    QStyle::PM_FocusFrameHMargin, &styleOption),
                2 * kapp->style()->pixelMetric(
                    QStyle::PM_FocusFrameVMargin, &styleOption)
                );
            boundingRect = contentRect;

            retVal = true;
        }
        default:
            break;
    }
#if 0


        // Metrics of the scroll bar
        case CTRL_SCROLLBAR:
            //pWidget = pWidgetPainter->scrollBar( rControlRegion,
                //( part == PART_BUTTON_LEFT || part == PART_BUTTON_RIGHT ),
                //ImplControlValue() );
            //aStyleOption.initFrom( pWidget );

            switch ( part )
            {
            case PART_BUTTON_LEFT:
            case PART_BUTTON_UP:
                qRect = kapp->style()->subControlRect(
                    QStyle::CC_ScrollBar, &aStyleOption, QStyle::SC_ScrollBarSubLine );

                // Workaround for Platinum style scroll bars. It makes the
                // left/up button invisible.
                if ( part == PART_BUTTON_LEFT )
                {
                    if ( qRect.left() > kapp->style()->subControlRect(
                        QStyle::CC_ScrollBar, &aStyleOption,
                        QStyle::SC_ScrollBarSubPage ).left() )
                    {
                        qRect.setLeft( 0 );
                        qRect.setRight( 0 );
                    }
                }
                else
                {
                    if ( qRect.top() > kapp->style()->subControlRect(
                        QStyle::CC_ScrollBar, &aStyleOption,
                        QStyle::SC_ScrollBarSubPage ).top() )
                    {
                        qRect.setTop( 0 );
                        qRect.setBottom( 0 );
                    }
                }

                qRect.translate( qBoundingRect.left(), qBoundingRect.top() );

                bReturn = TRUE;
                break;

            case PART_BUTTON_RIGHT:
            case PART_BUTTON_DOWN:
                qRect = kapp->style()->subControlRect(
                    QStyle::CC_ScrollBar, &aStyleOption, QStyle::SC_ScrollBarAddLine );

                // Workaround for Platinum and 3 button style scroll bars.
                // It makes the right/down button bigger.
                if ( part == PART_BUTTON_RIGHT )
                    qRect.setLeft( kapp->style()->subControlRect(
                        QStyle::CC_ScrollBar, &aStyleOption,
                        QStyle::SC_ScrollBarAddPage ).right() + 1 );
                else
                    qRect.setTop( kapp->style()->subControlRect(
                        QStyle::CC_ScrollBar, &aStyleOption,
                        QStyle::SC_ScrollBarAddPage ).bottom() + 1 );

                qRect.translate( qBoundingRect.left(), qBoundingRect.top() );

                bReturn = TRUE;
                break;
            }
            break;
    }
#endif

    if (retVal)
    {
        // Bounding region
        Point aBPoint( boundingRect.x(), boundingRect.y() );
        Size aBSize( boundingRect.width(), boundingRect.height() );
        nativeBoundingRegion = Region( Rectangle( aBPoint, aBSize ) );

        // Region of the content
        Point aPoint( contentRect.x(), contentRect.y() );
        Size  aSize( contentRect.width(), contentRect.height() );
        nativeContentRegion = Region( Rectangle( aPoint, aSize ) );
    }

    return retVal;
}