~ubuntu-branches/ubuntu/lucid/codelite/lucid

« back to all changes in this revision

Viewing changes to sdk/wxpropgrid/src/advprops.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Chow Loong Jin
  • Date: 2009-02-10 02:27:55 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20090210022755-m5692nfc1t5uf1w9
Tags: 1.0.2759+dfsg-0ubuntu1
* New upstream release (LP: #327216).
* debian/patches/series, debian/patches/00_fix-ia64-build.patch:
  + Dropped, applied upstream already.
* debian/patches/02_fix-desktop.patch,
  debian/patches/03_fix-sh.patch:
  + Refreshed to patch cleanly.
* debian/rules:
  + Make get-orig-source honour UPSTREAM_VERSION if set.
* debian/ctags-le.1,
  debian/codelite_indexer.1,
  debian/codelite.manpages:
  + Dropped ctags-le manpage, since ctags-le was replaced by
    codelite_indexer.
  + Added codelite_indexer manpage.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/////////////////////////////////////////////////////////////////////////////
 
2
// Name:        advprops.cpp
 
3
// Purpose:     wxPropertyGrid Advanced Properties (font, colour, etc.)
 
4
// Author:      Jaakko Salli
 
5
// Modified by:
 
6
// Created:     Sep-25-2004
 
7
// RCS-ID:      $Id:
 
8
// Copyright:   (c) Jaakko Salli
 
9
// Licence:     wxWindows license
 
10
/////////////////////////////////////////////////////////////////////////////
 
11
 
 
12
// For compilers that support precompilation, includes "wx/wx.h".
 
13
#include "wx/wxprec.h"
 
14
 
 
15
#ifdef __BORLANDC__
 
16
    #pragma hdrstop
 
17
#endif
 
18
 
 
19
#ifndef WX_PRECOMP
 
20
    #include "wx/defs.h"
 
21
    #include "wx/object.h"
 
22
    #include "wx/hash.h"
 
23
    #include "wx/string.h"
 
24
    #include "wx/log.h"
 
25
    #include "wx/event.h"
 
26
    #include "wx/window.h"
 
27
    #include "wx/panel.h"
 
28
    #include "wx/dc.h"
 
29
    #include "wx/dcclient.h"
 
30
    #include "wx/button.h"
 
31
    #include "wx/pen.h"
 
32
    #include "wx/brush.h"
 
33
    #include "wx/cursor.h"
 
34
    #include "wx/dialog.h"
 
35
    #include "wx/settings.h"
 
36
    #include "wx/msgdlg.h"
 
37
    #include "wx/choice.h"
 
38
    #include "wx/stattext.h"
 
39
    #include "wx/textctrl.h"
 
40
    #include "wx/scrolwin.h"
 
41
    #include "wx/dirdlg.h"
 
42
    #include "wx/combobox.h"
 
43
    #include "wx/layout.h"
 
44
    #include "wx/sizer.h"
 
45
    #include "wx/textdlg.h"
 
46
    #include "wx/filedlg.h"
 
47
    #include "wx/intl.h"
 
48
#endif
 
49
 
 
50
#define __wxPG_SOURCE_FILE__
 
51
 
 
52
#include <wx/propgrid/propgrid.h>
 
53
 
 
54
#if wxPG_INCLUDE_ADVPROPS
 
55
 
 
56
#include <wx/propgrid/propdev.h>
 
57
 
 
58
#include <wx/propgrid/advprops.h>
 
59
 
 
60
#ifdef __WXMSW__
 
61
    #include <wx/msw/private.h>
 
62
  #if wxCHECK_VERSION(2,9,0)
 
63
    #include <wx/msw/dc.h>
 
64
  #endif
 
65
#endif
 
66
 
 
67
// -----------------------------------------------------------------------
 
68
 
 
69
#if defined(__WXMSW__)
 
70
    #define wxPG_CAN_DRAW_CURSOR           1
 
71
#elif defined(__WXGTK__)
 
72
    #define wxPG_CAN_DRAW_CURSOR           0
 
73
#elif defined(__WXMAC__)
 
74
    #define wxPG_CAN_DRAW_CURSOR           0
 
75
#else
 
76
    #define wxPG_CAN_DRAW_CURSOR           0
 
77
#endif
 
78
 
 
79
 
 
80
// -----------------------------------------------------------------------
 
81
// Value type related
 
82
// -----------------------------------------------------------------------
 
83
 
 
84
 
 
85
// Implement dynamic class for type value.
 
86
IMPLEMENT_DYNAMIC_CLASS(wxColourPropertyValue, wxObject)
 
87
 
 
88
bool operator == (const wxColourPropertyValue& a, const wxColourPropertyValue& b)
 
89
{
 
90
    return ( ( a.m_colour == b.m_colour ) && (a.m_type == b.m_type) );
 
91
}
 
92
 
 
93
bool operator == (const wxArrayInt& array1, const wxArrayInt& array2)
 
94
{
 
95
    if ( array1.GetCount() != array2.GetCount() )
 
96
        return false;
 
97
    size_t i;
 
98
    for ( i=0; i<array1.GetCount(); i++ )
 
99
    {
 
100
        if ( array1[i] != array2[i] )
 
101
            return false;
 
102
    }
 
103
    return true;
 
104
}
 
105
 
 
106
// -----------------------------------------------------------------------
 
107
// wxSpinCtrl-based property editor
 
108
// -----------------------------------------------------------------------
 
109
 
 
110
#if wxUSE_SPINBTN
 
111
 
 
112
#ifdef __WXMSW__
 
113
  #define IS_MOTION_SPIN_SUPPORTED  1
 
114
#else
 
115
  #define IS_MOTION_SPIN_SUPPORTED  0
 
116
#endif
 
117
 
 
118
#if IS_MOTION_SPIN_SUPPORTED
 
119
//
 
120
// This class implements ability to rapidly change "spin" value
 
121
// by moving mouse when one of the spin buttons is depressed.
 
122
class wxPGSpinButton : public wxSpinButton
 
123
{
 
124
public:
 
125
    wxPGSpinButton() : wxSpinButton()
 
126
    {
 
127
        m_bLeftDown = false;
 
128
        m_hasCapture = false;
 
129
        m_spins = 1;
 
130
 
 
131
        Connect( wxEVT_LEFT_DOWN,
 
132
                 (wxObjectEventFunction) (wxEventFunction)
 
133
                 (wxMouseEventFunction)&wxPGSpinButton::OnMouseEvent );
 
134
        Connect( wxEVT_LEFT_UP,
 
135
                 (wxObjectEventFunction) (wxEventFunction)
 
136
                 (wxMouseEventFunction)&wxPGSpinButton::OnMouseEvent );
 
137
        Connect( wxEVT_MOTION,
 
138
                 (wxObjectEventFunction) (wxEventFunction)
 
139
                 (wxMouseEventFunction)&wxPGSpinButton::OnMouseEvent );
 
140
#if wxCHECK_VERSION(2,8,0)
 
141
        Connect( wxEVT_MOUSE_CAPTURE_LOST,
 
142
                 (wxObjectEventFunction) (wxEventFunction)
 
143
                 (wxMouseCaptureLostEventFunction)&wxPGSpinButton::OnMouseCaptureLost );
 
144
#endif
 
145
    }
 
146
 
 
147
 
 
148
    int GetSpins() const
 
149
    {
 
150
        return m_spins;
 
151
    }
 
152
 
 
153
private:
 
154
    wxPoint m_ptPosition;
 
155
 
 
156
    // Having a separate spins variable allows us to handle validation etc. for
 
157
    // multiple spin events at once (with quick mouse movements there could be
 
158
    // hundreds of 'spins' being done at once). Technically things like this
 
159
    // should be stored in event (wxSpinEvent in this case), but there probably
 
160
    // isn't anything there that can be reliably reused.
 
161
    int     m_spins;
 
162
 
 
163
    bool    m_bLeftDown;
 
164
 
 
165
    // SpinButton seems to be a special for mouse capture, so we may need track
 
166
    // privately whether mouse is actually captured.
 
167
    bool    m_hasCapture;
 
168
 
 
169
    void Capture()
 
170
    {
 
171
        if ( !m_hasCapture )
 
172
        {
 
173
            CaptureMouse();
 
174
            m_hasCapture = true;
 
175
        }
 
176
 
 
177
        SetCursor(wxCURSOR_SIZENS);
 
178
    }
 
179
    void Release()
 
180
    {
 
181
        m_bLeftDown = false;
 
182
 
 
183
        if ( m_hasCapture )
 
184
        {
 
185
            ReleaseMouse();
 
186
            m_hasCapture = false;
 
187
        }
 
188
 
 
189
        wxWindow *parent = GetParent();
 
190
        if ( parent )
 
191
            SetCursor(parent->GetCursor());
 
192
        else
 
193
            SetCursor(wxNullCursor);
 
194
    }
 
195
 
 
196
    void OnMouseEvent(wxMouseEvent& event)
 
197
    {
 
198
        if ( event.GetEventType() == wxEVT_LEFT_DOWN )
 
199
        {
 
200
            m_bLeftDown = true;
 
201
            m_ptPosition = event.GetPosition();
 
202
        }
 
203
        else if ( event.GetEventType() == wxEVT_LEFT_UP )
 
204
        {
 
205
            Release();
 
206
            m_bLeftDown = false;
 
207
        }
 
208
        else if ( event.GetEventType() == wxEVT_MOTION )
 
209
        {
 
210
            if ( m_bLeftDown )
 
211
            {
 
212
                int dy = m_ptPosition.y - event.GetPosition().y;
 
213
                if ( dy )
 
214
                {
 
215
                    Capture();
 
216
                    m_ptPosition = event.GetPosition();
 
217
 
 
218
                    wxSpinEvent evtscroll( (dy >= 0) ? wxEVT_SCROLL_LINEUP :
 
219
                                                       wxEVT_SCROLL_LINEDOWN,
 
220
                                           GetId() );
 
221
                    evtscroll.SetEventObject(this);
 
222
 
 
223
                    wxASSERT( m_spins == 1 );
 
224
 
 
225
                    m_spins = abs(dy);
 
226
                    GetEventHandler()->ProcessEvent(evtscroll);
 
227
                    m_spins = 1;
 
228
                }
 
229
            }
 
230
        }
 
231
 
 
232
        event.Skip();
 
233
    }
 
234
#if wxCHECK_VERSION(2,8,0)
 
235
    void OnMouseCaptureLost(wxMouseCaptureLostEvent& WXUNUSED(event))
 
236
    {
 
237
        Release();
 
238
    }
 
239
#endif
 
240
};
 
241
 
 
242
#endif // IS_MOTION_SPIN_SUPPORTED
 
243
 
 
244
 
 
245
// This macro also defines global wxPGEditor_SpinCtrl for storing
 
246
// the singleton class instance.
 
247
WX_PG_IMPLEMENT_EDITOR_CLASS(SpinCtrl,wxPGSpinCtrlEditor,wxPGEditor)
 
248
 
 
249
 
 
250
// Trivial destructor.
 
251
wxPGSpinCtrlEditor::~wxPGSpinCtrlEditor()
 
252
{
 
253
}
 
254
 
 
255
 
 
256
// Create controls and initialize event handling.
 
257
wxPGWindowList wxPGSpinCtrlEditor::CreateControls( wxPropertyGrid* propgrid, wxPGProperty* property,
 
258
                                                   const wxPoint& pos, const wxSize& sz ) const
 
259
{
 
260
    const int margin = 1;
 
261
    wxSize butSz(18, sz.y);
 
262
    wxSize tcSz(sz.x - butSz.x - margin, sz.y);
 
263
    wxPoint butPos(pos.x + tcSz.x + margin, pos.y);
 
264
 
 
265
    wxSpinButton* wnd2;
 
266
 
 
267
#if IS_MOTION_SPIN_SUPPORTED
 
268
    if ( property->GetAttributeAsLong(wxT("MotionSpin"), 0) )
 
269
    {
 
270
        wnd2 = new wxPGSpinButton();
 
271
    }
 
272
    else
 
273
#endif
 
274
    {
 
275
        wnd2 = new wxSpinButton();
 
276
    }
 
277
 
 
278
#ifdef __WXMSW__
 
279
    wnd2->Hide();
 
280
#endif
 
281
    wnd2->Create( propgrid->GetPanel(), wxPG_SUBID2, butPos, butSz, wxSP_VERTICAL );
 
282
 
 
283
    wnd2->SetRange( INT_MIN, INT_MAX );
 
284
    wnd2->SetValue( 0 );
 
285
 
 
286
    propgrid->Connect( wxPG_SUBID2, wxEVT_SCROLL_LINEUP,
 
287
                       (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction)
 
288
                       &wxPropertyGrid::OnCustomEditorEvent, NULL, propgrid );
 
289
    propgrid->Connect( wxPG_SUBID2, wxEVT_SCROLL_LINEDOWN,
 
290
                       (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction)
 
291
                       &wxPropertyGrid::OnCustomEditorEvent, NULL, propgrid );
 
292
    propgrid->Connect( wxPG_SUBID1, wxEVT_KEY_DOWN,
 
293
                       (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction)
 
294
                       &wxPropertyGrid::OnCustomEditorEvent, NULL, propgrid );
 
295
 
 
296
    // Let's add validator to make sure only numbers can be entered
 
297
    wxTextValidator validator(wxFILTER_NUMERIC, &m_tempString);
 
298
 
 
299
    wxTextCtrl* wnd1 = (wxTextCtrl*) wxPGTextCtrlEditor::CreateControls( propgrid, property, pos, tcSz ).m_primary;
 
300
    wnd1->SetValidator(validator);
 
301
 
 
302
    return wxPGWindowList(wnd1, wnd2);
 
303
}
 
304
 
 
305
// Control's events are redirected here
 
306
bool wxPGSpinCtrlEditor::OnEvent( wxPropertyGrid* propgrid, wxPGProperty* property,
 
307
                                  wxWindow* wnd, wxEvent& event ) const
 
308
{
 
309
    int evtType = event.GetEventType();
 
310
    int keycode = -1;
 
311
    int spins = 1;
 
312
    bool bigStep = false;
 
313
 
 
314
    if ( evtType == wxEVT_KEY_DOWN )
 
315
    {
 
316
        wxKeyEvent& keyEvent = (wxKeyEvent&)event;
 
317
        keycode = keyEvent.GetKeyCode();
 
318
 
 
319
        if ( keycode == WXK_UP )
 
320
            evtType = wxEVT_SCROLL_LINEUP;
 
321
        else if ( keycode == WXK_DOWN )
 
322
            evtType = wxEVT_SCROLL_LINEDOWN;
 
323
        else if ( keycode == WXK_PAGEUP )
 
324
        {
 
325
            evtType = wxEVT_SCROLL_LINEUP;
 
326
            bigStep = true;
 
327
        }
 
328
        else if ( keycode == WXK_PAGEDOWN )
 
329
        {
 
330
            evtType = wxEVT_SCROLL_LINEDOWN;
 
331
            bigStep = true;
 
332
        }
 
333
    }
 
334
 
 
335
    if ( evtType == wxEVT_SCROLL_LINEUP || evtType == wxEVT_SCROLL_LINEDOWN )
 
336
    {
 
337
    #if IS_MOTION_SPIN_SUPPORTED
 
338
        if ( property->GetAttributeAsLong(wxT("MotionSpin"), 0) )
 
339
        {
 
340
            wxPGSpinButton* spinButton =
 
341
                (wxPGSpinButton*) propgrid->GetEditorControlSecondary();
 
342
 
 
343
            if ( spinButton )
 
344
                spins = spinButton->GetSpins();
 
345
        }
 
346
    #endif
 
347
 
 
348
        wxString s;
 
349
        // Can't use wnd since it might be clipper window
 
350
        wxTextCtrl* tc = wxDynamicCast(propgrid->GetEditorControl(), wxTextCtrl);
 
351
 
 
352
        if ( tc )
 
353
            s = tc->GetValue();
 
354
        else
 
355
            s = property->GetValueAsString(wxPG_FULL_VALUE);
 
356
 
 
357
        int mode = wxPG_PROPERTY_VALIDATION_SATURATE;
 
358
 
 
359
        if ( property->GetAttributeAsLong(wxT("Wrap"), 0) )
 
360
            mode = wxPG_PROPERTY_VALIDATION_WRAP;
 
361
 
 
362
        if ( property->GetValueType() == wxT("double") )
 
363
        {
 
364
            double v_d;
 
365
            double step = property->GetAttributeAsDouble(wxT("Step"), 1.0);
 
366
 
 
367
            // Try double
 
368
            if ( s.ToDouble(&v_d) )
 
369
            {
 
370
                if ( bigStep )
 
371
                    step *= 10.0;
 
372
 
 
373
                step *= (double) spins;
 
374
 
 
375
                if ( evtType == wxEVT_SCROLL_LINEUP ) v_d += step;
 
376
                else v_d -= step;
 
377
 
 
378
                // Min/Max check
 
379
                wxFloatProperty::DoValidation(property, v_d, NULL, mode);
 
380
 
 
381
                wxPropertyGrid::DoubleToString(s, v_d, 6, true, NULL);
 
382
            }
 
383
            else
 
384
            {
 
385
                return false;
 
386
            }
 
387
        }
 
388
        else
 
389
        {
 
390
            wxLongLong_t v_ll;
 
391
            wxLongLong_t step = property->GetAttributeAsLong(wxT("Step"), 1);
 
392
 
 
393
            // Try long
 
394
            if ( wxPGStringToLongLong(s, &v_ll, 10) )
 
395
            {
 
396
                if ( bigStep )
 
397
                    step *= 10;
 
398
 
 
399
                step *= spins;
 
400
 
 
401
                if ( evtType == wxEVT_SCROLL_LINEUP ) v_ll += step;
 
402
                else v_ll -= step;
 
403
 
 
404
                // Min/Max check
 
405
                wxIntProperty::DoValidation(property, v_ll, NULL, mode);
 
406
 
 
407
                s = wxLongLong(v_ll).ToString();
 
408
            }
 
409
            else
 
410
            {
 
411
                return false;
 
412
            }
 
413
        }
 
414
 
 
415
        if ( tc )
 
416
        {
 
417
            int ip = tc->GetInsertionPoint();
 
418
            int lp = tc->GetLastPosition();
 
419
            tc->SetValue(s);
 
420
            tc->SetInsertionPoint(ip+(tc->GetLastPosition()-lp));
 
421
        }
 
422
 
 
423
        return true;
 
424
    }
 
425
 
 
426
    return wxPGTextCtrlEditor::OnEvent(propgrid,property,wnd,event);
 
427
}
 
428
 
 
429
#endif // wxUSE_SPINBTN
 
430
 
 
431
 
 
432
// -----------------------------------------------------------------------
 
433
// wxDatePickerCtrl-based property editor
 
434
// -----------------------------------------------------------------------
 
435
 
 
436
#if wxUSE_DATEPICKCTRL
 
437
 
 
438
 
 
439
#include <wx/datectrl.h>
 
440
#include <wx/dateevt.h>
 
441
 
 
442
class wxPGDatePickerCtrlEditor : public wxPGEditor
 
443
{
 
444
    WX_PG_DECLARE_EDITOR_CLASS(wxPGDatePickerCtrlEditor)
 
445
public:
 
446
    virtual ~wxPGDatePickerCtrlEditor();
 
447
 
 
448
    wxPG_DECLARE_CREATECONTROLS
 
449
 
 
450
    virtual void UpdateControl( wxPGProperty* property, wxWindow* wnd ) const;
 
451
    virtual bool OnEvent( wxPropertyGrid* propgrid, wxPGProperty* property,
 
452
        wxWindow* wnd, wxEvent& event ) const;
 
453
    virtual bool GetValueFromControl( wxVariant& variant, wxPGProperty* property, wxWindow* wnd ) const;
 
454
    virtual void SetValueToUnspecified( wxPGProperty* WXUNUSED(property), wxWindow* wnd ) const;
 
455
};
 
456
 
 
457
 
 
458
WX_PG_IMPLEMENT_EDITOR_CLASS(DatePickerCtrl,wxPGDatePickerCtrlEditor,wxPGEditor)
 
459
 
 
460
 
 
461
wxPGDatePickerCtrlEditor::~wxPGDatePickerCtrlEditor()
 
462
{
 
463
}
 
464
 
 
465
wxPGWindowList wxPGDatePickerCtrlEditor::CreateControls( wxPropertyGrid* propgrid,
 
466
                                                         wxPGProperty* property,
 
467
                                                         const wxPoint& pos,
 
468
                                                         const wxSize& sz ) const
 
469
{
 
470
    wxCHECK_MSG( property->IsKindOf(WX_PG_CLASSINFO(wxDateProperty)),
 
471
                 NULL,
 
472
                 wxT("DatePickerCtrl editor can only be used with wxDateProperty or derivative.") );
 
473
 
 
474
    wxDateProperty* prop = (wxDateProperty*) property;
 
475
 
 
476
    // Use two stage creation to allow cleaner display on wxMSW
 
477
    wxDatePickerCtrl* ctrl = new wxDatePickerCtrl();
 
478
#ifdef __WXMSW__
 
479
    ctrl->Hide();
 
480
    wxSize useSz = wxDefaultSize;
 
481
    useSz.x = sz.x;
 
482
#else
 
483
    wxSize useSz = sz;
 
484
#endif
 
485
 
 
486
    wxDateTime dateValue(wxInvalidDateTime);
 
487
    if ( prop->GetType() == wxT("datetime") )
 
488
        dateValue = prop->GetDateValue();
 
489
 
 
490
    ctrl->Create(propgrid->GetPanel(),
 
491
                 wxPG_SUBID1,
 
492
                 dateValue,
 
493
                 pos,
 
494
                 useSz,
 
495
                 prop->GetDatePickerStyle() | wxNO_BORDER);
 
496
 
 
497
    // Connect all required events to grid's OnCustomEditorEvent
 
498
    // (all relevenat wxTextCtrl, wxComboBox and wxButton events are
 
499
    // already connected)
 
500
    propgrid->Connect( wxPG_SUBID1, wxEVT_DATE_CHANGED,
 
501
                       (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction)
 
502
                       &wxPropertyGrid::OnCustomEditorEvent );
 
503
 
 
504
#ifdef __WXMSW__
 
505
    ctrl->Show();
 
506
#endif
 
507
 
 
508
    return ctrl;
 
509
}
 
510
 
 
511
// Copies value from property to control
 
512
void wxPGDatePickerCtrlEditor::UpdateControl( wxPGProperty* property, wxWindow* wnd ) const
 
513
{
 
514
    wxDatePickerCtrl* ctrl = (wxDatePickerCtrl*) wnd;
 
515
    wxASSERT( ctrl && ctrl->IsKindOf(CLASSINFO(wxDatePickerCtrl)) );
 
516
 
 
517
    // We assume that property's data type is 'int' (or something similar),
 
518
    // thus allowing us to get raw, unchecked value via DoGetValue.
 
519
    ctrl->SetValue( property->GetValue().GetDateTime() );
 
520
}
 
521
 
 
522
// Control's events are redirected here
 
523
bool wxPGDatePickerCtrlEditor::OnEvent( wxPropertyGrid* WXUNUSED(propgrid),
 
524
                                        wxPGProperty* WXUNUSED(property),
 
525
                                        wxWindow* WXUNUSED(wnd),
 
526
                                        wxEvent& event ) const
 
527
{
 
528
    if ( event.GetEventType() == wxEVT_DATE_CHANGED )
 
529
        return true;
 
530
 
 
531
    return false;
 
532
}
 
533
 
 
534
bool wxPGDatePickerCtrlEditor::GetValueFromControl( wxVariant& variant, wxPGProperty* WXUNUSED(property), wxWindow* wnd ) const
 
535
{
 
536
    wxDatePickerCtrl* ctrl = (wxDatePickerCtrl*) wnd;
 
537
    wxASSERT( ctrl && ctrl->IsKindOf(CLASSINFO(wxDatePickerCtrl)) );
 
538
 
 
539
    variant = ctrl->GetValue();
 
540
 
 
541
    return true;
 
542
}
 
543
 
 
544
void wxPGDatePickerCtrlEditor::SetValueToUnspecified( wxPGProperty* WXUNUSED(property), wxWindow* WXUNUSED(wnd) ) const
 
545
{
 
546
    // TODO?
 
547
    //wxDateProperty* prop = (wxDateProperty*) property;
 
548
    //ctrl->SetValue(?);
 
549
}
 
550
 
 
551
#endif // wxUSE_DATEPICKCTRL
 
552
 
 
553
 
 
554
// -----------------------------------------------------------------------
 
555
// wxFontProperty
 
556
// -----------------------------------------------------------------------
 
557
 
 
558
#include <wx/fontdlg.h>
 
559
#include <wx/fontenum.h>
 
560
 
 
561
static const wxChar* gs_fp_es_family_labels[] = {
 
562
    wxT("Default"), wxT("Decorative"),
 
563
    wxT("Roman"), wxT("Script"),
 
564
    wxT("Swiss"), wxT("Modern"),
 
565
    (const wxChar*) NULL
 
566
};
 
567
 
 
568
static long gs_fp_es_family_values[] = {
 
569
    wxDEFAULT, wxDECORATIVE,
 
570
    wxROMAN, wxSCRIPT,
 
571
    wxSWISS, wxMODERN
 
572
};
 
573
 
 
574
static const wxChar* gs_fp_es_style_labels[] = {
 
575
    wxT("Normal"),
 
576
    wxT("Slant"),
 
577
    wxT("Italic"),
 
578
    (const wxChar*) NULL
 
579
};
 
580
 
 
581
static long gs_fp_es_style_values[] = {
 
582
    wxNORMAL,
 
583
    wxSLANT,
 
584
    wxITALIC
 
585
};
 
586
 
 
587
static const wxChar* gs_fp_es_weight_labels[] = {
 
588
    wxT("Normal"),
 
589
    wxT("Light"),
 
590
    wxT("Bold"),
 
591
    (const wxChar*) NULL
 
592
};
 
593
 
 
594
static long gs_fp_es_weight_values[] = {
 
595
    wxNORMAL,
 
596
    wxLIGHT,
 
597
    wxBOLD
 
598
};
 
599
 
 
600
// Class body is in advprops.h
 
601
 
 
602
 
 
603
WX_PG_IMPLEMENT_PROPERTY_CLASS(wxFontProperty,wxPGProperty,
 
604
                               wxFont,const wxFont&,TextCtrlAndButton)
 
605
 
 
606
 
 
607
wxFontProperty::wxFontProperty( const wxString& label, const wxString& name,
 
608
                                const wxFont& value )
 
609
    : wxPGProperty(label,name)
 
610
{
 
611
    SetValue( wxFontToVariant(value) );
 
612
 
 
613
    // Initialize font family choices list
 
614
    if ( !wxPGGlobalVars->m_fontFamilyChoices )
 
615
    {
 
616
        wxFontEnumerator enumerator;
 
617
        enumerator.EnumerateFacenames();
 
618
 
 
619
#if wxMINOR_VERSION > 6
 
620
        wxArrayString faceNames = enumerator.GetFacenames();
 
621
#else
 
622
        wxArrayString& faceNames = *enumerator.GetFacenames();
 
623
#endif
 
624
 
 
625
        faceNames.Sort();
 
626
 
 
627
        wxPGGlobalVars->m_fontFamilyChoices = new wxPGChoices(faceNames);
 
628
    }
 
629
 
 
630
    wxString emptyString(wxEmptyString);
 
631
 
 
632
    wxFont& font = wxFontFromVariant(m_value);
 
633
 
 
634
    AddChild( new wxIntProperty( _("Point Size"), wxT("Point Size"), (long)font.GetPointSize() ) );
 
635
 
 
636
    AddChild( new wxEnumProperty(_("Family"), wxT("Family"),
 
637
              gs_fp_es_family_labels,gs_fp_es_family_values,
 
638
              font.GetFamily()) );
 
639
 
 
640
    wxString faceName = font.GetFaceName();
 
641
    // If font was not in there, add it now
 
642
    if ( faceName.length() &&
 
643
         wxPGGlobalVars->m_fontFamilyChoices->Index(faceName) == wxNOT_FOUND )
 
644
        wxPGGlobalVars->m_fontFamilyChoices->AddAsSorted(faceName);
 
645
 
 
646
    wxPGProperty* p = new wxEnumProperty(_("Face Name"), wxT("Face Name"),
 
647
                                         *wxPGGlobalVars->m_fontFamilyChoices);
 
648
 
 
649
    p->SetValueFromString(faceName, wxPG_FULL_VALUE);
 
650
 
 
651
    AddChild( p );
 
652
 
 
653
    AddChild( new wxEnumProperty(_("Style"), wxT("Style"),
 
654
              gs_fp_es_style_labels,gs_fp_es_style_values,font.GetStyle()) );
 
655
 
 
656
    AddChild( new wxEnumProperty(_("Weight"), wxT("Weight"),
 
657
              gs_fp_es_weight_labels,gs_fp_es_weight_values,font.GetWeight()) );
 
658
 
 
659
    AddChild( new wxBoolProperty(_("Underlined"), wxT("Underlined"),
 
660
              font.GetUnderlined()) );
 
661
}
 
662
 
 
663
wxFontProperty::~wxFontProperty() { }
 
664
 
 
665
void wxFontProperty::OnSetValue()
 
666
{
 
667
    wxFont& font = wxFontFromVariant(m_value);
 
668
    wxASSERT(&font);
 
669
 
 
670
    wxFont font2;
 
671
    if ( !font.Ok() )
 
672
        font2 = wxFont(10,wxSWISS,wxNORMAL,wxNORMAL);
 
673
    else
 
674
        font2 = font;
 
675
 
 
676
    m_value = wxFontToVariant(font2);
 
677
}
 
678
 
 
679
wxString wxFontProperty::GetValueAsString( int argFlags ) const
 
680
{
 
681
    return wxPGProperty::GetValueAsString(argFlags);
 
682
}
 
683
 
 
684
bool wxFontProperty::OnEvent( wxPropertyGrid* propgrid, wxWindow* WXUNUSED(primary),
 
685
                              wxEvent& event )
 
686
{
 
687
    if ( propgrid->IsMainButtonEvent(event) )
 
688
    {
 
689
        // Update value from last minute changes
 
690
        PrepareValueForDialogEditing(propgrid);
 
691
 
 
692
        wxFontData data;
 
693
        data.SetInitialFont( wxFontFromVariant(m_value) );
 
694
        data.SetColour(*wxBLACK);
 
695
 
 
696
        wxFontDialog dlg(propgrid, data);
 
697
        if ( dlg.ShowModal() == wxID_OK )
 
698
        {
 
699
            propgrid->EditorsValueWasModified();
 
700
 
 
701
            wxVariant variant = wxFontToVariant(dlg.GetFontData().GetChosenFont());
 
702
            SetValueInEvent( variant );
 
703
            return true;
 
704
        }
 
705
    }
 
706
    return false;
 
707
}
 
708
 
 
709
void wxFontProperty::RefreshChildren()
 
710
{
 
711
    if ( !GetCount() ) return;
 
712
    const wxFont& font = wxFontFromVariant(m_value);
 
713
    Item(0)->SetValue( (long)font.GetPointSize() );
 
714
    Item(1)->SetValue( (long)font.GetFamily() );
 
715
    Item(2)->SetValueFromString( font.GetFaceName(), wxPG_FULL_VALUE );
 
716
    Item(3)->SetValue( (long)font.GetStyle() );
 
717
    Item(4)->SetValue( (long)font.GetWeight() );
 
718
    Item(5)->SetValue( font.GetUnderlined() );
 
719
}
 
720
 
 
721
void wxFontProperty::ChildChanged( wxVariant& thisValue, int ind, wxVariant& childValue ) const
 
722
{
 
723
    wxFont& font = wxFontFromVariant(thisValue);
 
724
 
 
725
    if ( ind == 0 )
 
726
    {
 
727
        font.SetPointSize( wxPGVariantToInt(childValue) );
 
728
    }
 
729
    else if ( ind == 1 )
 
730
    {
 
731
        int fam = childValue.GetLong();
 
732
        if ( fam < wxDEFAULT ||
 
733
             fam > wxTELETYPE )
 
734
             fam = wxDEFAULT;
 
735
        font.SetFamily( fam );
 
736
    }
 
737
    else if ( ind == 2 )
 
738
    {
 
739
        wxString faceName;
 
740
        int faceIndex = childValue.GetLong();
 
741
 
 
742
        if ( faceIndex >= 0 )
 
743
            faceName = wxPGGlobalVars->m_fontFamilyChoices->GetLabel(faceIndex);
 
744
 
 
745
        font.SetFaceName( faceName );
 
746
    }
 
747
    else if ( ind == 3 )
 
748
    {
 
749
        int st = childValue.GetLong();
 
750
        if ( st != wxFONTSTYLE_NORMAL &&
 
751
             st != wxFONTSTYLE_SLANT &&
 
752
             st != wxFONTSTYLE_ITALIC )
 
753
             st = wxFONTWEIGHT_NORMAL;
 
754
        font.SetStyle( st );
 
755
    }
 
756
    else if ( ind == 4 )
 
757
    {
 
758
        int wt = childValue.GetLong();
 
759
        if ( wt != wxFONTWEIGHT_NORMAL &&
 
760
             wt != wxFONTWEIGHT_LIGHT &&
 
761
             wt != wxFONTWEIGHT_BOLD )
 
762
             wt = wxFONTWEIGHT_NORMAL;
 
763
        font.SetWeight( wt );
 
764
    }
 
765
    else if ( ind == 5 )
 
766
    {
 
767
        font.SetUnderlined( childValue.GetBool() );
 
768
    }
 
769
}
 
770
 
 
771
/*
 
772
wxSize wxFontProperty::OnMeasureImage() const
 
773
{
 
774
    return wxSize(-1,-1);
 
775
}
 
776
 
 
777
void wxFontProperty::OnCustomPaint(wxDC& dc,
 
778
                                        const wxRect& rect,
 
779
                                        wxPGPaintData& paintData)
 
780
{
 
781
    wxString drawFace;
 
782
    if ( paintData.m_choiceItem >= 0 )
 
783
        drawFace = wxPGGlobalVars->m_fontFamilyChoices->GetLabel(paintData.m_choiceItem);
 
784
    else
 
785
        drawFace = m_value_wxFont.GetFaceName();
 
786
 
 
787
    if ( drawFace.length() )
 
788
    {
 
789
        // Draw the background
 
790
        dc.SetBrush( wxColour(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE)) );
 
791
        //dc.SetBrush( *wxWHITE_BRUSH );
 
792
        //dc.SetPen( *wxMEDIUM_GREY_PEN );
 
793
        dc.DrawRectangle( rect );
 
794
 
 
795
        wxFont oldFont = dc.GetFont();
 
796
        wxFont drawFont(oldFont.GetPointSize(),
 
797
                        wxDEFAULT,wxNORMAL,wxBOLD,false,drawFace);
 
798
        dc.SetFont(drawFont);
 
799
 
 
800
        dc.SetTextForeground( wxSystemSettings::GetColour(wxSYS_COLOUR_BTNTEXT) );
 
801
        dc.DrawText( wxT("Aa"), rect.x+2, rect.y+1 );
 
802
 
 
803
        dc.SetFont(oldFont);
 
804
    }
 
805
    else
 
806
    {
 
807
        // No file - just draw a white box
 
808
        dc.SetBrush ( *wxWHITE_BRUSH );
 
809
        dc.DrawRectangle ( rect );
 
810
    }
 
811
}
 
812
*/
 
813
 
 
814
 
 
815
// -----------------------------------------------------------------------
 
816
// wxSystemColourProperty
 
817
// -----------------------------------------------------------------------
 
818
 
 
819
// wxEnumProperty based classes cannot use wxPG_PROP_CLASS_SPECIFIC_1
 
820
#define wxPG_PROP_HIDE_CUSTOM_COLOUR        wxPG_PROP_CLASS_SPECIFIC_2
 
821
 
 
822
#include <wx/colordlg.h>
 
823
 
 
824
//#define wx_cp_es_syscolours_len 25
 
825
static const wxChar* gs_cp_es_syscolour_labels[] = {
 
826
    wxT("AppWorkspace"),
 
827
    wxT("ActiveBorder"),
 
828
    wxT("ActiveCaption"),
 
829
    wxT("ButtonFace"),
 
830
    wxT("ButtonHighlight"),
 
831
    wxT("ButtonShadow"),
 
832
    wxT("ButtonText"),
 
833
    wxT("CaptionText"),
 
834
    wxT("ControlDark"),
 
835
    wxT("ControlLight"),
 
836
    wxT("Desktop"),
 
837
    wxT("GrayText"),
 
838
    wxT("Highlight"),
 
839
    wxT("HighlightText"),
 
840
    wxT("InactiveBorder"),
 
841
    wxT("InactiveCaption"),
 
842
    wxT("InactiveCaptionText"),
 
843
    wxT("Menu"),
 
844
    wxT("Scrollbar"),
 
845
    wxT("Tooltip"),
 
846
    wxT("TooltipText"),
 
847
    wxT("Window"),
 
848
    wxT("WindowFrame"),
 
849
    wxT("WindowText"),
 
850
    wxT("Custom"),
 
851
    (const wxChar*) NULL
 
852
};
 
853
 
 
854
static long gs_cp_es_syscolour_values[] = {
 
855
    wxSYS_COLOUR_APPWORKSPACE,
 
856
    wxSYS_COLOUR_ACTIVEBORDER,
 
857
    wxSYS_COLOUR_ACTIVECAPTION,
 
858
    wxSYS_COLOUR_BTNFACE,
 
859
    wxSYS_COLOUR_BTNHIGHLIGHT,
 
860
    wxSYS_COLOUR_BTNSHADOW,
 
861
    wxSYS_COLOUR_BTNTEXT ,
 
862
    wxSYS_COLOUR_CAPTIONTEXT,
 
863
    wxSYS_COLOUR_3DDKSHADOW,
 
864
    wxSYS_COLOUR_3DLIGHT,
 
865
    wxSYS_COLOUR_BACKGROUND,
 
866
    wxSYS_COLOUR_GRAYTEXT,
 
867
    wxSYS_COLOUR_HIGHLIGHT,
 
868
    wxSYS_COLOUR_HIGHLIGHTTEXT,
 
869
    wxSYS_COLOUR_INACTIVEBORDER,
 
870
    wxSYS_COLOUR_INACTIVECAPTION,
 
871
    wxSYS_COLOUR_INACTIVECAPTIONTEXT,
 
872
    wxSYS_COLOUR_MENU,
 
873
    wxSYS_COLOUR_SCROLLBAR,
 
874
    wxSYS_COLOUR_INFOBK,
 
875
    wxSYS_COLOUR_INFOTEXT,
 
876
    wxSYS_COLOUR_WINDOW,
 
877
    wxSYS_COLOUR_WINDOWFRAME,
 
878
    wxSYS_COLOUR_WINDOWTEXT,
 
879
    wxPG_COLOUR_CUSTOM
 
880
};
 
881
 
 
882
 
 
883
WX_PG_IMPLEMENT_WXOBJECT_VARIANT_DATA_WITH_PROPER_EQ(wxPGVariantDataColourPropertyValue,
 
884
                                                     wxColourPropertyValue)
 
885
 
 
886
 
 
887
// Class body is in advprops.h
 
888
 
 
889
WX_PG_IMPLEMENT_PROPERTY_CLASS(wxSystemColourProperty,wxEnumProperty,
 
890
                               wxColourPropertyValue,const wxColourPropertyValue&,Choice)
 
891
 
 
892
 
 
893
void wxSystemColourProperty::Init( int type, const wxColour& colour )
 
894
{
 
895
    wxColourPropertyValue cpv;
 
896
 
 
897
    if ( colour.Ok() )
 
898
        cpv.Init( type, colour );
 
899
    else
 
900
        cpv.Init( type, *wxWHITE );
 
901
 
 
902
    m_flags |= wxPG_PROP_STATIC_CHOICES; // Colour selection cannot be changed.
 
903
 
 
904
    m_value = wxColourPropertyValueToVariant(cpv);
 
905
 
 
906
    OnSetValue();
 
907
}
 
908
 
 
909
 
 
910
static wxPGChoices gs_wxSystemColourProperty_choicesCache;
 
911
 
 
912
 
 
913
wxSystemColourProperty::wxSystemColourProperty( const wxString& label, const wxString& name,
 
914
    const wxColourPropertyValue& value )
 
915
    : wxEnumProperty( label,
 
916
                      name,
 
917
                      gs_cp_es_syscolour_labels,
 
918
                      gs_cp_es_syscolour_values,
 
919
                      &gs_wxSystemColourProperty_choicesCache )
 
920
{
 
921
    if ( &value )
 
922
        Init( value.m_type, value.m_colour );
 
923
    else
 
924
        Init( wxPG_COLOUR_CUSTOM, *wxWHITE );
 
925
}
 
926
 
 
927
 
 
928
wxSystemColourProperty::wxSystemColourProperty( const wxString& label, const wxString& name,
 
929
    const wxChar** labels, const long* values, wxPGChoices* choicesCache,
 
930
    const wxColourPropertyValue& value )
 
931
    : wxEnumProperty( label, name, labels, values, choicesCache )
 
932
{
 
933
    if ( &value )
 
934
        Init( value.m_type, value.m_colour );
 
935
    else
 
936
        Init( wxPG_COLOUR_CUSTOM, *wxWHITE );
 
937
}
 
938
 
 
939
 
 
940
wxSystemColourProperty::wxSystemColourProperty( const wxString& label, const wxString& name,
 
941
    const wxChar** labels, const long* values, wxPGChoices* choicesCache,
 
942
    const wxColour& value )
 
943
    : wxEnumProperty( label, name, labels, values, choicesCache )
 
944
{
 
945
    if ( &value )
 
946
        Init( wxPG_COLOUR_CUSTOM, value );
 
947
    else
 
948
        Init( wxPG_COLOUR_CUSTOM, *wxWHITE );
 
949
}
 
950
 
 
951
 
 
952
wxSystemColourProperty::~wxSystemColourProperty() { }
 
953
 
 
954
 
 
955
wxColourPropertyValue wxSystemColourProperty::GetVal( const wxVariant* pVariant ) const
 
956
{
 
957
    if ( !pVariant )
 
958
        pVariant = &m_value;
 
959
 
 
960
    if ( pVariant->IsNull() )
 
961
        return wxColourPropertyValue(wxPG_COLOUR_UNSPECIFIED, wxColour());
 
962
 
 
963
    wxColourPropertyValue* v1 = &wxColourPropertyValueFromVariant(*pVariant);
 
964
    if ( v1 )
 
965
        return *v1;
 
966
 
 
967
    wxColour* pCol = wxGetVariantCast(*pVariant, wxColour);
 
968
    wxColour col;
 
969
 
 
970
    if ( pCol )
 
971
        col = *pCol;
 
972
    else
 
973
        col << *pVariant;
 
974
 
 
975
    wxColourPropertyValue v2( wxPG_COLOUR_CUSTOM, col );
 
976
 
 
977
    int colInd = ColToInd(col);
 
978
    if ( colInd != wxNOT_FOUND )
 
979
        v2.m_type = colInd;
 
980
 
 
981
    return v2;
 
982
}
 
983
 
 
984
wxVariant wxSystemColourProperty::DoTranslateVal( wxColourPropertyValue& v ) const
 
985
{
 
986
    return wxColourPropertyValueToVariant(v);
 
987
}
 
988
 
 
989
int wxSystemColourProperty::ColToInd( const wxColour& colour ) const
 
990
{
 
991
    size_t i;
 
992
    size_t i_max = m_choices.GetCount() - 1;
 
993
 
 
994
    for ( i=0; i<i_max; i++ )
 
995
    {
 
996
        int ind = m_choices[i].GetValue();
 
997
 
 
998
        if ( colour == GetColour(ind) )
 
999
        {
 
1000
            /*wxLogDebug(wxT("%s(%s): Index %i for ( getcolour(%i,%i,%i), colour(%i,%i,%i))"),
 
1001
                GetClassName(),GetLabel().c_str(),
 
1002
                (int)i,(int)GetColour(ind).Red(),(int)GetColour(ind).Green(),(int)GetColour(ind).Blue(),
 
1003
                (int)colour.Red(),(int)colour.Green(),(int)colour.Blue());*/
 
1004
            return ind;
 
1005
        }
 
1006
    }
 
1007
    return wxNOT_FOUND;
 
1008
}
 
1009
 
 
1010
 
 
1011
static inline wxColour wxColourFromPGLong( long col )
 
1012
{
 
1013
    return wxColour((col&0xFF),((col>>8)&0xFF),((col>>16)&0xFF));
 
1014
}
 
1015
 
 
1016
 
 
1017
void wxSystemColourProperty::OnSetValue()
 
1018
{
 
1019
    // Convert from generic wxobject ptr to wxPGVariantDataColour
 
1020
    if ( wxPGIsVariantType(m_value, wxobject) )
 
1021
    {
 
1022
        wxASSERT( m_value.IsValueKindOf(CLASSINFO(wxColour)) );
 
1023
        wxColour* pCol = (wxColour*) m_value.GetWxObjectPtr();
 
1024
#if wxCHECK_VERSION(2,8,0)
 
1025
        m_value << *pCol;
 
1026
#else
 
1027
        wxPGVariantAssign(m_value, WXVARIANT(*pCol));
 
1028
#endif
 
1029
    }
 
1030
 
 
1031
    wxColourPropertyValue val = GetVal(&m_value);
 
1032
 
 
1033
    if ( val.m_type == wxPG_COLOUR_UNSPECIFIED )
 
1034
    {
 
1035
        m_value.MakeNull();
 
1036
        return;
 
1037
    }
 
1038
    else
 
1039
    {
 
1040
 
 
1041
        if ( val.m_type < wxPG_COLOUR_WEB_BASE )
 
1042
            val.m_colour = GetColour( val.m_type );
 
1043
 
 
1044
        m_value = TranslateVal(val);
 
1045
    }
 
1046
 
 
1047
    wxColourPropertyValue* pCpv = &wxColourPropertyValueFromVariant(m_value);
 
1048
    wxColour col;
 
1049
    if ( pCpv )
 
1050
        col = pCpv->m_colour;
 
1051
    else
 
1052
        col << m_value;
 
1053
 
 
1054
    if ( !col.Ok() )
 
1055
    {
 
1056
        SetValueToUnspecified();
 
1057
        SetIndex(wxNOT_FOUND);
 
1058
        return;
 
1059
    }
 
1060
 
 
1061
    int ind;
 
1062
 
 
1063
    if ( pCpv )
 
1064
    {
 
1065
        if ( pCpv->m_type < wxPG_COLOUR_WEB_BASE )
 
1066
        {
 
1067
            ind = GetIndexForValue(pCpv->m_type);
 
1068
        }
 
1069
        else
 
1070
        {
 
1071
            pCpv->m_type = wxPG_COLOUR_CUSTOM;
 
1072
            ind = GetCustomColourIndex();
 
1073
        }
 
1074
    }
 
1075
    else
 
1076
    {
 
1077
        ind = ColToInd(col);
 
1078
 
 
1079
        if ( ind == wxNOT_FOUND )
 
1080
            ind = GetCustomColourIndex();
 
1081
    }
 
1082
 
 
1083
    SetIndex(ind);
 
1084
}
 
1085
 
 
1086
 
 
1087
wxColour wxSystemColourProperty::GetColour( int index ) const
 
1088
{
 
1089
    return wxSystemSettings::GetColour( (wxSystemColour)index );
 
1090
}
 
1091
 
 
1092
wxString wxSystemColourProperty::ColourToString( const wxColour& col, int index ) const
 
1093
{
 
1094
    if ( index == wxNOT_FOUND )
 
1095
        return wxString::Format(wxT("(%i,%i,%i)"),
 
1096
                                (int)col.Red(),
 
1097
                                (int)col.Green(),
 
1098
                                (int)col.Blue());
 
1099
    else
 
1100
        return m_choices.GetLabel(index);
 
1101
}
 
1102
 
 
1103
wxString wxSystemColourProperty::GetValueAsString( int argFlags ) const
 
1104
{
 
1105
    wxColourPropertyValue val = GetVal();
 
1106
 
 
1107
    int ind = GetIndex();
 
1108
 
 
1109
    // Always show custom colour for textctrl-editor
 
1110
    if ( val.m_type == wxPG_COLOUR_CUSTOM ||
 
1111
         ind == GetCustomColourIndex() ||
 
1112
         (argFlags & wxPG_PROPERTY_SPECIFIC) )
 
1113
    {
 
1114
        return ColourToString(val.m_colour, wxNOT_FOUND);
 
1115
    }
 
1116
 
 
1117
    if ( ind == -1 )
 
1118
        return wxEmptyString;
 
1119
 
 
1120
    return ColourToString(val.m_colour, ind);
 
1121
}
 
1122
 
 
1123
 
 
1124
wxSize wxSystemColourProperty::OnMeasureImage( int ) const
 
1125
{
 
1126
    return wxPG_DEFAULT_IMAGE_SIZE;
 
1127
}
 
1128
 
 
1129
 
 
1130
int wxSystemColourProperty::GetCustomColourIndex() const
 
1131
{
 
1132
    return m_choices.GetCount() - 1;
 
1133
}
 
1134
 
 
1135
 
 
1136
bool wxSystemColourProperty::QueryColourFromUser( wxVariant& variant ) const
 
1137
{
 
1138
    wxASSERT( m_value.GetType() != wxT("string") );
 
1139
    bool res = false;
 
1140
 
 
1141
    wxPropertyGrid* propgrid = GetGrid();
 
1142
    wxASSERT( propgrid );
 
1143
 
 
1144
    // Must only occur when user triggers event
 
1145
    if ( !(propgrid->GetInternalFlags() & wxPG_FL_IN_ONCUSTOMEDITOREVENT) )
 
1146
        return res;
 
1147
 
 
1148
    wxColourPropertyValue val = GetVal();
 
1149
 
 
1150
    val.m_type = wxPG_COLOUR_CUSTOM;
 
1151
 
 
1152
    wxColourData data;
 
1153
    data.SetChooseFull(true);
 
1154
    data.SetColour(val.m_colour);
 
1155
    int i;
 
1156
    for ( i = 0; i < 16; i++)
 
1157
    {
 
1158
        wxColour colour(i*16, i*16, i*16);
 
1159
        data.SetCustomColour(i, colour);
 
1160
    }
 
1161
 
 
1162
    wxColourDialog dialog(propgrid, &data);
 
1163
    if ( dialog.ShowModal() == wxID_OK )
 
1164
    {
 
1165
        wxColourData retData = dialog.GetColourData();
 
1166
        val.m_colour = retData.GetColour();
 
1167
 
 
1168
        variant = DoTranslateVal(val);
 
1169
 
 
1170
        SetValueInEvent(variant);
 
1171
 
 
1172
        res = true;
 
1173
    }
 
1174
 
 
1175
    return res;
 
1176
}
 
1177
 
 
1178
 
 
1179
bool wxSystemColourProperty::IntToValue( wxVariant& variant, int number, int WXUNUSED(argFlags) ) const
 
1180
{
 
1181
    int index = number;
 
1182
    int type = GetValueForIndex(index);
 
1183
 
 
1184
    if ( type == wxPG_COLOUR_CUSTOM )
 
1185
    {
 
1186
        QueryColourFromUser(variant);
 
1187
    }
 
1188
    else
 
1189
    {
 
1190
        variant = TranslateVal( type, GetColour(type) );
 
1191
    }
 
1192
 
 
1193
    return true;
 
1194
}
 
1195
 
 
1196
// Need to do some extra event handling.
 
1197
bool wxSystemColourProperty::OnEvent( wxPropertyGrid* propgrid, wxWindow* WXUNUSED(primary), wxEvent& event )
 
1198
{
 
1199
    if ( propgrid->IsMainButtonEvent(event) )
 
1200
    {
 
1201
        // We need to handle button click in case editor has been
 
1202
        // switched to one that has wxButton as well.
 
1203
        wxVariant variant;
 
1204
        if ( QueryColourFromUser(variant) )
 
1205
            return true;
 
1206
    }
 
1207
    return false;
 
1208
}
 
1209
 
 
1210
/*class wxPGColourPropertyRenderer : public wxPGDefaultRenderer
 
1211
{
 
1212
public:
 
1213
    virtual void Render( wxDC& dc, const wxRect& rect,
 
1214
                         const wxPropertyGrid* propertyGrid, wxPGProperty* property,
 
1215
                         int WXUNUSED(column), int item, int WXUNUSED(flags) ) const
 
1216
    {
 
1217
        wxASSERT( property->IsKindOf(CLASSINFO(wxSystemColourProperty)) );
 
1218
        wxSystemColourProperty* prop = wxStaticCast(property, wxSystemColourProperty);
 
1219
 
 
1220
        dc.SetPen(*wxBLACK_PEN);
 
1221
        if ( item >= 0 &&
 
1222
             ( item < (int)(GetCustomColourIndex) || (prop->HasFlag(wxPG_PROP_HIDE_CUSTOM_COLOUR)))
 
1223
           )
 
1224
        {
 
1225
            int colInd;
 
1226
            const wxArrayInt& values = prop->GetValues();
 
1227
            if ( values.GetCount() )
 
1228
                colInd = values[item];
 
1229
            else
 
1230
                colInd = item;
 
1231
            dc.SetBrush( wxColour( prop->GetColour( colInd ) ) );
 
1232
        }
 
1233
        else if ( !prop->IsValueUnspecified() )
 
1234
            dc.SetBrush( prop->GetVal().m_colour );
 
1235
        else
 
1236
            dc.SetBrush( *wxWHITE );
 
1237
 
 
1238
        wxRect imageRect = propertyGrid->GetImageRect(property, item);
 
1239
        wxLogDebug(wxT("%i, %i"),imageRect.x,imageRect.y);
 
1240
        dc.DrawRectangle( rect.x+imageRect.x, rect.y+imageRect.y,
 
1241
                          imageRect.width, imageRect.height );
 
1242
 
 
1243
        wxString text;
 
1244
        if ( item == -1 )
 
1245
            text = property->GetValueAsString();
 
1246
        else
 
1247
            text = property->GetChoiceString(item);
 
1248
        DrawText( dc, rect, imageRect.width, text );
 
1249
    }
 
1250
protected:
 
1251
};
 
1252
 
 
1253
wxPGColourPropertyRenderer g_wxPGColourPropertyRenderer;
 
1254
 
 
1255
wxPGCellRenderer* wxSystemColourProperty::GetCellRenderer( int column ) const
 
1256
{
 
1257
    if ( column == 1 )
 
1258
        return &g_wxPGColourPropertyRenderer;
 
1259
    return wxEnumProperty::GetCellRenderer(column);
 
1260
}*/
 
1261
 
 
1262
void wxSystemColourProperty::OnCustomPaint( wxDC& dc, const wxRect& rect,
 
1263
                                            wxPGPaintData& paintdata )
 
1264
{
 
1265
    wxColour col;
 
1266
 
 
1267
    if ( paintdata.m_choiceItem >= 0 && paintdata.m_choiceItem < (int)m_choices.GetCount() &&
 
1268
         paintdata.m_choiceItem != GetCustomColourIndex() )
 
1269
    {
 
1270
        int colInd = m_choices[paintdata.m_choiceItem].GetValue();
 
1271
        col = GetColour( colInd );
 
1272
    }
 
1273
    else if ( !IsValueUnspecified() )
 
1274
    {
 
1275
        col = GetVal().m_colour;
 
1276
    }
 
1277
 
 
1278
    if ( col.Ok() )
 
1279
    {
 
1280
        dc.SetBrush(col);
 
1281
        dc.DrawRectangle(rect);
 
1282
    }
 
1283
}
 
1284
 
 
1285
 
 
1286
bool wxSystemColourProperty::StringToValue( wxVariant& value, const wxString& text, int argFlags ) const
 
1287
{
 
1288
    //
 
1289
    // Accept colour format "[Name] [(R,G,B)]"
 
1290
    // Name takes precedence.
 
1291
    //
 
1292
    wxString colourName;
 
1293
    wxString colourRGB;
 
1294
 
 
1295
    int ppos = text.Find(wxT("("));
 
1296
 
 
1297
    if ( ppos == wxNOT_FOUND )
 
1298
    {
 
1299
        colourName = text;
 
1300
    }
 
1301
    else
 
1302
    {
 
1303
        colourName = text.substr(0, ppos);
 
1304
        colourRGB = text.substr(ppos, text.length()-ppos);
 
1305
    }
 
1306
 
 
1307
    // Strip spaces from extremities
 
1308
    colourName.Trim(true);
 
1309
    colourName.Trim(false);
 
1310
    colourRGB.Trim(true);
 
1311
 
 
1312
    // Validate colourRGB string - (1,1,1) is shortest allowed
 
1313
    if ( colourRGB.length() < 7 )
 
1314
        colourRGB.clear();
 
1315
 
 
1316
    if ( colourRGB.length() == 0 && m_choices.GetCount() &&
 
1317
         colourName == m_choices.GetLabel(GetCustomColourIndex()) )
 
1318
    {
 
1319
        if ( !(argFlags & wxPG_EDITABLE_VALUE ))
 
1320
        {
 
1321
            // This really should not occurr...
 
1322
            // wxASSERT(false);
 
1323
            ResetNextIndex();
 
1324
            return false;
 
1325
        }
 
1326
 
 
1327
        QueryColourFromUser(value);
 
1328
    }
 
1329
    else
 
1330
    {
 
1331
        wxColourPropertyValue val;
 
1332
 
 
1333
        bool done = false;
 
1334
 
 
1335
        if ( colourName.length() )
 
1336
        {
 
1337
            // Try predefined colour first
 
1338
            bool res = wxEnumProperty::StringToValue(value, colourName, argFlags);
 
1339
            if ( res && GetIndex() >= 0 )
 
1340
            {
 
1341
                val.m_type = GetIndex();
 
1342
                if ( val.m_type >= 0 && val.m_type < m_choices.GetCount() )
 
1343
                    val.m_type = m_choices[val.m_type].GetValue();
 
1344
 
 
1345
                // Get proper colour for type.
 
1346
                val.m_colour = GetColour(val.m_type);
 
1347
 
 
1348
                done = true;
 
1349
            }
 
1350
        }
 
1351
        if ( colourRGB.length() && !done )
 
1352
        {
 
1353
            // Then check custom colour.
 
1354
            val.m_type = wxPG_COLOUR_CUSTOM;
 
1355
 
 
1356
            int r = -1, g = -1, b = -1;
 
1357
            wxSscanf(colourRGB.c_str(),wxT("(%i,%i,%i)"),&r,&g,&b);
 
1358
 
 
1359
            if ( r >= 0 && r <= 255 &&
 
1360
                 g >= 0 && g <= 255 &&
 
1361
                 b >= 0 && b <= 255 )
 
1362
            {
 
1363
                val.m_colour.Set(r,g,b);
 
1364
 
 
1365
                done = true;
 
1366
            }
 
1367
        }
 
1368
 
 
1369
        if ( !done )
 
1370
        {
 
1371
            ResetNextIndex();
 
1372
            return false;
 
1373
        }
 
1374
 
 
1375
        value = DoTranslateVal(val);
 
1376
    }
 
1377
 
 
1378
    return true;
 
1379
}
 
1380
 
 
1381
 
 
1382
bool wxSystemColourProperty::DoSetAttribute( const wxString& name, wxVariant& value )
 
1383
{
 
1384
    if ( name == wxPG_COLOUR_ALLOW_CUSTOM )
 
1385
    {
 
1386
        int ival = wxPGVariantToInt(value);
 
1387
 
 
1388
        SetChoicesExclusive(); // Make sure we don't corrupt colour lists of other properties
 
1389
 
 
1390
        if ( ival && (m_flags & wxPG_PROP_HIDE_CUSTOM_COLOUR) )
 
1391
        {
 
1392
            // Show custom choice
 
1393
            m_choices.Insert(wxT("Custom"), GetCustomColourIndex(), wxPG_COLOUR_CUSTOM);
 
1394
            m_flags &= ~(wxPG_PROP_HIDE_CUSTOM_COLOUR);
 
1395
        }
 
1396
        else if ( !ival && !(m_flags & wxPG_PROP_HIDE_CUSTOM_COLOUR) )
 
1397
        {
 
1398
            // Hide custom choice
 
1399
            m_choices.RemoveAt(GetCustomColourIndex());
 
1400
            m_flags |= wxPG_PROP_HIDE_CUSTOM_COLOUR;
 
1401
        }
 
1402
        return true;
 
1403
    }
 
1404
    return false;
 
1405
}
 
1406
 
 
1407
 
 
1408
// -----------------------------------------------------------------------
 
1409
// wxColourProperty
 
1410
// -----------------------------------------------------------------------
 
1411
 
 
1412
static const wxChar* gs_cp_es_normcolour_labels[] = {
 
1413
    wxT("Black"),
 
1414
    wxT("Maroon"),
 
1415
    wxT("Navy"),
 
1416
    wxT("Purple"),
 
1417
    wxT("Teal"),
 
1418
    wxT("Gray"),
 
1419
    wxT("Green"),
 
1420
    wxT("Olive"),
 
1421
    wxT("Brown"),
 
1422
    wxT("Blue"),
 
1423
    wxT("Fuchsia"),
 
1424
    wxT("Red"),
 
1425
    wxT("Orange"),
 
1426
    wxT("Silver"),
 
1427
    wxT("Lime"),
 
1428
    wxT("Aqua"),
 
1429
    wxT("Yellow"),
 
1430
    wxT("White"),
 
1431
    wxT("Custom"),
 
1432
    (const wxChar*) NULL
 
1433
};
 
1434
 
 
1435
static unsigned long gs_cp_es_normcolour_colours[] = {
 
1436
    wxPG_COLOUR(0,0,0),
 
1437
    wxPG_COLOUR(128,0,0),
 
1438
    wxPG_COLOUR(0,0,128),
 
1439
    wxPG_COLOUR(128,0,128),
 
1440
    wxPG_COLOUR(0,128,128),
 
1441
    wxPG_COLOUR(128,128,128),
 
1442
    wxPG_COLOUR(0,128,0),
 
1443
    wxPG_COLOUR(128,128,0),
 
1444
    wxPG_COLOUR(166,124,81),
 
1445
    wxPG_COLOUR(0,0,255),
 
1446
    wxPG_COLOUR(255,0,255),
 
1447
    wxPG_COLOUR(255,0,0),
 
1448
    wxPG_COLOUR(247,148,28),
 
1449
    wxPG_COLOUR(192,192,192),
 
1450
    wxPG_COLOUR(0,255,0),
 
1451
    wxPG_COLOUR(0,255,255),
 
1452
    wxPG_COLOUR(255,255,0),
 
1453
    wxPG_COLOUR(255,255,255),
 
1454
    wxPG_COLOUR(0,0,0)
 
1455
};
 
1456
 
 
1457
WX_PG_IMPLEMENT_CUSTOM_COLOUR_PROPERTY_USES_WXCOLOUR2(wxColourProperty,
 
1458
                                                     gs_cp_es_normcolour_labels,
 
1459
                                                     (const long*)NULL,
 
1460
                                                     gs_cp_es_normcolour_colours,
 
1461
                                                     TextCtrlAndButton)
 
1462
 
 
1463
// -----------------------------------------------------------------------
 
1464
// wxCursorProperty
 
1465
// -----------------------------------------------------------------------
 
1466
 
 
1467
#define wxPG_CURSOR_IMAGE_WIDTH     32
 
1468
 
 
1469
#define NUM_CURSORS 28
 
1470
 
 
1471
//#define wx_cp_es_syscursors_len 28
 
1472
static const wxChar* gs_cp_es_syscursors_labels[NUM_CURSORS+1] = {
 
1473
    wxT("Default"),
 
1474
    wxT("Arrow"),
 
1475
    wxT("Right Arrow"),
 
1476
    wxT("Blank"),
 
1477
    wxT("Bullseye"),
 
1478
    wxT("Character"),
 
1479
    wxT("Cross"),
 
1480
    wxT("Hand"),
 
1481
    wxT("I-Beam"),
 
1482
    wxT("Left Button"),
 
1483
    wxT("Magnifier"),
 
1484
    wxT("Middle Button"),
 
1485
    wxT("No Entry"),
 
1486
    wxT("Paint Brush"),
 
1487
    wxT("Pencil"),
 
1488
    wxT("Point Left"),
 
1489
    wxT("Point Right"),
 
1490
    wxT("Question Arrow"),
 
1491
    wxT("Right Button"),
 
1492
    wxT("Sizing NE-SW"),
 
1493
    wxT("Sizing N-S"),
 
1494
    wxT("Sizing NW-SE"),
 
1495
    wxT("Sizing W-E"),
 
1496
    wxT("Sizing"),
 
1497
    wxT("Spraycan"),
 
1498
    wxT("Wait"),
 
1499
    wxT("Watch"),
 
1500
    wxT("Wait Arrow"),
 
1501
    (const wxChar*) NULL
 
1502
};
 
1503
 
 
1504
static long gs_cp_es_syscursors_values[NUM_CURSORS] = {
 
1505
    wxCURSOR_NONE,
 
1506
    wxCURSOR_ARROW,
 
1507
    wxCURSOR_RIGHT_ARROW,
 
1508
    wxCURSOR_BLANK,
 
1509
    wxCURSOR_BULLSEYE,
 
1510
    wxCURSOR_CHAR,
 
1511
    wxCURSOR_CROSS,
 
1512
    wxCURSOR_HAND,
 
1513
    wxCURSOR_IBEAM,
 
1514
    wxCURSOR_LEFT_BUTTON,
 
1515
    wxCURSOR_MAGNIFIER,
 
1516
    wxCURSOR_MIDDLE_BUTTON,
 
1517
    wxCURSOR_NO_ENTRY,
 
1518
    wxCURSOR_PAINT_BRUSH,
 
1519
    wxCURSOR_PENCIL,
 
1520
    wxCURSOR_POINT_LEFT,
 
1521
    wxCURSOR_POINT_RIGHT,
 
1522
    wxCURSOR_QUESTION_ARROW,
 
1523
    wxCURSOR_RIGHT_BUTTON,
 
1524
    wxCURSOR_SIZENESW,
 
1525
    wxCURSOR_SIZENS,
 
1526
    wxCURSOR_SIZENWSE,
 
1527
    wxCURSOR_SIZEWE,
 
1528
    wxCURSOR_SIZING,
 
1529
    wxCURSOR_SPRAYCAN,
 
1530
    wxCURSOR_WAIT,
 
1531
    wxCURSOR_WATCH,
 
1532
    wxCURSOR_ARROWWAIT
 
1533
};
 
1534
 
 
1535
IMPLEMENT_DYNAMIC_CLASS(wxCursorProperty, wxEnumProperty)
 
1536
 
 
1537
wxCursorProperty::wxCursorProperty( const wxString& label, const wxString& name,
 
1538
    int value )
 
1539
    : wxEnumProperty( label,
 
1540
                      name,
 
1541
                      gs_cp_es_syscursors_labels,
 
1542
                      gs_cp_es_syscursors_values,
 
1543
                      value )
 
1544
{
 
1545
    m_flags |= wxPG_PROP_STATIC_CHOICES; // Cursor selection cannot be changed.
 
1546
}
 
1547
 
 
1548
wxCursorProperty::~wxCursorProperty()
 
1549
{
 
1550
}
 
1551
 
 
1552
wxSize wxCursorProperty::OnMeasureImage( int item ) const
 
1553
{
 
1554
#if wxPG_CAN_DRAW_CURSOR
 
1555
    if ( item != -1 && item < NUM_CURSORS )
 
1556
        return wxSize(wxPG_CURSOR_IMAGE_WIDTH,wxPG_CURSOR_IMAGE_WIDTH);
 
1557
#endif
 
1558
    return wxSize(0,0);
 
1559
}
 
1560
 
 
1561
#if wxPG_CAN_DRAW_CURSOR
 
1562
 
 
1563
void wxCursorProperty::OnCustomPaint( wxDC& dc,
 
1564
                                      const wxRect& rect,
 
1565
                                      wxPGPaintData& paintdata )
 
1566
{
 
1567
    // Background brush
 
1568
    dc.SetBrush( wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE ) );
 
1569
 
 
1570
    if ( paintdata.m_choiceItem >= 0 )
 
1571
    {
 
1572
        dc.DrawRectangle( rect );
 
1573
 
 
1574
        if ( paintdata.m_choiceItem < NUM_CURSORS )
 
1575
        {
 
1576
            int cursorindex = gs_cp_es_syscursors_values[paintdata.m_choiceItem];
 
1577
 
 
1578
            {
 
1579
                if ( cursorindex == wxCURSOR_NONE )
 
1580
                    cursorindex = wxCURSOR_ARROW;
 
1581
 
 
1582
                wxCursor cursor( cursorindex );
 
1583
 
 
1584
            #ifdef __WXMSW__
 
1585
                  ::DrawIconEx( wxPG_GetHDCOf(dc),
 
1586
                              rect.x,
 
1587
                              rect.y,
 
1588
                              (HICON)cursor.GetHandle(),
 
1589
                              0,
 
1590
                              0,
 
1591
                              0,
 
1592
                              NULL,
 
1593
            #if !defined(__WXWINCE__)
 
1594
                              DI_COMPAT | DI_DEFAULTSIZE |
 
1595
            #endif
 
1596
                              DI_NORMAL
 
1597
                            );
 
1598
            #endif
 
1599
            }
 
1600
        }
 
1601
    }
 
1602
}
 
