ListWindow: convert list_window_callback_fn_t to an 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 #include "ListText.hxx"
29
30 struct mpdclient;
31 struct MpdQueue;
32 class ScreenManager;
33 class FileList;
34 struct FileListEntry;
35
36 class FileListPage : public ListPage, ListRenderer, ListText {
37 protected:
38         ScreenManager &screen;
39
40         FileList *filelist = nullptr;
41         const char *const song_format;
42
43 public:
44         FileListPage(ScreenManager &_screen, WINDOW *_w,
45                      Size size,
46                      const char *_song_format)
47                 :ListPage(_w, size),
48                  screen(_screen),
49                  song_format(_song_format) {}
50
51         ~FileListPage() override;
52
53 protected:
54         gcc_pure
55         FileListEntry *GetSelectedEntry() const;
56
57         gcc_pure
58         const struct mpd_entity *GetSelectedEntity() const;
59
60         gcc_pure
61         const struct mpd_song *GetSelectedSong() const;
62
63         FileListEntry *GetIndex(unsigned i) const;
64
65 private:
66         bool HandleEnter(struct mpdclient &c);
67         bool HandleSelect(struct mpdclient &c);
68         bool HandleAdd(struct mpdclient &c);
69
70         void HandleSelectAll(struct mpdclient &c);
71
72         static void PaintRow(WINDOW *w, unsigned i,
73                              unsigned y, unsigned width,
74                              bool selected, const void *data);
75
76         /* virtual methods from class ListRenderer */
77         void PaintListItem(WINDOW *w, unsigned i,
78                            unsigned y, unsigned width,
79                            bool selected) const final;
80
81         /* virtual methods from class ListText */
82         const char *GetListItemText(unsigned i) const override;
83
84 public:
85         /* virtual methods from class Page */
86         void Paint() const override;
87         bool OnCommand(struct mpdclient &c, command_t cmd) override;
88
89 #ifdef HAVE_GETMOUSE
90         bool OnMouse(struct mpdclient &c, Point p,
91                      mmask_t bstate) override;
92 #endif
93 };
94
95 #ifndef NCMPC_MINI
96
97 void
98 screen_browser_sync_highlights(FileList *fl,
99                                const MpdQueue *playlist);
100
101 #else
102
103 static inline void
104 screen_browser_sync_highlights(gcc_unused FileList *fl,
105                                gcc_unused const MpdQueue *playlist)
106 {
107 }
108
109 #endif
110
111 void
112 screen_browser_paint_directory(WINDOW *w, unsigned width,
113                                bool selected, const char *name);
114
115 #endif