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