1603
 
 
1604
#else
 
1605
void wxCursorProperty::OnCustomPaint( wxDC&, const wxRect&, wxPGPaintData& ) { }
 
1606
/*wxPGCellRenderer* wxCursorProperty::GetCellRenderer( int column ) const
 
1607
{
 
1608
    return wxEnumProperty::GetCellRenderer(column);
 
1609
}*/
 
1610
#endif
 
1611
 
 
1612
// -----------------------------------------------------------------------
 
1613
// wxImageFileProperty
 
1614
// -----------------------------------------------------------------------
 
1615
 
 
1616
#if wxUSE_IMAGE
 
1617
 
 
1618
const wxString& wxPGGetDefaultImageWildcard()
 
1619
{
 
1620
    // Form the wildcard, if not done yet
 
1621
    if ( !wxPGGlobalVars->m_pDefaultImageWildcard.length() )
 
1622
    {
 
1623
 
 
1624
        wxString str;
 
1625
 
 
1626
        // TODO: This section may require locking (using global).
 
1627
 
 
1628
        wxList& handlers = wxImage::GetHandlers();
 
1629
 
 
1630
        wxList::iterator node;
 
1631
 
 
1632
        // Let's iterate over the image handler list.
 
1633
        //for ( wxList::Node *node = handlers.GetFirst(); node; node = node->GetNext() )
 
1634
        for ( node = handlers.begin(); node != handlers.end(); node++ )
 
1635
        {
 
1636
            wxImageHandler *handler = (wxImageHandler*)*node;
 
1637
 
 
1638
            wxString ext_lo = handler->GetExtension();
 
1639
            wxString ext_up = ext_lo.Upper();
 
1640
 
 
1641
            str.append( ext_up );
 
1642
            str.append( wxT(" files (*.") );
 
1643
            str.append( ext_up );
 
1644
            str.append( wxT(")|*.") );
 
1645
            str.append( ext_lo );
 
1646
            str.append( wxT("|") );
 
1647
        }
 
1648
 
 
1649
        str.append ( wxT("All files (*.*)|*.*") );
 
1650
 
 
1651
        wxPGGlobalVars->m_pDefaultImageWildcard = str;
 
1652
    }
 
1653
 
 
1654
    return wxPGGlobalVars->m_pDefaultImageWildcard;
 
1655
}
 
