ListWindow: replace callback function with abstract class
[ncmpc-debian.git] / src / screen_browser.hxx
1 /* ncmpc (Ncurses MPD Client)
2  * (c) 2004-2018 The Music Player Daemon Project
3  * Project homepage: http://musicpd.org
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19
20 #ifndef SCREEN_BROWSER_H
21 #define SCREEN_BROWSER_H
22
23 #include "command.hxx"
24 #include "config.h"
25 #include "ncmpc_curses.h"
26 #include "ListPage.hxx"
27 #include "ListRenderer.hxx"
28
29 struct mpdclient;
30 struct MpdQueue;
31 class ScreenManager;
32 class FileList;
33 struct FileListEntry;
34
35 class FileListPage : public ListPage, ListRenderer {
36 protected:
37         ScreenManager &screen;
38
39         FileList *filelist = nullptr;
40         const char *const song_format;
41
42 public:
43         FileListPage(ScreenManager &_screen, WINDOW *_w,
44                      Size size,
45                      const char *_song_format)
46                 :ListPage(_w, size),
47                  screen(_screen),
48                  song_format(_song_format) {}
49
50         ~FileListPage() override;
51
52 protected:
53         gcc_pure
54         FileListEntry *GetSelectedEntry() const;
55
56         gcc_pure
57         const struct mpd_entity *GetSelectedEntity() const;
58
59         gcc_pure
60         const struct mpd_song *GetSelectedSong() const;
61
62         FileListEntry *GetIndex(unsigned i) const;
63
64 private:
65         bool HandleEnter(struct mpdclient &c);
66         bool HandleSelect(struct mpdclient &c);
67         bool HandleAdd(struct mpdclient &c);
68
69         void HandleSelectAll(struct mpdclient &c);
70
71         static void PaintRow(WINDOW *w, unsigned i,
72                              unsigned y, unsigned width,
73                              bool selected, const void *data);
74
75         /* virtual methods from class ListRenderer */
76         void PaintListItem(WINDOW *w, unsigned i,
77                            unsigned y, unsigned width,
78                            bool selected) const final;
79
80 public:
81         /* virtual methods from class Page */
82         void Paint() const override;
83         bool OnCommand(struct mpdclient &c, command_t cmd) override;
84
85 #ifdef HAVE_GETMOUSE
86         bool OnMouse(struct mpdclient &c, Point p,
87                      mmask_t bstate) override;
88 #endif
89 };
90
91 #ifndef NCMPC_MINI
92
93 void
94 screen_browser_sync_highlights(FileList *fl,
95                                const MpdQueue *playlist);
96
97 #else
98
99 static inline void
100 screen_browser_sync_highlights(gcc_unused FileList *fl,
101                                gcc_unused const MpdQueue *playlist)
102 {
103 }
104
105 #endif
106
107 void
108 screen_browser_paint_directory(WINDOW *w, unsigned width,
109                                bool selected, const char *name);
110
111 #endif