-
Notifications
You must be signed in to change notification settings - Fork 1
/
thumbnailctrl.h
354 lines (230 loc) · 11.4 KB
/
thumbnailctrl.h
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
#ifndef _WX_THUMBNAILCTRL_H_
#define _WX_THUMBNAILCTRL_H_
#include "wx/dynarray.h"
#include <wx/mstream.h>
#include <openssl/md5.h>
#include "sqlite3.h"
#include "EXIF.H"
#define wxTH_MULTIPLE_SELECT 0x0010
#define wxTH_SINGLE_SELECT 0x0000
#define wxTH_TEXT_LABEL 0x0020
#define wxTH_IMAGE_LABEL 0x0040
#define wxTH_EXTENSION_LABEL 0x0080
#define wxTHUMBNAIL_SHIFT_DOWN 0x01
#define wxTHUMBNAIL_CTRL_DOWN 0x02
#define wxTHUMBNAIL_ALT_DOWN 0x04
#define wxTHUMBNAIL_SORT_NAME_UP 1
#define wxTHUMBNAIL_SORT_NAME_DOWN 2
#define wxTHUMBNAIL_SORT_TIMESTAMP_UP 3
#define wxTHUMBNAIL_SORT_TIMESTAMP_DOWN 4
#define wxTHUMBNAIL_SORT_NUMERICALLY_UP 5
#define wxTHUMBNAIL_SORT_NUMERICALLY_DOWN 6
#define wxTHUMBNAIL_SORT_TYPE_UP 7
#define wxTHUMBNAIL_SORT_TYPE_DOWN 8
#define wxTHUMBNAIL_DEFAULT_OVERALL_SIZE wxSize(-1, -1)
#define wxTHUMBNAIL_DEFAULT_IMAGE_SIZE wxSize(80, 80)
#define wxTHUMBNAIL_DEFAULT_SPACING 3
#define wxTHUMBNAIL_DEFAULT_MARGIN 3
#define wxTHUMBNAIL_DEFAULT_UNFOCUSSED_BACKGROUND wxColour(175, 175, 175)
#define wxTHUMBNAIL_DEFAULT_FOCUSSED_BACKGROUND wxColour(140, 140, 140)
// #define wxTHUMBNAIL_DEFAULT_UNSELECTED_BACKGROUND wxColour(205, 205, 205)
#define wxTHUMBNAIL_DEFAULT_UNSELECTED_BACKGROUND wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE)
#define wxTHUMBNAIL_DEFAULT_TYPE_COLOUR wxColour(0, 0, 200)
#define wxTHUMBNAIL_DEFAULT_TAG_COLOUR wxColour(0, 0, 255)
#define wxTHUMBNAIL_DEFAULT_FOCUS_RECT_COLOUR wxColour(100, 80, 80)
class wxThumbnailCtrl;
#define wxTHUMBNAIL_SELECTED 0x01
#define wxTHUMBNAIL_TAGGED 0x02
#define wxTHUMBNAIL_FOCUSSED 0x04
#define wxTHUMBNAIL_IS_FOCUS 0x08
class wxThumbnailItem : public wxObject
{
DECLARE_CLASS(wxThumbnailItem)
public:
wxThumbnailItem(const wxString& filename = wxEmptyString)
{
m_filename = filename; m_state = 0;
}
void SetFilename(const wxString& filename) { m_filename = filename; }
const wxString& GetFilename() const { return m_filename; }
void SetState(int state) { m_state = state; }
int GetState() const { return m_state; }
virtual bool Draw(wxDC& dc, wxThumbnailCtrl* ctrl, const wxRect& rect, int style);
virtual bool DrawBackground(wxDC& dc, wxThumbnailCtrl* ctrl, const wxRect& rect, const wxRect& imageRect, int style, int index);
virtual bool Load(wxThumbnailCtrl* WXUNUSED(ctrl), bool WXUNUSED(forceLoad)) { return false; }
bool isRaw;
wxString hash;
protected:
wxString m_filename;
int m_state;
};
class wxImageThumbnailItem : public wxThumbnailItem
{
DECLARE_CLASS(wxImageThumbnailItem)
public:
wxImageThumbnailItem(const wxString& filename = wxEmptyString) :
wxThumbnailItem(filename) {}
virtual bool Draw(wxDC& dc, wxThumbnailCtrl* ctrl, const wxRect& rect, int style);
virtual bool Load(wxThumbnailCtrl* ctrl, bool forceLoad);
sqlite3 *m_db;
protected:
wxBitmap m_cachedBitmap;
};
WX_DECLARE_OBJARRAY(wxThumbnailItem, wxThumbnailItemArray);
class wxThumbnailCtrl : public wxScrolledWindow
{
DECLARE_CLASS(wxThumbnailCtrl)
DECLARE_EVENT_TABLE()
public:
wxThumbnailCtrl();
wxThumbnailCtrl(wxWindow* parent, wxWindowID id = -1, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize,
long style = wxTH_TEXT_LABEL | wxTH_IMAGE_LABEL | wxTH_EXTENSION_LABEL);
bool Create(wxWindow* parent, wxWindowID id = -1, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize,
long style = wxTH_TEXT_LABEL | wxTH_IMAGE_LABEL | wxTH_EXTENSION_LABEL);
void Init();
void Freeze();
void Thaw();
void EnsureVisible(int n);
void Reload(int n);
int FindItemForFilename(const wxString& filename);
void Sort(int sortMode);
virtual bool DrawItem(int n, wxDC& dc, const wxRect& rect, int style);
virtual bool DrawItemBackground(int n, wxDC& dc, const wxRect& rect, const wxRect& imageRect, int style);
virtual int Append(wxThumbnailItem* item);
virtual int Insert(wxThumbnailItem* item, int pos = 0);
virtual void Clear();
virtual void Delete(int n);
virtual int GetCount() const { return m_items.GetCount(); }
bool IsEmpty() const { return GetCount() == 0; }
wxThumbnailItem* GetItem(int n);
bool GetItemRect(int item, wxRect& rect, bool transform = true);
bool GetItemRectImage(int item, wxRect& rect, bool transform = true);
bool GetRowCol(int item, const wxSize& clientSize, int& row, int& col);
int GetFocusItem() const { return m_focusItem; }
void SetFocusItem(int item);
void Select(int n, bool select = true);
void SelectRange(int from, int to, bool select = true);
void Tag(int n, bool tag = true);
void SelectAll();
void SelectNone();
int GetSelection() const;
const wxArrayInt& GetSelections() const { return m_selections; }
const wxArrayInt& GetTags() const { return m_tags; }
bool IsSelected(int n) const;
bool IsTagged(int n) const;
void ClearSelections();
void ClearTags();
void SetThumbnailOverallSize(const wxSize& sz) { m_thumbnailOverallSize = sz; }
const wxSize& GetThumbnailOverallSize() const { return m_thumbnailOverallSize; }
void SetThumbnailImageSize(const wxSize& sz);
const wxSize& GetThumbnailImageSize() const { return m_thumbnailImageSize; }
void SetSpacing(int spacing) { m_spacing = spacing; }
int GetSpacing() const { return m_spacing; }
void SetThumbnailMargin(int margin) { m_thumbnailMargin = margin; }
int GetThumbnailMargin() const { return m_thumbnailMargin; }
void SetThumbnailTextHeight(int h) { m_thumbnailTextHeight = h; }
int GetThumbnailTextHeight() const { return m_thumbnailTextHeight; }
void SetSelectedThumbnailBackgroundColour(const wxColour& focussedColour, const wxColour& unfocussedColour)
{
m_focussedThumbnailBackgroundColour = focussedColour; m_unfocussedThumbnailBackgroundColour = unfocussedColour;
}
const wxColour& GetSelectedThumbnailFocussedBackgroundColour() const { return m_focussedThumbnailBackgroundColour; }
const wxColour& GetSelectedThumbnailUnfocussedBackgroundColour() const { return m_unfocussedThumbnailBackgroundColour; }
void SetUnselectedThumbnailBackgroundColour(const wxColour& colour) { m_unselectedThumbnailBackgroundColour = colour; }
const wxColour& GetUnselectedThumbnailBackgroundColour() const { return m_unselectedThumbnailBackgroundColour; }
void SetTypeColour(const wxColour& colour) { m_typeColour = colour; }
const wxColour& GetTypeColour() const { return m_typeColour; }
void SetTagColour(const wxColour& colour) { m_tagColour = colour; }
const wxColour& GetTagColour() const { return m_tagColour; }
void SetFocusRectColour(const wxColour& colour) { m_focusRectColour = colour; }
const wxColour& GetFocusRectColour() const { return m_focusRectColour; }
void OnSelectAll(wxCommandEvent& event);
void OnUpdateSelectAll(wxUpdateUIEvent& event);
void OnPaint(wxPaintEvent& event);
void OnEraseBackground(wxEraseEvent& event);
void OnLeftClick(wxMouseEvent& event);
void OnLeftDClick(wxMouseEvent& event);
void OnMiddleClick(wxMouseEvent& event);
void OnRightClick(wxMouseEvent& event);
void OnChar(wxKeyEvent& event);
void OnSize(wxSizeEvent& event);
void OnSetFocus(wxFocusEvent& event);
void OnKillFocus(wxFocusEvent& event);
void SetupScrollbars();
void CalculateOverallThumbnailSize();
void DoSelection(int n, int flags);
bool HitTest(const wxPoint& pt, int& n);
virtual bool Navigate(int keyCode, int flags);
void ScrollIntoView(int n, int keyCode);
void PaintBackground(wxDC& dc);
bool RecreateBuffer(const wxSize& size = wxDefaultSize);
const wxBitmap& GetTagBitmap() const { return m_tagBitmap; }
void SetSortMode(int sortMode) { m_sortMode = sortMode; }
int GetSortMode() const { return m_sortMode; }
static wxThumbnailCtrl* GetThumbnailCtrl() { return sm_currentThumbnailCtrl; }
wxSize DoGetBestSize() const;
private:
wxThumbnailItemArray m_items;
wxArrayInt m_selections;
wxArrayInt m_tags;
wxSize m_thumbnailOverallSize;
wxSize m_thumbnailImageSize;
int m_spacing;
int m_thumbnailMargin;
int m_thumbnailTextHeight;
int m_freezeCount;
int m_firstSelection;
int m_lastSelection;
int m_focusItem;
wxBitmap m_tagBitmap;
int m_sortMode;
static wxThumbnailCtrl* sm_currentThumbnailCtrl;
wxColour m_focussedThumbnailBackgroundColour;
wxColour m_unfocussedThumbnailBackgroundColour;
wxColour m_unselectedThumbnailBackgroundColour;
wxColour m_focusRectColour;
wxColour m_typeColour;
wxColour m_tagColour;
wxBitmap m_bufferBitmap;
};
class wxThumbnailEvent : public wxNotifyEvent
{
public:
wxThumbnailEvent(wxEventType commandType = wxEVT_NULL, int winid = 0)
: wxNotifyEvent(commandType, winid),
m_itemIndex(-1), m_flags(0)
{ }
wxThumbnailEvent(const wxThumbnailEvent& event)
: wxNotifyEvent(event),
m_itemIndex(event.m_itemIndex), m_flags(event.m_flags)
{ }
int GetIndex() const { return m_itemIndex; }
void SetIndex(int n) { m_itemIndex = n; }
int GetFlags() const { return m_flags; }
void SetFlags(int flags) { m_flags = flags; }
virtual wxEvent *Clone() const { return new wxThumbnailEvent(*this); }
protected:
int m_itemIndex;
int m_flags;
private:
DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxThumbnailEvent)
};
BEGIN_DECLARE_EVENT_TYPES()
DECLARE_EVENT_TYPE(wxEVT_COMMAND_THUMBNAIL_ITEM_SELECTED, 2600)
DECLARE_EVENT_TYPE(wxEVT_COMMAND_THUMBNAIL_ITEM_DESELECTED, 2601)
DECLARE_EVENT_TYPE(wxEVT_COMMAND_THUMBNAIL_LEFT_CLICK, 2602)
DECLARE_EVENT_TYPE(wxEVT_COMMAND_THUMBNAIL_RIGHT_CLICK, 2603)
DECLARE_EVENT_TYPE(wxEVT_COMMAND_THUMBNAIL_MIDDLE_CLICK, 2604)
DECLARE_EVENT_TYPE(wxEVT_COMMAND_THUMBNAIL_LEFT_DCLICK, 2605)
DECLARE_EVENT_TYPE(wxEVT_COMMAND_THUMBNAIL_RETURN, 2606)
END_DECLARE_EVENT_TYPES()
typedef void (wxEvtHandler::*wxThumbnailEventFunction)(wxThumbnailEvent&);
#define EVT_THUMBNAIL_ITEM_SELECTED(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_THUMBNAIL_ITEM_SELECTED, id, -1, (wxObjectEventFunction) (wxEventFunction) wxStaticCastEvent( wxThumbnailEventFunction, & fn ), NULL ),
#define EVT_THUMBNAIL_ITEM_DESELECTED(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_THUMBNAIL_ITEM_DESELECTED, id, -1, (wxObjectEventFunction) (wxEventFunction) wxStaticCastEvent( wxThumbnailEventFunction, & fn ), NULL ),
#define EVT_THUMBNAIL_LEFT_CLICK(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_THUMBNAIL_LEFT_CLICK, id, -1, (wxObjectEventFunction) (wxEventFunction) wxStaticCastEvent( wxThumbnailEventFunction, & fn ), NULL ),
#define EVT_THUMBNAIL_RIGHT_CLICK(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_THUMBNAIL_RIGHT_CLICK, id, -1, (wxObjectEventFunction) (wxEventFunction) wxStaticCastEvent( wxThumbnailEventFunction, & fn ), NULL ),
#define EVT_THUMBNAIL_MIDDLE_CLICK(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_THUMBNAIL_MIDDLE_CLICK, id, -1, (wxObjectEventFunction) (wxEventFunction) wxStaticCastEvent( wxThumbnailEventFunction, & fn ), NULL ),
#define EVT_THUMBNAIL_LEFT_DCLICK(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_THUMBNAIL_LEFT_DCLICK, id, -1, (wxObjectEventFunction) (wxEventFunction) wxStaticCastEvent( wxThumbnailEventFunction, & fn ), NULL ),
#define EVT_THUMBNAIL_RETURN(id, fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_COMMAND_THUMBNAIL_RETURN, id, -1, (wxObjectEventFunction) (wxEventFunction) wxStaticCastEvent( wxThumbnailEventFunction, & fn ), NULL ),
#endif
#pragma once