ncmpc  0.31
Page.hxx
Go to the documentation of this file.
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 NCMPC_PAGE_HXX
21 #define NCMPC_PAGE_HXX
22 
23 #include "config.h"
24 #include "ncmpc_curses.h"
25 #include "Point.hxx"
26 #include "Size.hxx"
27 #include "util/Compiler.h"
28 
29 #include <utility>
30 
31 #include <stddef.h>
32 
33 enum class Command : unsigned;
34 struct mpdclient;
35 
36 class Page {
37  Size last_size{0, 0};
38 
43  unsigned pending_events = ~0u;
44 
48  bool dirty = true;
49 
50 public:
51  virtual ~Page() = default;
52 
53  bool IsDirty() const {
54  return dirty;
55  }
56 
57  void SetDirty(bool _dirty=true) {
58  dirty = _dirty;
59  }
60 
61  void Resize(Size new_size) {
62  if (new_size == last_size)
63  return;
64 
65  last_size = new_size;
66  OnResize(new_size);
67  }
68 
69  void AddPendingEvents(unsigned events) {
70  pending_events |= events;
71  }
72 
73  void Update(struct mpdclient &c) {
74  Update(c, std::exchange(pending_events, 0));
75  }
76 
77 protected:
78  const Size &GetLastSize() const {
79  return last_size;
80  }
81 
82 public:
83  virtual void OnOpen(struct mpdclient &) {}
84  virtual void OnClose() {}
85  virtual void OnResize(Size size) = 0;
86  virtual void Paint() const = 0;
87  virtual void Update(struct mpdclient &, unsigned) {}
88 
95  virtual bool OnCommand(struct mpdclient &c, Command cmd) = 0;
96 
97 #ifdef HAVE_GETMOUSE
98 
104  virtual bool OnMouse(gcc_unused struct mpdclient &c,
105  gcc_unused Point position,
106  gcc_unused mmask_t bstate) {
107  return false;
108  }
109 #endif
110 
111  virtual const char *GetTitle(char *s, size_t size) const = 0;
112 };
113 
114 #endif
Command
Definition: Command.hxx:29
bool IsDirty() const
Definition: Page.hxx:53
virtual bool OnCommand(struct mpdclient &c, Command cmd)=0
void SetDirty(bool _dirty=true)
Definition: Page.hxx:57
virtual const char * GetTitle(char *s, size_t size) const =0
void Resize(Size new_size)
Definition: Page.hxx:61
void Update(struct mpdclient &c)
Definition: Page.hxx:73
unsigned events
Definition: mpdclient.hxx:78
const Size & GetLastSize() const
Definition: Page.hxx:78
Definition: mpdclient.hxx:17
virtual void OnResize(Size size)=0
Definition: Size.hxx:26
void AddPendingEvents(unsigned events)
Definition: Page.hxx:69
virtual void OnClose()
Definition: Page.hxx:84
virtual void Update(struct mpdclient &, unsigned)
Definition: Page.hxx:87
Definition: Point.hxx:28
virtual void Paint() const =0
virtual ~Page()=default
virtual void OnOpen(struct mpdclient &)
Definition: Page.hxx:83
Definition: Page.hxx:36