1656
 
 
1657
WX_PG_IMPLEMENT_DERIVED_PROPERTY_CLASS(wxImageFileProperty,
 
1658
                                       wxFileProperty,
 
1659
                                       const wxString&)
 
1660
 
 
1661
wxImageFileProperty::wxImageFileProperty( const wxString& label, const wxString& name,
 
1662
    const wxString& value )
 
1663
    : wxFileProperty(label,name,value)
 
1664
{
 
1665
    SetAttribute( wxPG_FILE_WILDCARD, wxPGGetDefaultImageWildcard() );
 
1666
 
 
1667
    m_pImage = (wxImage*) NULL;
 
1668
    m_pBitmap = (wxBitmap*) NULL;
 
1669
}
 
1670
 
 
1671
wxImageFileProperty::~wxImageFileProperty()
 
1672
{
 
1673
    if ( m_pBitmap )
 
1674
        delete m_pBitmap;
 
1675
    if ( m_pImage )
 
1676
        delete m_pImage;
 
1677
}
 
1678
 
 
1679
void wxImageFileProperty::OnSetValue()
 
1680
{
 
1681
    wxFileProperty::OnSetValue();
 
1682
 
 
1683
    // Delete old image
 
1684
    if ( m_pImage )
 
1685
    {
 
1686
        delete m_pImage;
 
1687
        m_pImage = NULL;
 
1688
    }
 
1689
    if ( m_pBitmap )
 
1690
    {
 
1691
        delete m_pBitmap;
 
1692
        m_pBitmap = NULL;
 
1693
    }
 
1694
 
 
1695
    // Create the image thumbnail
 
1696
    if ( m_filename.FileExists() )
 
1697
    {
 
1698
        m_pImage = new wxImage( m_filename.GetFullPath() );
 
1699
    }
 
1700
}
 
