1
0

welcomeWidget.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760
  1. #include "main.h"
  2. #include "./welcomeWidget.h"
  3. #include "../winamp/commandLink.h"
  4. #include <strsafe.h>
  5. #define WELCOMEWIDGET_OFFSET_LEFT_DLU 4
  6. #define WELCOMEWIDGET_OFFSET_TOP_DLU 2
  7. #define WELCOMEWIDGET_OFFSET_RIGHT_DLU 4
  8. #define WELCOMEWIDGET_OFFSET_BOTTOM_DLU 2
  9. #define WELCOMEWIDGET_IMAGE_MIN_WIDTH 280
  10. #define WELCOMEWIDGET_IMAGE_MIN_HEIGHT (424 - 200)
  11. #define WELCOMEWIDGET_TITLE_MAX_HEIGHT 168
  12. #define WELCOMEWIDGET_TITLE_MIN_WIDTH WELCOMEWIDGET_IMAGE_MIN_WIDTH
  13. #define WELCOMEWIDGET_TEXT_MAX_HEIGHT 66
  14. #define WELCOMEWIDGET_TEXT_MIN_WIDTH WELCOMEWIDGET_IMAGE_MIN_WIDTH
  15. #define WELCOMEWIDGET_HELP_LINK 1000
  16. typedef struct WelcomeWidget
  17. {
  18. HDC context;
  19. long contextWidth;
  20. long contextHeight;
  21. HBITMAP previousBitmap;
  22. HFONT helpFont;
  23. } WelcomeWidget;
  24. static BOOL
  25. WelcomeWidget_GetBestTextRect(HDC hdc, const wchar_t *text, unsigned int length,
  26. RECT *rect, long maxWidth, unsigned int format)
  27. {
  28. RECT testRect;
  29. long right;
  30. if (NULL == rect)
  31. return FALSE;
  32. format |= DT_CALCRECT;
  33. if (length < 0)
  34. length = (NULL != text) ? lstrlen(text) : 0;
  35. if (0 == length || NULL == text)
  36. {
  37. rect->right = rect->left;
  38. rect->bottom = rect->top;
  39. return TRUE;
  40. }
  41. SetRect(&testRect, rect->left, rect->top, rect->right, rect->top);
  42. maxWidth += rect->left;
  43. right = rect->right;
  44. for(;;)
  45. {
  46. if (FALSE == DrawText(hdc, text, length, &testRect, format))
  47. return FALSE;
  48. if (testRect.bottom <= rect->bottom || right >= maxWidth)
  49. {
  50. CopyRect(rect, &testRect);
  51. break;
  52. }
  53. long increment = maxWidth - right;
  54. if (increment > 60)
  55. increment = increment / 4;
  56. else if (increment > 4)
  57. increment = increment / 2;
  58. right += increment;
  59. testRect.right = right;
  60. testRect.bottom = rect->top;
  61. }
  62. return TRUE;
  63. }
  64. static COLORREF
  65. WelcomeWidget_GetTextColor(WidgetStyle *style, COLORREF *shadowColor, BOOL titleMode)
  66. {
  67. COLORREF frontColor, backColor;
  68. WORD backHue, backLuma, backSat, frontHue, frontLuma, frontSat;
  69. backColor = WIDGETSTYLE_BACK_COLOR(style);
  70. frontColor = WIDGETSTYLE_TEXT_COLOR(style);
  71. ColorRGBToHLS(backColor, &backHue, &backLuma, &backSat);
  72. ColorRGBToHLS(frontColor, &frontHue, &frontLuma, &frontSat);
  73. if(frontLuma > backLuma)
  74. {
  75. if (NULL != shadowColor)
  76. {
  77. if (FALSE != titleMode || backLuma > 180)
  78. *shadowColor = Graphics_BlendColors(0x000000, backColor, 102);
  79. else
  80. *shadowColor = backColor;
  81. }
  82. return Graphics_BlendColors((FALSE != titleMode) ? 0xBBBBBB : 0xEEEEEE, frontColor, 230);
  83. }
  84. if (NULL != shadowColor)
  85. {
  86. if (FALSE != titleMode || backLuma < 60)
  87. *shadowColor = Graphics_BlendColors(0xFFFFFF, backColor, 102);
  88. else
  89. *shadowColor = backColor;
  90. }
  91. return Graphics_BlendColors((FALSE != titleMode) ? 0x333333 : 0x111111, frontColor, 230);
  92. }
  93. static HFONT
  94. WelcomeWidget_CreateTitleFont(WidgetStyle *style, HDC hdc)
  95. {
  96. LOGFONT lf;
  97. HFONT textFont;
  98. long height, pixelsY;
  99. pixelsY = GetDeviceCaps(hdc, LOGPIXELSY);
  100. height = MulDiv(16, pixelsY, 96);
  101. textFont = WIDGETSTYLE_TITLE_FONT(style);
  102. if (NULL != textFont)
  103. {
  104. HFONT prevFont;
  105. TEXTMETRIC tm;
  106. prevFont = SelectFont(hdc, textFont);
  107. if (FALSE != GetTextMetricsW(hdc, &tm))
  108. {
  109. long test = MulDiv(tm.tmHeight - tm.tmInternalLeading, 96, pixelsY);
  110. test = MulDiv((test + 2), pixelsY, 72);
  111. if (test > height)
  112. height = test;
  113. }
  114. SelectFont(hdc, prevFont);
  115. }
  116. lf.lfHeight = -height;
  117. lf.lfWidth = 0;
  118. lf.lfEscapement = 0;
  119. lf.lfOrientation = 0;
  120. lf.lfWeight = FW_DONTCARE;
  121. lf.lfItalic = FALSE;
  122. lf.lfUnderline = FALSE;
  123. lf.lfStrikeOut = FALSE;
  124. lf.lfCharSet = DEFAULT_CHARSET;
  125. lf.lfOutPrecision = OUT_DEFAULT_PRECIS;
  126. lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
  127. lf.lfQuality = Graphics_GetSysFontQuality();
  128. lf.lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE;
  129. StringCchCopy(lf.lfFaceName, ARRAYSIZE(lf.lfFaceName), L"Arial");
  130. return CreateFontIndirect(&lf);
  131. }
  132. static BOOL
  133. WelcomeWidget_FillContext(HDC targetDC, long width, long height, HDC sourceDC,
  134. HBITMAP backBitmap, long backWidth, long backHeight, WidgetStyle *style)
  135. {
  136. RECT rect, partRect;
  137. wchar_t buffer[4096] = {0};
  138. int bufferLength;
  139. COLORREF textColor, shadowColor;
  140. HFONT prevFont;
  141. if (NULL == targetDC ||
  142. NULL == sourceDC ||
  143. NULL == style)
  144. {
  145. return FALSE;
  146. }
  147. SetRect(&rect, 0, 0, width, height);
  148. FillRect(targetDC, &rect, WIDGETSTYLE_BACK_BRUSH(style));
  149. if (NULL != backBitmap)
  150. {
  151. Image_AlphaBlend(targetDC, &rect, sourceDC, NULL, 255, backBitmap, NULL,
  152. AlphaBlend_AlignCenter | AlphaBlend_AlignVCenter, NULL);
  153. }
  154. SetBkMode(targetDC, TRANSPARENT);
  155. WASABI_API_LNGSTRINGW_BUF(IDS_WELCOMEWIDGET_TITLE, buffer, ARRAYSIZE(buffer));
  156. if (L'\0' != buffer[0])
  157. {
  158. BOOL textMode;
  159. textMode = TRUE;
  160. if (CSTR_EQUAL == CompareString(CSTR_INVARIANT, NORM_IGNORECASE, buffer, -1, L"WINAMP DEVICE MANAGER", -1))
  161. {
  162. HBITMAP titleBitmap;
  163. titleBitmap = Image_LoadEx(Plugin_GetInstance(), MAKEINTRESOURCE(IDR_WELCOME_WIDGET_TITLE_IMAGE),
  164. SRC_TYPE_PNG, ISF_PREMULTIPLY, 0, 0);
  165. if (NULL != titleBitmap)
  166. {
  167. SetRect(&partRect, rect.left, rect.top, rect.right, rect.top + WELCOMEWIDGET_TITLE_MAX_HEIGHT);
  168. if (FALSE != Image_AlphaBlend(targetDC, &partRect, sourceDC, NULL, 255, titleBitmap, NULL,
  169. AlphaBlend_AlignCenter | AlphaBlend_AlignVCenter, NULL))
  170. {
  171. textMode = FALSE;
  172. }
  173. DeleteObject(titleBitmap);
  174. }
  175. }
  176. if (FALSE != textMode)
  177. {
  178. HFONT titleFont;
  179. bufferLength = lstrlen(buffer);
  180. titleFont = WelcomeWidget_CreateTitleFont(style, targetDC);
  181. textColor = WelcomeWidget_GetTextColor(style, &shadowColor, TRUE);
  182. prevFont = SelectFont(targetDC, (NULL != titleFont) ? titleFont : WIDGETSTYLE_TITLE_FONT(style));
  183. SetRect(&partRect, 0, 0, width, 0);
  184. if (FALSE != DrawText(targetDC, buffer, bufferLength, &partRect,
  185. DT_CALCRECT | DT_LEFT | DT_TOP | DT_WORDBREAK | DT_NOPREFIX | DT_EDITCONTROL | DT_END_ELLIPSIS))
  186. {
  187. if (partRect.bottom > WELCOMEWIDGET_TITLE_MAX_HEIGHT)
  188. {
  189. TEXTMETRIC textMetrics;
  190. if (FALSE != GetTextMetrics(targetDC, &textMetrics))
  191. partRect.bottom = (WELCOMEWIDGET_TITLE_MAX_HEIGHT/textMetrics.tmHeight)*textMetrics.tmHeight;
  192. }
  193. OffsetRect(&partRect,
  194. rect.left + (RECTWIDTH(rect) - RECTWIDTH(partRect))/2,
  195. rect.top + (WELCOMEWIDGET_TITLE_MAX_HEIGHT - RECTHEIGHT(partRect))/2);
  196. OffsetRect(&partRect, 0, 2);
  197. SetTextColor(targetDC, shadowColor);
  198. DrawText(targetDC, buffer, bufferLength, &partRect,
  199. DT_CENTER | DT_TOP | DT_WORDBREAK | DT_NOPREFIX | DT_EDITCONTROL | DT_END_ELLIPSIS);
  200. OffsetRect(&partRect, 0, -2);
  201. SetTextColor(targetDC, textColor);
  202. DrawText(targetDC, buffer, bufferLength, &partRect,
  203. DT_CENTER | DT_TOP | DT_WORDBREAK | DT_NOPREFIX | DT_EDITCONTROL | DT_END_ELLIPSIS);
  204. }
  205. SelectFont(targetDC, prevFont);
  206. if (NULL != titleFont)
  207. DeleteObject(titleFont);
  208. }
  209. }
  210. WASABI_API_LNGSTRINGW_BUF(IDS_WELCOMEWIDGET_TEXT, buffer, ARRAYSIZE(buffer));
  211. if (L'\0' != buffer[0])
  212. {
  213. bufferLength = lstrlen(buffer);
  214. textColor = WelcomeWidget_GetTextColor(style, &shadowColor, FALSE);
  215. prevFont = SelectFont(targetDC, WIDGETSTYLE_TEXT_FONT(style));
  216. SetRect(&partRect, 0, 0, WELCOMEWIDGET_TEXT_MIN_WIDTH, WELCOMEWIDGET_TEXT_MAX_HEIGHT);
  217. if (FALSE != WelcomeWidget_GetBestTextRect(targetDC, buffer, bufferLength, &partRect, width,
  218. DT_LEFT | DT_TOP | DT_WORDBREAK | DT_NOPREFIX | DT_EDITCONTROL | DT_END_ELLIPSIS))
  219. {
  220. if (partRect.bottom > WELCOMEWIDGET_TEXT_MAX_HEIGHT)
  221. {
  222. TEXTMETRIC textMetrics;
  223. if (FALSE != GetTextMetrics(targetDC, &textMetrics))
  224. partRect.bottom = (WELCOMEWIDGET_TEXT_MAX_HEIGHT/textMetrics.tmHeight)*textMetrics.tmHeight;
  225. }
  226. OffsetRect(&partRect,
  227. rect.left + (RECTWIDTH(rect) - RECTWIDTH(partRect))/2,
  228. rect.bottom - WELCOMEWIDGET_TEXT_MAX_HEIGHT);
  229. OffsetRect(&partRect, 0, 1);
  230. SetTextColor(targetDC, shadowColor);
  231. DrawText(targetDC, buffer, bufferLength, &partRect,
  232. DT_LEFT | DT_TOP | DT_WORDBREAK | DT_NOPREFIX | DT_EDITCONTROL | DT_END_ELLIPSIS);
  233. OffsetRect(&partRect, 0, -1);
  234. SetTextColor(targetDC, textColor);
  235. DrawText(targetDC, buffer, bufferLength, &partRect,
  236. DT_LEFT | DT_TOP | DT_WORDBREAK | DT_NOPREFIX | DT_EDITCONTROL | DT_END_ELLIPSIS);
  237. }
  238. SelectFont(targetDC, prevFont);
  239. }
  240. return TRUE;
  241. }
  242. static HDC
  243. WelcomeWidget_CreateContext(HWND hwnd, WidgetStyle *style, HBITMAP *prevBitmapOut, long *widthOut, long *heightOut)
  244. {
  245. HDC windowDC, targetDC, sourceDC;
  246. HBITMAP backBitmap, targetBitmap;
  247. HBITMAP prevTargetBitmap;
  248. long width, height, backWidth, backHeight;
  249. if (NULL == prevBitmapOut || NULL == style)
  250. return NULL;
  251. windowDC = GetDCEx(hwnd, NULL, DCX_CACHE | DCX_NORESETATTRS);
  252. if (NULL == windowDC)
  253. return NULL;
  254. backBitmap = Image_LoadEx(Plugin_GetInstance(), MAKEINTRESOURCE(IDR_WELCOME_WIDGET_IMAGE),
  255. SRC_TYPE_PNG, ISF_PREMULTIPLY, 0, 0);
  256. width = WELCOMEWIDGET_IMAGE_MIN_WIDTH;
  257. height = WELCOMEWIDGET_IMAGE_MIN_HEIGHT;
  258. backWidth = 0;
  259. backHeight = 0;
  260. if (NULL != backBitmap)
  261. {
  262. BITMAP bi;
  263. if (sizeof(bi) == GetObject(backBitmap, sizeof(bi), &bi))
  264. {
  265. backWidth = bi.bmWidth;
  266. if (backWidth > width)
  267. width = backWidth;
  268. backHeight = ABS(bi.bmHeight);
  269. if (backHeight > height)
  270. height = backHeight;
  271. }
  272. }
  273. targetDC = CreateCompatibleDC(windowDC);
  274. sourceDC = CreateCompatibleDC(windowDC);
  275. targetBitmap = CreateCompatibleBitmap(windowDC, width, height);
  276. prevTargetBitmap = NULL;
  277. ReleaseDC(hwnd, windowDC);
  278. if (NULL != targetDC &&
  279. NULL != sourceDC &&
  280. NULL != targetBitmap)
  281. {
  282. HFONT prevTargetFont;
  283. prevTargetBitmap = SelectBitmap(targetDC, targetBitmap);
  284. prevTargetFont = GetCurrentFont(targetDC);
  285. HBITMAP prevSourceBitmap = GetCurrentBitmap(sourceDC);
  286. if (FALSE == WelcomeWidget_FillContext(targetDC, width, height, sourceDC,
  287. backBitmap, backWidth, backHeight, style))
  288. {
  289. SelectBitmap(targetDC, prevTargetBitmap);
  290. prevTargetBitmap = NULL;
  291. DeleteObject(targetBitmap);
  292. targetBitmap = NULL;
  293. }
  294. SelectFont(targetDC, prevTargetFont);
  295. SelectBitmap(sourceDC, prevSourceBitmap);
  296. }
  297. if (NULL != sourceDC)
  298. DeleteDC(sourceDC);
  299. if (NULL != targetDC && NULL == targetBitmap)
  300. {
  301. DeleteDC(targetDC);
  302. targetDC = NULL;
  303. prevTargetBitmap = NULL;
  304. }
  305. if (NULL != backBitmap)
  306. DeleteObject(backBitmap);
  307. *prevBitmapOut = prevTargetBitmap;
  308. if (NULL != widthOut)
  309. *widthOut = width;
  310. if (NULL != heightOut)
  311. *heightOut = height;
  312. return targetDC;
  313. }
  314. static void
  315. WelcomeWidget_ResetContext(WelcomeWidget * self)
  316. {
  317. if (NULL == self ||
  318. NULL == self->context)
  319. {
  320. return;
  321. }
  322. if (NULL != self->previousBitmap)
  323. {
  324. HBITMAP bitmap = SelectBitmap(self->context, self->previousBitmap);
  325. if (NULL != bitmap)
  326. DeleteObject(bitmap);
  327. }
  328. DeleteDC(self->context);
  329. self->context = NULL;
  330. self->previousBitmap = NULL;
  331. self->contextWidth = 0;
  332. self->contextHeight = 0;
  333. }
  334. static BOOL
  335. WelcomeWidget_GetViewOrigin(HWND hwnd, POINT *pt)
  336. {
  337. SCROLLINFO scrollInfo;
  338. if (NULL == pt)
  339. return FALSE;
  340. scrollInfo.cbSize = sizeof(scrollInfo);
  341. scrollInfo.fMask = SIF_POS;
  342. if (FALSE == GetScrollInfo(hwnd, SB_HORZ, &scrollInfo))
  343. return FALSE;
  344. pt->x = -scrollInfo.nPos;
  345. if (FALSE == GetScrollInfo(hwnd, SB_VERT, &scrollInfo))
  346. return FALSE;
  347. pt->y = -scrollInfo.nPos;
  348. return TRUE;
  349. }
  350. static BOOL
  351. WelcomeWidget_UpdateHelpPosition(WelcomeWidget *self, HWND hwnd, const RECT *clientRect, BOOL redraw)
  352. {
  353. HWND elementWindow;
  354. RECT elementRect;
  355. unsigned int positionFlags;
  356. long left, top;
  357. POINT origin;
  358. if (NULL == self || NULL == hwnd || NULL == clientRect)
  359. return FALSE;
  360. elementWindow = GetDlgItem(hwnd, WELCOMEWIDGET_HELP_LINK);
  361. if (NULL == elementWindow)
  362. return FALSE;
  363. if (FALSE == WelcomeWidget_GetViewOrigin(hwnd, &origin))
  364. {
  365. origin.x = 0;
  366. origin.y = 0;
  367. }
  368. if (FALSE == GetWindowRect(elementWindow, &elementRect))
  369. return FALSE;
  370. positionFlags = SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOSIZE;
  371. if (FALSE == redraw)
  372. positionFlags |= SWP_NOREDRAW;
  373. left = clientRect->right;
  374. left -= (RECTWIDTH(elementRect) + 2);
  375. if (left < clientRect->left)
  376. left = clientRect->left;
  377. top = clientRect->top;
  378. top += 2;
  379. return SetWindowPos(elementWindow, NULL, left, origin.y + top, 0, 0, positionFlags);
  380. }
  381. static BOOL
  382. WelcomeWidget_EnsureHelpVisible(WelcomeWidget *self, HWND hwnd)
  383. {
  384. HWND elementWindow;
  385. POINT origin;
  386. if (NULL == self || NULL == hwnd)
  387. return FALSE;
  388. elementWindow = GetDlgItem(hwnd, WELCOMEWIDGET_HELP_LINK);
  389. if (NULL == elementWindow)
  390. return FALSE;
  391. if (FALSE != WelcomeWidget_GetViewOrigin(hwnd, &origin) &&
  392. 0 != origin.y)
  393. {
  394. return WIDGET_SCROLL(hwnd, 0, origin.y, TRUE);
  395. }
  396. return FALSE;
  397. }
  398. static BOOL
  399. WelcomeWidget_GetHelpUrl(wchar_t *buffer, size_t bufferMax)
  400. {
  401. if (NULL == buffer)
  402. return FALSE;
  403. WASABI_API_LNGSTRINGW_BUF(IDS_WELCOMEWIDGET_HELP_URL, buffer, bufferMax);
  404. return (L'\0' != buffer[0]);
  405. }
  406. static BOOL
  407. WelcomeWidget_InitCb(HWND hwnd, void **object, void *param)
  408. {
  409. wchar_t buffer[64] = {0};
  410. WelcomeWidget *self = (WelcomeWidget*)malloc(sizeof(WelcomeWidget));
  411. if (NULL == self)
  412. return FALSE;
  413. ZeroMemory(self, sizeof(WelcomeWidget));
  414. WIDGET_ENABLE_CHILDREN_SCROLL(hwnd, FALSE);
  415. WASABI_API_LNGSTRINGW_BUF(IDS_HELP_LINK, buffer, ARRAYSIZE(buffer));
  416. CommandLink_CreateWindow(WS_EX_NOPARENTNOTIFY,
  417. buffer,
  418. WS_CHILD | WS_VISIBLE | WS_TABSTOP |
  419. /*CLS_ALWAYSUNDERLINE |*/ CLS_HOTTRACK | CLS_HIGHLIGHTCOLOR,
  420. 0, 0, 0, 0, hwnd, WELCOMEWIDGET_HELP_LINK);
  421. *object = self;
  422. return TRUE;
  423. }
  424. static void
  425. WelcomeWidget_DestroyCb(WelcomeWidget *self, HWND hwnd)
  426. {
  427. if (NULL == self)
  428. return;
  429. WelcomeWidget_ResetContext(self);
  430. if (NULL != self->helpFont)
  431. DeleteObject(self->helpFont);
  432. free(self);
  433. }
  434. static void
  435. WelcomeWidget_LayoutCb(WelcomeWidget *self, HWND hwnd, WidgetStyle *style,
  436. const RECT *clientRect, SIZE *viewSize, BOOL redraw)
  437. {
  438. if (NULL == self || NULL == style)
  439. return;
  440. if (NULL == self->context)
  441. {
  442. self->context = WelcomeWidget_CreateContext(hwnd, style, &self->previousBitmap, &self->contextWidth, &self->contextHeight);
  443. if (NULL == self->context)
  444. return;
  445. }
  446. viewSize->cx = self->contextWidth +
  447. WIDGETSTYLE_DLU_TO_HORZ_PX(style, WELCOMEWIDGET_OFFSET_LEFT_DLU);
  448. viewSize->cy = self->contextHeight +
  449. WIDGETSTYLE_DLU_TO_VERT_PX(style, WELCOMEWIDGET_OFFSET_TOP_DLU);
  450. WelcomeWidget_UpdateHelpPosition(self, hwnd, clientRect, redraw);
  451. }
  452. static BOOL
  453. WelcomeWidget_PaintCb(WelcomeWidget *self, HWND hwnd, WidgetStyle *style, HDC hdc, const RECT *paintRect, BOOL erase)
  454. {
  455. FillRegion fillRegion;
  456. FillRegion_Init(&fillRegion, paintRect);
  457. if (NULL != self->context)
  458. {
  459. RECT partRect, rect;
  460. long offsetX, offsetY;
  461. GetClientRect(hwnd, &rect);
  462. SetRect(&partRect, 0, 0, self->contextWidth, self->contextHeight);
  463. offsetX = rect.left + WIDGETSTYLE_DLU_TO_HORZ_PX(style, WELCOMEWIDGET_OFFSET_LEFT_DLU);
  464. offsetY = WIDGETSTYLE_DLU_TO_HORZ_PX(style, WELCOMEWIDGET_OFFSET_RIGHT_DLU);
  465. if ((offsetX + partRect.right + offsetY) < rect.right)
  466. offsetX += (rect.right - (offsetX + partRect.right + offsetY))/2;
  467. offsetY = rect.top + WIDGETSTYLE_DLU_TO_VERT_PX(style, WELCOMEWIDGET_OFFSET_TOP_DLU);
  468. OffsetRect(&partRect, offsetX, offsetY);
  469. if (FALSE != IntersectRect(&rect, &partRect, paintRect) &&
  470. FALSE != BitBlt(hdc, rect.left, rect.top, RECTWIDTH(rect), RECTHEIGHT(rect),
  471. self->context, rect.left - partRect.left, rect.top - partRect.top, SRCCOPY))
  472. {
  473. FillRegion_ExcludeRect(&fillRegion, &rect);
  474. }
  475. }
  476. if (FALSE != erase)
  477. FillRegion_BrushFill(&fillRegion, hdc, WIDGETSTYLE_BACK_BRUSH(style));
  478. FillRegion_Uninit(&fillRegion);
  479. return TRUE;
  480. }
  481. static void
  482. WelcomeWidget_StyleColorChangedCb(WelcomeWidget *self, HWND hwnd, WidgetStyle *style)
  483. {
  484. HWND elementWindow;
  485. if (NULL == self)
  486. return;
  487. WelcomeWidget_ResetContext(self);
  488. self->context = WelcomeWidget_CreateContext(hwnd, style, &self->previousBitmap, &self->contextWidth, &self->contextHeight);
  489. elementWindow = GetDlgItem(hwnd, WELCOMEWIDGET_HELP_LINK);
  490. if (NULL != elementWindow)
  491. {
  492. CommandLink_SetBackColor(elementWindow, WIDGETSTYLE_BACK_COLOR(style));
  493. CommandLink_SetTextColor(elementWindow, WelcomeWidget_GetTextColor(style, NULL, TRUE));
  494. CommandLink_SetHighlightColor(elementWindow, WelcomeWidget_GetTextColor(style, NULL, FALSE));
  495. }
  496. }
  497. static void
  498. WelcomeWidget_StyleFontChangedCb(WelcomeWidget *self, HWND hwnd, WidgetStyle *style)
  499. {
  500. HWND elementWindow;
  501. if (NULL == self)
  502. return;
  503. WelcomeWidget_ResetContext(self);
  504. self->context = WelcomeWidget_CreateContext(hwnd, style, &self->previousBitmap, &self->contextWidth, &self->contextHeight);
  505. elementWindow = GetDlgItem(hwnd, WELCOMEWIDGET_HELP_LINK);
  506. if (NULL != elementWindow)
  507. {
  508. SIZE elementSize;
  509. if (NULL != self->helpFont)
  510. DeleteObject(self->helpFont);
  511. self->helpFont = Graphics_DuplicateFont(WIDGETSTYLE_TEXT_FONT(style), 0, TRUE, TRUE);
  512. SendMessage(elementWindow, WM_SETFONT, (WPARAM)self->helpFont, 0L);
  513. if (FALSE != CommandLink_GetIdealSize(elementWindow, &elementSize))
  514. {
  515. SetWindowPos(elementWindow, NULL, 0, 0, elementSize.cx, elementSize.cy,
  516. SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOMOVE);
  517. }
  518. }
  519. }
  520. static void
  521. WelcomeWidget_ScrollCb(WelcomeWidget *self, HWND hwnd, int *dx, int *dy)
  522. {
  523. RECT clientRect;
  524. if (FALSE != GetClientRect(hwnd, &clientRect))
  525. WelcomeWidget_UpdateHelpPosition(self, hwnd, &clientRect, TRUE);
  526. }
  527. static void
  528. WelcomeWidget_HelpLinkCb(WelcomeWidget *self, HWND hwnd, NMHDR *pnmh, LRESULT *result)
  529. {
  530. switch(pnmh->code)
  531. {
  532. case NM_CLICK:
  533. {
  534. wchar_t buffer[4096] = {0};
  535. if (FALSE != WelcomeWidget_GetHelpUrl(buffer, ARRAYSIZE(buffer)))
  536. MediaLibrary_ShowHelp(Plugin_GetLibraryWindow(), buffer);
  537. }
  538. break;
  539. case NM_SETFOCUS:
  540. WelcomeWidget_EnsureHelpVisible(self, hwnd);
  541. break;
  542. }
  543. }
  544. static BOOL
  545. WelcomeWidget_NotifyCb(WelcomeWidget *self, HWND hwnd, NMHDR *pnmh, LRESULT *result)
  546. {
  547. switch(pnmh->idFrom)
  548. {
  549. case WELCOMEWIDGET_HELP_LINK:
  550. WelcomeWidget_HelpLinkCb(self, hwnd, pnmh, result);
  551. return TRUE;
  552. }
  553. return FALSE;
  554. }
  555. static BOOL
  556. WelcomeWidget_HelpCb(WelcomeWidget *self, HWND hwnd, wchar_t *buffer, size_t bufferMax)
  557. {
  558. return WelcomeWidget_GetHelpUrl(buffer, bufferMax);
  559. }
  560. HWND WelcomeWidget_CreateWindow(HWND parentWindow, int x, int y, int width, int height, BOOL border, unsigned int controlId)
  561. {
  562. const static WidgetInterface welcomeWidgetInterface =
  563. {
  564. (WidgetInitCallback)WelcomeWidget_InitCb,
  565. (WidgetDestroyCallback)WelcomeWidget_DestroyCb,
  566. (WidgetLayoutCallback)WelcomeWidget_LayoutCb,
  567. (WidgetPaintCallback)WelcomeWidget_PaintCb,
  568. (WidgetStyleCallback)WelcomeWidget_StyleColorChangedCb,
  569. (WidgetStyleCallback)WelcomeWidget_StyleFontChangedCb,
  570. NULL /*mouseMove*/,
  571. NULL /*leftButtonDown*/,
  572. NULL /*leftButtonUp*/,
  573. NULL /*leftButtonDblClk*/,
  574. NULL /*rightButtonDown*/,
  575. NULL /*rightButtonUp*/,
  576. NULL /*keyDown*/,
  577. NULL /*keyUp*/,
  578. NULL /*character*/,
  579. NULL /*inputRequest*/,
  580. NULL /*focusChanged*/,
  581. NULL /*contextMenu*/,
  582. NULL /*zoomChanging*/,
  583. NULL /*scrollBefore*/,
  584. (WidgetScrollCallback)WelcomeWidget_ScrollCb,
  585. (WidgetNotifyCallback)WelcomeWidget_NotifyCb,
  586. (WidgetHelpCallback)WelcomeWidget_HelpCb,
  587. };
  588. return Widget_CreateWindow(WIDGET_TYPE_WELCOME,
  589. &welcomeWidgetInterface,
  590. NULL,
  591. ((FALSE != border) ? WS_EX_CLIENTEDGE : 0) | WS_EX_CONTROLPARENT,
  592. WS_CLIPCHILDREN | WS_CLIPSIBLINGS,
  593. x, y, width, height,
  594. parentWindow,
  595. controlId, 0L);
  596. }