UIManager.cpp 139 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873
  1. #include "StdAfx.h"
  2. #include <zmouse.h>
  3. #pragma warning(push)
  4. #pragma warning(disable:4838 4244)
  5. namespace DuiLib
  6. {
  7. /////////////////////////////////////////////////////////////////////////////////////
  8. //
  9. //
  10. // 触屏参数(NIM Duilib 模型)
  11. // TOUCHINPUT 的坐标以 1/100 像素为单位,必须先换算成像素
  12. #ifndef TOUCH_COORD_TO_PIXEL
  13. #define TOUCH_COORD_TO_PIXEL(l) ((l) / 100)
  14. #endif
  15. // [触屏模型变更] 不再使用 tap-slop 阈值:100% 照搬 NIM Duilib,触摸“点击”交给 Windows
  16. // 为触摸模拟的 WM_LBUTTONDOWN/UP(原生鼠标路径),滚动交给原生 UIEVENT_TOUCHMOVE,
  17. // 二者由 m_pEventTouch 守卫互斥,无需自定滑动阈值。
  18. // WM_TOUCH 消息 ID 同样受 `#if _WIN32_WINNT >= 0x0601` 保护,DuiLib 工程未定义
  19. // _WIN32_WINNT(StdAfx.h 兜底为 XP)→ 必须自行声明,否则 switch 里引用该消息 ID
  20. // 会报 C2065(未声明的标识符)与 C2051(case 表达式不是常量)。实测固定值 0x0240。
  21. // 注:Win7+ 段受保护的不仅有结构体与函数,**消息 ID 与辅助宏同样在内**,
  22. // TOUCH_COORD_TO_PIXEL 也在上面用 #ifndef 兜底,原因相同。
  23. #ifndef WM_TOUCH
  24. #define WM_TOUCH 0x0240
  25. #endif
  26. static void GetChildWndRect(HWND hWnd, HWND hChildWnd, RECT& rcChildWnd)
  27. {
  28. ::GetWindowRect(hChildWnd, &rcChildWnd);
  29. POINT pt;
  30. pt.x = rcChildWnd.left;
  31. pt.y = rcChildWnd.top;
  32. ::ScreenToClient(hWnd, &pt);
  33. rcChildWnd.left = pt.x;
  34. rcChildWnd.top = pt.y;
  35. pt.x = rcChildWnd.right;
  36. pt.y = rcChildWnd.bottom;
  37. ::ScreenToClient(hWnd, &pt);
  38. rcChildWnd.right = pt.x;
  39. rcChildWnd.bottom = pt.y;
  40. }
  41. static UINT MapKeyState()
  42. {
  43. UINT uState = 0;
  44. if (::GetKeyState(VK_CONTROL) < 0) uState |= MK_CONTROL;
  45. if (::GetKeyState(VK_LBUTTON) < 0) uState |= MK_LBUTTON;
  46. if (::GetKeyState(VK_RBUTTON) < 0) uState |= MK_RBUTTON;
  47. if (::GetKeyState(VK_SHIFT) < 0) uState |= MK_SHIFT;
  48. if (::GetKeyState(VK_MENU) < 0) uState |= MK_ALT;
  49. return uState;
  50. }
  51. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  52. ///
  53. typedef struct tagFINDTABINFO
  54. {
  55. CControlUI* pFocus;
  56. CControlUI* pLast;
  57. bool bForward;
  58. bool bNextIsIt;
  59. } FINDTABINFO;
  60. typedef struct tagFINDSHORTCUT
  61. {
  62. TCHAR ch;
  63. bool bPickNext;
  64. } FINDSHORTCUT;
  65. typedef struct tagTIMERINFO
  66. {
  67. CControlUI* pSender;
  68. UINT nLocalID;
  69. HWND hWnd;
  70. UINT uWinTimer;
  71. bool bKilled;
  72. } TIMERINFO;
  73. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  74. ///
  75. tagTImageInfo::tagTImageInfo()
  76. {
  77. pImage = NULL;
  78. hBitmap = NULL;
  79. }
  80. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  81. ///
  82. tagTDrawInfo::tagTDrawInfo()
  83. {
  84. Clear();
  85. }
  86. void tagTDrawInfo::Parse(LPCTSTR pStrImage, LPCTSTR pStrModify, CPaintManagerUI* pManager)
  87. {
  88. // 1、aaa.jpg
  89. // 2、file='aaa.jpg' res='' restype='0' dest='0,0,0,0' source='0,0,0,0' corner='0,0,0,0'
  90. // mask='#FF0000' fade='255' hole='false' xtiled='false' ytiled='false'
  91. sDrawString = pStrImage;
  92. sDrawModify = pStrModify;
  93. sImageName = pStrImage;
  94. CDuiString sItem;
  95. CDuiString sValue;
  96. LPTSTR pstr = NULL;
  97. for (int i = 0; i < 2; ++i)
  98. {
  99. if (i == 1) pStrImage = pStrModify;
  100. if (!pStrImage) continue;
  101. while (*pStrImage != _T('\0'))
  102. {
  103. sItem.Empty();
  104. sValue.Empty();
  105. while (*pStrImage > _T('\0') && *pStrImage <= _T(' ')) pStrImage = ::CharNext(pStrImage);
  106. while (*pStrImage != _T('\0') && *pStrImage != _T('=') && *pStrImage > _T(' '))
  107. {
  108. LPTSTR pstrTemp = ::CharNext(pStrImage);
  109. while (pStrImage < pstrTemp)
  110. {
  111. sItem += *pStrImage++;
  112. }
  113. }
  114. while (*pStrImage > _T('\0') && *pStrImage <= _T(' ')) pStrImage = ::CharNext(pStrImage);
  115. if (*pStrImage++ != _T('=')) break;
  116. while (*pStrImage > _T('\0') && *pStrImage <= _T(' ')) pStrImage = ::CharNext(pStrImage);
  117. if (*pStrImage++ != _T('\'')) break;
  118. while (*pStrImage != _T('\0') && *pStrImage != _T('\''))
  119. {
  120. LPTSTR pstrTemp = ::CharNext(pStrImage);
  121. while (pStrImage < pstrTemp)
  122. {
  123. sValue += *pStrImage++;
  124. }
  125. }
  126. if (*pStrImage++ != _T('\'')) break;
  127. if (!sValue.IsEmpty())
  128. {
  129. if (sItem == _T("file") || sItem == _T("res"))
  130. {
  131. sImageName = sValue;
  132. }
  133. else if (sItem == _T("restype"))
  134. {
  135. sResType = sValue;
  136. }
  137. else if (sItem == _T("dest"))
  138. {
  139. rcDest.left = _tcstol(sValue.GetData(), &pstr, 10); ASSERT(pstr);
  140. rcDest.top = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  141. rcDest.right = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  142. rcDest.bottom = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  143. //if(pManager != NULL) pManager->GetDPIObj()->Scale(&rcDest);
  144. }
  145. else if (sItem == _T("source"))
  146. {
  147. rcSource.left = _tcstol(sValue.GetData(), &pstr, 10); ASSERT(pstr);
  148. rcSource.top = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  149. rcSource.right = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  150. rcSource.bottom = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  151. //if(pManager != NULL) pManager->GetDPIObj()->Scale(&rcSource);
  152. }
  153. else if (sItem == _T("corner"))
  154. {
  155. rcCorner.left = _tcstol(sValue.GetData(), &pstr, 10); ASSERT(pstr);
  156. rcCorner.top = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  157. rcCorner.right = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  158. rcCorner.bottom = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  159. //if(pManager != NULL) pManager->GetDPIObj()->Scale(&rcCorner);
  160. }
  161. else if (sItem == _T("mask"))
  162. {
  163. if (sValue[0] == _T('#')) dwMask = _tcstoul(sValue.GetData() + 1, &pstr, 16);
  164. else dwMask = _tcstoul(sValue.GetData(), &pstr, 16);
  165. }
  166. else if (sItem == _T("fade"))
  167. {
  168. uFade = (UINT)_tcstoul(sValue.GetData(), &pstr, 10);
  169. }
  170. else if (sItem == _T("rotate"))
  171. {
  172. uRotate = (UINT)_tcstoul(sValue.GetData(), &pstr, 10);
  173. bGdiplus = true;
  174. }
  175. else if (sItem == _T("gdiplus"))
  176. {
  177. bGdiplus = (_tcsicmp(sValue.GetData(), _T("true")) == 0);
  178. }
  179. else if (sItem == _T("hole"))
  180. {
  181. bHole = (_tcsicmp(sValue.GetData(), _T("true")) == 0);
  182. }
  183. else if (sItem == _T("xtiled"))
  184. {
  185. bTiledX = (_tcsicmp(sValue.GetData(), _T("true")) == 0);
  186. }
  187. else if (sItem == _T("ytiled"))
  188. {
  189. bTiledY = (_tcsicmp(sValue.GetData(), _T("true")) == 0);
  190. }
  191. else if (sItem == _T("hsl"))
  192. {
  193. bHSL = (_tcsicmp(sValue.GetData(), _T("true")) == 0);
  194. }
  195. else if (sItem == _T("size"))
  196. {
  197. szImage.cx = _tcstol(sValue.GetData(), &pstr, 10); ASSERT(pstr);
  198. szImage.cy = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  199. }
  200. else if (sItem == _T("align"))
  201. {
  202. sAlign = sValue;
  203. }
  204. else if (sItem == _T("padding"))
  205. {
  206. rcPadding.left = _tcstol(sValue.GetData(), &pstr, 10); ASSERT(pstr);
  207. rcPadding.top = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  208. rcPadding.right = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  209. rcPadding.bottom = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
  210. //if(pManager != NULL) pManager->GetDPIObj()->Scale(&rcPadding);
  211. }
  212. }
  213. if (*pStrImage++ != _T(' ')) break;
  214. }
  215. }
  216. // 调整DPI资源
  217. if (pManager != NULL && pManager->GetDPIObj()->GetScale() != 100)
  218. {
  219. CDuiString sScale;
  220. sScale.Format(_T("@%d."), pManager->GetDPIObj()->GetScale());
  221. sImageName.Replace(_T("."), sScale);
  222. }
  223. }
  224. void tagTDrawInfo::Clear()
  225. {
  226. sDrawString.Empty();
  227. sDrawModify.Empty();
  228. sImageName.Empty();
  229. memset(&rcDest, 0, sizeof(RECT));
  230. memset(&rcSource, 0, sizeof(RECT));
  231. memset(&rcCorner, 0, sizeof(RECT));
  232. dwMask = 0;
  233. uFade = 255;
  234. uRotate = 0;
  235. bHole = false;
  236. bTiledX = false;
  237. bTiledY = false;
  238. bHSL = false;
  239. bGdiplus = false;
  240. szImage.cx = szImage.cy = 0;
  241. sAlign.Empty();
  242. memset(&rcPadding, 0, sizeof(RECT));
  243. }
  244. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  245. ///
  246. typedef BOOL(__stdcall* PFUNCUPDATELAYEREDWINDOW)(HWND, HDC, POINT*, SIZE*, HDC, POINT*, COLORREF, BLENDFUNCTION*, DWORD);
  247. PFUNCUPDATELAYEREDWINDOW g_fUpdateLayeredWindow = NULL;
  248. HPEN m_hUpdateRectPen = NULL;
  249. HINSTANCE CPaintManagerUI::m_hResourceInstance = NULL;
  250. CDuiString CPaintManagerUI::m_pStrResourcePath;
  251. CDuiString CPaintManagerUI::m_pStrResourceZip;
  252. CDuiString CPaintManagerUI::m_pStrResourceZipPwd; //Garfield 20160325 带密码zip包解密
  253. HANDLE CPaintManagerUI::m_hResourceZip = NULL;
  254. bool CPaintManagerUI::m_bCachedResourceZip = true;
  255. BYTE* CPaintManagerUI::m_cbZipBuf = nullptr;
  256. int CPaintManagerUI::m_nResType = UILIB_FILE;
  257. TResInfo CPaintManagerUI::m_SharedResInfo;
  258. HINSTANCE CPaintManagerUI::m_hInstance = NULL;
  259. bool CPaintManagerUI::m_bUseHSL = false;
  260. short CPaintManagerUI::m_H = 180;
  261. short CPaintManagerUI::m_S = 100;
  262. short CPaintManagerUI::m_L = 100;
  263. CStdPtrArray CPaintManagerUI::m_aPreMessages;
  264. CStdPtrArray CPaintManagerUI::m_aPlugins;
  265. CPaintManagerUI::CPaintManagerUI() :
  266. m_hWndPaint(NULL),
  267. m_hDcPaint(NULL),
  268. m_hDcOffscreen(NULL),
  269. m_hDcBackground(NULL),
  270. m_bOffscreenPaint(true),
  271. m_hbmpOffscreen(NULL),
  272. m_pOffscreenBits(NULL),
  273. m_hbmpBackground(NULL),
  274. m_pBackgroundBits(NULL),
  275. m_hwndTooltip(NULL),
  276. m_uTimerID(0x1000),
  277. m_pRoot(NULL),
  278. m_pFocus(NULL),
  279. m_pEventHover(NULL),
  280. m_pEventClick(NULL),
  281. m_pEventRClick(NULL),
  282. m_pEventKey(NULL),
  283. m_bFirstLayout(true),
  284. m_bFocusNeeded(false),
  285. m_bUpdateNeeded(false),
  286. m_bMouseTracking(false),
  287. m_bMouseCapture(false),
  288. m_bAsyncNotifyPosted(false),
  289. m_bUsedVirtualWnd(false),
  290. m_bForceUseSharedRes(false),
  291. m_nOpacity(0xFF),
  292. m_bLayered(false),
  293. m_bLayeredChanged(false),
  294. m_bShowUpdateRect(false),
  295. m_bUseGdiplusText(false),
  296. m_trh(0),
  297. m_bDragDrop(false),
  298. m_bDragMode(false),
  299. m_hDragBitmap(NULL),
  300. m_pDPI(NULL),
  301. m_iHoverTime(400UL),
  302. // [FIX] m_bNoActivate 原本未初始化:Debug 堆新块填充 0xCD -> 读到 true;
  303. // Release 下则是随机垃圾值,属偶发性隐患。
  304. // 后果:本文件中 3 处 "if (!m_bNoActivate) ::SetFocus(m_hWndPaint);"
  305. // (WM_LBUTTONDOWN 1738 / CPaintManagerUI::SetFocus 2442 / SetFocusNeeded 2475) 全部被跳过,
  306. // 系统焦点无法回到主窗口 -> 原生 EDIT 子窗 CEditWnd 收不到 WM_KILLFOCUS ->
  307. // 其唯一的销毁途径 PostMessage(WM_CLOSE) 永不触发 -> 光标常闪、点空白不丢焦点。
  308. // XML 侧仅在显式书写 noactivate 属性时才赋值(UIDlgBuilder.cpp),故此处必须先给确定初值。
  309. m_bNoActivate(false),
  310. // 以下两个成员同样是漏网之鱼(全库无赋值点),一并清零以防后患。
  311. m_bIsPainting(false),
  312. m_pLastToolTip(NULL)
  313. {
  314. if (m_SharedResInfo.m_DefaultFontInfo.sFontName.IsEmpty())
  315. {
  316. m_SharedResInfo.m_dwDefaultDisabledColor = 0xFFA7A6AA;
  317. m_SharedResInfo.m_dwDefaultFontColor = 0xFF000000;
  318. m_SharedResInfo.m_dwDefaultLinkFontColor = 0xFF0000FF;
  319. m_SharedResInfo.m_dwDefaultLinkHoverFontColor = 0xFFD3215F;
  320. m_SharedResInfo.m_dwDefaultSelectedBkColor = 0xFFBAE4FF;
  321. LOGFONT lf = { 0 };
  322. ::GetObject(::GetStockObject(DEFAULT_GUI_FONT), sizeof(LOGFONT), &lf);
  323. lf.lfCharSet = DEFAULT_CHARSET;
  324. HFONT hDefaultFont = ::CreateFontIndirect(&lf);
  325. m_SharedResInfo.m_DefaultFontInfo.hFont = hDefaultFont;
  326. m_SharedResInfo.m_DefaultFontInfo.sFontName = lf.lfFaceName;
  327. m_SharedResInfo.m_DefaultFontInfo.iSize = -lf.lfHeight;
  328. m_SharedResInfo.m_DefaultFontInfo.bBold = (lf.lfWeight >= FW_BOLD);
  329. m_SharedResInfo.m_DefaultFontInfo.bUnderline = (lf.lfUnderline == TRUE);
  330. m_SharedResInfo.m_DefaultFontInfo.bItalic = (lf.lfItalic == TRUE);
  331. ::ZeroMemory(&m_SharedResInfo.m_DefaultFontInfo.tm, sizeof(m_SharedResInfo.m_DefaultFontInfo.tm));
  332. }
  333. m_ResInfo.m_dwDefaultDisabledColor = m_SharedResInfo.m_dwDefaultDisabledColor;
  334. m_ResInfo.m_dwDefaultFontColor = m_SharedResInfo.m_dwDefaultFontColor;
  335. m_ResInfo.m_dwDefaultLinkFontColor = m_SharedResInfo.m_dwDefaultLinkFontColor;
  336. m_ResInfo.m_dwDefaultLinkHoverFontColor = m_SharedResInfo.m_dwDefaultLinkHoverFontColor;
  337. m_ResInfo.m_dwDefaultSelectedBkColor = m_SharedResInfo.m_dwDefaultSelectedBkColor;
  338. if (m_hUpdateRectPen == NULL)
  339. {
  340. m_hUpdateRectPen = ::CreatePen(PS_SOLID, 1, RGB(220, 0, 0));
  341. // Boot Windows Common Controls (for the ToolTip control)
  342. ::InitCommonControls();
  343. ::LoadLibrary(_T("msimg32.dll"));
  344. }
  345. m_szMinWindow.cx = 0;
  346. m_szMinWindow.cy = 0;
  347. m_szMaxWindow.cx = 0;
  348. m_szMaxWindow.cy = 0;
  349. m_szInitWindowSize.cx = 0;
  350. m_szInitWindowSize.cy = 0;
  351. m_szRoundCorner.cx = m_szRoundCorner.cy = 0;
  352. ::ZeroMemory(&m_rcSizeBox, sizeof(m_rcSizeBox));
  353. ::ZeroMemory(&m_rcCaption, sizeof(m_rcCaption));
  354. ::ZeroMemory(&m_rcLayeredInset, sizeof(m_rcLayeredInset));
  355. ::ZeroMemory(&m_rcLayeredUpdate, sizeof(m_rcLayeredUpdate));
  356. m_ptLastMousePos.x = m_ptLastMousePos.y = -1;
  357. m_pGdiplusStartupInput = new Gdiplus::GdiplusStartupInput;
  358. Gdiplus::GdiplusStartup(&m_gdiplusToken, m_pGdiplusStartupInput, NULL); // 加载GDI接口
  359. CShadowUI::Initialize(m_hInstance);
  360. m_pDragDrop = NULL;
  361. }
  362. CPaintManagerUI::~CPaintManagerUI()
  363. {
  364. // Delete the control-tree structures
  365. for (int i = 0; i < m_aDelayedCleanup.GetSize(); i++) delete static_cast<CControlUI*>(m_aDelayedCleanup[i]);
  366. m_aDelayedCleanup.Resize(0);
  367. for (int i = 0; i < m_aAsyncNotify.GetSize(); i++) delete static_cast<TNotifyUI*>(m_aAsyncNotify[i]);
  368. m_aAsyncNotify.Resize(0);
  369. m_mNameHash.Resize(0);
  370. if (m_pRoot != NULL) delete m_pRoot;
  371. ::DeleteObject(m_ResInfo.m_DefaultFontInfo.hFont);
  372. RemoveAllFonts();
  373. RemoveAllImages();
  374. RemoveAllStyle();
  375. RemoveAllDefaultAttributeList();
  376. RemoveAllWindowCustomAttribute();
  377. RemoveAllOptionGroups();
  378. RemoveAllTimers();
  379. RemoveAllDrawInfos();
  380. if (m_hwndTooltip != NULL)
  381. {
  382. ::DestroyWindow(m_hwndTooltip);
  383. m_hwndTooltip = NULL;
  384. }
  385. if (!m_aFonts.IsEmpty())
  386. {
  387. for (int i = 0; i < m_aFonts.GetSize(); ++i)
  388. {
  389. HANDLE handle = static_cast<HANDLE>(m_aFonts.GetAt(i));
  390. ::RemoveFontMemResourceEx(handle);
  391. }
  392. }
  393. if (m_hDcOffscreen != NULL) ::DeleteDC(m_hDcOffscreen);
  394. if (m_hDcBackground != NULL) ::DeleteDC(m_hDcBackground);
  395. if (m_hbmpOffscreen != NULL) ::DeleteObject(m_hbmpOffscreen);
  396. if (m_hbmpBackground != NULL) ::DeleteObject(m_hbmpBackground);
  397. if (m_hDcPaint != NULL) ::ReleaseDC(m_hWndPaint, m_hDcPaint);
  398. m_aPreMessages.Remove(m_aPreMessages.Find(this));
  399. // 销毁拖拽图片
  400. if (m_hDragBitmap != NULL) ::DeleteObject(m_hDragBitmap);
  401. //卸载GDIPlus
  402. Gdiplus::GdiplusShutdown(m_gdiplusToken);
  403. delete m_pGdiplusStartupInput;
  404. // DPI管理对象
  405. if (m_pDPI != NULL)
  406. {
  407. delete m_pDPI;
  408. m_pDPI = NULL;
  409. }
  410. }
  411. void CPaintManagerUI::Init(HWND hWnd, LPCTSTR pstrName)
  412. {
  413. ASSERT(::IsWindow(hWnd));
  414. m_mNameHash.Resize();
  415. RemoveAllFonts();
  416. RemoveAllImages();
  417. RemoveAllStyle();
  418. RemoveAllDefaultAttributeList();
  419. RemoveAllWindowCustomAttribute();
  420. RemoveAllOptionGroups();
  421. RemoveAllTimers();
  422. m_sName.Empty();
  423. if (pstrName != NULL) m_sName = pstrName;
  424. if (m_hWndPaint != hWnd)
  425. {
  426. m_hWndPaint = hWnd;
  427. m_hDcPaint = ::GetDC(hWnd);
  428. m_aPreMessages.Add(this);
  429. // 触屏兼容:每个窗口(主窗口 + 所有弹框)统一注册 WM_TOUCH,由本类库级接管,
  430. // 无需 CTouchWindowBase 外挂,也无需逐窗口样板。注册是幂等的,重复调用无害。
  431. InitTouchSupport();
  432. }
  433. }
  434. // ---------------------------------------------------------------------------
  435. // 触摸 API 懒加载包装(对标 NIM Duilib 的 RegisterTouchWindowWrapper 系列)。
  436. //
  437. // 为什么不能直接调用这些 API:DuiLib 工程自身没有定义 _WIN32_WINNT,
  438. // StdAfx.h 会把它兜底设成 XP(0x0501);而 TOUCHINPUT / GetTouchInputInfo /
  439. // RegisterTouchWindow 在 winuser.h 里受 `#if _WIN32_WINNT >= 0x0601` 保护,
  440. // 直接引用会编译报错(C2065/C3861)。(主工程定义了 0x0601,所以
  441. // CTouchWindowBase 里能直接用,那里不受影响。)
  442. //
  443. // 因此这里完全自给自足:自行声明与 SDK 完全一致的 TOUCHINPUT 布局和事件标志,
  444. // 再用 GetProcAddress 取函数地址。这样:
  445. // * 无论 DuiLib 的 target 版本如何都能编译通过;
  446. // * 在没有触摸 API 的系统上自动降级为空操作,不会崩溃。
  447. // ---------------------------------------------------------------------------
  448. namespace TouchApi
  449. {
  450. // 与 winuser.h 的 tagTOUCHINPUT 布局逐字段一致
  451. typedef struct tagTouchInput
  452. {
  453. LONG x;
  454. LONG y;
  455. HANDLE hSource;
  456. DWORD dwID;
  457. DWORD dwFlags;
  458. DWORD dwMask;
  459. DWORD dwTime;
  460. ULONG_PTR dwExtraInfo;
  461. DWORD cxContact;
  462. DWORD cyContact;
  463. } TOUCHINPUT, *PTOUCHINPUT;
  464. // 事件标志,数值与 winuser.h 的触摸事件标志一致。
  465. // 名字必须避开 SDK 的同名宏:部分 SDK 把它们定义成【宏】,且不受 _WIN32_WINNT 版本段保护,
  466. // 同名会被预处理器展开——声明变成 `const DWORD 0x0002 = 0x0002;`(C2059),
  467. // 限定使用变成 `TouchApi::0x0004`(C2589)。故改用 TOUCHEVTFLAG 前缀。
  468. const DWORD TOUCHEVTFLAG_MOVE = 0x0002;
  469. const DWORD TOUCHEVTFLAG_DOWN = 0x0004;
  470. const DWORD TOUCHEVTFLAG_UP = 0x0008;
  471. typedef BOOL (WINAPI *PFN_RegisterTouchWindow)(HWND, ULONG);
  472. typedef BOOL (WINAPI *PFN_GetTouchInputInfo)(HANDLE, UINT, PTOUCHINPUT, int);
  473. typedef BOOL (WINAPI *PFN_CloseTouchInputHandle)(HANDLE);
  474. inline HMODULE GetUser32()
  475. {
  476. static HMODULE s_hMod = NULL;
  477. static bool s_bInited = false;
  478. if (!s_bInited)
  479. {
  480. s_bInited = true;
  481. s_hMod = ::GetModuleHandle(_T("user32.dll"));
  482. }
  483. return s_hMod;
  484. }
  485. inline PFN_RegisterTouchWindow GetRegisterTouchWindow()
  486. {
  487. static PFN_RegisterTouchWindow s_pfn = NULL;
  488. static bool s_bInited = false;
  489. if (!s_bInited)
  490. {
  491. s_bInited = true;
  492. HMODULE hMod = GetUser32();
  493. if (hMod != NULL) s_pfn = (PFN_RegisterTouchWindow)::GetProcAddress(hMod, "RegisterTouchWindow");
  494. }
  495. return s_pfn;
  496. }
  497. inline PFN_GetTouchInputInfo GetGetTouchInputInfo()
  498. {
  499. static PFN_GetTouchInputInfo s_pfn = NULL;
  500. static bool s_bInited = false;
  501. if (!s_bInited)
  502. {
  503. s_bInited = true;
  504. HMODULE hMod = GetUser32();
  505. if (hMod != NULL) s_pfn = (PFN_GetTouchInputInfo)::GetProcAddress(hMod, "GetTouchInputInfo");
  506. }
  507. return s_pfn;
  508. }
  509. inline PFN_CloseTouchInputHandle GetCloseTouchInputHandle()
  510. {
  511. static PFN_CloseTouchInputHandle s_pfn = NULL;
  512. static bool s_bInited = false;
  513. if (!s_bInited)
  514. {
  515. s_bInited = true;
  516. HMODULE hMod = GetUser32();
  517. if (hMod != NULL) s_pfn = (PFN_CloseTouchInputHandle)::GetProcAddress(hMod, "CloseTouchInputHandle");
  518. }
  519. return s_pfn;
  520. }
  521. }
  522. void CPaintManagerUI::InitTouchSupport()
  523. {
  524. if (m_hWndPaint == NULL || !::IsWindow(m_hWndPaint)) return;
  525. TouchApi::PFN_RegisterTouchWindow pfnRegister = TouchApi::GetRegisterTouchWindow();
  526. if (pfnRegister != NULL)
  527. pfnRegister(m_hWndPaint, 0);
  528. }
  529. void CPaintManagerUI::OnTouchInput(WPARAM wParam, LPARAM lParam)
  530. {
  531. // 100% 照搬 NIM Duilib 的 Window::HandleMessage case WM_TOUCH(Window.cpp:1139-1199)。
  532. // 设计要点(不要自创归一化 / 状态机):
  533. // 1) 独立的 m_pEventTouch 追踪“本次触摸命中控件”,DOWN 设定、UP 清空;绝不复用 m_pEventClick。
  534. // 2) 只向控件派发“原生触摸事件” UIEVENT_TOUCHDOWN / UIEVENT_TOUCHMOVE / UIEVENT_TOUCHUP,
  535. // 由 CContainerUI::DoEvent 把 TOUCHMOVE 当作 1:1 跟手滚动(对标 NIM ScrollableBox)。
  536. // 3) 按钮“点击”不在这里合成!它来自 Windows 为触摸自动模拟的 WM_LBUTTONDOWN/UP,
  537. // 走 MessageHandler 里原生的鼠标点击路径(CButtonUI 等据此 Activate())。NIM 从不过滤
  538. // 这些模拟鼠标,只在 WM_LBUTTON* 分支加了 m_pEventTouch!=NULL 守卫,保证一次手指手势
  539. // 要么滚动、要么点击,不会双触发。
  540. // 4) 守卫:若 m_pEventClick 已存在(鼠标/指针交互进行中),直接忽略本次触摸,互不打架。
  541. TouchApi::PFN_GetTouchInputInfo pfnGetInfo = TouchApi::GetGetTouchInputInfo();
  542. if (pfnGetInfo == NULL) return;
  543. UINT cInputs = LOWORD(wParam);
  544. if (cInputs == 0) return;
  545. std::vector<TouchApi::TOUCHINPUT> inputs(cInputs);
  546. if (!pfnGetInfo((HANDLE)lParam, cInputs, inputs.data(), (int)sizeof(TouchApi::TOUCHINPUT)))
  547. return;
  548. for (UINT i = 0; i < cInputs; ++i)
  549. {
  550. TouchApi::TOUCHINPUT& ti = inputs[i];
  551. // 仅处理主触点(dwID==0 为保留值,NIM 同款跳过)
  552. if (ti.dwID == 0) continue;
  553. POINT pt;
  554. pt.x = TOUCH_COORD_TO_PIXEL(ti.x);
  555. pt.y = TOUCH_COORD_TO_PIXEL(ti.y);
  556. ::ScreenToClient(m_hWndPaint, &pt);
  557. if (ti.dwFlags & TouchApi::TOUCHEVTFLAG_DOWN)
  558. {
  559. // 鼠标/指针交互进行中 -> 忽略触摸(NIM 同款守卫)
  560. if (m_pEventClick != NULL) break;
  561. ::SetFocus(m_hWndPaint);
  562. m_ptLastTouchPos = pt;
  563. CControlUI* pControl = FindControl(pt);
  564. if (pControl == NULL) break;
  565. if (pControl->GetManager() != this) break;
  566. // 滚动条:滑块拖拽/点击由原生鼠标路径(模拟的 WM_LBUTTONDOWN/MOVE/UP)驱动;
  567. // 若此处再派发 UIEVENT_TOUCHMOVE 会冒泡到容器把【内容】滚走,与滑块拖拽打架→滑块拖不动、点轨道误翻页。
  568. // 直接交回原生鼠标,本函数提前退出(悬浮态由 WM_TOUCH UP 统一清理)。
  569. if (pControl->GetInterface(_T("ScrollBar")) != NULL)
  570. break;
  571. m_pEventTouch = pControl;
  572. m_bTouchMoved = false;
  573. m_ptTouchStart = pt;
  574. pControl->SetFocus();
  575. SetCapture(); // mgr 级:m_bMouseCapture=true + ::SetCapture
  576. TEventUI event = { 0 };
  577. event.Type = UIEVENT_TOUCHDOWN;
  578. event.pSender = pControl;
  579. event.ptMouse = pt;
  580. event.dwTimestamp = ::GetTickCount();
  581. event.wKeyState = MapKeyState();
  582. pControl->Event(event);
  583. }
  584. else if (ti.dwFlags & TouchApi::TOUCHEVTFLAG_MOVE)
  585. {
  586. // 鼠标/指针交互进行中 -> 忽略触摸
  587. if (m_pEventClick != NULL) break;
  588. // 与上一包完全相同的点 -> 去重,避免无谓派发(NIM 同款守卫)
  589. if (m_ptLastTouchPos.x == pt.x && m_ptLastTouchPos.y == pt.y) break;
  590. // 本次位移增量(相对上一包),随事件下发,滚动容器据此做 1:1 跟手平移
  591. LONG dx = pt.x - m_ptLastTouchPos.x;
  592. LONG dy = pt.y - m_ptLastTouchPos.y;
  593. m_ptLastTouchPos = pt;
  594. // 相对手势起点的累计位移超过阈值 -> 判定为拖拽(用于松开时抑制点击)
  595. LONG ox = pt.x - m_ptTouchStart.x;
  596. LONG oy = pt.y - m_ptTouchStart.y;
  597. if (ox > 5 || ox < -5 || oy > 5 || oy < -5)
  598. m_bTouchMoved = true;
  599. if (m_pEventTouch == NULL) break;
  600. TEventUI event = { 0 };
  601. event.Type = UIEVENT_TOUCHMOVE;
  602. event.pSender = m_pEventTouch;
  603. event.ptMouse = pt;
  604. event.dwTimestamp = ::GetTickCount();
  605. event.wKeyState = MapKeyState();
  606. event.wParam = (WPARAM)(int)dx;
  607. event.lParam = (LPARAM)(int)dy;
  608. m_pEventTouch->Event(event);
  609. }
  610. else if (ti.dwFlags & TouchApi::TOUCHEVTFLAG_UP)
  611. {
  612. m_ptLastTouchPos = pt;
  613. // 触屏抬起模拟“鼠标离开”:清除悬浮态。触摸不会生成 WM_MOUSELEAVE,
  614. // 否则按钮/列表项点击后悬浮态残留。滚动条等提前退出的触点 m_pEventTouch 为 NULL,同样要清。
  615. if (m_pEventHover != NULL)
  616. {
  617. TEventUI event = { 0 };
  618. event.Type = UIEVENT_MOUSELEAVE;
  619. event.pSender = m_pEventHover;
  620. event.ptMouse = pt;
  621. event.wKeyState = MapKeyState();
  622. event.dwTimestamp = ::GetTickCount();
  623. m_pEventHover->Event(event);
  624. m_pEventHover = NULL;
  625. }
  626. // 滚动条等场景本函数未接管(m_pEventTouch 为 NULL),捕获由原生鼠标路径负责,这里不释放。
  627. if (m_pEventTouch == NULL) break;
  628. ReleaseCapture();
  629. TEventUI event = { 0 };
  630. event.Type = UIEVENT_TOUCHUP;
  631. event.pSender = m_pEventTouch;
  632. event.ptMouse = pt;
  633. event.dwTimestamp = ::GetTickCount();
  634. event.wKeyState = MapKeyState();
  635. m_pEventTouch->Event(event);
  636. m_pEventTouch = NULL;
  637. }
  638. }
  639. TouchApi::PFN_CloseTouchInputHandle pfnClose = TouchApi::GetCloseTouchInputHandle();
  640. if (pfnClose != NULL)
  641. pfnClose((HANDLE)lParam);
  642. }
  643. void CPaintManagerUI::DeletePtr(void* ptr)
  644. {
  645. if (ptr)
  646. {
  647. delete ptr; ptr = NULL;
  648. }
  649. }
  650. HINSTANCE CPaintManagerUI::GetInstance()
  651. {
  652. return m_hInstance;
  653. }
  654. CDuiString CPaintManagerUI::GetInstancePath()
  655. {
  656. if (m_hInstance == NULL) return _T('\0');
  657. TCHAR tszModule[MAX_PATH + 1] = { 0 };
  658. ::GetModuleFileName(m_hInstance, tszModule, MAX_PATH);
  659. CDuiString sInstancePath = tszModule;
  660. int pos = sInstancePath.ReverseFind(_T('\\'));
  661. if (pos >= 0) sInstancePath = sInstancePath.Left(pos + 1);
  662. return sInstancePath;
  663. }
  664. CDuiString CPaintManagerUI::GetCurrentPath()
  665. {
  666. TCHAR tszModule[MAX_PATH + 1] = { 0 };
  667. ::GetCurrentDirectory(MAX_PATH, tszModule);
  668. return tszModule;
  669. }
  670. HINSTANCE CPaintManagerUI::GetResourceDll()
  671. {
  672. if (m_hResourceInstance == NULL) return m_hInstance;
  673. return m_hResourceInstance;
  674. }
  675. const CDuiString& CPaintManagerUI::GetResourcePath()
  676. {
  677. return m_pStrResourcePath;
  678. }
  679. const CDuiString& CPaintManagerUI::GetResourceZip()
  680. {
  681. return m_pStrResourceZip;
  682. }
  683. const CDuiString& CPaintManagerUI::GetResourceZipPwd()
  684. {
  685. return m_pStrResourceZipPwd;
  686. }
  687. bool CPaintManagerUI::IsCachedResourceZip()
  688. {
  689. return m_bCachedResourceZip;
  690. }
  691. HANDLE CPaintManagerUI::GetResourceZipHandle()
  692. {
  693. return m_hResourceZip;
  694. }
  695. void CPaintManagerUI::SetInstance(HINSTANCE hInst)
  696. {
  697. m_hInstance = hInst;
  698. }
  699. void CPaintManagerUI::SetCurrentPath(LPCTSTR pStrPath)
  700. {
  701. ::SetCurrentDirectory(pStrPath);
  702. }
  703. void CPaintManagerUI::SetResourceDll(HINSTANCE hInst)
  704. {
  705. m_hResourceInstance = hInst;
  706. }
  707. void CPaintManagerUI::SetResourcePath(LPCTSTR pStrPath)
  708. {
  709. m_pStrResourcePath = pStrPath;
  710. if (m_pStrResourcePath.IsEmpty()) return;
  711. TCHAR cEnd = m_pStrResourcePath.GetAt(m_pStrResourcePath.GetLength() - 1);
  712. if (cEnd != _T('\\') && cEnd != _T('/')) m_pStrResourcePath += _T('\\');
  713. }
  714. void CPaintManagerUI::SetResourceZip(LPVOID pVoid, unsigned int len, LPCTSTR password)
  715. {
  716. if (m_pStrResourceZip == _T("membuffer")) return;
  717. if (m_bCachedResourceZip && m_hResourceZip != NULL)
  718. {
  719. CloseZip((HZIP)m_hResourceZip);
  720. m_hResourceZip = NULL;
  721. }
  722. m_pStrResourceZip = _T("membuffer");
  723. if (m_cbZipBuf)
  724. {
  725. delete[] m_cbZipBuf;
  726. m_cbZipBuf = nullptr;
  727. }
  728. if (!m_cbZipBuf)
  729. {
  730. m_cbZipBuf = new BYTE[len];
  731. memcpy(m_cbZipBuf, pVoid, len);
  732. }
  733. m_bCachedResourceZip = true;
  734. m_pStrResourceZipPwd = password; //Garfield 20160325 带密码zip包解密
  735. if (m_bCachedResourceZip)
  736. {
  737. #ifdef UNICODE
  738. char* pwd = w2a((wchar_t*)password);
  739. m_hResourceZip = (HANDLE)OpenZip(m_cbZipBuf, len, pwd);
  740. if (pwd)
  741. {
  742. delete[] pwd;
  743. pwd = NULL;
  744. }
  745. #else
  746. m_hResourceZip = (HANDLE)OpenZip(m_cbZipBuf, len, password);
  747. #endif
  748. }
  749. }
  750. void CPaintManagerUI::SetResourceZip(LPCTSTR pStrPath, bool bCachedResourceZip, LPCTSTR password)
  751. {
  752. if (m_pStrResourceZip == pStrPath && m_bCachedResourceZip == bCachedResourceZip) return;
  753. if (m_bCachedResourceZip && m_hResourceZip != NULL)
  754. {
  755. CloseZip((HZIP)m_hResourceZip);
  756. m_hResourceZip = NULL;
  757. }
  758. m_pStrResourceZip = pStrPath;
  759. m_bCachedResourceZip = bCachedResourceZip;
  760. m_pStrResourceZipPwd = password;
  761. if (m_bCachedResourceZip)
  762. {
  763. CDuiString sFile = CPaintManagerUI::GetResourcePath();
  764. sFile += CPaintManagerUI::GetResourceZip();
  765. #ifdef UNICODE
  766. char* pwd = w2a((wchar_t*)password);
  767. m_hResourceZip = (HANDLE)OpenZip(sFile.GetData(), pwd);
  768. if (pwd)
  769. {
  770. delete[] pwd;
  771. pwd = NULL;
  772. }
  773. #else
  774. m_hResourceZip = (HANDLE)OpenZip(sFile.GetData(), password);
  775. #endif
  776. }
  777. }
  778. void CPaintManagerUI::SetResourceType(int nType)
  779. {
  780. m_nResType = nType;
  781. }
  782. int CPaintManagerUI::GetResourceType()
  783. {
  784. return m_nResType;
  785. }
  786. bool CPaintManagerUI::GetHSL(short* H, short* S, short* L)
  787. {
  788. *H = m_H;
  789. *S = m_S;
  790. *L = m_L;
  791. return m_bUseHSL;
  792. }
  793. void CPaintManagerUI::SetHSL(bool bUseHSL, short H, short S, short L)
  794. {
  795. if (m_bUseHSL || m_bUseHSL != bUseHSL)
  796. {
  797. m_bUseHSL = bUseHSL;
  798. if (H == m_H && S == m_S && L == m_L) return;
  799. m_H = CLAMP(H, 0, 360);
  800. m_S = CLAMP(S, 0, 200);
  801. m_L = CLAMP(L, 0, 200);
  802. AdjustSharedImagesHSL();
  803. for (int i = 0; i < m_aPreMessages.GetSize(); i++)
  804. {
  805. CPaintManagerUI* pManager = static_cast<CPaintManagerUI*>(m_aPreMessages[i]);
  806. if (pManager != NULL) pManager->AdjustImagesHSL();
  807. }
  808. }
  809. }
  810. void CPaintManagerUI::ReloadSkin()
  811. {
  812. ReloadSharedImages();
  813. for (int i = 0; i < m_aPreMessages.GetSize(); i++)
  814. {
  815. CPaintManagerUI* pManager = static_cast<CPaintManagerUI*>(m_aPreMessages[i]);
  816. pManager->ReloadImages();
  817. }
  818. }
  819. CPaintManagerUI* CPaintManagerUI::GetPaintManager(LPCTSTR pstrName)
  820. {
  821. if (pstrName == NULL) return NULL;
  822. CDuiString sName = pstrName;
  823. if (sName.IsEmpty()) return NULL;
  824. for (int i = 0; i < m_aPreMessages.GetSize(); i++)
  825. {
  826. CPaintManagerUI* pManager = static_cast<CPaintManagerUI*>(m_aPreMessages[i]);
  827. if (pManager != NULL && sName == pManager->GetName()) return pManager;
  828. }
  829. return NULL;
  830. }
  831. CStdPtrArray* CPaintManagerUI::GetPaintManagers()
  832. {
  833. return &m_aPreMessages;
  834. }
  835. bool CPaintManagerUI::LoadPlugin(LPCTSTR pstrModuleName)
  836. {
  837. ASSERT(!::IsBadStringPtr(pstrModuleName, -1) || pstrModuleName == NULL);
  838. if (pstrModuleName == NULL) return false;
  839. HMODULE hModule = ::LoadLibrary(pstrModuleName);
  840. if (hModule != NULL)
  841. {
  842. LPCREATECONTROL lpCreateControl = (LPCREATECONTROL)::GetProcAddress(hModule, "CreateControl");
  843. if (lpCreateControl != NULL)
  844. {
  845. if (m_aPlugins.Find(lpCreateControl) >= 0) return true;
  846. m_aPlugins.Add(lpCreateControl);
  847. return true;
  848. }
  849. }
  850. return false;
  851. }
  852. CStdPtrArray* CPaintManagerUI::GetPlugins()
  853. {
  854. return &m_aPlugins;
  855. }
  856. HWND CPaintManagerUI::GetPaintWindow() const
  857. {
  858. return m_hWndPaint;
  859. }
  860. HWND CPaintManagerUI::GetTooltipWindow() const
  861. {
  862. return m_hwndTooltip;
  863. }
  864. int CPaintManagerUI::GetHoverTime() const
  865. {
  866. return m_iHoverTime;
  867. }
  868. void CPaintManagerUI::SetHoverTime(int iTime)
  869. {
  870. m_iHoverTime = iTime;
  871. }
  872. LPCTSTR CPaintManagerUI::GetName() const
  873. {
  874. return m_sName;
  875. }
  876. HDC CPaintManagerUI::GetPaintDC() const
  877. {
  878. return m_hDcPaint;
  879. }
  880. POINT CPaintManagerUI::GetMousePos() const
  881. {
  882. return m_ptLastMousePos;
  883. }
  884. SIZE CPaintManagerUI::GetClientSize() const
  885. {
  886. RECT rcClient = { 0 };
  887. ::GetClientRect(m_hWndPaint, &rcClient);
  888. return CDuiSize(rcClient.right - rcClient.left, rcClient.bottom - rcClient.top);
  889. }
  890. SIZE CPaintManagerUI::GetInitSize()
  891. {
  892. return m_szInitWindowSize;
  893. }
  894. void CPaintManagerUI::SetInitSize(int cx, int cy)
  895. {
  896. m_szInitWindowSize.cx = cx;
  897. m_szInitWindowSize.cy = cy;
  898. if (m_pRoot == NULL && m_hWndPaint != NULL)
  899. {
  900. ::SetWindowPos(m_hWndPaint, NULL, 0, 0, cx, cy, SWP_NOZORDER | SWP_NOMOVE | SWP_NOACTIVATE);
  901. }
  902. }
  903. RECT CPaintManagerUI::GetSizeBox()
  904. {
  905. return GetDPIObj()->Scale(m_rcSizeBox);
  906. }
  907. void CPaintManagerUI::SetSizeBox(RECT& rcSizeBox)
  908. {
  909. m_rcSizeBox = rcSizeBox;
  910. }
  911. RECT CPaintManagerUI::GetCaptionRect()
  912. {
  913. return GetDPIObj()->Scale(m_rcCaption);
  914. }
  915. void CPaintManagerUI::SetCaptionRect(RECT& rcCaption)
  916. {
  917. m_rcCaption = rcCaption;
  918. }
  919. SIZE CPaintManagerUI::GetRoundCorner()
  920. {
  921. return GetDPIObj()->Scale(m_szRoundCorner);
  922. }
  923. void CPaintManagerUI::SetRoundCorner(int cx, int cy)
  924. {
  925. m_szRoundCorner.cx = cx;
  926. m_szRoundCorner.cy = cy;
  927. }
  928. SIZE CPaintManagerUI::GetMinInfo()
  929. {
  930. return GetDPIObj()->Scale(m_szMinWindow);
  931. }
  932. void CPaintManagerUI::SetMinInfo(int cx, int cy)
  933. {
  934. ASSERT(cx >= 0 && cy >= 0);
  935. m_szMinWindow.cx = cx;
  936. m_szMinWindow.cy = cy;
  937. }
  938. SIZE CPaintManagerUI::GetMaxInfo()
  939. {
  940. return GetDPIObj()->Scale(m_szMaxWindow);
  941. }
  942. void CPaintManagerUI::SetMaxInfo(int cx, int cy)
  943. {
  944. ASSERT(cx >= 0 && cy >= 0);
  945. m_szMaxWindow.cx = cx;
  946. m_szMaxWindow.cy = cy;
  947. }
  948. bool CPaintManagerUI::IsShowUpdateRect()
  949. {
  950. return m_bShowUpdateRect;
  951. }
  952. void CPaintManagerUI::SetShowUpdateRect(bool show)
  953. {
  954. m_bShowUpdateRect = show;
  955. }
  956. bool CPaintManagerUI::IsNoActivate()
  957. {
  958. return m_bNoActivate;
  959. }
  960. void CPaintManagerUI::SetNoActivate(bool bNoActivate)
  961. {
  962. m_bNoActivate = bNoActivate;
  963. }
  964. BYTE CPaintManagerUI::GetOpacity() const
  965. {
  966. return m_nOpacity;
  967. }
  968. void CPaintManagerUI::SetOpacity(BYTE nOpacity)
  969. {
  970. m_nOpacity = nOpacity;
  971. if (m_hWndPaint != NULL)
  972. {
  973. typedef BOOL(__stdcall* PFUNCSETLAYEREDWINDOWATTR)(HWND, COLORREF, BYTE, DWORD);
  974. PFUNCSETLAYEREDWINDOWATTR fSetLayeredWindowAttributes = NULL;
  975. HMODULE hUser32 = ::GetModuleHandle(_T("User32.dll"));
  976. if (hUser32)
  977. {
  978. fSetLayeredWindowAttributes =
  979. (PFUNCSETLAYEREDWINDOWATTR)::GetProcAddress(hUser32, "SetLayeredWindowAttributes");
  980. if (fSetLayeredWindowAttributes == NULL) return;
  981. }
  982. DWORD dwStyle = ::GetWindowLong(m_hWndPaint, GWL_EXSTYLE);
  983. DWORD dwNewStyle = dwStyle;
  984. if (nOpacity >= 0 && nOpacity < 256) dwNewStyle |= WS_EX_LAYERED;
  985. else dwNewStyle &= ~WS_EX_LAYERED;
  986. if (dwStyle != dwNewStyle) ::SetWindowLong(m_hWndPaint, GWL_EXSTYLE, dwNewStyle);
  987. fSetLayeredWindowAttributes(m_hWndPaint, 0, nOpacity, LWA_ALPHA);
  988. }
  989. }
  990. bool CPaintManagerUI::IsLayered()
  991. {
  992. return m_bLayered;
  993. }
  994. void CPaintManagerUI::SetLayered(bool bLayered)
  995. {
  996. if (m_hWndPaint != NULL && bLayered != m_bLayered)
  997. {
  998. UINT uStyle = GetWindowStyle(m_hWndPaint);
  999. if ((uStyle & WS_CHILD) != 0) return;
  1000. if (g_fUpdateLayeredWindow == NULL)
  1001. {
  1002. HMODULE hUser32 = ::GetModuleHandle(_T("User32.dll"));
  1003. if (hUser32)
  1004. {
  1005. g_fUpdateLayeredWindow =
  1006. (PFUNCUPDATELAYEREDWINDOW)::GetProcAddress(hUser32, "UpdateLayeredWindow");
  1007. if (g_fUpdateLayeredWindow == NULL) return;
  1008. }
  1009. }
  1010. m_bLayered = bLayered;
  1011. if (m_pRoot != NULL) m_pRoot->NeedUpdate();
  1012. Invalidate();
  1013. }
  1014. }
  1015. RECT& CPaintManagerUI::GetLayeredInset()
  1016. {
  1017. return m_rcLayeredInset;
  1018. }
  1019. void CPaintManagerUI::SetLayeredInset(RECT& rcLayeredInset)
  1020. {
  1021. m_rcLayeredInset = rcLayeredInset;
  1022. m_bLayeredChanged = true;
  1023. Invalidate();
  1024. }
  1025. BYTE CPaintManagerUI::GetLayeredOpacity()
  1026. {
  1027. return m_nOpacity;
  1028. }
  1029. void CPaintManagerUI::SetLayeredOpacity(BYTE nOpacity)
  1030. {
  1031. m_nOpacity = nOpacity;
  1032. m_bLayeredChanged = true;
  1033. Invalidate();
  1034. }
  1035. LPCTSTR CPaintManagerUI::GetLayeredImage()
  1036. {
  1037. return m_diLayered.sDrawString;
  1038. }
  1039. void CPaintManagerUI::SetLayeredImage(LPCTSTR pstrImage)
  1040. {
  1041. m_diLayered.sDrawString = pstrImage;
  1042. RECT rcNull = { 0 };
  1043. CRenderEngine::DrawImageInfo(NULL, this, rcNull, rcNull, &m_diLayered);
  1044. m_bLayeredChanged = true;
  1045. Invalidate();
  1046. }
  1047. CShadowUI* CPaintManagerUI::GetShadow()
  1048. {
  1049. return &m_shadow;
  1050. }
  1051. void CPaintManagerUI::SetUseGdiplusText(bool bUse)
  1052. {
  1053. m_bUseGdiplusText = bUse;
  1054. }
  1055. bool CPaintManagerUI::IsUseGdiplusText() const
  1056. {
  1057. return m_bUseGdiplusText;
  1058. }
  1059. void CPaintManagerUI::SetGdiplusTextRenderingHint(int trh)
  1060. {
  1061. m_trh = trh;
  1062. }
  1063. int CPaintManagerUI::GetGdiplusTextRenderingHint() const
  1064. {
  1065. return m_trh;
  1066. }
  1067. bool CPaintManagerUI::PreMessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT& lRes)
  1068. {
  1069. for (int i = 0; i < m_aPreMessageFilters.GetSize(); i++)
  1070. {
  1071. bool bHandled = false;
  1072. LRESULT lResult = static_cast<IMessageFilterUI*>(m_aPreMessageFilters[i])->MessageHandler(uMsg, wParam, lParam, bHandled);
  1073. if (bHandled)
  1074. {
  1075. lRes = lResult;
  1076. return true;
  1077. }
  1078. }
  1079. switch (uMsg)
  1080. {
  1081. case WM_KEYDOWN:
  1082. {
  1083. // Tabbing between controls
  1084. if (wParam == VK_TAB)
  1085. {
  1086. if (m_pFocus && m_pFocus->IsVisible() && m_pFocus->IsEnabled() && _tcsstr(m_pFocus->GetClass(), _T("RichEditUI")) != NULL)
  1087. {
  1088. if (static_cast<CRichEditUI*>(m_pFocus)->IsWantTab()) return false;
  1089. }
  1090. if (m_pFocus && m_pFocus->IsVisible() && m_pFocus->IsEnabled() && _tcsstr(m_pFocus->GetClass(), _T("WkeWebkitUI")) != NULL)
  1091. {
  1092. return false;
  1093. }
  1094. SetNextTabControl(::GetKeyState(VK_SHIFT) >= 0);
  1095. return false;
  1096. }
  1097. }
  1098. break;
  1099. case WM_SYSCHAR:
  1100. {
  1101. // Handle ALT-shortcut key-combinations
  1102. FINDSHORTCUT fs = { 0 };
  1103. fs.ch = toupper((int)wParam);
  1104. CControlUI* pControl = m_pRoot->FindControl(__FindControlFromShortcut, &fs, UIFIND_ENABLED | UIFIND_ME_FIRST | UIFIND_TOP_FIRST);
  1105. if (pControl != NULL)
  1106. {
  1107. pControl->SetFocus();
  1108. pControl->Activate();
  1109. return true;
  1110. }
  1111. }
  1112. break;
  1113. case WM_SYSKEYDOWN:
  1114. {
  1115. if (m_pFocus != NULL)
  1116. {
  1117. TEventUI event = { 0 };
  1118. event.Type = UIEVENT_SYSKEY;
  1119. event.chKey = (TCHAR)wParam;
  1120. event.ptMouse = m_ptLastMousePos;
  1121. event.wKeyState = MapKeyState();
  1122. event.dwTimestamp = ::GetTickCount();
  1123. m_pFocus->Event(event);
  1124. }
  1125. }
  1126. break;
  1127. }
  1128. return false;
  1129. }
  1130. bool CPaintManagerUI::MessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT& lRes)
  1131. {
  1132. if (m_hWndPaint == NULL) return false;
  1133. // [触屏兼容] 不再过滤 Windows 为触摸模拟的鼠标消息(MOUSEEVENTF_FROMTOUCH)。
  1134. // 触摸的“点击”正来自这些模拟的 WM_LBUTTONDOWN/UP,由原生鼠标路径交给 CButtonUI 等控件
  1135. // Activate() 触发——而 DuiLib 的点击状态机依赖 WM_LBUTTONDOWN 设置 m_pEventClick,故绝不能
  1136. // 在鼠标分支吞掉这些模拟消息(之前那样做会导致触摸与鼠标点击全失效)。
  1137. // 为避免“拖拽=滚动”又“误点按钮”,改用 m_bTouchMoved:若本次手势发生位移,在 WM_LBUTTONUP 抑制点击。
  1138. // Cycle through listeners
  1139. for (int i = 0; i < m_aMessageFilters.GetSize(); i++)
  1140. {
  1141. bool bHandled = false;
  1142. LRESULT lResult = static_cast<IMessageFilterUI*>(m_aMessageFilters[i])->MessageHandler(uMsg, wParam, lParam, bHandled);
  1143. if (bHandled)
  1144. {
  1145. lRes = lResult;
  1146. switch (uMsg)
  1147. {
  1148. case WM_MOUSEMOVE:
  1149. case WM_LBUTTONDOWN:
  1150. case WM_LBUTTONDBLCLK:
  1151. case WM_LBUTTONUP:
  1152. {
  1153. POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
  1154. m_ptLastMousePos = pt;
  1155. }
  1156. break;
  1157. case WM_CONTEXTMENU:
  1158. case WM_MOUSEWHEEL:
  1159. {
  1160. POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
  1161. ::ScreenToClient(m_hWndPaint, &pt);
  1162. m_ptLastMousePos = pt;
  1163. }
  1164. break;
  1165. }
  1166. return true;
  1167. }
  1168. }
  1169. if (m_bLayered)
  1170. {
  1171. switch (uMsg)
  1172. {
  1173. case WM_NCACTIVATE:
  1174. if (!::IsIconic(m_hWndPaint))
  1175. {
  1176. lRes = (wParam == 0) ? TRUE : FALSE;
  1177. return true;
  1178. }
  1179. break;
  1180. case WM_NCCALCSIZE:
  1181. case WM_NCPAINT:
  1182. lRes = 0;
  1183. return true;
  1184. }
  1185. }
  1186. // Custom handling of events
  1187. switch (uMsg)
  1188. {
  1189. case WM_APP + 1:
  1190. {
  1191. for (int i = 0; i < m_aDelayedCleanup.GetSize(); i++)
  1192. delete static_cast<CControlUI*>(m_aDelayedCleanup[i]);
  1193. m_aDelayedCleanup.Empty();
  1194. m_bAsyncNotifyPosted = false;
  1195. TNotifyUI* pMsg = NULL;
  1196. while (pMsg = static_cast<TNotifyUI*>(m_aAsyncNotify.GetAt(0)))
  1197. {
  1198. m_aAsyncNotify.Remove(0);
  1199. if (pMsg->pSender != NULL)
  1200. {
  1201. if (pMsg->pSender->OnNotify) pMsg->pSender->OnNotify(pMsg);
  1202. }
  1203. for (int j = 0; j < m_aNotifiers.GetSize(); j++)
  1204. {
  1205. static_cast<INotifyUI*>(m_aNotifiers[j])->Notify(*pMsg);
  1206. }
  1207. delete pMsg;
  1208. }
  1209. }
  1210. break;
  1211. case WM_CLOSE:
  1212. {
  1213. // Make sure all matching "closing" events are sent
  1214. TEventUI event = { 0 };
  1215. event.ptMouse = m_ptLastMousePos;
  1216. event.wKeyState = MapKeyState();
  1217. event.dwTimestamp = ::GetTickCount();
  1218. if (m_pEventHover != NULL)
  1219. {
  1220. event.Type = UIEVENT_MOUSELEAVE;
  1221. event.pSender = m_pEventHover;
  1222. m_pEventHover->Event(event);
  1223. }
  1224. if (m_pEventClick != NULL)
  1225. {
  1226. event.Type = UIEVENT_BUTTONUP;
  1227. event.pSender = m_pEventClick;
  1228. m_pEventClick->Event(event);
  1229. }
  1230. if (m_pEventRClick != NULL)
  1231. {
  1232. event.Type = UIEVENT_RBUTTONUP;
  1233. event.pSender = m_pEventClick;
  1234. m_pEventRClick->Event(event);
  1235. }
  1236. SetFocus(NULL);
  1237. if (::GetActiveWindow() == m_hWndPaint)
  1238. {
  1239. HWND hwndParent = GetWindowOwner(m_hWndPaint);
  1240. if (hwndParent != NULL) ::SetFocus(hwndParent);
  1241. }
  1242. if (m_hwndTooltip != NULL)
  1243. {
  1244. ::DestroyWindow(m_hwndTooltip);
  1245. m_hwndTooltip = NULL;
  1246. }
  1247. }
  1248. break;
  1249. case WM_ERASEBKGND:
  1250. {
  1251. // We'll do the painting here...
  1252. lRes = 1;
  1253. }
  1254. return true;
  1255. case WM_PAINT:
  1256. {
  1257. if (m_pRoot == NULL)
  1258. {
  1259. PAINTSTRUCT ps = { 0 };
  1260. ::BeginPaint(m_hWndPaint, &ps);
  1261. CRenderEngine::DrawColor(m_hDcPaint, ps.rcPaint, 0xFF000000);
  1262. ::EndPaint(m_hWndPaint, &ps);
  1263. return true;
  1264. }
  1265. RECT rcClient = { 0 };
  1266. ::GetClientRect(m_hWndPaint, &rcClient);
  1267. RECT rcPaint = { 0 };
  1268. if (!::GetUpdateRect(m_hWndPaint, &rcPaint, FALSE)) return true;
  1269. //if( m_bLayered ) {
  1270. // m_bOffscreenPaint = true;
  1271. // rcPaint = m_rcLayeredUpdate;
  1272. // if( ::IsRectEmpty(&m_rcLayeredUpdate) ) {
  1273. // PAINTSTRUCT ps = { 0 };
  1274. // ::BeginPaint(m_hWndPaint, &ps);
  1275. // ::EndPaint(m_hWndPaint, &ps);
  1276. // return true;
  1277. // }
  1278. // if( rcPaint.right > rcClient.right ) rcPaint.right = rcClient.right;
  1279. // if( rcPaint.bottom > rcClient.bottom ) rcPaint.bottom = rcClient.bottom;
  1280. // ::ZeroMemory(&m_rcLayeredUpdate, sizeof(m_rcLayeredUpdate));
  1281. //}
  1282. //else {
  1283. // if( !::GetUpdateRect(m_hWndPaint, &rcPaint, FALSE) ) return true;
  1284. //}
  1285. // Set focus to first control?
  1286. if (m_bFocusNeeded)
  1287. {
  1288. //修复新窗口自动切换焦点的问题
  1289. //SetNextTabControl();
  1290. m_bFocusNeeded = false;
  1291. }
  1292. SetPainting(true);
  1293. bool bNeedSizeMsg = false;
  1294. DWORD dwWidth = rcClient.right - rcClient.left;
  1295. DWORD dwHeight = rcClient.bottom - rcClient.top;
  1296. SetPainting(true);
  1297. if (m_bUpdateNeeded)
  1298. {
  1299. m_bUpdateNeeded = false;
  1300. if (!::IsRectEmpty(&rcClient) && !::IsIconic(m_hWndPaint))
  1301. {
  1302. if (m_pRoot->IsUpdateNeeded())
  1303. {
  1304. RECT rcRoot = rcClient;
  1305. if (m_hDcOffscreen != NULL) ::DeleteDC(m_hDcOffscreen);
  1306. if (m_hDcBackground != NULL) ::DeleteDC(m_hDcBackground);
  1307. if (m_hbmpOffscreen != NULL) ::DeleteObject(m_hbmpOffscreen);
  1308. if (m_hbmpBackground != NULL) ::DeleteObject(m_hbmpBackground);
  1309. m_hDcOffscreen = NULL;
  1310. m_hDcBackground = NULL;
  1311. m_hbmpOffscreen = NULL;
  1312. m_hbmpBackground = NULL;
  1313. if (m_bLayered)
  1314. {
  1315. rcRoot.left += m_rcLayeredInset.left;
  1316. rcRoot.top += m_rcLayeredInset.top;
  1317. rcRoot.right -= m_rcLayeredInset.right;
  1318. rcRoot.bottom -= m_rcLayeredInset.bottom;
  1319. }
  1320. m_pRoot->SetPos(rcRoot, true);
  1321. bNeedSizeMsg = true;
  1322. }
  1323. else
  1324. {
  1325. CControlUI* pControl = NULL;
  1326. m_aFoundControls.Empty();
  1327. m_pRoot->FindControl(__FindControlsFromUpdate, NULL, UIFIND_VISIBLE | UIFIND_ME_FIRST | UIFIND_UPDATETEST);
  1328. for (int it = 0; it < m_aFoundControls.GetSize(); it++)
  1329. {
  1330. pControl = static_cast<CControlUI*>(m_aFoundControls[it]);
  1331. pControl->SetPos(pControl->GetPos(), true);
  1332. }
  1333. bNeedSizeMsg = true;
  1334. }
  1335. // We'll want to notify the window when it is first initialized
  1336. // with the correct layout. The window form would take the time
  1337. // to submit swipes/animations.
  1338. if (m_bFirstLayout)
  1339. {
  1340. m_bFirstLayout = false;
  1341. SendNotify(m_pRoot, DUI_MSGTYPE_WINDOWINIT, 0, 0, false);
  1342. if (m_bLayered && m_bLayeredChanged)
  1343. {
  1344. Invalidate();
  1345. SetPainting(false);
  1346. return true;
  1347. }
  1348. // 更新阴影窗口显示
  1349. m_shadow.Update(m_hWndPaint);
  1350. }
  1351. }
  1352. }
  1353. else if (m_bLayered && m_bLayeredChanged)
  1354. {
  1355. RECT rcRoot = rcClient;
  1356. if (m_pOffscreenBits) ::ZeroMemory(m_pOffscreenBits, (rcRoot.right - rcRoot.left)
  1357. * (rcRoot.bottom - rcRoot.top) * 4);
  1358. rcRoot.left += m_rcLayeredInset.left;
  1359. rcRoot.top += m_rcLayeredInset.top;
  1360. rcRoot.right -= m_rcLayeredInset.right;
  1361. rcRoot.bottom -= m_rcLayeredInset.bottom;
  1362. m_pRoot->SetPos(rcRoot, true);
  1363. }
  1364. if (m_bLayered)
  1365. {
  1366. DWORD dwExStyle = ::GetWindowLong(m_hWndPaint, GWL_EXSTYLE);
  1367. DWORD dwNewExStyle = dwExStyle | WS_EX_LAYERED;
  1368. if (dwExStyle != dwNewExStyle) ::SetWindowLong(m_hWndPaint, GWL_EXSTYLE, dwNewExStyle);
  1369. m_bOffscreenPaint = true;
  1370. UnionRect(&rcPaint, &rcPaint, &m_rcLayeredUpdate);
  1371. if (rcPaint.right > rcClient.right) rcPaint.right = rcClient.right;
  1372. if (rcPaint.bottom > rcClient.bottom) rcPaint.bottom = rcClient.bottom;
  1373. ::ZeroMemory(&m_rcLayeredUpdate, sizeof(m_rcLayeredUpdate));
  1374. }
  1375. //
  1376. // Render screen
  1377. //
  1378. // Prepare offscreen bitmap
  1379. if (m_bOffscreenPaint && m_hbmpOffscreen == NULL)
  1380. {
  1381. m_hDcOffscreen = ::CreateCompatibleDC(m_hDcPaint);
  1382. m_hbmpOffscreen = CRenderEngine::CreateARGB32Bitmap(m_hDcPaint, dwWidth, dwHeight, (LPBYTE*)&m_pOffscreenBits);
  1383. ASSERT(m_hDcOffscreen);
  1384. ASSERT(m_hbmpOffscreen);
  1385. }
  1386. // Begin Windows paint
  1387. PAINTSTRUCT ps = { 0 };
  1388. ::BeginPaint(m_hWndPaint, &ps);
  1389. if (m_bOffscreenPaint)
  1390. {
  1391. HBITMAP hOldBitmap = (HBITMAP) ::SelectObject(m_hDcOffscreen, m_hbmpOffscreen);
  1392. int iSaveDC = ::SaveDC(m_hDcOffscreen);
  1393. if (m_bLayered)
  1394. {
  1395. for (LONG y = rcClient.bottom - rcPaint.bottom; y < rcClient.bottom - rcPaint.top; ++y)
  1396. {
  1397. for (LONG x = rcPaint.left; x < rcPaint.right; ++x)
  1398. {
  1399. int i = (y * dwWidth + x) * 4;
  1400. *(DWORD*)(&m_pOffscreenBits[i]) = 0;
  1401. }
  1402. }
  1403. }
  1404. m_pRoot->Paint(m_hDcOffscreen, rcPaint, NULL);
  1405. if (m_bLayered)
  1406. {
  1407. for (int i = 0; i < m_aNativeWindow.GetSize(); )
  1408. {
  1409. HWND hChildWnd = static_cast<HWND>(m_aNativeWindow[i]);
  1410. if (!::IsWindow(hChildWnd))
  1411. {
  1412. m_aNativeWindow.Remove(i);
  1413. m_aNativeWindowControl.Remove(i);
  1414. continue;
  1415. }
  1416. ++i;
  1417. if (!::IsWindowVisible(hChildWnd)) continue;
  1418. RECT rcChildWnd = GetNativeWindowRect(hChildWnd);
  1419. RECT rcTemp = { 0 };
  1420. if (!::IntersectRect(&rcTemp, &rcPaint, &rcChildWnd)) continue;
  1421. COLORREF* pChildBitmapBits = NULL;
  1422. HDC hChildMemDC = ::CreateCompatibleDC(m_hDcOffscreen);
  1423. HBITMAP hChildBitmap = CRenderEngine::CreateARGB32Bitmap(hChildMemDC, rcChildWnd.right - rcChildWnd.left, rcChildWnd.bottom - rcChildWnd.top, (BYTE**)&pChildBitmapBits);
  1424. ::ZeroMemory(pChildBitmapBits, (rcChildWnd.right - rcChildWnd.left) * (rcChildWnd.bottom - rcChildWnd.top) * 4);
  1425. HBITMAP hOldChildBitmap = (HBITMAP) ::SelectObject(hChildMemDC, hChildBitmap);
  1426. ::SendMessage(hChildWnd, WM_PRINT, (WPARAM)hChildMemDC, (LPARAM)(PRF_CHECKVISIBLE | PRF_CHILDREN | PRF_CLIENT | PRF_OWNED));
  1427. COLORREF* pChildBitmapBit;
  1428. for (LONG y = 0; y < rcChildWnd.bottom - rcChildWnd.top; y++)
  1429. {
  1430. for (LONG x = 0; x < rcChildWnd.right - rcChildWnd.left; x++)
  1431. {
  1432. pChildBitmapBit = pChildBitmapBits + y * (rcChildWnd.right - rcChildWnd.left) + x;
  1433. if (*pChildBitmapBit != 0x00000000) *pChildBitmapBit |= 0xff000000;
  1434. }
  1435. }
  1436. ::BitBlt(m_hDcOffscreen, rcChildWnd.left, rcChildWnd.top, rcChildWnd.right - rcChildWnd.left,
  1437. rcChildWnd.bottom - rcChildWnd.top, hChildMemDC, 0, 0, SRCCOPY);
  1438. ::SelectObject(hChildMemDC, hOldChildBitmap);
  1439. ::DeleteObject(hChildBitmap);
  1440. ::DeleteDC(hChildMemDC);
  1441. }
  1442. }
  1443. for (int i = 0; i < m_aPostPaintControls.GetSize(); i++)
  1444. {
  1445. CControlUI* pPostPaintControl = static_cast<CControlUI*>(m_aPostPaintControls[i]);
  1446. pPostPaintControl->DoPostPaint(m_hDcOffscreen, rcPaint);
  1447. }
  1448. ::RestoreDC(m_hDcOffscreen, iSaveDC);
  1449. if (m_bLayered)
  1450. {
  1451. RECT rcWnd = { 0 };
  1452. ::GetWindowRect(m_hWndPaint, &rcWnd);
  1453. if (!m_diLayered.sDrawString.IsEmpty())
  1454. {
  1455. DWORD dwWidth = rcClient.right - rcClient.left;
  1456. DWORD dwHeight = rcClient.bottom - rcClient.top;
  1457. RECT rcLayeredClient = rcClient;
  1458. rcLayeredClient.left += m_rcLayeredInset.left;
  1459. rcLayeredClient.top += m_rcLayeredInset.top;
  1460. rcLayeredClient.right -= m_rcLayeredInset.right;
  1461. rcLayeredClient.bottom -= m_rcLayeredInset.bottom;
  1462. COLORREF* pOffscreenBits = (COLORREF*)m_pOffscreenBits;
  1463. COLORREF* pBackgroundBits = m_pBackgroundBits;
  1464. BYTE A = 0;
  1465. BYTE R = 0;
  1466. BYTE G = 0;
  1467. BYTE B = 0;
  1468. if (!m_diLayered.sDrawString.IsEmpty())
  1469. {
  1470. if (m_hbmpBackground == NULL)
  1471. {
  1472. m_hDcBackground = ::CreateCompatibleDC(m_hDcPaint);
  1473. m_hbmpBackground = CRenderEngine::CreateARGB32Bitmap(m_hDcPaint, dwWidth, dwHeight, (BYTE**)&m_pBackgroundBits);
  1474. ::ZeroMemory(m_pBackgroundBits, dwWidth * dwHeight * 4);
  1475. ::SelectObject(m_hDcBackground, m_hbmpBackground);
  1476. CRenderClip clip;
  1477. CRenderClip::GenerateClip(m_hDcBackground, rcLayeredClient, clip);
  1478. CRenderEngine::DrawImageInfo(m_hDcBackground, this, rcLayeredClient, rcLayeredClient, &m_diLayered);
  1479. }
  1480. else if (m_bLayeredChanged)
  1481. {
  1482. ::ZeroMemory(m_pBackgroundBits, dwWidth * dwHeight * 4);
  1483. CRenderClip clip;
  1484. CRenderClip::GenerateClip(m_hDcBackground, rcLayeredClient, clip);
  1485. CRenderEngine::DrawImageInfo(m_hDcBackground, this, rcLayeredClient, rcLayeredClient, &m_diLayered);
  1486. }
  1487. for (LONG y = rcClient.bottom - rcPaint.bottom; y < rcClient.bottom - rcPaint.top; ++y)
  1488. {
  1489. for (LONG x = rcPaint.left; x < rcPaint.right; ++x)
  1490. {
  1491. pOffscreenBits = (COLORREF*)(m_pOffscreenBits + y * dwWidth + x);
  1492. pBackgroundBits = m_pBackgroundBits + y * dwWidth + x;
  1493. A = (BYTE)((*pBackgroundBits) >> 24);
  1494. R = (BYTE)((*pOffscreenBits) >> 16) * A / 255;
  1495. G = (BYTE)((*pOffscreenBits) >> 8) * A / 255;
  1496. B = (BYTE)(*pOffscreenBits) * A / 255;
  1497. *pOffscreenBits = RGB(B, G, R) + ((DWORD)A << 24);
  1498. }
  1499. }
  1500. }
  1501. }
  1502. else
  1503. {
  1504. for (LONG y = rcClient.bottom - rcPaint.bottom; y < rcClient.bottom - rcPaint.top; ++y)
  1505. {
  1506. for (LONG x = rcPaint.left; x < rcPaint.right; ++x)
  1507. {
  1508. int i = (y * dwWidth + x) * 4;
  1509. if ((m_pOffscreenBits[i + 3] == 0) && (m_pOffscreenBits[i + 0] != 0 || m_pOffscreenBits[i + 1] != 0 || m_pOffscreenBits[i + 2] != 0))
  1510. m_pOffscreenBits[i + 3] = 255;
  1511. }
  1512. }
  1513. }
  1514. BLENDFUNCTION bf = { AC_SRC_OVER, 0, m_nOpacity, AC_SRC_ALPHA };
  1515. POINT ptPos = { rcWnd.left, rcWnd.top };
  1516. SIZE sizeWnd = { dwWidth, dwHeight };
  1517. POINT ptSrc = { 0, 0 };
  1518. g_fUpdateLayeredWindow(m_hWndPaint, m_hDcPaint, &ptPos, &sizeWnd, m_hDcOffscreen, &ptSrc, 0, &bf, ULW_ALPHA);
  1519. }
  1520. else
  1521. {
  1522. ::BitBlt(m_hDcPaint, rcPaint.left, rcPaint.top, rcPaint.right - rcPaint.left, rcPaint.bottom - rcPaint.top, m_hDcOffscreen, rcPaint.left, rcPaint.top, SRCCOPY);
  1523. }
  1524. ::SelectObject(m_hDcOffscreen, hOldBitmap);
  1525. if (m_bShowUpdateRect && !m_bLayered)
  1526. {
  1527. HPEN hOldPen = (HPEN)::SelectObject(m_hDcPaint, m_hUpdateRectPen);
  1528. ::SelectObject(m_hDcPaint, ::GetStockObject(HOLLOW_BRUSH));
  1529. ::Rectangle(m_hDcPaint, rcPaint.left, rcPaint.top, rcPaint.right, rcPaint.bottom);
  1530. ::SelectObject(m_hDcPaint, hOldPen);
  1531. }
  1532. }
  1533. else
  1534. {
  1535. // A standard paint job
  1536. int iSaveDC = ::SaveDC(m_hDcPaint);
  1537. m_pRoot->Paint(m_hDcPaint, rcPaint, NULL);
  1538. for (int i = 0; i < m_aPostPaintControls.GetSize(); i++)
  1539. {
  1540. CControlUI* pPostPaintControl = static_cast<CControlUI*>(m_aPostPaintControls[i]);
  1541. pPostPaintControl->DoPostPaint(m_hDcPaint, rcPaint);
  1542. }
  1543. ::RestoreDC(m_hDcPaint, iSaveDC);
  1544. }
  1545. // All Done!
  1546. ::EndPaint(m_hWndPaint, &ps);
  1547. // 绘制结束
  1548. SetPainting(false);
  1549. m_bLayeredChanged = false;
  1550. if (m_bUpdateNeeded) Invalidate();
  1551. // 发送窗口大小改变消息
  1552. if (bNeedSizeMsg)
  1553. {
  1554. this->SendNotify(m_pRoot, DUI_MSGTYPE_WINDOWSIZE, 0, 0, true);
  1555. }
  1556. return true;
  1557. }
  1558. case WM_PRINTCLIENT:
  1559. {
  1560. if (m_pRoot == NULL) break;
  1561. RECT rcClient;
  1562. ::GetClientRect(m_hWndPaint, &rcClient);
  1563. HDC hDC = (HDC)wParam;
  1564. int save = ::SaveDC(hDC);
  1565. m_pRoot->Paint(hDC, rcClient, NULL);
  1566. if ((lParam & PRF_CHILDREN) != 0)
  1567. {
  1568. HWND hWndChild = ::GetWindow(m_hWndPaint, GW_CHILD);
  1569. while (hWndChild != NULL)
  1570. {
  1571. RECT rcPos = { 0 };
  1572. ::GetWindowRect(hWndChild, &rcPos);
  1573. ::MapWindowPoints(HWND_DESKTOP, m_hWndPaint, reinterpret_cast<LPPOINT>(&rcPos), 2);
  1574. ::SetWindowOrgEx(hDC, -rcPos.left, -rcPos.top, NULL);
  1575. ::SendMessage(hWndChild, WM_PRINT, wParam, lParam | PRF_NONCLIENT);
  1576. hWndChild = ::GetWindow(hWndChild, GW_HWNDNEXT);
  1577. }
  1578. }
  1579. ::RestoreDC(hDC, save);
  1580. }
  1581. break;
  1582. case WM_GETMINMAXINFO:
  1583. {
  1584. MONITORINFO Monitor = {};
  1585. Monitor.cbSize = sizeof(Monitor);
  1586. ::GetMonitorInfo(::MonitorFromWindow(m_hWndPaint, MONITOR_DEFAULTTOPRIMARY), &Monitor);
  1587. RECT rcWork = Monitor.rcWork;
  1588. if (Monitor.dwFlags != MONITORINFOF_PRIMARY)
  1589. {
  1590. ::OffsetRect(&rcWork, -rcWork.left, -rcWork.top);
  1591. }
  1592. LPMINMAXINFO lpMMI = (LPMINMAXINFO)lParam;
  1593. if (m_szMinWindow.cx > 0) lpMMI->ptMinTrackSize.x = m_szMinWindow.cx;
  1594. if (m_szMinWindow.cy > 0) lpMMI->ptMinTrackSize.y = m_szMinWindow.cy;
  1595. if (m_szMaxWindow.cx > 0) lpMMI->ptMaxTrackSize.x = m_szMaxWindow.cx;
  1596. if (m_szMaxWindow.cy > 0) lpMMI->ptMaxTrackSize.y = m_szMaxWindow.cy;
  1597. if (m_szMaxWindow.cx > 0) lpMMI->ptMaxSize.x = m_szMaxWindow.cx;
  1598. if (m_szMaxWindow.cy > 0) lpMMI->ptMaxSize.y = m_szMaxWindow.cy;
  1599. }
  1600. break;
  1601. case WM_SIZE:
  1602. {
  1603. if (m_pFocus != NULL)
  1604. {
  1605. TEventUI event = { 0 };
  1606. event.Type = UIEVENT_WINDOWSIZE;
  1607. event.pSender = m_pFocus;
  1608. event.dwTimestamp = ::GetTickCount();
  1609. m_pFocus->Event(event);
  1610. }
  1611. if (m_pRoot != NULL) m_pRoot->NeedUpdate();
  1612. }
  1613. return true;
  1614. case WM_TIMER:
  1615. {
  1616. for (int i = 0; i < m_aTimers.GetSize(); i++)
  1617. {
  1618. const TIMERINFO* pTimer = static_cast<TIMERINFO*>(m_aTimers[i]);
  1619. if (pTimer->hWnd == m_hWndPaint &&
  1620. pTimer->uWinTimer == LOWORD(wParam) &&
  1621. pTimer->bKilled == false)
  1622. {
  1623. TEventUI event = { 0 };
  1624. event.Type = UIEVENT_TIMER;
  1625. event.pSender = pTimer->pSender;
  1626. event.dwTimestamp = ::GetTickCount();
  1627. event.ptMouse = m_ptLastMousePos;
  1628. event.wKeyState = MapKeyState();
  1629. event.wParam = pTimer->nLocalID;
  1630. event.lParam = lParam;
  1631. pTimer->pSender->Event(event);
  1632. break;
  1633. }
  1634. }
  1635. }
  1636. break;
  1637. case WM_MOUSEHOVER:
  1638. {
  1639. m_bMouseTracking = false;
  1640. POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
  1641. CControlUI* pHover = FindControl(pt);
  1642. if (pHover == NULL) break;
  1643. // Generate mouse hover event
  1644. if (m_pEventHover != NULL)
  1645. {
  1646. TEventUI event = { 0 };
  1647. event.Type = UIEVENT_MOUSEHOVER;
  1648. event.pSender = m_pEventHover;
  1649. event.wParam = wParam;
  1650. event.lParam = lParam;
  1651. event.dwTimestamp = ::GetTickCount();
  1652. event.ptMouse = pt;
  1653. event.wKeyState = MapKeyState();
  1654. m_pEventHover->Event(event);
  1655. }
  1656. // Create tooltip information
  1657. CDuiString sToolTip = pHover->GetToolTip();
  1658. if (sToolTip.IsEmpty()) return true;
  1659. ::ZeroMemory(&m_ToolTip, sizeof(TOOLINFO));
  1660. m_ToolTip.cbSize = sizeof(TOOLINFO);
  1661. m_ToolTip.uFlags = TTF_IDISHWND;
  1662. m_ToolTip.hwnd = m_hWndPaint;
  1663. m_ToolTip.uId = (UINT_PTR)m_hWndPaint;
  1664. m_ToolTip.hinst = m_hInstance;
  1665. m_ToolTip.lpszText = const_cast<LPTSTR>((LPCTSTR)sToolTip);
  1666. m_ToolTip.rect = pHover->GetPos();
  1667. if (m_hwndTooltip == NULL)
  1668. {
  1669. m_hwndTooltip = ::CreateWindowEx(0, TOOLTIPS_CLASS, NULL, WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, m_hWndPaint, NULL, m_hInstance, NULL);
  1670. ::SendMessage(m_hwndTooltip, TTM_ADDTOOL, 0, (LPARAM)&m_ToolTip);
  1671. ::SendMessage(m_hwndTooltip, TTM_SETMAXTIPWIDTH, 0, pHover->GetToolTipWidth());
  1672. }
  1673. if (!::IsWindowVisible(m_hwndTooltip))
  1674. {
  1675. ::SendMessage(m_hwndTooltip, TTM_SETTOOLINFO, 0, (LPARAM)&m_ToolTip);
  1676. ::SendMessage(m_hwndTooltip, TTM_TRACKACTIVATE, TRUE, (LPARAM)&m_ToolTip);
  1677. }
  1678. }
  1679. return true;
  1680. case WM_MOUSELEAVE:
  1681. {
  1682. if (m_hwndTooltip != NULL) ::SendMessage(m_hwndTooltip, TTM_TRACKACTIVATE, FALSE, (LPARAM)&m_ToolTip);
  1683. if (m_bMouseTracking)
  1684. {
  1685. POINT pt = { 0 };
  1686. RECT rcWnd = { 0 };
  1687. ::GetCursorPos(&pt);
  1688. ::GetWindowRect(m_hWndPaint, &rcWnd);
  1689. if (!::IsIconic(m_hWndPaint) && ::GetActiveWindow() == m_hWndPaint && ::PtInRect(&rcWnd, pt))
  1690. {
  1691. if (::SendMessage(m_hWndPaint, WM_NCHITTEST, 0, MAKELPARAM(pt.x, pt.y)) == HTCLIENT)
  1692. {
  1693. ::ScreenToClient(m_hWndPaint, &pt);
  1694. ::SendMessage(m_hWndPaint, WM_MOUSEMOVE, 0, MAKELPARAM(pt.x, pt.y));
  1695. }
  1696. else
  1697. ::SendMessage(m_hWndPaint, WM_MOUSEMOVE, 0, (LPARAM)-1);
  1698. }
  1699. else
  1700. ::SendMessage(m_hWndPaint, WM_MOUSEMOVE, 0, (LPARAM)-1);
  1701. }
  1702. m_bMouseTracking = false;
  1703. }
  1704. break;
  1705. case WM_MOUSEMOVE:
  1706. {
  1707. // Start tracking this entire window again...
  1708. if (!m_bMouseTracking)
  1709. {
  1710. TRACKMOUSEEVENT tme = { 0 };
  1711. tme.cbSize = sizeof(TRACKMOUSEEVENT);
  1712. tme.dwFlags = TME_HOVER | TME_LEAVE;
  1713. tme.hwndTrack = m_hWndPaint;
  1714. tme.dwHoverTime = m_hwndTooltip == NULL ? m_iHoverTime : (DWORD) ::SendMessage(m_hwndTooltip, TTM_GETDELAYTIME, TTDT_INITIAL, 0L);
  1715. _TrackMouseEvent(&tme);
  1716. m_bMouseTracking = true;
  1717. }
  1718. // Generate the appropriate mouse messages
  1719. POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
  1720. // 是否移动
  1721. bool bNeedDrag = true;
  1722. if (m_ptLastMousePos.x == pt.x && m_ptLastMousePos.y == pt.y)
  1723. {
  1724. bNeedDrag = false;
  1725. }
  1726. // 记录鼠标位置
  1727. m_ptLastMousePos = pt;
  1728. CControlUI* pNewHover = FindControl(pt);
  1729. if (pNewHover != NULL && pNewHover->GetManager() != this) break;
  1730. // 拖拽事件
  1731. if (bNeedDrag && m_bDragMode && wParam == MK_LBUTTON)
  1732. {
  1733. // 释放Capture
  1734. ::ReleaseCapture();
  1735. // 接口
  1736. if (m_pDragDrop != NULL && m_pDragDrop->OnDragDrop(m_pEventClick))
  1737. {
  1738. m_bDragMode = false;
  1739. break;
  1740. }
  1741. CIDropSource* pdsrc = new CIDropSource;
  1742. if (pdsrc == NULL) return 0;
  1743. pdsrc->AddRef();
  1744. CIDataObject* pdobj = new CIDataObject(pdsrc);
  1745. if (pdobj == NULL) return 0;
  1746. pdobj->AddRef();
  1747. FORMATETC fmtetc = { 0 };
  1748. STGMEDIUM medium = { 0 };
  1749. fmtetc.dwAspect = DVASPECT_CONTENT;
  1750. fmtetc.lindex = -1;
  1751. fmtetc.cfFormat = CF_BITMAP;
  1752. fmtetc.tymed = TYMED_GDI;
  1753. //////////////////////////////////////
  1754. HBITMAP hBitmap = (HBITMAP)OleDuplicateData(m_hDragBitmap, fmtetc.cfFormat, NULL);
  1755. medium.hBitmap = hBitmap;
  1756. pdobj->SetData(&fmtetc, &medium, FALSE);
  1757. //////////////////////////////////////
  1758. BITMAP bmap;
  1759. GetObject(hBitmap, sizeof(BITMAP), &bmap);
  1760. RECT rc = { 0, 0, bmap.bmWidth, bmap.bmHeight };
  1761. fmtetc.cfFormat = CF_ENHMETAFILE;
  1762. fmtetc.tymed = TYMED_ENHMF;
  1763. HDC hMetaDC = CreateEnhMetaFile(m_hDcPaint, NULL, NULL, NULL);
  1764. HDC hdcMem = CreateCompatibleDC(m_hDcPaint);
  1765. HGDIOBJ hOldBmp = ::SelectObject(hdcMem, hBitmap);
  1766. ::BitBlt(hMetaDC, 0, 0, rc.right, rc.bottom, hdcMem, 0, 0, SRCCOPY);
  1767. ::SelectObject(hdcMem, hOldBmp);
  1768. medium.hEnhMetaFile = CloseEnhMetaFile(hMetaDC);
  1769. DeleteDC(hdcMem);
  1770. medium.tymed = TYMED_ENHMF;
  1771. pdobj->SetData(&fmtetc, &medium, TRUE);
  1772. //////////////////////////////////////
  1773. CDragSourceHelper dragSrcHelper;
  1774. POINT ptDrag = { 0 };
  1775. ptDrag.x = bmap.bmWidth / 2;
  1776. ptDrag.y = bmap.bmHeight / 2;
  1777. dragSrcHelper.InitializeFromBitmap(hBitmap, ptDrag, rc, pdobj); //will own the bmp
  1778. DWORD dwEffect;
  1779. HRESULT hr = ::DoDragDrop(pdobj, pdsrc, DROPEFFECT_COPY | DROPEFFECT_MOVE, &dwEffect);
  1780. if (dwEffect) pdsrc->Release();
  1781. else delete pdsrc;
  1782. pdobj->Release();
  1783. m_bDragMode = false;
  1784. break;
  1785. }
  1786. TEventUI event = { 0 };
  1787. event.ptMouse = pt;
  1788. event.wParam = wParam;
  1789. event.lParam = lParam;
  1790. event.dwTimestamp = ::GetTickCount();
  1791. event.wKeyState = MapKeyState();
  1792. if (!IsCaptured())
  1793. {
  1794. pNewHover = FindControl(pt);
  1795. if (pNewHover != NULL && pNewHover->GetManager() != this) break;
  1796. if (pNewHover != m_pEventHover && m_pEventHover != NULL)
  1797. {
  1798. event.Type = UIEVENT_MOUSELEAVE;
  1799. event.pSender = m_pEventHover;
  1800. CStdPtrArray aNeedMouseLeaveNeeded(m_aNeedMouseLeaveNeeded.GetSize());
  1801. aNeedMouseLeaveNeeded.Resize(m_aNeedMouseLeaveNeeded.GetSize());
  1802. ::CopyMemory(aNeedMouseLeaveNeeded.GetData(), m_aNeedMouseLeaveNeeded.GetData(), m_aNeedMouseLeaveNeeded.GetSize() * sizeof(LPVOID));
  1803. for (int i = 0; i < aNeedMouseLeaveNeeded.GetSize(); i++)
  1804. {
  1805. static_cast<CControlUI*>(aNeedMouseLeaveNeeded[i])->Event(event);
  1806. }
  1807. m_pEventHover->Event(event);
  1808. m_pEventHover = NULL;
  1809. if (m_hwndTooltip != NULL) ::SendMessage(m_hwndTooltip, TTM_TRACKACTIVATE, FALSE, (LPARAM)&m_ToolTip);
  1810. }
  1811. if (pNewHover != m_pEventHover && pNewHover != NULL)
  1812. {
  1813. event.Type = UIEVENT_MOUSEENTER;
  1814. event.pSender = pNewHover;
  1815. pNewHover->Event(event);
  1816. m_pEventHover = pNewHover;
  1817. }
  1818. }
  1819. if (m_pEventClick != NULL)
  1820. {
  1821. event.Type = UIEVENT_MOUSEMOVE;
  1822. event.pSender = m_pEventClick;
  1823. m_pEventClick->Event(event);
  1824. }
  1825. else if (pNewHover != NULL)
  1826. {
  1827. event.Type = UIEVENT_MOUSEMOVE;
  1828. event.pSender = pNewHover;
  1829. pNewHover->Event(event);
  1830. }
  1831. }
  1832. break;
  1833. case WM_LBUTTONDOWN:
  1834. {
  1835. // We alway set focus back to our app (this helps
  1836. // when Win32 child windows are placed on the dialog
  1837. // and we need to remove them on focus change).
  1838. if (!m_bNoActivate) ::SetFocus(m_hWndPaint);
  1839. if (m_pRoot == NULL) break;
  1840. // 查找控件
  1841. POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
  1842. m_ptLastMousePos = pt;
  1843. CControlUI* pControl = FindControl(pt);
  1844. if (pControl == NULL) break;
  1845. if (pControl->GetManager() != this) break;
  1846. // 准备拖拽
  1847. if (m_bDragDrop && pControl->IsDragEnabled())
  1848. {
  1849. m_bDragMode = true;
  1850. if (m_hDragBitmap != NULL)
  1851. {
  1852. ::DeleteObject(m_hDragBitmap);
  1853. m_hDragBitmap = NULL;
  1854. }
  1855. m_hDragBitmap = CRenderEngine::GenerateBitmap(this, pControl, pControl->GetPos());
  1856. }
  1857. // 开启捕获
  1858. SetCapture();
  1859. // 事件处理
  1860. m_pEventClick = pControl;
  1861. pControl->SetFocus();
  1862. TEventUI event = { 0 };
  1863. event.Type = UIEVENT_BUTTONDOWN;
  1864. event.pSender = pControl;
  1865. event.wParam = wParam;
  1866. event.lParam = lParam;
  1867. event.ptMouse = pt;
  1868. event.wKeyState = (WORD)wParam;
  1869. event.dwTimestamp = ::GetTickCount();
  1870. pControl->Event(event);
  1871. }
  1872. break;
  1873. case WM_LBUTTONDBLCLK:
  1874. {
  1875. if (!m_bNoActivate) ::SetFocus(m_hWndPaint);
  1876. POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
  1877. m_ptLastMousePos = pt;
  1878. CControlUI* pControl = FindControl(pt);
  1879. if (pControl == NULL) break;
  1880. if (pControl->GetManager() != this) break;
  1881. //SetCapture();
  1882. TEventUI event = { 0 };
  1883. event.Type = UIEVENT_DBLCLICK;
  1884. event.pSender = pControl;
  1885. event.ptMouse = pt;
  1886. event.wParam = wParam;
  1887. event.lParam = lParam;
  1888. event.wKeyState = (WORD)wParam;
  1889. event.dwTimestamp = ::GetTickCount();
  1890. pControl->Event(event);
  1891. m_pEventClick = pControl;
  1892. }
  1893. break;
  1894. case WM_LBUTTONUP:
  1895. {
  1896. // 触屏拖拽手势(已发生位移)-> 松开不触发点击,仅滚动(避免“拖拽又误点”)
  1897. if (m_bTouchMoved) m_pEventClick = NULL;
  1898. m_bTouchMoved = false; // 用完即清,绝不影响后续真实鼠标点击
  1899. POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
  1900. m_ptLastMousePos = pt;
  1901. if (m_pEventClick == NULL) break;
  1902. ReleaseCapture();
  1903. TEventUI event = { 0 };
  1904. event.Type = UIEVENT_BUTTONUP;
  1905. event.pSender = m_pEventClick;
  1906. event.wParam = wParam;
  1907. event.lParam = lParam;
  1908. event.ptMouse = pt;
  1909. event.wKeyState = (WORD)wParam;
  1910. event.dwTimestamp = ::GetTickCount();
  1911. CControlUI* pClick = m_pEventClick;
  1912. m_pEventClick = NULL;
  1913. pClick->Event(event);
  1914. }
  1915. break;
  1916. case WM_RBUTTONDOWN:
  1917. {
  1918. if (!m_bNoActivate) ::SetFocus(m_hWndPaint);
  1919. POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
  1920. m_ptLastMousePos = pt;
  1921. CControlUI* pControl = FindControl(pt);
  1922. if (pControl == NULL) break;
  1923. if (pControl->GetManager() != this) break;
  1924. pControl->SetFocus();
  1925. SetCapture();
  1926. TEventUI event = { 0 };
  1927. event.Type = UIEVENT_RBUTTONDOWN;
  1928. event.pSender = pControl;
  1929. event.wParam = wParam;
  1930. event.lParam = lParam;
  1931. event.ptMouse = pt;
  1932. event.wKeyState = (WORD)wParam;
  1933. event.dwTimestamp = ::GetTickCount();
  1934. pControl->Event(event);
  1935. m_pEventRClick = pControl;
  1936. }
  1937. break;
  1938. case WM_RBUTTONUP:
  1939. {
  1940. if (m_bMouseCapture) ReleaseCapture();
  1941. POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
  1942. m_ptLastMousePos = pt;
  1943. m_pEventRClick = FindControl(pt);
  1944. if (m_pEventRClick == NULL) break;
  1945. TEventUI event = { 0 };
  1946. event.Type = UIEVENT_RBUTTONUP;
  1947. event.pSender = m_pEventRClick;
  1948. event.wParam = wParam;
  1949. event.lParam = lParam;
  1950. event.ptMouse = pt;
  1951. event.wKeyState = (WORD)wParam;
  1952. event.dwTimestamp = ::GetTickCount();
  1953. m_pEventRClick->Event(event);
  1954. }
  1955. break;
  1956. case WM_MBUTTONDOWN:
  1957. {
  1958. if (!m_bNoActivate) ::SetFocus(m_hWndPaint);
  1959. POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
  1960. m_ptLastMousePos = pt;
  1961. CControlUI* pControl = FindControl(pt);
  1962. if (pControl == NULL) break;
  1963. if (pControl->GetManager() != this) break;
  1964. pControl->SetFocus();
  1965. SetCapture();
  1966. TEventUI event = { 0 };
  1967. event.Type = UIEVENT_MBUTTONDOWN;
  1968. event.pSender = pControl;
  1969. event.wParam = wParam;
  1970. event.lParam = lParam;
  1971. event.ptMouse = pt;
  1972. event.wKeyState = (WORD)wParam;
  1973. event.dwTimestamp = ::GetTickCount();
  1974. pControl->Event(event);
  1975. m_pEventClick = pControl;
  1976. }
  1977. break;
  1978. case WM_MBUTTONUP:
  1979. {
  1980. if (m_bMouseCapture) ReleaseCapture();
  1981. POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
  1982. m_ptLastMousePos = pt;
  1983. m_pEventClick = FindControl(pt);
  1984. if (m_pEventClick == NULL) break;
  1985. TEventUI event = { 0 };
  1986. event.Type = UIEVENT_MBUTTONUP;
  1987. event.pSender = m_pEventClick;
  1988. event.wParam = wParam;
  1989. event.lParam = lParam;
  1990. event.ptMouse = pt;
  1991. event.wKeyState = (WORD)wParam;
  1992. event.dwTimestamp = ::GetTickCount();
  1993. m_pEventClick->Event(event);
  1994. }
  1995. break;
  1996. case WM_CONTEXTMENU:
  1997. {
  1998. if (m_pRoot == NULL) break;
  1999. POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
  2000. ::ScreenToClient(m_hWndPaint, &pt);
  2001. m_ptLastMousePos = pt;
  2002. if (m_pEventRClick == NULL) break;
  2003. ReleaseCapture();
  2004. TEventUI event = { 0 };
  2005. event.Type = UIEVENT_CONTEXTMENU;
  2006. event.pSender = m_pEventRClick;
  2007. event.wParam = wParam;
  2008. event.lParam = lParam;
  2009. event.ptMouse = pt;
  2010. event.wKeyState = (WORD)wParam;
  2011. event.lParam = (LPARAM)m_pEventRClick;
  2012. event.dwTimestamp = ::GetTickCount();
  2013. m_pEventRClick->Event(event);
  2014. m_pEventRClick = NULL;
  2015. }
  2016. break;
  2017. case WM_TOUCH:
  2018. {
  2019. OnTouchInput(wParam, lParam);
  2020. lRes = 0;
  2021. return true;
  2022. }
  2023. case WM_MOUSEWHEEL:
  2024. {
  2025. if (m_pRoot == NULL) break;
  2026. POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
  2027. ::ScreenToClient(m_hWndPaint, &pt);
  2028. m_ptLastMousePos = pt;
  2029. CControlUI* pControl = FindControl(pt);
  2030. if (pControl == NULL) break;
  2031. if (pControl->GetManager() != this) break;
  2032. int zDelta = (int)(short)HIWORD(wParam);
  2033. TEventUI event = { 0 };
  2034. event.Type = UIEVENT_SCROLLWHEEL;
  2035. event.pSender = pControl;
  2036. event.wParam = MAKEWPARAM(zDelta < 0 ? SB_LINEDOWN : SB_LINEUP, zDelta);
  2037. event.lParam = lParam;
  2038. event.ptMouse = pt;
  2039. event.wKeyState = MapKeyState();
  2040. event.dwTimestamp = ::GetTickCount();
  2041. pControl->Event(event);
  2042. // Let's make sure that the scroll item below the cursor is the same as before...
  2043. ::SendMessage(m_hWndPaint, WM_MOUSEMOVE, 0, (LPARAM)MAKELPARAM(m_ptLastMousePos.x, m_ptLastMousePos.y));
  2044. }
  2045. break;
  2046. case WM_CHAR:
  2047. {
  2048. if (m_pRoot == NULL) break;
  2049. if (m_pFocus == NULL) break;
  2050. TEventUI event = { 0 };
  2051. event.Type = UIEVENT_CHAR;
  2052. event.pSender = m_pFocus;
  2053. event.wParam = wParam;
  2054. event.lParam = lParam;
  2055. event.chKey = (TCHAR)wParam;
  2056. event.ptMouse = m_ptLastMousePos;
  2057. event.wKeyState = MapKeyState();
  2058. event.dwTimestamp = ::GetTickCount();
  2059. m_pFocus->Event(event);
  2060. }
  2061. break;
  2062. case WM_KEYDOWN:
  2063. {
  2064. if (m_pRoot == NULL) break;
  2065. if (m_pFocus == NULL) break;
  2066. TEventUI event = { 0 };
  2067. event.Type = UIEVENT_KEYDOWN;
  2068. event.pSender = m_pFocus;
  2069. event.wParam = wParam;
  2070. event.lParam = lParam;
  2071. event.chKey = (TCHAR)wParam;
  2072. event.ptMouse = m_ptLastMousePos;
  2073. event.wKeyState = MapKeyState();
  2074. event.dwTimestamp = ::GetTickCount();
  2075. m_pFocus->Event(event);
  2076. m_pEventKey = m_pFocus;
  2077. }
  2078. break;
  2079. case WM_KEYUP:
  2080. {
  2081. if (m_pRoot == NULL) break;
  2082. if (m_pEventKey == NULL) break;
  2083. TEventUI event = { 0 };
  2084. event.Type = UIEVENT_KEYUP;
  2085. event.pSender = m_pEventKey;
  2086. event.wParam = wParam;
  2087. event.lParam = lParam;
  2088. event.chKey = (TCHAR)wParam;
  2089. event.ptMouse = m_ptLastMousePos;
  2090. event.wKeyState = MapKeyState();
  2091. event.dwTimestamp = ::GetTickCount();
  2092. m_pEventKey->Event(event);
  2093. m_pEventKey = NULL;
  2094. }
  2095. break;
  2096. case WM_SETCURSOR:
  2097. {
  2098. if (m_pRoot == NULL) break;
  2099. if (LOWORD(lParam) != HTCLIENT) break;
  2100. if (m_bMouseCapture) return true;
  2101. POINT pt = { 0 };
  2102. ::GetCursorPos(&pt);
  2103. ::ScreenToClient(m_hWndPaint, &pt);
  2104. CControlUI* pControl = FindControl(pt);
  2105. if (pControl == NULL) break;
  2106. if ((pControl->GetControlFlags() & UIFLAG_SETCURSOR) == 0) break;
  2107. TEventUI event = { 0 };
  2108. event.Type = UIEVENT_SETCURSOR;
  2109. event.pSender = pControl;
  2110. event.wParam = wParam;
  2111. event.lParam = lParam;
  2112. event.ptMouse = pt;
  2113. event.wKeyState = MapKeyState();
  2114. event.dwTimestamp = ::GetTickCount();
  2115. pControl->Event(event);
  2116. }
  2117. return true;
  2118. case WM_SETFOCUS:
  2119. {
  2120. if (m_pFocus != NULL)
  2121. {
  2122. TEventUI event = { 0 };
  2123. event.Type = UIEVENT_SETFOCUS;
  2124. event.wParam = wParam;
  2125. event.lParam = lParam;
  2126. event.pSender = m_pFocus;
  2127. event.dwTimestamp = ::GetTickCount();
  2128. m_pFocus->Event(event);
  2129. }
  2130. break;
  2131. }
  2132. case WM_KILLFOCUS:
  2133. {
  2134. if (IsCaptured()) ReleaseCapture();
  2135. break;
  2136. }
  2137. case WM_NOTIFY:
  2138. {
  2139. if (lParam == 0) break;
  2140. LPNMHDR lpNMHDR = (LPNMHDR)lParam;
  2141. if (lpNMHDR != NULL) lRes = ::SendMessage(lpNMHDR->hwndFrom, OCM__BASE + uMsg, wParam, lParam);
  2142. return true;
  2143. }
  2144. break;
  2145. case WM_COMMAND:
  2146. {
  2147. if (lParam == 0) break;
  2148. HWND hWndChild = (HWND)lParam;
  2149. lRes = ::SendMessage(hWndChild, OCM__BASE + uMsg, wParam, lParam);
  2150. if (lRes != 0) return true;
  2151. }
  2152. break;
  2153. case WM_CTLCOLOREDIT:
  2154. case WM_CTLCOLORSTATIC:
  2155. {
  2156. // Refer To: http://msdn.microsoft.com/en-us/library/bb761691(v=vs.85).aspx
  2157. // Read-only or disabled edit controls do not send the WM_CTLCOLOREDIT message; instead, they send the WM_CTLCOLORSTATIC message.
  2158. if (lParam == 0) break;
  2159. HWND hWndChild = (HWND)lParam;
  2160. lRes = ::SendMessage(hWndChild, OCM__BASE + uMsg, wParam, lParam);
  2161. if (lRes != 0) return true;
  2162. }
  2163. break;
  2164. default:
  2165. break;
  2166. }
  2167. return false;
  2168. }
  2169. bool CPaintManagerUI::IsUpdateNeeded() const
  2170. {
  2171. return m_bUpdateNeeded;
  2172. }
  2173. void CPaintManagerUI::NeedUpdate()
  2174. {
  2175. m_bUpdateNeeded = true;
  2176. }
  2177. void CPaintManagerUI::Invalidate()
  2178. {
  2179. RECT rcClient = { 0 };
  2180. ::GetClientRect(m_hWndPaint, &rcClient);
  2181. ::UnionRect(&m_rcLayeredUpdate, &m_rcLayeredUpdate, &rcClient);
  2182. ::InvalidateRect(m_hWndPaint, NULL, FALSE);
  2183. }
  2184. void CPaintManagerUI::Invalidate(RECT& rcItem)
  2185. {
  2186. if (rcItem.left < 0) rcItem.left = 0;
  2187. if (rcItem.top < 0) rcItem.top = 0;
  2188. if (rcItem.right < rcItem.left) rcItem.right = rcItem.left;
  2189. if (rcItem.bottom < rcItem.top) rcItem.bottom = rcItem.top;
  2190. ::UnionRect(&m_rcLayeredUpdate, &m_rcLayeredUpdate, &rcItem);
  2191. ::InvalidateRect(m_hWndPaint, &rcItem, FALSE);
  2192. }
  2193. bool CPaintManagerUI::IsValid()
  2194. {
  2195. return m_hWndPaint != NULL && m_pRoot != NULL;
  2196. }
  2197. bool CPaintManagerUI::AttachDialog(CControlUI* pControl)
  2198. {
  2199. ASSERT(::IsWindow(m_hWndPaint));
  2200. // 创建阴影窗口
  2201. m_shadow.Create(this);
  2202. // Reset any previous attachment
  2203. SetFocus(NULL);
  2204. m_pEventKey = NULL;
  2205. m_pEventHover = NULL;
  2206. m_pEventClick = NULL;
  2207. m_pEventRClick = NULL;
  2208. // Remove the existing control-tree. We might have gotten inside this function as
  2209. // a result of an event fired or similar, so we cannot just delete the objects and
  2210. // pull the internal memory of the calling code. We'll delay the cleanup.
  2211. if (m_pRoot != NULL)
  2212. {
  2213. m_aPostPaintControls.Empty();
  2214. AddDelayedCleanup(m_pRoot);
  2215. }
  2216. // Set the dialog root element
  2217. m_pRoot = pControl;
  2218. // Go ahead...
  2219. m_bUpdateNeeded = true;
  2220. m_bFirstLayout = true;
  2221. m_bFocusNeeded = true;
  2222. // Initiate all control
  2223. return InitControls(pControl);
  2224. }
  2225. bool CPaintManagerUI::InitControls(CControlUI* pControl, CControlUI* pParent /*= NULL*/)
  2226. {
  2227. ASSERT(pControl);
  2228. if (pControl == NULL) return false;
  2229. pControl->SetManager(this, pParent != NULL ? pParent : pControl->GetParent(), true);
  2230. pControl->FindControl(__FindControlFromNameHash, this, UIFIND_ALL);
  2231. return true;
  2232. }
  2233. void CPaintManagerUI::ReapObjects(CControlUI* pControl)
  2234. {
  2235. if (pControl == m_pEventKey) m_pEventKey = NULL;
  2236. if (pControl == m_pEventHover) m_pEventHover = NULL;
  2237. if (pControl == m_pEventClick) m_pEventClick = NULL;
  2238. if (pControl == m_pEventRClick) m_pEventRClick = NULL;
  2239. if (pControl == m_pFocus) m_pFocus = NULL;
  2240. KillTimer(pControl);
  2241. const CDuiString& sName = pControl->GetName();
  2242. if (!sName.IsEmpty())
  2243. {
  2244. if (pControl == FindControl(sName)) m_mNameHash.Remove(sName);
  2245. }
  2246. for (int i = 0; i < m_aAsyncNotify.GetSize(); i++)
  2247. {
  2248. TNotifyUI* pMsg = static_cast<TNotifyUI*>(m_aAsyncNotify[i]);
  2249. if (pMsg->pSender == pControl) pMsg->pSender = NULL;
  2250. }
  2251. }
  2252. bool CPaintManagerUI::AddOptionGroup(LPCTSTR pStrGroupName, CControlUI* pControl)
  2253. {
  2254. LPVOID lp = m_mOptionGroup.Find(pStrGroupName);
  2255. if (lp)
  2256. {
  2257. CStdPtrArray* aOptionGroup = static_cast<CStdPtrArray*>(lp);
  2258. for (int i = 0; i < aOptionGroup->GetSize(); i++)
  2259. {
  2260. if (static_cast<CControlUI*>(aOptionGroup->GetAt(i)) == pControl)
  2261. {
  2262. return false;
  2263. }
  2264. }
  2265. aOptionGroup->Add(pControl);
  2266. }
  2267. else
  2268. {
  2269. CStdPtrArray* aOptionGroup = new CStdPtrArray(6);
  2270. aOptionGroup->Add(pControl);
  2271. m_mOptionGroup.Insert(pStrGroupName, aOptionGroup);
  2272. }
  2273. return true;
  2274. }
  2275. CStdPtrArray* CPaintManagerUI::GetOptionGroup(LPCTSTR pStrGroupName)
  2276. {
  2277. LPVOID lp = m_mOptionGroup.Find(pStrGroupName);
  2278. if (lp) return static_cast<CStdPtrArray*>(lp);
  2279. return NULL;
  2280. }
  2281. void CPaintManagerUI::RemoveOptionGroup(LPCTSTR pStrGroupName, CControlUI* pControl)
  2282. {
  2283. LPVOID lp = m_mOptionGroup.Find(pStrGroupName);
  2284. if (lp)
  2285. {
  2286. CStdPtrArray* aOptionGroup = static_cast<CStdPtrArray*>(lp);
  2287. if (aOptionGroup == NULL) return;
  2288. for (int i = 0; i < aOptionGroup->GetSize(); i++)
  2289. {
  2290. if (static_cast<CControlUI*>(aOptionGroup->GetAt(i)) == pControl)
  2291. {
  2292. aOptionGroup->Remove(i);
  2293. break;
  2294. }
  2295. }
  2296. if (aOptionGroup->IsEmpty())
  2297. {
  2298. delete aOptionGroup;
  2299. m_mOptionGroup.Remove(pStrGroupName);
  2300. }
  2301. }
  2302. }
  2303. void CPaintManagerUI::RemoveAllOptionGroups()
  2304. {
  2305. CStdPtrArray* aOptionGroup;
  2306. for (int i = 0; i < m_mOptionGroup.GetSize(); i++)
  2307. {
  2308. if (LPCTSTR key = m_mOptionGroup.GetAt(i))
  2309. {
  2310. aOptionGroup = static_cast<CStdPtrArray*>(m_mOptionGroup.Find(key));
  2311. delete aOptionGroup;
  2312. }
  2313. }
  2314. m_mOptionGroup.RemoveAll();
  2315. }
  2316. void CPaintManagerUI::MessageLoop()
  2317. {
  2318. MSG msg = { 0 };
  2319. while (::GetMessage(&msg, NULL, 0, 0))
  2320. {
  2321. if (!CPaintManagerUI::TranslateMessage(&msg))
  2322. {
  2323. ::TranslateMessage(&msg);
  2324. try
  2325. {
  2326. ::DispatchMessage(&msg);
  2327. }
  2328. catch (...)
  2329. {
  2330. DUITRACE(_T("EXCEPTION: %s(%d)\n"), __FILET__, __LINE__);
  2331. #ifdef _DEBUG
  2332. throw "CPaintManagerUI::MessageLoop";
  2333. #endif
  2334. }
  2335. }
  2336. }
  2337. }
  2338. void CPaintManagerUI::Term()
  2339. {
  2340. // 销毁资源管理器
  2341. CResourceManager::GetInstance()->Release();
  2342. CControlFactory::GetInstance()->Release();
  2343. // 清理共享资源
  2344. // 图片
  2345. TImageInfo* data;
  2346. for (int i = 0; i < m_SharedResInfo.m_ImageHash.GetSize(); i++)
  2347. {
  2348. if (LPCTSTR key = m_SharedResInfo.m_ImageHash.GetAt(i))
  2349. {
  2350. data = static_cast<TImageInfo*>(m_SharedResInfo.m_ImageHash.Find(key, false));
  2351. if (data)
  2352. {
  2353. CRenderEngine::FreeImage(data);
  2354. data = NULL;
  2355. }
  2356. }
  2357. }
  2358. m_SharedResInfo.m_ImageHash.RemoveAll();
  2359. // 字体
  2360. TFontInfo* pFontInfo;
  2361. for (int i = 0; i < m_SharedResInfo.m_CustomFonts.GetSize(); i++)
  2362. {
  2363. if (LPCTSTR key = m_SharedResInfo.m_CustomFonts.GetAt(i))
  2364. {
  2365. pFontInfo = static_cast<TFontInfo*>(m_SharedResInfo.m_CustomFonts.Find(key, false));
  2366. if (pFontInfo)
  2367. {
  2368. ::DeleteObject(pFontInfo->hFont);
  2369. delete pFontInfo;
  2370. pFontInfo = NULL;
  2371. }
  2372. }
  2373. }
  2374. m_SharedResInfo.m_CustomFonts.RemoveAll();
  2375. // 默认字体
  2376. if (m_SharedResInfo.m_DefaultFontInfo.hFont != NULL)
  2377. {
  2378. ::DeleteObject(m_SharedResInfo.m_DefaultFontInfo.hFont);
  2379. }
  2380. // 样式
  2381. CDuiString* pStyle;
  2382. for (int i = 0; i < m_SharedResInfo.m_StyleHash.GetSize(); i++)
  2383. {
  2384. if (LPCTSTR key = m_SharedResInfo.m_StyleHash.GetAt(i))
  2385. {
  2386. pStyle = static_cast<CDuiString*>(m_SharedResInfo.m_StyleHash.Find(key, false));
  2387. if (pStyle)
  2388. {
  2389. delete pStyle;
  2390. pStyle = NULL;
  2391. }
  2392. }
  2393. }
  2394. m_SharedResInfo.m_StyleHash.RemoveAll();
  2395. // 样式
  2396. CDuiString* pAttr;
  2397. for (int i = 0; i < m_SharedResInfo.m_AttrHash.GetSize(); i++)
  2398. {
  2399. if (LPCTSTR key = m_SharedResInfo.m_AttrHash.GetAt(i))
  2400. {
  2401. pAttr = static_cast<CDuiString*>(m_SharedResInfo.m_AttrHash.Find(key, false));
  2402. if (pAttr)
  2403. {
  2404. delete pAttr;
  2405. pAttr = NULL;
  2406. }
  2407. }
  2408. }
  2409. m_SharedResInfo.m_AttrHash.RemoveAll();
  2410. // 关闭ZIP
  2411. if (m_bCachedResourceZip && m_hResourceZip != NULL)
  2412. {
  2413. CloseZip((HZIP)m_hResourceZip);
  2414. m_hResourceZip = NULL;
  2415. }
  2416. if (m_cbZipBuf)
  2417. {
  2418. delete[] m_cbZipBuf;
  2419. m_cbZipBuf = nullptr;
  2420. }
  2421. }
  2422. CDPI* DuiLib::CPaintManagerUI::GetDPIObj()
  2423. {
  2424. if (m_pDPI == NULL)
  2425. {
  2426. m_pDPI = new CDPI;
  2427. }
  2428. return m_pDPI;
  2429. }
  2430. void DuiLib::CPaintManagerUI::SetDPI(int iDPI)
  2431. {
  2432. int scale1 = GetDPIObj()->GetScale();
  2433. GetDPIObj()->SetScale(iDPI);
  2434. int scale2 = GetDPIObj()->GetScale();
  2435. ResetDPIAssets();
  2436. RECT rcWnd = { 0 };
  2437. ::GetWindowRect(GetPaintWindow(), &rcWnd);
  2438. RECT* prcNewWindow = &rcWnd;
  2439. if (!::IsZoomed(GetPaintWindow()))
  2440. {
  2441. RECT rc = rcWnd;
  2442. rc.right = rcWnd.left + (rcWnd.right - rcWnd.left) * scale2 / scale1;
  2443. rc.bottom = rcWnd.top + (rcWnd.bottom - rcWnd.top) * scale2 / scale1;
  2444. prcNewWindow = &rc;
  2445. }
  2446. SetWindowPos(GetPaintWindow(), NULL, prcNewWindow->left, prcNewWindow->top, prcNewWindow->right - prcNewWindow->left, prcNewWindow->bottom - prcNewWindow->top, SWP_NOZORDER | SWP_NOACTIVATE);
  2447. if (GetRoot() != NULL) GetRoot()->NeedUpdate();
  2448. ::PostMessage(GetPaintWindow(), UIMSG_SET_DPI, 0, 0);
  2449. }
  2450. void DuiLib::CPaintManagerUI::SetAllDPI(int iDPI)
  2451. {
  2452. for (int i = 0; i < m_aPreMessages.GetSize(); i++)
  2453. {
  2454. CPaintManagerUI* pManager = static_cast<CPaintManagerUI*>(m_aPreMessages[i]);
  2455. pManager->SetDPI(iDPI);
  2456. }
  2457. }
  2458. void DuiLib::CPaintManagerUI::ResetDPIAssets()
  2459. {
  2460. RemoveAllDrawInfos();
  2461. RemoveAllImages();;
  2462. for (int it = 0; it < m_ResInfo.m_CustomFonts.GetSize(); it++)
  2463. {
  2464. TFontInfo* pFontInfo = static_cast<TFontInfo*>(m_ResInfo.m_CustomFonts.Find(m_ResInfo.m_CustomFonts[it]));
  2465. RebuildFont(pFontInfo);
  2466. }
  2467. RebuildFont(&m_ResInfo.m_DefaultFontInfo);
  2468. for (int it = 0; it < m_SharedResInfo.m_CustomFonts.GetSize(); it++)
  2469. {
  2470. TFontInfo* pFontInfo = static_cast<TFontInfo*>(m_SharedResInfo.m_CustomFonts.Find(m_SharedResInfo.m_CustomFonts[it]));
  2471. RebuildFont(pFontInfo);
  2472. }
  2473. RebuildFont(&m_SharedResInfo.m_DefaultFontInfo);
  2474. CStdPtrArray* richEditList = FindSubControlsByClass(GetRoot(), _T("RichEditUI"));
  2475. for (int i = 0; i < richEditList->GetSize(); i++)
  2476. {
  2477. CRichEditUI* pT = static_cast<CRichEditUI*>((*richEditList)[i]);
  2478. pT->SetFont(pT->GetFont());
  2479. }
  2480. }
  2481. void DuiLib::CPaintManagerUI::RebuildFont(TFontInfo* pFontInfo)
  2482. {
  2483. ::DeleteObject(pFontInfo->hFont);
  2484. LOGFONT lf = { 0 };
  2485. ::GetObject(::GetStockObject(DEFAULT_GUI_FONT), sizeof(LOGFONT), &lf);
  2486. _tcsncpy(lf.lfFaceName, pFontInfo->sFontName, LF_FACESIZE);
  2487. lf.lfCharSet = DEFAULT_CHARSET;
  2488. lf.lfHeight = -GetDPIObj()->Scale(pFontInfo->iSize);
  2489. lf.lfQuality = CLEARTYPE_QUALITY;
  2490. if (pFontInfo->bBold) lf.lfWeight += FW_BOLD;
  2491. if (pFontInfo->bUnderline) lf.lfUnderline = TRUE;
  2492. if (pFontInfo->bItalic) lf.lfItalic = TRUE;
  2493. HFONT hFont = ::CreateFontIndirect(&lf);
  2494. pFontInfo->hFont = hFont;
  2495. ::ZeroMemory(&(pFontInfo->tm), sizeof(pFontInfo->tm));
  2496. if (m_hDcPaint)
  2497. {
  2498. HFONT hOldFont = (HFONT) ::SelectObject(m_hDcPaint, hFont);
  2499. ::GetTextMetrics(m_hDcPaint, &pFontInfo->tm);
  2500. ::SelectObject(m_hDcPaint, hOldFont);
  2501. }
  2502. }
  2503. CControlUI* CPaintManagerUI::GetFocus() const
  2504. {
  2505. return m_pFocus;
  2506. }
  2507. void CPaintManagerUI::SetFocus(CControlUI* pControl)
  2508. {
  2509. // Paint manager window has focus?
  2510. HWND hFocusWnd = ::GetFocus();
  2511. if (!m_bNoActivate && hFocusWnd != m_hWndPaint && pControl != m_pFocus) ::SetFocus(m_hWndPaint);
  2512. // Already has focus?
  2513. if (pControl == m_pFocus) return;
  2514. // Remove focus from old control
  2515. if (m_pFocus != NULL)
  2516. {
  2517. TEventUI event = { 0 };
  2518. event.Type = UIEVENT_KILLFOCUS;
  2519. event.pSender = pControl;
  2520. event.dwTimestamp = ::GetTickCount();
  2521. m_pFocus->Event(event);
  2522. SendNotify(m_pFocus, DUI_MSGTYPE_KILLFOCUS);
  2523. m_pFocus = NULL;
  2524. }
  2525. if (pControl == NULL) return;
  2526. // Set focus to new control
  2527. if (pControl != NULL
  2528. && pControl->GetManager() == this
  2529. && pControl->IsVisible()
  2530. && pControl->IsEnabled())
  2531. {
  2532. m_pFocus = pControl;
  2533. TEventUI event = { 0 };
  2534. event.Type = UIEVENT_SETFOCUS;
  2535. event.pSender = pControl;
  2536. event.dwTimestamp = ::GetTickCount();
  2537. m_pFocus->Event(event);
  2538. SendNotify(m_pFocus, DUI_MSGTYPE_SETFOCUS);
  2539. }
  2540. }
  2541. void CPaintManagerUI::SetFocusNeeded(CControlUI* pControl)
  2542. {
  2543. if (!m_bNoActivate) ::SetFocus(m_hWndPaint);
  2544. if (pControl == NULL) return;
  2545. if (m_pFocus != NULL)
  2546. {
  2547. TEventUI event = { 0 };
  2548. event.Type = UIEVENT_KILLFOCUS;
  2549. event.pSender = pControl;
  2550. event.dwTimestamp = ::GetTickCount();
  2551. m_pFocus->Event(event);
  2552. SendNotify(m_pFocus, DUI_MSGTYPE_KILLFOCUS);
  2553. m_pFocus = NULL;
  2554. }
  2555. FINDTABINFO info = { 0 };
  2556. info.pFocus = pControl;
  2557. info.bForward = false;
  2558. m_pFocus = m_pRoot->FindControl(__FindControlFromTab, &info, UIFIND_VISIBLE | UIFIND_ENABLED | UIFIND_ME_FIRST);
  2559. m_bFocusNeeded = true;
  2560. if (m_pRoot != NULL) m_pRoot->NeedUpdate();
  2561. }
  2562. bool CPaintManagerUI::SetTimer(CControlUI* pControl, UINT nTimerID, UINT uElapse)
  2563. {
  2564. ASSERT(pControl != NULL);
  2565. ASSERT(uElapse > 0);
  2566. for (int i = 0; i < m_aTimers.GetSize(); i++)
  2567. {
  2568. TIMERINFO* pTimer = static_cast<TIMERINFO*>(m_aTimers[i]);
  2569. if (pTimer->pSender == pControl
  2570. && pTimer->hWnd == m_hWndPaint
  2571. && pTimer->nLocalID == nTimerID)
  2572. {
  2573. if (pTimer->bKilled == true)
  2574. {
  2575. if (::SetTimer(m_hWndPaint, pTimer->uWinTimer, uElapse, NULL))
  2576. {
  2577. pTimer->bKilled = false;
  2578. return true;
  2579. }
  2580. return false;
  2581. }
  2582. return false;
  2583. }
  2584. }
  2585. m_uTimerID = (++m_uTimerID) % 0xF0; //0xf1-0xfe特殊用途
  2586. if (!::SetTimer(m_hWndPaint, m_uTimerID, uElapse, NULL)) return FALSE;
  2587. TIMERINFO* pTimer = new TIMERINFO;
  2588. if (pTimer == NULL) return FALSE;
  2589. pTimer->hWnd = m_hWndPaint;
  2590. pTimer->pSender = pControl;
  2591. pTimer->nLocalID = nTimerID;
  2592. pTimer->uWinTimer = m_uTimerID;
  2593. pTimer->bKilled = false;
  2594. return m_aTimers.Add(pTimer);
  2595. }
  2596. bool CPaintManagerUI::KillTimer(CControlUI* pControl, UINT nTimerID)
  2597. {
  2598. ASSERT(pControl != NULL);
  2599. for (int i = 0; i < m_aTimers.GetSize(); i++)
  2600. {
  2601. TIMERINFO* pTimer = static_cast<TIMERINFO*>(m_aTimers[i]);
  2602. if (pTimer->pSender == pControl
  2603. && pTimer->hWnd == m_hWndPaint
  2604. && pTimer->nLocalID == nTimerID)
  2605. {
  2606. if (pTimer->bKilled == false)
  2607. {
  2608. if (::IsWindow(m_hWndPaint)) ::KillTimer(pTimer->hWnd, pTimer->uWinTimer);
  2609. pTimer->bKilled = true;
  2610. return true;
  2611. }
  2612. }
  2613. }
  2614. return false;
  2615. }
  2616. void CPaintManagerUI::KillTimer(CControlUI* pControl)
  2617. {
  2618. ASSERT(pControl != NULL);
  2619. int count = m_aTimers.GetSize();
  2620. for (int i = 0, j = 0; i < count; i++)
  2621. {
  2622. TIMERINFO* pTimer = static_cast<TIMERINFO*>(m_aTimers[i - j]);
  2623. if (pTimer->pSender == pControl && pTimer->hWnd == m_hWndPaint)
  2624. {
  2625. if (pTimer->bKilled == false) ::KillTimer(pTimer->hWnd, pTimer->uWinTimer);
  2626. delete pTimer;
  2627. m_aTimers.Remove(i - j);
  2628. j++;
  2629. }
  2630. }
  2631. }
  2632. void CPaintManagerUI::RemoveAllTimers()
  2633. {
  2634. for (int i = 0; i < m_aTimers.GetSize(); i++)
  2635. {
  2636. TIMERINFO* pTimer = static_cast<TIMERINFO*>(m_aTimers[i]);
  2637. if (pTimer->hWnd == m_hWndPaint)
  2638. {
  2639. if (pTimer->bKilled == false)
  2640. {
  2641. if (::IsWindow(m_hWndPaint)) ::KillTimer(m_hWndPaint, pTimer->uWinTimer);
  2642. }
  2643. delete pTimer;
  2644. }
  2645. }
  2646. m_aTimers.Empty();
  2647. }
  2648. void CPaintManagerUI::SetCapture()
  2649. {
  2650. ::SetCapture(m_hWndPaint);
  2651. m_bMouseCapture = true;
  2652. }
  2653. void CPaintManagerUI::ReleaseCapture()
  2654. {
  2655. ::ReleaseCapture();
  2656. m_bMouseCapture = false;
  2657. m_bDragMode = false;
  2658. }
  2659. bool CPaintManagerUI::IsCaptured()
  2660. {
  2661. return m_bMouseCapture;
  2662. }
  2663. bool CPaintManagerUI::IsPainting()
  2664. {
  2665. return m_bIsPainting;
  2666. }
  2667. void CPaintManagerUI::SetPainting(bool bIsPainting)
  2668. {
  2669. m_bIsPainting = bIsPainting;
  2670. }
  2671. bool CPaintManagerUI::SetNextTabControl(bool bForward)
  2672. {
  2673. // If we're in the process of restructuring the layout we can delay the
  2674. // focus calulation until the next repaint.
  2675. if (m_bUpdateNeeded && bForward)
  2676. {
  2677. m_bFocusNeeded = true;
  2678. ::InvalidateRect(m_hWndPaint, NULL, FALSE);
  2679. return true;
  2680. }
  2681. // Find next/previous tabbable control
  2682. FINDTABINFO info1 = { 0 };
  2683. info1.pFocus = m_pFocus;
  2684. info1.bForward = bForward;
  2685. CControlUI* pControl = m_pRoot->FindControl(__FindControlFromTab, &info1, UIFIND_VISIBLE | UIFIND_ENABLED | UIFIND_ME_FIRST);
  2686. if (pControl == NULL)
  2687. {
  2688. if (bForward)
  2689. {
  2690. // Wrap around
  2691. FINDTABINFO info2 = { 0 };
  2692. info2.pFocus = bForward ? NULL : info1.pLast;
  2693. info2.bForward = bForward;
  2694. pControl = m_pRoot->FindControl(__FindControlFromTab, &info2, UIFIND_VISIBLE | UIFIND_ENABLED | UIFIND_ME_FIRST);
  2695. }
  2696. else
  2697. {
  2698. pControl = info1.pLast;
  2699. }
  2700. }
  2701. if (pControl != NULL) SetFocus(pControl);
  2702. m_bFocusNeeded = false;
  2703. return true;
  2704. }
  2705. bool CPaintManagerUI::AddNotifier(INotifyUI* pNotifier)
  2706. {
  2707. ASSERT(m_aNotifiers.Find(pNotifier) < 0);
  2708. return m_aNotifiers.Add(pNotifier);
  2709. }
  2710. bool CPaintManagerUI::RemoveNotifier(INotifyUI* pNotifier)
  2711. {
  2712. for (int i = 0; i < m_aNotifiers.GetSize(); i++)
  2713. {
  2714. if (static_cast<INotifyUI*>(m_aNotifiers[i]) == pNotifier)
  2715. {
  2716. return m_aNotifiers.Remove(i);
  2717. }
  2718. }
  2719. return false;
  2720. }
  2721. bool CPaintManagerUI::AddPreMessageFilter(IMessageFilterUI* pFilter)
  2722. {
  2723. ASSERT(m_aPreMessageFilters.Find(pFilter) < 0);
  2724. return m_aPreMessageFilters.Add(pFilter);
  2725. }
  2726. bool CPaintManagerUI::RemovePreMessageFilter(IMessageFilterUI* pFilter)
  2727. {
  2728. for (int i = 0; i < m_aPreMessageFilters.GetSize(); i++)
  2729. {
  2730. if (static_cast<IMessageFilterUI*>(m_aPreMessageFilters[i]) == pFilter)
  2731. {
  2732. return m_aPreMessageFilters.Remove(i);
  2733. }
  2734. }
  2735. return false;
  2736. }
  2737. bool CPaintManagerUI::AddMessageFilter(IMessageFilterUI* pFilter)
  2738. {
  2739. ASSERT(m_aMessageFilters.Find(pFilter) < 0);
  2740. return m_aMessageFilters.Add(pFilter);
  2741. }
  2742. bool CPaintManagerUI::RemoveMessageFilter(IMessageFilterUI* pFilter)
  2743. {
  2744. for (int i = 0; i < m_aMessageFilters.GetSize(); i++)
  2745. {
  2746. if (static_cast<IMessageFilterUI*>(m_aMessageFilters[i]) == pFilter)
  2747. {
  2748. return m_aMessageFilters.Remove(i);
  2749. }
  2750. }
  2751. return false;
  2752. }
  2753. int CPaintManagerUI::GetPostPaintCount() const
  2754. {
  2755. return m_aPostPaintControls.GetSize();
  2756. }
  2757. bool CPaintManagerUI::IsPostPaint(CControlUI* pControl)
  2758. {
  2759. return m_aPostPaintControls.Find(pControl) >= 0;
  2760. }
  2761. bool CPaintManagerUI::AddPostPaint(CControlUI* pControl)
  2762. {
  2763. ASSERT(m_aPostPaintControls.Find(pControl) < 0);
  2764. return m_aPostPaintControls.Add(pControl);
  2765. }
  2766. bool CPaintManagerUI::RemovePostPaint(CControlUI* pControl)
  2767. {
  2768. for (int i = 0; i < m_aPostPaintControls.GetSize(); i++)
  2769. {
  2770. if (static_cast<CControlUI*>(m_aPostPaintControls[i]) == pControl)
  2771. {
  2772. return m_aPostPaintControls.Remove(i);
  2773. }
  2774. }
  2775. return false;
  2776. }
  2777. bool CPaintManagerUI::SetPostPaintIndex(CControlUI* pControl, int iIndex)
  2778. {
  2779. RemovePostPaint(pControl);
  2780. return m_aPostPaintControls.InsertAt(iIndex, pControl);
  2781. }
  2782. int CPaintManagerUI::GetNativeWindowCount() const
  2783. {
  2784. return m_aNativeWindow.GetSize();
  2785. }
  2786. bool CPaintManagerUI::AddNativeWindow(CControlUI* pControl, HWND hChildWnd)
  2787. {
  2788. if (pControl == NULL || hChildWnd == NULL) return false;
  2789. RECT rcChildWnd = GetNativeWindowRect(hChildWnd);
  2790. Invalidate(rcChildWnd);
  2791. if (m_aNativeWindow.Find(hChildWnd) >= 0) return false;
  2792. if (m_aNativeWindow.Add(hChildWnd))
  2793. {
  2794. m_aNativeWindowControl.Add(pControl);
  2795. return true;
  2796. }
  2797. return false;
  2798. }
  2799. bool CPaintManagerUI::RemoveNativeWindow(HWND hChildWnd)
  2800. {
  2801. for (int i = 0; i < m_aNativeWindow.GetSize(); i++)
  2802. {
  2803. if (static_cast<HWND>(m_aNativeWindow[i]) == hChildWnd)
  2804. {
  2805. if (m_aNativeWindow.Remove(i))
  2806. {
  2807. m_aNativeWindowControl.Remove(i);
  2808. return true;
  2809. }
  2810. return false;
  2811. }
  2812. }
  2813. return false;
  2814. }
  2815. RECT CPaintManagerUI::GetNativeWindowRect(HWND hChildWnd)
  2816. {
  2817. RECT rcChildWnd;
  2818. ::GetWindowRect(hChildWnd, &rcChildWnd);
  2819. ::ScreenToClient(m_hWndPaint, (LPPOINT)(&rcChildWnd));
  2820. ::ScreenToClient(m_hWndPaint, (LPPOINT)(&rcChildWnd) + 1);
  2821. return rcChildWnd;
  2822. }
  2823. void CPaintManagerUI::AddDelayedCleanup(CControlUI* pControl)
  2824. {
  2825. if (pControl == NULL) return;
  2826. pControl->SetManager(this, NULL, false);
  2827. m_aDelayedCleanup.Add(pControl);
  2828. PostAsyncNotify();
  2829. }
  2830. void CPaintManagerUI::AddMouseLeaveNeeded(CControlUI* pControl)
  2831. {
  2832. if (pControl == NULL) return;
  2833. for (int i = 0; i < m_aNeedMouseLeaveNeeded.GetSize(); i++)
  2834. {
  2835. if (static_cast<CControlUI*>(m_aNeedMouseLeaveNeeded[i]) == pControl)
  2836. {
  2837. return;
  2838. }
  2839. }
  2840. m_aNeedMouseLeaveNeeded.Add(pControl);
  2841. }
  2842. bool CPaintManagerUI::RemoveMouseLeaveNeeded(CControlUI* pControl)
  2843. {
  2844. if (pControl == NULL) return false;
  2845. for (int i = 0; i < m_aNeedMouseLeaveNeeded.GetSize(); i++)
  2846. {
  2847. if (static_cast<CControlUI*>(m_aNeedMouseLeaveNeeded[i]) == pControl)
  2848. {
  2849. return m_aNeedMouseLeaveNeeded.Remove(i);
  2850. }
  2851. }
  2852. return false;
  2853. }
  2854. void CPaintManagerUI::SendNotify(CControlUI* pControl, LPCTSTR pstrMessage, WPARAM wParam /*= 0*/, LPARAM lParam /*= 0*/, bool bAsync /*= false*/)
  2855. {
  2856. TNotifyUI Msg;
  2857. Msg.pSender = pControl;
  2858. Msg.sType = pstrMessage;
  2859. Msg.wParam = wParam;
  2860. Msg.lParam = lParam;
  2861. SendNotify(Msg, bAsync);
  2862. }
  2863. void CPaintManagerUI::SendNotify(TNotifyUI& Msg, bool bAsync /*= false*/)
  2864. {
  2865. Msg.ptMouse = m_ptLastMousePos;
  2866. Msg.dwTimestamp = ::GetTickCount();
  2867. if (m_bUsedVirtualWnd)
  2868. {
  2869. Msg.sVirtualWnd = Msg.pSender->GetVirtualWnd();
  2870. }
  2871. if (!bAsync)
  2872. {
  2873. // Send to all listeners
  2874. if (Msg.pSender != NULL)
  2875. {
  2876. if (Msg.pSender->OnNotify) Msg.pSender->OnNotify(&Msg);
  2877. }
  2878. for (int i = 0; i < m_aNotifiers.GetSize(); i++)
  2879. {
  2880. static_cast<INotifyUI*>(m_aNotifiers[i])->Notify(Msg);
  2881. }
  2882. }
  2883. else
  2884. {
  2885. TNotifyUI* pMsg = new TNotifyUI;
  2886. pMsg->sVirtualWnd = Msg.sVirtualWnd;
  2887. pMsg->pSender = Msg.pSender;
  2888. pMsg->sType = Msg.sType;
  2889. pMsg->wParam = Msg.wParam;
  2890. pMsg->lParam = Msg.lParam;
  2891. pMsg->ptMouse = Msg.ptMouse;
  2892. pMsg->dwTimestamp = Msg.dwTimestamp;
  2893. m_aAsyncNotify.Add(pMsg);
  2894. PostAsyncNotify();
  2895. }
  2896. }
  2897. bool CPaintManagerUI::IsForceUseSharedRes() const
  2898. {
  2899. return m_bForceUseSharedRes;
  2900. }
  2901. void CPaintManagerUI::SetForceUseSharedRes(bool bForce)
  2902. {
  2903. m_bForceUseSharedRes = bForce;
  2904. }
  2905. DWORD CPaintManagerUI::GetDefaultDisabledColor() const
  2906. {
  2907. return m_ResInfo.m_dwDefaultDisabledColor;
  2908. }
  2909. void CPaintManagerUI::SetDefaultDisabledColor(DWORD dwColor, bool bShared)
  2910. {
  2911. if (bShared)
  2912. {
  2913. if (m_ResInfo.m_dwDefaultDisabledColor == m_SharedResInfo.m_dwDefaultDisabledColor)
  2914. m_ResInfo.m_dwDefaultDisabledColor = dwColor;
  2915. m_SharedResInfo.m_dwDefaultDisabledColor = dwColor;
  2916. }
  2917. else
  2918. {
  2919. m_ResInfo.m_dwDefaultDisabledColor = dwColor;
  2920. }
  2921. }
  2922. DWORD CPaintManagerUI::GetDefaultFontColor() const
  2923. {
  2924. return m_ResInfo.m_dwDefaultFontColor;
  2925. }
  2926. void CPaintManagerUI::SetDefaultFontColor(DWORD dwColor, bool bShared)
  2927. {
  2928. if (bShared)
  2929. {
  2930. if (m_ResInfo.m_dwDefaultFontColor == m_SharedResInfo.m_dwDefaultFontColor)
  2931. m_ResInfo.m_dwDefaultFontColor = dwColor;
  2932. m_SharedResInfo.m_dwDefaultFontColor = dwColor;
  2933. }
  2934. else
  2935. {
  2936. m_ResInfo.m_dwDefaultFontColor = dwColor;
  2937. }
  2938. }
  2939. DWORD CPaintManagerUI::GetDefaultLinkFontColor() const
  2940. {
  2941. return m_ResInfo.m_dwDefaultLinkFontColor;
  2942. }
  2943. void CPaintManagerUI::SetDefaultLinkFontColor(DWORD dwColor, bool bShared)
  2944. {
  2945. if (bShared)
  2946. {
  2947. if (m_ResInfo.m_dwDefaultLinkFontColor == m_SharedResInfo.m_dwDefaultLinkFontColor)
  2948. m_ResInfo.m_dwDefaultLinkFontColor = dwColor;
  2949. m_SharedResInfo.m_dwDefaultLinkFontColor = dwColor;
  2950. }
  2951. else
  2952. {
  2953. m_ResInfo.m_dwDefaultLinkFontColor = dwColor;
  2954. }
  2955. }
  2956. DWORD CPaintManagerUI::GetDefaultLinkHoverFontColor() const
  2957. {
  2958. return m_ResInfo.m_dwDefaultLinkHoverFontColor;
  2959. }
  2960. void CPaintManagerUI::SetDefaultLinkHoverFontColor(DWORD dwColor, bool bShared)
  2961. {
  2962. if (bShared)
  2963. {
  2964. if (m_ResInfo.m_dwDefaultLinkHoverFontColor == m_SharedResInfo.m_dwDefaultLinkHoverFontColor)
  2965. m_ResInfo.m_dwDefaultLinkHoverFontColor = dwColor;
  2966. m_SharedResInfo.m_dwDefaultLinkHoverFontColor = dwColor;
  2967. }
  2968. else
  2969. {
  2970. m_ResInfo.m_dwDefaultLinkHoverFontColor = dwColor;
  2971. }
  2972. }
  2973. DWORD CPaintManagerUI::GetDefaultSelectedBkColor() const
  2974. {
  2975. return m_ResInfo.m_dwDefaultSelectedBkColor;
  2976. }
  2977. void CPaintManagerUI::SetDefaultSelectedBkColor(DWORD dwColor, bool bShared)
  2978. {
  2979. if (bShared)
  2980. {
  2981. if (m_ResInfo.m_dwDefaultSelectedBkColor == m_SharedResInfo.m_dwDefaultSelectedBkColor)
  2982. m_ResInfo.m_dwDefaultSelectedBkColor = dwColor;
  2983. m_SharedResInfo.m_dwDefaultSelectedBkColor = dwColor;
  2984. }
  2985. else
  2986. {
  2987. m_ResInfo.m_dwDefaultSelectedBkColor = dwColor;
  2988. }
  2989. }
  2990. TFontInfo* CPaintManagerUI::GetDefaultFontInfo()
  2991. {
  2992. if (m_ResInfo.m_DefaultFontInfo.sFontName.IsEmpty())
  2993. {
  2994. if (m_SharedResInfo.m_DefaultFontInfo.tm.tmHeight == 0)
  2995. {
  2996. HFONT hOldFont = (HFONT) ::SelectObject(m_hDcPaint, m_SharedResInfo.m_DefaultFontInfo.hFont);
  2997. ::GetTextMetrics(m_hDcPaint, &m_SharedResInfo.m_DefaultFontInfo.tm);
  2998. ::SelectObject(m_hDcPaint, hOldFont);
  2999. }
  3000. return &m_SharedResInfo.m_DefaultFontInfo;
  3001. }
  3002. else
  3003. {
  3004. if (m_ResInfo.m_DefaultFontInfo.tm.tmHeight == 0)
  3005. {
  3006. HFONT hOldFont = (HFONT) ::SelectObject(m_hDcPaint, m_ResInfo.m_DefaultFontInfo.hFont);
  3007. ::GetTextMetrics(m_hDcPaint, &m_ResInfo.m_DefaultFontInfo.tm);
  3008. ::SelectObject(m_hDcPaint, hOldFont);
  3009. }
  3010. return &m_ResInfo.m_DefaultFontInfo;
  3011. }
  3012. }
  3013. void CPaintManagerUI::SetDefaultFont(LPCTSTR pStrFontName, int nSize, bool bBold, bool bUnderline, bool bItalic, bool bStrikeout, bool bShared)
  3014. {
  3015. LOGFONT lf = { 0 };
  3016. ::GetObject(::GetStockObject(DEFAULT_GUI_FONT), sizeof(LOGFONT), &lf);
  3017. if (lstrlen(pStrFontName) > 0)
  3018. {
  3019. TCHAR szFaceName[32] = { 0 };//_T("@");
  3020. _tcsncat(szFaceName, pStrFontName, LF_FACESIZE);
  3021. _tcsncpy(lf.lfFaceName, szFaceName, LF_FACESIZE);
  3022. }
  3023. lf.lfCharSet = DEFAULT_CHARSET;
  3024. lf.lfHeight = -GetDPIObj()->Scale(nSize);;
  3025. if (bBold) lf.lfWeight += FW_BOLD;
  3026. if (bUnderline) lf.lfUnderline = TRUE;
  3027. if (bItalic) lf.lfItalic = TRUE;
  3028. if (bStrikeout) lf.lfStrikeOut = TRUE;
  3029. HFONT hFont = ::CreateFontIndirect(&lf);
  3030. if (hFont == NULL) return;
  3031. if (bShared)
  3032. {
  3033. ::DeleteObject(m_SharedResInfo.m_DefaultFontInfo.hFont);
  3034. m_SharedResInfo.m_DefaultFontInfo.hFont = hFont;
  3035. m_SharedResInfo.m_DefaultFontInfo.sFontName = lf.lfFaceName;
  3036. m_SharedResInfo.m_DefaultFontInfo.iSize = nSize;
  3037. m_SharedResInfo.m_DefaultFontInfo.bBold = bBold;
  3038. m_SharedResInfo.m_DefaultFontInfo.bUnderline = bUnderline;
  3039. m_SharedResInfo.m_DefaultFontInfo.bItalic = bItalic;
  3040. m_SharedResInfo.m_DefaultFontInfo.bStrikeout = bStrikeout;
  3041. ::ZeroMemory(&m_SharedResInfo.m_DefaultFontInfo.tm, sizeof(m_SharedResInfo.m_DefaultFontInfo.tm));
  3042. if (m_hDcPaint)
  3043. {
  3044. HFONT hOldFont = (HFONT) ::SelectObject(m_hDcPaint, hFont);
  3045. ::GetTextMetrics(m_hDcPaint, &m_SharedResInfo.m_DefaultFontInfo.tm);
  3046. ::SelectObject(m_hDcPaint, hOldFont);
  3047. }
  3048. }
  3049. else
  3050. {
  3051. ::DeleteObject(m_ResInfo.m_DefaultFontInfo.hFont);
  3052. m_ResInfo.m_DefaultFontInfo.hFont = hFont;
  3053. m_ResInfo.m_DefaultFontInfo.sFontName = lf.lfFaceName;
  3054. m_ResInfo.m_DefaultFontInfo.iSize = nSize;
  3055. m_ResInfo.m_DefaultFontInfo.bBold = bBold;
  3056. m_ResInfo.m_DefaultFontInfo.bUnderline = bUnderline;
  3057. m_ResInfo.m_DefaultFontInfo.bItalic = bItalic;
  3058. m_ResInfo.m_DefaultFontInfo.bStrikeout = bStrikeout;
  3059. ::ZeroMemory(&m_ResInfo.m_DefaultFontInfo.tm, sizeof(m_ResInfo.m_DefaultFontInfo.tm));
  3060. if (m_hDcPaint)
  3061. {
  3062. HFONT hOldFont = (HFONT) ::SelectObject(m_hDcPaint, hFont);
  3063. ::GetTextMetrics(m_hDcPaint, &m_ResInfo.m_DefaultFontInfo.tm);
  3064. ::SelectObject(m_hDcPaint, hOldFont);
  3065. }
  3066. }
  3067. }
  3068. DWORD CPaintManagerUI::GetCustomFontCount(bool bShared) const
  3069. {
  3070. if (bShared)
  3071. return m_SharedResInfo.m_CustomFonts.GetSize();
  3072. else
  3073. return m_ResInfo.m_CustomFonts.GetSize();
  3074. }
  3075. HFONT CPaintManagerUI::AddFont(int id, LPCTSTR pStrFontName, int nSize, bool bBold, bool bUnderline, bool bItalic, bool bStrikeout, bool bShared)
  3076. {
  3077. LOGFONT lf = { 0 };
  3078. ::GetObject(::GetStockObject(DEFAULT_GUI_FONT), sizeof(LOGFONT), &lf);
  3079. if (lstrlen(pStrFontName) > 0)
  3080. {
  3081. TCHAR szFaceName[32] = { 0 };//_T("@");
  3082. _tcsncat(szFaceName, pStrFontName, LF_FACESIZE);
  3083. _tcsncpy(lf.lfFaceName, szFaceName, LF_FACESIZE);
  3084. }
  3085. lf.lfCharSet = DEFAULT_CHARSET;
  3086. lf.lfHeight = -GetDPIObj()->Scale(nSize);
  3087. if (bBold) lf.lfWeight = FW_BOLD;
  3088. if (bUnderline) lf.lfUnderline = TRUE;
  3089. if (bItalic) lf.lfItalic = TRUE;
  3090. if (bStrikeout) lf.lfStrikeOut = TRUE;
  3091. HFONT hFont = ::CreateFontIndirect(&lf);
  3092. if (hFont == NULL) return NULL;
  3093. TFontInfo* pFontInfo = new TFontInfo;
  3094. if (!pFontInfo) return false;
  3095. ::ZeroMemory(pFontInfo, sizeof(TFontInfo));
  3096. pFontInfo->hFont = hFont;
  3097. pFontInfo->sFontName = lf.lfFaceName;
  3098. pFontInfo->iSize = nSize;
  3099. pFontInfo->bBold = bBold;
  3100. pFontInfo->bUnderline = bUnderline;
  3101. pFontInfo->bItalic = bItalic;
  3102. pFontInfo->bStrikeout = bStrikeout;
  3103. if (m_hDcPaint)
  3104. {
  3105. HFONT hOldFont = (HFONT) ::SelectObject(m_hDcPaint, hFont);
  3106. ::GetTextMetrics(m_hDcPaint, &pFontInfo->tm);
  3107. ::SelectObject(m_hDcPaint, hOldFont);
  3108. }
  3109. TCHAR idBuffer[16];
  3110. ::ZeroMemory(idBuffer, sizeof(idBuffer));
  3111. _itot(id, idBuffer, 10);
  3112. if (bShared || m_bForceUseSharedRes)
  3113. {
  3114. TFontInfo* pOldFontInfo = static_cast<TFontInfo*>(m_SharedResInfo.m_CustomFonts.Find(idBuffer));
  3115. if (pOldFontInfo)
  3116. {
  3117. ::DeleteObject(pOldFontInfo->hFont);
  3118. delete pOldFontInfo;
  3119. m_SharedResInfo.m_CustomFonts.Remove(idBuffer);
  3120. }
  3121. if (!m_SharedResInfo.m_CustomFonts.Insert(idBuffer, pFontInfo))
  3122. {
  3123. ::DeleteObject(hFont);
  3124. delete pFontInfo;
  3125. return NULL;
  3126. }
  3127. }
  3128. else
  3129. {
  3130. TFontInfo* pOldFontInfo = static_cast<TFontInfo*>(m_ResInfo.m_CustomFonts.Find(idBuffer));
  3131. if (pOldFontInfo)
  3132. {
  3133. ::DeleteObject(pOldFontInfo->hFont);
  3134. delete pOldFontInfo;
  3135. m_ResInfo.m_CustomFonts.Remove(idBuffer);
  3136. }
  3137. if (!m_ResInfo.m_CustomFonts.Insert(idBuffer, pFontInfo))
  3138. {
  3139. ::DeleteObject(hFont);
  3140. delete pFontInfo;
  3141. return NULL;
  3142. }
  3143. }
  3144. return hFont;
  3145. }
  3146. void CPaintManagerUI::AddFontArray(LPCTSTR pstrPath)
  3147. {
  3148. LPBYTE pData = NULL;
  3149. DWORD dwSize = 0;
  3150. do
  3151. {
  3152. CDuiString sFile = CPaintManagerUI::GetResourcePath();
  3153. if (CPaintManagerUI::GetResourceZip().IsEmpty())
  3154. {
  3155. sFile += pstrPath;
  3156. HANDLE hFile = ::CreateFile(sFile.GetData(), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, \
  3157. FILE_ATTRIBUTE_NORMAL, NULL);
  3158. if (hFile == INVALID_HANDLE_VALUE) break;
  3159. dwSize = ::GetFileSize(hFile, NULL);
  3160. if (dwSize == 0) break;
  3161. DWORD dwRead = 0;
  3162. pData = new BYTE[dwSize];
  3163. ::ReadFile(hFile, pData, dwSize, &dwRead, NULL);
  3164. ::CloseHandle(hFile);
  3165. if (dwRead != dwSize)
  3166. {
  3167. delete[] pData;
  3168. pData = NULL;
  3169. break;
  3170. }
  3171. }
  3172. else
  3173. {
  3174. sFile += CPaintManagerUI::GetResourceZip();
  3175. HZIP hz = NULL;
  3176. if (CPaintManagerUI::IsCachedResourceZip()) hz = (HZIP)CPaintManagerUI::GetResourceZipHandle();
  3177. else
  3178. {
  3179. CDuiString sFilePwd = CPaintManagerUI::GetResourceZipPwd();
  3180. #ifdef UNICODE
  3181. char* pwd = w2a((wchar_t*)sFilePwd.GetData());
  3182. hz = OpenZip(sFile.GetData(), pwd);
  3183. if (pwd) delete[] pwd;
  3184. #else
  3185. hz = OpenZip(sFile.GetData(), sFilePwd.GetData());
  3186. #endif
  3187. }
  3188. if (hz == NULL) break;
  3189. ZIPENTRY ze;
  3190. int i = 0;
  3191. CDuiString key = pstrPath;
  3192. key.Replace(_T("\\"), _T("/"));
  3193. if (FindZipItem(hz, key, true, &i, &ze) != 0) break;
  3194. dwSize = ze.unc_size;
  3195. if (dwSize == 0) break;
  3196. pData = new BYTE[dwSize];
  3197. int res = UnzipItem(hz, i, pData, dwSize);
  3198. if (res != 0x00000000 && res != 0x00000600)
  3199. {
  3200. delete[] pData;
  3201. pData = NULL;
  3202. if (!CPaintManagerUI::IsCachedResourceZip()) CloseZip(hz);
  3203. break;
  3204. }
  3205. if (!CPaintManagerUI::IsCachedResourceZip()) CloseZip(hz);
  3206. }
  3207. } while (0);
  3208. while (!pData)
  3209. {
  3210. //读不到图片, 则直接去读取bitmap.m_lpstr指向的路径
  3211. HANDLE hFile = ::CreateFile(pstrPath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
  3212. if (hFile == INVALID_HANDLE_VALUE) break;
  3213. dwSize = ::GetFileSize(hFile, NULL);
  3214. if (dwSize == 0) break;
  3215. DWORD dwRead = 0;
  3216. pData = new BYTE[dwSize];
  3217. ::ReadFile(hFile, pData, dwSize, &dwRead, NULL);
  3218. ::CloseHandle(hFile);
  3219. if (dwRead != dwSize)
  3220. {
  3221. delete[] pData;
  3222. pData = NULL;
  3223. }
  3224. break;
  3225. }
  3226. DWORD nFonts;
  3227. HANDLE hFont = ::AddFontMemResourceEx(pData, dwSize, NULL, &nFonts);
  3228. delete[] pData;
  3229. pData = NULL;
  3230. m_aFonts.Add(hFont);
  3231. }
  3232. HFONT CPaintManagerUI::GetFont(int id)
  3233. {
  3234. if (id < 0) return GetDefaultFontInfo()->hFont;
  3235. TCHAR idBuffer[16];
  3236. ::ZeroMemory(idBuffer, sizeof(idBuffer));
  3237. _itot(id, idBuffer, 10);
  3238. TFontInfo* pFontInfo = static_cast<TFontInfo*>(m_ResInfo.m_CustomFonts.Find(idBuffer));
  3239. if (!pFontInfo) pFontInfo = static_cast<TFontInfo*>(m_SharedResInfo.m_CustomFonts.Find(idBuffer));
  3240. if (!pFontInfo) return GetDefaultFontInfo()->hFont;
  3241. return pFontInfo->hFont;
  3242. }
  3243. HFONT CPaintManagerUI::GetFont(LPCTSTR pStrFontName, int nSize, bool bBold, bool bUnderline, bool bItalic, bool bStrikeout)
  3244. {
  3245. TFontInfo* pFontInfo = NULL;
  3246. for (int i = 0; i < m_ResInfo.m_CustomFonts.GetSize(); i++)
  3247. {
  3248. if (LPCTSTR key = m_ResInfo.m_CustomFonts.GetAt(i))
  3249. {
  3250. pFontInfo = static_cast<TFontInfo*>(m_ResInfo.m_CustomFonts.Find(key));
  3251. if (pFontInfo && pFontInfo->sFontName == pStrFontName && pFontInfo->iSize == nSize &&
  3252. pFontInfo->bBold == bBold && pFontInfo->bUnderline == bUnderline && pFontInfo->bItalic == bItalic
  3253. && pFontInfo->bStrikeout == bStrikeout)
  3254. return pFontInfo->hFont;
  3255. }
  3256. }
  3257. for (int i = 0; i < m_SharedResInfo.m_CustomFonts.GetSize(); i++)
  3258. {
  3259. if (LPCTSTR key = m_SharedResInfo.m_CustomFonts.GetAt(i))
  3260. {
  3261. pFontInfo = static_cast<TFontInfo*>(m_SharedResInfo.m_CustomFonts.Find(key));
  3262. if (pFontInfo && pFontInfo->sFontName == pStrFontName && pFontInfo->iSize == nSize &&
  3263. pFontInfo->bBold == bBold && pFontInfo->bUnderline == bUnderline && pFontInfo->bItalic == bItalic
  3264. && pFontInfo->bStrikeout == bStrikeout)
  3265. return pFontInfo->hFont;
  3266. }
  3267. }
  3268. return NULL;
  3269. }
  3270. int CPaintManagerUI::GetFontIndex(HFONT hFont, bool bShared)
  3271. {
  3272. TFontInfo* pFontInfo = NULL;
  3273. if (bShared)
  3274. {
  3275. for (int i = 0; i < m_SharedResInfo.m_CustomFonts.GetSize(); i++)
  3276. {
  3277. if (LPCTSTR key = m_SharedResInfo.m_CustomFonts.GetAt(i))
  3278. {
  3279. pFontInfo = static_cast<TFontInfo*>(m_SharedResInfo.m_CustomFonts.Find(key));
  3280. if (pFontInfo && pFontInfo->hFont == hFont) return _ttoi(key);
  3281. }
  3282. }
  3283. }
  3284. else
  3285. {
  3286. for (int i = 0; i < m_ResInfo.m_CustomFonts.GetSize(); i++)
  3287. {
  3288. if (LPCTSTR key = m_ResInfo.m_CustomFonts.GetAt(i))
  3289. {
  3290. pFontInfo = static_cast<TFontInfo*>(m_ResInfo.m_CustomFonts.Find(key));
  3291. if (pFontInfo && pFontInfo->hFont == hFont) return _ttoi(key);
  3292. }
  3293. }
  3294. }
  3295. return -1;
  3296. }
  3297. int CPaintManagerUI::GetFontIndex(LPCTSTR pStrFontName, int nSize, bool bBold, bool bUnderline, bool bItalic, bool bStrikeout, bool bShared)
  3298. {
  3299. TFontInfo* pFontInfo = NULL;
  3300. if (bShared)
  3301. {
  3302. for (int i = 0; i < m_SharedResInfo.m_CustomFonts.GetSize(); i++)
  3303. {
  3304. if (LPCTSTR key = m_SharedResInfo.m_CustomFonts.GetAt(i))
  3305. {
  3306. pFontInfo = static_cast<TFontInfo*>(m_SharedResInfo.m_CustomFonts.Find(key));
  3307. if (pFontInfo && pFontInfo->sFontName == pStrFontName && pFontInfo->iSize == nSize &&
  3308. pFontInfo->bBold == bBold && pFontInfo->bUnderline == bUnderline && pFontInfo->bItalic == bItalic
  3309. && pFontInfo->bStrikeout == bStrikeout)
  3310. return _ttoi(key);
  3311. }
  3312. }
  3313. }
  3314. else
  3315. {
  3316. for (int i = 0; i < m_ResInfo.m_CustomFonts.GetSize(); i++)
  3317. {
  3318. if (LPCTSTR key = m_ResInfo.m_CustomFonts.GetAt(i))
  3319. {
  3320. pFontInfo = static_cast<TFontInfo*>(m_ResInfo.m_CustomFonts.Find(key));
  3321. if (pFontInfo && pFontInfo->sFontName == pStrFontName && pFontInfo->iSize == nSize &&
  3322. pFontInfo->bBold == bBold && pFontInfo->bUnderline == bUnderline && pFontInfo->bItalic == bItalic
  3323. && pFontInfo->bStrikeout == bStrikeout)
  3324. return _ttoi(key);
  3325. }
  3326. }
  3327. }
  3328. return -1;
  3329. }
  3330. void CPaintManagerUI::RemoveFont(HFONT hFont, bool bShared)
  3331. {
  3332. TFontInfo* pFontInfo = NULL;
  3333. if (bShared)
  3334. {
  3335. for (int i = 0; i < m_SharedResInfo.m_CustomFonts.GetSize(); i++)
  3336. {
  3337. if (LPCTSTR key = m_SharedResInfo.m_CustomFonts.GetAt(i))
  3338. {
  3339. pFontInfo = static_cast<TFontInfo*>(m_SharedResInfo.m_CustomFonts.Find(key));
  3340. if (pFontInfo && pFontInfo->hFont == hFont)
  3341. {
  3342. ::DeleteObject(pFontInfo->hFont);
  3343. delete pFontInfo;
  3344. m_SharedResInfo.m_CustomFonts.Remove(key);
  3345. return;
  3346. }
  3347. }
  3348. }
  3349. }
  3350. else
  3351. {
  3352. for (int i = 0; i < m_ResInfo.m_CustomFonts.GetSize(); i++)
  3353. {
  3354. if (LPCTSTR key = m_ResInfo.m_CustomFonts.GetAt(i))
  3355. {
  3356. pFontInfo = static_cast<TFontInfo*>(m_ResInfo.m_CustomFonts.Find(key));
  3357. if (pFontInfo && pFontInfo->hFont == hFont)
  3358. {
  3359. ::DeleteObject(pFontInfo->hFont);
  3360. delete pFontInfo;
  3361. m_ResInfo.m_CustomFonts.Remove(key);
  3362. return;
  3363. }
  3364. }
  3365. }
  3366. }
  3367. }
  3368. void CPaintManagerUI::RemoveFont(int id, bool bShared)
  3369. {
  3370. TCHAR idBuffer[16];
  3371. ::ZeroMemory(idBuffer, sizeof(idBuffer));
  3372. _itot(id, idBuffer, 10);
  3373. TFontInfo* pFontInfo = NULL;
  3374. if (bShared)
  3375. {
  3376. pFontInfo = static_cast<TFontInfo*>(m_SharedResInfo.m_CustomFonts.Find(idBuffer));
  3377. if (pFontInfo)
  3378. {
  3379. ::DeleteObject(pFontInfo->hFont);
  3380. delete pFontInfo;
  3381. m_SharedResInfo.m_CustomFonts.Remove(idBuffer);
  3382. }
  3383. }
  3384. else
  3385. {
  3386. pFontInfo = static_cast<TFontInfo*>(m_ResInfo.m_CustomFonts.Find(idBuffer));
  3387. if (pFontInfo)
  3388. {
  3389. ::DeleteObject(pFontInfo->hFont);
  3390. delete pFontInfo;
  3391. m_ResInfo.m_CustomFonts.Remove(idBuffer);
  3392. }
  3393. }
  3394. }
  3395. void CPaintManagerUI::RemoveAllFonts(bool bShared)
  3396. {
  3397. TFontInfo* pFontInfo;
  3398. if (bShared)
  3399. {
  3400. for (int i = 0; i < m_SharedResInfo.m_CustomFonts.GetSize(); i++)
  3401. {
  3402. if (LPCTSTR key = m_SharedResInfo.m_CustomFonts.GetAt(i))
  3403. {
  3404. pFontInfo = static_cast<TFontInfo*>(m_SharedResInfo.m_CustomFonts.Find(key, false));
  3405. if (pFontInfo)
  3406. {
  3407. ::DeleteObject(pFontInfo->hFont);
  3408. delete pFontInfo;
  3409. }
  3410. }
  3411. }
  3412. m_SharedResInfo.m_CustomFonts.RemoveAll();
  3413. }
  3414. else
  3415. {
  3416. for (int i = 0; i < m_ResInfo.m_CustomFonts.GetSize(); i++)
  3417. {
  3418. if (LPCTSTR key = m_ResInfo.m_CustomFonts.GetAt(i))
  3419. {
  3420. pFontInfo = static_cast<TFontInfo*>(m_ResInfo.m_CustomFonts.Find(key, false));
  3421. if (pFontInfo)
  3422. {
  3423. ::DeleteObject(pFontInfo->hFont);
  3424. delete pFontInfo;
  3425. }
  3426. }
  3427. }
  3428. m_ResInfo.m_CustomFonts.RemoveAll();
  3429. }
  3430. }
  3431. TFontInfo* CPaintManagerUI::GetFontInfo(int id)
  3432. {
  3433. if (id < 0) return GetDefaultFontInfo();
  3434. TCHAR idBuffer[16];
  3435. ::ZeroMemory(idBuffer, sizeof(idBuffer));
  3436. _itot(id, idBuffer, 10);
  3437. TFontInfo* pFontInfo = static_cast<TFontInfo*>(m_ResInfo.m_CustomFonts.Find(idBuffer));
  3438. if (!pFontInfo) pFontInfo = static_cast<TFontInfo*>(m_SharedResInfo.m_CustomFonts.Find(idBuffer));
  3439. if (!pFontInfo) pFontInfo = GetDefaultFontInfo();
  3440. if (pFontInfo->tm.tmHeight == 0)
  3441. {
  3442. HFONT hOldFont = (HFONT) ::SelectObject(m_hDcPaint, pFontInfo->hFont);
  3443. ::GetTextMetrics(m_hDcPaint, &pFontInfo->tm);
  3444. ::SelectObject(m_hDcPaint, hOldFont);
  3445. }
  3446. return pFontInfo;
  3447. }
  3448. TFontInfo* CPaintManagerUI::GetFontInfo(HFONT hFont)
  3449. {
  3450. TFontInfo* pFontInfo = NULL;
  3451. for (int i = 0; i < m_ResInfo.m_CustomFonts.GetSize(); i++)
  3452. {
  3453. if (LPCTSTR key = m_ResInfo.m_CustomFonts.GetAt(i))
  3454. {
  3455. pFontInfo = static_cast<TFontInfo*>(m_ResInfo.m_CustomFonts.Find(key));
  3456. if (pFontInfo && pFontInfo->hFont == hFont) break;
  3457. }
  3458. }
  3459. if (!pFontInfo)
  3460. {
  3461. for (int i = 0; i < m_SharedResInfo.m_CustomFonts.GetSize(); i++)
  3462. {
  3463. if (LPCTSTR key = m_SharedResInfo.m_CustomFonts.GetAt(i))
  3464. {
  3465. pFontInfo = static_cast<TFontInfo*>(m_SharedResInfo.m_CustomFonts.Find(key));
  3466. if (pFontInfo && pFontInfo->hFont == hFont) break;
  3467. }
  3468. }
  3469. }
  3470. if (!pFontInfo) pFontInfo = GetDefaultFontInfo();
  3471. if (pFontInfo->tm.tmHeight == 0)
  3472. {
  3473. HFONT hOldFont = (HFONT) ::SelectObject(m_hDcPaint, pFontInfo->hFont);
  3474. ::GetTextMetrics(m_hDcPaint, &pFontInfo->tm);
  3475. ::SelectObject(m_hDcPaint, hOldFont);
  3476. }
  3477. return pFontInfo;
  3478. }
  3479. const TImageInfo* CPaintManagerUI::GetImage(LPCTSTR bitmap)
  3480. {
  3481. TImageInfo* data = static_cast<TImageInfo*>(m_ResInfo.m_ImageHash.Find(bitmap));
  3482. if (!data) data = static_cast<TImageInfo*>(m_SharedResInfo.m_ImageHash.Find(bitmap));
  3483. return data;
  3484. }
  3485. const TImageInfo* CPaintManagerUI::GetImageEx(LPCTSTR bitmap, LPCTSTR type, DWORD mask, bool bUseHSL, bool bGdiplus, HINSTANCE instance)
  3486. {
  3487. const TImageInfo* data = GetImage(bitmap);
  3488. if (!data)
  3489. {
  3490. if (AddImage(bitmap, type, mask, bUseHSL, bGdiplus, false, instance))
  3491. {
  3492. if (m_bForceUseSharedRes) data = static_cast<TImageInfo*>(m_SharedResInfo.m_ImageHash.Find(bitmap));
  3493. else data = static_cast<TImageInfo*>(m_ResInfo.m_ImageHash.Find(bitmap));
  3494. }
  3495. }
  3496. return data;
  3497. }
  3498. const TImageInfo* CPaintManagerUI::AddImage(LPCTSTR bitmap, LPCTSTR type, DWORD mask, bool bUseHSL, bool bGdiplus, bool bShared, HINSTANCE instance)
  3499. {
  3500. if (bitmap == NULL || bitmap[0] == _T('\0')) return NULL;
  3501. TImageInfo* data = NULL;
  3502. if (type != NULL && lstrlen(type) > 0)
  3503. {
  3504. if (isdigit(*bitmap))
  3505. {
  3506. LPTSTR pstr = NULL;
  3507. int iIndex = _tcstol(bitmap, &pstr, 10);
  3508. data = bGdiplus ? CRenderEngine::GdiplusLoadImage(iIndex, type, mask, instance) : CRenderEngine::LoadImage(iIndex, type, mask, instance);
  3509. }
  3510. }
  3511. else
  3512. {
  3513. data = bGdiplus ? CRenderEngine::GdiplusLoadImage(bitmap, NULL, mask, instance) : CRenderEngine::LoadImage(bitmap, NULL, mask, instance);
  3514. if (!data)
  3515. {
  3516. CDuiString sImageName = bitmap;
  3517. int iAtIdx = sImageName.ReverseFind(_T('@'));
  3518. int iDotIdx = sImageName.ReverseFind(_T('.'));
  3519. if (iAtIdx != -1 && iDotIdx != -1)
  3520. {
  3521. CDuiString sExe = sImageName.Mid(iDotIdx);
  3522. sImageName = sImageName.Left(iAtIdx) + sExe;
  3523. data = bGdiplus ? CRenderEngine::GdiplusLoadImage(sImageName.GetData(), NULL, mask, instance) : CRenderEngine::LoadImage(sImageName.GetData(), NULL, mask, instance);
  3524. }
  3525. }
  3526. }
  3527. if (data == NULL)
  3528. {
  3529. return NULL;
  3530. }
  3531. data->bUseHSL = bUseHSL;
  3532. if (type != NULL) data->sResType = type;
  3533. data->dwMask = mask;
  3534. if (data->bUseHSL)
  3535. {
  3536. data->pSrcBits = new BYTE[data->nX * data->nY * 4];
  3537. ::CopyMemory(data->pSrcBits, data->pBits, data->nX * data->nY * 4);
  3538. }
  3539. else data->pSrcBits = NULL;
  3540. if (m_bUseHSL) CRenderEngine::AdjustImage(true, data, m_H, m_S, m_L);
  3541. if (data)
  3542. {
  3543. if (bShared || m_bForceUseSharedRes)
  3544. {
  3545. TImageInfo* pOldImageInfo = static_cast<TImageInfo*>(m_SharedResInfo.m_ImageHash.Find(bitmap));
  3546. if (pOldImageInfo)
  3547. {
  3548. CRenderEngine::FreeImage(pOldImageInfo);
  3549. m_SharedResInfo.m_ImageHash.Remove(bitmap);
  3550. }
  3551. if (!m_SharedResInfo.m_ImageHash.Insert(bitmap, data))
  3552. {
  3553. CRenderEngine::FreeImage(data);
  3554. data = NULL;
  3555. }
  3556. }
  3557. else
  3558. {
  3559. TImageInfo* pOldImageInfo = static_cast<TImageInfo*>(m_ResInfo.m_ImageHash.Find(bitmap));
  3560. if (pOldImageInfo)
  3561. {
  3562. CRenderEngine::FreeImage(pOldImageInfo);
  3563. m_ResInfo.m_ImageHash.Remove(bitmap);
  3564. }
  3565. if (!m_ResInfo.m_ImageHash.Insert(bitmap, data))
  3566. {
  3567. CRenderEngine::FreeImage(data);
  3568. data = NULL;
  3569. }
  3570. }
  3571. }
  3572. return data;
  3573. }
  3574. const TImageInfo* CPaintManagerUI::AddImage(LPCTSTR bitmap, HBITMAP hBitmap, int iWidth, int iHeight, bool bAlpha, bool bShared)
  3575. {
  3576. // 因无法确定外部HBITMAP格式,不能使用hsl调整
  3577. if (bitmap == NULL || bitmap[0] == _T('\0')) return NULL;
  3578. if (hBitmap == NULL || iWidth <= 0 || iHeight <= 0) return NULL;
  3579. TImageInfo* data = new TImageInfo;
  3580. data->pBits = NULL;
  3581. data->pSrcBits = NULL;
  3582. data->hBitmap = hBitmap;
  3583. data->pBits = NULL;
  3584. data->nX = iWidth;
  3585. data->nY = iHeight;
  3586. data->bAlpha = bAlpha;
  3587. data->bUseHSL = false;
  3588. data->pSrcBits = NULL;
  3589. data->dwMask = 0;
  3590. if (bShared || m_bForceUseSharedRes)
  3591. {
  3592. if (!m_SharedResInfo.m_ImageHash.Insert(bitmap, data))
  3593. {
  3594. CRenderEngine::FreeImage(data);
  3595. data = NULL;
  3596. }
  3597. }
  3598. else
  3599. {
  3600. if (!m_ResInfo.m_ImageHash.Insert(bitmap, data))
  3601. {
  3602. CRenderEngine::FreeImage(data);
  3603. data = NULL;
  3604. }
  3605. }
  3606. return data;
  3607. }
  3608. void CPaintManagerUI::RemoveImage(LPCTSTR bitmap, bool bShared)
  3609. {
  3610. TImageInfo* data = NULL;
  3611. if (bShared)
  3612. {
  3613. data = static_cast<TImageInfo*>(m_SharedResInfo.m_ImageHash.Find(bitmap));
  3614. if (data)
  3615. {
  3616. CRenderEngine::FreeImage(data);
  3617. m_SharedResInfo.m_ImageHash.Remove(bitmap);
  3618. }
  3619. }
  3620. else
  3621. {
  3622. data = static_cast<TImageInfo*>(m_ResInfo.m_ImageHash.Find(bitmap));
  3623. if (data)
  3624. {
  3625. CRenderEngine::FreeImage(data);
  3626. m_ResInfo.m_ImageHash.Remove(bitmap);
  3627. }
  3628. }
  3629. }
  3630. void CPaintManagerUI::RemoveAllImages(bool bShared)
  3631. {
  3632. if (bShared)
  3633. {
  3634. TImageInfo* data;
  3635. for (int i = 0; i < m_SharedResInfo.m_ImageHash.GetSize(); i++)
  3636. {
  3637. if (LPCTSTR key = m_SharedResInfo.m_ImageHash.GetAt(i))
  3638. {
  3639. data = static_cast<TImageInfo*>(m_SharedResInfo.m_ImageHash.Find(key, false));
  3640. if (data)
  3641. {
  3642. CRenderEngine::FreeImage(data);
  3643. }
  3644. }
  3645. }
  3646. m_SharedResInfo.m_ImageHash.RemoveAll();
  3647. }
  3648. else
  3649. {
  3650. TImageInfo* data;
  3651. for (int i = 0; i < m_ResInfo.m_ImageHash.GetSize(); i++)
  3652. {
  3653. if (LPCTSTR key = m_ResInfo.m_ImageHash.GetAt(i))
  3654. {
  3655. data = static_cast<TImageInfo*>(m_ResInfo.m_ImageHash.Find(key, false));
  3656. if (data)
  3657. {
  3658. CRenderEngine::FreeImage(data);
  3659. }
  3660. }
  3661. }
  3662. m_ResInfo.m_ImageHash.RemoveAll();
  3663. }
  3664. }
  3665. void CPaintManagerUI::AdjustSharedImagesHSL()
  3666. {
  3667. TImageInfo* data;
  3668. for (int i = 0; i < m_SharedResInfo.m_ImageHash.GetSize(); i++)
  3669. {
  3670. if (LPCTSTR key = m_SharedResInfo.m_ImageHash.GetAt(i))
  3671. {
  3672. data = static_cast<TImageInfo*>(m_SharedResInfo.m_ImageHash.Find(key));
  3673. if (data && data->bUseHSL)
  3674. {
  3675. CRenderEngine::AdjustImage(m_bUseHSL, data, m_H, m_S, m_L);
  3676. }
  3677. }
  3678. }
  3679. }
  3680. void CPaintManagerUI::AdjustImagesHSL()
  3681. {
  3682. TImageInfo* data;
  3683. for (int i = 0; i < m_ResInfo.m_ImageHash.GetSize(); i++)
  3684. {
  3685. if (LPCTSTR key = m_ResInfo.m_ImageHash.GetAt(i))
  3686. {
  3687. data = static_cast<TImageInfo*>(m_ResInfo.m_ImageHash.Find(key));
  3688. if (data && data->bUseHSL)
  3689. {
  3690. CRenderEngine::AdjustImage(m_bUseHSL, data, m_H, m_S, m_L);
  3691. }
  3692. }
  3693. }
  3694. Invalidate();
  3695. }
  3696. void CPaintManagerUI::PostAsyncNotify()
  3697. {
  3698. if (!m_bAsyncNotifyPosted)
  3699. {
  3700. ::PostMessage(m_hWndPaint, WM_APP + 1, 0, 0L);
  3701. m_bAsyncNotifyPosted = true;
  3702. }
  3703. }
  3704. void CPaintManagerUI::ReloadSharedImages()
  3705. {
  3706. TImageInfo* data = NULL;
  3707. TImageInfo* pNewData = NULL;
  3708. for (int i = 0; i < m_SharedResInfo.m_ImageHash.GetSize(); i++)
  3709. {
  3710. if (LPCTSTR bitmap = m_SharedResInfo.m_ImageHash.GetAt(i))
  3711. {
  3712. data = static_cast<TImageInfo*>(m_SharedResInfo.m_ImageHash.Find(bitmap));
  3713. if (data != NULL)
  3714. {
  3715. if (!data->sResType.IsEmpty())
  3716. {
  3717. if (isdigit(*bitmap))
  3718. {
  3719. LPTSTR pstr = NULL;
  3720. int iIndex = _tcstol(bitmap, &pstr, 10);
  3721. pNewData = CRenderEngine::LoadImage(iIndex, data->sResType.GetData(), data->dwMask);
  3722. }
  3723. }
  3724. else
  3725. {
  3726. pNewData = CRenderEngine::LoadImage(bitmap, NULL, data->dwMask);
  3727. }
  3728. if (pNewData == NULL) continue;
  3729. CRenderEngine::FreeImage(data, false);
  3730. data->hBitmap = pNewData->hBitmap;
  3731. data->pImage = pNewData->pImage;
  3732. data->pBits = pNewData->pBits;
  3733. data->nX = pNewData->nX;
  3734. data->nY = pNewData->nY;
  3735. data->bAlpha = pNewData->bAlpha;
  3736. data->pSrcBits = NULL;
  3737. if (data->bUseHSL)
  3738. {
  3739. data->pSrcBits = new BYTE[data->nX * data->nY * 4];
  3740. ::CopyMemory(data->pSrcBits, data->pBits, data->nX * data->nY * 4);
  3741. }
  3742. else data->pSrcBits = NULL;
  3743. if (m_bUseHSL) CRenderEngine::AdjustImage(true, data, m_H, m_S, m_L);
  3744. delete pNewData;
  3745. }
  3746. }
  3747. }
  3748. }
  3749. void CPaintManagerUI::ReloadImages()
  3750. {
  3751. RemoveAllDrawInfos();
  3752. TImageInfo* data = NULL;
  3753. TImageInfo* pNewData = NULL;
  3754. for (int i = 0; i < m_ResInfo.m_ImageHash.GetSize(); i++)
  3755. {
  3756. if (LPCTSTR bitmap = m_ResInfo.m_ImageHash.GetAt(i))
  3757. {
  3758. data = static_cast<TImageInfo*>(m_ResInfo.m_ImageHash.Find(bitmap));
  3759. if (data != NULL)
  3760. {
  3761. if (!data->sResType.IsEmpty())
  3762. {
  3763. if (isdigit(*bitmap))
  3764. {
  3765. LPTSTR pstr = NULL;
  3766. int iIndex = _tcstol(bitmap, &pstr, 10);
  3767. pNewData = CRenderEngine::LoadImage(iIndex, data->sResType.GetData(), data->dwMask);
  3768. }
  3769. }
  3770. else
  3771. {
  3772. pNewData = CRenderEngine::LoadImage(bitmap, NULL, data->dwMask);
  3773. }
  3774. CRenderEngine::FreeImage(data, false);
  3775. if (pNewData == NULL)
  3776. {
  3777. m_ResInfo.m_ImageHash.Remove(bitmap);
  3778. continue;
  3779. }
  3780. data->hBitmap = pNewData->hBitmap;
  3781. data->pBits = pNewData->pBits;
  3782. data->nX = pNewData->nX;
  3783. data->nY = pNewData->nY;
  3784. data->bAlpha = pNewData->bAlpha;
  3785. data->pSrcBits = NULL;
  3786. if (data->bUseHSL)
  3787. {
  3788. data->pSrcBits = new BYTE[data->nX * data->nY * 4];
  3789. ::CopyMemory(data->pSrcBits, data->pBits, data->nX * data->nY * 4);
  3790. }
  3791. else data->pSrcBits = NULL;
  3792. if (m_bUseHSL) CRenderEngine::AdjustImage(true, data, m_H, m_S, m_L);
  3793. delete pNewData;
  3794. }
  3795. }
  3796. }
  3797. if (m_pRoot) m_pRoot->Invalidate();
  3798. }
  3799. const TDrawInfo* CPaintManagerUI::GetDrawInfo(LPCTSTR pStrImage, LPCTSTR pStrModify)
  3800. {
  3801. CDuiString sKey;
  3802. sKey.Format(_T("%s%s"), pStrImage == NULL ? _T("") : pStrImage, pStrModify == NULL ? _T("") : pStrModify);
  3803. TDrawInfo* pDrawInfo = static_cast<TDrawInfo*>(m_ResInfo.m_DrawInfoHash.Find(sKey));
  3804. if (pDrawInfo == NULL && !sKey.IsEmpty())
  3805. {
  3806. pDrawInfo = new TDrawInfo();
  3807. pDrawInfo->Parse(pStrImage, pStrModify, this);
  3808. m_ResInfo.m_DrawInfoHash.Insert(sKey, pDrawInfo);
  3809. }
  3810. return pDrawInfo;
  3811. }
  3812. void CPaintManagerUI::RemoveDrawInfo(LPCTSTR pStrImage, LPCTSTR pStrModify)
  3813. {
  3814. CDuiString sKey;
  3815. sKey.Format(_T("%s%s"), pStrImage == NULL ? _T("") : pStrImage, pStrModify == NULL ? _T("") : pStrModify);
  3816. TDrawInfo* pDrawInfo = static_cast<TDrawInfo*>(m_ResInfo.m_DrawInfoHash.Find(sKey));
  3817. if (pDrawInfo != NULL)
  3818. {
  3819. m_ResInfo.m_DrawInfoHash.Remove(sKey);
  3820. delete pDrawInfo;
  3821. pDrawInfo = NULL;
  3822. }
  3823. }
  3824. void CPaintManagerUI::RemoveAllDrawInfos()
  3825. {
  3826. TDrawInfo* pDrawInfo = NULL;
  3827. for (int i = 0; i < m_ResInfo.m_DrawInfoHash.GetSize(); i++)
  3828. {
  3829. LPCTSTR key = m_ResInfo.m_DrawInfoHash.GetAt(i);
  3830. if (key != NULL)
  3831. {
  3832. pDrawInfo = static_cast<TDrawInfo*>(m_ResInfo.m_DrawInfoHash.Find(key, false));
  3833. if (pDrawInfo)
  3834. {
  3835. delete pDrawInfo;
  3836. pDrawInfo = NULL;
  3837. }
  3838. }
  3839. }
  3840. m_ResInfo.m_DrawInfoHash.RemoveAll();
  3841. }
  3842. void CPaintManagerUI::AddDefaultAttributeList(LPCTSTR pStrControlName, LPCTSTR pStrControlAttrList, bool bShared)
  3843. {
  3844. if (bShared || m_bForceUseSharedRes)
  3845. {
  3846. CDuiString* pDefaultAttr = new CDuiString(pStrControlAttrList);
  3847. if (pDefaultAttr != NULL)
  3848. {
  3849. CDuiString* pOldDefaultAttr = static_cast<CDuiString*>(m_SharedResInfo.m_AttrHash.Set(pStrControlName, (LPVOID)pDefaultAttr));
  3850. if (pOldDefaultAttr) delete pOldDefaultAttr;
  3851. }
  3852. }
  3853. else
  3854. {
  3855. CDuiString* pDefaultAttr = new CDuiString(pStrControlAttrList);
  3856. if (pDefaultAttr != NULL)
  3857. {
  3858. CDuiString* pOldDefaultAttr = static_cast<CDuiString*>(m_ResInfo.m_AttrHash.Set(pStrControlName, (LPVOID)pDefaultAttr));
  3859. if (pOldDefaultAttr) delete pOldDefaultAttr;
  3860. }
  3861. }
  3862. }
  3863. LPCTSTR CPaintManagerUI::GetDefaultAttributeList(LPCTSTR pStrControlName) const
  3864. {
  3865. CDuiString* pDefaultAttr = static_cast<CDuiString*>(m_ResInfo.m_AttrHash.Find(pStrControlName));
  3866. if (!pDefaultAttr) pDefaultAttr = static_cast<CDuiString*>(m_SharedResInfo.m_AttrHash.Find(pStrControlName));
  3867. if (pDefaultAttr) return pDefaultAttr->GetData();
  3868. return NULL;
  3869. }
  3870. bool CPaintManagerUI::RemoveDefaultAttributeList(LPCTSTR pStrControlName, bool bShared)
  3871. {
  3872. if (bShared)
  3873. {
  3874. CDuiString* pDefaultAttr = static_cast<CDuiString*>(m_SharedResInfo.m_AttrHash.Find(pStrControlName));
  3875. if (!pDefaultAttr) return false;
  3876. delete pDefaultAttr;
  3877. return m_SharedResInfo.m_AttrHash.Remove(pStrControlName);
  3878. }
  3879. else
  3880. {
  3881. CDuiString* pDefaultAttr = static_cast<CDuiString*>(m_ResInfo.m_AttrHash.Find(pStrControlName));
  3882. if (!pDefaultAttr) return false;
  3883. delete pDefaultAttr;
  3884. return m_ResInfo.m_AttrHash.Remove(pStrControlName);
  3885. }
  3886. }
  3887. void CPaintManagerUI::RemoveAllDefaultAttributeList(bool bShared)
  3888. {
  3889. if (bShared)
  3890. {
  3891. CDuiString* pDefaultAttr;
  3892. for (int i = 0; i < m_SharedResInfo.m_AttrHash.GetSize(); i++)
  3893. {
  3894. if (LPCTSTR key = m_SharedResInfo.m_AttrHash.GetAt(i))
  3895. {
  3896. pDefaultAttr = static_cast<CDuiString*>(m_SharedResInfo.m_AttrHash.Find(key));
  3897. if (pDefaultAttr) delete pDefaultAttr;
  3898. }
  3899. }
  3900. m_SharedResInfo.m_AttrHash.RemoveAll();
  3901. }
  3902. else
  3903. {
  3904. CDuiString* pDefaultAttr;
  3905. for (int i = 0; i < m_ResInfo.m_AttrHash.GetSize(); i++)
  3906. {
  3907. if (LPCTSTR key = m_ResInfo.m_AttrHash.GetAt(i))
  3908. {
  3909. pDefaultAttr = static_cast<CDuiString*>(m_ResInfo.m_AttrHash.Find(key));
  3910. if (pDefaultAttr) delete pDefaultAttr;
  3911. }
  3912. }
  3913. m_ResInfo.m_AttrHash.RemoveAll();
  3914. }
  3915. }
  3916. void CPaintManagerUI::AddWindowCustomAttribute(LPCTSTR pstrName, LPCTSTR pstrAttr)
  3917. {
  3918. if (pstrName == NULL || pstrName[0] == _T('\0') || pstrAttr == NULL || pstrAttr[0] == _T('\0')) return;
  3919. CDuiString* pCostomAttr = new CDuiString(pstrAttr);
  3920. if (pCostomAttr != NULL)
  3921. {
  3922. if (m_mWindowCustomAttrHash.Find(pstrName) == NULL)
  3923. m_mWindowCustomAttrHash.Set(pstrName, (LPVOID)pCostomAttr);
  3924. else
  3925. delete pCostomAttr;
  3926. }
  3927. }
  3928. LPCTSTR CPaintManagerUI::GetWindowCustomAttribute(LPCTSTR pstrName) const
  3929. {
  3930. if (pstrName == NULL || pstrName[0] == _T('\0')) return NULL;
  3931. CDuiString* pCostomAttr = static_cast<CDuiString*>(m_mWindowCustomAttrHash.Find(pstrName));
  3932. if (pCostomAttr) return pCostomAttr->GetData();
  3933. return NULL;
  3934. }
  3935. bool CPaintManagerUI::RemoveWindowCustomAttribute(LPCTSTR pstrName)
  3936. {
  3937. if (pstrName == NULL || pstrName[0] == _T('\0')) return NULL;
  3938. CDuiString* pCostomAttr = static_cast<CDuiString*>(m_mWindowCustomAttrHash.Find(pstrName));
  3939. if (!pCostomAttr) return false;
  3940. delete pCostomAttr;
  3941. return m_mWindowCustomAttrHash.Remove(pstrName);
  3942. }
  3943. void CPaintManagerUI::RemoveAllWindowCustomAttribute()
  3944. {
  3945. CDuiString* pCostomAttr;
  3946. for (int i = 0; i < m_mWindowCustomAttrHash.GetSize(); i++)
  3947. {
  3948. if (LPCTSTR key = m_mWindowCustomAttrHash.GetAt(i))
  3949. {
  3950. pCostomAttr = static_cast<CDuiString*>(m_mWindowCustomAttrHash.Find(key));
  3951. delete pCostomAttr;
  3952. }
  3953. }
  3954. m_mWindowCustomAttrHash.Resize();
  3955. }
  3956. CControlUI* CPaintManagerUI::GetRoot() const
  3957. {
  3958. ASSERT(m_pRoot);
  3959. return m_pRoot;
  3960. }
  3961. CControlUI* CPaintManagerUI::FindControl(POINT pt) const
  3962. {
  3963. ASSERT(m_pRoot);
  3964. return m_pRoot->FindControl(__FindControlFromPoint, &pt, UIFIND_VISIBLE | UIFIND_HITTEST | UIFIND_TOP_FIRST);
  3965. }
  3966. CControlUI* CPaintManagerUI::FindControl(LPCTSTR pstrName) const
  3967. {
  3968. ASSERT(m_pRoot);
  3969. return static_cast<CControlUI*>(m_mNameHash.Find(pstrName));
  3970. }
  3971. CControlUI* CPaintManagerUI::FindSubControlByPoint(CControlUI* pParent, POINT pt) const
  3972. {
  3973. if (pParent == NULL) pParent = GetRoot();
  3974. ASSERT(pParent);
  3975. return pParent->FindControl(__FindControlFromPoint, &pt, UIFIND_VISIBLE | UIFIND_HITTEST | UIFIND_TOP_FIRST);
  3976. }
  3977. CControlUI* CPaintManagerUI::FindSubControlByName(CControlUI* pParent, LPCTSTR pstrName) const
  3978. {
  3979. if (pParent == NULL) pParent = GetRoot();
  3980. ASSERT(pParent);
  3981. return pParent->FindControl(__FindControlFromName, (LPVOID)pstrName, UIFIND_ALL);
  3982. }
  3983. CControlUI* CPaintManagerUI::FindSubControlByClass(CControlUI* pParent, LPCTSTR pstrClass, int iIndex)
  3984. {
  3985. if (pParent == NULL) pParent = GetRoot();
  3986. ASSERT(pParent);
  3987. m_aFoundControls.Resize(iIndex + 1);
  3988. return pParent->FindControl(__FindControlFromClass, (LPVOID)pstrClass, UIFIND_ALL);
  3989. }
  3990. CStdPtrArray* CPaintManagerUI::FindSubControlsByClass(CControlUI* pParent, LPCTSTR pstrClass)
  3991. {
  3992. if (pParent == NULL) pParent = GetRoot();
  3993. ASSERT(pParent);
  3994. m_aFoundControls.Empty();
  3995. pParent->FindControl(__FindControlsFromClass, (LPVOID)pstrClass, UIFIND_ALL);
  3996. return &m_aFoundControls;
  3997. }
  3998. CStdPtrArray* CPaintManagerUI::GetFoundControls()
  3999. {
  4000. return &m_aFoundControls;
  4001. }
  4002. CControlUI* CALLBACK CPaintManagerUI::__FindControlFromNameHash(CControlUI* pThis, LPVOID pData)
  4003. {
  4004. CPaintManagerUI* pManager = static_cast<CPaintManagerUI*>(pData);
  4005. const CDuiString& sName = pThis->GetName();
  4006. if (sName.IsEmpty()) return NULL;
  4007. // Add this control to the hash list
  4008. pManager->m_mNameHash.Set(sName, pThis);
  4009. return NULL; // Attempt to add all controls
  4010. }
  4011. CControlUI* CALLBACK CPaintManagerUI::__FindControlFromCount(CControlUI* /*pThis*/, LPVOID pData)
  4012. {
  4013. int* pnCount = static_cast<int*>(pData);
  4014. (*pnCount)++;
  4015. return NULL; // Count all controls
  4016. }
  4017. CControlUI* CALLBACK CPaintManagerUI::__FindControlFromPoint(CControlUI* pThis, LPVOID pData)
  4018. {
  4019. LPPOINT pPoint = static_cast<LPPOINT>(pData);
  4020. return ::PtInRect(&pThis->GetPos(), *pPoint) ? pThis : NULL;
  4021. }
  4022. CControlUI* CALLBACK CPaintManagerUI::__FindControlFromTab(CControlUI* pThis, LPVOID pData)
  4023. {
  4024. FINDTABINFO* pInfo = static_cast<FINDTABINFO*>(pData);
  4025. if (pInfo->pFocus == pThis)
  4026. {
  4027. if (pInfo->bForward) pInfo->bNextIsIt = true;
  4028. return pInfo->bForward ? NULL : pInfo->pLast;
  4029. }
  4030. if ((pThis->GetControlFlags() & UIFLAG_TABSTOP) == 0) return NULL;
  4031. pInfo->pLast = pThis;
  4032. if (pInfo->bNextIsIt) return pThis;
  4033. if (pInfo->pFocus == NULL) return pThis;
  4034. return NULL; // Examine all controls
  4035. }
  4036. CControlUI* CALLBACK CPaintManagerUI::__FindControlFromShortcut(CControlUI* pThis, LPVOID pData)
  4037. {
  4038. if (!pThis->IsVisible()) return NULL;
  4039. FINDSHORTCUT* pFS = static_cast<FINDSHORTCUT*>(pData);
  4040. if (pFS->ch == toupper(pThis->GetShortcut())) pFS->bPickNext = true;
  4041. if (_tcsstr(pThis->GetClass(), _T("LabelUI")) != NULL) return NULL; // Labels never get focus!
  4042. return pFS->bPickNext ? pThis : NULL;
  4043. }
  4044. CControlUI* CALLBACK CPaintManagerUI::__FindControlFromName(CControlUI* pThis, LPVOID pData)
  4045. {
  4046. LPCTSTR pstrName = static_cast<LPCTSTR>(pData);
  4047. const CDuiString& sName = pThis->GetName();
  4048. if (sName.IsEmpty()) return NULL;
  4049. return (_tcsicmp(sName, pstrName) == 0) ? pThis : NULL;
  4050. }
  4051. CControlUI* CALLBACK CPaintManagerUI::__FindControlFromClass(CControlUI* pThis, LPVOID pData)
  4052. {
  4053. LPCTSTR pstrType = static_cast<LPCTSTR>(pData);
  4054. LPCTSTR pType = pThis->GetClass();
  4055. CStdPtrArray* pFoundControls = pThis->GetManager()->GetFoundControls();
  4056. if (_tcscmp(pstrType, _T("*")) == 0 || _tcscmp(pstrType, pType) == 0)
  4057. {
  4058. int iIndex = -1;
  4059. while (pFoundControls->GetAt(++iIndex) != NULL);
  4060. if (iIndex < pFoundControls->GetSize()) pFoundControls->SetAt(iIndex, pThis);
  4061. }
  4062. if (pFoundControls->GetAt(pFoundControls->GetSize() - 1) != NULL) return pThis;
  4063. return NULL;
  4064. }
  4065. CControlUI* CALLBACK CPaintManagerUI::__FindControlsFromClass(CControlUI* pThis, LPVOID pData)
  4066. {
  4067. LPCTSTR pstrType = static_cast<LPCTSTR>(pData);
  4068. LPCTSTR pType = pThis->GetClass();
  4069. if (_tcscmp(pstrType, _T("*")) == 0 || _tcscmp(pstrType, pType) == 0)
  4070. pThis->GetManager()->GetFoundControls()->Add((LPVOID)pThis);
  4071. return NULL;
  4072. }
  4073. CControlUI* CALLBACK CPaintManagerUI::__FindControlsFromUpdate(CControlUI* pThis, LPVOID pData)
  4074. {
  4075. if (pThis->IsUpdateNeeded())
  4076. {
  4077. pThis->GetManager()->GetFoundControls()->Add((LPVOID)pThis);
  4078. return pThis;
  4079. }
  4080. return NULL;
  4081. }
  4082. bool CPaintManagerUI::TranslateAccelerator(LPMSG pMsg)
  4083. {
  4084. for (int i = 0; i < m_aTranslateAccelerator.GetSize(); i++)
  4085. {
  4086. LRESULT lResult = static_cast<ITranslateAccelerator*>(m_aTranslateAccelerator[i])->TranslateAccelerator(pMsg);
  4087. if (lResult == S_OK) return true;
  4088. }
  4089. return false;
  4090. }
  4091. bool CPaintManagerUI::TranslateMessage(const LPMSG pMsg)
  4092. {
  4093. // Pretranslate Message takes care of system-wide messages, such as
  4094. // tabbing and shortcut key-combos. We'll look for all messages for
  4095. // each window and any child control attached.
  4096. UINT uStyle = GetWindowStyle(pMsg->hwnd);
  4097. UINT uChildRes = uStyle & WS_CHILD;
  4098. LRESULT lRes = 0;
  4099. if (uChildRes != 0)
  4100. {
  4101. HWND hWndParent = ::GetParent(pMsg->hwnd);
  4102. for (int i = 0; i < m_aPreMessages.GetSize(); i++)
  4103. {
  4104. CPaintManagerUI* pT = static_cast<CPaintManagerUI*>(m_aPreMessages[i]);
  4105. HWND hTempParent = hWndParent;
  4106. while (hTempParent)
  4107. {
  4108. if (pMsg->hwnd == pT->GetPaintWindow() || hTempParent == pT->GetPaintWindow())
  4109. {
  4110. if (pT->TranslateAccelerator(pMsg))
  4111. return true;
  4112. pT->PreMessageHandler(pMsg->message, pMsg->wParam, pMsg->lParam, lRes);
  4113. }
  4114. hTempParent = GetParent(hTempParent);
  4115. }
  4116. }
  4117. }
  4118. else
  4119. {
  4120. for (int i = 0; i < m_aPreMessages.GetSize(); i++)
  4121. {
  4122. CPaintManagerUI* pT = static_cast<CPaintManagerUI*>(m_aPreMessages[i]);
  4123. if (pMsg->hwnd == pT->GetPaintWindow())
  4124. {
  4125. if (pT->TranslateAccelerator(pMsg))
  4126. return true;
  4127. if (pT->PreMessageHandler(pMsg->message, pMsg->wParam, pMsg->lParam, lRes))
  4128. return true;
  4129. return false;
  4130. }
  4131. }
  4132. }
  4133. return false;
  4134. }
  4135. bool CPaintManagerUI::AddTranslateAccelerator(ITranslateAccelerator* pTranslateAccelerator)
  4136. {
  4137. ASSERT(m_aTranslateAccelerator.Find(pTranslateAccelerator) < 0);
  4138. return m_aTranslateAccelerator.Add(pTranslateAccelerator);
  4139. }
  4140. bool CPaintManagerUI::RemoveTranslateAccelerator(ITranslateAccelerator* pTranslateAccelerator)
  4141. {
  4142. for (int i = 0; i < m_aTranslateAccelerator.GetSize(); i++)
  4143. {
  4144. if (static_cast<ITranslateAccelerator*>(m_aTranslateAccelerator[i]) == pTranslateAccelerator)
  4145. {
  4146. return m_aTranslateAccelerator.Remove(i);
  4147. }
  4148. }
  4149. return false;
  4150. }
  4151. void CPaintManagerUI::UsedVirtualWnd(bool bUsed)
  4152. {
  4153. m_bUsedVirtualWnd = bUsed;
  4154. }
  4155. // 样式管理
  4156. void CPaintManagerUI::AddStyle(LPCTSTR pName, LPCTSTR pDeclarationList, bool bShared)
  4157. {
  4158. CDuiString* pStyle = new CDuiString(pDeclarationList);
  4159. if (bShared || m_bForceUseSharedRes)
  4160. {
  4161. if (!m_SharedResInfo.m_StyleHash.Insert(pName, pStyle))
  4162. {
  4163. delete pStyle;
  4164. }
  4165. }
  4166. else
  4167. {
  4168. if (!m_ResInfo.m_StyleHash.Insert(pName, pStyle))
  4169. {
  4170. delete pStyle;
  4171. }
  4172. }
  4173. }
  4174. LPCTSTR CPaintManagerUI::GetStyle(LPCTSTR pName) const
  4175. {
  4176. CDuiString* pStyle = static_cast<CDuiString*>(m_ResInfo.m_StyleHash.Find(pName));
  4177. if (!pStyle) pStyle = static_cast<CDuiString*>(m_SharedResInfo.m_StyleHash.Find(pName));
  4178. if (pStyle) return pStyle->GetData();
  4179. else return NULL;
  4180. }
  4181. BOOL CPaintManagerUI::RemoveStyle(LPCTSTR pName, bool bShared)
  4182. {
  4183. CDuiString* pStyle = NULL;
  4184. if (bShared)
  4185. {
  4186. pStyle = static_cast<CDuiString*>(m_SharedResInfo.m_StyleHash.Find(pName));
  4187. if (pStyle)
  4188. {
  4189. delete pStyle;
  4190. m_SharedResInfo.m_StyleHash.Remove(pName);
  4191. }
  4192. }
  4193. else
  4194. {
  4195. pStyle = static_cast<CDuiString*>(m_ResInfo.m_StyleHash.Find(pName));
  4196. if (pStyle)
  4197. {
  4198. delete pStyle;
  4199. m_ResInfo.m_StyleHash.Remove(pName);
  4200. }
  4201. }
  4202. return true;
  4203. }
  4204. const CStdStringPtrMap& CPaintManagerUI::GetStyles(bool bShared) const
  4205. {
  4206. if (bShared) return m_SharedResInfo.m_StyleHash;
  4207. else return m_ResInfo.m_StyleHash;
  4208. }
  4209. void CPaintManagerUI::RemoveAllStyle(bool bShared)
  4210. {
  4211. if (bShared)
  4212. {
  4213. CDuiString* pStyle;
  4214. for (int i = 0; i < m_SharedResInfo.m_StyleHash.GetSize(); i++)
  4215. {
  4216. if (LPCTSTR key = m_SharedResInfo.m_StyleHash.GetAt(i))
  4217. {
  4218. pStyle = static_cast<CDuiString*>(m_SharedResInfo.m_StyleHash.Find(key));
  4219. delete pStyle;
  4220. }
  4221. }
  4222. m_SharedResInfo.m_StyleHash.RemoveAll();
  4223. }
  4224. else
  4225. {
  4226. CDuiString* pStyle;
  4227. for (int i = 0; i < m_ResInfo.m_StyleHash.GetSize(); i++)
  4228. {
  4229. if (LPCTSTR key = m_ResInfo.m_StyleHash.GetAt(i))
  4230. {
  4231. pStyle = static_cast<CDuiString*>(m_ResInfo.m_StyleHash.Find(key));
  4232. delete pStyle;
  4233. }
  4234. }
  4235. m_ResInfo.m_StyleHash.RemoveAll();
  4236. }
  4237. }
  4238. const TImageInfo* CPaintManagerUI::GetImageString(LPCTSTR pStrImage, LPCTSTR pStrModify)
  4239. {
  4240. CDuiString sImageName = pStrImage;
  4241. CDuiString sImageResType = _T("");
  4242. DWORD dwMask = 0;
  4243. CDuiString sItem;
  4244. CDuiString sValue;
  4245. LPTSTR pstr = NULL;
  4246. for (int i = 0; i < 2; ++i)
  4247. {
  4248. if (i == 1)
  4249. pStrImage = pStrModify;
  4250. if (!pStrImage) continue;
  4251. while (*pStrImage != _T('\0'))
  4252. {
  4253. sItem.Empty();
  4254. sValue.Empty();
  4255. while (*pStrImage > _T('\0') && *pStrImage <= _T(' ')) pStrImage = ::CharNext(pStrImage);
  4256. while (*pStrImage != _T('\0') && *pStrImage != _T('=') && *pStrImage > _T(' '))
  4257. {
  4258. LPTSTR pstrTemp = ::CharNext(pStrImage);
  4259. while (pStrImage < pstrTemp)
  4260. {
  4261. sItem += *pStrImage++;
  4262. }
  4263. }
  4264. while (*pStrImage > _T('\0') && *pStrImage <= _T(' ')) pStrImage = ::CharNext(pStrImage);
  4265. if (*pStrImage++ != _T('=')) break;
  4266. while (*pStrImage > _T('\0') && *pStrImage <= _T(' ')) pStrImage = ::CharNext(pStrImage);
  4267. if (*pStrImage++ != _T('\'')) break;
  4268. while (*pStrImage != _T('\0') && *pStrImage != _T('\''))
  4269. {
  4270. LPTSTR pstrTemp = ::CharNext(pStrImage);
  4271. while (pStrImage < pstrTemp)
  4272. {
  4273. sValue += *pStrImage++;
  4274. }
  4275. }
  4276. if (*pStrImage++ != _T('\'')) break;
  4277. if (!sValue.IsEmpty())
  4278. {
  4279. if (sItem == _T("file") || sItem == _T("res"))
  4280. {
  4281. sImageName = sValue;
  4282. }
  4283. else if (sItem == _T("restype"))
  4284. {
  4285. sImageResType = sValue;
  4286. }
  4287. else if (sItem == _T("mask"))
  4288. {
  4289. if (sValue[0] == _T('#')) dwMask = _tcstoul(sValue.GetData() + 1, &pstr, 16);
  4290. else dwMask = _tcstoul(sValue.GetData(), &pstr, 16);
  4291. }
  4292. }
  4293. if (*pStrImage++ != _T(' ')) break;
  4294. }
  4295. }
  4296. return GetImageEx(sImageName, sImageResType, dwMask);
  4297. }
  4298. bool CPaintManagerUI::EnableDragDrop(bool bEnable)
  4299. {
  4300. if (m_bDragDrop == bEnable) return false;
  4301. m_bDragDrop = bEnable;
  4302. if (bEnable)
  4303. {
  4304. AddRef();
  4305. if (FAILED(RegisterDragDrop(m_hWndPaint, this)))
  4306. {
  4307. return false;
  4308. }
  4309. SetTargetWnd(m_hWndPaint);
  4310. FORMATETC ftetc = { 0 };
  4311. ftetc.cfFormat = CF_BITMAP;
  4312. ftetc.dwAspect = DVASPECT_CONTENT;
  4313. ftetc.lindex = -1;
  4314. ftetc.tymed = TYMED_GDI;
  4315. AddSuportedFormat(ftetc);
  4316. ftetc.cfFormat = CF_DIB;
  4317. ftetc.tymed = TYMED_HGLOBAL;
  4318. AddSuportedFormat(ftetc);
  4319. ftetc.cfFormat = CF_HDROP;
  4320. ftetc.tymed = TYMED_HGLOBAL;
  4321. AddSuportedFormat(ftetc);
  4322. ftetc.cfFormat = CF_ENHMETAFILE;
  4323. ftetc.tymed = TYMED_ENHMF;
  4324. AddSuportedFormat(ftetc);
  4325. }
  4326. else
  4327. {
  4328. Release();
  4329. if (FAILED(RevokeDragDrop(m_hWndPaint)))
  4330. {
  4331. return false;
  4332. }
  4333. }
  4334. return true;
  4335. }
  4336. void CPaintManagerUI::SetDragDrop(IDragDropUI* pDragDrop)
  4337. {
  4338. m_pDragDrop = pDragDrop;
  4339. }
  4340. static WORD DIBNumColors(void* pv)
  4341. {
  4342. int bits;
  4343. LPBITMAPINFOHEADER lpbi;
  4344. LPBITMAPCOREHEADER lpbc;
  4345. lpbi = ((LPBITMAPINFOHEADER)pv);
  4346. lpbc = ((LPBITMAPCOREHEADER)pv);
  4347. /* With the BITMAPINFO format headers, the size of the palette
  4348. * is in biClrUsed, whereas in the BITMAPCORE - style headers, it
  4349. * is dependent on the bits per pixel ( = 2 raised to the power of
  4350. * bits/pixel).
  4351. */
  4352. if (lpbi->biSize != sizeof(BITMAPCOREHEADER))
  4353. {
  4354. if (lpbi->biClrUsed != 0)
  4355. return (WORD)lpbi->biClrUsed;
  4356. bits = lpbi->biBitCount;
  4357. }
  4358. else
  4359. bits = lpbc->bcBitCount;
  4360. switch (bits)
  4361. {
  4362. case 1:
  4363. return 2;
  4364. case 4:
  4365. return 16;
  4366. case 8:
  4367. return 256;
  4368. default:
  4369. /* A 24 bitcount DIB has no color table */
  4370. return 0;
  4371. }
  4372. }
  4373. //code taken from SEEDIB MSDN sample
  4374. static WORD ColorTableSize(LPVOID lpv)
  4375. {
  4376. LPBITMAPINFOHEADER lpbih = (LPBITMAPINFOHEADER)lpv;
  4377. if (lpbih->biSize != sizeof(BITMAPCOREHEADER))
  4378. {
  4379. if (((LPBITMAPINFOHEADER)(lpbih))->biCompression == BI_BITFIELDS)
  4380. /* Remember that 16/32bpp dibs can still have a color table */
  4381. return (sizeof(DWORD) * 3) + (DIBNumColors(lpbih) * sizeof(RGBQUAD));
  4382. else
  4383. return (WORD)(DIBNumColors(lpbih) * sizeof(RGBQUAD));
  4384. }
  4385. else
  4386. return (WORD)(DIBNumColors(lpbih) * sizeof(RGBTRIPLE));
  4387. }
  4388. bool CPaintManagerUI::OnDrop(FORMATETC* pFmtEtc, STGMEDIUM& medium, DWORD* pdwEffect)
  4389. {
  4390. POINT ptMouse = { 0 };
  4391. GetCursorPos(&ptMouse);
  4392. ::SendMessage(m_hTargetWnd, WM_LBUTTONUP, NULL, MAKELPARAM(ptMouse.x, ptMouse.y));
  4393. if (pFmtEtc->cfFormat == CF_DIB && medium.tymed == TYMED_HGLOBAL)
  4394. {
  4395. if (medium.hGlobal != NULL)
  4396. {
  4397. LPBITMAPINFOHEADER lpbi = (BITMAPINFOHEADER*)GlobalLock(medium.hGlobal);
  4398. if (lpbi != NULL)
  4399. {
  4400. HBITMAP hbm = NULL;
  4401. HDC hdc = GetDC(NULL);
  4402. if (hdc != NULL)
  4403. {
  4404. int i = ((BITMAPFILEHEADER*)lpbi)->bfOffBits;
  4405. hbm = CreateDIBitmap(hdc, (LPBITMAPINFOHEADER)lpbi,
  4406. (LONG)CBM_INIT,
  4407. (LPSTR)lpbi + lpbi->biSize + ColorTableSize(lpbi),
  4408. (LPBITMAPINFO)lpbi, DIB_RGB_COLORS);
  4409. ::ReleaseDC(NULL, hdc);
  4410. }
  4411. GlobalUnlock(medium.hGlobal);
  4412. if (hbm != NULL)
  4413. hbm = (HBITMAP)SendMessage(m_hTargetWnd, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hbm);
  4414. if (hbm != NULL)
  4415. DeleteObject(hbm);
  4416. return true; //release the medium
  4417. }
  4418. }
  4419. }
  4420. if (pFmtEtc->cfFormat == CF_BITMAP && medium.tymed == TYMED_GDI)
  4421. {
  4422. if (medium.hBitmap != NULL)
  4423. {
  4424. HBITMAP hBmp = (HBITMAP)SendMessage(m_hTargetWnd, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)medium.hBitmap);
  4425. if (hBmp != NULL)
  4426. DeleteObject(hBmp);
  4427. return false; //don't free the bitmap
  4428. }
  4429. }
  4430. if (pFmtEtc->cfFormat == CF_ENHMETAFILE && medium.tymed == TYMED_ENHMF)
  4431. {
  4432. ENHMETAHEADER emh;
  4433. GetEnhMetaFileHeader(medium.hEnhMetaFile, sizeof(ENHMETAHEADER), &emh);
  4434. RECT rc;//={0,0,EnhMetaHdr.rclBounds.right-EnhMetaHdr.rclBounds.left, EnhMetaHdr.rclBounds.bottom-EnhMetaHdr.rclBounds.top};
  4435. HDC hDC = GetDC(m_hTargetWnd);
  4436. //start code: taken from ENHMETA.EXE MSDN Sample
  4437. //*ALSO NEED to GET the pallete (select and RealizePalette it, but i was too lazy*
  4438. // Get the characteristics of the output device
  4439. float PixelsX = (float)GetDeviceCaps(hDC, HORZRES);
  4440. float PixelsY = (float)GetDeviceCaps(hDC, VERTRES);
  4441. float MMX = (float)GetDeviceCaps(hDC, HORZSIZE);
  4442. float MMY = (float)GetDeviceCaps(hDC, VERTSIZE);
  4443. // Calculate the rect in which to draw the metafile based on the
  4444. // intended size and the current output device resolution
  4445. // Remember that the intended size is given in 0.01mm units, so
  4446. // convert those to device units on the target device
  4447. rc.top = (int)((float)(emh.rclFrame.top) * PixelsY / (MMY * 100.0f));
  4448. rc.left = (int)((float)(emh.rclFrame.left) * PixelsX / (MMX * 100.0f));
  4449. rc.right = (int)((float)(emh.rclFrame.right) * PixelsX / (MMX * 100.0f));
  4450. rc.bottom = (int)((float)(emh.rclFrame.bottom) * PixelsY / (MMY * 100.0f));
  4451. //end code: taken from ENHMETA.EXE MSDN Sample
  4452. HDC hdcMem = CreateCompatibleDC(hDC);
  4453. HGDIOBJ hBmpMem = CreateCompatibleBitmap(hDC, emh.rclBounds.right, emh.rclBounds.bottom);
  4454. HGDIOBJ hOldBmp = ::SelectObject(hdcMem, hBmpMem);
  4455. PlayEnhMetaFile(hdcMem, medium.hEnhMetaFile, &rc);
  4456. HBITMAP hBmp = (HBITMAP)::SelectObject(hdcMem, hOldBmp);
  4457. DeleteDC(hdcMem);
  4458. ReleaseDC(m_hTargetWnd, hDC);
  4459. hBmp = (HBITMAP)SendMessage(m_hTargetWnd, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hBmp);
  4460. if (hBmp != NULL)
  4461. DeleteObject(hBmp);
  4462. return true;
  4463. }
  4464. if (pFmtEtc->cfFormat == CF_HDROP && medium.tymed == TYMED_HGLOBAL)
  4465. {
  4466. HDROP hDrop = (HDROP)GlobalLock(medium.hGlobal);
  4467. if (hDrop != NULL)
  4468. {
  4469. TCHAR szFileName[MAX_PATH];
  4470. UINT cFiles = DragQueryFile(hDrop, 0xFFFFFFFF, NULL, 0);
  4471. if (cFiles > 0)
  4472. {
  4473. DragQueryFile(hDrop, 0, szFileName, sizeof(szFileName));
  4474. HBITMAP hBitmap = (HBITMAP)LoadImage(NULL, szFileName, IMAGE_BITMAP, 0, 0, LR_DEFAULTSIZE | LR_LOADFROMFILE);
  4475. if (hBitmap)
  4476. {
  4477. HBITMAP hBmp = (HBITMAP)SendMessage(m_hTargetWnd, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hBitmap);
  4478. if (hBmp != NULL)
  4479. DeleteObject(hBmp);
  4480. }
  4481. }
  4482. }
  4483. GlobalUnlock(medium.hGlobal);
  4484. }
  4485. return true; //let base free the medium
  4486. }
  4487. } // namespace DuiLib
  4488. #pragma warning(pop)