00001
00002
00003
00004
00005
00006
00007
00008
00010
00011
#ifndef WXVILLALIB_THUMBNAILS_H
00012
#define WXVILLALIB_THUMBNAILS_H
00013
00014
#include <wx/wx.h>
00015
#include <wx/image.h>
00016
00017
const int POINTED_BRIGHTNESS = 24;
00018
00019
class wxThumbnails;
00020
00021
class wxThumb
00022 {
00023
public:
00024 wxThumb(wxImage image, wxString caption = wxEmptyString)
00025 { m_image = image; SetCaption(caption); m_id = 0; }
00026 wxThumb(wxString filename, wxString caption = wxEmptyString)
00027 { m_filename = filename; SetCaption(caption); m_id = 0; }
00028
virtual ~wxThumb() {}
00029
00030 wxString GetCaption() {
return m_caption; }
00031
void SetCaption(wxString caption);
00032
00033 wxImage GetImage() {
return m_image; }
00034
void SetImage(wxImage image) { m_image = image; }
00035
00036 wxString GetFilename() {
return m_filename; }
00037
void SetFilename(wxString fname);
00038
00039
int GetId() {
return m_id; }
00040
void SetId(
int id) { m_id =
id; }
00041
00042 wxBitmap GetBitmap() {
return m_bitmap; }
00043
void SetBitmap(wxBitmap bitmap) { m_bitmap = bitmap; }
00044
void Update() { m_bitmap = wxBitmap(); }
00045
00046
virtual wxBitmap GetBitmap(
wxThumbnails* parent,
int width,
int height);
00047 wxString GetCaption(
unsigned int line);
00048
int GetCaptionLinesCount(
int width);
00049
00050
protected:
00051 wxImage m_image;
00052 wxString m_filename;
00053
int m_id;
00054 wxBitmap m_bitmap;
00055 wxString m_caption;
00056 wxArrayInt m_captionBreaks;
00057
void BreakCaption(
int width);
00058 };
00059
00060 WX_DEFINE_ARRAY(wxThumb*, wxThumbArray);
00061
00062
inline int cmpthumb(wxThumb** first, wxThumb** second)
00063 {
00064
if ((*first)->GetFilename() < (*second)->GetFilename())
00065
return -1;
00066
else if ((*first)->GetFilename() == (*second)->GetFilename())
00067
return (*first)->GetId() - (*second)->GetId();
00068
return 1;
00069 }
00070
00071
enum wxThumbOutline
00072 {
00073 wxTHUMB_OUTLINE_NONE,
00074 wxTHUMB_OUTLINE_FULL,
00075 wxTHUMB_OUTLINE_RECT,
00076 wxTHUMB_OUTLINE_IMAGE
00077 };
00078
00079
enum wxThumbFilter
00080 {
00081 wxTHUMB_FILTER_IMAGES = 1,
00082 wxTHUMB_FILTER_VIDEOS = 2,
00083 wxTHUMB_FILTER_AUDIOS = 4,
00084 wxTHUMB_FILTER_CUSTOM = 8,
00085 };
00086
00088
enum
00089 {
00090 wxTHUMB_HORIZONTAL = wxHORIZONTAL,
00091 wxTHUMB_VERTICAL = wxVERTICAL
00092 };
00093
00104 class wxThumbnails:
public wxScrolledWindow
00105 {
00106
public:
00107
wxThumbnails(wxWindow* parent,
int id);
00108
virtual ~
wxThumbnails();
00109
00111
void Clear();
00113
void ShowDir(wxString dir,
int filter = -1);
00114
static bool IsAudioVideo(
const wxString& fname);
00115
static bool IsVideo(
const wxString& fname);
00116
static bool IsAudio(
const wxString& fname);
00117
bool IsCustomFile(
const wxString& fname) {
return m_customExtentions.Index(fname.AfterLast(wxT(
'.')).Lower()) >= 0; }
00118
void AddCustomExtention(
const wxString& ext) {
m_customExtentions.Add(ext.Lower()); }
00119
void ClearCustomExtentions() {
m_customExtentions.Clear(); }
00121 void SetFilter(
int filter) { m_filter = filter; }
00122
00124 inline int GetSelected(
int selIndex = -1) {
return selIndex == -1 ? m_selected : m_selectedArray[selIndex]; }
00125
inline wxThumb* GetSelectedItem(
int selIndex = -1) {
return GetItem(GetSelected(selIndex)); }
00126
inline int GetSelectedCount() {
return m_selectedArray.Count(); }
00127
inline bool IsSelected(
int index) {
return m_selectedArray.Index(index) != -1; }
00128
void SetSelected(
int value);
00129
inline void AddToSelection(
int value) { m_selectedArray.Add(value); }
00131 inline int GetPointed() {
return m_pointed; }
00132
inline wxThumb* GetPointedItem() {
return GetItem(m_pointed); }
00133
00134
inline wxThumb* GetItem(
int index)
00135 {
return index>=0 && index<(
int)m_items.GetCount()? m_items[index]:NULL; }
00136
inline int GetItemCount() {
return m_items.GetCount(); }
00137
void InsertItem(wxThumb* thumb,
int pos = -1);
00138
void RemoveItemAt(
int pos,
int count = 1);
00139
inline void SortItems() { m_items.Sort(cmpthumb); }
00140
00142
virtual void UpdateItems();
00143
00144
void SetThumbSize(
int width,
int height,
int border=8);
00145
void GetThumbSize(
int& width,
int& height,
int& border);
00146
inline int GetThumbWidth() {
return m_tWidth; }
00147
inline int GetThumbHeight() {
return m_tHeight; }
00148
inline int GetThumbBorder() {
return m_tBorder; }
00149
00150
virtual void SetCaption(wxString caption);
00151 wxString GetCaption() {
return m_caption; }
00152
void SetLabelControl(wxStaticText* value) { m_labelControl = value; }
00153
00154
void ShowFileNames(
bool value =
true) { m_showFileNames = value; }
00155
00156
void SetOrientaion(
int value = wxTHUMB_VERTICAL) { m_orient = value; }
00157
00159 void SetPopupMenu(wxMenu* menu) { m_pmenu = menu; }
00161 wxMenu*
GetPopupMenu() {
return m_pmenu; }
00162
00164 void SetGlobalPopupMenu(wxMenu* menu) { m_gpmenu = menu; }
00166 wxMenu*
GetGloalPopupMenu() {
return m_gpmenu; }
00167
00168
inline void EnableDragging(
bool value =
true) { m_allowDragging = value; }
00169
00170
protected:
00172 int m_tWidth;
00173
int m_tHeight;
00174
int m_tBorder;
00175
int m_tCaptionBorder;
00176 wxArrayInt m_tCaptionHeight;
00177
int m_tTextHeight;
00178 wxThumbOutline m_tOutline;
00179
bool m_tOutlineNotSelected;
00180
00181
int m_selected;
00182 wxArrayInt m_selectedArray;
00183
int m_pointed;
00184
00185 wxString m_dir;
00186
int m_filter;
00187 wxString m_caption;
00188
00189 wxThumbArray m_items;
00190
int m_cols;
00191
int m_rows;
00192
00193 wxStaticText* m_labelControl;
00194 wxMenu* m_pmenu;
00195 wxMenu* m_gpmenu;
00196
bool m_allowDragging;
00197
bool m_mouseEventHandled;
00198
bool m_showFileNames;
00199
int m_orient;
00200
00202 wxArrayString
m_customExtentions;
00203
00204
virtual int GetCaptionHeight(
int begRow,
int count = 1);
00205
virtual int GetItemIndex(
int x,
int y);
00206
virtual void UpdateProp(
bool checkSize =
true);
00207
virtual void ScrollToSelected();
00208
virtual void DrawThumbnail(wxBitmap& bmp, wxThumb& thumb,
int index);
00209
virtual void OnPaint(wxPaintEvent& WXUNUSED(event));
00210
virtual void OnResize(wxSizeEvent &event);
00211
virtual void OnMouseDown(wxMouseEvent &event);
00212
virtual void OnMouseUp(wxMouseEvent &event);
00213
virtual void OnMouseDClick(wxMouseEvent &event);
00214
virtual void OnMouseMove(wxMouseEvent &event);
00215
virtual void OnMouseLeave(wxMouseEvent &event);
00216
virtual void OnThumbChanged(wxCommandEvent &event);
00217
virtual void OnEraseBackground(wxEraseEvent &event) {}
00218 wxRect GetPaintRect();
00219
00220
virtual void UpdateItemsInt();
00221
00222
private:
00223 DECLARE_EVENT_TABLE()
00224 };
00225
00226 BEGIN_DECLARE_EVENT_TYPES()
00227 DECLARE_EVENT_TYPE(EVT_COMMAND_THUMBNAILS_SEL_CHANGED, 3200)
00228 DECLARE_EVENT_TYPE(EVT_COMMAND_THUMBNAILS_POINTED, 3201)
00229 DECLARE_EVENT_TYPE(EVT_COMMAND_THUMBNAILS_DCLICK, 3202)
00230 DECLARE_EVENT_TYPE(EVT_COMMAND_THUMBNAILS_CAPTION_CHANGED, 3203)
00231 DECLARE_EVENT_TYPE(EVT_COMMAND_THUMBNAILS_THUMB_CHANGED, 3204)
00232 END_DECLARE_EVENT_TYPES()
00233
00234 #define EVT_THUMBNAILS_SEL_CHANGED(
id, fn)\
00235 DECLARE_EVENT_TABLE_ENTRY(EVT_COMMAND_THUMBNAILS_SEL_CHANGED,
id, wxID_ANY,\
00236 (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction)& fn, NULL),
00237
00238 #define EVT_THUMBNAILS_POINTED(
id, fn)\
00239 DECLARE_EVENT_TABLE_ENTRY(EVT_COMMAND_THUMBNAILS_POINTED,
id, wxID_ANY,\
00240 (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction)& fn, NULL),
00241
00242 #define EVT_THUMBNAILS_DCLICK(
id, fn)\
00243 DECLARE_EVENT_TABLE_ENTRY(EVT_COMMAND_THUMBNAILS_DCLICK,
id, wxID_ANY,\
00244 (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction)& fn, NULL),
00245
00246 #define EVT_THUMBNAILS_CAPTION_CHANGED(
id, fn)\
00247 DECLARE_EVENT_TABLE_ENTRY(EVT_COMMAND_THUMBNAILS_CAPTION_CHANGED,
id,wxID_ANY,\
00248 (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction)& fn, NULL),
00249
00250 #define EVT_THUMBNAILS_THUMB_CHANGED(
id, fn)\
00251 DECLARE_EVENT_TABLE_ENTRY(EVT_COMMAND_THUMBNAILS_THUMB_CHANGED,
id,wxID_ANY,\
00252 (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction)& fn, NULL),
00253
00254 #endif