po: Remove English strings from the Russian translation.
[wine/multimedia.git] / programs / explorer / explorer.c
blob35080a3ca1ae13096c6e3cf044550168b39dfa09
1 /*
2 * explorer.exe
4 * Copyright 2004 CodeWeavers, Mike Hearn
5 * Copyright 2005,2006 CodeWeavers, Aric Stewart
6 * Copyright 2011 Jay Yang
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #define COBJMACROS
24 #define NONAMELESSUNION
26 #include "wine/unicode.h"
27 #include "wine/debug.h"
28 #include "explorer_private.h"
29 #include "resource.h"
31 #include <initguid.h>
32 #include <windows.h>
33 #include <shobjidl.h>
34 #include <shlobj.h>
35 #include <shlwapi.h>
36 #include <commoncontrols.h>
37 #include <commctrl.h>
39 WINE_DEFAULT_DEBUG_CHANNEL(explorer);
41 #define EXPLORER_INFO_INDEX 0
43 #define NAV_TOOLBAR_HEIGHT 30
44 #define PATHBOX_HEIGHT 24
46 #define DEFAULT_WIDTH 640
47 #define DEFAULT_HEIGHT 480
50 static const WCHAR EXPLORER_CLASS[] = {'W','I','N','E','_','E','X','P','L','O','R','E','R','\0'};
51 static const WCHAR PATH_BOX_NAME[] = {'\0'};
53 HINSTANCE explorer_hInstance;
55 typedef struct parametersTAG {
56 BOOL explorer_mode;
57 WCHAR root[MAX_PATH];
58 WCHAR selection[MAX_PATH];
59 } parameters_struct;
61 typedef struct
63 IExplorerBrowser *browser;
64 HWND main_window,path_box;
65 INT rebar_height;
66 LPITEMIDLIST pidl;
67 IImageList *icon_list;
68 DWORD advise_cookie;
69 } explorer_info;
71 enum
73 BACK_BUTTON,FORWARD_BUTTON,UP_BUTTON
76 typedef struct
78 IExplorerBrowserEvents IExplorerBrowserEvents_iface;
79 explorer_info* info;
80 LONG ref;
81 } IExplorerBrowserEventsImpl;
83 static IExplorerBrowserEventsImpl *impl_from_IExplorerBrowserEvents(IExplorerBrowserEvents *iface)
85 return CONTAINING_RECORD(iface, IExplorerBrowserEventsImpl, IExplorerBrowserEvents_iface);
88 static HRESULT WINAPI IExplorerBrowserEventsImpl_fnQueryInterface(IExplorerBrowserEvents *iface, REFIID riid, void **ppvObject)
90 return E_NOINTERFACE;
93 static ULONG WINAPI IExplorerBrowserEventsImpl_fnAddRef(IExplorerBrowserEvents *iface)
95 IExplorerBrowserEventsImpl *This = impl_from_IExplorerBrowserEvents(iface);
96 return InterlockedIncrement(&This->ref);
99 static ULONG WINAPI IExplorerBrowserEventsImpl_fnRelease(IExplorerBrowserEvents *iface)
101 IExplorerBrowserEventsImpl *This = impl_from_IExplorerBrowserEvents(iface);
102 ULONG ref = InterlockedDecrement(&This->ref);
103 if(!ref)
104 HeapFree(GetProcessHeap(),0,This);
105 return ref;
108 static BOOL create_combobox_item(IShellFolder *folder, LPCITEMIDLIST pidl, IImageList *icon_list, COMBOBOXEXITEMW *item)
110 STRRET strret;
111 HRESULT hres;
112 IExtractIconW *extract_icon;
113 UINT reserved;
114 WCHAR icon_file[MAX_PATH];
115 INT icon_index;
116 UINT icon_flags;
117 HICON icon;
118 strret.uType=STRRET_WSTR;
119 hres = IShellFolder_GetDisplayNameOf(folder,pidl,SHGDN_FORADDRESSBAR,&strret);
120 if(FAILED(hres))
122 WINE_WARN("Could not get name for pidl\n");
123 return FALSE;
125 switch(strret.uType)
127 case STRRET_WSTR:
128 item->pszText = strret.u.pOleStr;
129 break;
130 default:
131 WINE_FIXME("Unimplemented STRRET type:%u\n",strret.uType);
132 break;
134 hres = IShellFolder_GetUIObjectOf(folder,NULL,1,&pidl,&IID_IExtractIconW,
135 &reserved,(void**)&extract_icon);
136 if(SUCCEEDED(hres))
138 item->mask |= CBEIF_IMAGE;
139 IExtractIconW_GetIconLocation(extract_icon,GIL_FORSHELL,icon_file,
140 sizeof(icon_file)/sizeof(WCHAR),
141 &icon_index,&icon_flags);
142 IExtractIconW_Extract(extract_icon,icon_file,icon_index,NULL,&icon,20);
143 item->iImage = ImageList_AddIcon((HIMAGELIST)icon_list,icon);
144 IExtractIconW_Release(extract_icon);
146 else
148 item->mask &= ~CBEIF_IMAGE;
149 WINE_WARN("Could not get an icon for %s\n",wine_dbgstr_w(item->pszText));
151 return TRUE;
154 static void update_path_box(explorer_info *info)
156 COMBOBOXEXITEMW item;
157 COMBOBOXEXITEMW main_item;
158 IShellFolder *desktop;
159 IPersistFolder2 *persist;
160 LPITEMIDLIST desktop_pidl;
161 IEnumIDList *ids;
163 ImageList_Remove((HIMAGELIST)info->icon_list,-1);
164 SendMessageW(info->path_box,CB_RESETCONTENT,0,0);
165 SHGetDesktopFolder(&desktop);
166 IShellFolder_QueryInterface(desktop,&IID_IPersistFolder2,(void**)&persist);
167 IPersistFolder2_GetCurFolder(persist,&desktop_pidl);
168 IPersistFolder2_Release(persist);
169 persist = NULL;
170 /*Add Desktop*/
171 item.iItem = -1;
172 item.mask = CBEIF_TEXT | CBEIF_INDENT | CBEIF_LPARAM;
173 item.iIndent = 0;
174 create_combobox_item(desktop,desktop_pidl,info->icon_list,&item);
175 item.lParam = (LPARAM)desktop_pidl;
176 SendMessageW(info->path_box,CBEM_INSERTITEMW,0,(LPARAM)&item);
177 if(ILIsEqual(info->pidl,desktop_pidl))
178 main_item = item;
179 else
180 CoTaskMemFree(item.pszText);
181 /*Add all direct subfolders of Desktop*/
182 if(SUCCEEDED(IShellFolder_EnumObjects(desktop,NULL,SHCONTF_FOLDERS,&ids))
183 && ids!=NULL)
185 LPITEMIDLIST curr_pidl=NULL;
186 HRESULT hres;
188 item.iIndent = 1;
189 while(1)
191 ILFree(curr_pidl);
192 curr_pidl=NULL;
193 hres = IEnumIDList_Next(ids,1,&curr_pidl,NULL);
194 if(FAILED(hres) || hres == S_FALSE)
195 break;
196 if(!create_combobox_item(desktop,curr_pidl,info->icon_list,&item))
197 WINE_WARN("Could not create a combobox item\n");
198 else
200 LPITEMIDLIST full_pidl = ILCombine(desktop_pidl,curr_pidl);
201 item.lParam = (LPARAM)full_pidl;
202 SendMessageW(info->path_box,CBEM_INSERTITEMW,0,(LPARAM)&item);
203 if(ILIsEqual(full_pidl,info->pidl))
204 main_item = item;
205 else if(ILIsParent(full_pidl,info->pidl,FALSE))
207 /*add all parents of the pidl passed in*/
208 LPITEMIDLIST next_pidl = ILFindChild(full_pidl,info->pidl);
209 IShellFolder *curr_folder = NULL, *temp;
210 hres = IShellFolder_BindToObject(desktop,curr_pidl,NULL,
211 &IID_IShellFolder,
212 (void**)&curr_folder);
213 if(FAILED(hres))
214 WINE_WARN("Could not get an IShellFolder\n");
215 while(!ILIsEmpty(next_pidl))
217 LPITEMIDLIST first = ILCloneFirst(next_pidl);
218 CoTaskMemFree(item.pszText);
219 if(!create_combobox_item(curr_folder,first,
220 info->icon_list,&item))
222 WINE_WARN("Could not create a combobox item\n");
223 break;
225 ++item.iIndent;
226 full_pidl = ILCombine(full_pidl,first);
227 item.lParam = (LPARAM)full_pidl;
228 SendMessageW(info->path_box,CBEM_INSERTITEMW,0,(LPARAM)&item);
229 temp=NULL;
230 hres = IShellFolder_BindToObject(curr_folder,first,NULL,
231 &IID_IShellFolder,
232 (void**)&temp);
233 if(FAILED(hres))
235 WINE_WARN("Could not get an IShellFolder\n");
236 break;
238 IShellFolder_Release(curr_folder);
239 curr_folder = temp;
241 ILFree(first);
242 next_pidl = ILGetNext(next_pidl);
244 memcpy(&main_item,&item,sizeof(item));
245 if(curr_folder)
246 IShellFolder_Release(curr_folder);
247 item.iIndent = 1;
249 else
250 CoTaskMemFree(item.pszText);
253 ILFree(curr_pidl);
254 IEnumIDList_Release(ids);
256 else
257 WINE_WARN("Could not enumerate the desktop\n");
258 SendMessageW(info->path_box,CBEM_SETITEMW,0,(LPARAM)&main_item);
259 CoTaskMemFree(main_item.pszText);
262 static HRESULT WINAPI IExplorerBrowserEventsImpl_fnOnNavigationComplete(IExplorerBrowserEvents *iface, PCIDLIST_ABSOLUTE pidl)
264 IExplorerBrowserEventsImpl *This = impl_from_IExplorerBrowserEvents(iface);
265 ILFree(This->info->pidl);
266 This->info->pidl = ILClone(pidl);
267 update_path_box(This->info);
268 return S_OK;
271 static HRESULT WINAPI IExplorerBrowserEventsImpl_fnOnNavigationFailed(IExplorerBrowserEvents *iface, PCIDLIST_ABSOLUTE pidl)
273 return S_OK;
276 static HRESULT WINAPI IExplorerBrowserEventsImpl_fnOnNavigationPending(IExplorerBrowserEvents *iface, PCIDLIST_ABSOLUTE pidl)
278 return S_OK;
281 static HRESULT WINAPI IExplorerBrowserEventsImpl_fnOnViewCreated(IExplorerBrowserEvents *iface, IShellView *psv)
283 return S_OK;
286 static IExplorerBrowserEventsVtbl vt_IExplorerBrowserEvents =
288 IExplorerBrowserEventsImpl_fnQueryInterface,
289 IExplorerBrowserEventsImpl_fnAddRef,
290 IExplorerBrowserEventsImpl_fnRelease,
291 IExplorerBrowserEventsImpl_fnOnNavigationPending,
292 IExplorerBrowserEventsImpl_fnOnViewCreated,
293 IExplorerBrowserEventsImpl_fnOnNavigationComplete,
294 IExplorerBrowserEventsImpl_fnOnNavigationFailed
297 static IExplorerBrowserEvents *make_explorer_events(explorer_info *info)
299 IExplorerBrowserEventsImpl *ret
300 = HeapAlloc(GetProcessHeap(), 0, sizeof(IExplorerBrowserEventsImpl));
301 ret->IExplorerBrowserEvents_iface.lpVtbl = &vt_IExplorerBrowserEvents;
302 ret->info = info;
303 ret->ref = 1;
304 SHGetImageList(SHIL_SMALL,&IID_IImageList,(void**)&(ret->info->icon_list));
305 SendMessageW(info->path_box,CBEM_SETIMAGELIST,0,(LPARAM)ret->info->icon_list);
306 return &ret->IExplorerBrowserEvents_iface;
309 static void make_explorer_window(IShellFolder* startFolder)
311 RECT explorerRect;
312 HWND rebar,nav_toolbar;
313 FOLDERSETTINGS fs;
314 IExplorerBrowserEvents *events;
315 explorer_info *info;
316 HRESULT hres;
317 WCHAR explorer_title[100];
318 WCHAR pathbox_label[50];
319 TBADDBITMAP bitmap_info;
320 TBBUTTON nav_buttons[3];
321 int hist_offset,view_offset;
322 REBARBANDINFOW band_info;
323 memset(nav_buttons,0,sizeof(nav_buttons));
324 LoadStringW(explorer_hInstance,IDS_EXPLORER_TITLE,explorer_title,
325 sizeof(explorer_title)/sizeof(WCHAR));
326 LoadStringW(explorer_hInstance,IDS_PATHBOX_LABEL,pathbox_label,
327 sizeof(pathbox_label)/sizeof(WCHAR));
328 info = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(explorer_info));
329 if(!info)
331 WINE_ERR("Could not allocate a explorer_info struct\n");
332 return;
334 hres = CoCreateInstance(&CLSID_ExplorerBrowser,NULL,CLSCTX_INPROC_SERVER,
335 &IID_IExplorerBrowser,(LPVOID*)&info->browser);
336 if(FAILED(hres))
338 WINE_ERR("Could not obtain an instance of IExplorerBrowser\n");
339 HeapFree(GetProcessHeap(),0,info);
340 return;
342 info->rebar_height=0;
343 info->main_window
344 = CreateWindowW(EXPLORER_CLASS,explorer_title,WS_OVERLAPPEDWINDOW,
345 CW_USEDEFAULT,CW_USEDEFAULT,DEFAULT_WIDTH,
346 DEFAULT_HEIGHT,NULL,NULL,explorer_hInstance,NULL);
348 fs.ViewMode = FVM_DETAILS;
349 fs.fFlags = FWF_AUTOARRANGE;
350 explorerRect.left = 0;
351 explorerRect.top = 0;
352 explorerRect.right = DEFAULT_WIDTH;
353 explorerRect.bottom = DEFAULT_HEIGHT;
355 IExplorerBrowser_Initialize(info->browser,info->main_window,&explorerRect,&fs);
356 IExplorerBrowser_SetOptions(info->browser,EBO_SHOWFRAMES);
357 SetWindowLongPtrW(info->main_window,EXPLORER_INFO_INDEX,(LONG_PTR)info);
359 /*setup navbar*/
360 rebar = CreateWindowExW(WS_EX_TOOLWINDOW,REBARCLASSNAMEW,NULL,
361 WS_CHILD|WS_VISIBLE|RBS_VARHEIGHT|CCS_TOP|CCS_NODIVIDER,
362 0,0,0,0,info->main_window,NULL,explorer_hInstance,NULL);
363 nav_toolbar
364 = CreateWindowExW(TBSTYLE_EX_MIXEDBUTTONS,TOOLBARCLASSNAMEW,NULL,
365 WS_CHILD|WS_VISIBLE|TBSTYLE_FLAT,0,0,0,0,rebar,NULL,
366 explorer_hInstance,NULL);
368 bitmap_info.hInst = HINST_COMMCTRL;
369 bitmap_info.nID = IDB_HIST_LARGE_COLOR;
370 hist_offset= SendMessageW(nav_toolbar,TB_ADDBITMAP,0,(LPARAM)&bitmap_info);
371 bitmap_info.nID = IDB_VIEW_LARGE_COLOR;
372 view_offset= SendMessageW(nav_toolbar,TB_ADDBITMAP,0,(LPARAM)&bitmap_info);
374 nav_buttons[0].iBitmap=hist_offset+HIST_BACK;
375 nav_buttons[0].idCommand=BACK_BUTTON;
376 nav_buttons[0].fsState=TBSTATE_ENABLED;
377 nav_buttons[0].fsStyle=BTNS_BUTTON|BTNS_AUTOSIZE;
378 nav_buttons[1].iBitmap=hist_offset+HIST_FORWARD;
379 nav_buttons[1].idCommand=FORWARD_BUTTON;
380 nav_buttons[1].fsState=TBSTATE_ENABLED;
381 nav_buttons[1].fsStyle=BTNS_BUTTON|BTNS_AUTOSIZE;
382 nav_buttons[2].iBitmap=view_offset+VIEW_PARENTFOLDER;
383 nav_buttons[2].idCommand=UP_BUTTON;
384 nav_buttons[2].fsState=TBSTATE_ENABLED;
385 nav_buttons[2].fsStyle=BTNS_BUTTON|BTNS_AUTOSIZE;
386 SendMessageW(nav_toolbar,TB_BUTTONSTRUCTSIZE,sizeof(TBBUTTON),0);
387 SendMessageW(nav_toolbar,TB_ADDBUTTONSW,sizeof(nav_buttons)/sizeof(TBBUTTON),(LPARAM)nav_buttons);
389 band_info.cbSize = sizeof(band_info);
390 band_info.fMask = RBBIM_STYLE|RBBIM_CHILD|RBBIM_CHILDSIZE|RBBIM_SIZE;
391 band_info.hwndChild = nav_toolbar;
392 band_info.fStyle=RBBS_GRIPPERALWAYS|RBBS_CHILDEDGE;
393 band_info.cyChild=NAV_TOOLBAR_HEIGHT;
394 band_info.cx=0;
395 band_info.cyMinChild=NAV_TOOLBAR_HEIGHT;
396 band_info.cxMinChild=0;
397 SendMessageW(rebar,RB_INSERTBANDW,-1,(LPARAM)&band_info);
398 info->path_box = CreateWindowW(WC_COMBOBOXEXW,PATH_BOX_NAME,
399 WS_CHILD | WS_VISIBLE | CBS_DROPDOWN,
400 0,0,DEFAULT_WIDTH,PATHBOX_HEIGHT,rebar,NULL,
401 explorer_hInstance,NULL);
402 band_info.cyChild=PATHBOX_HEIGHT;
403 band_info.cx=0;
404 band_info.cyMinChild=PATHBOX_HEIGHT;
405 band_info.cxMinChild=0;
406 band_info.fMask|=RBBIM_TEXT;
407 band_info.lpText=pathbox_label;
408 band_info.fStyle|=RBBS_BREAK;
409 band_info.hwndChild=info->path_box;
410 SendMessageW(rebar,RB_INSERTBANDW,-1,(LPARAM)&band_info);
411 events = make_explorer_events(info);
412 IExplorerBrowser_Advise(info->browser,events,&info->advise_cookie);
413 IExplorerBrowser_BrowseToObject(info->browser,(IUnknown*)startFolder,
414 SBSP_ABSOLUTE);
415 ShowWindow(info->main_window,SW_SHOWDEFAULT);
416 UpdateWindow(info->main_window);
417 IExplorerBrowserEvents_Release(events);
420 static void update_window_size(explorer_info *info, int height, int width)
422 RECT new_rect;
423 new_rect.left = 0;
424 new_rect.top = info->rebar_height;
425 new_rect.right = width;
426 new_rect.bottom = height;
427 IExplorerBrowser_SetRect(info->browser,NULL,new_rect);
430 static void do_exit(int code)
432 OleUninitialize();
433 ExitProcess(code);
436 static LRESULT explorer_on_end_edit(explorer_info *info,NMCBEENDEDITW *edit_info)
438 LPITEMIDLIST pidl = NULL;
440 WINE_TRACE("iWhy=%x\n",edit_info->iWhy);
441 switch(edit_info->iWhy)
443 case CBENF_DROPDOWN:
444 if(edit_info->iNewSelection!=CB_ERR)
445 pidl = (LPITEMIDLIST)SendMessageW(edit_info->hdr.hwndFrom,
446 CB_GETITEMDATA,
447 edit_info->iNewSelection,0);
448 break;
449 case CBENF_RETURN:
451 WCHAR path[MAX_PATH];
452 HWND edit_ctrl = (HWND)SendMessageW(edit_info->hdr.hwndFrom,
453 CBEM_GETEDITCONTROL,0,0);
454 *((WORD*)path)=MAX_PATH;
455 SendMessageW(edit_ctrl,EM_GETLINE,0,(LPARAM)path);
456 pidl = ILCreateFromPathW(path);
457 break;
459 case CBENF_ESCAPE:
460 /*make sure the that the path box resets*/
461 update_path_box(info);
462 return 0;
463 default:
464 return 0;
466 if(pidl)
467 IExplorerBrowser_BrowseToIDList(info->browser,pidl,SBSP_ABSOLUTE);
468 if(edit_info->iWhy==CBENF_RETURN)
469 ILFree(pidl);
470 return 0;
473 static LRESULT update_rebar_size(explorer_info* info,NMRBAUTOSIZE *size_info)
475 RECT new_rect;
476 RECT window_rect;
477 info->rebar_height = size_info->rcTarget.bottom-size_info->rcTarget.top;
478 GetWindowRect(info->main_window,&window_rect);
479 new_rect.left = 0;
480 new_rect.top = info->rebar_height;
481 new_rect.right = window_rect.right-window_rect.left;
482 new_rect.bottom = window_rect.bottom-window_rect.top;
483 IExplorerBrowser_SetRect(info->browser,NULL,new_rect);
484 return 0;
487 static LRESULT explorer_on_notify(explorer_info* info,NMHDR* notification)
489 WINE_TRACE("code=%i\n",notification->code);
490 switch(notification->code)
492 case CBEN_BEGINEDIT:
494 WCHAR path[MAX_PATH];
495 HWND edit_ctrl = (HWND)SendMessageW(notification->hwndFrom,
496 CBEM_GETEDITCONTROL,0,0);
497 SHGetPathFromIDListW(info->pidl,path);
498 SetWindowTextW(edit_ctrl,path);
499 break;
501 case CBEN_ENDEDITA:
503 NMCBEENDEDITA *edit_info_a = (NMCBEENDEDITA*)notification;
504 NMCBEENDEDITW edit_info_w;
505 edit_info_w.hdr = edit_info_a->hdr;
506 edit_info_w.fChanged = edit_info_a->fChanged;
507 edit_info_w.iNewSelection = edit_info_a->iNewSelection;
508 MultiByteToWideChar(CP_ACP,0,edit_info_a->szText,-1,
509 edit_info_w.szText,CBEMAXSTRLEN);
510 edit_info_w.iWhy = edit_info_a->iWhy;
511 return explorer_on_end_edit(info,&edit_info_w);
513 case CBEN_ENDEDITW:
514 return explorer_on_end_edit(info,(NMCBEENDEDITW*)notification);
515 case CBEN_DELETEITEM:
517 NMCOMBOBOXEXW *entry = (NMCOMBOBOXEXW*)notification;
518 if(entry->ceItem.lParam)
519 ILFree((LPITEMIDLIST)entry->ceItem.lParam);
520 break;
522 case RBN_AUTOSIZE:
523 return update_rebar_size(info,(NMRBAUTOSIZE*)notification);
524 default:
525 break;
527 return 0;
530 static LRESULT CALLBACK explorer_wnd_proc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
532 explorer_info *info
533 = (explorer_info*)GetWindowLongPtrW(hwnd,EXPLORER_INFO_INDEX);
534 IExplorerBrowser *browser = NULL;
536 WINE_TRACE("(hwnd=%p,uMsg=%u,wParam=%lx,lParam=%lx)\n",hwnd,uMsg,wParam,lParam);
537 if(info)
538 browser = info->browser;
539 switch(uMsg)
541 case WM_DESTROY:
542 IExplorerBrowser_Unadvise(browser,info->advise_cookie);
543 IExplorerBrowser_Destroy(browser);
544 IExplorerBrowser_Release(browser);
545 ILFree(info->pidl);
546 IImageList_Release(info->icon_list);
547 HeapFree(GetProcessHeap(),0,info);
548 SetWindowLongPtrW(hwnd,EXPLORER_INFO_INDEX,0);
549 PostQuitMessage(0);
550 break;
551 case WM_QUIT:
552 do_exit(wParam);
553 case WM_NOTIFY:
554 return explorer_on_notify(info,(NMHDR*)lParam);
555 case WM_COMMAND:
556 if(HIWORD(wParam)==BN_CLICKED)
558 switch(LOWORD(wParam))
560 case BACK_BUTTON:
561 IExplorerBrowser_BrowseToObject(browser,NULL,SBSP_NAVIGATEBACK);
562 break;
563 case FORWARD_BUTTON:
564 IExplorerBrowser_BrowseToObject(browser,NULL,SBSP_NAVIGATEFORWARD);
565 break;
566 case UP_BUTTON:
567 IExplorerBrowser_BrowseToObject(browser,NULL,SBSP_PARENT);
568 break;
571 break;
572 case WM_SIZE:
573 update_window_size(info,HIWORD(lParam),LOWORD(lParam));
574 break;
575 default:
576 return DefWindowProcW(hwnd,uMsg,wParam,lParam);
578 return 0;
581 static void register_explorer_window_class(void)
583 WNDCLASSEXW window_class;
584 window_class.cbSize = sizeof(WNDCLASSEXW);
585 window_class.style = 0;
586 window_class.cbClsExtra = 0;
587 window_class.cbWndExtra = sizeof(LONG_PTR);
588 window_class.lpfnWndProc = explorer_wnd_proc;
589 window_class.hInstance = explorer_hInstance;
590 window_class.hIcon = NULL;
591 window_class.hCursor = NULL;
592 window_class.hbrBackground = (HBRUSH)COLOR_BACKGROUND;
593 window_class.lpszMenuName = NULL;
594 window_class.lpszClassName = EXPLORER_CLASS;
595 window_class.hIconSm = NULL;
596 RegisterClassExW(&window_class);
599 static IShellFolder* get_starting_shell_folder(parameters_struct* params)
601 IShellFolder* desktop,*folder;
602 LPITEMIDLIST root_pidl;
603 HRESULT hres;
605 SHGetDesktopFolder(&desktop);
606 if (!params->root[0])
608 return desktop;
610 hres = IShellFolder_ParseDisplayName(desktop,NULL,NULL,
611 params->root,NULL,
612 &root_pidl,NULL);
614 if(FAILED(hres))
616 return desktop;
618 hres = IShellFolder_BindToObject(desktop,root_pidl,NULL,
619 &IID_IShellFolder,
620 (void**)&folder);
621 if(FAILED(hres))
623 return desktop;
625 IShellFolder_Release(desktop);
626 return folder;
629 static int copy_path_string(LPWSTR target, LPWSTR source)
631 INT i = 0;
633 while (isspaceW(*source)) source++;
635 if (*source == '\"')
637 source ++;
638 while (*source != '\"') target[i++] = *source++;
639 target[i] = 0;
640 source ++;
641 i+=2;
643 else
645 while (*source && !isspaceW(*source)) target[i++] = *source++;
646 target[i] = 0;
648 return i;
652 static void copy_path_root(LPWSTR root, LPWSTR path)
654 LPWSTR p,p2;
655 INT i = 0;
657 p = path;
658 while (*p!=0)
659 p++;
661 while (*p!='\\' && p > path)
662 p--;
664 if (p == path)
665 return;
667 p2 = path;
668 while (p2 != p)
670 root[i] = *p2;
671 i++;
672 p2++;
674 root[i] = 0;
678 * Command Line parameters are:
679 * [/n] Opens in single-paned view for each selected items. This is default
680 * [/e,] Uses Windows Explorer View
681 * [/root,object] Specifies the root level of the view
682 * [/select,object] parent folder is opened and specified object is selected
684 static void parse_command_line(LPWSTR commandline,parameters_struct *parameters)
686 static const WCHAR arg_n[] = {'/','n'};
687 static const WCHAR arg_e[] = {'/','e',','};
688 static const WCHAR arg_root[] = {'/','r','o','o','t',','};
689 static const WCHAR arg_select[] = {'/','s','e','l','e','c','t',','};
690 static const WCHAR arg_desktop[] = {'/','d','e','s','k','t','o','p'};
692 LPWSTR p, p2;
694 p2 = commandline;
695 p = strchrW(commandline,'/');
696 while(p)
698 if (strncmpW(p, arg_n, sizeof(arg_n)/sizeof(WCHAR))==0)
700 parameters->explorer_mode = FALSE;
701 p += sizeof(arg_n)/sizeof(WCHAR);
703 else if (strncmpW(p, arg_e, sizeof(arg_e)/sizeof(WCHAR))==0)
705 parameters->explorer_mode = TRUE;
706 p += sizeof(arg_e)/sizeof(WCHAR);
708 else if (strncmpW(p, arg_root, sizeof(arg_root)/sizeof(WCHAR))==0)
710 p += sizeof(arg_root)/sizeof(WCHAR);
711 p+=copy_path_string(parameters->root,p);
713 else if (strncmpW(p, arg_select, sizeof(arg_select)/sizeof(WCHAR))==0)
715 p += sizeof(arg_select)/sizeof(WCHAR);
716 p+=copy_path_string(parameters->selection,p);
717 if (!parameters->root[0])
718 copy_path_root(parameters->root,
719 parameters->selection);
721 else if (strncmpW(p, arg_desktop, sizeof(arg_desktop)/sizeof(WCHAR))==0)
723 p += sizeof(arg_desktop)/sizeof(WCHAR);
724 manage_desktop( p ); /* the rest of the command line is handled by desktop mode */
726 else p++;
728 p2 = p;
729 p = strchrW(p,'/');
731 if (p2 && *p2)
733 /* left over command line is generally the path to be opened */
734 copy_path_string(parameters->root,p2);
738 int WINAPI wWinMain(HINSTANCE hinstance,
739 HINSTANCE previnstance,
740 LPWSTR cmdline,
741 int cmdshow)
744 parameters_struct parameters;
745 HRESULT hres;
746 MSG msg;
747 IShellFolder *folder;
748 INITCOMMONCONTROLSEX init_info;
750 memset(&parameters,0,sizeof(parameters));
751 explorer_hInstance = hinstance;
752 parse_command_line(cmdline,&parameters);
753 hres = OleInitialize(NULL);
754 if(FAILED(hres))
756 WINE_ERR("Could not initialize COM\n");
757 ExitProcess(EXIT_FAILURE);
759 if(parameters.root[0] && !PathIsDirectoryW(parameters.root))
760 if(ShellExecuteW(NULL,NULL,parameters.root,NULL,NULL,SW_SHOWDEFAULT) > (HINSTANCE)32)
761 ExitProcess(EXIT_SUCCESS);
762 init_info.dwSize = sizeof(INITCOMMONCONTROLSEX);
763 init_info.dwICC = ICC_USEREX_CLASSES | ICC_BAR_CLASSES | ICC_COOL_CLASSES;
764 if(!InitCommonControlsEx(&init_info))
766 WINE_ERR("Could not initialize Comctl\n");
767 ExitProcess(EXIT_FAILURE);
769 register_explorer_window_class();
770 folder = get_starting_shell_folder(&parameters);
771 make_explorer_window(folder);
772 IShellFolder_Release(folder);
773 while(GetMessageW( &msg, NULL, 0, 0 ) != 0)
775 TranslateMessage(&msg);
776 DispatchMessageW(&msg);
778 return 0;