-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTableViewDelegate.cpp
137 lines (109 loc) · 4.7 KB
/
TableViewDelegate.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
// TableViewDelegate.cpp
// AmiKo-wx
//
// Created by Alex Bettarini on 18 Jun 2020
// Copyright © 2020 Ywesee GmbH. All rights reserved.
#include <wx/colour.h>
#include "TableViewDelegate.hpp"
#include "DataObject.hpp"
#include "MainWindow.h"
#include "ItemCellView.hpp"
extern bool searchStateFullText();
wxIMPLEMENT_DYNAMIC_CLASS(TableViewDelegate, wxHtmlListBox);
TableViewDelegate::TableViewDelegate(wxWindow *parent, bool multi)
: wxHtmlListBox(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize,
multi ? wxLB_MULTIPLE : 0)
, m_change(false)
{
SetMargins(5, 5);
SetItemCount(0);
// MLCustomTableView.m line 40
SetSelectionBackground(wxColor(0.8*255, 0.8*255, 255)); // selectBlue
}
void TableViewDelegate::OnDrawSeparator(wxDC& dc, wxRect& rect, size_t) const
{
dc.SetPen(*wxBLACK_PEN);
dc.DrawLine(rect.x, rect.GetBottom(), rect.GetRight(), rect.GetBottom());
}
// See MLMainWindowController.m:2783 tableView:viewForTableColumn:row
// In AmiKo-osx this is a handler for 3 table views
// myTableView, mySectionTitles, myPrescriptionsTableView
wxString TableViewDelegate::OnGetItem(size_t n) const
{
//std::cerr << "=== n:" << n << " === " << __PRETTY_FUNCTION__ << std::endl;
const wxColour typicalGray(127,127,127); // MLColors.m:26
const wxColour lightYellow(255,255,0); // MLColors.m:32
DataObject *dobj = searchRes[n];
// ItemCellView.m 123 tableView:viewForTableColumn:row
wxArrayString listOfPackages = wxSplit(wxString(dobj->subTitle), '\n');
// favoritesCheckBox
wxColour starColor = typicalGray;
wxString starChar = wxString::FromUTF8("☆");
{
// MLMainWindowController.m:2801
MainWindow * parent = wxDynamicCast(m_parent, MainWindow); // GetParent()
int m = parent->favoriteKeyData.size();
// Compare index n with count m
if (n >= m) {
#if 0 //ndef NDEBUG
std::cerr << "ERROR: === " << __FUNCTION__
<< " n: " << n << " out of bounds: " << m << " === " << std::endl;
#endif
}
else
{
bool starOn(false);
if (!searchStateFullText()) {
wxString regnrStr = parent->favoriteKeyData[n];
FAVORITES_SET::iterator it = parent->favoriteMedsSet.find(regnrStr);
starOn = (it != parent->favoriteMedsSet.end());
}
else {
wxString hashId = parent->favoriteKeyData[n];
FAVORITES_SET::iterator it = parent->favoriteFTEntrySet.find(hashId);
starOn = (it != parent->favoriteFTEntrySet.end());
}
if (starOn) {
starColor = lightYellow;
starChar = wxString::FromUTF8("★");
}
}
}
//label += "<STYLE>A {text-decoration: none;} </STYLE>"; // not effective
// Note the string literal defined as: L"" because it contains a Unicode character
wxString star_TAG = wxString::Format(L"<font color=%s size=+3>%s</font>",
starColor.GetAsString(wxC2S_HTML_SYNTAX),
starChar);
wxString title_TAG = wxString::Format("<b><font color=%s> %s</font></b>",
wxSystemSettings::GetColour(wxSYS_COLOUR_BTNTEXT).GetAsString(wxC2S_HTML_SYNTAX),
dobj->title);
wxString allPackagesList;
// Encode in the URL the row index and the package index
unsigned long rowIndex = (unsigned long)n;
for (int i=0; i<listOfPackages.size(); i++)
{
const char *packageColorCSS = "gray"; // default
if (listOfPackages[i].Contains(", O]")) // original
packageColorCSS = "red";
else if (listOfPackages[i].Contains(", G]")) // Generika
packageColorCSS = "green";
// Packages are clickable
wxString onePackage_TAG = wxString::Format("<a href='%lu_%d' style=\"color: %s;\">%s</a>",
rowIndex,
i,
packageColorCSS,
listOfPackages[i].c_str());
allPackagesList += wxString::Format("<li>%s</li>", onePackage_TAG);
}
wxString ul_TAG;
if (listOfPackages.size() > 0)
ul_TAG = wxString::Format("<ul>%s</ul>", allPackagesList);
else
ul_TAG = _("No packages"); // We should never get here
wxString oneCell_HTML = wxString::Format("<br>%s %s%s", star_TAG, title_TAG, ul_TAG);
return oneCell_HTML;
}
wxColour TableViewDelegate::GetSelectedTextColour(const wxColour& colFg) const
{
return m_change ? wxHtmlListBox::GetSelectedTextColour(colFg) : colFg;
}