~ubuntu-branches/ubuntu/precise/boinc/precise

« back to all changes in this revision

Viewing changes to clientgui/sg_CustomControls.cpp

Tags: 6.12.8+dfsg-1
* New upstream release.
* Simplified debian/rules

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// Berkeley Open Infrastructure for Network Computing
2
 
// http://boinc.berkeley.edu
3
 
// Copyright (C) 2005 University of California
4
 
//
5
 
// This is free software; you can redistribute it and/or
6
 
// modify it under the terms of the GNU Lesser General Public
7
 
// License as published by the Free Software Foundation;
8
 
// either version 2.1 of the License, or (at your option) any later version.
9
 
//
10
 
// This software is distributed in the hope that it will be useful,
11
 
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13
 
// See the GNU Lesser General Public License for more details.
14
 
//
15
 
// To view the GNU Lesser General Public License visit
16
 
// http://www.gnu.org/copyleft/lesser.html
17
 
// or write to the Free Software Foundation, Inc.,
18
 
// 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
19
 
 
20
 
#if defined(__GNUG__) && !defined(__APPLE__)
21
 
#pragma implementation "sg_CustomControls.h"
22
 
#endif
23
 
 
24
 
#include "stdwx.h"
25
 
#include "sg_CustomControls.h" 
26
 
 
27
 
 
28
 
IMPLEMENT_DYNAMIC_CLASS (CTransparentStaticLine, wxPanel)
29
 
 
30
 
BEGIN_EVENT_TABLE(CTransparentStaticLine, wxPanel)
31
 
    EVT_PAINT(CTransparentStaticLine::OnPaint)
32
 
END_EVENT_TABLE()
33
 
 
34
 
 
35
 
CTransparentStaticLine::CTransparentStaticLine() {}
36
 
 
37
 
CTransparentStaticLine::CTransparentStaticLine(wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style, const wxString& name ) {
38
 
    Create(parent, id, pos, size, style, name);
39
 
}
40
 
 
41
 
 
42
 
bool CTransparentStaticLine::Create(wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style, const wxString& name ) { 
43
 
    bool bRetVal = wxPanel::Create(parent, id, pos, size, style|wxTRANSPARENT_WINDOW, name);
44
 
 
45
 
    SetBackgroundColour(parent->GetBackgroundColour());
46
 
    SetBackgroundStyle(wxBG_STYLE_COLOUR);
47
 
    SetForegroundColour(parent->GetForegroundColour());
48
 
 
49
 
    return bRetVal;
50
 
}
51
 
 
52
 
 
53
 
void CTransparentStaticLine::OnPaint(wxPaintEvent& /*event*/) {
54
 
    wxPaintDC dc(this); 
55
 
    wxPen pen = wxPen(GetLineColor(), 1);
56
 
    dc.SetPen(pen);
57
 
    dc.DrawLine(0, 0, GetSize().GetWidth(), 0); 
58
 
}
59
 
 
60
 
 
61
 
IMPLEMENT_DYNAMIC_CLASS (CTransparentStaticText, wxStaticText)
62
 
 
63
 
BEGIN_EVENT_TABLE(CTransparentStaticText, wxStaticText)
64
 
#ifdef __WXMAC__
65
 
    EVT_ERASE_BACKGROUND(CTransparentStaticText::OnEraseBackground)
66
 
#endif
67
 
    EVT_PAINT(CTransparentStaticText::OnPaint)
68
 
END_EVENT_TABLE()
69
 
 
70
 
 
71
 
CTransparentStaticText::CTransparentStaticText() {}
72
 
 
73
 
CTransparentStaticText::CTransparentStaticText(wxWindow* parent, wxWindowID id, const wxString& label, const wxPoint& pos, const wxSize& size, long style, const wxString& name ) {
74
 
    Create(parent, id, label, pos, size, style, name);
75
 
}
76
 
 
77
 
 
78
 
bool CTransparentStaticText::Create(wxWindow* parent, wxWindowID id, const wxString& label, const wxPoint& pos, const wxSize& size, long style, const wxString& name ) { 
79
 
    bool bRetVal = wxStaticText::Create(parent, id, label, pos, size, style|wxTRANSPARENT_WINDOW, name);
80
 
 
81
 
    SetBackgroundColour(parent->GetBackgroundColour());
82
 
    SetBackgroundStyle(wxBG_STYLE_COLOUR);
83
 
    SetForegroundColour(parent->GetForegroundColour());
84
 
 
85
 
    return bRetVal;
86
 
}
87
 
 
88
 
 
89
 
