gdi32: Fix arguments for OSMesaMakeCurrent when using 16 bit formats.
[wine.git] / programs / explorer / explorer.c
bloba4f93bca544f9c11b83a9d66939065d32e39d4fd
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 <shellapi.h>
34 #include <shobjidl.h>
35 #include <shlobj.h>
36 #include <shlwapi.h>
37 #include <commoncontrols.h>
38 #include <commctrl.h>
40 WINE_DEFAULT_DEBUG_CHANNEL(explorer);
42 #define EXPLORER_INFO_INDEX 0
44 #define NAV_TOOLBAR_HEIGHT 30
45 #define PATHBOX_HEIGHT 24
47 #define DEFAULT_WIDTH 640
48 #define DEFAULT_HEIGHT 480
51 static const WCHAR EXPLORER_CLASS[] = {'W','I','N','E','_','E','X','P','L','O','R','E','R','\0'};
52 static const WCHAR PATH_BOX_NAME[] = {'\0'};
54 HINSTANCE explorer_hInstance;
56 typedef struct parametersTAG {
57 BOOL explorer_mode;
58 WCHAR root[MAX_PATH];
59 WCHAR selection[MAX_PATH];
60 } parameters_struct;
62 typedef struct
64 IExplorerBrowser *browser;
65 HWND main_window,path_box;
66 INT rebar_height;
67 LPITEMIDLIST pidl;
68 IImageList *icon_list;
69 DWORD advise_cookie;
70 } explorer_info;
72 enum
74 BACK_BUTTON,FORWARD_BUTTON,UP_BUTTON
77 typedef struct
79 IExplorerBrowserEvents IExplorerBrowserEvents_iface;
80 explorer_info* info;
81 LONG ref;
82 } IExplorerBrowserEventsImpl;
84 static IExplorerBrowserEventsImpl *impl_from_IExplorerBrowserEvents(IExplorerBrowserEvents *iface)
86 return CONTAINING_RECORD(iface, IExplorerBrowserEventsImpl, IExplorerBrowserEvents_iface);
89 static HRESULT WINAPI IExplorerBrowserEventsImpl_fnQueryInterface(IExplorerBrowserEvents *iface, REFIID riid, void **ppvObject)
91 return E_NOINTERFACE;
94 static ULONG WINAPI IExplorerBrowserEventsImpl_fnAddRef(IExplorerBrowserEvents *iface)
96 IExplorerBrowserEventsImpl *This = impl_from_IExplorerBrowserEvents(iface);
97 return InterlockedIncrement(&This->ref);
100 static ULONG WINAPI IExplorerBrowserEventsImpl_fnRelease(IExplorerBrowserEvents *iface)
102 IExplorerBrowserEventsImpl *This = impl_from_IExplorerBrowserEvents(iface);
103 ULONG ref = InterlockedDecrement(&This->ref);
104 if(!ref)
105 HeapFree(GetProcessHeap(),0,This);
106 return ref;
109 static BOOL create_combobox_item(IShellFolder *folder, LPCITEMIDLIST pidl, IImageList *icon_list, COMBOBOXEXITEMW *item)
111 STRRET strret;
112 HRESULT hres;
113 IExtractIconW *extract_icon;
114 UINT reserved;
115 WCHAR icon_file[MAX_PATH];
116 INT icon_index;
117 UINT icon_flags;
118 HICON icon;
119 strret.uType=STRRET_WSTR;
120 hres = IShellFolder_GetDisplayNameOf(folder,pidl,SHGDN_FORADDRESSBAR,&strret);
121 if(SUCCEEDED(hres))
122 hres = StrRetToStrW(&strret, pidl, &item->pszText);
123 if(FAILED(hres))
125 WINE_WARN("Could not get name for pidl\n");
126 return FALSE;
128 hres = IShellFolder_GetUIObjectOf(folder,NULL,1,&pidl,&IID_IExtractIconW,
129 &reserved,(void**)&extract_icon);
130 if(SUCCEEDED(hres))
132 item->mask |= CBEIF_IMAGE;
133 IExtractIconW_GetIconLocation(extract_icon,GIL_FORSHELL,icon_file,
134 sizeof(icon_file)/sizeof(WCHAR),
135 &icon_index,&icon_flags);
136 IExtractIconW_Extract(extract_icon,icon_file,icon_index,NULL,&icon,20);
137 item->iImage = ImageList_AddIcon((HIMAGELIST)icon_list,icon);
138 IExtractIconW_Release(extract_icon);
140 else
142 item->mask &= ~CBEIF_IMAGE;
143 WINE_WARN("Could not get an icon for %s\n",wine_dbgstr_w(item->pszText));
145 return TRUE;
148 static void update_path_box(explorer_info *info)
150 COMBOBOXEXITEMW item;
151 COMBOBOXEXITEMW main_item;
152 IShellFolder *desktop;
153 IPersistFolder2 *persist;
154 LPITEMIDLIST desktop_pidl;
155 IEnumIDList *ids;
157 ImageList_Remove((HIMAGELIST)info->icon_list,-1);
158 SendMessageW(info->path_box,CB_RESETCONTENT,0,0);
159 SHGetDesktopFolder(&desktop);
160 IShellFolder_QueryInterface(desktop,&IID_IPersistFolder2,(void**)&persist);
161 IPersistFolder2_GetCurFolder(persist,&desktop_pidl);
162 IPersistFolder2_Release(persist);
163 persist = NULL;
164 /*Add Desktop*/
165 item.iItem = -1;
166 item.mask = CBEIF_TEXT | CBEIF_INDENT | CBEIF_LPARAM;
167 item.iIndent = 0;
168 create_combobox_item(desktop,desktop_pidl,info->icon_list,&item);
169 item.lParam = (LPARAM)desktop_pidl;
170 SendMessageW(info->path_box,CBEM_INSERTITEMW,0,(LPARAM)&item);
171 if(ILIsEqual(info->pidl,desktop_pidl))
172 main_item = item;
173 else
174 CoTaskMemFree(item.pszText);
175 /*Add all direct subfolders of Desktop*/
176 if(SUCCEEDED(IShellFolder_EnumObjects(desktop,NULL,SHCONTF_FOLDERS,&ids))
177 && ids!=NULL)
179 LPITEMIDLIST curr_pidl=NULL;
180 HRESULT hres;
182 item.iIndent = 1;
183 while(1)
185 ILFree(curr_pidl);
186 curr_pidl=NULL;
187 hres = IEnumIDList_Next(ids,1,&curr_pidl,NULL);
188 if(FAILED(hres) || hres == S_FALSE)
189 break;
190 if(!create_combobox_item(desktop,curr_pidl,info->icon_list,&item))
191 WINE_WARN("Could not create a combobox item\n");
192 else
194 LPITEMIDLIST full_pidl = ILCombine(desktop_pidl,curr_pidl);
195 item.lParam = (LPARAM)full_pidl;
196 SendMessageW(info->path_box,CBEM_INSERTITEMW,0,(LPARAM)&item);
197 if(ILIsEqual(full_pidl,info->pidl))
198 main_item = item;
199 else if(ILIsParent(full_pidl,info->pidl,FALSE))
201 /*add all parents of the pidl passed in*/
202 LPITEMIDLIST next_pidl = ILFindChild(full_pidl,info->pidl);
203 IShellFolder *curr_folder = NULL, *temp;
204 hres = IShellFolder_BindToObject(desktop,curr_pidl,NULL,
205 &IID_IShellFolder,
206 (void**)&curr_folder);
207 if(FAILED(hres))
208 WINE_WARN("Could not get an IShellFolder\n");
209 while(!ILIsEmpty(next_pidl))
211 LPITEMIDLIST first = ILCloneFirst(next_pidl);
212 CoTaskMemFree(item.pszText);
213 if(!create_combobox_item(curr_folder,first,
214 info->icon_list,&item))
216 WINE_WARN("Could not create a combobox item\n");
217 break;
219 ++item.iIndent;
220 full_pidl = ILCombine(full_pidl,first);
221 item.lParam = (LPARAM)full_pidl;
222 SendMessageW(info->path_box,CBEM_INSERTITEMW,0,(LPARAM)&item);
223 temp=NULL;
224 hres = IShellFolder_BindToObject(curr_folder,first,NULL,
225 &IID_IShellFolder,
226 (void**)&temp);
227 if(FAILED(hres))
229 WINE_WARN("Could not get an IShellFolder\n");
230 break;
232 IShellFolder_Release(curr_folder);
233 curr_folder = temp;
235 ILFree(first);
236 next_pidl = ILGetNext(next_pidl);
238 memcpy(&main_item,&item,sizeof(item));
239 if(curr_folder)
240 IShellFolder_Release(curr_folder);
241 item.iIndent = 1;
243 else
244 CoTaskMemFree(item.pszText);
247 ILFree(curr_pidl);
248 IEnumIDList_Release(ids);
250 else
251 WINE_WARN("Could not enumerate the desktop\n");
252 SendMessageW(info->path_box,CBEM_SETITEMW,0,(LPARAM)&main_item);
253 CoTaskMemFree(main_item.pszText);
256 static HRESULT WINAPI IExplorerBrowserEventsImpl_fnOnNavigationComplete(IExplorerBrowserEvents *iface, PCIDLIST_ABSOLUTE pidl)
258 IExplorerBrowserEventsImpl *This = impl_from_IExplorerBrowserEvents(iface);
259 ILFree(This->info->pidl);
260 This->info->pidl = ILClone(pidl);
261 update_path_box(This->info);
262 return S_OK;
265 static HRESULT WINAPI IExplorerBrowserEventsImpl_fnOnNavigationFailed(IExplorerBrowserEvents *iface, PCIDLIST_ABSOLUTE pidl)
267 return S_OK;
270 static HRESULT WINAPI IExplorerBrowserEventsImpl_fnOnNavigationPending(IExplorerBrowserEvents *iface, PCIDLIST_ABSOLUTE pidl)
272 return S_OK;
275 static HRESULT WINAPI IExplorerBrowserEventsImpl_fnOnViewCreated(IExplorerBrowserEvents *iface, IShellView *psv)
277 return S_OK;
280 static IExplorerBrowserEventsVtbl vt_IExplorerBrowserEvents =
282 IExplorerBrowserEventsImpl_fnQueryInterface,
283 IExplorerBrowserEventsImpl_fnAddRef,
284 IExplorerBrowserEventsImpl_fnRelease,
285 IExplorerBrowserEventsImpl_fnOnNavigationPending,
286 IExplorerBrowserEventsImpl_fnOnViewCreated,
287 IExplorerBrowserEventsImpl_fnOnNavigationComplete,
288 IExplorerBrowserEventsImpl_fnOnNavigationFailed
291 static IExplorerBrowserEvents *make_explorer_events(explorer_info *info)
293 IExplorerBrowserEventsImpl *ret
294 = HeapAlloc(GetProcessHeap(), 0, sizeof(IExplorerBrowserEventsImpl));
295 ret->IExplorerBrowserEvents_iface.lpVtbl = &vt_IExplorerBrowserEvents;
296 ret->info = info;
297 ret->ref = 1;
298 SHGetImageList(SHIL_SMALL,&IID_IImageList,(void**)&(ret->info->icon_list));
299 SendMessageW(info->path_box,CBEM_SETIMAGELIST,0,(LPARAM)ret->info->icon_list);
300 return &ret->IExplorerBrowserEvents_iface;
303 static void make_explorer_window(IShellFolder* startFolder)
305 RECT explorerRect;
306 HWND rebar,nav_toolbar;
307 FOLDERSETTINGS fs;
308 IExplorerBrowserEvents *events;
309 explorer_info *info;
310 HRESULT hres;
311 WCHAR explorer_title[100];
312 WCHAR pathbox_label[50];
313 TBADDBITMAP bitmap_info;
314 TBBUTTON nav_buttons[3];
315 int hist_offset,view_offset;
316 REBARBANDINFOW band_info;
317 memset(nav_buttons,0,sizeof(nav_buttons));
318 LoadStringW(explorer_hInstance,IDS_EXPLORER_TITLE,explorer_title,
319 sizeof(explorer_title)/sizeof(WCHAR));
320 LoadStringW(explorer_hInstance,IDS_PATHBOX_LABEL,pathbox_label,
321 sizeof(pathbox_label)/sizeof(WCHAR));
322 info = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(explorer_info));
323 if(!info)
325 WINE_ERR("Could not allocate an explorer_info struct\n");
326 return;
328 hres = CoCreateInstance(&CLSID_ExplorerBrowser,NULL,CLSCTX_INPROC_SERVER,
329 &IID_IExplorerBrowser,(LPVOID*)&info->browser);
330 if(FAILED(hres))
332 WINE_ERR("Could not obtain an instance of IExplorerBrowser\n");
333 HeapFree(GetProcessHeap(),0,info);
334 return;
336 info->rebar_height=0;
337 info->main_window
338 = CreateWindowW(EXPLORER_CLASS,explorer_title,WS_OVERLAPPEDWINDOW,
339 CW_USEDEFAULT,CW_USEDEFAULT,DEFAULT_WIDTH,
340 DEFAULT_HEIGHT,NULL,NULL,explorer_hInstance,NULL);
342 fs.ViewMode = FVM_DETAILS;
343 fs.fFlags = FWF_AUTOARRANGE;
344 explorerRect.left = 0;
345 explorerRect.top = 0;
346 explorerRect.right = DEFAULT_WIDTH;
347 explorerRect.bottom = DEFAULT_HEIGHT;
349 IExplorerBrowser_Initialize(info->browser,info->main_window,&explorerRect,&fs);
350 IExplorerBrowser_SetOptions(info->browser,EBO_SHOWFRAMES);
351 SetWindowLongPtrW(info->main_window,EXPLORER_INFO_INDEX,(LONG_PTR)info);
353 /*setup navbar*/
354 rebar = CreateWindowExW(WS_EX_TOOLWINDOW,REBARCLASSNAMEW,NULL,
355 WS_CHILD|WS_VISIBLE|RBS_VARHEIGHT|CCS_TOP|CCS_NODIVIDER,
356 0,0,0,0,info->main_window,NULL,explorer_hInstance,NULL);
357 nav_toolbar
358 = CreateWindowExW(TBSTYLE_EX_MIXEDBUTTONS,TOOLBARCLASSNAMEW,NULL,
359 WS_CHILD|WS_VISIBLE|TBSTYLE_FLAT,0,0,0,0,rebar,NULL,
360 explorer_hInstance,NULL);
362 bitmap_info.hInst = HINST_COMMCTRL;
363 bitmap_info.nID = IDB_HIST_LARGE_COLOR;
364 hist_offset= SendMessageW(nav_toolbar,TB_ADDBITMAP,0,(LPARAM)&bitmap_info);
365 bitmap_info.nID = IDB_VIEW_LARGE_COLOR;
366 view_offset= SendMessageW(nav_toolbar,TB_ADDBITMAP,0,(LPARAM)&bitmap_info);
368 nav_buttons[0].iBitmap=hist_offset+HIST_BACK;
369 nav_buttons[0].idCommand=BACK_BUTTON;
370 nav_buttons[0].fsState=TBSTATE_ENABLED;
371 nav_buttons[0].fsStyle=BTNS_BUTTON|BTNS_AUTOSIZE;
372 nav_buttons[1].iBitmap=hist_offset+HIST_FORWARD;
373 nav_buttons[1].idCommand=FORWARD_BUTTON;
374 nav_buttons[1].fsState=TBSTATE_ENABLED;
375 nav_buttons[1].fsStyle=BTNS_BUTTON|BTNS_AUTOSIZE;
376 nav_buttons[2].iBitmap=view_offset+VIEW_PARENTFOLDER;
377 nav_buttons[2].idCommand=UP_BUTTON;
378 nav_buttons[2].fsState=TBSTATE_ENABLED;
379 nav_buttons[2].fsStyle=BTNS_BUTTON|BTNS_AUTOSIZE;
380 SendMessageW(nav_toolbar,TB_BUTTONSTRUCTSIZE,sizeof(TBBUTTON),0);
381 SendMessageW(nav_toolbar,TB_ADDBUTTONSW,sizeof(nav_buttons)/sizeof(TBBUTTON),(LPARAM)nav_buttons);
383 band_info.cbSize = sizeof(band_info);
384 band_info.fMask = RBBIM_STYLE|RBBIM_CHILD|RBBIM_CHILDSIZE|RBBIM_SIZE;
385 band_info.hwndChild = nav_toolbar;
386 band_info.fStyle=RBBS_GRIPPERALWAYS|RBBS_CHILDEDGE;
387 band_info.cyChild=NAV_TOOLBAR_HEIGHT;
388 band_info.cx=0;
389 band_info.cyMinChild=NAV_TOOLBAR_HEIGHT;
390 band_info.cxMinChild=0;
391 SendMessageW(rebar,RB_INSERTBANDW,-1,(LPARAM)&band_info);
392 info->path_box = CreateWindowW(WC_COMBOBOXEXW,PATH_BOX_NAME,
393 WS_CHILD | WS_VISIBLE | CBS_DROPDOWN,
394 0,0,DEFAULT_WIDTH,PATHBOX_HEIGHT,rebar,NULL,
395 explorer_hInstance,NULL);
396 band_info.cyChild=PATHBOX_HEIGHT;
397 band_info.cx=0;
398 band_info.cyMinChild=PATHBOX_HEIGHT;
399 band_info.cxMinChild=0;
400 band_info.fMask|=RBBIM_TEXT;
401 band_info.lpText=pathbox_label;
402 band_info.fStyle|=RBBS_BREAK;
403 band_info.hwndChild=info->path_box;
404 SendMessageW(rebar,RB_INSERTBANDW,-1,(LPARAM)&band_info);
405 events = make_explorer_events(info);
406 IExplorerBrowser_Advise(info->browser,events,&info->advise_cookie);
407 IExplorerBrowser_BrowseToObject(info->browser,(IUnknown*)startFolder,
408 SBSP_ABSOLUTE);
409 ShowWindow(info->main_window,SW_SHOWDEFAULT);
410 UpdateWindow(info->main_window);
411 IExplorerBrowserEvents_Release(events);
414 static void update_window_size(explorer_info *info, int height, int width)
416 RECT new_rect;
417 new_rect.left = 0;
418 new_rect.top = info->rebar_height;
419 new_rect.right = width;
420 new_rect.bottom = height;
421 IExplorerBrowser_SetRect(info->browser,NULL,new_rect);
424 static void do_exit(int code)
426 OleUninitialize();
427 ExitProcess(code);
430 static LRESULT explorer_on_end_edit(explorer_info *info,NMCBEENDEDITW *edit_info)
432 LPITEMIDLIST pidl = NULL;
434 WINE_TRACE("iWhy=%x\n",edit_info->iWhy);
435 switch(edit_info->iWhy)
437 case CBENF_DROPDOWN:
438 if(edit_info->iNewSelection!=CB_ERR)
439 pidl = (LPITEMIDLIST)SendMessageW(edit_info->hdr.hwndFrom,
440 CB_GETITEMDATA,
441 edit_info->iNewSelection,0);
442 break;
443 case CBENF_RETURN:
445 WCHAR path[MAX_PATH];
446 HWND edit_ctrl = (HWND)SendMessageW(edit_info->hdr.hwndFrom,
447 CBEM_GETEDITCONTROL,0,0);
448 *((WORD*)path)=MAX_PATH;
449 SendMessageW(edit_ctrl,EM_GETLINE,0,(LPARAM)path);
450 pidl = ILCreateFromPathW(path);
451 break;
453 case CBENF_ESCAPE:
454 /*make sure the that the path box resets*/
455 update_path_box(info);
456 return 0;
457 default:
458 return 0;
460 if(pidl)
461 IExplorerBrowser_BrowseToIDList(info->browser,pidl,SBSP_ABSOLUTE);
462 if(edit_info->iWhy==CBENF_RETURN)
463 ILFree(pidl);
464 return 0;
467 static LRESULT update_rebar_size(explorer_info* info,NMRBAUTOSIZE *size_info)
469 RECT new_rect;
470 RECT window_rect;
471 info->rebar_height = size_info->rcTarget.bottom-size_info->rcTarget.top;
472 GetWindowRect(info->main_window,&window_rect);
473 new_rect.left = 0;
474 new_rect.top = info->rebar_height;
475 new_rect.right = window_rect.right-window_rect.left;
476 new_rect.bottom = window_rect.bottom-window_rect.top;
477 IExplorerBrowser_SetRect(info->browser,NULL,new_rect);
478 return 0;
481 static LRESULT explorer_on_notify(explorer_info* info,NMHDR* notification)
483 WINE_TRACE("code=%i\n",notification->code);
484 switch(notification->code)
486 case CBEN_BEGINEDIT:
488 WCHAR path[MAX_PATH];
489 HWND edit_ctrl = (HWND)SendMessageW(notification->hwndFrom,
490 CBEM_GETEDITCONTROL,0,0);
491 SHGetPathFromIDListW(info->pidl,path);
492 SetWindowTextW(edit_ctrl,path);
493 break;
495 case CBEN_ENDEDITA:
497 NMCBEENDEDITA *edit_info_a = (NMCBEENDEDITA*)notification;
498 NMCBEENDEDITW edit_info_w;
499 edit_info_w.hdr = edit_info_a->hdr;
500 edit_info_w.fChanged = edit_info_a->fChanged;
501 edit_info_w.iNewSelection = edit_info_a->iNewSelection;
502 MultiByteToWideChar(CP_ACP,0,edit_info_a->szText,-1,
503 edit_info_w.szText,CBEMAXSTRLEN);
504 edit_info_w.iWhy = edit_info_a->iWhy;
505 return explorer_on_end_edit(info,&edit_info_w);
507 case CBEN_ENDEDITW:
508 return explorer_on_end_edit(info,(NMCBEENDEDITW*)notification);
509 case CBEN_DELETEITEM:
511 NMCOMBOBOXEXW *entry = (NMCOMBOBOXEXW*)notification;
512 if(entry->ceItem.lParam)
513 ILFree((LPITEMIDLIST)entry->ceItem.lParam);
514 break;
516 case RBN_AUTOSIZE:
517 return update_rebar_size(info,(NMRBAUTOSIZE*)notification);
518 default:
519 break;
521 return 0;
524 static LRESULT CALLBACK explorer_wnd_proc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
526 explorer_info *info
527 = (explorer_info*)GetWindowLongPtrW(hwnd,EXPLORER_INFO_INDEX);
528 IExplorerBrowser *browser = NULL;
530 WINE_TRACE("(hwnd=%p,uMsg=%u,wParam=%lx,lParam=%lx)\n",hwnd,uMsg,wParam,lParam);
531 if(info)
532 browser = info->browser;
533 switch(uMsg)
535 case WM_DESTROY:
536 IExplorerBrowser_Unadvise(browser,info->advise_cookie);
537 IExplorerBrowser_Destroy(browser);
538 IExplorerBrowser_Release(browser);
539 ILFree(info->pidl);
540 IImageList_Release(info->icon_list);
541 HeapFree(GetProcessHeap(),0,info);
542 SetWindowLongPtrW(hwnd,EXPLORER_INFO_INDEX,0);
543 PostQuitMessage(0);
544 break;
545 case WM_QUIT:
546 do_exit(wParam);
547 case WM_NOTIFY:
548 return explorer_on_notify(info,(NMHDR*)lParam);
549 case WM_COMMAND:
550 if(HIWORD(wParam)==BN_CLICKED)
552 switch(LOWORD(wParam))
554 case BACK_BUTTON:
555 IExplorerBrowser_BrowseToObject(browser,NULL,SBSP_NAVIGATEBACK);
556 break;
557 case FORWARD_BUTTON:
558 IExplorerBrowser_BrowseToObject(browser,NULL,SBSP_NAVIGATEFORWARD);
559 break;
560 case UP_BUTTON:
561 IExplorerBrowser_BrowseToObject(browser,NULL,SBSP_PARENT);
562 break;
565 break;
566 case WM_SIZE:
567 update_window_size(info,HIWORD(lParam),LOWORD(lParam));
568 break;
569 default:
570 return DefWindowProcW(hwnd,uMsg,wParam,lParam);
572 return 0;
575 static void register_explorer_window_class(void)
577 WNDCLASSEXW window_class;
578 window_class.cbSize = sizeof(WNDCLASSEXW);
579 window_class.style = 0;
580 window_class.cbClsExtra = 0;
581 window_class.cbWndExtra = sizeof(LONG_PTR);
582 window_class.lpfnWndProc = explorer_wnd_proc;
583 window_class.hInstance = explorer_hInstance;
584 window_class.hIcon = NULL;
585 window_class.hCursor = NULL;
586 window_class.hbrBackground = (HBRUSH)COLOR_BACKGROUND;
587 window_class.lpszMenuName = NULL;
588 window_class.lpszClassName = EXPLORER_CLASS;
589 window_class.hIconSm = NULL;
590 RegisterClassExW(&window_class);
593 static IShellFolder* get_starting_shell_folder(parameters_struct* params)
595 IShellFolder* desktop,*folder;
596 LPITEMIDLIST root_pidl;
597 HRESULT hres;
599 SHGetDesktopFolder(&desktop);
600 if (!params->root[0])
602 return desktop;
604 hres = IShellFolder_ParseDisplayName(desktop,NULL,NULL,
605 params->root,NULL,
606 &root_pidl,NULL);
608 if(FAILED(hres))
610 return desktop;
612 hres = IShellFolder_BindToObject(desktop,root_pidl,NULL,
613 &IID_IShellFolder,
614 (void**)&folder);
615 if(FAILED(hres))
617 return desktop;
619 IShellFolder_Release(desktop);
620 return folder;
623 static int copy_path_string(LPWSTR target, LPWSTR source)
625 INT i = 0;
627 while (isspaceW(*source)) source++;
629 if (*source == '\"')
631 source ++;
632 while (*source != '\"') target[i++] = *source++;
633 target[i] = 0;
634 source ++;
635 i+=2;
637 else
639 while (*source && *source != ',') target[i++] = *source++;
640 target[i] = 0;
642 PathRemoveBackslashW(target);
643 return i;
647 static void copy_path_root(LPWSTR root, LPWSTR path)
649 LPWSTR p,p2;
650 INT i = 0;
652 p = path;
653 while (*p!=0)
654 p++;
656 while (*p!='\\' && p > path)
657 p--;
659 if (p == path)
660 return;
662 p2 = path;
663 while (p2 != p)
665 root[i] = *p2;
666 i++;
667 p2++;
669 root[i] = 0;
673 * Command Line parameters are:
674 * [/n] Opens in single-paned view for each selected items. This is default
675 * [/e,] Uses Windows Explorer View
676 * [/root,object] Specifies the root level of the view
677 * [/select,object] parent folder is opened and specified object is selected
679 static void parse_command_line(LPWSTR commandline,parameters_struct *parameters)
681 static const WCHAR arg_n[] = {'/','n'};
682 static const WCHAR arg_e[] = {'/','e',','};
683 static const WCHAR arg_root[] = {'/','r','o','o','t',','};
684 static const WCHAR arg_select[] = {'/','s','e','l','e','c','t',','};
685 static const WCHAR arg_desktop[] = {'/','d','e','s','k','t','o','p'};
687 LPWSTR p, p2;
689 p2 = commandline;
690 p = strchrW(commandline,'/');
691 while(p)
693 if (strncmpW(p, arg_n, sizeof(arg_n)/sizeof(WCHAR))==0)
695 parameters->explorer_mode = FALSE;
696 p += sizeof(arg_n)/sizeof(WCHAR);
698 else if (strncmpW(p, arg_e, sizeof(arg_e)/sizeof(WCHAR))==0)
700 parameters->explorer_mode = TRUE;
701 p += sizeof(arg_e)/sizeof(WCHAR);
703 else if (strncmpW(p, arg_root, sizeof(arg_root)/sizeof(WCHAR))==0)
705 p += sizeof(arg_root)/sizeof(WCHAR);
706 p+=copy_path_string(parameters->root,p);
708 else if (strncmpW(p, arg_select, sizeof(arg_select)/sizeof(WCHAR))==0)
710 p += sizeof(arg_select)/sizeof(WCHAR);
711 p+=copy_path_string(parameters->selection,p);
712 if (!parameters->root[0])
713 copy_path_root(parameters->root,
714 parameters->selection);
716 else if (strncmpW(p, arg_desktop, sizeof(arg_desktop)/sizeof(WCHAR))==0)
718 p += sizeof(arg_desktop)/sizeof(WCHAR);
719 manage_desktop( p ); /* the rest of the command line is handled by desktop mode */
721 else p++;
723 p2 = p;
724 p = strchrW(p,'/');
726 if (p2 && *p2)
728 /* left over command line is generally the path to be opened */
729 copy_path_string(parameters->root,p2);
733 int WINAPI wWinMain(HINSTANCE hinstance,
734 HINSTANCE previnstance,
735 LPWSTR cmdline,
736 int cmdshow)
739 parameters_struct parameters;
740 HRESULT hres;
741 MSG msg;
742 IShellFolder *folder;
743 INITCOMMONCONTROLSEX init_info;
745 memset(&parameters,0,sizeof(parameters));
746 explorer_hInstance = hinstance;
747 parse_command_line(cmdline,&parameters);
748 hres = OleInitialize(NULL);
749 if(FAILED(hres))
751 WINE_ERR("Could not initialize COM\n");
752 ExitProcess(EXIT_FAILURE);
754 if(parameters.root[0] && !PathIsDirectoryW(parameters.root))
755 if(ShellExecuteW(NULL,NULL,parameters.root,NULL,NULL,SW_SHOWDEFAULT) > (HINSTANCE)32)
756 ExitProcess(EXIT_SUCCESS);
757 init_info.dwSize = sizeof(INITCOMMONCONTROLSEX);
758 init_info.dwICC = ICC_USEREX_CLASSES | ICC_BAR_CLASSES | ICC_COOL_CLASSES;
759 if(!InitCommonControlsEx(&init_info))
761 WINE_ERR("Could not initialize Comctl\n");
762 ExitProcess(EXIT_FAILURE);
764 register_explorer_window_class();
765 folder = get_starting_shell_folder(&parameters);
766 make_explorer_window(folder);
767 IShellFolder_Release(folder);
768 while(GetMessageW( &msg, NULL, 0, 0 ) != 0)
770 TranslateMessage(&msg);
771 DispatchMessageW(&msg);
773 return 0;