1701
 
 
1702
wxSize wxImageFileProperty::OnMeasureImage( int ) const
 
1703
{
 
1704
    return wxPG_DEFAULT_IMAGE_SIZE;
 
1705
}
 
1706
 
 
1707
void wxImageFileProperty::OnCustomPaint( wxDC& dc,
 
1708
                                         const wxRect& rect,
 
1709
                                         wxPGPaintData& )
 
1710
{
 
1711
    if ( m_pBitmap || (m_pImage && m_pImage->Ok() ) )
 
1712
    {
 
1713
        // Draw the thumbnail
 
1714
 
 
1715
        // Create the bitmap here because required size is not known in OnSetValue().
 
1716
        if ( !m_pBitmap )
 
1717
        {
 
1718
            m_pImage->Rescale( rect.width, rect.height );
 
1719
            m_pBitmap = new wxBitmap( *m_pImage );
 
1720
            delete m_pImage;
 
1721
            m_pImage = NULL;
 
1722
        }
 
1723
 
 
1724
        dc.DrawBitmap( *m_pBitmap, rect.x, rect.y, false );
 
1725
    }
 
1726
    else
 
1727
    {
 
1728
        // No file - just draw a white box
 
1729
        dc.SetBrush( *wxWHITE_BRUSH );
 
1730
        dc.DrawRectangle ( rect );
 
1731
    }
 
1732
}
 
