main.cpp 107 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527
  1. #include "precomp__gen_ff.h"
  2. #include <windows.h>
  3. #include <commctrl.h>
  4. #include "main.h"
  5. #include "resource.h"
  6. #include "prefs.h"
  7. #include "wa2frontend.h"
  8. #include "wa2groupdefs.h"
  9. #include "wa2wndembed.h"
  10. #include "wa2cfgitems.h"
  11. #include "wa2coreactions.h"
  12. #include "wa2pledit.h"
  13. #include "embedwndguid.h"
  14. #include "gen_ff_ipc.h"
  15. #include "fsmonitor.h"
  16. #include <api/wnd/wndclass/foreignwnd.h>
  17. #include "../winamp/wa_ipc.h"
  18. #include "../gen_hotkeys/wa_hotkeys.h"
  19. #include <api/script/objects/c_script/c_group.h>
  20. #include <api/script/objects/c_script/c_text.h>
  21. #include <api/apiinit.h>
  22. #include <api/wnd/rootwnd.h>
  23. #include <api/script/objects/guiobject.h>
  24. #include <api/core/coreactions.h>
  25. #include "menuactions.h"
  26. #include <api/wnd/wndclass/oswndhost.h>
  27. #include <api/script/scriptobj.h>
  28. #include <api/service/svcs/svc_wndcreate.h>
  29. #include <bfc/reentryfilter.h>
  30. #include <api/skin/skinparse.h>
  31. #include <api/wndmgr/skinembed.h>
  32. #include <api/skin/widgets/xuiwndholder.h>
  33. #include <api/skin/widgets/text.h>
  34. #include <api/script/scriptmgr.h>
  35. #include <api/wac/compon.h>
  36. #include <api/application/version.h>
  37. #include <bfc/parse/pathparse.h>
  38. #include <tataki/blending/blending.h>
  39. #include "skininfo.h"
  40. #include <api/skin/guitree.h>
  41. #include <bfc/wasabi_std_wnd.h>
  42. #include "wa2core.h"
  43. #include <api/locales/xlatstr.h>
  44. #include <api/wndmgr/gc.h>
  45. #include <api/syscb/callbacks/gccb.h>
  46. #include <api/script/vcpu.h>
  47. #include <tataki/canvas/bltcanvas.h>
  48. #include "../nu/AutoWide.h"
  49. #include <shlwapi.h>
  50. #include <windowsx.h>
  51. //wtf?
  52. #define _WAFE_H_
  53. #define ___HOTAMP3_H___
  54. #include "../gen_hotkeys/hotkey.h"
  55. int embedCreateProc(embedWindowState *p, embedEnumStruct *parms);
  56. DECLARE_MODULE_SVCMGR;
  57. #define VERSION L"1.55"
  58. //#define VIDDEBUG
  59. //#define DEBUG_CAPTURES
  60. #include "../gen_ml/ml_ipc.h"
  61. librarySendToMenuStruct mainSendTo;
  62. #include "../Agave/Language/api_language.h"
  63. // wasabi based services for localisation support
  64. api_language *WASABI_API_LNG = 0;
  65. HINSTANCE WASABI_API_LNG_HINST = 0, WASABI_API_ORIG_HINST;
  66. static wchar_t szDescription[256];
  67. //-----------------------------------------------------------------------------------------------
  68. #define GET_X_LPARAM(lp) ((int)(short)LOWORD(lp))
  69. #define GET_Y_LPARAM(lp) ((int)(short)HIWORD(lp))
  70. #define ID_FILE_SHOWLIBRARY 40379
  71. #define WINAMP_OPTIONS_PREFS 40012
  72. #define WINAMP_HELP_ABOUT 40041
  73. #define WINAMP_LIGHTNING_CLICK 40339
  74. #define WINAMP
  75. #define UPDATE_EGG 0xC0DE+2
  76. #define VIEWPORT 0xC0DE+3
  77. static int DEFERREDCALLBACKMSG;
  78. static int UPDATEDIALOGBOXPARENTMSG;
  79. //-----------------------------------------------------------------------------------------------
  80. void config();
  81. void quit();
  82. int init();
  83. void quit_inst();
  84. void init_inst();
  85. void ToggleLayout(const wchar_t *containerName);
  86. void RestoreClassicWinamp(int was_loaded);
  87. extern "C" winampGeneralPurposePlugin plugin =
  88. {
  89. GPPHDR_VER_U,
  90. "nullsoft(gen_ff.dll)",
  91. init,
  92. config,
  93. quit,
  94. };
  95. //-----------------------------------------------------------------------------------------------
  96. int wantContainerInMenu(Container *cont)
  97. {
  98. wchar_t tmpBuf[96] = {0};
  99. GUID g = cont->getGUID();
  100. if (WCSCASEEQLSAFE(cont->getId(), L"main")) return 0;
  101. if (cont->getNoMenu()) return 0;
  102. if (g == pleditWndGuid) return 0;
  103. if (g == videoWndGuid) return 0;
  104. if (g == avs_guid) return 0;
  105. if (g == library_guid) return 0;
  106. if (WCSCASEEQLSAFE(cont->getName(), L":componenttitle")) return 0;
  107. if (WCSCASEEQLSAFE(cont->getName(), L"Playlist Editor") || WCSCASEEQLSAFE(cont->getName(), L"Playlist") || WCSCASEEQLSAFE(cont->getId(), L"pledit")) return 0;
  108. if (WCSCASEEQLSAFE(cont->getName(), L"Video Window") || WCSCASEEQLSAFE(cont->getName(), L"Video") || WCSCASEEQLSAFE(cont->getId(), L"Video")) return 0;
  109. if (WCSCASEEQLSAFE(cont->getName(), WASABI_API_LNG->GetStringFromGUIDW(GenMlLangGUID,plugin.hDllInstance,18)) ||
  110. WCSCASEEQLSAFE(cont->getName(), L"Media Library") ||
  111. WCSCASEEQLSAFE(cont->getId(), L"Library") ||
  112. WCSCASEEQLSAFE(cont->getName(),WASABI_API_LNGSTRINGW_BUF(IDS_MEDIA_LIBRARY,tmpBuf,96))) return 0;
  113. if (WCSCASEEQLSAFE(cont->getName(), L"AVS") || WCSCASEEQLSAFE(cont->getName(), WASABI_API_LNGSTRINGW(IDS_VISUALIZATIONS)) || WCSCASEEQLSAFE(cont->getName(), L"Vis") || WCSCASEEQLSAFE(cont->getId(), L"Avs") || WCSCASEEQLSAFE(cont->getId(), L"Vis")) return 0;
  114. return 1;
  115. }
  116. //-----------------------------------------------------------------------------------------------
  117. api_playlists *AGAVE_API_PLAYLISTS = 0;
  118. api_playlistmanager *AGAVE_API_PLAYLISTMANAGER = 0;
  119. api_albumart *AGAVE_API_ALBUMART = 0;
  120. api_downloadManager *WAC_API_DOWNLOADMANAGER = 0;
  121. api_colorthemes *WASABI_API_COLORTHEMES = 0;
  122. api_palette *WASABI_API_PALETTE = 0;
  123. api_threadpool *WASABI_API_THREADPOOL = 0;
  124. StringW m_lastskin_nam, m_lastskin_dir;
  125. inline int lumidiff(int a, int b) {
  126. int r1 = (a & 0xFF0000) >> 16;
  127. int r2 = (b & 0xFF0000) >> 16;
  128. int g1 = (a & 0xFF00) >> 8;
  129. int g2 = (b & 0xFF00) >> 8;
  130. int b1 = a & 0xFF;
  131. int b2 = b & 0xFF;
  132. return MIN((ABS(r1 - r2), ABS(g1 - g2)), ABS(b1 - b2));
  133. }
  134. static void doplaylistcolors()
  135. {
  136. int interpolate = 0;
  137. if (SkinParser::getSkinVersion()*10 < 10) interpolate = 1;
  138. // update colors
  139. int buf[6] = {0};
  140. waSetPlColorsStruct s = {0, };
  141. extern COLORREF getWindowBackground(COLORREF *);
  142. COLORREF windowbackground;
  143. buf[5] = getWindowBackground(&windowbackground); // auto inverted
  144. int need_cols = 1, need_bms = 1;
  145. if (!m_lastskin_dir.isempty())
  146. {
  147. StringPathCombine bitmapfilename(m_lastskin_dir, L"pledit.bmp");
  148. HANDLE h = CreateFileW(bitmapfilename, 0, 0, 0, OPEN_EXISTING, 0, 0);
  149. if (h != INVALID_HANDLE_VALUE)
  150. {
  151. CloseHandle(h);
  152. need_bms = 0;
  153. }
  154. bitmapfilename = StringPathCombine(m_lastskin_dir, L"pledit.txt");
  155. h = CreateFileW(bitmapfilename, 0, 0, 0, OPEN_EXISTING, 0, 0);
  156. if (h != INVALID_HANDLE_VALUE)
  157. {
  158. CloseHandle(h);
  159. need_cols = 0;
  160. }
  161. }
  162. if (need_cols)
  163. {
  164. s.numElems = 6;
  165. s.elems = buf;
  166. // list background
  167. if (WASABI_API_SKIN->skin_getColorElementRef(L"wasabi.list.background"))
  168. buf[2] = SkinColor(L"wasabi.list.background") & 0xFFFFFF;
  169. else
  170. buf[2] = RGBTOBGR(WASABI_API_SKIN->skin_getBitmapColor(L"wasabi.list.background")) & 0xFFFFFF; // inverted coz coming from bitmap
  171. // normal text
  172. if (WASABI_API_SKIN->skin_getColorElementRef(L"wasabi.list.text"))
  173. buf[0] = SkinColor(L"wasabi.list.text") & 0xFFFFFF;
  174. else
  175. buf[0] = SkinColor(L"wasabi.edit.text") & 0xFFFFFF;
  176. if (interpolate)
  177. {
  178. int c = buf[0];
  179. c = lumidiff(c, buf[2]) < 0x1F ? Blenders::BLEND_AVG(buf[0], 0xFF7F7F7F) : c;
  180. c = lumidiff(c, buf[2]) < 0x1F ? Blenders::BLEND_AVG(buf[0], 0xFF101010) : c;
  181. buf[0] = c & 0xFFFFFF;
  182. }
  183. COLORREF selected;
  184. // selected items background
  185. if (WASABI_API_SKIN->skin_getColorElementRef(L"wasabi.list.text.selected.background"))
  186. {
  187. selected = SkinColor(L"wasabi.list.text.selected.background");
  188. buf[3] = selected;
  189. }
  190. else
  191. {
  192. // inverted twice, see bellow
  193. if (WASABI_API_SKIN->skin_getColorElementRef(L"wasabi.list.item.selected"))
  194. selected = RGBTOBGR(SkinColor(L"wasabi.list.item.selected"));
  195. else
  196. selected = RGBTOBGR(SkinColor(SKINCOLOR_TREE_SELITEMBKG));
  197. COLORREF col = RGBTOBGR(SkinColor(SKINCOLOR_LIST_COLUMNBKG));
  198. int a = MAX((col & 0xFF0000) >> 16, MAX((col & 0xFF00) >> 8, col & 0xFF));
  199. col = a < 0x1F ? Blenders::BLEND_AVG(windowbackground, 0xFF000000) : col;
  200. int listbkg = RGBTOBGR(buf[2]);
  201. selected = lumidiff(selected, listbkg) < 0x2F ? Blenders::BLEND_AVG(windowbackground, 0xFF7F7F7F) : selected;
  202. selected = lumidiff(selected, listbkg) < 0x2F ? Blenders::BLEND_AVG(listbkg, 0xFF7F7F7F) : selected;
  203. selected = lumidiff(selected, listbkg) < 0x2F ? Blenders::BLEND_AVG(windowbackground, 0xFFF0F0F0) : selected;
  204. selected = lumidiff(selected, listbkg) < 0x2F ? Blenders::BLEND_AVG(listbkg, 0xFFF0F0F0) : selected;
  205. selected = lumidiff(selected, listbkg) < 0x2F ? Blenders::BLEND_AVG(col, 0xFFF0F0F0) : selected;
  206. selected = lumidiff(selected, listbkg) < 0x2F ? Blenders::BLEND_AVG(col, 0xFF101010) : selected;
  207. selected = lumidiff(selected, RGBTOBGR(buf[0])) < 0x1F ? Blenders::BLEND_AVG(selected, 0xFF101010) : selected;
  208. selected = lumidiff(selected, RGBTOBGR(buf[0])) < 0x1F ? Blenders::BLEND_AVG(selected, 0xFFF0F0F0) : selected;
  209. selected &= 0xFFFFFF;
  210. buf[3] = RGBTOBGR(selected);
  211. }
  212. // active text
  213. if (WASABI_API_SKIN->skin_getColorElementRef(L"wasabi.list.text.current"))
  214. buf[1] = SkinColor(L"wasabi.list.text.current");
  215. else
  216. {
  217. COLORREF act = Blenders::BLEND_AVG(selected, buf[0]);
  218. act = (lumidiff(act, buf[0]) < 0x3F || lumidiff(act, buf[2]) < 0x2F) ? Blenders::BLEND_AVG(buf[2], 0xFFFFFFFF) : act;
  219. act = (lumidiff(act, buf[0]) < 0x3F || lumidiff(act, buf[2]) < 0x2F) ? Blenders::BLEND_AVG(buf[2], 0xFF101010) : act;
  220. act = (lumidiff(act, buf[0]) < 0x3F || lumidiff(act, buf[2]) < 0x2F) ? Blenders::BLEND_AVG(selected, buf[0]) : act;
  221. act = (lumidiff(act, buf[0]) < 0x3F || lumidiff(act, buf[2]) < 0x2F) ? Blenders::BLEND_AVG(selected, buf[2]) : act;
  222. act = (lumidiff(act, buf[0]) < 0x3F || lumidiff(act, buf[2]) < 0x2F) ? Blenders::BLEND_AVG(buf[0], buf[2]) : act;
  223. buf[1] = act & 0xFFFFFF;
  224. }
  225. }
  226. if (need_bms)
  227. {
  228. BltCanvas c(280, 186);
  229. c.fillBits(windowbackground); // already inverted
  230. void blitButtonToCanvas(int w, int h, int state, const wchar_t *overlayelement, int xpos, int ypos, BltCanvas *c);
  231. blitButtonToCanvas(8, 18, 0, L"wasabi.scrollbar.vertical.grip", 52, 53, &c);
  232. blitButtonToCanvas(8, 18, 1, L"wasabi.scrollbar.vertical.grip", 61, 53, &c);
  233. int xpos, ypos;
  234. //w=8,h=29
  235. int cols[2];
  236. int *fb = (int*)c.getBits() + 280 * 42;
  237. // inverted colors because going into bitmap
  238. if (WASABI_API_SKIN->skin_getColorElementRef(L"wasabi.scrollbar.background.inverted"))
  239. cols[0] = RGBTOBGR(SkinColor(L"wasabi.scrollbar.background.inverted"));
  240. else
  241. {
  242. if (WASABI_API_SKIN->skin_getColorElementRef(L"wasabi.list.column.empty"))
  243. cols[0] = RGBTOBGR(SkinColor(L"wasabi.list.column.empty"));
  244. else
  245. {
  246. COLORREF col = SkinColor(SKINCOLOR_LIST_COLUMNBKG);
  247. int a = MAX((col & 0xFF0000) >> 16, MAX((col & 0xFF00) >> 8, col & 0xFF));
  248. col = a < 0x1F ? Blenders::BLEND_AVG(windowbackground, 0xFF000000) : col;
  249. cols[0] = RGBTOBGR(Blenders::BLEND_AVG(col, 0xFF000000));
  250. }
  251. }
  252. if (WASABI_API_SKIN->skin_getColorElementRef(L"wasabi.border.sunken"))
  253. cols[1] = RGBTOBGR(SkinColor(L"wasabi.border.sunken"));
  254. else
  255. {
  256. int a = MAX((windowbackground & 0xFF0000) >> 16, MAX((windowbackground & 0xFF00) >> 8, windowbackground & 0xFF));
  257. cols[1] = Blenders::BLEND_AVG(windowbackground, a > 0xE0 ? 0xFF000000 : 0xFFFFFFFF);
  258. }
  259. for (ypos = 42;ypos < 42 + 29; ypos ++)
  260. {
  261. for (xpos = 36; xpos < 36 + 8; xpos ++)
  262. {
  263. fb[xpos] = cols[(xpos == 36 || xpos == 36 + 8 - 1)];
  264. }
  265. fb += 280;
  266. }
  267. extern HBITMAP CreateBitmapDIB(int w, int h, int planes, int bpp, void *data);
  268. s.bm = CreateBitmapDIB(280, 186, 1, 32, c.getBits());
  269. }
  270. if (s.bm || s.elems) SendMessageW(wa2.getMainWindow(), WM_WA_IPC, (WPARAM)&s, IPC_SETPLEDITCOLORS);
  271. }
  272. static prefsDlgRecW ffPrefsItem;
  273. //-----------------------------------------------------------------------------------------------
  274. // a guid for our app : {4BE592C7-6937-426a-A388-ACF0EBC88E93}
  275. static const GUID GEN_FREEFORM =
  276. { 0x4be592c7, 0x6937, 0x426a, { 0xa3, 0x88, 0xac, 0xf0, 0xeb, 0xc8, 0x8e, 0x93 } };
  277. Wa2Groupdefs *groups;
  278. static WNDPROC wa_oldWndProc;
  279. Wa2CfgItems *cfgitems=0;
  280. HINSTANCE hInstance = NULL;
  281. HWND last_dlg_parent = NULL;
  282. void populateWindowsMenus();
  283. void unpopulateWindowsMenus();
  284. void addWindowOptionsToContextMenu(ifc_window *w);
  285. void removeWindowOptionsFromContextMenu();
  286. void controlOpacity(int v);
  287. void controlScaling(double v);
  288. void customScaling();
  289. void customOpacity();
  290. void autoOpacifyHover();
  291. void autoOpacifyFocus();
  292. ifc_window *g_controlMenuTarget = NULL;
  293. HMENU controlmenu = NULL;
  294. void lockScaling(int lock);
  295. int ffwindowsitempos = -1;
  296. int ffoptionstop = -1;
  297. int ffwoptionstop = -1;
  298. int ffwindowstop = -1;
  299. int ffwindowsitempos2 = -1;
  300. int eqremoved = 0;
  301. void removeEq();
  302. void restoreEq();
  303. int g_timedisplaymode = 0;
  304. ifc_window *lastFocused = NULL;
  305. int before_startup_callback = 0;
  306. void loadExtraColorThemes();
  307. extern _int last_page;
  308. int gothrueqmsg = 0;
  309. void unhookOutputIPC();
  310. int we_have_ml = 0;
  311. void checkMlPresent();
  312. char eggstr[9] = {0};
  313. int eggstat = 0;
  314. int eggfallout = 0;
  315. void initEgg();
  316. void toggleEgg();
  317. Layout *lastlayoutegg = NULL;
  318. int disable_send_visrandom = 0;
  319. void registerGlobalHotkeys();
  320. int processGenericHotkey(const char *hk);
  321. const char *getSkinInfo();
  322. const wchar_t *getSkinInfoW();
  323. void controlAppBar(int side);
  324. void controlAppBarAOT();
  325. void controlAppBarAH();
  326. void updateAppBarMenu(ifc_window *w);
  327. void startFSMonitor();
  328. void stopFSMonitor();
  329. void onGoFullscreen();
  330. void onCancelFullscreen();
  331. FullScreenMonitor *g_fsmonitor = NULL;
  332. class Wa5FSCallback : public FSCallback
  333. {
  334. public:
  335. virtual void onGoFullscreen()
  336. {
  337. ::onGoFullscreen();
  338. }
  339. virtual void onCancelFullscreen()
  340. {
  341. ::onCancelFullscreen();
  342. }
  343. };
  344. Wa5FSCallback *g_fscallback = NULL;
  345. int getAOTTempDisable()
  346. {
  347. return g_fsmonitor->isFullScreen();
  348. }
  349. LRESULT CallWinampWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
  350. {
  351. return CallWindowProcW(wa_oldWndProc, hwnd, msg, wParam, lParam);
  352. }
  353. //-----------------------------------------------------------------------------------------------
  354. BOOL WINAPI dll_main_raw_fn(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
  355. {
  356. hInstance = hinstDLL;
  357. Wasabi::Std::Initialize();
  358. return TRUE;
  359. }
  360. extern "C"
  361. {
  362. void *_pRawDllMain = &dll_main_raw_fn;
  363. };
  364. __declspec(dllexport) BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
  365. {
  366. hInstance = hinstDLL;
  367. return TRUE;
  368. }
  369. //-----------------------------------------------------------------------------------------------
  370. // core actions implement "play", "stop", etc. wndEmbedded embed wa2 windows into GUID-based wnds
  371. //-----------------------------------------------------------------------------------------------
  372. BEGIN_SERVICES(Winamp2_Svcs);
  373. DECLARE_SERVICETSINGLE(svc_action, CoreActions);
  374. DECLARE_SERVICETSINGLE(svc_action, MenuActions);
  375. DECLARE_SERVICETSINGLE(svc_windowCreate, Wa2WndEmbed);
  376. END_SERVICES(Winamp2_Svcs, _Winamp2_Svcs);
  377. //-----------------------------------------------------------------------------------------------
  378. // functions called by the overriden windowproc to create and destroy wndembedders
  379. //-----------------------------------------------------------------------------------------------
  380. ifc_window *plWnd = NULL;
  381. #ifdef MINIBROWSER_SUPPORT
  382. ifc_window *mbWnd = NULL;
  383. #endif
  384. ifc_window *vidWnd = NULL;
  385. TList<HWND> forcedoffwnds;
  386. int going_freeform = 0;
  387. int going_fixedform = 0;
  388. wchar_t *INI_FILE = 0, *INI_DIR = 0;
  389. void ToggleLayout(const wchar_t *containerName)
  390. {
  391. Container *c = SkinParser::getContainer(containerName);
  392. if (c)
  393. {
  394. int numLayouts = c->getNumLayouts();
  395. for (int i = 0;i < numLayouts;i++)
  396. {
  397. if (c->enumLayout(i) == c->getCurrentLayout())
  398. {
  399. int nextLayout = (i + 1) % numLayouts;
  400. Layout *layout = c->enumLayout(nextLayout);
  401. c->switchToLayout(layout->getId());
  402. return ;
  403. }
  404. }
  405. }
  406. }
  407. int updatePl()
  408. {
  409. // find out if this GUID is already shown.
  410. WindowHolder *wh = skinEmbedder->getSuitableWindowHolder(pleditWndGuid, NULL, NULL, NULL, 1, -1, 0, 1, -1);
  411. if (wh != NULL)
  412. {
  413. wh->cancelDeferredRemove();
  414. GuiObject *go = wh->getRootWndPtr()->getGuiObject();
  415. if (go)
  416. {
  417. Layout *l = go->guiobject_getParentLayout();
  418. if (l)
  419. {
  420. Container *c = l->getParentContainer();
  421. if (c)
  422. {
  423. DebugStringW(L"Container is %s\n", c->getId());
  424. SkinEmbedder::cancelDestroyContainer(c);
  425. }
  426. }
  427. }
  428. plWnd = wh->getRootWndPtr(); //->getDesktopParent();
  429. return 1;
  430. }
  431. return 0;
  432. }
  433. int createPl()
  434. {
  435. if (updatePl())
  436. {
  437. ShowWindow(wa2.getWnd(IPC_GETWND_PE), SW_SHOWNA);
  438. return 1;
  439. }
  440. ReentryFilter f(&wndMsgFilter, IPC_GETWND_PE);
  441. if (f.mustLeave()) return 1;
  442. plWnd = WASABI_API_WNDMGR->skinwnd_createByGuid(pleditWndGuid, L"resizable_status");
  443. if (plWnd != NULL)
  444. {
  445. plWnd->setVisible(1);
  446. }
  447. return plWnd != NULL;
  448. }
  449. static ifc_window *updateEmb(GUID thisguid, embedWindowState *ws)
  450. {
  451. WindowHolder *wh = skinEmbedder->getSuitableWindowHolder(thisguid, NULL, NULL, NULL, 1, -1, 0, 1, -1);
  452. if (wh != NULL && !(ws->flags & EMBED_FLAGS_LEGACY_WND))
  453. {
  454. ifc_window *p = wh->getRootWndPtr(); //->getDesktopParent();
  455. // p->getGuiScriptObject()->vcpu_setInterface(embeddedWndStateGuid, ws, INTERFACE_GENERICVOIDPTR);
  456. ws->extra_data[EMBED_STATE_EXTRA_FFROOTWND] = (intptr_t)p;
  457. return p;
  458. }
  459. return 0;
  460. }
  461. static ifc_window *createEmb(embedWindowState *ws, bool startHidden)
  462. {
  463. GUID thisguid = EmbedWndGuid(ws).getGuid();
  464. if (thisguid == INVALID_GUID || (ws->flags & EMBED_FLAGS_LEGACY_WND))
  465. return 0;
  466. //thisguid.Data1 = (int)ws->me;
  467. ifc_window *update = updateEmb(thisguid, ws);
  468. if (update)
  469. return update;
  470. ReentryFilter f(&wndMsgFilter, (intptr_t)ws);
  471. if (f.mustLeave())
  472. return 0;
  473. RECT r;
  474. if (!GetWindowRect(ws->me, &r))
  475. SetRectEmpty(&r);
  476. ifc_window *p = NULL;
  477. if (ws->flags & EMBED_FLAGS_NORESIZE)
  478. p = WASABI_API_WNDMGR->skinwnd_createByGuid(thisguid, L"static", 0, NULL, 0, startHidden, NULL);
  479. else
  480. p = WASABI_API_WNDMGR->skinwnd_createByGuid(thisguid, L"resizable_nostatus", 0, NULL, 0, startHidden, NULL);
  481. ws->extra_data[EMBED_STATE_EXTRA_FFROOTWND] = (intptr_t) p;
  482. if (p != NULL)
  483. {
  484. // p->getGuiScriptObject()->vcpu_setInterface(embeddedWndStateGuid, ws, INTERFACE_GENERICVOIDPTR);
  485. if (NULL != WASABI_API_APP)
  486. WASABI_API_APP->app_unregisterGlobalWindow(p->getDesktopParent()->gethWnd());
  487. if (!startHidden)
  488. p->setVisible(1);
  489. GuiObject *go = p->getGuiObject();
  490. if (go)
  491. {
  492. Layout *l = go->guiobject_getParentLayout();
  493. if (l)
  494. {
  495. Container *c = l->getParentContainer();
  496. if (c)
  497. {
  498. if (ws->flags & EMBED_FLAGS_NOWINDOWMENU)
  499. c->setXmlParam(L"nomenu", L"1");
  500. else
  501. c->setXmlParam(L"nomenu", L"0");
  502. }
  503. }
  504. }
  505. }
  506. if (p == NULL)
  507. {
  508. RECT r;
  509. GetWindowRect(ws->me, &r);
  510. //////SetWindowPos( ws->me, NULL, r.left - 20000, r.top - 20000, 0, 0, SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOREDRAW | SWP_NOSENDCHANGING | SWP_NOZORDER | SWP_NOCOPYBITS );
  511. SetWindowPos( ws->me, NULL, r.left, r.top, 0, 0, SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOREDRAW | SWP_NOSENDCHANGING | SWP_NOZORDER | SWP_NOCOPYBITS );
  512. forcedoffwnds.addItem(ws->me);
  513. //if (0 != (WS_VISIBLE & windowStyle))
  514. //RedrawWindow(GetDesktopWindow(), &r, NULL, RDW_INVALIDATE | RDW_ALLCHILDREN | RDW_UPDATENOW | RDW_NOERASE);
  515. }
  516. RedrawWindow(GetDesktopWindow(), &r, NULL, RDW_INVALIDATE | RDW_ALLCHILDREN | RDW_UPDATENOW | RDW_NOERASE);
  517. return p;
  518. }
  519. #ifdef MINIBROWSER_SUPPORT
  520. int updateMb()
  521. {
  522. WindowHolder *wh = skinEmbedder->getSuitableWindowHolder(minibrowserWndGuid, NULL, NULL, NULL, 1, -1, 0, 1, -1);
  523. if (wh != NULL)
  524. {
  525. mbWnd = wh->getRootWndPtr(); //->getDesktopParent();
  526. ShowWindow(wa2.getWnd(IPC_GETWND_MB), SW_SHOWNA);
  527. return 1;
  528. }
  529. return 0;
  530. }
  531. int createMb()
  532. {
  533. // see cratePl()
  534. if (updateMb()) return 1;
  535. ReentryFilter f(&wndMsgFilter, IPC_GETWND_MB);
  536. if (f.mustLeave()) return 1;
  537. mbWnd = WASABI_API_WNDMGR->skinwnd_createByGuid(minibrowserWndGuid, "resizable_status");
  538. if (mbWnd != NULL) mbWnd->setVisible(1);
  539. return mbWnd != NULL;
  540. }
  541. #endif
  542. static HWND oldVideoWnd;
  543. static WNDPROC oldVideoWndProc;
  544. static DWORD WINAPI newVideoWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  545. {
  546. if (uMsg == WM_USER + 0x100 && wParam == 1 && lParam)
  547. return 0;
  548. return CallWindowProc(oldVideoWndProc, hwnd, uMsg, wParam, lParam);
  549. }
  550. int updateVid()
  551. {
  552. WindowHolder *wh = skinEmbedder->getSuitableWindowHolder(videoWndGuid, NULL, NULL, NULL, 1, -1, 0, 1, -1);
  553. if (wh != NULL)
  554. {
  555. #ifdef VIDDEBUG
  556. DebugString("Video : Host already exists and window already shown in it\n");
  557. #endif
  558. wh->cancelDeferredRemove();
  559. GuiObject *go = wh->getRootWndPtr()->getGuiObject();
  560. if (go)
  561. {
  562. Layout *l = go->guiobject_getParentLayout();
  563. if (l)
  564. {
  565. Container *c = l->getParentContainer();
  566. if (c)
  567. {
  568. DebugStringW(L"Container is %s\n", c->getId());
  569. SkinEmbedder::cancelDestroyContainer(c);
  570. }
  571. }
  572. }
  573. vidWnd = wh->getRootWndPtr(); //->getDesktopParent();
  574. return 1;
  575. }
  576. return 0;
  577. }
  578. int createVid()
  579. {
  580. ShowWindow(WASABI_API_WND->main_getRootWnd()->gethWnd(), SW_RESTORE);
  581. SetForegroundWindow(WASABI_API_WND->main_getRootWnd()->gethWnd());
  582. if (updateVid())
  583. {
  584. ShowWindow(wa2.getWnd(IPC_GETWND_VIDEO), SW_SHOWNA);
  585. return 1;
  586. }
  587. if (vidWnd == NULL)
  588. {
  589. ReentryFilter f(&wndMsgFilter, IPC_GETWND_VIDEO);
  590. if (f.mustLeave()) return 1;
  591. #ifdef VIDDEBUG
  592. DebugString("Video : Trying to find a host or creating it if needed\n");
  593. #endif
  594. vidWnd = WASABI_API_WNDMGR->skinwnd_createByGuid(videoWndGuid, L"resizable_status");
  595. }
  596. if (vidWnd != NULL)
  597. {
  598. vidWnd->setVisible(1);
  599. }
  600. return vidWnd != NULL;
  601. }
  602. int destroyPl(HWND hwndDlg, int uMsg, WPARAM wParam, LPARAM lParam)
  603. {
  604. ReentryFilter f(&wndMsgFilter, IPC_GETWND_PE);
  605. int r = CallWinampWndProc(hwndDlg, uMsg, wParam, lParam);
  606. if (f.mustLeave()) return r;
  607. if (plWnd != NULL && WASABI_API_WND->rootwndIsValid(plWnd))
  608. {
  609. WASABI_API_WNDMGR->skinwnd_destroy(plWnd);
  610. r = !WASABI_API_WND->rootwndIsValid(plWnd);
  611. }
  612. else
  613. r = !SOM::checkAbortShowHideWindow(pleditWndGuid, 0);
  614. if (r)
  615. plWnd = NULL;
  616. return r;
  617. }
  618. int destroyEmb(HWND hwndDlg, int uMsg, WPARAM wParam, LPARAM lParam, embedWindowState *ws)
  619. {
  620. ReentryFilter f(&wndMsgFilter, (intptr_t)ws);
  621. int r = CallWinampWndProc(hwndDlg, uMsg, wParam, lParam);
  622. if (f.mustLeave() || (ws->flags & EMBED_FLAGS_LEGACY_WND)) return r;
  623. if (ws->extra_data[EMBED_STATE_EXTRA_FFROOTWND] == NULL) return r;
  624. if (ws->extra_data[EMBED_STATE_EXTRA_REPARENTING] == 1) return r;
  625. ifc_window *w = (ifc_window*)ws->extra_data[EMBED_STATE_EXTRA_FFROOTWND];
  626. #if 1
  627. if (WASABI_API_WND->rootwndIsValid(w))
  628. {
  629. WASABI_API_WNDMGR->skinwnd_destroy(w);
  630. r = !WASABI_API_WND->rootwndIsValid(w);
  631. }
  632. else
  633. {
  634. r = !SOM::checkAbortShowHideWindow(embedWndGuidMgr.getGuid(ws), 0);
  635. }
  636. if (r)
  637. ws->extra_data[EMBED_STATE_EXTRA_FFROOTWND] = NULL;
  638. #else
  639. if (WASABI_API_WND->rootwndIsValid(w)) WASABI_API_WNDMGR->skinwnd_destroy(w);
  640. else SOM::checkAbortShowHideWindow(embedWndGuidMgr.getGuid(ws), 0);
  641. ws->extra_data[EMBED_STATE_EXTRA_FFROOTWND] = NULL;
  642. #endif
  643. return r;
  644. }
  645. #ifdef MINIBROWSER_SUPPORT
  646. int destroyMb(HWND hwndDlg, int uMsg, WPARAM wParam, LPARAM lParam)
  647. {
  648. ReentryFilter f(&wndMsgFilter, IPC_GETWND_MB);
  649. int r = CallWinampWndProc(hwndDlg, uMsg, wParam, lParam);
  650. if (f.mustLeave()) return r;
  651. if (mbWnd != NULL && WASABI_API_WND->rootwndIsValid(mbWnd)) WASABI_API_WNDMGR->skinwnd_destroy(mbWnd);
  652. else SOM::checkAbortShowHideWindow(minibrowserWndGuid, 0);
  653. mbWnd = NULL;
  654. return r;
  655. }
  656. #endif
  657. int destroyVid(HWND hwndDlg, int uMsg, WPARAM wParam, LPARAM lParam)
  658. {
  659. ReentryFilter f(&wndMsgFilter, IPC_GETWND_VIDEO);
  660. int r = CallWinampWndProc(hwndDlg, uMsg, wParam, lParam);
  661. if (f.mustLeave()) return r;
  662. if (vidWnd != NULL && WASABI_API_WND->rootwndIsValid(vidWnd))
  663. {
  664. WASABI_API_WNDMGR->skinwnd_destroy(vidWnd);
  665. r = !WASABI_API_WND->rootwndIsValid(vidWnd);
  666. }
  667. else
  668. r = !SOM::checkAbortShowHideWindow(videoWndGuid, 0);
  669. if (r)
  670. vidWnd = NULL;
  671. return r;
  672. }
  673. int m_loading_at_startup;
  674. int m_are_we_loaded;
  675. #define WINAMP_REFRESHSKIN 40291
  676. #define WINAMP_OPTIONS_EQ 40036
  677. #define WINAMP_OPTIONS_DSIZE 40165
  678. #define WINAMP_OPTIONS_ELAPSED 40037
  679. #define WINAMP_OPTIONS_REMAINING 40038
  680. //-----------------------------------------------------------------------------------------------
  681. class MainLayoutMonitor : public H_Layout
  682. {
  683. public:
  684. MainLayoutMonitor(HWND _w, ScriptObject *o) : H_Layout(o) { hwnd= _w; }
  685. void hook_onResize(int x, int y, int w, int h);
  686. HWND hwnd;
  687. };
  688. void MainLayoutMonitor::hook_onResize(int x, int y, int w, int h)
  689. {
  690. PostMessage(wa2.getMainWindow(), WM_WA_IPC, (WPARAM)hwnd, UPDATEDIALOGBOXPARENTMSG);
  691. }
  692. //-----------------------------------------------------------------------------------------------
  693. // must be called after switching to a new freeform skin
  694. // should also be called when the main container changes its visible layout
  695. //-----------------------------------------------------------------------------------------------
  696. Layout *GetMainLayout()
  697. {
  698. Container *container = SkinParser::getContainer(L"main");
  699. if (container != NULL)
  700. {
  701. return container->getCurrentLayout();
  702. }
  703. return 0;
  704. }
  705. HWND GetMainContainerHWND()
  706. {
  707. Layout *l = GetMainLayout();
  708. if (l != NULL)
  709. return l->gethWnd();
  710. return 0;
  711. }
  712. static MainLayoutMonitor *mainLayoutMonitor = 0;
  713. void setDialogBoxesParent()
  714. {
  715. Layout *l = GetMainLayout();
  716. if (l != NULL)
  717. {
  718. HWND hwnd = l->gethWnd();
  719. delete mainLayoutMonitor;
  720. mainLayoutMonitor = new MainLayoutMonitor(hwnd, l->getScriptObject());
  721. wa2.setDialogBoxParent(hwnd);
  722. PostMessage(wa2.getMainWindow(), WM_WA_IPC, (WPARAM)hwnd, UPDATEDIALOGBOXPARENTMSG);
  723. lastFocused = l;
  724. }
  725. }
  726. static void removeSkinExtension(StringW &skinname)
  727. {
  728. int x = skinname.len() - 4;
  729. if (x > 0)
  730. {
  731. const wchar_t *p = ((const wchar_t *)skinname) + x;
  732. if (!_wcsicmp(p, L".zip") || !_wcsicmp(p, L".wal") || !_wcsicmp(p, L".wsz"))
  733. skinname.trunc(x);
  734. }
  735. }
  736. extern HWND subWnd, tabwnd;
  737. extern int subWndId;
  738. extern int toggle_from_wa2;
  739. int switching_skin = 0;
  740. void shutdownFFApi();
  741. /*-----------------------------------------------------------------------------------------------
  742. * Winamp2 message processor
  743. */
  744. static void RerouteMessage(MSG *pMsg, ifc_window *wnd)
  745. {
  746. if (NULL == wnd)
  747. return;
  748. HWND hReroute = NULL;
  749. if (pMsg->hwnd == GetMainContainerHWND())
  750. {
  751. hReroute = WASABI_API_WND->main_getRootWnd()->gethWnd();
  752. if (NULL != hReroute)
  753. {
  754. pMsg->hwnd = hReroute;
  755. }
  756. return;
  757. }
  758. if (wnd->gethWnd() != pMsg->hwnd)
  759. return;
  760. ifc_window *parent = wnd->getRootParent();
  761. if (NULL == parent)
  762. return;
  763. Layout *l = static_cast<Layout *>(parent->getInterface(layoutGuid));
  764. if (NULL == l)
  765. return;
  766. Container *c = l->getParentContainer();
  767. if (NULL == c)
  768. return;
  769. GUID g = c->getDefaultContent();
  770. if (INVALID_GUID == g)
  771. return;
  772. if (g == playerWndGuid)
  773. hReroute = wa2.getMainWindow();
  774. else if (g == pleditWndGuid)
  775. hReroute = wa2.getWnd(IPC_GETWND_PE);
  776. else if (g == videoWndGuid)
  777. hReroute = wa2.getWnd(IPC_GETWND_VIDEO);
  778. else
  779. {
  780. embedWindowState *ews = embedWndGuidMgr.getEmbedWindowState(g);
  781. if (ews)
  782. hReroute = ews->me;
  783. }
  784. if (NULL != hReroute)
  785. pMsg->hwnd = hReroute;
  786. }
  787. class WaMessageProccessor : public ifc_messageprocessor
  788. {
  789. public:
  790. WaMessageProccessor() {}
  791. ~WaMessageProccessor(void) {}
  792. public:
  793. bool ProcessMessage(MSG *pMsg)
  794. {
  795. if (WM_KEYDOWN == pMsg->message ||
  796. WM_KEYUP == pMsg->message ||
  797. WM_SYSKEYDOWN == pMsg->message ||
  798. WM_SYSKEYUP == pMsg->message)
  799. {
  800. ifc_window *wnd;
  801. HWND h = pMsg->hwnd;
  802. do
  803. {
  804. wnd = WASABI_API_WND->rootWndFromOSHandle(h);
  805. } while (!wnd && NULL!= (h = GetAncestor(h, GA_PARENT)));
  806. if (wnd)
  807. {
  808. if (!wnd->isVirtual())
  809. {
  810. while (wnd)
  811. {
  812. const wchar_t *pid = wnd->getId();
  813. if (pid && *pid) break;
  814. wnd = wnd->getParent();
  815. }
  816. }
  817. if (wnd && wnd->getCurVirtualChildFocus())
  818. wnd = wnd->getCurVirtualChildFocus();
  819. }
  820. if (wnd)
  821. DebugStringW(L"target wnd 0x%08X, id: %s", wnd, wnd->getId());
  822. INT keyMsg = -1;
  823. switch(pMsg->message)
  824. {
  825. case WM_KEYDOWN:
  826. static int pos;
  827. if (toupper((int)pMsg->wParam) == eggstr[pos])
  828. {
  829. if (!eggstr[++pos])
  830. {
  831. toggleEgg();
  832. pos = 0;
  833. }
  834. }
  835. else pos = 0;
  836. keyMsg = (0 != WASABI_API_WND->forwardOnKeyDown(wnd, (int)pMsg->wParam, pMsg->lParam));
  837. break;
  838. case WM_KEYUP: keyMsg = (wnd && 0 != WASABI_API_WND->forwardOnKeyUp(wnd, (int)pMsg->wParam, pMsg->lParam)); break;
  839. case WM_SYSKEYDOWN: keyMsg = ( 0 != WASABI_API_WND->forwardOnSysKeyDown(wnd, (int)pMsg->wParam, pMsg->lParam)); break;
  840. case WM_SYSKEYUP: keyMsg = (wnd && 0 != WASABI_API_WND->forwardOnSysKeyUp(wnd, (int)pMsg->wParam, pMsg->lParam)); break;
  841. }
  842. if (-1 != keyMsg)
  843. {
  844. if (keyMsg > 0)
  845. return true;
  846. RerouteMessage(pMsg, wnd);
  847. }
  848. }
  849. return false;
  850. }
  851. protected:
  852. RECVS_DISPATCH;
  853. };
  854. #define CBCLASS WaMessageProccessor
  855. START_DISPATCH;
  856. CB(IFC_MESSAGEPROCESSOR_PROCESS_MESSAGE, ProcessMessage)
  857. END_DISPATCH;
  858. #undef CBCLASS
  859. static WaMessageProccessor waMessageProcessor;
  860. #define TabCtrl_InsertItemW(hwnd, iItem, pitem) \
  861. (int)SNDMSG((hwnd), TCM_INSERTITEMW, (WPARAM)(int)(iItem), (LPARAM)(const TC_ITEMW *)(pitem))
  862. //-----------------------------------------------------------------------------------------------
  863. void onSkinSwitch()
  864. {
  865. switching_skin = 1;
  866. int lastloaded = m_are_we_loaded;
  867. Wa2WndEmbed::rememberVisibleWindows();
  868. // get skin name
  869. wchar_t buf[MAX_PATH] = {0};
  870. wchar_t *p = (wchar_t *) SendMessageW(plugin.hwndParent, WM_WA_IPC, (WPARAM)buf, IPC_GETSKINW);
  871. {
  872. m_lastskin_nam.setValue(p);
  873. m_lastskin_dir.setValue(buf);
  874. StringPathCombine t(m_lastskin_dir, L"skin.xml");
  875. if (!m_lastskin_nam.isempty()
  876. && _waccess(t.getValue(), 0))
  877. {
  878. t.setValue(m_lastskin_dir);
  879. StringW n = m_lastskin_nam;
  880. removeSkinExtension(n);
  881. t.AppendPath(n);
  882. t.AppendPath(L"skin.xml");
  883. if (!_waccess(t.getValue(), 0))
  884. m_lastskin_dir.AppendPath(n);
  885. }
  886. if (!_waccess(t.getValue(), 0))
  887. {
  888. if (!m_are_we_loaded) init_inst();
  889. else
  890. {
  891. // load new skin
  892. StringW skinname = m_lastskin_nam;
  893. removeSkinExtension(skinname);
  894. before_startup_callback = 1;
  895. WASABI_API_SKIN->skin_switchSkin(skinname, m_lastskin_dir);
  896. if (DEFERREDCALLBACKMSG > 65536)
  897. PostMessage(wa2.getMainWindow(), WM_WA_IPC, 2, DEFERREDCALLBACKMSG);
  898. //embedEnumStruct cs = { embedCreateProc, 0 };
  899. //SendMessageW(plugin.hwndParent, WM_WA_IPC, (WPARAM)&cs, IPC_EMBED_ENUM);
  900. doplaylistcolors();
  901. setDialogBoxesParent();
  902. populateWindowsMenus();
  903. }
  904. }
  905. else
  906. {
  907. going_fixedform = 1;
  908. quit_inst();
  909. }
  910. }
  911. if (subWnd != NULL && IsWindow(subWnd)) SendMessageW(subWnd, WM_INITDIALOG, 0, 0);
  912. if (IsWindow(tabwnd))
  913. {
  914. if (!m_are_we_loaded)
  915. {
  916. if (subWndId == 5)
  917. {
  918. DestroyWindow(subWnd);
  919. TabCtrl_SetCurSel(tabwnd,0);
  920. _dosetsel(GetParent(tabwnd));
  921. }
  922. if (TabCtrl_GetItemCount(tabwnd) == 5)
  923. {
  924. TabCtrl_DeleteItem(tabwnd,4);
  925. TabCtrl_DeleteItem(tabwnd,3);
  926. }
  927. }
  928. else
  929. {
  930. if (TabCtrl_GetItemCount(tabwnd) == 3)
  931. {
  932. TCITEMW item = {0};
  933. item.mask=TCIF_TEXT;
  934. item.pszText=WASABI_API_LNGSTRINGW(IDS_COLOR_THEMES);
  935. TabCtrl_InsertItemW(tabwnd,3,&item);
  936. item.pszText=WASABI_API_LNGSTRINGW(IDS_CURRENT_SKIN);
  937. TabCtrl_InsertItemW(tabwnd,4,&item);
  938. }
  939. }
  940. }
  941. if (m_are_we_loaded || lastloaded) // dont call this if going from classic->classic
  942. Wa2WndEmbed::restoreVisibleWindows();
  943. if (m_are_we_loaded && WASABI_API_SYSCB)
  944. WASABI_API_SYSCB->syscb_issueCallback(SysCallback::GC, GarbageCollectCallback::GARBAGECOLLECT);
  945. if (WASABI_API_APP)
  946. {
  947. if (m_are_we_loaded) WASABI_API_APP->app_addMessageProcessor(&waMessageProcessor);
  948. else WASABI_API_APP->app_removeMessageProcessor(&waMessageProcessor);
  949. }
  950. /* TODO: benski> want to add this, but it's causing a weird crash
  951. if (going_fixedform)
  952. shutdownFFApi();
  953. */
  954. switching_skin = 0;
  955. going_fixedform = 0;
  956. before_startup_callback = 0;
  957. }
  958. static int embedUpdateColorProc(embedWindowState *p, embedEnumStruct *parms)
  959. {
  960. SendMessageW(p->me, WM_DISPLAYCHANGE, 0, 0);
  961. return 0;
  962. }
  963. int embedCreateProc(embedWindowState *ws, embedEnumStruct *parms)
  964. {
  965. ifc_window *rw = reinterpret_cast<ifc_window*>(ws->extra_data[EMBED_STATE_EXTRA_FFROOTWND]);
  966. if (!rw && IsWindow(ws->me) && IsWindowVisible(ws->me) && !(ws->flags & EMBED_FLAGS_LEGACY_WND))
  967. {
  968. ifc_window *windowParent = createEmb(ws, true);
  969. if (NULL != windowParent)
  970. {
  971. GuiObject *uiObject = windowParent->getGuiObject();
  972. if (NULL != uiObject)
  973. {
  974. if (0 != (EMBED_FLAGS_FFCALLBACK & ws->flags) &&
  975. NULL != ws->callback)
  976. {
  977. ws->callback(ws, FFC_CREATEEMBED, (LPARAM)windowParent);
  978. }
  979. Layout *layout = uiObject->guiobject_getParentLayout();
  980. if (NULL != layout)
  981. {
  982. Container *container = layout->getParentContainer();
  983. if (NULL != container) container->setVisible(1);
  984. else layout->setVisible(1);
  985. windowParent->setVisible(1);
  986. }
  987. }
  988. }
  989. if (NULL == windowParent)
  990. ShowWindow(ws->me, SW_HIDE);
  991. }
  992. return 0;
  993. }
  994. //-----------------------------------------------------------------------------------------------
  995. void syncDoubleSize(int loading = 0)
  996. {
  997. if (!cfg_uioptions_uselocks.getValueAsInt()) return ;
  998. int isdsize = wa2.isDoubleSize();
  999. int i;
  1000. for (i = 0;i < SkinParser::getNumContainers();i++)
  1001. {
  1002. Container *c = SkinParser::enumContainer(i);
  1003. if (c != NULL)
  1004. {
  1005. int j;
  1006. for (j = 0;j < c->getNumLayouts();j++)
  1007. {
  1008. Layout *l = c->enumLayout(j);
  1009. if (l != NULL)
  1010. {
  1011. if (l->isScaleLocked()) continue;
  1012. l->setRenderRatio(isdsize ? 2.0f : 1.0f);
  1013. }
  1014. }
  1015. }
  1016. }
  1017. }
  1018. //-----------------------------------------------------------------------------------------------
  1019. class syncDisplayModeEnumerator : public FindObjectCallbackI
  1020. {
  1021. public:
  1022. int findobjectcb_matchObject(ifc_window *object)
  1023. {
  1024. ScriptObject *s = NULL;
  1025. GuiObject *g = object->getGuiObject();
  1026. if (g)
  1027. {
  1028. ScriptObject *_s = g->guiobject_getScriptObject();
  1029. if (_s)
  1030. {
  1031. void *v = _s->vcpu_getInterfaceObject(textGuid, &s);
  1032. if (v && !s)
  1033. {
  1034. (static_cast<Text*>(v))->setTimeDisplayMode(g_timedisplaymode);
  1035. }
  1036. }
  1037. }
  1038. return 0;
  1039. }
  1040. };
  1041. //-----------------------------------------------------------------------------------------------
  1042. void syncDisplayMode()
  1043. {
  1044. if (switching_skin) return ;
  1045. g_timedisplaymode = wa2.getTimeDisplayMode();
  1046. int i;
  1047. syncDisplayModeEnumerator enumerator;
  1048. for (i = 0;i < SkinParser::getNumContainers();i++)
  1049. {
  1050. Container *c = SkinParser::enumContainer(i);
  1051. if (c != NULL)
  1052. {
  1053. int j;
  1054. for (j = 0;j < c->getNumLayouts();j++)
  1055. {
  1056. Layout *l = c->enumLayout(j);
  1057. if (!WASABI_API_WND->rootwndIsValid(l)) continue;
  1058. l->findWindowByCallback(&enumerator);
  1059. }
  1060. }
  1061. }
  1062. }
  1063. static POINT viewPort;
  1064. VOID CALLBACK ViewPortChanged(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime)
  1065. {
  1066. KillTimer(hwnd, idEvent);
  1067. if (viewPort.x && viewPort.y)
  1068. {
  1069. SystemObject::onViewPortChanged(viewPort.x, viewPort.y);
  1070. }
  1071. }
  1072. //-----------------------------------------------------------------------------------------------
  1073. // Winamp2 main window subclass
  1074. //-----------------------------------------------------------------------------------------------
  1075. static LRESULT WINAPI wa_newWndProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  1076. {
  1077. static int m_in_skinrefresh;
  1078. if (uMsg == WM_COMMAND && LOWORD(wParam) == WINAMP_REFRESHSKIN)
  1079. {
  1080. HWND prefs = wa2.getPreferencesWindow();
  1081. RECT prefrect = {0};
  1082. if (prefs)
  1083. {
  1084. GetWindowRect(prefs, &prefrect);
  1085. HWND hOwner = (HWND)(LONG_PTR)GetWindowLongPtrW(prefs, GWLP_HWNDPARENT);
  1086. if (NULL != hOwner && hOwner != hwndDlg)
  1087. SetWindowLongPtrW(prefs, GWLP_HWNDPARENT, (LONG_PTR)hwndDlg);
  1088. }
  1089. m_in_skinrefresh++;
  1090. DWORD b = CallWinampWndProc(hwndDlg, uMsg, wParam, lParam);
  1091. onSkinSwitch();
  1092. if (m_are_we_loaded) doplaylistcolors();
  1093. m_in_skinrefresh--;
  1094. if (prefs && !wa2.getPreferencesWindow())
  1095. {
  1096. SendMessageW(wa2.getMainWindow(), WM_COMMAND, WINAMP_OPTIONS_PREFS, 0);
  1097. SetWindowPos(wa2.getPreferencesWindow(), NULL, prefrect.left, prefrect.top, prefrect.right - prefrect.left, prefrect.bottom - prefrect.top, SWP_NOZORDER | SWP_NOACTIVATE | SWP_DEFERERASE);
  1098. }
  1099. return b;
  1100. }
  1101. if (g_Core)
  1102. {
  1103. if (uMsg == WM_WA_IPC && lParam == IPC_CB_MISC) g_Core->gotCallback(wParam);
  1104. #define WINAMP_FILE_REPEAT 40022
  1105. #define WINAMP_FILE_SHUFFLE 40023
  1106. #define WINAMP_FILE_MANUALPLADVANCE 40395
  1107. #define UPDATE_DISPLAY_TIMER 38
  1108. if (uMsg == WM_TIMER)
  1109. {
  1110. if (LOWORD(wParam) == UPDATE_EGG)
  1111. {
  1112. for (int i = 0;i < SkinParser::getNumContainers();i++)
  1113. {
  1114. Container *cont = SkinParser::enumContainer(i);
  1115. if (cont->isMainContainer())
  1116. {
  1117. Layout *l = cont->getCurrentLayout();
  1118. if (lastlayoutegg && l != lastlayoutegg)
  1119. {
  1120. if (WASABI_API_WND->rootwndIsValid(lastlayoutegg))
  1121. {
  1122. lastlayoutegg->updateTransparency();
  1123. lastlayoutegg->setTransparencyOverride(-1);
  1124. }
  1125. }
  1126. lastlayoutegg = l;
  1127. int v = (WASABI_API_MEDIACORE->core_getLeftVuMeter(0) + WASABI_API_MEDIACORE->core_getRightVuMeter(0)) / 4;
  1128. eggfallout -= 4;
  1129. if (v > eggfallout) eggfallout = v;
  1130. lastlayoutegg->setTransparencyOverride(255 - eggfallout);
  1131. break;
  1132. }
  1133. }
  1134. return 0;
  1135. }
  1136. if (LOWORD(wParam) == UPDATE_DISPLAY_TIMER + 4)
  1137. {
  1138. syncDisplayMode();
  1139. }
  1140. if (LOWORD(wParam) == 0xC0DE)
  1141. {
  1142. if (!wa2.isVisRunning())
  1143. {
  1144. KillTimer(wa2.getMainWindow(), 0xC0DE);
  1145. KillTimer(wa2.getMainWindow(), 0xC0DE + 1);
  1146. wa2.toggleVis();
  1147. }
  1148. }
  1149. if (LOWORD(wParam) == 0xC0DE + 1)
  1150. {
  1151. KillTimer(wa2.getMainWindow(), 0xC0DE);
  1152. KillTimer(wa2.getMainWindow(), 0xC0DE + 1);
  1153. }
  1154. }
  1155. if (!my_set && (uMsg == WM_COMMAND || uMsg == WM_SYSCOMMAND) && LOWORD(wParam) == WINAMP_FILE_SHUFFLE)
  1156. {
  1157. DWORD v = CallWinampWndProc(hwndDlg, uMsg, wParam, lParam);
  1158. int shuf = wa2.getShuffle();
  1159. if (!shuffle.getValueAsInt() != !shuf) shuffle.setValueAsInt(shuf);
  1160. return v;
  1161. }
  1162. if (!my_set && (uMsg == WM_COMMAND || uMsg == WM_SYSCOMMAND) &&
  1163. (LOWORD(wParam) == WINAMP_FILE_REPEAT) ||
  1164. (LOWORD(wParam) == WINAMP_FILE_MANUALPLADVANCE))
  1165. {
  1166. DWORD v = CallWinampWndProc(hwndDlg, uMsg, wParam, lParam);
  1167. int rep = wa2.getRepeat();
  1168. int manadv = wa2.getManualPlaylistAdvance();
  1169. int _v = (rep && manadv) ? -1 : rep;
  1170. if (repeat.getValueAsInt() != _v) repeat.setValueAsInt(_v);
  1171. return v;
  1172. }
  1173. if ((uMsg == WM_COMMAND || uMsg == WM_SYSCOMMAND) && LOWORD(wParam) == WINAMP_OPTIONS_DSIZE)
  1174. {
  1175. int v = CallWinampWndProc(hwndDlg, uMsg, wParam, lParam);
  1176. syncDoubleSize();
  1177. return v;
  1178. }
  1179. if ((uMsg == WM_COMMAND || uMsg == WM_SYSCOMMAND) && (LOWORD(wParam) == WINAMP_OPTIONS_ELAPSED || LOWORD(wParam) == WINAMP_OPTIONS_REMAINING))
  1180. {
  1181. int v = CallWinampWndProc(hwndDlg, uMsg, wParam, lParam);
  1182. syncDisplayMode();
  1183. return v;
  1184. }
  1185. }
  1186. if (m_are_we_loaded)
  1187. {
  1188. if (uMsg == WM_COMMAND && LOWORD(wParam) == 40266)
  1189. {
  1190. ToggleLayout(L"pledit");
  1191. return 0;
  1192. }
  1193. else if (uMsg == WM_COMMAND && LOWORD(wParam) == 40064)
  1194. {
  1195. ToggleLayout(L"main");
  1196. return 0;
  1197. }
  1198. else if (uMsg == WM_CLOSE && wParam == 0xDEADBEEF && lParam == 0xDEADF00D)
  1199. {
  1200. //if (/*todo: configurable */ 1)
  1201. {
  1202. uMsg = WM_COMMAND;
  1203. wParam = WINAMP_MAIN_WINDOW;
  1204. }
  1205. }
  1206. else if (uMsg == WM_SETTINGCHANGE)
  1207. {
  1208. // used to track viewport changes so we can update
  1209. // e.g. when removing Win8's side-by-side app mode
  1210. if (wParam == SPI_SETWORKAREA)
  1211. {
  1212. KillTimer(wa2.getMainWindow(), VIEWPORT);
  1213. viewPort.x = -1;
  1214. viewPort.y = -1;
  1215. SetTimer(wa2.getMainWindow(), VIEWPORT, 100, ViewPortChanged);
  1216. }
  1217. }
  1218. else if (uMsg == WM_DISPLAYCHANGE)
  1219. {
  1220. DWORD b = CallWinampWndProc(hwndDlg, uMsg, wParam, lParam);
  1221. if (!m_in_skinrefresh) doplaylistcolors();
  1222. // filter out our internal skin updates
  1223. if (wParam && lParam)
  1224. {
  1225. KillTimer(wa2.getMainWindow(), VIEWPORT);
  1226. viewPort.x = LOWORD(lParam);
  1227. viewPort.y = HIWORD(lParam);
  1228. SetTimer(wa2.getMainWindow(), VIEWPORT, 100, ViewPortChanged);
  1229. }
  1230. return b;
  1231. }
  1232. else if (uMsg == WM_INITMENUPOPUP)
  1233. {
  1234. HMENU hmenuPopup = (HMENU) wParam;
  1235. if (hmenuPopup && hmenuPopup == mainSendTo.build_hMenu && mainSendTo.mode == 1)
  1236. {
  1237. int IPC_LIBRARY_SENDTOMENU = SendMessageW(plugin.hwndParent, WM_WA_IPC, (WPARAM)&"LibrarySendToMenu", IPC_REGISTER_WINAMP_IPCMESSAGE);
  1238. if (IPC_LIBRARY_SENDTOMENU > 65536 && SendMessageW(plugin.hwndParent, WM_WA_IPC, (WPARAM)&mainSendTo, IPC_LIBRARY_SENDTOMENU) == 0xffffffff)
  1239. mainSendTo.mode = 2;
  1240. }
  1241. if(hmenuPopup == wa2.getMenuBarMenu(Winamp2FrontEnd::WA2_MAINMENUBAR_PLAY))
  1242. {
  1243. CheckMenuItem((HMENU)wParam, WINAMP_FILE_SHUFFLE, wa2.getShuffle() ? MF_CHECKED : MF_UNCHECKED);
  1244. CheckMenuItem((HMENU)wParam, WINAMP_FILE_REPEAT, wa2.getRepeat() ? MF_CHECKED : MF_UNCHECKED);
  1245. }
  1246. if (hmenuPopup == wa2.getPopupMenu() ||
  1247. hmenuPopup == wa2.getMenuBarMenu(Winamp2FrontEnd::WA2_MAINMENUBAR_OPTIONS) ||
  1248. hmenuPopup == wa2.getMenuBarMenu(Winamp2FrontEnd::WA2_MAINMENUBAR_WINDOWS))
  1249. {
  1250. if (hmenuPopup == wa2.getMenuBarMenu(Winamp2FrontEnd::WA2_MAINMENUBAR_OPTIONS)) {
  1251. EnableMenuItem(hmenuPopup, WINAMP_OPTIONS_DSIZE,
  1252. MF_BYCOMMAND | (cfg_uioptions_uselocks.getValueAsInt() ? MF_ENABLED : MF_GRAYED));
  1253. }
  1254. if (hmenuPopup == wa2.getPopupMenu()){
  1255. EnableMenuItem(GetSubMenu(hmenuPopup, 11 + wa2.adjustOptionsPopupMenu(0)), WINAMP_OPTIONS_DSIZE,
  1256. MF_BYCOMMAND | (cfg_uioptions_uselocks.getValueAsInt() ? MF_ENABLED : MF_GRAYED));
  1257. }
  1258. populateWindowsMenus();
  1259. if ((HMENU)wParam == wa2.getPopupMenu())
  1260. {
  1261. for (int i = 0;i < SkinParser::getNumContainers();i++)
  1262. {
  1263. Container *cont = SkinParser::enumContainer(i);
  1264. if (!_wcsicmp(cont->getId(), L"main"))
  1265. {
  1266. CheckMenuItem((HMENU)wParam, WINAMP_MAIN_WINDOW, cont->isVisible() ? MF_CHECKED : MF_UNCHECKED);
  1267. break;
  1268. }
  1269. }
  1270. }
  1271. }
  1272. }
  1273. else if (uMsg == WM_SETFOCUS)
  1274. {
  1275. if (m_are_we_loaded && !switching_skin)
  1276. {
  1277. Container *c = SkinParser::getContainer(L"main");
  1278. if (c)
  1279. {
  1280. Layout *l = c->enumLayout(0);
  1281. if (l) l->setFocus();
  1282. }
  1283. return 1;
  1284. }
  1285. }
  1286. else if (uMsg == WM_WA_IPC)
  1287. {
  1288. if (lParam == DEFERREDCALLBACKMSG && DEFERREDCALLBACKMSG > 65536)
  1289. {
  1290. if (wParam == 1)
  1291. {
  1292. setDialogBoxesParent();
  1293. return 1;
  1294. }
  1295. else if (wParam == 2)
  1296. {
  1297. // embed the windows that are currently visible because at the time the window were originally shown,
  1298. // we hadn't been loaded yet
  1299. // but then again, we might if it's only a switch skin and not a app load, so let's check anyway
  1300. populateWindowsMenus();
  1301. doplaylistcolors();
  1302. if (plWnd == NULL && wa2.isWindowVisible(IPC_GETWND_PE))
  1303. if (!createPl()) wa2.setWindowVisible(IPC_GETWND_PE, 0);
  1304. #ifdef MINIBROWSER_SUPPORT
  1305. if (mbWnd == NULL && wa2.isWindowVisible(IPC_GETWND_MB))
  1306. if (!createMb()) wa2.setWindowVisible(IPC_GETWND_MB, 0);
  1307. #endif
  1308. if (vidWnd == NULL && wa2.isWindowVisible(IPC_GETWND_VIDEO))
  1309. if (!createVid()) wa2.setWindowVisible(IPC_GETWND_VIDEO, 0);
  1310. embedEnumStruct cs = { embedCreateProc, 0 };
  1311. SendMessageW(hwndDlg, WM_WA_IPC, (WPARAM)&cs, IPC_EMBED_ENUM);
  1312. for (int i = 0;i < SkinParser::getNumContainers();i++)
  1313. {
  1314. Container *cont = SkinParser::enumContainer(i);
  1315. if (!_wcsicmp(cont->getId(), L"main"))
  1316. {
  1317. for (int j = 0;j < cont->getNumLayouts();j++)
  1318. {
  1319. Layout *l = cont->enumLayout(j);
  1320. if (l && l->isVisible())
  1321. {
  1322. SetFocus(l->gethWnd());
  1323. break;
  1324. }
  1325. }
  1326. }
  1327. }
  1328. Crossfader::onOutputChanged();
  1329. extern int make_sure_library_is_here_at_startup;
  1330. if (make_sure_library_is_here_at_startup)
  1331. SendMessageW(wa2.getMainWindow(), WM_COMMAND, ID_FILE_SHOWLIBRARY, 0);
  1332. make_sure_library_is_here_at_startup = 0;
  1333. before_startup_callback = 0;
  1334. registerGlobalHotkeys();
  1335. // force a title update since it's not always correct
  1336. // if gen_ml hasn't loaded fully when we're loading
  1337. if (wa2.isPlaying())
  1338. g_Core->gotCallback(IPC_CB_MISC_TITLE, 2);
  1339. return 1;
  1340. }
  1341. }
  1342. else if (lParam == UPDATEDIALOGBOXPARENTMSG && UPDATEDIALOGBOXPARENTMSG > 65536)
  1343. {
  1344. wa2.updateDialogBoxParent((HWND)wParam);
  1345. }
  1346. else switch (lParam)
  1347. {
  1348. case IPC_GETSKININFO:
  1349. return (LRESULT)getSkinInfo();
  1350. case IPC_GETSKININFOW:
  1351. return (LRESULT)getSkinInfoW();
  1352. case IPC_SHOW_NOTIFICATION:
  1353. return SystemObject::onShowNotification();
  1354. case IPC_CB_VISRANDOM:
  1355. {
  1356. int v = wParam;
  1357. extern _bool visrandom;
  1358. if (!!v == !!visrandom.getValueAsInt()) break;
  1359. disable_send_visrandom = 1;
  1360. visrandom.setValueAsInt(v);
  1361. disable_send_visrandom = 0;
  1362. break;
  1363. }
  1364. case IPC_CB_OUTPUTCHANGED:
  1365. Crossfader::onOutputChanged();
  1366. break;
  1367. case IPC_CB_ONTOGGLEAOT:
  1368. {
  1369. if ((WPARAM)cfg_options_alwaysontop.getValueAsInt() != wParam)
  1370. cfg_options_alwaysontop.setValueAsInt(wParam);
  1371. break;
  1372. }
  1373. case IPC_SETIDEALVIDEOSIZE:
  1374. {
  1375. wa2.setIdealVideoSize(HIWORD(wParam), LOWORD(wParam));
  1376. break;
  1377. }
  1378. // this is where we detect that wa2 wants to open one of its windows (thru popup menu, button, whatever)
  1379. // when this happens, we create a freeform wndembedder if one doesn't already exist. that embedder will
  1380. // reparent and resize the wa2 window on its own. when we return, winamp then shows the HWND inside our frame
  1381. // as it would show the HWND as a popup normally.
  1382. case IPC_CB_ONSHOWWND:
  1383. switch (wParam)
  1384. {
  1385. case IPC_CB_WND_PE:
  1386. if (!createPl()) return 0;
  1387. break;
  1388. #ifdef MINIBROWSER_SUPPORT
  1389. case IPC_CB_WND_MB:
  1390. if (!createMb()) return 0;
  1391. break;
  1392. #endif
  1393. case IPC_CB_WND_VIDEO:
  1394. #ifdef VIDDEBUG
  1395. DebugString("Video : Got IPC_ONSHOW\n");
  1396. #endif
  1397. if (!createVid())
  1398. {
  1399. #ifdef VIDDEBUG
  1400. DebugString("Video : SHOW was cancelled by script\n");
  1401. #endif
  1402. return 0;
  1403. }
  1404. break;
  1405. default:
  1406. DebugStringW(L"embedWnd : Got IPC_ONSHOW\n");
  1407. if (IsWindow((HWND)wParam))
  1408. {
  1409. HWND hTarget = (HWND)wParam;
  1410. embedWindowState *ws = (embedWindowState*)GetWindowLongPtrW(hTarget, GWLP_USERDATA);
  1411. if (ws && ws->me == hTarget)
  1412. {
  1413. GUID thisguid = EmbedWndGuid(ws).getGuid();
  1414. if (INVALID_GUID == thisguid || NULL == updateEmb(thisguid, ws))
  1415. {
  1416. ifc_window *windowParent = createEmb(ws, true);
  1417. if (NULL != windowParent)
  1418. {
  1419. GuiObject *uiObject = windowParent->getGuiObject();
  1420. if (NULL != uiObject)
  1421. {
  1422. if (0 != (EMBED_FLAGS_FFCALLBACK & ws->flags) &&
  1423. NULL != ws->callback)
  1424. {
  1425. ws->callback(ws, FFC_CREATEEMBED, (LPARAM)windowParent);
  1426. }
  1427. Layout *layout = uiObject->guiobject_getParentLayout();
  1428. if (NULL != layout)
  1429. {
  1430. Container *container = layout->getParentContainer();
  1431. if (NULL != container) container->setVisible(1);
  1432. else layout->setVisible(1);
  1433. windowParent->setVisible(1);
  1434. }
  1435. }
  1436. }
  1437. return (NULL != windowParent);
  1438. }
  1439. }
  1440. }
  1441. break;
  1442. }
  1443. break;
  1444. // here we do the reverse, we detect that wa2 wants to close one of its windows, so we destroy our window
  1445. // embedder (it will reparent the wa2 window back to its former parent and resize it back to where it was
  1446. // on its own). when we return, winamp then hides the window.
  1447. // NOTE! because of this, there might be a split second where the window is seen on the screen as a popup
  1448. // after you closed the window (this won't happen for static containers [ie: pledit/video in mmd3] since
  1449. // they are hidden rather than destroyed). this can be fixed in the future
  1450. case IPC_CB_ONHIDEWND:
  1451. switch (wParam)
  1452. {
  1453. case IPC_CB_WND_PE:
  1454. destroyPl(hwndDlg, uMsg, wParam, lParam);
  1455. break;
  1456. #ifdef MINIBROWSER_SUPPORT
  1457. case IPC_CB_WND_MB:
  1458. return destroyMb(hwndDlg, uMsg, wParam, lParam);
  1459. #endif
  1460. case IPC_CB_WND_VIDEO:
  1461. #ifdef VIDDEBUG
  1462. DebugString("Video : Got IPC_ONHIDE\n");
  1463. #endif
  1464. return destroyVid(hwndDlg, uMsg, wParam, lParam);
  1465. default:
  1466. DebugStringW(L"embedWnd : Got IPC_ONHIDE\n");
  1467. if (IsWindow((HWND)wParam))
  1468. {
  1469. HWND h = (HWND)wParam;
  1470. embedWindowState *ws = (embedWindowState *)GetWindowLongPtrW(h, GWLP_USERDATA);
  1471. if (ws) return destroyEmb(hwndDlg, uMsg, wParam, lParam, ws);
  1472. }
  1473. break;
  1474. }
  1475. break;
  1476. case IPC_FF_ISMAINWND:
  1477. {
  1478. for (int i = 0;i < SkinParser::getNumContainers();i++)
  1479. {
  1480. Container *cont = SkinParser::enumContainer(i);
  1481. if (!_wcsicmp(cont->getId(), L"main"))
  1482. {
  1483. for (int j = 0;j < cont->getNumLayouts();j++)
  1484. {
  1485. if (cont->enumLayout(j)->gethWnd() == (HWND)wParam) return 1;
  1486. }
  1487. break;
  1488. }
  1489. }
  1490. return 0;
  1491. }
  1492. case IPC_FF_GETCONTENTWND:
  1493. return (LRESULT)ff_ipc_getContentWnd((HWND)wParam);
  1494. case IPC_FF_GETSKINCOLOR:
  1495. ff_ipc_getSkinColor((ff_skincolor*)wParam);
  1496. return 1;
  1497. case IPC_FF_GENSKINBITMAP:
  1498. ff_ipc_genSkinBitmap((ff_skinbitmap*)wParam);
  1499. return 1;
  1500. case IPC_FF_NOTIFYHOTKEY:
  1501. if (processGenericHotkey((const char *)wParam)) return 0; // prevent gen_hotkey from processing the hotkey
  1502. return 1; // let gen_hotkey process the hotkey
  1503. case IPC_GET_GENSKINBITMAP:
  1504. if (m_are_we_loaded)
  1505. {
  1506. if (wParam == 0)
  1507. {
  1508. if (m_lastskin_dir[0])
  1509. {
  1510. HBITMAP bm;
  1511. wchar_t bitmapfilename[MAX_PATH] = {0};
  1512. PathCombineW(bitmapfilename, m_lastskin_dir, L"genex.bmp");
  1513. bm = (HBITMAP)LoadImageW(NULL, bitmapfilename, IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION | LR_LOADFROMFILE);
  1514. if (bm) return (LRESULT)bm;
  1515. }
  1516. return (LRESULT)ff_genwa2skinbitmap();
  1517. }
  1518. else if (wParam == 4)
  1519. {
  1520. // TODO need to make sure we're covering everything needed for all of this!!
  1521. int buf[6] = {0};
  1522. // active text
  1523. if (WASABI_API_SKIN->skin_getColorElementRef(L"wasabi.list.text.current"))
  1524. buf[1] = SkinColor(L"wasabi.list.text.current");
  1525. /*else
  1526. {
  1527. COLORREF act = Blenders::BLEND_AVG(selected, buf[0]);
  1528. act = (lumidiff(act, buf[0]) < 0x3F || lumidiff(act, buf[2]) < 0x2F) ? Blenders::BLEND_AVG(buf[2], 0xFFFFFFFF) : act;
  1529. act = (lumidiff(act, buf[0]) < 0x3F || lumidiff(act, buf[2]) < 0x2F) ? Blenders::BLEND_AVG(buf[2], 0xFF101010) : act;
  1530. act = (lumidiff(act, buf[0]) < 0x3F || lumidiff(act, buf[2]) < 0x2F) ? Blenders::BLEND_AVG(selected, buf[0]) : act;
  1531. act = (lumidiff(act, buf[0]) < 0x3F || lumidiff(act, buf[2]) < 0x2F) ? Blenders::BLEND_AVG(selected, buf[2]) : act;
  1532. act = (lumidiff(act, buf[0]) < 0x3F || lumidiff(act, buf[2]) < 0x2F) ? Blenders::BLEND_AVG(buf[0], buf[2]) : act;
  1533. buf[1] = act & 0xFFFFFF;
  1534. }*/
  1535. return buf[1];
  1536. }
  1537. }
  1538. break;
  1539. case IPC_FF_ONCOLORTHEMECHANGED:
  1540. {
  1541. embedEnumStruct cs = { embedUpdateColorProc, 0 };
  1542. SendMessageW(hwndDlg, WM_WA_IPC, (WPARAM)&cs, IPC_EMBED_ENUM);
  1543. if (wParam != 0xf00d) doplaylistcolors();
  1544. }
  1545. break;
  1546. case IPC_PLAYLIST_MODIFIED:
  1547. {
  1548. Wa2PlaylistEditor::_onPlaylistModified();
  1549. }
  1550. break;
  1551. }
  1552. }
  1553. else if (uMsg == WM_COMMAND && (LOWORD(wParam) == 40144 || LOWORD(wParam) == 40148))
  1554. {
  1555. // seek left/right, we need to disable them if we are in a menu, because this is a
  1556. // plugin (ie: milkdrop) sending us the command manually as a forward rather than
  1557. // sending us the WM_KEY* directly
  1558. if (WASABI_API_WND->isKeyboardLocked()) return 0;
  1559. }
  1560. else if ((uMsg == WM_COMMAND || uMsg == WM_SYSCOMMAND) && LOWORD(wParam) >= 43000 && LOWORD(wParam) < ffwindowstop)
  1561. {
  1562. int id = LOWORD(wParam) - 43000;
  1563. int n = SkinParser::getNumContainers();
  1564. if (id < n)
  1565. {
  1566. Container *cont = SkinParser::enumContainer(id);
  1567. if (cont) cont->toggle();
  1568. return 1;
  1569. }
  1570. id -= n;
  1571. n = WASABI_API_WNDMGR->autopopup_getNumGuids();
  1572. if (id < n)
  1573. {
  1574. GUID guid = WASABI_API_WNDMGR->autopopup_enumGuid(id);
  1575. if (guid != INVALID_GUID)
  1576. WASABI_API_WNDMGR->skinwnd_toggleByGuid(guid);
  1577. return 1;
  1578. }
  1579. id -= n;
  1580. n = WASABI_API_WNDMGR->autopopup_getNumGroups();
  1581. if (id < n)
  1582. {
  1583. const wchar_t *gid = WASABI_API_WNDMGR->autopopup_enumGroup(id);
  1584. if (gid && *gid)
  1585. WASABI_API_WNDMGR->skinwnd_toggleByGroupId(gid);
  1586. return 1;
  1587. }
  1588. /* for (int c=0;c<SkinParser::getNumContainers();c++) {
  1589. Container *cont = SkinParser::enumContainer(c);
  1590. if (cont && wantContainerInMenu(cont)) {
  1591. if (cont->getName() == NULL) continue;
  1592. if (id == 0) {
  1593. if (cont)
  1594. cont->toggle();
  1595. return 1;
  1596. }
  1597. id--;
  1598. }
  1599. }
  1600. int n = WASABI_API_WNDMGR->autopopup_getNumGuids();
  1601. for (c=0;c<n;c++) {
  1602. GUID guid = WASABI_API_WNDMGR->autopopup_enumGuid(c);
  1603. const char *groupdesc = WASABI_API_WNDMGR->autopopup_enumGuidDescription(c);
  1604. if (guid != INVALID_GUID && groupdesc && *groupdesc) {
  1605. if (id == 0) {
  1606. WASABI_API_WNDMGR->skinwnd_toggleByGuid(guid);
  1607. return 1;
  1608. }
  1609. id--;
  1610. }
  1611. }
  1612. n = WASABI_API_WNDMGR->autopopup_getNumGroups();
  1613. for (c=0;c<n;c++) {
  1614. const char *gid = WASABI_API_WNDMGR->autopopup_enumGroup(c);
  1615. const char *groupdesc = WASABI_API_WNDMGR->autopopup_enumGroupDescription(c);
  1616. if (id && groupdesc && *gid && *groupdesc) {
  1617. if (id == 0) {
  1618. WASABI_API_WNDMGR->skinwnd_toggleByGroupId(gid);
  1619. return 1;
  1620. }
  1621. id--;
  1622. }
  1623. }*/
  1624. return 0;
  1625. }
  1626. else if ((uMsg == WM_COMMAND || uMsg == WM_SYSCOMMAND) && LOWORD(wParam) >= 44000 && LOWORD(wParam) < ffoptionstop)
  1627. {
  1628. int id = LOWORD(wParam);
  1629. MenuActions::toggleOption(id - 44000);
  1630. }
  1631. else if ((uMsg == WM_COMMAND || uMsg == WM_SYSCOMMAND) && LOWORD(wParam) >= 44500 && LOWORD(wParam) < 45000)
  1632. {
  1633. int id = LOWORD(wParam) - 44500;
  1634. WASABI_API_SKIN->colortheme_setColorSet(WASABI_API_SKIN->colortheme_enumColorSet(id));
  1635. }
  1636. else if ((uMsg == WM_COMMAND || uMsg == WM_SYSCOMMAND) && LOWORD(wParam) >= 42000 && LOWORD(wParam) < ffwoptionstop)
  1637. {
  1638. int id = LOWORD(wParam);
  1639. MenuActions::toggleWindowOption(id - 42000);
  1640. }
  1641. else if ((uMsg == WM_COMMAND || uMsg == WM_SYSCOMMAND) && LOWORD(wParam) == WINAMP_MAIN_WINDOW)
  1642. {
  1643. for (int i = 0;i < SkinParser::getNumContainers();i++)
  1644. {
  1645. Container *cont = SkinParser::enumContainer(i);
  1646. if (!_wcsicmp(cont->getId(), L"main"))
  1647. {
  1648. cont->toggle();
  1649. return 1;
  1650. }
  1651. }
  1652. }
  1653. else if ((uMsg == WM_COMMAND || uMsg == WM_SYSCOMMAND) && LOWORD(wParam) == WINAMP_OPTIONS_EQ)
  1654. {
  1655. if (!gothrueqmsg)
  1656. return 0;
  1657. }
  1658. else if ((uMsg == WM_COMMAND || uMsg == WM_SYSCOMMAND))
  1659. {
  1660. switch (LOWORD(wParam))
  1661. {
  1662. case ID_CONTROLMENU_OPACITY_10: controlOpacity(10); return 0;
  1663. case ID_CONTROLMENU_OPACITY_20: controlOpacity(20); return 0;
  1664. case ID_CONTROLMENU_OPACITY_30: controlOpacity(30); return 0;
  1665. case ID_CONTROLMENU_OPACITY_40: controlOpacity(40); return 0;
  1666. case ID_CONTROLMENU_OPACITY_50: controlOpacity(50); return 0;
  1667. case ID_CONTROLMENU_OPACITY_60: controlOpacity(60); return 0;
  1668. case ID_CONTROLMENU_OPACITY_70: controlOpacity(70); return 0;
  1669. case ID_CONTROLMENU_OPACITY_80: controlOpacity(80); return 0;
  1670. case ID_CONTROLMENU_OPACITY_90: controlOpacity(90); return 0;
  1671. case ID_CONTROLMENU_OPACITY_100: controlOpacity(100); return 0;
  1672. case ID_CONTROLMENU_SCALING_50: controlScaling(0.5); return 0;
  1673. case ID_CONTROLMENU_SCALING_75: controlScaling(0.75); return 0;
  1674. case ID_CONTROLMENU_SCALING_100: controlScaling(1.0); return 0;
  1675. case ID_CONTROLMENU_SCALING_125: controlScaling(1.25); return 0;
  1676. case ID_CONTROLMENU_SCALING_150: controlScaling(1.5); return 0;
  1677. case ID_CONTROLMENU_SCALING_200: controlScaling(2.0); return 0;
  1678. case ID_CONTROLMENU_SCALING_250: controlScaling(2.5); return 0;
  1679. case ID_CONTROLMENU_SCALING_300: controlScaling(3.0); return 0;
  1680. case ID_CONTROLMENU_SCALING_LOCKED: lockScaling(1); return 0;
  1681. case ID_CONTROLMENU_SCALING_FOLLOWDOUBLESIZE: lockScaling(0); return 0;
  1682. case ID_CONTROLMENU_SCALING_CUSTOM: customScaling(); return 0;
  1683. case ID_CONTROLMENU_OPACITY_CUSTOM: customOpacity(); return 0;
  1684. case ID_CONTROLMENU_OPACITY_AUTO100_HOVER: autoOpacifyHover(); return 0;
  1685. case ID_CONTROLMENU_OPACITY_AUTO100_FOCUS: autoOpacifyFocus(); return 0;
  1686. case SC_MOVE:
  1687. {
  1688. Layout *l = SkinParser::getMainLayout();
  1689. if (l != NULL)
  1690. {
  1691. Container *c = l->getParentContainer();
  1692. if (c)
  1693. {
  1694. Layout *ll = c->getCurrentLayout();
  1695. if (ll) l = ll;
  1696. if (l)
  1697. {
  1698. if (!l->isVisible()) l->setVisible(1);
  1699. return SendMessageW(l->gethWnd(), WM_SYSCOMMAND, wParam, lParam);
  1700. }
  1701. }
  1702. }
  1703. break;
  1704. }
  1705. case ID_CONTROLMENU_TOOLBAR_DISABLED: controlAppBar(APPBAR_NOTDOCKED); break;
  1706. case ID_CONTROLMENU_TOOLBAR_TOP: controlAppBar(APPBAR_TOP); break;
  1707. case ID_CONTROLMENU_TOOLBAR_LEFT: controlAppBar(APPBAR_LEFT); break;
  1708. case ID_CONTROLMENU_TOOLBAR_RIGHT: controlAppBar(APPBAR_RIGHT); break;
  1709. case ID_CONTROLMENU_TOOLBAR_BOTTOM: controlAppBar(APPBAR_BOTTOM); break;
  1710. case ID_CONTROLMENU_TOOLBAR_ALWAYSONTOP: controlAppBarAOT(); break;
  1711. case ID_CONTROLMENU_TOOLBAR_AUTOHIDE: controlAppBarAH(); break;
  1712. case ID_CONTROLMENU_TOOLBAR_AUTODOCKONDRAG: cfg_options_appbarondrag = !cfg_options_appbarondrag; break;
  1713. }
  1714. }
  1715. }
  1716. return CallWinampWndProc(hwndDlg, uMsg, wParam, lParam);
  1717. }
  1718. void onLayoutChanged()
  1719. {
  1720. if (DEFERREDCALLBACKMSG > 65536)
  1721. PostMessage(wa2.getMainWindow(), WM_WA_IPC, 1, DEFERREDCALLBACKMSG);
  1722. }
  1723. #ifdef DEBUG_CAPTURES
  1724. int tid = 0;
  1725. VOID TimerProc(HWND hwnd, UINT uMsg, UINT idEvent, DWORD time)
  1726. {
  1727. DebugString("Capture belongs to %x (foregroundwnd = %x)\n", GetCapture(), GetForegroundWindow());
  1728. }
  1729. #endif
  1730. template <class api_T>
  1731. static void ServiceBuild(api_T *&api_t, GUID factoryGUID_t)
  1732. {
  1733. if (WASABI_API_SVC)
  1734. {
  1735. waServiceFactory *factory = WASABI_API_SVC->service_getServiceByGuid(factoryGUID_t);
  1736. if (factory)
  1737. api_t = reinterpret_cast<api_T *>( factory->getInterface() );
  1738. }
  1739. }
  1740. template <class api_T>
  1741. static void ServiceRelease(api_T *api_t, GUID factoryGUID_t)
  1742. {
  1743. if (WASABI_API_SVC && api_t)
  1744. {
  1745. waServiceFactory *factory = WASABI_API_SVC->service_getServiceByGuid(factoryGUID_t);
  1746. if (factory)
  1747. factory->releaseInterface(api_t);
  1748. }
  1749. api_t = NULL;
  1750. }
  1751. //-----------------------------------------------------------------------------------------------
  1752. // initializes freeform library
  1753. //-----------------------------------------------------------------------------------------------
  1754. int m_loaded_at_all = 0;
  1755. StringW g_resourcepath;
  1756. void initFFApi()
  1757. {
  1758. if ( !m_loaded_at_all )
  1759. {
  1760. m_loaded_at_all = 1;
  1761. api_service *svc = (api_service *)SendMessageW( wa2.getMainWindow(), WM_WA_IPC, 0, IPC_GET_API_SERVICE );
  1762. ServiceBuild( AGAVE_API_PLAYLISTS, api_playlistsGUID );
  1763. ServiceBuild( AGAVE_API_ALBUMART, albumArtGUID );
  1764. ServiceBuild( AGAVE_API_PLAYLISTMANAGER, api_playlistmanagerGUID );
  1765. ServiceBuild( WAC_API_DOWNLOADMANAGER, DownloadManagerGUID );
  1766. ServiceBuild( WASABI_API_COLORTHEMES, ColorThemesAPIGUID );
  1767. ServiceBuild( WASABI_API_PALETTE, PaletteManagerGUID );
  1768. ServiceBuild( WASABI_API_THREADPOOL, ThreadPoolGUID );
  1769. ApiInit::init( hInstance, wa2.getMainWindow(), svc );
  1770. cfgitems = new Wa2CfgItems();
  1771. #ifdef DEBUG_CAPTURES
  1772. tid = SetTimer( NULL, 0x159, 50, (TIMERPROC)TimerProc );
  1773. #endif
  1774. wchar_t filename[ WA_MAX_PATH ] = { 0 };
  1775. GetModuleFileNameW( hInstance, filename, WA_MAX_PATH );
  1776. PathParserW pp( filename );
  1777. StringW path;
  1778. for ( int i = 0; i < pp.getNumStrings() - 1; i++ )
  1779. {
  1780. path.AppendPath( pp.enumString( i ) );
  1781. }
  1782. path.AppendPath( L"freeform" );
  1783. path.AppendFolder( L"wacs" );
  1784. // we can load a somewhat restricted version of the wac format
  1785. ComponentManager::loadAll( path );
  1786. ComponentManager::postLoad();
  1787. ApiInit::widgets->loadResources();
  1788. startFSMonitor();
  1789. }
  1790. cfg_options_alwaysontop.setValueAsInt( wa2.isOnTop() );
  1791. }
  1792. //-----------------------------------------------------------------------------------------------
  1793. // shutdown ff lib
  1794. //-----------------------------------------------------------------------------------------------
  1795. void shutdownFFApi()
  1796. {
  1797. if (m_loaded_at_all)
  1798. {
  1799. ServiceRelease( AGAVE_API_PLAYLISTS, api_playlistsGUID);
  1800. ServiceRelease( AGAVE_API_ALBUMART, albumArtGUID);
  1801. ServiceRelease( AGAVE_API_PLAYLISTMANAGER, api_playlistmanagerGUID);
  1802. ServiceRelease( WAC_API_DOWNLOADMANAGER, DownloadManagerGUID);
  1803. ServiceRelease( WASABI_API_COLORTHEMES, ColorThemesAPIGUID);
  1804. ServiceRelease( WASABI_API_PALETTE, PaletteManagerGUID);
  1805. ServiceRelease( WASABI_API_THREADPOOL, ThreadPoolGUID);
  1806. stopFSMonitor();
  1807. // shutdown the library
  1808. #ifdef DEBUG_CAPTURES
  1809. KillTimer(NULL, tid);
  1810. #endif
  1811. delete cfgitems; cfgitems = NULL;
  1812. ApiInit::shutdown();
  1813. ComponentManager::unloadAll();
  1814. m_loaded_at_all = 0;
  1815. }
  1816. }
  1817. static void MakeControlMenu()
  1818. {
  1819. if (controlmenu)
  1820. return ;
  1821. controlmenu = WASABI_API_LOADMENU(IDR_CONTROLMENU);
  1822. if (!Wasabi::Std::Wnd::isDesktopAlphaAvailable())
  1823. EnableMenuItem(controlmenu, 0, MF_BYPOSITION | MF_GRAYED);
  1824. }
  1825. //-----------------------------------------------------------------------------------------------
  1826. // go freeform
  1827. //-----------------------------------------------------------------------------------------------
  1828. void init_inst()
  1829. {
  1830. if ( m_are_we_loaded )
  1831. return;
  1832. // set the classic main window to be transparent
  1833. // so we can move it around the screen to allow
  1834. // certain Windows 8 modes as well as improving
  1835. // where it is placed for some multi-mon setups
  1836. Wasabi::Std::Wnd::setLayeredWnd( wa2.getMainWindow(), 1 );
  1837. Wasabi::Std::Wnd::setLayeredAlpha( wa2.getMainWindow(), 0 );
  1838. initEgg();
  1839. wa2.setDrawBorders( 0 );
  1840. wa2.disableSkinnedCursors( 1 );
  1841. int wasminimized = IsIconic( wa2.getMainWindow() );
  1842. if ( wasminimized )
  1843. ShowWindow( wa2.getMainWindow(), SW_RESTORE );
  1844. MakeControlMenu();
  1845. going_freeform = 1;
  1846. Wa2WndEmbed::rememberVisibleWindows();
  1847. if ( wa2.isWindowVisible( IPC_GETWND_PE ) )
  1848. {
  1849. if ( !m_loading_at_startup ) WritePrivateProfileStringW( L"gen_ff", L"classicpe", L"1", INI_FILE );
  1850. }
  1851. else
  1852. if ( !m_loading_at_startup ) WritePrivateProfileStringW( L"gen_ff", L"classicpe", L"0", INI_FILE );
  1853. if ( wa2.isWindowVisible( IPC_GETWND_EQ ) )
  1854. {
  1855. gothrueqmsg = 1;
  1856. SendMessageW( plugin.hwndParent, WM_COMMAND, WINAMP_OPTIONS_EQ, 0 );
  1857. gothrueqmsg = 0;
  1858. if ( !m_loading_at_startup ) WritePrivateProfileStringW( L"gen_ff", L"classiceq", L"1", INI_FILE );
  1859. }
  1860. else
  1861. if ( !m_loading_at_startup ) WritePrivateProfileStringW( L"gen_ff", L"classiceq", L"0", INI_FILE );
  1862. removeEq();
  1863. if ( SendMessageW( plugin.hwndParent, WM_WA_IPC, 0, IPC_ISMAINWNDVISIBLE ) )
  1864. {
  1865. SendMessageW( plugin.hwndParent, WM_COMMAND, WINAMP_MAIN_WINDOW, 0 );
  1866. if ( !m_loading_at_startup ) WritePrivateProfileStringW( L"gen_ff", L"classicmw", L"1", INI_FILE );
  1867. }
  1868. else
  1869. if ( !m_loading_at_startup ) WritePrivateProfileStringW( L"gen_ff", L"classicmw", L"0", INI_FILE );
  1870. m_are_we_loaded = 1;
  1871. initFFApi();
  1872. // redirect drag and drop to winamp2 by default
  1873. WASABI_API_WND->setDefaultDropTarget( (void *)wa2.getDropTarget() );
  1874. // this installs a bunch of predefined groups to map wa3 to wa2 functionnality
  1875. groups = new Wa2Groupdefs();
  1876. // now load a skin ! the path to the skin is extracted and temporarilly becomes the official skins directory
  1877. StringW skinname = m_lastskin_nam;
  1878. removeSkinExtension( skinname );
  1879. before_startup_callback = 1;
  1880. WASABI_API_SKIN->skin_switchSkin( skinname, m_lastskin_dir );
  1881. /* // if we wanted to have drag&drop support for just the main window, we'd do it this way :-)
  1882. Container *maincontainer = SkinParser::getContainer("main");
  1883. if (maincontainer != NULL) {
  1884. for (int i=0;i<maincontainer->getNumLayouts();i++) {
  1885. Layout *layout = maincontainer->enumLayout(i);
  1886. if (layout != NULL) {
  1887. layout->setDropTarget((void *)wa2.getDropTarget());
  1888. }
  1889. }
  1890. }*/
  1891. // send event for dialog parent
  1892. onLayoutChanged();
  1893. if ( wa2.export_sa_setreq )
  1894. wa2.export_sa_setreq( 1 );
  1895. shuffle.setValueAsInt( wa2.getShuffle() );
  1896. int rep = wa2.getRepeat();
  1897. int manadv = wa2.getManualPlaylistAdvance();
  1898. disable_set_wa2_repeat = 1;
  1899. repeat.setValueAsInt( ( rep && manadv ) ? -1 : rep );
  1900. disable_set_wa2_repeat = 0;
  1901. if ( DEFERREDCALLBACKMSG > 65536 )
  1902. PostMessage( wa2.getMainWindow(), WM_WA_IPC, 2, DEFERREDCALLBACKMSG );
  1903. // so if some embedwindows are already visible, they update their look
  1904. PostMessage( wa2.getMainWindow(), WM_WA_IPC, 0xf00d, IPC_FF_ONCOLORTHEMECHANGED );
  1905. // monitor color theme
  1906. colorThemeMonitor = new ColorThemeMonitor();
  1907. syncDoubleSize( 1 );
  1908. syncDisplayMode();
  1909. going_freeform = 0;
  1910. if ( wa2.getWnd( IPC_GETWND_VIDEO ) )
  1911. {
  1912. oldVideoWnd = wa2.getWnd( IPC_GETWND_VIDEO );
  1913. if ( !oldVideoWndProc )
  1914. oldVideoWndProc = (WNDPROC)SetWindowLongPtrW( oldVideoWnd, GWLP_WNDPROC, (LONG_PTR)newVideoWndProc );
  1915. }
  1916. if ( wasminimized )
  1917. ShowWindow( wa2.getMainWindow(), SW_MINIMIZE );
  1918. if ( eggstat )
  1919. SetTimer( wa2.getMainWindow(), UPDATE_EGG, 25, NULL );
  1920. }
  1921. void quit_inst()
  1922. {
  1923. if (!m_are_we_loaded) return ;
  1924. KillTimer(wa2.getMainWindow(), UPDATE_EGG);
  1925. wa2.setDrawBorders(1);
  1926. wa2.disableSkinnedCursors(0);
  1927. KillTimer(wa2.getMainWindow(), 0xC0DE);
  1928. KillTimer(wa2.getMainWindow(), 0xC0DE + 1);
  1929. EnableMenuItem(wa2.getMenuBarMenu(Winamp2FrontEnd::WA2_MAINMENUBAR_OPTIONS), WINAMP_OPTIONS_DSIZE, MF_ENABLED);
  1930. EnableMenuItem(GetSubMenu(wa2.getPopupMenu(), 11 + wa2.adjustOptionsPopupMenu(0)), WINAMP_OPTIONS_DSIZE, MF_ENABLED);
  1931. if (oldVideoWnd && oldVideoWndProc)
  1932. SetWindowLongPtrW(oldVideoWnd, GWLP_WNDPROC, (LONG_PTR)oldVideoWndProc);
  1933. oldVideoWndProc = 0;
  1934. oldVideoWnd = 0;
  1935. removeWindowOptionsFromContextMenu();
  1936. delete mainLayoutMonitor;
  1937. mainLayoutMonitor=0;
  1938. wa2.setDialogBoxParent(NULL);
  1939. unpopulateWindowsMenus();
  1940. restoreEq();
  1941. // unload the skin -- skinspath is restored to default
  1942. WASABI_API_SKIN->skin_unloadSkin();
  1943. // delete predefined groups service
  1944. delete groups; groups = NULL;
  1945. // delete options
  1946. delete ffoptions; ffoptions = NULL;
  1947. // stop monitoring color theme
  1948. delete colorThemeMonitor; colorThemeMonitor = NULL;
  1949. if (wa2.export_sa_setreq) wa2.export_sa_setreq(0);
  1950. m_are_we_loaded = 0;
  1951. int classicmw = GetPrivateProfileIntW(L"gen_ff", L"classicmw", 1, INI_FILE);
  1952. if (classicmw && !SendMessageW(plugin.hwndParent, WM_WA_IPC, 0, IPC_ISMAINWNDVISIBLE))
  1953. SendMessageW(plugin.hwndParent, WM_COMMAND, WINAMP_MAIN_WINDOW, 0);
  1954. CheckMenuItem(wa2.getPopupMenu(), WINAMP_MAIN_WINDOW, classicmw ? MF_CHECKED : MF_UNCHECKED);
  1955. if (GetPrivateProfileIntW(L"gen_ff", L"classiceq", 1, INI_FILE) && !wa2.isWindowVisible(IPC_GETWND_EQ))
  1956. {
  1957. gothrueqmsg = 1;
  1958. SendMessageW(plugin.hwndParent, WM_COMMAND, WINAMP_OPTIONS_EQ, 0);
  1959. gothrueqmsg = 0;
  1960. }
  1961. if (GetPrivateProfileIntW(L"gen_ff", L"classicpe", 1, INI_FILE) && !wa2.isWindowVisible(IPC_GETWND_PE))
  1962. {
  1963. SendMessageW(plugin.hwndParent, WM_COMMAND, WINAMP_OPTIONS_PLEDIT, 0);
  1964. }
  1965. // restore the classic main window to be solid
  1966. Wasabi::Std::Wnd::setLayeredWnd(wa2.getMainWindow(), 0);
  1967. }
  1968. //-----------------------------------------------------------------------------------------------
  1969. // init (from Winamp2)
  1970. //-----------------------------------------------------------------------------------------------
  1971. int init()
  1972. {
  1973. // loader so that we can get the localisation service api for use
  1974. WASABI_API_SVC = (api_service*) SendMessageW(plugin.hwndParent, WM_WA_IPC, 0, IPC_GET_API_SERVICE);
  1975. if (WASABI_API_SVC == (api_service*)1) WASABI_API_SVC = NULL;
  1976. if (!WASABI_API_SVC || WASABI_API_SVC == (api_service *)1)
  1977. return GEN_INIT_FAILURE;
  1978. static wchar_t modskin[128];
  1979. INI_FILE = (wchar_t*) SendMessageW(plugin.hwndParent, WM_WA_IPC, 0, IPC_GETINIFILEW);
  1980. INI_DIR = (wchar_t*) SendMessageW(plugin.hwndParent, WM_WA_IPC, 0, IPC_GETINIDIRECTORYW);
  1981. waServiceFactory *sf = WASABI_API_SVC->service_getServiceByGuid(languageApiGUID);
  1982. if (sf) WASABI_API_LNG = reinterpret_cast<api_language*>(sf->getInterface());
  1983. // need to have this initialised before we try to do anything with localisation features
  1984. WASABI_API_START_LANG(plugin.hDllInstance,GenFFLangGUID);
  1985. swprintf(szDescription, ARRAYSIZE(szDescription),
  1986. WASABI_API_LNGSTRINGW(IDS_NULLSOFT_MODERN_SKINS), VERSION);
  1987. plugin.description = (char*)szDescription;
  1988. wa2.init(plugin.hwndParent);
  1989. DEFERREDCALLBACKMSG = SendMessageW(plugin.hwndParent, WM_WA_IPC, (WPARAM)"gen_ff_deferred", IPC_REGISTER_WINAMP_IPCMESSAGE);
  1990. UPDATEDIALOGBOXPARENTMSG = SendMessageW(plugin.hwndParent, WM_WA_IPC, (WPARAM)"gen_ff_update", IPC_REGISTER_WINAMP_IPCMESSAGE);
  1991. // subclass the Winamp2 main window to receive our callbacks
  1992. wa_oldWndProc = (WNDPROC) SetWindowLongPtrW(wa2.getMainWindow(), GWLP_WNDPROC, (LONG_PTR)wa_newWndProc);
  1993. ffPrefsItem.dlgID = IDD_PREFS;
  1994. ffPrefsItem.name = WASABI_API_LNGSTRINGW_BUF(IDS_MODERN_SKINS,modskin,128);
  1995. ffPrefsItem.proc = (void*)ffPrefsProc;
  1996. ffPrefsItem.hInst = WASABI_API_LNG_HINST;
  1997. ffPrefsItem.where = 2; //skins subtreeitem
  1998. SendMessageW(plugin.hwndParent, WM_WA_IPC, (WPARAM)&ffPrefsItem, IPC_ADD_PREFS_DLGW);
  1999. checkMlPresent();
  2000. m_loading_at_startup = 1;
  2001. onSkinSwitch();
  2002. m_loading_at_startup = 0;
  2003. return 0;
  2004. }
  2005. void RestoreClassicWinamp(int was_loaded)
  2006. {
  2007. // JF> my proposed fix to the problems :)
  2008. // investigating doing this from winamp.exe on startup, gotta figure it out
  2009. if (INI_FILE && was_loaded) // restore winamp.ini to about what it shoulda been
  2010. {
  2011. int classicpews = GetPrivateProfileIntW(L"gen_ff", L"classicplws", 0, INI_FILE);
  2012. int classicwidth = GetPrivateProfileIntW(L"gen_ff", L"classicplwidth", 275, INI_FILE);
  2013. int classicheight = GetPrivateProfileIntW(L"gen_ff", L"classicplheight", 145, INI_FILE);
  2014. int classicmw = GetPrivateProfileIntW(L"gen_ff", L"classicmw", 1, INI_FILE);
  2015. int classiceq = GetPrivateProfileIntW(L"gen_ff", L"classiceq", 1, INI_FILE);
  2016. wchar_t buf[64] = {0};
  2017. wsprintfW(buf, L"%d", classicheight);
  2018. if (classicpews)
  2019. {
  2020. WritePrivateProfileStringW(L"winamp", L"pe_height", L"14", INI_FILE);
  2021. WritePrivateProfileStringW(L"winamp", L"pe_height_ws", buf, INI_FILE);
  2022. }
  2023. else
  2024. {
  2025. WritePrivateProfileStringW(L"winamp", L"pe_height", buf, INI_FILE);
  2026. WritePrivateProfileStringW(L"winamp", L"pe_height_ws", L"", INI_FILE);
  2027. }
  2028. wsprintfW(buf, L"%d", classicwidth);
  2029. WritePrivateProfileStringW(L"winamp", L"pe_width", buf, INI_FILE);
  2030. WritePrivateProfileStringW(L"winamp", L"eq_open", classiceq ? L"1" : L"0", INI_FILE);
  2031. WritePrivateProfileStringW(L"winamp", L"mw_open", classicmw ? L"1" : L"0", INI_FILE);
  2032. }
  2033. }
  2034. //-----------------------------------------------------------------------------------------------
  2035. // quit (from Winamp 2)
  2036. //-----------------------------------------------------------------------------------------------
  2037. void quit()
  2038. {
  2039. int was_loaded = m_are_we_loaded;
  2040. quit_inst();
  2041. RestoreClassicWinamp(was_loaded);
  2042. // restore wa2's windowproc
  2043. //SetWindowLong(wa2.getMainWindow(), GWL_WNDPROC, (LONG)wa_oldWndProc);
  2044. shutdownFFApi();
  2045. }
  2046. //-----------------------------------------------------------------------------------------------
  2047. // About box wndproc
  2048. //-----------------------------------------------------------------------------------------------
  2049. ifc_window *about_group = NULL;
  2050. StringW oldrenderer;
  2051. BOOL CALLBACK aboutProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  2052. {
  2053. switch (uMsg)
  2054. {
  2055. case WM_INITDIALOG:
  2056. {
  2057. oldrenderer = cfg_options_fontrenderer.getValue();
  2058. if (!WCSCASEEQLSAFE(cfg_options_fontrenderer.getValue(), L"FreeType"))
  2059. cfg_options_fontrenderer.setValue(L"FreeType");
  2060. about_group = WASABI_API_SKIN->group_create(L"wasabi.gen_ff.about");
  2061. about_group->setVirtual(0);
  2062. HWND w = GetDlgItem(hwndDlg, IDC_STATIC_GROUP);
  2063. about_group->setStartHidden(1);
  2064. about_group->init(WASABI_API_WND->main_getRootWnd(), 1);
  2065. SetWindowLong(about_group->gethWnd(), GWL_STYLE, GetWindowLong(about_group->gethWnd(), GWL_STYLE) | WS_CHILD);
  2066. SetParent(about_group->gethWnd(), w);
  2067. SetWindowLong(w, GWL_STYLE, GetWindowLong(w, GWL_STYLE) | WS_CLIPCHILDREN);
  2068. RECT r;
  2069. GetClientRect(w, &r);
  2070. about_group->resize(r.left + 1, r.top + 1, r.right - r.left - 2, r.bottom - r.top - 2);
  2071. about_group->setVisible(1);
  2072. C_Group g(about_group->getGuiObject()->guiobject_getScriptObject());
  2073. ScriptObject *ver = g.findObject(L"version");
  2074. if (ver)
  2075. {
  2076. C_Text t(ver);
  2077. t.setText(StringPrintfW(L". © 2003-2023 Winamp SA %s", VERSION));
  2078. }
  2079. ShowWindow(about_group->gethWnd(), SW_NORMAL);
  2080. return 1;
  2081. }
  2082. case WM_DESTROY:
  2083. WASABI_API_SKIN->group_destroy(about_group);
  2084. about_group = NULL;
  2085. break;
  2086. case WM_COMMAND:
  2087. switch (LOWORD(wParam))
  2088. {
  2089. case IDOK: case IDCANCEL:
  2090. if (!WCSCASEEQLSAFE(cfg_options_fontrenderer.getValue(), oldrenderer))
  2091. cfg_options_fontrenderer.setValue(oldrenderer);
  2092. EndDialog(hwndDlg, 0);
  2093. return 0;
  2094. }
  2095. return 0;
  2096. }
  2097. return 0;
  2098. }
  2099. //-----------------------------------------------------------------------------------------------
  2100. // configure plugin (from Winamp 2)
  2101. //-----------------------------------------------------------------------------------------------
  2102. void config()
  2103. {
  2104. if (m_loaded_at_all)
  2105. {
  2106. StringW skin = WASABI_API_SKIN->getSkinName();
  2107. wchar_t _skName[64] = {0};
  2108. WASABI_API_LNGSTRINGW_BUF(IDS_NO_SKIN_LOADED_,_skName,64);
  2109. if ((!skin.iscaseequal(_skName)) || guiTree->getNumObject() > 0)
  2110. {
  2111. WASABI_API_DIALOGBOXW(IDD_ABOUT, wa2.getPreferencesWindow(), aboutProc);
  2112. return ;
  2113. }
  2114. }
  2115. MSGBOXPARAMSW msgbx = {sizeof(MSGBOXPARAMS),0};
  2116. msgbx.lpszText = WASABI_API_LNGSTRINGW(IDS_MODERN_SKIN_SUPPORT_CLASSIC);
  2117. msgbx.lpszCaption = szDescription;
  2118. msgbx.lpszIcon = MAKEINTRESOURCEW(102);
  2119. msgbx.hInstance = GetModuleHandle(0);
  2120. msgbx.dwStyle = MB_USERICON;
  2121. MessageBoxIndirectW(&msgbx);
  2122. }
  2123. //-----------------------------------------------------------------------------------------------
  2124. // expose the genpurp plugin interface to dll
  2125. //-----------------------------------------------------------------------------------------------
  2126. extern "C" __declspec(dllexport) winampGeneralPurposePlugin * winampGetGeneralPurposePlugin() { return &plugin; }
  2127. //-----------------------------------------------------------------------------------------------
  2128. // a window was right clicked where there was no custom context menu available, spawn Wa2's menu
  2129. //-----------------------------------------------------------------------------------------------
  2130. void appContextMenu(ifc_window *w)
  2131. {
  2132. if (!WASABI_API_WND->rootwndIsValid(w)) return ;
  2133. WASABI_API_WND->appdeactivation_setbypass(1);
  2134. SetCursor(LoadCursor(NULL, IDC_ARROW));
  2135. w->setFocus();
  2136. DWORD p = GetMessagePos();
  2137. int x = GET_X_LPARAM(p);
  2138. int y = GET_Y_LPARAM(p);
  2139. addWindowOptionsToContextMenu(w);
  2140. wa2.triggerPopupMenu(x, y);
  2141. WASABI_API_WND->appdeactivation_setbypass(0);
  2142. }
  2143. //-----------------------------------------------------------------------------------------------
  2144. void updateControlMenu(ifc_window *w)
  2145. {
  2146. int curalpha = 255;
  2147. double curratio = 1.;
  2148. int opacitysafe = 0;
  2149. int scalelocked = 0;
  2150. int auto100_hover = 0;
  2151. int auto100_focus = 0;
  2152. if (g_controlMenuTarget == NULL) return ;
  2153. if (w)
  2154. {
  2155. ifc_window *rootparent = g_controlMenuTarget->getDesktopParent();
  2156. if (rootparent && rootparent->getInterface(layoutGuid))
  2157. {
  2158. Layout *l = static_cast<Layout*>(rootparent);
  2159. opacitysafe = l->isTransparencySafe();
  2160. scalelocked = l->isScaleLocked();
  2161. curratio = w->getRenderRatio();
  2162. if (!cfg_uioptions_linkallalpha.getValueAsInt())
  2163. {
  2164. auto100_hover = l->getAutoOpacify() == 1;
  2165. auto100_focus = l->getAutoOpacify() == 2;
  2166. curalpha = l->getAlpha();
  2167. }
  2168. else
  2169. {
  2170. auto100_hover = l->getAlphaMgr()->getAutoOpacify() == 1;
  2171. auto100_focus = l->getAlphaMgr()->getAutoOpacify() == 2;
  2172. curalpha = l->getAlphaMgr()->getGlobalAlpha();
  2173. }
  2174. }
  2175. }
  2176. HMENU ctrlmenu = GetSubMenu(controlmenu, 0);
  2177. EnableMenuItem(ctrlmenu, 0, MF_BYPOSITION | (opacitysafe ? MF_ENABLED : MF_GRAYED));
  2178. HMENU scalemenu = GetSubMenu(ctrlmenu, 1);
  2179. HMENU alphamenu = GetSubMenu(ctrlmenu, 0);
  2180. int uselocks = cfg_uioptions_uselocks.getValueAsInt();
  2181. CheckMenuItem(scalemenu, ID_CONTROLMENU_SCALING_LOCKED, MF_BYCOMMAND | ((scalelocked || !uselocks) ? MF_CHECKED : MF_UNCHECKED));
  2182. EnableMenuItem(scalemenu, ID_CONTROLMENU_SCALING_LOCKED, MF_BYCOMMAND | (uselocks ? MF_ENABLED : MF_GRAYED));
  2183. CheckMenuItem(scalemenu, ID_CONTROLMENU_SCALING_FOLLOWDOUBLESIZE, MF_BYCOMMAND | (scalelocked || !uselocks ? MF_UNCHECKED : MF_CHECKED));
  2184. EnableMenuItem(scalemenu, ID_CONTROLMENU_SCALING_FOLLOWDOUBLESIZE, MF_BYCOMMAND | (uselocks ? MF_ENABLED : MF_GRAYED));
  2185. CheckMenuItem(alphamenu, ID_CONTROLMENU_OPACITY_AUTO100_HOVER, MF_BYCOMMAND | (auto100_hover ? MF_CHECKED : MF_UNCHECKED));
  2186. CheckMenuItem(alphamenu, ID_CONTROLMENU_OPACITY_AUTO100_FOCUS, MF_BYCOMMAND | (auto100_focus ? MF_CHECKED : MF_UNCHECKED));
  2187. int v = (int)((curalpha / 255.0f * 100.0f) + 0.5f);
  2188. int u = (int)((curratio * 100.0f) + 0.5f);
  2189. CheckMenuItem(alphamenu, ID_CONTROLMENU_OPACITY_10, MF_BYCOMMAND | (v == 10 ? MF_CHECKED : MF_UNCHECKED));
  2190. CheckMenuItem(alphamenu, ID_CONTROLMENU_OPACITY_20, MF_BYCOMMAND | (v == 20 ? MF_CHECKED : MF_UNCHECKED));
  2191. CheckMenuItem(alphamenu, ID_CONTROLMENU_OPACITY_30, MF_BYCOMMAND | (v == 30 ? MF_CHECKED : MF_UNCHECKED));
  2192. CheckMenuItem(alphamenu, ID_CONTROLMENU_OPACITY_40, MF_BYCOMMAND | (v == 40 ? MF_CHECKED : MF_UNCHECKED));
  2193. CheckMenuItem(alphamenu, ID_CONTROLMENU_OPACITY_50, MF_BYCOMMAND | (v == 50 ? MF_CHECKED : MF_UNCHECKED));
  2194. CheckMenuItem(alphamenu, ID_CONTROLMENU_OPACITY_60, MF_BYCOMMAND | (v == 60 ? MF_CHECKED : MF_UNCHECKED));
  2195. CheckMenuItem(alphamenu, ID_CONTROLMENU_OPACITY_70, MF_BYCOMMAND | (v == 70 ? MF_CHECKED : MF_UNCHECKED));
  2196. CheckMenuItem(alphamenu, ID_CONTROLMENU_OPACITY_80, MF_BYCOMMAND | (v == 80 ? MF_CHECKED : MF_UNCHECKED));
  2197. CheckMenuItem(alphamenu, ID_CONTROLMENU_OPACITY_90, MF_BYCOMMAND | (v == 90 ? MF_CHECKED : MF_UNCHECKED));
  2198. CheckMenuItem(alphamenu, ID_CONTROLMENU_OPACITY_100, MF_BYCOMMAND | (v == 100 ? MF_CHECKED : MF_UNCHECKED));
  2199. CheckMenuItem(scalemenu, ID_CONTROLMENU_SCALING_50, MF_BYCOMMAND | (u == 50 ? MF_CHECKED : MF_UNCHECKED));
  2200. CheckMenuItem(scalemenu, ID_CONTROLMENU_SCALING_75, MF_BYCOMMAND | (u == 75 ? MF_CHECKED : MF_UNCHECKED));
  2201. CheckMenuItem(scalemenu, ID_CONTROLMENU_SCALING_100, MF_BYCOMMAND | (u == 100 ? MF_CHECKED : MF_UNCHECKED));
  2202. CheckMenuItem(scalemenu, ID_CONTROLMENU_SCALING_125, MF_BYCOMMAND | (u == 125 ? MF_CHECKED : MF_UNCHECKED));
  2203. CheckMenuItem(scalemenu, ID_CONTROLMENU_SCALING_150, MF_BYCOMMAND | (u == 150 ? MF_CHECKED : MF_UNCHECKED));
  2204. CheckMenuItem(scalemenu, ID_CONTROLMENU_SCALING_200, MF_BYCOMMAND | (u == 200 ? MF_CHECKED : MF_UNCHECKED));
  2205. CheckMenuItem(scalemenu, ID_CONTROLMENU_SCALING_250, MF_BYCOMMAND | (u == 250 ? MF_CHECKED : MF_UNCHECKED));
  2206. CheckMenuItem(scalemenu, ID_CONTROLMENU_SCALING_300, MF_BYCOMMAND | (u == 300 ? MF_CHECKED : MF_UNCHECKED));
  2207. if (u != 50 && u != 75 && u != 100 && u != 125 && u != 150 && u != 200 && u != 250 && u != 300)
  2208. {
  2209. ModifyMenuW(scalemenu, ID_CONTROLMENU_SCALING_CUSTOM, MF_BYCOMMAND | MF_STRING, ID_CONTROLMENU_SCALING_CUSTOM, StringPrintfW(WASABI_API_LNGSTRINGW(IDS_CUSTOM_X_PERCENT), u));
  2210. CheckMenuItem(scalemenu, ID_CONTROLMENU_SCALING_CUSTOM, MF_BYCOMMAND | MF_CHECKED);
  2211. }
  2212. else
  2213. {
  2214. ModifyMenuW(scalemenu, ID_CONTROLMENU_SCALING_CUSTOM, MF_BYCOMMAND | MF_STRING, ID_CONTROLMENU_SCALING_CUSTOM, WASABI_API_LNGSTRINGW(IDS_CUSTOM));
  2215. CheckMenuItem(scalemenu, ID_CONTROLMENU_SCALING_CUSTOM, MF_BYCOMMAND | MF_UNCHECKED);
  2216. }
  2217. if (((float)v / 10.0) - (v / 10) != 0.0)
  2218. {
  2219. ModifyMenuW(alphamenu, ID_CONTROLMENU_OPACITY_CUSTOM, MF_BYCOMMAND | MF_STRING, ID_CONTROLMENU_OPACITY_CUSTOM, StringPrintfW(WASABI_API_LNGSTRINGW(IDS_CUSTOM_X_PERCENT), v));
  2220. CheckMenuItem(alphamenu, ID_CONTROLMENU_OPACITY_CUSTOM, MF_BYCOMMAND | MF_CHECKED);
  2221. }
  2222. else
  2223. {
  2224. ModifyMenuW(alphamenu, ID_CONTROLMENU_OPACITY_CUSTOM, MF_BYCOMMAND | MF_STRING, ID_CONTROLMENU_OPACITY_CUSTOM, WASABI_API_LNGSTRINGW(IDS_CUSTOM));
  2225. CheckMenuItem(alphamenu, ID_CONTROLMENU_OPACITY_CUSTOM, MF_BYCOMMAND | MF_UNCHECKED);
  2226. }
  2227. }
  2228. //-----------------------------------------------------------------------------------------------
  2229. // a window has triggered the control menu (control scale & alpha)
  2230. //-----------------------------------------------------------------------------------------------
  2231. void appControlMenu(ifc_window *w)
  2232. {
  2233. WASABI_API_WND->appdeactivation_setbypass(1);
  2234. int x, y;
  2235. if (w)
  2236. {
  2237. Wasabi::Std::getMousePos(&x, &y);
  2238. g_controlMenuTarget = w;
  2239. updateControlMenu(w);
  2240. updateAppBarMenu(w);
  2241. HMENU ctrlmenu = GetSubMenu(controlmenu, 0);
  2242. DoTrackPopup(ctrlmenu, TPM_LEFTALIGN | TPM_TOPALIGN | TPM_LEFTBUTTON, x, y, wa2.getMainWindow());
  2243. }
  2244. WASABI_API_WND->appdeactivation_setbypass(0);
  2245. }
  2246. //-----------------------------------------------------------------------------------------------
  2247. // a close application button was clicked
  2248. //-----------------------------------------------------------------------------------------------
  2249. void appQuit()
  2250. {
  2251. if (!wa2.isExitEnabled()) return ;
  2252. wa2.quit(); // this is in fact *posting* a quit message
  2253. }
  2254. //-----------------------------------------------------------------------------------------------
  2255. // a fatal skin error occured, we should revert to the wa2 skin (deferred)
  2256. //-----------------------------------------------------------------------------------------------
  2257. #define DCB_UNLOADSKIN 64
  2258. class deferredUnloadSkin : public TimerClientDI
  2259. {
  2260. public:
  2261. deferredUnloadSkin()
  2262. {
  2263. timerclient_postDeferredCallback(DCB_UNLOADSKIN, 0);
  2264. }
  2265. virtual int timerclient_onDeferredCallback(intptr_t param1, intptr_t param2)
  2266. {
  2267. if (param1 == DCB_UNLOADSKIN)
  2268. {
  2269. quit_inst();
  2270. delete this;
  2271. return 1;
  2272. }
  2273. else return TimerClientDI::timerclient_onDeferredCallback(param1, param2);
  2274. }
  2275. };
  2276. //-----------------------------------------------------------------------------------------------
  2277. // this is the actual event for skin fata errors, it is called when a try/except block failed
  2278. // upon calling a skin operation which should not be able to fail (ie: calling a script function pointer)
  2279. //-----------------------------------------------------------------------------------------------
  2280. void onFatalSkinError()
  2281. {
  2282. new deferredUnloadSkin();
  2283. }
  2284. //-----------------------------------------------------------------------------------------------
  2285. // map a GUID to the toggling of a window for which there is no permanent wndCreationService,
  2286. // ie: library, prefs, avs
  2287. //-----------------------------------------------------------------------------------------------
  2288. // called by a skinwnd_toggle call when the guid isn't found in the wndcreation services
  2289. int onCreateExternalWindowGuid(GUID g)
  2290. {
  2291. if (g == library_guid)
  2292. {
  2293. SendMessageW(wa2.getMainWindow(), WM_COMMAND, ID_FILE_SHOWLIBRARY, 0);
  2294. return 1;
  2295. }
  2296. else if (g == preferences_guid)
  2297. {
  2298. SendMessageW(wa2.getMainWindow(), WM_COMMAND, WINAMP_OPTIONS_PREFS, 0);
  2299. return 1;
  2300. }
  2301. else if (g == about_guid)
  2302. {
  2303. SendMessageW(wa2.getMainWindow(), WM_COMMAND, WINAMP_HELP_ABOUT, 0);
  2304. return 1;
  2305. }
  2306. else if (g == lightning_bolt_guid)
  2307. {
  2308. SendMessageW(wa2.getMainWindow(), WM_COMMAND, WINAMP_LIGHTNING_CLICK, 0);
  2309. return 1;
  2310. }
  2311. else if (g == colorthemes_guid)
  2312. {
  2313. last_page.setData(L"3");
  2314. SendMessageW(plugin.hwndParent, WM_WA_IPC, (WPARAM)&ffPrefsItem, IPC_OPENPREFSTOPAGE);
  2315. return 1;
  2316. }
  2317. else if (g == avs_guid)
  2318. {
  2319. if (wa2.isVisRunning())
  2320. {
  2321. SetTimer(wa2.getMainWindow(), 0xC0DE, 50, NULL);
  2322. SetTimer(wa2.getMainWindow(), 0xC0DE + 1, 5000, NULL);
  2323. }
  2324. else
  2325. wa2.toggleVis();
  2326. return 1;
  2327. }
  2328. return 0;
  2329. }
  2330. //-----------------------------------------------------------------------------------------------
  2331. void onToggleDesktopAlpha(int v)
  2332. {
  2333. if (!toggle_from_wa2 && subWndId == 0 && IsWindow(subWnd)) SendMessageW(subWnd, WM_INITDIALOG, 0, 0);
  2334. }
  2335. //-----------------------------------------------------------------------------------------------
  2336. // changes the name of a container so that static containers with the wrong name don't load the config
  2337. // values off the wrong name. this should match the WindowText of the embededwindow. note: this is only
  2338. // necessary for static containers holding an internal embedwnd (ie: library, avs, but not third party wnds
  2339. // as they can't be refered to by GUID anyway [if they can't be refered to by GUID, you can't make a static
  2340. // container for them])
  2341. //-----------------------------------------------------------------------------------------------
  2342. const wchar_t *onTweakContainerNameW(const wchar_t *name)
  2343. {
  2344. static wchar_t tweaked[96];
  2345. ZERO(tweaked);
  2346. if (!_wcsicmp(name, WASABI_API_LNG->GetStringFromGUIDW(GenMlLangGUID, plugin.hDllInstance, 18, tweaked, sizeof(tweaked)/sizeof(wchar_t))) ||
  2347. !_wcsicmp(name, L"Media Library") ||
  2348. !_wcsicmp(name, L"Winamp Library") ||
  2349. !_wcsicmp(name, L"Library"))
  2350. {
  2351. return WASABI_API_LNGSTRINGW_BUF(IDS_MEDIA_LIBRARY,tweaked, sizeof(tweaked)/sizeof(wchar_t));
  2352. }
  2353. if (!_wcsicmp(name, L"Avs")) return WASABI_API_LNGSTRINGW_BUF(IDS_VISUALIZATIONS,tweaked, sizeof(tweaked)/sizeof(wchar_t));
  2354. return name;
  2355. }
  2356. const wchar_t *GetMenuItemString(HMENU menu, int id, int bypos)
  2357. {
  2358. static StringW rtn;
  2359. rtn.trunc(0);
  2360. MENUITEMINFOW info = {sizeof(info), MIIM_DATA | MIIM_TYPE | MIIM_STATE | MIIM_ID, MFT_STRING, };
  2361. GetMenuItemInfoW(menu, id, bypos, &info);
  2362. if (info.cch > 0)
  2363. {
  2364. info.dwTypeData = WMALLOC(++info.cch + 1);
  2365. GetMenuItemInfoW(menu, id, bypos, &info);
  2366. info.dwTypeData[info.cch] = 0;
  2367. rtn = info.dwTypeData;
  2368. FREE(info.dwTypeData);
  2369. }
  2370. return rtn;
  2371. }
  2372. StringW eqmenustring;
  2373. //-----------------------------------------------------------------------------------------------
  2374. void removeEq()
  2375. {
  2376. if (eqremoved) return ;
  2377. eqremoved = 1;
  2378. eqmenustring = GetMenuItemString(wa2.getPopupMenu(), WINAMP_OPTIONS_EQ, FALSE);
  2379. RemoveMenu(wa2.getPopupMenu(), WINAMP_OPTIONS_EQ, MF_BYCOMMAND);
  2380. wa2.adjustOptionsPopupMenu(-1);
  2381. }
  2382. //-----------------------------------------------------------------------------------------------
  2383. void restoreEq()
  2384. {
  2385. if (!eqremoved) return ;
  2386. MENUITEMINFOW i = {sizeof(i), MIIM_ID | MIIM_STATE | MIIM_TYPE, MFT_STRING, wa2.isWindowVisible(IPC_GETWND_EQ) ? MFS_CHECKED : 0, WINAMP_OPTIONS_EQ};
  2387. i.dwTypeData = eqmenustring.getNonConstVal();
  2388. InsertMenuItemW(wa2.getPopupMenu(), 8, TRUE, &i);
  2389. wa2.adjustOptionsPopupMenu(1);
  2390. eqremoved = 0;
  2391. }
  2392. //-----------------------------------------------------------------------------------------------
  2393. void unpopulateWindowsMenus()
  2394. {
  2395. if (ffwindowsitempos == -1) return ;
  2396. HMENU menuBarMenu = wa2.getMenuBarMenu(Winamp2FrontEnd::WA2_MAINMENUBAR_WINDOWS);
  2397. for(int i = GetMenuItemCount(menuBarMenu)-1; i >= 0; i--)
  2398. {
  2399. MENUITEMINFOW info = {sizeof(info), MIIM_DATA, 0, };
  2400. if(GetMenuItemInfoW(menuBarMenu,i,TRUE,&info))
  2401. {
  2402. if(info.dwItemData == 0xD01){
  2403. RemoveMenu(menuBarMenu,i,MF_BYPOSITION);
  2404. wa2.adjustFFWindowsMenu(-1);
  2405. }
  2406. }
  2407. }
  2408. HMENU menuPopupMenu = wa2.getPopupMenu();
  2409. for(int i = GetMenuItemCount(menuPopupMenu)-1; i >= 0; i--)
  2410. {
  2411. MENUITEMINFOW info = {sizeof(info), MIIM_DATA, 0, };
  2412. if(GetMenuItemInfoW(menuPopupMenu,i,TRUE,&info))
  2413. {
  2414. if(info.dwItemData == 0xD01){
  2415. RemoveMenu(menuPopupMenu,i,MF_BYPOSITION);
  2416. wa2.adjustOptionsPopupMenu(-1);
  2417. }
  2418. }
  2419. }
  2420. ffwindowsitempos = -1;
  2421. ffwindowsitempos2 = -1;
  2422. MenuActions::removeSkinWindowOptions();
  2423. MenuActions::removeSkinOptions();
  2424. }
  2425. //-----------------------------------------------------------------------------------------------
  2426. void populateWindowsMenus()
  2427. {
  2428. if (ffwindowsitempos != -1) unpopulateWindowsMenus();
  2429. MenuActions::installSkinOptions();
  2430. MenuActions::installSkinWindowOptions();
  2431. ffwindowsitempos = wa2.adjustFFWindowsMenu(0) + NUMSTATICWINDOWS;
  2432. ffwindowsitempos2 = wa2.adjustOptionsPopupMenu(0) + 6 + NUMSTATICWINDOWS + 1;
  2433. MENUITEMINFOW i = {sizeof(i), };
  2434. i.fMask = MIIM_TYPE | MIIM_DATA | MIIM_ID | MIIM_STATE;
  2435. i.fType = MFT_STRING;
  2436. i.wID = 43000;
  2437. i.dwItemData = 0xD01; // use this as a check so we're only removing the correct items!!
  2438. int pos = ffwindowsitempos;
  2439. int pos2 = ffwindowsitempos2;
  2440. PtrListQuickSorted<StringW, StringWComparator> items;
  2441. HMENU hMenu = wa2.getMenuBarMenu(Winamp2FrontEnd::WA2_MAINMENUBAR_WINDOWS);
  2442. HMENU hMenu2 = wa2.getPopupMenu();
  2443. for (int c = 0;c < SkinParser::getNumContainers();c++)
  2444. {
  2445. Container *cont = SkinParser::enumContainer(c);
  2446. if (cont && wantContainerInMenu(cont))
  2447. {
  2448. i.dwTypeData = const_cast<wchar_t *>(cont->getName());
  2449. if (i.dwTypeData != NULL)
  2450. {
  2451. if (!items.findItem(i.dwTypeData))
  2452. {
  2453. items.addItem(new StringW(i.dwTypeData));
  2454. i.cch = wcslen(i.dwTypeData);
  2455. i.fState = cont->isVisible() ? MFS_CHECKED : 0;
  2456. InsertMenuItemW(hMenu, pos++, TRUE, &i);
  2457. wa2.adjustFFWindowsMenu(1);
  2458. InsertMenuItemW(hMenu2, pos2++, TRUE, &i);
  2459. wa2.adjustOptionsPopupMenu(1);
  2460. }
  2461. }
  2462. }
  2463. i.wID++;
  2464. }
  2465. int n = WASABI_API_WNDMGR->autopopup_getNumGuids();
  2466. for (int c = 0;c < n;c++)
  2467. {
  2468. GUID guid = WASABI_API_WNDMGR->autopopup_enumGuid(c);
  2469. const wchar_t *groupdesc = WASABI_API_WNDMGR->autopopup_enumGuidDescription(c);
  2470. if (guid != INVALID_GUID && groupdesc && *groupdesc)
  2471. {
  2472. i.dwTypeData = const_cast<wchar_t *>(groupdesc);
  2473. if (!items.findItem(i.dwTypeData))
  2474. {
  2475. items.addItem(new StringW(i.dwTypeData));
  2476. i.cch = wcslen(i.dwTypeData);
  2477. i.fState = WASABI_API_WNDMGR->skinwnd_getNumByGuid(guid) ? MFS_CHECKED : 0;
  2478. InsertMenuItemW(hMenu, pos++, TRUE, &i);
  2479. wa2.adjustFFWindowsMenu(1);
  2480. InsertMenuItemW(hMenu2, pos2++, TRUE, &i);
  2481. wa2.adjustOptionsPopupMenu(1);
  2482. }
  2483. }
  2484. i.wID++;
  2485. }
  2486. n = WASABI_API_WNDMGR->autopopup_getNumGroups();
  2487. for (int c = 0;c < n;c++)
  2488. {
  2489. const wchar_t *id = WASABI_API_WNDMGR->autopopup_enumGroup(c);
  2490. const wchar_t *groupdesc = WASABI_API_WNDMGR->autopopup_enumGroupDescription(c);
  2491. if (id && groupdesc && *id && *groupdesc)
  2492. {
  2493. i.dwTypeData = const_cast<wchar_t *>(groupdesc);
  2494. // allow localisation of the color editor menu item
  2495. i.dwTypeData = const_cast<wchar_t *>(MenuActions::localizeSkinWindowName(i.dwTypeData));
  2496. if (!items.findItem(i.dwTypeData))
  2497. {
  2498. items.addItem(new StringW(i.dwTypeData));
  2499. i.cch = wcslen(i.dwTypeData);
  2500. i.fState = WASABI_API_WNDMGR->skinwnd_getNumByGroupId(id) ? MFS_CHECKED : 0;
  2501. InsertMenuItemW(hMenu, pos++, TRUE, &i);
  2502. wa2.adjustFFWindowsMenu(1);
  2503. InsertMenuItemW(hMenu2, pos2++, TRUE, &i);
  2504. wa2.adjustOptionsPopupMenu(1);
  2505. }
  2506. }
  2507. i.wID++;
  2508. }
  2509. items.deleteAll();
  2510. ffwindowstop = i.wID;
  2511. }
  2512. //-----------------------------------------------------------------------------------------------
  2513. void switchSkin(const wchar_t *skinname)
  2514. {
  2515. wa2.switchSkin(skinname);
  2516. }
  2517. //-----------------------------------------------------------------------------------------------
  2518. void addWindowOptionsToContextMenu(ifc_window *w)
  2519. {
  2520. if (g_controlMenuTarget != NULL)
  2521. removeWindowOptionsFromContextMenu();
  2522. if (w == NULL && WASABI_API_WND->rootwndIsValid(lastFocused))
  2523. w = lastFocused;
  2524. g_controlMenuTarget = w;
  2525. if (g_controlMenuTarget == NULL) return ;
  2526. /*int opacitysafe = 1;
  2527. int scalelocked = 0;
  2528. ifc_window *rootparent = g_controlMenuTarget->getDesktopParent();
  2529. if (rootparent && rootparent->getInterface(layoutGuid))
  2530. {
  2531. Layout *l = static_cast<Layout*>(rootparent);
  2532. opacitysafe = l->isTransparencySafe();
  2533. scalelocked = l->isScaleLocked();
  2534. }*/
  2535. updateControlMenu(w);
  2536. updateAppBarMenu(w);
  2537. HMENU menu = wa2.getPopupMenu();
  2538. HMENU ctrlmenu = GetSubMenu(controlmenu, 0);
  2539. // JF> Francis, made this use command IDs (inserts it right before the help ID in the main menu).
  2540. // does this look OK? if you want, revert back to the old one. I just thought this seemed a tiny
  2541. // bit cleaner... :)
  2542. #define ID_HELP_HELPTOPICS 40347
  2543. InsertMenuW(menu, ID_HELP_HELPTOPICS, MF_BYCOMMAND | MF_POPUP, (UINT_PTR)ctrlmenu, WASABI_API_LNGSTRINGW(IDS_WINDOW_SETTINGS));
  2544. InsertMenu(menu, ID_HELP_HELPTOPICS, MF_BYCOMMAND | MF_SEPARATOR, 0, NULL);
  2545. }
  2546. //-----------------------------------------------------------------------------------------------
  2547. void removeWindowOptionsFromContextMenu()
  2548. {
  2549. if (g_controlMenuTarget == NULL) return ;
  2550. g_controlMenuTarget = NULL;
  2551. HMENU menu = wa2.getPopupMenu();
  2552. HMENU ctrlmenu = GetSubMenu(controlmenu, 0);
  2553. if (ctrlmenu)
  2554. {
  2555. int l = GetMenuItemCount(menu);
  2556. while (l-- > 0 && GetSubMenu(menu, l) != ctrlmenu);
  2557. if (l >= 0)
  2558. {
  2559. RemoveMenu(menu, l, MF_BYPOSITION);
  2560. RemoveMenu(menu, l, MF_BYPOSITION); // remove sep
  2561. }
  2562. }
  2563. }
  2564. //-----------------------------------------------------------------------------------------------
  2565. void controlOpacity(int v)
  2566. {
  2567. if (!g_controlMenuTarget) return ;
  2568. if (!WASABI_API_WND->rootwndIsValid(g_controlMenuTarget)) return ;
  2569. v = (int)(((float)v / 100.0f) * 255.0f + 0.5f);
  2570. ifc_window *rootparent = g_controlMenuTarget->getDesktopParent();
  2571. if (rootparent && rootparent->getInterface(layoutGuid))
  2572. {
  2573. Layout *l = static_cast<Layout*>(rootparent);
  2574. if (!cfg_uioptions_linkallalpha.getValueAsInt())
  2575. {
  2576. l->setAlpha(v);
  2577. }
  2578. else
  2579. {
  2580. cfg_uioptions_linkedalpha.setValueAsInt(v);
  2581. }
  2582. }
  2583. }
  2584. //-----------------------------------------------------------------------------------------------
  2585. void controlScaling(double v)
  2586. {
  2587. if (!g_controlMenuTarget) return ;
  2588. if (!WASABI_API_WND->rootwndIsValid(g_controlMenuTarget)) return ;
  2589. ifc_window *rootparent = g_controlMenuTarget->getDesktopParent();
  2590. if (rootparent) rootparent->setRenderRatio(v);
  2591. }
  2592. //-----------------------------------------------------------------------------------------------
  2593. void lockScaling(int lock)
  2594. {
  2595. ifc_window *rootparent = g_controlMenuTarget->getDesktopParent();
  2596. if (!WASABI_API_WND->rootwndIsValid(g_controlMenuTarget)) return ;
  2597. if (rootparent && rootparent->getInterface(layoutGuid))
  2598. {
  2599. Layout *l = static_cast<Layout*>(rootparent);
  2600. l->lockScale(lock);
  2601. }
  2602. }
  2603. //-----------------------------------------------------------------------------------------------
  2604. void controlAppBar(int side)
  2605. {
  2606. ifc_window *rootparent = g_controlMenuTarget->getDesktopParent();
  2607. if (rootparent)
  2608. {
  2609. AppBar *ab = (AppBar *)rootparent->getInterface(appBarGuid);
  2610. if (ab)
  2611. {
  2612. ab->appbar_dock(side);
  2613. }
  2614. }
  2615. }
  2616. //-----------------------------------------------------------------------------------------------
  2617. void controlAppBarAOT()
  2618. {
  2619. ifc_window *rootparent = g_controlMenuTarget->getDesktopParent();
  2620. if (rootparent)
  2621. {
  2622. Layout *l = (Layout *)rootparent->getInterface(layoutGuid);
  2623. if (l)
  2624. {
  2625. int curaot = l->getAppBarAlwaysOnTop();
  2626. l->setAppBarAlwaysOnTop(!curaot);
  2627. }
  2628. }
  2629. }
  2630. //-----------------------------------------------------------------------------------------------
  2631. void controlAppBarAH()
  2632. {
  2633. ifc_window *rootparent = g_controlMenuTarget->getDesktopParent();
  2634. if (rootparent)
  2635. {
  2636. Layout *l = (Layout *)rootparent->getInterface(layoutGuid);
  2637. if (l)
  2638. {
  2639. int curah = l->getAppBarAutoHide();
  2640. l->setAppBarAutoHide(!curah);
  2641. }
  2642. }
  2643. }
  2644. //-----------------------------------------------------------------------------------------------
  2645. void updateAppBarMenu(ifc_window *w)
  2646. {
  2647. if (g_controlMenuTarget == NULL) return ;
  2648. ifc_window *rootparent = g_controlMenuTarget->getDesktopParent();
  2649. if (rootparent)
  2650. {
  2651. Layout *l = (Layout *)rootparent->getInterface(layoutGuid);
  2652. if (l)
  2653. {
  2654. HMENU ctrlmenu = GetSubMenu(controlmenu, 0);
  2655. HMENU appbarmenu = GetSubMenu(ctrlmenu, 2);
  2656. if (l->appbar_getEnabledSides() == 0)
  2657. {
  2658. EnableMenuItem(ctrlmenu, 2, MF_BYPOSITION | MF_GRAYED);
  2659. return ;
  2660. }
  2661. else
  2662. EnableMenuItem(ctrlmenu, 2, MF_BYPOSITION | MF_ENABLED);
  2663. int docked = l->appbar_isDocked();
  2664. int side = l->appbar_getSide();
  2665. CheckMenuItem(appbarmenu, ID_CONTROLMENU_TOOLBAR_ALWAYSONTOP, MF_BYCOMMAND | (l->appbar_wantAlwaysOnTop() ? MF_CHECKED : MF_UNCHECKED));
  2666. CheckMenuItem(appbarmenu, ID_CONTROLMENU_TOOLBAR_AUTOHIDE, MF_BYCOMMAND | (l->appbar_wantAutoHide() ? MF_CHECKED : MF_UNCHECKED));
  2667. CheckMenuItem(appbarmenu, ID_CONTROLMENU_TOOLBAR_LEFT, MF_BYCOMMAND | ((docked && side == APPBAR_LEFT) ? MF_CHECKED : MF_UNCHECKED));
  2668. CheckMenuItem(appbarmenu, ID_CONTROLMENU_TOOLBAR_TOP, MF_BYCOMMAND | ((docked && side == APPBAR_TOP) ? MF_CHECKED : MF_UNCHECKED));
  2669. CheckMenuItem(appbarmenu, ID_CONTROLMENU_TOOLBAR_RIGHT, MF_BYCOMMAND | ((docked && side == APPBAR_RIGHT) ? MF_CHECKED : MF_UNCHECKED));
  2670. CheckMenuItem(appbarmenu, ID_CONTROLMENU_TOOLBAR_BOTTOM, MF_BYCOMMAND | ((docked && side == APPBAR_BOTTOM) ? MF_CHECKED : MF_UNCHECKED));
  2671. CheckMenuItem(appbarmenu, ID_CONTROLMENU_TOOLBAR_DISABLED, MF_BYCOMMAND | (!docked ? MF_CHECKED : MF_UNCHECKED));
  2672. EnableMenuItem(appbarmenu, ID_CONTROLMENU_TOOLBAR_AUTOHIDE, MF_BYCOMMAND | ((!docked || l->appbar_isSideAutoHideSafe(side)) ? MF_ENABLED : MF_GRAYED));
  2673. EnableMenuItem(appbarmenu, ID_CONTROLMENU_TOOLBAR_LEFT, MF_BYCOMMAND | (l->appbar_isSideEnabled(APPBAR_LEFT) ? MF_ENABLED : MF_GRAYED));
  2674. EnableMenuItem(appbarmenu, ID_CONTROLMENU_TOOLBAR_TOP, MF_BYCOMMAND | (l->appbar_isSideEnabled(APPBAR_TOP) ? MF_ENABLED : MF_GRAYED));
  2675. EnableMenuItem(appbarmenu, ID_CONTROLMENU_TOOLBAR_RIGHT, MF_BYCOMMAND | (l->appbar_isSideEnabled(APPBAR_RIGHT) ? MF_ENABLED : MF_GRAYED));
  2676. EnableMenuItem(appbarmenu, ID_CONTROLMENU_TOOLBAR_BOTTOM, MF_BYCOMMAND | (l->appbar_isSideEnabled(APPBAR_BOTTOM) ? MF_ENABLED : MF_GRAYED));
  2677. CheckMenuItem(appbarmenu, ID_CONTROLMENU_TOOLBAR_AUTODOCKONDRAG, MF_BYCOMMAND | (cfg_options_appbarondrag ? MF_CHECKED : MF_UNCHECKED));
  2678. }
  2679. }
  2680. }
  2681. //-----------------------------------------------------------------------------------------------
  2682. double onTweakRenderRatio(double v)
  2683. {
  2684. if (!cfg_uioptions_uselocks.getValueAsInt())
  2685. return v;
  2686. return wa2.isDoubleSize() ? 2.0 : 1.0;
  2687. }
  2688. //-----------------------------------------------------------------------------------------------
  2689. void onCustomAltF4()
  2690. {
  2691. SendMessageW(wa2.getMainWindow(), WM_CLOSE, 0, 0);
  2692. }
  2693. int isSkinStillLoading()
  2694. {
  2695. return before_startup_callback;
  2696. }
  2697. //-----------------------------------------------------------------------------------------------
  2698. void loadExtraColorThemes()
  2699. {
  2700. wchar_t filename[WA_MAX_PATH] = {0};
  2701. GetModuleFileNameW(hInstance, filename, WA_MAX_PATH);
  2702. PathParserW pp(filename);
  2703. StringW path;
  2704. for (int i = 0;i < pp.getNumStrings() - 1;i++)
  2705. {
  2706. path.AppendPath(pp.enumString(i));
  2707. }
  2708. StringW file = path;
  2709. file.AppendPath(L"ColorThemes");
  2710. file.AppendPath(WASABI_API_SKIN->getSkinName());
  2711. file.AppendPath(L"*.xml");
  2712. WASABI_API_SKIN->loadSkinFile(file);
  2713. }
  2714. double oldscale = 1.;
  2715. //-----------------------------------------------------------------------------------------------
  2716. static BOOL CALLBACK customScaleProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  2717. {
  2718. switch (uMsg)
  2719. {
  2720. case WM_INITDIALOG:
  2721. {
  2722. //CUT: double curratio=1.;
  2723. ifc_window *rootparent = g_controlMenuTarget->getDesktopParent();
  2724. if (!rootparent || !WASABI_API_WND->rootwndIsValid(rootparent))
  2725. {
  2726. g_controlMenuTarget = NULL; return TRUE;
  2727. }
  2728. oldscale = rootparent->getRenderRatio();
  2729. int u = (int)((oldscale * 100.0f) + 0.5f);
  2730. SendMessageW(GetDlgItem(hwndDlg, IDC_SLIDER_CUSTOMSCALE), TBM_SETRANGEMAX, 0, 300);
  2731. SendMessageW(GetDlgItem(hwndDlg, IDC_SLIDER_CUSTOMSCALE), TBM_SETRANGEMIN, 0, 10);
  2732. SendMessageW(GetDlgItem(hwndDlg, IDC_SLIDER_CUSTOMSCALE), TBM_SETPOS, 1, u);
  2733. SetDlgItemTextW(hwndDlg, IDC_STATIC_SCALE, StringPrintfW(WASABI_API_LNGSTRINGW(IDS_SCALE_X_PERCENT), u));
  2734. return TRUE;
  2735. }
  2736. case WM_HSCROLL:
  2737. {
  2738. int t = (int)SendMessageW((HWND) lParam, TBM_GETPOS, 0, 0);
  2739. if ((HWND) lParam == GetDlgItem(hwndDlg, IDC_SLIDER_CUSTOMSCALE))
  2740. {
  2741. SetDlgItemTextW(hwndDlg, IDC_STATIC_SCALE, StringPrintfW(WASABI_API_LNGSTRINGW(IDS_SCALE_X_PERCENT), t));
  2742. controlScaling((double)t / 100.0);
  2743. if (g_controlMenuTarget)
  2744. {
  2745. ifc_window *w = g_controlMenuTarget->getDesktopParent();
  2746. UpdateWindow(w->gethWnd());
  2747. }
  2748. }
  2749. break;
  2750. }
  2751. case WM_COMMAND:
  2752. switch (LOWORD(wParam))
  2753. {
  2754. case IDOK:
  2755. EndDialog(hwndDlg, IDOK);
  2756. return 0;
  2757. case IDCANCEL:
  2758. EndDialog(hwndDlg, IDCANCEL);
  2759. return 0;
  2760. }
  2761. break;
  2762. }
  2763. return FALSE;
  2764. }
  2765. double oldalpha = 255.;
  2766. //-----------------------------------------------------------------------------------------------
  2767. static BOOL CALLBACK customAlphaProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  2768. {
  2769. switch (uMsg)
  2770. {
  2771. case WM_INITDIALOG:
  2772. {
  2773. ifc_window *rootparent = g_controlMenuTarget->getDesktopParent();
  2774. if (!rootparent || !WASABI_API_WND->rootwndIsValid(rootparent))
  2775. {
  2776. g_controlMenuTarget = NULL; return TRUE;
  2777. }
  2778. int v = 100;
  2779. if (!cfg_uioptions_linkallalpha.getValueAsInt())
  2780. {
  2781. Layout *l = static_cast<Layout *>(rootparent);
  2782. if (l != NULL)
  2783. oldalpha = static_cast<double>(l->getAlpha());
  2784. }
  2785. else
  2786. {
  2787. oldalpha = static_cast<double>(cfg_uioptions_linkedalpha.getValueAsInt());
  2788. }
  2789. v = (int)((oldalpha / 255.0f * 100.0f) + 0.5f);
  2790. SendMessageW(GetDlgItem(hwndDlg, IDC_SLIDER_CUSTOMALPHA), TBM_SETRANGEMAX, 0, 100);
  2791. SendMessageW(GetDlgItem(hwndDlg, IDC_SLIDER_CUSTOMALPHA), TBM_SETRANGEMIN, 0, 10);
  2792. SendMessageW(GetDlgItem(hwndDlg, IDC_SLIDER_CUSTOMALPHA), TBM_SETPOS, 1, v);
  2793. SetDlgItemTextW(hwndDlg, IDC_STATIC_ALPHA, StringPrintfW(WASABI_API_LNGSTRINGW(IDS_OPACITY_X_PERCENT), v));
  2794. return TRUE;
  2795. }
  2796. case WM_HSCROLL:
  2797. {
  2798. int t = (int)SendMessageW((HWND) lParam, TBM_GETPOS, 0, 0);
  2799. if ((HWND) lParam == GetDlgItem(hwndDlg, IDC_SLIDER_CUSTOMALPHA))
  2800. {
  2801. SetDlgItemTextW(hwndDlg, IDC_STATIC_ALPHA, StringPrintfW(WASABI_API_LNGSTRINGW(IDS_OPACITY_X_PERCENT), t));
  2802. controlOpacity(t);
  2803. }
  2804. break;
  2805. }
  2806. case WM_COMMAND:
  2807. switch (LOWORD(wParam))
  2808. {
  2809. case IDOK:
  2810. EndDialog(hwndDlg, IDOK);
  2811. return 0;
  2812. case IDCANCEL:
  2813. EndDialog(hwndDlg, IDCANCEL);
  2814. return 0;
  2815. }
  2816. break;
  2817. }
  2818. return FALSE;
  2819. }
  2820. void customScaling()
  2821. {
  2822. if (!g_controlMenuTarget) return ;
  2823. if (!WASABI_API_WND->rootwndIsValid(g_controlMenuTarget)) return ;
  2824. ifc_window *w = g_controlMenuTarget->getDesktopParent();
  2825. if (!w || !WASABI_API_WND->rootwndIsValid(w)) return ;
  2826. int r = WASABI_API_DIALOGBOXW(IDD_CUSTOMSCALE, w->gethWnd(), customScaleProc);
  2827. if (r != IDOK)
  2828. controlScaling(oldscale);
  2829. }
  2830. void customOpacity()
  2831. {
  2832. if (!g_controlMenuTarget) return ;
  2833. if (!WASABI_API_WND->rootwndIsValid(g_controlMenuTarget)) return ;
  2834. ifc_window *w = g_controlMenuTarget->getDesktopParent();
  2835. if (!w || !WASABI_API_WND->rootwndIsValid(w)) return ;
  2836. int r = WASABI_API_DIALOGBOXW(IDD_CUSTOMALPHA, w->gethWnd(), customAlphaProc);
  2837. if (r != IDOK)
  2838. controlOpacity((int)((oldalpha / 255.0f * 100.0f) + 0.5f));
  2839. }
  2840. void autoOpacifyHover()
  2841. {
  2842. if (!g_controlMenuTarget) return ;
  2843. if (!WASABI_API_WND->rootwndIsValid(g_controlMenuTarget)) return ;
  2844. ifc_window *w = g_controlMenuTarget->getDesktopParent();
  2845. Layout *l = static_cast<Layout*>(w->getInterface(layoutGuid));
  2846. if (l)
  2847. {
  2848. if (!cfg_uioptions_linkallalpha.getValueAsInt())
  2849. {
  2850. int a = l->getAutoOpacify();
  2851. if (a == 2) a = 1;
  2852. else a = !a;
  2853. l->setAutoOpacify(a);
  2854. }
  2855. else
  2856. {
  2857. int a = cfg_uioptions_autoopacitylinked.getValueAsInt();
  2858. if (a == 2) a = 1;
  2859. else a = !a;
  2860. cfg_uioptions_autoopacitylinked.setValueAsInt(a);
  2861. }
  2862. }
  2863. }
  2864. void autoOpacifyFocus()
  2865. {
  2866. if (!g_controlMenuTarget) return ;
  2867. if (!WASABI_API_WND->rootwndIsValid(g_controlMenuTarget)) return ;
  2868. ifc_window *w = g_controlMenuTarget->getDesktopParent();
  2869. Layout *l = static_cast<Layout*>(w->getInterface(layoutGuid));
  2870. if (l)
  2871. {
  2872. if (!cfg_uioptions_linkallalpha.getValueAsInt())
  2873. {
  2874. int a = l->getAutoOpacify();
  2875. if (a == 1) a = 2;
  2876. else if (a == 0) a = 2;
  2877. else if (a == 2) a = 0;
  2878. l->setAutoOpacify(a);
  2879. }
  2880. else
  2881. {
  2882. int a = cfg_uioptions_autoopacitylinked.getValueAsInt();
  2883. if (a == 1) a = 2;
  2884. else if (a == 0) a = 2;
  2885. else if (a == 2) a = 0;
  2886. cfg_uioptions_autoopacitylinked.setValueAsInt(a);
  2887. }
  2888. }
  2889. }
  2890. StringW langpackfilename;
  2891. const wchar_t *localesCustomGetFile()
  2892. {
  2893. const wchar_t *langDir = WASABI_API_LNG->GetLanguageFolder();
  2894. if (!langDir || !*langDir)
  2895. return NULL;
  2896. langpackfilename = StringPathCombine(langDir, L"freeform");
  2897. return langpackfilename;
  2898. #if 0 // old code
  2899. wchar_t buf[256] = L"";
  2900. GetPrivateProfileStringW(L"Winamp", L"langpack", L"", buf, 256, AutoWide(INI_FILE)); // TODO: maybe we should change all ini file stuff to W versions
  2901. if (*buf == 0)
  2902. return NULL;
  2903. wchar_t *p = wcschr(buf, '.');
  2904. if (p)
  2905. *p = 0;
  2906. wchar_t filename[WA_MAX_PATH] = {0};
  2907. GetModuleFileNameW(hInstance, filename, WA_MAX_PATH);
  2908. PathParserW pp(filename);
  2909. langpackfilename = L"";
  2910. for (int i = 0;i < pp.getNumStrings() - 1;i++)
  2911. {
  2912. langpackfilename.AppendPath(pp.enumString(i));
  2913. }
  2914. langpackfilename.AppendPath(L"freeform");
  2915. langpackfilename.AppendPath(L"langpacks");
  2916. langpackfilename.AppendPath(StringPrintfW(L"%s.xml", buf));
  2917. return langpackfilename;
  2918. #endif
  2919. }
  2920. const wchar_t *getCustomVar(const wchar_t *var)
  2921. {
  2922. static StringW ret;
  2923. if (WCSCASEEQLSAFE(var, L"@HAVE_LIBRARY@"))
  2924. {
  2925. ret = StringPrintfW(L"%d", we_have_ml);
  2926. return ret;
  2927. }
  2928. return NULL;
  2929. }
  2930. void checkMlPresent()
  2931. {
  2932. wchar_t filename[WA_MAX_PATH] = {0};
  2933. GetModuleFileNameW(hInstance, filename, WA_MAX_PATH);
  2934. PathParserW pp(filename);
  2935. StringW path;
  2936. for (int i = 0;i < pp.getNumStrings() - 1;i++)
  2937. {
  2938. path.AppendPath(pp.enumString(i));
  2939. }
  2940. path.AppendPath(L"gen_ml.dll");
  2941. we_have_ml = !WACCESS(path, 0);
  2942. }
  2943. void initEgg()
  2944. {
  2945. eggstr[0] = ~'N';
  2946. eggstr[1] = ~'U';
  2947. eggstr[2] = ~'L';
  2948. eggstr[3] = ~'L';
  2949. eggstr[4] = ~'S';
  2950. eggstr[5] = ~'O';
  2951. eggstr[6] = ~'F';
  2952. eggstr[7] = ~'T';
  2953. eggstr[8] = 0;
  2954. {
  2955. int x;
  2956. for (x = 0; x < 8; x ++) eggstr[x] ^= 255;
  2957. }
  2958. }
  2959. void toggleEgg()
  2960. {
  2961. eggstat = !eggstat;
  2962. if (!eggstat)
  2963. {
  2964. KillTimer(wa2.getMainWindow(), UPDATE_EGG);
  2965. if (lastlayoutegg && WASABI_API_WND->rootwndIsValid(lastlayoutegg)) lastlayoutegg->setTransparencyOverride(-1);
  2966. lastlayoutegg = NULL;
  2967. }
  2968. else SetTimer(wa2.getMainWindow(), UPDATE_EGG, 25, NULL);
  2969. }
  2970. void getCustomMetaData(const wchar_t *field, wchar_t *buf, int len)
  2971. {
  2972. StringW curfile = WASABI_API_MEDIACORE->core_getCurrent(0);
  2973. if (curfile.isempty())
  2974. {
  2975. buf[0] = 0;
  2976. return ;
  2977. }
  2978. if (!_wcsnicmp(curfile, L"file://", 7))
  2979. curfile = StringW(curfile.getValue() + 7);
  2980. buf[0] = 0;
  2981. if (WCSCASEEQLSAFE(field, L"filename"))
  2982. {
  2983. WCSCPYN(buf, curfile, len);
  2984. }
  2985. else
  2986. {
  2987. wa2.getMetaData(curfile, field, buf, len);
  2988. }
  2989. }
  2990. void registerGlobalHotkeys()
  2991. {
  2992. static int registered = 0;
  2993. if (!registered)
  2994. {
  2995. static wchar_t ghkStr[96];
  2996. wa2.registerGlobalHotkey((char*)WASABI_API_LNGSTRINGW_BUF(IDS_GHK_SHOW_NOTIFICATION,ghkStr,96), WM_WA_IPC, 0, IPC_SHOW_NOTIFICATION, HKF_UNICODE_NAME, "genff shn");
  2997. registered = 1;
  2998. }
  2999. }
  3000. const wchar_t *getSongInfoText()
  3001. {
  3002. return Core::getSongInfoText();
  3003. }
  3004. const wchar_t *getSongInfoTextTranslated()
  3005. {
  3006. return Core::getSongInfoTextTranslated();
  3007. }
  3008. OSWINDOWHANDLE getKeyboardForwardWnd(GUID g)
  3009. {
  3010. if (g != INVALID_GUID)
  3011. {
  3012. if (g == playerWndGuid)
  3013. return wa2.getMainWindow();
  3014. else if (g == pleditWndGuid)
  3015. return wa2.getWnd(IPC_GETWND_PE);
  3016. else if (g == videoWndGuid)
  3017. return wa2.getWnd(IPC_GETWND_VIDEO);
  3018. else
  3019. {
  3020. embedWindowState *ews = embedWndGuidMgr.getEmbedWindowState(g);
  3021. if (ews && wa2.isValidEmbedWndState(ews)) return ews->me;
  3022. }
  3023. }
  3024. return WASABI_API_WND->main_getRootWnd()->gethWnd();
  3025. }
  3026. void onAppBarDockChanged(ifc_window *w)
  3027. {
  3028. setDialogBoxesParent();
  3029. }
  3030. void onMainLayoutMove(HWND w)
  3031. {
  3032. // for Winamp to appear on the correct taskbar on Windows 8
  3033. // its necessary to set the classic main window to appear on
  3034. // that monitor and to be on-screen (but hidden) otherwise
  3035. // Windows will ignore it and it then makes us look buggy.
  3036. RECT r;
  3037. Wasabi::Std::getViewport(&r, w, 1);
  3038. SetWindowPos(wa2.getMainWindow(), NULL, r.left, r.bottom - 1, 0, 0, SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOREDRAW);
  3039. }
  3040. void updateAll()
  3041. {
  3042. updatePl();
  3043. #ifdef MINIBROWSER_SUPPORT
  3044. updateMb();
  3045. #endif
  3046. updateVid();
  3047. int n = embedWndGuidMgr.getNumWindowStates();
  3048. for (int i = 0;i < n;i++)
  3049. {
  3050. embedWindowState *ws = NULL;
  3051. GUID g = embedWndGuidMgr.enumWindowState(i, &ws);
  3052. if (g != INVALID_GUID)
  3053. {
  3054. updateEmb(g, ws);
  3055. }
  3056. }
  3057. }
  3058. void onReParent(HWND wnd)
  3059. {
  3060. updateAll();
  3061. }
  3062. void onReInit(HWND wnd)
  3063. {
  3064. updateAll();
  3065. }
  3066. void startFSMonitor()
  3067. {
  3068. g_fsmonitor = new FullScreenMonitor();
  3069. g_fscallback = new Wa5FSCallback();
  3070. g_fsmonitor->registerCallback(g_fscallback);
  3071. }
  3072. void stopFSMonitor()
  3073. {
  3074. delete g_fsmonitor;
  3075. g_fsmonitor = NULL;
  3076. delete g_fscallback;
  3077. g_fscallback = NULL;
  3078. }
  3079. void updateParentlessOnTop()
  3080. {
  3081. int i;
  3082. for (i = 0;i < SkinParser::getNumContainers();i++)
  3083. {
  3084. Container *c = SkinParser::enumContainer(i);
  3085. if (c != NULL)
  3086. {
  3087. int j;
  3088. for (j = 0;j < c->getNumLayouts();j++)
  3089. {
  3090. Layout *l = c->enumLayout(j);
  3091. if (l != NULL)
  3092. {
  3093. // skip windows owned by winamp
  3094. // skip appbars, they take care of themselves
  3095. if (l->getNoParent() && !l->appbar_isDocked())
  3096. {
  3097. l->updateOnTop();
  3098. }
  3099. }
  3100. }
  3101. }
  3102. }
  3103. }
  3104. void onGoFullscreen()
  3105. {
  3106. // hidden windows will not receive APPBAR_CALLBACK, so forward it to winamp's main
  3107. SendMessageW(wa2.getMainWindow(), APPBAR_CALLBACK, ABN_FULLSCREENAPP, 1);
  3108. // update ontop flag for windows that are not parented to winamp
  3109. updateParentlessOnTop();
  3110. }
  3111. void onCancelFullscreen()
  3112. {
  3113. // hidden windows will not receive APPBAR_CALLBACK, so forward it to winamp's main
  3114. SendMessageW(wa2.getMainWindow(), APPBAR_CALLBACK, ABN_FULLSCREENAPP, 0);
  3115. // update ontop flag for windows that are not owned by winamp
  3116. updateParentlessOnTop();
  3117. }
  3118. int processGenericHotkey(const char *hk)
  3119. {
  3120. if (!m_are_we_loaded) return 0;
  3121. SystemObject::onKeyDown(AutoWide(StringPrintf("HOTKEY: %s", hk)));
  3122. if (VCPU::getComplete())
  3123. {
  3124. DebugStringW(L"HOTKEY: %s trapped by script\n", hk);
  3125. return 1;
  3126. }
  3127. return 0;
  3128. }
  3129. int canExitWinamp()
  3130. {
  3131. return wa2.isExitEnabled();
  3132. }
  3133. int fsMonitorIsFS()
  3134. {
  3135. return g_fsmonitor->isFullScreen();
  3136. }
  3137. void modalPush()
  3138. {
  3139. wa2.pushExitDisabled();
  3140. }
  3141. void modalPop()
  3142. {
  3143. wa2.popExitDisabled();
  3144. }