listWidget.cpp 97 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096
  1. #include "main.h"
  2. #include "./listWidget.h"
  3. #include "./listWidgetInternal.h"
  4. #include <vector>
  5. #include <strsafe.h>
  6. #define LISTWIDGET_OFFSET_LEFT_DLU 0
  7. #define LISTWIDGET_OFFSET_TOP_DLU 1
  8. #define LISTWIDGET_OFFSET_BOTTOM_DLU 2
  9. #define LISTWIDGET_CATEGORY_OFFSET_TOP_DLU 0
  10. #define LISTWIDGET_CATEGORY_OFFSET_LEFT_DLU 1
  11. #define LISTWIDGET_CATEGORY_SPACING_DLU 2
  12. #define LISTWIDGET_CATEGORY_SPACING_COLLAPSED_DLU 0
  13. #define LISTWIDGET_ITEM_OFFSET_TOP_DLU 1
  14. #define LISTWIDGET_ITEM_OFFSET_LEFT_DLU 2
  15. #define LISTWIDGET_ITEM_SPACING_HORZ_DLU 2
  16. #define LISTWIDGET_ITEM_SPACING_VERT_DLU 10
  17. #define LISTWIDGET_ITEM_TITLE_MAX_LINES 3
  18. #define LISTWIDGET_IMAGE_MIN_HEIGHT 48
  19. #define LISTWIDGET_IMAGE_MAX_HEIGHT 256
  20. #define LISTWIDGET_IMAGE_DEFAULT_HEIGHT 160//128
  21. #define LISTWIDGET_IMAGE_DEFAULT_WIDTH 160//96
  22. #define LISTWIDGETTIMER_SHOW_COMMANDS_ID 3
  23. #define LISTWIDGETTIMER_SHOW_COMMANDS_DELAY 75
  24. #define LISTWIDGETTIMER_PROGRESS_TICK_ID 4
  25. #define LISTWIDGETTIMER_PROGRESS_TICK_DELAY 130
  26. #define LISTWIDGETTIMER_EDIT_TITLE_ID 5
  27. #define LISTWIDGET_CONNECTION_MIN_HEIGHT 20
  28. #define LISTWIDGET_CONNECTION_MAX_HEIGHT 48
  29. #define LISTWIDGET_CONNECTION_DEFAULT_HEIGHT 36
  30. #define LISTWIDGET_PRIMARYCOMMAND_MIN_HEIGHT 16
  31. #define LISTWIDGET_PRIMARYCOMMAND_MAX_HEIGHT 48
  32. #define LISTWIDGET_PRIMARYCOMMAND_DEFAULT_HEIGHT 36
  33. #define LISTWIDGET_SECONDARYCOMMAND_MIN_HEIGHT 14
  34. #define LISTWIDGET_SECONDARYCOMMAND_MAX_HEIGHT 36
  35. #define LISTWIDGET_SECONDARYCOMMAND_DEFAULT_HEIGHT 20
  36. #define LISTWIDGET_ACTIVITY_MIN_HEIGHT 16
  37. #define LISTWIDGET_ACTIVITY_MAX_HEIGHT 48
  38. #define LISTWIDGET_ACTIVITY_DEFAULT_HEIGHT 36
  39. #define LISTWIDGET_PROGRESS_MIN_HEIGHT 16
  40. #define LISTWIDGET_PROGRESS_FRAME_COUNT 9/*12*/
  41. typedef std::vector<ifc_device*> DeviceList;
  42. static ListWidgetCategory *
  43. ListWidget_CreateCategoryHelper(const char *name, int titleId, wchar_t *buffer, size_t bufferMax)
  44. {
  45. WASABI_API_LNGSTRINGW_BUF(titleId, buffer, bufferMax);
  46. return ListWidget_CreateCategory(name,
  47. buffer,
  48. Config_ReadBool("CollapsedCategories", name, FALSE));
  49. }
  50. static void
  51. ListWidget_CreateDefaultCategories(ListWidget *self)
  52. {
  53. ListWidgetCategory *category;
  54. wchar_t buffer[512] = {0};
  55. category = ListWidget_CreateCategoryHelper("attached", IDS_CATEGORY_ATTACHED, buffer, ARRAYSIZE(buffer));
  56. if (NULL != category)
  57. {
  58. WASABI_API_LNGSTRINGW_BUF(IDS_CATEGORY_ATTACHED_EMPTY_TEXT, buffer, ARRAYSIZE(buffer));
  59. ListWidget_SetCategoryEmptyText(category, buffer);
  60. self->categories.push_back(category);
  61. }
  62. category = ListWidget_CreateCategoryHelper("discovered", IDS_CATEGORY_DISCOVERED, buffer, ARRAYSIZE(buffer));
  63. if (NULL != category)
  64. self->categories.push_back(category);
  65. }
  66. BOOL
  67. ListWidget_GetViewOrigin(HWND hwnd, POINT *pt)
  68. {
  69. SCROLLINFO scrollInfo;
  70. if (NULL == pt)
  71. return FALSE;
  72. scrollInfo.cbSize = sizeof(scrollInfo);
  73. scrollInfo.fMask = SIF_POS;
  74. if (FALSE == GetScrollInfo(hwnd, SB_HORZ, &scrollInfo))
  75. return FALSE;
  76. pt->x = -scrollInfo.nPos;
  77. if (FALSE == GetScrollInfo(hwnd, SB_VERT, &scrollInfo))
  78. return FALSE;
  79. pt->y = -scrollInfo.nPos;
  80. return TRUE;
  81. }
  82. static HBITMAP
  83. ListWidget_CreateSpacebarBitmap(HBITMAP sourceBitmap, HWND hwnd, long width, long height)
  84. {
  85. HDC windowDC, sourceDC, resultDC;
  86. HBITMAP resultBitmap;
  87. BITMAP sourceInfo;
  88. RECT resultRect, sourceRect;
  89. if (NULL == sourceBitmap ||
  90. sizeof(sourceInfo) != GetObject(sourceBitmap, sizeof(sourceInfo), &sourceInfo))
  91. {
  92. return FALSE;
  93. }
  94. windowDC = GetDCEx(hwnd, NULL, DCX_CACHE | DCX_NORESETATTRS);
  95. if (NULL == windowDC)
  96. return NULL;
  97. sourceDC = CreateCompatibleDC(windowDC);
  98. resultDC = CreateCompatibleDC(windowDC);
  99. resultBitmap = CreateCompatibleBitmap(windowDC, width, height*2);
  100. ReleaseDC(hwnd, windowDC);
  101. if (NULL != sourceDC &&
  102. NULL != resultDC &&
  103. NULL != resultBitmap)
  104. {
  105. HBITMAP prevSourceBitmap, prevResultBitmap;
  106. prevSourceBitmap = SelectBitmap(sourceDC, sourceBitmap);
  107. prevResultBitmap = SelectBitmap(resultDC, resultBitmap);
  108. SetRect(&resultRect, 0, 0, width, height);
  109. SetRect(&sourceRect, 0, 0, sourceInfo.bmWidth, ABS(sourceInfo.bmHeight)/2);
  110. Image_FillBorder(resultDC, &resultRect, sourceDC, &sourceRect, TRUE, 255);
  111. OffsetRect(&resultRect, 0, height);
  112. OffsetRect(&sourceRect, 0, RECTHEIGHT(sourceRect));
  113. Image_FillBorder(resultDC, &resultRect, sourceDC, &sourceRect, TRUE, 255);
  114. SelectBitmap(sourceDC, prevSourceBitmap);
  115. SelectBitmap(resultDC, prevResultBitmap);
  116. }
  117. if (NULL != sourceDC)
  118. DeleteDC(sourceDC);
  119. if (NULL != resultDC)
  120. DeleteDC(resultDC);
  121. if (NULL != resultBitmap)
  122. {
  123. RECT imageRect;
  124. SetRect(&imageRect, 0, 0, width, height);
  125. Image_Premultiply(resultBitmap, &imageRect);
  126. }
  127. return resultBitmap;
  128. }
  129. HBITMAP
  130. ListWidget_GetSpacebarBitmap(ListWidget *self, WidgetStyle *style, HWND hwnd, long width, long height)
  131. {
  132. if (NULL == self)
  133. return NULL;
  134. if (NULL != self->spacebarBitmap)
  135. {
  136. BITMAP bi;
  137. if (sizeof(bi) != GetObject(self->spacebarBitmap, sizeof(bi), &bi) ||
  138. bi.bmWidth != width ||
  139. bi.bmHeight/2 != height)
  140. {
  141. DeleteObject(self->spacebarBitmap);
  142. self->spacebarBitmap = NULL;
  143. }
  144. }
  145. if (NULL == self->spacebarBitmap &&
  146. NULL != style)
  147. {
  148. HBITMAP baseBitmap;
  149. baseBitmap = Image_Load(MAKEINTRESOURCE(IDR_SPACEBAR_IMAGE), SRC_TYPE_PNG, 0, 0, 0);
  150. //WIDGETSTYLE_IMAGE_BACK_COLOR(style),
  151. // WIDGETSTYLE_IMAGE_FRONT_COLOR(style),
  152. // WIDGETSTYLE_BACK_COLOR(style));
  153. if (NULL != baseBitmap)
  154. {
  155. DIBSECTION bitmapData;
  156. if (sizeof(bitmapData) == GetObjectW(baseBitmap, sizeof(bitmapData), &bitmapData))
  157. {
  158. BITMAP *bi;
  159. long bitmapHeight;
  160. void *pixels;
  161. WORD backHue, backLuma, backSat, frontHue, frontLuma, frontSat;
  162. bi = &bitmapData.dsBm;
  163. bitmapHeight = ABS(bi->bmHeight);
  164. pixels = ((BYTE*)bi->bmBits) + (bi->bmWidthBytes * (bitmapHeight - bitmapHeight/2));
  165. ColorRGBToHLS(WIDGETSTYLE_IMAGE_BACK_COLOR(style), &backHue, &backLuma, &backSat);
  166. ColorRGBToHLS(WIDGETSTYLE_IMAGE_FRONT_COLOR(style), &frontHue, &frontLuma, &frontSat);
  167. if (backLuma > frontLuma)
  168. {
  169. COLORREF backColor;
  170. frontLuma = 25;
  171. backColor = ColorHLSToRGB(frontHue, frontLuma, frontSat);
  172. Image_FilterEx(pixels, bi->bmWidth, bitmapHeight/2, bi->bmBitsPixel,
  173. 0,
  174. backColor,
  175. WIDGETSTYLE_IMAGE_BACK_COLOR(style),
  176. WIDGETSTYLE_BACK_COLOR(style));
  177. }
  178. else
  179. {
  180. Image_FilterEx(pixels, bi->bmWidth, bitmapHeight/2, bi->bmBitsPixel,
  181. 0,
  182. WIDGETSTYLE_IMAGE_BACK_COLOR(style),
  183. WIDGETSTYLE_IMAGE_FRONT_COLOR(style),
  184. WIDGETSTYLE_BACK_COLOR(style));
  185. }
  186. }
  187. Image_Premultiply(baseBitmap, NULL);
  188. self->spacebarBitmap = ListWidget_CreateSpacebarBitmap(baseBitmap, hwnd, width, height);
  189. DeleteObject(baseBitmap);
  190. }
  191. }
  192. return self->spacebarBitmap;
  193. }
  194. static HBITMAP
  195. ListWidget_CreateBorderBitmap(HBITMAP sourceBitmap, HWND hwnd, long width, long height)
  196. {
  197. HDC windowDC, sourceDC, resultDC;
  198. HBITMAP resultBitmap;
  199. BITMAP sourceInfo;
  200. RECT resultRect, sourceRect;
  201. if (NULL == sourceBitmap ||
  202. sizeof(sourceInfo) != GetObject(sourceBitmap, sizeof(sourceInfo), &sourceInfo))
  203. {
  204. return FALSE;
  205. }
  206. SetRect(&resultRect, 0, 0, width, height);
  207. SetRect(&sourceRect, 0, 0, sourceInfo.bmWidth, ABS(sourceInfo.bmHeight));
  208. windowDC = GetDCEx(hwnd, NULL, DCX_CACHE | DCX_NORESETATTRS);
  209. if (NULL == windowDC)
  210. return NULL;
  211. sourceDC = CreateCompatibleDC(windowDC);
  212. resultDC = CreateCompatibleDC(windowDC);
  213. resultBitmap = CreateCompatibleBitmap(windowDC, width, height);
  214. ReleaseDC(hwnd, windowDC);
  215. if (NULL != sourceDC &&
  216. NULL != resultDC &&
  217. NULL != resultBitmap)
  218. {
  219. HBITMAP prevSourceBitmap, prevResultBitmap;
  220. prevSourceBitmap = SelectBitmap(sourceDC, sourceBitmap);
  221. prevResultBitmap = SelectBitmap(resultDC, resultBitmap);
  222. Image_FillBorder(resultDC, &resultRect, sourceDC, &sourceRect, TRUE, 255);
  223. SelectBitmap(sourceDC, prevSourceBitmap);
  224. SelectBitmap(resultDC, prevResultBitmap);
  225. }
  226. if (NULL != sourceDC)
  227. DeleteDC(sourceDC);
  228. if (NULL != resultDC)
  229. DeleteDC(resultDC);
  230. return resultBitmap;
  231. }
  232. static HBITMAP
  233. ListWidget_GetBorderBitmap(HBITMAP bitmap, const wchar_t *path, WidgetStyle *style,
  234. HWND hwnd, long width, long height, BOOL disableSkin,
  235. COLORREF colorBack, COLORREF colorFront)
  236. {
  237. if (NULL != bitmap)
  238. {
  239. BITMAP bi;
  240. if (sizeof(bi) != GetObject(bitmap, sizeof(bi), &bi) ||
  241. bi.bmWidth != width ||
  242. bi.bmHeight != height)
  243. {
  244. DeleteObject(bitmap);
  245. bitmap = NULL;
  246. }
  247. }
  248. if (NULL == bitmap &&
  249. NULL != style)
  250. {
  251. HBITMAP baseBitmap;
  252. if (FALSE == disableSkin)
  253. {
  254. baseBitmap = Image_LoadSkinned(path,
  255. SRC_TYPE_PNG,
  256. IMAGE_FILTER_NORMAL,
  257. 0, 0,
  258. colorBack, colorFront,
  259. WIDGETSTYLE_BACK_COLOR(style));
  260. }
  261. else
  262. {
  263. baseBitmap = Image_Load(path, SRC_TYPE_PNG, 0, 0, 0);
  264. }
  265. if (NULL != baseBitmap)
  266. {
  267. Image_Premultiply(baseBitmap, NULL);
  268. bitmap = ListWidget_CreateBorderBitmap(baseBitmap, hwnd, width, height);
  269. DeleteObject(baseBitmap);
  270. }
  271. }
  272. return bitmap;
  273. }
  274. HBITMAP
  275. ListWidget_GetHoverBitmap(ListWidget *self, WidgetStyle *style, HWND hwnd, long width, long height)
  276. {
  277. if (NULL == self)
  278. return NULL;
  279. self->hoverBitmap = ListWidget_GetBorderBitmap(self->hoverBitmap,
  280. MAKEINTRESOURCE(IDR_ITEM_HOVER_IMAGE),
  281. style, hwnd, width, height, FALSE,
  282. WIDGETSTYLE_SELECT_BACK_COLOR(style),
  283. WIDGETSTYLE_SELECT_FRONT_COLOR(style));
  284. return self->hoverBitmap;
  285. }
  286. HBITMAP
  287. ListWidget_GetSelectBitmap(ListWidget *self, WidgetStyle *style, HWND hwnd, long width, long height)
  288. {
  289. if (NULL == self)
  290. return NULL;
  291. self->selectBitmap = ListWidget_GetBorderBitmap(self->selectBitmap,
  292. MAKEINTRESOURCE(IDR_ITEM_SELECT_IMAGE),
  293. style, hwnd, width, height, FALSE,
  294. WIDGETSTYLE_SELECT_BACK_COLOR(style),
  295. WIDGETSTYLE_SELECT_FRONT_COLOR(style));
  296. return self->selectBitmap;
  297. }
  298. HBITMAP
  299. ListWidget_GetInactiveSelectBitmap(ListWidget *self, WidgetStyle *style, HWND hwnd, long width, long height)
  300. {
  301. if (NULL == self)
  302. return NULL;
  303. self->inactiveSelectBitmap = ListWidget_GetBorderBitmap(self->inactiveSelectBitmap,
  304. MAKEINTRESOURCE(IDR_ITEM_SELECT_IMAGE),
  305. style, hwnd, width, height, FALSE,
  306. WIDGETSTYLE_INACTIVE_SELECT_BACK_COLOR(style),
  307. WIDGETSTYLE_INACTIVE_SELECT_FRONT_COLOR(style));
  308. return self->inactiveSelectBitmap;
  309. }
  310. HBITMAP
  311. ListWidget_GetLargeBadgeBitmap(ListWidget *self, WidgetStyle *style, HWND hwnd, long width, long height)
  312. {
  313. if (NULL == self)
  314. return NULL;
  315. self->largeBadgeBitmap = ListWidget_GetBorderBitmap(self->largeBadgeBitmap,
  316. MAKEINTRESOURCE(IDR_COMMAND_BACKGROUND_IMAGE),
  317. style, hwnd, width, height, TRUE,
  318. WIDGETSTYLE_IMAGE_BACK_COLOR(style),
  319. WIDGETSTYLE_IMAGE_FRONT_COLOR(style));
  320. return self->largeBadgeBitmap;
  321. }
  322. HBITMAP
  323. ListWidget_GetSmallBadgeBitmap(ListWidget *self, WidgetStyle *style, HWND hwnd, long width, long height)
  324. {
  325. if (NULL == self)
  326. return NULL;
  327. self->smallBadgeBitmap = ListWidget_GetBorderBitmap(self->smallBadgeBitmap,
  328. MAKEINTRESOURCE(IDR_COMMAND_SECONDARY_BACKGROUND_IMAGE),
  329. style, hwnd, width, height, TRUE,
  330. WIDGETSTYLE_IMAGE_BACK_COLOR(style),
  331. WIDGETSTYLE_IMAGE_FRONT_COLOR(style));
  332. return self->smallBadgeBitmap;
  333. }
  334. HBITMAP
  335. ListWidget_GetArrowsBitmap(ListWidget *self, WidgetStyle *style, HWND hwnd)
  336. {
  337. if (NULL == self)
  338. return NULL;
  339. if (NULL == self->arrowsBitmap &&
  340. NULL != style)
  341. {
  342. self->arrowsBitmap = Image_LoadSkinned(MAKEINTRESOURCE(IDR_CATEGORY_ARROWS_IMAGE),
  343. SRC_TYPE_PNG,
  344. IMAGE_FILTER_NORMAL,
  345. 0, 0,
  346. WIDGETSTYLE_CATEGORY_BACK_COLOR(style),
  347. WIDGETSTYLE_CATEGORY_TEXT_COLOR(style),
  348. WIDGETSTYLE_CATEGORY_BACK_COLOR(style));
  349. if (NULL != self->arrowsBitmap)
  350. Image_Premultiply(self->arrowsBitmap, NULL);
  351. }
  352. return self->arrowsBitmap;
  353. }
  354. HBITMAP
  355. ListWidget_GetUnknownCommandLargeBitmap(ListWidget *self, WidgetStyle *style, long width, long height)
  356. {
  357. if (NULL == self)
  358. return NULL;
  359. if (NULL == self->unknownCommandLargeImage &&
  360. NULL != style)
  361. {
  362. self->unknownCommandLargeImage = DeviceImageCache_GetImage(Plugin_GetImageCache(),
  363. MAKEINTRESOURCE(IDR_UNKNOWN_COMMAND_LARGE_IMAGE),
  364. width, height,
  365. NULL, NULL);
  366. }
  367. return DeviceImage_GetBitmap(self->unknownCommandLargeImage, DeviceImage_Normal);
  368. }
  369. HBITMAP
  370. ListWidget_GetUnknownCommandSmallBitmap(ListWidget *self, WidgetStyle *style, long width, long height)
  371. {
  372. if (NULL == self)
  373. return NULL;
  374. if (NULL == self->unknownCommandSmallImage &&
  375. NULL != style)
  376. {
  377. self->unknownCommandSmallImage = DeviceImageCache_GetImage(Plugin_GetImageCache(),
  378. MAKEINTRESOURCE(IDR_UNKNOWN_COMMAND_LARGE_IMAGE),
  379. width, height,
  380. NULL, NULL);
  381. }
  382. return DeviceImage_GetBitmap(self->unknownCommandSmallImage, DeviceImage_Normal);
  383. }
  384. HBITMAP
  385. ListWidget_GetActivityProgressBitmap(ListWidget *self, WidgetStyle *style)
  386. {
  387. if (NULL == self)
  388. return NULL;
  389. if (NULL == self->activityProgressImage &&
  390. NULL != style)
  391. {
  392. self->activityProgressImage = DeviceImageCache_GetImage(Plugin_GetImageCache(),
  393. MAKEINTRESOURCE(IDR_PROGRESS_SMALL_IMAGE),
  394. self->activityMetrics.progressWidth, self->activityMetrics.progressHeight * LISTWIDGET_PROGRESS_FRAME_COUNT,
  395. NULL, NULL);
  396. }
  397. return DeviceImage_GetBitmap(self->activityProgressImage, DeviceImage_Normal);
  398. }
  399. HBITMAP
  400. ListWidget_GetActivityBadgeBitmap(ListWidget *self, WidgetStyle *style, HWND hwnd, long width, long height)
  401. {
  402. if (NULL == self)
  403. return NULL;
  404. self->activityBadgeBitmap = ListWidget_GetBorderBitmap(self->activityBadgeBitmap,
  405. MAKEINTRESOURCE(IDR_ACTION_BACKGROUND_IMAGE),
  406. style, hwnd, width, height, TRUE,
  407. WIDGETSTYLE_IMAGE_BACK_COLOR(style),
  408. WIDGETSTYLE_IMAGE_FRONT_COLOR(style));
  409. return self->activityBadgeBitmap;
  410. }
  411. static BOOL
  412. ListWidget_UpdateCommandsLayout(ListWidget *self, HWND hwnd)
  413. {
  414. WidgetStyle *style;
  415. ListWidgetItemMetric metrics;
  416. RECT rect;
  417. size_t index, indexMax;
  418. long spacing;
  419. if (NULL == self)
  420. return FALSE;
  421. style = WIDGET_GET_STYLE(hwnd);
  422. if (NULL == style)
  423. return FALSE;
  424. if (0 == self->commandsCount)
  425. return TRUE;
  426. if (FALSE == ListWidget_GetItemMetrics(style, &metrics))
  427. return FALSE;
  428. indexMax = self->commandsCount;
  429. if ((NULL == self->hoveredItem || NULL == self->hoveredItem->activity) &&
  430. FALSE != ListWidget_GetCommandPrimary(self->commands[0]))
  431. {
  432. rect.bottom = self->imageSize.cy /*+ metrics.imageOffsetBottom*/;
  433. rect.bottom += metrics.offsetTop + metrics.imageOffsetTop;
  434. rect.top = rect.bottom - self->primaryCommandSize.cy;
  435. rect.left = (self->itemWidth - self->primaryCommandSize.cx)/2;
  436. rect.right = rect.left + self->primaryCommandSize.cx;
  437. ListWidget_SetCommandRect(self->commands[0], &rect);
  438. indexMax--;
  439. }
  440. rect.top = metrics.offsetTop + metrics.imageOffsetTop;
  441. rect.bottom = rect.top + self->secondaryCommandSize.cy;
  442. rect.right = self->itemWidth - metrics.offsetRight - metrics.imageOffsetRight;
  443. rect.left = rect.right - self->secondaryCommandSize.cx;
  444. spacing = self->secondaryCommandSize.cx/16 + 1;
  445. for(index = 0; index < indexMax; index++)
  446. {
  447. ListWidget_SetCommandRect(self->commands[self->commandsCount - index - 1], &rect);
  448. OffsetRect(&rect, -(self->secondaryCommandSize.cx + spacing), 0);
  449. }
  450. return TRUE;
  451. }
  452. static BOOL
  453. ListWidget_UpdateActiveCommands(ListWidget *self, HWND hwnd)
  454. {
  455. ListWidgetCommand **clone;
  456. size_t cloneSize, index;
  457. BOOL invalidated;
  458. POINT origin, pt;
  459. RECT rect;
  460. if (NULL == self)
  461. return FALSE;
  462. if (FALSE == ListWidget_GetViewOrigin(hwnd, &origin))
  463. {
  464. origin.x = 0;
  465. origin.y = 0;
  466. }
  467. if (NULL == self->hoveredItem)
  468. {
  469. ListWidget_DestroyAllCommands(self->commands, self->commandsCount);
  470. self->commandsCount = 0;
  471. return TRUE;
  472. }
  473. origin.x += self->hoveredItem->rect.left;
  474. origin.y += self->hoveredItem->rect.top;
  475. invalidated = FALSE;
  476. if (0 != self->commandsCount)
  477. {
  478. for(index = 0; index < self->commandsCount; index++)
  479. {
  480. if (FALSE != ListWidget_GetCommandRect(self->commands[index], &rect))
  481. {
  482. OffsetRect(&rect, origin.x, origin.y);
  483. if (FALSE != InvalidateRect(hwnd, &rect, FALSE))
  484. invalidated = TRUE;
  485. }
  486. }
  487. clone = (ListWidgetCommand**)malloc(sizeof(ListWidgetCommand*) * self->commandsCount);
  488. if (NULL != clone)
  489. {
  490. cloneSize = self->commandsCount;
  491. CopyMemory(clone, self->commands, sizeof(ListWidgetCommand*) * cloneSize);
  492. }
  493. else
  494. {
  495. cloneSize = 0;
  496. ListWidget_DestroyAllCommands(self->commands, self->commandsCount);
  497. }
  498. }
  499. else
  500. {
  501. clone = NULL;
  502. cloneSize = 0;
  503. }
  504. self->commandsCount = ListWidget_GetItemCommands(self->hoveredItem,
  505. self->commands, self->commandsMax);
  506. if (0 != self->commandsCount)
  507. {
  508. ListWidget_UpdateCommandsLayout(self, hwnd);
  509. ListWidgetItem_SetInteractive(self->hoveredItem);
  510. for(index = 0; index < self->commandsCount; index++)
  511. {
  512. if (FALSE != ListWidget_GetCommandRect(self->commands[index], &rect))
  513. {
  514. OffsetRect(&rect, origin.x, origin.y);
  515. if (FALSE != InvalidateRect(hwnd, &rect, FALSE))
  516. invalidated = TRUE;
  517. }
  518. }
  519. }
  520. else
  521. ListWidgetItem_UnsetInteractive(self->hoveredItem);
  522. if (NULL != clone)
  523. {
  524. ListWidget_DestroyAllCommands(clone, cloneSize);
  525. free(clone);
  526. }
  527. if (FALSE != GetCursorPos(&pt))
  528. {
  529. ListWidgetItem *tooltipItem;
  530. ListWidgetItemPart tooltipItemPart;
  531. RECT tooltipItemPartRect;
  532. tooltipItem = ListWidget_TooltipGetCurrent(self->tooltip, &tooltipItemPart, &tooltipItemPartRect);
  533. MapWindowPoints(HWND_DESKTOP, hwnd, &pt, 1);
  534. ListWidget_UpdateHoverEx(self, hwnd, &pt);
  535. if (FALSE != ListWidget_TooltipGetChanged(self->tooltip, tooltipItem,
  536. tooltipItemPart, &tooltipItemPartRect))
  537. {
  538. ListWidget_TooltipRelayMouseMessage(self->tooltip, WM_MOUSEMOVE, 0, &pt);
  539. }
  540. }
  541. if (FALSE != invalidated)
  542. UpdateWindow(hwnd);
  543. return TRUE;
  544. }
  545. static void CALLBACK
  546. ListWidget_ShowCommandTimerCb(HWND hwnd, UINT uMsg, UINT_PTR eventId, DWORD elpasedTime)
  547. {
  548. ListWidget *self;
  549. KillTimer(hwnd, eventId);
  550. self = WIDGET_GET_SELF(hwnd, ListWidget);
  551. if (NULL == self)
  552. return;
  553. if (NULL != self->hoveredItem &&
  554. FALSE == ListWidgetItem_IsInteractive(self->hoveredItem) &&
  555. NULL == self->activeMenu)
  556. {
  557. ListWidget_UpdateActiveCommands(self, hwnd);
  558. }
  559. }
  560. static void CALLBACK
  561. ListWidget_ProgressTickCb(HWND hwnd, UINT uMsg, UINT_PTR eventId, DWORD elpasedTime)
  562. {
  563. ListWidget *self = WIDGET_GET_SELF(hwnd, ListWidget);
  564. if (NULL == self)
  565. {
  566. KillTimer(hwnd, eventId);
  567. return;
  568. }
  569. size_t index = self->activeItems.size();
  570. if (index > 0)
  571. {
  572. POINT origin;
  573. RECT rect;
  574. ListWidgetItemMetric metrics, *metrics_ptr;
  575. WidgetStyle *style;
  576. if (FALSE == ListWidget_GetViewOrigin(hwnd, &origin))
  577. {
  578. origin.x = 0;
  579. origin.y = 0;
  580. }
  581. style = WIDGET_GET_STYLE(hwnd);
  582. if (NULL != style && FALSE != ListWidget_GetItemMetrics(style, &metrics))
  583. metrics_ptr = &metrics;
  584. else
  585. metrics_ptr = NULL;
  586. while(index--)
  587. {
  588. ListWidgetItem *item = self->activeItems[index];
  589. item->activity->step++;
  590. if (item->activity->step >= LISTWIDGET_PROGRESS_FRAME_COUNT)
  591. item->activity->step = 1;
  592. if (FALSE != ListWidget_GetItemActivityProgressRect(self, NULL, item, metrics_ptr, &rect))
  593. {
  594. OffsetRect(&rect, origin.x, origin.y);
  595. InvalidateRect(hwnd, &rect, FALSE);
  596. }
  597. }
  598. }
  599. else
  600. {
  601. KillTimer(hwnd, eventId);
  602. self->activityTimerEnabled = FALSE;
  603. }
  604. }
  605. static void CALLBACK
  606. ListWidget_BeginTitleEditTimerCb(HWND hwnd, UINT uMsg, UINT_PTR eventId, DWORD elpasedTime)
  607. {
  608. ListWidget *self;
  609. self = WIDGET_GET_SELF(hwnd, ListWidget);
  610. KillTimer(hwnd, eventId);
  611. if (NULL != self &&
  612. NULL != self->titleEditItem)
  613. {
  614. if (self->titleEditItem == self->selectedItem)
  615. {
  616. if (NULL != self->titleEditor)
  617. {
  618. DestroyWindow(self->titleEditor);
  619. self->titleEditor = NULL;
  620. }
  621. self->titleEditor = ListWidget_BeginItemTitleEdit(self, hwnd, self->titleEditItem);
  622. }
  623. self->titleEditItem = NULL;
  624. }
  625. }
  626. BOOL
  627. ListWidget_UpdateHoverEx(ListWidget *self, HWND hwnd, const POINT *cursor)
  628. {
  629. ListWidgetItem *hoveredItem;
  630. ListWidgetItemMetric metrics, *metrics_ptr;
  631. WidgetStyle *style;
  632. ListWidgetItemPart hoveredPart = ListWidgetItemPart_None;
  633. RECT rect, hoveredPartRect;
  634. POINT pt, origin;
  635. if (NULL == cursor)
  636. return FALSE;
  637. metrics_ptr = NULL;
  638. pt = *cursor;
  639. if (NULL != self->pressedCategory ||
  640. NULL != self->activeMenu ||
  641. 0 != (0x8000 & GetAsyncKeyState(VK_LBUTTON)) ||
  642. 0 != (0x8000 & GetAsyncKeyState(VK_RBUTTON)))
  643. {
  644. return FALSE;
  645. }
  646. if (FALSE == ListWidget_GetViewOrigin(hwnd, &origin))
  647. {
  648. origin.x = 0;
  649. origin.y = 0;
  650. }
  651. if (FALSE != GetClientRect(hwnd, &rect) &&
  652. FALSE != PtInRect(&rect, pt))
  653. {
  654. pt.x -= origin.x;
  655. pt.y -= origin.y;
  656. hoveredItem = ListWidget_GetItemFromPoint(self, pt);
  657. if (NULL != hoveredItem)
  658. {
  659. if (NULL == metrics_ptr)
  660. {
  661. style = WIDGET_GET_STYLE(hwnd);
  662. if (NULL != style &&
  663. FALSE != ListWidget_GetItemMetrics(style, &metrics))
  664. {
  665. metrics_ptr = &metrics;
  666. }
  667. }
  668. hoveredPart = ListWidgetItemPart_Frame |
  669. ListWidgetItemPart_Command |
  670. ListWidgetItemPart_Spacebar |
  671. ListWidgetItemPart_Title;
  672. hoveredPart = ListWidget_GetItemPartFromPoint(self, hoveredItem, metrics_ptr, pt, hoveredPart, &hoveredPartRect);
  673. }
  674. }
  675. else
  676. hoveredItem = NULL;
  677. if (NULL == hoveredItem)
  678. hoveredPart= ListWidgetItemPart_None;
  679. ListWidget_TooltipUpdate(self->tooltip, hoveredItem, hoveredPart, &hoveredPartRect);
  680. if (ListWidgetItemPart_None == ((ListWidgetItemPart_Frame | ListWidgetItemPart_Command | ListWidgetItemPart_Activity) & hoveredPart))
  681. hoveredItem = NULL;
  682. if (self->hoveredItem == hoveredItem)
  683. return FALSE;
  684. if (NULL == metrics_ptr)
  685. {
  686. style = WIDGET_GET_STYLE(hwnd);
  687. if (NULL != style &&
  688. FALSE != ListWidget_GetItemMetrics(style, &metrics))
  689. {
  690. metrics_ptr = &metrics;
  691. }
  692. }
  693. if (NULL != self->hoveredItem)
  694. {
  695. ListWidgetItem_UnsetHovered(self->hoveredItem);
  696. ListWidgetItem_UnsetInteractive(self->hoveredItem);
  697. if (NULL == metrics_ptr ||
  698. FALSE == ListWidget_GetItemFrameRect(self, self->hoveredItem, metrics_ptr, &rect))
  699. {
  700. CopyRect(&rect, &self->hoveredItem->rect);
  701. }
  702. OffsetRect(&rect, origin.x, origin.y);
  703. InvalidateRect(hwnd, &rect, FALSE);
  704. }
  705. if (NULL != hoveredItem)
  706. {
  707. ListWidgetItem_SetHovered(hoveredItem);
  708. if (NULL == metrics_ptr ||
  709. FALSE == ListWidget_GetItemFrameRect(self, hoveredItem, metrics_ptr, &rect))
  710. {
  711. CopyRect(&rect, &hoveredItem->rect);
  712. }
  713. OffsetRect(&rect, origin.x, origin.y);
  714. InvalidateRect(hwnd, &rect, FALSE);
  715. SetTimer(hwnd, LISTWIDGETTIMER_SHOW_COMMANDS_ID,
  716. LISTWIDGETTIMER_SHOW_COMMANDS_DELAY,
  717. ListWidget_ShowCommandTimerCb);
  718. }
  719. else
  720. KillTimer(hwnd, LISTWIDGETTIMER_SHOW_COMMANDS_ID);
  721. self->hoveredItem = hoveredItem;
  722. return TRUE;
  723. }
  724. BOOL
  725. ListWidget_UpdateHover(ListWidget *self, HWND hwnd)
  726. {
  727. POINT pt;
  728. if (FALSE == GetCursorPos(&pt))
  729. return FALSE;
  730. MapWindowPoints(HWND_DESKTOP, hwnd, &pt, 1);
  731. return ListWidget_UpdateHoverEx(self, hwnd, &pt);
  732. }
  733. BOOL
  734. ListWidget_RemoveHover(ListWidget *self, HWND hwnd, BOOL invalidate)
  735. {
  736. if (NULL == self)
  737. return FALSE;
  738. if (NULL == self->hoveredItem)
  739. return FALSE;
  740. ListWidgetItem_UnsetHovered(self->hoveredItem);
  741. ListWidgetItem_UnsetInteractive(self->hoveredItem);
  742. KillTimer(hwnd, LISTWIDGETTIMER_SHOW_COMMANDS_ID);
  743. if (FALSE != invalidate)
  744. {
  745. RECT rect;
  746. POINT origin;
  747. ListWidgetItemMetric metrics;
  748. WidgetStyle *style;
  749. style = WIDGET_GET_STYLE(hwnd);
  750. if (NULL == style ||
  751. FALSE == ListWidget_GetItemMetrics(style, &metrics) ||
  752. FALSE == ListWidget_GetItemFrameRect(self, self->hoveredItem, &metrics, &rect))
  753. {
  754. CopyRect(&rect, &self->hoveredItem->rect);
  755. }
  756. if (FALSE != ListWidget_GetViewOrigin(hwnd, &origin))
  757. OffsetRect(&rect, origin.x, origin.y);
  758. InvalidateRect(hwnd, &rect, FALSE);
  759. }
  760. self->hoveredItem = NULL;
  761. return TRUE;
  762. }
  763. void
  764. ListWidget_UpdateSelectionStatus(ListWidget *self, HWND hwnd, BOOL ensureVisible)
  765. {
  766. HWND statusWindow;
  767. if (NULL == self)
  768. return;
  769. statusWindow = GetParent(hwnd);
  770. if (NULL == statusWindow)
  771. return;
  772. statusWindow = MANAGERVIEW_GET_STATUS_BAR(statusWindow);
  773. if (NULL == statusWindow)
  774. return;
  775. if (NULL != self->selectedItem)
  776. {
  777. wchar_t buffer[2048] = {0};
  778. const wchar_t *statusString;
  779. if (FALSE == ListWidget_FormatItemStatus(self, self->selectedItem, buffer, ARRAYSIZE(buffer)) ||
  780. L'\0' == *buffer)
  781. {
  782. statusString = NULL;
  783. }
  784. else
  785. statusString = buffer;
  786. if (STATUS_ERROR == self->selectionStatus)
  787. {
  788. self->selectionStatus = STATUSBAR_ADD_STATUS(statusWindow, statusString);
  789. if (STATUS_ERROR != self->selectionStatus)
  790. {
  791. if (FALSE == ListWidget_FormatItemSpaceStatus(self, self->selectedItem, buffer, ARRAYSIZE(buffer)) ||
  792. L'\0' == *buffer)
  793. {
  794. statusString = NULL;
  795. }
  796. else
  797. statusString = buffer;
  798. STATUSBAR_SET_STATUS_RTEXT(statusWindow, self->selectionStatus, statusString);
  799. }
  800. }
  801. else
  802. {
  803. STATUSBAR_SET_STATUS_TEXT(statusWindow, self->selectionStatus, statusString);
  804. if (FALSE == ListWidget_FormatItemSpaceStatus(self, self->selectedItem, buffer, ARRAYSIZE(buffer)) ||
  805. L'\0' == *buffer)
  806. {
  807. statusString = NULL;
  808. }
  809. else
  810. statusString = buffer;
  811. STATUSBAR_SET_STATUS_RTEXT(statusWindow, self->selectionStatus, statusString);
  812. if (FALSE != ensureVisible)
  813. {
  814. STATUSBAR_MOVE_STATUS(statusWindow, self->selectionStatus, STATUS_MOVE_TOP);
  815. }
  816. }
  817. }
  818. else
  819. {
  820. if (STATUS_ERROR != self->selectionStatus)
  821. {
  822. STATUSBAR_REMOVE_STATUS(statusWindow, self->selectionStatus);
  823. self->selectionStatus = STATUS_ERROR;
  824. }
  825. }
  826. }
  827. void
  828. ListWidget_UpdateSelectionSpaceStatus(ListWidget *self, HWND hwnd, BOOL ensureVisible)
  829. {
  830. HWND statusWindow;
  831. if (NULL == self)
  832. return;
  833. statusWindow = GetParent(hwnd);
  834. if (NULL == statusWindow)
  835. return;
  836. statusWindow = MANAGERVIEW_GET_STATUS_BAR(statusWindow);
  837. if (NULL == statusWindow)
  838. return;
  839. if (NULL != self->selectedItem &&
  840. STATUS_ERROR != self->selectionStatus)
  841. {
  842. wchar_t buffer[2048] = {0};
  843. const wchar_t *statusString;
  844. if (FALSE == ListWidget_FormatItemSpaceStatus(self, self->selectedItem, buffer, ARRAYSIZE(buffer)) ||
  845. L'\0' == *buffer)
  846. {
  847. statusString = NULL;
  848. }
  849. else
  850. statusString = buffer;
  851. STATUSBAR_SET_STATUS_RTEXT(statusWindow, self->selectionStatus, statusString);
  852. if (FALSE != ensureVisible)
  853. STATUSBAR_MOVE_STATUS(statusWindow, self->selectionStatus, STATUS_MOVE_TOP);
  854. }
  855. }
  856. BOOL
  857. ListWidget_SelectItem(ListWidget *self, HWND hwnd, ListWidgetItem *item, BOOL ensureVisible)
  858. {
  859. BOOL invalidated;
  860. if (NULL == self)
  861. return FALSE;
  862. invalidated = FALSE;
  863. if (self->selectedItem != item)
  864. {
  865. RECT rect;
  866. POINT origin;
  867. ListWidgetItemMetric metrics, *metrics_ptr;
  868. WidgetStyle *style;
  869. if (FALSE == ListWidget_GetViewOrigin(hwnd, &origin))
  870. {
  871. origin.x = 0;
  872. origin.y = 0;
  873. }
  874. style = WIDGET_GET_STYLE(hwnd);
  875. if (NULL != style &&
  876. FALSE != ListWidget_GetItemMetrics(style, &metrics))
  877. {
  878. metrics_ptr = &metrics;
  879. }
  880. else
  881. metrics_ptr = NULL;
  882. if (NULL != self->selectedItem)
  883. {
  884. ListWidgetItem_UnsetSelected(self->selectedItem);
  885. if (NULL == metrics_ptr ||
  886. FALSE == ListWidget_GetItemFrameRect(self, self->selectedItem, metrics_ptr, &rect))
  887. {
  888. CopyRect(&rect, &self->selectedItem->rect);
  889. }
  890. OffsetRect(&rect, origin.x, origin.y);
  891. if (FALSE != InvalidateRect(hwnd, &rect, FALSE))
  892. invalidated = TRUE;
  893. }
  894. if (NULL != item)
  895. {
  896. ListWidgetItem_SetSelected(item);
  897. if (NULL == metrics_ptr ||
  898. FALSE == ListWidget_GetItemFrameRect(self, item, metrics_ptr, &rect))
  899. {
  900. CopyRect(&rect, &item->rect);
  901. }
  902. OffsetRect(&rect, origin.x, origin.y);
  903. if (FALSE != InvalidateRect(hwnd, &rect, FALSE))
  904. invalidated = TRUE;
  905. }
  906. self->selectedItem = item;
  907. }
  908. if (FALSE != ensureVisible)
  909. {
  910. if (FALSE != ListWidget_EnsureItemVisisble(self, hwnd, item, VISIBLE_NORMAL))
  911. invalidated = TRUE;
  912. }
  913. if (FALSE != invalidated)
  914. UpdateWindow(hwnd);
  915. ListWidget_UpdateSelectionStatus(self, hwnd, TRUE);
  916. return TRUE;
  917. }
  918. static void
  919. ListWidget_EnsureFocused(ListWidget *self, HWND hwnd, BOOL forceSelect)
  920. {
  921. HWND hDialog, hParent;
  922. if (NULL == self || NULL == hwnd)
  923. return;
  924. if (GetFocus() == hwnd)
  925. return;
  926. hDialog = NULL;
  927. hParent = hwnd;
  928. while(NULL != (hParent = GetAncestor(hParent, GA_PARENT)))
  929. {
  930. if (32770 != GetClassLongPtr(hParent, GCW_ATOM) ||
  931. 0 == (WS_EX_CONTROLPARENT & GetWindowStyleEx(hParent)))
  932. {
  933. break;
  934. }
  935. hDialog = hParent;
  936. }
  937. self->flags |= ListWidgetFlag_NoFocusSelect;
  938. if (NULL != hDialog)
  939. SendMessage(hDialog, WM_NEXTDLGCTL, (WPARAM)hwnd, TRUE);
  940. else
  941. SetFocus(hwnd);
  942. self->flags &= ~ListWidgetFlag_NoFocusSelect;
  943. }
  944. static BOOL
  945. ListWidget_EnsureTopVisible(ListWidget *self, HWND hwnd)
  946. {
  947. POINT pt;
  948. if (NULL == self || NULL == hwnd)
  949. return FALSE;
  950. if (FALSE == ListWidget_GetViewOrigin(hwnd, &pt) ||
  951. (0 == pt.x && 0 == pt.y))
  952. {
  953. return FALSE;
  954. }
  955. if (FALSE == WIDGET_SCROLL(hwnd, pt.x, pt.y, TRUE))
  956. return FALSE;
  957. ListWidget_UpdateHover(self, hwnd);
  958. return TRUE;
  959. }
  960. static BOOL
  961. ListWidget_EnsureBottomVisible(ListWidget *self, HWND hwnd)
  962. {
  963. SCROLLINFO scrollInfo;
  964. POINT pt;
  965. if (NULL == self || NULL == hwnd)
  966. return FALSE;
  967. scrollInfo.cbSize = sizeof(scrollInfo);
  968. scrollInfo.fMask = SIF_POS | SIF_RANGE | SIF_PAGE;
  969. if (FALSE != GetScrollInfo(hwnd, SB_HORZ, &scrollInfo))
  970. pt.x = -scrollInfo.nPos;
  971. else
  972. pt.x = 0;
  973. if (FALSE != GetScrollInfo(hwnd, SB_VERT, &scrollInfo) && 0 != scrollInfo.nPage)
  974. pt.y = (scrollInfo.nMax + 1 - scrollInfo.nPage) - scrollInfo.nPos;
  975. else
  976. pt.y = 0;
  977. if (0 == pt.x && 0 == pt.y)
  978. return FALSE;
  979. if (FALSE == WIDGET_SCROLL(hwnd, pt.x, pt.y, TRUE))
  980. return FALSE;
  981. ListWidget_UpdateHover(self, hwnd);
  982. return TRUE;
  983. }
  984. BOOL
  985. ListWidget_UpdateLayout(HWND hwnd, ListWidgetLayoutFlags layoutFlags)
  986. {
  987. BOOL result;
  988. unsigned int flags;
  989. ListWidget *self;
  990. POINT anchorPoint;
  991. ListWidgetItem *anchorItem;
  992. SCROLLINFO scrollInfo;
  993. HWND managerWindow, focusWindow;
  994. POINT pt, menuAnchor, hoverAnchor;
  995. self = WIDGET_GET_SELF(hwnd, ListWidget);
  996. if (NULL == self)
  997. return FALSE;
  998. if (NULL == self->activeMenu ||
  999. NULL == self->selectedItem ||
  1000. FALSE == ListWidget_GetViewItemPos(hwnd, self->selectedItem, &menuAnchor))
  1001. {
  1002. menuAnchor.x = 0x7FFFFFFF;
  1003. menuAnchor.y = 0x7FFFFFFF;
  1004. }
  1005. if (NULL != self->hoveredItem ||
  1006. FALSE == ListWidget_GetViewItemPos(hwnd, self->hoveredItem, &hoverAnchor))
  1007. {
  1008. hoverAnchor.x = 0x7FFFFFFF;
  1009. hoverAnchor.y = 0x7FFFFFFF;
  1010. }
  1011. scrollInfo.cbSize = sizeof(scrollInfo);
  1012. scrollInfo.fMask = SIF_POS;
  1013. anchorItem = NULL;
  1014. managerWindow = GetAncestor(hwnd, GA_PARENT);
  1015. if (NULL == managerWindow)
  1016. managerWindow = hwnd;
  1017. focusWindow = GetFocus();
  1018. if (0 != (ListWidgetLayout_KeepStable & layoutFlags) &&
  1019. (managerWindow == focusWindow || IsChild(managerWindow, focusWindow)))
  1020. {
  1021. if (NULL != self->selectedItem)
  1022. {
  1023. RECT clientRect;
  1024. GetClientRect(hwnd, &clientRect);
  1025. anchorPoint.x = (FALSE != GetScrollInfo(hwnd, SB_HORZ, &scrollInfo)) ?
  1026. -scrollInfo.nPos : 0;
  1027. anchorPoint.y = (FALSE != GetScrollInfo(hwnd, SB_VERT, &scrollInfo)) ?
  1028. -scrollInfo.nPos : 0;
  1029. OffsetRect(&clientRect, -anchorPoint.x, -anchorPoint.y);
  1030. if (clientRect.left <= self->selectedItem->rect.left &&
  1031. clientRect.top <= self->selectedItem->rect.top &&
  1032. clientRect.right >= self->selectedItem->rect.right &&
  1033. clientRect.bottom >= self->selectedItem->rect.bottom)
  1034. {
  1035. anchorItem = self->selectedItem;
  1036. anchorPoint.x += self->selectedItem->rect.left;
  1037. anchorPoint.y += self->selectedItem->rect.top;
  1038. }
  1039. }
  1040. }
  1041. flags = SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOMOVE | SWP_NOSIZE |
  1042. SWP_FRAMECHANGED | SWP_NOREDRAW;
  1043. result = SetWindowPos(hwnd, NULL, 0, 0, 0, 0, flags);
  1044. if (NULL != anchorItem)
  1045. {
  1046. long positionY;
  1047. positionY = anchorItem->rect.top;
  1048. if (FALSE != GetScrollInfo(hwnd, SB_VERT, &scrollInfo))
  1049. positionY -= scrollInfo.nPos;
  1050. if (positionY != anchorPoint.y)
  1051. WIDGET_SET_SCROLL_POS(hwnd, 0, positionY - anchorPoint.y, FALSE);
  1052. }
  1053. if (0x7FFFFFFF != menuAnchor.x &&
  1054. NULL != self->selectedItem &&
  1055. FALSE != ListWidget_GetViewItemPos(hwnd, self->selectedItem, &pt) &&
  1056. menuAnchor.x != pt.x && menuAnchor.y != pt.y)
  1057. {
  1058. if (NULL != self->activeMenu)
  1059. EndMenu();
  1060. }
  1061. if (0x7FFFFFFF != hoverAnchor.x &&
  1062. NULL != self->hoveredItem &&
  1063. FALSE != ListWidget_GetViewItemPos(hwnd, self->hoveredItem, &pt) &&
  1064. hoverAnchor.x != pt.x && hoverAnchor.y != pt.y)
  1065. {
  1066. ListWidget_UpdateHover(self, hwnd);
  1067. }
  1068. if (0 == (ListWidgetLayout_NoRedraw & layoutFlags))
  1069. {
  1070. flags = RDW_INVALIDATE | RDW_ALLCHILDREN | RDW_FRAME | RDW_ERASE;
  1071. if (0 != (ListWidgetLayout_UpdateNow & layoutFlags))
  1072. flags |= (RDW_ERASENOW | RDW_UPDATENOW);
  1073. RedrawWindow(hwnd, NULL, NULL, flags);
  1074. }
  1075. return result;
  1076. }
  1077. double
  1078. ListWidget_GetZoomRatio(ListWidget *self)
  1079. {
  1080. if (NULL == self)
  1081. return 1.0;
  1082. if (self->imageSize.cy > LISTWIDGET_IMAGE_DEFAULT_HEIGHT)
  1083. {
  1084. return (1.0 + (double)(self->imageSize.cy - LISTWIDGET_IMAGE_DEFAULT_HEIGHT)/
  1085. (LISTWIDGET_IMAGE_MAX_HEIGHT - LISTWIDGET_IMAGE_DEFAULT_HEIGHT));
  1086. }
  1087. return (double)(self->imageSize.cy - LISTWIDGET_IMAGE_MIN_HEIGHT)/
  1088. (LISTWIDGET_IMAGE_DEFAULT_HEIGHT - LISTWIDGET_IMAGE_MIN_HEIGHT);
  1089. }
  1090. long
  1091. ListWidget_GetZoomedValue(double zoomRatio, long normal, long min, long max)
  1092. {
  1093. if (zoomRatio < 1.0)
  1094. return min + (long)floor((double)(normal - min) * zoomRatio);
  1095. else if (zoomRatio > 1.0)
  1096. return normal + (long)ceil((double)(max - normal) * (zoomRatio - 1.0));
  1097. return normal;
  1098. }
  1099. static BOOL
  1100. ListWidget_UpdateActivityLayout(ListWidget *self, HWND hwnd, double zoomRatio)
  1101. {
  1102. LOGFONTW lf;
  1103. HDC windowDC;
  1104. long elementHeight, titleMinWidth, workHeight;
  1105. ListWidgetItem *item;
  1106. ListWidgetActivityMetric *activityMetrics;
  1107. // always reset items activity size cache
  1108. size_t index = (self ? self->activeItems.size() : NULL);
  1109. while(index--)
  1110. {
  1111. item = self->activeItems[index];
  1112. if (NULL != item)
  1113. SetSizeEmpty(&item->activity->titleSize);
  1114. }
  1115. if (NULL == self)
  1116. return FALSE;
  1117. activityMetrics = &self->activityMetrics;
  1118. activityMetrics->offsetLeft = self->activityMetrics.height/16;
  1119. if (activityMetrics->offsetLeft < 1)
  1120. activityMetrics->offsetLeft = 1;
  1121. activityMetrics->offsetRight = activityMetrics->offsetLeft;
  1122. activityMetrics->offsetTop = self->activityMetrics.height/9;
  1123. if (activityMetrics->offsetTop < 3)
  1124. activityMetrics->offsetTop = 3;
  1125. activityMetrics->offsetBottom = activityMetrics->offsetTop;
  1126. activityMetrics->spacing = 4 + self->activityMetrics.height/16;
  1127. workHeight = activityMetrics->height - (activityMetrics->offsetTop + activityMetrics->offsetBottom);
  1128. activityMetrics->fontHeight = workHeight/2;
  1129. if (activityMetrics->fontHeight < 8)
  1130. activityMetrics->fontHeight = 8;
  1131. if (NULL == self->activityFont ||
  1132. sizeof(lf) != GetObject(self->activityFont, sizeof(lf), &lf) ||
  1133. lf.lfHeight != activityMetrics->fontHeight)
  1134. {
  1135. if (NULL != self->activityFont)
  1136. DeleteObject(self->activityFont);
  1137. lf.lfHeight = activityMetrics->fontHeight;
  1138. lf.lfWidth = 0;
  1139. lf.lfEscapement = 0;
  1140. lf.lfOrientation = 0;
  1141. lf.lfWeight = FW_NORMAL;
  1142. lf.lfItalic = FALSE;
  1143. lf.lfUnderline = FALSE;
  1144. lf.lfStrikeOut = FALSE;
  1145. lf.lfCharSet = DEFAULT_CHARSET;
  1146. lf.lfOutPrecision = OUT_TT_PRECIS;
  1147. lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
  1148. lf.lfQuality = Graphics_GetSysFontQuality();
  1149. lf.lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE;
  1150. StringCchCopy(lf.lfFaceName, ARRAYSIZE(lf.lfFaceName), L"Arial"/*L"Times New Roman"*/);
  1151. self->activityFont = CreateFontIndirect(&lf);
  1152. }
  1153. activityMetrics->titleHeight = workHeight;
  1154. if (activityMetrics->titleHeight < 0)
  1155. activityMetrics->titleHeight = 0;
  1156. activityMetrics->titleWidth = 0;
  1157. activityMetrics->percentWidth = 0;
  1158. activityMetrics->percentHeight = 0;
  1159. titleMinWidth = 0;
  1160. windowDC = GetWindowDC(hwnd);
  1161. if (NULL != windowDC)
  1162. {
  1163. SIZE textSize;
  1164. HFONT prevFont;
  1165. prevFont = SelectFont(windowDC, self->activityFont);
  1166. if (FALSE == GetTextExtentPoint32(windowDC, L"00%", 3, &textSize))
  1167. SetSizeEmpty(&textSize);
  1168. if (textSize.cy <= workHeight)
  1169. {
  1170. activityMetrics->fontHeight = textSize.cy;
  1171. activityMetrics->percentHeight = textSize.cy;
  1172. activityMetrics->percentWidth = textSize.cx;
  1173. }
  1174. titleMinWidth = Graphics_GetAveStrWidth(windowDC, 6);
  1175. activityMetrics->spacing = Graphics_GetAveStrWidth(windowDC, 1) - 2;
  1176. }
  1177. if (NULL != self->activityBadgeBitmap)
  1178. {
  1179. DeleteObject(self->activityBadgeBitmap);
  1180. self->activityBadgeBitmap = NULL;
  1181. }
  1182. elementHeight = (long)(18.0 * (double)workHeight/28.0);
  1183. if (activityMetrics->progressWidth != elementHeight ||
  1184. activityMetrics->progressHeight != elementHeight)
  1185. {
  1186. activityMetrics->progressWidth = elementHeight;
  1187. activityMetrics->progressHeight = elementHeight;
  1188. if (NULL != self->activityProgressImage)
  1189. {
  1190. DeviceImage_Release(self->activityProgressImage);
  1191. self->activityProgressImage = NULL;
  1192. }
  1193. }
  1194. for(;;)
  1195. {
  1196. activityMetrics->titleWidth = activityMetrics->width -
  1197. (activityMetrics->offsetLeft + activityMetrics->offsetRight);
  1198. if(0 != activityMetrics->progressWidth)
  1199. activityMetrics->titleWidth -= (activityMetrics->progressWidth + activityMetrics->spacing);
  1200. if(0 != activityMetrics->percentWidth)
  1201. activityMetrics->titleWidth -= (activityMetrics->percentWidth + activityMetrics->spacing);
  1202. if (activityMetrics->titleWidth < titleMinWidth)
  1203. {
  1204. if (0 != activityMetrics->percentWidth)
  1205. {
  1206. activityMetrics->percentWidth = 0;
  1207. activityMetrics->percentHeight = 0;
  1208. continue;
  1209. }
  1210. if (0 != activityMetrics->progressWidth)
  1211. {
  1212. activityMetrics->progressWidth = 0;
  1213. activityMetrics->progressHeight = 0;
  1214. continue;
  1215. }
  1216. activityMetrics->titleWidth = 0;
  1217. activityMetrics->titleHeight = 0;
  1218. }
  1219. break;
  1220. }
  1221. return TRUE;
  1222. }
  1223. BOOL
  1224. ListWidget_SetImageSize(ListWidget *self, HWND hwnd, int imageWidth, int imageHeight, BOOL redraw)
  1225. {
  1226. size_t iCategory, iGroup, iItem;
  1227. ListWidgetCategory *category;
  1228. ListWidgetGroup *group;
  1229. ListWidgetItem *item;
  1230. long elementWidth, elementHeight;
  1231. double zoomRatio;
  1232. if (NULL == self)
  1233. return FALSE;
  1234. SetSize(&self->imageSize, imageWidth, imageHeight);
  1235. zoomRatio = ListWidget_GetZoomRatio(self);
  1236. for (iCategory = 0; iCategory < self->categories.size(); iCategory++)
  1237. {
  1238. category = self->categories[iCategory];
  1239. for(iGroup = 0; iGroup < category->groups.size(); iGroup++)
  1240. {
  1241. group = category->groups[iGroup];
  1242. for(iItem = 0; iItem < group->items.size(); iItem++)
  1243. {
  1244. item = group->items[iItem];
  1245. if (NULL != item->image)
  1246. {
  1247. DeviceImage_Release(item->image);
  1248. item->image = NULL;
  1249. }
  1250. SetSize(&item->titleSize, -1, -1);
  1251. }
  1252. }
  1253. }
  1254. // connetion size
  1255. elementHeight = ListWidget_GetZoomedValue(zoomRatio, LISTWIDGET_CONNECTION_DEFAULT_HEIGHT,
  1256. LISTWIDGET_CONNECTION_MIN_HEIGHT, LISTWIDGET_CONNECTION_MAX_HEIGHT);
  1257. elementWidth = elementHeight;
  1258. if (self->connectionSize.cx != elementWidth ||
  1259. self->connectionSize.cy != elementHeight)
  1260. {
  1261. SetSize(&self->connectionSize, elementWidth, elementHeight);
  1262. int index = (int)self->connections.size();
  1263. while (index--)
  1264. {
  1265. ListWidget_UpdateConnectionImageSize(self->connections[index],
  1266. self->connectionSize.cx, self->connectionSize.cy);
  1267. }
  1268. }
  1269. // primary command
  1270. elementHeight = ListWidget_GetZoomedValue(zoomRatio, LISTWIDGET_PRIMARYCOMMAND_DEFAULT_HEIGHT,
  1271. LISTWIDGET_PRIMARYCOMMAND_MIN_HEIGHT, LISTWIDGET_PRIMARYCOMMAND_MAX_HEIGHT);
  1272. elementWidth = self->imageSize.cx;
  1273. if (self->primaryCommandSize.cx != elementWidth ||
  1274. self->primaryCommandSize.cy != elementHeight)
  1275. {
  1276. SetSize(&self->primaryCommandSize, elementWidth, elementHeight);
  1277. }
  1278. // secondary command
  1279. elementHeight = ListWidget_GetZoomedValue(zoomRatio, LISTWIDGET_SECONDARYCOMMAND_DEFAULT_HEIGHT,
  1280. LISTWIDGET_SECONDARYCOMMAND_MIN_HEIGHT, LISTWIDGET_SECONDARYCOMMAND_MAX_HEIGHT);
  1281. elementWidth = elementHeight;
  1282. if (self->secondaryCommandSize.cx != elementWidth ||
  1283. self->secondaryCommandSize.cy != elementHeight)
  1284. {
  1285. SetSize(&self->secondaryCommandSize, elementWidth, elementHeight);
  1286. }
  1287. // activity
  1288. elementHeight = ListWidget_GetZoomedValue(zoomRatio, LISTWIDGET_ACTIVITY_DEFAULT_HEIGHT,
  1289. LISTWIDGET_ACTIVITY_MIN_HEIGHT, LISTWIDGET_ACTIVITY_MAX_HEIGHT);
  1290. elementWidth = self->imageSize.cx;
  1291. if (self->activityMetrics.width != elementWidth ||
  1292. self->activityMetrics.height != elementHeight)
  1293. {
  1294. self->activityMetrics.width = elementWidth;
  1295. self->activityMetrics.height = elementHeight;
  1296. }
  1297. ListWidget_UpdateLayout(hwnd, ListWidgetLayout_NoRedraw);
  1298. if (NULL != self->hoveredItem &&
  1299. FALSE != ListWidgetItem_IsInteractive(self->hoveredItem))
  1300. {
  1301. ListWidget_UpdateActiveCommands(self, hwnd);
  1302. }
  1303. ListWidget_UpdateActivityLayout(self, hwnd, zoomRatio);
  1304. if (FALSE != redraw)
  1305. {
  1306. RedrawWindow(hwnd, NULL, NULL,
  1307. RDW_INVALIDATE | RDW_ERASE | RDW_ERASENOW | RDW_UPDATENOW | RDW_ALLCHILDREN);
  1308. }
  1309. return TRUE;
  1310. }
  1311. BOOL
  1312. ListWidget_DisplayContextMenu(ListWidget *self, HWND hostWindow, POINT pt)
  1313. {
  1314. return FALSE;
  1315. }
  1316. BOOL
  1317. ListWidget_RegisterActiveItem(ListWidget *self, HWND hwnd, ListWidgetItem *item)
  1318. {
  1319. size_t index;
  1320. if (NULL == self || NULL == item)
  1321. return FALSE;
  1322. index = self->activeItems.size();
  1323. while(index--)
  1324. {
  1325. if (item == self->activeItems[index])
  1326. return FALSE;
  1327. }
  1328. self->activeItems.push_back(item);
  1329. if (1 == self->activeItems.size())
  1330. {
  1331. if (0 != SetTimer(hwnd, LISTWIDGETTIMER_PROGRESS_TICK_ID,
  1332. LISTWIDGETTIMER_PROGRESS_TICK_DELAY, ListWidget_ProgressTickCb))
  1333. {
  1334. self->activityTimerEnabled = TRUE;
  1335. }
  1336. }
  1337. return TRUE;
  1338. }
  1339. BOOL
  1340. ListWidget_UnregisterActiveItem(ListWidget *self, HWND hwnd, ListWidgetItem *item)
  1341. {
  1342. size_t index;
  1343. if (NULL == self || NULL == item)
  1344. return FALSE;
  1345. index = self->activeItems.size();
  1346. while(index--)
  1347. {
  1348. if (item == self->activeItems[index])
  1349. {
  1350. self->activeItems.erase(self->activeItems.begin() + index);
  1351. if (0 == self->activeItems.size())
  1352. {
  1353. KillTimer(hwnd, LISTWIDGETTIMER_PROGRESS_TICK_ID);
  1354. self->activityTimerEnabled = FALSE;
  1355. }
  1356. return TRUE;
  1357. }
  1358. }
  1359. return FALSE;
  1360. }
  1361. static void
  1362. ListWidget_CallItemAction(ListWidget *self, HWND hwnd, ListWidgetCategory *category, ListWidgetItem *item)
  1363. {
  1364. ifc_device *device;
  1365. if (NULL == self || NULL == item)
  1366. return;
  1367. if (NULL == category)
  1368. {
  1369. if (FALSE == ListWidget_GetItemOwner(self, item, &category) ||
  1370. NULL == category)
  1371. {
  1372. return;
  1373. }
  1374. }
  1375. if (NULL == WASABI_API_DEVICES ||
  1376. S_OK != WASABI_API_DEVICES->DeviceFind(item->name, &device))
  1377. {
  1378. return;
  1379. }
  1380. if (CSTR_EQUAL == CompareStringA(CSTR_INVARIANT, 0, category->name, -1, "discovered", -1))
  1381. {
  1382. if (FALSE == device->GetAttached())
  1383. device->Attach(NULL);
  1384. }
  1385. if (CSTR_EQUAL == CompareStringA(CSTR_INVARIANT, 0, category->name, -1, "attached", -1))
  1386. {
  1387. Navigation_SelectDevice(device->GetName());
  1388. }
  1389. device->Release();
  1390. }
  1391. static BOOL
  1392. ListWidget_AddDevicesToCategory(ListWidget *self, ListWidgetCategory *category, DeviceList *list)
  1393. {
  1394. ListWidgetGroup *group;
  1395. ListWidgetItem *item;
  1396. ifc_device *device;
  1397. size_t index, groupCount, categoryCount;
  1398. if (NULL == list || NULL == category)
  1399. return FALSE;
  1400. categoryCount = category->groups.size();
  1401. index = list->size();
  1402. if (0 == index)
  1403. return FALSE;
  1404. do
  1405. {
  1406. index--;
  1407. device = list->at(index);
  1408. const char *groupName = device->GetType();
  1409. group = ListWidget_FindGroupEx(category, groupName, categoryCount);
  1410. if (NULL == group)
  1411. {
  1412. group = ListWidget_CreateGroup(groupName);
  1413. if (NULL != group)
  1414. ListWidget_AddGroup(category, group);
  1415. }
  1416. if (NULL != group)
  1417. {
  1418. groupCount = group->items.size();
  1419. item = ListWidget_FindGroupItemEx(group, device->GetName(), groupCount);
  1420. if (NULL == item)
  1421. {
  1422. item = ListWidget_CreateItemFromDevice(self, device);
  1423. if (NULL != item)
  1424. {
  1425. ListWidget_AddItem(group, item);
  1426. if (NULL != item->activity)
  1427. self->activeItems.push_back(item);
  1428. }
  1429. }
  1430. }
  1431. else
  1432. groupCount = 0;
  1433. list->erase(list->begin() + index);
  1434. device->Release();
  1435. while(index--)
  1436. {
  1437. device = list->at(index);
  1438. if (CSTR_EQUAL == CompareStringA(CSTR_INVARIANT, 0, groupName, -1, device->GetType(), -1))
  1439. {
  1440. if (NULL != group)
  1441. {
  1442. item = ListWidget_FindGroupItemEx(group, device->GetName(), groupCount);
  1443. if (NULL == item)
  1444. {
  1445. item = ListWidget_CreateItemFromDevice(self, device);
  1446. if (NULL != item)
  1447. {
  1448. ListWidget_AddItem(group, item);
  1449. if (NULL != item->activity)
  1450. {
  1451. self->activeItems.push_back(item);
  1452. }
  1453. }
  1454. }
  1455. }
  1456. list->erase(list->begin() + index);
  1457. device->Release();
  1458. }
  1459. }
  1460. if (NULL != group)
  1461. ListWidget_SortGroup(group);
  1462. index = list->size();
  1463. } while(0 != index);
  1464. ListWidget_SortCategory(category);
  1465. return TRUE;
  1466. }
  1467. static void
  1468. ListWidget_AddExistingDevices(ListWidget *self, HWND hwnd)
  1469. {
  1470. DeviceList discoveredList, attachedList;
  1471. ifc_device *device;
  1472. ListWidgetCategory *category;
  1473. size_t index, activeItemsCount;
  1474. BOOL devicesAdded;
  1475. if (NULL == self)
  1476. return;
  1477. activeItemsCount = self->activeItems.size();
  1478. if (NULL != WASABI_API_DEVICES)
  1479. {
  1480. ifc_deviceobjectenum *enumerator;
  1481. if (SUCCEEDED(WASABI_API_DEVICES->DeviceEnumerate(&enumerator)))
  1482. {
  1483. size_t reserveSize;
  1484. ifc_deviceobject *object;
  1485. if (SUCCEEDED(enumerator->GetCount(&reserveSize)))
  1486. {
  1487. discoveredList.reserve(reserveSize);
  1488. attachedList.reserve(reserveSize);
  1489. }
  1490. while(S_OK == enumerator->Next(&object, 1, NULL))
  1491. {
  1492. if (SUCCEEDED(object->QueryInterface(IFC_Device, (void**)&device)))
  1493. {
  1494. if (FALSE == device->GetHidden() &&
  1495. // excludes 'cloud' devices from appearing
  1496. lstrcmpiA(device->GetConnection(), "cloud"))
  1497. {
  1498. if (FALSE == device->GetAttached())
  1499. discoveredList.push_back(device);
  1500. else
  1501. attachedList.push_back(device);
  1502. }
  1503. else
  1504. device->Release();
  1505. }
  1506. object->Release();
  1507. }
  1508. enumerator->Release();
  1509. }
  1510. }
  1511. devicesAdded = FALSE;
  1512. if (0 != attachedList.size())
  1513. {
  1514. category = ListWidget_FindCategory(self, "attached");
  1515. if (NULL != category)
  1516. {
  1517. if (FALSE != ListWidget_AddDevicesToCategory(self, category, &attachedList))
  1518. {
  1519. ListWidget_ResetCategoryCounter(category);
  1520. devicesAdded = TRUE;
  1521. }
  1522. }
  1523. index = attachedList.size();
  1524. while(index--)
  1525. attachedList[index]->Release();
  1526. }
  1527. if (0 != discoveredList.size())
  1528. {
  1529. category = ListWidget_FindCategory(self, "discovered");
  1530. if (NULL != category)
  1531. {
  1532. if (FALSE != ListWidget_AddDevicesToCategory(self, category, &discoveredList))
  1533. {
  1534. ListWidget_ResetCategoryCounter(category);
  1535. devicesAdded = TRUE;
  1536. }
  1537. }
  1538. index = discoveredList.size();
  1539. while(index--)
  1540. discoveredList[index]->Release();
  1541. }
  1542. if (self->activeItems.size() > 0)
  1543. {
  1544. if (0 == activeItemsCount)
  1545. {
  1546. if (0 != SetTimer(hwnd, LISTWIDGETTIMER_PROGRESS_TICK_ID,
  1547. LISTWIDGETTIMER_PROGRESS_TICK_DELAY, ListWidget_ProgressTickCb))
  1548. {
  1549. self->activityTimerEnabled = TRUE;
  1550. }
  1551. }
  1552. }
  1553. else
  1554. {
  1555. if (0 != activeItemsCount)
  1556. {
  1557. KillTimer(hwnd, LISTWIDGETTIMER_PROGRESS_TICK_ID);
  1558. self->activityTimerEnabled = FALSE;
  1559. }
  1560. }
  1561. if (FALSE != devicesAdded)
  1562. {
  1563. ListWidget_UpdateLayout(hwnd, ListWidgetLayout_Normal);
  1564. }
  1565. }
  1566. void
  1567. ListWidget_UpdateTitleEditorColors(HWND editor, WidgetStyle *style)
  1568. {
  1569. if (NULL == editor || NULL == style)
  1570. return;
  1571. EMBEDDEDEDITOR_SET_TEXT_COLOR(editor, WIDGETSTYLE_TEXT_COLOR(style));
  1572. EMBEDDEDEDITOR_SET_BACK_COLOR(editor, WIDGETSTYLE_BACK_COLOR(style));
  1573. EMBEDDEDEDITOR_SET_BORDER_COLOR(editor, WIDGETSTYLE_TEXT_EDITOR_BORDER_COLOR(style));
  1574. InvalidateRect(editor, NULL, TRUE);
  1575. }
  1576. static BOOL
  1577. ListWidget_DeviceAdd(HWND hwnd, ifc_device *device, DeviceImage *deviceImage)
  1578. {
  1579. ListWidget *self;
  1580. ListWidgetCategory *category;
  1581. ListWidgetGroup *group;
  1582. ListWidgetItem *item;
  1583. self = WIDGET_GET_SELF(hwnd, ListWidget);
  1584. if (NULL == self)
  1585. return FALSE;
  1586. if (NULL == self ||
  1587. NULL == device ||
  1588. FALSE != device->GetHidden() &&
  1589. // excludes 'cloud' devices from appearing
  1590. lstrcmpiA(device->GetConnection(), "cloud"))
  1591. {
  1592. return FALSE;
  1593. }
  1594. category = ListWidget_FindCategory(self, (FALSE != device->GetAttached()) ? "attached" : "discovered");
  1595. if (NULL == category)
  1596. return FALSE;
  1597. group = ListWidget_FindGroup(category, device->GetType());
  1598. if (NULL == group)
  1599. {
  1600. group = ListWidget_CreateGroup(device->GetType());
  1601. if (NULL == group)
  1602. return FALSE;
  1603. ListWidget_AddGroup(category, group);
  1604. ListWidget_SortCategory(category);
  1605. }
  1606. item = ListWidget_FindGroupItem(group, device->GetName());
  1607. if (NULL != item)
  1608. return FALSE;
  1609. item = ListWidget_CreateItemFromDevice(self, device);
  1610. if (NULL == item)
  1611. return NULL;
  1612. if (NULL == item->image && NULL != deviceImage)
  1613. {
  1614. item->image = deviceImage;
  1615. DeviceImage_AddRef(item->image);
  1616. }
  1617. ListWidget_AddItem(group, item);
  1618. ListWidget_SortGroup(group);
  1619. if (NULL != item->activity)
  1620. ListWidget_RegisterActiveItem(self, hwnd, item);
  1621. ListWidget_ResetCategoryCounter(category);
  1622. if (FALSE == category->collapsed)
  1623. {
  1624. ListWidget_UpdateLayout(hwnd,
  1625. ListWidgetLayout_UpdateNow | ListWidgetLayout_KeepStable);
  1626. }
  1627. else
  1628. {
  1629. RECT rect;
  1630. POINT origin;
  1631. CopyRect(&rect, &category->rect);
  1632. if (FALSE != ListWidget_GetViewOrigin(hwnd, &origin))
  1633. OffsetRect(&rect, origin.x, origin.y);
  1634. InvalidateRect(hwnd, &rect, FALSE);
  1635. }
  1636. return TRUE;
  1637. }
  1638. static BOOL
  1639. ListWidget_DeviceRemove(HWND hwnd, ifc_device *device)
  1640. {
  1641. ListWidget *self;
  1642. self = WIDGET_GET_SELF(hwnd, ListWidget);
  1643. if (NULL == self || NULL == device)
  1644. return FALSE;
  1645. ListWidget_RemoveItem(self, hwnd, device->GetName());
  1646. ListWidget_UpdateHover(self, hwnd);
  1647. return TRUE;
  1648. }
  1649. static BOOL
  1650. ListWidget_DeviceAttach(HWND hwnd, ifc_device *device)
  1651. {
  1652. ListWidget *self;
  1653. ListWidgetCategory *category;
  1654. ListWidgetItem *item;
  1655. DeviceImage *image;
  1656. BOOL result;
  1657. self = WIDGET_GET_SELF(hwnd, ListWidget);
  1658. if (NULL == self || NULL == device)
  1659. return FALSE;
  1660. image = NULL;
  1661. category = ListWidget_FindCategory(self, "discovered");
  1662. if (NULL != category)
  1663. {
  1664. ListWidgetGroup *group = ListWidget_FindGroup(category, device->GetType());
  1665. if (NULL != group)
  1666. {
  1667. item = ListWidget_FindGroupItem(group, device->GetName());
  1668. if (NULL != item)
  1669. {
  1670. image = item->image;
  1671. if (NULL != image)
  1672. DeviceImage_AddRef(image);
  1673. ListWidget_RemoveItem(self, hwnd, device->GetName());
  1674. }
  1675. }
  1676. }
  1677. result = ListWidget_DeviceAdd(hwnd, device, image);
  1678. if (NULL != image)
  1679. DeviceImage_Release(image);
  1680. return result;
  1681. }
  1682. static BOOL
  1683. ListWidget_DeviceDetach(HWND hwnd, ifc_device *device)
  1684. {
  1685. ListWidget *self;
  1686. ListWidgetCategory *category;
  1687. ListWidgetItem *item;
  1688. DeviceImage *image;
  1689. BOOL result;
  1690. self = WIDGET_GET_SELF(hwnd, ListWidget);
  1691. if (NULL == self || NULL == device)
  1692. return FALSE;
  1693. image = NULL;
  1694. category = ListWidget_FindCategory(self, "attached");
  1695. if (NULL != category)
  1696. {
  1697. ListWidgetGroup *group = ListWidget_FindGroup(category, device->GetType());
  1698. if (NULL != group)
  1699. {
  1700. item = ListWidget_FindGroupItem(group, device->GetName());
  1701. if (NULL != item)
  1702. {
  1703. image = item->image;
  1704. if (NULL != image)
  1705. DeviceImage_AddRef(image);
  1706. ListWidget_RemoveItem(self, hwnd, device->GetName());
  1707. }
  1708. }
  1709. }
  1710. result = ListWidget_DeviceAdd(hwnd, device, image);
  1711. if (NULL != image)
  1712. DeviceImage_Release(image);
  1713. return result;
  1714. }
  1715. static BOOL
  1716. ListWidget_DeviceTitleChanged(HWND hwnd, ifc_device *device)
  1717. {
  1718. ListWidget *self;
  1719. ListWidgetItem *item;
  1720. ListWidgetCategory *category;
  1721. wchar_t buffer[1024] = {0};
  1722. self = WIDGET_GET_SELF(hwnd, ListWidget);
  1723. if (NULL == self || NULL == device)
  1724. return FALSE;
  1725. item = ListWidget_FindItem(self, device->GetName(), &category, NULL);
  1726. if (NULL == item)
  1727. return FALSE;
  1728. if (FAILED(device->GetDisplayName(buffer, ARRAYSIZE(buffer))))
  1729. return FALSE;
  1730. ListWidget_SetItemTitle(item, buffer);
  1731. if (NULL == category ||
  1732. FALSE == category->collapsed)
  1733. {
  1734. ListWidget_UpdateLayout(hwnd, ListWidgetLayout_UpdateNow | ListWidgetLayout_KeepStable);
  1735. ListWidget_TooltipUpdateText(self, self->tooltip, item, Tooltip_DeviceTitleChanged);
  1736. if (STATUS_ERROR != self->selectionStatus &&
  1737. item == self->selectedItem)
  1738. {
  1739. ListWidget_UpdateSelectionStatus(self, hwnd, FALSE);
  1740. }
  1741. }
  1742. return TRUE;
  1743. }
  1744. static BOOL
  1745. ListWidget_DeviceSpaceChanged(HWND hwnd, ifc_device *device)
  1746. {
  1747. ListWidget *self;
  1748. ListWidgetItem *item;
  1749. ListWidgetCategory *category;
  1750. self = WIDGET_GET_SELF(hwnd, ListWidget);
  1751. if (NULL == self || NULL == device)
  1752. return FALSE;
  1753. item = ListWidget_FindItem(self, device->GetName(), &category, NULL);
  1754. if (NULL == item)
  1755. return FALSE;
  1756. if (FAILED(device->GetTotalSpace(&item->spaceTotal)))
  1757. return FALSE;
  1758. if (FAILED(device->GetUsedSpace(&item->spaceUsed)))
  1759. return FALSE;
  1760. if (NULL == category ||
  1761. FALSE == category->collapsed)
  1762. {
  1763. RECT rect;
  1764. POINT origin;
  1765. ListWidgetItemMetric metrics;
  1766. WidgetStyle *style;
  1767. CopyRect(&rect, &item->rect);
  1768. if (FALSE != ListWidget_GetViewOrigin(hwnd, &origin))
  1769. OffsetRect(&rect, origin.x, origin.y);
  1770. style = WIDGET_GET_STYLE(hwnd);
  1771. if (NULL != style && FALSE != ListWidget_GetItemMetrics(style, &metrics))
  1772. {
  1773. rect.top += metrics.offsetTop +
  1774. metrics.imageOffsetTop +
  1775. self->imageSize.cy +
  1776. metrics.imageOffsetBottom +
  1777. metrics.spacebarOffsetTop;
  1778. rect.left += metrics.offsetLeft;
  1779. rect.right -= metrics.offsetRight;
  1780. rect.bottom = rect.top + metrics.spacebarHeight;
  1781. }
  1782. InvalidateRect(hwnd, &rect, FALSE);
  1783. UpdateWindow(hwnd);
  1784. ListWidget_TooltipUpdateText(self, self->tooltip, item, Tooltip_DeviceSpaceChanged);
  1785. if (STATUS_ERROR != self->selectionStatus &&
  1786. item == self->selectedItem)
  1787. {
  1788. ListWidget_UpdateSelectionSpaceStatus(self, hwnd, FALSE);
  1789. }
  1790. }
  1791. return TRUE;
  1792. }
  1793. static BOOL
  1794. ListWidget_DeviceIconChanged(HWND hwnd, ifc_device *device)
  1795. {
  1796. ListWidget *self;
  1797. ListWidgetItem *item;
  1798. ListWidgetCategory *category;
  1799. DeviceImage *previousImage;
  1800. self = WIDGET_GET_SELF(hwnd, ListWidget);
  1801. if (NULL == self || NULL == device)
  1802. return FALSE;
  1803. item = ListWidget_FindItem(self, device->GetName(), &category, NULL);
  1804. if (NULL == item)
  1805. return FALSE;
  1806. previousImage = item->image;
  1807. item->image = NULL;
  1808. if (NULL == category ||
  1809. FALSE == category->collapsed)
  1810. {
  1811. RECT rect;
  1812. POINT origin;
  1813. ListWidgetItemMetric metrics;
  1814. WidgetStyle *style;
  1815. style = WIDGET_GET_STYLE(hwnd);
  1816. if (NULL == style ||
  1817. FALSE == ListWidget_GetItemMetrics(style, &metrics) ||
  1818. FALSE == ListWidget_GetItemImageRect(self, item, &metrics, &rect))
  1819. {
  1820. CopyRect(&rect, &item->rect);
  1821. }
  1822. if (FALSE != ListWidget_GetViewOrigin(hwnd, &origin))
  1823. OffsetRect(&rect, origin.x, origin.y);
  1824. InvalidateRect(hwnd, &rect, FALSE);
  1825. UpdateWindow(hwnd);
  1826. }
  1827. if (NULL != previousImage)
  1828. DeviceImage_Release(previousImage);
  1829. return TRUE;
  1830. }
  1831. static BOOL
  1832. ListWidget_DeviceCommandChanged(HWND hwnd, ifc_device *device)
  1833. {
  1834. ListWidget *self;
  1835. ListWidgetItem *item;
  1836. self = WIDGET_GET_SELF(hwnd, ListWidget);
  1837. if (NULL == self || NULL == device)
  1838. return FALSE;
  1839. item = ListWidget_FindItem(self, device->GetName(), NULL, NULL);
  1840. if (NULL == item)
  1841. return FALSE;
  1842. if (item == self->hoveredItem &&
  1843. NULL == self->activeMenu)
  1844. {
  1845. ListWidget_UpdateActiveCommands(self, hwnd);
  1846. }
  1847. return TRUE;
  1848. }
  1849. static BOOL
  1850. ListWidget_DeviceActivityStarted(HWND hwnd, ifc_device *device)
  1851. {
  1852. ListWidget *self;
  1853. ListWidgetItem *item;
  1854. ListWidgetCategory *category;
  1855. size_t index;
  1856. self = WIDGET_GET_SELF(hwnd, ListWidget);
  1857. if (NULL == self || NULL == device)
  1858. return FALSE;
  1859. item = ListWidget_FindItem(self, device->GetName(), &category, NULL);
  1860. if (NULL == item)
  1861. return FALSE;
  1862. index = self->activeItems.size();
  1863. while(index--)
  1864. {
  1865. if (item == self->activeItems[index])
  1866. return FALSE;
  1867. }
  1868. if (FALSE != ListWidget_CreateItemActivity(item))
  1869. {
  1870. ifc_deviceactivity *activity;
  1871. ListWidget_RegisterActiveItem(self, hwnd, item);
  1872. if(S_OK == device->GetActivity(&activity) &&
  1873. NULL != activity)
  1874. {
  1875. ListWidget_UpdateItemActivity(item, activity);
  1876. activity->Release();
  1877. }
  1878. }
  1879. if (NULL == category ||
  1880. FALSE == category->collapsed)
  1881. {
  1882. ListWidget_InvalidateItemImage(self, hwnd, item);
  1883. if (STATUS_ERROR != self->selectionStatus &&
  1884. item == self->selectedItem)
  1885. {
  1886. ListWidget_UpdateSelectionStatus(self, hwnd, FALSE);
  1887. }
  1888. }
  1889. if (item == self->hoveredItem &&
  1890. NULL == self->activeMenu)
  1891. {
  1892. ListWidget_UpdateActiveCommands(self, hwnd);
  1893. }
  1894. return TRUE;
  1895. }
  1896. static BOOL
  1897. ListWidget_DeviceActivityFinished(HWND hwnd, ifc_device *device)
  1898. {
  1899. ListWidget *self;
  1900. ListWidgetItem *item;
  1901. ListWidgetCategory *category;
  1902. BOOL activityChanged;
  1903. self = WIDGET_GET_SELF(hwnd, ListWidget);
  1904. if (NULL == self || NULL == device)
  1905. return FALSE;
  1906. item = ListWidget_FindItem(self, device->GetName(), &category, NULL);
  1907. if (NULL == item)
  1908. return FALSE;
  1909. activityChanged = FALSE;
  1910. if (FALSE != ListWidget_UnregisterActiveItem(self, hwnd, item))
  1911. activityChanged = TRUE;
  1912. if (FALSE != ListWidget_DeleteItemActivity(item))
  1913. activityChanged = TRUE;
  1914. if (FALSE != activityChanged)
  1915. {
  1916. if (NULL == category ||
  1917. FALSE == category->collapsed)
  1918. {
  1919. ListWidget_InvalidateItemImage(self, hwnd, item);
  1920. }
  1921. if (item == self->hoveredItem &&
  1922. NULL == self->activeMenu)
  1923. {
  1924. ListWidget_UpdateActiveCommands(self, hwnd);
  1925. }
  1926. if (STATUS_ERROR != self->selectionStatus &&
  1927. item == self->selectedItem)
  1928. {
  1929. ListWidget_UpdateSelectionStatus(self, hwnd, FALSE);
  1930. }
  1931. }
  1932. return TRUE;
  1933. }
  1934. static BOOL
  1935. ListWidget_DeviceActivityChanged(HWND hwnd, ifc_device *device)
  1936. {
  1937. ListWidget *self;
  1938. ListWidgetItem *item;
  1939. ListWidgetCategory *category;
  1940. ifc_deviceactivity *activity;
  1941. ListWidgetActivityChange changes;
  1942. self = WIDGET_GET_SELF(hwnd, ListWidget);
  1943. if (NULL == self || NULL == device)
  1944. return FALSE;
  1945. item = ListWidget_FindItem(self, device->GetName(), &category, NULL);
  1946. if (NULL == item)
  1947. return FALSE;
  1948. if (S_OK == device->GetActivity(&activity) &&
  1949. NULL != activity)
  1950. {
  1951. changes = ListWidget_UpdateItemActivity(item, activity);
  1952. activity->Release();
  1953. }
  1954. else
  1955. changes = ListWidgetActivityChanged_Nothing;
  1956. //if (FALSE != self->activityTimerEnabled)
  1957. // changes &= ~ListWidgetActivityChanged_Percent;
  1958. if (ListWidgetActivityChanged_Nothing != changes &&
  1959. (NULL == category || FALSE == category->collapsed))
  1960. {
  1961. ListWidget_InvalidateItemActivity(self, hwnd, item, changes);
  1962. ListWidget_TooltipUpdateText(self, self->tooltip, item, Tooltip_DeviceActivityChanged);
  1963. if (0 != (ListWidgetActivityChanged_Title & changes) &&
  1964. STATUS_ERROR != self->selectionStatus &&
  1965. item == self->selectedItem)
  1966. {
  1967. ListWidget_UpdateSelectionStatus(self, hwnd, FALSE);
  1968. }
  1969. }
  1970. return TRUE;
  1971. }
  1972. static BOOL
  1973. ListWidget_DeviceModelChanged(HWND hwnd, ifc_device *device)
  1974. {
  1975. ListWidget *self;
  1976. ListWidgetItem *item;
  1977. ListWidgetCategory *category;
  1978. self = WIDGET_GET_SELF(hwnd, ListWidget);
  1979. if (NULL == self || NULL == device)
  1980. return FALSE;
  1981. item = ListWidget_FindItem(self, device->GetName(), &category, NULL);
  1982. if (NULL == item)
  1983. return FALSE;
  1984. if (NULL == category ||
  1985. FALSE == category->collapsed)
  1986. {
  1987. ListWidget_TooltipUpdateText(self, self->tooltip, item, Tooltip_DeviceModelChanged);
  1988. if (STATUS_ERROR != self->selectionStatus &&
  1989. item == self->selectedItem)
  1990. {
  1991. ListWidget_UpdateSelectionStatus(self, hwnd, FALSE);
  1992. }
  1993. }
  1994. return TRUE;
  1995. }
  1996. static BOOL
  1997. ListWidget_DeviceStatusChanged(HWND hwnd, ifc_device *device)
  1998. {
  1999. ListWidget *self;
  2000. ListWidgetItem *item;
  2001. ListWidgetCategory *category;
  2002. self = WIDGET_GET_SELF(hwnd, ListWidget);
  2003. if (NULL == self || NULL == device)
  2004. return FALSE;
  2005. item = ListWidget_FindItem(self, device->GetName(), &category, NULL);
  2006. if (NULL == item)
  2007. return FALSE;
  2008. if (NULL == category ||
  2009. FALSE == category->collapsed)
  2010. {
  2011. ListWidget_TooltipUpdateText(self, self->tooltip, item, Tooltip_DeviceStatusChanged);
  2012. if (STATUS_ERROR != self->selectionStatus &&
  2013. item == self->selectedItem)
  2014. {
  2015. ListWidget_UpdateSelectionStatus(self, hwnd, FALSE);
  2016. }
  2017. }
  2018. return TRUE;
  2019. }
  2020. static void
  2021. ListWidget_DeviceCb(ifc_device *device, DeviceEvent eventId, void *user)
  2022. {
  2023. HWND hwnd;
  2024. hwnd = (HWND)user;
  2025. switch(eventId)
  2026. {
  2027. case Event_DeviceAdded:
  2028. ListWidget_DeviceAdd(hwnd, device, NULL);
  2029. break;
  2030. case Event_DeviceRemoved:
  2031. ListWidget_DeviceRemove(hwnd, device);
  2032. break;
  2033. case Event_DeviceHidden:
  2034. ListWidget_DeviceRemove(hwnd, device);
  2035. break;
  2036. case Event_DeviceShown:
  2037. ListWidget_DeviceAdd(hwnd, device, NULL);
  2038. break;
  2039. case Event_DeviceAttached:
  2040. ListWidget_DeviceAttach(hwnd, device);
  2041. break;
  2042. case Event_DeviceDetached:
  2043. ListWidget_DeviceDetach(hwnd, device);
  2044. break;
  2045. case Event_DeviceDisplayNameChanged:
  2046. ListWidget_DeviceTitleChanged(hwnd, device);
  2047. break;
  2048. case Event_DeviceTotalSpaceChanged:
  2049. ListWidget_DeviceSpaceChanged(hwnd, device);
  2050. break;
  2051. case Event_DeviceUsedSpaceChanged:
  2052. ListWidget_DeviceSpaceChanged(hwnd, device);
  2053. break;
  2054. case Event_DeviceIconChanged:
  2055. ListWidget_DeviceIconChanged(hwnd, device);
  2056. break;
  2057. case Event_DeviceActivityStarted:
  2058. ListWidget_DeviceActivityStarted(hwnd, device);
  2059. break;
  2060. case Event_DeviceActivityFinished:
  2061. ListWidget_DeviceActivityFinished(hwnd, device);
  2062. break;
  2063. case Event_DeviceActivityChanged:
  2064. ListWidget_DeviceActivityChanged(hwnd, device);
  2065. break;
  2066. case Event_DeviceCommandChanged:
  2067. ListWidget_DeviceCommandChanged(hwnd, device);
  2068. break;
  2069. case Event_DeviceModelChanged:
  2070. ListWidget_DeviceModelChanged(hwnd, device);
  2071. break;
  2072. case Event_DeviceStatusChanged:
  2073. ListWidget_DeviceStatusChanged(hwnd, device);
  2074. break;
  2075. }
  2076. }
  2077. static BOOL
  2078. ListWidget_RegisterDeviceHandler(ListWidget *self, HWND hwnd)
  2079. {
  2080. HWND eventRelay;
  2081. DeviceEventCallbacks callbacks;
  2082. if (NULL == self)
  2083. return FALSE;
  2084. if (0 != self->deviceHandler)
  2085. return FALSE;
  2086. eventRelay = Plugin_GetEventRelayWindow();
  2087. if (NULL == eventRelay)
  2088. return FALSE;
  2089. ZeroMemory(&callbacks, sizeof(callbacks));
  2090. callbacks.deviceCb = ListWidget_DeviceCb;
  2091. self->deviceHandler = EVENTRELAY_REGISTER_HANDLER(eventRelay, &callbacks, hwnd);
  2092. return (0 != self->deviceHandler);
  2093. }
  2094. static BOOL
  2095. ListWidget_InitCb(HWND hwnd, void **object, void *param)
  2096. {
  2097. ListWidget *self;
  2098. HWND sliderWindow;
  2099. int imageHeight, imageWidth;
  2100. self = new ListWidget();
  2101. if (NULL == self)
  2102. return FALSE;
  2103. self->flags = (ListWidgetFlags)0;
  2104. self->hoveredItem = NULL;
  2105. self->selectedItem = NULL;
  2106. self->titleEditItem = NULL;
  2107. self->pressedCategory = NULL;
  2108. self->itemWidth = 0;
  2109. self->spacebarBitmap = NULL;
  2110. self->hoverBitmap = NULL;
  2111. self->selectBitmap = NULL;
  2112. self->inactiveSelectBitmap = NULL;
  2113. self->largeBadgeBitmap = NULL;
  2114. self->smallBadgeBitmap = NULL;
  2115. self->arrowsBitmap = NULL;
  2116. self->itemsPerLine = 0;
  2117. self->deviceHandler = 0;
  2118. self->activeMenu = NULL;
  2119. self->previousMouse.x = -1;
  2120. self->previousMouse.y = -1;
  2121. self->commands = NULL;
  2122. self->commandsCount = 0;
  2123. self->commandsMax = 0;
  2124. self->unknownCommandLargeImage = NULL;
  2125. self->unknownCommandSmallImage = NULL;
  2126. ZeroMemory(&self->activityMetrics, sizeof(ListWidgetActivityMetric));
  2127. self->activityFont = NULL;
  2128. self->activityProgressImage = NULL;
  2129. self->activityBadgeBitmap = NULL;
  2130. self->activityTimerEnabled = FALSE;
  2131. SetSizeEmpty(&self->connectionSize);
  2132. SetSizeEmpty(&self->primaryCommandSize);
  2133. SetSizeEmpty(&self->secondaryCommandSize);
  2134. self->selectionStatus = STATUS_ERROR;
  2135. self->titleEditor = NULL;
  2136. BackBuffer_Initialize(&self->backBuffer, hwnd);
  2137. imageHeight = Config_ReadInt("View", "imageHeight", LISTWIDGET_IMAGE_DEFAULT_HEIGHT);
  2138. if (imageHeight < LISTWIDGET_IMAGE_MIN_HEIGHT)
  2139. imageHeight = LISTWIDGET_IMAGE_MIN_HEIGHT;
  2140. else if (imageHeight > LISTWIDGET_IMAGE_MAX_HEIGHT)
  2141. imageHeight = LISTWIDGET_IMAGE_MAX_HEIGHT;
  2142. imageWidth = (imageHeight * LISTWIDGET_IMAGE_DEFAULT_WIDTH)/LISTWIDGET_IMAGE_DEFAULT_HEIGHT;
  2143. ListWidget_SetImageSize(self, hwnd, imageWidth, imageHeight, FALSE);
  2144. ListWidget_CreateDefaultCategories(self);
  2145. *object = self;
  2146. sliderWindow = MANAGERVIEW_GET_ZOOM_SLIDER(GetParent(hwnd));
  2147. if (NULL != sliderWindow)
  2148. {
  2149. int pos;
  2150. SendMessage(sliderWindow, TBM_SETPAGESIZE, 0, 10);
  2151. SendMessage(sliderWindow, TBM_SETLINESIZE, 0, 10);
  2152. SendMessage(sliderWindow, TBM_SETRANGE, TRUE, MAKELPARAM(-100, 100));
  2153. SendMessage(sliderWindow, TBM_SETTIC, 0, 0);
  2154. if (imageHeight == LISTWIDGET_IMAGE_DEFAULT_HEIGHT)
  2155. pos = 0;
  2156. else if (imageHeight > LISTWIDGET_IMAGE_DEFAULT_HEIGHT)
  2157. pos = (100 * (imageHeight- LISTWIDGET_IMAGE_DEFAULT_HEIGHT))/(LISTWIDGET_IMAGE_MAX_HEIGHT - LISTWIDGET_IMAGE_DEFAULT_HEIGHT);
  2158. else
  2159. pos = (100 * (imageHeight - LISTWIDGET_IMAGE_MIN_HEIGHT))/(LISTWIDGET_IMAGE_DEFAULT_HEIGHT - LISTWIDGET_IMAGE_MIN_HEIGHT) - 100;
  2160. SendMessage(sliderWindow, TBM_SETPOS, TRUE, pos);
  2161. }
  2162. self->tooltip = ListWidget_TooltipCreate(hwnd);
  2163. ListWidget_AddExistingDevices(self, hwnd);
  2164. ListWidget_RegisterDeviceHandler(self, hwnd);
  2165. return TRUE;
  2166. }
  2167. static void
  2168. ListWidget_DestroyCb(ListWidget *self, HWND hwnd)
  2169. {
  2170. HWND sliderWindow;
  2171. size_t index;
  2172. if (NULL == self)
  2173. return;
  2174. Config_WriteInt("View", "imageHeight", self->imageSize.cy);
  2175. if (0 != self->deviceHandler)
  2176. {
  2177. HWND eventRelay;
  2178. eventRelay = Plugin_GetEventRelayWindow();
  2179. if (NULL != eventRelay)
  2180. {
  2181. EVENTRELAY_UNREGISTER_HANDLER(eventRelay, self->deviceHandler);
  2182. }
  2183. }
  2184. index = self->activeItems.size();
  2185. if (0 != index)
  2186. {
  2187. KillTimer(hwnd, LISTWIDGETTIMER_PROGRESS_TICK_ID);
  2188. self->activityTimerEnabled = FALSE;
  2189. while(index--)
  2190. ListWidget_DeleteItemActivity(self->activeItems[index]);
  2191. }
  2192. index = self->categories.size();
  2193. if (0 != index)
  2194. {
  2195. while(index--)
  2196. {
  2197. ListWidgetCategory *category = self->categories[index];
  2198. Config_WriteBool("CollapsedCategories", category->name, category->collapsed);
  2199. ListWidget_DestroyCategory(category);
  2200. }
  2201. self->categories.clear();
  2202. }
  2203. ListWidget_RemoveAllConnections(self);
  2204. BackBuffer_Uninitialize(&self->backBuffer);
  2205. if (NULL != self->spacebarBitmap)
  2206. DeleteObject(self->spacebarBitmap);
  2207. if (NULL != self->hoverBitmap)
  2208. DeleteObject(self->hoverBitmap);
  2209. if (NULL != self->selectBitmap)
  2210. DeleteObject(self->selectBitmap);
  2211. if (NULL != self->inactiveSelectBitmap)
  2212. DeleteObject(self->inactiveSelectBitmap);
  2213. if (NULL != self->largeBadgeBitmap)
  2214. DeleteObject(self->largeBadgeBitmap);
  2215. if (NULL != self->smallBadgeBitmap)
  2216. DeleteObject(self->smallBadgeBitmap);
  2217. if (NULL != self->unknownCommandLargeImage)
  2218. DeviceImage_Release(self->unknownCommandLargeImage);
  2219. if (NULL != self->unknownCommandSmallImage)
  2220. DeviceImage_Release(self->unknownCommandSmallImage);
  2221. if (NULL != self->arrowsBitmap)
  2222. DeleteObject(self->arrowsBitmap);
  2223. if (NULL != self->activityProgressImage)
  2224. DeviceImage_Release(self->activityProgressImage);
  2225. if (NULL != self->activityBadgeBitmap)
  2226. DeleteObject(self->activityBadgeBitmap);
  2227. if (NULL != self->activityFont)
  2228. DeleteObject(self->activityFont);
  2229. ListWidget_TooltipDestroy(self->tooltip);
  2230. if (NULL != self->commands)
  2231. {
  2232. ListWidget_DestroyAllCommands(self->commands, self->commandsCount);
  2233. free(self->commands);
  2234. }
  2235. free(self);
  2236. sliderWindow = MANAGERVIEW_GET_ZOOM_SLIDER(GetParent(hwnd));
  2237. if (NULL != sliderWindow)
  2238. {
  2239. ShowWindow(sliderWindow, SW_HIDE);
  2240. }
  2241. }
  2242. static void
  2243. ListWidget_LayoutCb(ListWidget *self, HWND hwnd, WidgetStyle *style,
  2244. const RECT *clientRect, SIZE *viewSize, BOOL redraw)
  2245. {
  2246. size_t iCategory, iGroup, iItem;
  2247. ListWidgetCategory *category;
  2248. ListWidgetGroup *group;
  2249. ListWidgetItem *item;
  2250. ListWidgetCategoryMetric categoryMetrics;
  2251. size_t itemsInLine;
  2252. long viewWidth, itemHeight, lineHeight;
  2253. long itemTextWidth, itemTextHeightMax, textHeight, fontHeight;
  2254. long categoryHeight, categorySpacing, categorySpacingCollapsed;
  2255. SIZE itemSpacing, widgetSize, itemSize;
  2256. POINT widgetOffset, categoryOffset, itemOffset;
  2257. RECT elementRect;
  2258. HDC targetDC;
  2259. HFONT targetPrevFont;
  2260. TEXTMETRIC textMetrics;
  2261. if (NULL == style)
  2262. return;
  2263. viewWidth = RECTWIDTH(*clientRect);
  2264. if (FALSE == ListWidget_CalculateItemBaseSize(self, style, &itemSize, &itemTextWidth))
  2265. SetSizeEmpty(&itemSize);
  2266. self->itemWidth = itemSize.cx;
  2267. WIDGETSTYLE_DLU_TO_HORZ_PX_MIN(widgetOffset.x, style, LISTWIDGET_OFFSET_LEFT_DLU, 1);
  2268. WIDGETSTYLE_DLU_TO_VERT_PX_MIN(widgetOffset.y, style, LISTWIDGET_OFFSET_TOP_DLU, 1);
  2269. WIDGETSTYLE_DLU_TO_HORZ_PX_MIN(categoryOffset.x, style, LISTWIDGET_CATEGORY_OFFSET_LEFT_DLU, 1);
  2270. WIDGETSTYLE_DLU_TO_VERT_PX_MIN(categoryOffset.y, style, LISTWIDGET_CATEGORY_OFFSET_TOP_DLU, 1);
  2271. WIDGETSTYLE_DLU_TO_VERT_PX_MIN(categorySpacing, style, LISTWIDGET_CATEGORY_SPACING_DLU, 1);
  2272. WIDGETSTYLE_DLU_TO_VERT_PX_MIN(categorySpacingCollapsed, style, LISTWIDGET_CATEGORY_SPACING_COLLAPSED_DLU, 1);
  2273. WIDGETSTYLE_DLU_TO_HORZ_PX_MIN(itemOffset.x, style, LISTWIDGET_ITEM_OFFSET_LEFT_DLU, 1);
  2274. WIDGETSTYLE_DLU_TO_VERT_PX_MIN(itemOffset.y, style, LISTWIDGET_ITEM_OFFSET_TOP_DLU, 1);
  2275. WIDGETSTYLE_DLU_TO_HORZ_PX_MIN(itemSpacing.cx, style, LISTWIDGET_ITEM_SPACING_HORZ_DLU, 1);
  2276. WIDGETSTYLE_DLU_TO_VERT_PX_MIN(itemSpacing.cy, style, LISTWIDGET_ITEM_SPACING_VERT_DLU, 1);
  2277. self->itemsPerLine = ((viewWidth - (widgetOffset.x + itemOffset.x))/* + itemSpacing.cx*/) / (itemSize.cx + itemSpacing.cx);
  2278. self->itemsPerLine = MAX(self->itemsPerLine, 1);
  2279. itemsInLine = 0;
  2280. for (iCategory = 0; iCategory < self->categories.size(); iCategory++)
  2281. {
  2282. category = self->categories[iCategory];
  2283. if (FALSE == category->collapsed)
  2284. {
  2285. for(iGroup = 0; iGroup < category->groups.size(); iGroup++)
  2286. {
  2287. group = category->groups[iGroup];
  2288. if (itemsInLine < group->items.size())
  2289. itemsInLine = group->items.size();
  2290. }
  2291. }
  2292. }
  2293. if (self->itemsPerLine < itemsInLine && self->itemsPerLine > 1)
  2294. itemSpacing.cx = (LONG)(((viewWidth - (widgetOffset.x + itemOffset.x)) - (itemSize.cx * self->itemsPerLine))/self->itemsPerLine);
  2295. if (itemsInLine < self->itemsPerLine)
  2296. self->itemsPerLine = itemsInLine;
  2297. widgetSize.cx = widgetOffset.x + itemOffset.x + itemSize.cx;
  2298. widgetSize.cy = widgetOffset.y;
  2299. targetDC = GetDCEx(hwnd, NULL, DCX_CACHE | DCX_NORESETATTRS);
  2300. if (NULL != targetDC)
  2301. {
  2302. targetPrevFont = SelectFont(targetDC, WIDGETSTYLE_CATEGORY_FONT(style));
  2303. categoryHeight = Graphics_GetFontHeight(targetDC);
  2304. SelectFont(targetDC, WIDGETSTYLE_TEXT_FONT(style));
  2305. fontHeight = Graphics_GetFontHeight(targetDC);
  2306. itemTextHeightMax = LISTWIDGET_ITEM_TITLE_MAX_LINES * fontHeight;
  2307. }
  2308. else
  2309. {
  2310. targetPrevFont = NULL;
  2311. itemTextHeightMax = 0;
  2312. categoryHeight = 0;
  2313. fontHeight = 0;
  2314. }
  2315. if (NULL == targetDC ||
  2316. FALSE == GetTextMetrics(targetDC, &textMetrics))
  2317. {
  2318. ZeroMemory(&textMetrics, sizeof(textMetrics));
  2319. }
  2320. if (FALSE != ListWidget_GetCategoryMetrics(style, &categoryMetrics))
  2321. {
  2322. if (categoryHeight < categoryMetrics.minHeight)
  2323. categoryHeight = categoryMetrics.minHeight;
  2324. categoryHeight += categoryMetrics.offsetTop + categoryMetrics.offsetBottom +
  2325. categoryMetrics.lineHeight + categoryMetrics.lineOffsetTop;
  2326. }
  2327. for (iCategory = 0; iCategory < self->categories.size(); iCategory++)
  2328. {
  2329. category = self->categories[iCategory];
  2330. SetRect(&category->rect, 0, 0, viewWidth, categoryHeight);
  2331. long offsetX = clientRect->left + categoryOffset.x;
  2332. long offsetY = clientRect->top + widgetSize.cy;
  2333. if (0 == iCategory)
  2334. offsetY += categoryOffset.y;
  2335. else
  2336. {
  2337. if (FALSE == self->categories[iCategory - 1]->collapsed)
  2338. offsetY += categorySpacing;
  2339. else
  2340. offsetY += categorySpacingCollapsed;
  2341. }
  2342. OffsetRect(&category->rect, offsetX, offsetY);
  2343. widgetSize.cy = category->rect.bottom - clientRect->top;
  2344. size_t itemsInCategory = 0;
  2345. if (FALSE == category->collapsed)
  2346. {
  2347. for(iGroup = 0; iGroup < category->groups.size(); iGroup++)
  2348. {
  2349. group = category->groups[iGroup];
  2350. itemsInLine = 1;
  2351. lineHeight = 0;
  2352. if (0 != group->items.size())
  2353. {
  2354. if (0 == iGroup)
  2355. widgetSize.cy += itemOffset.y;
  2356. else
  2357. widgetSize.cy += itemSpacing.cy;
  2358. for(iItem = 0; iItem < group->items.size(); iItem++, itemsInLine++)
  2359. {
  2360. item = group->items[iItem];
  2361. if (itemsInLine > self->itemsPerLine)
  2362. {
  2363. widgetSize.cy += lineHeight + itemSpacing.cy;
  2364. lineHeight = 0;
  2365. itemsInLine = 1;
  2366. }
  2367. itemHeight = itemSize.cy;
  2368. itemsInCategory++;
  2369. if (-1 == item->titleSize.cy)
  2370. {
  2371. if (FALSE == IS_STRING_EMPTY(item->title))
  2372. {
  2373. SetRect(&elementRect, 0, 0, itemTextWidth - textMetrics.tmAveCharWidth/2, 0);
  2374. if (FALSE != DrawText(targetDC, item->title, -1, &elementRect,
  2375. DT_NOPREFIX | DT_CALCRECT | DT_EDITCONTROL | DT_WORDBREAK))
  2376. {
  2377. SetSize(&item->titleSize, RECTWIDTH(elementRect), RECTHEIGHT(elementRect));
  2378. item->titleSize.cx += textMetrics.tmAveCharWidth/2;
  2379. if (item->titleSize.cx > itemTextWidth)
  2380. item->titleSize.cx = itemTextWidth;
  2381. }
  2382. else
  2383. SetSizeEmpty(&item->titleSize);
  2384. }
  2385. else
  2386. {
  2387. SetSize(&item->titleSize, 0, textMetrics.tmHeight);
  2388. }
  2389. }
  2390. textHeight = item->titleSize.cy;
  2391. if (textHeight > itemTextHeightMax)
  2392. {
  2393. textHeight = itemTextHeightMax;
  2394. ListWidgetItem_SetTextTruncated(item);
  2395. }
  2396. itemHeight += textHeight;
  2397. SetRect(&item->rect, 0, 0, itemSize.cx, itemHeight);
  2398. offsetX = long(clientRect->left + itemOffset.x +
  2399. (itemsInLine - 1)*(itemSize.cx + itemSpacing.cx));
  2400. offsetY = clientRect->top + widgetSize.cy;
  2401. OffsetRect(&item->rect, offsetX, offsetY);
  2402. if (lineHeight < itemHeight)
  2403. lineHeight = itemHeight;
  2404. }
  2405. if (0 != lineHeight)
  2406. widgetSize.cy += lineHeight;
  2407. }
  2408. }
  2409. if (0 == itemsInCategory &&
  2410. FALSE == IS_STRING_EMPTY(category->emptyText))
  2411. {
  2412. SetRect(&category->emptyTextRect, 0, 0, viewWidth - textMetrics.tmAveCharWidth/2, 0);
  2413. if (FALSE != DrawText(targetDC, category->emptyText, -1, &category->emptyTextRect,
  2414. DT_NOPREFIX | DT_CALCRECT | DT_EDITCONTROL | DT_WORDBREAK))
  2415. {
  2416. category->emptyTextRect.right += textMetrics.tmAveCharWidth/2;
  2417. if (category->emptyTextRect.right > viewWidth)
  2418. category->emptyTextRect.right = viewWidth;
  2419. offsetX = clientRect->left + categoryOffset.x +
  2420. (viewWidth - category->emptyTextRect.right)/2;
  2421. offsetY = clientRect->top + widgetSize.cy + itemOffset.y + fontHeight/2;
  2422. OffsetRect(&category->emptyTextRect, offsetX, offsetY);
  2423. widgetSize.cy += RECTHEIGHT(category->emptyTextRect) + itemOffset.y + fontHeight;
  2424. }
  2425. else
  2426. SetRectEmpty(&category->emptyTextRect);
  2427. }
  2428. }
  2429. else
  2430. {
  2431. for(iGroup = 0; iGroup < category->groups.size(); iGroup++)
  2432. {
  2433. group = category->groups[iGroup];
  2434. for(iItem = 0; iItem < group->items.size(); iItem++, itemsInLine++)
  2435. {
  2436. item = group->items[iItem];
  2437. SetRectEmpty(&item->rect);
  2438. itemsInCategory++;
  2439. }
  2440. }
  2441. }
  2442. }
  2443. widgetSize.cy += WIDGETSTYLE_DLU_TO_VERT_PX(style, LISTWIDGET_OFFSET_BOTTOM_DLU);
  2444. viewSize->cx = widgetSize.cx;
  2445. viewSize->cy = widgetSize.cy;
  2446. size_t commandsMax = 1;
  2447. if (self->commandsMax != commandsMax)
  2448. {
  2449. if (NULL != self->commands)
  2450. {
  2451. ListWidget_DestroyAllCommands(self->commands, self->commandsCount);
  2452. free(self->commands);
  2453. }
  2454. self->commandsCount = 0;
  2455. self->commands = (ListWidgetCommand**)malloc(sizeof(ListWidgetCommand*) * commandsMax);
  2456. if (NULL != self->commands)
  2457. self->commandsMax = commandsMax;
  2458. else
  2459. self->commandsMax = 0;
  2460. }
  2461. if (NULL != targetDC)
  2462. {
  2463. SelectFont(targetDC, targetPrevFont);
  2464. ReleaseDC(hwnd, targetDC);
  2465. }
  2466. }
  2467. static BOOL
  2468. ListWidget_PaintCb(ListWidget *self, HWND hwnd, WidgetStyle *style, HDC hdc, const RECT *paintRect, BOOL erase)
  2469. {
  2470. size_t iCategory, iGroup, iItem;
  2471. ListWidgetCategory *category;
  2472. ListWidgetGroup *group;
  2473. ListWidgetItem *item;
  2474. HFONT prevFont;
  2475. FillRegion fillRegion;
  2476. ListWidgetPaint paint;
  2477. size_t itemsInCategory;
  2478. if (FALSE == ListWidgetPaint_Initialize(&paint, self, style, hwnd, hdc, paintRect, erase))
  2479. return FALSE;
  2480. SetTextColor(hdc, style->textColor);
  2481. SetBkColor(hdc, style->backColor);
  2482. SetBkMode(hdc, TRANSPARENT);
  2483. prevFont = SelectFont(hdc, style->textFont);
  2484. FillRegion_Init(&fillRegion, paintRect);
  2485. if (FALSE != erase)
  2486. {
  2487. for (iCategory = 0; iCategory < self->categories.size(); iCategory++)
  2488. {
  2489. category = self->categories[iCategory];
  2490. FillRegion_ExcludeRect(&fillRegion, &category->rect);
  2491. if (FALSE == category->collapsed)
  2492. {
  2493. itemsInCategory = 0;
  2494. for(iGroup = 0; iGroup < category->groups.size(); iGroup++)
  2495. {
  2496. group = category->groups[iGroup];
  2497. for(iItem = 0; iItem < group->items.size(); iItem++)
  2498. {
  2499. item = group->items[iItem];
  2500. itemsInCategory++;
  2501. FillRegion_ExcludeRect(&fillRegion, &item->rect);
  2502. }
  2503. }
  2504. if (0 == itemsInCategory &&
  2505. FALSE == IS_STRING_EMPTY(category->emptyText))
  2506. {
  2507. FillRegion_ExcludeRect(&fillRegion, &category->emptyTextRect);
  2508. }
  2509. }
  2510. }
  2511. FillRegion_BrushFill(&fillRegion, hdc, style->backBrush);
  2512. FillRegion_SetEmpty(&fillRegion);
  2513. }
  2514. for (iCategory = 0; iCategory < self->categories.size(); iCategory++)
  2515. {
  2516. category = self->categories[iCategory];
  2517. if (FALSE == ListWidgetPaint_DrawCategory(&paint, category))
  2518. FillRegion_AppendRect(&fillRegion, &category->rect);
  2519. if (FALSE == category->collapsed)
  2520. {
  2521. itemsInCategory = 0;
  2522. for(iGroup = 0; iGroup < category->groups.size(); iGroup++)
  2523. {
  2524. group = category->groups[iGroup];
  2525. for(iItem = 0; iItem < group->items.size(); iItem++)
  2526. {
  2527. item = group->items[iItem];
  2528. itemsInCategory++;
  2529. if (FALSE == ListWidgetPaint_DrawItem(&paint, item))
  2530. FillRegion_AppendRect(&fillRegion, &item->rect);
  2531. }
  2532. }
  2533. if (0 == itemsInCategory &&
  2534. FALSE == IS_STRING_EMPTY(category->emptyText))
  2535. {
  2536. if (FALSE == ListWidgetPaint_DrawEmptyCategoryText(&paint, category))
  2537. FillRegion_AppendRect(&fillRegion, &category->emptyTextRect);
  2538. }
  2539. }
  2540. }
  2541. FillRegion_BrushFill(&fillRegion, hdc, style->backBrush);
  2542. FillRegion_Uninit(&fillRegion);
  2543. SelectFont(hdc, prevFont);
  2544. ListWidgetPaint_Uninitialize(&paint);
  2545. return TRUE;
  2546. }
  2547. static void
  2548. ListWidget_StyleColorChangedCb(ListWidget *self, HWND hwnd, WidgetStyle *style)
  2549. {
  2550. if (NULL == self)
  2551. return;
  2552. if (NULL != self->spacebarBitmap)
  2553. {
  2554. DeleteObject(self->spacebarBitmap);
  2555. self->spacebarBitmap = NULL;
  2556. }
  2557. if (NULL != self->hoverBitmap)
  2558. {
  2559. DeleteObject(self->hoverBitmap);
  2560. self->hoverBitmap = NULL;
  2561. }
  2562. if (NULL != self->selectBitmap)
  2563. {
  2564. DeleteObject(self->selectBitmap);
  2565. self->selectBitmap = NULL;
  2566. }
  2567. if (NULL != self->inactiveSelectBitmap)
  2568. {
  2569. DeleteObject(self->inactiveSelectBitmap);
  2570. self->inactiveSelectBitmap = NULL;
  2571. }
  2572. if (NULL != self->arrowsBitmap)
  2573. {
  2574. DeleteObject(self->arrowsBitmap);
  2575. self->arrowsBitmap = NULL;
  2576. }
  2577. ListWidget_ResetConnnectionsColors(self, style);
  2578. if (NULL != self->titleEditor)
  2579. ListWidget_UpdateTitleEditorColors(self->titleEditor, style);
  2580. }
  2581. static void
  2582. ListWidget_StyleFontChangedCb(ListWidget *self, HWND hwnd, WidgetStyle *style)
  2583. {
  2584. size_t iCategory, iGroup, iItem;
  2585. ListWidgetCategory *category;
  2586. ListWidgetGroup *group;
  2587. ListWidgetItem *item;
  2588. if (NULL == self)
  2589. return;
  2590. for (iCategory = 0; iCategory < self->categories.size(); iCategory++)
  2591. {
  2592. category = self->categories[iCategory];
  2593. category->countWidth = -1;
  2594. category->titleWidth = -1;
  2595. SetRect(&category->emptyTextRect, -1, -1, -1, -1);
  2596. for(iGroup = 0; iGroup < category->groups.size(); iGroup++)
  2597. {
  2598. group = category->groups[iGroup];
  2599. for(iItem = 0; iItem < group->items.size(); iItem++)
  2600. {
  2601. item = group->items[iItem];
  2602. SetSize(&item->titleSize, -1, -1);
  2603. }
  2604. }
  2605. }
  2606. ListWidget_TooltipFontChanged(self->tooltip);
  2607. if (NULL != self->titleEditor)
  2608. SendMessage(self->titleEditor, WM_SETFONT, (WPARAM)WIDGETSTYLE_TEXT_FONT(style), TRUE);
  2609. }
  2610. static BOOL
  2611. ListWidget_MouseMoveCb(ListWidget *self, HWND hwnd, unsigned int vKeys, const POINT *cursor)
  2612. {
  2613. if (self->previousMouse.x == cursor->x &&
  2614. self->previousMouse.y == cursor->y)
  2615. {
  2616. return TRUE;
  2617. }
  2618. self->previousMouse = *cursor;
  2619. if (FALSE != ListWidget_UpdateHoverEx(self, hwnd, cursor))
  2620. UpdateWindow(hwnd);
  2621. ListWidget_TooltipRelayMouseMessage(self->tooltip, WM_MOUSEMOVE, vKeys, cursor);
  2622. return TRUE;
  2623. }
  2624. static BOOL
  2625. ListWidget_LeftButtonDownCb(ListWidget *self, HWND hwnd, unsigned int vKeys, const POINT *cursor)
  2626. {
  2627. ListWidgetItem *selectedItem;
  2628. ListWidgetCategory *pressedCategory;
  2629. ListWidgetItemPart pressedPart;
  2630. ListWidgetCommand *command, *pressedCommand;
  2631. WidgetStyle *style;
  2632. RECT rect, pressedPartRect;
  2633. POINT pt, origin;
  2634. size_t index;
  2635. style = WIDGET_GET_STYLE(hwnd);
  2636. if (NULL == style)
  2637. return FALSE;
  2638. pt = *cursor;
  2639. if (FALSE == ListWidget_GetViewOrigin(hwnd, &origin))
  2640. {
  2641. origin.x = 0;
  2642. origin.y = 0;
  2643. }
  2644. selectedItem = NULL;
  2645. pressedCategory = NULL;
  2646. pressedPart = ListWidgetItemPart_None;
  2647. pressedCommand = NULL;
  2648. if (FALSE != GetClientRect(hwnd, &rect) &&
  2649. FALSE != PtInRect(&rect, pt))
  2650. {
  2651. pt.x -= origin.x;
  2652. pt.y -= origin.y;
  2653. pressedCategory = ListWidget_GetCategoryFromPoint(self, pt);
  2654. if (NULL == pressedCategory)
  2655. {
  2656. selectedItem = ListWidget_GetItemFromPoint(self, pt);
  2657. if (NULL != selectedItem)
  2658. {
  2659. ListWidgetItemMetric metrics;
  2660. if (FALSE != ListWidget_GetItemMetrics(style, &metrics))
  2661. {
  2662. pressedPart = ListWidgetItemPart_Command;
  2663. if (selectedItem == self->selectedItem)
  2664. pressedPart |= ListWidgetItemPart_Title;
  2665. pressedPart = ListWidget_GetItemPartFromPoint(self, selectedItem, &metrics, pt,
  2666. pressedPart, &pressedPartRect);
  2667. if (ListWidgetItemPart_Title == pressedPart &&
  2668. self->titleEditItem != selectedItem &&
  2669. hwnd == GetFocus() &&
  2670. FALSE == ListWidgetItem_IsTextEdited(selectedItem))
  2671. {
  2672. self->titleEditItem = selectedItem;
  2673. SetTimer(hwnd, LISTWIDGETTIMER_EDIT_TITLE_ID,
  2674. GetDoubleClickTime() + 1,
  2675. ListWidget_BeginTitleEditTimerCb);
  2676. }
  2677. }
  2678. }
  2679. }
  2680. }
  2681. if (NULL != pressedCategory)
  2682. {
  2683. ListWidgetCategoryMetric metrics;
  2684. if (FALSE == ListWidget_GetCategoryMetrics(style, &metrics))
  2685. SetRectEmpty(&rect);
  2686. else
  2687. {
  2688. CopyRect(&rect, &pressedCategory->rect);
  2689. rect.left += metrics.offsetLeft;
  2690. rect.top += metrics.offsetTop;
  2691. rect.right = rect.left + metrics.iconWidth;
  2692. rect.bottom -= (metrics.offsetBottom + metrics.lineHeight + metrics.lineOffsetTop);
  2693. }
  2694. if (FALSE == PtInRect(&rect, pt))
  2695. pressedCategory = NULL;
  2696. }
  2697. self->pressedCategory = pressedCategory;
  2698. ListWidget_SelectItem(self, hwnd, selectedItem, FALSE);
  2699. ListWidget_EnsureFocused(self, hwnd, FALSE);
  2700. if (ListWidgetItemPart_Command == pressedPart &&
  2701. NULL != selectedItem)
  2702. {
  2703. OffsetRect(&pressedPartRect, -selectedItem->rect.left, -selectedItem->rect.top);
  2704. }
  2705. index = self->commandsCount;
  2706. while(index--)
  2707. {
  2708. command = self->commands[index];
  2709. if (NULL == pressedCommand &&
  2710. ListWidgetItemPart_Command == pressedPart &&
  2711. ListWidget_GetCommandRectEqual(command, &pressedPartRect))
  2712. {
  2713. pressedCommand = command;
  2714. }
  2715. if (FALSE != ListWidget_GetCommandPressed(command) ||
  2716. pressedCommand == command)
  2717. {
  2718. if (FALSE != ListWidget_SetCommandPressed(pressedCommand, (pressedCommand == command)) &&
  2719. FALSE != ListWidget_GetCommandRect(command, &rect) &&
  2720. NULL != selectedItem)
  2721. {
  2722. OffsetRect(&rect, selectedItem->rect.left + origin.x, selectedItem->rect.top + origin.y);
  2723. InvalidateRect(hwnd, &rect, FALSE);
  2724. }
  2725. }
  2726. }
  2727. if (NULL != pressedCommand)
  2728. self->flags |= ListWidgetFlag_LButtonDownOnCommand;
  2729. else
  2730. self->flags &= ~ListWidgetFlag_LButtonDownOnCommand;
  2731. if (GetCapture() != hwnd)
  2732. SetCapture(hwnd);
  2733. UpdateWindow(hwnd);
  2734. ListWidget_TooltipHide(self->tooltip);
  2735. return TRUE;
  2736. }
  2737. static BOOL
  2738. ListWidget_LeftButtonUpCb(ListWidget *self, HWND hwnd, unsigned int vKeys, const POINT *cursor)
  2739. {
  2740. WidgetStyle *style;
  2741. RECT rect;
  2742. POINT pt, origin;
  2743. ListWidgetCategory *pressedCategory;
  2744. ListWidgetCommand *pressedCommand;
  2745. size_t index;
  2746. BOOL updateWindow;
  2747. style = WIDGET_GET_STYLE(hwnd);
  2748. pt = *cursor;
  2749. if (FALSE == ListWidget_GetViewOrigin(hwnd, &origin))
  2750. {
  2751. origin.x = 0;
  2752. origin.y = 0;
  2753. }
  2754. pressedCategory = NULL;
  2755. pressedCommand = NULL;
  2756. updateWindow = FALSE;
  2757. if (FALSE != GetClientRect(hwnd, &rect) &&
  2758. FALSE != PtInRect(&rect, pt))
  2759. {
  2760. pt.x -= origin.x;
  2761. pt.y -= origin.y;
  2762. pressedCategory = ListWidget_GetCategoryFromPoint(self, pt);
  2763. if (NULL == pressedCategory)
  2764. {
  2765. if (NULL != self->selectedItem &&
  2766. FALSE != ListWidgetItem_IsInteractive(self->selectedItem))
  2767. {
  2768. index = self->commandsCount;
  2769. while(index--)
  2770. {
  2771. if (FALSE != ListWidget_GetCommandRect(self->commands[index], &rect))
  2772. {
  2773. OffsetRect(&rect, self->selectedItem->rect.left, self->selectedItem->rect.top);
  2774. if (PtInRect(&rect, pt))
  2775. {
  2776. pressedCommand = self->commands[index];
  2777. if (FALSE != ListWidget_GetCommandDisabled(pressedCommand) ||
  2778. FALSE == ListWidget_GetCommandPressed(pressedCommand))
  2779. {
  2780. pressedCommand = NULL;
  2781. }
  2782. break;
  2783. }
  2784. }
  2785. }
  2786. }
  2787. }
  2788. }
  2789. if (NULL != self->pressedCategory)
  2790. {
  2791. if (NULL != pressedCategory)
  2792. {
  2793. ListWidgetCategoryMetric metrics;
  2794. if (FALSE == ListWidget_GetCategoryMetrics(style, &metrics))
  2795. SetRectEmpty(&rect);
  2796. else
  2797. {
  2798. CopyRect(&rect, &pressedCategory->rect);
  2799. rect.left += metrics.offsetLeft;
  2800. rect.top += metrics.offsetTop;
  2801. rect.right = rect.left + metrics.iconWidth;
  2802. rect.bottom -= (metrics.offsetBottom + metrics.lineHeight + metrics.lineOffsetTop);
  2803. }
  2804. if (FALSE == PtInRect(&rect, pt))
  2805. pressedCategory = NULL;
  2806. }
  2807. if(self->pressedCategory == pressedCategory)
  2808. {
  2809. ListWidget_ToggleCategory(pressedCategory, hwnd);
  2810. }
  2811. self->pressedCategory = NULL;
  2812. }
  2813. if (NULL != self->selectedItem)
  2814. {
  2815. if (NULL != pressedCommand && NULL != self->selectedItem)
  2816. {
  2817. ListWidget_SendItemCommand(self->selectedItem->name,
  2818. ListWidget_GetCommandName(pressedCommand),
  2819. hwnd, 0, TRUE);
  2820. }
  2821. index = self->commandsCount;
  2822. while(index--)
  2823. {
  2824. if (FALSE != ListWidget_GetCommandPressed(self->commands[index]))
  2825. {
  2826. if (FALSE != ListWidget_SetCommandPressed(self->commands[index], FALSE) &&
  2827. FALSE != ListWidget_GetCommandRect(self->commands[index], &rect))
  2828. {
  2829. OffsetRect(&rect, self->selectedItem->rect.left + origin.x, self->selectedItem->rect.top + origin.y);
  2830. InvalidateRect(hwnd, &rect, FALSE);
  2831. updateWindow = TRUE;
  2832. }
  2833. break;
  2834. }
  2835. }
  2836. if (FALSE != ListWidget_EnsureItemVisisble(self, hwnd, self->selectedItem, VISIBLE_NORMAL))
  2837. updateWindow = TRUE;
  2838. }
  2839. if (FALSE != ListWidget_UpdateHoverEx(self, hwnd, cursor))
  2840. updateWindow = TRUE;
  2841. if (GetCapture() == hwnd)
  2842. ReleaseCapture();
  2843. if (FALSE != updateWindow)
  2844. UpdateWindow(hwnd);
  2845. ListWidget_TooltipRelayMouseMessage(self->tooltip, WM_LBUTTONUP, vKeys, cursor);
  2846. return TRUE;
  2847. }
  2848. static BOOL
  2849. ListWidget_LeftButtonDblClkCb(ListWidget *self, HWND hwnd, unsigned int vKeys, const POINT *cursor)
  2850. {
  2851. RECT rect;
  2852. POINT pt = *cursor, origin;
  2853. ListWidgetCategory *category;
  2854. if (NULL != self->titleEditItem)
  2855. {
  2856. KillTimer(hwnd, LISTWIDGETTIMER_EDIT_TITLE_ID);
  2857. self->titleEditItem = NULL;
  2858. }
  2859. if (0 != (ListWidgetFlag_LButtonDownOnCommand & self->flags))
  2860. return FALSE;
  2861. if (FALSE == ListWidget_GetViewOrigin(hwnd, &origin))
  2862. {
  2863. origin.x = 0;
  2864. origin.y = 0;
  2865. }
  2866. if (FALSE != GetClientRect(hwnd, &rect) &&
  2867. FALSE != PtInRect(&rect, pt))
  2868. {
  2869. pt.x -= origin.x;
  2870. pt.y -= origin.y;
  2871. category = ListWidget_GetCategoryFromPoint(self, pt);
  2872. if (NULL != category)
  2873. {
  2874. ListWidget_ToggleCategory(category, hwnd);
  2875. self->pressedCategory = NULL;
  2876. return TRUE;
  2877. }
  2878. ListWidgetItem *item = ListWidget_GetItemFromPointEx(self, pt, &category, NULL);
  2879. if (NULL != item)
  2880. {
  2881. if (NULL != item &&
  2882. FALSE != ListWidgetItem_IsInteractive(item))
  2883. {
  2884. size_t index;
  2885. index = self->commandsCount;
  2886. while(index--)
  2887. {
  2888. if (FALSE != ListWidget_GetCommandRect(self->commands[index], &rect))
  2889. {
  2890. OffsetRect(&rect, item->rect.left, item->rect.top);
  2891. if (PtInRect(&rect, pt))
  2892. {
  2893. item = NULL;
  2894. break;
  2895. }
  2896. }
  2897. }
  2898. }
  2899. if (NULL != item)
  2900. {
  2901. ListWidget_CallItemAction(self, hwnd, category, item);
  2902. return TRUE;
  2903. }
  2904. }
  2905. }
  2906. return FALSE;
  2907. }
  2908. static BOOL
  2909. ListWidget_RightButtonDownCb(ListWidget *self, HWND hwnd, unsigned int vKeys, const POINT *cursor)
  2910. {
  2911. ListWidgetItem *selectedItem;
  2912. RECT rect;
  2913. POINT pt, origin;
  2914. pt = *cursor;
  2915. if (NULL != self->titleEditItem)
  2916. {
  2917. KillTimer(hwnd, LISTWIDGETTIMER_EDIT_TITLE_ID);
  2918. self->titleEditItem = NULL;
  2919. }
  2920. if (FALSE == ListWidget_GetViewOrigin(hwnd, &origin))
  2921. {
  2922. origin.x = 0;
  2923. origin.y = 0;
  2924. }
  2925. selectedItem = NULL;
  2926. if (FALSE != GetClientRect(hwnd, &rect) &&
  2927. FALSE != PtInRect(&rect, pt))
  2928. {
  2929. pt.x -= origin.x;
  2930. pt.y -= origin.y;
  2931. selectedItem = ListWidget_GetItemFromPoint(self, pt);
  2932. }
  2933. ListWidget_SelectItem(self, hwnd, selectedItem, TRUE);
  2934. ListWidget_EnsureFocused(self, hwnd, FALSE);
  2935. if (GetCapture() != hwnd)
  2936. SetCapture(hwnd);
  2937. UpdateWindow(hwnd);
  2938. ListWidget_TooltipRelayMouseMessage(self->tooltip, WM_RBUTTONDOWN, vKeys, cursor);
  2939. return FALSE; // allow defwindowproc to get this message
  2940. }
  2941. static BOOL
  2942. ListWidget_RightButtonUpCb(ListWidget *self, HWND hwnd, unsigned int vKeys, const POINT *cursor)
  2943. {
  2944. RECT rect;
  2945. if (FALSE != ListWidget_UpdateHoverEx(self, hwnd, cursor))
  2946. UpdateWindow(hwnd);
  2947. if (GetCapture() == hwnd)
  2948. ReleaseCapture();
  2949. ListWidget_TooltipRelayMouseMessage(self->tooltip, WM_RBUTTONUP, vKeys, cursor);
  2950. if (FALSE != GetClientRect(hwnd, &rect) &&
  2951. FALSE != PtInRect(&rect, *cursor))
  2952. {
  2953. ListWidgetItem *item;
  2954. ListWidgetItemMetric metrics;
  2955. POINT pt;
  2956. if (FALSE == ListWidget_GetViewOrigin(hwnd, &pt))
  2957. {
  2958. pt.x = 0;
  2959. pt.y = 0;
  2960. }
  2961. pt.x = cursor->x - pt.x;
  2962. pt.y = cursor->y - pt.y;
  2963. item = ListWidget_GetItemFromPoint(self, pt);
  2964. if (NULL != item)
  2965. {
  2966. WidgetStyle *style = WIDGET_GET_STYLE(hwnd);
  2967. if (NULL != style &&
  2968. FALSE != ListWidget_GetItemMetrics(style, &metrics))
  2969. {
  2970. ListWidgetItemPart part;
  2971. part = ListWidgetItemPart_Command | ListWidgetItemPart_Activity;
  2972. part = ListWidget_GetItemPartFromPoint(self, item, &metrics, pt, part, NULL);
  2973. if (ListWidgetItemPart_None != part)
  2974. return TRUE;
  2975. }
  2976. }
  2977. }
  2978. return FALSE; // allow defwindowproc to get this message
  2979. }
  2980. static BOOL
  2981. ListWidget_KeyDownCb(ListWidget *self, HWND hwnd, unsigned int vKey, unsigned int flags)
  2982. {
  2983. ListWidgetItem *selectedItem;
  2984. ListWidgetVisibleFlags visibleFlags;
  2985. selectedItem = NULL;
  2986. visibleFlags = VISIBLE_NORMAL/*VISIBLE_PARTIAL_OK*/;
  2987. switch(vKey)
  2988. {
  2989. case VK_HOME:
  2990. ListWidget_EnsureTopVisible(self, hwnd);
  2991. visibleFlags |= VISIBLE_ALIGN_TOP | VISIBLE_ALIGN_ALWAYS;
  2992. selectedItem = ListWidget_GetFirstItem(self);
  2993. break;
  2994. case VK_END:
  2995. ListWidget_EnsureBottomVisible(self, hwnd);
  2996. visibleFlags |= VISIBLE_ALIGN_BOTTOM | VISIBLE_ALIGN_ALWAYS;
  2997. selectedItem = ListWidget_GetLastItem(self);
  2998. break;
  2999. case VK_LEFT:
  3000. selectedItem = (NULL != self->selectedItem) ?
  3001. ListWidget_GetPreviousItem(self, self->selectedItem) :
  3002. ListWidget_GetLastItem(self);
  3003. if (NULL == selectedItem)
  3004. ListWidget_EnsureTopVisible(self, hwnd);
  3005. break;
  3006. case VK_RIGHT:
  3007. selectedItem = (NULL != self->selectedItem) ?
  3008. ListWidget_GetNextItem(self, self->selectedItem) :
  3009. ListWidget_GetFirstItem(self);
  3010. if (NULL == selectedItem)
  3011. ListWidget_EnsureBottomVisible(self, hwnd);
  3012. break;
  3013. case VK_UP:
  3014. selectedItem = (NULL != self->selectedItem) ?
  3015. ListWidget_GetPreviousLineItem(self, self->selectedItem) :
  3016. ListWidget_GetLastItem(self);
  3017. if (NULL == selectedItem)
  3018. ListWidget_EnsureTopVisible(self, hwnd);
  3019. break;
  3020. case VK_DOWN:
  3021. selectedItem = (NULL != self->selectedItem) ?
  3022. ListWidget_GetNextLineItem(self, self->selectedItem) :
  3023. ListWidget_GetFirstItem(self);
  3024. if (NULL == selectedItem)
  3025. ListWidget_EnsureBottomVisible(self, hwnd);
  3026. break;
  3027. case VK_PRIOR:
  3028. visibleFlags |= VISIBLE_ALIGN_BOTTOM;
  3029. selectedItem = (NULL != self->selectedItem) ?
  3030. ListWidget_GetPreviousPageItem(self, hwnd, self->selectedItem) :
  3031. ListWidget_GetLastItem(self);
  3032. if (NULL == selectedItem)
  3033. ListWidget_EnsureTopVisible(self, hwnd);
  3034. break;
  3035. case VK_NEXT:
  3036. visibleFlags |= VISIBLE_ALIGN_TOP;
  3037. selectedItem = (NULL != self->selectedItem) ?
  3038. ListWidget_GetNextPageItem(self, hwnd, self->selectedItem) :
  3039. ListWidget_GetFirstItem(self);
  3040. if (NULL == selectedItem)
  3041. ListWidget_EnsureBottomVisible(self, hwnd);
  3042. break;
  3043. case VK_RETURN:
  3044. if (NULL != self->selectedItem)
  3045. {
  3046. ListWidget_CallItemAction(self, hwnd, NULL, self->selectedItem);
  3047. ListWidget_EnsureItemVisisble(self, hwnd, self->selectedItem, visibleFlags);
  3048. }
  3049. break;
  3050. case VK_F2:
  3051. if (NULL != self->selectedItem)
  3052. {
  3053. if (NULL != self->titleEditor)
  3054. DestroyWindow(self->titleEditor);
  3055. self->titleEditor = ListWidget_BeginItemTitleEdit(self, hwnd, self->selectedItem);
  3056. }
  3057. break;
  3058. default:
  3059. return FALSE;
  3060. }
  3061. if (NULL != selectedItem)
  3062. {
  3063. ListWidget_SelectItem(self, hwnd, selectedItem, FALSE);
  3064. ListWidget_EnsureItemVisisble(self, hwnd, self->selectedItem, visibleFlags);
  3065. }
  3066. return TRUE;
  3067. }
  3068. static BOOL
  3069. ListWidget_KeyUpCb(ListWidget *self, HWND hwnd, unsigned int vKey, unsigned int flags)
  3070. {
  3071. return FALSE;
  3072. }
  3073. static BOOL
  3074. ListWidget_CharacterCb(ListWidget *self, HWND hwnd, unsigned int vKey, unsigned int flags)
  3075. {
  3076. return FALSE;
  3077. }
  3078. static INT
  3079. ListWidget_InputRequestCb(ListWidget *self, HWND hwnd, unsigned int vKey, MSG *message)
  3080. {
  3081. INT result;
  3082. if (NULL == message)
  3083. return DLGC_WANTALLKEYS;
  3084. ListWidget_TooltipHide(self->tooltip);
  3085. result = DLGC_WANTCHARS;
  3086. switch(vKey)
  3087. {
  3088. case VK_LEFT:
  3089. case VK_RIGHT:
  3090. case VK_UP:
  3091. case VK_DOWN:
  3092. case VK_PRIOR:
  3093. case VK_NEXT:
  3094. case VK_END:
  3095. case VK_HOME:
  3096. case VK_RETURN:
  3097. result |= DLGC_WANTALLKEYS;
  3098. break;
  3099. }
  3100. return result;
  3101. }
  3102. static void
  3103. ListWidget_FocusChangedCb(ListWidget *self, HWND hwnd, HWND focusWindow, BOOL focusReceived)
  3104. {
  3105. if (NULL == self)
  3106. return;
  3107. if (NULL == self->selectedItem)
  3108. {
  3109. if (FALSE != focusReceived && 0 == (ListWidgetFlag_NoFocusSelect & self->flags))
  3110. {
  3111. BOOL disableSelect;
  3112. disableSelect = FALSE;
  3113. if (NULL != focusWindow)
  3114. {
  3115. HWND ancestorWindow;
  3116. ancestorWindow = hwnd;
  3117. while(NULL != ancestorWindow)
  3118. {
  3119. ancestorWindow = GetAncestor(ancestorWindow, GA_PARENT);
  3120. if (focusWindow == ancestorWindow)
  3121. {
  3122. wchar_t buffer[64] = {0};
  3123. if (0 != GetClassName(focusWindow, buffer, ARRAYSIZE(buffer)) &&
  3124. CSTR_EQUAL == CompareString(CSTR_INVARIANT, NORM_IGNORECASE, buffer, -1, L"Winamp Gen", -1))
  3125. {
  3126. disableSelect = TRUE;
  3127. }
  3128. break;
  3129. }
  3130. }
  3131. }
  3132. if (FALSE == disableSelect)
  3133. {
  3134. ListWidgetItem *item;
  3135. item = ListWidget_GetFirstItem(self);
  3136. if (NULL != item)
  3137. ListWidget_SelectItem(self, hwnd, item, FALSE);
  3138. }
  3139. }
  3140. }
  3141. else
  3142. {
  3143. POINT origin;
  3144. RECT rect;
  3145. CopyRect(&rect, &self->selectedItem->rect);
  3146. if (FALSE != ListWidget_GetViewOrigin(hwnd, &origin))
  3147. OffsetRect(&rect, origin.x, origin.y);
  3148. InvalidateRect(hwnd, &rect, FALSE);
  3149. UpdateWindow(hwnd);
  3150. }
  3151. }
  3152. static BOOL
  3153. ListWidget_ContextMenuCb(ListWidget *self, HWND hwnd, HWND targetWindow, const POINT *cursor)
  3154. {
  3155. POINT pt;
  3156. ListWidgetItem *item;
  3157. if (NULL == self)
  3158. return FALSE;
  3159. if (NULL == cursor ||
  3160. (-1 == cursor->x && -1 == cursor->y))
  3161. {
  3162. if (hwnd != targetWindow)
  3163. return FALSE;
  3164. item = self->selectedItem;
  3165. if (NULL != item)
  3166. {
  3167. POINT origin;
  3168. pt.x = RECTWIDTH(item->rect);
  3169. pt.x = item->rect.left + pt.x/2 + pt.x%2;
  3170. pt.y = RECTHEIGHT(item->rect);
  3171. pt.y = item->rect.top + pt.y/2 + pt.y%2;
  3172. if (FALSE != ListWidget_GetViewOrigin(hwnd, &origin))
  3173. {
  3174. pt.x += origin.x;
  3175. pt.y += origin.y;
  3176. }
  3177. }
  3178. else
  3179. {
  3180. RECT rect;
  3181. GetClientRect(hwnd, &rect);
  3182. pt.x = rect.left + 2;
  3183. pt.y = rect.top + 2;
  3184. }
  3185. MapWindowPoints(hwnd, HWND_DESKTOP, &pt, 1);
  3186. }
  3187. else
  3188. {
  3189. POINT test;
  3190. pt = *cursor;
  3191. if (FALSE == ListWidget_GetViewOrigin(hwnd, &test))
  3192. {
  3193. test = pt;
  3194. }
  3195. else
  3196. {
  3197. test.x = pt.x - test.x;
  3198. test.y = pt.y - test.y;
  3199. }
  3200. MapWindowPoints(HWND_DESKTOP, hwnd, &test, 1);
  3201. item = ListWidget_GetItemFromPoint(self, test);
  3202. }
  3203. if (NULL == item)
  3204. ListWidget_DisplayContextMenu(self, hwnd, pt);
  3205. else
  3206. ListWidget_DisplayItemContextMenu(self, hwnd, item, pt);
  3207. return TRUE;
  3208. };
  3209. static void
  3210. ListWidget_ZoomChangingCb(ListWidget *self, HWND hwnd, NMTRBTHUMBPOSCHANGING *zoomInfo)
  3211. {
  3212. double pos, height, width;
  3213. int cx, cy;
  3214. if (NULL == self)
  3215. return;
  3216. pos = (double)(int)zoomInfo->dwPos;
  3217. if (0 == pos)
  3218. {
  3219. height = LISTWIDGET_IMAGE_DEFAULT_HEIGHT;
  3220. }
  3221. else if (pos < 0)
  3222. {
  3223. height = ((LISTWIDGET_IMAGE_DEFAULT_HEIGHT - LISTWIDGET_IMAGE_MIN_HEIGHT) * (100.0 + pos))/100.0;
  3224. height += LISTWIDGET_IMAGE_MIN_HEIGHT;
  3225. height = floor(height);
  3226. }
  3227. else
  3228. {
  3229. height = ((LISTWIDGET_IMAGE_MAX_HEIGHT - LISTWIDGET_IMAGE_DEFAULT_HEIGHT) * pos)/100.0;
  3230. height += LISTWIDGET_IMAGE_DEFAULT_HEIGHT;
  3231. height = ceil(height);
  3232. }
  3233. width = (height * LISTWIDGET_IMAGE_DEFAULT_WIDTH)/ LISTWIDGET_IMAGE_DEFAULT_HEIGHT;
  3234. cx = (int)(width + 0.5);
  3235. cy = (int)(height + 0.5);
  3236. if (self->imageSize.cx == cx &&
  3237. self->imageSize.cy == cy)
  3238. {
  3239. return;
  3240. }
  3241. ListWidget_SetImageSize(self, hwnd, cx, cy, TRUE);
  3242. // aTRACE_FMT("zoom changing: pos = %d, width = %d, height = %d\r\n", zoomInfo->dwPos, cx, cy);
  3243. }
  3244. static void
  3245. ListWidget_ScrollCb(ListWidget *self, HWND hwnd, int *dx, int *dy)
  3246. {
  3247. if (NULL != self->titleEditor)
  3248. {
  3249. DestroyWindow(self->titleEditor);
  3250. self->titleEditor = NULL;
  3251. }
  3252. if (FALSE != ListWidget_UpdateHover(self, hwnd))
  3253. UpdateWindow(hwnd);
  3254. ListWidget_TooltipHide(self->tooltip);
  3255. }
  3256. static BOOL
  3257. ListWidget_NotifyCb(ListWidget *self, HWND hwnd, NMHDR *pnmh, LRESULT *result)
  3258. {
  3259. if (FALSE != ListWidget_TooltipProcessNotification(self, self->tooltip, pnmh, result))
  3260. return TRUE;
  3261. return FALSE;
  3262. }
  3263. HWND
  3264. ListWidget_CreateWindow(HWND parentWindow, int x, int y, int width, int height, BOOL border, unsigned int controlId)
  3265. {
  3266. const static WidgetInterface widgetInterface =
  3267. {
  3268. (WidgetInitCallback)ListWidget_InitCb,
  3269. (WidgetDestroyCallback)ListWidget_DestroyCb,
  3270. (WidgetLayoutCallback)ListWidget_LayoutCb,
  3271. (WidgetPaintCallback)ListWidget_PaintCb,
  3272. (WidgetStyleCallback)ListWidget_StyleColorChangedCb,
  3273. (WidgetStyleCallback)ListWidget_StyleFontChangedCb,
  3274. (WidgetMouseCallback)ListWidget_MouseMoveCb,
  3275. (WidgetMouseCallback)ListWidget_LeftButtonDownCb,
  3276. (WidgetMouseCallback)ListWidget_LeftButtonUpCb,
  3277. (WidgetMouseCallback)ListWidget_LeftButtonDblClkCb,
  3278. (WidgetMouseCallback)ListWidget_RightButtonDownCb,
  3279. (WidgetMouseCallback)ListWidget_RightButtonUpCb,
  3280. (WidgetKeyCallback)ListWidget_KeyDownCb,
  3281. (WidgetKeyCallback)ListWidget_KeyUpCb,
  3282. (WidgetKeyCallback)ListWidget_CharacterCb,
  3283. (WidgetInputCallback)ListWidget_InputRequestCb,
  3284. (WidgetFocusCallback)ListWidget_FocusChangedCb,
  3285. (WidgetMenuCallback)ListWidget_ContextMenuCb,
  3286. (WidgetZoomCallback)ListWidget_ZoomChangingCb,
  3287. (WidgetScrollCallback)NULL, /*scrollBefore*/
  3288. (WidgetScrollCallback)ListWidget_ScrollCb,
  3289. (WidgetNotifyCallback)ListWidget_NotifyCb,
  3290. };
  3291. return Widget_CreateWindow(WIDGET_TYPE_LIST,
  3292. &widgetInterface,
  3293. NULL,
  3294. (FALSE != border) ? WS_EX_CLIENTEDGE : 0,
  3295. WS_TABSTOP,
  3296. x, y, width, height,
  3297. parentWindow,
  3298. controlId, 0L);
  3299. }