1733
 
 
1734
#endif // wxUSE_IMAGE
 
1735
 
 
1736
// -----------------------------------------------------------------------
 
1737
// wxMultiChoiceProperty
 
1738
// -----------------------------------------------------------------------
 
1739
 
 
1740
#if wxUSE_CHOICEDLG
 
1741
 
 
1742
#include <wx/choicdlg.h>
 
1743
 
 
1744
WX_PG_IMPLEMENT_PROPERTY_CLASS(wxMultiChoiceProperty,wxPGProperty,
 
1745
                               wxArrayInt,const wxArrayInt&,TextCtrlAndButton)
 
1746
 
 
1747
wxMultiChoiceProperty::wxMultiChoiceProperty( const wxString& label,
 
1748
                                              const wxString& name,
 
1749
                                              const wxPGChoices& choices,
 
1750
                                              const wxArrayString& value)
 
1751
                                                : wxPGProperty(label,name)
 
1752
{
 
1753
    m_choices.Assign(choices);
 
1754
    SetValue(value);
 
1755
}
 
1756
 
 
1757
wxMultiChoiceProperty::wxMultiChoiceProperty( const wxString& label,
 
1758
                                              const wxString& name,
 
1759
                                              const wxArrayString& strings,
 
1760
                                              const wxArrayString& value)
 
