1
0

widget.cpp 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284
  1. #include "main.h"
  2. #include "./widget.h"
  3. typedef
  4. enum WidgetState
  5. {
  6. WIDGET_STATE_MOUSE_MOVE_TRACKED = (1 << 0),
  7. WIDGET_STATE_DISABLE_CHILDREN_SCROLL = (1 << 1),
  8. } WidgetState;
  9. DEFINE_ENUM_FLAG_OPERATORS(WidgetState);
  10. #define WIDGET_IS_FROZEN(_widget) (0 != (_widget)->freezer)
  11. #define WIDGET_IS_MOUSE_MOVE_TRACKED(_widget) (0 != (WIDGET_STATE_MOUSE_MOVE_TRACKED & (_widget)->state))
  12. #define WIDGET_SET_MOUSE_MOVE_TRACK(_widget) (((_widget)->state) |= WIDGET_STATE_MOUSE_MOVE_TRACKED)
  13. #define WIDGET_UNSET_MOUSE_MOVE_TRACK(_widget) (((_widget)->state) &= ~WIDGET_STATE_MOUSE_MOVE_TRACKED)
  14. #define WIDGET_IS_CHILDREN_SCROLL_DISABLED(_widget) (0 != (WIDGET_STATE_DISABLE_CHILDREN_SCROLL & (_widget)->state))
  15. #define WIDGET_SET_DISABLE_CHILDREN_SCROLL(_widget) (((_widget)->state) |= WIDGET_STATE_DISABLE_CHILDREN_SCROLL)
  16. #define WIDGET_UNSET_DISABLE_CHILDREN_SCROLL(_widget) (((_widget)->state) &= ~WIDGET_STATE_DISABLE_CHILDREN_SCROLL)
  17. typedef struct Widget
  18. {
  19. unsigned int type;
  20. WidgetState state;
  21. const WidgetInterface *callbacks;
  22. void *object;
  23. WidgetStyle *style;
  24. wchar_t *text;
  25. HFONT font;
  26. SIZE viewSize;
  27. POINT viewOrigin;
  28. int wheelCarryover;
  29. size_t freezer;
  30. } Widget;
  31. typedef struct WidgetCreateParam
  32. {
  33. unsigned int type;
  34. const WidgetInterface *callbacks;
  35. void *param;
  36. const wchar_t *text;
  37. } WidgetCreateParam;
  38. #define WIDGET(_hwnd) ((Widget*)(LONGX86)GetWindowLongPtrW((_hwnd), 0))
  39. #define WIDGET_RET_VOID(_view, _hwnd) {(_view) = WIDGET((_hwnd)); if (NULL == (_view)) return;}
  40. #define WIDGET_RET_VAL(_view, _hwnd, _error) {(_view) = WIDGET((_hwnd)); if (NULL == (_view)) return (_error);}
  41. #define WIDGETSTYLE(_widget) (((Widget*)(_widget))->style)
  42. #define WIDGETOBJECT(_widget) (((Widget*)(_widget))->object)
  43. #define WIDGETCALLBACKS(_widget) (((Widget*)(_widget))->callbacks)
  44. static UINT WINAMP_WM_DIRECT_MOUSE_WHEEL = WM_NULL;
  45. static LRESULT CALLBACK
  46. Widget_WindowProc(HWND hwnd, unsigned int uMsg, WPARAM wParam, LPARAM lParam);
  47. static ATOM
  48. Widget_GetClassAtom(HINSTANCE instance)
  49. {
  50. WNDCLASSEXW klass;
  51. ATOM klassAtom;
  52. klassAtom = (ATOM)GetClassInfoExW(instance, WIDGET_WINDOW_CLASS, &klass);
  53. if (0 != klassAtom)
  54. return klassAtom;
  55. memset(&klass, 0, sizeof(klass));
  56. klass.cbSize = sizeof(klass);
  57. klass.style = CS_DBLCLKS;
  58. klass.lpfnWndProc = Widget_WindowProc;
  59. klass.cbClsExtra = 0;
  60. klass.cbWndExtra = sizeof(Widget*);
  61. klass.hInstance = instance;
  62. klass.hIcon = NULL;
  63. klass.hCursor = LoadCursorW(NULL, (LPCWSTR)IDC_ARROW);
  64. klass.hbrBackground = NULL;
  65. klass.lpszMenuName = NULL;
  66. klass.lpszClassName = WIDGET_WINDOW_CLASS;
  67. klass.hIconSm = NULL;
  68. klassAtom = RegisterClassExW(&klass);
  69. return klassAtom;
  70. }
  71. HWND
  72. Widget_CreateWindow(unsigned int type, const WidgetInterface *callbacks,
  73. const wchar_t *text, unsigned long windowExStyle, unsigned long windowStyle,
  74. int x, int y, int width, int height,
  75. HWND parentWindow, unsigned int controlId, void *param)
  76. {
  77. HINSTANCE instance;
  78. ATOM klassAtom;
  79. HWND hwnd;
  80. WidgetCreateParam createParam;
  81. if (NULL == parentWindow || FALSE == IsWindow(parentWindow))
  82. return NULL;
  83. instance = GetModuleHandleW(NULL);
  84. klassAtom = Widget_GetClassAtom(instance);
  85. if (0 == klassAtom)
  86. return NULL;
  87. createParam.type = type;
  88. createParam.param = param;
  89. createParam.callbacks = callbacks;
  90. createParam.text = text;
  91. hwnd = CreateWindowExW(WS_EX_NOPARENTNOTIFY | windowExStyle, (LPCWSTR)MAKEINTATOM(klassAtom), NULL,
  92. WS_CHILD | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | windowStyle,
  93. x, y, width, height,
  94. parentWindow, (HMENU)controlId, instance, &createParam);
  95. return hwnd;
  96. }
  97. static LRESULT
  98. Widget_DefWindowProc(HWND hwnd, unsigned int uMsg, WPARAM wParam, LPARAM lParam)
  99. {
  100. Widget *self;
  101. self = WIDGET(hwnd);
  102. if (NULL != self && NULL != self->callbacks->messageProc)
  103. {
  104. LRESULT result;
  105. result = 0;
  106. if (FALSE != self->callbacks->messageProc(self->object,
  107. hwnd, uMsg, wParam, lParam, &result))
  108. {
  109. return result;
  110. }
  111. }
  112. return DefWindowProc(hwnd, uMsg, wParam, lParam);
  113. }
  114. static void
  115. Widget_Freeze(Widget *self)
  116. {
  117. if (NULL != self)
  118. self->freezer++;
  119. }
  120. static void
  121. Widget_Thaw(Widget *self)
  122. {
  123. if (NULL != self && 0 != self->freezer)
  124. self->freezer--;
  125. }
  126. static INT
  127. Widget_ScrollBarOffsetPos(HWND hwnd, INT barType, INT delta, BOOL redraw)
  128. {
  129. Widget *self;
  130. INT position;
  131. SCROLLINFO scrollInfo;
  132. self = WIDGET(hwnd);
  133. scrollInfo.cbSize = sizeof(scrollInfo);
  134. scrollInfo.fMask = SIF_POS | SIF_RANGE | SIF_PAGE;
  135. if (FALSE == GetScrollInfo(hwnd, barType, &scrollInfo))
  136. return 0;
  137. position = scrollInfo.nPos + delta;
  138. if (position < scrollInfo.nMin)
  139. position = scrollInfo.nMin;
  140. else if (position > (scrollInfo.nMax - (INT)scrollInfo.nPage))
  141. position = scrollInfo.nMax - (INT)scrollInfo.nPage + 1;
  142. delta = position - scrollInfo.nPos;
  143. scrollInfo.fMask = SIF_POS;
  144. scrollInfo.nPos = position;
  145. SetScrollInfo(hwnd, barType, &scrollInfo, redraw);
  146. if (NULL != self)
  147. {
  148. if (SB_HORZ == barType)
  149. self->viewOrigin.x = -position;
  150. else
  151. self->viewOrigin.y = -position;
  152. }
  153. return delta;
  154. }
  155. static BOOL
  156. Widget_ScrollContent(HWND hwnd, int dx, int dy, BOOL redraw)
  157. {
  158. Widget *self;
  159. UINT scrollFlags;
  160. HRGN invalidRgn;
  161. INT scrollError;
  162. if (0 == dx && 0 == dy)
  163. return FALSE;
  164. self = WIDGET(hwnd);
  165. if (NULL != self &&
  166. NULL != self->callbacks &&
  167. NULL != self->callbacks->scrollBefore)
  168. {
  169. self->callbacks->scrollBefore(WIDGETOBJECT(self), hwnd, &dx, &dy);
  170. if (0 == dx && 0 == dy)
  171. return FALSE;
  172. }
  173. scrollFlags = (FALSE == WIDGET_IS_CHILDREN_SCROLL_DISABLED(self)) ? SW_SCROLLCHILDREN : 0;
  174. if (FALSE != redraw)
  175. {
  176. invalidRgn = CreateRectRgn(0, 0, 0, 0);
  177. scrollFlags |= SW_INVALIDATE | SW_ERASE;
  178. }
  179. else
  180. {
  181. invalidRgn = NULL;
  182. }
  183. scrollError = ScrollWindowEx(hwnd, -dx, -dy, NULL, NULL, invalidRgn, NULL, scrollFlags);
  184. if (ERROR != scrollError)
  185. {
  186. if (NULL != self &&
  187. NULL != self->callbacks &&
  188. NULL != self->callbacks->scroll)
  189. {
  190. self->callbacks->scroll(WIDGETOBJECT(self), hwnd, &dx, &dy);
  191. }
  192. if (FALSE != redraw && NULLREGION != scrollError)
  193. {
  194. RedrawWindow(hwnd, NULL, invalidRgn,
  195. RDW_ERASENOW | RDW_UPDATENOW | RDW_ALLCHILDREN);
  196. }
  197. }
  198. if (NULL != invalidRgn)
  199. DeleteObject(invalidRgn);
  200. return (ERROR != scrollError);
  201. }
  202. static BOOL
  203. Widget_SyncContentOrigin(HWND hwnd, BOOL redraw)
  204. {
  205. Widget *self;
  206. RECT clientRect;
  207. SCROLLINFO scrollInfo;
  208. INT dx, dy;
  209. WIDGET_RET_VAL(self, hwnd, FALSE);
  210. scrollInfo.cbSize = sizeof(scrollInfo);
  211. scrollInfo.fMask = SIF_POS;
  212. if (FALSE == GetClientRect(hwnd, &clientRect))
  213. SetRectEmpty(&clientRect);
  214. if (self->viewSize.cx < RECTWIDTH(clientRect))
  215. {
  216. scrollInfo.nPos = 0;
  217. dx = scrollInfo.nPos + self->viewOrigin.x;
  218. self->viewOrigin.x = 0;
  219. }
  220. else if (FALSE != GetScrollInfo(hwnd, SB_HORZ, &scrollInfo))
  221. {
  222. dx = scrollInfo.nPos + self->viewOrigin.x;
  223. self->viewOrigin.x = -scrollInfo.nPos;
  224. }
  225. else
  226. dx = 0;
  227. if (FALSE != GetScrollInfo(hwnd, SB_VERT, &scrollInfo))
  228. {
  229. dy = scrollInfo.nPos + self->viewOrigin.y;
  230. self->viewOrigin.y = -scrollInfo.nPos;
  231. }
  232. else
  233. dy = 0;
  234. if (0 == dx && 0 == dy)
  235. return FALSE;
  236. return Widget_ScrollContent(hwnd, dx, dy, redraw);
  237. }
  238. static BOOL
  239. Widget_ScrollWindow(HWND hwnd, INT dx, INT dy, BOOL redraw)
  240. {
  241. if (0 != dx)
  242. dx = Widget_ScrollBarOffsetPos(hwnd, SB_HORZ, dx, redraw);
  243. if (0 != dy)
  244. dy = Widget_ScrollBarOffsetPos(hwnd, SB_VERT, dy, redraw);
  245. return Widget_ScrollContent(hwnd, dx, dy, redraw);
  246. }
  247. static BOOL
  248. Widget_ScrollBarAction(HWND hwnd, INT barType, INT actionLayout, INT line, BOOL redraw)
  249. {
  250. INT delta;
  251. SCROLLINFO scrollInfo;
  252. scrollInfo.cbSize = sizeof(scrollInfo);
  253. scrollInfo.fMask = SIF_PAGE | SIF_POS | SIF_RANGE | SIF_TRACKPOS;
  254. if (FALSE == GetScrollInfo(hwnd, barType, &scrollInfo))
  255. return FALSE;
  256. switch(actionLayout)
  257. {
  258. case SB_BOTTOM:
  259. delta = scrollInfo.nMax - scrollInfo.nPos;
  260. break;
  261. case SB_TOP:
  262. delta = scrollInfo.nMin - scrollInfo.nPos;
  263. break;
  264. case SB_LINEDOWN:
  265. delta = line;
  266. break;
  267. case SB_LINEUP:
  268. delta = -line;
  269. break;
  270. case SB_PAGEDOWN:
  271. delta = (INT)scrollInfo.nPage;
  272. break;
  273. case SB_PAGEUP:
  274. delta = -(INT)scrollInfo.nPage;
  275. break;
  276. case SB_THUMBTRACK:
  277. delta = scrollInfo.nTrackPos - scrollInfo.nPos;
  278. break;
  279. case SB_THUMBPOSITION:
  280. case SB_ENDSCROLL:
  281. delta = 0;
  282. break;
  283. default:
  284. return FALSE;
  285. }
  286. if(0 != delta)
  287. {
  288. Widget_ScrollWindow(hwnd,
  289. (SB_HORZ == barType) ? delta : 0,
  290. (SB_VERT == barType) ? delta : 0,
  291. redraw);
  292. }
  293. else
  294. Widget_SyncContentOrigin(hwnd, redraw);
  295. return TRUE;
  296. }
  297. static BOOL
  298. Widget_ScrollBarUpdate(HWND hwnd, INT barType, UINT page, INT max, BOOL redraw)
  299. {
  300. Widget *self;
  301. SCROLLINFO scrollInfo;
  302. UINT windowStyle, styleFilter;
  303. WIDGET_RET_VAL(self, hwnd, FALSE);
  304. windowStyle = GetWindowStyle(hwnd);
  305. switch(barType)
  306. {
  307. case SB_HORZ: styleFilter = WS_HSCROLL; break;
  308. case SB_VERT: styleFilter = WS_VSCROLL; break;
  309. default: return FALSE;
  310. }
  311. scrollInfo.cbSize = sizeof(SCROLLINFO);
  312. scrollInfo.fMask = SIF_PAGE | SIF_RANGE;
  313. if (page >= (UINT)max)
  314. {
  315. if (0 == (styleFilter & windowStyle))
  316. return FALSE;
  317. scrollInfo.nPage = page + 1;
  318. scrollInfo.nMin = 0;
  319. scrollInfo.nMax = max;
  320. scrollInfo.nPos = scrollInfo.nMin;
  321. scrollInfo.nTrackPos = scrollInfo.nPos;
  322. scrollInfo.fMask |= (SIF_POS | SIF_TRACKPOS);
  323. Widget_Freeze(self);
  324. SetScrollInfo(hwnd, barType, &scrollInfo, redraw);
  325. Widget_Thaw(self);
  326. windowStyle = GetWindowStyle(hwnd);
  327. if (0 != (styleFilter & windowStyle))
  328. SetWindowStyle(hwnd, windowStyle & ~styleFilter);
  329. return TRUE;
  330. }
  331. if (FALSE == GetScrollInfo(hwnd, barType, &scrollInfo))
  332. {
  333. if (ERROR_NO_SCROLLBARS == GetLastError())
  334. {
  335. scrollInfo.nPage = 0;
  336. scrollInfo.nMax = 0;
  337. scrollInfo.nMin = 0;
  338. scrollInfo.nPos = scrollInfo.nMin;
  339. scrollInfo.nTrackPos = scrollInfo.nPos;
  340. }
  341. else
  342. return FALSE;
  343. }
  344. scrollInfo.fMask = 0;
  345. if (scrollInfo.nPage != page)
  346. {
  347. scrollInfo.nPage = page;
  348. scrollInfo.fMask |= SIF_PAGE;
  349. }
  350. if (scrollInfo.nMax != max)
  351. {
  352. scrollInfo.nMax = max;
  353. scrollInfo.fMask |= SIF_RANGE;
  354. }
  355. if (0 == (styleFilter & windowStyle))
  356. {
  357. scrollInfo.fMask |= (SIF_POS | SIF_TRACKPOS);
  358. scrollInfo.nPos = scrollInfo.nMin;
  359. scrollInfo.nTrackPos = scrollInfo.nMin;
  360. }
  361. if (0 == scrollInfo.fMask)
  362. return FALSE;
  363. Widget_Freeze(self);
  364. SetScrollInfo(hwnd, barType, &scrollInfo, redraw);
  365. Widget_Thaw(self);
  366. if (0 == (styleFilter & windowStyle))
  367. {
  368. windowStyle = GetWindowStyle(hwnd);
  369. if (0 == (styleFilter & windowStyle))
  370. SetWindowStyle(hwnd, windowStyle | styleFilter);
  371. return TRUE;
  372. }
  373. return FALSE;
  374. }
  375. static void
  376. Widget_Layout(HWND hwnd, BOOL redraw)
  377. {
  378. Widget *self;
  379. RECT rect;
  380. size_t iteration;
  381. WIDGET_RET_VOID(self, hwnd);
  382. iteration = 0;
  383. do
  384. {
  385. if (iteration++ > 2)
  386. break;
  387. if (FALSE == GetClientRect(hwnd, &rect))
  388. break;
  389. SetSize(&self->viewSize, 0, 0);
  390. if (NULL != self->callbacks->layout)
  391. {
  392. self->callbacks->layout(self->object, hwnd, self->style, &rect, &self->viewSize, redraw);
  393. }
  394. if (FALSE != IsSizeEmpty(&self->viewSize))
  395. SetSize(&self->viewSize, RECTWIDTH(rect), RECTHEIGHT(rect));
  396. }
  397. while(FALSE != Widget_ScrollBarUpdate(hwnd, SB_HORZ, RECTWIDTH(rect), self->viewSize.cx, redraw) ||
  398. FALSE != Widget_ScrollBarUpdate(hwnd, SB_VERT, RECTHEIGHT(rect), self->viewSize.cy, redraw));
  399. Widget_SyncContentOrigin(hwnd, redraw);
  400. }
  401. static BOOL
  402. Widget_Paint(HWND hwnd, HDC hdc, const RECT *paintRect, BOOL erase)
  403. {
  404. Widget *self;
  405. BOOL result;
  406. self = WIDGET(hwnd);
  407. if (NULL == self || NULL == self->style)
  408. return FALSE;
  409. if (NULL != self->callbacks->paint)
  410. {
  411. POINT prevOrigin;
  412. RECT viewRect;
  413. CopyRect(&viewRect, paintRect);
  414. OffsetRect(&viewRect, -self->viewOrigin.x, -self->viewOrigin.y);
  415. OffsetViewportOrgEx(hdc, self->viewOrigin.x, self->viewOrigin.y, &prevOrigin);
  416. result = self->callbacks->paint(self->object, hwnd,
  417. self->style, hdc, &viewRect, erase);
  418. SetViewportOrgEx(hdc, prevOrigin.x, prevOrigin.y, NULL);
  419. }
  420. else
  421. result = FALSE;
  422. if (FALSE == result)
  423. {
  424. if (FALSE != erase)
  425. result = FillRect(hdc, paintRect, WIDGETSTYLE_BACK_BRUSH(self->style));
  426. else
  427. result = TRUE;
  428. }
  429. return result;
  430. }
  431. static void
  432. Widget_FocusChanged(HWND hwnd, HWND focusWindow, BOOL focusReceived)
  433. {
  434. Widget *self;
  435. WIDGET_RET_VOID(self, hwnd);
  436. if (NULL != self->callbacks &&
  437. NULL != self->callbacks->focusChanged)
  438. {
  439. self->callbacks->focusChanged(self->object, hwnd, focusWindow, focusReceived);
  440. }
  441. }
  442. static LRESULT
  443. Widget_OnCreate(HWND hwnd, CREATESTRUCT *createStruct)
  444. {
  445. Widget *self;
  446. WidgetCreateParam *createParam;
  447. if (NULL == createStruct)
  448. return -1;
  449. createParam = (WidgetCreateParam*)createStruct->lpCreateParams;
  450. if (NULL == createParam)
  451. return -1;
  452. self = (Widget*)malloc(sizeof(Widget));
  453. if (NULL == self)
  454. return -1;
  455. SetLastError(ERROR_SUCCESS);
  456. if (!SetWindowLongPtr(hwnd, 0, (LONGX86)self) && ERROR_SUCCESS != GetLastError())
  457. return -1;
  458. memset(self, 0, sizeof(Widget));
  459. if (WM_NULL == WINAMP_WM_DIRECT_MOUSE_WHEEL)
  460. WINAMP_WM_DIRECT_MOUSE_WHEEL = RegisterWindowMessageW(L"WINAMP_WM_DIRECT_MOUSE_WHEEL");
  461. self->type = createParam->type;
  462. self->callbacks = createParam->callbacks;
  463. Widget_Freeze(self);
  464. if (NULL != createParam->text)
  465. SendMessage(hwnd, WM_SETTEXT, 0, (LPARAM)createParam->text);
  466. MLSkinWindow2(Plugin_GetLibraryWindow(), hwnd, SKINNEDWND_TYPE_SCROLLWND,
  467. SWS_USESKINFONT | SWS_USESKINCOLORS | SWS_USESKINCURSORS);
  468. if (NULL != self->callbacks->init &&
  469. FALSE == self->callbacks->init(hwnd, &self->object, createParam->param))
  470. {
  471. return -1;
  472. }
  473. Widget_Thaw(self);
  474. return 0;
  475. }
  476. static void
  477. Widget_OnDestroy(HWND hwnd)
  478. {
  479. Widget *self;
  480. self = WIDGET(hwnd);
  481. SetWindowLongPtr(hwnd, 0, 0);
  482. if (NULL == self)
  483. return;
  484. Widget_Freeze(self);
  485. if (NULL != self->callbacks->destroy)
  486. self->callbacks->destroy(self->object, hwnd);
  487. String_Free(self->text);
  488. free(self);
  489. }
  490. static void
  491. Widget_OnPaint(HWND hwnd)
  492. {
  493. PAINTSTRUCT ps;
  494. if (NULL != BeginPaint(hwnd, &ps))
  495. {
  496. if (FALSE == Widget_Paint(hwnd, ps.hdc, &ps.rcPaint, ps.fErase))
  497. {
  498. COLORREF backColor, prevBackColor;
  499. backColor = Graphics_GetSkinColor(WADLG_WNDBG);
  500. prevBackColor = SetBkColor(ps.hdc, backColor);
  501. ExtTextOut(ps.hdc, 0, 0, ETO_OPAQUE, &ps.rcPaint, NULL, 0, NULL);
  502. SetBkColor(ps.hdc, prevBackColor);
  503. }
  504. EndPaint(hwnd, &ps);
  505. }
  506. }
  507. static void
  508. Widget_OnPrintClient(HWND hwnd, HDC hdc, UINT options)
  509. {
  510. RECT clientRect;
  511. if (GetClientRect(hwnd, &clientRect))
  512. {
  513. Widget_Paint(hwnd, hdc, &clientRect, TRUE);
  514. }
  515. }
  516. static void
  517. Widget_OnWindowPosChanged(HWND hwnd, WINDOWPOS *windowPos)
  518. {
  519. if ((SWP_NOSIZE | SWP_NOMOVE) != ((SWP_NOSIZE | SWP_NOMOVE | SWP_FRAMECHANGED) & windowPos->flags))
  520. {
  521. Widget *self;
  522. WIDGET_RET_VOID(self, hwnd);
  523. if (FALSE != WIDGET_IS_FROZEN(self))
  524. return;
  525. Widget_Layout(hwnd, 0 == (SWP_NOREDRAW & windowPos->flags));
  526. }
  527. }
  528. static LRESULT
  529. Widget_OnSetText(HWND hwnd, LPCWSTR text)
  530. {
  531. Widget *self;
  532. WIDGET_RET_VAL(self, hwnd, FALSE);
  533. String_Free(self->text);
  534. if (NULL == text)
  535. self->text = NULL;
  536. else if (FALSE != IS_INTRESOURCE(text))
  537. {
  538. WCHAR buffer[4096] = {0};
  539. ResourceString_CopyTo(buffer, text, ARRAYSIZE(buffer));
  540. self->text = String_Duplicate(buffer);
  541. }
  542. else
  543. self->text = String_Duplicate(text);
  544. return TRUE;
  545. }
  546. static LRESULT
  547. Widget_OnGetText(HWND hwnd, LPWSTR buffer, size_t bufferMax)
  548. {
  549. Widget *self;
  550. WIDGET_RET_VAL(self, hwnd, 0);
  551. return String_CopyTo(buffer, self->text, bufferMax);
  552. }
  553. static LRESULT
  554. Widget_OnGetTextLength(HWND hwnd)
  555. {
  556. Widget *self;
  557. WIDGET_RET_VAL(self, hwnd, 0);
  558. return ( NULL != self->text) ? lstrlenW(self->text) : 0;
  559. }
  560. static void
  561. Widget_OnSetFont(HWND hwnd, HFONT font, BOOL redraw)
  562. {
  563. Widget *self;
  564. WIDGET_RET_VOID(self, hwnd);
  565. self->font = font;
  566. if (NULL != redraw)
  567. InvalidateRect(hwnd, NULL, TRUE);
  568. }
  569. static HFONT
  570. Widget_OnGetFont(HWND hwnd)
  571. {
  572. Widget *self;
  573. WIDGET_RET_VAL(self, hwnd, NULL);
  574. return self->font;
  575. }
  576. static void
  577. Widget_OnVertScroll(HWND hwnd, INT actionLayout, INT trackPosition, HWND scrollBar)
  578. {
  579. Widget *self;
  580. WIDGET_RET_VOID(self, hwnd);
  581. Widget_ScrollBarAction(hwnd, SB_VERT, actionLayout, self->style->unitSize.cy, TRUE);
  582. }
  583. static void
  584. Widget_OnHorzScroll(HWND hwnd, INT actionLayout, INT trackPosition, HWND scrollBar)
  585. {
  586. Widget *self;
  587. WIDGET_RET_VOID(self, hwnd);
  588. Widget_ScrollBarAction(hwnd, SB_HORZ, actionLayout, self->style->unitSize.cx, TRUE);
  589. }
  590. static void
  591. Widget_OnMouseWheel(HWND hwnd, INT virtualKeys, INT distance, LONG pointer_s)
  592. {
  593. Widget *self;
  594. UINT wheelScroll;
  595. INT scrollLines;
  596. UINT windowStyle;
  597. INT barType;
  598. WIDGET_RET_VOID(self, hwnd);
  599. windowStyle = GetWindowStyle(hwnd);
  600. if (0 != (WS_VSCROLL & windowStyle))
  601. barType = SB_VERT;
  602. else if (0 != (WS_HSCROLL & windowStyle))
  603. barType = SB_HORZ;
  604. else
  605. return;
  606. if (FALSE == SystemParametersInfo(SPI_GETWHEELSCROLLLINES, 0, &wheelScroll, 0))
  607. wheelScroll = 3;
  608. if (0 == wheelScroll)
  609. return;
  610. if (WHEEL_PAGESCROLL == wheelScroll)
  611. {
  612. RECT clientRect;
  613. GetClientRect(hwnd, &clientRect);
  614. if (SB_VERT == barType)
  615. wheelScroll = RECTHEIGHT(clientRect)/self->style->unitSize.cy;
  616. else
  617. wheelScroll = RECTWIDTH(clientRect)/self->style->unitSize.cx;
  618. }
  619. distance += self->wheelCarryover;
  620. scrollLines = distance * (INT)wheelScroll / WHEEL_DELTA;
  621. self->wheelCarryover = distance - scrollLines * WHEEL_DELTA / (INT)wheelScroll;
  622. if (FALSE != Widget_ScrollWindow(hwnd,
  623. (SB_HORZ == barType) ? -(scrollLines * self->style->unitSize.cx) : 0,
  624. (SB_VERT == barType) ? -(scrollLines * self->style->unitSize.cy) : 0,
  625. TRUE))
  626. {
  627. }
  628. }
  629. static void
  630. Widget_OnMouseMove(HWND hwnd, unsigned int vKeys, long cursor_s)
  631. {
  632. Widget *self;
  633. WIDGET_RET_VOID(self, hwnd);
  634. if (NULL != self->callbacks && NULL != self->callbacks->mouseMove)
  635. {
  636. BOOL processed;
  637. POINT cursor;
  638. POINTSTOPOINT(cursor, cursor_s);
  639. processed = self->callbacks->mouseMove(self->object, hwnd, vKeys, &cursor);
  640. if (FALSE == WIDGET_IS_MOUSE_MOVE_TRACKED(self))
  641. {
  642. TRACKMOUSEEVENT trackMouse;
  643. trackMouse.cbSize = sizeof(trackMouse);
  644. trackMouse.dwFlags = TME_LEAVE;
  645. trackMouse.hwndTrack = hwnd;
  646. if (FALSE != TrackMouseEvent(&trackMouse))
  647. WIDGET_SET_MOUSE_MOVE_TRACK(self);
  648. }
  649. if (FALSE != processed)
  650. return;
  651. }
  652. DefWindowProc(hwnd, WM_MOUSEMOVE, (WPARAM)vKeys, (LPARAM)cursor_s);
  653. }
  654. static void
  655. Widget_OnMouseLeave(HWND hwnd)
  656. {
  657. Widget *self;
  658. WIDGET_RET_VOID(self, hwnd);
  659. WIDGET_UNSET_MOUSE_MOVE_TRACK(self);
  660. if (NULL != self->callbacks && NULL != self->callbacks->mouseMove)
  661. {
  662. POINT cursor;
  663. cursor.x = 0xEFFFFFFF;
  664. cursor.y = 0xEFFFFFFF;
  665. if (FALSE != self->callbacks->mouseMove(self->object, hwnd, 0, &cursor))
  666. return;
  667. }
  668. DefWindowProc(hwnd, WM_MOUSELEAVE, 0, 0L);
  669. }
  670. static void
  671. Widget_OnLeftButtonDown(HWND hwnd, unsigned int vKeys, long cursor_s)
  672. {
  673. Widget *self;
  674. WIDGET_RET_VOID(self, hwnd);
  675. if (NULL != self->callbacks && NULL != self->callbacks->leftButtonDown)
  676. {
  677. POINT cursor;
  678. POINTSTOPOINT(cursor, cursor_s);
  679. if (FALSE != self->callbacks->leftButtonDown(self->object, hwnd, vKeys, &cursor))
  680. return;
  681. }
  682. DefWindowProc(hwnd, WM_LBUTTONDOWN, (WPARAM)vKeys, (LPARAM)cursor_s);
  683. }
  684. static void
  685. Widget_OnLeftButtonUp(HWND hwnd, unsigned int vKeys, long cursor_s)
  686. {
  687. Widget *self;
  688. WIDGET_RET_VOID(self, hwnd);
  689. if (NULL != self->callbacks && NULL != self->callbacks->leftButtonUp)
  690. {
  691. POINT cursor;
  692. POINTSTOPOINT(cursor, cursor_s);
  693. if (FALSE != self->callbacks->leftButtonUp(self->object, hwnd, vKeys, &cursor))
  694. return;
  695. }
  696. DefWindowProc(hwnd, WM_LBUTTONUP, (WPARAM)vKeys, (LPARAM)cursor_s);
  697. }
  698. static void
  699. Widget_OnLeftButtonDblClk(HWND hwnd, unsigned int vKeys, long cursor_s)
  700. {
  701. Widget *self;
  702. WIDGET_RET_VOID(self, hwnd);
  703. if (NULL != self->callbacks && NULL != self->callbacks->leftButtonDblClk)
  704. {
  705. POINT cursor;
  706. POINTSTOPOINT(cursor, cursor_s);
  707. if (FALSE != self->callbacks->leftButtonDblClk(self->object, hwnd, vKeys, &cursor))
  708. return;
  709. }
  710. DefWindowProc(hwnd, WM_LBUTTONDBLCLK, (WPARAM)vKeys, (LPARAM)cursor_s);
  711. }
  712. static void
  713. Widget_OnRightButtonDown(HWND hwnd, unsigned int vKeys, long cursor_s)
  714. {
  715. Widget *self;
  716. WIDGET_RET_VOID(self, hwnd);
  717. if (NULL != self->callbacks && NULL != self->callbacks->rightButtonDown)
  718. {
  719. POINT cursor;
  720. POINTSTOPOINT(cursor, cursor_s);
  721. if (FALSE != self->callbacks->rightButtonDown(self->object, hwnd, vKeys, &cursor))
  722. return;
  723. }
  724. DefWindowProc(hwnd, WM_RBUTTONDOWN, (WPARAM)vKeys, (LPARAM)cursor_s);
  725. }
  726. static void
  727. Widget_OnRightButtonUp(HWND hwnd, unsigned int vKeys, long cursor_s)
  728. {
  729. Widget *self;
  730. WIDGET_RET_VOID(self, hwnd);
  731. if (NULL != self->callbacks && NULL != self->callbacks->rightButtonUp)
  732. {
  733. POINT cursor;
  734. POINTSTOPOINT(cursor, cursor_s);
  735. if (FALSE != self->callbacks->rightButtonUp(self->object, hwnd, vKeys, &cursor))
  736. return;
  737. }
  738. DefWindowProc(hwnd, WM_RBUTTONUP, (WPARAM)vKeys, (LPARAM)cursor_s);
  739. }
  740. static void
  741. Widget_OnKeyDown(HWND hwnd, unsigned int vKey, unsigned int flags)
  742. {
  743. Widget *self;
  744. WIDGET_RET_VOID(self, hwnd);
  745. if (NULL != self->callbacks &&
  746. NULL != self->callbacks->keyDown &&
  747. FALSE != self->callbacks->keyDown(self->object, hwnd, vKey, flags))
  748. {
  749. return;
  750. }
  751. DefWindowProc(hwnd, WM_KEYDOWN, (WPARAM)vKey, (LPARAM)flags);
  752. }
  753. static void
  754. Widget_OnKeyUp(HWND hwnd, unsigned int vKey, unsigned int flags)
  755. {
  756. Widget *self;
  757. self = WIDGET(hwnd);
  758. if (NULL != self &&
  759. NULL != self->callbacks &&
  760. NULL != self->callbacks->keyUp &&
  761. FALSE != self->callbacks->keyUp(self->object, hwnd, vKey, flags))
  762. {
  763. return;
  764. }
  765. DefWindowProc(hwnd, WM_KEYUP, (WPARAM)vKey, (LPARAM)flags);
  766. }
  767. static void
  768. Widget_OnChar(HWND hwnd, unsigned int vKey, unsigned int flags)
  769. {
  770. Widget *self;
  771. self = WIDGET(hwnd);
  772. if (NULL != self &&
  773. NULL != self->callbacks &&
  774. NULL != self->callbacks->character &&
  775. FALSE != self->callbacks->character(self->object, hwnd, vKey, flags))
  776. {
  777. return;
  778. }
  779. DefWindowProc(hwnd, WM_CHAR, (WPARAM)vKey, (LPARAM)flags);
  780. }
  781. static unsigned int
  782. Widget_OnGetDlgCode(HWND hwnd, unsigned int vKey, MSG *message)
  783. {
  784. Widget *self;
  785. self = WIDGET(hwnd);
  786. if (NULL != self &&
  787. NULL != self->callbacks &&
  788. NULL != self->callbacks->inputRequest)
  789. {
  790. return self->callbacks->inputRequest(self->object, hwnd, vKey, message);
  791. }
  792. return (unsigned int)DefWindowProc(hwnd, WM_GETDLGCODE, (WPARAM)vKey, (LPARAM)message);
  793. }
  794. static void
  795. Widget_OnSetFocus(HWND hwnd, HWND focusWindow)
  796. {
  797. Widget_FocusChanged(hwnd, focusWindow, TRUE);
  798. }
  799. static void
  800. Widget_OnKillFocus(HWND hwnd, HWND focusWindow)
  801. {
  802. Widget_FocusChanged(hwnd, focusWindow, FALSE);
  803. }
  804. static void
  805. Widget_OnContextMenu(HWND hwnd, HWND targetWindow, long cursor_s)
  806. {
  807. BOOL processed;
  808. Widget *self;
  809. WIDGET_RET_VOID(self, hwnd);
  810. if (NULL != self->callbacks && NULL != self->callbacks->contextMenu)
  811. {
  812. POINT cursor;
  813. POINTSTOPOINT(cursor, cursor_s);
  814. processed = self->callbacks->contextMenu(self->object, hwnd, targetWindow, &cursor);
  815. }
  816. else
  817. processed = FALSE;
  818. if (FALSE == processed)
  819. Widget_DefWindowProc(hwnd, WM_CONTEXTMENU, (WPARAM)targetWindow, (LPARAM)cursor_s);
  820. }
  821. static unsigned int
  822. Widget_OnGetType(HWND hwnd)
  823. {
  824. Widget *self;
  825. WIDGET_RET_VAL(self, hwnd, WIDGET_TYPE_UNKNOWN);
  826. return self->type;
  827. }
  828. static void*
  829. Widget_OnGetSelf(HWND hwnd)
  830. {
  831. Widget *self;
  832. WIDGET_RET_VAL(self, hwnd, NULL);
  833. return self->object;
  834. }
  835. static BOOL
  836. Widget_OnSetStyle(HWND hwnd, WidgetStyle *style)
  837. {
  838. Widget *self;
  839. BOOL styleChanged;
  840. WIDGET_RET_VAL(self, hwnd, FALSE);
  841. styleChanged = (self->style != style);
  842. self->style = style;
  843. if (FALSE != styleChanged)
  844. {
  845. if (NULL != WIDGETCALLBACKS(self))
  846. {
  847. if (NULL != WIDGETCALLBACKS(self)->styleColorChanged)
  848. WIDGETCALLBACKS(self)->styleColorChanged(WIDGETOBJECT(self), hwnd, WIDGETSTYLE(self));
  849. if (NULL != WIDGETCALLBACKS(self)->styleFontChanged)
  850. WIDGETCALLBACKS(self)->styleFontChanged(WIDGETOBJECT(self), hwnd, WIDGETSTYLE(self));
  851. }
  852. }
  853. return TRUE;
  854. }
  855. static WidgetStyle *
  856. Widget_OnGetStyle(HWND hwnd)
  857. {
  858. Widget *self;
  859. WIDGET_RET_VAL(self, hwnd, NULL);
  860. return self->style;
  861. }
  862. static void
  863. Widget_OnStyleColorChanged(HWND hwnd)
  864. {
  865. Widget *self;
  866. WIDGET_RET_VOID(self, hwnd);
  867. if (FALSE != WIDGET_IS_FROZEN(self))
  868. return;
  869. if (NULL != WIDGETCALLBACKS(self) &&
  870. NULL != WIDGETCALLBACKS(self)->styleColorChanged)
  871. {
  872. WIDGETCALLBACKS(self)->styleColorChanged(WIDGETOBJECT(self), hwnd, WIDGETSTYLE(self));
  873. }
  874. }
  875. static void
  876. Widget_OnStyleFontChanged(HWND hwnd)
  877. {
  878. Widget *self;
  879. WIDGET_RET_VOID(self, hwnd);
  880. if (FALSE != WIDGET_IS_FROZEN(self))
  881. return;
  882. if (NULL != WIDGETCALLBACKS(self) &&
  883. NULL != WIDGETCALLBACKS(self)->styleFontChanged)
  884. {
  885. WIDGETCALLBACKS(self)->styleFontChanged(WIDGETOBJECT(self), hwnd, WIDGETSTYLE(self));
  886. }
  887. }
  888. static void
  889. Widget_OnFreeze(HWND hwnd, BOOL freeze)
  890. {
  891. Widget *self;
  892. WIDGET_RET_VOID(self, hwnd);
  893. if (FALSE == freeze)
  894. Widget_Thaw(self);
  895. else
  896. Widget_Freeze(self);
  897. }
  898. static BOOL
  899. Widget_OnScroll(HWND hwnd, int dx, int dy, BOOL redraw)
  900. {
  901. return Widget_ScrollWindow(hwnd, dx, dy, redraw);
  902. }
  903. static LRESULT
  904. Widget_OnSetScrollPos(HWND hwnd, int dx, int dy, BOOL redraw)
  905. {
  906. if (0 != dx)
  907. dx = Widget_ScrollBarOffsetPos(hwnd, SB_HORZ, dx, redraw);
  908. if (0 != dy)
  909. dy = Widget_ScrollBarOffsetPos(hwnd, SB_VERT, dy, redraw);
  910. return (LRESULT)MAKELONG(dx, dy);
  911. }
  912. static void
  913. Widget_OnZoomSliderPosChanging(HWND hwnd, NMTRBTHUMBPOSCHANGING *sliderInfo)
  914. {
  915. Widget *self;
  916. WIDGET_RET_VOID(self, hwnd);
  917. if (NULL != WIDGETCALLBACKS(self) &&
  918. NULL != WIDGETCALLBACKS(self)->zoomChanging)
  919. {
  920. WIDGETCALLBACKS(self)->zoomChanging(WIDGETOBJECT(self), hwnd, sliderInfo);
  921. }
  922. }
  923. static LRESULT
  924. Widget_OnNotify(HWND hwnd, NMHDR *notification)
  925. {
  926. Widget *self;
  927. self = WIDGET(hwnd);
  928. if (NULL != self &&
  929. NULL != self->callbacks &&
  930. NULL != self->callbacks->notify)
  931. {
  932. LRESULT result;
  933. if (FALSE != self->callbacks->notify(WIDGETOBJECT(self), hwnd, notification, &result))
  934. return result;
  935. }
  936. return Widget_DefWindowProc(hwnd, WM_NOTIFY,
  937. (WPARAM)notification->idFrom, (LPARAM)notification);
  938. }
  939. static BOOL
  940. Widget_OnEnableChildrenScroll(HWND hwnd, BOOL enable)
  941. {
  942. Widget *self;
  943. BOOL previous;
  944. WIDGET_RET_VAL(self, hwnd, FALSE);
  945. previous = (FALSE == WIDGET_IS_CHILDREN_SCROLL_DISABLED(self));
  946. if (FALSE != enable)
  947. WIDGET_UNSET_DISABLE_CHILDREN_SCROLL(self);
  948. else
  949. WIDGET_SET_DISABLE_CHILDREN_SCROLL(self);
  950. return previous;
  951. }
  952. static BOOL
  953. Widget_OnGetChildrenScrollEnabled(HWND hwnd)
  954. {
  955. Widget *self;
  956. WIDGET_RET_VAL(self, hwnd, FALSE);
  957. return (FALSE == WIDGET_IS_CHILDREN_SCROLL_DISABLED(self));
  958. }
  959. static LRESULT CALLBACK
  960. Widget_WindowProc(HWND hwnd, unsigned int uMsg, WPARAM wParam, LPARAM lParam)
  961. {
  962. switch(uMsg)
  963. {
  964. case WM_CREATE: return Widget_OnCreate(hwnd, (CREATESTRUCT*)lParam);
  965. case WM_DESTROY: Widget_OnDestroy(hwnd); return 0;
  966. case WM_PAINT: Widget_OnPaint(hwnd); return 0;
  967. case WM_PRINTCLIENT: Widget_OnPrintClient(hwnd, (HDC)wParam, (UINT)lParam); return 0;
  968. case WM_PRINT: return 0;
  969. case WM_ERASEBKGND: return 0;
  970. case WM_WINDOWPOSCHANGED: Widget_OnWindowPosChanged(hwnd, (WINDOWPOS*)lParam); return 0;
  971. case WM_SIZE: return 0;
  972. case WM_MOVE: return 0;
  973. case WM_SETTEXT: return Widget_OnSetText(hwnd, (LPCWSTR)lParam);
  974. case WM_GETTEXT: return Widget_OnGetText(hwnd, (LPWSTR)lParam, (INT)wParam);
  975. case WM_GETTEXTLENGTH: return Widget_OnGetTextLength(hwnd);
  976. case WM_SETFONT: Widget_OnSetFont(hwnd, (HFONT)wParam, (BOOL)LOWORD(lParam)); return 0;
  977. case WM_GETFONT: return (LRESULT)Widget_OnGetFont(hwnd);
  978. case WM_VSCROLL: Widget_OnVertScroll(hwnd, LOWORD(wParam), (short)HIWORD(wParam), (HWND)lParam); return 0;
  979. case WM_HSCROLL: Widget_OnHorzScroll(hwnd, LOWORD(wParam), (short)HIWORD(wParam), (HWND)lParam); return 0;
  980. case WM_MOUSEWHEEL: Widget_OnMouseWheel(hwnd, LOWORD(wParam), (short)HIWORD(wParam), (LONG)lParam); return 0;
  981. case WM_MOUSEMOVE: Widget_OnMouseMove(hwnd, (unsigned int)wParam, (long)lParam); return 0;
  982. case WM_MOUSELEAVE: Widget_OnMouseLeave(hwnd); return 0;
  983. case WM_LBUTTONDOWN: Widget_OnLeftButtonDown(hwnd, (unsigned int)wParam, (long)lParam); return 0;
  984. case WM_LBUTTONUP: Widget_OnLeftButtonUp(hwnd, (unsigned int)wParam, (long)lParam); return 0;
  985. case WM_LBUTTONDBLCLK: Widget_OnLeftButtonDblClk(hwnd, (unsigned int)wParam, (long)lParam); return 0;
  986. case WM_RBUTTONDOWN: Widget_OnRightButtonDown(hwnd, (unsigned int)wParam, (long)lParam); return 0;
  987. case WM_RBUTTONUP: Widget_OnRightButtonUp(hwnd, (unsigned int)wParam, (long)lParam); return 0;
  988. case WM_KEYDOWN: Widget_OnKeyDown(hwnd, (unsigned int)wParam, (unsigned int)lParam); return 0;
  989. case WM_KEYUP: Widget_OnKeyUp(hwnd, (unsigned int)wParam, (unsigned int)lParam); return 0;
  990. case WM_CHAR: Widget_OnChar(hwnd, (unsigned int)wParam, (unsigned int)lParam); return 0;
  991. case WM_GETDLGCODE: return Widget_OnGetDlgCode(hwnd, (unsigned int)wParam, (MSG*)lParam);
  992. case WM_SETFOCUS: Widget_OnSetFocus(hwnd, (HWND)wParam); return 0;
  993. case WM_KILLFOCUS: Widget_OnKillFocus(hwnd, (HWND)wParam); return 0;
  994. case WM_CONTEXTMENU: Widget_OnContextMenu(hwnd, (HWND)wParam, (long)lParam); return 0;
  995. case WM_NOTIFY: return Widget_OnNotify(hwnd, (NMHDR*)lParam);
  996. case WIDGET_WM_GET_TYPE: return (LRESULT)Widget_OnGetType(hwnd);
  997. case WIDGET_WM_GET_SELF: return (LRESULT)Widget_OnGetSelf(hwnd);
  998. case WIDGET_WM_SET_STYLE: return Widget_OnSetStyle(hwnd, (WidgetStyle*)lParam);
  999. case WIDGET_WM_GET_STYLE: return (LRESULT)Widget_OnGetStyle(hwnd);
  1000. case WIDGET_WM_STYLE_COLOR_CHANGED: Widget_OnStyleColorChanged(hwnd); return 0;
  1001. case WIDGET_WM_STYLE_FONT_CHANGED: Widget_OnStyleFontChanged(hwnd); return 0;
  1002. case WIDGET_WM_FREEZE: Widget_OnFreeze(hwnd, (BOOL)wParam); return 0;
  1003. case WIDGET_WM_SET_SCROLL_POS: return Widget_OnSetScrollPos(hwnd, (short)LOWORD(lParam), (short)HIWORD(lParam), (BOOL)wParam);
  1004. case WIDGET_WM_SCROLL: return Widget_OnScroll(hwnd, (short)LOWORD(lParam), (short)HIWORD(lParam), (BOOL)wParam);
  1005. case WIDGET_WM_ZOOM_SLIDER_POS_CHANGING: Widget_OnZoomSliderPosChanging(hwnd, (NMTRBTHUMBPOSCHANGING*)lParam); return 0;
  1006. case WIDGET_WM_ENABLE_CHILDREN_SCROLL: return Widget_OnEnableChildrenScroll(hwnd, (BOOL)lParam);
  1007. case WIDGET_WM_GET_CHILDREN_SCROLL_ENABLED: return Widget_OnGetChildrenScrollEnabled(hwnd);
  1008. }
  1009. if (WINAMP_WM_DIRECT_MOUSE_WHEEL == uMsg &&
  1010. WM_NULL != WINAMP_WM_DIRECT_MOUSE_WHEEL)
  1011. {
  1012. Widget_OnMouseWheel(hwnd, LOWORD(wParam), (SHORT)HIWORD(wParam), (LONG)lParam);
  1013. return TRUE;
  1014. }
  1015. return Widget_DefWindowProc(hwnd, uMsg, wParam, lParam);
  1016. }