CPI_Verbs.c
上传用户:hxb_1234
上传日期:2010-03-30
资源大小:8328k
文件大小:16k
源码类别:

VC书籍

开发平台:

Visual C++

  1. ////////////////////////////////////////////////////////////////////////////////
  2. #include "stdafx.h"
  3. #include "globals.h"
  4. #include "resource.h"
  5. #include "CPI_Playlist.h"
  6. #include "CPI_PlaylistWindow.h"
  7. #include "DLG_Find.h"
  8. #include "CPI_Player.h"
  9. ////////////////////////////////////////////////////////////////////////////////
  10. //
  11. wp_Verb glb_pfnAllVerbs[] = {
  12.                                 CPVERB_TogglePlaylistWindow,
  13.                                 CPVERB_ToggleRepeat,
  14.                                 CPVERB_ToggleShuffle,
  15.                                 CPVERB_ToggleEqualiser,
  16.                                 CPVERB_ToggleFindDialog,
  17.                                 CPVERB_PlaylistClearSelected,
  18.                                 CPVERB_PlaylistClearAll,
  19.                                 CPVERB_Play,
  20.                                 CPVERB_Stop,
  21.                                 CPVERB_Pause,
  22.                                 CPVERB_NextTrack,
  23.                                 CPVERB_PrevTrack,
  24.                                 CPVERB_SkipForwards,
  25.                                 CPVERB_SkipBackwards,
  26.                                 CPVERB_VolumeUp,
  27.                                 CPVERB_VolumeDown,
  28.                                 CPVERB_OpenFile,
  29.                                 CPVERB_About,
  30.                                 CPVERB_Exit,
  31.                                 CPVERB_SavePlaylist,
  32.                                 CPVERB_PlaylistShuffle,
  33.                                 CPVERB_PlaylistOffsetUp,
  34.                                 CPVERB_PlaylistOffsetDown,
  35.                                 CPVERB_AddDirectory,
  36.                                 CPVERB_PlaylistMinimise,
  37.                                 CPVERB_PlaylistMaximise,
  38.                                 NULL
  39.                             };
  40. //
  41. ////////////////////////////////////////////////////////////////////////////////
  42. ////////////////////////////////////////////////////////////////////////////////
  43. //
  44. //
  45. //
  46. void CPVERB_TogglePlaylistWindow(const CPe_VerbAction enAction, void* _pParam)
  47. {
  48.     if(enAction == vaDoVerb)
  49.     {
  50.         options.show_playlist = !options.show_playlist;
  51.         CPlaylistWindow_SetVisible(options.show_playlist);
  52.     }
  53.     else if(enAction == vaQueryName)
  54.     {
  55.         CPs_VerbQueryName* pParam = (CPs_VerbQueryName*)_pParam;
  56.         if(stricmp(pParam->m_pcName, "TogglePlaylistWindow") == 0)
  57.             pParam->m_bNameMatched = TRUE;
  58.     }
  59. }
  60. //
  61. //
  62. //
  63. void CPVERB_ToggleRepeat(const CPe_VerbAction enAction, void* _pParam)
  64. {
  65.     if(enAction == vaDoVerb)
  66.     {
  67.         options.repeat_playlist = !options.repeat_playlist;
  68.         InvalidateRect(windows.wnd_main, NULL, FALSE);
  69.     }
  70.     else if(enAction == vaQueryName)
  71.     {
  72.         CPs_VerbQueryName* pParam = (CPs_VerbQueryName*)_pParam;
  73.         if(stricmp(pParam->m_pcName, "ToggleRepeat") == 0)
  74.             pParam->m_bNameMatched = TRUE;
  75.     }
  76. }
  77. //
  78. //
  79. //
  80. void CPVERB_ToggleShuffle(const CPe_VerbAction enAction, void* _pParam)
  81. {
  82.     if(enAction == vaDoVerb)
  83.     {
  84.   options.shuffle_play = !options.shuffle_play;
  85.    
  86. if(options.shuffle_play)
  87. {
  88. CPL_Stack_Shuffle(globals.m_hPlaylist, FALSE);
  89. }else
  90. {
  91. CPL_Stack_RestackAll(globals.m_hPlaylist);
  92. }
  93.         InvalidateRect(windows.wnd_main, NULL, FALSE);
  94.     }
  95.     else if(enAction == vaQueryName)
  96.     {
  97.         CPs_VerbQueryName* pParam = (CPs_VerbQueryName*)_pParam;
  98.         if(stricmp(pParam->m_pcName, "ToggleShuffle") == 0)
  99.             pParam->m_bNameMatched = TRUE;
  100.     }
  101. }
  102. //
  103. //
  104. //
  105. void CPVERB_ToggleEqualiser(const CPe_VerbAction enAction, void* _pParam)
  106. {
  107.     if(enAction == vaDoVerb)
  108.     {
  109.         options.equalizer = !options.equalizer;
  110.         main_set_eq();
  111.         InvalidateRect(windows.wnd_main, NULL, FALSE);
  112.     }
  113.     else if(enAction == vaQueryName)
  114.     {
  115.         CPs_VerbQueryName* pParam = (CPs_VerbQueryName*)_pParam;
  116.         if(stricmp(pParam->m_pcName, "ToggleEqualiser") == 0)
  117.             pParam->m_bNameMatched = TRUE;
  118.     }
  119. }
  120. //
  121. //
  122. //
  123. void CPVERB_ToggleFindDialog(const CPe_VerbAction enAction, void* _pParam)
  124. {
  125.     if(enAction == vaDoVerb)
  126.     {
  127.         if(windows.m_hWndFindDialog == NULL)
  128.         {
  129.             windows.m_hWndFindDialog = CreateDialog( GetModuleHandle(NULL),
  130.                                        MAKEINTRESOURCE(IDD_QUICKFIND),
  131.                                        windows.wnd_main,
  132.                                        wp_FindDialog);
  133.         }
  134.         else
  135.             SendMessage(windows.m_hWndFindDialog, WM_CLOSE, 0L, 0L);
  136.     }
  137.     else if(enAction == vaQueryName)
  138.     {
  139.         CPs_VerbQueryName* pParam = (CPs_VerbQueryName*)_pParam;
  140.         if(stricmp(pParam->m_pcName, "ToggleFindDialog") == 0)
  141.             pParam->m_bNameMatched = TRUE;
  142.     }
  143. }
  144. //
  145. //
  146. //
  147. void CPVERB_PlaylistClearSelected(const CPe_VerbAction enAction, void* _pParam)
  148. {
  149.     if(enAction == vaDoVerb)
  150.         CPlaylistWindow_ClearSelectedItems();
  151.     else if(enAction == vaQueryName)
  152.     {
  153.         CPs_VerbQueryName* pParam = (CPs_VerbQueryName*)_pParam;
  154.         if(stricmp(pParam->m_pcName, "PlaylistClearSelected") == 0)
  155.             pParam->m_bNameMatched = TRUE;
  156.     }
  157. }
  158. //
  159. //
  160. //
  161. void CPVERB_PlaylistClearAll(const CPe_VerbAction enAction, void* _pParam)
  162. {
  163.     if(enAction == vaDoVerb)
  164.         CPL_Empty(globals.m_hPlaylist);
  165.     else if(enAction == vaQueryName)
  166.     {
  167.         CPs_VerbQueryName* pParam = (CPs_VerbQueryName*)_pParam;
  168.         if(stricmp(pParam->m_pcName, "PlaylistClearAll") == 0)
  169.             pParam->m_bNameMatched = TRUE;
  170.     }
  171. }
  172. //
  173. //
  174. //
  175. void CPVERB_Play(const CPe_VerbAction enAction, void* _pParam)
  176. {
  177.     if(enAction == vaDoVerb)
  178.     {
  179.         if(globals.m_enPlayerState == cppsPaused)
  180.             CPI_Player__Play(globals.m_hPlayer);
  181.         else
  182.             CPL_PlayItem(globals.m_hPlaylist, TRUE, pmCurrentItem);
  183.     }
  184.     else if(enAction == vaQueryName)
  185.     {
  186.         CPs_VerbQueryName* pParam = (CPs_VerbQueryName*)_pParam;
  187.         if(stricmp(pParam->m_pcName, "Play") == 0)
  188.             pParam->m_bNameMatched = TRUE;
  189.     }
  190. }
  191. //
  192. //
  193. //
  194. void CPVERB_Stop(const CPe_VerbAction enAction, void* _pParam)
  195. {
  196.     if(enAction == vaDoVerb)
  197.     {
  198.         CPI_Player__Stop(globals.m_hPlayer);
  199.         globals.main_bool_wavwrite_dir_already_known = FALSE;
  200.     }
  201.     else if(enAction == vaQueryName)
  202.     {
  203.         CPs_VerbQueryName* pParam = (CPs_VerbQueryName*)_pParam;
  204.         if(stricmp(pParam->m_pcName, "Stop") == 0)
  205.             pParam->m_bNameMatched = TRUE;
  206.     }
  207. }
  208. //
  209. //
  210. //
  211. void CPVERB_Pause(const CPe_VerbAction enAction, void* _pParam)
  212. {
  213.     if(enAction == vaDoVerb)
  214.     {
  215.         if(globals.m_enPlayerState == cppsPaused)
  216.             CPI_Player__Play(globals.m_hPlayer);
  217.         else
  218.             CPI_Player__Pause(globals.m_hPlayer);
  219.     }
  220.     else if(enAction == vaQueryName)
  221.     {
  222.         CPs_VerbQueryName* pParam = (CPs_VerbQueryName*)_pParam;
  223.         if(stricmp(pParam->m_pcName, "Pause") == 0)
  224.             pParam->m_bNameMatched = TRUE;
  225.     }
  226. }
  227. //
  228. //
  229. //
  230. void CPVERB_NextTrack(const CPe_VerbAction enAction, void* _pParam)
  231. {
  232.     if(enAction == vaDoVerb)
  233.         CPL_PlayItem(globals.m_hPlaylist, TRUE, pmNextItem);
  234.     else if(enAction == vaQueryName)
  235.     {
  236.         CPs_VerbQueryName* pParam = (CPs_VerbQueryName*)_pParam;
  237.         if(stricmp(pParam->m_pcName, "NextTrack") == 0)
  238.             pParam->m_bNameMatched = TRUE;
  239.     }
  240. }
  241. //
  242. //
  243. //
  244. void CPVERB_PrevTrack(const CPe_VerbAction enAction, void* _pParam)
  245. {
  246.     if(enAction == vaDoVerb)
  247.         CPL_PlayItem(globals.m_hPlaylist, TRUE, pmPrevItem);
  248.     else if(enAction == vaQueryName)
  249.     {
  250.         CPs_VerbQueryName* pParam = (CPs_VerbQueryName*)_pParam;
  251.         if(stricmp(pParam->m_pcName, "PrevTrack") == 0)
  252.             pParam->m_bNameMatched = TRUE;
  253.     }
  254. }
  255. //
  256. //
  257. //
  258. void CPVERB_SkipForwards(const CPe_VerbAction enAction, void* _pParam)
  259. {
  260.     if(enAction == vaDoVerb)
  261.     {
  262.         if(globals.m_bStreaming == FALSE)
  263.         {
  264.             globals.main_int_track_position++;
  265.             if(globals.main_int_track_position > Skin.Object[PositionSlider].w)
  266.                 globals.main_int_track_position = Skin.Object[PositionSlider].w;
  267.             if (Skin.Object[PositionSlider].maxw == 1)
  268.                 CPI_Player__Seek(globals.m_hPlayer, globals.main_int_track_position, Skin.Object[PositionSlider].h);
  269.             else
  270.                 CPI_Player__Seek(globals.m_hPlayer, globals.main_int_track_position, Skin.Object[PositionSlider].w);
  271.         }
  272.     }
  273.     else if(enAction == vaQueryName)
  274.     {
  275.         CPs_VerbQueryName* pParam = (CPs_VerbQueryName*)_pParam;
  276.         if(stricmp(pParam->m_pcName, "SkipForwards") == 0)
  277.             pParam->m_bNameMatched = TRUE;
  278.     }
  279. }
  280. //
  281. //
  282. //
  283. void CPVERB_SkipBackwards(const CPe_VerbAction enAction, void* _pParam)
  284. {
  285.     if(enAction == vaDoVerb)
  286.     {
  287.         if(globals.m_bStreaming == FALSE)
  288.         {
  289.             globals.main_int_track_position = globals.main_int_track_position - 3;
  290.             if (globals.main_int_track_position < 0)
  291.                 globals.main_int_track_position = 0;
  292.             if (Skin.Object[PositionSlider].maxw == 1)
  293.                 CPI_Player__Seek(globals.m_hPlayer, globals.main_int_track_position, Skin.Object[PositionSlider].h);
  294.             else
  295.                 CPI_Player__Seek(globals.m_hPlayer, globals.main_int_track_position, Skin.Object[PositionSlider].w);
  296.         }
  297.     }
  298.     else if(enAction == vaQueryName)
  299.     {
  300.         CPs_VerbQueryName* pParam = (CPs_VerbQueryName*)_pParam;
  301.         if(stricmp(pParam->m_pcName, "SkipBackwards") == 0)
  302.             pParam->m_bNameMatched = TRUE;
  303.     }
  304. }
  305. //
  306. //
  307. //
  308. void CPVERB_VolumeUp(const CPe_VerbAction enAction, void* _pParam)
  309. {
  310.     if(enAction == vaDoVerb)
  311.     {
  312.         globals.m_iVolume++;
  313.         if(globals.m_iVolume > 100)
  314.             globals.m_iVolume = 100;
  315.         main_draw_vu_from_value(windows.wnd_main, VolumeSlider, globals.m_iVolume);
  316.         CPI_Player__SetVolume(globals.m_hPlayer, globals.m_iVolume);
  317.     }
  318.     else if(enAction == vaQueryName)
  319.     {
  320.         CPs_VerbQueryName* pParam = (CPs_VerbQueryName*)_pParam;
  321.         if(stricmp(pParam->m_pcName, "VolumeUp") == 0)
  322.             pParam->m_bNameMatched = TRUE;
  323.     }
  324. }
  325. //
  326. //
  327. //
  328. void CPVERB_VolumeDown(const CPe_VerbAction enAction, void* _pParam)
  329. {
  330.     if(enAction == vaDoVerb)
  331.     {
  332.         globals.m_iVolume--;
  333.         if (globals.m_iVolume < 0)
  334.             globals.m_iVolume = 0;
  335.         main_draw_vu_from_value(windows.wnd_main, VolumeSlider, globals.m_iVolume);
  336.         CPI_Player__SetVolume(globals.m_hPlayer, globals.m_iVolume);
  337.     }
  338.     else if(enAction == vaQueryName)
  339.     {
  340.         CPs_VerbQueryName* pParam = (CPs_VerbQueryName*)_pParam;
  341.         if(stricmp(pParam->m_pcName, "VolumeDown") == 0)
  342.             pParam->m_bNameMatched = TRUE;
  343.     }
  344. }
  345. //
  346. //
  347. //
  348. void CPVERB_OpenFile(const CPe_VerbAction enAction, void* _pParam)
  349. {
  350.     if(enAction == vaDoVerb)
  351.     {
  352.         if(playlist_open_file(TRUE))
  353.             CPL_PlayItem(globals.m_hPlaylist, TRUE, pmCurrentItem);
  354.     }
  355.     else if(enAction == vaQueryName)
  356.     {
  357.         CPs_VerbQueryName* pParam = (CPs_VerbQueryName*)_pParam;
  358.         if(stricmp(pParam->m_pcName, "OpenFile") == 0)
  359.             pParam->m_bNameMatched = TRUE;
  360.     }
  361. }
  362. //
  363. //
  364. //
  365. void CPVERB_About(const CPe_VerbAction enAction, void* _pParam)
  366. {
  367.     if(enAction == vaDoVerb)
  368.         about_create((HWND)_pParam);
  369.     else if(enAction == vaQueryName)
  370.     {
  371.         CPs_VerbQueryName* pParam = (CPs_VerbQueryName*)_pParam;
  372.         if(stricmp(pParam->m_pcName, "About") == 0)
  373.             pParam->m_bNameMatched = TRUE;
  374.     }
  375. }
  376. //
  377. //
  378. //
  379. void CPVERB_Exit(const CPe_VerbAction enAction, void* _pParam)
  380. {
  381.     if(enAction == vaDoVerb)
  382.         DestroyWindow(windows.wnd_main);
  383.     else if(enAction == vaQueryName)
  384.     {
  385.         CPs_VerbQueryName* pParam = (CPs_VerbQueryName*)_pParam;
  386.         if(stricmp(pParam->m_pcName, "Exit") == 0)
  387.             pParam->m_bNameMatched = TRUE;
  388.     }
  389. }
  390. //
  391. //
  392. //
  393. void CPVERB_SavePlaylist(const CPe_VerbAction enAction, void* _pParam)
  394. {
  395.     if(enAction == vaDoVerb)
  396.         playlist_write();
  397.     else if(enAction == vaQueryName)
  398.     {
  399.         CPs_VerbQueryName* pParam = (CPs_VerbQueryName*)_pParam;
  400.         if(stricmp(pParam->m_pcName, "SavePlaylist") == 0)
  401.             pParam->m_bNameMatched = TRUE;
  402.     }
  403. }
  404. //
  405. //
  406. //
  407. void CPVERB_PlaylistShuffle(const CPe_VerbAction enAction, void* _pParam)
  408. {
  409.     if(enAction == vaDoVerb)
  410.     {
  411.         CPL_Stack_Shuffle(globals.m_hPlaylist, TRUE);
  412.     }
  413.     else if(enAction == vaQueryName)
  414.     {
  415.         CPs_VerbQueryName* pParam = (CPs_VerbQueryName*)_pParam;
  416.         if(stricmp(pParam->m_pcName, "PlaylistShuffle") == 0)
  417.             pParam->m_bNameMatched = TRUE;
  418.     }
  419. }
  420. //
  421. //
  422. //
  423. void CPVERB_PlaylistOffsetUp(const CPe_VerbAction enAction, void* _pParam)
  424. {
  425.     if(enAction == vaDoVerb)
  426.         CPlaylistWindow_OffsetSelectedItems(-1);
  427.     else if(enAction == vaQueryName)
  428.     {
  429.         CPs_VerbQueryName* pParam = (CPs_VerbQueryName*)_pParam;
  430.         if(stricmp(pParam->m_pcName, "PlaylistOffsetUp") == 0)
  431.             pParam->m_bNameMatched = TRUE;
  432.     }
  433. }
  434. //
  435. //
  436. //
  437. void CPVERB_PlaylistOffsetDown(const CPe_VerbAction enAction, void* _pParam)
  438. {
  439.     if(enAction == vaDoVerb)
  440.         CPlaylistWindow_OffsetSelectedItems(1);
  441.     else if(enAction == vaQueryName)
  442.     {
  443.         CPs_VerbQueryName* pParam = (CPs_VerbQueryName*)_pParam;
  444.         if(stricmp(pParam->m_pcName, "PlaylistOffsetDown") == 0)
  445.             pParam->m_bNameMatched = TRUE;
  446.     }
  447. }
  448. //
  449. //
  450. //
  451. void CPVERB_AddDirectory(const CPe_VerbAction enAction, void* _pParam)
  452. {
  453.     if(enAction == vaDoVerb)
  454.     {
  455.         BROWSEINFO browseinfo;
  456.         LPITEMIDLIST itemlist;
  457.         int image = 0;
  458.         char directorychoice[MAX_PATH];
  459.         browseinfo.hwndOwner = (HWND)_pParam;
  460.         browseinfo.pidlRoot = NULL;
  461.         browseinfo.pszDisplayName = directorychoice;
  462.         browseinfo.lpszTitle = "Choose a directory to add";
  463.         browseinfo.ulFlags = BIF_EDITBOX;
  464.         browseinfo.lpfn = NULL;
  465.         browseinfo.lParam = 0;
  466.         browseinfo.iImage = image;
  467.         itemlist = SHBrowseForFolder(&browseinfo);
  468.         if(itemlist == NULL)
  469.             return;
  470.         SHGetPathFromIDList(itemlist, globals.main_text_last_browsed_dir);
  471.         CPL_SyncLoadNextFile(globals.m_hPlaylist);
  472.         CPL_AddDirectory_Recurse(globals.m_hPlaylist, globals.main_text_last_browsed_dir);
  473.         if(options.shuffle_play)
  474.             CPL_Stack_Shuffle(globals.m_hPlaylist, TRUE);
  475.     }
  476.     else if(enAction == vaQueryName)
  477.     {
  478.         CPs_VerbQueryName* pParam = (CPs_VerbQueryName*)_pParam;
  479.         if(stricmp(pParam->m_pcName, "AddDirectory") == 0)
  480.             pParam->m_bNameMatched = TRUE;
  481.     }
  482. }
  483. //
  484. //
  485. //
  486. void CPVERB_PlaylistMinimise(const CPe_VerbAction enAction, void* _pParam)
  487. {
  488.     if(enAction == vaDoVerb)
  489.         ShowWindow(IF_GetHWnd(windows.m_hifPlaylist), SW_MINIMIZE);
  490.     else if(enAction == vaQueryName)
  491.     {
  492.         CPs_VerbQueryName* pParam = (CPs_VerbQueryName*)_pParam;
  493.         if(stricmp(pParam->m_pcName, "PlaylistMinimise") == 0)
  494.             pParam->m_bNameMatched = TRUE;
  495.     }
  496. }
  497. //
  498. //
  499. //
  500. void CPVERB_PlaylistMaximise(const CPe_VerbAction enAction, void* _pParam)
  501. {
  502.     if(enAction == vaDoVerb)
  503.     {
  504.         if(IsZoomed(IF_GetHWnd(windows.m_hifPlaylist)))
  505.             ShowWindow(IF_GetHWnd(windows.m_hifPlaylist), SW_RESTORE);
  506.         else
  507.             ShowWindow(IF_GetHWnd(windows.m_hifPlaylist), SW_MAXIMIZE);
  508.     }
  509.     else if(enAction == vaQueryName)
  510.     {
  511.         CPs_VerbQueryName* pParam = (CPs_VerbQueryName*)_pParam;
  512.         if(stricmp(pParam->m_pcName, "PlaylistMaximise") == 0)
  513.             pParam->m_bNameMatched = TRUE;
  514.     }
  515. }
  516. //
  517. //
  518. //