1761
                                                : wxPGProperty(label,name)
 
1762
{
 
1763
    m_choices.Set(strings);
 
1764
    SetValue(value);
 
1765
}
 
1766
 
 
1767
wxMultiChoiceProperty::wxMultiChoiceProperty( const wxString& label,
 
1768
                                              const wxString& name,
 
1769
                                              const wxArrayString& value)
 
1770
                                                : wxPGProperty(label,name)
 
1771
{
 
1772
    wxArrayString strings;
 
1773
    m_choices.Set(strings);
 
1774
    SetValue(value);
 
1775
}
 
1776
 
 
1777
wxMultiChoiceProperty::~wxMultiChoiceProperty()
 
1778
{
 
1779
}
 
1780
 
 
1781
void wxMultiChoiceProperty::OnSetValue()
 
1782
{
 
1783
    GenerateValueAsString();
 
1784
}
 
1785
 
 
1786
wxString wxMultiChoiceProperty::GetValueAsString( int ) const
 
1787
{
 
1788
    return m_display;
 
1789
}
 
1790
 
 
1791
void wxMultiChoiceProperty::GenerateValueAsString()
 
1792
{
 
1793
    wxArrayString strings;
 
1794
 
 
1795
    if ( wxPGIsVariantType(m_value, arrstring) )
 
1796
        strings = m_value.GetArrayString();
 
1797
 
 
1798
    wxString& tempStr = m_display;
 
1799
    unsigned int i;
 
1800
    unsigned int itemCount = strings.GetCount();
 
1801
 
 
1802
    tempStr.Empty();
 
1803
 
 
1804
    if ( itemCount )
 
1805
        tempStr.append( wxT("\"") );
 
1806
 
 
1807
    for ( i = 0; i < itemCount; i++ )
 
1808
    {
 
1809
        tempStr.append( strings[i] );
 
1810
        tempStr.append( wxT("\"") );
 
1811
        if ( i < (itemCount-1) )
 
1812
            tempStr.append ( wxT(" \"") );
 
1813
    }
 
1814
}
 