void CTransparentStaticText::OnPaint(wxPaintEvent& /*event*/) {
90
 
    wxPaintDC dc(this);
91
 
    dc.SetFont(GetFont());
92
 
    dc.DrawText(GetLabel(), 0, 0);
93
 
}
94
 
 
95
 
 
96
 
IMPLEMENT_DYNAMIC_CLASS (CTransparentStaticTextAssociate, wxPanel)
97
 
 
98
 
BEGIN_EVENT_TABLE(CTransparentStaticTextAssociate, wxPanel)
99
 
    EVT_ERASE_BACKGROUND(CTransparentStaticTextAssociate::OnEraseBackground)
100
 
    EVT_PAINT(CTransparentStaticTextAssociate::OnPaint)
101
 
    EVT_MOUSE_EVENTS(CTransparentStaticTextAssociate::OnMouse)
102
 
END_EVENT_TABLE()
103
 
 
104
 
 
105
 
CTransparentStaticTextAssociate::CTransparentStaticTextAssociate() {}
106
 
 
107
 
CTransparentStaticTextAssociate::CTransparentStaticTextAssociate(wxWindow* parent, wxWindowID id, const wxString& label, const wxPoint& pos, const wxSize& size, long style, const wxString& name ) {
108
 
    Create(parent, id, label, pos, size, style, name);
109
 
}
110
 
 
111
 
 
112
 
bool CTransparentStaticTextAssociate::Create(wxWindow* parent, wxWindowID id, const wxString& label, const wxPoint& pos, const wxSize& size, long style, const wxString& name ) { 
113
 
    bool bRetVal = wxPanel::Create(parent, id, pos, size, style|wxTRANSPARENT_WINDOW, name);
114
 
 
115
 
    m_pWnd = NULL;
116
 
 
117
 
    SetLabel(label);
118
 
    SetFont(GetFont());
119
 
 
120
 
    SetBackgroundColour(parent->GetBackgroundColour());
121
 
    SetBackgroundStyle(wxBG_STYLE_COLOUR);
122
 
    SetForegroundColour(parent->GetForegroundColour());
123
 
 
124
 
    return bRetVal;
125
 
}
126
 
 
127
 
 
128
 
bool CTransparentStaticTextAssociate::SetFont(const wxFont& font) {
129
 
 
130
 
    bool ret = wxPanel::SetFont(font);
131
 
 
132
 
    InvalidateBestSize();
133
 
 
134
 
    wxCoord width, height;
135
 
    wxClientDC dc(this);
136
 
    dc.SetFont(font);
137
 
    dc.GetMultiLineTextExtent(GetLabel(), &width, &height);
138
 
 
139
 
    CacheBestSize(wxSize(width, height));
140
 
 
141
 
    return ret;
142
 
}
143
 
 
144
 
 
145
 
// Due to the nature of how wxWidgets handles some controls when Windows XP
146
 
//   themes are enabled, it is easier to make a simulated CheckBox or
147
 
//   RadioButton by linking two windows together. So when a mouse event
148
 
//   happens with this window it forwards the event to the associated
149
 
//   window.
150
 
bool CTransparentStaticTextAssociate::AssociateWindow(wxWindow* pWnd) {
151
 
    m_pWnd = pWnd;
152
 
    return true;
153
 
}
154
 
 
155
 
 
156
 
void CTransparentStaticTextAssociate::OnPaint(wxPaintEvent& /*event*/) {
157
 
    wxPaintDC dc(this);
158
 
    dc.SetFont(GetFont());
159
 
    dc.DrawText(GetLabel(), 1, 1);
160
 
}
161
 
 
162
 
 
163
 
void CTransparentStaticTextAssociate::OnMouse(wxMouseEvent& event) {
164
 
    if (m_pWnd) {
165
 
        wxMouseEvent evtAssociate(event);
166
 
        evtAssociate.SetId(m_pWnd->GetId());
167
 
        m_pWnd->ProcessEvent(event);
168
 
    }
169
 
 
170
 
    // If we get the left button up event and we already had focus, that must
171
 
    //   mean the user clicked on the static text, So change the associated
172
 
    //   control so that it has been clicked.
173
 
    if (event.GetEventType() == wxEVT_LEFT_UP) {
174
 
        wxCheckBox* pCheckBox = wxDynamicCast(m_pWnd, wxCheckBox);
175
 
        if (pCheckBox) {
176
 
            // Send the updated click event
177
 
            wxCommandEvent evtCheckBox(wxEVT_COMMAND_CHECKBOX_CLICKED, pCheckBox->GetId());
178
 
            evtCheckBox.SetEventObject(pCheckBox);
179
 
            if (pCheckBox->IsChecked()) {
180
 
                evtCheckBox.SetInt(wxCHK_UNCHECKED);
181
 
            } else {
182
 
                evtCheckBox.SetInt(wxCHK_CHECKED);
183
 
            }
184
 
            pCheckBox->Command(evtCheckBox);
185
 
        }
186
 
    }
187
 
    event.Skip();
188
 
}
189
 
 
190
 
 
191
 
