home *** CD-ROM | disk | FTP | other *** search
- /********************************************************************/
- /* Folder View - Drag and drop directory viewer */
- /* Public Domain (P) 1992 Benjamin Cooley */
- /* icons.cpp - FolderView Icon Classes */
- /********************************************************************/
-
- #include "include.h"
- #pragma hdrstop
-
- #include "fldrview.h"
-
- // Make big enough for 32 * 32 by 256 pixel image
- #define MAXPIXELS (32 * 32)
- char pixelbuf[MAXPIXELS];
-
- TStreamableClass RegIconImage("IconImage", TIconImage::build, __DELTA(TIconImage));
- TStreamableClass RegFileIcon("FileIcon", TFileIcon::build, __DELTA(TFileIcon));
- TStreamableClass RegDirIcon("DirIcon", TDirIcon::build, __DELTA(TDirIcon));
- TStreamableClass RegProgIcon("ProgIcon", TProgIcon::build, __DELTA(TProgIcon));
-
- /************************* IconImage Stuff *************************/
-
- TIconImage::TIconImage(Pchar Afilename, int Animage, HICON Anicon)
- {
- /* If no bitmap, hose out */
- if (!Anicon) DebugBreak();
-
- /* Set filename and image number */
- filename = new char[strlen(Afilename) + 1];
- strcpy(filename, Afilename);
- strupr(filename);
- image = Animage;
-
- /* Create memdc2 */
- HDC scrndc = GetDC(NULL);
- HDC memdc2 = CreateCompatibleDC(MemDC);
- HBITMAP oldbitmap2;
-
- /* Create XOR bitmap */
- bmih16->biWidth = IconWidth;
- bmih16->biHeight = IconHeight;
- memset(pixelbuf, 0, IconWidth * IconHeight / 2);
- xorbitmap = CreateDIBitmap(scrndc, bmih16,
- CBM_INIT, pixelbuf, bmi16, DIB_RGB_COLORS);
- HBITMAP oldbitmap = SelectObject(MemDC, xorbitmap);
- DrawIcon(MemDC, 0, 0, Anicon);
-
- /* Create small XOR bitmap */
- bmih16->biWidth = SmallIconWidth;
- bmih16->biHeight = SmallIconHeight;
- smallxorbitmap = CreateDIBitmap(scrndc, bmih16,
- CBM_INIT, pixelbuf, bmi16, DIB_RGB_COLORS);
- oldbitmap2 = SelectObject(memdc2, smallxorbitmap);
- StretchBlt(memdc2, 0, 0, SmallIconWidth, SmallIconHeight,
- MemDC, 0, 0, IconWidth, IconHeight, SRCCOPY);
-
- /* Create AND bitmap */
- bmih2->biWidth = IconWidth;
- bmih2->biHeight = IconHeight;
- memset(pixelbuf, 0, IconWidth * IconHeight / 8);
- andbitmap = CreateDIBitmap(scrndc, bmih2,
- CBM_INIT, pixelbuf, bmi2, DIB_RGB_COLORS);
- SelectObject(MemDC, andbitmap);
- DrawIcon(MemDC, 0, 0, Anicon);
-
- memset(pixelbuf, 0xFF, IconWidth * IconHeight / 8);
- HBITMAP tempbitmap = CreateDIBitmap(scrndc, bmih2,
- CBM_INIT, pixelbuf, bmi2, DIB_RGB_COLORS);
- SelectObject(memdc2, tempbitmap);
- DrawIcon(memdc2, 0, 0, Anicon);
- BitBlt(MemDC, 0, 0, IconWidth, IconHeight, memdc2, 0, 0, SRCINVERT);
-
- /* Create small AND bitmap */
- bmih2->biWidth = SmallIconWidth;
- bmih2->biHeight = SmallIconHeight;
- smallandbitmap = CreateDIBitmap(scrndc, bmih2,
- CBM_INIT, pixelbuf, bmi2, DIB_RGB_COLORS);
- SelectObject(memdc2, smallandbitmap);
- StretchBlt(memdc2, 0, 0, SmallIconWidth, SmallIconHeight,
- MemDC, 0, 0, IconWidth, IconHeight, SRCCOPY);
-
- /* Free DC's */
- SelectObject(memdc2, oldbitmap2);
- DeleteObject(tempbitmap);
- DeleteDC(memdc2);
- SelectObject(MemDC, oldbitmap);
- ReleaseDC(NULL, scrndc);
- }
-
- TIconImage::~TIconImage()
- {
- if (filename) delete filename;
- if (xorbitmap) DeleteObject(xorbitmap);
- if (andbitmap) DeleteObject(andbitmap);
- if (smallxorbitmap) DeleteObject(smallxorbitmap);
- if (smallandbitmap) DeleteObject(smallandbitmap);
- }
-
-
- Pvoid TIconImage::read(Ripstream is)
- {
-
- /* Name */
- char namebuf[MAXPATH];
- is.readString(namebuf, MAXPATH);
- filename = new char[strlen(namebuf) + 1];
- strcpy(filename, namebuf);
-
- /* Image number */
- is >> image;
-
- /* Get Screen DC */
- HDC scrndc = GetDC(NULL);
-
- /* XOR Bitmap */
- is.readBytes(pixelbuf, IconWidth * IconHeight / 2);
- bmih16->biWidth = IconWidth;
- bmih16->biHeight = IconHeight;
- xorbitmap = CreateDIBitmap(scrndc, bmih16,
- CBM_INIT, pixelbuf, bmi16, DIB_RGB_COLORS);
-
- /* AND Bitmap */
- is.readBytes(pixelbuf, IconWidth * IconHeight / 8);
- bmih2->biWidth = IconWidth;
- bmih2->biHeight = IconHeight;
- andbitmap = CreateDIBitmap(scrndc, bmih2,
- CBM_INIT, pixelbuf, bmi2, DIB_RGB_COLORS);
-
- /* Small XOR bitmap */
- is.readBytes(pixelbuf, SmallIconWidth * SmallIconHeight / 2);
- bmih16->biWidth = SmallIconWidth;
- bmih16->biHeight = SmallIconHeight;
- smallxorbitmap = CreateDIBitmap(scrndc, bmih16,
- CBM_INIT, pixelbuf, bmi16, DIB_RGB_COLORS);
-
- /* Small AND bitmap (Note: small icon has 4 bytes, not 2, per scan) */
- is.readBytes(pixelbuf, SmallIconWidth * SmallIconHeight / 4);
- bmih2->biWidth = SmallIconWidth;
- bmih2->biHeight = SmallIconHeight;
- smallandbitmap = CreateDIBitmap(scrndc, bmih2,
- CBM_INIT, pixelbuf, bmi2, DIB_RGB_COLORS);
-
- /* Release Screen DC */
- ReleaseDC(NULL, scrndc);
-
- return this;
- }
-
- void TIconImage::write(Ropstream os)
- {
- /* Name and image num */
- os.writeString(filename);
- os << image;
-
- /* Get Screen DC */
- HDC scrndc = GetDC(NULL);
-
- /* XOR bitmap bits */
- bmih16->biWidth = IconWidth;
- bmih16->biHeight = IconHeight;
- GetDIBits(scrndc, xorbitmap, 0, IconHeight,
- pixelbuf, bmi16, DIB_RGB_COLORS);
- os.writeBytes(pixelbuf, IconWidth * IconHeight / 2);
-
- /* AND bitmap bits */
- bmih2->biWidth = IconWidth;
- bmih2->biHeight = IconHeight;
- GetDIBits(scrndc, andbitmap, 0, IconHeight,
- pixelbuf, bmi2, DIB_RGB_COLORS);
- os.writeBytes(pixelbuf, IconWidth * IconHeight / 8);
-
- /* Small XOR bitmap bits */
- bmih16->biWidth = SmallIconWidth;
- bmih16->biHeight = SmallIconHeight;
- GetDIBits(scrndc, smallxorbitmap, 0, SmallIconHeight,
- pixelbuf, bmi16, DIB_RGB_COLORS);
- os.writeBytes(pixelbuf, SmallIconWidth * SmallIconHeight / 2);
-
- /* Small AND bitmap (Note: small icon has 4 bytes, not 2, per scan) */
- bmih2->biWidth = SmallIconWidth;
- bmih2->biHeight = SmallIconHeight;
- GetDIBits(scrndc, smallandbitmap, 0, SmallIconHeight,
- pixelbuf, bmi2, DIB_RGB_COLORS);
- os.writeBytes(pixelbuf, SmallIconWidth * SmallIconHeight / 4);
-
- /* Release Screen DC */
- ReleaseDC(NULL, scrndc);
- }
-
- /************************* IconList Stuff *************************/
-
- PTIconImage TIconList::FindIconImage(Pchar filename, int image)
- {
- for (int c = 0; c < IconImages(); c++)
- {
- PTIconImage iconimage = GetIconImage(c);
- if (!stricmp(filename, iconimage->FileName()) &&
- image == iconimage->Image()) return iconimage;
- }
- return NULL;
- }
-
- void TIconList::AddIconImage(PTIconImage iconimage)
- {
- for (int c = 0; c < IconImages(); c++)
- {
- PTIconImage animage = GetIconImage(c);
- if (!strcmp(animage->filename, iconimage->filename) &&
- (animage->image == iconimage->image))
- {
- if (animage != iconimage)
- {
- detach(c, TShouldDelete::Delete);
- add(*iconimage);
- }
- return;
- }
- }
- add(*iconimage);
- }
-
- /*************************** Icon Stuff ***************************/
-
- PTIcon TIcon::NewIcon(RTFolderView AFolderView, ffblk &Affblk)
- {
- if (Affblk.ff_attrib == FA_DIREC)
- {
- return new TDirIcon(AFolderView, Affblk);
- }
- else if (strstr(Affblk.ff_name, ".exe") ||
- strstr(Affblk.ff_name, ".com") ||
- strstr(Affblk.ff_name, ".bat") ||
- strstr(Affblk.ff_name, ".pif"))
- {
- return new TProgIcon(AFolderView, Affblk);
- }
- else
- {
- return new TFileIcon(AFolderView, Affblk);
- }
- }
-
- TIcon::TIcon(RTFolderView AFolderView, ffblk &Affblk)
- {
- folderview = &AFolderView;
- time = Affblk.ff_ftime;
- date = Affblk.ff_fdate;
- size = Affblk.ff_fsize;
- strcpy(name, Affblk.ff_name);
- strlwr(name);
- icon = 0; // Set me when painting
- strcpy(desc, Affblk.ff_name);
- strlwr(desc);
- rect.left = rect.right = rect.top = rect.bottom = 0;
- state = 0;
- textrect.left = -1;
- }
-
- int TIcon::SortOrder() const
- {
- return folderview->GetSortOrder();
- }
-
- int TIcon::View() const
- {
- return folderview->GetView();
- }
-
- Pvoid TIcon::read(Ripstream is)
- {
- is.readString(name, 13);
- is.readString(desc, DESCLEN);
- is >> date >> time >> size;
- is >> state;
- textrect.left = -1;
-
- icon = NULL;
- is >> icon;
- IconList.AddIconImage(icon);
-
- return this;
- }
-
- void TIcon::write(Ropstream os)
- {
- os.writeString(name);
- os.writeString(desc);
- os << date << time << size;
- os << state;
- os << icon;
- }
-
- HCURSOR TIcon::CreateCursor(int hotspotx, int hotspoty)
- {
- static char cursorandbits[32 * 32 / 8];
- static char cursorxorbits[32 * 32 / 8];
-
- HBITMAP bm = CreateBitmap(32, 32, 1, 1, cursorandbits);
- HBITMAP oldbitmap = SelectObject(MemDC, bm);
- HDC memdc2 = CreateCompatibleDC(MemDC);
-
- HBITMAP oldbitmap2 = SelectObject(memdc2, icon->ANDBitmap());
- BitBlt(MemDC, 0, 0, 32, 32, memdc2, 0, 0, SRCCOPY);
- GetBitmapBits(bm, 32 * 32 / 8, cursorandbits);
-
- SelectObject(memdc2, icon->XORBitmap());
- BitBlt(MemDC, 0, 0, 32, 32, memdc2, 0, 0, SRCCOPY);
- GetBitmapBits(bm, 32 * 32 / 8, cursorxorbits);
-
- SelectObject(memdc2, oldbitmap2);
- DeleteDC(memdc2);
- SelectObject(MemDC, oldbitmap);
- DeleteObject(bm);
-
- return ::CreateCursor(hInstance, hotspotx, hotspoty,
- IconWidth, IconHeight, cursorandbits, cursorxorbits);
- }
-
- BOOL TIcon::ShouldUpdate(ffblk &affblk)
- {
- if (strcmp(name, affblk.ff_name) ||
- date != affblk.ff_fdate ||
- time != affblk.ff_ftime ||
- size != affblk.ff_fsize) return TRUE;
- return FALSE;
- }
-
- void TIcon::PaintIcon(HDC PaintDC, int drawmode)
- {
-
- if (drawmode == PAINTICON_REDRAW)
- {
- FillRect(PaintDC, &rect, WindowBrush);
- }
-
- if ((drawmode == PAINTICON_ALL) || (drawmode == PAINTICON_REDRAW))
- {
- if (!icon) icon = GetIconImage();
- if (!icon) DebugBreak();
- SetTextColor(PaintDC, RGB(0, 0, 0));
- SetBkColor(PaintDC, RGB(255, 255, 255));
- HBITMAP oldbitmap = SelectObject(MemDC, icon->ANDBitmap());
- BitBlt(PaintDC, rect.left + IconLeft, rect.top + IconTop,
- IconWidth, IconHeight, MemDC, 0, 0, SRCAND);
- SelectObject(MemDC, icon->XORBitmap());
- BitBlt(PaintDC, rect.left + IconLeft, rect.top + IconTop,
- IconWidth, IconHeight, MemDC, 0, 0, SRCPAINT);
- SelectObject(MemDC, oldbitmap);
- }
-
- if (textrect.left == -1)
- {
- DWORD l = GetTextExtent(PaintDC, desc, strlen(desc));
- POINT size = MAKEPOINT(l);
- size.x += 2;
- size.y += 2;
- textrect.left = rect.left + (IconSpaceWidth / 2) - (size.x / 2);
- textrect.right = textrect.left + size.x;
- textrect.top = rect.top + IconTop + IconHeight + 2;
- textrect.bottom = textrect.top + size.y;
- }
-
- if ((drawmode == PAINTICON_ALL) ||
- (drawmode == PAINTICON_REDRAW) ||
- (drawmode == PAINTICON_DESC))
- {
- HBRUSH backbrush;
- if (state & IS_SELECTED)
- {
- SetTextColor(PaintDC, SelectedTextColor);
- SetBkColor(PaintDC, SelectedTextBkColor);
- backbrush = SelectedBrush;
- }
- else
- {
- SetTextColor(PaintDC, TextColor);
- SetBkColor(PaintDC, TextBkColor);
- backbrush = WindowBrush;
- }
-
- FillRect(PaintDC, &textrect, backbrush);
- DrawText(PaintDC, desc, strlen(desc), &textrect,
- DT_NOPREFIX | DT_SINGLELINE | DT_CENTER | DT_VCENTER | DT_NOCLIP);
- }
-
- if ((drawmode == PAINTICON_ALL) ||
- (drawmode == PAINTICON_REDRAW) ||
- (drawmode == PAINTICON_FOCUS))
- {
- if (state & IS_FOCUSED)
- {
- InflateRect(&textrect, 1, 1);
- DrawFocusRect(PaintDC, &textrect);
- InflateRect(&textrect, -1, -1);
- }
- }
-
- }
-
- void TIcon::PaintInfo(HDC PaintDC, int drawmode)
- {
- rect.right++;
- rect.bottom++;
-
- if ((drawmode == PAINTICON_ALL) ||
- (drawmode == PAINTICON_REDRAW) ||
- (drawmode == PAINTICON_DESC))
- {
-
- /* Get brush */
- HBRUSH backbrush;
- if (state & IS_SELECTED)
- {
- SetTextColor(PaintDC, SelectedTextColor);
- SetBkColor(PaintDC, SelectedTextBkColor);
- backbrush = SelectedBrush;
- }
- else
- {
- SetTextColor(PaintDC, TextColor);
- SetBkColor(PaintDC, TextBkColor);
- backbrush = WindowBrush;
- }
-
- /* Redraw background */
- FillRect(PaintDC, &rect, backbrush);
-
- /* Add space on left */
- rect.left += SmallIconWidth + 4;
-
- /* Get text to display */
- Pchar ptr;
- int tabs = 0;
- int tabarray[10];
- if (View() == VIEW_ALL)
- {
- static char buf[128];
-
- ptr = buf;
- int dispitems = folderview->GetDisplayItems();
- if (dispitems & DISPLAY_NAME)
- {
- ptr = stpcpy(ptr, name);
- *ptr++ = '\t';
- if (tabs) tabarray[tabs] = tabarray[tabs - 1];
- else tabarray[tabs] = rect.left;
- tabarray[tabs++] += AllNameWidth;
- }
- if (dispitems & DISPLAY_DATE)
- {
- struct ftime *f = (struct ftime *)&time;
- ptr += wsprintf(ptr, "%d/%d/%d",
- f->ft_month, f->ft_day, f->ft_year + 80);
- *ptr++ = '\t';
- if (tabs) tabarray[tabs] = tabarray[tabs - 1];
- else tabarray[tabs] = rect.left;
- tabarray[tabs++] += AllDateWidth;
- }
- if (dispitems & DISPLAY_TIME)
- {
- struct ftime *f = (struct ftime *)&time;
- int hour;
- Pchar ampm;
- if (f->ft_hour > 12)
- {
- hour = f->ft_hour - 12;
- ampm = "pm";
- }
- else
- {
- hour = f->ft_hour;
- if (!hour) hour = 12;
- ampm = "am";
- }
- ptr += wsprintf(ptr, "%d:%02d%s", hour, f->ft_min, ampm);
- *ptr++ = '\t';
- if (tabs) tabarray[tabs] = tabarray[tabs - 1];
- else tabarray[tabs] = rect.left;
- tabarray[tabs++] += AllTimeWidth;
- }
- if (dispitems & DISPLAY_SIZE)
- {
- ltoa(size, ptr, 10);
- ptr += strlen(ptr);
- *ptr++ = '\t';
- if (tabs) tabarray[tabs] = tabarray[tabs - 1];
- else tabarray[tabs] = rect.left;
- tabarray[tabs++] += AllSizeWidth;
- }
- if (dispitems & DISPLAY_ATTRIB)
- {
- if (attrib & FA_RDONLY) *ptr++ = 'r';
- if (attrib & FA_HIDDEN) *ptr++ = 'h';
- if (attrib & FA_SYSTEM) *ptr++ = 's';
- if (attrib & FA_LABEL) *ptr++ = 'l';
- if (attrib & FA_DIREC) *ptr++ = 'd';
- if (attrib & FA_ARCH) *ptr++ = 'a';
- *ptr++ = '\t';
- if (tabs) tabarray[tabs] = tabarray[tabs - 1];
- else tabarray[tabs] = rect.left;
- tabarray[tabs++] += AllAttribWidth;
- }
- if (dispitems & DISPLAY_DESC)
- {
- ptr = stpcpy(ptr, desc);
- *ptr++ = '\t';
- if (tabs) tabarray[tabs] = tabarray[tabs - 1];
- else tabarray[tabs] = rect.left;
- tabarray[tabs++] += AllDescWidth;
- }
- *ptr = NULL;
- ptr = buf;
- } else ptr = name; // Just name for name view
-
- /* Output text */
- TabbedTextOut(PaintDC, rect.left, rect.top, ptr, strlen(ptr),
- tabs, tabarray, rect.left);
-
- /* Restore recangle */
- rect.left -= SmallIconWidth + 4;
- }
-
- if ((drawmode == PAINTICON_ALL) ||
- (drawmode == PAINTICON_REDRAW) ||
- (drawmode == PAINTICON_DESC))
- {
- int t = (IconNameHeight - SmallIconHeight) / 2;
- if (!icon) icon = GetIconImage();
- if (!icon) DebugBreak();
- SetTextColor(PaintDC, RGB(0, 0, 0));
- SetBkColor(PaintDC, RGB(255, 255, 255));
- HBITMAP oldbitmap = SelectObject(MemDC, icon->SmallANDBitmap());
- BitBlt(PaintDC, rect.left + 2, rect.top + t,
- SmallIconWidth, SmallIconHeight, MemDC, 0, 0, SRCAND);
- SelectObject(MemDC, icon->SmallXORBitmap());
- BitBlt(PaintDC, rect.left + 2, rect.top + t,
- SmallIconWidth, SmallIconHeight, MemDC, 0, 0, SRCPAINT);
- SelectObject(MemDC, oldbitmap);
- }
-
- if ((drawmode == PAINTICON_ALL) ||
- (drawmode == PAINTICON_REDRAW) ||
- (drawmode == PAINTICON_FOCUS) ||
- (drawmode == PAINTICON_DESC))
- {
- if (state & IS_FOCUSED)
- {
- DrawFocusRect(PaintDC, &rect);
- }
- }
-
- rect.right--;
- rect.bottom--;
- }
-
- void TIcon::Paint(HDC PaintDC, int drawmode)
- {
- if (View() == VIEW_ICON) PaintIcon(PaintDC, drawmode);
- else PaintInfo(PaintDC, drawmode);
- }
-
- void TIcon::RedrawIcon()
- {
- HDC dc = folderview->GetDC();
- Paint(dc, PAINTICON_REDRAW);
- folderview->ReleaseDC(dc);
- }
-
- void TIcon::RedrawDescription()
- {
- HDC dc = folderview->GetDC();
- Paint(dc, PAINTICON_DESC);
- folderview->ReleaseDC(dc);
- }
-
- void TIcon::ToggleFocusRect()
- {
- HDC dc = folderview->GetDC();
-
- if (View() == VIEW_ICON)
- {
- InflateRect(&textrect, 1, 1);
- DrawFocusRect(dc, &textrect);
- InflateRect(&textrect, -1, -1);
- }
- else
- {
- rect.right++;
- rect.bottom++;
- DrawFocusRect(dc, &rect);
- rect.right--;
- rect.bottom--;
- }
-
- folderview->ReleaseDC(dc);
- }
-
- void TIcon::SetState(int flags)
- {
- if ((IS_FOCUSED & flags) != (IS_FOCUSED & state))
- {
- ToggleFocusRect();
- state = (state & ~IS_FOCUSED) | (flags & IS_FOCUSED);
- }
- if ((IS_SELECTED & flags) != (IS_SELECTED & state))
- {
- state = (state & ~IS_SELECTED) | (flags & IS_SELECTED);
- RedrawDescription();
- }
- }
-
- BOOL TIcon::PointOn(POINT p)
- {
- RECT r, *rptr;
-
- if (View() == VIEW_ICON)
- {
- r.left = rect.left + IconLeft;
- r.top = rect.top + IconTop;
- r.right = r.left + IconWidth - 1;
- r.bottom = r.top + IconHeight - 1;
- rptr = &r;
- } else rptr = ▭
-
- return PtInRect(rptr, p);
- }
-
- int TIcon::isEqual(RCObject object) const
- {
- RTIcon icon = (RTIcon)object;
-
- switch (SortOrder())
- {
- case SORT_BYNAME:
- return strcmp(name, icon.name) == 0;
- case SORT_BYEXT:
- Pchar ext1 = strchr(name, '.');
- if (!ext1) ext1 = (Pchar)(name + strlen(name));
- Pchar ext2 = strchr(icon.name, '.');
- if (!ext2) ext2 = (Pchar)(icon.name + strlen(icon.name));
- int result = strcmp(ext1, ext2);
- if (result == 0) result = strcmp(name, icon.name);
- return result == 0;
- case SORT_BYDATE:
- return (date == icon.date) && (time == icon.time);
- case SORT_BYSIZE:
- return size == icon.size;
- case SORT_BYDESC:
- default:
- return strcmp(desc, icon.desc) == 0;
- }
- }
-
- int TIcon::isLessThan(RCObject object) const
- {
- RTIcon icon = (RTIcon)object;
-
- switch (SortOrder())
- {
- case SORT_BYNAME:
- return strcmp(name, icon.name) < 0;
- case SORT_BYEXT:
- Pchar ext1 = strchr(name, '.');
- if (!ext1) ext1 = (Pchar)(name + strlen(name));
- Pchar ext2 = strchr(icon.name, '.');
- if (!ext2) ext2 = (Pchar)(icon.name + strlen(icon.name));
- int result = strcmp(ext1, ext2);
- if (result == 0) result = strcmp(name, icon.name);
- return result < 0;
- case SORT_BYDATE:
- return (date < icon.date) || ((date == icon.date) && (time < icon.time));
- case SORT_BYSIZE:
- return size < icon.size;
- case SORT_BYDESC:
- default:
- return strcmp(desc, icon.desc) < 0;
- }
- }
-
- void TIcon::Delete()
- {
- }
-
- void TIcon::Copy(Pchar to)
- {
- }
-
- void TIcon::Move(Pchar to)
- {
- }
-
- #if 0
- struct dostate
- {
- int pos;
- ffblk affblk;
- BOOL found;
- }
-
- static int DoFirstFile(dostate *state, Pchar dir, Pchar to,
- int (*do)(Pchar name), void (*func)(Pchar name, Pchar to))
- {
- int ok = do(dir);
- if (ok != IDYES) return ok;
-
- state->pos = strlen(dir);
- strcpy(dir + state->pos, "\\*.*");
-
- state->found = !findfirst(dir, &(state->affblk),
- FA_DIREC | FA_SYSTEM | FA_HIDDEN_;
-
- return IDYES;
- }
-
-
- #define MAXDIRLEVELS (6)
-
- class _CLASSTYPE TProcessingDialog : public TDialog
- {
- public:
- TProcessingDialog(Pchar Adirname, Pchar Atoname,
- int (*do)(Pchar name), BOOL (*func)(Pchar name, Pchar to));
-
- protected:
- PTStatic fromdesc;
- PTStatic fromfile;
- PTStatic todesc;
- PTStatic tofile;
- Pchar desc;
- char dirname[MAXPATH];
- char toname[MAXPATH];
- int (TIcon::*do)(Pchar name);
- BOOL (TIcon::*func)(Pchar name, Pchar to);
- dirstate dirarray[MAXDIRLEVELS];
- dirstate *dir;
- int dirlevel;
- int iconnum;
-
- virtual void WMNextFile(RTMessage Msg) = [WM_FIRST + WM_NEXTFILE];
- }
-
- TProcessingDialog::TProcessingDialog(Pchar Adesc, Pchar Atoname,
- int (*Ado)(Pchar name), BOOL (*Afunc)(Pchar name, Pchar to)) :
- TDialog(FolderView, DLG_Processing)
- {
-
- /* Data items */
- desc = Adesc;
- strcpy(dirname, FolderView->Dir());
- if (Atoname)
- strcpy(toname, Atoname);
- else *toname = NULL;
- do = Ado;
- func = Afunc;
-
- /* Controls */
- fromdesc = new TStatic(this, 101, 0);
- fromfile = new TStatic(this, 102, 0);
- todesc = new TStatic(this, 103, 0);
- tofile = new TStatic(this, 104, 0);
- dirlevel = 0;
-
- /* Get first icon */
- iconnum = 0;
- while (iconnum < NumAllIcons() &&
- !GetAllIcon(iconnum)->GetStateFlag(IS_SELECTED))
- iconnum++;
- }
-
- TProcessingDialog::SetupWindow()
- {
- TDialog::SetupWindow();
-
- fromdesc->SetText(desc);
- if (!*toname) todesc->SetText("");
-
-
- SendDlgMsg
-
- ;
- TProcessingDialog::TProcessingDialog(
-
- int TProcessingDialog::DoFirstFile()
- {
- int ok = do(dirname);
- if (ok != IDYES && ok != IDOK) return ok;
-
- dir->frompos = strlen(dirname);
- strcpy(dirname + dir->frompos, "\\*.*");
- dir->topos = strlen(toname);
- strcpy(toname + dir->topos, "\\");
-
- dir->found = !findfirst(dirname, &(dir->affblk),
- FA_DIREC | FA_SYSTEM | FA_HIDDEN);
- }
-
- int TProcessingDialog::DoNextFile()
- {
- if (dir->affblk.ff_name[0] != '.')
- {
- strcpy(dirname + dir->frompos + 1, dir->affblk.ff_name);
- if (*toname)
- strcpy(toname + dir->topos + 1, dir->affblk.ff_name);
- if (dir->affblk.ff_attrib & FA_DIREC)
- {
- if (dirlevel >= MAXDIRLEVELS)
- {
- MessageBox(FolderView->HWindow, "Directory level too deep!", ProgramName,
- MB_ICONSTOP | MB_OK);
- return IDCANCEL;
- }
- dirlevel++;
- dir = &(dirarray[dirlevel]);
- if (DoFirstFile() == IDCANCEL) return IDCANCEL;
- }
- else
- {
- fromfile->SetText(dirname);
- if (*toname) tofile->SetText(toname);
- func(dirname, toname);
- }
- }
-
- dir->found = !findnext(&(dir->affblk));
- while (!dir->found && dirlevel > 0)
- {
- dirlevel--;
- dir = &(dirarray[dirlevel]);
- dir->found = !findnext(&(dir->affblk));
- }
-
- return IDYES;
- }
-
- void TProcessingDialog::WMNextFile(RTMessage Msg)
- {
- int status;
-
- fromfile->SetText(dirname);
- if (*toname) tofile->SetText(toname);
-
- status = icon->NextFile(frompath, topath);
- if (status == IDCANCEL)
- {
- CloseWindow(IDCANCEL);
- return;
- }
-
- if (status == IDNO)
- {
- iconnum++;
- while (iconnum < NumAllIcons() &&
- !GetAllIcon(iconnum)->GetStateFlag(IS_SELECTED))
- iconnum++;
- if (iconnum > NumAllIcons())
- {
- CloseWindow(IDOK);
- return;
- }
- icon->FirstFile(
- }
- PostMessage(HWindow, WM_NEXTFILE, 0, 0L);
- }
-
- DoNextFile(
- if (dirlevel)
-
-
- (icon->*func)(dirname, toname);
-
-
-
-
- static int DoDeleteDir(Pchar dir)
- {
- wsprintf(TextBuf,
- "Are you sure you want to delete all files in directory %s", dir);
- int MessageBox(FolderView->HWindow, TextBuf, ProgramName,
- MB_ICONQUESTION | MB_YESNOCANCEL);
- }
-
-
-
-
- void TDirIcon::Delete()
- {
-
-
- void TIcon::Move(Pchar to)
- {
- }
-
- void TIcon::Copy(Pchar to)
- {
- _dos_open(
-
- }
-
- #endif
-
- // *************** TFileIcon Class ***************
-
- PTIconImage TFileIcon::GetIconImage()
- {
- char exepath[MAXPATH];
- PTIconImage iconimage;
-
- int ret = (int)FindExecutable(name, folderview->MainView()->Directory(), exepath);
- if (ret > 32)
- {
- iconimage = IconList.FindIconImage(exepath, 0);
- if (iconimage) return iconimage;
- HICON icon = ExtractIcon(hInstance, exepath, 0);
- if (icon)
- {
- iconimage = new TIconImage(exepath, 0, icon);
- IconList.add(*iconimage);
- }
- else
- {
- iconimage = IconList.FindIconImage(FileIconName, 0);
- }
- }
- else
- {
- iconimage = IconList.FindIconImage(FileIconName, 0);
- }
- return iconimage;
- }
-
- void TFileIcon::Open()
- {
- char filepath[MAXPATH];
-
- strcpy(filepath, folderview->MainView()->Directory());
- strcat(filepath, name);
- ShellExecute(folderview->HWindow, NULL,
- filepath, NULL, folderview->MainView()->Directory(), SW_SHOWNORMAL);
- }
-
- // *************** TDirIcon Class ***************
-
- PTIconImage TDirIcon::GetIconImage()
- {
- return IconList.FindIconImage(DirIconName, 0);
- }
-
- void TDirIcon::Open()
- {
- char dirbuf[MAXPATH];
-
- strcpy(dirbuf, folderview->MainView()->Directory());
- strcat(dirbuf, name);
- strcat(dirbuf, "\\");
- ShellExecute(folderview->HWindow, NULL,
- FolderViewFileName, dirbuf, dirbuf, SW_SHOWNORMAL);
- }
-
- // *************** TProgIcon Class ***************
-
- PTIconImage TProgIcon::GetIconImage()
- {
- char exepath[MAXPATH];
-
- strcpy(exepath, folderview->MainView()->Directory());
- strcat(exepath, name);
- PTIconImage iconimage = IconList.FindIconImage(exepath, 0);
- if (iconimage) return iconimage;
- HICON icon = ExtractIcon(hInstance, exepath, 0);
- if (icon && icon != 1)
- {
- iconimage = new TIconImage(exepath, 0, icon);
- IconList.add(*iconimage);
- }
- else
- {
- if (strstr(name, ".bat"))
- iconimage = IconList.FindIconImage(BatchIconName, 0);
- else if (strstr(name, ".pif"))
- iconimage = IconList.FindIconImage(PifIconName, 0);
- else
- iconimage = IconList.FindIconImage(ProgIconName, 0);
- }
- return iconimage;
- }
-
- void TProgIcon::Open()
- {
- char exepath[MAXPATH];
-
- strcpy(exepath, folderview->MainView()->Directory());
- strcat(exepath, name);
- ShellExecute(folderview->HWindow, NULL,
- exepath, NULL, folderview->MainView()->Directory(), SW_SHOWNORMAL);
- }
-
-