1
0

wa2pledit.cpp 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. #include <precomp.h>
  2. #include "wa2pledit.h"
  3. #include <api/script/objects/PlaylistScriptObject.h>
  4. #include <tataki/color/skinclr.h>
  5. #include "wa2frontend.h"
  6. #include <tataki/canvas/bltcanvas.h>
  7. #include "../nu/AutoWide.h"
  8. #ifndef _WASABIRUNTIME
  9. BEGIN_SERVICES(Wa2Pledit_Svc);
  10. DECLARE_SERVICE(XuiObjectCreator<Wa2PleditXuiSvc>);
  11. END_SERVICES(Wa2Pledit_Svc, _Wa2Pledit_Svc);
  12. #ifdef _X86_
  13. extern "C" { int _link_Wa2PleditXuiSvc; }
  14. #else
  15. extern "C" { int __link_Wa2PleditXuiSvc; }
  16. #endif
  17. #endif
  18. // -----------------------------------------------------------------------
  19. const wchar_t Wa2PleditXuiObjectStr[] = L"PlaylistEditor"; // This is the xml tag
  20. char Wa2PleditXuiSvcName[] = "Playlist Editor xui object";
  21. // -----------------------------------------------------------------------
  22. #define TRACKLENGTH_WIDTH 40
  23. #define DC_CURRENTIDX 10
  24. #define DC_PLAY 11
  25. #define TIMER_REFRESHLIST 12
  26. static SkinColor text(L"pledit.text"), rotext(L"pledit.text.readonly");
  27. static SkinColor text_disabled(L"pledit.text.disabled");
  28. static SkinColor bgcolor(L"pledit.bgcolor");
  29. static SkinColor currenttext(L"wasabi.itemlist.outline.focus");
  30. static SkinColor currentoutline(L"wasabi.itemlist.outline.current");
  31. PtrList<Wa2PlaylistEditor> Wa2PlaylistEditor::editors;
  32. COLORREF Wa2PlaylistEditor::getTextColor(LPARAM lParam) {
  33. // if (playlist == NULL) return text;
  34. // PlaylistEntry *entry = playlist->enumEntry(lParam);
  35. // if (entry && entry->getCurrent())
  36. // return currenttext;
  37. // else
  38. if (lParam == cur_index)
  39. return currenttext;
  40. return text;
  41. }
  42. COLORREF Wa2PlaylistEditor::getBgColor(LPARAM lParam) {
  43. return bgcolor;
  44. }
  45. COLORREF Wa2PlaylistEditor::getFocusRectColor(LPARAM lParam) {
  46. return currentoutline;
  47. }
  48. int Wa2PlaylistEditor::needFocusRect(LPARAM lParam)
  49. {
  50. return lParam == cur_index;
  51. }
  52. Wa2PlaylistEditor::Wa2PlaylistEditor()
  53. : curplaylist(0)
  54. {
  55. curplaylist = NULL;
  56. cur_index = wa2.PE_getCurrentIndex()+1;
  57. }
  58. Wa2PlaylistEditor::~Wa2PlaylistEditor() {
  59. killTimer(TIMER_REFRESHLIST);
  60. editors.removeItem(this);
  61. }
  62. int Wa2PlaylistEditor::onInit()
  63. {
  64. WA2PLAYLISTEDITOR_PARENT::onInit();
  65. setShowColumnsHeaders(FALSE);
  66. addColumn(L"Track #", calcTrackNumWidth());
  67. addColumn(L"Track Name", 200);
  68. addColumn(L"Length", TRACKLENGTH_WIDTH, 1, COL_RIGHTALIGN);
  69. editors.addItem(this);
  70. return 1;
  71. }
  72. void Wa2PlaylistEditor::onVScrollToggle(int set) {
  73. resizeCols();
  74. }
  75. int Wa2PlaylistEditor::onResize() {
  76. WA2PLAYLISTEDITOR_PARENT::onResize();
  77. resizeCols();
  78. return 1;
  79. }
  80. void Wa2PlaylistEditor::resizeCols() {
  81. RECT r;
  82. getClientRect(&r);
  83. ListColumn *c0 = getColumn(0);
  84. int tw = calcTrackNumWidth();
  85. c0->setWidth(tw);
  86. ListColumn *c1 = getColumn(1);
  87. c1->setWidth(r.right-r.left - tw - TRACKLENGTH_WIDTH);
  88. }
  89. int Wa2PlaylistEditor::calcTrackNumWidth()
  90. {
  91. WndCanvas bc(this);
  92. Wasabi::FontInfo fontInfo;
  93. fontInfo.pointSize = getFontSize();
  94. int cw = getFontSize();
  95. int dw = 8;
  96. bc.getTextExtent(L"W", &cw, NULL, &fontInfo);
  97. bc.getTextExtent(L".", &dw, NULL, &fontInfo);
  98. int n = getNumItems();
  99. if (n < 0) return dw+cw;
  100. float f = log10((float)n);
  101. int l = (int)ceil(f);
  102. return (l * cw) + dw + 5;
  103. }
  104. void *Wa2PlaylistEditor::getInterface(GUID interface_guid) {
  105. if (interface_guid == Wa2PlaylistEditor::getInterfaceGuid()) {
  106. return this;
  107. }
  108. return WA2PLAYLISTEDITOR_PARENT::getInterface(interface_guid);
  109. }
  110. void Wa2PlaylistEditor::setPlaylist(Wa2Playlist *playlist) {
  111. if (curplaylist == playlist)
  112. return;
  113. curplaylist = playlist;
  114. loadList();
  115. }
  116. void Wa2PlaylistEditor::_loadList() {
  117. int y = getScrollY();
  118. setRedraw(FALSE);
  119. deleteAllItems();
  120. if (curplaylist == (Wa2Playlist *)-1) {
  121. // load the current playlist (the one in the real playlist editor)
  122. int n = wa2.PE_getNumItems();
  123. for (int i=0;i<n;i++)
  124. {
  125. fileinfo2 *fi = wa2.PE_getFileTitle(i);
  126. addItem(StringPrintfW(L"%d.", i+1), i+1);
  127. setSubItem(i, 1, AutoWide(fi->filetitle));
  128. setSubItem(i, 2, AutoWide(fi->filelength));
  129. }
  130. } else {
  131. // load an available playlist
  132. }
  133. RECT r;
  134. getClientRect(&r);
  135. int ch = getContentsHeight();
  136. if (ch - y >= r.bottom-r.top) scrollToY(y);
  137. else if (ch - r.bottom-r.top >= 0) scrollToY(ch - r.bottom-r.top);
  138. else scrollToY(0);
  139. resizeCols();
  140. postDeferredCallback(DC_CURRENTIDX);
  141. setRedraw(TRUE);
  142. }
  143. void Wa2PlaylistEditor::_onNewCurrentIndex(int idx)
  144. {
  145. foreach(editors)
  146. editors.getfor()->onNewCurrentIndex(idx);
  147. endfor
  148. }
  149. void Wa2PlaylistEditor::onNewCurrentIndex(int idx)
  150. {
  151. if (idx!=cur_index)
  152. {
  153. int oldIdx = cur_index;
  154. cur_index = idx;
  155. invalidateItem(oldIdx);
  156. invalidateItem(idx);
  157. }
  158. }
  159. void Wa2PlaylistEditor::onSetVisible(int show) {
  160. WA2PLAYLISTEDITOR_PARENT::onSetVisible(show);
  161. if (!show) getParent()->setFocus();
  162. }
  163. void Wa2PlaylistEditor::onPlaylistModified() {
  164. if (curplaylist == (Wa2Playlist *)-1)
  165. loadList();
  166. }
  167. void Wa2PlaylistEditor::_onPlaylistModified() {
  168. // fist call the Pledit script object
  169. SPlaylist::onPleditModified();
  170. // than all our old pledit xml objects
  171. foreach(editors)
  172. editors.getfor()->onPlaylistModified();
  173. endfor
  174. }
  175. int Wa2PlaylistEditor::onDeferredCallback(intptr_t p1, intptr_t p2)
  176. {
  177. if (p1 == DC_CURRENTIDX)
  178. {
  179. onNewCurrentIndex(wa2.PE_getCurrentIndex()+1);
  180. return 1;
  181. }
  182. return WA2PLAYLISTEDITOR_PARENT::onDeferredCallback(p1, p2);
  183. }
  184. void Wa2PlaylistEditor::onDoubleClick(int itemnum)
  185. {
  186. WA2PLAYLISTEDITOR_PARENT::onDoubleClick(itemnum);
  187. wa2.PE_setCurrentIndex(itemnum);
  188. wa2.userButton(WA2_USERBUTTON_PLAY, 0);
  189. _onNewCurrentIndex(itemnum+1);
  190. }
  191. void Wa2PlaylistEditor::timerCallback(int id)
  192. {
  193. if (id == TIMER_REFRESHLIST) {
  194. killTimer(TIMER_REFRESHLIST);
  195. _loadList();
  196. }
  197. }
  198. void Wa2PlaylistEditor::loadList()
  199. {
  200. killTimer(TIMER_REFRESHLIST);
  201. setTimer(TIMER_REFRESHLIST, 500);
  202. }