1
0

skinning.cpp 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. #include "./skinning.h"
  2. #include "./skinneddlg.h"
  3. #include "./skinnedheader.h"
  4. #include "./skinnedlistview.h"
  5. #include "./skinnedbutton.h"
  6. #include "./skinneddivider.h"
  7. #include "./skinnededit.h"
  8. #include "./skinnedstatic.h"
  9. #include "./skinnedlistbox.h"
  10. #include "./skinnedcombo.h"
  11. #include "./skinnedfolder.h"
  12. #include "./skinnedmenu.h"
  13. #include "./skinnedtooltip.h"
  14. #include "./skinnedprogressbar.h"
  15. #include "./config.h"
  16. extern C_Config *g_config;
  17. BOOL SkinWindow(HWND hwndToSkin, UINT style)
  18. {
  19. return SkinWindowEx(hwndToSkin, SKINNEDWND_TYPE_AUTO, style);
  20. }
  21. BOOL SkinWindowEx(HWND hwndToSkin, INT type, UINT style)
  22. {
  23. SkinnedWnd *psw;
  24. if (!hwndToSkin || !IsWindow(hwndToSkin) || SkinnedWnd::GetFromHWND(hwndToSkin)) return FALSE;
  25. if (SKINNEDWND_TYPE_AUTO == type)
  26. {
  27. wchar_t szName[256] = {0};
  28. if (!RealGetWindowClassW(hwndToSkin, szName, sizeof(szName)/sizeof(wchar_t)))
  29. return FALSE;
  30. if (0== lstrcmpW(szName, L"#32770")) type = SKINNEDWND_TYPE_DIALOG;
  31. else if (0== lstrcmpW(szName, WC_HEADERW)) type = SKINNEDWND_TYPE_HEADER;
  32. else if (0== lstrcmpW(szName, WC_LISTVIEWW)) type = SKINNEDWND_TYPE_LISTVIEW;
  33. else if (0== lstrcmpW(szName, WC_BUTTONW)) type = SKINNEDWND_TYPE_BUTTON;
  34. else if (0== lstrcmpW(szName, WC_EDITW)) type = SKINNEDWND_TYPE_EDIT;
  35. else if (0== lstrcmpW(szName, WC_STATICW)) type = SKINNEDWND_TYPE_STATIC;
  36. else if (0== lstrcmpW(szName, WC_LISTBOXW)) type = SKINNEDWND_TYPE_LISTBOX;
  37. else if (0== lstrcmpW(szName, WC_COMBOBOXW)) type = SKINNEDWND_TYPE_COMBOBOX;
  38. else if (0== lstrcmpW(szName, TOOLTIPS_CLASSW)) type = SKINNEDWND_TYPE_TOOLTIP;
  39. else if (0== lstrcmpW(szName, FOLDERBROWSER_NAME)) type = SKINNEDWND_TYPE_FOLDERBROWSER;
  40. else if (0== lstrcmpW(szName, PROGRESS_CLASSW)) type = SKINNEDWND_TYPE_PROGRESSBAR;
  41. else
  42. {
  43. if (0 != ((WS_VSCROLL | WS_HSCROLL) & GetWindowLongPtrW(hwndToSkin, GWL_STYLE)))
  44. type = SKINNEDWND_TYPE_SCROLLWND;
  45. else
  46. type = SKINNEDWND_TYPE_WINDOW;
  47. }
  48. }
  49. switch(type)
  50. {
  51. case SKINNEDWND_TYPE_WINDOW: psw = new SkinnedWnd(FALSE); break;
  52. case SKINNEDWND_TYPE_SCROLLWND: psw = new SkinnedScrollWnd(FALSE); break;
  53. case SKINNEDWND_TYPE_DIALOG: psw = new SkinnedDialog(); break;
  54. case SKINNEDWND_TYPE_HEADER: psw = new SkinnedHeader(); break;
  55. case SKINNEDWND_TYPE_LISTVIEW: psw = new SkinnedListView(); break;
  56. case SKINNEDWND_TYPE_BUTTON: psw = new SkinnedButton(); break;
  57. case SKINNEDWND_TYPE_DIVIDER: psw = new SkinnedDivider(); break;
  58. case SKINNEDWND_TYPE_EDIT: psw = new SkinnedEdit(); break;
  59. case SKINNEDWND_TYPE_STATIC: psw = new SkinnedStatic(); break;
  60. case SKINNEDWND_TYPE_LISTBOX: psw = new SkinnedListbox(); break;
  61. case SKINNEDWND_TYPE_COMBOBOX: psw = new SkinnedCombobox(); break;
  62. case SKINNEDWND_TYPE_FOLDERBROWSER: psw = new SkinnedFolderBrowser(); break;
  63. case SKINNEDWND_TYPE_TOOLTIP: psw = new SkinnedToolTip(); break;
  64. case SKINNEDWND_TYPE_PROGRESSBAR: psw = new SkinnedProgressBar(); break;
  65. default: psw = NULL; break;
  66. }
  67. if (!psw) return FALSE;
  68. if (!psw->Attach(hwndToSkin))
  69. {
  70. delete(psw);
  71. return FALSE;
  72. }
  73. psw->SetStyle(style, FALSE);
  74. return TRUE;
  75. }
  76. BOOL UnskinWindow(HWND hwndToUnskin)
  77. {
  78. SkinnedWnd *psw;
  79. psw = SkinnedWnd::GetFromHWND(hwndToUnskin);
  80. if (!psw) return FALSE;
  81. delete (psw);
  82. return TRUE;
  83. }
  84. BOOL TrackSkinnedPopupMenuEx(HMENU hmenu, UINT fuFlags, INT x, INT y, HWND hwnd, LPTPMPARAMS lptpm, HMLIMGLST hmlil,
  85. INT width, UINT skinStyle, MENUCUSTOMIZEPROC customProc, ULONG_PTR customParam)
  86. {
  87. if (!hmenu) return FALSE;
  88. SkinnedMenu skinnedMenu;
  89. return skinnedMenu.TrackMenuPopupEx(hmenu, fuFlags, x, y, hwnd, lptpm, skinStyle, hmlil, width, customProc, customParam);
  90. }
  91. HANDLE InitSkinnedPopupHook(HWND hwndOwner, HMLIMGLST hmlil, INT width, UINT skinStyle, MENUCUSTOMIZEPROC customProc, ULONG_PTR customParam)
  92. {
  93. SkinnedMenu *psm = new SkinnedMenu();
  94. if (NULL != psm &&
  95. FALSE == psm->InitializeHook(hwndOwner, skinStyle, hmlil, width, customProc, customParam))
  96. {
  97. delete(psm);
  98. psm = NULL;
  99. }
  100. return (HANDLE)psm;
  101. }
  102. void RemoveSkinnedPopupHook(HANDLE hPopupHook)
  103. {
  104. SkinnedMenu *psm = (SkinnedMenu*)hPopupHook;
  105. if (NULL != psm)
  106. delete(psm);
  107. }
  108. #define SKINNEDMENU_DEFAULT TRUE
  109. BOOL IsSkinnedPopupEnabled(BOOL fIgnoreCache)
  110. {
  111. static INT fUseSkinnedMenus = -1;
  112. if (FALSE != fIgnoreCache)
  113. fUseSkinnedMenus = -1;
  114. if (-1 == fUseSkinnedMenus)
  115. {
  116. fUseSkinnedMenus = (NULL != g_config) ?
  117. (0 != g_config->ReadInt(L"skinned_menus", SKINNEDMENU_DEFAULT)) :
  118. SKINNEDMENU_DEFAULT;
  119. }
  120. return (FALSE != fUseSkinnedMenus);
  121. }
  122. BOOL EnableSkinnedPopup(BOOL fEnable)
  123. {
  124. if (NULL == g_config)
  125. return FALSE;
  126. g_config->WriteInt(L"skinned_menus", (FALSE != fEnable));
  127. return (fEnable == IsSkinnedPopupEnabled(TRUE));
  128. }