IMPLEMENT_DYNAMIC_CLASS (CLinkButton, wxBitmapButton)
192
 
 
193
 
BEGIN_EVENT_TABLE(CLinkButton, wxBitmapButton)
194
 
    EVT_MOUSE_EVENTS(CLinkButton::OnMouse)
195
 
END_EVENT_TABLE()
196
 
 
197
 
 
198
 
CLinkButton::CLinkButton() {}
199
 
 
200
 
CLinkButton::CLinkButton(wxWindow* parent, wxWindowID id, const wxBitmap& bitmap, const wxPoint& pos, const wxSize& size, long style, const wxValidator& validator, const wxString& name ) {
201
 
    Create(parent, id, bitmap, pos, size, style, validator, name);
202
 
}
203
 
 
204
 
 
205
 
bool CLinkButton::Create(wxWindow* parent, wxWindowID id, const wxBitmap& bitmap, const wxPoint& pos, const wxSize& size, long style, const wxValidator& validator, const wxString& name ) { 
206
 
    bool bRetVal = wxBitmapButton::Create(parent, id, bitmap, pos, size, style, validator, name);
207
 
 
208
 
    m_HandCursor = wxCursor(wxCURSOR_HAND);
209
 
 
210
 
    return bRetVal;
211
 
}
212
 
 
213
 
 
214
 
void CLinkButton::OnMouse(wxMouseEvent& event) {
215
 
    if (event.Entering()) {
216
 
        SetCursor(m_HandCursor);
217
 
    } else if (event.Leaving()) {
218
 
        SetCursor(*wxSTANDARD_CURSOR);
219
 
    }
220
 
    event.Skip();
221
 
}
 
1
// This file is part of BOINC.
 
2
// http://boinc.berkeley.edu
 
3
// Copyright (C) 2008 University of California
 
4
//
 
5
// BOINC is free software; you can redistribute it and/or modify it
 
6
// under the terms of the GNU Lesser General Public License
 
7
// as published by the Free Software Foundation,
 
8
// either version 3 of the License, or (at your option) any later version.
 
9
//
 
10
// BOINC is distributed in the hope that it will be useful,
 
11
// but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 
13
// See the GNU Lesser General Public License for more details.
 
14
//
 
15
// You should have received a copy of the GNU Lesser General Public License
 
16
// along with BOINC.  If not, see <http://www.gnu.org/licenses/>.
 
17
 
 
18
#if defined(__GNUG__) && !defined(__APPLE__)
 
19
#pragma implementation "sg_CustomControls.h"
 
20
#endif
 
21
 
 
22
#include "stdwx.h"
 
23
#include "sg_CustomControls.h" 
 
24
 
 
25
 
 
26
IMPLEMENT_DYNAMIC_CLASS (CTransparentStaticLine, wxPanel)
 
27
 
 
28
BEGIN_EVENT_TABLE(CTransparentStaticLine, wxPanel)
 
29
    EVT_PAINT(CTransparentStaticLine::OnPaint)
 
30
END_EVENT_TABLE()
 
31
 
 
32
 
 
33
CTransparentStaticLine::CTransparentStaticLine() {}
 
34
 
 
35
CTransparentStaticLine::CTransparentStaticLine(wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style, const wxString& name ) {
 
36
    Create(parent, id, pos, size, style, name);
 
37
}
 
38
 
 
39
 
 
40
bool CTransparentStaticLine::Create(wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style, const wxString& name ) { 
 
41
    bool bRetVal = wxPanel::Create(parent, id, pos, size, style|wxTRANSPARENT_WINDOW, name);
 
42
 
 
43
    SetBackgroundColour(parent->GetBackgroundColour());
 
44
    SetBackgroundStyle(wxBG_STYLE_COLOUR);
 
45
    SetForegroundColour(parent->GetForegroundColour());
 
46
 
 
47
    return bRetVal;
 
48
}
 
