summaryrefslogtreecommitdiff
path: root/chart2/source/view/main/DummyXShape.cxx
blob: 164c10f4758a35ff1308c6da889bbc25105d8072 (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
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */

#include "DummyXShape.hxx"
#include "CommonConverters.hxx"
#include <rtl/ustring.hxx>

#include <vcl/window.hxx>
#include <tools/gen.hxx>

#include <algorithm>

using namespace com::sun::star;

namespace chart {

namespace dummy {

DummyXShape::DummyXShape():
    mpParent(NULL)
{
}

OUString DummyXShape::getName()
    throw(uno::RuntimeException)
{
    return maName;
}

void DummyXShape::setName( const OUString& rName )
    throw(uno::RuntimeException)
{
    maName = rName;
}

awt::Point DummyXShape::getPosition()
    throw(uno::RuntimeException)
{
    return maPosition;
}

void DummyXShape::setPosition( const awt::Point& rPoint )
    throw(uno::RuntimeException)
{
    maPosition = rPoint;
}

awt::Size DummyXShape::getSize()
    throw(uno::RuntimeException)
{
    return maSize;
}

void DummyXShape::setSize( const awt::Size& rSize )
    throw(beans::PropertyVetoException, uno::RuntimeException)
{
    maSize = rSize;
}

OUString DummyXShape::getShapeType()
    throw(uno::RuntimeException)
{
    return OUString("dummy shape");
}
uno::Reference< beans::XPropertySetInfo > DummyXShape::getPropertySetInfo()
    throw(uno::RuntimeException)
{
    return uno::Reference< beans::XPropertySetInfo >();
}

void DummyXShape::setPropertyValue( const OUString& rName, const uno::Any& rValue)
    throw(beans::UnknownPropertyException, beans::PropertyVetoException,
            lang::IllegalArgumentException, lang::WrappedTargetException,
            uno::RuntimeException)
{
    SAL_DEBUG("DummyXShape::setProperty: " << rName << " " << "Any");
    maProperties[rName] = rValue;
}

uno::Any DummyXShape::getPropertyValue( const OUString& rName )
    throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
{
    SAL_DEBUG("DummyXShape::getPropertyValue: " << rName);
    std::map<OUString, uno::Any>::iterator itr = maProperties.find(rName);
    if(itr != maProperties.end())
        return itr->second;

    return uno::Any();
}

void DummyXShape::addPropertyChangeListener( const OUString&, const uno::Reference< beans::XPropertyChangeListener >& )
    throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
{
}

void DummyXShape::removePropertyChangeListener( const OUString&, const uno::Reference< beans::XPropertyChangeListener >& )
    throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
{
}

void DummyXShape::addVetoableChangeListener( const OUString&, const uno::Reference< beans::XVetoableChangeListener >& )
    throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
{
}

void DummyXShape::removeVetoableChangeListener( const OUString&, const uno::Reference< beans::XVetoableChangeListener >& )
    throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
{
}

void DummyXShape::setPropertyValues( const uno::Sequence< OUString >& ,
        const uno::Sequence< uno::Any >& )
throw (beans::PropertyVetoException, lang::IllegalArgumentException,
        lang::WrappedTargetException, uno::RuntimeException)
{
}

uno::Sequence< uno::Any > DummyXShape::getPropertyValues(
        const uno::Sequence< OUString >& rNames)
    throw (uno::RuntimeException)
{
    uno::Sequence< uno::Any > aValues(rNames.getLength());
    for(sal_Int32 i = 0; i < rNames.getLength(); ++i)
    {
        OUString aName = rNames[i];

        std::map<OUString, uno::Any>::iterator itr = maProperties.find(aName);
        if(itr != maProperties.end())
            aValues[i] = itr->second;
    }
    return aValues;
}

    void DummyXShape::addPropertiesChangeListener( const uno::Sequence< OUString >& , const uno::Reference< beans::XPropertiesChangeListener >& ) throw (uno::RuntimeException)
{
}

    void DummyXShape::removePropertiesChangeListener( const uno::Reference< beans::XPropertiesChangeListener >& ) throw (uno::RuntimeException)
{
}

void DummyXShape::firePropertiesChangeEvent( const uno::Sequence< OUString >& ,
        const uno::Reference< beans::XPropertiesChangeListener >& )
    throw (uno::RuntimeException)
{
}

OUString DummyXShape::getImplementationName()
    throw(uno::RuntimeException)
{
    return OUString("DummyXShape");
}

namespace {

uno::Sequence< OUString > listSupportedServices()
{
    static uno::Sequence< OUString > aSupportedServices;
    if(aSupportedServices.getLength() == 0)
    {
        aSupportedServices.realloc(3);
        aSupportedServices[0] = "com.sun.star.drawing.Shape";
        aSupportedServices[1] = "com.sun.star.container.Named";
        aSupportedServices[2] = "com.sun.star.beans.PropertySet";
    }

    return aSupportedServices;
}

}

uno::Sequence< OUString > DummyXShape::getSupportedServiceNames()
    throw(uno::RuntimeException)
{
    return listSupportedServices();
}

sal_Bool DummyXShape::supportsService( const OUString& rServiceName )
    throw(uno::RuntimeException)
{
    uno::Sequence< OUString > aSupportedServices = listSupportedServices();
    for(sal_Int32 i = 0; i < aSupportedServices.getLength(); ++i)
    {
        if(aSupportedServices[i] == rServiceName)
            return true;
    }

    return false;
}

uno::Reference< uno::XInterface > DummyXShape::getParent()
    throw(uno::RuntimeException)
{
    return mxParent;
}

void DummyXShape::setParent( const uno::Reference< uno::XInterface >& xParent )
    throw(lang::NoSupportException, uno::RuntimeException)
{
    mxParent = xParent;
}

namespace {

void setProperties( uno::Reference< beans::XPropertySet > xPropSet, const tPropertyNameMap& rPropertyNameMap,
        std::map<OUString, uno::Any>& rTargetMap )
{
    tNameSequence aNames;
    tAnySequence aValues;
    PropertyMapper::getMultiPropertyLists( aNames, aValues,
            xPropSet, rPropertyNameMap );

    sal_Int32 nSize = std::min(aNames.getLength(), aValues.getLength());
    for(sal_Int32 i = 0; i < nSize; ++i)
    {
        rTargetMap[aNames[i]] = aValues[i];
    }
}

}

DummyCube::DummyCube(const drawing::Position3D &rPos, const drawing::Direction3D& rSize,
        sal_Int32 nRotateZAngleHundredthDegree, const uno::Reference< beans::XPropertySet > xPropSet,
        const tPropertyNameMap& rPropertyNameMap, bool bRounded ):
    mnRotateZAngleHundredthDegree(nRotateZAngleHundredthDegree),
    mbRounded(bRounded)
{
    setPosition(Position3DToAWTPoint(rPos));
    setSize(Direction3DToAWTSize(rSize));
    setProperties(xPropSet, rPropertyNameMap, maProperties);
}

DummyCylinder::DummyCylinder(const drawing::Position3D& rPos, const drawing::Direction3D& rSize,
            sal_Int32 nRotateZAngleHundredthDegree ):
    mnRotateZAngleHundredthDegree(nRotateZAngleHundredthDegree)
{
    setPosition(Position3DToAWTPoint(rPos));
    setSize(Direction3DToAWTSize(rSize));
}

DummyPyramid::DummyPyramid(const drawing::Position3D& rPos, const drawing::Direction3D& rSize,
        double fTopHeight, bool bRotateZ, uno::Reference< beans::XPropertySet > xPropSet,
        const tPropertyNameMap& rPropertyNameMap):
    mfTopHeight(fTopHeight),
    mbRotateZ(bRotateZ)
{
    setPosition(Position3DToAWTPoint(rPos));
    setSize(Direction3DToAWTSize(rSize));
    setProperties(xPropSet, rPropertyNameMap, maProperties);
}

DummyCone::DummyCone(const drawing::Position3D& rPos, const drawing::Direction3D& rSize,
        double fTopHeight, sal_Int32 nRotateZAngleHundredthDegree):
    mnRotateZAngleHundredthDegree(nRotateZAngleHundredthDegree),
    mfTopHeight(fTopHeight)
{
    setPosition(Position3DToAWTPoint(rPos));
    setSize(Direction3DToAWTSize(rSize));
}

DummyPieSegment2D::DummyPieSegment2D(double fUnitCircleStartAngleDegree, double fUnitCircleWidthAngleDegree,
        double fUnitCircleInnerRadius, double fUnitCircleOuterRadius,
        const drawing::Direction3D& rOffset, const drawing::HomogenMatrix& rUnitCircleToScene):
    mfUnitCircleStartAngleDegree(fUnitCircleStartAngleDegree),
    mfUnitCircleWidthAngleDegree(fUnitCircleWidthAngleDegree),
    mfUnitCircleInnerRadius(fUnitCircleInnerRadius),
    mfUnitCircleOuterRadius(fUnitCircleOuterRadius),
    maOffset(rOffset),
    maUnitCircleToScene(rUnitCircleToScene)
{
}

DummyPieSegment::DummyPieSegment(double fUnitCircleStartAngleDegree, double fUnitCircleWidthAngleDegree,
        double fUnitCircleInnerRadius, double fUnitCircleOuterRadius,
        const drawing::Direction3D& rOffset, const drawing::HomogenMatrix& rUnitCircleToScene,
        double fDepth ):
    mfUnitCircleStartAngleDegree(fUnitCircleStartAngleDegree),
    mfUnitCircleWidthAngleDegree(fUnitCircleWidthAngleDegree),
    mfUnitCircleInnerRadius(fUnitCircleInnerRadius),
    mfUnitCircleOuterRadius(fUnitCircleOuterRadius),
    maOffset(rOffset),
    maUnitCircleToScene(rUnitCircleToScene),
    mfDepth(fDepth)
{
}

DummyStripe::DummyStripe(const Stripe& rStripe, uno::Reference< beans::XPropertySet > xPropSet,
        const tPropertyNameMap& rPropertyNameMap, sal_Bool bDoubleSided,
        short nRotatedTexture, bool bFlatNormals ):
    maStripe(rStripe),
    mbDoubleSided(bDoubleSided),
    mnRotatedTexture(nRotatedTexture),
    mbFlatNormals(bFlatNormals)
{
    setProperties(xPropSet, rPropertyNameMap, maProperties);
}

DummyArea3D::DummyArea3D(const drawing::PolyPolygonShape3D& rShape, double fDepth):
    mfDepth(fDepth),
    maShapes(rShape)
{
}

DummyArea2D::DummyArea2D(const drawing::PolyPolygonShape3D& rShape):
    maShapes(rShape)
{
}

DummySymbol2D::DummySymbol2D(const drawing::Position3D& rPos, const drawing::Direction3D& rSize,
        sal_Int32 nStandardSymbol, sal_Int32 , sal_Int32 ):
    mnStandardSymbol(nStandardSymbol)
{
    setPosition(Position3DToAWTPoint(rPos));
    setSize(Direction3DToAWTSize(rSize));
}

DummyCircle::DummyCircle(const awt::Point& rPos, const awt::Size& rSize)
{
    setPosition(rPos);
    setSize(rSize);
}

DummyLine3D::DummyLine3D(const drawing::PolyPolygonShape3D& rPoints, const VLineProperties& ):
    maPoints(rPoints)
{
}

DummyLine2D::DummyLine2D(const drawing::PointSequenceSequence& rPoints, const VLineProperties* ):
    maPoints(rPoints)
{
}

DummyLine2D::DummyLine2D(const awt::Size& rSize, const awt::Point& rPosition)
{
    setPosition(rPosition);
    setSize(rSize);
}

DummyRectangle::DummyRectangle()
{
}

DummyRectangle::DummyRectangle(const awt::Size& rSize)
{
    setSize(rSize);
}

DummyRectangle::DummyRectangle(const awt::Size& rSize, const awt::Point& rPoint, const tNameSequence& ,
        const tAnySequence& )
{
    setSize(rSize);
    setPosition(rPoint);
}

DummyText::DummyText(const OUString& rText, const tNameSequence& ,
        const tAnySequence& , const uno::Any& rTrans ):
    maText(rText),
    maTrans(rTrans)
{
}

DummyGroup3D::DummyGroup3D(const OUString& rName)
{
    setName(rName);
}

DummyGroup2D::DummyGroup2D(const OUString& rName)
{
    setName(rName);
}

DummyGraphic2D::DummyGraphic2D(const drawing::Position3D& rPos, const drawing::Direction3D& rSize,
        const uno::Reference< graphic::XGraphic > xGraphic ):
    mxGraphic(xGraphic)
{
    setPosition(Position3DToAWTPoint(rPos));
    setSize(Direction3DToAWTSize(rSize));
}

DummyChart* DummyXShape::getRootShape()
{
    assert(mxParent.is());
    DummyXShape* pParent = dynamic_cast<DummyXShape*>(mxParent.get());
    assert(pParent);
    return pParent->getRootShape();
}

DummyChart* DummyChart::getRootShape()
{
    return this;
}

#define QUERYINT( xint ) \
    if( rType == ::getCppuType((const uno::Reference< xint >*)0) ) \
        aAny <<= uno::Reference< xint >(this)

uno::Any DummyXShapes::queryInterface( const uno::Type& rType )
    throw(uno::RuntimeException)
{
    return DummyXShape::queryInterface(rType);
}

uno::Any DummyXShapes::queryAggregation( const uno::Type & rType )
    throw(uno::RuntimeException)
{
    uno::Any aAny;

    //QUERYINT( drawing::XShapeGroup );
    QUERYINT( drawing::XShapes );
    else
        return DummyXShape::queryAggregation( rType );

    return aAny;
}

void DummyXShapes::acquire()
    throw()
{
    DummyXShape::acquire();
}

void DummyXShapes::release()
    throw()
{
    DummyXShape::release();
}

void DummyXShapes::add( const uno::Reference< drawing::XShape>& xShape )
    throw(uno::RuntimeException)
{
    DummyXShape* pChild = dynamic_cast<DummyXShape*>(xShape.get());
    assert(pChild);
    maUNOShapes.push_back(xShape);
    pChild->setParent(static_cast< ::cppu::OWeakObject* >( this ));
    maShapes.push_back(pChild);
}

void DummyXShapes::remove( const uno::Reference< drawing::XShape>& xShape )
    throw(uno::RuntimeException)
{
    std::vector< uno::Reference<drawing::XShape> >::iterator itr = std::find(maUNOShapes.begin(), maUNOShapes.end(), xShape);

    DummyXShape* pChild = dynamic_cast<DummyXShape*>((*itr).get());
    std::vector< DummyXShape* >::iterator itrShape = std::find(maShapes.begin(), maShapes.end(), pChild);
    if(itrShape != maShapes.end())
        maShapes.erase(itrShape);

    if(itr != maUNOShapes.end())
        maUNOShapes.erase(itr);
}

uno::Type DummyXShapes::getElementType()
    throw(uno::RuntimeException)
{
    return ::getCppuType(( const uno::Reference< drawing::XShape >*)0);
}

sal_Bool DummyXShapes::hasElements()
    throw(uno::RuntimeException)
{
    return !maUNOShapes.empty();
}

sal_Int32 DummyXShapes::getCount()
    throw(uno::RuntimeException)
{
    return maUNOShapes.size();
}

uno::Any DummyXShapes::getByIndex(sal_Int32 nIndex)
    throw(lang::IndexOutOfBoundsException, lang::WrappedTargetException,
            uno::RuntimeException)
{
    uno::Any aShape;
    aShape <<= maUNOShapes[nIndex];
    return aShape;
}

bool DummyChart::initWindow()
{
    const SystemEnvData* sysData(mpWindow->GetSystemData());
#if defined( WNT )
    GLWin.hWnd = sysData->hWnd;
#elif defined( UNX )
    GLWin.dpy = reinterpret_cast<unx::Display*>(sysData->pDisplay);

    if( unx::glXQueryExtension( GLWin.dpy, NULL, NULL ) == false )
        return false;

    GLWin.win = sysData->aWindow;

    OSL_TRACE("parent window: %d", GLWin.win);

    unx::XWindowAttributes xattr;
    unx::XGetWindowAttributes( GLWin.dpy, GLWin.win, &xattr );

    GLWin.screen = XScreenNumberOfScreen( xattr.screen );

    unx::XVisualInfo* vi( NULL );
#if defined( GLX_VERSION_1_3 ) && defined( GLX_EXT_texture_from_pixmap )
    unx::XVisualInfo* visinfo;
    unx::XVisualInfo* firstVisual( NULL );
#endif
    static int attrList3[] =
    {
        GLX_RGBA,//only TrueColor or DirectColor
        //single buffered
        GLX_RED_SIZE,4,//use the maximum red bits, with a minimum of 4 bits
        GLX_GREEN_SIZE,4,//use the maximum green bits, with a minimum of 4 bits
        GLX_BLUE_SIZE,4,//use the maximum blue bits, with a minimum of 4 bits
        GLX_DEPTH_SIZE,0,//no depth buffer
        None
    };
    static int attrList2[] =
    {
        GLX_RGBA,//only TrueColor or DirectColor
        /// single buffered
        GLX_RED_SIZE,4,/// use the maximum red bits, with a minimum of 4 bits
        GLX_GREEN_SIZE,4,/// use the maximum green bits, with a minimum of 4 bits
        GLX_BLUE_SIZE,4,/// use the maximum blue bits, with a minimum of 4 bits
        GLX_DEPTH_SIZE,1,/// use the maximum depth bits, making sure there is a depth buffer
        None
    };
    static int attrList1[] =
    {
        GLX_RGBA,//only TrueColor or DirectColor
        GLX_DOUBLEBUFFER,/// only double buffer
        GLX_RED_SIZE,4,/// use the maximum red bits, with a minimum of 4 bits
        GLX_GREEN_SIZE,4,/// use the maximum green bits, with a minimum of 4 bits
        GLX_BLUE_SIZE,4,/// use the maximum blue bits, with a minimum of 4 bits
        GLX_DEPTH_SIZE,0,/// no depth buffer
        None
    };
    static int attrList0[] =
    {
        GLX_RGBA,//only TrueColor or DirectColor
        GLX_DOUBLEBUFFER,/// only double buffer
        GLX_RED_SIZE,4,/// use the maximum red bits, with a minimum of 4 bits
        GLX_GREEN_SIZE,4,/// use the maximum green bits, with a minimum of 4 bits
        GLX_BLUE_SIZE,4,/// use the maximum blue bits, with a minimum of 4 bits
        GLX_DEPTH_SIZE,1,/// use the maximum depth bits, making sure there is a depth buffer
        None
    };
    static int* attrTable[] =
    {
        attrList0,
        attrList1,
        attrList2,
        attrList3,
        NULL
    };
    int** pAttributeTable = attrTable;
    const SystemEnvData* pChildSysData = NULL;
    pWindow.reset();

#if defined( GLX_VERSION_1_3 ) && defined( GLX_EXT_texture_from_pixmap )
    unx::GLXFBConfig* fbconfigs = NULL;
    int nfbconfigs, value, i = 0;
#endif

    while( *pAttributeTable )
    {
        // try to find a visual for the current set of attributes
        vi = unx::glXChooseVisual( GLWin.dpy,
                GLWin.screen,
                *pAttributeTable );

#if defined( GLX_VERSION_1_3 ) && defined( GLX_EXT_texture_from_pixmap )
        if( vi ) {
            if( !firstVisual )
                firstVisual = vi;
            OSL_TRACE("trying VisualID %08X", vi->visualid);
            fbconfigs = glXGetFBConfigs (GLWin.dpy, GLWin.screen, &nfbconfigs);

            for ( ; i < nfbconfigs; i++)
            {
                visinfo = glXGetVisualFromFBConfig (GLWin.dpy, fbconfigs[i]);
                if( !visinfo || visinfo->visualid != vi->visualid )
                    continue;

                glXGetFBConfigAttrib (GLWin.dpy, fbconfigs[i], GLX_DRAWABLE_TYPE, &value);
                if (!(value & GLX_PIXMAP_BIT))
                    continue;

                glXGetFBConfigAttrib (GLWin.dpy, fbconfigs[i],
                        GLX_BIND_TO_TEXTURE_TARGETS_EXT,
                        &value);
                if (!(value & GLX_TEXTURE_2D_BIT_EXT))
                    continue;

                glXGetFBConfigAttrib (GLWin.dpy, fbconfigs[i],
                        GLX_BIND_TO_TEXTURE_RGB_EXT,
                        &value);
                if (value == sal_False)
                    continue;

                glXGetFBConfigAttrib (GLWin.dpy, fbconfigs[i],
                        GLX_BIND_TO_MIPMAP_TEXTURE_EXT,
                        &value);
                if (value == sal_False)
                    continue;

                // TODO: handle non Y inverted cases
                break;
            }

            if( i != nfbconfigs || ( firstVisual && pAttributeTable[1] == NULL ) ) {
                if( i != nfbconfigs ) {
                    vi = glXGetVisualFromFBConfig( GLWin.dpy, fbconfigs[i] );
                    // TODO:moggi
                    // mbHasTFPVisual = true;
                    OSL_TRACE("found visual suitable for texture_from_pixmap");
                } else {
                    vi = firstVisual;
                    // TODO:moggi
                    // mbHasTFPVisual = false;
                    OSL_TRACE("did not find visual suitable for texture_from_pixmap, using %08X", vi->visualid);
                }
#else
                if( vi ) {
#endif
                    SystemWindowData winData;
                    winData.nSize = sizeof(winData);
                    OSL_TRACE("using VisualID %08X", vi->visualid);
                    winData.pVisual = (void*)(vi->visual);
                    pWindow.reset(new SystemChildWindow(mpWindow.get(), 0, &winData, sal_False));
                    pChildSysData = pWindow->GetSystemData();

                    if( pChildSysData ) {
                        break;
                    } else {
                        pWindow.reset();
                    }
                }
#if defined( GLX_VERSION_1_3 ) && defined( GLX_EXT_texture_from_pixmap )
            }
#endif

            ++pAttributeTable;
        }
#endif

#if defined( WNT )
        SystemWindowData winData;
        winData.nSize = sizeof(winData);
        pWindow.reset(new SystemChildWindow(mpWindow.get(), 0, &winData, sal_False));
#endif

        if( pWindow )
        {
            pWindow->SetMouseTransparent( sal_True );
            pWindow->SetParentClipMode( PARENTCLIPMODE_NOCLIP );
            pWindow->EnableEraseBackground( sal_False );
            pWindow->SetControlForeground();
            pWindow->SetControlBackground();
            pWindow->EnablePaint(sal_False);
#if defined( WNT )
            GLWin.hWnd = sysData->hWnd;
#elif defined( UNX )
            GLWin.dpy = reinterpret_cast<unx::Display*>(pChildSysData->pDisplay);
            GLWin.win = pChildSysData->aWindow;
#if defined( GLX_VERSION_1_3 ) && defined( GLX_EXT_texture_from_pixmap )
            //TODO: moggi
            /*
            if( mbHasTFPVisual )
                GLWin.fbc = fbconfigs[i];
                */
#endif
            GLWin.vi = vi;
            GLWin.GLXExtensions = unx::glXQueryExtensionsString( GLWin.dpy, GLWin.screen );
            OSL_TRACE("available GLX extensions: %s", GLWin.GLXExtensions);
#endif

        return false;
        }

    return true;
}

namespace {

static bool errorTriggered;
int oglErrorHandler( unx::Display* /*dpy*/, unx::XErrorEvent* /*evnt*/ )
{
    errorTriggered = true;

    return 0;
}

}

bool DummyChart::initOpengl()
{
    initWindow();
    mpWindow->setPosSizePixel(0,0,0,0);
    GLWin.Width = 0;
    GLWin.Height = 0;

#if defined( WNT )
    GLWin.hDC = GetDC(GLWin.hWnd);
#elif defined( UNX )
    GLWin.ctx = glXCreateContext(GLWin.dpy,
                                 GLWin.vi,
                                 0,
                                 GL_TRUE);
    if( GLWin.ctx == NULL )
    {
        OSL_TRACE("unable to create GLX context");
        return false;
    }
#endif

#if defined( WNT )
    PIXELFORMATDESCRIPTOR PixelFormatFront =                    // PixelFormat Tells Windows How We Want Things To Be
    {
        sizeof(PIXELFORMATDESCRIPTOR),
        1,                              // Version Number
        PFD_DRAW_TO_WINDOW |
        PFD_SUPPORT_OPENGL |
        PFD_DOUBLEBUFFER,
        PFD_TYPE_RGBA,                  // Request An RGBA Format
        (BYTE)32,                       // Select Our Color Depth
        0, 0, 0, 0, 0, 0,               // Color Bits Ignored
        0,                              // No Alpha Buffer
        0,                              // Shift Bit Ignored
        0,                              // No Accumulation Buffer
        0, 0, 0, 0,                     // Accumulation Bits Ignored
        64,                             // 32 bit Z-BUFFER
        0,                              // 0 bit stencil buffer
        0,                              // No Auxiliary Buffer
        0,                              // now ignored
        0,                              // Reserved
        0, 0, 0                         // Layer Masks Ignored
    };
    int WindowPix = ChoosePixelFormat(GLWin.hDC,&PixelFormatFront);
    SetPixelFormat(GLWin.hDC,WindowPix,&PixelFormatFront);
    GLWin.hRC  = wglCreateContext(GLWin.hDC);
    wglMakeCurrent(GLWin.hDC,GLWin.hRC);
#elif defined( UNX )
    if( !glXMakeCurrent( GLWin.dpy, GLWin.win, GLWin.ctx ) )
    {
        OSL_TRACE("unable to select current GLX context");
        return false;
    }

    int glxMinor, glxMajor;
    double nGLXVersion = 0;
    if( glXQueryVersion( GLWin.dpy, &glxMajor, &glxMinor ) )
      nGLXVersion = glxMajor + 0.1*glxMinor;
    OSL_TRACE("available GLX version: %f", nGLXVersion);

    GLWin.GLExtensions = glGetString( GL_EXTENSIONS );
    OSL_TRACE("available GL  extensions: %s", GLWin.GLExtensions);

    // TODO: moggi
    // mbTextureFromPixmap = GLWin.HasGLXExtension( "GLX_EXT_texture_from_pixmap" );
    // mbGenerateMipmap = GLWin.HasGLExtension( "GL_SGIS_generate_mipmap" );

    if( GLWin.HasGLXExtension("GLX_SGI_swap_control" ) )
    {
        // enable vsync
        typedef GLint (*glXSwapIntervalProc)(GLint);
        glXSwapIntervalProc glXSwapInterval = (glXSwapIntervalProc) unx::glXGetProcAddress( (const GLubyte*) "glXSwapIntervalSGI" );
        if( glXSwapInterval ) {
        int (*oldHandler)(unx::Display* /*dpy*/, unx::XErrorEvent* /*evnt*/);

        // replace error handler temporarily
        oldHandler = unx::XSetErrorHandler( oglErrorHandler );

        errorTriggered = false;

        glXSwapInterval( 1 );

        // sync so that we possibly get an XError
        unx::glXWaitGL();
        XSync(GLWin.dpy, false);

        if( errorTriggered )
            OSL_TRACE("error when trying to set swap interval, NVIDIA or Mesa bug?");
        else
            OSL_TRACE("set swap interval to 1 (enable vsync)");

        // restore the error handler
        unx::XSetErrorHandler( oldHandler );
        }
    }
#endif

    glEnable(GL_CULL_FACE);
    glCullFace(GL_BACK);
    glClearColor (0, 0, 0, 0);
    glClear(GL_COLOR_BUFFER_BIT);
#if defined( WNT )
    SwapBuffers(GLWin.hDC);
#elif defined( UNX )
    unx::glXSwapBuffers(GLWin.dpy, GLWin.win);
#endif

    glEnable(GL_LIGHTING);
    GLfloat light_direction[] = { 0.0 , 0.0 , 1.0 };
    GLfloat materialDiffuse[] = { 1.0 , 1.0 , 1.0 , 1.0};
    glLightfv(GL_LIGHT0, GL_SPOT_DIRECTION, light_direction);
    glMaterialfv(GL_FRONT,GL_DIFFUSE,materialDiffuse);
    glEnable(GL_LIGHT0);
    glEnable(GL_NORMALIZE);

    return true;
}

DummyChart::DummyChart():
    mpWindow(new Window(0, WB_NOBORDER|WB_NODIALOGCONTROL))
{
    setName("com.sun.star.chart2.shapes");
    createGLContext();
}

void DummyChart::createGLContext()
{
    initOpengl();
}

void DummyChart::setPosition( const awt::Point& aPosition )
    throw( uno::RuntimeException )
{
    DummyXShape::setPosition(aPosition);
}

void DummyChart::setSize( const awt::Size& aSize )
    throw( beans::PropertyVetoException, uno::RuntimeException )
{
    DummyXShape::setSize(aSize);
    mpWindow->SetSizePixel(Size(aSize.Width, aSize.Height));
    pWindow->SetSizePixel(Size(aSize.Width, aSize.Height));
}

}

}

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */