1 /***************************************************************************
2 * Copyright (C) 2008-2014 by Andrzej Rybczak *
3 * electricityispower@gmail.com *
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. *
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. *
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 ***************************************************************************/
27 using Global::myScreen
;
28 using Global::myLockedScreen
;
29 using Global::myInactiveScreen
;
31 void drawSeparator(int x
)
33 attron(COLOR_PAIR(int(Config
.main_color
)));
34 mvvline(Global::MainStartY
, x
, 0, Global::MainHeight
);
35 attroff(COLOR_PAIR(int(Config
.main_color
)));
39 void genericMouseButtonPressed(NC::Window
&w
, MEVENT me
)
41 if (me
.bstate
& BUTTON2_PRESSED
)
43 if (Config
.mouse_list_scroll_whole_page
)
44 w
.scroll(NC::Scroll::PageDown
);
46 for (size_t i
= 0; i
< Config
.lines_scrolled
; ++i
)
47 w
.scroll(NC::Scroll::Down
);
49 else if (me
.bstate
& BUTTON4_PRESSED
)
51 if (Config
.mouse_list_scroll_whole_page
)
52 w
.scroll(NC::Scroll::PageUp
);
54 for (size_t i
= 0; i
< Config
.lines_scrolled
; ++i
)
55 w
.scroll(NC::Scroll::Up
);
59 void scrollpadMouseButtonPressed(NC::Scrollpad
&w
, MEVENT me
)
61 if (me
.bstate
& BUTTON2_PRESSED
)
63 for (size_t i
= 0; i
< Config
.lines_scrolled
; ++i
)
64 w
.scroll(NC::Scroll::Down
);
66 else if (me
.bstate
& BUTTON4_PRESSED
)
68 for (size_t i
= 0; i
< Config
.lines_scrolled
; ++i
)
69 w
.scroll(NC::Scroll::Up
);
73 /***********************************************************************/
75 void BaseScreen::getWindowResizeParams(size_t &x_offset
, size_t &width
, bool adjust_locked_screen
)
79 if (myLockedScreen
&& myInactiveScreen
)
81 size_t locked_width
= COLS
*Config
.locked_screen_width_part
;
82 if (myLockedScreen
== this)
86 width
= COLS
-locked_width
-1;
87 x_offset
= locked_width
+1;
89 if (adjust_locked_screen
)
91 myLockedScreen
->resize();
92 myLockedScreen
->refresh();
93 drawSeparator(x_offset
-1);
99 bool BaseScreen::lock()
105 myLockedScreen
= this;
112 void BaseScreen::unlock()
114 if (myInactiveScreen
&& myInactiveScreen
!= myLockedScreen
)
115 myScreen
= myInactiveScreen
;
116 if (myScreen
!= myLockedScreen
)
117 myLockedScreen
->switchTo();
119 myInactiveScreen
= 0;
122 /***********************************************************************/
124 void applyToVisibleWindows(std::function
<void(BaseScreen
*)> f
)
126 if (myLockedScreen
&& myScreen
->isMergable())
128 if (myScreen
== myLockedScreen
)
130 if (myInactiveScreen
)
139 void updateInactiveScreen(BaseScreen
*screen_to_be_set
)
141 if (myInactiveScreen
&& myLockedScreen
!= myInactiveScreen
&& myLockedScreen
== screen_to_be_set
)
143 // if we're here, the following conditions are (or at least should be) met:
144 // 1. screen is split (myInactiveScreen is not null)
145 // 2. current screen (myScreen) is not splittable, ie. is stacked on top of split screens
146 // 3. current screen was activated while master screen was active
147 // 4. we are returning to master screen
148 // in such case we want to keep slave screen visible, so we never set it to null
149 // as in "else" case. we also need to refresh it and redraw separator between
150 // them as stacked screen probably has overwritten part ot it.
151 myInactiveScreen
->refresh();
152 drawSeparator(COLS
*Config
.locked_screen_width_part
);
156 if (myLockedScreen
== screen_to_be_set
)
157 myInactiveScreen
= 0;
159 myInactiveScreen
= myLockedScreen
;
163 bool isVisible(BaseScreen
*screen
)
166 if (myLockedScreen
&& myScreen
->isMergable())
167 return screen
== myScreen
|| screen
== myInactiveScreen
|| screen
== myLockedScreen
;
169 return screen
== myScreen
;