49
 
 
50
 
 
51
void CTransparentStaticLine::OnPaint(wxPaintEvent& /*event*/) {
 
52
    wxPaintDC dc(this); 
 
53
    wxPen pen = wxPen(GetLineColor(), 1);
 
54
    dc.SetPen(pen);
 
55
    dc.DrawLine(0, 0, GetSize().GetWidth(), 0); 
 
56
}
 
57
 
 
58
 
 
59
IMPLEMENT_DYNAMIC_CLASS (CTransparentStaticText, wxStaticText)
 
60
 
 
61
BEGIN_EVENT_TABLE(CTransparentStaticText, wxStaticText)
 
62
#ifdef __WXMAC__
 
63
    EVT_ERASE_BACKGROUND(CTransparentStaticText::OnEraseBackground)
 
64
#endif
 
65
    EVT_PAINT(CTransparentStaticText::OnPaint)
 
66
END_EVENT_TABLE()
 
67
 
 
68
 
 
69
CTransparentStaticText::CTransparentStaticText() {}
 
70
 
 
71
CTransparentStaticText::CTransparentStaticText(wxWindow* parent, wxWindowID id, const wxString& label, const wxPoint& pos, const wxSize& size, long style, const wxString& name ) {
 
72
    Create(parent, id, label, pos, size, style, name);
 
73
}
 
74
 
 
75
 
 
76
bool CTransparentStaticText::Create(wxWindow* parent, wxWindowID id, const wxString& label, const wxPoint& pos, const wxSize& size, long style, const wxString& name ) { 
 
77
    bool bRetVal = wxStaticText::Create(parent, id, label, pos, size, style|wxTRANSPARENT_WINDOW, name);
 
78
 
 
79
    SetBackgroundColour(parent->GetBackgroundColour());
 
80
    SetBackgroundStyle(wxBG_STYLE_COLOUR);
 
81
    SetForegroundColour(parent->GetForegroundColour());
 
82
 
 
83
    return bRetVal;
 
84
}
 
85
 
 
86
 
 
87
void CTransparentStaticText::OnPaint(wxPaintEvent& /*event*/) {
 
88
    wxPaintDC dc(this);
 
89
    dc.SetFont(GetFont());
 
90
    dc.DrawText(GetLabel(), 0, 0);
 
91
}
 
92
 
 
93
 
 
94
IMPLEMENT_DYNAMIC_CLASS (CTransparentStaticTextAssociate, wxPanel)
 
95
 
 
96
BEGIN_EVENT_TABLE(CTransparentStaticTextAssociate, wxPanel)
 
97
    EVT_ERASE_BACKGROUND(CTransparentStaticTextAssociate::OnEraseBackground)
 
98
    EVT_PAINT(CTransparentStaticTextAssociate::OnPaint)
 
99
    EVT_MOUSE_EVENTS(CTransparentStaticTextAssociate::OnMouse)
 
100
END_EVENT_TABLE()
 
101
 
 
102
 
 
103
CTransparentStaticTextAssociate::CTransparentStaticTextAssociate() {}
 
104
 
 
105
CTransparentStaticTextAssociate::CTransparentStaticTextAssociate(wxWindow* parent, wxWindowID id, const wxString& label, const wxPoint& pos, const wxSize& size, long style, const wxString& name ) {
 
106
    Create(parent, id, label, pos, size, style, name);
 
107
}
 
108
 
 
109
 
 
110
bool CTransparentStaticTextAssociate::Create(wxWindow* parent, wxWindowID id, const wxString& label, const wxPoint& pos, const wxSize& size, long style, const wxString& name ) { 
 
111
    bool bRetVal = wxPanel::Create(parent, id, pos, size, style|wxTRANSPARENT_WINDOW, name);
 
112
 
 
113
    m_pWnd = NULL;
 
114
 
 
115
    SetLabel(label);
 
116
    SetFont(GetFont());
 
117
 
 
118
    SetBackgroundColour(parent->GetBackgroundColour());
 
119
    SetBackgroundStyle(wxBG_STYLE_COLOUR);
 
120
    SetForegroundColour(parent->GetForegroundColour());
 
121
 
 
122
    return bRetVal;
 
123
}
 
