winefile.c 104 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112
  1. /*
  2. * Winefile
  3. *
  4. * Copyright 2000, 2003, 2004, 2005 Martin Fuchs
  5. * Copyright 2006 Jason Green
  6. *
  7. * This library is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * This library is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with this library; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
  20. */
  21. #define COBJMACROS
  22. #include <assert.h>
  23. #include <stdio.h>
  24. #include "winefile.h"
  25. #include "resource.h"
  26. #ifdef NONAMELESSUNION
  27. #define UNION_MEMBER(x) DUMMYUNIONNAME.x
  28. #else
  29. #define UNION_MEMBER(x) x
  30. #endif
  31. #define DEFAULT_SPLIT_POS 300
  32. static const WCHAR registry_key[] = { 'S','o','f','t','w','a','r','e','\\',
  33. 'W','i','n','e','\\',
  34. 'W','i','n','e','F','i','l','e','\0'};
  35. static const WCHAR reg_start_x[] = { 's','t','a','r','t','X','\0'};
  36. static const WCHAR reg_start_y[] = { 's','t','a','r','t','Y','\0'};
  37. static const WCHAR reg_width[] = { 'w','i','d','t','h','\0'};
  38. static const WCHAR reg_height[] = { 'h','e','i','g','h','t','\0'};
  39. static const WCHAR reg_logfont[] = { 'l','o','g','f','o','n','t','\0'};
  40. enum ENTRY_TYPE {
  41. ET_WINDOWS,
  42. ET_SHELL
  43. };
  44. typedef struct _Entry {
  45. struct _Entry* next;
  46. struct _Entry* down;
  47. struct _Entry* up;
  48. BOOL expanded;
  49. BOOL scanned;
  50. int level;
  51. WIN32_FIND_DATAW data;
  52. BY_HANDLE_FILE_INFORMATION bhfi;
  53. BOOL bhfi_valid;
  54. enum ENTRY_TYPE etype;
  55. LPITEMIDLIST pidl;
  56. IShellFolder* folder;
  57. HICON hicon;
  58. } Entry;
  59. typedef struct {
  60. Entry entry;
  61. WCHAR path[MAX_PATH];
  62. WCHAR volname[_MAX_FNAME];
  63. WCHAR fs[_MAX_DIR];
  64. DWORD drive_type;
  65. DWORD fs_flags;
  66. } Root;
  67. enum COLUMN_FLAGS {
  68. COL_SIZE = 0x01,
  69. COL_DATE = 0x02,
  70. COL_TIME = 0x04,
  71. COL_ATTRIBUTES = 0x08,
  72. COL_DOSNAMES = 0x10,
  73. COL_INDEX = 0x20,
  74. COL_LINKS = 0x40,
  75. COL_ALL = COL_SIZE|COL_DATE|COL_TIME|COL_ATTRIBUTES|COL_DOSNAMES|COL_INDEX|COL_LINKS
  76. };
  77. typedef enum {
  78. SORT_NAME,
  79. SORT_EXT,
  80. SORT_SIZE,
  81. SORT_DATE
  82. } SORT_ORDER;
  83. typedef struct {
  84. HWND hwnd;
  85. HWND hwndHeader;
  86. #define COLUMNS 10
  87. int widths[COLUMNS];
  88. int widths_shown[COLUMNS];
  89. int positions[COLUMNS+1];
  90. BOOL treePane;
  91. int visible_cols;
  92. Entry* root;
  93. Entry* cur;
  94. } Pane;
  95. typedef struct {
  96. HWND hwnd;
  97. Pane left;
  98. Pane right;
  99. int focus_pane; /* 0: left 1: right */
  100. WINDOWPLACEMENT pos;
  101. int split_pos;
  102. BOOL header_wdths_ok;
  103. WCHAR path[MAX_PATH];
  104. WCHAR filter_pattern[MAX_PATH];
  105. int filter_flags;
  106. Root root;
  107. SORT_ORDER sortOrder;
  108. } ChildWnd;
  109. static void read_directory(Entry* dir, LPCWSTR path, SORT_ORDER sortOrder, HWND hwnd);
  110. static void set_curdir(ChildWnd* child, Entry* entry, int idx, HWND hwnd);
  111. static void refresh_child(ChildWnd* child);
  112. static void refresh_drives(void);
  113. static void get_path(Entry* dir, PWSTR path);
  114. static void format_date(const FILETIME* ft, WCHAR* buffer, int visible_cols);
  115. static LRESULT CALLBACK FrameWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam);
  116. static LRESULT CALLBACK ChildWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam);
  117. static LRESULT CALLBACK TreeWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam);
  118. /* globals */
  119. WINEFILE_GLOBALS Globals;
  120. static int last_split;
  121. /* some common string constants */
  122. static const WCHAR sEmpty[] = {'\0'};
  123. static const WCHAR sSpace[] = {' ', '\0'};
  124. static const WCHAR sNumFmt[] = {'%','d','\0'};
  125. static const WCHAR sQMarks[] = {'?','?','?','\0'};
  126. /* window class names */
  127. static const WCHAR sWINEFILEFRAME[] = {'W','F','S','_','F','r','a','m','e','\0'};
  128. static const WCHAR sWINEFILETREE[] = {'W','F','S','_','T','r','e','e','\0'};
  129. static void format_longlong(LPWSTR ret, ULONGLONG val)
  130. {
  131. WCHAR buffer[65], *p = &buffer[64];
  132. *p = 0;
  133. do {
  134. *(--p) = '0' + val % 10;
  135. val /= 10;
  136. } while (val);
  137. lstrcpyW( ret, p );
  138. }
  139. /* load resource string */
  140. static LPWSTR load_string(LPWSTR buffer, DWORD size, UINT id)
  141. {
  142. LoadStringW(Globals.hInstance, id, buffer, size);
  143. return buffer;
  144. }
  145. #define RS(b, i) load_string(b, ARRAY_SIZE(b), i)
  146. /* display error message for the specified WIN32 error code */
  147. static void display_error(HWND hwnd, DWORD error)
  148. {
  149. WCHAR b1[BUFFER_LEN], b2[BUFFER_LEN];
  150. PWSTR msg;
  151. if (FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM,
  152. 0, error, MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT), (PWSTR)&msg, 0, NULL))
  153. MessageBoxW(hwnd, msg, RS(b2,IDS_WINEFILE), MB_OK);
  154. else
  155. MessageBoxW(hwnd, RS(b1,IDS_ERROR), RS(b2,IDS_WINEFILE), MB_OK);
  156. LocalFree(msg);
  157. }
  158. /* display network error message using WNetGetLastErrorW() */
  159. static void display_network_error(HWND hwnd)
  160. {
  161. WCHAR msg[BUFFER_LEN], provider[BUFFER_LEN], b2[BUFFER_LEN];
  162. DWORD error;
  163. if (WNetGetLastErrorW(&error, msg, BUFFER_LEN, provider, BUFFER_LEN) == NO_ERROR)
  164. MessageBoxW(hwnd, msg, RS(b2,IDS_WINEFILE), MB_OK);
  165. }
  166. static inline BOOL get_check(HWND hwnd, INT id)
  167. {
  168. return BST_CHECKED&SendMessageW(GetDlgItem(hwnd, id), BM_GETSTATE, 0, 0);
  169. }
  170. static inline INT set_check(HWND hwnd, INT id, BOOL on)
  171. {
  172. return SendMessageW(GetDlgItem(hwnd, id), BM_SETCHECK, on?BST_CHECKED:BST_UNCHECKED, 0);
  173. }
  174. static inline void choose_font(HWND hwnd)
  175. {
  176. WCHAR dlg_name[BUFFER_LEN], dlg_info[BUFFER_LEN];
  177. CHOOSEFONTW chFont;
  178. LOGFONTW lFont;
  179. HDC hdc = GetDC(hwnd);
  180. GetObjectW(Globals.hfont, sizeof(LOGFONTW), &lFont);
  181. chFont.lStructSize = sizeof(CHOOSEFONTW);
  182. chFont.hwndOwner = hwnd;
  183. chFont.hDC = NULL;
  184. chFont.lpLogFont = &lFont;
  185. chFont.Flags = CF_SCREENFONTS | CF_FORCEFONTEXIST | CF_LIMITSIZE | CF_NOSCRIPTSEL | CF_INITTOLOGFONTSTRUCT | CF_NOVERTFONTS;
  186. chFont.rgbColors = RGB(0,0,0);
  187. chFont.lCustData = 0;
  188. chFont.lpfnHook = NULL;
  189. chFont.lpTemplateName = NULL;
  190. chFont.hInstance = Globals.hInstance;
  191. chFont.lpszStyle = NULL;
  192. chFont.nFontType = SIMULATED_FONTTYPE;
  193. chFont.nSizeMin = 0;
  194. chFont.nSizeMax = 24;
  195. if (ChooseFontW(&chFont)) {
  196. HWND childWnd;
  197. HFONT hFontOld;
  198. DeleteObject(Globals.hfont);
  199. Globals.hfont = CreateFontIndirectW(&lFont);
  200. hFontOld = SelectObject(hdc, Globals.hfont);
  201. GetTextExtentPoint32W(hdc, sSpace, 1, &Globals.spaceSize);
  202. /* change font in all open child windows */
  203. for(childWnd=GetWindow(Globals.hmdiclient,GW_CHILD); childWnd; childWnd=GetNextWindow(childWnd,GW_HWNDNEXT)) {
  204. ChildWnd* child = (ChildWnd*) GetWindowLongPtrW(childWnd, GWLP_USERDATA);
  205. SendMessageW(child->left.hwnd, WM_SETFONT, (WPARAM)Globals.hfont, TRUE);
  206. SendMessageW(child->right.hwnd, WM_SETFONT, (WPARAM)Globals.hfont, TRUE);
  207. SendMessageW(child->left.hwnd, LB_SETITEMHEIGHT, 1, max(Globals.spaceSize.cy,IMAGE_HEIGHT+3));
  208. SendMessageW(child->right.hwnd, LB_SETITEMHEIGHT, 1, max(Globals.spaceSize.cy,IMAGE_HEIGHT+3));
  209. InvalidateRect(child->left.hwnd, NULL, TRUE);
  210. InvalidateRect(child->right.hwnd, NULL, TRUE);
  211. }
  212. SelectObject(hdc, hFontOld);
  213. }
  214. else if (CommDlgExtendedError()) {
  215. LoadStringW(Globals.hInstance, IDS_FONT_SEL_DLG_NAME, dlg_name, BUFFER_LEN);
  216. LoadStringW(Globals.hInstance, IDS_FONT_SEL_ERROR, dlg_info, BUFFER_LEN);
  217. MessageBoxW(hwnd, dlg_info, dlg_name, MB_OK);
  218. }
  219. ReleaseDC(hwnd, hdc);
  220. }
  221. /* allocate and initialise a directory entry */
  222. static Entry* alloc_entry(void)
  223. {
  224. Entry* entry = HeapAlloc(GetProcessHeap(), 0, sizeof(Entry));
  225. entry->pidl = NULL;
  226. entry->folder = NULL;
  227. entry->hicon = 0;
  228. return entry;
  229. }
  230. /* free a directory entry */
  231. static void free_entry(Entry* entry)
  232. {
  233. if (entry->hicon && entry->hicon!=(HICON)-1)
  234. DestroyIcon(entry->hicon);
  235. if (entry->folder && entry->folder!=Globals.iDesktop)
  236. IShellFolder_Release(entry->folder);
  237. if (entry->pidl)
  238. IMalloc_Free(Globals.iMalloc, entry->pidl);
  239. HeapFree(GetProcessHeap(), 0, entry);
  240. }
  241. /* recursively free all child entries */
  242. static void free_entries(Entry* dir)
  243. {
  244. Entry *entry, *next=dir->down;
  245. if (next) {
  246. dir->down = 0;
  247. do {
  248. entry = next;
  249. next = entry->next;
  250. free_entries(entry);
  251. free_entry(entry);
  252. } while(next);
  253. }
  254. }
  255. static void read_directory_win(Entry* dir, LPCWSTR path)
  256. {
  257. Entry* first_entry = NULL;
  258. Entry* last = NULL;
  259. Entry* entry;
  260. int level = dir->level + 1;
  261. WIN32_FIND_DATAW w32fd;
  262. HANDLE hFind;
  263. HANDLE hFile;
  264. WCHAR buffer[MAX_PATH], *p;
  265. for(p=buffer; *path; )
  266. *p++ = *path++;
  267. *p++ = '\\';
  268. p[0] = '*';
  269. p[1] = '\0';
  270. hFind = FindFirstFileW(buffer, &w32fd);
  271. if (hFind != INVALID_HANDLE_VALUE) {
  272. do {
  273. entry = alloc_entry();
  274. if (!first_entry)
  275. first_entry = entry;
  276. if (last)
  277. last->next = entry;
  278. memcpy(&entry->data, &w32fd, sizeof(WIN32_FIND_DATAW));
  279. entry->down = NULL;
  280. entry->up = dir;
  281. entry->expanded = FALSE;
  282. entry->scanned = FALSE;
  283. entry->level = level;
  284. entry->etype = ET_WINDOWS;
  285. entry->bhfi_valid = FALSE;
  286. lstrcpyW(p, entry->data.cFileName);
  287. hFile = CreateFileW(buffer, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
  288. 0, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0);
  289. if (hFile != INVALID_HANDLE_VALUE) {
  290. if (GetFileInformationByHandle(hFile, &entry->bhfi))
  291. entry->bhfi_valid = TRUE;
  292. CloseHandle(hFile);
  293. }
  294. last = entry;
  295. } while(FindNextFileW(hFind, &w32fd));
  296. if (last)
  297. last->next = NULL;
  298. FindClose(hFind);
  299. }
  300. dir->down = first_entry;
  301. dir->scanned = TRUE;
  302. }
  303. static Entry* find_entry_win(Entry* dir, LPCWSTR name)
  304. {
  305. Entry* entry;
  306. for(entry=dir->down; entry; entry=entry->next) {
  307. LPCWSTR p = name;
  308. LPCWSTR q = entry->data.cFileName;
  309. do {
  310. if (!*p || *p == '\\' || *p == '/')
  311. return entry;
  312. } while(tolower(*p++) == tolower(*q++));
  313. p = name;
  314. q = entry->data.cAlternateFileName;
  315. do {
  316. if (!*p || *p == '\\' || *p == '/')
  317. return entry;
  318. } while(tolower(*p++) == tolower(*q++));
  319. }
  320. return 0;
  321. }
  322. static Entry* read_tree_win(Root* root, LPCWSTR path, SORT_ORDER sortOrder, HWND hwnd)
  323. {
  324. WCHAR buffer[MAX_PATH];
  325. Entry* entry = &root->entry;
  326. LPCWSTR s = path;
  327. PWSTR d = buffer;
  328. HCURSOR old_cursor = SetCursor(LoadCursorW(0, (LPCWSTR)IDC_WAIT));
  329. entry->etype = ET_WINDOWS;
  330. while(entry) {
  331. while(*s && *s != '\\' && *s != '/')
  332. *d++ = *s++;
  333. while(*s == '\\' || *s == '/')
  334. s++;
  335. *d++ = '\\';
  336. *d = '\0';
  337. read_directory(entry, buffer, sortOrder, hwnd);
  338. if (entry->down)
  339. entry->expanded = TRUE;
  340. if (!*s)
  341. break;
  342. entry = find_entry_win(entry, s);
  343. }
  344. SetCursor(old_cursor);
  345. return entry;
  346. }
  347. static void free_strret(STRRET* str)
  348. {
  349. if (str->uType == STRRET_WSTR)
  350. IMalloc_Free(Globals.iMalloc, str->UNION_MEMBER(pOleStr));
  351. }
  352. static LPWSTR wcscpyn(LPWSTR dest, LPCWSTR source, size_t count)
  353. {
  354. LPCWSTR s;
  355. LPWSTR d = dest;
  356. for(s=source; count&&(*d++=*s++); )
  357. count--;
  358. return dest;
  359. }
  360. static void get_strretW(STRRET* str, const SHITEMID* shiid, LPWSTR buffer, int len)
  361. {
  362. switch(str->uType) {
  363. case STRRET_WSTR:
  364. wcscpyn(buffer, str->UNION_MEMBER(pOleStr), len);
  365. break;
  366. case STRRET_OFFSET:
  367. MultiByteToWideChar(CP_ACP, 0, (LPCSTR)shiid+str->UNION_MEMBER(uOffset), -1, buffer, len);
  368. break;
  369. case STRRET_CSTR:
  370. MultiByteToWideChar(CP_ACP, 0, str->UNION_MEMBER(cStr), -1, buffer, len);
  371. }
  372. }
  373. static HRESULT name_from_pidl(IShellFolder* folder, LPITEMIDLIST pidl, LPWSTR buffer, int len, SHGDNF flags)
  374. {
  375. STRRET str;
  376. HRESULT hr = IShellFolder_GetDisplayNameOf(folder, pidl, flags, &str);
  377. if (SUCCEEDED(hr)) {
  378. get_strretW(&str, &pidl->mkid, buffer, len);
  379. free_strret(&str);
  380. } else
  381. buffer[0] = '\0';
  382. return hr;
  383. }
  384. static HRESULT path_from_pidlW(IShellFolder* folder, LPITEMIDLIST pidl, LPWSTR buffer, int len)
  385. {
  386. STRRET str;
  387. /* SHGDN_FORPARSING: get full path of id list */
  388. HRESULT hr = IShellFolder_GetDisplayNameOf(folder, pidl, SHGDN_FORPARSING, &str);
  389. if (SUCCEEDED(hr)) {
  390. get_strretW(&str, &pidl->mkid, buffer, len);
  391. free_strret(&str);
  392. } else
  393. buffer[0] = '\0';
  394. return hr;
  395. }
  396. /* create an item id list from a file system path */
  397. static LPITEMIDLIST get_path_pidl(LPWSTR path, HWND hwnd)
  398. {
  399. LPITEMIDLIST pidl;
  400. HRESULT hr;
  401. ULONG len;
  402. LPWSTR buffer = path;
  403. hr = IShellFolder_ParseDisplayName(Globals.iDesktop, hwnd, NULL, buffer, &len, &pidl, NULL);
  404. if (FAILED(hr))
  405. return NULL;
  406. return pidl;
  407. }
  408. /* convert an item id list from relative to absolute (=relative to the desktop) format */
  409. static LPITEMIDLIST get_to_absolute_pidl(Entry* entry, HWND hwnd)
  410. {
  411. if (entry->up && entry->up->etype==ET_SHELL) {
  412. LPITEMIDLIST idl = NULL;
  413. while (entry->up) {
  414. idl = ILCombine(ILClone(entry->pidl), idl);
  415. entry = entry->up;
  416. }
  417. return idl;
  418. } else if (entry->etype == ET_WINDOWS) {
  419. WCHAR path[MAX_PATH];
  420. get_path(entry, path);
  421. return get_path_pidl(path, hwnd);
  422. } else if (entry->pidl)
  423. return ILClone(entry->pidl);
  424. return NULL;
  425. }
  426. static HICON extract_icon(IShellFolder* folder, LPCITEMIDLIST pidl)
  427. {
  428. IExtractIconW* pExtract;
  429. if (SUCCEEDED(IShellFolder_GetUIObjectOf(folder, 0, 1, &pidl, &IID_IExtractIconW, 0, (void**)&pExtract))) {
  430. WCHAR path[_MAX_PATH];
  431. unsigned flags;
  432. HICON hicon;
  433. int idx;
  434. if (SUCCEEDED(IExtractIconW_GetIconLocation(pExtract, GIL_FORSHELL, path, _MAX_PATH, &idx, &flags))) {
  435. if (!(flags & GIL_NOTFILENAME)) {
  436. if (idx == -1)
  437. idx = 0; /* special case for some control panel applications */
  438. if ((int)ExtractIconExW(path, idx, 0, &hicon, 1) > 0)
  439. flags &= ~GIL_DONTCACHE;
  440. } else {
  441. HICON hIconLarge = 0;
  442. HRESULT hr = IExtractIconW_Extract(pExtract, path, idx, &hIconLarge, &hicon, MAKELONG(0/*GetSystemMetrics(SM_CXICON)*/,GetSystemMetrics(SM_CXSMICON)));
  443. if (SUCCEEDED(hr))
  444. DestroyIcon(hIconLarge);
  445. }
  446. return hicon;
  447. }
  448. }
  449. return 0;
  450. }
  451. static Entry* find_entry_shell(Entry* dir, LPCITEMIDLIST pidl)
  452. {
  453. Entry* entry;
  454. for(entry=dir->down; entry; entry=entry->next) {
  455. if (entry->pidl->mkid.cb == pidl->mkid.cb &&
  456. !memcmp(entry->pidl, pidl, entry->pidl->mkid.cb))
  457. return entry;
  458. }
  459. return 0;
  460. }
  461. static Entry* read_tree_shell(Root* root, LPITEMIDLIST pidl, SORT_ORDER sortOrder, HWND hwnd)
  462. {
  463. Entry* entry = &root->entry;
  464. Entry* next;
  465. LPITEMIDLIST next_pidl = pidl;
  466. IShellFolder* folder;
  467. IShellFolder* child = NULL;
  468. HRESULT hr;
  469. HCURSOR old_cursor = SetCursor(LoadCursorW(0, (LPCWSTR)IDC_WAIT));
  470. entry->etype = ET_SHELL;
  471. folder = Globals.iDesktop;
  472. while(entry) {
  473. entry->pidl = next_pidl;
  474. entry->folder = folder;
  475. if (!pidl->mkid.cb)
  476. break;
  477. /* copy first element of item idlist */
  478. next_pidl = IMalloc_Alloc(Globals.iMalloc, pidl->mkid.cb+sizeof(USHORT));
  479. memcpy(next_pidl, pidl, pidl->mkid.cb);
  480. ((LPITEMIDLIST)((LPBYTE)next_pidl+pidl->mkid.cb))->mkid.cb = 0;
  481. hr = IShellFolder_BindToObject(folder, next_pidl, 0, &IID_IShellFolder, (void**)&child);
  482. if (FAILED(hr))
  483. break;
  484. read_directory(entry, NULL, sortOrder, hwnd);
  485. if (entry->down)
  486. entry->expanded = TRUE;
  487. next = find_entry_shell(entry, next_pidl);
  488. if (!next)
  489. break;
  490. folder = child;
  491. entry = next;
  492. /* go to next element */
  493. pidl = (LPITEMIDLIST) ((LPBYTE)pidl+pidl->mkid.cb);
  494. }
  495. SetCursor(old_cursor);
  496. return entry;
  497. }
  498. static void fill_w32fdata_shell(IShellFolder* folder, LPCITEMIDLIST pidl, SFGAOF attribs, WIN32_FIND_DATAW* w32fdata)
  499. {
  500. if (!(attribs & SFGAO_FILESYSTEM) ||
  501. FAILED(SHGetDataFromIDListW(folder, pidl, SHGDFIL_FINDDATA, w32fdata, sizeof(WIN32_FIND_DATAW)))) {
  502. WIN32_FILE_ATTRIBUTE_DATA fad;
  503. IDataObject* pDataObj;
  504. STGMEDIUM medium = {0, {0}, 0};
  505. FORMATETC fmt = {Globals.cfStrFName, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL};
  506. HRESULT hr = IShellFolder_GetUIObjectOf(folder, 0, 1, &pidl, &IID_IDataObject, 0, (LPVOID*)&pDataObj);
  507. if (SUCCEEDED(hr)) {
  508. hr = IDataObject_GetData(pDataObj, &fmt, &medium);
  509. IDataObject_Release(pDataObj);
  510. if (SUCCEEDED(hr)) {
  511. LPCWSTR path = GlobalLock(medium.UNION_MEMBER(hGlobal));
  512. UINT sem_org = SetErrorMode(SEM_FAILCRITICALERRORS);
  513. if (GetFileAttributesExW(path, GetFileExInfoStandard, &fad)) {
  514. w32fdata->dwFileAttributes = fad.dwFileAttributes;
  515. w32fdata->ftCreationTime = fad.ftCreationTime;
  516. w32fdata->ftLastAccessTime = fad.ftLastAccessTime;
  517. w32fdata->ftLastWriteTime = fad.ftLastWriteTime;
  518. if (!(fad.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
  519. w32fdata->nFileSizeLow = fad.nFileSizeLow;
  520. w32fdata->nFileSizeHigh = fad.nFileSizeHigh;
  521. }
  522. }
  523. SetErrorMode(sem_org);
  524. GlobalUnlock(medium.UNION_MEMBER(hGlobal));
  525. GlobalFree(medium.UNION_MEMBER(hGlobal));
  526. }
  527. }
  528. }
  529. if (attribs & (SFGAO_FOLDER|SFGAO_HASSUBFOLDER))
  530. w32fdata->dwFileAttributes |= FILE_ATTRIBUTE_DIRECTORY;
  531. if (attribs & SFGAO_READONLY)
  532. w32fdata->dwFileAttributes |= FILE_ATTRIBUTE_READONLY;
  533. if (attribs & SFGAO_COMPRESSED)
  534. w32fdata->dwFileAttributes |= FILE_ATTRIBUTE_COMPRESSED;
  535. }
  536. static void read_directory_shell(Entry* dir, HWND hwnd)
  537. {
  538. IShellFolder* folder = dir->folder;
  539. int level = dir->level + 1;
  540. HRESULT hr;
  541. IShellFolder* child;
  542. IEnumIDList* idlist;
  543. Entry* first_entry = NULL;
  544. Entry* last = NULL;
  545. Entry* entry;
  546. if (!folder)
  547. return;
  548. hr = IShellFolder_EnumObjects(folder, hwnd, SHCONTF_FOLDERS|SHCONTF_NONFOLDERS|SHCONTF_INCLUDEHIDDEN|SHCONTF_SHAREABLE|SHCONTF_STORAGE, &idlist);
  549. if (SUCCEEDED(hr)) {
  550. for(;;) {
  551. #define FETCH_ITEM_COUNT 32
  552. LPITEMIDLIST pidls[FETCH_ITEM_COUNT];
  553. SFGAOF attribs;
  554. ULONG cnt = 0;
  555. ULONG n;
  556. memset(pidls, 0, sizeof(pidls));
  557. hr = IEnumIDList_Next(idlist, FETCH_ITEM_COUNT, pidls, &cnt);
  558. if (FAILED(hr))
  559. break;
  560. if (hr == S_FALSE)
  561. break;
  562. for(n=0; n<cnt; ++n) {
  563. entry = alloc_entry();
  564. if (!first_entry)
  565. first_entry = entry;
  566. if (last)
  567. last->next = entry;
  568. memset(&entry->data, 0, sizeof(WIN32_FIND_DATAW));
  569. entry->bhfi_valid = FALSE;
  570. attribs = ~SFGAO_FILESYSTEM; /*SFGAO_HASSUBFOLDER|SFGAO_FOLDER; SFGAO_FILESYSTEM sorgt dafür, daß "My Documents" anstatt von "Martin's Documents" angezeigt wird */
  571. hr = IShellFolder_GetAttributesOf(folder, 1, (LPCITEMIDLIST*)&pidls[n], &attribs);
  572. if (SUCCEEDED(hr)) {
  573. if (attribs != (SFGAOF)~SFGAO_FILESYSTEM) {
  574. fill_w32fdata_shell(folder, pidls[n], attribs, &entry->data);
  575. entry->bhfi_valid = TRUE;
  576. } else
  577. attribs = 0;
  578. } else
  579. attribs = 0;
  580. entry->pidl = pidls[n];
  581. if (entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
  582. hr = IShellFolder_BindToObject(folder, pidls[n], 0, &IID_IShellFolder, (void**)&child);
  583. if (SUCCEEDED(hr))
  584. entry->folder = child;
  585. else
  586. entry->folder = NULL;
  587. }
  588. else
  589. entry->folder = NULL;
  590. if (!entry->data.cFileName[0])
  591. /*hr = */name_from_pidl(folder, pidls[n], entry->data.cFileName, MAX_PATH, /*SHGDN_INFOLDER*/0x2000/*0x2000=SHGDN_INCLUDE_NONFILESYS*/);
  592. /* get display icons for files and virtual objects */
  593. if (!(entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ||
  594. !(attribs & SFGAO_FILESYSTEM)) {
  595. entry->hicon = extract_icon(folder, pidls[n]);
  596. if (!entry->hicon)
  597. entry->hicon = (HICON)-1; /* don't try again later */
  598. }
  599. entry->down = NULL;
  600. entry->up = dir;
  601. entry->expanded = FALSE;
  602. entry->scanned = FALSE;
  603. entry->level = level;
  604. entry->etype = ET_SHELL;
  605. entry->bhfi_valid = FALSE;
  606. last = entry;
  607. }
  608. }
  609. IEnumIDList_Release(idlist);
  610. }
  611. if (last)
  612. last->next = NULL;
  613. dir->down = first_entry;
  614. dir->scanned = TRUE;
  615. }
  616. /* sort order for different directory/file types */
  617. enum TYPE_ORDER {
  618. TO_DIR = 0,
  619. TO_DOT = 1,
  620. TO_DOTDOT = 2,
  621. TO_OTHER_DIR = 3,
  622. TO_FILE = 4
  623. };
  624. /* distinguish between ".", ".." and any other directory names */
  625. static int TypeOrderFromDirname(LPCWSTR name)
  626. {
  627. if (name[0] == '.') {
  628. if (name[1] == '\0')
  629. return TO_DOT; /* "." */
  630. if (name[1]=='.' && name[2]=='\0')
  631. return TO_DOTDOT; /* ".." */
  632. }
  633. return TO_OTHER_DIR; /* anything else */
  634. }
  635. /* directories first... */
  636. static int compareType(const WIN32_FIND_DATAW* fd1, const WIN32_FIND_DATAW* fd2)
  637. {
  638. int order1 = fd1->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY? TO_DIR: TO_FILE;
  639. int order2 = fd2->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY? TO_DIR: TO_FILE;
  640. /* Handle "." and ".." as special case and move them at the very first beginning. */
  641. if (order1==TO_DIR && order2==TO_DIR) {
  642. order1 = TypeOrderFromDirname(fd1->cFileName);
  643. order2 = TypeOrderFromDirname(fd2->cFileName);
  644. }
  645. return order2==order1? 0: order1<order2? -1: 1;
  646. }
  647. static int __cdecl compareName(const void* arg1, const void* arg2)
  648. {
  649. const WIN32_FIND_DATAW* fd1 = &(*(const Entry* const*)arg1)->data;
  650. const WIN32_FIND_DATAW* fd2 = &(*(const Entry* const*)arg2)->data;
  651. int cmp = compareType(fd1, fd2);
  652. if (cmp)
  653. return cmp;
  654. return lstrcmpiW(fd1->cFileName, fd2->cFileName);
  655. }
  656. static int __cdecl compareExt(const void* arg1, const void* arg2)
  657. {
  658. const WIN32_FIND_DATAW* fd1 = &(*(const Entry* const*)arg1)->data;
  659. const WIN32_FIND_DATAW* fd2 = &(*(const Entry* const*)arg2)->data;
  660. const WCHAR *name1, *name2, *ext1, *ext2;
  661. int cmp = compareType(fd1, fd2);
  662. if (cmp)
  663. return cmp;
  664. name1 = fd1->cFileName;
  665. name2 = fd2->cFileName;
  666. ext1 = wcsrchr(name1, '.');
  667. ext2 = wcsrchr(name2, '.');
  668. if (ext1)
  669. ext1++;
  670. else
  671. ext1 = sEmpty;
  672. if (ext2)
  673. ext2++;
  674. else
  675. ext2 = sEmpty;
  676. cmp = lstrcmpiW(ext1, ext2);
  677. if (cmp)
  678. return cmp;
  679. return lstrcmpiW(name1, name2);
  680. }
  681. static int __cdecl compareSize(const void* arg1, const void* arg2)
  682. {
  683. const WIN32_FIND_DATAW* fd1 = &(*(const Entry* const*)arg1)->data;
  684. const WIN32_FIND_DATAW* fd2 = &(*(const Entry* const*)arg2)->data;
  685. int cmp = compareType(fd1, fd2);
  686. if (cmp)
  687. return cmp;
  688. cmp = fd2->nFileSizeHigh - fd1->nFileSizeHigh;
  689. if (cmp < 0)
  690. return -1;
  691. else if (cmp > 0)
  692. return 1;
  693. cmp = fd2->nFileSizeLow - fd1->nFileSizeLow;
  694. return cmp<0? -1: cmp>0? 1: 0;
  695. }
  696. static int __cdecl compareDate(const void* arg1, const void* arg2)
  697. {
  698. const WIN32_FIND_DATAW* fd1 = &(*(const Entry* const*)arg1)->data;
  699. const WIN32_FIND_DATAW* fd2 = &(*(const Entry* const*)arg2)->data;
  700. int cmp = compareType(fd1, fd2);
  701. if (cmp)
  702. return cmp;
  703. return CompareFileTime(&fd2->ftLastWriteTime, &fd1->ftLastWriteTime);
  704. }
  705. static int (CDECL *sortFunctions[])(const void* arg1, const void* arg2) = {
  706. compareName, /* SORT_NAME */
  707. compareExt, /* SORT_EXT */
  708. compareSize, /* SORT_SIZE */
  709. compareDate /* SORT_DATE */
  710. };
  711. static void SortDirectory(Entry* dir, SORT_ORDER sortOrder)
  712. {
  713. Entry* entry;
  714. Entry** array, **p;
  715. int len;
  716. len = 0;
  717. for(entry=dir->down; entry; entry=entry->next)
  718. len++;
  719. if (len) {
  720. array = HeapAlloc(GetProcessHeap(), 0, len*sizeof(Entry*));
  721. p = array;
  722. for(entry=dir->down; entry; entry=entry->next)
  723. *p++ = entry;
  724. /* call qsort with the appropriate compare function */
  725. qsort(array, len, sizeof(array[0]), sortFunctions[sortOrder]);
  726. dir->down = array[0];
  727. for(p=array; --len; p++)
  728. p[0]->next = p[1];
  729. (*p)->next = 0;
  730. HeapFree(GetProcessHeap(), 0, array);
  731. }
  732. }
  733. static void read_directory(Entry* dir, LPCWSTR path, SORT_ORDER sortOrder, HWND hwnd)
  734. {
  735. WCHAR buffer[MAX_PATH];
  736. Entry* entry;
  737. LPCWSTR s;
  738. PWSTR d;
  739. if (dir->etype == ET_SHELL)
  740. {
  741. read_directory_shell(dir, hwnd);
  742. if (Globals.prescan_node) {
  743. s = path;
  744. d = buffer;
  745. while(*s)
  746. *d++ = *s++;
  747. *d++ = '\\';
  748. for(entry=dir->down; entry; entry=entry->next)
  749. if (entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
  750. read_directory_shell(entry, hwnd);
  751. SortDirectory(entry, sortOrder);
  752. }
  753. }
  754. }
  755. else
  756. {
  757. read_directory_win(dir, path);
  758. if (Globals.prescan_node) {
  759. s = path;
  760. d = buffer;
  761. while(*s)
  762. *d++ = *s++;
  763. *d++ = '\\';
  764. for(entry=dir->down; entry; entry=entry->next)
  765. if (entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
  766. lstrcpyW(d, entry->data.cFileName);
  767. read_directory_win(entry, buffer);
  768. SortDirectory(entry, sortOrder);
  769. }
  770. }
  771. }
  772. SortDirectory(dir, sortOrder);
  773. }
  774. static Entry* read_tree(Root* root, LPCWSTR path, LPITEMIDLIST pidl, LPWSTR drv, SORT_ORDER sortOrder, HWND hwnd)
  775. {
  776. static const WCHAR sBackslash[] = {'\\', '\0'};
  777. if (pidl)
  778. {
  779. /* read shell namespace tree */
  780. root->drive_type = DRIVE_UNKNOWN;
  781. drv[0] = '\\';
  782. drv[1] = '\0';
  783. load_string(root->volname, ARRAY_SIZE(root->volname), IDS_DESKTOP);
  784. root->fs_flags = 0;
  785. load_string(root->fs, ARRAY_SIZE(root->fs), IDS_SHELL);
  786. return read_tree_shell(root, pidl, sortOrder, hwnd);
  787. }
  788. /* read WIN32 file system tree */
  789. root->drive_type = GetDriveTypeW(path);
  790. lstrcatW(drv, sBackslash);
  791. GetVolumeInformationW(drv, root->volname, _MAX_FNAME, 0, 0, &root->fs_flags, root->fs, _MAX_DIR);
  792. lstrcpyW(root->path, drv);
  793. return read_tree_win(root, path, sortOrder, hwnd);
  794. }
  795. /* flags to filter different file types */
  796. enum TYPE_FILTER {
  797. TF_DIRECTORIES = 0x01,
  798. TF_PROGRAMS = 0x02,
  799. TF_DOCUMENTS = 0x04,
  800. TF_OTHERS = 0x08,
  801. TF_HIDDEN = 0x10,
  802. TF_ALL = 0x1F
  803. };
  804. static ChildWnd* alloc_child_window(LPCWSTR path, LPITEMIDLIST pidl, HWND hwnd)
  805. {
  806. WCHAR drv[_MAX_DRIVE+1], dir[_MAX_DIR], name[_MAX_FNAME], ext[_MAX_EXT];
  807. WCHAR dir_path[MAX_PATH];
  808. static const WCHAR sAsterics[] = {'*', '\0'};
  809. static const WCHAR sTitleFmt[] = {'%','s',' ','-',' ','%','s','\0'};
  810. ChildWnd* child = HeapAlloc(GetProcessHeap(), 0, sizeof(ChildWnd));
  811. Root* root = &child->root;
  812. Entry* entry;
  813. memset(child, 0, sizeof(ChildWnd));
  814. child->left.treePane = TRUE;
  815. child->left.visible_cols = 0;
  816. child->right.treePane = FALSE;
  817. child->right.visible_cols = COL_SIZE|COL_DATE|COL_TIME|COL_ATTRIBUTES|COL_INDEX|COL_LINKS;
  818. child->pos.length = sizeof(WINDOWPLACEMENT);
  819. child->pos.flags = 0;
  820. child->pos.showCmd = SW_SHOWNORMAL;
  821. child->pos.rcNormalPosition.left = CW_USEDEFAULT;
  822. child->pos.rcNormalPosition.top = CW_USEDEFAULT;
  823. child->pos.rcNormalPosition.right = CW_USEDEFAULT;
  824. child->pos.rcNormalPosition.bottom = CW_USEDEFAULT;
  825. child->focus_pane = 0;
  826. child->split_pos = DEFAULT_SPLIT_POS;
  827. child->sortOrder = SORT_NAME;
  828. child->header_wdths_ok = FALSE;
  829. if (path)
  830. {
  831. int pathlen = lstrlenW(path);
  832. const WCHAR *npath = path;
  833. if (path[0] == '"' && path[pathlen - 1] == '"')
  834. {
  835. npath++;
  836. pathlen--;
  837. }
  838. lstrcpynW(child->path, npath, pathlen + 1);
  839. _wsplitpath(child->path, drv, dir, name, ext);
  840. }
  841. lstrcpyW(child->filter_pattern, sAsterics);
  842. child->filter_flags = TF_ALL;
  843. root->entry.level = 0;
  844. lstrcpyW(dir_path, drv);
  845. lstrcatW(dir_path, dir);
  846. entry = read_tree(root, dir_path, pidl, drv, child->sortOrder, hwnd);
  847. if (root->entry.etype == ET_SHELL)
  848. load_string(root->entry.data.cFileName, ARRAY_SIZE(root->entry.data.cFileName), IDS_DESKTOP);
  849. else
  850. wsprintfW(root->entry.data.cFileName, sTitleFmt, drv, root->fs);
  851. root->entry.data.dwFileAttributes = FILE_ATTRIBUTE_DIRECTORY;
  852. child->left.root = &root->entry;
  853. child->right.root = NULL;
  854. set_curdir(child, entry, 0, hwnd);
  855. return child;
  856. }
  857. /* free all memory associated with a child window */
  858. static void free_child_window(ChildWnd* child)
  859. {
  860. free_entries(&child->root.entry);
  861. HeapFree(GetProcessHeap(), 0, child);
  862. }
  863. /* get full path of specified directory entry */
  864. static void get_path(Entry* dir, PWSTR path)
  865. {
  866. Entry* entry;
  867. int len = 0;
  868. int level = 0;
  869. if (dir->etype == ET_SHELL)
  870. {
  871. SFGAOF attribs;
  872. HRESULT hr = S_OK;
  873. path[0] = '\0';
  874. attribs = 0;
  875. if (dir->folder)
  876. hr = IShellFolder_GetAttributesOf(dir->folder, 1, (LPCITEMIDLIST*)&dir->pidl, &attribs);
  877. if (SUCCEEDED(hr) && (attribs&SFGAO_FILESYSTEM)) {
  878. IShellFolder* parent = dir->up? dir->up->folder: Globals.iDesktop;
  879. hr = path_from_pidlW(parent, dir->pidl, path, MAX_PATH);
  880. }
  881. }
  882. else
  883. {
  884. for(entry=dir; entry; level++) {
  885. LPCWSTR name;
  886. int l;
  887. {
  888. LPCWSTR s;
  889. name = entry->data.cFileName;
  890. s = name;
  891. for(l=0; *s && *s != '/' && *s != '\\'; s++)
  892. l++;
  893. }
  894. if (entry->up) {
  895. if (l > 0) {
  896. memmove(path+l+1, path, len*sizeof(WCHAR));
  897. memcpy(path+1, name, l*sizeof(WCHAR));
  898. len += l+1;
  899. path[0] = '\\';
  900. }
  901. entry = entry->up;
  902. } else {
  903. memmove(path+l, path, len*sizeof(WCHAR));
  904. memcpy(path, name, l*sizeof(WCHAR));
  905. len += l;
  906. break;
  907. }
  908. }
  909. if (!level) path[len++] = '\\';
  910. path[len] = '\0';
  911. }
  912. }
  913. static windowOptions load_registry_settings(void)
  914. {
  915. DWORD size;
  916. DWORD type;
  917. HKEY hKey;
  918. windowOptions opts;
  919. LOGFONTW logfont;
  920. RegOpenKeyExW( HKEY_CURRENT_USER, registry_key,
  921. 0, KEY_QUERY_VALUE, &hKey );
  922. size = sizeof(opts.start_x);
  923. if( RegQueryValueExW( hKey, reg_start_x, NULL, &type,
  924. (LPBYTE) &opts.start_x, &size ) != ERROR_SUCCESS )
  925. opts.start_x = CW_USEDEFAULT;
  926. size = sizeof(opts.start_y);
  927. if( RegQueryValueExW( hKey, reg_start_y, NULL, &type,
  928. (LPBYTE) &opts.start_y, &size ) != ERROR_SUCCESS )
  929. opts.start_y = CW_USEDEFAULT;
  930. size = sizeof(opts.width);
  931. if( RegQueryValueExW( hKey, reg_width, NULL, &type,
  932. (LPBYTE) &opts.width, &size ) != ERROR_SUCCESS )
  933. opts.width = CW_USEDEFAULT;
  934. size = sizeof(opts.height);
  935. if( RegQueryValueExW( hKey, reg_height, NULL, &type,
  936. (LPBYTE) &opts.height, &size ) != ERROR_SUCCESS )
  937. opts.height = CW_USEDEFAULT;
  938. size=sizeof(logfont);
  939. if( RegQueryValueExW( hKey, reg_logfont, NULL, &type,
  940. (LPBYTE) &logfont, &size ) != ERROR_SUCCESS )
  941. GetObjectW(GetStockObject(DEFAULT_GUI_FONT),sizeof(logfont),&logfont);
  942. RegCloseKey( hKey );
  943. Globals.hfont = CreateFontIndirectW(&logfont);
  944. return opts;
  945. }
  946. static void save_registry_settings(void)
  947. {
  948. WINDOWINFO wi;
  949. HKEY hKey;
  950. INT width, height;
  951. LOGFONTW logfont;
  952. wi.cbSize = sizeof( WINDOWINFO );
  953. GetWindowInfo(Globals.hMainWnd, &wi);
  954. width = wi.rcWindow.right - wi.rcWindow.left;
  955. height = wi.rcWindow.bottom - wi.rcWindow.top;
  956. if ( RegOpenKeyExW( HKEY_CURRENT_USER, registry_key,
  957. 0, KEY_SET_VALUE, &hKey ) != ERROR_SUCCESS )
  958. {
  959. /* Unable to save registry settings - try to create key */
  960. if ( RegCreateKeyExW( HKEY_CURRENT_USER, registry_key,
  961. 0, NULL, REG_OPTION_NON_VOLATILE,
  962. KEY_SET_VALUE, NULL, &hKey, NULL ) != ERROR_SUCCESS )
  963. {
  964. /* FIXME: Cannot create key */
  965. return;
  966. }
  967. }
  968. /* Save all of the settings */
  969. RegSetValueExW( hKey, reg_start_x, 0, REG_DWORD,
  970. (LPBYTE) &wi.rcWindow.left, sizeof(DWORD) );
  971. RegSetValueExW( hKey, reg_start_y, 0, REG_DWORD,
  972. (LPBYTE) &wi.rcWindow.top, sizeof(DWORD) );
  973. RegSetValueExW( hKey, reg_width, 0, REG_DWORD,
  974. (LPBYTE) &width, sizeof(DWORD) );
  975. RegSetValueExW( hKey, reg_height, 0, REG_DWORD,
  976. (LPBYTE) &height, sizeof(DWORD) );
  977. GetObjectW(Globals.hfont, sizeof(logfont), &logfont);
  978. RegSetValueExW( hKey, reg_logfont, 0, REG_BINARY,
  979. (LPBYTE)&logfont, sizeof(LOGFONTW) );
  980. /* TODO: Save more settings here (List vs. Detailed View, etc.) */
  981. RegCloseKey( hKey );
  982. }
  983. static void resize_frame_rect(HWND hwnd, PRECT prect)
  984. {
  985. int new_top;
  986. RECT rt;
  987. if (IsWindowVisible(Globals.htoolbar)) {
  988. SendMessageW(Globals.htoolbar, WM_SIZE, 0, 0);
  989. GetClientRect(Globals.htoolbar, &rt);
  990. prect->top = rt.bottom+3;
  991. prect->bottom -= rt.bottom+3;
  992. }
  993. if (IsWindowVisible(Globals.hdrivebar)) {
  994. SendMessageW(Globals.hdrivebar, WM_SIZE, 0, 0);
  995. GetClientRect(Globals.hdrivebar, &rt);
  996. new_top = --prect->top + rt.bottom+3;
  997. MoveWindow(Globals.hdrivebar, 0, prect->top, rt.right, new_top, TRUE);
  998. prect->top = new_top;
  999. prect->bottom -= rt.bottom+2;
  1000. }
  1001. if (IsWindowVisible(Globals.hstatusbar)) {
  1002. int parts[] = {300, 500};
  1003. SendMessageW(Globals.hstatusbar, WM_SIZE, 0, 0);
  1004. SendMessageW(Globals.hstatusbar, SB_SETPARTS, 2, (LPARAM)&parts);
  1005. GetClientRect(Globals.hstatusbar, &rt);
  1006. prect->bottom -= rt.bottom;
  1007. }
  1008. MoveWindow(Globals.hmdiclient, prect->left-1,prect->top-1,prect->right+2,prect->bottom+1, TRUE);
  1009. }
  1010. static void resize_frame(HWND hwnd, int cx, int cy)
  1011. {
  1012. RECT rect;
  1013. rect.left = 0;
  1014. rect.top = 0;
  1015. rect.right = cx;
  1016. rect.bottom = cy;
  1017. resize_frame_rect(hwnd, &rect);
  1018. }
  1019. static void resize_frame_client(HWND hwnd)
  1020. {
  1021. RECT rect;
  1022. GetClientRect(hwnd, &rect);
  1023. resize_frame_rect(hwnd, &rect);
  1024. }
  1025. static HHOOK hcbthook;
  1026. static ChildWnd* newchild = NULL;
  1027. static LRESULT CALLBACK CBTProc(int code, WPARAM wparam, LPARAM lparam)
  1028. {
  1029. if (code==HCBT_CREATEWND && newchild) {
  1030. ChildWnd* child = newchild;
  1031. newchild = NULL;
  1032. child->hwnd = (HWND) wparam;
  1033. SetWindowLongPtrW(child->hwnd, GWLP_USERDATA, (LPARAM)child);
  1034. }
  1035. return CallNextHookEx(hcbthook, code, wparam, lparam);
  1036. }
  1037. static HWND create_child_window(ChildWnd* child)
  1038. {
  1039. MDICREATESTRUCTW mcs;
  1040. int idx;
  1041. mcs.szClass = sWINEFILETREE;
  1042. mcs.szTitle = child->path;
  1043. mcs.hOwner = Globals.hInstance;
  1044. mcs.x = child->pos.rcNormalPosition.left;
  1045. mcs.y = child->pos.rcNormalPosition.top;
  1046. mcs.cx = child->pos.rcNormalPosition.right-child->pos.rcNormalPosition.left;
  1047. mcs.cy = child->pos.rcNormalPosition.bottom-child->pos.rcNormalPosition.top;
  1048. mcs.style = 0;
  1049. mcs.lParam = 0;
  1050. hcbthook = SetWindowsHookExW(WH_CBT, CBTProc, 0, GetCurrentThreadId());
  1051. newchild = child;
  1052. child->hwnd = (HWND)SendMessageW(Globals.hmdiclient, WM_MDICREATE, 0, (LPARAM)&mcs);
  1053. if (!child->hwnd) {
  1054. UnhookWindowsHookEx(hcbthook);
  1055. return 0;
  1056. }
  1057. UnhookWindowsHookEx(hcbthook);
  1058. SendMessageW(child->left.hwnd, LB_SETITEMHEIGHT, 1, max(Globals.spaceSize.cy,IMAGE_HEIGHT+3));
  1059. SendMessageW(child->right.hwnd, LB_SETITEMHEIGHT, 1, max(Globals.spaceSize.cy,IMAGE_HEIGHT+3));
  1060. idx = SendMessageW(child->left.hwnd, LB_FINDSTRING, 0, (LPARAM)child->left.cur);
  1061. SendMessageW(child->left.hwnd, LB_SETCURSEL, idx, 0);
  1062. return child->hwnd;
  1063. }
  1064. #define RFF_NODEFAULT 0x02 /* No default item selected. */
  1065. static void WineFile_OnRun( HWND hwnd )
  1066. {
  1067. static const WCHAR shell32_dll[] = {'S','H','E','L','L','3','2','.','D','L','L',0};
  1068. void (WINAPI *pRunFileDlgAW )(HWND, HICON, LPWSTR, LPWSTR, LPWSTR, DWORD);
  1069. HMODULE hshell = GetModuleHandleW( shell32_dll );
  1070. HICON hIcon = LoadIconW(Globals.hInstance, MAKEINTRESOURCEW(IDI_WINEFILE));
  1071. pRunFileDlgAW = (void*)GetProcAddress(hshell, (LPCSTR)61);
  1072. if (pRunFileDlgAW) pRunFileDlgAW( hwnd, hIcon, NULL, NULL, NULL, RFF_NODEFAULT);
  1073. }
  1074. static INT_PTR CALLBACK DestinationDlgProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
  1075. {
  1076. WCHAR b1[BUFFER_LEN], b2[BUFFER_LEN];
  1077. switch(nmsg) {
  1078. case WM_INITDIALOG:
  1079. SetWindowLongPtrW(hwnd, GWLP_USERDATA, lparam);
  1080. SetWindowTextW(GetDlgItem(hwnd, 201), (LPCWSTR)lparam);
  1081. return 1;
  1082. case WM_COMMAND: {
  1083. int id = (int)wparam;
  1084. switch(id) {
  1085. case IDOK: {
  1086. LPWSTR dest = (LPWSTR)GetWindowLongPtrW(hwnd, GWLP_USERDATA);
  1087. GetWindowTextW(GetDlgItem(hwnd, 201), dest, MAX_PATH);
  1088. EndDialog(hwnd, id);
  1089. break;}
  1090. case IDCANCEL:
  1091. EndDialog(hwnd, id);
  1092. break;
  1093. case 254:
  1094. MessageBoxW(hwnd, RS(b1,IDS_NO_IMPL), RS(b2,IDS_WINEFILE), MB_OK);
  1095. break;
  1096. }
  1097. return 1;
  1098. }
  1099. }
  1100. return 0;
  1101. }
  1102. struct FilterDialog {
  1103. WCHAR pattern[MAX_PATH];
  1104. int flags;
  1105. };
  1106. static INT_PTR CALLBACK FilterDialogDlgProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
  1107. {
  1108. static struct FilterDialog* dlg;
  1109. switch(nmsg) {
  1110. case WM_INITDIALOG:
  1111. dlg = (struct FilterDialog*) lparam;
  1112. SetWindowTextW(GetDlgItem(hwnd, IDC_VIEW_PATTERN), dlg->pattern);
  1113. set_check(hwnd, IDC_VIEW_TYPE_DIRECTORIES, dlg->flags&TF_DIRECTORIES);
  1114. set_check(hwnd, IDC_VIEW_TYPE_PROGRAMS, dlg->flags&TF_PROGRAMS);
  1115. set_check(hwnd, IDC_VIEW_TYPE_DOCUMENTS, dlg->flags&TF_DOCUMENTS);
  1116. set_check(hwnd, IDC_VIEW_TYPE_OTHERS, dlg->flags&TF_OTHERS);
  1117. set_check(hwnd, IDC_VIEW_TYPE_HIDDEN, dlg->flags&TF_HIDDEN);
  1118. return 1;
  1119. case WM_COMMAND: {
  1120. int id = (int)wparam;
  1121. if (id == IDOK) {
  1122. int flags = 0;
  1123. GetWindowTextW(GetDlgItem(hwnd, IDC_VIEW_PATTERN), dlg->pattern, MAX_PATH);
  1124. flags |= get_check(hwnd, IDC_VIEW_TYPE_DIRECTORIES) ? TF_DIRECTORIES : 0;
  1125. flags |= get_check(hwnd, IDC_VIEW_TYPE_PROGRAMS) ? TF_PROGRAMS : 0;
  1126. flags |= get_check(hwnd, IDC_VIEW_TYPE_DOCUMENTS) ? TF_DOCUMENTS : 0;
  1127. flags |= get_check(hwnd, IDC_VIEW_TYPE_OTHERS) ? TF_OTHERS : 0;
  1128. flags |= get_check(hwnd, IDC_VIEW_TYPE_HIDDEN) ? TF_HIDDEN : 0;
  1129. dlg->flags = flags;
  1130. EndDialog(hwnd, id);
  1131. } else if (id == IDCANCEL)
  1132. EndDialog(hwnd, id);
  1133. return 1;}
  1134. }
  1135. return 0;
  1136. }
  1137. struct PropertiesDialog {
  1138. WCHAR path[MAX_PATH];
  1139. Entry entry;
  1140. void* pVersionData;
  1141. };
  1142. /* Structure used to store enumerated languages and code pages. */
  1143. struct LANGANDCODEPAGE {
  1144. WORD wLanguage;
  1145. WORD wCodePage;
  1146. } *lpTranslate;
  1147. static LPCSTR InfoStrings[] = {
  1148. "Comments",
  1149. "CompanyName",
  1150. "FileDescription",
  1151. "FileVersion",
  1152. "InternalName",
  1153. "LegalCopyright",
  1154. "LegalTrademarks",
  1155. "OriginalFilename",
  1156. "PrivateBuild",
  1157. "ProductName",
  1158. "ProductVersion",
  1159. "SpecialBuild",
  1160. NULL
  1161. };
  1162. static void PropDlg_DisplayValue(HWND hlbox, HWND hedit)
  1163. {
  1164. int idx = SendMessageW(hlbox, LB_GETCURSEL, 0, 0);
  1165. if (idx != LB_ERR) {
  1166. LPCWSTR pValue = (LPCWSTR)SendMessageW(hlbox, LB_GETITEMDATA, idx, 0);
  1167. if (pValue)
  1168. SetWindowTextW(hedit, pValue);
  1169. }
  1170. }
  1171. static void CheckForFileInfo(struct PropertiesDialog* dlg, HWND hwnd, LPCWSTR strFilename)
  1172. {
  1173. static const WCHAR sBackSlash[] = {'\\','\0'};
  1174. static const WCHAR sTranslation[] = {'\\','V','a','r','F','i','l','e','I','n','f','o','\\','T','r','a','n','s','l','a','t','i','o','n','\0'};
  1175. static const WCHAR sStringFileInfo[] = {'\\','S','t','r','i','n','g','F','i','l','e','I','n','f','o','\\',
  1176. '%','0','4','x','%','0','4','x','\\','%','s','\0'};
  1177. static const WCHAR sFmt[] = {'%','d','.','%','d','.','%','d','.','%','d','\0'};
  1178. DWORD dwVersionDataLen = GetFileVersionInfoSizeW(strFilename, NULL);
  1179. if (dwVersionDataLen) {
  1180. dlg->pVersionData = HeapAlloc(GetProcessHeap(), 0, dwVersionDataLen);
  1181. if (GetFileVersionInfoW(strFilename, 0, dwVersionDataLen, dlg->pVersionData)) {
  1182. LPVOID pVal;
  1183. UINT nValLen;
  1184. if (VerQueryValueW(dlg->pVersionData, sBackSlash, &pVal, &nValLen)) {
  1185. if (nValLen == sizeof(VS_FIXEDFILEINFO)) {
  1186. VS_FIXEDFILEINFO* pFixedFileInfo = (VS_FIXEDFILEINFO*)pVal;
  1187. WCHAR buffer[BUFFER_LEN];
  1188. swprintf(buffer, ARRAY_SIZE(buffer), sFmt,
  1189. HIWORD(pFixedFileInfo->dwFileVersionMS), LOWORD(pFixedFileInfo->dwFileVersionMS),
  1190. HIWORD(pFixedFileInfo->dwFileVersionLS), LOWORD(pFixedFileInfo->dwFileVersionLS));
  1191. SetDlgItemTextW(hwnd, IDC_STATIC_PROP_VERSION, buffer);
  1192. }
  1193. }
  1194. /* Read the list of languages and code pages. */
  1195. if (VerQueryValueW(dlg->pVersionData, sTranslation, &pVal, &nValLen)) {
  1196. struct LANGANDCODEPAGE* pTranslate = (struct LANGANDCODEPAGE*)pVal;
  1197. struct LANGANDCODEPAGE* pEnd = (struct LANGANDCODEPAGE*)((LPBYTE)pVal+nValLen);
  1198. HWND hlbox = GetDlgItem(hwnd, IDC_LIST_PROP_VERSION_TYPES);
  1199. /* Read the file description for each language and code page. */
  1200. for(; pTranslate<pEnd; ++pTranslate) {
  1201. LPCSTR* p;
  1202. for(p=InfoStrings; *p; ++p) {
  1203. WCHAR subblock[200];
  1204. WCHAR infoStr[100];
  1205. LPCWSTR pTxt;
  1206. UINT nValLen;
  1207. LPCSTR pInfoString = *p;
  1208. MultiByteToWideChar(CP_ACP, 0, pInfoString, -1, infoStr, 100);
  1209. wsprintfW(subblock, sStringFileInfo, pTranslate->wLanguage, pTranslate->wCodePage, infoStr);
  1210. /* Retrieve file description for language and code page */
  1211. if (VerQueryValueW(dlg->pVersionData, subblock, (PVOID)&pTxt, &nValLen)) {
  1212. int idx = SendMessageW(hlbox, LB_ADDSTRING, 0L, (LPARAM)infoStr);
  1213. SendMessageW(hlbox, LB_SETITEMDATA, idx, (LPARAM)pTxt);
  1214. }
  1215. }
  1216. }
  1217. SendMessageW(hlbox, LB_SETCURSEL, 0, 0);
  1218. PropDlg_DisplayValue(hlbox, GetDlgItem(hwnd,IDC_LIST_PROP_VERSION_VALUES));
  1219. }
  1220. }
  1221. }
  1222. }
  1223. static INT_PTR CALLBACK PropertiesDialogDlgProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
  1224. {
  1225. static struct PropertiesDialog* dlg;
  1226. switch(nmsg) {
  1227. case WM_INITDIALOG: {
  1228. static const WCHAR sByteFmt[] = {'%','s',' ','B','y','t','e','s','\0'};
  1229. WCHAR b1[BUFFER_LEN], b2[BUFFER_LEN];
  1230. LPWIN32_FIND_DATAW pWFD;
  1231. dlg = (struct PropertiesDialog*) lparam;
  1232. pWFD = (LPWIN32_FIND_DATAW)&dlg->entry.data;
  1233. GetWindowTextW(hwnd, b1, MAX_PATH);
  1234. wsprintfW(b2, b1, pWFD->cFileName);
  1235. SetWindowTextW(hwnd, b2);
  1236. format_date(&pWFD->ftLastWriteTime, b1, COL_DATE|COL_TIME);
  1237. SetWindowTextW(GetDlgItem(hwnd, IDC_STATIC_PROP_LASTCHANGE), b1);
  1238. format_longlong( b1, ((ULONGLONG)pWFD->nFileSizeHigh << 32) | pWFD->nFileSizeLow );
  1239. wsprintfW(b2, sByteFmt, b1);
  1240. SetWindowTextW(GetDlgItem(hwnd, IDC_STATIC_PROP_SIZE), b2);
  1241. SetWindowTextW(GetDlgItem(hwnd, IDC_STATIC_PROP_FILENAME), pWFD->cFileName);
  1242. SetWindowTextW(GetDlgItem(hwnd, IDC_STATIC_PROP_PATH), dlg->path);
  1243. set_check(hwnd, IDC_CHECK_READONLY, pWFD->dwFileAttributes&FILE_ATTRIBUTE_READONLY);
  1244. set_check(hwnd, IDC_CHECK_ARCHIVE, pWFD->dwFileAttributes&FILE_ATTRIBUTE_ARCHIVE);
  1245. set_check(hwnd, IDC_CHECK_COMPRESSED, pWFD->dwFileAttributes&FILE_ATTRIBUTE_COMPRESSED);
  1246. set_check(hwnd, IDC_CHECK_HIDDEN, pWFD->dwFileAttributes&FILE_ATTRIBUTE_HIDDEN);
  1247. set_check(hwnd, IDC_CHECK_SYSTEM, pWFD->dwFileAttributes&FILE_ATTRIBUTE_SYSTEM);
  1248. CheckForFileInfo(dlg, hwnd, dlg->path);
  1249. return 1;}
  1250. case WM_COMMAND: {
  1251. int id = (int)wparam;
  1252. switch(HIWORD(wparam)) {
  1253. case LBN_SELCHANGE: {
  1254. HWND hlbox = GetDlgItem(hwnd, IDC_LIST_PROP_VERSION_TYPES);
  1255. PropDlg_DisplayValue(hlbox, GetDlgItem(hwnd,IDC_LIST_PROP_VERSION_VALUES));
  1256. break;
  1257. }
  1258. case BN_CLICKED:
  1259. if (id==IDOK || id==IDCANCEL)
  1260. EndDialog(hwnd, id);
  1261. }
  1262. return 1;}
  1263. case WM_NCDESTROY:
  1264. HeapFree(GetProcessHeap(), 0, dlg->pVersionData);
  1265. dlg->pVersionData = NULL;
  1266. break;
  1267. }
  1268. return 0;
  1269. }
  1270. static void show_properties_dlg(Entry* entry, HWND hwnd)
  1271. {
  1272. struct PropertiesDialog dlg;
  1273. memset(&dlg, 0, sizeof(struct PropertiesDialog));
  1274. get_path(entry, dlg.path);
  1275. memcpy(&dlg.entry, entry, sizeof(Entry));
  1276. DialogBoxParamW(Globals.hInstance, MAKEINTRESOURCEW(IDD_DIALOG_PROPERTIES), hwnd, PropertiesDialogDlgProc, (LPARAM)&dlg);
  1277. }
  1278. static struct FullScreenParameters {
  1279. BOOL mode;
  1280. RECT orgPos;
  1281. BOOL wasZoomed;
  1282. } g_fullscreen = {
  1283. FALSE, /* mode */
  1284. {0, 0, 0, 0},
  1285. FALSE
  1286. };
  1287. static void frame_get_clientspace(HWND hwnd, PRECT prect)
  1288. {
  1289. RECT rt;
  1290. if (!IsIconic(hwnd))
  1291. GetClientRect(hwnd, prect);
  1292. else {
  1293. WINDOWPLACEMENT wp;
  1294. wp.length = sizeof(wp);
  1295. GetWindowPlacement(hwnd, &wp);
  1296. prect->left = prect->top = 0;
  1297. prect->right = wp.rcNormalPosition.right-wp.rcNormalPosition.left-
  1298. 2*(GetSystemMetrics(SM_CXSIZEFRAME)+GetSystemMetrics(SM_CXEDGE));
  1299. prect->bottom = wp.rcNormalPosition.bottom-wp.rcNormalPosition.top-
  1300. 2*(GetSystemMetrics(SM_CYSIZEFRAME)+GetSystemMetrics(SM_CYEDGE))-
  1301. GetSystemMetrics(SM_CYCAPTION)-GetSystemMetrics(SM_CYMENUSIZE);
  1302. }
  1303. if (IsWindowVisible(Globals.htoolbar)) {
  1304. GetClientRect(Globals.htoolbar, &rt);
  1305. prect->top += rt.bottom+2;
  1306. }
  1307. if (IsWindowVisible(Globals.hdrivebar)) {
  1308. GetClientRect(Globals.hdrivebar, &rt);
  1309. prect->top += rt.bottom+2;
  1310. }
  1311. if (IsWindowVisible(Globals.hstatusbar)) {
  1312. GetClientRect(Globals.hstatusbar, &rt);
  1313. prect->bottom -= rt.bottom;
  1314. }
  1315. }
  1316. static BOOL toggle_fullscreen(HWND hwnd)
  1317. {
  1318. RECT rt;
  1319. if ((g_fullscreen.mode=!g_fullscreen.mode)) {
  1320. GetWindowRect(hwnd, &g_fullscreen.orgPos);
  1321. g_fullscreen.wasZoomed = IsZoomed(hwnd);
  1322. Frame_CalcFrameClient(hwnd, &rt);
  1323. MapWindowPoints( hwnd, 0, (POINT *)&rt, 2 );
  1324. rt.left = g_fullscreen.orgPos.left-rt.left;
  1325. rt.top = g_fullscreen.orgPos.top-rt.top;
  1326. rt.right = GetSystemMetrics(SM_CXSCREEN)+g_fullscreen.orgPos.right-rt.right;
  1327. rt.bottom = GetSystemMetrics(SM_CYSCREEN)+g_fullscreen.orgPos.bottom-rt.bottom;
  1328. MoveWindow(hwnd, rt.left, rt.top, rt.right-rt.left, rt.bottom-rt.top, TRUE);
  1329. } else {
  1330. MoveWindow(hwnd, g_fullscreen.orgPos.left, g_fullscreen.orgPos.top,
  1331. g_fullscreen.orgPos.right-g_fullscreen.orgPos.left,
  1332. g_fullscreen.orgPos.bottom-g_fullscreen.orgPos.top, TRUE);
  1333. if (g_fullscreen.wasZoomed)
  1334. ShowWindow(hwnd, WS_MAXIMIZE);
  1335. }
  1336. return g_fullscreen.mode;
  1337. }
  1338. static void fullscreen_move(HWND hwnd)
  1339. {
  1340. RECT rt, pos;
  1341. GetWindowRect(hwnd, &pos);
  1342. Frame_CalcFrameClient(hwnd, &rt);
  1343. MapWindowPoints( hwnd, 0, (POINT *)&rt, 2 );
  1344. rt.left = pos.left-rt.left;
  1345. rt.top = pos.top-rt.top;
  1346. rt.right = GetSystemMetrics(SM_CXSCREEN)+pos.right-rt.right;
  1347. rt.bottom = GetSystemMetrics(SM_CYSCREEN)+pos.bottom-rt.bottom;
  1348. MoveWindow(hwnd, rt.left, rt.top, rt.right-rt.left, rt.bottom-rt.top, TRUE);
  1349. }
  1350. static void toggle_child(HWND hwnd, UINT cmd, HWND hchild)
  1351. {
  1352. BOOL vis = IsWindowVisible(hchild);
  1353. CheckMenuItem(Globals.hMenuOptions, cmd, vis?MF_BYCOMMAND:MF_BYCOMMAND|MF_CHECKED);
  1354. ShowWindow(hchild, vis?SW_HIDE:SW_SHOW);
  1355. if (g_fullscreen.mode)
  1356. fullscreen_move(hwnd);
  1357. resize_frame_client(hwnd);
  1358. }
  1359. static BOOL activate_drive_window(LPCWSTR path)
  1360. {
  1361. WCHAR drv1[_MAX_DRIVE], drv2[_MAX_DRIVE];
  1362. HWND child_wnd;
  1363. _wsplitpath(path, drv1, 0, 0, 0);
  1364. /* search for an already open window for the same drive */
  1365. for(child_wnd=GetNextWindow(Globals.hmdiclient,GW_CHILD); child_wnd; child_wnd=GetNextWindow(child_wnd, GW_HWNDNEXT)) {
  1366. ChildWnd* child = (ChildWnd*)GetWindowLongPtrW(child_wnd, GWLP_USERDATA);
  1367. if (child) {
  1368. _wsplitpath(child->root.path, drv2, 0, 0, 0);
  1369. if (!lstrcmpiW(drv2, drv1)) {
  1370. SendMessageW(Globals.hmdiclient, WM_MDIACTIVATE, (WPARAM)child_wnd, 0);
  1371. if (IsIconic(child_wnd))
  1372. ShowWindow(child_wnd, SW_SHOWNORMAL);
  1373. return TRUE;
  1374. }
  1375. }
  1376. }
  1377. return FALSE;
  1378. }
  1379. static BOOL activate_fs_window(LPCWSTR filesys)
  1380. {
  1381. HWND child_wnd;
  1382. /* search for an already open window of the given file system name */
  1383. for(child_wnd=GetNextWindow(Globals.hmdiclient,GW_CHILD); child_wnd; child_wnd=GetNextWindow(child_wnd, GW_HWNDNEXT)) {
  1384. ChildWnd* child = (ChildWnd*) GetWindowLongPtrW(child_wnd, GWLP_USERDATA);
  1385. if (child) {
  1386. if (!lstrcmpiW(child->root.fs, filesys)) {
  1387. SendMessageW(Globals.hmdiclient, WM_MDIACTIVATE, (WPARAM)child_wnd, 0);
  1388. if (IsIconic(child_wnd))
  1389. ShowWindow(child_wnd, SW_SHOWNORMAL);
  1390. return TRUE;
  1391. }
  1392. }
  1393. }
  1394. return FALSE;
  1395. }
  1396. static LRESULT CALLBACK FrameWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
  1397. {
  1398. WCHAR b1[BUFFER_LEN], b2[BUFFER_LEN];
  1399. switch(nmsg) {
  1400. case WM_CLOSE:
  1401. if (Globals.saveSettings)
  1402. save_registry_settings();
  1403. DestroyWindow(hwnd);
  1404. /* clear handle variables */
  1405. Globals.hMenuFrame = 0;
  1406. Globals.hMenuView = 0;
  1407. Globals.hMenuOptions = 0;
  1408. Globals.hMainWnd = 0;
  1409. Globals.hmdiclient = 0;
  1410. Globals.hdrivebar = 0;
  1411. break;
  1412. case WM_DESTROY:
  1413. PostQuitMessage(0);
  1414. break;
  1415. case WM_INITMENUPOPUP: {
  1416. HWND hwndClient = (HWND)SendMessageW(Globals.hmdiclient, WM_MDIGETACTIVE, 0, 0);
  1417. if (!SendMessageW(hwndClient, WM_INITMENUPOPUP, wparam, lparam))
  1418. return 0;
  1419. break;}
  1420. case WM_COMMAND: {
  1421. UINT cmd = LOWORD(wparam);
  1422. HWND hwndClient = (HWND)SendMessageW(Globals.hmdiclient, WM_MDIGETACTIVE, 0, 0);
  1423. if (SendMessageW(hwndClient, WM_DISPATCH_COMMAND, wparam, lparam))
  1424. break;
  1425. if (cmd>=ID_DRIVE_FIRST && cmd<=ID_DRIVE_FIRST+0xFF) {
  1426. WCHAR drv[_MAX_DRIVE], path[MAX_PATH];
  1427. ChildWnd* child;
  1428. LPCWSTR root = Globals.drives;
  1429. int i;
  1430. for(i=cmd-ID_DRIVE_FIRST; i--; root++)
  1431. while(*root)
  1432. root++;
  1433. if (activate_drive_window(root))
  1434. return 0;
  1435. _wsplitpath(root, drv, 0, 0, 0);
  1436. if (!SetCurrentDirectoryW(drv)) {
  1437. display_error(hwnd, GetLastError());
  1438. return 0;
  1439. }
  1440. GetCurrentDirectoryW(MAX_PATH, path); /*TODO: store last directory per drive */
  1441. child = alloc_child_window(path, NULL, hwnd);
  1442. if (!create_child_window(child))
  1443. HeapFree(GetProcessHeap(), 0, child);
  1444. } else switch(cmd) {
  1445. case ID_FILE_EXIT:
  1446. SendMessageW(hwnd, WM_CLOSE, 0, 0);
  1447. break;
  1448. case ID_WINDOW_NEW: {
  1449. WCHAR path[MAX_PATH];
  1450. ChildWnd* child;
  1451. GetCurrentDirectoryW(MAX_PATH, path);
  1452. child = alloc_child_window(path, NULL, hwnd);
  1453. if (!create_child_window(child))
  1454. HeapFree(GetProcessHeap(), 0, child);
  1455. break;}
  1456. case ID_REFRESH:
  1457. refresh_drives();
  1458. break;
  1459. case ID_WINDOW_CASCADE:
  1460. SendMessageW(Globals.hmdiclient, WM_MDICASCADE, 0, 0);
  1461. break;
  1462. case ID_WINDOW_TILE_HORZ:
  1463. SendMessageW(Globals.hmdiclient, WM_MDITILE, MDITILE_HORIZONTAL, 0);
  1464. break;
  1465. case ID_WINDOW_TILE_VERT:
  1466. SendMessageW(Globals.hmdiclient, WM_MDITILE, MDITILE_VERTICAL, 0);
  1467. break;
  1468. case ID_WINDOW_ARRANGE:
  1469. SendMessageW(Globals.hmdiclient, WM_MDIICONARRANGE, 0, 0);
  1470. break;
  1471. case ID_SELECT_FONT:
  1472. choose_font(hwnd);
  1473. break;
  1474. case ID_VIEW_TOOL_BAR:
  1475. toggle_child(hwnd, cmd, Globals.htoolbar);
  1476. break;
  1477. case ID_VIEW_DRIVE_BAR:
  1478. toggle_child(hwnd, cmd, Globals.hdrivebar);
  1479. break;
  1480. case ID_VIEW_STATUSBAR:
  1481. toggle_child(hwnd, cmd, Globals.hstatusbar);
  1482. break;
  1483. case ID_VIEW_SAVESETTINGS:
  1484. Globals.saveSettings = !Globals.saveSettings;
  1485. CheckMenuItem(Globals.hMenuOptions, ID_VIEW_SAVESETTINGS,
  1486. Globals.saveSettings ? MF_CHECKED : MF_UNCHECKED );
  1487. break;
  1488. case ID_RUN:
  1489. WineFile_OnRun( hwnd );
  1490. break;
  1491. case ID_CONNECT_NETWORK_DRIVE: {
  1492. DWORD ret = WNetConnectionDialog(hwnd, RESOURCETYPE_DISK);
  1493. if (ret == NO_ERROR)
  1494. refresh_drives();
  1495. else if (ret != (DWORD)-1) {
  1496. if (ret == ERROR_EXTENDED_ERROR)
  1497. display_network_error(hwnd);
  1498. else
  1499. display_error(hwnd, ret);
  1500. }
  1501. break;}
  1502. case ID_DISCONNECT_NETWORK_DRIVE: {
  1503. DWORD ret = WNetDisconnectDialog(hwnd, RESOURCETYPE_DISK);
  1504. if (ret == NO_ERROR)
  1505. refresh_drives();
  1506. else if (ret != (DWORD)-1) {
  1507. if (ret == ERROR_EXTENDED_ERROR)
  1508. display_network_error(hwnd);
  1509. else
  1510. display_error(hwnd, ret);
  1511. }
  1512. break;}
  1513. case ID_HELP:
  1514. WinHelpW(hwnd, RS(b1,IDS_WINEFILE), HELP_INDEX, 0);
  1515. break;
  1516. case ID_VIEW_FULLSCREEN:
  1517. CheckMenuItem(Globals.hMenuOptions, cmd, toggle_fullscreen(hwnd)?MF_CHECKED:0);
  1518. break;
  1519. case ID_DRIVE_SHELL_NS: {
  1520. WCHAR path[MAX_PATH];
  1521. ChildWnd* child;
  1522. if (activate_fs_window(RS(b1,IDS_SHELL)))
  1523. break;
  1524. GetCurrentDirectoryW(MAX_PATH, path);
  1525. child = alloc_child_window(path, get_path_pidl(path,hwnd), hwnd);
  1526. if (!create_child_window(child))
  1527. HeapFree(GetProcessHeap(), 0, child);
  1528. break;}
  1529. /*TODO: There are even more menu items! */
  1530. case ID_ABOUT:
  1531. ShellAboutW(hwnd, RS(b1,IDS_WINEFILE), NULL,
  1532. LoadImageW( Globals.hInstance, MAKEINTRESOURCEW(IDI_WINEFILE),
  1533. IMAGE_ICON, 48, 48, LR_SHARED ));
  1534. break;
  1535. default:
  1536. /*TODO: if (wParam >= PM_FIRST_LANGUAGE && wParam <= PM_LAST_LANGUAGE)
  1537. STRING_SelectLanguageByNumber(wParam - PM_FIRST_LANGUAGE);
  1538. else */if ((cmd<IDW_FIRST_CHILD || cmd>=IDW_FIRST_CHILD+0x100) &&
  1539. (cmd<SC_SIZE || cmd>SC_RESTORE))
  1540. MessageBoxW(hwnd, RS(b2,IDS_NO_IMPL), RS(b1,IDS_WINEFILE), MB_OK);
  1541. return DefFrameProcW(hwnd, Globals.hmdiclient, nmsg, wparam, lparam);
  1542. }
  1543. break;}
  1544. case WM_SIZE:
  1545. resize_frame(hwnd, LOWORD(lparam), HIWORD(lparam));
  1546. break; /* do not pass message to DefFrameProcW */
  1547. case WM_DEVICECHANGE:
  1548. SendMessageW(hwnd, WM_COMMAND, MAKELONG(ID_REFRESH,0), 0);
  1549. break;
  1550. case WM_GETMINMAXINFO: {
  1551. LPMINMAXINFO lpmmi = (LPMINMAXINFO)lparam;
  1552. lpmmi->ptMaxTrackSize.x <<= 1;/*2*GetSystemMetrics(SM_CXSCREEN) / SM_CXVIRTUALSCREEN */
  1553. lpmmi->ptMaxTrackSize.y <<= 1;/*2*GetSystemMetrics(SM_CYSCREEN) / SM_CYVIRTUALSCREEN */
  1554. break;}
  1555. case FRM_CALC_CLIENT:
  1556. frame_get_clientspace(hwnd, (PRECT)lparam);
  1557. return TRUE;
  1558. default:
  1559. return DefFrameProcW(hwnd, Globals.hmdiclient, nmsg, wparam, lparam);
  1560. }
  1561. return 0;
  1562. }
  1563. static WCHAR g_pos_names[COLUMNS][40] = {
  1564. {'\0'} /* symbol */
  1565. };
  1566. static const int g_pos_align[] = {
  1567. 0,
  1568. HDF_LEFT, /* Name */
  1569. HDF_RIGHT, /* Size */
  1570. HDF_LEFT, /* CDate */
  1571. HDF_LEFT, /* ADate */
  1572. HDF_LEFT, /* MDate */
  1573. HDF_LEFT, /* Index */
  1574. HDF_CENTER, /* Links */
  1575. HDF_CENTER, /* Attributes */
  1576. HDF_LEFT /* Security */
  1577. };
  1578. static void resize_tree(ChildWnd* child, int cx, int cy)
  1579. {
  1580. HDWP hdwp = BeginDeferWindowPos(4);
  1581. RECT rt;
  1582. WINDOWPOS wp;
  1583. HD_LAYOUT hdl;
  1584. rt.left = 0;
  1585. rt.top = 0;
  1586. rt.right = cx;
  1587. rt.bottom = cy;
  1588. cx = child->split_pos + SPLIT_WIDTH/2;
  1589. hdl.prc = &rt;
  1590. hdl.pwpos = &wp;
  1591. SendMessageW(child->left.hwndHeader, HDM_LAYOUT, 0, (LPARAM)&hdl);
  1592. DeferWindowPos(hdwp, child->left.hwndHeader, wp.hwndInsertAfter,
  1593. wp.x-1, wp.y, child->split_pos-SPLIT_WIDTH/2+1, wp.cy, wp.flags);
  1594. DeferWindowPos(hdwp, child->right.hwndHeader, wp.hwndInsertAfter,
  1595. rt.left+cx+1, wp.y, wp.cx-cx+2, wp.cy, wp.flags);
  1596. 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);
  1597. DeferWindowPos(hdwp, child->right.hwnd, 0, rt.left+cx+1, rt.top, rt.right-cx, rt.bottom-rt.top, SWP_NOZORDER|SWP_NOACTIVATE);
  1598. EndDeferWindowPos(hdwp);
  1599. }
  1600. static HWND create_header(HWND parent, Pane* pane, UINT id)
  1601. {
  1602. HDITEMW hdi;
  1603. int idx;
  1604. HWND hwnd = CreateWindowW(WC_HEADERW, 0, WS_CHILD|WS_VISIBLE|HDS_HORZ|HDS_FULLDRAG/*TODO: |HDS_BUTTONS + sort orders*/,
  1605. 0, 0, 0, 0, parent, (HMENU)ULongToHandle(id), Globals.hInstance, 0);
  1606. if (!hwnd)
  1607. return 0;
  1608. SendMessageW(hwnd, WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), FALSE);
  1609. hdi.mask = HDI_TEXT|HDI_WIDTH|HDI_FORMAT;
  1610. for(idx=0; idx<COLUMNS; idx++) {
  1611. hdi.pszText = g_pos_names[idx];
  1612. hdi.fmt = HDF_STRING | g_pos_align[idx];
  1613. hdi.cxy = pane->widths[idx];
  1614. pane->widths_shown[idx] = hdi.cxy;
  1615. SendMessageW(hwnd, HDM_INSERTITEMW, idx, (LPARAM)&hdi);
  1616. }
  1617. return hwnd;
  1618. }
  1619. static void init_output(HWND hwnd)
  1620. {
  1621. static const WCHAR s1000[] = {'1','0','0','0','\0'};
  1622. WCHAR b[16];
  1623. HFONT old_font;
  1624. HDC hdc = GetDC(hwnd);
  1625. if (GetNumberFormatW(LOCALE_USER_DEFAULT, 0, s1000, 0, b, 16) > 4)
  1626. Globals.num_sep = b[1];
  1627. else
  1628. Globals.num_sep = '.';
  1629. old_font = SelectObject(hdc, Globals.hfont);
  1630. GetTextExtentPoint32W(hdc, sSpace, 1, &Globals.spaceSize);
  1631. SelectObject(hdc, old_font);
  1632. ReleaseDC(hwnd, hdc);
  1633. }
  1634. static void draw_item(Pane* pane, LPDRAWITEMSTRUCT dis, Entry* entry, int calcWidthCol);
  1635. /* calculate preferred width for all visible columns */
  1636. static BOOL calc_widths(Pane* pane, BOOL anyway)
  1637. {
  1638. int col, x, cx, spc=3*Globals.spaceSize.cx;
  1639. int entries = SendMessageW(pane->hwnd, LB_GETCOUNT, 0, 0);
  1640. int orgWidths[COLUMNS];
  1641. int orgPositions[COLUMNS+1];
  1642. HFONT hfontOld;
  1643. HDC hdc;
  1644. int cnt;
  1645. if (!anyway) {
  1646. memcpy(orgWidths, pane->widths, sizeof(orgWidths));
  1647. memcpy(orgPositions, pane->positions, sizeof(orgPositions));
  1648. }
  1649. for(col=0; col<COLUMNS; col++)
  1650. pane->widths[col] = 0;
  1651. hdc = GetDC(pane->hwnd);
  1652. hfontOld = SelectObject(hdc, Globals.hfont);
  1653. for(cnt=0; cnt<entries; cnt++) {
  1654. Entry* entry = (Entry*)SendMessageW(pane->hwnd, LB_GETITEMDATA, cnt, 0);
  1655. DRAWITEMSTRUCT dis;
  1656. dis.CtlType = 0;
  1657. dis.CtlID = 0;
  1658. dis.itemID = 0;
  1659. dis.itemAction = 0;
  1660. dis.itemState = 0;
  1661. dis.hwndItem = pane->hwnd;
  1662. dis.hDC = hdc;
  1663. SetRectEmpty(&dis.rcItem);
  1664. /*dis.itemData = 0; */
  1665. draw_item(pane, &dis, entry, COLUMNS);
  1666. }
  1667. SelectObject(hdc, hfontOld);
  1668. ReleaseDC(pane->hwnd, hdc);
  1669. x = 0;
  1670. for(col=0; col<COLUMNS; col++) {
  1671. pane->positions[col] = x;
  1672. cx = pane->widths[col];
  1673. if (cx) {
  1674. cx += spc;
  1675. if (cx < IMAGE_WIDTH)
  1676. cx = IMAGE_WIDTH;
  1677. pane->widths[col] = cx;
  1678. }
  1679. x += cx;
  1680. }
  1681. pane->positions[COLUMNS] = x;
  1682. SendMessageW(pane->hwnd, LB_SETHORIZONTALEXTENT, x, 0);
  1683. /* no change? */
  1684. if (!anyway && !memcmp(orgWidths, pane->widths, sizeof(orgWidths)))
  1685. return FALSE;
  1686. /* don't move, if only collapsing an entry */
  1687. if (!anyway && pane->widths[0]<orgWidths[0] &&
  1688. !memcmp(orgWidths+1, pane->widths+1, sizeof(orgWidths)-sizeof(int))) {
  1689. pane->widths[0] = orgWidths[0];
  1690. memcpy(pane->positions, orgPositions, sizeof(orgPositions));
  1691. return FALSE;
  1692. }
  1693. InvalidateRect(pane->hwnd, 0, TRUE);
  1694. return TRUE;
  1695. }
  1696. /* calculate one preferred column width */
  1697. static void calc_single_width(Pane* pane, int col)
  1698. {
  1699. HFONT hfontOld;
  1700. int x, cx;
  1701. int entries = SendMessageW(pane->hwnd, LB_GETCOUNT, 0, 0);
  1702. int cnt;
  1703. HDC hdc;
  1704. pane->widths[col] = 0;
  1705. hdc = GetDC(pane->hwnd);
  1706. hfontOld = SelectObject(hdc, Globals.hfont);
  1707. for(cnt=0; cnt<entries; cnt++) {
  1708. Entry* entry = (Entry*)SendMessageW(pane->hwnd, LB_GETITEMDATA, cnt, 0);
  1709. DRAWITEMSTRUCT dis;
  1710. dis.CtlType = 0;
  1711. dis.CtlID = 0;
  1712. dis.itemID = 0;
  1713. dis.itemAction = 0;
  1714. dis.itemState = 0;
  1715. dis.hwndItem = pane->hwnd;
  1716. dis.hDC = hdc;
  1717. SetRectEmpty(&dis.rcItem);
  1718. /*dis.itemData = 0; */
  1719. draw_item(pane, &dis, entry, col);
  1720. }
  1721. SelectObject(hdc, hfontOld);
  1722. ReleaseDC(pane->hwnd, hdc);
  1723. cx = pane->widths[col];
  1724. if (cx) {
  1725. cx += 3*Globals.spaceSize.cx;
  1726. if (cx < IMAGE_WIDTH)
  1727. cx = IMAGE_WIDTH;
  1728. }
  1729. pane->widths[col] = cx;
  1730. x = pane->positions[col] + cx;
  1731. for(; col<COLUMNS-1; ) {
  1732. pane->positions[++col] = x;
  1733. x += pane->widths[col];
  1734. }
  1735. SendMessageW(pane->hwnd, LB_SETHORIZONTALEXTENT, x, 0);
  1736. }
  1737. static BOOL pattern_match(LPCWSTR str, LPCWSTR pattern)
  1738. {
  1739. for( ; *str&&*pattern; str++,pattern++) {
  1740. if (*pattern == '*') {
  1741. do pattern++;
  1742. while(*pattern == '*');
  1743. if (!*pattern)
  1744. return TRUE;
  1745. for(; *str; str++)
  1746. if (*str==*pattern && pattern_match(str, pattern))
  1747. return TRUE;
  1748. return FALSE;
  1749. }
  1750. else if (*str!=*pattern && *pattern!='?')
  1751. return FALSE;
  1752. }
  1753. if (*str || *pattern)
  1754. if (*pattern!='*' || pattern[1]!='\0')
  1755. return FALSE;
  1756. return TRUE;
  1757. }
  1758. static BOOL pattern_imatch(LPCWSTR str, LPCWSTR pattern)
  1759. {
  1760. WCHAR b1[BUFFER_LEN], b2[BUFFER_LEN];
  1761. lstrcpyW(b1, str);
  1762. lstrcpyW(b2, pattern);
  1763. CharUpperW(b1);
  1764. CharUpperW(b2);
  1765. return pattern_match(b1, b2);
  1766. }
  1767. enum FILE_TYPE {
  1768. FT_OTHER = 0,
  1769. FT_EXECUTABLE = 1,
  1770. FT_DOCUMENT = 2
  1771. };
  1772. static enum FILE_TYPE get_file_type(LPCWSTR filename);
  1773. /* insert listbox entries after index idx */
  1774. static int insert_entries(Pane* pane, Entry* dir, LPCWSTR pattern, int filter_flags, int idx)
  1775. {
  1776. Entry* entry = dir;
  1777. if (!entry)
  1778. return idx;
  1779. ShowWindow(pane->hwnd, SW_HIDE);
  1780. for(; entry; entry=entry->next) {
  1781. if (pane->treePane && !(entry->data.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY))
  1782. continue;
  1783. if (entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
  1784. /* don't display entries "." and ".." in the left pane */
  1785. if (pane->treePane && entry->data.cFileName[0] == '.')
  1786. if (entry->data.cFileName[1] == '\0' ||
  1787. (entry->data.cFileName[1] == '.' &&
  1788. entry->data.cFileName[2] == '\0'))
  1789. continue;
  1790. /* filter directories in right pane */
  1791. if (!pane->treePane && !(filter_flags&TF_DIRECTORIES))
  1792. continue;
  1793. }
  1794. /* filter using the file name pattern */
  1795. if (pattern)
  1796. if (!pattern_imatch(entry->data.cFileName, pattern))
  1797. continue;
  1798. /* filter system and hidden files */
  1799. if (!(filter_flags&TF_HIDDEN) && (entry->data.dwFileAttributes&(FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM)))
  1800. continue;
  1801. /* filter looking at the file type */
  1802. if ((filter_flags&(TF_PROGRAMS|TF_DOCUMENTS|TF_OTHERS)) != (TF_PROGRAMS|TF_DOCUMENTS|TF_OTHERS))
  1803. switch(get_file_type(entry->data.cFileName)) {
  1804. case FT_EXECUTABLE:
  1805. if (!(filter_flags & TF_PROGRAMS))
  1806. continue;
  1807. break;
  1808. case FT_DOCUMENT:
  1809. if (!(filter_flags & TF_DOCUMENTS))
  1810. continue;
  1811. break;
  1812. default: /* TF_OTHERS */
  1813. if (!(filter_flags & TF_OTHERS))
  1814. continue;
  1815. }
  1816. if (idx != -1)
  1817. idx++;
  1818. SendMessageW(pane->hwnd, LB_INSERTSTRING, idx, (LPARAM)entry);
  1819. if (pane->treePane && entry->expanded)
  1820. idx = insert_entries(pane, entry->down, pattern, filter_flags, idx);
  1821. }
  1822. ShowWindow(pane->hwnd, SW_SHOW);
  1823. return idx;
  1824. }
  1825. static void set_space_status(void)
  1826. {
  1827. ULARGE_INTEGER ulFreeBytesToCaller, ulTotalBytes, ulFreeBytes;
  1828. WCHAR fmt[64], b1[64], b2[64], buffer[BUFFER_LEN];
  1829. if (GetDiskFreeSpaceExW(NULL, &ulFreeBytesToCaller, &ulTotalBytes, &ulFreeBytes)) {
  1830. DWORD_PTR args[2];
  1831. args[0] = (DWORD_PTR)StrFormatByteSizeW(ulFreeBytesToCaller.QuadPart, b1, ARRAY_SIZE(b1));
  1832. args[1] = (DWORD_PTR)StrFormatByteSizeW(ulTotalBytes.QuadPart, b2, ARRAY_SIZE(b2));
  1833. FormatMessageW(FORMAT_MESSAGE_FROM_STRING|FORMAT_MESSAGE_ARGUMENT_ARRAY,
  1834. RS(fmt,IDS_FREE_SPACE_FMT), 0, 0, buffer, ARRAY_SIZE(buffer),
  1835. (__ms_va_list*)args);
  1836. } else
  1837. lstrcpyW(buffer, sQMarks);
  1838. SendMessageW(Globals.hstatusbar, SB_SETTEXTW, 0, (LPARAM)buffer);
  1839. }
  1840. static WNDPROC g_orgTreeWndProc;
  1841. static void create_tree_window(HWND parent, Pane* pane, UINT id, UINT id_header, LPCWSTR pattern, int filter_flags)
  1842. {
  1843. static const WCHAR sListBox[] = {'L','i','s','t','B','o','x','\0'};
  1844. static BOOL s_init = FALSE;
  1845. Entry* entry = pane->root;
  1846. pane->hwnd = CreateWindowW(sListBox, sEmpty, WS_CHILD|WS_VISIBLE|WS_HSCROLL|WS_VSCROLL|
  1847. LBS_DISABLENOSCROLL|LBS_NOINTEGRALHEIGHT|LBS_OWNERDRAWFIXED|LBS_NOTIFY,
  1848. 0, 0, 0, 0, parent, (HMENU)ULongToHandle(id), Globals.hInstance, 0);
  1849. SetWindowLongPtrW(pane->hwnd, GWLP_USERDATA, (LPARAM)pane);
  1850. g_orgTreeWndProc = (WNDPROC)SetWindowLongPtrW(pane->hwnd, GWLP_WNDPROC, (LPARAM)TreeWndProc);
  1851. SendMessageW(pane->hwnd, WM_SETFONT, (WPARAM)Globals.hfont, FALSE);
  1852. /* insert entries into listbox */
  1853. if (entry)
  1854. insert_entries(pane, entry, pattern, filter_flags, -1);
  1855. /* calculate column widths */
  1856. if (!s_init) {
  1857. s_init = TRUE;
  1858. init_output(pane->hwnd);
  1859. }
  1860. calc_widths(pane, TRUE);
  1861. pane->hwndHeader = create_header(parent, pane, id_header);
  1862. }
  1863. static void InitChildWindow(ChildWnd* child)
  1864. {
  1865. create_tree_window(child->hwnd, &child->left, IDW_TREE_LEFT, IDW_HEADER_LEFT, NULL, TF_ALL);
  1866. create_tree_window(child->hwnd, &child->right, IDW_TREE_RIGHT, IDW_HEADER_RIGHT, child->filter_pattern, child->filter_flags);
  1867. }
  1868. static void format_date(const FILETIME* ft, WCHAR* buffer, int visible_cols)
  1869. {
  1870. SYSTEMTIME systime;
  1871. FILETIME lft;
  1872. int len = 0;
  1873. *buffer = '\0';
  1874. if (!ft->dwLowDateTime && !ft->dwHighDateTime)
  1875. return;
  1876. if (!FileTimeToLocalFileTime(ft, &lft))
  1877. {err: lstrcpyW(buffer,sQMarks); return;}
  1878. if (!FileTimeToSystemTime(&lft, &systime))
  1879. goto err;
  1880. if (visible_cols & COL_DATE) {
  1881. len = GetDateFormatW(LOCALE_USER_DEFAULT, 0, &systime, 0, buffer, BUFFER_LEN);
  1882. if (!len)
  1883. goto err;
  1884. }
  1885. if (visible_cols & COL_TIME) {
  1886. if (len)
  1887. buffer[len-1] = ' ';
  1888. buffer[len++] = ' ';
  1889. if (!GetTimeFormatW(LOCALE_USER_DEFAULT, 0, &systime, 0, buffer+len, BUFFER_LEN-len))
  1890. buffer[len] = '\0';
  1891. }
  1892. }
  1893. static void calc_width(Pane* pane, LPDRAWITEMSTRUCT dis, int col, LPCWSTR str)
  1894. {
  1895. RECT rt = {0, 0, 0, 0};
  1896. DrawTextW(dis->hDC, str, -1, &rt, DT_CALCRECT|DT_SINGLELINE|DT_NOPREFIX);
  1897. if (rt.right > pane->widths[col])
  1898. pane->widths[col] = rt.right;
  1899. }
  1900. static void calc_tabbed_width(Pane* pane, LPDRAWITEMSTRUCT dis, int col, LPCWSTR str)
  1901. {
  1902. RECT rt = {0, 0, 0, 0};
  1903. DrawTextW(dis->hDC, str, -1, &rt, DT_CALCRECT|DT_SINGLELINE|DT_EXPANDTABS|DT_TABSTOP|(2<<8));
  1904. /*FIXME rt (0,0) ??? */
  1905. if (rt.right > pane->widths[col])
  1906. pane->widths[col] = rt.right;
  1907. }
  1908. static void output_text(Pane* pane, LPDRAWITEMSTRUCT dis, int col, LPCWSTR str, DWORD flags)
  1909. {
  1910. int x = dis->rcItem.left;
  1911. RECT rt;
  1912. rt.left = x+pane->positions[col]+Globals.spaceSize.cx;
  1913. rt.top = dis->rcItem.top;
  1914. rt.right = x+pane->positions[col+1]-Globals.spaceSize.cx;
  1915. rt.bottom = dis->rcItem.bottom;
  1916. DrawTextW(dis->hDC, str, -1, &rt, DT_SINGLELINE|DT_NOPREFIX|flags);
  1917. }
  1918. static void output_tabbed_text(Pane* pane, LPDRAWITEMSTRUCT dis, int col, LPCWSTR str)
  1919. {
  1920. int x = dis->rcItem.left;
  1921. RECT rt;
  1922. rt.left = x+pane->positions[col]+Globals.spaceSize.cx;
  1923. rt.top = dis->rcItem.top;
  1924. rt.right = x+pane->positions[col+1]-Globals.spaceSize.cx;
  1925. rt.bottom = dis->rcItem.bottom;
  1926. DrawTextW(dis->hDC, str, -1, &rt, DT_SINGLELINE|DT_EXPANDTABS|DT_TABSTOP|(2<<8));
  1927. }
  1928. static void output_number(Pane* pane, LPDRAWITEMSTRUCT dis, int col, LPCWSTR str)
  1929. {
  1930. int x = dis->rcItem.left;
  1931. RECT rt;
  1932. LPCWSTR s = str;
  1933. WCHAR b[128];
  1934. LPWSTR d = b;
  1935. int pos;
  1936. rt.left = x+pane->positions[col]+Globals.spaceSize.cx;
  1937. rt.top = dis->rcItem.top;
  1938. rt.right = x+pane->positions[col+1]-Globals.spaceSize.cx;
  1939. rt.bottom = dis->rcItem.bottom;
  1940. if (*s)
  1941. *d++ = *s++;
  1942. /* insert number separator characters */
  1943. pos = lstrlenW(s) % 3;
  1944. while(*s)
  1945. if (pos--)
  1946. *d++ = *s++;
  1947. else {
  1948. *d++ = Globals.num_sep;
  1949. pos = 3;
  1950. }
  1951. DrawTextW(dis->hDC, b, d-b, &rt, DT_RIGHT|DT_SINGLELINE|DT_NOPREFIX|DT_END_ELLIPSIS);
  1952. }
  1953. static BOOL is_exe_file(LPCWSTR ext)
  1954. {
  1955. static const WCHAR executable_extensions[][4] = {
  1956. {'C','O','M','\0'},
  1957. {'E','X','E','\0'},
  1958. {'B','A','T','\0'},
  1959. {'C','M','D','\0'},
  1960. {'C','M','M','\0'},
  1961. {'B','T','M','\0'},
  1962. {'A','W','K','\0'},
  1963. {'\0'}
  1964. };
  1965. WCHAR ext_buffer[_MAX_EXT];
  1966. const WCHAR (*p)[4];
  1967. LPCWSTR s;
  1968. LPWSTR d;
  1969. for(s=ext+1,d=ext_buffer; (*d=tolower(*s)); s++)
  1970. d++;
  1971. for(p=executable_extensions; (*p)[0]; p++)
  1972. if (!lstrcmpiW(ext_buffer, *p))
  1973. return TRUE;
  1974. return FALSE;
  1975. }
  1976. static BOOL is_registered_type(LPCWSTR ext)
  1977. {
  1978. /* check if there exists a classname for this file extension in the registry */
  1979. if (!RegQueryValueW(HKEY_CLASSES_ROOT, ext, NULL, NULL))
  1980. return TRUE;
  1981. return FALSE;
  1982. }
  1983. static enum FILE_TYPE get_file_type(LPCWSTR filename)
  1984. {
  1985. LPCWSTR ext = wcsrchr(filename, '.');
  1986. if (!ext)
  1987. ext = sEmpty;
  1988. if (is_exe_file(ext))
  1989. return FT_EXECUTABLE;
  1990. else if (is_registered_type(ext))
  1991. return FT_DOCUMENT;
  1992. else
  1993. return FT_OTHER;
  1994. }
  1995. static void draw_item(Pane* pane, LPDRAWITEMSTRUCT dis, Entry* entry, int calcWidthCol)
  1996. {
  1997. WCHAR buffer[BUFFER_LEN];
  1998. DWORD attrs;
  1999. int visible_cols = pane->visible_cols;
  2000. COLORREF bkcolor, textcolor;
  2001. RECT focusRect = dis->rcItem;
  2002. HBRUSH hbrush;
  2003. enum IMAGE img;
  2004. int img_pos, cx;
  2005. int col = 0;
  2006. if (entry) {
  2007. attrs = entry->data.dwFileAttributes;
  2008. if (attrs & FILE_ATTRIBUTE_DIRECTORY) {
  2009. if (entry->data.cFileName[0] == '.' && entry->data.cFileName[1] == '.'
  2010. && entry->data.cFileName[2] == '\0')
  2011. img = IMG_FOLDER_UP;
  2012. else if (entry->data.cFileName[0] == '.' && entry->data.cFileName[1] == '\0')
  2013. img = IMG_FOLDER_CUR;
  2014. else if (pane->treePane && (dis->itemState&ODS_FOCUS))
  2015. img = IMG_OPEN_FOLDER;
  2016. else
  2017. img = IMG_FOLDER;
  2018. } else {
  2019. switch(get_file_type(entry->data.cFileName)) {
  2020. case FT_EXECUTABLE: img = IMG_EXECUTABLE; break;
  2021. case FT_DOCUMENT: img = IMG_DOCUMENT; break;
  2022. default: img = IMG_FILE;
  2023. }
  2024. }
  2025. } else {
  2026. attrs = 0;
  2027. img = IMG_NONE;
  2028. }
  2029. if (pane->treePane) {
  2030. if (entry) {
  2031. img_pos = dis->rcItem.left + entry->level*(IMAGE_WIDTH+TREE_LINE_DX);
  2032. if (calcWidthCol == -1) {
  2033. int x;
  2034. int y = dis->rcItem.top + IMAGE_HEIGHT/2;
  2035. Entry* up;
  2036. RECT rt_clip;
  2037. HRGN hrgn_org = CreateRectRgn(0, 0, 0, 0);
  2038. HRGN hrgn;
  2039. rt_clip.left = dis->rcItem.left;
  2040. rt_clip.top = dis->rcItem.top;
  2041. rt_clip.right = dis->rcItem.left+pane->widths[col];
  2042. rt_clip.bottom = dis->rcItem.bottom;
  2043. hrgn = CreateRectRgnIndirect(&rt_clip);
  2044. if (!GetClipRgn(dis->hDC, hrgn_org)) {
  2045. DeleteObject(hrgn_org);
  2046. hrgn_org = 0;
  2047. }
  2048. ExtSelectClipRgn(dis->hDC, hrgn, RGN_AND);
  2049. DeleteObject(hrgn);
  2050. if ((up=entry->up) != NULL) {
  2051. MoveToEx(dis->hDC, img_pos-IMAGE_WIDTH/2, y, 0);
  2052. LineTo(dis->hDC, img_pos-2, y);
  2053. x = img_pos - IMAGE_WIDTH/2;
  2054. do {
  2055. x -= IMAGE_WIDTH+TREE_LINE_DX;
  2056. if (up->next
  2057. && (up->next->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
  2058. ) {
  2059. MoveToEx(dis->hDC, x, dis->rcItem.top, 0);
  2060. LineTo(dis->hDC, x, dis->rcItem.bottom);
  2061. }
  2062. } while((up=up->up) != NULL);
  2063. }
  2064. x = img_pos - IMAGE_WIDTH/2;
  2065. MoveToEx(dis->hDC, x, dis->rcItem.top, 0);
  2066. LineTo(dis->hDC, x, y);
  2067. if (entry->next
  2068. && (entry->next->data.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY))
  2069. LineTo(dis->hDC, x, dis->rcItem.bottom);
  2070. SelectClipRgn(dis->hDC, hrgn_org);
  2071. if (hrgn_org) DeleteObject(hrgn_org);
  2072. } else if (calcWidthCol==col || calcWidthCol==COLUMNS) {
  2073. int right = img_pos + IMAGE_WIDTH - TREE_LINE_DX;
  2074. if (right > pane->widths[col])
  2075. pane->widths[col] = right;
  2076. }
  2077. } else {
  2078. img_pos = dis->rcItem.left;
  2079. }
  2080. } else {
  2081. img_pos = dis->rcItem.left;
  2082. if (calcWidthCol==col || calcWidthCol==COLUMNS)
  2083. pane->widths[col] = IMAGE_WIDTH;
  2084. }
  2085. if (calcWidthCol == -1) {
  2086. focusRect.left = img_pos -2;
  2087. if (attrs & FILE_ATTRIBUTE_COMPRESSED)
  2088. textcolor = COLOR_COMPRESSED;
  2089. else
  2090. textcolor = RGB(0,0,0);
  2091. if (dis->itemState & ODS_FOCUS) {
  2092. textcolor = RGB(255,255,255);
  2093. bkcolor = COLOR_SELECTION;
  2094. } else {
  2095. bkcolor = RGB(255,255,255);
  2096. }
  2097. hbrush = CreateSolidBrush(bkcolor);
  2098. FillRect(dis->hDC, &focusRect, hbrush);
  2099. DeleteObject(hbrush);
  2100. SetBkMode(dis->hDC, TRANSPARENT);
  2101. SetTextColor(dis->hDC, textcolor);
  2102. cx = pane->widths[col];
  2103. if (cx && img!=IMG_NONE) {
  2104. if (cx > IMAGE_WIDTH)
  2105. cx = IMAGE_WIDTH;
  2106. if (entry->hicon && entry->hicon!=(HICON)-1)
  2107. DrawIconEx(dis->hDC, img_pos, dis->rcItem.top, entry->hicon, cx, GetSystemMetrics(SM_CYSMICON), 0, 0, DI_NORMAL);
  2108. else
  2109. ImageList_DrawEx(Globals.himl, img, dis->hDC,
  2110. img_pos, dis->rcItem.top, cx,
  2111. IMAGE_HEIGHT, bkcolor, CLR_DEFAULT, ILD_NORMAL);
  2112. }
  2113. }
  2114. if (!entry)
  2115. return;
  2116. col++;
  2117. /* output file name */
  2118. if (calcWidthCol == -1)
  2119. output_text(pane, dis, col, entry->data.cFileName, 0);
  2120. else if (calcWidthCol==col || calcWidthCol==COLUMNS)
  2121. calc_width(pane, dis, col, entry->data.cFileName);
  2122. col++;
  2123. /* display file size */
  2124. if (visible_cols & COL_SIZE) {
  2125. format_longlong( buffer, ((ULONGLONG)entry->data.nFileSizeHigh << 32) | entry->data.nFileSizeLow );
  2126. if (calcWidthCol == -1)
  2127. output_number(pane, dis, col, buffer);
  2128. else if (calcWidthCol==col || calcWidthCol==COLUMNS)
  2129. calc_width(pane, dis, col, buffer);/*TODO: not ever time enough */
  2130. col++;
  2131. }
  2132. /* display file date */
  2133. if (visible_cols & (COL_DATE|COL_TIME)) {
  2134. format_date(&entry->data.ftCreationTime, buffer, visible_cols);
  2135. if (calcWidthCol == -1)
  2136. output_text(pane, dis, col, buffer, 0);
  2137. else if (calcWidthCol==col || calcWidthCol==COLUMNS)
  2138. calc_width(pane, dis, col, buffer);
  2139. col++;
  2140. format_date(&entry->data.ftLastAccessTime, buffer, visible_cols);
  2141. if (calcWidthCol == -1)
  2142. output_text(pane, dis, col, buffer, 0);
  2143. else if (calcWidthCol==col || calcWidthCol==COLUMNS)
  2144. calc_width(pane, dis, col, buffer);
  2145. col++;
  2146. format_date(&entry->data.ftLastWriteTime, buffer, visible_cols);
  2147. if (calcWidthCol == -1)
  2148. output_text(pane, dis, col, buffer, 0);
  2149. else if (calcWidthCol==col || calcWidthCol==COLUMNS)
  2150. calc_width(pane, dis, col, buffer);
  2151. col++;
  2152. }
  2153. if (entry->bhfi_valid) {
  2154. if (visible_cols & COL_INDEX) {
  2155. static const WCHAR fmtlow[] = {'%','X',0};
  2156. static const WCHAR fmthigh[] = {'%','X','%','0','8','X',0};
  2157. if (entry->bhfi.nFileIndexHigh)
  2158. wsprintfW(buffer, fmthigh,
  2159. entry->bhfi.nFileIndexHigh, entry->bhfi.nFileIndexLow );
  2160. else
  2161. wsprintfW(buffer, fmtlow, entry->bhfi.nFileIndexLow );
  2162. if (calcWidthCol == -1)
  2163. output_text(pane, dis, col, buffer, DT_RIGHT);
  2164. else if (calcWidthCol==col || calcWidthCol==COLUMNS)
  2165. calc_width(pane, dis, col, buffer);
  2166. col++;
  2167. }
  2168. if (visible_cols & COL_LINKS) {
  2169. wsprintfW(buffer, sNumFmt, entry->bhfi.nNumberOfLinks);
  2170. if (calcWidthCol == -1)
  2171. output_text(pane, dis, col, buffer, DT_CENTER);
  2172. else if (calcWidthCol==col || calcWidthCol==COLUMNS)
  2173. calc_width(pane, dis, col, buffer);
  2174. col++;
  2175. }
  2176. } else
  2177. col += 2;
  2178. /* show file attributes */
  2179. if (visible_cols & COL_ATTRIBUTES) {
  2180. static const WCHAR s11Tabs[] = {' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\0'};
  2181. lstrcpyW(buffer, s11Tabs);
  2182. if (attrs & FILE_ATTRIBUTE_NORMAL) buffer[ 0] = 'N';
  2183. else {
  2184. if (attrs & FILE_ATTRIBUTE_READONLY) buffer[ 2] = 'R';
  2185. if (attrs & FILE_ATTRIBUTE_HIDDEN) buffer[ 4] = 'H';
  2186. if (attrs & FILE_ATTRIBUTE_SYSTEM) buffer[ 6] = 'S';
  2187. if (attrs & FILE_ATTRIBUTE_ARCHIVE) buffer[ 8] = 'A';
  2188. if (attrs & FILE_ATTRIBUTE_COMPRESSED) buffer[10] = 'C';
  2189. if (attrs & FILE_ATTRIBUTE_DIRECTORY) buffer[12] = 'D';
  2190. if (attrs & FILE_ATTRIBUTE_ENCRYPTED) buffer[14] = 'E';
  2191. if (attrs & FILE_ATTRIBUTE_TEMPORARY) buffer[16] = 'T';
  2192. if (attrs & FILE_ATTRIBUTE_SPARSE_FILE) buffer[18] = 'P';
  2193. if (attrs & FILE_ATTRIBUTE_REPARSE_POINT) buffer[20] = 'Q';
  2194. if (attrs & FILE_ATTRIBUTE_OFFLINE) buffer[22] = 'O';
  2195. if (attrs & FILE_ATTRIBUTE_NOT_CONTENT_INDEXED) buffer[24] = 'X';
  2196. }
  2197. if (calcWidthCol == -1)
  2198. output_tabbed_text(pane, dis, col, buffer);
  2199. else if (calcWidthCol==col || calcWidthCol==COLUMNS)
  2200. calc_tabbed_width(pane, dis, col, buffer);
  2201. col++;
  2202. }
  2203. }
  2204. static void set_header(Pane* pane)
  2205. {
  2206. HDITEMW item;
  2207. int scroll_pos = GetScrollPos(pane->hwnd, SB_HORZ);
  2208. int i;
  2209. item.mask = HDI_WIDTH;
  2210. for (i = 0; i < COLUMNS; ++i) {
  2211. if (pane->positions[i] >= scroll_pos) {
  2212. item.cxy = pane->widths[i];
  2213. } else if (pane->positions[i+1] <= scroll_pos) {
  2214. item.cxy = 0;
  2215. } else {
  2216. item.cxy = pane->positions[i+1] - scroll_pos;
  2217. }
  2218. pane->widths_shown[i] = item.cxy;
  2219. SendMessageW(pane->hwndHeader, HDM_SETITEMW, i, (LPARAM)&item);
  2220. }
  2221. }
  2222. static LRESULT pane_notify(Pane* pane, NMHDR* pnmh)
  2223. {
  2224. switch(pnmh->code) {
  2225. case HDN_ITEMCHANGEDW: {
  2226. LPNMHEADERW phdn = (LPNMHEADERW)pnmh;
  2227. int idx = phdn->iItem;
  2228. int dx = phdn->pitem->cxy - pane->widths_shown[idx];
  2229. int i;
  2230. RECT clnt;
  2231. GetClientRect(pane->hwnd, &clnt);
  2232. pane->widths[idx] += dx;
  2233. pane->widths_shown[idx] += dx;
  2234. for(i=idx; ++i<=COLUMNS; )
  2235. pane->positions[i] += dx;
  2236. {
  2237. int scroll_pos = GetScrollPos(pane->hwnd, SB_HORZ);
  2238. RECT rt_scr;
  2239. RECT rt_clip;
  2240. rt_scr.left = pane->positions[idx+1]-scroll_pos;
  2241. rt_scr.top = 0;
  2242. rt_scr.right = clnt.right;
  2243. rt_scr.bottom = clnt.bottom;
  2244. rt_clip.left = pane->positions[idx]-scroll_pos;
  2245. rt_clip.top = 0;
  2246. rt_clip.right = clnt.right;
  2247. rt_clip.bottom = clnt.bottom;
  2248. if (rt_scr.left < 0) rt_scr.left = 0;
  2249. if (rt_clip.left < 0) rt_clip.left = 0;
  2250. ScrollWindowEx(pane->hwnd, dx, 0, &rt_scr, &rt_clip, 0, 0, SW_INVALIDATE);
  2251. rt_clip.right = pane->positions[idx+1];
  2252. RedrawWindow(pane->hwnd, &rt_clip, 0, RDW_INVALIDATE|RDW_UPDATENOW);
  2253. if (pnmh->code == HDN_ENDTRACKW) {
  2254. SendMessageW(pane->hwnd, LB_SETHORIZONTALEXTENT, pane->positions[COLUMNS], 0);
  2255. if (GetScrollPos(pane->hwnd, SB_HORZ) != scroll_pos)
  2256. set_header(pane);
  2257. }
  2258. }
  2259. return FALSE;
  2260. }
  2261. case HDN_DIVIDERDBLCLICKW: {
  2262. LPNMHEADERW phdn = (LPNMHEADERW)pnmh;
  2263. HDITEMW item;
  2264. calc_single_width(pane, phdn->iItem);
  2265. item.mask = HDI_WIDTH;
  2266. item.cxy = pane->widths[phdn->iItem];
  2267. SendMessageW(pane->hwndHeader, HDM_SETITEMW, phdn->iItem, (LPARAM)&item);
  2268. InvalidateRect(pane->hwnd, 0, TRUE);
  2269. break;}
  2270. }
  2271. return 0;
  2272. }
  2273. static void scan_entry(ChildWnd* child, Entry* entry, int idx, HWND hwnd)
  2274. {
  2275. WCHAR path[MAX_PATH];
  2276. HCURSOR old_cursor = SetCursor(LoadCursorW(0, (LPCWSTR)IDC_WAIT));
  2277. /* delete sub entries in left pane */
  2278. for(;;) {
  2279. LRESULT res = SendMessageW(child->left.hwnd, LB_GETITEMDATA, idx+1, 0);
  2280. Entry* sub = (Entry*) res;
  2281. if (res==LB_ERR || !sub || sub->level<=entry->level)
  2282. break;
  2283. SendMessageW(child->left.hwnd, LB_DELETESTRING, idx+1, 0);
  2284. }
  2285. /* empty right pane */
  2286. SendMessageW(child->right.hwnd, LB_RESETCONTENT, 0, 0);
  2287. /* release memory */
  2288. free_entries(entry);
  2289. /* read contents from disk */
  2290. if (entry->etype == ET_SHELL)
  2291. {
  2292. read_directory(entry, NULL, child->sortOrder, hwnd);
  2293. }
  2294. else
  2295. {
  2296. get_path(entry, path);
  2297. read_directory(entry, path, child->sortOrder, hwnd);
  2298. }
  2299. /* insert found entries in right pane */
  2300. insert_entries(&child->right, entry->down, child->filter_pattern, child->filter_flags, -1);
  2301. calc_widths(&child->right, FALSE);
  2302. set_header(&child->right);
  2303. child->header_wdths_ok = FALSE;
  2304. SetCursor(old_cursor);
  2305. }
  2306. /* expand a directory entry */
  2307. static BOOL expand_entry(ChildWnd* child, Entry* dir)
  2308. {
  2309. int idx;
  2310. Entry* p;
  2311. if (!dir || dir->expanded || !dir->down)
  2312. return FALSE;
  2313. p = dir->down;
  2314. if (p->data.cFileName[0]=='.' && p->data.cFileName[1]=='\0' && p->next) {
  2315. p = p->next;
  2316. if (p->data.cFileName[0]=='.' && p->data.cFileName[1]=='.' &&
  2317. p->data.cFileName[2]=='\0' && p->next)
  2318. p = p->next;
  2319. }
  2320. /* no subdirectories ? */
  2321. if (!(p->data.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY))
  2322. return FALSE;
  2323. idx = SendMessageW(child->left.hwnd, LB_FINDSTRING, 0, (LPARAM)dir);
  2324. dir->expanded = TRUE;
  2325. /* insert entries in left pane */
  2326. insert_entries(&child->left, p, NULL, TF_ALL, idx);
  2327. if (!child->header_wdths_ok) {
  2328. if (calc_widths(&child->left, FALSE)) {
  2329. set_header(&child->left);
  2330. child->header_wdths_ok = TRUE;
  2331. }
  2332. }
  2333. return TRUE;
  2334. }
  2335. static void collapse_entry(Pane* pane, Entry* dir)
  2336. {
  2337. int idx;
  2338. if (!dir) return;
  2339. idx = SendMessageW(pane->hwnd, LB_FINDSTRING, 0, (LPARAM)dir);
  2340. ShowWindow(pane->hwnd, SW_HIDE);
  2341. /* hide sub entries */
  2342. for(;;) {
  2343. LRESULT res = SendMessageW(pane->hwnd, LB_GETITEMDATA, idx+1, 0);
  2344. Entry* sub = (Entry*) res;
  2345. if (res==LB_ERR || !sub || sub->level<=dir->level)
  2346. break;
  2347. SendMessageW(pane->hwnd, LB_DELETESTRING, idx+1, 0);
  2348. }
  2349. dir->expanded = FALSE;
  2350. ShowWindow(pane->hwnd, SW_SHOW);
  2351. }
  2352. static void refresh_right_pane(ChildWnd* child)
  2353. {
  2354. SendMessageW(child->right.hwnd, LB_RESETCONTENT, 0, 0);
  2355. insert_entries(&child->right, child->right.root, child->filter_pattern, child->filter_flags, -1);
  2356. calc_widths(&child->right, FALSE);
  2357. set_header(&child->right);
  2358. }
  2359. static void set_curdir(ChildWnd* child, Entry* entry, int idx, HWND hwnd)
  2360. {
  2361. WCHAR path[MAX_PATH];
  2362. if (!entry)
  2363. return;
  2364. path[0] = '\0';
  2365. child->left.cur = entry;
  2366. child->right.root = entry->down? entry->down: entry;
  2367. child->right.cur = entry;
  2368. if (!entry->scanned)
  2369. scan_entry(child, entry, idx, hwnd);
  2370. else
  2371. refresh_right_pane(child);
  2372. get_path(entry, path);
  2373. lstrcpyW(child->path, path);
  2374. if (child->hwnd) /* only change window title, if the window already exists */
  2375. SetWindowTextW(child->hwnd, path);
  2376. if (path[0])
  2377. if (SetCurrentDirectoryW(path))
  2378. set_space_status();
  2379. }
  2380. static void refresh_child(ChildWnd* child)
  2381. {
  2382. WCHAR path[MAX_PATH], drv[_MAX_DRIVE+1];
  2383. Entry* entry;
  2384. int idx;
  2385. get_path(child->left.cur, path);
  2386. _wsplitpath(path, drv, NULL, NULL, NULL);
  2387. child->right.root = NULL;
  2388. scan_entry(child, &child->root.entry, 0, child->hwnd);
  2389. if (child->root.entry.etype == ET_SHELL)
  2390. {
  2391. LPITEMIDLIST local_pidl = get_path_pidl(path,child->hwnd);
  2392. if (local_pidl)
  2393. entry = read_tree(&child->root, NULL, local_pidl , drv, child->sortOrder, child->hwnd);
  2394. else
  2395. entry = NULL;
  2396. }
  2397. else
  2398. entry = read_tree(&child->root, path, NULL, drv, child->sortOrder, child->hwnd);
  2399. if (!entry)
  2400. entry = &child->root.entry;
  2401. insert_entries(&child->left, child->root.entry.down, NULL, TF_ALL, 0);
  2402. set_curdir(child, entry, 0, child->hwnd);
  2403. idx = SendMessageW(child->left.hwnd, LB_FINDSTRING, 0, (LPARAM)child->left.cur);
  2404. SendMessageW(child->left.hwnd, LB_SETCURSEL, idx, 0);
  2405. }
  2406. static void create_drive_bar(void)
  2407. {
  2408. TBBUTTON drivebarBtn = {0, 0, TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0};
  2409. WCHAR b1[BUFFER_LEN];
  2410. int btn = 1;
  2411. PWSTR p;
  2412. GetLogicalDriveStringsW(BUFFER_LEN, Globals.drives);
  2413. Globals.hdrivebar = CreateToolbarEx(Globals.hMainWnd, WS_CHILD|WS_VISIBLE|CCS_NOMOVEY|TBSTYLE_LIST,
  2414. IDW_DRIVEBAR, 2, Globals.hInstance, IDB_DRIVEBAR, &drivebarBtn,
  2415. 0, 16, 13, 16, 13, sizeof(TBBUTTON));
  2416. /* insert shell namespace button */
  2417. load_string(b1, ARRAY_SIZE(b1), IDS_SHELL);
  2418. b1[lstrlenW(b1)+1] = '\0';
  2419. SendMessageW(Globals.hdrivebar, TB_ADDSTRINGW, 0, (LPARAM)b1);
  2420. drivebarBtn.idCommand = ID_DRIVE_SHELL_NS;
  2421. SendMessageW(Globals.hdrivebar, TB_INSERTBUTTONW, btn++, (LPARAM)&drivebarBtn);
  2422. drivebarBtn.iString++;
  2423. /* register windows drive root strings */
  2424. SendMessageW(Globals.hdrivebar, TB_ADDSTRINGW, 0, (LPARAM)Globals.drives);
  2425. drivebarBtn.idCommand = ID_DRIVE_FIRST;
  2426. for(p=Globals.drives; *p; ) {
  2427. switch(GetDriveTypeW(p)) {
  2428. case DRIVE_REMOVABLE: drivebarBtn.iBitmap = 1; break;
  2429. case DRIVE_CDROM: drivebarBtn.iBitmap = 3; break;
  2430. case DRIVE_REMOTE: drivebarBtn.iBitmap = 4; break;
  2431. case DRIVE_RAMDISK: drivebarBtn.iBitmap = 5; break;
  2432. default:/*DRIVE_FIXED*/ drivebarBtn.iBitmap = 2;
  2433. }
  2434. SendMessageW(Globals.hdrivebar, TB_INSERTBUTTONW, btn++, (LPARAM)&drivebarBtn);
  2435. drivebarBtn.idCommand++;
  2436. drivebarBtn.iString++;
  2437. while(*p++);
  2438. }
  2439. }
  2440. static void refresh_drives(void)
  2441. {
  2442. RECT rect;
  2443. /* destroy drive bar */
  2444. DestroyWindow(Globals.hdrivebar);
  2445. Globals.hdrivebar = 0;
  2446. /* re-create drive bar */
  2447. create_drive_bar();
  2448. /* update window layout */
  2449. GetClientRect(Globals.hMainWnd, &rect);
  2450. SendMessageW(Globals.hMainWnd, WM_SIZE, 0, MAKELONG(rect.right, rect.bottom));
  2451. }
  2452. static BOOL launch_file(HWND hwnd, LPCWSTR cmd, UINT nCmdShow)
  2453. {
  2454. HINSTANCE hinst = ShellExecuteW(hwnd, NULL/*operation*/, cmd, NULL/*parameters*/, NULL/*dir*/, nCmdShow);
  2455. if (PtrToUlong(hinst) <= 32) {
  2456. display_error(hwnd, GetLastError());
  2457. return FALSE;
  2458. }
  2459. return TRUE;
  2460. }
  2461. static BOOL launch_entry(Entry* entry, HWND hwnd, UINT nCmdShow)
  2462. {
  2463. WCHAR cmd[MAX_PATH];
  2464. if (entry->etype == ET_SHELL) {
  2465. BOOL ret = TRUE;
  2466. SHELLEXECUTEINFOW shexinfo;
  2467. shexinfo.cbSize = sizeof(SHELLEXECUTEINFOW);
  2468. shexinfo.fMask = SEE_MASK_IDLIST;
  2469. shexinfo.hwnd = hwnd;
  2470. shexinfo.lpVerb = NULL;
  2471. shexinfo.lpFile = NULL;
  2472. shexinfo.lpParameters = NULL;
  2473. shexinfo.lpDirectory = NULL;
  2474. shexinfo.nShow = nCmdShow;
  2475. shexinfo.lpIDList = get_to_absolute_pidl(entry, hwnd);
  2476. if (!ShellExecuteExW(&shexinfo)) {
  2477. display_error(hwnd, GetLastError());
  2478. ret = FALSE;
  2479. }
  2480. if (shexinfo.lpIDList != entry->pidl)
  2481. IMalloc_Free(Globals.iMalloc, shexinfo.lpIDList);
  2482. return ret;
  2483. }
  2484. get_path(entry, cmd);
  2485. /* start program, open document... */
  2486. return launch_file(hwnd, cmd, nCmdShow);
  2487. }
  2488. static void activate_entry(ChildWnd* child, Pane* pane, HWND hwnd)
  2489. {
  2490. Entry* entry = pane->cur;
  2491. if (!entry)
  2492. return;
  2493. if (entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
  2494. int scanned_old = entry->scanned;
  2495. if (!scanned_old)
  2496. {
  2497. int idx = SendMessageW(child->left.hwnd, LB_GETCURSEL, 0, 0);
  2498. scan_entry(child, entry, idx, hwnd);
  2499. }
  2500. if (entry->data.cFileName[0]=='.' && entry->data.cFileName[1]=='\0')
  2501. return;
  2502. if (entry->data.cFileName[0]=='.' && entry->data.cFileName[1]=='.' && entry->data.cFileName[2]=='\0') {
  2503. entry = child->left.cur->up;
  2504. collapse_entry(&child->left, entry);
  2505. goto focus_entry;
  2506. } else if (entry->expanded)
  2507. collapse_entry(pane, child->left.cur);
  2508. else {
  2509. expand_entry(child, child->left.cur);
  2510. if (!pane->treePane) focus_entry: {
  2511. int idxstart = SendMessageW(child->left.hwnd, LB_GETCURSEL, 0, 0);
  2512. int idx = SendMessageW(child->left.hwnd, LB_FINDSTRING, idxstart, (LPARAM)entry);
  2513. SendMessageW(child->left.hwnd, LB_SETCURSEL, idx, 0);
  2514. set_curdir(child, entry, idx, hwnd);
  2515. }
  2516. }
  2517. if (!scanned_old) {
  2518. calc_widths(pane, FALSE);
  2519. set_header(pane);
  2520. }
  2521. } else {
  2522. if (GetKeyState(VK_MENU) < 0)
  2523. show_properties_dlg(entry, child->hwnd);
  2524. else
  2525. launch_entry(entry, child->hwnd, SW_SHOWNORMAL);
  2526. }
  2527. }
  2528. static BOOL pane_command(Pane* pane, UINT cmd)
  2529. {
  2530. switch(cmd) {
  2531. case ID_VIEW_NAME:
  2532. if (pane->visible_cols) {
  2533. pane->visible_cols = 0;
  2534. calc_widths(pane, TRUE);
  2535. set_header(pane);
  2536. InvalidateRect(pane->hwnd, 0, TRUE);
  2537. CheckMenuItem(Globals.hMenuView, ID_VIEW_NAME, MF_BYCOMMAND|MF_CHECKED);
  2538. CheckMenuItem(Globals.hMenuView, ID_VIEW_ALL_ATTRIBUTES, MF_BYCOMMAND);
  2539. }
  2540. break;
  2541. case ID_VIEW_ALL_ATTRIBUTES:
  2542. if (pane->visible_cols != COL_ALL) {
  2543. pane->visible_cols = COL_ALL;
  2544. calc_widths(pane, TRUE);
  2545. set_header(pane);
  2546. InvalidateRect(pane->hwnd, 0, TRUE);
  2547. CheckMenuItem(Globals.hMenuView, ID_VIEW_NAME, MF_BYCOMMAND);
  2548. CheckMenuItem(Globals.hMenuView, ID_VIEW_ALL_ATTRIBUTES, MF_BYCOMMAND|MF_CHECKED);
  2549. }
  2550. break;
  2551. case ID_PREFERRED_SIZES: {
  2552. calc_widths(pane, TRUE);
  2553. set_header(pane);
  2554. InvalidateRect(pane->hwnd, 0, TRUE);
  2555. break;}
  2556. /* TODO: more command ids... */
  2557. default:
  2558. return FALSE;
  2559. }
  2560. return TRUE;
  2561. }
  2562. static void set_sort_order(ChildWnd* child, SORT_ORDER sortOrder)
  2563. {
  2564. if (child->sortOrder != sortOrder) {
  2565. child->sortOrder = sortOrder;
  2566. refresh_child(child);
  2567. }
  2568. }
  2569. static void update_view_menu(ChildWnd* child)
  2570. {
  2571. CheckMenuItem(Globals.hMenuView, ID_VIEW_SORT_NAME, child->sortOrder==SORT_NAME? MF_CHECKED: MF_UNCHECKED);
  2572. CheckMenuItem(Globals.hMenuView, ID_VIEW_SORT_TYPE, child->sortOrder==SORT_EXT? MF_CHECKED: MF_UNCHECKED);
  2573. CheckMenuItem(Globals.hMenuView, ID_VIEW_SORT_SIZE, child->sortOrder==SORT_SIZE? MF_CHECKED: MF_UNCHECKED);
  2574. CheckMenuItem(Globals.hMenuView, ID_VIEW_SORT_DATE, child->sortOrder==SORT_DATE? MF_CHECKED: MF_UNCHECKED);
  2575. }
  2576. static BOOL is_directory(LPCWSTR target)
  2577. {
  2578. DWORD target_attr = GetFileAttributesW(target);
  2579. if (target_attr == INVALID_FILE_ATTRIBUTES)
  2580. return FALSE;
  2581. return (target_attr & FILE_ATTRIBUTE_DIRECTORY) != 0;
  2582. }
  2583. static BOOL prompt_target(Pane* pane, LPWSTR source, LPWSTR target)
  2584. {
  2585. WCHAR path[MAX_PATH];
  2586. int len;
  2587. get_path(pane->cur, path);
  2588. if (DialogBoxParamW(Globals.hInstance, MAKEINTRESOURCEW(IDD_SELECT_DESTINATION), pane->hwnd, DestinationDlgProc, (LPARAM)path) != IDOK)
  2589. return FALSE;
  2590. get_path(pane->cur, source);
  2591. /* convert relative targets to absolute paths */
  2592. if (path[0]!='/' && path[1]!=':') {
  2593. get_path(pane->cur->up, target);
  2594. len = lstrlenW(target);
  2595. if (target[len-1]!='\\' && target[len-1]!='/')
  2596. target[len++] = '/';
  2597. lstrcpyW(target+len, path);
  2598. } else
  2599. lstrcpyW(target, path);
  2600. /* If the target already exists as directory, create a new target below this. */
  2601. if (is_directory(path)) {
  2602. WCHAR fname[_MAX_FNAME], ext[_MAX_EXT];
  2603. static const WCHAR sAppend[] = {'%','s','/','%','s','%','s','\0'};
  2604. _wsplitpath(source, NULL, NULL, fname, ext);
  2605. wsprintfW(target, sAppend, path, fname, ext);
  2606. }
  2607. return TRUE;
  2608. }
  2609. static IContextMenu2* s_pctxmenu2 = NULL;
  2610. static IContextMenu3* s_pctxmenu3 = NULL;
  2611. static void CtxMenu_reset(void)
  2612. {
  2613. s_pctxmenu2 = NULL;
  2614. s_pctxmenu3 = NULL;
  2615. }
  2616. static IContextMenu* CtxMenu_query_interfaces(IContextMenu* pcm1)
  2617. {
  2618. IContextMenu* pcm = NULL;
  2619. CtxMenu_reset();
  2620. if (IContextMenu_QueryInterface(pcm1, &IID_IContextMenu3, (void**)&pcm) == NOERROR)
  2621. s_pctxmenu3 = (LPCONTEXTMENU3)pcm;
  2622. else if (IContextMenu_QueryInterface(pcm1, &IID_IContextMenu2, (void**)&pcm) == NOERROR)
  2623. s_pctxmenu2 = (LPCONTEXTMENU2)pcm;
  2624. if (pcm) {
  2625. IContextMenu_Release(pcm1);
  2626. return pcm;
  2627. } else
  2628. return pcm1;
  2629. }
  2630. static BOOL CtxMenu_HandleMenuMsg(UINT nmsg, WPARAM wparam, LPARAM lparam)
  2631. {
  2632. if (s_pctxmenu3) {
  2633. if (SUCCEEDED(IContextMenu3_HandleMenuMsg(s_pctxmenu3, nmsg, wparam, lparam)))
  2634. return TRUE;
  2635. }
  2636. if (s_pctxmenu2)
  2637. if (SUCCEEDED(IContextMenu2_HandleMenuMsg(s_pctxmenu2, nmsg, wparam, lparam)))
  2638. return TRUE;
  2639. return FALSE;
  2640. }
  2641. static HRESULT ShellFolderContextMenu(IShellFolder* shell_folder, HWND hwndParent, int cidl, LPCITEMIDLIST* apidl, int x, int y)
  2642. {
  2643. IContextMenu* pcm;
  2644. BOOL executed = FALSE;
  2645. HRESULT hr = IShellFolder_GetUIObjectOf(shell_folder, hwndParent, cidl, apidl, &IID_IContextMenu, NULL, (LPVOID*)&pcm);
  2646. if (SUCCEEDED(hr)) {
  2647. HMENU hmenu = CreatePopupMenu();
  2648. pcm = CtxMenu_query_interfaces(pcm);
  2649. if (hmenu) {
  2650. hr = IContextMenu_QueryContextMenu(pcm, hmenu, 0, FCIDM_SHVIEWFIRST, FCIDM_SHVIEWLAST, CMF_NORMAL);
  2651. if (SUCCEEDED(hr)) {
  2652. UINT idCmd = TrackPopupMenu(hmenu, TPM_LEFTALIGN|TPM_RETURNCMD|TPM_RIGHTBUTTON, x, y, 0, hwndParent, NULL);
  2653. CtxMenu_reset();
  2654. if (idCmd) {
  2655. CMINVOKECOMMANDINFO cmi;
  2656. cmi.cbSize = sizeof(CMINVOKECOMMANDINFO);
  2657. cmi.fMask = 0;
  2658. cmi.hwnd = hwndParent;
  2659. cmi.lpVerb = (LPCSTR)(INT_PTR)(idCmd - FCIDM_SHVIEWFIRST);
  2660. cmi.lpParameters = NULL;
  2661. cmi.lpDirectory = NULL;
  2662. cmi.nShow = SW_SHOWNORMAL;
  2663. cmi.dwHotKey = 0;
  2664. cmi.hIcon = 0;
  2665. hr = IContextMenu_InvokeCommand(pcm, &cmi);
  2666. executed = TRUE;
  2667. }
  2668. } else
  2669. CtxMenu_reset();
  2670. }
  2671. IContextMenu_Release(pcm);
  2672. }
  2673. return FAILED(hr)? hr: executed? S_OK: S_FALSE;
  2674. }
  2675. static LRESULT CALLBACK ChildWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
  2676. {
  2677. ChildWnd* child = (ChildWnd*)GetWindowLongPtrW(hwnd, GWLP_USERDATA);
  2678. assert(child);
  2679. switch(nmsg) {
  2680. case WM_DRAWITEM: {
  2681. LPDRAWITEMSTRUCT dis = (LPDRAWITEMSTRUCT)lparam;
  2682. Entry* entry = (Entry*) dis->itemData;
  2683. if (dis->CtlID == IDW_TREE_LEFT)
  2684. draw_item(&child->left, dis, entry, -1);
  2685. else if (dis->CtlID == IDW_TREE_RIGHT)
  2686. draw_item(&child->right, dis, entry, -1);
  2687. else
  2688. goto draw_menu_item;
  2689. return TRUE;}
  2690. case WM_CREATE:
  2691. InitChildWindow(child);
  2692. break;
  2693. case WM_NCDESTROY:
  2694. free_child_window(child);
  2695. SetWindowLongPtrW(hwnd, GWLP_USERDATA, 0);
  2696. break;
  2697. case WM_PAINT: {
  2698. PAINTSTRUCT ps;
  2699. HBRUSH lastBrush;
  2700. RECT rt;
  2701. GetClientRect(hwnd, &rt);
  2702. BeginPaint(hwnd, &ps);
  2703. rt.left = child->split_pos-SPLIT_WIDTH/2;
  2704. rt.right = child->split_pos+SPLIT_WIDTH/2+1;
  2705. lastBrush = SelectObject(ps.hdc, GetStockObject(COLOR_SPLITBAR));
  2706. Rectangle(ps.hdc, rt.left, rt.top-1, rt.right, rt.bottom+1);
  2707. SelectObject(ps.hdc, lastBrush);
  2708. EndPaint(hwnd, &ps);
  2709. break;}
  2710. case WM_SETCURSOR:
  2711. if (LOWORD(lparam) == HTCLIENT) {
  2712. POINT pt;
  2713. GetCursorPos(&pt);
  2714. ScreenToClient(hwnd, &pt);
  2715. if (pt.x>=child->split_pos-SPLIT_WIDTH/2 && pt.x<child->split_pos+SPLIT_WIDTH/2+1) {
  2716. SetCursor(LoadCursorW(0, (LPCWSTR)IDC_SIZEWE));
  2717. return TRUE;
  2718. }
  2719. }
  2720. goto def;
  2721. case WM_LBUTTONDOWN: {
  2722. RECT rt;
  2723. int x = (short)LOWORD(lparam);
  2724. GetClientRect(hwnd, &rt);
  2725. if (x>=child->split_pos-SPLIT_WIDTH/2 && x<child->split_pos+SPLIT_WIDTH/2+1) {
  2726. last_split = child->split_pos;
  2727. SetCapture(hwnd);
  2728. }
  2729. break;}
  2730. case WM_LBUTTONUP:
  2731. if (GetCapture() == hwnd)
  2732. ReleaseCapture();
  2733. break;
  2734. case WM_KEYDOWN:
  2735. if (wparam == VK_ESCAPE)
  2736. if (GetCapture() == hwnd) {
  2737. RECT rt;
  2738. child->split_pos = last_split;
  2739. GetClientRect(hwnd, &rt);
  2740. resize_tree(child, rt.right, rt.bottom);
  2741. last_split = -1;
  2742. ReleaseCapture();
  2743. SetCursor(LoadCursorW(0, (LPCWSTR)IDC_ARROW));
  2744. }
  2745. break;
  2746. case WM_MOUSEMOVE:
  2747. if (GetCapture() == hwnd) {
  2748. RECT rt;
  2749. int x = (short)LOWORD(lparam);
  2750. GetClientRect(hwnd, &rt);
  2751. if (x>=0 && x<rt.right) {
  2752. child->split_pos = x;
  2753. resize_tree(child, rt.right, rt.bottom);
  2754. rt.left = x-SPLIT_WIDTH/2;
  2755. rt.right = x+SPLIT_WIDTH/2+1;
  2756. InvalidateRect(hwnd, &rt, FALSE);
  2757. UpdateWindow(child->left.hwnd);
  2758. UpdateWindow(hwnd);
  2759. UpdateWindow(child->right.hwnd);
  2760. }
  2761. }
  2762. break;
  2763. case WM_GETMINMAXINFO:
  2764. DefMDIChildProcW(hwnd, nmsg, wparam, lparam);
  2765. {LPMINMAXINFO lpmmi = (LPMINMAXINFO)lparam;
  2766. lpmmi->ptMaxTrackSize.x <<= 1;/*2*GetSystemMetrics(SM_CXSCREEN) / SM_CXVIRTUALSCREEN */
  2767. lpmmi->ptMaxTrackSize.y <<= 1;/*2*GetSystemMetrics(SM_CYSCREEN) / SM_CYVIRTUALSCREEN */
  2768. break;}
  2769. case WM_SETFOCUS:
  2770. if (SetCurrentDirectoryW(child->path))
  2771. set_space_status();
  2772. SetFocus(child->focus_pane? child->right.hwnd: child->left.hwnd);
  2773. break;
  2774. case WM_DISPATCH_COMMAND: {
  2775. Pane* pane = GetFocus()==child->left.hwnd? &child->left: &child->right;
  2776. switch(LOWORD(wparam)) {
  2777. case ID_WINDOW_NEW: {
  2778. ChildWnd* new_child = alloc_child_window(child->path, NULL, hwnd);
  2779. if (!create_child_window(new_child))
  2780. HeapFree(GetProcessHeap(), 0, new_child);
  2781. break;}
  2782. case ID_REFRESH:
  2783. refresh_drives();
  2784. refresh_child(child);
  2785. break;
  2786. case ID_ACTIVATE:
  2787. activate_entry(child, pane, hwnd);
  2788. break;
  2789. case ID_FILE_MOVE: {
  2790. WCHAR source[BUFFER_LEN], target[BUFFER_LEN];
  2791. if (prompt_target(pane, source, target)) {
  2792. SHFILEOPSTRUCTW shfo = {hwnd, FO_MOVE, source, target};
  2793. source[lstrlenW(source)+1] = '\0';
  2794. target[lstrlenW(target)+1] = '\0';
  2795. if (!SHFileOperationW(&shfo))
  2796. refresh_child(child);
  2797. }
  2798. break;}
  2799. case ID_FILE_COPY: {
  2800. WCHAR source[BUFFER_LEN], target[BUFFER_LEN];
  2801. if (prompt_target(pane, source, target)) {
  2802. SHFILEOPSTRUCTW shfo = {hwnd, FO_COPY, source, target};
  2803. source[lstrlenW(source)+1] = '\0';
  2804. target[lstrlenW(target)+1] = '\0';
  2805. if (!SHFileOperationW(&shfo))
  2806. refresh_child(child);
  2807. }
  2808. break;}
  2809. case ID_FILE_DELETE: {
  2810. WCHAR path[BUFFER_LEN];
  2811. SHFILEOPSTRUCTW shfo = {hwnd, FO_DELETE, path, NULL, FOF_ALLOWUNDO};
  2812. get_path(pane->cur, path);
  2813. path[lstrlenW(path)+1] = '\0';
  2814. if (!SHFileOperationW(&shfo))
  2815. refresh_child(child);
  2816. break;}
  2817. case ID_VIEW_SORT_NAME:
  2818. set_sort_order(child, SORT_NAME);
  2819. break;
  2820. case ID_VIEW_SORT_TYPE:
  2821. set_sort_order(child, SORT_EXT);
  2822. break;
  2823. case ID_VIEW_SORT_SIZE:
  2824. set_sort_order(child, SORT_SIZE);
  2825. break;
  2826. case ID_VIEW_SORT_DATE:
  2827. set_sort_order(child, SORT_DATE);
  2828. break;
  2829. case ID_VIEW_FILTER: {
  2830. struct FilterDialog dlg;
  2831. memset(&dlg, 0, sizeof(struct FilterDialog));
  2832. lstrcpyW(dlg.pattern, child->filter_pattern);
  2833. dlg.flags = child->filter_flags;
  2834. if (DialogBoxParamW(Globals.hInstance, MAKEINTRESOURCEW(IDD_DIALOG_VIEW_TYPE), hwnd, FilterDialogDlgProc, (LPARAM)&dlg) == IDOK) {
  2835. lstrcpyW(child->filter_pattern, dlg.pattern);
  2836. child->filter_flags = dlg.flags;
  2837. refresh_right_pane(child);
  2838. }
  2839. break;}
  2840. case ID_VIEW_SPLIT: {
  2841. last_split = child->split_pos;
  2842. SetCapture(hwnd);
  2843. break;}
  2844. case ID_EDIT_PROPERTIES:
  2845. show_properties_dlg(pane->cur, child->hwnd);
  2846. break;
  2847. default:
  2848. return pane_command(pane, LOWORD(wparam));
  2849. }
  2850. return TRUE;}
  2851. case WM_COMMAND: {
  2852. Pane* pane = GetFocus()==child->left.hwnd? &child->left: &child->right;
  2853. switch(HIWORD(wparam)) {
  2854. case LBN_SELCHANGE: {
  2855. int idx = SendMessageW(pane->hwnd, LB_GETCURSEL, 0, 0);
  2856. Entry* entry = (Entry*)SendMessageW(pane->hwnd, LB_GETITEMDATA, idx, 0);
  2857. if (pane == &child->left)
  2858. set_curdir(child, entry, idx, hwnd);
  2859. else
  2860. pane->cur = entry;
  2861. break;}
  2862. case LBN_DBLCLK:
  2863. activate_entry(child, pane, hwnd);
  2864. break;
  2865. }
  2866. break;}
  2867. case WM_NOTIFY: {
  2868. NMHDR* pnmh = (NMHDR*) lparam;
  2869. return pane_notify(pnmh->idFrom==IDW_HEADER_LEFT? &child->left: &child->right, pnmh);}
  2870. case WM_CONTEXTMENU: {
  2871. POINT pt, pt_clnt;
  2872. Pane* pane;
  2873. int idx;
  2874. /* first select the current item in the listbox */
  2875. HWND hpanel = (HWND) wparam;
  2876. pt_clnt.x = pt.x = (short)LOWORD(lparam);
  2877. pt_clnt.y = pt.y = (short)HIWORD(lparam);
  2878. ScreenToClient(hpanel, &pt_clnt);
  2879. SendMessageW(hpanel, WM_LBUTTONDOWN, 0, MAKELONG(pt_clnt.x, pt_clnt.y));
  2880. SendMessageW(hpanel, WM_LBUTTONUP, 0, MAKELONG(pt_clnt.x, pt_clnt.y));
  2881. /* now create the popup menu using shell namespace and IContextMenu */
  2882. pane = GetFocus()==child->left.hwnd? &child->left: &child->right;
  2883. idx = SendMessageW(pane->hwnd, LB_GETCURSEL, 0, 0);
  2884. if (idx != -1) {
  2885. Entry* entry = (Entry*)SendMessageW(pane->hwnd, LB_GETITEMDATA, idx, 0);
  2886. LPITEMIDLIST pidl_abs = get_to_absolute_pidl(entry, hwnd);
  2887. if (pidl_abs) {
  2888. IShellFolder* parentFolder;
  2889. LPCITEMIDLIST pidlLast;
  2890. /* get and use the parent folder to display correct context menu in all cases */
  2891. if (SUCCEEDED(SHBindToParent(pidl_abs, &IID_IShellFolder, (LPVOID*)&parentFolder, &pidlLast))) {
  2892. if (ShellFolderContextMenu(parentFolder, hwnd, 1, &pidlLast, pt.x, pt.y) == S_OK)
  2893. refresh_child(child);
  2894. IShellFolder_Release(parentFolder);
  2895. }
  2896. IMalloc_Free(Globals.iMalloc, pidl_abs);
  2897. }
  2898. }
  2899. break;}
  2900. case WM_MEASUREITEM:
  2901. draw_menu_item:
  2902. if (!wparam) /* Is the message menu-related? */
  2903. if (CtxMenu_HandleMenuMsg(nmsg, wparam, lparam))
  2904. return TRUE;
  2905. break;
  2906. case WM_INITMENUPOPUP:
  2907. if (CtxMenu_HandleMenuMsg(nmsg, wparam, lparam))
  2908. return 0;
  2909. update_view_menu(child);
  2910. break;
  2911. case WM_MENUCHAR: /* only supported by IContextMenu3 */
  2912. if (s_pctxmenu3) {
  2913. LRESULT lResult = 0;
  2914. IContextMenu3_HandleMenuMsg2(s_pctxmenu3, nmsg, wparam, lparam, &lResult);
  2915. return lResult;
  2916. }
  2917. break;
  2918. case WM_SIZE:
  2919. if (wparam != SIZE_MINIMIZED)
  2920. resize_tree(child, LOWORD(lparam), HIWORD(lparam));
  2921. /* fall through */
  2922. default: def:
  2923. return DefMDIChildProcW(hwnd, nmsg, wparam, lparam);
  2924. }
  2925. return 0;
  2926. }
  2927. static LRESULT CALLBACK TreeWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
  2928. {
  2929. ChildWnd* child = (ChildWnd*)GetWindowLongPtrW(GetParent(hwnd), GWLP_USERDATA);
  2930. Pane* pane = (Pane*)GetWindowLongPtrW(hwnd, GWLP_USERDATA);
  2931. assert(child);
  2932. switch(nmsg) {
  2933. case WM_HSCROLL:
  2934. set_header(pane);
  2935. break;
  2936. case WM_SETFOCUS:
  2937. child->focus_pane = pane==&child->right? 1: 0;
  2938. SendMessageW(hwnd, LB_SETSEL, TRUE, 1);
  2939. /*TODO: check menu items */
  2940. break;
  2941. case WM_KEYDOWN:
  2942. if (wparam == VK_TAB) {
  2943. /*TODO: SetFocus(Globals.hdrivebar) */
  2944. SetFocus(child->focus_pane? child->left.hwnd: child->right.hwnd);
  2945. }
  2946. }
  2947. return CallWindowProcW(g_orgTreeWndProc, hwnd, nmsg, wparam, lparam);
  2948. }
  2949. static void InitInstance(HINSTANCE hinstance)
  2950. {
  2951. static const WCHAR sFont[] = {'M','i','c','r','o','s','o','f','t',' ','S','a','n','s',' ','S','e','r','i','f','\0'};
  2952. WNDCLASSEXW wcFrame;
  2953. WNDCLASSW wcChild;
  2954. int col;
  2955. INITCOMMONCONTROLSEX icc = {
  2956. sizeof(INITCOMMONCONTROLSEX),
  2957. ICC_BAR_CLASSES
  2958. };
  2959. HDC hdc = GetDC(0);
  2960. setlocale(LC_COLLATE, ""); /* set collating rules to local settings for compareName */
  2961. InitCommonControlsEx(&icc);
  2962. /* register frame window class */
  2963. wcFrame.cbSize = sizeof(WNDCLASSEXW);
  2964. wcFrame.style = 0;
  2965. wcFrame.lpfnWndProc = FrameWndProc;
  2966. wcFrame.cbClsExtra = 0;
  2967. wcFrame.cbWndExtra = 0;
  2968. wcFrame.hInstance = hinstance;
  2969. wcFrame.hIcon = LoadIconW(hinstance, MAKEINTRESOURCEW(IDI_WINEFILE));
  2970. wcFrame.hCursor = LoadCursorW(0, (LPCWSTR)IDC_ARROW);
  2971. wcFrame.hbrBackground = 0;
  2972. wcFrame.lpszMenuName = 0;
  2973. wcFrame.lpszClassName = sWINEFILEFRAME;
  2974. wcFrame.hIconSm = LoadImageW(hinstance, MAKEINTRESOURCEW(IDI_WINEFILE), IMAGE_ICON, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_SHARED);
  2975. Globals.hframeClass = RegisterClassExW(&wcFrame);
  2976. /* register tree windows class */
  2977. wcChild.style = CS_CLASSDC|CS_DBLCLKS|CS_VREDRAW;
  2978. wcChild.lpfnWndProc = ChildWndProc;
  2979. wcChild.cbClsExtra = 0;
  2980. wcChild.cbWndExtra = 0;
  2981. wcChild.hInstance = hinstance;
  2982. wcChild.hIcon = LoadIconW(hinstance, MAKEINTRESOURCEW(IDI_WINEFILE));
  2983. wcChild.hCursor = LoadCursorW(0, (LPCWSTR)IDC_ARROW);
  2984. wcChild.hbrBackground = 0;
  2985. wcChild.lpszMenuName = 0;
  2986. wcChild.lpszClassName = sWINEFILETREE;
  2987. RegisterClassW(&wcChild);
  2988. Globals.haccel = LoadAcceleratorsW(hinstance, MAKEINTRESOURCEW(IDA_WINEFILE));
  2989. Globals.hfont = CreateFontW(-MulDiv(8,GetDeviceCaps(hdc,LOGPIXELSY),72), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, sFont);
  2990. ReleaseDC(0, hdc);
  2991. Globals.hInstance = hinstance;
  2992. CoInitialize(NULL);
  2993. CoGetMalloc(MEMCTX_TASK, &Globals.iMalloc);
  2994. SHGetDesktopFolder(&Globals.iDesktop);
  2995. Globals.cfStrFName = RegisterClipboardFormatW(CFSTR_FILENAMEW);
  2996. /* load column strings */
  2997. col = 1;
  2998. load_string(g_pos_names[col++], ARRAY_SIZE(g_pos_names[col]), IDS_COL_NAME);
  2999. load_string(g_pos_names[col++], ARRAY_SIZE(g_pos_names[col]), IDS_COL_SIZE);
  3000. load_string(g_pos_names[col++], ARRAY_SIZE(g_pos_names[col]), IDS_COL_CDATE);
  3001. load_string(g_pos_names[col++], ARRAY_SIZE(g_pos_names[col]), IDS_COL_ADATE);
  3002. load_string(g_pos_names[col++], ARRAY_SIZE(g_pos_names[col]), IDS_COL_MDATE);
  3003. load_string(g_pos_names[col++], ARRAY_SIZE(g_pos_names[col]), IDS_COL_IDX);
  3004. load_string(g_pos_names[col++], ARRAY_SIZE(g_pos_names[col]), IDS_COL_LINKS);
  3005. load_string(g_pos_names[col++], ARRAY_SIZE(g_pos_names[col]), IDS_COL_ATTR);
  3006. load_string(g_pos_names[col++], ARRAY_SIZE(g_pos_names[col]), IDS_COL_SEC);
  3007. }
  3008. static BOOL show_frame(HWND hwndParent, int cmdshow, LPWSTR path)
  3009. {
  3010. static const WCHAR sMDICLIENT[] = {'M','D','I','C','L','I','E','N','T','\0'};
  3011. WCHAR buffer[MAX_PATH], b1[BUFFER_LEN];
  3012. ChildWnd* child;
  3013. HMENU hMenuFrame, hMenuWindow;
  3014. windowOptions opts;
  3015. CLIENTCREATESTRUCT ccs;
  3016. if (Globals.hMainWnd)
  3017. return TRUE;
  3018. opts = load_registry_settings();
  3019. hMenuFrame = LoadMenuW(Globals.hInstance, MAKEINTRESOURCEW(IDM_WINEFILE));
  3020. hMenuWindow = GetSubMenu(hMenuFrame, GetMenuItemCount(hMenuFrame)-2);
  3021. Globals.hMenuFrame = hMenuFrame;
  3022. Globals.hMenuView = GetSubMenu(hMenuFrame, 2);
  3023. Globals.hMenuOptions = GetSubMenu(hMenuFrame, 3);
  3024. ccs.hWindowMenu = hMenuWindow;
  3025. ccs.idFirstChild = IDW_FIRST_CHILD;
  3026. /* create main window */
  3027. Globals.hMainWnd = CreateWindowExW(0, MAKEINTRESOURCEW(Globals.hframeClass), RS(b1,IDS_WINEFILE), WS_OVERLAPPEDWINDOW,
  3028. opts.start_x, opts.start_y, opts.width, opts.height,
  3029. hwndParent, Globals.hMenuFrame, Globals.hInstance, 0/*lpParam*/);
  3030. Globals.hmdiclient = CreateWindowExW(0, sMDICLIENT, NULL,
  3031. WS_CHILD|WS_CLIPCHILDREN|WS_VSCROLL|WS_HSCROLL|WS_VISIBLE|WS_BORDER,
  3032. 0, 0, 0, 0,
  3033. Globals.hMainWnd, 0, Globals.hInstance, &ccs);
  3034. CheckMenuItem(Globals.hMenuOptions, ID_VIEW_DRIVE_BAR, MF_BYCOMMAND|MF_CHECKED);
  3035. CheckMenuItem(Globals.hMenuOptions, ID_VIEW_SAVESETTINGS, MF_BYCOMMAND);
  3036. create_drive_bar();
  3037. {
  3038. TBBUTTON toolbarBtns[] = {
  3039. {0, 0, 0, BTNS_SEP, {0, 0}, 0, 0},
  3040. {0, ID_WINDOW_NEW, TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
  3041. {1, ID_WINDOW_CASCADE, TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
  3042. {2, ID_WINDOW_TILE_HORZ, TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
  3043. {3, ID_WINDOW_TILE_VERT, TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
  3044. };
  3045. Globals.htoolbar = CreateToolbarEx(Globals.hMainWnd, WS_CHILD|WS_VISIBLE,
  3046. IDW_TOOLBAR, 2, Globals.hInstance, IDB_TOOLBAR, toolbarBtns,
  3047. ARRAY_SIZE(toolbarBtns), 16, 15, 16, 15, sizeof(TBBUTTON));
  3048. CheckMenuItem(Globals.hMenuOptions, ID_VIEW_TOOL_BAR, MF_BYCOMMAND|MF_CHECKED);
  3049. }
  3050. Globals.hstatusbar = CreateStatusWindowW(WS_CHILD|WS_VISIBLE, 0, Globals.hMainWnd, IDW_STATUSBAR);
  3051. CheckMenuItem(Globals.hMenuOptions, ID_VIEW_STATUSBAR, MF_BYCOMMAND|MF_CHECKED);
  3052. /*TODO: read paths from registry */
  3053. if (!path || !*path) {
  3054. GetCurrentDirectoryW(MAX_PATH, buffer);
  3055. path = buffer;
  3056. }
  3057. ShowWindow(Globals.hMainWnd, cmdshow);
  3058. /* Shell Namespace as default: */
  3059. child = alloc_child_window(path, get_path_pidl(path,Globals.hMainWnd), Globals.hMainWnd);
  3060. child->pos.showCmd = SW_SHOWMAXIMIZED;
  3061. child->pos.rcNormalPosition.left = 0;
  3062. child->pos.rcNormalPosition.top = 0;
  3063. child->pos.rcNormalPosition.right = 320;
  3064. child->pos.rcNormalPosition.bottom = 280;
  3065. if (!create_child_window(child)) {
  3066. HeapFree(GetProcessHeap(), 0, child);
  3067. return FALSE;
  3068. }
  3069. SetWindowPlacement(child->hwnd, &child->pos);
  3070. Globals.himl = ImageList_LoadImageW(Globals.hInstance, MAKEINTRESOURCEW(IDB_IMAGES), 16, 0, RGB(0,255,0), IMAGE_BITMAP, 0);
  3071. Globals.prescan_node = FALSE;
  3072. UpdateWindow(Globals.hMainWnd);
  3073. if (child->hwnd && path && path[0])
  3074. {
  3075. int index,count;
  3076. WCHAR drv[_MAX_DRIVE+1], dir[_MAX_DIR], name[_MAX_FNAME], ext[_MAX_EXT];
  3077. WCHAR fullname[_MAX_FNAME+_MAX_EXT+1];
  3078. memset(name,0,sizeof(name));
  3079. memset(name,0,sizeof(ext));
  3080. _wsplitpath(path, drv, dir, name, ext);
  3081. if (name[0])
  3082. {
  3083. count = SendMessageW(child->right.hwnd, LB_GETCOUNT, 0, 0);
  3084. lstrcpyW(fullname,name);
  3085. lstrcatW(fullname,ext);
  3086. for (index = 0; index < count; index ++)
  3087. {
  3088. Entry* entry = (Entry*)SendMessageW(child->right.hwnd, LB_GETITEMDATA, index, 0);
  3089. if (lstrcmpW(entry->data.cFileName,fullname)==0 ||
  3090. lstrcmpW(entry->data.cAlternateFileName,fullname)==0)
  3091. {
  3092. SendMessageW(child->right.hwnd, LB_SETCURSEL, index, 0);
  3093. SetFocus(child->right.hwnd);
  3094. break;
  3095. }
  3096. }
  3097. }
  3098. }
  3099. return TRUE;
  3100. }
  3101. static void ExitInstance(void)
  3102. {
  3103. IShellFolder_Release(Globals.iDesktop);
  3104. IMalloc_Release(Globals.iMalloc);
  3105. CoUninitialize();
  3106. DeleteObject(Globals.hfont);
  3107. ImageList_Destroy(Globals.himl);
  3108. }
  3109. int APIENTRY wWinMain(HINSTANCE hinstance, HINSTANCE previnstance, LPWSTR cmdline, int cmdshow)
  3110. {
  3111. MSG msg;
  3112. InitInstance(hinstance);
  3113. if( !show_frame(0, cmdshow, cmdline) )
  3114. {
  3115. ExitInstance();
  3116. return 1;
  3117. }
  3118. while(GetMessageW(&msg, 0, 0, 0)) {
  3119. if (Globals.hmdiclient && TranslateMDISysAccel(Globals.hmdiclient, &msg))
  3120. continue;
  3121. if (Globals.hMainWnd && TranslateAcceleratorW(Globals.hMainWnd, Globals.haccel, &msg))
  3122. continue;
  3123. TranslateMessage(&msg);
  3124. DispatchMessageW(&msg);
  3125. }
  3126. ExitInstance();
  3127. return msg.wParam;
  3128. }