OSDN Git Service

Fix search feature
authorStarg <starg@users.osdn.me>
Fri, 31 Jul 2020 23:24:14 +0000 (08:24 +0900)
committerStarg <starg@users.osdn.me>
Fri, 31 Jul 2020 23:24:14 +0000 (08:24 +0900)
interface/w32g.h
interface/w32g_playlist.c
interface/w32g_subwin.c

index 29e529e..a59789e 100644 (file)
@@ -303,6 +303,7 @@ extern void MPanelStartLoad(const char *filename);
 extern int w32g_add_playlist(int nfiles, char **files, int expand_flag,
                             int autouniq, int autorefine);
 extern char *w32g_get_playlist(int idx);
+extern char *w32g_get_playlist_title(int idx);
 extern int w32g_next_playlist(int skip_invalid_file);
 extern int w32g_prev_playlist(int skip_invalid_file);
 extern int w32g_random_playlist(int skip_invalid_file);
@@ -314,6 +315,7 @@ extern char *w32g_curr_playlist(void);
 extern void w32g_update_playlist(void);
 extern void w32g_get_playlist_index(int *selected, int *nfiles, int *cursel);
 extern int w32g_goto_playlist(int num, int skip_invalid_file);
+extern void w32g_focus_playlist_index(int idx);
 extern int w32g_delete_playlist(int pos);
 extern int w32g_nvalid_playlist(void);
 extern int w32g_ismidi_playlist(int n);
@@ -337,6 +339,7 @@ extern void w32g_set_playmode_rate(int32 rate);
 extern char *w32g_get_playlist_play(int idx);
 extern void w32g_get_playlist_play_index(int *selected);
 #ifdef LISTVIEW_PLAYLIST
+extern char *w32g_get_playlist_artist(int idx);
 extern void w32g_copy_playlist(void);
 extern void w32g_paste_playlist(int uniq, int refine);
 #endif
index acaf45f..2fd39d1 100644 (file)
@@ -575,6 +575,22 @@ int w32g_goto_playlist(int num, int skip_invalid_file)
     return 0;
 }
 
