/* * Winefile * * Copyright 2000, 2003, 2004, 2005, 2008 Martin Fuchs * Copyright 2006 Jason Green * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA */ #include "winefile.h" static void set_curdir(ChildWnd* child, Entry* entry, int idx, HWND hwnd); static void refresh_child(ChildWnd* child); static void refresh_drives(void); /* some common string constants */ const TCHAR sEmpty[] = {'\0'}; const TCHAR sSpace[] = {' ', '\0'}; const TCHAR sNumFmt[] = {'%','d','\0'}; const TCHAR sQMarks[] = {'?','?','?','\0'}; #ifdef _MSC_VER const TCHAR sLongHexFmt[] = {'%','I','6','4','X','\0'}; const TCHAR sLongNumFmt[] = {'%','I','6','4','d','\0'}; #else const TCHAR sLongHexFmt[] = {'%','L','X','\0'}; const TCHAR sLongNumFmt[] = {'%','L','d','\0'}; #endif /* window class names */ const TCHAR sWINEFILEFRAME[] = {'W','F','S','_','F','r','a','m','e','\0'}; const TCHAR sWINEFILETREE[] = {'W','F','S','_','T','r','e','e','\0'}; /* globals */ struct WINEFILE_GLOBALS Globals; static int last_split; /* load resource string */ LPTSTR load_string(LPTSTR buffer, UINT id) { LoadString(Globals.hInstance, id, buffer, BUFFER_LEN); return buffer; } /* display error message for the specified WIN32 error code */ void display_error(HWND hwnd, DWORD error) { TCHAR b1[BUFFER_LEN], b2[BUFFER_LEN]; PTSTR msg; if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM, 0, error, MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT), (PTSTR)&msg, 0, NULL)) MessageBox(hwnd, msg, RS(b2,IDS_WINEFILE), MB_OK); else MessageBox(hwnd, RS(b1,IDS_ERROR), RS(b2,IDS_WINEFILE), MB_OK); LocalFree(msg); } /* display network error message using WNetGetLastError() */ void display_network_error(HWND hwnd) { TCHAR msg[BUFFER_LEN], provider[BUFFER_LEN], b2[BUFFER_LEN]; DWORD error; if (WNetGetLastError(&error, msg, BUFFER_LEN, provider, BUFFER_LEN) == NO_ERROR) MessageBox(hwnd, msg, RS(b2,IDS_WINEFILE), MB_OK); } #ifdef __WINE__ #ifdef UNICODE /* call vswprintf() in msvcrt.dll */ /*TODO: fix swprintf() in non-msvcrt mode, so that this dynamic linking function can be removed */ static int msvcrt_swprintf(WCHAR* buffer, const WCHAR* fmt, ...) { static int (__cdecl *pvswprintf)(WCHAR*, const WCHAR*, va_list) = NULL; va_list ap; int ret; if (!pvswprintf) { HMODULE hModMsvcrt = LoadLibraryA("msvcrt"); pvswprintf = (int(__cdecl*)(WCHAR*,const WCHAR*,va_list)) GetProcAddress(hModMsvcrt, "vswprintf"); } va_start(ap, fmt); ret = (*pvswprintf)(buffer, fmt, ap); va_end(ap); return ret; } /* UNICODE version of strrchr() for WINE */ static LPCWSTR my_wcsrchr(LPCWSTR str, WCHAR c) { LPCWSTR p = str; while(*p) ++p; do { if (--p < str) return NULL; } while(*p != c); return p; } #define _tcsrchr my_wcsrchr #else /* UNICODE */ #define _tcsrchr strrchr #endif /* UNICODE */ #endif /* __WINE__ */ /* allocate and initialize memeory for a new child window for the given path */ static ChildWnd* alloc_child_window(LPCTSTR path, LPITEMIDLIST pidl, HWND hwnd) { TCHAR drv[_MAX_DRIVE+1], dir[_MAX_DIR], name[_MAX_FNAME], ext[_MAX_EXT]; TCHAR dir_path[MAX_PATH]; TCHAR b1[BUFFER_LEN]; static const TCHAR sAsterics[] = {'*', '\0'}; ChildWnd* child = (ChildWnd*) heap_alloc(sizeof(ChildWnd)); Root* root = &child->root; Entry* entry; memset(child, 0, sizeof(ChildWnd)); child->left.treePane = TRUE; child->left.visible_cols = 0; child->right.treePane = FALSE; #ifndef _NO_EXTENSIONS child->right.visible_cols = COL_SIZE|COL_DATE|COL_TIME|COL_ATTRIBUTES|COL_INDEX|COL_LINKS; #else child->right.visible_cols = COL_SIZE|COL_DATE|COL_TIME|COL_ATTRIBUTES; #endif child->pos.length = sizeof(WINDOWPLACEMENT); child->pos.flags = 0; child->pos.showCmd = SW_SHOWNORMAL; child->pos.rcNormalPosition.left = CW_USEDEFAULT; child->pos.rcNormalPosition.top = CW_USEDEFAULT; child->pos.rcNormalPosition.right = CW_USEDEFAULT; child->pos.rcNormalPosition.bottom = CW_USEDEFAULT; child->focus_pane = 0; child->split_pos = DEFAULT_SPLIT_POS; child->sortOrder = SORT_NAME; child->header_wdths_ok = FALSE; if (path) { lstrcpy(child->path, path); _tsplitpath(path, drv, dir, name, ext); } lstrcpy(child->filter_pattern, sAsterics); child->filter_flags = TF_ALL; root->entry.level = 0; lstrcpy(dir_path, drv); lstrcat(dir_path, dir); entry = read_tree(root, dir_path, pidl, drv, child->sortOrder, hwnd); #ifdef _SHELL_FOLDERS if (root->entry.etype == ET_SHELL) load_string(root->entry.data.cFileName, IDS_DESKTOP); else #endif wsprintf(root->entry.data.cFileName, RS(b1,IDS_TITLEFMT), drv, root->fs); root->entry.data.dwFileAttributes = FILE_ATTRIBUTE_DIRECTORY; child->left.root = &root->entry; child->right.root = NULL; set_curdir(child, entry, 0, hwnd); return child; } /* free all memory associated with a child window */ static void free_child_window(ChildWnd* child) { free_entries(&child->root.entry); heap_free(child); } /* adjust child windows to the new frame window size */ static void resize_frame_rect(HWND hwnd, PRECT prect) { int new_top; RECT rt; if (IsWindowVisible(Globals.htoolbar)) { SendMessage(Globals.htoolbar, WM_SIZE, 0, 0); GetClientRect(Globals.htoolbar, &rt); prect->top = rt.bottom+3; prect->bottom -= rt.bottom+3; } if (IsWindowVisible(Globals.hdrivebar)) { SendMessage(Globals.hdrivebar, WM_SIZE, 0, 0); GetClientRect(Globals.hdrivebar, &rt); new_top = --prect->top + rt.bottom+3; MoveWindow(Globals.hdrivebar, 0, prect->top, rt.right, new_top, TRUE); prect->top = new_top; prect->bottom -= rt.bottom+2; } if (IsWindowVisible(Globals.hstatusbar)) { int parts[] = {300, 500}; SendMessage(Globals.hstatusbar, WM_SIZE, 0, 0); SendMessage(Globals.hstatusbar, SB_SETPARTS, 2, (LPARAM)&parts); GetClientRect(Globals.hstatusbar, &rt); prect->bottom -= rt.bottom; } MoveWindow(Globals.hmdiclient, prect->left-1,prect->top-1,prect->right+2,prect->bottom+1, TRUE); } /* set the frame window size */ static void resize_frame(HWND hwnd, int cx, int cy) { RECT rect; rect.left = 0; rect.top = 0; rect.right = cx; rect.bottom = cy; resize_frame_rect(hwnd, &rect); } /* update window layouts to the current frame window size */ static void resize_frame_client(HWND hwnd) { RECT rect; GetClientRect(hwnd, &rect); resize_frame_rect(hwnd, &rect); } static HHOOK hcbthook; static ChildWnd* newchild = NULL; /* window creation callback function used in create_child_window() */ static LRESULT CALLBACK CBTProc(int code, WPARAM wparam, LPARAM lparam) { if (code==HCBT_CREATEWND && newchild) { ChildWnd* child = newchild; newchild = NULL; child->hwnd = (HWND) wparam; SetWindowLongPtr(child->hwnd, GWLP_USERDATA, (LPARAM)child); } return CallNextHookEx(hcbthook, code, wparam, lparam); } /* create a new MDI child window */ static HWND create_child_window(ChildWnd* child) { MDICREATESTRUCT mcs; int idx; mcs.szClass = sWINEFILETREE; mcs.szTitle = (LPTSTR)child->path; mcs.hOwner = Globals.hInstance; mcs.x = child->pos.rcNormalPosition.left; mcs.y = child->pos.rcNormalPosition.top; mcs.cx = child->pos.rcNormalPosition.right-child->pos.rcNormalPosition.left; mcs.cy = child->pos.rcNormalPosition.bottom-child->pos.rcNormalPosition.top; mcs.style = 0; mcs.lParam = 0; hcbthook = SetWindowsHookEx(WH_CBT, CBTProc, 0, GetCurrentThreadId()); newchild = child; child->hwnd = (HWND) SendMessage(Globals.hmdiclient, WM_MDICREATE, 0, (LPARAM)&mcs); if (!child->hwnd) { UnhookWindowsHookEx(hcbthook); return 0; } UnhookWindowsHookEx(hcbthook); (void)ListBox_SetItemHeight(child->left.hwnd, 1, max(Globals.spaceSize.cy,IMAGE_HEIGHT+3)); (void)ListBox_SetItemHeight(child->right.hwnd, 1, max(Globals.spaceSize.cy,IMAGE_HEIGHT+3)); idx = ListBox_FindItemData(child->left.hwnd, 0, child->left.cur); (void)ListBox_SetCurSel(child->left.hwnd, idx); return child->hwnd; } #ifndef _NO_EXTENSIONS /* calculate client space for the frame window */ static void frame_get_clientspace(HWND hwnd, PRECT prect) { RECT rt; if (!IsIconic(hwnd)) GetClientRect(hwnd, prect); else { WINDOWPLACEMENT wp; GetWindowPlacement(hwnd, &wp); prect->left = prect->top = 0; prect->right = wp.rcNormalPosition.right-wp.rcNormalPosition.left- 2*(GetSystemMetrics(SM_CXSIZEFRAME)+GetSystemMetrics(SM_CXEDGE)); prect->bottom = wp.rcNormalPosition.bottom-wp.rcNormalPosition.top- 2*(GetSystemMetrics(SM_CYSIZEFRAME)+GetSystemMetrics(SM_CYEDGE))- GetSystemMetrics(SM_CYCAPTION)-GetSystemMetrics(SM_CYMENUSIZE); } if (IsWindowVisible(Globals.htoolbar)) { GetClientRect(Globals.htoolbar, &rt); prect->top += rt.bottom+2; } if (IsWindowVisible(Globals.hdrivebar)) { GetClientRect(Globals.hdrivebar, &rt); prect->top += rt.bottom+2; } if (IsWindowVisible(Globals.hstatusbar)) { GetClientRect(Globals.hstatusbar, &rt); prect->bottom -= rt.bottom; } } /* full screen mode state */ static struct FullScreenParameters { BOOL mode; RECT orgPos; BOOL wasZoomed; } g_fullscreen = { FALSE, /* mode */ {0, 0, 0, 0}, FALSE }; /* toggle full screen mode */ static BOOL toggle_fullscreen(HWND hwnd) { RECT rt; if ((g_fullscreen.mode=!g_fullscreen.mode)) { GetWindowRect(hwnd, &g_fullscreen.orgPos); g_fullscreen.wasZoomed = IsZoomed(hwnd); (void)Frame_CalcFrameClient(hwnd, &rt); ClientToScreen(hwnd, (LPPOINT)&rt.left); ClientToScreen(hwnd, (LPPOINT)&rt.right); rt.left = g_fullscreen.orgPos.left-rt.left; rt.top = g_fullscreen.orgPos.top-rt.top; rt.right = GetSystemMetrics(SM_CXSCREEN)+g_fullscreen.orgPos.right-rt.right; rt.bottom = GetSystemMetrics(SM_CYSCREEN)+g_fullscreen.orgPos.bottom-rt.bottom; MoveWindow(hwnd, rt.left, rt.top, rt.right-rt.left, rt.bottom-rt.top, TRUE); } else { MoveWindow(hwnd, g_fullscreen.orgPos.left, g_fullscreen.orgPos.top, g_fullscreen.orgPos.right-g_fullscreen.orgPos.left, g_fullscreen.orgPos.bottom-g_fullscreen.orgPos.top, TRUE); if (g_fullscreen.wasZoomed) ShowWindow(hwnd, WS_MAXIMIZE); } return g_fullscreen.mode; } /* adjust window coordinates in full screen mode */ static void fullscreen_move(HWND hwnd) { RECT rt, pos; GetWindowRect(hwnd, &pos); (void)Frame_CalcFrameClient(hwnd, &rt); ClientToScreen(hwnd, (LPPOINT)&rt.left); ClientToScreen(hwnd, (LPPOINT)&rt.right); rt.left = pos.left-rt.left; rt.top = pos.top-rt.top; rt.right = GetSystemMetrics(SM_CXSCREEN)+pos.right-rt.right; rt.bottom = GetSystemMetrics(SM_CYSCREEN)+pos.bottom-rt.bottom; MoveWindow(hwnd, rt.left, rt.top, rt.right-rt.left, rt.bottom-rt.top, TRUE); } #endif /* toggle the visibility of a child window */ static void toggle_child(HWND hwnd, UINT cmd, HWND hchild) { BOOL vis = IsWindowVisible(hchild); CheckMenuItem(Globals.hMenuOptions, cmd, vis?MF_BYCOMMAND:MF_BYCOMMAND|MF_CHECKED); ShowWindow(hchild, vis?SW_HIDE:SW_SHOW); #ifndef _NO_EXTENSIONS if (g_fullscreen.mode) fullscreen_move(hwnd); #endif resize_frame_client(hwnd); } /* activate a drive child window */ static BOOL activate_drive_window(LPCTSTR path) { TCHAR drv1[_MAX_DRIVE], drv2[_MAX_DRIVE]; HWND child_wnd; _tsplitpath(path, drv1, 0, 0, 0); /* search for a already open window for the same drive */ for(child_wnd=GetNextWindow(Globals.hmdiclient,GW_CHILD); child_wnd; child_wnd=GetNextWindow(child_wnd, GW_HWNDNEXT)) { ChildWnd* child = (ChildWnd*) GetWindowLongPtr(child_wnd, GWLP_USERDATA); if (child) { _tsplitpath(child->root.path, drv2, 0, 0, 0); if (!lstrcmpi(drv2, drv1)) { SendMessage(Globals.hmdiclient, WM_MDIACTIVATE, (WPARAM)child_wnd, 0); if (IsMinimized(child_wnd)) ShowWindow(child_wnd, SW_SHOWNORMAL); return TRUE; } } } return FALSE; } /* activate window containing a file system tree */ static BOOL activate_fs_window(LPCTSTR filesys) { HWND child_wnd; /* search for a already open window of the given file system name */ for(child_wnd=GetNextWindow(Globals.hmdiclient,GW_CHILD); child_wnd; child_wnd=GetNextWindow(child_wnd, GW_HWNDNEXT)) { ChildWnd* child = (ChildWnd*) GetWindowLongPtr(child_wnd, GWLP_USERDATA); if (child) { if (!lstrcmpi(child->root.fs, filesys)) { SendMessage(Globals.hmdiclient, WM_MDIACTIVATE, (WPARAM)child_wnd, 0); if (IsMinimized(child_wnd)) ShowWindow(child_wnd, SW_SHOWNORMAL); return TRUE; } } } return FALSE; } /* frame window message handler */ static LRESULT CALLBACK FrameWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam) { TCHAR b1[BUFFER_LEN], b2[BUFFER_LEN]; switch(nmsg) { case WM_CLOSE: if (Globals.saveSettings) save_registry_settings(); DestroyWindow(hwnd); /* clear handle variables */ Globals.hMenuFrame = 0; Globals.hMenuView = 0; Globals.hMenuOptions = 0; Globals.hMainWnd = 0; Globals.hmdiclient = 0; Globals.hdrivebar = 0; break; case WM_DESTROY: PostQuitMessage(0); break; case WM_INITMENUPOPUP: { HWND hwndClient = (HWND) SendMessage(Globals.hmdiclient, WM_MDIGETACTIVE, 0, 0); if (!SendMessage(hwndClient, WM_INITMENUPOPUP, wparam, lparam)) return 0; break;} case WM_COMMAND: { UINT cmd = LOWORD(wparam); HWND hwndClient = (HWND) SendMessage(Globals.hmdiclient, WM_MDIGETACTIVE, 0, 0); if (SendMessage(hwndClient, WM_DISPATCH_COMMAND, wparam, lparam)) break; if (cmd>=ID_DRIVE_FIRST && cmd<=ID_DRIVE_FIRST+0xFF) { TCHAR drv[_MAX_DRIVE], path[MAX_PATH]; ChildWnd* child; LPCTSTR root = Globals.drives; int i; for(i=cmd-ID_DRIVE_FIRST; i--; root++) while(*root) root++; if (activate_drive_window(root)) return 0; _tsplitpath(root, drv, 0, 0, 0); if (!SetCurrentDirectory(drv)) { display_error(hwnd, GetLastError()); return 0; } GetCurrentDirectory(MAX_PATH, path); /*TODO: store last directory per drive */ child = alloc_child_window(path, NULL, hwnd); if (!create_child_window(child)) heap_free(child); } else switch(cmd) { case ID_FILE_EXIT: SendMessage(hwnd, WM_CLOSE, 0, 0); break; case ID_WINDOW_NEW: { TCHAR path[MAX_PATH]; ChildWnd* child; GetCurrentDirectory(MAX_PATH, path); child = alloc_child_window(path, NULL, hwnd); if (!create_child_window(child)) heap_free(child); break;} case ID_REFRESH: refresh_drives(); break; case ID_WINDOW_CASCADE: SendMessage(Globals.hmdiclient, WM_MDICASCADE, 0, 0); break; case ID_WINDOW_TILE_HORZ: SendMessage(Globals.hmdiclient, WM_MDITILE, MDITILE_HORIZONTAL, 0); break; case ID_WINDOW_TILE_VERT: SendMessage(Globals.hmdiclient, WM_MDITILE, MDITILE_VERTICAL, 0); break; case ID_WINDOW_ARRANGE: SendMessage(Globals.hmdiclient, WM_MDIICONARRANGE, 0, 0); break; case ID_SELECT_FONT: choose_font(hwnd); break; case ID_VIEW_TOOL_BAR: toggle_child(hwnd, cmd, Globals.htoolbar); break; case ID_VIEW_DRIVE_BAR: toggle_child(hwnd, cmd, Globals.hdrivebar); break; case ID_VIEW_STATUSBAR: toggle_child(hwnd, cmd, Globals.hstatusbar); break; case ID_VIEW_SAVESETTINGS: Globals.saveSettings = !Globals.saveSettings; CheckMenuItem(Globals.hMenuOptions, ID_VIEW_SAVESETTINGS, Globals.saveSettings ? MF_CHECKED : MF_UNCHECKED); break; case ID_EXECUTE: { struct ExecuteDialog dlg; memset(&dlg, 0, sizeof(struct ExecuteDialog)); if (DialogBoxParam(Globals.hInstance, MAKEINTRESOURCE(IDD_EXECUTE), hwnd, ExecuteDialogDlgProc, (LPARAM)&dlg) == IDOK) { HINSTANCE hinst = ShellExecute(hwnd, NULL/*operation*/, dlg.cmd/*file*/, NULL/*parameters*/, NULL/*dir*/, dlg.cmdshow); if (PtrToUlong(hinst) <= 32) display_error(hwnd, GetLastError()); } break;} case ID_CONNECT_NETWORK_DRIVE: { DWORD ret = WNetConnectionDialog(hwnd, RESOURCETYPE_DISK); if (ret == NO_ERROR) refresh_drives(); else if (ret != (DWORD)-1) { if (ret == ERROR_EXTENDED_ERROR) display_network_error(hwnd); else display_error(hwnd, ret); } break;} case ID_DISCONNECT_NETWORK_DRIVE: { DWORD ret = WNetDisconnectDialog(hwnd, RESOURCETYPE_DISK); if (ret == NO_ERROR) refresh_drives(); else if (ret != (DWORD)-1) { if (ret == ERROR_EXTENDED_ERROR) display_network_error(hwnd); else display_error(hwnd, ret); } break;} case ID_FORMAT_DISK: { UINT sem_org = SetErrorMode(0); /* Get the current Error Mode settings. */ SetErrorMode(sem_org & ~SEM_FAILCRITICALERRORS); /* Force O/S to handle */ SHFormatDrive(hwnd, 0 /* A: */, SHFMT_ID_DEFAULT, 0); SetErrorMode(sem_org); /* Put it back the way it was. */ break;} case ID_HELP: WinHelp(hwnd, RS(b1,IDS_WINEFILE), HELP_INDEX, 0); break; #ifndef _NO_EXTENSIONS case ID_VIEW_FULLSCREEN: CheckMenuItem(Globals.hMenuOptions, cmd, toggle_fullscreen(hwnd)?MF_CHECKED:0); break; #ifdef __WINE__ case ID_DRIVE_UNIX_FS: { TCHAR path[MAX_PATH]; #ifdef UNICODE char cpath[MAX_PATH]; #endif ChildWnd* child; if (activate_fs_window(RS(b1,IDS_UNIXFS))) break; #ifdef UNICODE getcwd(cpath, MAX_PATH); MultiByteToWideChar(CP_UNIXCP, 0, cpath, -1, path, MAX_PATH); #else getcwd(path, MAX_PATH); #endif child = alloc_child_window(path, NULL, hwnd); if (!create_child_window(child)) heap_free(child); break;} #endif #ifdef _SHELL_FOLDERS case ID_DRIVE_SHELL_NS: { TCHAR path[MAX_PATH]; ChildWnd* child; if (activate_fs_window(RS(b1,IDS_SHELL))) break; GetCurrentDirectory(MAX_PATH, path); child = alloc_child_window(path, get_path_pidl(path,hwnd), hwnd); if (!create_child_window(child)) heap_free(child); break;} #endif #endif /*TODO: There are even more menu items! */ case ID_ABOUT: ShellAbout(hwnd, RS(b1,IDS_WINEFILE), NULL, LoadImage(Globals.hInstance, MAKEINTRESOURCE(IDI_WINEFILE), IMAGE_ICON, 48, 48, LR_SHARED)); break; default: /*TODO: if (wParam >= PM_FIRST_LANGUAGE && wParam <= PM_LAST_LANGUAGE) STRING_SelectLanguageByNumber(wParam - PM_FIRST_LANGUAGE); else */if ((cmd=IDW_FIRST_CHILD+0x100) && (cmdSC_RESTORE)) MessageBox(hwnd, RS(b2,IDS_NO_IMPL), RS(b1,IDS_WINEFILE), MB_OK); return DefFrameProc(hwnd, Globals.hmdiclient, nmsg, wparam, lparam); } break;} case WM_SIZE: resize_frame(hwnd, LOWORD(lparam), HIWORD(lparam)); break; /* do not pass message to DefFrameProc */ case WM_DEVICECHANGE: SendMessage(hwnd, WM_COMMAND, MAKELONG(ID_REFRESH,0), 0); break; #ifndef _NO_EXTENSIONS case WM_GETMINMAXINFO: { LPMINMAXINFO lpmmi = (LPMINMAXINFO)lparam; lpmmi->ptMaxTrackSize.x <<= 1;/*2*GetSystemMetrics(SM_CXSCREEN) / SM_CXVIRTUALSCREEN */ lpmmi->ptMaxTrackSize.y <<= 1;/*2*GetSystemMetrics(SM_CYSCREEN) / SM_CYVIRTUALSCREEN */ break;} case FRM_CALC_CLIENT: frame_get_clientspace(hwnd, (PRECT)lparam); return TRUE; #endif /* _NO_EXTENSIONS */ default: return DefFrameProc(hwnd, Globals.hmdiclient, nmsg, wparam, lparam); } return 0; } /* array of item attribute names, filled from ressource strings */ static TCHAR g_pos_names[COLUMNS][20] = { {'\0'} /* symbol */ }; /* array of item attribute flags */ static const int g_pos_align[] = { 0, HDF_LEFT, /* Name */ HDF_RIGHT, /* Size */ HDF_LEFT, /* CDate */ #ifndef _NO_EXTENSIONS HDF_LEFT, /* ADate */ HDF_LEFT, /* MDate */ HDF_LEFT, /* Index */ HDF_CENTER, /* Links */ #endif HDF_CENTER, /* Attributes */ #ifndef _NO_EXTENSIONS HDF_LEFT /* Security */ #endif }; /* resize child window descendants */ static void resize_tree(ChildWnd* child, int cx, int cy) { HDWP hdwp = BeginDeferWindowPos(4); RECT rt; rt.left = 0; rt.top = 0; rt.right = cx; rt.bottom = cy; cx = child->split_pos + SPLIT_WIDTH/2; #ifndef _NO_EXTENSIONS { WINDOWPOS wp; HD_LAYOUT hdl; hdl.prc = &rt; hdl.pwpos = ℘ (void)Header_Layout(child->left.hwndHeader, &hdl); DeferWindowPos(hdwp, child->left.hwndHeader, wp.hwndInsertAfter, wp.x-1, wp.y, child->split_pos-SPLIT_WIDTH/2+1, wp.cy, wp.flags); DeferWindowPos(hdwp, child->right.hwndHeader, wp.hwndInsertAfter, rt.left+cx+1, wp.y, wp.cx-cx+2, wp.cy, wp.flags); } #endif /* _NO_EXTENSIONS */ DeferWindowPos(hdwp, child->left.hwnd, 0, rt.left, rt.top, child->split_pos-SPLIT_WIDTH/2-rt.left, rt.bottom-rt.top, SWP_NOZORDER|SWP_NOACTIVATE); DeferWindowPos(hdwp, child->right.hwnd, 0, rt.left+cx+1, rt.top, rt.right-cx, rt.bottom-rt.top, SWP_NOZORDER|SWP_NOACTIVATE); EndDeferWindowPos(hdwp); } #ifndef _NO_EXTENSIONS /* create the header control for the given pane */ static HWND create_header(HWND parent, Pane* pane, UINT id) { HD_ITEM hdi; int idx; HWND hwnd = CreateWindow(WC_HEADER, 0, WS_CHILD|WS_VISIBLE|HDS_HORZ|HDS_FULLDRAG/*TODO: |HDS_BUTTONS + sort orders*/, 0, 0, 0, 0, parent, (HMENU)ULongToHandle(id), Globals.hInstance, 0); if (!hwnd) return 0; SetWindowFont(hwnd, GetStockObject(DEFAULT_GUI_FONT), FALSE); hdi.mask = HDI_TEXT|HDI_WIDTH|HDI_FORMAT; for(idx=0; idxwidths[idx]; (void)Header_InsertItem(hwnd, idx, &hdi); } return hwnd; } #endif /* _NO_EXTENSIONS */ /* initialise global variables for text output */ static void init_output(HWND hwnd) { static const TCHAR s1000[] = {'1','0','0','0','\0'}; TCHAR b[16]; HFONT old_font; HDC hdc = GetDC(hwnd); if (GetNumberFormat(LOCALE_USER_DEFAULT, 0, s1000, 0, b, 16) > 4) Globals.num_sep = b[1]; else Globals.num_sep = '.'; old_font = SelectFont(hdc, Globals.hfont); GetTextExtentPoint32(hdc, sSpace, 1, &Globals.spaceSize); (void)SelectFont(hdc, old_font); ReleaseDC(hwnd, hdc); } static void draw_item(Pane* pane, LPDRAWITEMSTRUCT dis, Entry* entry, int calcWidthCol); /* calculate preferred width for all visible columns */ static BOOL calc_widths(Pane* pane, BOOL anyway) { int col, x, cx, spc=3*Globals.spaceSize.cx; int entries = ListBox_GetCount(pane->hwnd); int orgWidths[COLUMNS]; int orgPositions[COLUMNS+1]; HFONT hfontOld; HDC hdc; int cnt; if (!anyway) { memcpy(orgWidths, pane->widths, sizeof(orgWidths)); memcpy(orgPositions, pane->positions, sizeof(orgPositions)); } for(col=0; colwidths[col] = 0; hdc = GetDC(pane->hwnd); hfontOld = SelectFont(hdc, Globals.hfont); for(cnt=0; cnthwnd, cnt); DRAWITEMSTRUCT dis; dis.CtlType = 0; dis.CtlID = 0; dis.itemID = 0; dis.itemAction = 0; dis.itemState = 0; dis.hwndItem = pane->hwnd; dis.hDC = hdc; dis.rcItem.left = 0; dis.rcItem.top = 0; dis.rcItem.right = 0; dis.rcItem.bottom = 0; /*dis.itemData = 0; */ draw_item(pane, &dis, entry, COLUMNS); } SelectObject(hdc, hfontOld); ReleaseDC(pane->hwnd, hdc); x = 0; for(col=0; colpositions[col] = x; cx = pane->widths[col]; if (cx) { cx += spc; if (cx < IMAGE_WIDTH) cx = IMAGE_WIDTH; pane->widths[col] = cx; } x += cx; } pane->positions[COLUMNS] = x; ListBox_SetHorizontalExtent(pane->hwnd, x); /* no change? */ if (!memcmp(orgWidths, pane->widths, sizeof(orgWidths))) return FALSE; /* don't move, if only collapsing an entry */ if (!anyway && pane->widths[0]widths+1, sizeof(orgWidths)-sizeof(int))) { pane->widths[0] = orgWidths[0]; memcpy(pane->positions, orgPositions, sizeof(orgPositions)); return FALSE; } InvalidateRect(pane->hwnd, 0, TRUE); return TRUE; } /* calculate one preferred column width */ static void calc_single_width(Pane* pane, int col) { HFONT hfontOld; int x, cx; int entries = ListBox_GetCount(pane->hwnd); int cnt; HDC hdc; pane->widths[col] = 0; hdc = GetDC(pane->hwnd); hfontOld = SelectFont(hdc, Globals.hfont); for(cnt=0; cnthwnd, cnt); DRAWITEMSTRUCT dis; dis.CtlType = 0; dis.CtlID = 0; dis.itemID = 0; dis.itemAction = 0; dis.itemState = 0; dis.hwndItem = pane->hwnd; dis.hDC = hdc; dis.rcItem.left = 0; dis.rcItem.top = 0; dis.rcItem.right = 0; dis.rcItem.bottom = 0; /*dis.itemData = 0; */ draw_item(pane, &dis, entry, col); } SelectObject(hdc, hfontOld); ReleaseDC(pane->hwnd, hdc); cx = pane->widths[col]; if (cx) { cx += 3*Globals.spaceSize.cx; if (cx < IMAGE_WIDTH) cx = IMAGE_WIDTH; } pane->widths[col] = cx; x = pane->positions[col] + cx; for(; colpositions[++col] = x; x += pane->widths[col]; } ListBox_SetHorizontalExtent(pane->hwnd, x); } /* check for file name matches, taking case into account */ static BOOL pattern_match(LPCTSTR str, LPCTSTR pattern) { for( ; *str&&*pattern; str++,pattern++) { if (*pattern == '*') { do pattern++; while(*pattern == '*'); if (!*pattern) return TRUE; for(; *str; str++) if (*str==*pattern && pattern_match(str, pattern)) return TRUE; return FALSE; } else if (*str!=*pattern && *pattern!='?') return FALSE; } if (*str || *pattern) if (*pattern!='*' || pattern[1]!='\0') return FALSE; return TRUE; } /* case independent file name matching algorithm */ static BOOL pattern_imatch(LPCTSTR str, LPCTSTR pattern) { TCHAR b1[BUFFER_LEN], b2[BUFFER_LEN]; lstrcpy(b1, str); lstrcpy(b2, pattern); CharUpper(b1); CharUpper(b2); return pattern_match(b1, b2); } /* file type constants */ enum FILE_TYPE { FT_OTHER = 0, FT_EXECUTABLE = 1, FT_DOCUMENT = 2 }; static enum FILE_TYPE get_file_type(LPCTSTR filename); /* insert listbox entries after index idx */ static int insert_entries(Pane* pane, Entry* dir, LPCTSTR pattern, int filter_flags, int idx) { Entry* entry = dir; if (!entry) return idx; ShowWindow(pane->hwnd, SW_HIDE); for(; entry; entry=entry->next) { #ifndef _LEFT_FILES if (pane->treePane && !(entry->data.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY)) continue; #endif if (entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { /* don't display entries "." and ".." in the left pane */ if (pane->treePane && entry->data.cFileName[0]=='.') if ( #ifndef _NO_EXTENSIONS entry->data.cFileName[1]=='\0' || #endif (entry->data.cFileName[1]=='.' && entry->data.cFileName[2]=='\0')) continue; /* filter directories in right pane */ if (!pane->treePane && !(filter_flags&TF_DIRECTORIES)) continue; } /* filter using the file name pattern */ if (pattern) if (!pattern_imatch(entry->data.cFileName, pattern)) continue; /* filter system and hidden files */ if (!(filter_flags&TF_HIDDEN) && (entry->data.dwFileAttributes&(FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM))) continue; /* filter looking at the file type */ if ((filter_flags&(TF_PROGRAMS|TF_DOCUMENTS|TF_OTHERS)) != (TF_PROGRAMS|TF_DOCUMENTS|TF_OTHERS)) switch(get_file_type(entry->data.cFileName)) { case FT_EXECUTABLE: if (!(filter_flags & TF_PROGRAMS)) continue; break; case FT_DOCUMENT: if (!(filter_flags & TF_DOCUMENTS)) continue; break; default: /* TF_OTHERS */ if (!(filter_flags & TF_OTHERS)) continue; } if (idx != -1) idx++; (void)ListBox_InsertItemData(pane->hwnd, idx, entry); if (pane->treePane && entry->expanded) idx = insert_entries(pane, entry->down, pattern, filter_flags, idx); } ShowWindow(pane->hwnd, SW_SHOW); return idx; } /* print a file size as textual representation into the given character buffer */ static void format_bytes(LPTSTR buffer, LONGLONG bytes) { static const TCHAR sFmtGB[] = {'%', '.', '1', 'f', ' ', 'G', 'B', '\0'}; static const TCHAR sFmtMB[] = {'%', '.', '1', 'f', ' ', 'M', 'B', '\0'}; static const TCHAR sFmtkB[] = {'%', '.', '1', 'f', ' ', 'k', 'B', '\0'}; float fBytes = (float)bytes; if (bytes >= 1073741824) /* 1 GB */ _stprintf(buffer, sFmtGB, fBytes/1073741824.f+.5f); else if (bytes >= 1048576) /* 1 MB */ _stprintf(buffer, sFmtMB, fBytes/1048576.f+.5f); else if (bytes >= 1024) /* 1 kB */ _stprintf(buffer, sFmtkB, fBytes/1024.f+.5f); else _stprintf(buffer, sLongNumFmt, bytes); } /* display free space of the current drive in the status bar */ static void set_space_status(void) { ULARGE_INTEGER ulFreeBytesToCaller, ulTotalBytes, ulFreeBytes; TCHAR fmt[64], b1[64], b2[64], buffer[BUFFER_LEN]; if (GetDiskFreeSpaceEx(NULL, &ulFreeBytesToCaller, &ulTotalBytes, &ulFreeBytes)) { format_bytes(b1, ulFreeBytesToCaller.QuadPart); format_bytes(b2, ulTotalBytes.QuadPart); wsprintf(buffer, RS(fmt,IDS_FREE_SPACE_FMT), b1, b2); } else lstrcpy(buffer, sQMarks); SendMessage(Globals.hstatusbar, SB_SETTEXT, 0, (LPARAM)buffer); } #ifndef _NO_EXTENSIONS /* initialise the header control for a Winefile pane */ static void set_header(Pane* pane) { HD_ITEM item; int scroll_pos = GetScrollPos(pane->hwnd, SB_HORZ); int i=0, x=0; item.mask = HDI_WIDTH; item.cxy = 0; for(; x+pane->widths[i]widths[i]; (void)Header_SetItem(pane->hwndHeader, i, &item); } if (i < COLUMNS) { x += pane->widths[i]; item.cxy = x - scroll_pos; (void)Header_SetItem(pane->hwndHeader, i++, &item); for(; iwidths[i]; x += pane->widths[i]; (void)Header_SetItem(pane->hwndHeader, i, &item); } } } /* handle WM_NOTIFY messages for Winefile panes */ static LRESULT pane_notify(Pane* pane, NMHDR* pnmh) { switch(pnmh->code) { case HDN_ITEMCHANGED: { HD_NOTIFY* phdn = (HD_NOTIFY*) pnmh; int idx = phdn->iItem; int dx = phdn->pitem->cxy - pane->widths[idx]; int i; RECT clnt; GetClientRect(pane->hwnd, &clnt); pane->widths[idx] += dx; for(i=idx; ++i<=COLUMNS; ) pane->positions[i] += dx; { int scroll_pos = GetScrollPos(pane->hwnd, SB_HORZ); RECT rt_scr; RECT rt_clip; rt_scr.left = pane->positions[idx+1]-scroll_pos; rt_scr.top = 0; rt_scr.right = clnt.right; rt_scr.bottom = clnt.bottom; rt_clip.left = pane->positions[idx]-scroll_pos; rt_clip.top = 0; rt_clip.right = clnt.right; rt_clip.bottom = clnt.bottom; if (rt_scr.left < 0) rt_scr.left = 0; if (rt_clip.left < 0) rt_clip.left = 0; ScrollWindowEx(pane->hwnd, dx, 0, &rt_scr, &rt_clip, 0, 0, SW_INVALIDATE); rt_clip.right = pane->positions[idx+1]; RedrawWindow(pane->hwnd, &rt_clip, 0, RDW_INVALIDATE|RDW_UPDATENOW); if (pnmh->code == HDN_ENDTRACK) { ListBox_SetHorizontalExtent(pane->hwnd, pane->positions[COLUMNS]); if (GetScrollPos(pane->hwnd, SB_HORZ) != scroll_pos) set_header(pane); } } return FALSE; } case HDN_DIVIDERDBLCLICK: { HD_NOTIFY* phdn = (HD_NOTIFY*) pnmh; HD_ITEM item; calc_single_width(pane, phdn->iItem); item.mask = HDI_WIDTH; item.cxy = pane->widths[phdn->iItem]; (void)Header_SetItem(pane->hwndHeader, phdn->iItem, &item); InvalidateRect(pane->hwnd, 0, TRUE); break;} } return 0; } #endif /* _NO_EXTENSIONS */ /* original tree window message handler */ static WNDPROC g_orgTreeWndProc; /* tree window message handler */ static LRESULT CALLBACK TreeWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam) { ChildWnd* child = (ChildWnd*) GetWindowLongPtr(GetParent(hwnd), GWLP_USERDATA); Pane* pane = (Pane*) GetWindowLongPtr(hwnd, GWLP_USERDATA); ASSERT(child); switch(nmsg) { #ifndef _NO_EXTENSIONS case WM_HSCROLL: set_header(pane); break; #endif case WM_SETFOCUS: child->focus_pane = pane==&child->right? 1: 0; (void)ListBox_SetSel(hwnd, TRUE, 1); /*TODO: check menu items */ break; case WM_KEYDOWN: if (wparam == VK_TAB) { /*TODO: SetFocus(Globals.hdrivebar) */ SetFocus(child->focus_pane? child->left.hwnd: child->right.hwnd); } } return CallWindowProc(g_orgTreeWndProc, hwnd, nmsg, wparam, lparam); } /* create a new tree window to be used as Winefile pane */ static void create_tree_window(HWND parent, Pane* pane, UINT id, UINT id_header, LPCTSTR pattern, int filter_flags) { static const TCHAR sListBox[] = {'L','i','s','t','B','o','x','\0'}; static int s_init = 0; Entry* entry = pane->root; pane->hwnd = CreateWindow(sListBox, sEmpty, WS_CHILD|WS_VISIBLE|WS_HSCROLL|WS_VSCROLL| LBS_DISABLENOSCROLL|LBS_NOINTEGRALHEIGHT|LBS_OWNERDRAWFIXED|LBS_NOTIFY, 0, 0, 0, 0, parent, (HMENU)ULongToHandle(id), Globals.hInstance, 0); SetWindowLongPtr(pane->hwnd, GWLP_USERDATA, (LPARAM)pane); g_orgTreeWndProc = SubclassWindow(pane->hwnd, TreeWndProc); SetWindowFont(pane->hwnd, Globals.hfont, FALSE); /* insert entries into listbox */ if (entry) insert_entries(pane, entry, pattern, filter_flags, -1); /* calculate column widths */ if (!s_init) { s_init = 1; init_output(pane->hwnd); } calc_widths(pane, TRUE); #ifndef _NO_EXTENSIONS pane->hwndHeader = create_header(parent, pane, id_header); #endif } /* initialise child window data */ static void InitChildWindow(ChildWnd* child) { create_tree_window(child->hwnd, &child->left, IDW_TREE_LEFT, IDW_HEADER_LEFT, NULL, TF_ALL); create_tree_window(child->hwnd, &child->right, IDW_TREE_RIGHT, IDW_HEADER_RIGHT, child->filter_pattern, child->filter_flags); } /* print a FILETIME as textual representation */ void format_date(const FILETIME* ft, TCHAR* buffer, int visible_cols) { SYSTEMTIME systime; FILETIME lft; int len = 0; *buffer = '\0'; if (!ft->dwLowDateTime && !ft->dwHighDateTime) return; if (!FileTimeToLocalFileTime(ft, &lft)) {err: lstrcpy(buffer,sQMarks); return;} if (!FileTimeToSystemTime(&lft, &systime)) goto err; if (visible_cols & COL_DATE) { len = GetDateFormat(LOCALE_USER_DEFAULT, 0, &systime, 0, buffer, BUFFER_LEN); if (!len) goto err; } if (visible_cols & COL_TIME) { if (len) buffer[len-1] = ' '; buffer[len++] = ' '; if (!GetTimeFormat(LOCALE_USER_DEFAULT, 0, &systime, 0, buffer+len, BUFFER_LEN-len)) buffer[len] = '\0'; } } /* accumulate the maximum pane width for the given text */ static void calc_width(Pane* pane, LPDRAWITEMSTRUCT dis, int col, LPCTSTR str) { RECT rt = {0, 0, 0, 0}; DrawText(dis->hDC, (LPTSTR)str, -1, &rt, DT_CALCRECT|DT_SINGLELINE|DT_NOPREFIX); if (rt.right > pane->widths[col]) pane->widths[col] = rt.right; } /* accumulate the maximum oane width for the given text, taking tabs into account */ static void calc_tabbed_width(Pane* pane, LPDRAWITEMSTRUCT dis, int col, LPCTSTR str) { RECT rt = {0, 0, 0, 0}; /* DRAWTEXTPARAMS dtp = {sizeof(DRAWTEXTPARAMS), 2}; DrawTextEx(dis->hDC, (LPTSTR)str, -1, &rt, DT_CALCRECT|DT_SINGLELINE|DT_NOPREFIX|DT_EXPANDTABS|DT_TABSTOP, &dtp);*/ DrawText(dis->hDC, (LPTSTR)str, -1, &rt, DT_CALCRECT|DT_SINGLELINE|DT_EXPANDTABS|DT_TABSTOP|(2<<8)); /*FIXME rt (0,0) ??? */ if (rt.right > pane->widths[col]) pane->widths[col] = rt.right; } /* display text in a Winefile pane */ static void output_text(Pane* pane, LPDRAWITEMSTRUCT dis, int col, LPCTSTR str, DWORD flags) { int x = dis->rcItem.left; RECT rt; rt.left = x+pane->positions[col]+Globals.spaceSize.cx; rt.top = dis->rcItem.top; rt.right = x+pane->positions[col+1]-Globals.spaceSize.cx; rt.bottom = dis->rcItem.bottom; DrawText(dis->hDC, (LPTSTR)str, -1, &rt, DT_SINGLELINE|DT_NOPREFIX|flags); } /* display text in a Winefile pane, formated by tabulator characters */ static void output_tabbed_text(Pane* pane, LPDRAWITEMSTRUCT dis, int col, LPCTSTR str) { int x = dis->rcItem.left; RECT rt; rt.left = x+pane->positions[col]+Globals.spaceSize.cx; rt.top = dis->rcItem.top; rt.right = x+pane->positions[col+1]-Globals.spaceSize.cx; rt.bottom = dis->rcItem.bottom; /* DRAWTEXTPARAMS dtp = {sizeof(DRAWTEXTPARAMS), 2}; DrawTextEx(dis->hDC, (LPTSTR)str, -1, &rt, DT_SINGLELINE|DT_NOPREFIX|DT_EXPANDTABS|DT_TABSTOP, &dtp);*/ DrawText(dis->hDC, (LPTSTR)str, -1, &rt, DT_SINGLELINE|DT_EXPANDTABS|DT_TABSTOP|(2<<8)); } /* display numbers in a Winefile pane */ static void output_number(Pane* pane, LPDRAWITEMSTRUCT dis, int col, LPCTSTR str) { int x = dis->rcItem.left; RECT rt; LPCTSTR s = str; TCHAR b[128]; LPTSTR d = b; int pos; rt.left = x+pane->positions[col]+Globals.spaceSize.cx; rt.top = dis->rcItem.top; rt.right = x+pane->positions[col+1]-Globals.spaceSize.cx; rt.bottom = dis->rcItem.bottom; if (*s) *d++ = *s++; /* insert number separator characters */ pos = lstrlen(s) % 3; while(*s) if (pos--) *d++ = *s++; else { *d++ = Globals.num_sep; pos = 3; } DrawText(dis->hDC, b, d-b, &rt, DT_RIGHT|DT_SINGLELINE|DT_NOPREFIX|DT_END_ELLIPSIS); } /* check for executable filename extensions */ static BOOL is_exe_file(LPCTSTR ext) { static const TCHAR executable_extensions[][4] = { {'C','O','M','\0'}, {'E','X','E','\0'}, {'B','A','T','\0'}, {'C','M','D','\0'}, #ifndef _NO_EXTENSIONS {'C','M','M','\0'}, {'B','T','M','\0'}, {'A','W','K','\0'}, #endif /* _NO_EXTENSIONS */ {'\0'} }; TCHAR ext_buffer[_MAX_EXT]; const TCHAR (*p)[4]; LPCTSTR s; LPTSTR d; for(s=ext+1,d=ext_buffer; (*d=tolower(*s)); s++) d++; for(p=executable_extensions; (*p)[0]; p++) if (!lstrcmpi(ext_buffer, *p)) return TRUE; return FALSE; } /* check is the given file name extension is present in the Registry */ static BOOL is_registered_type(LPCTSTR ext) { /* check if there exists a classname for this file extension in the registry */ if (!RegQueryValue(HKEY_CLASSES_ROOT, ext, NULL, NULL)) return TRUE; return FALSE; } /* determine file type from filename */ static enum FILE_TYPE get_file_type(LPCTSTR filename) { LPCTSTR ext = _tcsrchr(filename, '.'); if (!ext) ext = sEmpty; if (is_exe_file(ext)) return FT_EXECUTABLE; else if (is_registered_type(ext)) return FT_DOCUMENT; else return FT_OTHER; } /* display a entry in a Winefile pane */ //@@ TODO refactor into smaller functions static void draw_item(Pane* pane, LPDRAWITEMSTRUCT dis, Entry* entry, int calcWidthCol) { TCHAR buffer[BUFFER_LEN]; DWORD attrs; int visible_cols = pane->visible_cols; COLORREF bkcolor, textcolor; RECT focusRect = dis->rcItem; HBRUSH hbrush; enum IMAGE img; int img_pos, cx; int col = 0; if (entry) { attrs = entry->data.dwFileAttributes; if (attrs & FILE_ATTRIBUTE_DIRECTORY) { if (entry->data.cFileName[0]=='.' && entry->data.cFileName[1]=='.' && entry->data.cFileName[2]=='\0') img = IMG_FOLDER_UP; #ifndef _NO_EXTENSIONS else if (entry->data.cFileName[0]=='.' && entry->data.cFileName[1]=='\0') img = IMG_FOLDER_CUR; #endif else if ( #ifdef _NO_EXTENSIONS entry->expanded || #endif (pane->treePane && (dis->itemState&ODS_FOCUS))) img = IMG_OPEN_FOLDER; else img = IMG_FOLDER; } else { switch(get_file_type(entry->data.cFileName)) { case FT_EXECUTABLE: img = IMG_EXECUTABLE; break; case FT_DOCUMENT: img = IMG_DOCUMENT; break; default: img = IMG_FILE; } } } else { attrs = 0; img = IMG_NONE; } if (pane->treePane) { if (entry) { img_pos = dis->rcItem.left + entry->level*(IMAGE_WIDTH+TREE_LINE_DX); if (calcWidthCol == -1) { int x; int y = dis->rcItem.top + IMAGE_HEIGHT/2; Entry* up; RECT rt_clip; HRGN hrgn_org = CreateRectRgn(0, 0, 0, 0); HRGN hrgn; rt_clip.left = dis->rcItem.left; rt_clip.top = dis->rcItem.top; rt_clip.right = dis->rcItem.left+pane->widths[col]; rt_clip.bottom = dis->rcItem.bottom; hrgn = CreateRectRgnIndirect(&rt_clip); if (!GetClipRgn(dis->hDC, hrgn_org)) { DeleteObject(hrgn_org); hrgn_org = 0; } /* HGDIOBJ holdPen = SelectObject(dis->hDC, GetStockObject(BLACK_PEN)); */ ExtSelectClipRgn(dis->hDC, hrgn, RGN_AND); DeleteObject(hrgn); if ((up=entry->up) != NULL) { MoveToEx(dis->hDC, img_pos-IMAGE_WIDTH/2, y, 0); LineTo(dis->hDC, img_pos-2, y); x = img_pos - IMAGE_WIDTH/2; do { x -= IMAGE_WIDTH+TREE_LINE_DX; if (up->next #ifndef _LEFT_FILES && (up->next->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) #endif ) { MoveToEx(dis->hDC, x, dis->rcItem.top, 0); LineTo(dis->hDC, x, dis->rcItem.bottom); } } while((up=up->up) != NULL); } x = img_pos - IMAGE_WIDTH/2; MoveToEx(dis->hDC, x, dis->rcItem.top, 0); LineTo(dis->hDC, x, y); if (entry->next #ifndef _LEFT_FILES && (entry->next->data.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY) #endif ) LineTo(dis->hDC, x, dis->rcItem.bottom); SelectClipRgn(dis->hDC, hrgn_org); if (hrgn_org) DeleteObject(hrgn_org); /* SelectObject(dis->hDC, holdPen); */ } else if (calcWidthCol==col || calcWidthCol==COLUMNS) { int right = img_pos + IMAGE_WIDTH - TREE_LINE_DX; if (right > pane->widths[col]) pane->widths[col] = right; } } else { img_pos = dis->rcItem.left; } } else { img_pos = dis->rcItem.left; if (calcWidthCol==col || calcWidthCol==COLUMNS) pane->widths[col] = IMAGE_WIDTH; } if (calcWidthCol == -1) { focusRect.left = img_pos - 2; #ifdef _NO_EXTENSIONS if (pane->treePane && entry) { RECT rt = {0}; DrawText(dis->hDC, entry->data.cFileName, -1, &rt, DT_CALCRECT|DT_SINGLELINE|DT_NOPREFIX); focusRect.right = dis->rcItem.left+pane->positions[col+1]+TREE_LINE_DX + rt.right +2; } #else if (attrs & FILE_ATTRIBUTE_COMPRESSED) textcolor = COLOR_COMPRESSED; else #endif /* _NO_EXTENSIONS */ textcolor = RGB(0,0,0); if (dis->itemState & ODS_FOCUS) { textcolor = COLOR_SELECTION_TXT; bkcolor = COLOR_SELECTION; } else { bkcolor = GetSysColor(COLOR_WINDOW); } hbrush = CreateSolidBrush(bkcolor); FillRect(dis->hDC, &focusRect, hbrush); DeleteObject(hbrush); SetBkMode(dis->hDC, TRANSPARENT); SetTextColor(dis->hDC, textcolor); cx = pane->widths[col]; if (cx && img!=IMG_NONE) { if (cx > IMAGE_WIDTH) cx = IMAGE_WIDTH; #ifdef _SHELL_FOLDERS if (entry->hicon && entry->hicon!=(HICON)-1) DrawIconEx(dis->hDC, img_pos, dis->rcItem.top, entry->hicon, cx, GetSystemMetrics(SM_CYSMICON), 0, 0, DI_NORMAL); else #endif ImageList_DrawEx(Globals.himl, img, dis->hDC, img_pos, dis->rcItem.top, cx, IMAGE_HEIGHT, bkcolor, CLR_DEFAULT, ILD_NORMAL); } } if (!entry) return; #ifdef _NO_EXTENSIONS if (img >= IMG_FOLDER_UP) return; #endif col++; /* ouput file name */ if (calcWidthCol == -1) output_text(pane, dis, col, entry->data.cFileName, 0); else if (calcWidthCol==col || calcWidthCol==COLUMNS) calc_width(pane, dis, col, entry->data.cFileName); col++; #ifdef _NO_EXTENSIONS if (!pane->treePane) { #endif /* display file size */ if (visible_cols & COL_SIZE) { #ifdef _NO_EXTENSIONS if (!(attrs&FILE_ATTRIBUTE_DIRECTORY)) #endif { ULONGLONG size; size = ((ULONGLONG)entry->data.nFileSizeHigh << 32) | entry->data.nFileSizeLow; _stprintf(buffer, sLongNumFmt, size); if (calcWidthCol == -1) output_number(pane, dis, col, buffer); else if (calcWidthCol==col || calcWidthCol==COLUMNS) calc_width(pane, dis, col, buffer);/*TODO: not in every case time enough */ } col++; } /* display file date */ if (visible_cols & (COL_DATE|COL_TIME)) { #ifndef _NO_EXTENSIONS format_date(&entry->data.ftCreationTime, buffer, visible_cols); if (calcWidthCol == -1) output_text(pane, dis, col, buffer, 0); else if (calcWidthCol==col || calcWidthCol==COLUMNS) calc_width(pane, dis, col, buffer); col++; format_date(&entry->data.ftLastAccessTime, buffer, visible_cols); if (calcWidthCol == -1) output_text(pane, dis, col, buffer, 0); else if (calcWidthCol==col || calcWidthCol==COLUMNS) calc_width(pane, dis, col, buffer); col++; #endif /* _NO_EXTENSIONS */ format_date(&entry->data.ftLastWriteTime, buffer, visible_cols); if (calcWidthCol == -1) output_text(pane, dis, col, buffer, 0); else if (calcWidthCol==col || calcWidthCol==COLUMNS) calc_width(pane, dis, col, buffer); col++; } #ifndef _NO_EXTENSIONS if (entry->bhfi_valid) { ULONGLONG index = ((ULONGLONG)entry->bhfi.nFileIndexHigh << 32) | entry->bhfi.nFileIndexLow; if (visible_cols & COL_INDEX) { _stprintf(buffer, sLongHexFmt, index); if (calcWidthCol == -1) output_text(pane, dis, col, buffer, DT_RIGHT); else if (calcWidthCol==col || calcWidthCol==COLUMNS) calc_width(pane, dis, col, buffer); col++; } if (visible_cols & COL_LINKS) { wsprintf(buffer, sNumFmt, entry->bhfi.nNumberOfLinks); if (calcWidthCol == -1) output_text(pane, dis, col, buffer, DT_CENTER); else if (calcWidthCol==col || calcWidthCol==COLUMNS) calc_width(pane, dis, col, buffer); col++; } } else col += 2; #endif /* _NO_EXTENSIONS */ /* show file attributes */ if (visible_cols & COL_ATTRIBUTES) { #ifdef _NO_EXTENSIONS static const TCHAR s4Tabs[] = {' ','\t',' ','\t',' ','\t',' ','\t',' ','\0'}; lstrcpy(buffer, s4Tabs); #else static const TCHAR s11Tabs[] = {' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\0'}; lstrcpy(buffer, s11Tabs); #endif if (attrs & FILE_ATTRIBUTE_NORMAL) buffer[ 0] = 'N'; else { if (attrs & FILE_ATTRIBUTE_READONLY) buffer[ 2] = 'R'; if (attrs & FILE_ATTRIBUTE_HIDDEN) buffer[ 4] = 'H'; if (attrs & FILE_ATTRIBUTE_SYSTEM) buffer[ 6] = 'S'; if (attrs & FILE_ATTRIBUTE_ARCHIVE) buffer[ 8] = 'A'; if (attrs & FILE_ATTRIBUTE_COMPRESSED) buffer[10] = 'C'; #ifndef _NO_EXTENSIONS if (attrs & FILE_ATTRIBUTE_DIRECTORY) buffer[12] = 'D'; if (attrs & FILE_ATTRIBUTE_ENCRYPTED) buffer[14] = 'E'; if (attrs & FILE_ATTRIBUTE_TEMPORARY) buffer[16] = 'T'; if (attrs & FILE_ATTRIBUTE_SPARSE_FILE) buffer[18] = 'P'; if (attrs & FILE_ATTRIBUTE_REPARSE_POINT) buffer[20] = 'Q'; if (attrs & FILE_ATTRIBUTE_OFFLINE) buffer[22] = 'O'; if (attrs & FILE_ATTRIBUTE_NOT_CONTENT_INDEXED) buffer[24] = 'X'; #endif /* _NO_EXTENSIONS */ } if (calcWidthCol == -1) output_tabbed_text(pane, dis, col, buffer); else if (calcWidthCol==col || calcWidthCol==COLUMNS) calc_tabbed_width(pane, dis, col, buffer); col++; } /*TODO if (flags.security) { static const TCHAR sSecTabs[] = { ' ','\t',' ','\t',' ','\t',' ', ' ','\t',' ', ' ','\t',' ','\t',' ','\t',' ', ' ','\t',' ', ' ','\t',' ','\t',' ','\t',' ', '\0' }; DWORD rights = get_access_mask(); lstrcpy(buffer, sSecTabs); if (rights & FILE_READ_DATA) buffer[ 0] = 'R'; if (rights & FILE_WRITE_DATA) buffer[ 2] = 'W'; if (rights & FILE_APPEND_DATA) buffer[ 4] = 'A'; if (rights & FILE_READ_EA) {buffer[6] = 'entry'; buffer[ 7] = 'R';} if (rights & FILE_WRITE_EA) {buffer[9] = 'entry'; buffer[10] = 'W';} if (rights & FILE_EXECUTE) buffer[12] = 'X'; if (rights & FILE_DELETE_CHILD) buffer[14] = 'D'; if (rights & FILE_READ_ATTRIBUTES) {buffer[16] = 'a'; buffer[17] = 'R';} if (rights & FILE_WRITE_ATTRIBUTES) {buffer[19] = 'a'; buffer[20] = 'W';} if (rights & WRITE_DAC) buffer[22] = 'C'; if (rights & WRITE_OWNER) buffer[24] = 'O'; if (rights & SYNCHRONIZE) buffer[26] = 'S'; output_text(dis, col++, buffer, DT_LEFT, 3, psize); } if (flags.description) { get_description(buffer); output_text(dis, col++, buffer, 0, psize); } */ #ifdef _NO_EXTENSIONS } /* draw focus frame */ if ((dis->itemState&ODS_FOCUS) && calcWidthCol==-1) { /* Currently [04/2000] Wine neither behaves exactly the same */ /* way as WIN 95 nor like Windows NT... */ HGDIOBJ lastBrush; HPEN lastPen; HPEN hpen; if (!(GetVersion() & 0x80000000)) { /* Is the OS already Windows NT compatible? */ LOGBRUSH lb = {PS_SOLID, RGB(255,255,255)}; hpen = ExtCreatePen(PS_COSMETIC|PS_ALTERNATE, 1, &lb, 0, 0); } else hpen = CreatePen(PS_DOT, 0, RGB(255,255,255)); lastPen = SelectPen(dis->hDC, hpen); lastBrush = SelectObject(dis->hDC, GetStockObject(HOLLOW_BRUSH)); SetROP2(dis->hDC, R2_XORPEN); Rectangle(dis->hDC, focusRect.left, focusRect.top, focusRect.right, focusRect.bottom); SelectObject(dis->hDC, lastBrush); SelectObject(dis->hDC, lastPen); DeleteObject(hpen); } #endif /* _NO_EXTENSIONS */ } #ifdef _NO_EXTENSIONS /* draw the window split bar when not providing extensions over the original Winfile user interface */ static void draw_splitbar(HWND hwnd, int x) { RECT rt; HDC hdc = GetDC(hwnd); GetClientRect(hwnd, &rt); rt.left = x - SPLIT_WIDTH/2; rt.right = x + SPLIT_WIDTH/2+1; InvertRect(hdc, &rt); ReleaseDC(hwnd, hdc); } #endif /* _NO_EXTENSIONS */ /* scan the content of the given entry node */ static void scan_entry(ChildWnd* child, Entry* entry, int idx, HWND hwnd) { TCHAR path[MAX_PATH]; HCURSOR old_cursor = SetCursor(LoadCursor(0, IDC_WAIT)); /* delete sub entries in left pane */ for(;;) { LRESULT res = ListBox_GetItemData(child->left.hwnd, idx+1); Entry* sub = (Entry*) res; if (res==LB_ERR || !sub || sub->level<=entry->level) break; (void)ListBox_DeleteString(child->left.hwnd, idx+1); } /* empty right pane */ (void)ListBox_ResetContent(child->right.hwnd); /* release memory */ free_entries(entry); /* read contents from disk */ #ifdef _SHELL_FOLDERS if (entry->etype == ET_SHELL) { read_directory(entry, NULL, child->sortOrder, hwnd); } else #endif { get_path(entry, path); read_directory(entry, path, child->sortOrder, hwnd); } /* insert found entries in right pane */ insert_entries(&child->right, entry->down, child->filter_pattern, child->filter_flags, -1); calc_widths(&child->right, FALSE); #ifndef _NO_EXTENSIONS set_header(&child->right); #endif child->header_wdths_ok = FALSE; SetCursor(old_cursor); } /* expand a directory entry */ static BOOL expand_entry(ChildWnd* child, Entry* dir) { int idx; Entry* p; if (!dir || dir->expanded || !dir->down) return FALSE; p = dir->down; if (p->data.cFileName[0]=='.' && p->data.cFileName[1]=='\0' && p->next) { p = p->next; if (p->data.cFileName[0]=='.' && p->data.cFileName[1]=='.' && p->data.cFileName[2]=='\0' && p->next) p = p->next; } /* no subdirectories ? */ if (!(p->data.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY)) return FALSE; idx = ListBox_FindItemData(child->left.hwnd, 0, dir); dir->expanded = TRUE; /* insert entries in left pane */ insert_entries(&child->left, p, NULL, TF_ALL, idx); if (!child->header_wdths_ok) { if (calc_widths(&child->left, FALSE)) { #ifndef _NO_EXTENSIONS set_header(&child->left); #endif child->header_wdths_ok = TRUE; } } return TRUE; } /* close child nodes of the given entry */ static void collapse_entry(Pane* pane, Entry* dir) { int idx = ListBox_FindItemData(pane->hwnd, 0, dir); ShowWindow(pane->hwnd, SW_HIDE); /* hide sub entries */ for(;;) { LRESULT res = ListBox_GetItemData(pane->hwnd, idx+1); Entry* sub = (Entry*) res; if (res==LB_ERR || !sub || sub->level<=dir->level) break; (void)ListBox_DeleteString(pane->hwnd, idx+1); } dir->expanded = FALSE; ShowWindow(pane->hwnd, SW_SHOW); } /* refresh the right pane of a Winefile child window */ static void refresh_right_pane(ChildWnd* child) { (void)ListBox_ResetContent(child->right.hwnd); insert_entries(&child->right, child->right.root, child->filter_pattern, child->filter_flags, -1); calc_widths(&child->right, FALSE); #ifndef _NO_EXTENSIONS set_header(&child->right); #endif } /* change the current directory of a child window according to the given entry pointer */ static void set_curdir(ChildWnd* child, Entry* entry, int idx, HWND hwnd) { TCHAR path[MAX_PATH]; if (!entry) return; path[0] = '\0'; child->left.cur = entry; child->right.root = entry->down? entry->down: entry; child->right.cur = entry; if (!entry->scanned) scan_entry(child, entry, idx, hwnd); else refresh_right_pane(child); get_path(entry, path); lstrcpy(child->path, path); if (child->hwnd) /* only change window title, if the window already exists */ SetWindowText(child->hwnd, path); if (path[0]) if (SetCurrentDirectory(path)) set_space_status(); } /* refresh the child window content */ static void refresh_child(ChildWnd* child) { TCHAR path[MAX_PATH], drv[_MAX_DRIVE+1]; Entry* entry; int idx; get_path(child->left.cur, path); _tsplitpath(path, drv, NULL, NULL, NULL); child->right.root = NULL; scan_entry(child, &child->root.entry, 0, child->hwnd); #ifdef _SHELL_FOLDERS if (child->root.entry.etype == ET_SHELL) entry = read_tree(&child->root, NULL, get_path_pidl(path,child->hwnd), drv, child->sortOrder, child->hwnd); else #endif entry = read_tree(&child->root, path, NULL, drv, child->sortOrder, child->hwnd); if (!entry) entry = &child->root.entry; insert_entries(&child->left, child->root.entry.down, NULL, TF_ALL, 0); set_curdir(child, entry, 0, child->hwnd); idx = ListBox_FindItemData(child->left.hwnd, 0, child->left.cur); (void)ListBox_SetCurSel(child->left.hwnd, idx); } /* create the drive toolbar */ static void create_drive_bar(void) { TBBUTTON drivebarBtn = {0, 0, TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0}; #ifndef _NO_EXTENSIONS TCHAR b1[BUFFER_LEN]; #endif int btn = 1; PTSTR p; GetLogicalDriveStrings(BUFFER_LEN, Globals.drives); Globals.hdrivebar = CreateToolbarEx(Globals.hMainWnd, WS_CHILD|WS_VISIBLE|CCS_NOMOVEY|TBSTYLE_LIST, IDW_DRIVEBAR, 2, Globals.hInstance, IDB_DRIVEBAR, &drivebarBtn, 0, 16, 13, 16, 13, sizeof(TBBUTTON)); #ifndef _NO_EXTENSIONS #ifdef __WINE__ /* insert unix file system button */ b1[0] = '/'; b1[1] = '\0'; b1[2] = '\0'; SendMessage(Globals.hdrivebar, TB_ADDSTRING, 0, (LPARAM)b1); drivebarBtn.idCommand = ID_DRIVE_UNIX_FS; SendMessage(Globals.hdrivebar, TB_INSERTBUTTON, btn++, (LPARAM)&drivebarBtn); drivebarBtn.iString++; #endif #ifdef _SHELL_FOLDERS /* insert shell namespace button */ load_string(b1, IDS_SHELL); b1[lstrlen(b1)+1] = '\0'; SendMessage(Globals.hdrivebar, TB_ADDSTRING, 0, (LPARAM)b1); drivebarBtn.idCommand = ID_DRIVE_SHELL_NS; SendMessage(Globals.hdrivebar, TB_INSERTBUTTON, btn++, (LPARAM)&drivebarBtn); drivebarBtn.iString++; #endif /* register windows drive root strings */ SendMessage(Globals.hdrivebar, TB_ADDSTRING, 0, (LPARAM)Globals.drives); #endif drivebarBtn.idCommand = ID_DRIVE_FIRST; for(p=Globals.drives; *p; ) { #ifdef _NO_EXTENSIONS /* insert drive letter */ TCHAR b[3] = {tolower(*p)}; SendMessage(Globals.hdrivebar, TB_ADDSTRING, 0, (LPARAM)b); #endif switch(GetDriveType(p)) { case DRIVE_REMOVABLE: drivebarBtn.iBitmap = 1; break; case DRIVE_CDROM: drivebarBtn.iBitmap = 3; break; case DRIVE_REMOTE: drivebarBtn.iBitmap = 4; break; case DRIVE_RAMDISK: drivebarBtn.iBitmap = 5; break; default:/*DRIVE_FIXED*/ drivebarBtn.iBitmap = 2; } SendMessage(Globals.hdrivebar, TB_INSERTBUTTON, btn++, (LPARAM)&drivebarBtn); drivebarBtn.idCommand++; drivebarBtn.iString++; while(*p++); } } /* refresh the drive toolbar */ static void refresh_drives(void) { RECT rect; /* destroy drive bar */ DestroyWindow(Globals.hdrivebar); Globals.hdrivebar = 0; /* re-create drive bar */ create_drive_bar(); /* update window layout */ GetClientRect(Globals.hMainWnd, &rect); SendMessage(Globals.hMainWnd, WM_SIZE, 0, MAKELONG(rect.right, rect.bottom)); } /* launch a executable or document */ static BOOL launch_file(HWND hwnd, LPCTSTR cmd, UINT nCmdShow) { HINSTANCE hinst = ShellExecute(hwnd, NULL/*operation*/, cmd, NULL/*parameters*/, NULL/*dir*/, nCmdShow); if (PtrToUlong(hinst) <= 32) { display_error(hwnd, GetLastError()); return FALSE; } return TRUE; } /* launch the file associated with a Winefile entry */ static BOOL launch_entry(Entry* entry, HWND hwnd, UINT nCmdShow) { TCHAR cmd[MAX_PATH]; #ifdef _SHELL_FOLDERS if (entry->etype == ET_SHELL) { BOOL ret = TRUE; SHELLEXECUTEINFO shexinfo; shexinfo.cbSize = sizeof(SHELLEXECUTEINFO); shexinfo.fMask = SEE_MASK_IDLIST; shexinfo.hwnd = hwnd; shexinfo.lpVerb = NULL; shexinfo.lpFile = NULL; shexinfo.lpParameters = NULL; shexinfo.lpDirectory = NULL; shexinfo.nShow = nCmdShow; shexinfo.lpIDList = get_to_absolute_pidl(entry, hwnd); if (!ShellExecuteEx(&shexinfo)) { display_error(hwnd, GetLastError()); ret = FALSE; } if (shexinfo.lpIDList != entry->pidl) IMalloc_Free(Globals.iMalloc, shexinfo.lpIDList); return ret; } #endif get_path(entry, cmd); /* start program, open document... */ return launch_file(hwnd, cmd, nCmdShow); } /* activate a Winefile entry (on double click or ENTER) */ static void activate_entry(ChildWnd* child, Pane* pane, HWND hwnd) { Entry* entry = pane->cur; if (!entry) return; if (entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { int scanned_old = entry->scanned; if (!scanned_old) scan_entry(child, entry, ListBox_GetCurSel(child->left.hwnd), hwnd); #ifndef _NO_EXTENSIONS if (entry->data.cFileName[0]=='.' && entry->data.cFileName[1]=='\0') return; #endif if (entry->data.cFileName[0]=='.' && entry->data.cFileName[1]=='.' && entry->data.cFileName[2]=='\0') { entry = child->left.cur->up; collapse_entry(&child->left, entry); goto focus_entry; } else if (entry->expanded) collapse_entry(pane, child->left.cur); else { expand_entry(child, child->left.cur); if (!pane->treePane) focus_entry: { int idx = ListBox_FindItemData(child->left.hwnd, ListBox_GetCurSel(child->left.hwnd), entry); (void)ListBox_SetCurSel(child->left.hwnd, idx); set_curdir(child, entry, idx, hwnd); } } if (!scanned_old) { calc_widths(pane, FALSE); #ifndef _NO_EXTENSIONS set_header(pane); #endif } } else { if (GetKeyState(VK_MENU) < 0) show_properties_dlg(entry, child->hwnd); else launch_entry(entry, child->hwnd, SW_SHOWNORMAL); } } /* command handler for Winefile panes */ static BOOL pane_command(Pane* pane, UINT cmd) { switch(cmd) { case ID_VIEW_NAME: if (pane->visible_cols) { pane->visible_cols = 0; calc_widths(pane, TRUE); #ifndef _NO_EXTENSIONS set_header(pane); #endif InvalidateRect(pane->hwnd, 0, TRUE); CheckMenuItem(Globals.hMenuView, ID_VIEW_NAME, MF_BYCOMMAND|MF_CHECKED); CheckMenuItem(Globals.hMenuView, ID_VIEW_ALL_ATTRIBUTES, MF_BYCOMMAND); CheckMenuItem(Globals.hMenuView, ID_VIEW_SELECTED_ATTRIBUTES, MF_BYCOMMAND); } break; case ID_VIEW_ALL_ATTRIBUTES: if (pane->visible_cols != COL_ALL) { pane->visible_cols = COL_ALL; calc_widths(pane, TRUE); #ifndef _NO_EXTENSIONS set_header(pane); #endif InvalidateRect(pane->hwnd, 0, TRUE); CheckMenuItem(Globals.hMenuView, ID_VIEW_NAME, MF_BYCOMMAND); CheckMenuItem(Globals.hMenuView, ID_VIEW_ALL_ATTRIBUTES, MF_BYCOMMAND|MF_CHECKED); CheckMenuItem(Globals.hMenuView, ID_VIEW_SELECTED_ATTRIBUTES, MF_BYCOMMAND); } break; #ifndef _NO_EXTENSIONS case ID_PREFERRED_SIZES: { calc_widths(pane, TRUE); set_header(pane); InvalidateRect(pane->hwnd, 0, TRUE); break;} #endif /* TODO: more command ids... */ default: return FALSE; } return TRUE; } /* set the sort order of a child window */ static void set_sort_order(ChildWnd* child, enum SORT_ORDER sortOrder) { if (child->sortOrder != sortOrder) { child->sortOrder = sortOrder; refresh_child(child); } } /* update the check state of the view menu items */ static void update_view_menu(ChildWnd* child) { CheckMenuItem(Globals.hMenuView, ID_VIEW_SORT_NAME, child->sortOrder==SORT_NAME? MF_CHECKED: MF_UNCHECKED); CheckMenuItem(Globals.hMenuView, ID_VIEW_SORT_TYPE, child->sortOrder==SORT_EXT? MF_CHECKED: MF_UNCHECKED); CheckMenuItem(Globals.hMenuView, ID_VIEW_SORT_SIZE, child->sortOrder==SORT_SIZE? MF_CHECKED: MF_UNCHECKED); CheckMenuItem(Globals.hMenuView, ID_VIEW_SORT_DATE, child->sortOrder==SORT_DATE? MF_CHECKED: MF_UNCHECKED); } /* utility function to check for directories at the given path */ static BOOL is_directory(LPCTSTR target) { /*TODO correctly handle UNIX paths */ DWORD target_attr = GetFileAttributes(target); if (target_attr == INVALID_FILE_ATTRIBUTES) return FALSE; return target_attr&FILE_ATTRIBUTE_DIRECTORY? TRUE: FALSE; } /* display a dialog to ask the user for a target path */ static BOOL prompt_target(Pane* pane, LPTSTR source, LPTSTR target) { TCHAR path[MAX_PATH]; int len; get_path(pane->cur, path); if (DialogBoxParam(Globals.hInstance, MAKEINTRESOURCE(IDD_SELECT_DESTINATION), pane->hwnd, DestinationDlgProc, (LPARAM)path) != IDOK) return FALSE; get_path(pane->cur, source); /* convert relative targets to absolute paths */ if (path[0]!='/' && path[1]!=':') { get_path(pane->cur->up, target); len = lstrlen(target); if (target[len-1]!='\\' && target[len-1]!='/') target[len++] = '/'; lstrcpy(target+len, path); } else lstrcpy(target, path); /* If the target already exists as directory, create a new target below this. */ if (is_directory(path)) { TCHAR fname[_MAX_FNAME], ext[_MAX_EXT]; static const TCHAR sAppend[] = {'%','s','/','%','s','%','s','\0'}; _tsplitpath(source, NULL, NULL, fname, ext); wsprintf(target, sAppend, path, fname, ext); } return TRUE; } /* message handler funtion for the Winefile child windows */ static LRESULT CALLBACK ChildWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam) { ChildWnd* child = (ChildWnd*) GetWindowLongPtr(hwnd, GWLP_USERDATA); ASSERT(child); switch(nmsg) { case WM_DRAWITEM: { LPDRAWITEMSTRUCT dis = (LPDRAWITEMSTRUCT)lparam; Entry* entry = (Entry*) dis->itemData; if (dis->CtlID == IDW_TREE_LEFT) draw_item(&child->left, dis, entry, -1); else if (dis->CtlID == IDW_TREE_RIGHT) draw_item(&child->right, dis, entry, -1); else goto draw_menu_item; return TRUE;} case WM_CREATE: InitChildWindow(child); break; case WM_NCDESTROY: free_child_window(child); SetWindowLongPtr(hwnd, GWLP_USERDATA, 0); break; case WM_PAINT: { PAINTSTRUCT ps; HBRUSH lastBrush; RECT rt; GetClientRect(hwnd, &rt); BeginPaint(hwnd, &ps); rt.left = child->split_pos-SPLIT_WIDTH/2; rt.right = child->split_pos+SPLIT_WIDTH/2+1; lastBrush = SelectBrush(ps.hdc, (HBRUSH)GetStockObject(COLOR_SPLITBAR)); Rectangle(ps.hdc, rt.left, rt.top-1, rt.right, rt.bottom+1); SelectObject(ps.hdc, lastBrush); #ifdef _NO_EXTENSIONS rt.top = rt.bottom - GetSystemMetrics(SM_CYHSCROLL); FillRect(ps.hdc, &rt, GetStockObject(BLACK_BRUSH)); #endif EndPaint(hwnd, &ps); break;} case WM_SETCURSOR: if (LOWORD(lparam) == HTCLIENT) { POINT pt; GetCursorPos(&pt); ScreenToClient(hwnd, &pt); if (pt.x>=child->split_pos-SPLIT_WIDTH/2 && pt.xsplit_pos+SPLIT_WIDTH/2+1) { SetCursor(LoadCursor(0, IDC_SIZEWE)); return TRUE; } } goto def; case WM_LBUTTONDOWN: { RECT rt; int x = GET_X_LPARAM(lparam); GetClientRect(hwnd, &rt); if (x>=child->split_pos-SPLIT_WIDTH/2 && xsplit_pos+SPLIT_WIDTH/2+1) { last_split = child->split_pos; #ifdef _NO_EXTENSIONS draw_splitbar(hwnd, last_split); #endif SetCapture(hwnd); } break;} case WM_LBUTTONUP: if (GetCapture() == hwnd) { #ifdef _NO_EXTENSIONS RECT rt; int x = LOWORD(lparam); draw_splitbar(hwnd, last_split); last_split = -1; GetClientRect(hwnd, &rt); child->split_pos = x; resize_tree(child, rt.right, rt.bottom); #endif ReleaseCapture(); } break; #ifdef _NO_EXTENSIONS case WM_CAPTURECHANGED: if (GetCapture()==hwnd && last_split>=0) draw_splitbar(hwnd, last_split); break; #endif case WM_KEYDOWN: if (wparam == VK_ESCAPE) if (GetCapture() == hwnd) { RECT rt; #ifdef _NO_EXTENSIONS draw_splitbar(hwnd, last_split); #else child->split_pos = last_split; #endif GetClientRect(hwnd, &rt); resize_tree(child, rt.right, rt.bottom); last_split = -1; ReleaseCapture(); SetCursor(LoadCursor(0, IDC_ARROW)); } break; case WM_MOUSEMOVE: if (GetCapture() == hwnd) { RECT rt; int x = LOWORD(lparam); #ifdef _NO_EXTENSIONS HDC hdc = GetDC(hwnd); GetClientRect(hwnd, &rt); rt.left = last_split-SPLIT_WIDTH/2; rt.right = last_split+SPLIT_WIDTH/2+1; InvertRect(hdc, &rt); last_split = x; rt.left = x-SPLIT_WIDTH/2; rt.right = x+SPLIT_WIDTH/2+1; InvertRect(hdc, &rt); ReleaseDC(hwnd, hdc); #else GetClientRect(hwnd, &rt); if (x>=0 && xsplit_pos = x; resize_tree(child, rt.right, rt.bottom); rt.left = x-SPLIT_WIDTH/2; rt.right = x+SPLIT_WIDTH/2+1; InvalidateRect(hwnd, &rt, FALSE); UpdateWindow(child->left.hwnd); UpdateWindow(hwnd); UpdateWindow(child->right.hwnd); } #endif } break; #ifndef _NO_EXTENSIONS case WM_GETMINMAXINFO: DefMDIChildProc(hwnd, nmsg, wparam, lparam); {LPMINMAXINFO lpmmi = (LPMINMAXINFO)lparam; lpmmi->ptMaxTrackSize.x <<= 1;/*2*GetSystemMetrics(SM_CXSCREEN) / SM_CXVIRTUALSCREEN */ lpmmi->ptMaxTrackSize.y <<= 1;/*2*GetSystemMetrics(SM_CYSCREEN) / SM_CYVIRTUALSCREEN */ break;} #endif /* _NO_EXTENSIONS */ case WM_SETFOCUS: if (SetCurrentDirectory(child->path)) set_space_status(); SetFocus(child->focus_pane? child->right.hwnd: child->left.hwnd); break; case WM_DISPATCH_COMMAND: { Pane* pane = GetFocus()==child->left.hwnd? &child->left: &child->right; switch(LOWORD(wparam)) { case ID_WINDOW_NEW: { ChildWnd* new_child = alloc_child_window(child->path, NULL, hwnd); if (!create_child_window(new_child)) heap_free(new_child); break;} case ID_REFRESH: refresh_drives(); refresh_child(child); break; case ID_ACTIVATE: activate_entry(child, pane, hwnd); break; case ID_FILE_MOVE: { TCHAR source[BUFFER_LEN], target[BUFFER_LEN]; if (prompt_target(pane, source, target)) { SHFILEOPSTRUCT shfo = {hwnd, FO_MOVE, source, target}; source[lstrlen(source)+1] = '\0'; target[lstrlen(target)+1] = '\0'; if (!SHFileOperation(&shfo)) refresh_child(child); } break;} case ID_FILE_COPY: { TCHAR source[BUFFER_LEN], target[BUFFER_LEN]; if (prompt_target(pane, source, target)) { SHFILEOPSTRUCT shfo = {hwnd, FO_COPY, source, target}; source[lstrlen(source)+1] = '\0'; target[lstrlen(target)+1] = '\0'; if (!SHFileOperation(&shfo)) refresh_child(child); } break;} case ID_FILE_DELETE: { TCHAR path[BUFFER_LEN]; SHFILEOPSTRUCT shfo = {hwnd, FO_DELETE, path, NULL, FOF_ALLOWUNDO}; get_path(pane->cur, path); path[lstrlen(path)+1] = '\0'; if (!SHFileOperation(&shfo)) refresh_child(child); break;} case ID_VIEW_SORT_NAME: set_sort_order(child, SORT_NAME); break; case ID_VIEW_SORT_TYPE: set_sort_order(child, SORT_EXT); break; case ID_VIEW_SORT_SIZE: set_sort_order(child, SORT_SIZE); break; case ID_VIEW_SORT_DATE: set_sort_order(child, SORT_DATE); break; case ID_VIEW_FILTER: { struct FilterDialog dlg; memset(&dlg, 0, sizeof(struct FilterDialog)); lstrcpy(dlg.pattern, child->filter_pattern); dlg.flags = child->filter_flags; if (DialogBoxParam(Globals.hInstance, MAKEINTRESOURCE(IDD_DIALOG_VIEW_TYPE), hwnd, FilterDialogDlgProc, (LPARAM)&dlg) == IDOK) { lstrcpy(child->filter_pattern, dlg.pattern); child->filter_flags = dlg.flags; refresh_right_pane(child); } break;} case ID_VIEW_SPLIT: { last_split = child->split_pos; #ifdef _NO_EXTENSIONS draw_splitbar(hwnd, last_split); #endif SetCapture(hwnd); break;} case ID_EDIT_PROPERTIES: show_properties_dlg(pane->cur, child->hwnd); break; default: return pane_command(pane, LOWORD(wparam)); } return TRUE;} case WM_COMMAND: { Pane* pane = GetFocus()==child->left.hwnd? &child->left: &child->right; switch(HIWORD(wparam)) { case LBN_SELCHANGE: { int idx = ListBox_GetCurSel(pane->hwnd); Entry* entry = (Entry*) ListBox_GetItemData(pane->hwnd, idx); if (pane == &child->left) set_curdir(child, entry, idx, hwnd); else pane->cur = entry; break;} case LBN_DBLCLK: activate_entry(child, pane, hwnd); break; } break;} #ifndef _NO_EXTENSIONS case WM_NOTIFY: { NMHDR* pnmh = (NMHDR*) lparam; return pane_notify(pnmh->idFrom==IDW_HEADER_LEFT? &child->left: &child->right, pnmh);} #endif #ifdef _SHELL_FOLDERS case WM_CONTEXTMENU: { POINT pt, pt_clnt; Pane* pane; int idx; /* first select the current item in the listbox */ HWND hpanel = (HWND) wparam; pt_clnt.x = pt.x = (short)LOWORD(lparam); pt_clnt.y = pt.y = (short)HIWORD(lparam); ScreenToClient(hpanel, &pt_clnt); SendMessage(hpanel, WM_LBUTTONDOWN, 0, MAKELONG(pt_clnt.x, pt_clnt.y)); SendMessage(hpanel, WM_LBUTTONUP, 0, MAKELONG(pt_clnt.x, pt_clnt.y)); /* now create the popup menu using shell namespace and IContextMenu */ pane = GetFocus()==child->left.hwnd? &child->left: &child->right; idx = ListBox_GetCurSel(pane->hwnd); if (idx != -1) { Entry* entry = (Entry*) ListBox_GetItemData(pane->hwnd, idx); LPITEMIDLIST pidl_abs = get_to_absolute_pidl(entry, hwnd); if (pidl_abs) { IShellFolder* parentFolder; LPCITEMIDLIST pidlLast; /* get and use the parent folder to display correct context menu in all cases */ if (SUCCEEDED(SHBindToParent(pidl_abs, &IID_IShellFolder, (LPVOID*)&parentFolder, &pidlLast))) { if (ShellFolderContextMenu(parentFolder, hwnd, 1, &pidlLast, pt.x, pt.y) == S_OK) refresh_child(child); IShellFolder_Release(parentFolder); } IMalloc_Free(Globals.iMalloc, pidl_abs); } } break;} #endif case WM_MEASUREITEM: draw_menu_item: if (!wparam) /* Is the message menu-related? */ if (CtxMenu_HandleMenuMsg(nmsg, wparam, lparam)) return TRUE; break; case WM_INITMENUPOPUP: if (CtxMenu_HandleMenuMsg(nmsg, wparam, lparam)) return 0; update_view_menu(child); break; case WM_MENUCHAR: /* only supported by IContextMenu3 */ if (s_pctxmenu3) { LRESULT lResult = 0; (*s_pctxmenu3->lpVtbl->HandleMenuMsg2)(s_pctxmenu3, nmsg, wparam, lparam, &lResult); return lResult; } break; case WM_SIZE: if (wparam != SIZE_MINIMIZED) resize_tree(child, LOWORD(lparam), HIWORD(lparam)); /* fall through */ default: def: return DefMDIChildProc(hwnd, nmsg, wparam, lparam); } return 0; } /* program initialisation */ static void InitInstance(HINSTANCE hinstance) { static const TCHAR sFont[] = {'M','i','c','r','o','s','o','f','t',' ','S','a','n','s',' ','S','e','r','i','f','\0'}; WNDCLASSEX wcFrame; WNDCLASS wcChild; ATOM hChildClass; int col; INITCOMMONCONTROLSEX icc = { sizeof(INITCOMMONCONTROLSEX), ICC_BAR_CLASSES }; HDC hdc = GetDC(0); setlocale(LC_COLLATE, ""); /* set collating rules to local settings for compareName */ InitCommonControlsEx(&icc); /* register frame window class */ wcFrame.cbSize = sizeof(WNDCLASSEX); wcFrame.style = 0; wcFrame.lpfnWndProc = FrameWndProc; wcFrame.cbClsExtra = 0; wcFrame.cbWndExtra = 0; wcFrame.hInstance = hinstance; wcFrame.hIcon = LoadIcon(hinstance, MAKEINTRESOURCE(IDI_WINEFILE)); wcFrame.hCursor = LoadCursor(0, IDC_ARROW); wcFrame.hbrBackground = 0; wcFrame.lpszMenuName = 0; wcFrame.lpszClassName = sWINEFILEFRAME; wcFrame.hIconSm = (HICON)LoadImage(hinstance, MAKEINTRESOURCE(IDI_WINEFILE), IMAGE_ICON, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_SHARED); Globals.hframeClass = RegisterClassEx(&wcFrame); /* register tree windows class */ wcChild.style = CS_CLASSDC|CS_DBLCLKS|CS_VREDRAW; wcChild.lpfnWndProc = ChildWndProc; wcChild.cbClsExtra = 0; wcChild.cbWndExtra = 0; wcChild.hInstance = hinstance; wcChild.hIcon = 0; wcChild.hCursor = LoadCursor(0, IDC_ARROW); wcChild.hbrBackground = 0; wcChild.lpszMenuName = 0; wcChild.lpszClassName = sWINEFILETREE; hChildClass = RegisterClass(&wcChild); Globals.haccel = LoadAccelerators(hinstance, MAKEINTRESOURCE(IDA_WINEFILE)); Globals.hfont = CreateFont(-MulDiv(8,GetDeviceCaps(hdc,LOGPIXELSY),72), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, sFont); ReleaseDC(0, hdc); Globals.hInstance = hinstance; #ifdef _SHELL_FOLDERS CoInitialize(NULL); CoGetMalloc(MEMCTX_TASK, &Globals.iMalloc); SHGetDesktopFolder(&Globals.iDesktop); #ifdef __WINE__ Globals.cfStrFName = RegisterClipboardFormatA(CFSTR_FILENAME); #else Globals.cfStrFName = RegisterClipboardFormat(CFSTR_FILENAME); #endif #endif /* load column strings */ col = 1; load_string(g_pos_names[col++], IDS_COL_NAME); load_string(g_pos_names[col++], IDS_COL_SIZE); load_string(g_pos_names[col++], IDS_COL_CDATE); #ifndef _NO_EXTENSIONS load_string(g_pos_names[col++], IDS_COL_ADATE); load_string(g_pos_names[col++], IDS_COL_MDATE); load_string(g_pos_names[col++], IDS_COL_IDX); load_string(g_pos_names[col++], IDS_COL_LINKS); #endif load_string(g_pos_names[col++], IDS_COL_ATTR); #ifndef _NO_EXTENSIONS load_string(g_pos_names[col++], IDS_COL_SEC); #endif } /* display main frame window */ static void show_frame(HWND hwndParent, int cmdshow, LPCTSTR path) { static const TCHAR sMDICLIENT[] = {'M','D','I','C','L','I','E','N','T','\0'}; TCHAR buffer[MAX_PATH], b1[BUFFER_LEN]; HMENU hMenuFrame, hMenuWindow; ChildWnd* child; struct WINDOW_OPTIONS opts; CLIENTCREATESTRUCT ccs; if (Globals.hMainWnd) return; load_registry_settings(&opts); hMenuFrame = LoadMenu(Globals.hInstance, MAKEINTRESOURCE(IDM_WINEFILE)); hMenuWindow = GetSubMenu(hMenuFrame, GetMenuItemCount(hMenuFrame)-2); Globals.hMenuFrame = hMenuFrame; Globals.hMenuView = GetSubMenu(hMenuFrame, 3); Globals.hMenuOptions = GetSubMenu(hMenuFrame, 4); ccs.hWindowMenu = hMenuWindow; ccs.idFirstChild = IDW_FIRST_CHILD; /* create main window */ Globals.hMainWnd = CreateWindowEx(0, MAKEINTRESOURCE(Globals.hframeClass), RS(b1,IDS_WINE_FILE), WS_OVERLAPPEDWINDOW, opts.start_x, opts.start_y, opts.width, opts.height, hwndParent, Globals.hMenuFrame, Globals.hInstance, 0/*lpParam*/); Globals.hmdiclient = CreateWindowEx(0, sMDICLIENT, NULL, WS_CHILD|WS_CLIPCHILDREN|WS_VSCROLL|WS_HSCROLL|WS_VISIBLE|WS_BORDER, 0, 0, 0, 0, Globals.hMainWnd, 0, Globals.hInstance, &ccs); CheckMenuItem(Globals.hMenuOptions, ID_VIEW_DRIVE_BAR, MF_BYCOMMAND|MF_CHECKED); CheckMenuItem(Globals.hMenuOptions, ID_VIEW_SAVESETTINGS, MF_BYCOMMAND); create_drive_bar(); { TBBUTTON toolbarBtns[] = { {0, 0, 0, BTNS_SEP, {0, 0}, 0, 0}, {0, ID_WINDOW_NEW, TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0}, {1, ID_WINDOW_CASCADE, TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0}, {2, ID_WINDOW_TILE_HORZ, TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0}, {3, ID_WINDOW_TILE_VERT, TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0}, /*TODO {4, ID_... , TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0}, {5, ID_... , TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0}, */ }; Globals.htoolbar = CreateToolbarEx(Globals.hMainWnd, WS_CHILD|WS_VISIBLE, IDW_TOOLBAR, 2, Globals.hInstance, IDB_TOOLBAR, toolbarBtns, sizeof(toolbarBtns)/sizeof(TBBUTTON), 16, 15, 16, 15, sizeof(TBBUTTON)); CheckMenuItem(Globals.hMenuOptions, ID_VIEW_TOOL_BAR, MF_BYCOMMAND|MF_CHECKED); } Globals.hstatusbar = CreateStatusWindow(WS_CHILD|WS_VISIBLE, 0, Globals.hMainWnd, IDW_STATUSBAR); CheckMenuItem(Globals.hMenuOptions, ID_VIEW_STATUSBAR, MF_BYCOMMAND|MF_CHECKED); /* CreateStatusWindow does not accept WS_BORDER Globals.hstatusbar = CreateWindowEx(WS_EX_NOPARENTNOTIFY, STATUSCLASSNAME, 0, WS_CHILD|WS_VISIBLE|WS_CLIPSIBLINGS|WS_BORDER|CCS_NODIVIDER, 0,0,0,0, Globals.hMainWnd, (HMENU)IDW_STATUSBAR, hinstance, 0);*/ /*TODO: read paths from registry */ if (!path || !*path) { GetCurrentDirectory(MAX_PATH, buffer); path = buffer; } ShowWindow(Globals.hMainWnd, cmdshow); #if defined(_SHELL_FOLDERS) && 0 /* Display drive view as default. */ /* display Shell Namespace */ child = alloc_child_window(path, get_path_pidl(path,Globals.hMainWnd), Globals.hMainWnd); #else child = alloc_child_window(path, NULL, Globals.hMainWnd); #endif child->pos.showCmd = SW_SHOWMAXIMIZED; child->pos.rcNormalPosition.left = 0; child->pos.rcNormalPosition.top = 0; child->pos.rcNormalPosition.right = 320; child->pos.rcNormalPosition.bottom = 280; if (!create_child_window(child)) heap_free(child); SetWindowPlacement(child->hwnd, &child->pos); Globals.himl = ImageList_LoadBitmap(Globals.hInstance, MAKEINTRESOURCE(IDB_IMAGES), 16, 0, RGB(0,255,0)); Globals.prescan_node = FALSE; UpdateWindow(Globals.hMainWnd); if (path && path[0]) { int index,count; TCHAR drv[_MAX_DRIVE+1], dir[_MAX_DIR], name[_MAX_FNAME], ext[_MAX_EXT]; TCHAR fullname[_MAX_FNAME+_MAX_EXT+1]; memset(name,0,sizeof(name)); memset(name,0,sizeof(ext)); _tsplitpath(path, drv, dir, name, ext); if (name[0]) { count = ListBox_GetCount(child->right.hwnd); lstrcpy(fullname,name); lstrcat(fullname,ext); for (index = 0; index < count; index ++) { Entry* entry = (Entry*) ListBox_GetItemData(child->right.hwnd, index); if (lstrcmp(entry->data.cFileName,fullname)==0 || lstrcmp(entry->data.cAlternateFileName,fullname)==0) { (void)ListBox_SetCurSel(child->right.hwnd, index); SetFocus(child->right.hwnd); break; } } } } } /* release memory on program termination */ static void ExitInstance(void) { #ifdef _SHELL_FOLDERS IShellFolder_Release(Globals.iDesktop); IMalloc_Release(Globals.iMalloc); CoUninitialize(); #endif DeleteObject(Globals.hfont); ImageList_Destroy(Globals.himl); } #ifdef _NO_EXTENSIONS /* search for already running win[e]file instances */ static int g_foundPrevInstance = 0; /* callback fucntion to enumerate Win[e]file frame windows */ static BOOL CALLBACK EnumWndProc(HWND hwnd, LPARAM lparam) { TCHAR cls[128]; GetClassName(hwnd, cls, 128); if (!lstrcmp(cls, (LPCTSTR)lparam)) { g_foundPrevInstance++; return FALSE; } return TRUE; } /* search for window of given class name to allow only one running instance */ static int find_window_class(LPCTSTR classname) { EnumWindows(EnumWndProc, (LPARAM)classname); if (g_foundPrevInstance) return 1; return 0; } #endif /* main function */ static int winefile_main(HINSTANCE hinstance, int cmdshow, LPCTSTR path) { MSG msg; InitInstance(hinstance); show_frame(0, cmdshow, path); while(GetMessage(&msg, 0, 0, 0)) { if (Globals.hmdiclient && TranslateMDISysAccel(Globals.hmdiclient, &msg)) continue; if (Globals.hMainWnd && TranslateAccelerator(Globals.hMainWnd, Globals.haccel, &msg)) continue; TranslateMessage(&msg); DispatchMessage(&msg); } ExitInstance(); return msg.wParam; } /* program entry function */ #if defined(UNICODE) && defined(_MSC_VER) int APIENTRY wWinMain(HINSTANCE hinstance, HINSTANCE previnstance, LPWSTR cmdline, int cmdshow) #else int APIENTRY WinMain(HINSTANCE hinstance, HINSTANCE previnstance, LPSTR cmdline, int cmdshow) #endif { #ifdef _NO_EXTENSIONS if (find_window_class(sWINEFILEFRAME)) return 1; #endif #if defined(UNICODE) && !defined(_MSC_VER) { /* convert ANSI cmdline into WCS path string */ TCHAR buffer[MAX_PATH]; MultiByteToWideChar(CP_ACP, 0, cmdline, -1, buffer, MAX_PATH); winefile_main(hinstance, cmdshow, buffer); } #else winefile_main(hinstance, cmdshow, cmdline); #endif return 0; }