finally kill NC::List
[ncmpcpp.git] / src / screen.h
blobd232d2a27be3f70706efece9f74cc050bdddc2a9
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 ///
34 class BasicScreen
36 public:
37 /// Initializes all variables to zero
38 ///
39 BasicScreen() : hasToBeResized(0), isInitialized(0) { }
41 virtual ~BasicScreen() { }
43 /// @see Screen::ActiveWindow()
44 virtual NC::Window *ActiveWindow() = 0;
46 /// Method used for switching to screen
47 virtual void SwitchTo() = 0;
49 /// Method that should resize screen
50 /// if requested by hasToBeResized
51 virtual void Resize() = 0;
53 /// @return title of the screen
54 virtual std::basic_string<my_char_t> Title() = 0;
56 /// If the screen contantly has to update itself
57 /// somehow, it should be called by this function.
58 virtual void Update() { }
60 /// @see Screen::Refresh()
61 virtual void Refresh() = 0;
63 /// @see Screen::RefreshWindow()
64 virtual void RefreshWindow() = 0;
66 /// @see Screen::Scroll()
67 virtual void Scroll(NC::Where where) = 0;
69 /// Invoked after Enter was pressed
70 virtual void EnterPressed() = 0;
72 /// Invoked after Space was pressed
73 virtual void SpacePressed() = 0;
75 /// @see Screen::MouseButtonPressed()
76 virtual void MouseButtonPressed(MEVENT) { }
78 /// When this is overwritten with a function returning true, the
79 /// screen will be used in tab switching.
80 virtual bool isTabbable() { return false; }
82 /// @return true if screen is mergable, ie. can be "proper" subwindow
83 /// if one of the screens is locked. Screens that somehow resemble popups
84 /// will want to return false here.
85 virtual bool isMergable() = 0;
87 /// Locks current screen.
88 /// @return true if lock was successful, false otherwise. Note that
89 /// if there is already locked screen, it'll not overwrite it.
90 bool Lock();
92 /// Should be set to true each time screen needs resize
93 bool hasToBeResized;
95 /// Unlocks a screen, ie. hides merged window (if there is one set).
96 static void Unlock();
98 protected:
99 /// Since screens initialization is lazy, we don't want to do
100 /// this in the constructor. This function should be invoked
101 /// only once and after that isInitialized flag has to be set
102 /// to true to somehow avoid next attempt of initialization.
104 virtual void Init() = 0;
106 /// @return true if screen can be locked. Note that returning
107 /// false here doesn't neccesarily mean that screen is also not
108 /// mergable (eg. lyrics screen is not lockable since that wouldn't
109 /// make much sense, but it's perfectly fine to merge it).
110 virtual bool isLockable() = 0;
112 /// Gets X offset and width of current screen to be used eg. in Resize() function.
113 /// @param adjust_locked_screen indicates whether this function should
114 /// automatically adjust locked screen's dimensions (if there is one set)
115 /// if current screen is going to be subwindow.
116 void GetWindowResizeParams(size_t &x_offset, size_t &width, bool adjust_locked_screen = true);
118 /// Flag that inditates whether the screen is initialized or not
120 bool isInitialized;
123 void ApplyToVisibleWindows(void (BasicScreen::*f)());
124 void UpdateInactiveScreen(BasicScreen *screen_to_be_set);
125 bool isVisible(BasicScreen *screen);
127 /// Class that all screens should derive from. It provides basic interface
128 /// for the screen to be working properly and assumes that we didn't forget
129 /// about anything vital.
131 template <typename WindowType> class Screen : public BasicScreen
133 public:
134 Screen() : w(0) { }
135 virtual ~Screen() { }
137 /// Since some screens contain more that one window
138 /// it's useful to determine the one that is being
139 /// active
140 /// @return address to window object cast to void *
141 virtual NC::Window *ActiveWindow();
143 /// @return pointer to currently active window
144 WindowType *Main();
146 /// Refreshes whole screen
147 virtual void Refresh();
149 /// Refreshes active window of the screen
150 virtual void RefreshWindow();
152 /// Scrolls the screen by given amount of lines and
153 /// if fancy scrolling feature is disabled, enters the
154 /// loop that holds main loop until user releases the key
155 /// @param where indicates where one wants to scroll
156 virtual void Scroll(NC::Where where);
158 /// Invoked after there was one of mouse buttons pressed
159 /// @param me struct that contains coords of where the click
160 /// had its place and button actions
161 virtual void MouseButtonPressed(MEVENT me);
163 protected:
164 /// Template parameter that should indicate the main type
165 /// of window used by the screen. What is more, it should
166 /// always be assigned to the currently active window (if
167 /// acreen contains more that one)
168 WindowType *w;
171 template <typename WindowType> NC::Window *Screen<WindowType>::ActiveWindow()
173 return w;
176 template <typename WindowType> WindowType *Screen<WindowType>::Main()
178 return w;
181 template <typename WindowType> void Screen<WindowType>::Refresh()
183 w->Display();
186 template <typename WindowType> void Screen<WindowType>::RefreshWindow()
188 w->Display();
191 template <typename WindowType> void Screen<WindowType>::Scroll(NC::Where where)
193 w->Scroll(where);
196 template <typename WindowType> void Screen<WindowType>::MouseButtonPressed(MEVENT me)
198 GenericMouseButtonPressed(w, me);
201 /// Specialization for Screen<Scrollpad>::MouseButtonPressed, that should
202 /// not scroll whole page, but rather a few lines (the number of them is
203 /// defined in the config)
204 template <> inline void Screen<NC::Scrollpad>::MouseButtonPressed(MEVENT me)
206 ScrollpadMouseButtonPressed(w, me);
209 #endif