strbuffer: change basic_buffer to BasicBuffer
[ncmpcpp.git] / src / screen.h
blob47719eae2705c4e4ba78cd1361c98d1829c5466d
1 /***************************************************************************
2 * Copyright (C) 2008-2012 by Andrzej Rybczak *
3 * electricityispower@gmail.com *
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 *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
19 ***************************************************************************/
21 #ifndef _SCREEN_H
22 #define _SCREEN_H
24 #include "menu.h"
25 #include "scrollpad.h"
27 void GenericMouseButtonPressed(NC::Window *w, MEVENT me);
28 void ScrollpadMouseButtonPressed(NC::Scrollpad *w, MEVENT me);
30 /// An interface for various instantiations of Screen template class. Since C++ doesn't like
31 /// comparison of two different instantiations of the same template class we need the most
32 /// basic class to be non-template to allow it.
33 class BasicScreen
35 public:
36 /// Initializes all variables to zero
37 BasicScreen() : hasToBeResized(0), isInitialized(0) { }
39 virtual ~BasicScreen() { }
41 /// @see Screen::ActiveWindow()
42 virtual NC::Window *ActiveWindow() = 0;
44 /// @see Screen::Refresh()
45 virtual void Refresh() = 0;
47 /// @see Screen::RefreshWindow()
48 virtual void RefreshWindow() = 0;
50 /// @see Screen::Scroll()
51 virtual void Scroll(NC::Where where) = 0;
53 /// Method used for switching to screen
54 virtual void SwitchTo() = 0;
56 /// Method that should resize screen
57 /// if requested by hasToBeResized
58 virtual void Resize() = 0;
60 /// @return title of the screen
61 virtual std::wstring Title() = 0;
63 /// If the screen contantly has to update itself
64 /// somehow, it should be called by this function.
65 virtual void Update() = 0;
67 /// Invoked after Enter was pressed
68 virtual void EnterPressed() = 0;
70 /// Invoked after Space was pressed
71 virtual void SpacePressed() = 0;
73 /// @see Screen::MouseButtonPressed()
74 virtual void MouseButtonPressed(MEVENT me) = 0;
76 /// When this is overwritten with a function returning true, the
77 /// screen will be used in tab switching.
78 virtual bool isTabbable() = 0;
80 /// @return true if screen is mergable, ie. can be "proper" subwindow
81 /// if one of the screens is locked. Screens that somehow resemble popups
82 /// will want to return false here.
83 virtual bool isMergable() = 0;
85 /// Locks current screen.
86 /// @return true if lock was successful, false otherwise. Note that
87 /// if there is already locked screen, it'll not overwrite it.
88 bool Lock();
90 /// Should be set to true each time screen needs resize
91 bool hasToBeResized;
93 /// Unlocks a screen, ie. hides merged window (if there is one set).
94 static void Unlock();
96 protected:
97 /// Since screens initialization is lazy, we don't want to do
98 /// this in the constructor. This function should be invoked
99 /// only once and after that isInitialized flag has to be set
100 /// to true to somehow avoid next attempt of initialization.
101 virtual void Init() = 0;
103 /// @return true if screen can be locked. Note that returning
104 /// false here doesn't neccesarily mean that screen is also not
105 /// mergable (eg. lyrics screen is not lockable since that wouldn't
106 /// make much sense, but it's perfectly fine to merge it).
107 virtual bool isLockable() = 0;
109 /// Gets X offset and width of current screen to be used eg. in Resize() function.
110 /// @param adjust_locked_screen indicates whether this function should
111 /// automatically adjust locked screen's dimensions (if there is one set)
112 /// if current screen is going to be subwindow.
113 void GetWindowResizeParams(size_t &x_offset, size_t &width, bool adjust_locked_screen = true);
115 /// Flag that inditates whether the screen is initialized or not
116 bool isInitialized;
119 void ApplyToVisibleWindows(void (BasicScreen::*f)());
120 void UpdateInactiveScreen(BasicScreen *screen_to_be_set);
121 bool isVisible(BasicScreen *screen);
123 /// Class that all screens should derive from. It provides basic interface
124 /// for the screen to be working properly and assumes that we didn't forget
125 /// about anything vital.
127 template <typename WindowType> class Screen : public BasicScreen
129 public:
130 Screen() : w(0) { }
131 virtual ~Screen() { }
133 /// Since some screens contain more that one window
134 /// it's useful to determine the one that is being
135 /// active
136 /// @return address to window object cast to void *
137 virtual NC::Window *ActiveWindow() OVERRIDE {
138 return w;
141 /// Refreshes whole screen
142 virtual void Refresh() OVERRIDE {
143 w->display();
146 /// Refreshes active window of the screen
147 virtual void RefreshWindow() OVERRIDE {
148 w->display();
151 /// Scrolls the screen by given amount of lines and
152 /// if fancy scrolling feature is disabled, enters the
153 /// loop that holds main loop until user releases the key
154 /// @param where indicates where one wants to scroll
155 virtual void Scroll(NC::Where where) OVERRIDE {
156 w->scroll(where);
159 /// Invoked after there was one of mouse buttons pressed
160 /// @param me struct that contains coords of where the click
161 /// had its place and button actions
162 virtual void MouseButtonPressed(MEVENT me) OVERRIDE {
163 GenericMouseButtonPressed(w, me);
166 /// @return pointer to currently active window
167 WindowType *Main() {
168 return w;
171 protected:
172 /// Template parameter that should indicate the main type
173 /// of window used by the screen. What is more, it should
174 /// always be assigned to the currently active window (if
175 /// acreen contains more that one)
176 WindowType *w;
179 /// Specialization for Screen<Scrollpad>::MouseButtonPressed, that should
180 /// not scroll whole page, but rather a few lines (the number of them is
181 /// defined in the config)
182 template <> inline void Screen<NC::Scrollpad>::MouseButtonPressed(MEVENT me)
184 ScrollpadMouseButtonPressed(w, me);
187 #endif