forked from NatLabRockies/SAM
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathipagelist.cpp
More file actions
362 lines (293 loc) · 9.96 KB
/
ipagelist.cpp
File metadata and controls
362 lines (293 loc) · 9.96 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
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
/*******************************************************************************************************
* Copyright 2017 Alliance for Sustainable Energy, LLC
*
* NOTICE: This software was developed at least in part by Alliance for Sustainable Energy, LLC
* (“Alliance”) under Contract No. DE-AC36-08GO28308 with the U.S. Department of Energy and the U.S.
* The Government retains for itself and others acting on its behalf a nonexclusive, paid-up,
* irrevocable worldwide license in the software to reproduce, prepare derivative works, distribute
* copies to the public, perform publicly and display publicly, and to permit others to do so.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted
* provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, the above government
* rights notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, the above government
* rights notice, this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
*
* 3. The entire corresponding source code of any redistribution, with or without modification, by a
* research entity, including but not limited to any contracting manager/operator of a United States
* National Laboratory, any institution of higher learning, and any non-profit organization, must be
* made publicly available under this license for as long as the redistribution is made available by
* the research entity.
*
* 4. Redistribution of this software, without modification, must refer to the software by the same
* designation. Redistribution of a modified version of this software (i) may not refer to the modified
* version by the same designation, or by any confusingly similar designation, and (ii) must refer to
* the underlying software originally provided by Alliance as “System Advisor Model” or “SAM”. Except
* to comply with the foregoing, the terms “System Advisor Model”, “SAM”, or any confusingly similar
* designation may not be used to refer to any modified version of this software or any modified
* version of the underlying software originally provided by Alliance without the prior written consent
* of Alliance.
*
* 5. The name of the copyright holder, contributors, the United States Government, the United States
* Department of Energy, or any of their employees may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER,
* CONTRIBUTORS, UNITED STATES GOVERNMENT OR UNITED STATES DEPARTMENT OF ENERGY, NOR ANY OF THEIR
* EMPLOYEES, BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
* THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************************************/
#include <algorithm>
#include <wx/wx.h>
#include <wx/dcbuffer.h>
#include <wex/metro.h>
#include <wex/utils.h>
#include "main.h"
#include "ipagelist.h"
#include "casewin.h"
#include "../resource/notes.cpng"
#define SCRL_RATE 25
#ifndef MAX
#define MAX(a,b) ((a)<(b)?(b):(a))
#endif
BEGIN_EVENT_TABLE(InputPageList, wxScrolledWindow)
EVT_SIZE( InputPageList::OnResize )
EVT_LEFT_DOWN( InputPageList::OnLeftDown )
EVT_PAINT( InputPageList::OnPaint )
EVT_MOTION( InputPageList::OnMouseMove )
EVT_LEAVE_WINDOW( InputPageList::OnLeave )
EVT_ERASE_BACKGROUND( InputPageList::OnErase )
END_EVENT_TABLE()
static wxBitmap g_notesBitmap;
static wxColour HighlightColour(224,224,224);
static wxColour SelectColour(204,204,204);
static wxColour BackColour(243,243,243);
InputPageList::InputPageList(wxWindow *parent, int id, const wxPoint &pos, const wxSize &size)
: wxScrolledWindow(parent,id, pos, size, wxBORDER_NONE)
{
SetBackgroundStyle(wxBG_STYLE_CUSTOM);
SetBackgroundColour( BackColour );
if ( !g_notesBitmap.IsOk() )
g_notesBitmap = wxBITMAP_PNG_FROM_DATA( notes );
m_caseWin = 0;
m_selectedIdx = -1;
m_hoverIdx = -1;
}
InputPageList::~InputPageList()
{
/* nothing to do */
}
void InputPageList::Add(const wxString &item, bool geom_recalc, const wxString &resource)
{
if (Find(item) >= 0)
return;
_item x;
x.name = item;
x.resource = resource.IsEmpty()?item:resource;
wxString res_name = (!resource.IsEmpty()?resource:item);
res_name.Replace("/","");
m_items.push_back( x );
if (geom_recalc)
Invalidate();
}
void InputPageList::SetCaseWindow(CaseWindow *cw)
{
m_caseWin = cw;
}
void InputPageList::Add(const wxArrayString &item)
{
for (int i=0;i<(int)item.size();i++)
Add(item[i], (i==(int)(item.size()-1)) );
}
int InputPageList::Find(const wxString &item)
{
for (size_t i=0;i<m_items.size();i++)
if (m_items[i].name == item)
return i;
return -1;
}
wxString InputPageList::GetItem(int idx)
{
if (idx >= 0 && idx < (int)m_items.size())
return m_items[idx].name;
else
return wxEmptyString;
}
wxString InputPageList::GetValue()
{
return GetItem(m_selectedIdx);
}
void InputPageList::Remove(int idx)
{
if (idx >= 0 && idx < (int)m_items.size())
{
m_items.erase( m_items.begin() + idx );
Invalidate();
}
}
void InputPageList::ClearItems()
{
m_items.clear();
Invalidate();
}
int InputPageList::Count()
{
return m_items.size();
}
int InputPageList::FindItem(const wxString &name)
{
for (size_t i=0;i<m_items.size();i++)
if (m_items[i].name == name)
return i;
return -1;
}
wxArrayString InputPageList::GetItems()
{
wxArrayString list;
for (size_t i=0;i<m_items.size();i++)
list.Add( m_items[i].name );
return list;
}
void InputPageList::Select(int idx)
{
m_selectedIdx = idx;
Refresh();
}
int InputPageList::GetSelection()
{
return m_selectedIdx;
}
wxString InputPageList::GetStringSelection()
{
if ( m_selectedIdx >= 0 && m_selectedIdx < (int)m_items.size() )
return m_items[m_selectedIdx].name;
else
return wxEmptyString;
}
#define MYFONT wxMetroTheme::Font( wxMT_LIGHT, 13 )
void InputPageList::Invalidate()
{
int hpos, vpos;
GetViewStart( &hpos, &vpos );
hpos *= SCRL_RATE;
vpos *= SCRL_RATE;
wxSize sz = GetClientSize();
wxClientDC dc(this);
dc.SetFont( MYFONT );
int height = (int)(1.6*dc.GetCharHeight());
int y = 0;
for (size_t i=0;i<m_items.size();i++)
{
m_items[i].geom.x = 0;
m_items[i].geom.y = y;
m_items[i].geom.width = sz.GetWidth()+1;
m_items[i].geom.height = height;
y += height;
}
SetScrollbars(1,1,sz.GetWidth(),y, hpos, vpos);
SetScrollRate( SCRL_RATE, SCRL_RATE );
Refresh();
}
void InputPageList::OnResize(wxSizeEvent &)
{
Invalidate();
}
#define TXTXOFF 10
void InputPageList::OnPaint(wxPaintEvent &)
{
wxAutoBufferedPaintDC dc(this);
DoPrepareDC( dc );
wxColour bg = GetBackgroundColour();
dc.SetBrush(wxBrush(bg));
dc.SetPen(wxPen(bg,1));
wxRect windowRect( wxPoint(0,0), GetClientSize() );
CalcUnscrolledPosition(windowRect.x, windowRect.y,
&windowRect.x, &windowRect.y);
dc.DrawRectangle(windowRect);
double scale = wxGetScreenHDScale();
dc.SetTextForeground( *wxBLACK );
dc.SetFont( MYFONT );
for (int i=0;i<(int)m_items.size();i++)
{
wxRect r = m_items[i].geom;
wxColour c( GetBackgroundColour() );
if(i==m_hoverIdx) c=HighlightColour;
if(i==m_selectedIdx) c=SelectColour;
dc.SetPen( wxPen(c) );
dc.SetBrush( wxBrush(c, wxBRUSHSTYLE_SOLID) );
dc.DrawRectangle( r.x, r.y, r.width, r.height);
//wxFont font(MYFONT);
//if ( i==m_selectedIdx ) font.SetWeight( wxFONTWEIGHT_BOLD );
//dc.SetFont( font );
wxSize tsz( dc.GetTextExtent( m_items[i].name ) );
dc.DrawText( m_items[i].name, r.x+(int)(TXTXOFF*scale), r.y+r.height/2-tsz.y/2 );
dc.SetBackground( wxBrush( GetBackgroundColour() ) );
if (g_notesBitmap.IsOk() && m_caseWin
&& m_caseWin->HasPageNote( m_items[i].resource ) )
{
// int tx_w = dc.GetTextExtent( m_items[i].name ).GetWidth();
dc.DrawBitmap(g_notesBitmap,
r.x + r.width - g_notesBitmap.GetWidth() - ((int)TXTXOFF*scale),
r.y + r.height/2 - g_notesBitmap.GetHeight()/2);
}
}
}
void InputPageList::OnErase( wxEraseEvent & )
{
/* nothing to do */
}
void InputPageList::OnLeftDown(wxMouseEvent &evt)
{
int vsx, vsy;
GetViewStart( &vsx, &vsy );
vsx *= SCRL_RATE;
vsy *= SCRL_RATE;
SetFocus();
for (size_t i=0;i<m_items.size();i++)
{
if (evt.GetY()+vsy > m_items[i].geom.y
&& evt.GetY()+vsy < m_items[i].geom.y+m_items[i].geom.height )
{
m_selectedIdx = i;
Refresh();
wxCommandEvent selevt(wxEVT_COMMAND_LISTBOX_SELECTED, this->GetId() );
selevt.SetEventObject(this);
selevt.SetInt(i);
selevt.SetString(GetValue());
GetEventHandler()->ProcessEvent(selevt);
return;
}
}
}
void InputPageList::OnMouseMove(wxMouseEvent &evt)
{
int vsx, vsy;
GetViewStart( &vsx, &vsy );
vsx *= SCRL_RATE;
vsy *= SCRL_RATE;
for (int i=0;i<(int)m_items.size();i++)
{
if (evt.GetY()+vsy > m_items[i].geom.y
&& evt.GetY()+vsy < m_items[i].geom.y+m_items[i].geom.height
&& m_hoverIdx != i )
{
m_hoverIdx = i;
Refresh();
return;
}
}
}
void InputPageList::OnLeave(wxMouseEvent &)
{
m_hoverIdx = -1;
Refresh();
}