1815
 
 
1816
wxArrayInt wxMultiChoiceProperty::GetValueAsIndices() const
 
1817
{
 
1818
    const wxArrayInt& valueArr = wxArrayIntFromVariant(GetValue());
 
1819
    unsigned int i;
 
1820
 
 
1821
    // Translate values to string indices.
 
1822
    wxArrayInt selections;
 
1823
 
 
1824
    if ( !m_choices.IsOk() || !m_choices.GetCount() || !(&valueArr) )
 
1825
    {
 
1826
        for ( i=0; i<valueArr.GetCount(); i++ )
 
1827
            selections.Add(-1);
 
1828
    }
 
1829
    else
 
1830
    {
 
1831
        for ( i=0; i<valueArr.GetCount(); i++ )
 
1832
        {
 
1833
            int sIndex = m_choices.Index(valueArr[i]);
 
1834
            if ( sIndex >= 0 )
 
1835
                selections.Add(sIndex);
 
1836
        }
 
1837
    }
 
1838
 
 
1839
    return selections;
 
1840
}
 
1841
 
 
1842
bool wxMultiChoiceProperty::OnEvent( wxPropertyGrid* propgrid,
 
1843
                                     wxWindow* WXUNUSED(primary),
 
1844
                                     wxEvent& event )
 
