-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsendbutton.cpp
More file actions
108 lines (87 loc) · 2.72 KB
/
sendbutton.cpp
File metadata and controls
108 lines (87 loc) · 2.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
// Copyright (C) 2016 Frode Roxrud Gill
// See LICENSE file for license
#ifdef __GNUG__
#pragma implementation "sendbutton.h"
#endif
#include <wx/button.h>
#include <wx/renderer.h>
#include <wx/settings.h>
#include "sendbutton.h"
#include "frame.h"
#define PADDING_WIDTH (4)
#define PADDING_HEIGHT (4)
using namespace PhotoMailer;
SendButtonClientData::SendButtonClientData()
: wxClientData(),
m_progress(0.0),
m_has_failed(false),
m_is_pressed(false)
{
}
SendButtonClientData::~SendButtonClientData()
{
}
SendButtonRenderer::SendButtonRenderer()
: wxGridCellRenderer()
{
}
SendButtonRenderer::~SendButtonRenderer()
{
}
void SendButtonRenderer::Draw(wxGrid& grid, wxGridCellAttr& attr, wxDC& dc, const wxRect& rect,
int row, int col, bool isSelected)
{
wxGridCellRenderer::Draw(grid, attr, dc, rect, row, col, isSelected);
#ifndef CLIENTDATA_FIX
wxGridCellAttrPtr attr_ptr = grid.GetOrCreateCellAttrPtr(row, col);
SendButtonClientData* sendbutton_clientdata = static_cast<SendButtonClientData*>(attr_ptr.get()?attr_ptr->GetClientObject():nullptr);
#else
SendButtonClientData* sendbutton_clientdata = static_cast<SendButtonClientData*>(attr.GetClientObject());
#endif
if (sendbutton_clientdata)
{
float progress = sendbutton_clientdata->GetProgress();
if (0.0<progress)
{
dc.SetPen(*wxTRANSPARENT_PEN);
const wxBrush* brush;
if (sendbutton_clientdata->HasFailed())
{
brush = wxRED_BRUSH;
}
else
{
brush = (1.0>progress) ? wxBLUE_BRUSH : wxGREEN_BRUSH;
}
dc.SetBrush(*brush);
dc.DrawRectangle(wxRect(rect.GetLeft(), rect.GetTop(), rect.GetWidth()*progress, rect.GetHeight()));
}
if (0.0>=progress || 1.0<=progress)
{
wxString email = grid.GetCellValue(row, EMAIL_COLUMN);
if (!email.IsEmpty())
{
int button_width = rect.GetWidth()-(2*PADDING_WIDTH);
int button_height = rect.GetHeight()-(2*PADDING_HEIGHT);
int default_button_height = wxButton::GetDefaultSize().GetHeight();
if (default_button_height<button_height)
{
button_height = default_button_height;
}
if ((2*PADDING_WIDTH)<button_width && (2*PADDING_HEIGHT)<button_height)
{
wxRect button_rect = wxRect(rect.GetX()+PADDING_WIDTH, rect.GetY()+(rect.GetHeight()-button_height)/2, button_width, button_height);
wxRendererNative::Get().DrawPushButton(grid.GetGridWindow(), dc, button_rect,
sendbutton_clientdata->GetIsPressed()?wxCONTROL_PRESSED:wxCONTROL_NONE);
dc.SetTextForeground(grid.GetLabelTextColour());
dc.SetBackgroundMode(wxPENSTYLE_TRANSPARENT);
dc.DrawLabel(_("Send"), button_rect, wxALIGN_CENTER);
}
}
}
}
}
wxGridCellRenderer* SendButtonRenderer::Clone() const
{
return new SendButtonRenderer;
}