~ubuntu-branches/ubuntu/utopic/pgadmin3/utopic-proposed

« back to all changes in this revision

Viewing changes to pgadmin/ctl/ctlColourPicker.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Gerfried Fuchs
  • Date: 2011-06-07 23:03:54 UTC
  • mfrom: (1.3.1 upstream) (13 sid)
  • mto: This revision was merged to the branch mainline in revision 14.
  • Revision ID: james.westby@ubuntu.com-20110607230354-3td4j9y71u4ahcvj
Tags: 1.14.0~beta1-1
* New upstream development release, adding Build-Depends on
  postgresql-server-dev-all >= 117~.
* Add Build-Depends on quilt, (un)patch to debian/rules and patch for fixing
  the include for kwlist.h in pgadmin/db/keywords.c.
* Add pg_config --includedir-server output to CPPFLAGS.
* Remove unrecognized configure options: --with-wx-config,
  --with-pgsql-include, --enable-gtk2, --enable-unicode.
* Clean up manually the files that are left behind after the broken
  distclean.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
//////////////////////////////////////////////////////////////////////////
2
2
//
3
3
// pgAdmin III - PostgreSQL Tools
4
 
// 
5
 
// Copyright (C) 2002 - 2010, The pgAdmin Development Team
 
4
//
 
5
// Copyright (C) 2002 - 2011, The pgAdmin Development Team
6
6
// This software is released under the BSD Licence
7
7
//
8
8
// ctlColourPicker.cpp - Colour Picker with a wxBitmapButton
19
19
#include "ctl/ctlColourPicker.h"
20
20
 
21
21
 
22
 
void ctlColourPicker::Create(wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size)
 
22
void ctlColourPicker::Create(wxWindow *parent, wxWindowID id, const wxPoint &pos, const wxSize &size)
23
23
{
24
 
    // Set Default Title
25
 
    m_title = _("Choose the colour");
26
 
 
27
 
    // Create the wxBitmapButton
28
 
    ((wxBitmapButton *)this)->Create(parent, id, wxNullBitmap, pos, size);
29
 
 
30
 
    // Set the handler for a click
31
 
    Connect(id, wxEVT_LEFT_DOWN, wxMouseEventHandler(ctlColourPicker::DoProcessLeftClick) );
 
24
        // Set Default Title
 
25
        m_title = _("Choose the colour");
 
26
 
 
27
        // Create the wxBitmapButton
 
28
        ((wxBitmapButton *)this)->Create(parent, id, wxNullBitmap, pos, size);
 
29
 
 
30
        // Set the handler for a click
 
31
        Connect(id, wxEVT_LEFT_DOWN, wxMouseEventHandler(ctlColourPicker::DoProcessLeftClick) );
32
32
}
33
33
 
34
34
 
35
 
void ctlColourPicker::DoProcessLeftClick(wxMouseEvent& event)
 
35
void ctlColourPicker::DoProcessLeftClick(wxMouseEvent &event)
36
36
{
37
 
    wxColourData clrData;
38
 
 
39
 
    // If there is an initial colour, set it for wxColourDialog
40
 
    if (m_colour_clr.IsOk())
41
 
        clrData.SetColour(m_colour_clr);
42
 
 
43
 
    // Declare the new dialog
44
 
    wxColourDialog dialog(this, &clrData);
45
 
 
46
 
    // and set its title
47
 
    dialog.SetTitle(m_title);
48
 
 
49
 
    // Now, show it
50
 
    if (dialog.ShowModal() == wxID_OK)
51
 
    {
52
 
        clrData = dialog.GetColourData();
 
37
        wxColourData clrData;
 
38
 
 
39
        // Initialise custom colours
 
40
        for (int index = 0; index < 16; index++)
 
41
                clrData.SetCustomColour(index, settings->GetCustomColour(index));
 
42
 
 
43
        // If there is an initial colour, set it for wxColourDialog
 
44
        if (m_colour_clr.IsOk())
 
45
                clrData.SetColour(m_colour_clr);
 
46
 
 
47
        // Declare the new dialog
 
48
        wxColourDialog dialog(this, &clrData);
 
49
 
 
50
        // and set its title
 
51
        dialog.SetTitle(m_title);
 
52
 
 
53
        // Now, show it
 
54
        if (dialog.ShowModal() == wxID_OK)
 
55
        {
 
56
                clrData = dialog.GetColourData();
53
57
                SetColour(clrData.GetColour());
54
 
    }
 
58
 
 
59
                // Store custom colours
 
60
                for (int index = 0; index < 16; index++)
 
61
                        settings->SetCustomColour(index, clrData.GetCustomColour(index).GetAsString(wxC2S_HTML_SYNTAX));
 
62
        }
55
63
}
56
64
 