1845
{
 
1846
    if ( propgrid->IsMainButtonEvent(event) )
 
1847
    {
 
1848
        // Update the value
 
1849
        PrepareValueForDialogEditing(propgrid);
 
1850
 
 
1851
        wxArrayString labels = m_choices.GetLabels();
 
1852
        unsigned int choiceCount;
 
1853
 
 
1854
        if ( m_choices.IsOk() )
 
1855
            choiceCount = m_choices.GetCount();
 
1856
        else
 
1857
            choiceCount = 0;
 
1858
 
 
1859
        // launch editor dialog
 
1860
        wxMultiChoiceDialog dlg( propgrid,
 
1861
                                 _("Make a selection:"),
 
1862
                                 m_label,
 
1863
                                 choiceCount,
 
1864
                                 choiceCount?&labels[0]:NULL,
 
1865
                                 wxCHOICEDLG_STYLE );
 
1866
 
 
1867
        dlg.Move( propgrid->GetGoodEditorDialogPosition(this,dlg.GetSize()) );
 
1868
 
 
1869
        wxArrayString strings = m_value.GetArrayString();
 
1870
        wxArrayString extraStrings;
 
1871
 
 
1872
        dlg.SetSelections(m_choices.GetIndicesForStrings(strings, &extraStrings));
 
1873
 
 
1874
        if ( dlg.ShowModal() == wxID_OK && choiceCount )
 
1875
        {
 
1876
            int userStringMode = GetAttributeAsLong(wxT("UserStringMode"), 0);
 
1877
 
 
1878
            wxArrayInt arrInt = dlg.GetSelections();
 
1879
 
 
1880
            wxVariant variant;
 
1881
 
 
1882
            // Strings that were not in list of choices
 
1883
            wxArrayString value;
 
1884
 
 
1885
            // Translate string indices to strings
 
1886
 
 
1887
            unsigned int n;
 
1888
            if ( userStringMode == 1 )
 
1889
            {
 
1890
                for (n=0;n<extraStrings.size();n++)
 
1891
                    value.push_back(extraStrings[n]);
 
1892
            }
 
1893
 
 
1894
            unsigned int i;
 
1895
            for ( i=0; i<arrInt.GetCount(); i++ )
 
1896
                value.Add(m_choices.GetLabel(arrInt.Item(i)));
 
1897
 
 
1898
            if ( userStringMode == 2 )
 
1899
            {
 
1900
                for (n=0;n<extraStrings.size();n++)
 
1901
                    value.push_back(extraStrings[n]);
 
1902
            }
 
1903
 
 
1904
            variant = WXVARIANT(value);
 
1905
 
 
1906
            SetValueInEvent(variant);
 
1907
 
 
1908
            return true;
 
1909
        }
 
1910
    }
 
1911
    return false;
 
1912
}
 
1913
 
 
1914
int wxMultiChoiceProperty::GetChoiceInfo( wxPGChoiceInfo* choiceinfo )
 
1915
{
 
1916
    if ( choiceinfo )
 
1917
        choiceinfo->m_choices = &m_choices;
 
1918
    return -1;
 
1919
}
 
1920
 
 
1921
bool wxMultiChoiceProperty::StringToValue( wxVariant& variant, const wxString& text, int ) const
 
1922
{
 
1923
    wxArrayString arr;
 
1924
 
 
1925
    int userStringMode = GetAttributeAsLong(wxT("UserStringMode"), 0);
 
1926
 
 
1927
    WX_PG_TOKENIZER2_BEGIN(text,wxT('"'))
 
1928
        if ( userStringMode > 0 || (m_choices.IsOk() && m_choices.Index( token ) != wxNOT_FOUND) )
 
1929
            arr.Add(token);
 
1930
    WX_PG_TOKENIZER2_END()
 
1931
 
 
1932
    wxVariant v( WXVARIANT(arr) );
 
1933
    variant = v;
 
1934
 
 
1935
    return true;
 
1936
}
 
1937
 
 
1938
#endif // wxUSE_CHOICEDLG
 
1939
 
 
1940
 
 
1941
// -----------------------------------------------------------------------
 
1942
// wxDateProperty
 
1943
// -----------------------------------------------------------------------
 
1944
 
 
1945
#if wxUSE_DATETIME
 
1946
 
 
1947
 
 
1948
#if wxUSE_DATEPICKCTRL
 
1949
    #define dtCtrl      DatePickerCtrl
 
1950
#else
 
1951
    #define dtCtrl      TextCtrl
 
1952
#endif
 
1953
 
 
1954
WX_PG_IMPLEMENT_PROPERTY_CLASS(wxDateProperty,
 
1955
                               wxPGProperty,
 
1956
                               wxDateTime,
 
1957
                               const wxDateTime&,
 
1958
                               dtCtrl)
 
1959
 
 
1960
 
 
1961
wxString wxDateProperty::ms_defaultDateFormat;
 
1962
 
 
1963
 
 
1964
wxDateProperty::wxDateProperty( const wxString& label,
 
1965
                                const wxString& name,
 
1966
                                const wxDateTime& value )
 
1967
    : wxPGProperty(label,name)
 
1968
{
 
1969
    //wxPGRegisterDefaultValueType(wxDateTime)
 
1970
 
 
1971
#if wxUSE_DATEPICKCTRL
 
1972
    wxPGRegisterEditorClass(DatePickerCtrl);
 
1973
 
 
1974
    m_dpStyle = wxDP_DEFAULT | wxDP_SHOWCENTURY;
 
1975
#else
 
1976
    m_dpStyle = 0;
 
1977
#endif
 
1978
 
 
1979
    SetValue( value );
 
1980
}
 
1981
 
 
1982
wxDateProperty::~wxDateProperty()
 
1983
{
 
1984
}
 
1985
 
 
1986
bool wxDateProperty::StringToValue( wxVariant& variant, const wxString& text,
 
1987
                                    int WXUNUSED(argFlags) ) const
 
1988
{
 
1989
    wxDateTime dt;
 
1990
 
 
1991
#if wxCHECK_VERSION(2,9,0)
 
1992
    const char* c = dt.ParseFormat(text, wxString(wxDefaultDateTimeFormat), wxDefaultDateTime, NULL);
 
1993
#else
 
1994
    const wxChar* c = dt.ParseFormat(text, wxDefaultDateTimeFormat);
 
1995
#endif
 
1996
 
 
1997
    if ( c )
 
1998
    {
 
1999
        variant = dt;
 
2000
        return true;
 
2001
    }
 
2002
 
 
2003
    return false;
 
2004
}
 
2005
 
 
2006
wxString wxDateProperty::GetValueAsString( int argFlags ) const
 
2007
{
 
2008
    const wxChar* format = (const wxChar*) NULL;
 
2009
 
 
2010
    wxDateTime dateTime = m_value.GetDateTime();
 
2011
 
 
2012
    if ( !dateTime.IsValid() )
 
2013
        return wxT("Invalid");
 
2014
 
 
2015
    if ( !ms_defaultDateFormat.length() )
 
2016
    {
 
2017
#if wxUSE_DATEPICKCTRL
 
2018
        bool showCentury = m_dpStyle & wxDP_SHOWCENTURY ? true : false;
 
2019
#else
 
2020
        bool showCentury = true;
 
2021
#endif
 
2022
        ms_defaultDateFormat = DetermineDefaultDateFormat( showCentury );
 
2023
    }
 
2024
 
 
2025
    if ( m_format.length() &&
 
2026
         !(argFlags & wxPG_FULL_VALUE) )
 
2027
            format = m_format.c_str();
 
2028
 
 
2029
    // Determine default from locale
 
2030
    // NB: This is really simple stuff, but can't figure anything
 
2031
    //     better without proper support in wxLocale
 
2032
    if ( !format )
 
2033
        format = ms_defaultDateFormat.c_str();
 
2034
 
 
2035
    return dateTime.Format(format);
 
2036
}
 
2037
 
 
2038
wxString wxDateProperty::DetermineDefaultDateFormat( bool showCentury )
 
2039
{
 
2040
    // This code is basicly copied from datectlg.cpp's SetFormat
 
2041
    //
 
2042
    wxString format;
 
2043
 
 
2044
    wxDateTime dt;
 
2045
    dt.ParseFormat(wxT("2003-10-13"), wxT("%Y-%m-%d"));
 
2046
    wxString str(dt.Format(wxT("%x")));
 
2047
 
 
2048
    const wxChar *p = str.c_str();
 
2049
    while ( *p )
 
2050
    {
 
2051
        int n=wxAtoi(p);
 
2052
        if (n == dt.GetDay())
 
2053
        {
 
2054
            format.Append(wxT("%d"));
 
2055
            p += 2;
 
2056
        }
 
2057
        else if (n == (int)dt.GetMonth()+1)
 
2058
        {
 
2059
            format.Append(wxT("%m"));
 
2060
            p += 2;
 
2061
        }
 
2062
        else if (n == dt.GetYear())
 
2063
        {
 
2064
            format.Append(wxT("%Y"));
 
2065
            p += 4;
 
2066
        }
 
2067
        else if (n == (dt.GetYear() % 100))
 
2068
        {
 
2069
            if (showCentury)
 
2070
                format.Append(wxT("%Y"));
 
2071
            else
 
2072
                format.Append(wxT("%y"));
 
2073
            p += 2;
 
2074
        }
 
2075
        else
 
2076
            format.Append(*p++);
 
2077
    }
 
2078
 
 
2079
    return format;
 
2080
}
 
2081
 
 
2082
bool wxDateProperty::DoSetAttribute( const wxString& name, wxVariant& value )
 
2083
{
 
2084
    if ( name == wxPG_DATE_FORMAT )
 
2085
    {
 
2086
        m_format = value.GetString();
 
2087
        return true;
 
2088
    }
 
2089
    else if ( name == wxPG_DATE_PICKER_STYLE )
 
2090
    {
 
2091
        m_dpStyle = value.GetLong();
 
2092
        ms_defaultDateFormat.clear();  // This may need recalculation
 
2093
        return true;
 
2094
    }
 
2095
    return false;
 
2096
}
 
2097
 
 
2098
#endif  // wxUSE_DATETIME
 
2099
 
 
2100
 
 
2101
// -----------------------------------------------------------------------
 
2102
// wxPropertyGridInterface
 
2103
// -----------------------------------------------------------------------
 
2104
 
 
2105
void wxPropertyGridInterface::InitAllTypeHandlers()
 
2106
{
 
2107
    //wxPG_INIT_REQUIRED_TYPE(wxColour)
 
2108
    //wxPG_INIT_REQUIRED_TYPE(wxFont)
 
2109
    //wxPG_INIT_REQUIRED_TYPE(wxArrayInt)
 
2110
    //wxPG_INIT_REQUIRED_TYPE(wxColourPropertyValue)
 
2111
/*#if wxUSE_DATETIME
 
2112
    wxPGRegisterDefaultValueType(wxDateTime)
 
2113
#endif*/
 
2114
}
 
2115
 
 
2116
// -----------------------------------------------------------------------
 
2117
 
 
2118
void wxPropertyGridInterface::RegisterAdditionalEditors()
 
2119
{
 
2120
#if wxUSE_SPINBTN
 
2121
    wxPGRegisterEditorClass(SpinCtrl);
 
2122
#endif
 
2123
#if wxUSE_DATEPICKCTRL
 
2124
    wxPGRegisterEditorClass(DatePickerCtrl);
 
2125
#endif
 
2126
}
 
2127
 
 
2128
// -----------------------------------------------------------------------
 
2129
 
 
2130
#endif // wxPG_INCLUDE_ADVPROPS