#include "wx/image.h"
#include "wx/module.h"
#include "wx/config.h"
-
+#include "wx/imaglist.h"
#if wxUSE_TOOLTIPS
#include "wx/tooltip.h"
class wxFileIconEntry : public wxObject
{
- public:
- wxFileIconEntry(int i) { id = i; }
-
- int id;
+public:
+ wxFileIconEntry(int i) { id = i; }
+
+ int id;
};
class wxFileIconsTable
{
- public:
+public:
+ wxFileIconsTable();
- wxFileIconsTable();
-
- int GetIconID(const wxString& extension, const wxString& mime = wxEmptyString);
- wxImageList *GetImageList() { return &m_ImageList; }
+ int GetIconID(const wxString& extension, const wxString& mime = wxEmptyString);
+ wxImageList *GetImageList() { return &m_ImageList; }
- protected:
- wxImageList m_ImageList;
- wxHashTable m_HashTable;
+protected:
+ wxImageList m_ImageList;
+ wxHashTable m_HashTable;
};
static wxFileIconsTable *g_IconsTable = NULL;
m_HashTable.DeleteContents(TRUE);
m_ImageList.Add(wxBitmap(folder_xpm)); // FI_FOLDER
m_ImageList.Add(wxBitmap(deffile_xpm)); // FI_UNKNOWN
- if (GetIconID(wxEmptyString, _T("application/x-executable")) == FI_UNKNOWN)
+ if (GetIconID(wxEmptyString, _T("application/x-executable")) == FI_UNKNOWN)
{ // FI_EXECUTABLE
- m_ImageList.Add(wxBitmap(exefile_xpm));
+ m_ImageList.Add(wxBitmap(exefile_xpm));
m_HashTable.Delete(_T("exe"));
m_HashTable.Put(_T("exe"), new wxFileIconEntry(FI_EXECUTABLE));
}
{
wxImage small(16, 16);
unsigned char *p1, *p2, *ps;
- unsigned char mr = img.GetMaskRed(),
- mg = img.GetMaskGreen(),
+ unsigned char mr = img.GetMaskRed(),
+ mg = img.GetMaskGreen(),
mb = img.GetMaskBlue();
-
+
unsigned x, y;
unsigned sr, sg, sb, smask;
-
+
p1 = img.GetData(), p2 = img.GetData() + 3 * 32, ps = small.GetData();
small.SetMaskColour(mr, mr, mr);
-
+
for (y = 0; y < 16; y++)
{
for (x = 0; x < 16; x++)
sr += p2[0], sg += p2[1], sb += p2[2];
else smask++;
p2 += 3;
-
- if (smask > 2)
+
+ if (smask > 2)
ps[0] = ps[1] = ps[2] = mr;
else
ps[0] = sr >> 2, ps[1] = sg >> 2, ps[2] = sb >> 2;
}
p1 += 32 * 3, p2 += 32 * 3;
}
-
+
return small.ConvertToBitmap();
}
+// finds empty borders and return non-empty area of image:
+static wxImage CutEmptyBorders(const wxImage& img)
+{
+ unsigned char mr = img.GetMaskRed(),
+ mg = img.GetMaskGreen(),
+ mb = img.GetMaskBlue();
+ unsigned char *dt = img.GetData(), *dttmp;
+ unsigned w = img.GetWidth(), h = img.GetHeight();
+
+ unsigned top, bottom, left, right, i;
+ bool empt;
+
+#define MK_DTTMP(x,y) dttmp = dt + ((x + y * w) * 3)
+#define NOEMPTY_PIX(empt) if (dttmp[0] != mr || dttmp[1] != mg || dttmp[2] != mb) {empt = FALSE; break;}
+
+ for (empt = TRUE, top = 0; empt && top < h; top++)
+ {
+ MK_DTTMP(0, top);
+ for (i = 0; i < w; i++, dttmp+=3)
+ NOEMPTY_PIX(empt)
+ }
+ for (empt = TRUE, bottom = h-1; empt && bottom > top; bottom--)
+ {
+ MK_DTTMP(0, bottom);
+ for (i = 0; i < w; i++, dttmp+=3)
+ NOEMPTY_PIX(empt)
+ }
+ for (empt = TRUE, left = 0; empt && left < w; left++)
+ {
+ MK_DTTMP(left, 0);
+ for (i = 0; i < h; i++, dttmp+=3*w)
+ NOEMPTY_PIX(empt)
+ }
+ for (empt = TRUE, right = w-1; empt && right > left; right--)
+ {
+ MK_DTTMP(right, 0);
+ for (i = 0; i < h; i++, dttmp+=3*w)
+ NOEMPTY_PIX(empt)
+ }
+ top--, left--, bottom++, right++;
+
+ return img.GetSubImage(wxRect(left, top, right - left + 1, bottom - top + 1));
+}
+
+
+
int wxFileIconsTable::GetIconID(const wxString& extension, const wxString& mime)
{
if (!extension.IsEmpty())
if (entry) return (entry -> id);
}
- wxFileType *ft = (mime.IsEmpty()) ?
+ wxFileType *ft = (mime.IsEmpty()) ?
wxTheMimeTypesManager -> GetFileTypeFromExtension(extension) :
wxTheMimeTypesManager -> GetFileTypeFromMimeType(mime);
wxIcon ic;
}
wxImage img(ic);
delete ft;
-
+
int id = m_ImageList.GetImageCount();
if (img.GetWidth() == 16 && img.GetHeight() == 16)
m_ImageList.Add(img.ConvertToBitmap());
else
{
if (img.GetWidth() != 32 || img.GetHeight() != 32)
- img.Rescale(32, 32);
- m_ImageList.Add(CreateAntialiasedBitmap(img));
+ m_ImageList.Add(CreateAntialiasedBitmap(CutEmptyBorders(img).Rescale(32, 32)));
+ else
+ m_ImageList.Add(CreateAntialiasedBitmap(img));
}
m_HashTable.Put(extension, new wxFileIconEntry(id));
return id;
item.ClearAttributes();
if (IsExe()) item.SetTextColour(*wxRED);
if (IsDir()) item.SetTextColour(*wxBLUE);
-
+
if (IsDir())
item.m_image = FI_FOLDER;
- else if (IsExe())
+ else if (IsExe())
item.m_image = FI_EXECUTABLE;
else if (m_name.Find(wxT('.')) != wxNOT_FOUND)
item.m_image = g_IconsTable -> GetIconID(m_name.AfterLast(wxT('.')));
BEGIN_EVENT_TABLE(wxFileCtrl,wxListCtrl)
EVT_LIST_DELETE_ITEM(-1, wxFileCtrl::OnListDeleteItem)
+ EVT_LIST_DELETE_ALL_ITEMS(-1, wxFileCtrl::OnListDeleteAllItems)
EVT_LIST_END_LABEL_EDIT(-1, wxFileCtrl::OnListEndLabelEdit)
END_EVENT_TABLE()
-
wxFileCtrl::wxFileCtrl()
{
m_dirName = wxT("/");
if (GetColumnCount() > 0)
name_col_width = GetColumnWidth( 0 );
}
-
+
ClearAll();
if (my_style & wxLC_REPORT)
{
delete fd;
}
+void wxFileCtrl::OnListDeleteAllItems( wxListEvent &WXUNUSED(event) )
+{
+ wxListItem item;
+ item.m_mask = wxLIST_MASK_DATA;
+
+ item.m_itemId = GetNextItem( -1, wxLIST_NEXT_ALL );
+ while ( item.m_itemId != -1 )
+ {
+ GetItem( item );
+ wxFileData *fd = (wxFileData*)item.m_data;
+ delete fd;
+ item.m_data = 0;
+ SetItem( item );
+ item.m_itemId = GetNextItem( item.m_itemId, wxLIST_NEXT_ALL );
+ }
+}
+
void wxFileCtrl::OnListEndLabelEdit( wxListEvent &event )
{
wxFileData *fd = (wxFileData*)event.m_item.m_data;
if (m_dialogStyle & wxMULTIPLE)
m_list = new wxFileCtrl( this, ID_LIST_CTRL, m_dir, firstWild, wxDefaultPosition,
- wxSize(440,180), s_lastViewStyle | wxSUNKEN_BORDER );
+ wxSize(440,180), s_lastViewStyle | wxSUNKEN_BORDER );
else
m_list = new wxFileCtrl( this, ID_LIST_CTRL, m_dir, firstWild, wxDefaultPosition,
- wxSize(440,180), s_lastViewStyle | wxSUNKEN_BORDER | wxLC_SINGLE_SEL );
+ wxSize(440,180), s_lastViewStyle | wxSUNKEN_BORDER | wxLC_SINGLE_SEL );
m_list -> ShowHidden(s_lastShowHidden);
mainsizer->Add( m_list, 1, wxEXPAND | wxLEFT|wxRIGHT, 10 );
mainsizer->Fit( this );
mainsizer->SetSizeHints( this );
-
+
Centre( wxBOTH );
+/*
if (m_fileName.IsEmpty())
m_list->SetFocus();
else
+*/
m_text->SetFocus();
wxEndBusyCursor();
item.m_mask = wxLIST_MASK_TEXT;
item.m_itemId = m_list->GetNextItem( -1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED );
- while ( item.m_itemId != -1 ) {
+ while ( item.m_itemId != -1 )
+ {
m_list->GetItem( item );
paths.Add( dir + item.m_text );
- item.m_itemId = m_list->GetNextItem( item.m_itemId + 1,
+ item.m_itemId = m_list->GetNextItem( item.m_itemId,
wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED );
}
}
item.m_mask = wxLIST_MASK_TEXT;
item.m_itemId = m_list->GetNextItem( -1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED );
- while ( item.m_itemId != -1 ) {
+ while ( item.m_itemId != -1 )
+ {
m_list->GetItem( item );
files.Add( item.m_text );
- item.m_itemId = m_list->GetNextItem( item.m_itemId + 1,
+ item.m_itemId = m_list->GetNextItem( item.m_itemId,
wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED );
}
}