57
65
 
58
66
void ctlColourPicker::UpdateColour()
59
67
{
60
 
    if (!m_colour_clr.IsOk())
61
 
    {
62
 
        wxBitmap empty(1,1);
63
 
        SetBitmapLabel(empty);
64
 
        return;
65
 
    }
66
 
 
67
 
    wxSize sz = GetSize();
68
 
    sz.x -= 2*GetMarginX();
69
 
    sz.y -= 2*GetMarginY();
70
 
 
71
 
    wxPoint topleft;
72
 
    if ( sz.x < 1 )
73
 
        sz.x = 1;
74
 
    else
75
 
        if ( sz.y < 1 )
76
 
             sz.y = 1;
77
 
    wxBitmap bmp(sz.x, sz.y);
78
 
 
79
 
    wxMemoryDC dc(bmp);
80
 
    dc.SetBrush(wxBrush(m_colour_clr));
81
 
    dc.DrawRectangle(topleft,sz);
82
 
 
83
 
    ((wxBitmapButton *)this)->SetBitmapLabel(bmp);
 
68
        if (!m_colour_clr.IsOk())
 
69
        {
 
70
                wxBitmap empty(1, 1);
 
71
                SetBitmapLabel(empty);
 
72
                return;
 
73
        }
 
74
 
 
75
        wxSize sz = GetSize();
 
76
        sz.x -= 2 * GetMarginX();
 
77
        sz.y -= 2 * GetMarginY();
 
78
 
 
79
        wxPoint topleft;
 
80
        if ( sz.x < 1 )
 
81
                sz.x = 1;
 
82
        else if ( sz.y < 1 )
 
83
                sz.y = 1;
 
84
        wxBitmap bmp(sz.x, sz.y);
 
85
 
 
86
        wxMemoryDC dc(bmp);
 
87
        dc.SetBrush(wxBrush(m_colour_clr));
 
88
        dc.DrawRectangle(topleft, sz);
 
89
 
 
90
        ((wxBitmapButton *)this)->SetBitmapLabel(bmp);
84
91
}
85
92
 
86
93
wxColour ctlColourPicker::GetColour()
90
97
 
91
98
wxString ctlColourPicker::GetColourString()
92
99
{
93
 
    if (!m_colour_clr.IsOk())
94
 
        return wxEmptyString;
 
100
        if (!m_colour_clr.IsOk())
 
101
                return wxEmptyString;
95
102
        return m_colour_clr.GetAsString();
96
103
}
97
104
 
98
 
void ctlColourPicker::SetColour(const wxColour& colour)
 
105
void ctlColourPicker::SetColour(const wxColour &colour)
99
106
{
100
107
        m_colour_clr = colour;
101
108
        UpdateColour();
102
109
}
103
110
 
104
 
void ctlColourPicker::SetColour(const wxString& colour)
 
111
void ctlColourPicker::SetColour(const wxString &colour)
105
112
{
106
113
        m_colour_clr = wxColour(colour);
107
114
        UpdateColour();
108
115
}
109
116
 
110
 
void ctlColourPicker::SetTitle(const wxString& title)
 
117
void ctlColourPicker::SetTitle(const wxString &title)
111
118
{
112
119
        m_title = title;
113
120
}