+void w32g_focus_playlist_index(int idx)
+{
+       HWND hList;
+
+       if (!(hList = playlist_box()))
+               return;
+
+#ifdef LISTVIEW_PLAYLIST
+       ListView_SetItemState(hList, -1, 0, LVIS_SELECTED | LVIS_FOCUSED);
+       ListView_SetItemState(hList, idx, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
+       ListView_EnsureVisible(hList, idx, FALSE);
+#else
+       ListBox_SetCurSel(hList, cur);
+#endif
+}
+
 int w32g_isempty_playlist(void)
 {
     return playlist_ctrl->nfiles == 0;
@@ -1252,6 +1268,13 @@ char *w32g_get_playlist(int idx)
     return playlist_ctrl->list[idx].filepath;
 }
 
+char *w32g_get_playlist_title(int idx)
+{
+       if (idx < 0 || idx >= playlist_ctrl->nfiles)
+               return NULL;
+       return playlist_ctrl->list[idx].title;
+}
+
 char *w32g_get_playlist_play(int idx)
 {
     if (idx < 0 || idx >= playlist_play->nfiles)
@@ -1260,6 +1283,14 @@ char *w32g_get_playlist_play(int idx)
 }
 
 #ifdef LISTVIEW_PLAYLIST
+
+char *w32g_get_playlist_artist(int idx)
+{
+       if (idx < 0 || idx >= playlist_ctrl->nfiles)
+               return NULL;
+       return playlist_ctrl->list[idx].artist;
+}
+
 void w32g_copy_playlist(void)
 {
     int i, num, pos, selnum = 0;
index d1f5013..bbe084b 100644 (file)
@@ -2370,7 +2370,7 @@ void ClearDocWnd(void)
 
 //****************************************************************************
 // List Search Dialog
-#define ListSearchStringMax 256
+#define ListSearchStringMax 1024
 static char ListSearchString[ListSearchStringMax];
 
 LRESULT CALLBACK ListSearchWndProc(HWND hwnd, UINT uMess, WPARAM wParam, LPARAM lParam);
@@ -2434,29 +2434,29 @@ ListSearchWndProc(HWND hwnd, UINT uMess, WPARAM wParam, LPARAM lParam)
                {
                        int selected, nfiles, cursel;
                        SendDlgItemMessage(hwnd,IDC_EDIT_ONE_LINE,
-                               WM_GETTEXT,(WPARAM)250,(LPARAM)ListSearchString);
+                               WM_GETTEXT,(WPARAM)ListSearchStringMax,(LPARAM)ListSearchString);
                        w32g_get_playlist_index(&selected, &nfiles, &cursel);
+                       if (LOWORD(wParam) == IDC_BUTTON_1)
+                               cursel = 0;
                        if ( LOWORD(wParam) == IDC_BUTTON_2 )
                                cursel++;
                        if ( strlen ( ListSearchString ) > 0 ) {
-                               char buff[ListSearchStringBuffSize];
                                for ( ; cursel < nfiles; cursel ++ ) {
-                                       int result = SendDlgItemMessage(hListWnd,IDC_LISTBOX_PLAYLIST,
-                                               LB_GETTEXTLEN,(WPARAM)cursel, 0 );
-                                       if ( result < ListSearchStringBuffSize ) {
-                                               result = SendDlgItemMessage(hListWnd,IDC_LISTBOX_PLAYLIST,
-                                                       LB_GETTEXT,(WPARAM)cursel,(LPARAM)buff);
-                                               if ( result == LB_ERR ) {
-                                                       cursel = LB_ERR;
-                                                       break;
-                                               }
-                                               if ( strstr ( buff, ListSearchString ) != NULL ) {
-                                                       break;
-                                               }
-                                       } else if ( result == LB_ERR ) {
-                                               cursel = LB_ERR;
+                                       const char *str = w32g_get_playlist(cursel);
+                                       if (str != NULL && strstr(str, ListSearchString) != NULL) {
+                                               break;
+                                       }
+
+                                       str = w32g_get_playlist_title(cursel);
+                                       if (str != NULL && strstr(str, ListSearchString) != NULL) {
+                                               break;
+                                       }
+#ifdef LISTVIEW_PLAYLIST
+                                       str = w32g_get_playlist_artist(cursel);
+                                       if (str != NULL && strstr(str, ListSearchString) != NULL) {
                                                break;
                                        }
+#endif
                                }
                                if ( cursel >= nfiles ) {
                                        cursel = LB_ERR;
@@ -2465,11 +2465,15 @@ ListSearchWndProc(HWND hwnd, UINT uMess, WPARAM wParam, LPARAM lParam)
                                cursel = LB_ERR;
                        }
                        if ( cursel != LB_ERR ) {
-                               SendDlgItemMessage(hListWnd,IDC_LISTBOX_PLAYLIST,
-                                       LB_SETCURSEL,(WPARAM)cursel,0);
-                               SetNumListWnd(cursel,nfiles);
-                               if ( LOWORD(wParam) == IDC_BUTTON_1 )
-                                       HideListSearch();
+                               w32g_focus_playlist_index(cursel);
+                               //if ( LOWORD(wParam) == IDC_BUTTON_1 )
+                               //      HideListSearch();
+                       } else {
+                               if (PlayerLanguage == LANGUAGE_JAPANESE) {
+                                       MessageBox(hwnd, "\88ê\92v\82·\82é\8d\80\96Ú\82ª\8c©\82Â\82©\82è\82Ü\82¹\82ñ", "\83v\83\8c\83C\83\8a\83X\83g\82Ì\8c\9f\8dõ", MB_ICONINFORMATION);
+                               } else {
+                                       MessageBox(hwnd, "No matches found.", "Playlist Search", MB_ICONINFORMATION);
+                               }
                        }
                }
                        break;