124
 
 
125
 
 
126
bool CTransparentStaticTextAssociate::SetFont(const wxFont& font) {
 
127
 
 
128
    bool ret = wxPanel::SetFont(font);
 
129
 
 
130
    InvalidateBestSize();
 
131
 
 
132
    wxCoord width, height;
 
133
    wxClientDC dc(this);
 
134
    dc.SetFont(font);
 
135
    dc.GetMultiLineTextExtent(GetLabel(), &width, &height);
 
136
 
 
137
    CacheBestSize(wxSize(width, height));
 
138
 
 
139
    return ret;
 
140
}
 
141
 
 
142
 
 
143
// Due to the nature of how wxWidgets handles some controls when Windows XP
 
144
//   themes are enabled, it is easier to make a simulated CheckBox or
 
145
//   RadioButton by linking two windows together. So when a mouse event
 
146
//   happens with this window it forwards the event to the associated
 
147
//   window.
 
148
bool CTransparentStaticTextAssociate::AssociateWindow(wxWindow* pWnd) {
 
149
    m_pWnd = pWnd;
 
150
    return true;
 
151
}
 
152
 
 
153
 
 
154
void CTransparentStaticTextAssociate::OnPaint(wxPaintEvent& /*event*/) {
 
155
    wxPaintDC dc(this);
 
156
    dc.SetFont(GetFont());
 
157
    dc.DrawText(GetLabel(), 1, 1);
 
158
}
 
159
 
 
160
 
 
161
void CTransparentStaticTextAssociate::OnMouse(wxMouseEvent& event) {
 
162
    if (m_pWnd) {
 
163
        wxMouseEvent evtAssociate(event);
 
164
        evtAssociate.SetId(m_pWnd->GetId());
 
165
        m_pWnd->ProcessEvent(event);
 
166
    }
 
167
 
 
168
    // If we get the left button up event and we already had focus, that must
 
169
    //   mean the user clicked on the static text, So change the associated
 
170
    //   control so that it has been clicked.
 
171
    if (event.GetEventType() == wxEVT_LEFT_UP) {
 
172
        wxCheckBox* pCheckBox = wxDynamicCast(m_pWnd, wxCheckBox);
 
173
        if (pCheckBox) {
 
174
            // Send the updated click event
 
175
            wxCommandEvent evtCheckBox(wxEVT_COMMAND_CHECKBOX_CLICKED, pCheckBox->GetId());
 
176
            evtCheckBox.SetEventObject(pCheckBox);
 
177
            if (pCheckBox->IsChecked()) {
 
178
                evtCheckBox.SetInt(wxCHK_UNCHECKED);
 
179
            } else {
 
180
                evtCheckBox.SetInt(wxCHK_CHECKED);
 
181
            }
 
182
            pCheckBox->Command(evtCheckBox);
 
183
        }
 
184
    }
 
185
    event.Skip();
 
186
}
 
187
 
 
188
 
 
189
IMPLEMENT_DYNAMIC_CLASS (CLinkButton, wxBitmapButton)
 
190
 
 
191
BEGIN_EVENT_TABLE(CLinkButton, wxBitmapButton)
 
192
    EVT_MOUSE_EVENTS(CLinkButton::OnMouse)
 
193
END_EVENT_TABLE()
 
194
 
 
195
 
 
196
CLinkButton::CLinkButton() {}
 
197
 
 
198
CLinkButton::CLinkButton(wxWindow* parent, wxWindowID id, const wxBitmap& bitmap, const wxPoint& pos, const wxSize& size, long style, const wxValidator& validator, const wxString& name ) {
 
199
    Create(parent, id, bitmap, pos, size, style, validator, name);
 
200
}
 
201
 
 
202
 
 
203
bool CLinkButton::Create(wxWindow* parent, wxWindowID id, const wxBitmap& bitmap, const wxPoint& pos, const wxSize& size, long style, const wxValidator& validator, const wxString& name ) { 
 
204
    bool bRetVal = wxBitmapButton::Create(parent, id, bitmap, pos, size, style, validator, name);
 
205
 
 
206
    m_HandCursor = wxCursor(wxCURSOR_HAND);
 
207
 
 
208
    return bRetVal;
 
209
}
 
210
 
 
211
 
 
212
void CLinkButton::OnMouse(wxMouseEvent& event) {
 
213
    if (event.Entering()) {
 
214
        SetCursor(m_HandCursor);
 
215
    } else if (event.Leaving()) {
 
216
        SetCursor(*wxSTANDARD_CURSOR);
 
217
    }
 
218
    event.Skip();
 
219
}