winefile.c 104 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110
  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(DWORD);
  923. if( RegQueryValueExW( hKey, reg_start_x, NULL, &type,
  924. (LPBYTE) &opts.start_x, &size ) != ERROR_SUCCESS )
  925. opts.start_x = CW_USEDEFAULT;
  926. if( RegQueryValueExW( hKey, reg_start_y, NULL, &type,
  927. (LPBYTE) &opts.start_y, &size ) != ERROR_SUCCESS )
  928. opts.start_y = CW_USEDEFAULT;
  929. if( RegQueryValueExW( hKey, reg_width, NULL, &type,
  930. (LPBYTE) &opts.width, &size ) != ERROR_SUCCESS )
  931. opts.width = CW_USEDEFAULT;
  932. if( RegQueryValueExW( hKey, reg_height, NULL, &type,
  933. (LPBYTE) &opts.height, &size ) != ERROR_SUCCESS )
  934. opts.height = CW_USEDEFAULT;
  935. size=sizeof(logfont);
  936. if( RegQueryValueExW( hKey, reg_logfont, NULL, &type,
  937. (LPBYTE) &logfont, &size ) != ERROR_SUCCESS )
  938. GetObjectW(GetStockObject(DEFAULT_GUI_FONT),sizeof(logfont),&logfont);
  939. RegCloseKey( hKey );
  940. Globals.hfont = CreateFontIndirectW(&logfont);
  941. return opts;
  942. }
  943. static void save_registry_settings(void)
  944. {
  945. WINDOWINFO wi;
  946. HKEY hKey;
  947. INT width, height;
  948. LOGFONTW logfont;
  949. wi.cbSize = sizeof( WINDOWINFO );
  950. GetWindowInfo(Globals.hMainWnd, &wi);
  951. width = wi.rcWindow.right - wi.rcWindow.left;
  952. height = wi.rcWindow.bottom - wi.rcWindow.top;
  953. if ( RegOpenKeyExW( HKEY_CURRENT_USER, registry_key,
  954. 0, KEY_SET_VALUE, &hKey ) != ERROR_SUCCESS )
  955. {
  956. /* Unable to save registry settings - try to create key */
  957. if ( RegCreateKeyExW( HKEY_CURRENT_USER, registry_key,
  958. 0, NULL, REG_OPTION_NON_VOLATILE,
  959. KEY_SET_VALUE, NULL, &hKey, NULL ) != ERROR_SUCCESS )
  960. {
  961. /* FIXME: Cannot create key */
  962. return;
  963. }
  964. }
  965. /* Save all of the settings */
  966. RegSetValueExW( hKey, reg_start_x, 0, REG_DWORD,
  967. (LPBYTE) &wi.rcWindow.left, sizeof(DWORD) );
  968. RegSetValueExW( hKey, reg_start_y, 0, REG_DWORD,
  969. (LPBYTE) &wi.rcWindow.top, sizeof(DWORD) );
  970. RegSetValueExW( hKey, reg_width, 0, REG_DWORD,
  971. (LPBYTE) &width, sizeof(DWORD) );
  972. RegSetValueExW( hKey, reg_height, 0, REG_DWORD,
  973. (LPBYTE) &height, sizeof(DWORD) );
  974. GetObjectW(Globals.hfont, sizeof(logfont), &logfont);
  975. RegSetValueExW( hKey, reg_logfont, 0, REG_BINARY,
  976. (LPBYTE)&logfont, sizeof(LOGFONTW) );
  977. /* TODO: Save more settings here (List vs. Detailed View, etc.) */
  978. RegCloseKey( hKey );
  979. }
  980. static void resize_frame_rect(HWND hwnd, PRECT prect)
  981. {
  982. int new_top;
  983. RECT rt;
  984. if (IsWindowVisible(Globals.htoolbar)) {
  985. SendMessageW(Globals.htoolbar, WM_SIZE, 0, 0);
  986. GetClientRect(Globals.htoolbar, &rt);
  987. prect->top = rt.bottom+3;
  988. prect->bottom -= rt.bottom+3;
  989. }
  990. if (IsWindowVisible(Globals.hdrivebar)) {
  991. SendMessageW(Globals.hdrivebar, WM_SIZE, 0, 0);
  992. GetClientRect(Globals.hdrivebar, &rt);
  993. new_top = --prect->top + rt.bottom+3;
  994. MoveWindow(Globals.hdrivebar, 0, prect->top, rt.right, new_top, TRUE);
  995. prect->top = new_top;
  996. prect->bottom -= rt.bottom+2;
  997. }
  998. if (IsWindowVisible(Globals.hstatusbar)) {
  999. int parts[] = {300, 500};
  1000. SendMessageW(Globals.hstatusbar, WM_SIZE, 0, 0);
  1001. SendMessageW(Globals.hstatusbar, SB_SETPARTS, 2, (LPARAM)&parts);
  1002. GetClientRect(Globals.hstatusbar, &rt);
  1003. prect->bottom -= rt.bottom;
  1004. }
  1005. MoveWindow(Globals.hmdiclient, prect->left-1,prect->top-1,prect->right+2,prect->bottom+1, TRUE);
  1006. }
  1007. static void resize_frame(HWND hwnd, int cx, int cy)
  1008. {
  1009. RECT rect;
  1010. rect.left = 0;
  1011. rect.top = 0;
  1012. rect.right = cx;
  1013. rect.bottom = cy;
  1014. resize_frame_rect(hwnd, &rect);
  1015. }
  1016. static void resize_frame_client(HWND hwnd)
  1017. {
  1018. RECT rect;
  1019. GetClientRect(hwnd, &rect);
  1020. resize_frame_rect(hwnd, &rect);
  1021. }
  1022. static HHOOK hcbthook;
  1023. static ChildWnd* newchild = NULL;
  1024. static LRESULT CALLBACK CBTProc(int code, WPARAM wparam, LPARAM lparam)
  1025. {
  1026. if (code==HCBT_CREATEWND && newchild) {
  1027. ChildWnd* child = newchild;
  1028. newchild = NULL;
  1029. child->hwnd = (HWND) wparam;
  1030. SetWindowLongPtrW(child->hwnd, GWLP_USERDATA, (LPARAM)child);
  1031. }
  1032. return CallNextHookEx(hcbthook, code, wparam, lparam);
  1033. }
  1034. static HWND create_child_window(ChildWnd* child)
  1035. {
  1036. MDICREATESTRUCTW mcs;
  1037. int idx;
  1038. mcs.szClass = sWINEFILETREE;
  1039. mcs.szTitle = child->path;
  1040. mcs.hOwner = Globals.hInstance;
  1041. mcs.x = child->pos.rcNormalPosition.left;
  1042. mcs.y = child->pos.rcNormalPosition.top;
  1043. mcs.cx = child->pos.rcNormalPosition.right-child->pos.rcNormalPosition.left;
  1044. mcs.cy = child->pos.rcNormalPosition.bottom-child->pos.rcNormalPosition.top;
  1045. mcs.style = 0;
  1046. mcs.lParam = 0;
  1047. hcbthook = SetWindowsHookExW(WH_CBT, CBTProc, 0, GetCurrentThreadId());
  1048. newchild = child;
  1049. child->hwnd = (HWND)SendMessageW(Globals.hmdiclient, WM_MDICREATE, 0, (LPARAM)&mcs);
  1050. if (!child->hwnd) {
  1051. UnhookWindowsHookEx(hcbthook);
  1052. return 0;
  1053. }
  1054. UnhookWindowsHookEx(hcbthook);
  1055. SendMessageW(child->left.hwnd, LB_SETITEMHEIGHT, 1, max(Globals.spaceSize.cy,IMAGE_HEIGHT+3));
  1056. SendMessageW(child->right.hwnd, LB_SETITEMHEIGHT, 1, max(Globals.spaceSize.cy,IMAGE_HEIGHT+3));
  1057. idx = SendMessageW(child->left.hwnd, LB_FINDSTRING, 0, (LPARAM)child->left.cur);
  1058. SendMessageW(child->left.hwnd, LB_SETCURSEL, idx, 0);
  1059. return child->hwnd;
  1060. }
  1061. #define RFF_NODEFAULT 0x02 /* No default item selected. */
  1062. static void WineFile_OnRun( HWND hwnd )
  1063. {
  1064. static const WCHAR shell32_dll[] = {'S','H','E','L','L','3','2','.','D','L','L',0};
  1065. void (WINAPI *pRunFileDlgAW )(HWND, HICON, LPWSTR, LPWSTR, LPWSTR, DWORD);
  1066. HMODULE hshell = GetModuleHandleW( shell32_dll );
  1067. HICON hIcon = LoadIconW(Globals.hInstance, MAKEINTRESOURCEW(IDI_WINEFILE));
  1068. pRunFileDlgAW = (void*)GetProcAddress(hshell, (LPCSTR)61);
  1069. if (pRunFileDlgAW) pRunFileDlgAW( hwnd, hIcon, NULL, NULL, NULL, RFF_NODEFAULT);
  1070. }
  1071. static INT_PTR CALLBACK DestinationDlgProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
  1072. {
  1073. WCHAR b1[BUFFER_LEN], b2[BUFFER_LEN];
  1074. switch(nmsg) {
  1075. case WM_INITDIALOG:
  1076. SetWindowLongPtrW(hwnd, GWLP_USERDATA, lparam);
  1077. SetWindowTextW(GetDlgItem(hwnd, 201), (LPCWSTR)lparam);
  1078. return 1;
  1079. case WM_COMMAND: {
  1080. int id = (int)wparam;
  1081. switch(id) {
  1082. case IDOK: {
  1083. LPWSTR dest = (LPWSTR)GetWindowLongPtrW(hwnd, GWLP_USERDATA);
  1084. GetWindowTextW(GetDlgItem(hwnd, 201), dest, MAX_PATH);
  1085. EndDialog(hwnd, id);
  1086. break;}
  1087. case IDCANCEL:
  1088. EndDialog(hwnd, id);
  1089. break;
  1090. case 254:
  1091. MessageBoxW(hwnd, RS(b1,IDS_NO_IMPL), RS(b2,IDS_WINEFILE), MB_OK);
  1092. break;
  1093. }
  1094. return 1;
  1095. }
  1096. }
  1097. return 0;
  1098. }
  1099. struct FilterDialog {
  1100. WCHAR pattern[MAX_PATH];
  1101. int flags;
  1102. };
  1103. static INT_PTR CALLBACK FilterDialogDlgProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
  1104. {
  1105. static struct FilterDialog* dlg;
  1106. switch(nmsg) {
  1107. case WM_INITDIALOG:
  1108. dlg = (struct FilterDialog*) lparam;
  1109. SetWindowTextW(GetDlgItem(hwnd, IDC_VIEW_PATTERN), dlg->pattern);
  1110. set_check(hwnd, IDC_VIEW_TYPE_DIRECTORIES, dlg->flags&TF_DIRECTORIES);
  1111. set_check(hwnd, IDC_VIEW_TYPE_PROGRAMS, dlg->flags&TF_PROGRAMS);
  1112. set_check(hwnd, IDC_VIEW_TYPE_DOCUMENTS, dlg->flags&TF_DOCUMENTS);
  1113. set_check(hwnd, IDC_VIEW_TYPE_OTHERS, dlg->flags&TF_OTHERS);
  1114. set_check(hwnd, IDC_VIEW_TYPE_HIDDEN, dlg->flags&TF_HIDDEN);
  1115. return 1;
  1116. case WM_COMMAND: {
  1117. int id = (int)wparam;
  1118. if (id == IDOK) {
  1119. int flags = 0;
  1120. GetWindowTextW(GetDlgItem(hwnd, IDC_VIEW_PATTERN), dlg->pattern, MAX_PATH);
  1121. flags |= get_check(hwnd, IDC_VIEW_TYPE_DIRECTORIES) ? TF_DIRECTORIES : 0;
  1122. flags |= get_check(hwnd, IDC_VIEW_TYPE_PROGRAMS) ? TF_PROGRAMS : 0;
  1123. flags |= get_check(hwnd, IDC_VIEW_TYPE_DOCUMENTS) ? TF_DOCUMENTS : 0;
  1124. flags |= get_check(hwnd, IDC_VIEW_TYPE_OTHERS) ? TF_OTHERS : 0;
  1125. flags |= get_check(hwnd, IDC_VIEW_TYPE_HIDDEN) ? TF_HIDDEN : 0;
  1126. dlg->flags = flags;
  1127. EndDialog(hwnd, id);
  1128. } else if (id == IDCANCEL)
  1129. EndDialog(hwnd, id);
  1130. return 1;}
  1131. }
  1132. return 0;
  1133. }
  1134. struct PropertiesDialog {
  1135. WCHAR path[MAX_PATH];
  1136. Entry entry;
  1137. void* pVersionData;
  1138. };
  1139. /* Structure used to store enumerated languages and code pages. */
  1140. struct LANGANDCODEPAGE {
  1141. WORD wLanguage;
  1142. WORD wCodePage;
  1143. } *lpTranslate;
  1144. static LPCSTR InfoStrings[] = {
  1145. "Comments",
  1146. "CompanyName",
  1147. "FileDescription",
  1148. "FileVersion",
  1149. "InternalName",
  1150. "LegalCopyright",
  1151. "LegalTrademarks",
  1152. "OriginalFilename",
  1153. "PrivateBuild",
  1154. "ProductName",
  1155. "ProductVersion",
  1156. "SpecialBuild",
  1157. NULL
  1158. };
  1159. static void PropDlg_DisplayValue(HWND hlbox, HWND hedit)
  1160. {
  1161. int idx = SendMessageW(hlbox, LB_GETCURSEL, 0, 0);
  1162. if (idx != LB_ERR) {
  1163. LPCWSTR pValue = (LPCWSTR)SendMessageW(hlbox, LB_GETITEMDATA, idx, 0);
  1164. if (pValue)
  1165. SetWindowTextW(hedit, pValue);
  1166. }
  1167. }
  1168. static void CheckForFileInfo(struct PropertiesDialog* dlg, HWND hwnd, LPCWSTR strFilename)
  1169. {
  1170. static const WCHAR sBackSlash[] = {'\\','\0'};
  1171. 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'};
  1172. static const WCHAR sStringFileInfo[] = {'\\','S','t','r','i','n','g','F','i','l','e','I','n','f','o','\\',
  1173. '%','0','4','x','%','0','4','x','\\','%','s','\0'};
  1174. static const WCHAR sFmt[] = {'%','d','.','%','d','.','%','d','.','%','d','\0'};
  1175. DWORD dwVersionDataLen = GetFileVersionInfoSizeW(strFilename, NULL);
  1176. if (dwVersionDataLen) {
  1177. dlg->pVersionData = HeapAlloc(GetProcessHeap(), 0, dwVersionDataLen);
  1178. if (GetFileVersionInfoW(strFilename, 0, dwVersionDataLen, dlg->pVersionData)) {
  1179. LPVOID pVal;
  1180. UINT nValLen;
  1181. if (VerQueryValueW(dlg->pVersionData, sBackSlash, &pVal, &nValLen)) {
  1182. if (nValLen == sizeof(VS_FIXEDFILEINFO)) {
  1183. VS_FIXEDFILEINFO* pFixedFileInfo = (VS_FIXEDFILEINFO*)pVal;
  1184. WCHAR buffer[BUFFER_LEN];
  1185. swprintf(buffer, ARRAY_SIZE(buffer), sFmt,
  1186. HIWORD(pFixedFileInfo->dwFileVersionMS), LOWORD(pFixedFileInfo->dwFileVersionMS),
  1187. HIWORD(pFixedFileInfo->dwFileVersionLS), LOWORD(pFixedFileInfo->dwFileVersionLS));
  1188. SetDlgItemTextW(hwnd, IDC_STATIC_PROP_VERSION, buffer);
  1189. }
  1190. }
  1191. /* Read the list of languages and code pages. */
  1192. if (VerQueryValueW(dlg->pVersionData, sTranslation, &pVal, &nValLen)) {
  1193. struct LANGANDCODEPAGE* pTranslate = (struct LANGANDCODEPAGE*)pVal;
  1194. struct LANGANDCODEPAGE* pEnd = (struct LANGANDCODEPAGE*)((LPBYTE)pVal+nValLen);
  1195. HWND hlbox = GetDlgItem(hwnd, IDC_LIST_PROP_VERSION_TYPES);
  1196. /* Read the file description for each language and code page. */
  1197. for(; pTranslate<pEnd; ++pTranslate) {
  1198. LPCSTR* p;
  1199. for(p=InfoStrings; *p; ++p) {
  1200. WCHAR subblock[200];
  1201. WCHAR infoStr[100];
  1202. LPCWSTR pTxt;
  1203. UINT nValLen;
  1204. LPCSTR pInfoString = *p;
  1205. MultiByteToWideChar(CP_ACP, 0, pInfoString, -1, infoStr, 100);
  1206. wsprintfW(subblock, sStringFileInfo, pTranslate->wLanguage, pTranslate->wCodePage, infoStr);
  1207. /* Retrieve file description for language and code page */
  1208. if (VerQueryValueW(dlg->pVersionData, subblock, (PVOID)&pTxt, &nValLen)) {
  1209. int idx = SendMessageW(hlbox, LB_ADDSTRING, 0L, (LPARAM)infoStr);
  1210. SendMessageW(hlbox, LB_SETITEMDATA, idx, (LPARAM)pTxt);
  1211. }
  1212. }
  1213. }
  1214. SendMessageW(hlbox, LB_SETCURSEL, 0, 0);
  1215. PropDlg_DisplayValue(hlbox, GetDlgItem(hwnd,IDC_LIST_PROP_VERSION_VALUES));
  1216. }
  1217. }
  1218. }
  1219. }
  1220. static INT_PTR CALLBACK PropertiesDialogDlgProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
  1221. {
  1222. static struct PropertiesDialog* dlg;
  1223. switch(nmsg) {
  1224. case WM_INITDIALOG: {
  1225. static const WCHAR sByteFmt[] = {'%','s',' ','B','y','t','e','s','\0'};
  1226. WCHAR b1[BUFFER_LEN], b2[BUFFER_LEN];
  1227. LPWIN32_FIND_DATAW pWFD;
  1228. dlg = (struct PropertiesDialog*) lparam;
  1229. pWFD = (LPWIN32_FIND_DATAW)&dlg->entry.data;
  1230. GetWindowTextW(hwnd, b1, MAX_PATH);
  1231. wsprintfW(b2, b1, pWFD->cFileName);
  1232. SetWindowTextW(hwnd, b2);
  1233. format_date(&pWFD->ftLastWriteTime, b1, COL_DATE|COL_TIME);
  1234. SetWindowTextW(GetDlgItem(hwnd, IDC_STATIC_PROP_LASTCHANGE), b1);
  1235. format_longlong( b1, ((ULONGLONG)pWFD->nFileSizeHigh << 32) | pWFD->nFileSizeLow );
  1236. wsprintfW(b2, sByteFmt, b1);
  1237. SetWindowTextW(GetDlgItem(hwnd, IDC_STATIC_PROP_SIZE), b2);
  1238. SetWindowTextW(GetDlgItem(hwnd, IDC_STATIC_PROP_FILENAME), pWFD->cFileName);
  1239. SetWindowTextW(GetDlgItem(hwnd, IDC_STATIC_PROP_PATH), dlg->path);
  1240. set_check(hwnd, IDC_CHECK_READONLY, pWFD->dwFileAttributes&FILE_ATTRIBUTE_READONLY);
  1241. set_check(hwnd, IDC_CHECK_ARCHIVE, pWFD->dwFileAttributes&FILE_ATTRIBUTE_ARCHIVE);
  1242. set_check(hwnd, IDC_CHECK_COMPRESSED, pWFD->dwFileAttributes&FILE_ATTRIBUTE_COMPRESSED);
  1243. set_check(hwnd, IDC_CHECK_HIDDEN, pWFD->dwFileAttributes&FILE_ATTRIBUTE_HIDDEN);
  1244. set_check(hwnd, IDC_CHECK_SYSTEM, pWFD->dwFileAttributes&FILE_ATTRIBUTE_SYSTEM);
  1245. CheckForFileInfo(dlg, hwnd, dlg->path);
  1246. return 1;}
  1247. case WM_COMMAND: {
  1248. int id = (int)wparam;
  1249. switch(HIWORD(wparam)) {
  1250. case LBN_SELCHANGE: {
  1251. HWND hlbox = GetDlgItem(hwnd, IDC_LIST_PROP_VERSION_TYPES);
  1252. PropDlg_DisplayValue(hlbox, GetDlgItem(hwnd,IDC_LIST_PROP_VERSION_VALUES));
  1253. break;
  1254. }
  1255. case BN_CLICKED:
  1256. if (id==IDOK || id==IDCANCEL)
  1257. EndDialog(hwnd, id);
  1258. }
  1259. return 1;}
  1260. case WM_NCDESTROY:
  1261. HeapFree(GetProcessHeap(), 0, dlg->pVersionData);
  1262. dlg->pVersionData = NULL;
  1263. break;
  1264. }
  1265. return 0;
  1266. }
  1267. static void show_properties_dlg(Entry* entry, HWND hwnd)
  1268. {
  1269. struct PropertiesDialog dlg;
  1270. memset(&dlg, 0, sizeof(struct PropertiesDialog));
  1271. get_path(entry, dlg.path);
  1272. memcpy(&dlg.entry, entry, sizeof(Entry));
  1273. DialogBoxParamW(Globals.hInstance, MAKEINTRESOURCEW(IDD_DIALOG_PROPERTIES), hwnd, PropertiesDialogDlgProc, (LPARAM)&dlg);
  1274. }
  1275. static struct FullScreenParameters {
  1276. BOOL mode;
  1277. RECT orgPos;
  1278. BOOL wasZoomed;
  1279. } g_fullscreen = {
  1280. FALSE, /* mode */
  1281. {0, 0, 0, 0},
  1282. FALSE
  1283. };
  1284. static void frame_get_clientspace(HWND hwnd, PRECT prect)
  1285. {
  1286. RECT rt;
  1287. if (!IsIconic(hwnd))
  1288. GetClientRect(hwnd, prect);
  1289. else {
  1290. WINDOWPLACEMENT wp;
  1291. wp.length = sizeof(wp);
  1292. GetWindowPlacement(hwnd, &wp);
  1293. prect->left = prect->top = 0;
  1294. prect->right = wp.rcNormalPosition.right-wp.rcNormalPosition.left-
  1295. 2*(GetSystemMetrics(SM_CXSIZEFRAME)+GetSystemMetrics(SM_CXEDGE));
  1296. prect->bottom = wp.rcNormalPosition.bottom-wp.rcNormalPosition.top-
  1297. 2*(GetSystemMetrics(SM_CYSIZEFRAME)+GetSystemMetrics(SM_CYEDGE))-
  1298. GetSystemMetrics(SM_CYCAPTION)-GetSystemMetrics(SM_CYMENUSIZE);
  1299. }
  1300. if (IsWindowVisible(Globals.htoolbar)) {
  1301. GetClientRect(Globals.htoolbar, &rt);
  1302. prect->top += rt.bottom+2;
  1303. }
  1304. if (IsWindowVisible(Globals.hdrivebar)) {
  1305. GetClientRect(Globals.hdrivebar, &rt);
  1306. prect->top += rt.bottom+2;
  1307. }
  1308. if (IsWindowVisible(Globals.hstatusbar)) {
  1309. GetClientRect(Globals.hstatusbar, &rt);
  1310. prect->bottom -= rt.bottom;
  1311. }
  1312. }
  1313. static BOOL toggle_fullscreen(HWND hwnd)
  1314. {
  1315. RECT rt;
  1316. if ((g_fullscreen.mode=!g_fullscreen.mode)) {
  1317. GetWindowRect(hwnd, &g_fullscreen.orgPos);
  1318. g_fullscreen.wasZoomed = IsZoomed(hwnd);
  1319. Frame_CalcFrameClient(hwnd, &rt);
  1320. MapWindowPoints( hwnd, 0, (POINT *)&rt, 2 );
  1321. rt.left = g_fullscreen.orgPos.left-rt.left;
  1322. rt.top = g_fullscreen.orgPos.top-rt.top;
  1323. rt.right = GetSystemMetrics(SM_CXSCREEN)+g_fullscreen.orgPos.right-rt.right;
  1324. rt.bottom = GetSystemMetrics(SM_CYSCREEN)+g_fullscreen.orgPos.bottom-rt.bottom;
  1325. MoveWindow(hwnd, rt.left, rt.top, rt.right-rt.left, rt.bottom-rt.top, TRUE);
  1326. } else {
  1327. MoveWindow(hwnd, g_fullscreen.orgPos.left, g_fullscreen.orgPos.top,
  1328. g_fullscreen.orgPos.right-g_fullscreen.orgPos.left,
  1329. g_fullscreen.orgPos.bottom-g_fullscreen.orgPos.top, TRUE);
  1330. if (g_fullscreen.wasZoomed)
  1331. ShowWindow(hwnd, WS_MAXIMIZE);
  1332. }
  1333. return g_fullscreen.mode;
  1334. }
  1335. static void fullscreen_move(HWND hwnd)
  1336. {
  1337. RECT rt, pos;
  1338. GetWindowRect(hwnd, &pos);
  1339. Frame_CalcFrameClient(hwnd, &rt);
  1340. MapWindowPoints( hwnd, 0, (POINT *)&rt, 2 );
  1341. rt.left = pos.left-rt.left;
  1342. rt.top = pos.top-rt.top;
  1343. rt.right = GetSystemMetrics(SM_CXSCREEN)+pos.right-rt.right;
  1344. rt.bottom = GetSystemMetrics(SM_CYSCREEN)+pos.bottom-rt.bottom;
  1345. MoveWindow(hwnd, rt.left, rt.top, rt.right-rt.left, rt.bottom-rt.top, TRUE);
  1346. }
  1347. static void toggle_child(HWND hwnd, UINT cmd, HWND hchild)
  1348. {
  1349. BOOL vis = IsWindowVisible(hchild);
  1350. CheckMenuItem(Globals.hMenuOptions, cmd, vis?MF_BYCOMMAND:MF_BYCOMMAND|MF_CHECKED);
  1351. ShowWindow(hchild, vis?SW_HIDE:SW_SHOW);
  1352. if (g_fullscreen.mode)
  1353. fullscreen_move(hwnd);
  1354. resize_frame_client(hwnd);
  1355. }
  1356. static BOOL activate_drive_window(LPCWSTR path)
  1357. {
  1358. WCHAR drv1[_MAX_DRIVE], drv2[_MAX_DRIVE];
  1359. HWND child_wnd;
  1360. _wsplitpath(path, drv1, 0, 0, 0);
  1361. /* search for an already open window for the same drive */
  1362. for(child_wnd=GetNextWindow(Globals.hmdiclient,GW_CHILD); child_wnd; child_wnd=GetNextWindow(child_wnd, GW_HWNDNEXT)) {
  1363. ChildWnd* child = (ChildWnd*)GetWindowLongPtrW(child_wnd, GWLP_USERDATA);
  1364. if (child) {
  1365. _wsplitpath(child->root.path, drv2, 0, 0, 0);
  1366. if (!lstrcmpiW(drv2, drv1)) {
  1367. SendMessageW(Globals.hmdiclient, WM_MDIACTIVATE, (WPARAM)child_wnd, 0);
  1368. if (IsIconic(child_wnd))
  1369. ShowWindow(child_wnd, SW_SHOWNORMAL);
  1370. return TRUE;
  1371. }
  1372. }
  1373. }
  1374. return FALSE;
  1375. }
  1376. static BOOL activate_fs_window(LPCWSTR filesys)
  1377. {
  1378. HWND child_wnd;
  1379. /* search for an already open window of the given file system name */
  1380. for(child_wnd=GetNextWindow(Globals.hmdiclient,GW_CHILD); child_wnd; child_wnd=GetNextWindow(child_wnd, GW_HWNDNEXT)) {
  1381. ChildWnd* child = (ChildWnd*) GetWindowLongPtrW(child_wnd, GWLP_USERDATA);
  1382. if (child) {
  1383. if (!lstrcmpiW(child->root.fs, filesys)) {
  1384. SendMessageW(Globals.hmdiclient, WM_MDIACTIVATE, (WPARAM)child_wnd, 0);
  1385. if (IsIconic(child_wnd))
  1386. ShowWindow(child_wnd, SW_SHOWNORMAL);
  1387. return TRUE;
  1388. }
  1389. }
  1390. }
  1391. return FALSE;
  1392. }
  1393. static LRESULT CALLBACK FrameWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
  1394. {
  1395. WCHAR b1[BUFFER_LEN], b2[BUFFER_LEN];
  1396. switch(nmsg) {
  1397. case WM_CLOSE:
  1398. if (Globals.saveSettings)
  1399. save_registry_settings();
  1400. DestroyWindow(hwnd);
  1401. /* clear handle variables */
  1402. Globals.hMenuFrame = 0;
  1403. Globals.hMenuView = 0;
  1404. Globals.hMenuOptions = 0;
  1405. Globals.hMainWnd = 0;
  1406. Globals.hmdiclient = 0;
  1407. Globals.hdrivebar = 0;
  1408. break;
  1409. case WM_DESTROY:
  1410. PostQuitMessage(0);
  1411. break;
  1412. case WM_INITMENUPOPUP: {
  1413. HWND hwndClient = (HWND)SendMessageW(Globals.hmdiclient, WM_MDIGETACTIVE, 0, 0);
  1414. if (!SendMessageW(hwndClient, WM_INITMENUPOPUP, wparam, lparam))
  1415. return 0;
  1416. break;}
  1417. case WM_COMMAND: {
  1418. UINT cmd = LOWORD(wparam);
  1419. HWND hwndClient = (HWND)SendMessageW(Globals.hmdiclient, WM_MDIGETACTIVE, 0, 0);
  1420. if (SendMessageW(hwndClient, WM_DISPATCH_COMMAND, wparam, lparam))
  1421. break;
  1422. if (cmd>=ID_DRIVE_FIRST && cmd<=ID_DRIVE_FIRST+0xFF) {
  1423. WCHAR drv[_MAX_DRIVE], path[MAX_PATH];
  1424. ChildWnd* child;
  1425. LPCWSTR root = Globals.drives;
  1426. int i;
  1427. for(i=cmd-ID_DRIVE_FIRST; i--; root++)
  1428. while(*root)
  1429. root++;
  1430. if (activate_drive_window(root))
  1431. return 0;
  1432. _wsplitpath(root, drv, 0, 0, 0);
  1433. if (!SetCurrentDirectoryW(drv)) {
  1434. display_error(hwnd, GetLastError());
  1435. return 0;
  1436. }
  1437. GetCurrentDirectoryW(MAX_PATH, path); /*TODO: store last directory per drive */
  1438. child = alloc_child_window(path, NULL, hwnd);
  1439. if (!create_child_window(child))
  1440. HeapFree(GetProcessHeap(), 0, child);
  1441. } else switch(cmd) {
  1442. case ID_FILE_EXIT:
  1443. SendMessageW(hwnd, WM_CLOSE, 0, 0);
  1444. break;
  1445. case ID_WINDOW_NEW: {
  1446. WCHAR path[MAX_PATH];
  1447. ChildWnd* child;
  1448. GetCurrentDirectoryW(MAX_PATH, path);
  1449. child = alloc_child_window(path, NULL, hwnd);
  1450. if (!create_child_window(child))
  1451. HeapFree(GetProcessHeap(), 0, child);
  1452. break;}
  1453. case ID_REFRESH:
  1454. refresh_drives();
  1455. break;
  1456. case ID_WINDOW_CASCADE:
  1457. SendMessageW(Globals.hmdiclient, WM_MDICASCADE, 0, 0);
  1458. break;
  1459. case ID_WINDOW_TILE_HORZ:
  1460. SendMessageW(Globals.hmdiclient, WM_MDITILE, MDITILE_HORIZONTAL, 0);
  1461. break;
  1462. case ID_WINDOW_TILE_VERT:
  1463. SendMessageW(Globals.hmdiclient, WM_MDITILE, MDITILE_VERTICAL, 0);
  1464. break;
  1465. case ID_WINDOW_ARRANGE:
  1466. SendMessageW(Globals.hmdiclient, WM_MDIICONARRANGE, 0, 0);
  1467. break;
  1468. case ID_SELECT_FONT:
  1469. choose_font(hwnd);
  1470. break;
  1471. case ID_VIEW_TOOL_BAR:
  1472. toggle_child(hwnd, cmd, Globals.htoolbar);
  1473. break;
  1474. case ID_VIEW_DRIVE_BAR:
  1475. toggle_child(hwnd, cmd, Globals.hdrivebar);
  1476. break;
  1477. case ID_VIEW_STATUSBAR:
  1478. toggle_child(hwnd, cmd, Globals.hstatusbar);
  1479. break;
  1480. case ID_VIEW_SAVESETTINGS:
  1481. Globals.saveSettings = !Globals.saveSettings;
  1482. CheckMenuItem(Globals.hMenuOptions, ID_VIEW_SAVESETTINGS,
  1483. Globals.saveSettings ? MF_CHECKED : MF_UNCHECKED );
  1484. break;
  1485. case ID_RUN:
  1486. WineFile_OnRun( hwnd );
  1487. break;
  1488. case ID_CONNECT_NETWORK_DRIVE: {
  1489. DWORD ret = WNetConnectionDialog(hwnd, RESOURCETYPE_DISK);
  1490. if (ret == NO_ERROR)
  1491. refresh_drives();
  1492. else if (ret != (DWORD)-1) {
  1493. if (ret == ERROR_EXTENDED_ERROR)
  1494. display_network_error(hwnd);
  1495. else
  1496. display_error(hwnd, ret);
  1497. }
  1498. break;}
  1499. case ID_DISCONNECT_NETWORK_DRIVE: {
  1500. DWORD ret = WNetDisconnectDialog(hwnd, RESOURCETYPE_DISK);
  1501. if (ret == NO_ERROR)
  1502. refresh_drives();
  1503. else if (ret != (DWORD)-1) {
  1504. if (ret == ERROR_EXTENDED_ERROR)
  1505. display_network_error(hwnd);
  1506. else
  1507. display_error(hwnd, ret);
  1508. }
  1509. break;}
  1510. case ID_HELP:
  1511. WinHelpW(hwnd, RS(b1,IDS_WINEFILE), HELP_INDEX, 0);
  1512. break;
  1513. case ID_VIEW_FULLSCREEN:
  1514. CheckMenuItem(Globals.hMenuOptions, cmd, toggle_fullscreen(hwnd)?MF_CHECKED:0);
  1515. break;
  1516. case ID_DRIVE_SHELL_NS: {
  1517. WCHAR path[MAX_PATH];
  1518. ChildWnd* child;
  1519. if (activate_fs_window(RS(b1,IDS_SHELL)))
  1520. break;
  1521. GetCurrentDirectoryW(MAX_PATH, path);
  1522. child = alloc_child_window(path, get_path_pidl(path,hwnd), hwnd);
  1523. if (!create_child_window(child))
  1524. HeapFree(GetProcessHeap(), 0, child);
  1525. break;}
  1526. /*TODO: There are even more menu items! */
  1527. case ID_ABOUT:
  1528. ShellAboutW(hwnd, RS(b1,IDS_WINEFILE), NULL,
  1529. LoadImageW( Globals.hInstance, MAKEINTRESOURCEW(IDI_WINEFILE),
  1530. IMAGE_ICON, 48, 48, LR_SHARED ));
  1531. break;
  1532. default:
  1533. /*TODO: if (wParam >= PM_FIRST_LANGUAGE && wParam <= PM_LAST_LANGUAGE)
  1534. STRING_SelectLanguageByNumber(wParam - PM_FIRST_LANGUAGE);
  1535. else */if ((cmd<IDW_FIRST_CHILD || cmd>=IDW_FIRST_CHILD+0x100) &&
  1536. (cmd<SC_SIZE || cmd>SC_RESTORE))
  1537. MessageBoxW(hwnd, RS(b2,IDS_NO_IMPL), RS(b1,IDS_WINEFILE), MB_OK);
  1538. return DefFrameProcW(hwnd, Globals.hmdiclient, nmsg, wparam, lparam);
  1539. }
  1540. break;}
  1541. case WM_SIZE:
  1542. resize_frame(hwnd, LOWORD(lparam), HIWORD(lparam));
  1543. break; /* do not pass message to DefFrameProcW */
  1544. case WM_DEVICECHANGE:
  1545. SendMessageW(hwnd, WM_COMMAND, MAKELONG(ID_REFRESH,0), 0);
  1546. break;
  1547. case WM_GETMINMAXINFO: {
  1548. LPMINMAXINFO lpmmi = (LPMINMAXINFO)lparam;
  1549. lpmmi->ptMaxTrackSize.x <<= 1;/*2*GetSystemMetrics(SM_CXSCREEN) / SM_CXVIRTUALSCREEN */
  1550. lpmmi->ptMaxTrackSize.y <<= 1;/*2*GetSystemMetrics(SM_CYSCREEN) / SM_CYVIRTUALSCREEN */
  1551. break;}
  1552. case FRM_CALC_CLIENT:
  1553. frame_get_clientspace(hwnd, (PRECT)lparam);
  1554. return TRUE;
  1555. default:
  1556. return DefFrameProcW(hwnd, Globals.hmdiclient, nmsg, wparam, lparam);
  1557. }
  1558. return 0;
  1559. }
  1560. static WCHAR g_pos_names[COLUMNS][40] = {
  1561. {'\0'} /* symbol */
  1562. };
  1563. static const int g_pos_align[] = {
  1564. 0,
  1565. HDF_LEFT, /* Name */
  1566. HDF_RIGHT, /* Size */
  1567. HDF_LEFT, /* CDate */
  1568. HDF_LEFT, /* ADate */
  1569. HDF_LEFT, /* MDate */
  1570. HDF_LEFT, /* Index */
  1571. HDF_CENTER, /* Links */
  1572. HDF_CENTER, /* Attributes */
  1573. HDF_LEFT /* Security */
  1574. };
  1575. static void resize_tree(ChildWnd* child, int cx, int cy)
  1576. {
  1577. HDWP hdwp = BeginDeferWindowPos(4);
  1578. RECT rt;
  1579. WINDOWPOS wp;
  1580. HD_LAYOUT hdl;
  1581. rt.left = 0;
  1582. rt.top = 0;
  1583. rt.right = cx;
  1584. rt.bottom = cy;
  1585. cx = child->split_pos + SPLIT_WIDTH/2;
  1586. hdl.prc = &rt;
  1587. hdl.pwpos = &wp;
  1588. SendMessageW(child->left.hwndHeader, HDM_LAYOUT, 0, (LPARAM)&hdl);
  1589. DeferWindowPos(hdwp, child->left.hwndHeader, wp.hwndInsertAfter,
  1590. wp.x-1, wp.y, child->split_pos-SPLIT_WIDTH/2+1, wp.cy, wp.flags);
  1591. DeferWindowPos(hdwp, child->right.hwndHeader, wp.hwndInsertAfter,
  1592. rt.left+cx+1, wp.y, wp.cx-cx+2, wp.cy, wp.flags);
  1593. 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);
  1594. DeferWindowPos(hdwp, child->right.hwnd, 0, rt.left+cx+1, rt.top, rt.right-cx, rt.bottom-rt.top, SWP_NOZORDER|SWP_NOACTIVATE);
  1595. EndDeferWindowPos(hdwp);
  1596. }
  1597. static HWND create_header(HWND parent, Pane* pane, UINT id)
  1598. {
  1599. HDITEMW hdi;
  1600. int idx;
  1601. HWND hwnd = CreateWindowW(WC_HEADERW, 0, WS_CHILD|WS_VISIBLE|HDS_HORZ|HDS_FULLDRAG/*TODO: |HDS_BUTTONS + sort orders*/,
  1602. 0, 0, 0, 0, parent, (HMENU)ULongToHandle(id), Globals.hInstance, 0);
  1603. if (!hwnd)
  1604. return 0;
  1605. SendMessageW(hwnd, WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), FALSE);
  1606. hdi.mask = HDI_TEXT|HDI_WIDTH|HDI_FORMAT;
  1607. for(idx=0; idx<COLUMNS; idx++) {
  1608. hdi.pszText = g_pos_names[idx];
  1609. hdi.fmt = HDF_STRING | g_pos_align[idx];
  1610. hdi.cxy = pane->widths[idx];
  1611. pane->widths_shown[idx] = hdi.cxy;
  1612. SendMessageW(hwnd, HDM_INSERTITEMW, idx, (LPARAM)&hdi);
  1613. }
  1614. return hwnd;
  1615. }
  1616. static void init_output(HWND hwnd)
  1617. {
  1618. static const WCHAR s1000[] = {'1','0','0','0','\0'};
  1619. WCHAR b[16];
  1620. HFONT old_font;
  1621. HDC hdc = GetDC(hwnd);
  1622. if (GetNumberFormatW(LOCALE_USER_DEFAULT, 0, s1000, 0, b, 16) > 4)
  1623. Globals.num_sep = b[1];
  1624. else
  1625. Globals.num_sep = '.';
  1626. old_font = SelectObject(hdc, Globals.hfont);
  1627. GetTextExtentPoint32W(hdc, sSpace, 1, &Globals.spaceSize);
  1628. SelectObject(hdc, old_font);
  1629. ReleaseDC(hwnd, hdc);
  1630. }
  1631. static void draw_item(Pane* pane, LPDRAWITEMSTRUCT dis, Entry* entry, int calcWidthCol);
  1632. /* calculate preferred width for all visible columns */
  1633. static BOOL calc_widths(Pane* pane, BOOL anyway)
  1634. {
  1635. int col, x, cx, spc=3*Globals.spaceSize.cx;
  1636. int entries = SendMessageW(pane->hwnd, LB_GETCOUNT, 0, 0);
  1637. int orgWidths[COLUMNS];
  1638. int orgPositions[COLUMNS+1];
  1639. HFONT hfontOld;
  1640. HDC hdc;
  1641. int cnt;
  1642. if (!anyway) {
  1643. memcpy(orgWidths, pane->widths, sizeof(orgWidths));
  1644. memcpy(orgPositions, pane->positions, sizeof(orgPositions));
  1645. }
  1646. for(col=0; col<COLUMNS; col++)
  1647. pane->widths[col] = 0;
  1648. hdc = GetDC(pane->hwnd);
  1649. hfontOld = SelectObject(hdc, Globals.hfont);
  1650. for(cnt=0; cnt<entries; cnt++) {
  1651. Entry* entry = (Entry*)SendMessageW(pane->hwnd, LB_GETITEMDATA, cnt, 0);
  1652. DRAWITEMSTRUCT dis;
  1653. dis.CtlType = 0;
  1654. dis.CtlID = 0;
  1655. dis.itemID = 0;
  1656. dis.itemAction = 0;
  1657. dis.itemState = 0;
  1658. dis.hwndItem = pane->hwnd;
  1659. dis.hDC = hdc;
  1660. SetRectEmpty(&dis.rcItem);
  1661. /*dis.itemData = 0; */
  1662. draw_item(pane, &dis, entry, COLUMNS);
  1663. }
  1664. SelectObject(hdc, hfontOld);
  1665. ReleaseDC(pane->hwnd, hdc);
  1666. x = 0;
  1667. for(col=0; col<COLUMNS; col++) {
  1668. pane->positions[col] = x;
  1669. cx = pane->widths[col];
  1670. if (cx) {
  1671. cx += spc;
  1672. if (cx < IMAGE_WIDTH)
  1673. cx = IMAGE_WIDTH;
  1674. pane->widths[col] = cx;
  1675. }
  1676. x += cx;
  1677. }
  1678. pane->positions[COLUMNS] = x;
  1679. SendMessageW(pane->hwnd, LB_SETHORIZONTALEXTENT, x, 0);
  1680. /* no change? */
  1681. if (!anyway && !memcmp(orgWidths, pane->widths, sizeof(orgWidths)))
  1682. return FALSE;
  1683. /* don't move, if only collapsing an entry */
  1684. if (!anyway && pane->widths[0]<orgWidths[0] &&
  1685. !memcmp(orgWidths+1, pane->widths+1, sizeof(orgWidths)-sizeof(int))) {
  1686. pane->widths[0] = orgWidths[0];
  1687. memcpy(pane->positions, orgPositions, sizeof(orgPositions));
  1688. return FALSE;
  1689. }
  1690. InvalidateRect(pane->hwnd, 0, TRUE);
  1691. return TRUE;
  1692. }
  1693. /* calculate one preferred column width */
  1694. static void calc_single_width(Pane* pane, int col)
  1695. {
  1696. HFONT hfontOld;
  1697. int x, cx;
  1698. int entries = SendMessageW(pane->hwnd, LB_GETCOUNT, 0, 0);
  1699. int cnt;
  1700. HDC hdc;
  1701. pane->widths[col] = 0;
  1702. hdc = GetDC(pane->hwnd);
  1703. hfontOld = SelectObject(hdc, Globals.hfont);
  1704. for(cnt=0; cnt<entries; cnt++) {
  1705. Entry* entry = (Entry*)SendMessageW(pane->hwnd, LB_GETITEMDATA, cnt, 0);
  1706. DRAWITEMSTRUCT dis;
  1707. dis.CtlType = 0;
  1708. dis.CtlID = 0;
  1709. dis.itemID = 0;
  1710. dis.itemAction = 0;
  1711. dis.itemState = 0;
  1712. dis.hwndItem = pane->hwnd;
  1713. dis.hDC = hdc;
  1714. SetRectEmpty(&dis.rcItem);
  1715. /*dis.itemData = 0; */
  1716. draw_item(pane, &dis, entry, col);
  1717. }
  1718. SelectObject(hdc, hfontOld);
  1719. ReleaseDC(pane->hwnd, hdc);
  1720. cx = pane->widths[col];
  1721. if (cx) {
  1722. cx += 3*Globals.spaceSize.cx;
  1723. if (cx < IMAGE_WIDTH)
  1724. cx = IMAGE_WIDTH;
  1725. }
  1726. pane->widths[col] = cx;
  1727. x = pane->positions[col] + cx;
  1728. for(; col<COLUMNS-1; ) {
  1729. pane->positions[++col] = x;
  1730. x += pane->widths[col];
  1731. }
  1732. SendMessageW(pane->hwnd, LB_SETHORIZONTALEXTENT, x, 0);
  1733. }
  1734. static BOOL pattern_match(LPCWSTR str, LPCWSTR pattern)
  1735. {
  1736. for( ; *str&&*pattern; str++,pattern++) {
  1737. if (*pattern == '*') {
  1738. do pattern++;
  1739. while(*pattern == '*');
  1740. if (!*pattern)
  1741. return TRUE;
  1742. for(; *str; str++)
  1743. if (*str==*pattern && pattern_match(str, pattern))
  1744. return TRUE;
  1745. return FALSE;
  1746. }
  1747. else if (*str!=*pattern && *pattern!='?')
  1748. return FALSE;
  1749. }
  1750. if (*str || *pattern)
  1751. if (*pattern!='*' || pattern[1]!='\0')
  1752. return FALSE;
  1753. return TRUE;
  1754. }
  1755. static BOOL pattern_imatch(LPCWSTR str, LPCWSTR pattern)
  1756. {
  1757. WCHAR b1[BUFFER_LEN], b2[BUFFER_LEN];
  1758. lstrcpyW(b1, str);
  1759. lstrcpyW(b2, pattern);
  1760. CharUpperW(b1);
  1761. CharUpperW(b2);
  1762. return pattern_match(b1, b2);
  1763. }
  1764. enum FILE_TYPE {
  1765. FT_OTHER = 0,
  1766. FT_EXECUTABLE = 1,
  1767. FT_DOCUMENT = 2
  1768. };
  1769. static enum FILE_TYPE get_file_type(LPCWSTR filename);
  1770. /* insert listbox entries after index idx */
  1771. static int insert_entries(Pane* pane, Entry* dir, LPCWSTR pattern, int filter_flags, int idx)
  1772. {
  1773. Entry* entry = dir;
  1774. if (!entry)
  1775. return idx;
  1776. ShowWindow(pane->hwnd, SW_HIDE);
  1777. for(; entry; entry=entry->next) {
  1778. if (pane->treePane && !(entry->data.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY))
  1779. continue;
  1780. if (entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
  1781. /* don't display entries "." and ".." in the left pane */
  1782. if (pane->treePane && entry->data.cFileName[0] == '.')
  1783. if (entry->data.cFileName[1] == '\0' ||
  1784. (entry->data.cFileName[1] == '.' &&
  1785. entry->data.cFileName[2] == '\0'))
  1786. continue;
  1787. /* filter directories in right pane */
  1788. if (!pane->treePane && !(filter_flags&TF_DIRECTORIES))
  1789. continue;
  1790. }
  1791. /* filter using the file name pattern */
  1792. if (pattern)
  1793. if (!pattern_imatch(entry->data.cFileName, pattern))
  1794. continue;
  1795. /* filter system and hidden files */
  1796. if (!(filter_flags&TF_HIDDEN) && (entry->data.dwFileAttributes&(FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM)))
  1797. continue;
  1798. /* filter looking at the file type */
  1799. if ((filter_flags&(TF_PROGRAMS|TF_DOCUMENTS|TF_OTHERS)) != (TF_PROGRAMS|TF_DOCUMENTS|TF_OTHERS))
  1800. switch(get_file_type(entry->data.cFileName)) {
  1801. case FT_EXECUTABLE:
  1802. if (!(filter_flags & TF_PROGRAMS))
  1803. continue;
  1804. break;
  1805. case FT_DOCUMENT:
  1806. if (!(filter_flags & TF_DOCUMENTS))
  1807. continue;
  1808. break;
  1809. default: /* TF_OTHERS */
  1810. if (!(filter_flags & TF_OTHERS))
  1811. continue;
  1812. }
  1813. if (idx != -1)
  1814. idx++;
  1815. SendMessageW(pane->hwnd, LB_INSERTSTRING, idx, (LPARAM)entry);
  1816. if (pane->treePane && entry->expanded)
  1817. idx = insert_entries(pane, entry->down, pattern, filter_flags, idx);
  1818. }
  1819. ShowWindow(pane->hwnd, SW_SHOW);
  1820. return idx;
  1821. }
  1822. static void set_space_status(void)
  1823. {
  1824. ULARGE_INTEGER ulFreeBytesToCaller, ulTotalBytes, ulFreeBytes;
  1825. WCHAR fmt[64], b1[64], b2[64], buffer[BUFFER_LEN];
  1826. if (GetDiskFreeSpaceExW(NULL, &ulFreeBytesToCaller, &ulTotalBytes, &ulFreeBytes)) {
  1827. DWORD_PTR args[2];
  1828. args[0] = (DWORD_PTR)StrFormatByteSizeW(ulFreeBytesToCaller.QuadPart, b1, ARRAY_SIZE(b1));
  1829. args[1] = (DWORD_PTR)StrFormatByteSizeW(ulTotalBytes.QuadPart, b2, ARRAY_SIZE(b2));
  1830. FormatMessageW(FORMAT_MESSAGE_FROM_STRING|FORMAT_MESSAGE_ARGUMENT_ARRAY,
  1831. RS(fmt,IDS_FREE_SPACE_FMT), 0, 0, buffer, ARRAY_SIZE(buffer),
  1832. (__ms_va_list*)args);
  1833. } else
  1834. lstrcpyW(buffer, sQMarks);
  1835. SendMessageW(Globals.hstatusbar, SB_SETTEXTW, 0, (LPARAM)buffer);
  1836. }
  1837. static WNDPROC g_orgTreeWndProc;
  1838. static void create_tree_window(HWND parent, Pane* pane, UINT id, UINT id_header, LPCWSTR pattern, int filter_flags)
  1839. {
  1840. static const WCHAR sListBox[] = {'L','i','s','t','B','o','x','\0'};
  1841. static BOOL s_init = FALSE;
  1842. Entry* entry = pane->root;
  1843. pane->hwnd = CreateWindowW(sListBox, sEmpty, WS_CHILD|WS_VISIBLE|WS_HSCROLL|WS_VSCROLL|
  1844. LBS_DISABLENOSCROLL|LBS_NOINTEGRALHEIGHT|LBS_OWNERDRAWFIXED|LBS_NOTIFY,
  1845. 0, 0, 0, 0, parent, (HMENU)ULongToHandle(id), Globals.hInstance, 0);
  1846. SetWindowLongPtrW(pane->hwnd, GWLP_USERDATA, (LPARAM)pane);
  1847. g_orgTreeWndProc = (WNDPROC)SetWindowLongPtrW(pane->hwnd, GWLP_WNDPROC, (LPARAM)TreeWndProc);
  1848. SendMessageW(pane->hwnd, WM_SETFONT, (WPARAM)Globals.hfont, FALSE);
  1849. /* insert entries into listbox */
  1850. if (entry)
  1851. insert_entries(pane, entry, pattern, filter_flags, -1);
  1852. /* calculate column widths */
  1853. if (!s_init) {
  1854. s_init = TRUE;
  1855. init_output(pane->hwnd);
  1856. }
  1857. calc_widths(pane, TRUE);
  1858. pane->hwndHeader = create_header(parent, pane, id_header);
  1859. }
  1860. static void InitChildWindow(ChildWnd* child)
  1861. {
  1862. create_tree_window(child->hwnd, &child->left, IDW_TREE_LEFT, IDW_HEADER_LEFT, NULL, TF_ALL);
  1863. create_tree_window(child->hwnd, &child->right, IDW_TREE_RIGHT, IDW_HEADER_RIGHT, child->filter_pattern, child->filter_flags);
  1864. }
  1865. static void format_date(const FILETIME* ft, WCHAR* buffer, int visible_cols)
  1866. {
  1867. SYSTEMTIME systime;
  1868. FILETIME lft;
  1869. int len = 0;
  1870. *buffer = '\0';
  1871. if (!ft->dwLowDateTime && !ft->dwHighDateTime)
  1872. return;
  1873. if (!FileTimeToLocalFileTime(ft, &lft))
  1874. {err: lstrcpyW(buffer,sQMarks); return;}
  1875. if (!FileTimeToSystemTime(&lft, &systime))
  1876. goto err;
  1877. if (visible_cols & COL_DATE) {
  1878. len = GetDateFormatW(LOCALE_USER_DEFAULT, 0, &systime, 0, buffer, BUFFER_LEN);
  1879. if (!len)
  1880. goto err;
  1881. }
  1882. if (visible_cols & COL_TIME) {
  1883. if (len)
  1884. buffer[len-1] = ' ';
  1885. buffer[len++] = ' ';
  1886. if (!GetTimeFormatW(LOCALE_USER_DEFAULT, 0, &systime, 0, buffer+len, BUFFER_LEN-len))
  1887. buffer[len] = '\0';
  1888. }
  1889. }
  1890. static void calc_width(Pane* pane, LPDRAWITEMSTRUCT dis, int col, LPCWSTR str)
  1891. {
  1892. RECT rt = {0, 0, 0, 0};
  1893. DrawTextW(dis->hDC, str, -1, &rt, DT_CALCRECT|DT_SINGLELINE|DT_NOPREFIX);
  1894. if (rt.right > pane->widths[col])
  1895. pane->widths[col] = rt.right;
  1896. }
  1897. static void calc_tabbed_width(Pane* pane, LPDRAWITEMSTRUCT dis, int col, LPCWSTR str)
  1898. {
  1899. RECT rt = {0, 0, 0, 0};
  1900. DrawTextW(dis->hDC, str, -1, &rt, DT_CALCRECT|DT_SINGLELINE|DT_EXPANDTABS|DT_TABSTOP|(2<<8));
  1901. /*FIXME rt (0,0) ??? */
  1902. if (rt.right > pane->widths[col])
  1903. pane->widths[col] = rt.right;
  1904. }
  1905. static void output_text(Pane* pane, LPDRAWITEMSTRUCT dis, int col, LPCWSTR str, DWORD flags)
  1906. {
  1907. int x = dis->rcItem.left;
  1908. RECT rt;
  1909. rt.left = x+pane->positions[col]+Globals.spaceSize.cx;
  1910. rt.top = dis->rcItem.top;
  1911. rt.right = x+pane->positions[col+1]-Globals.spaceSize.cx;
  1912. rt.bottom = dis->rcItem.bottom;
  1913. DrawTextW(dis->hDC, str, -1, &rt, DT_SINGLELINE|DT_NOPREFIX|flags);
  1914. }
  1915. static void output_tabbed_text(Pane* pane, LPDRAWITEMSTRUCT dis, int col, LPCWSTR str)
  1916. {
  1917. int x = dis->rcItem.left;
  1918. RECT rt;
  1919. rt.left = x+pane->positions[col]+Globals.spaceSize.cx;
  1920. rt.top = dis->rcItem.top;
  1921. rt.right = x+pane->positions[col+1]-Globals.spaceSize.cx;
  1922. rt.bottom = dis->rcItem.bottom;
  1923. DrawTextW(dis->hDC, str, -1, &rt, DT_SINGLELINE|DT_EXPANDTABS|DT_TABSTOP|(2<<8));
  1924. }
  1925. static void output_number(Pane* pane, LPDRAWITEMSTRUCT dis, int col, LPCWSTR str)
  1926. {
  1927. int x = dis->rcItem.left;
  1928. RECT rt;
  1929. LPCWSTR s = str;
  1930. WCHAR b[128];
  1931. LPWSTR d = b;
  1932. int pos;
  1933. rt.left = x+pane->positions[col]+Globals.spaceSize.cx;
  1934. rt.top = dis->rcItem.top;
  1935. rt.right = x+pane->positions[col+1]-Globals.spaceSize.cx;
  1936. rt.bottom = dis->rcItem.bottom;
  1937. if (*s)
  1938. *d++ = *s++;
  1939. /* insert number separator characters */
  1940. pos = lstrlenW(s) % 3;
  1941. while(*s)
  1942. if (pos--)
  1943. *d++ = *s++;
  1944. else {
  1945. *d++ = Globals.num_sep;
  1946. pos = 3;
  1947. }
  1948. DrawTextW(dis->hDC, b, d-b, &rt, DT_RIGHT|DT_SINGLELINE|DT_NOPREFIX|DT_END_ELLIPSIS);
  1949. }
  1950. static BOOL is_exe_file(LPCWSTR ext)
  1951. {
  1952. static const WCHAR executable_extensions[][4] = {
  1953. {'C','O','M','\0'},
  1954. {'E','X','E','\0'},
  1955. {'B','A','T','\0'},
  1956. {'C','M','D','\0'},
  1957. {'C','M','M','\0'},
  1958. {'B','T','M','\0'},
  1959. {'A','W','K','\0'},
  1960. {'\0'}
  1961. };
  1962. WCHAR ext_buffer[_MAX_EXT];
  1963. const WCHAR (*p)[4];
  1964. LPCWSTR s;
  1965. LPWSTR d;
  1966. for(s=ext+1,d=ext_buffer; (*d=tolower(*s)); s++)
  1967. d++;
  1968. for(p=executable_extensions; (*p)[0]; p++)
  1969. if (!lstrcmpiW(ext_buffer, *p))
  1970. return TRUE;
  1971. return FALSE;
  1972. }
  1973. static BOOL is_registered_type(LPCWSTR ext)
  1974. {
  1975. /* check if there exists a classname for this file extension in the registry */
  1976. if (!RegQueryValueW(HKEY_CLASSES_ROOT, ext, NULL, NULL))
  1977. return TRUE;
  1978. return FALSE;
  1979. }
  1980. static enum FILE_TYPE get_file_type(LPCWSTR filename)
  1981. {
  1982. LPCWSTR ext = wcsrchr(filename, '.');
  1983. if (!ext)
  1984. ext = sEmpty;
  1985. if (is_exe_file(ext))
  1986. return FT_EXECUTABLE;
  1987. else if (is_registered_type(ext))
  1988. return FT_DOCUMENT;
  1989. else
  1990. return FT_OTHER;
  1991. }
  1992. static void draw_item(Pane* pane, LPDRAWITEMSTRUCT dis, Entry* entry, int calcWidthCol)
  1993. {
  1994. WCHAR buffer[BUFFER_LEN];
  1995. DWORD attrs;
  1996. int visible_cols = pane->visible_cols;
  1997. COLORREF bkcolor, textcolor;
  1998. RECT focusRect = dis->rcItem;
  1999. HBRUSH hbrush;
  2000. enum IMAGE img;
  2001. int img_pos, cx;
  2002. int col = 0;
  2003. if (entry) {
  2004. attrs = entry->data.dwFileAttributes;
  2005. if (attrs & FILE_ATTRIBUTE_DIRECTORY) {
  2006. if (entry->data.cFileName[0] == '.' && entry->data.cFileName[1] == '.'
  2007. && entry->data.cFileName[2] == '\0')
  2008. img = IMG_FOLDER_UP;
  2009. else if (entry->data.cFileName[0] == '.' && entry->data.cFileName[1] == '\0')
  2010. img = IMG_FOLDER_CUR;
  2011. else if (pane->treePane && (dis->itemState&ODS_FOCUS))
  2012. img = IMG_OPEN_FOLDER;
  2013. else
  2014. img = IMG_FOLDER;
  2015. } else {
  2016. switch(get_file_type(entry->data.cFileName)) {
  2017. case FT_EXECUTABLE: img = IMG_EXECUTABLE; break;
  2018. case FT_DOCUMENT: img = IMG_DOCUMENT; break;
  2019. default: img = IMG_FILE;
  2020. }
  2021. }
  2022. } else {
  2023. attrs = 0;
  2024. img = IMG_NONE;
  2025. }
  2026. if (pane->treePane) {
  2027. if (entry) {
  2028. img_pos = dis->rcItem.left + entry->level*(IMAGE_WIDTH+TREE_LINE_DX);
  2029. if (calcWidthCol == -1) {
  2030. int x;
  2031. int y = dis->rcItem.top + IMAGE_HEIGHT/2;
  2032. Entry* up;
  2033. RECT rt_clip;
  2034. HRGN hrgn_org = CreateRectRgn(0, 0, 0, 0);
  2035. HRGN hrgn;
  2036. rt_clip.left = dis->rcItem.left;
  2037. rt_clip.top = dis->rcItem.top;
  2038. rt_clip.right = dis->rcItem.left+pane->widths[col];
  2039. rt_clip.bottom = dis->rcItem.bottom;
  2040. hrgn = CreateRectRgnIndirect(&rt_clip);
  2041. if (!GetClipRgn(dis->hDC, hrgn_org)) {
  2042. DeleteObject(hrgn_org);
  2043. hrgn_org = 0;
  2044. }
  2045. ExtSelectClipRgn(dis->hDC, hrgn, RGN_AND);
  2046. DeleteObject(hrgn);
  2047. if ((up=entry->up) != NULL) {
  2048. MoveToEx(dis->hDC, img_pos-IMAGE_WIDTH/2, y, 0);
  2049. LineTo(dis->hDC, img_pos-2, y);
  2050. x = img_pos - IMAGE_WIDTH/2;
  2051. do {
  2052. x -= IMAGE_WIDTH+TREE_LINE_DX;
  2053. if (up->next
  2054. && (up->next->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
  2055. ) {
  2056. MoveToEx(dis->hDC, x, dis->rcItem.top, 0);
  2057. LineTo(dis->hDC, x, dis->rcItem.bottom);
  2058. }
  2059. } while((up=up->up) != NULL);
  2060. }
  2061. x = img_pos - IMAGE_WIDTH/2;
  2062. MoveToEx(dis->hDC, x, dis->rcItem.top, 0);
  2063. LineTo(dis->hDC, x, y);
  2064. if (entry->next
  2065. && (entry->next->data.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY))
  2066. LineTo(dis->hDC, x, dis->rcItem.bottom);
  2067. SelectClipRgn(dis->hDC, hrgn_org);
  2068. if (hrgn_org) DeleteObject(hrgn_org);
  2069. } else if (calcWidthCol==col || calcWidthCol==COLUMNS) {
  2070. int right = img_pos + IMAGE_WIDTH - TREE_LINE_DX;
  2071. if (right > pane->widths[col])
  2072. pane->widths[col] = right;
  2073. }
  2074. } else {
  2075. img_pos = dis->rcItem.left;
  2076. }
  2077. } else {
  2078. img_pos = dis->rcItem.left;
  2079. if (calcWidthCol==col || calcWidthCol==COLUMNS)
  2080. pane->widths[col] = IMAGE_WIDTH;
  2081. }
  2082. if (calcWidthCol == -1) {
  2083. focusRect.left = img_pos -2;
  2084. if (attrs & FILE_ATTRIBUTE_COMPRESSED)
  2085. textcolor = COLOR_COMPRESSED;
  2086. else
  2087. textcolor = RGB(0,0,0);
  2088. if (dis->itemState & ODS_FOCUS) {
  2089. textcolor = RGB(255,255,255);
  2090. bkcolor = COLOR_SELECTION;
  2091. } else {
  2092. bkcolor = RGB(255,255,255);
  2093. }
  2094. hbrush = CreateSolidBrush(bkcolor);
  2095. FillRect(dis->hDC, &focusRect, hbrush);
  2096. DeleteObject(hbrush);
  2097. SetBkMode(dis->hDC, TRANSPARENT);
  2098. SetTextColor(dis->hDC, textcolor);
  2099. cx = pane->widths[col];
  2100. if (cx && img!=IMG_NONE) {
  2101. if (cx > IMAGE_WIDTH)
  2102. cx = IMAGE_WIDTH;
  2103. if (entry->hicon && entry->hicon!=(HICON)-1)
  2104. DrawIconEx(dis->hDC, img_pos, dis->rcItem.top, entry->hicon, cx, GetSystemMetrics(SM_CYSMICON), 0, 0, DI_NORMAL);
  2105. else
  2106. ImageList_DrawEx(Globals.himl, img, dis->hDC,
  2107. img_pos, dis->rcItem.top, cx,
  2108. IMAGE_HEIGHT, bkcolor, CLR_DEFAULT, ILD_NORMAL);
  2109. }
  2110. }
  2111. if (!entry)
  2112. return;
  2113. col++;
  2114. /* output file name */
  2115. if (calcWidthCol == -1)
  2116. output_text(pane, dis, col, entry->data.cFileName, 0);
  2117. else if (calcWidthCol==col || calcWidthCol==COLUMNS)
  2118. calc_width(pane, dis, col, entry->data.cFileName);
  2119. col++;
  2120. /* display file size */
  2121. if (visible_cols & COL_SIZE) {
  2122. format_longlong( buffer, ((ULONGLONG)entry->data.nFileSizeHigh << 32) | entry->data.nFileSizeLow );
  2123. if (calcWidthCol == -1)
  2124. output_number(pane, dis, col, buffer);
  2125. else if (calcWidthCol==col || calcWidthCol==COLUMNS)
  2126. calc_width(pane, dis, col, buffer);/*TODO: not ever time enough */
  2127. col++;
  2128. }
  2129. /* display file date */
  2130. if (visible_cols & (COL_DATE|COL_TIME)) {
  2131. format_date(&entry->data.ftCreationTime, buffer, visible_cols);
  2132. if (calcWidthCol == -1)
  2133. output_text(pane, dis, col, buffer, 0);
  2134. else if (calcWidthCol==col || calcWidthCol==COLUMNS)
  2135. calc_width(pane, dis, col, buffer);
  2136. col++;
  2137. format_date(&entry->data.ftLastAccessTime, buffer, visible_cols);
  2138. if (calcWidthCol == -1)
  2139. output_text(pane, dis, col, buffer, 0);
  2140. else if (calcWidthCol==col || calcWidthCol==COLUMNS)
  2141. calc_width(pane, dis, col, buffer);
  2142. col++;
  2143. format_date(&entry->data.ftLastWriteTime, buffer, visible_cols);
  2144. if (calcWidthCol == -1)
  2145. output_text(pane, dis, col, buffer, 0);
  2146. else if (calcWidthCol==col || calcWidthCol==COLUMNS)
  2147. calc_width(pane, dis, col, buffer);
  2148. col++;
  2149. }
  2150. if (entry->bhfi_valid) {
  2151. if (visible_cols & COL_INDEX) {
  2152. static const WCHAR fmtlow[] = {'%','X',0};
  2153. static const WCHAR fmthigh[] = {'%','X','%','0','8','X',0};
  2154. if (entry->bhfi.nFileIndexHigh)
  2155. wsprintfW(buffer, fmthigh,
  2156. entry->bhfi.nFileIndexHigh, entry->bhfi.nFileIndexLow );
  2157. else
  2158. wsprintfW(buffer, fmtlow, entry->bhfi.nFileIndexLow );
  2159. if (calcWidthCol == -1)
  2160. output_text(pane, dis, col, buffer, DT_RIGHT);
  2161. else if (calcWidthCol==col || calcWidthCol==COLUMNS)
  2162. calc_width(pane, dis, col, buffer);
  2163. col++;
  2164. }
  2165. if (visible_cols & COL_LINKS) {
  2166. wsprintfW(buffer, sNumFmt, entry->bhfi.nNumberOfLinks);
  2167. if (calcWidthCol == -1)
  2168. output_text(pane, dis, col, buffer, DT_CENTER);
  2169. else if (calcWidthCol==col || calcWidthCol==COLUMNS)
  2170. calc_width(pane, dis, col, buffer);
  2171. col++;
  2172. }
  2173. } else
  2174. col += 2;
  2175. /* show file attributes */
  2176. if (visible_cols & COL_ATTRIBUTES) {
  2177. static const WCHAR s11Tabs[] = {' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\t',' ','\0'};
  2178. lstrcpyW(buffer, s11Tabs);
  2179. if (attrs & FILE_ATTRIBUTE_NORMAL) buffer[ 0] = 'N';
  2180. else {
  2181. if (attrs & FILE_ATTRIBUTE_READONLY) buffer[ 2] = 'R';
  2182. if (attrs & FILE_ATTRIBUTE_HIDDEN) buffer[ 4] = 'H';
  2183. if (attrs & FILE_ATTRIBUTE_SYSTEM) buffer[ 6] = 'S';
  2184. if (attrs & FILE_ATTRIBUTE_ARCHIVE) buffer[ 8] = 'A';
  2185. if (attrs & FILE_ATTRIBUTE_COMPRESSED) buffer[10] = 'C';
  2186. if (attrs & FILE_ATTRIBUTE_DIRECTORY) buffer[12] = 'D';
  2187. if (attrs & FILE_ATTRIBUTE_ENCRYPTED) buffer[14] = 'E';
  2188. if (attrs & FILE_ATTRIBUTE_TEMPORARY) buffer[16] = 'T';
  2189. if (attrs & FILE_ATTRIBUTE_SPARSE_FILE) buffer[18] = 'P';
  2190. if (attrs & FILE_ATTRIBUTE_REPARSE_POINT) buffer[20] = 'Q';
  2191. if (attrs & FILE_ATTRIBUTE_OFFLINE) buffer[22] = 'O';
  2192. if (attrs & FILE_ATTRIBUTE_NOT_CONTENT_INDEXED) buffer[24] = 'X';
  2193. }
  2194. if (calcWidthCol == -1)
  2195. output_tabbed_text(pane, dis, col, buffer);
  2196. else if (calcWidthCol==col || calcWidthCol==COLUMNS)
  2197. calc_tabbed_width(pane, dis, col, buffer);
  2198. col++;
  2199. }
  2200. }
  2201. static void set_header(Pane* pane)
  2202. {
  2203. HDITEMW item;
  2204. int scroll_pos = GetScrollPos(pane->hwnd, SB_HORZ);
  2205. int i;
  2206. item.mask = HDI_WIDTH;
  2207. for (i = 0; i < COLUMNS; ++i) {
  2208. if (pane->positions[i] >= scroll_pos) {
  2209. item.cxy = pane->widths[i];
  2210. } else if (pane->positions[i+1] <= scroll_pos) {
  2211. item.cxy = 0;
  2212. } else {
  2213. item.cxy = pane->positions[i+1] - scroll_pos;
  2214. }
  2215. pane->widths_shown[i] = item.cxy;
  2216. SendMessageW(pane->hwndHeader, HDM_SETITEMW, i, (LPARAM)&item);
  2217. }
  2218. }
  2219. static LRESULT pane_notify(Pane* pane, NMHDR* pnmh)
  2220. {
  2221. switch(pnmh->code) {
  2222. case HDN_ITEMCHANGEDW: {
  2223. LPNMHEADERW phdn = (LPNMHEADERW)pnmh;
  2224. int idx = phdn->iItem;
  2225. int dx = phdn->pitem->cxy - pane->widths_shown[idx];
  2226. int i;
  2227. RECT clnt;
  2228. GetClientRect(pane->hwnd, &clnt);
  2229. pane->widths[idx] += dx;
  2230. pane->widths_shown[idx] += dx;
  2231. for(i=idx; ++i<=COLUMNS; )
  2232. pane->positions[i] += dx;
  2233. {
  2234. int scroll_pos = GetScrollPos(pane->hwnd, SB_HORZ);
  2235. RECT rt_scr;
  2236. RECT rt_clip;
  2237. rt_scr.left = pane->positions[idx+1]-scroll_pos;
  2238. rt_scr.top = 0;
  2239. rt_scr.right = clnt.right;
  2240. rt_scr.bottom = clnt.bottom;
  2241. rt_clip.left = pane->positions[idx]-scroll_pos;
  2242. rt_clip.top = 0;
  2243. rt_clip.right = clnt.right;
  2244. rt_clip.bottom = clnt.bottom;
  2245. if (rt_scr.left < 0) rt_scr.left = 0;
  2246. if (rt_clip.left < 0) rt_clip.left = 0;
  2247. ScrollWindowEx(pane->hwnd, dx, 0, &rt_scr, &rt_clip, 0, 0, SW_INVALIDATE);
  2248. rt_clip.right = pane->positions[idx+1];
  2249. RedrawWindow(pane->hwnd, &rt_clip, 0, RDW_INVALIDATE|RDW_UPDATENOW);
  2250. if (pnmh->code == HDN_ENDTRACKW) {
  2251. SendMessageW(pane->hwnd, LB_SETHORIZONTALEXTENT, pane->positions[COLUMNS], 0);
  2252. if (GetScrollPos(pane->hwnd, SB_HORZ) != scroll_pos)
  2253. set_header(pane);
  2254. }
  2255. }
  2256. return FALSE;
  2257. }
  2258. case HDN_DIVIDERDBLCLICKW: {
  2259. LPNMHEADERW phdn = (LPNMHEADERW)pnmh;
  2260. HDITEMW item;
  2261. calc_single_width(pane, phdn->iItem);
  2262. item.mask = HDI_WIDTH;
  2263. item.cxy = pane->widths[phdn->iItem];
  2264. SendMessageW(pane->hwndHeader, HDM_SETITEMW, phdn->iItem, (LPARAM)&item);
  2265. InvalidateRect(pane->hwnd, 0, TRUE);
  2266. break;}
  2267. }
  2268. return 0;
  2269. }
  2270. static void scan_entry(ChildWnd* child, Entry* entry, int idx, HWND hwnd)
  2271. {
  2272. WCHAR path[MAX_PATH];
  2273. HCURSOR old_cursor = SetCursor(LoadCursorW(0, (LPCWSTR)IDC_WAIT));
  2274. /* delete sub entries in left pane */
  2275. for(;;) {
  2276. LRESULT res = SendMessageW(child->left.hwnd, LB_GETITEMDATA, idx+1, 0);
  2277. Entry* sub = (Entry*) res;
  2278. if (res==LB_ERR || !sub || sub->level<=entry->level)
  2279. break;
  2280. SendMessageW(child->left.hwnd, LB_DELETESTRING, idx+1, 0);
  2281. }
  2282. /* empty right pane */
  2283. SendMessageW(child->right.hwnd, LB_RESETCONTENT, 0, 0);
  2284. /* release memory */
  2285. free_entries(entry);
  2286. /* read contents from disk */
  2287. if (entry->etype == ET_SHELL)
  2288. {
  2289. read_directory(entry, NULL, child->sortOrder, hwnd);
  2290. }
  2291. else
  2292. {
  2293. get_path(entry, path);
  2294. read_directory(entry, path, child->sortOrder, hwnd);
  2295. }
  2296. /* insert found entries in right pane */
  2297. insert_entries(&child->right, entry->down, child->filter_pattern, child->filter_flags, -1);
  2298. calc_widths(&child->right, FALSE);
  2299. set_header(&child->right);
  2300. child->header_wdths_ok = FALSE;
  2301. SetCursor(old_cursor);
  2302. }
  2303. /* expand a directory entry */
  2304. static BOOL expand_entry(ChildWnd* child, Entry* dir)
  2305. {
  2306. int idx;
  2307. Entry* p;
  2308. if (!dir || dir->expanded || !dir->down)
  2309. return FALSE;
  2310. p = dir->down;
  2311. if (p->data.cFileName[0]=='.' && p->data.cFileName[1]=='\0' && p->next) {
  2312. p = p->next;
  2313. if (p->data.cFileName[0]=='.' && p->data.cFileName[1]=='.' &&
  2314. p->data.cFileName[2]=='\0' && p->next)
  2315. p = p->next;
  2316. }
  2317. /* no subdirectories ? */
  2318. if (!(p->data.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY))
  2319. return FALSE;
  2320. idx = SendMessageW(child->left.hwnd, LB_FINDSTRING, 0, (LPARAM)dir);
  2321. dir->expanded = TRUE;
  2322. /* insert entries in left pane */
  2323. insert_entries(&child->left, p, NULL, TF_ALL, idx);
  2324. if (!child->header_wdths_ok) {
  2325. if (calc_widths(&child->left, FALSE)) {
  2326. set_header(&child->left);
  2327. child->header_wdths_ok = TRUE;
  2328. }
  2329. }
  2330. return TRUE;
  2331. }
  2332. static void collapse_entry(Pane* pane, Entry* dir)
  2333. {
  2334. int idx;
  2335. if (!dir) return;
  2336. idx = SendMessageW(pane->hwnd, LB_FINDSTRING, 0, (LPARAM)dir);
  2337. ShowWindow(pane->hwnd, SW_HIDE);
  2338. /* hide sub entries */
  2339. for(;;) {
  2340. LRESULT res = SendMessageW(pane->hwnd, LB_GETITEMDATA, idx+1, 0);
  2341. Entry* sub = (Entry*) res;
  2342. if (res==LB_ERR || !sub || sub->level<=dir->level)
  2343. break;
  2344. SendMessageW(pane->hwnd, LB_DELETESTRING, idx+1, 0);
  2345. }
  2346. dir->expanded = FALSE;
  2347. ShowWindow(pane->hwnd, SW_SHOW);
  2348. }
  2349. static void refresh_right_pane(ChildWnd* child)
  2350. {
  2351. SendMessageW(child->right.hwnd, LB_RESETCONTENT, 0, 0);
  2352. insert_entries(&child->right, child->right.root, child->filter_pattern, child->filter_flags, -1);
  2353. calc_widths(&child->right, FALSE);
  2354. set_header(&child->right);
  2355. }
  2356. static void set_curdir(ChildWnd* child, Entry* entry, int idx, HWND hwnd)
  2357. {
  2358. WCHAR path[MAX_PATH];
  2359. if (!entry)
  2360. return;
  2361. path[0] = '\0';
  2362. child->left.cur = entry;
  2363. child->right.root = entry->down? entry->down: entry;
  2364. child->right.cur = entry;
  2365. if (!entry->scanned)
  2366. scan_entry(child, entry, idx, hwnd);
  2367. else
  2368. refresh_right_pane(child);
  2369. get_path(entry, path);
  2370. lstrcpyW(child->path, path);
  2371. if (child->hwnd) /* only change window title, if the window already exists */
  2372. SetWindowTextW(child->hwnd, path);
  2373. if (path[0])
  2374. if (SetCurrentDirectoryW(path))
  2375. set_space_status();
  2376. }
  2377. static void refresh_child(ChildWnd* child)
  2378. {
  2379. WCHAR path[MAX_PATH], drv[_MAX_DRIVE+1];
  2380. Entry* entry;
  2381. int idx;
  2382. get_path(child->left.cur, path);
  2383. _wsplitpath(path, drv, NULL, NULL, NULL);
  2384. child->right.root = NULL;
  2385. scan_entry(child, &child->root.entry, 0, child->hwnd);
  2386. if (child->root.entry.etype == ET_SHELL)
  2387. {
  2388. LPITEMIDLIST local_pidl = get_path_pidl(path,child->hwnd);
  2389. if (local_pidl)
  2390. entry = read_tree(&child->root, NULL, local_pidl , drv, child->sortOrder, child->hwnd);
  2391. else
  2392. entry = NULL;
  2393. }
  2394. else
  2395. entry = read_tree(&child->root, path, NULL, drv, child->sortOrder, child->hwnd);
  2396. if (!entry)
  2397. entry = &child->root.entry;
  2398. insert_entries(&child->left, child->root.entry.down, NULL, TF_ALL, 0);
  2399. set_curdir(child, entry, 0, child->hwnd);
  2400. idx = SendMessageW(child->left.hwnd, LB_FINDSTRING, 0, (LPARAM)child->left.cur);
  2401. SendMessageW(child->left.hwnd, LB_SETCURSEL, idx, 0);
  2402. }
  2403. static void create_drive_bar(void)
  2404. {
  2405. TBBUTTON drivebarBtn = {0, 0, TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0};
  2406. WCHAR b1[BUFFER_LEN];
  2407. int btn = 1;
  2408. PWSTR p;
  2409. GetLogicalDriveStringsW(BUFFER_LEN, Globals.drives);
  2410. Globals.hdrivebar = CreateToolbarEx(Globals.hMainWnd, WS_CHILD|WS_VISIBLE|CCS_NOMOVEY|TBSTYLE_LIST,
  2411. IDW_DRIVEBAR, 2, Globals.hInstance, IDB_DRIVEBAR, &drivebarBtn,
  2412. 0, 16, 13, 16, 13, sizeof(TBBUTTON));
  2413. /* insert shell namespace button */
  2414. load_string(b1, ARRAY_SIZE(b1), IDS_SHELL);
  2415. b1[lstrlenW(b1)+1] = '\0';
  2416. SendMessageW(Globals.hdrivebar, TB_ADDSTRINGW, 0, (LPARAM)b1);
  2417. drivebarBtn.idCommand = ID_DRIVE_SHELL_NS;
  2418. SendMessageW(Globals.hdrivebar, TB_INSERTBUTTONW, btn++, (LPARAM)&drivebarBtn);
  2419. drivebarBtn.iString++;
  2420. /* register windows drive root strings */
  2421. SendMessageW(Globals.hdrivebar, TB_ADDSTRINGW, 0, (LPARAM)Globals.drives);
  2422. drivebarBtn.idCommand = ID_DRIVE_FIRST;
  2423. for(p=Globals.drives; *p; ) {
  2424. switch(GetDriveTypeW(p)) {
  2425. case DRIVE_REMOVABLE: drivebarBtn.iBitmap = 1; break;
  2426. case DRIVE_CDROM: drivebarBtn.iBitmap = 3; break;
  2427. case DRIVE_REMOTE: drivebarBtn.iBitmap = 4; break;
  2428. case DRIVE_RAMDISK: drivebarBtn.iBitmap = 5; break;
  2429. default:/*DRIVE_FIXED*/ drivebarBtn.iBitmap = 2;
  2430. }
  2431. SendMessageW(Globals.hdrivebar, TB_INSERTBUTTONW, btn++, (LPARAM)&drivebarBtn);
  2432. drivebarBtn.idCommand++;
  2433. drivebarBtn.iString++;
  2434. while(*p++);
  2435. }
  2436. }
  2437. static void refresh_drives(void)
  2438. {
  2439. RECT rect;
  2440. /* destroy drive bar */
  2441. DestroyWindow(Globals.hdrivebar);
  2442. Globals.hdrivebar = 0;
  2443. /* re-create drive bar */
  2444. create_drive_bar();
  2445. /* update window layout */
  2446. GetClientRect(Globals.hMainWnd, &rect);
  2447. SendMessageW(Globals.hMainWnd, WM_SIZE, 0, MAKELONG(rect.right, rect.bottom));
  2448. }
  2449. static BOOL launch_file(HWND hwnd, LPCWSTR cmd, UINT nCmdShow)
  2450. {
  2451. HINSTANCE hinst = ShellExecuteW(hwnd, NULL/*operation*/, cmd, NULL/*parameters*/, NULL/*dir*/, nCmdShow);
  2452. if (PtrToUlong(hinst) <= 32) {
  2453. display_error(hwnd, GetLastError());
  2454. return FALSE;
  2455. }
  2456. return TRUE;
  2457. }
  2458. static BOOL launch_entry(Entry* entry, HWND hwnd, UINT nCmdShow)
  2459. {
  2460. WCHAR cmd[MAX_PATH];
  2461. if (entry->etype == ET_SHELL) {
  2462. BOOL ret = TRUE;
  2463. SHELLEXECUTEINFOW shexinfo;
  2464. shexinfo.cbSize = sizeof(SHELLEXECUTEINFOW);
  2465. shexinfo.fMask = SEE_MASK_IDLIST;
  2466. shexinfo.hwnd = hwnd;
  2467. shexinfo.lpVerb = NULL;
  2468. shexinfo.lpFile = NULL;
  2469. shexinfo.lpParameters = NULL;
  2470. shexinfo.lpDirectory = NULL;
  2471. shexinfo.nShow = nCmdShow;
  2472. shexinfo.lpIDList = get_to_absolute_pidl(entry, hwnd);
  2473. if (!ShellExecuteExW(&shexinfo)) {
  2474. display_error(hwnd, GetLastError());
  2475. ret = FALSE;
  2476. }
  2477. if (shexinfo.lpIDList != entry->pidl)
  2478. IMalloc_Free(Globals.iMalloc, shexinfo.lpIDList);
  2479. return ret;
  2480. }
  2481. get_path(entry, cmd);
  2482. /* start program, open document... */
  2483. return launch_file(hwnd, cmd, nCmdShow);
  2484. }
  2485. static void activate_entry(ChildWnd* child, Pane* pane, HWND hwnd)
  2486. {
  2487. Entry* entry = pane->cur;
  2488. if (!entry)
  2489. return;
  2490. if (entry->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
  2491. int scanned_old = entry->scanned;
  2492. if (!scanned_old)
  2493. {
  2494. int idx = SendMessageW(child->left.hwnd, LB_GETCURSEL, 0, 0);
  2495. scan_entry(child, entry, idx, hwnd);
  2496. }
  2497. if (entry->data.cFileName[0]=='.' && entry->data.cFileName[1]=='\0')
  2498. return;
  2499. if (entry->data.cFileName[0]=='.' && entry->data.cFileName[1]=='.' && entry->data.cFileName[2]=='\0') {
  2500. entry = child->left.cur->up;
  2501. collapse_entry(&child->left, entry);
  2502. goto focus_entry;
  2503. } else if (entry->expanded)
  2504. collapse_entry(pane, child->left.cur);
  2505. else {
  2506. expand_entry(child, child->left.cur);
  2507. if (!pane->treePane) focus_entry: {
  2508. int idxstart = SendMessageW(child->left.hwnd, LB_GETCURSEL, 0, 0);
  2509. int idx = SendMessageW(child->left.hwnd, LB_FINDSTRING, idxstart, (LPARAM)entry);
  2510. SendMessageW(child->left.hwnd, LB_SETCURSEL, idx, 0);
  2511. set_curdir(child, entry, idx, hwnd);
  2512. }
  2513. }
  2514. if (!scanned_old) {
  2515. calc_widths(pane, FALSE);
  2516. set_header(pane);
  2517. }
  2518. } else {
  2519. if (GetKeyState(VK_MENU) < 0)
  2520. show_properties_dlg(entry, child->hwnd);
  2521. else
  2522. launch_entry(entry, child->hwnd, SW_SHOWNORMAL);
  2523. }
  2524. }
  2525. static BOOL pane_command(Pane* pane, UINT cmd)
  2526. {
  2527. switch(cmd) {
  2528. case ID_VIEW_NAME:
  2529. if (pane->visible_cols) {
  2530. pane->visible_cols = 0;
  2531. calc_widths(pane, TRUE);
  2532. set_header(pane);
  2533. InvalidateRect(pane->hwnd, 0, TRUE);
  2534. CheckMenuItem(Globals.hMenuView, ID_VIEW_NAME, MF_BYCOMMAND|MF_CHECKED);
  2535. CheckMenuItem(Globals.hMenuView, ID_VIEW_ALL_ATTRIBUTES, MF_BYCOMMAND);
  2536. }
  2537. break;
  2538. case ID_VIEW_ALL_ATTRIBUTES:
  2539. if (pane->visible_cols != COL_ALL) {
  2540. pane->visible_cols = COL_ALL;
  2541. calc_widths(pane, TRUE);
  2542. set_header(pane);
  2543. InvalidateRect(pane->hwnd, 0, TRUE);
  2544. CheckMenuItem(Globals.hMenuView, ID_VIEW_NAME, MF_BYCOMMAND);
  2545. CheckMenuItem(Globals.hMenuView, ID_VIEW_ALL_ATTRIBUTES, MF_BYCOMMAND|MF_CHECKED);
  2546. }
  2547. break;
  2548. case ID_PREFERRED_SIZES: {
  2549. calc_widths(pane, TRUE);
  2550. set_header(pane);
  2551. InvalidateRect(pane->hwnd, 0, TRUE);
  2552. break;}
  2553. /* TODO: more command ids... */
  2554. default:
  2555. return FALSE;
  2556. }
  2557. return TRUE;
  2558. }
  2559. static void set_sort_order(ChildWnd* child, SORT_ORDER sortOrder)
  2560. {
  2561. if (child->sortOrder != sortOrder) {
  2562. child->sortOrder = sortOrder;
  2563. refresh_child(child);
  2564. }
  2565. }
  2566. static void update_view_menu(ChildWnd* child)
  2567. {
  2568. CheckMenuItem(Globals.hMenuView, ID_VIEW_SORT_NAME, child->sortOrder==SORT_NAME? MF_CHECKED: MF_UNCHECKED);
  2569. CheckMenuItem(Globals.hMenuView, ID_VIEW_SORT_TYPE, child->sortOrder==SORT_EXT? MF_CHECKED: MF_UNCHECKED);
  2570. CheckMenuItem(Globals.hMenuView, ID_VIEW_SORT_SIZE, child->sortOrder==SORT_SIZE? MF_CHECKED: MF_UNCHECKED);
  2571. CheckMenuItem(Globals.hMenuView, ID_VIEW_SORT_DATE, child->sortOrder==SORT_DATE? MF_CHECKED: MF_UNCHECKED);
  2572. }
  2573. static BOOL is_directory(LPCWSTR target)
  2574. {
  2575. DWORD target_attr = GetFileAttributesW(target);
  2576. if (target_attr == INVALID_FILE_ATTRIBUTES)
  2577. return FALSE;
  2578. return (target_attr & FILE_ATTRIBUTE_DIRECTORY) != 0;
  2579. }
  2580. static BOOL prompt_target(Pane* pane, LPWSTR source, LPWSTR target)
  2581. {
  2582. WCHAR path[MAX_PATH];
  2583. int len;
  2584. get_path(pane->cur, path);
  2585. if (DialogBoxParamW(Globals.hInstance, MAKEINTRESOURCEW(IDD_SELECT_DESTINATION), pane->hwnd, DestinationDlgProc, (LPARAM)path) != IDOK)
  2586. return FALSE;
  2587. get_path(pane->cur, source);
  2588. /* convert relative targets to absolute paths */
  2589. if (path[0]!='/' && path[1]!=':') {
  2590. get_path(pane->cur->up, target);
  2591. len = lstrlenW(target);
  2592. if (target[len-1]!='\\' && target[len-1]!='/')
  2593. target[len++] = '/';
  2594. lstrcpyW(target+len, path);
  2595. } else
  2596. lstrcpyW(target, path);
  2597. /* If the target already exists as directory, create a new target below this. */
  2598. if (is_directory(path)) {
  2599. WCHAR fname[_MAX_FNAME], ext[_MAX_EXT];
  2600. static const WCHAR sAppend[] = {'%','s','/','%','s','%','s','\0'};
  2601. _wsplitpath(source, NULL, NULL, fname, ext);
  2602. wsprintfW(target, sAppend, path, fname, ext);
  2603. }
  2604. return TRUE;
  2605. }
  2606. static IContextMenu2* s_pctxmenu2 = NULL;
  2607. static IContextMenu3* s_pctxmenu3 = NULL;
  2608. static void CtxMenu_reset(void)
  2609. {
  2610. s_pctxmenu2 = NULL;
  2611. s_pctxmenu3 = NULL;
  2612. }
  2613. static IContextMenu* CtxMenu_query_interfaces(IContextMenu* pcm1)
  2614. {
  2615. IContextMenu* pcm = NULL;
  2616. CtxMenu_reset();
  2617. if (IContextMenu_QueryInterface(pcm1, &IID_IContextMenu3, (void**)&pcm) == NOERROR)
  2618. s_pctxmenu3 = (LPCONTEXTMENU3)pcm;
  2619. else if (IContextMenu_QueryInterface(pcm1, &IID_IContextMenu2, (void**)&pcm) == NOERROR)
  2620. s_pctxmenu2 = (LPCONTEXTMENU2)pcm;
  2621. if (pcm) {
  2622. IContextMenu_Release(pcm1);
  2623. return pcm;
  2624. } else
  2625. return pcm1;
  2626. }
  2627. static BOOL CtxMenu_HandleMenuMsg(UINT nmsg, WPARAM wparam, LPARAM lparam)
  2628. {
  2629. if (s_pctxmenu3) {
  2630. if (SUCCEEDED(IContextMenu3_HandleMenuMsg(s_pctxmenu3, nmsg, wparam, lparam)))
  2631. return TRUE;
  2632. }
  2633. if (s_pctxmenu2)
  2634. if (SUCCEEDED(IContextMenu2_HandleMenuMsg(s_pctxmenu2, nmsg, wparam, lparam)))
  2635. return TRUE;
  2636. return FALSE;
  2637. }
  2638. static HRESULT ShellFolderContextMenu(IShellFolder* shell_folder, HWND hwndParent, int cidl, LPCITEMIDLIST* apidl, int x, int y)
  2639. {
  2640. IContextMenu* pcm;
  2641. BOOL executed = FALSE;
  2642. HRESULT hr = IShellFolder_GetUIObjectOf(shell_folder, hwndParent, cidl, apidl, &IID_IContextMenu, NULL, (LPVOID*)&pcm);
  2643. if (SUCCEEDED(hr)) {
  2644. HMENU hmenu = CreatePopupMenu();
  2645. pcm = CtxMenu_query_interfaces(pcm);
  2646. if (hmenu) {
  2647. hr = IContextMenu_QueryContextMenu(pcm, hmenu, 0, FCIDM_SHVIEWFIRST, FCIDM_SHVIEWLAST, CMF_NORMAL);
  2648. if (SUCCEEDED(hr)) {
  2649. UINT idCmd = TrackPopupMenu(hmenu, TPM_LEFTALIGN|TPM_RETURNCMD|TPM_RIGHTBUTTON, x, y, 0, hwndParent, NULL);
  2650. CtxMenu_reset();
  2651. if (idCmd) {
  2652. CMINVOKECOMMANDINFO cmi;
  2653. cmi.cbSize = sizeof(CMINVOKECOMMANDINFO);
  2654. cmi.fMask = 0;
  2655. cmi.hwnd = hwndParent;
  2656. cmi.lpVerb = (LPCSTR)(INT_PTR)(idCmd - FCIDM_SHVIEWFIRST);
  2657. cmi.lpParameters = NULL;
  2658. cmi.lpDirectory = NULL;
  2659. cmi.nShow = SW_SHOWNORMAL;
  2660. cmi.dwHotKey = 0;
  2661. cmi.hIcon = 0;
  2662. hr = IContextMenu_InvokeCommand(pcm, &cmi);
  2663. executed = TRUE;
  2664. }
  2665. } else
  2666. CtxMenu_reset();
  2667. }
  2668. IContextMenu_Release(pcm);
  2669. }
  2670. return FAILED(hr)? hr: executed? S_OK: S_FALSE;
  2671. }
  2672. static LRESULT CALLBACK ChildWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
  2673. {
  2674. ChildWnd* child = (ChildWnd*)GetWindowLongPtrW(hwnd, GWLP_USERDATA);
  2675. assert(child);
  2676. switch(nmsg) {
  2677. case WM_DRAWITEM: {
  2678. LPDRAWITEMSTRUCT dis = (LPDRAWITEMSTRUCT)lparam;
  2679. Entry* entry = (Entry*) dis->itemData;
  2680. if (dis->CtlID == IDW_TREE_LEFT)
  2681. draw_item(&child->left, dis, entry, -1);
  2682. else if (dis->CtlID == IDW_TREE_RIGHT)
  2683. draw_item(&child->right, dis, entry, -1);
  2684. else
  2685. goto draw_menu_item;
  2686. return TRUE;}
  2687. case WM_CREATE:
  2688. InitChildWindow(child);
  2689. break;
  2690. case WM_NCDESTROY:
  2691. free_child_window(child);
  2692. SetWindowLongPtrW(hwnd, GWLP_USERDATA, 0);
  2693. break;
  2694. case WM_PAINT: {
  2695. PAINTSTRUCT ps;
  2696. HBRUSH lastBrush;
  2697. RECT rt;
  2698. GetClientRect(hwnd, &rt);
  2699. BeginPaint(hwnd, &ps);
  2700. rt.left = child->split_pos-SPLIT_WIDTH/2;
  2701. rt.right = child->split_pos+SPLIT_WIDTH/2+1;
  2702. lastBrush = SelectObject(ps.hdc, GetStockObject(COLOR_SPLITBAR));
  2703. Rectangle(ps.hdc, rt.left, rt.top-1, rt.right, rt.bottom+1);
  2704. SelectObject(ps.hdc, lastBrush);
  2705. EndPaint(hwnd, &ps);
  2706. break;}
  2707. case WM_SETCURSOR:
  2708. if (LOWORD(lparam) == HTCLIENT) {
  2709. POINT pt;
  2710. GetCursorPos(&pt);
  2711. ScreenToClient(hwnd, &pt);
  2712. if (pt.x>=child->split_pos-SPLIT_WIDTH/2 && pt.x<child->split_pos+SPLIT_WIDTH/2+1) {
  2713. SetCursor(LoadCursorW(0, (LPCWSTR)IDC_SIZEWE));
  2714. return TRUE;
  2715. }
  2716. }
  2717. goto def;
  2718. case WM_LBUTTONDOWN: {
  2719. RECT rt;
  2720. int x = (short)LOWORD(lparam);
  2721. GetClientRect(hwnd, &rt);
  2722. if (x>=child->split_pos-SPLIT_WIDTH/2 && x<child->split_pos+SPLIT_WIDTH/2+1) {
  2723. last_split = child->split_pos;
  2724. SetCapture(hwnd);
  2725. }
  2726. break;}
  2727. case WM_LBUTTONUP:
  2728. if (GetCapture() == hwnd)
  2729. ReleaseCapture();
  2730. break;
  2731. case WM_KEYDOWN:
  2732. if (wparam == VK_ESCAPE)
  2733. if (GetCapture() == hwnd) {
  2734. RECT rt;
  2735. child->split_pos = last_split;
  2736. GetClientRect(hwnd, &rt);
  2737. resize_tree(child, rt.right, rt.bottom);
  2738. last_split = -1;
  2739. ReleaseCapture();
  2740. SetCursor(LoadCursorW(0, (LPCWSTR)IDC_ARROW));
  2741. }
  2742. break;
  2743. case WM_MOUSEMOVE:
  2744. if (GetCapture() == hwnd) {
  2745. RECT rt;
  2746. int x = (short)LOWORD(lparam);
  2747. GetClientRect(hwnd, &rt);
  2748. if (x>=0 && x<rt.right) {
  2749. child->split_pos = x;
  2750. resize_tree(child, rt.right, rt.bottom);
  2751. rt.left = x-SPLIT_WIDTH/2;
  2752. rt.right = x+SPLIT_WIDTH/2+1;
  2753. InvalidateRect(hwnd, &rt, FALSE);
  2754. UpdateWindow(child->left.hwnd);
  2755. UpdateWindow(hwnd);
  2756. UpdateWindow(child->right.hwnd);
  2757. }
  2758. }
  2759. break;
  2760. case WM_GETMINMAXINFO:
  2761. DefMDIChildProcW(hwnd, nmsg, wparam, lparam);
  2762. {LPMINMAXINFO lpmmi = (LPMINMAXINFO)lparam;
  2763. lpmmi->ptMaxTrackSize.x <<= 1;/*2*GetSystemMetrics(SM_CXSCREEN) / SM_CXVIRTUALSCREEN */
  2764. lpmmi->ptMaxTrackSize.y <<= 1;/*2*GetSystemMetrics(SM_CYSCREEN) / SM_CYVIRTUALSCREEN */
  2765. break;}
  2766. case WM_SETFOCUS:
  2767. if (SetCurrentDirectoryW(child->path))
  2768. set_space_status();
  2769. SetFocus(child->focus_pane? child->right.hwnd: child->left.hwnd);
  2770. break;
  2771. case WM_DISPATCH_COMMAND: {
  2772. Pane* pane = GetFocus()==child->left.hwnd? &child->left: &child->right;
  2773. switch(LOWORD(wparam)) {
  2774. case ID_WINDOW_NEW: {
  2775. ChildWnd* new_child = alloc_child_window(child->path, NULL, hwnd);
  2776. if (!create_child_window(new_child))
  2777. HeapFree(GetProcessHeap(), 0, new_child);
  2778. break;}
  2779. case ID_REFRESH:
  2780. refresh_drives();
  2781. refresh_child(child);
  2782. break;
  2783. case ID_ACTIVATE:
  2784. activate_entry(child, pane, hwnd);
  2785. break;
  2786. case ID_FILE_MOVE: {
  2787. WCHAR source[BUFFER_LEN], target[BUFFER_LEN];
  2788. if (prompt_target(pane, source, target)) {
  2789. SHFILEOPSTRUCTW shfo = {hwnd, FO_MOVE, source, target};
  2790. source[lstrlenW(source)+1] = '\0';
  2791. target[lstrlenW(target)+1] = '\0';
  2792. if (!SHFileOperationW(&shfo))
  2793. refresh_child(child);
  2794. }
  2795. break;}
  2796. case ID_FILE_COPY: {
  2797. WCHAR source[BUFFER_LEN], target[BUFFER_LEN];
  2798. if (prompt_target(pane, source, target)) {
  2799. SHFILEOPSTRUCTW shfo = {hwnd, FO_COPY, source, target};
  2800. source[lstrlenW(source)+1] = '\0';
  2801. target[lstrlenW(target)+1] = '\0';
  2802. if (!SHFileOperationW(&shfo))
  2803. refresh_child(child);
  2804. }
  2805. break;}
  2806. case ID_FILE_DELETE: {
  2807. WCHAR path[BUFFER_LEN];
  2808. SHFILEOPSTRUCTW shfo = {hwnd, FO_DELETE, path, NULL, FOF_ALLOWUNDO};
  2809. get_path(pane->cur, path);
  2810. path[lstrlenW(path)+1] = '\0';
  2811. if (!SHFileOperationW(&shfo))
  2812. refresh_child(child);
  2813. break;}
  2814. case ID_VIEW_SORT_NAME:
  2815. set_sort_order(child, SORT_NAME);
  2816. break;
  2817. case ID_VIEW_SORT_TYPE:
  2818. set_sort_order(child, SORT_EXT);
  2819. break;
  2820. case ID_VIEW_SORT_SIZE:
  2821. set_sort_order(child, SORT_SIZE);
  2822. break;
  2823. case ID_VIEW_SORT_DATE:
  2824. set_sort_order(child, SORT_DATE);
  2825. break;
  2826. case ID_VIEW_FILTER: {
  2827. struct FilterDialog dlg;
  2828. memset(&dlg, 0, sizeof(struct FilterDialog));
  2829. lstrcpyW(dlg.pattern, child->filter_pattern);
  2830. dlg.flags = child->filter_flags;
  2831. if (DialogBoxParamW(Globals.hInstance, MAKEINTRESOURCEW(IDD_DIALOG_VIEW_TYPE), hwnd, FilterDialogDlgProc, (LPARAM)&dlg) == IDOK) {
  2832. lstrcpyW(child->filter_pattern, dlg.pattern);
  2833. child->filter_flags = dlg.flags;
  2834. refresh_right_pane(child);
  2835. }
  2836. break;}
  2837. case ID_VIEW_SPLIT: {
  2838. last_split = child->split_pos;
  2839. SetCapture(hwnd);
  2840. break;}
  2841. case ID_EDIT_PROPERTIES:
  2842. show_properties_dlg(pane->cur, child->hwnd);
  2843. break;
  2844. default:
  2845. return pane_command(pane, LOWORD(wparam));
  2846. }
  2847. return TRUE;}
  2848. case WM_COMMAND: {
  2849. Pane* pane = GetFocus()==child->left.hwnd? &child->left: &child->right;
  2850. switch(HIWORD(wparam)) {
  2851. case LBN_SELCHANGE: {
  2852. int idx = SendMessageW(pane->hwnd, LB_GETCURSEL, 0, 0);
  2853. Entry* entry = (Entry*)SendMessageW(pane->hwnd, LB_GETITEMDATA, idx, 0);
  2854. if (pane == &child->left)
  2855. set_curdir(child, entry, idx, hwnd);
  2856. else
  2857. pane->cur = entry;
  2858. break;}
  2859. case LBN_DBLCLK:
  2860. activate_entry(child, pane, hwnd);
  2861. break;
  2862. }
  2863. break;}
  2864. case WM_NOTIFY: {
  2865. NMHDR* pnmh = (NMHDR*) lparam;
  2866. return pane_notify(pnmh->idFrom==IDW_HEADER_LEFT? &child->left: &child->right, pnmh);}
  2867. case WM_CONTEXTMENU: {
  2868. POINT pt, pt_clnt;
  2869. Pane* pane;
  2870. int idx;
  2871. /* first select the current item in the listbox */
  2872. HWND hpanel = (HWND) wparam;
  2873. pt_clnt.x = pt.x = (short)LOWORD(lparam);
  2874. pt_clnt.y = pt.y = (short)HIWORD(lparam);
  2875. ScreenToClient(hpanel, &pt_clnt);
  2876. SendMessageW(hpanel, WM_LBUTTONDOWN, 0, MAKELONG(pt_clnt.x, pt_clnt.y));
  2877. SendMessageW(hpanel, WM_LBUTTONUP, 0, MAKELONG(pt_clnt.x, pt_clnt.y));
  2878. /* now create the popup menu using shell namespace and IContextMenu */
  2879. pane = GetFocus()==child->left.hwnd? &child->left: &child->right;
  2880. idx = SendMessageW(pane->hwnd, LB_GETCURSEL, 0, 0);
  2881. if (idx != -1) {
  2882. Entry* entry = (Entry*)SendMessageW(pane->hwnd, LB_GETITEMDATA, idx, 0);
  2883. LPITEMIDLIST pidl_abs = get_to_absolute_pidl(entry, hwnd);
  2884. if (pidl_abs) {
  2885. IShellFolder* parentFolder;
  2886. LPCITEMIDLIST pidlLast;
  2887. /* get and use the parent folder to display correct context menu in all cases */
  2888. if (SUCCEEDED(SHBindToParent(pidl_abs, &IID_IShellFolder, (LPVOID*)&parentFolder, &pidlLast))) {
  2889. if (ShellFolderContextMenu(parentFolder, hwnd, 1, &pidlLast, pt.x, pt.y) == S_OK)
  2890. refresh_child(child);
  2891. IShellFolder_Release(parentFolder);
  2892. }
  2893. IMalloc_Free(Globals.iMalloc, pidl_abs);
  2894. }
  2895. }
  2896. break;}
  2897. case WM_MEASUREITEM:
  2898. draw_menu_item:
  2899. if (!wparam) /* Is the message menu-related? */
  2900. if (CtxMenu_HandleMenuMsg(nmsg, wparam, lparam))
  2901. return TRUE;
  2902. break;
  2903. case WM_INITMENUPOPUP:
  2904. if (CtxMenu_HandleMenuMsg(nmsg, wparam, lparam))
  2905. return 0;
  2906. update_view_menu(child);
  2907. break;
  2908. case WM_MENUCHAR: /* only supported by IContextMenu3 */
  2909. if (s_pctxmenu3) {
  2910. LRESULT lResult = 0;
  2911. IContextMenu3_HandleMenuMsg2(s_pctxmenu3, nmsg, wparam, lparam, &lResult);
  2912. return lResult;
  2913. }
  2914. break;
  2915. case WM_SIZE:
  2916. if (wparam != SIZE_MINIMIZED)
  2917. resize_tree(child, LOWORD(lparam), HIWORD(lparam));
  2918. /* fall through */
  2919. default: def:
  2920. return DefMDIChildProcW(hwnd, nmsg, wparam, lparam);
  2921. }
  2922. return 0;
  2923. }
  2924. static LRESULT CALLBACK TreeWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam)
  2925. {
  2926. ChildWnd* child = (ChildWnd*)GetWindowLongPtrW(GetParent(hwnd), GWLP_USERDATA);
  2927. Pane* pane = (Pane*)GetWindowLongPtrW(hwnd, GWLP_USERDATA);
  2928. assert(child);
  2929. switch(nmsg) {
  2930. case WM_HSCROLL:
  2931. set_header(pane);
  2932. break;
  2933. case WM_SETFOCUS:
  2934. child->focus_pane = pane==&child->right? 1: 0;
  2935. SendMessageW(hwnd, LB_SETSEL, TRUE, 1);
  2936. /*TODO: check menu items */
  2937. break;
  2938. case WM_KEYDOWN:
  2939. if (wparam == VK_TAB) {
  2940. /*TODO: SetFocus(Globals.hdrivebar) */
  2941. SetFocus(child->focus_pane? child->left.hwnd: child->right.hwnd);
  2942. }
  2943. }
  2944. return CallWindowProcW(g_orgTreeWndProc, hwnd, nmsg, wparam, lparam);
  2945. }
  2946. static void InitInstance(HINSTANCE hinstance)
  2947. {
  2948. static const WCHAR sFont[] = {'M','i','c','r','o','s','o','f','t',' ','S','a','n','s',' ','S','e','r','i','f','\0'};
  2949. WNDCLASSEXW wcFrame;
  2950. WNDCLASSW wcChild;
  2951. int col;
  2952. INITCOMMONCONTROLSEX icc = {
  2953. sizeof(INITCOMMONCONTROLSEX),
  2954. ICC_BAR_CLASSES
  2955. };
  2956. HDC hdc = GetDC(0);
  2957. setlocale(LC_COLLATE, ""); /* set collating rules to local settings for compareName */
  2958. InitCommonControlsEx(&icc);
  2959. /* register frame window class */
  2960. wcFrame.cbSize = sizeof(WNDCLASSEXW);
  2961. wcFrame.style = 0;
  2962. wcFrame.lpfnWndProc = FrameWndProc;
  2963. wcFrame.cbClsExtra = 0;
  2964. wcFrame.cbWndExtra = 0;
  2965. wcFrame.hInstance = hinstance;
  2966. wcFrame.hIcon = LoadIconW(hinstance, MAKEINTRESOURCEW(IDI_WINEFILE));
  2967. wcFrame.hCursor = LoadCursorW(0, (LPCWSTR)IDC_ARROW);
  2968. wcFrame.hbrBackground = 0;
  2969. wcFrame.lpszMenuName = 0;
  2970. wcFrame.lpszClassName = sWINEFILEFRAME;
  2971. wcFrame.hIconSm = LoadImageW(hinstance, MAKEINTRESOURCEW(IDI_WINEFILE), IMAGE_ICON, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_SHARED);
  2972. Globals.hframeClass = RegisterClassExW(&wcFrame);
  2973. /* register tree windows class */
  2974. wcChild.style = CS_CLASSDC|CS_DBLCLKS|CS_VREDRAW;
  2975. wcChild.lpfnWndProc = ChildWndProc;
  2976. wcChild.cbClsExtra = 0;
  2977. wcChild.cbWndExtra = 0;
  2978. wcChild.hInstance = hinstance;
  2979. wcChild.hIcon = LoadIconW(hinstance, MAKEINTRESOURCEW(IDI_WINEFILE));
  2980. wcChild.hCursor = LoadCursorW(0, (LPCWSTR)IDC_ARROW);
  2981. wcChild.hbrBackground = 0;
  2982. wcChild.lpszMenuName = 0;
  2983. wcChild.lpszClassName = sWINEFILETREE;
  2984. RegisterClassW(&wcChild);
  2985. Globals.haccel = LoadAcceleratorsW(hinstance, MAKEINTRESOURCEW(IDA_WINEFILE));
  2986. Globals.hfont = CreateFontW(-MulDiv(8,GetDeviceCaps(hdc,LOGPIXELSY),72), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, sFont);
  2987. ReleaseDC(0, hdc);
  2988. Globals.hInstance = hinstance;
  2989. CoInitialize(NULL);
  2990. CoGetMalloc(MEMCTX_TASK, &Globals.iMalloc);
  2991. SHGetDesktopFolder(&Globals.iDesktop);
  2992. Globals.cfStrFName = RegisterClipboardFormatW(CFSTR_FILENAMEW);
  2993. /* load column strings */
  2994. col = 1;
  2995. load_string(g_pos_names[col++], ARRAY_SIZE(g_pos_names[col]), IDS_COL_NAME);
  2996. load_string(g_pos_names[col++], ARRAY_SIZE(g_pos_names[col]), IDS_COL_SIZE);
  2997. load_string(g_pos_names[col++], ARRAY_SIZE(g_pos_names[col]), IDS_COL_CDATE);
  2998. load_string(g_pos_names[col++], ARRAY_SIZE(g_pos_names[col]), IDS_COL_ADATE);
  2999. load_string(g_pos_names[col++], ARRAY_SIZE(g_pos_names[col]), IDS_COL_MDATE);
  3000. load_string(g_pos_names[col++], ARRAY_SIZE(g_pos_names[col]), IDS_COL_IDX);
  3001. load_string(g_pos_names[col++], ARRAY_SIZE(g_pos_names[col]), IDS_COL_LINKS);
  3002. load_string(g_pos_names[col++], ARRAY_SIZE(g_pos_names[col]), IDS_COL_ATTR);
  3003. load_string(g_pos_names[col++], ARRAY_SIZE(g_pos_names[col]), IDS_COL_SEC);
  3004. }
  3005. static BOOL show_frame(HWND hwndParent, int cmdshow, LPWSTR path)
  3006. {
  3007. static const WCHAR sMDICLIENT[] = {'M','D','I','C','L','I','E','N','T','\0'};
  3008. WCHAR buffer[MAX_PATH], b1[BUFFER_LEN];
  3009. ChildWnd* child;
  3010. HMENU hMenuFrame, hMenuWindow;
  3011. windowOptions opts;
  3012. CLIENTCREATESTRUCT ccs;
  3013. if (Globals.hMainWnd)
  3014. return TRUE;
  3015. opts = load_registry_settings();
  3016. hMenuFrame = LoadMenuW(Globals.hInstance, MAKEINTRESOURCEW(IDM_WINEFILE));
  3017. hMenuWindow = GetSubMenu(hMenuFrame, GetMenuItemCount(hMenuFrame)-2);
  3018. Globals.hMenuFrame = hMenuFrame;
  3019. Globals.hMenuView = GetSubMenu(hMenuFrame, 2);
  3020. Globals.hMenuOptions = GetSubMenu(hMenuFrame, 3);
  3021. ccs.hWindowMenu = hMenuWindow;
  3022. ccs.idFirstChild = IDW_FIRST_CHILD;
  3023. /* create main window */
  3024. Globals.hMainWnd = CreateWindowExW(0, MAKEINTRESOURCEW(Globals.hframeClass), RS(b1,IDS_WINEFILE), WS_OVERLAPPEDWINDOW,
  3025. opts.start_x, opts.start_y, opts.width, opts.height,
  3026. hwndParent, Globals.hMenuFrame, Globals.hInstance, 0/*lpParam*/);
  3027. Globals.hmdiclient = CreateWindowExW(0, sMDICLIENT, NULL,
  3028. WS_CHILD|WS_CLIPCHILDREN|WS_VSCROLL|WS_HSCROLL|WS_VISIBLE|WS_BORDER,
  3029. 0, 0, 0, 0,
  3030. Globals.hMainWnd, 0, Globals.hInstance, &ccs);
  3031. CheckMenuItem(Globals.hMenuOptions, ID_VIEW_DRIVE_BAR, MF_BYCOMMAND|MF_CHECKED);
  3032. CheckMenuItem(Globals.hMenuOptions, ID_VIEW_SAVESETTINGS, MF_BYCOMMAND);
  3033. create_drive_bar();
  3034. {
  3035. TBBUTTON toolbarBtns[] = {
  3036. {0, 0, 0, BTNS_SEP, {0, 0}, 0, 0},
  3037. {0, ID_WINDOW_NEW, TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
  3038. {1, ID_WINDOW_CASCADE, TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
  3039. {2, ID_WINDOW_TILE_HORZ, TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
  3040. {3, ID_WINDOW_TILE_VERT, TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0},
  3041. };
  3042. Globals.htoolbar = CreateToolbarEx(Globals.hMainWnd, WS_CHILD|WS_VISIBLE,
  3043. IDW_TOOLBAR, 2, Globals.hInstance, IDB_TOOLBAR, toolbarBtns,
  3044. ARRAY_SIZE(toolbarBtns), 16, 15, 16, 15, sizeof(TBBUTTON));
  3045. CheckMenuItem(Globals.hMenuOptions, ID_VIEW_TOOL_BAR, MF_BYCOMMAND|MF_CHECKED);
  3046. }
  3047. Globals.hstatusbar = CreateStatusWindowW(WS_CHILD|WS_VISIBLE, 0, Globals.hMainWnd, IDW_STATUSBAR);
  3048. CheckMenuItem(Globals.hMenuOptions, ID_VIEW_STATUSBAR, MF_BYCOMMAND|MF_CHECKED);
  3049. /*TODO: read paths from registry */
  3050. if (!path || !*path) {
  3051. GetCurrentDirectoryW(MAX_PATH, buffer);
  3052. path = buffer;
  3053. }
  3054. ShowWindow(Globals.hMainWnd, cmdshow);
  3055. /* Shell Namespace as default: */
  3056. child = alloc_child_window(path, get_path_pidl(path,Globals.hMainWnd), Globals.hMainWnd);
  3057. child->pos.showCmd = SW_SHOWMAXIMIZED;
  3058. child->pos.rcNormalPosition.left = 0;
  3059. child->pos.rcNormalPosition.top = 0;
  3060. child->pos.rcNormalPosition.right = 320;
  3061. child->pos.rcNormalPosition.bottom = 280;
  3062. if (!create_child_window(child)) {
  3063. HeapFree(GetProcessHeap(), 0, child);
  3064. return FALSE;
  3065. }
  3066. SetWindowPlacement(child->hwnd, &child->pos);
  3067. Globals.himl = ImageList_LoadImageW(Globals.hInstance, MAKEINTRESOURCEW(IDB_IMAGES), 16, 0, RGB(0,255,0), IMAGE_BITMAP, 0);
  3068. Globals.prescan_node = FALSE;
  3069. UpdateWindow(Globals.hMainWnd);
  3070. if (child->hwnd && path && path[0])
  3071. {
  3072. int index,count;
  3073. WCHAR drv[_MAX_DRIVE+1], dir[_MAX_DIR], name[_MAX_FNAME], ext[_MAX_EXT];
  3074. WCHAR fullname[_MAX_FNAME+_MAX_EXT+1];
  3075. memset(name,0,sizeof(name));
  3076. memset(name,0,sizeof(ext));
  3077. _wsplitpath(path, drv, dir, name, ext);
  3078. if (name[0])
  3079. {
  3080. count = SendMessageW(child->right.hwnd, LB_GETCOUNT, 0, 0);
  3081. lstrcpyW(fullname,name);
  3082. lstrcatW(fullname,ext);
  3083. for (index = 0; index < count; index ++)
  3084. {
  3085. Entry* entry = (Entry*)SendMessageW(child->right.hwnd, LB_GETITEMDATA, index, 0);
  3086. if (lstrcmpW(entry->data.cFileName,fullname)==0 ||
  3087. lstrcmpW(entry->data.cAlternateFileName,fullname)==0)
  3088. {
  3089. SendMessageW(child->right.hwnd, LB_SETCURSEL, index, 0);
  3090. SetFocus(child->right.hwnd);
  3091. break;
  3092. }
  3093. }
  3094. }
  3095. }
  3096. return TRUE;
  3097. }
  3098. static void ExitInstance(void)
  3099. {
  3100. IShellFolder_Release(Globals.iDesktop);
  3101. IMalloc_Release(Globals.iMalloc);
  3102. CoUninitialize();
  3103. DeleteObject(Globals.hfont);
  3104. ImageList_Destroy(Globals.himl);
  3105. }
  3106. int APIENTRY wWinMain(HINSTANCE hinstance, HINSTANCE previnstance, LPWSTR cmdline, int cmdshow)
  3107. {
  3108. MSG msg;
  3109. InitInstance(hinstance);
  3110. if( !show_frame(0, cmdshow, cmdline) )
  3111. {
  3112. ExitInstance();
  3113. return 1;
  3114. }
  3115. while(GetMessageW(&msg, 0, 0, 0)) {
  3116. if (Globals.hmdiclient && TranslateMDISysAccel(Globals.hmdiclient, &msg))
  3117. continue;
  3118. if (Globals.hMainWnd && TranslateAcceleratorW(Globals.hMainWnd, Globals.haccel, &msg))
  3119. continue;
  3120. TranslateMessage(&msg);
  3121. DispatchMessageW(&msg);
  3122. }
  3123. ExitInstance();
  3124. return msg.wParam;
  3125. }