summaryrefslogtreecommitdiff
path: root/src/screen.cpp
blob: cb1d958267c912c121c2509d2fa436b22fe8322f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
/***************************************************************************
 *   Copyright (C) 2008-2012 by Andrzej Rybczak                            *
 *   electricityispower@gmail.com                                          *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.              *
 ***************************************************************************/

#include <cassert>

#include "global.h"
#include "screen.h"
#include "settings.h"

using Global::myScreen;
using Global::myLockedScreen;
using Global::myInactiveScreen;

namespace {//

void drawScreenSeparator(int x)
{
	attron(COLOR_PAIR(Config.main_color));
	mvvline(Global::MainStartY, x, 0, Global::MainHeight);
	attroff(COLOR_PAIR(Config.main_color));
	refresh();
}

}

void genericMouseButtonPressed(NC::Window &w, MEVENT me)
{
	if (me.bstate & BUTTON2_PRESSED)
	{
		if (Config.mouse_list_scroll_whole_page)
			w.scroll(NC::wPageDown);
		else
			for (size_t i = 0; i < Config.lines_scrolled; ++i)
				w.scroll(NC::wDown);
	}
	else if (me.bstate & BUTTON4_PRESSED)
	{
		if (Config.mouse_list_scroll_whole_page)
			w.scroll(NC::wPageUp);
		else
			for (size_t i = 0; i < Config.lines_scrolled; ++i)
				w.scroll(NC::wUp);
	}
}

void scrollpadMouseButtonPressed(NC::Scrollpad &w, MEVENT me)
{
	if (me.bstate & BUTTON2_PRESSED)
	{
		for (size_t i = 0; i < Config.lines_scrolled; ++i)
			w.scroll(NC::wDown);
	}
	else if (me.bstate & BUTTON4_PRESSED)
	{
		for (size_t i = 0; i < Config.lines_scrolled; ++i)
			w.scroll(NC::wUp);
	}
}

/***********************************************************************/

void BasicScreen::getWindowResizeParams(size_t &x_offset, size_t &width, bool adjust_locked_screen)
{
	width = COLS;
	x_offset = 0;
	if (myLockedScreen && myInactiveScreen)
	{
		size_t locked_width = COLS*Config.locked_screen_width_part;
		if (myLockedScreen == this)
			width = locked_width;
		else
		{
			width = COLS-locked_width-1;
			x_offset = locked_width+1;
			
			if (adjust_locked_screen)
			{
				myLockedScreen->resize();
				myLockedScreen->refresh();
				drawScreenSeparator(x_offset-1);
			}
		}
	}
}

bool BasicScreen::lock()
{
	if (myLockedScreen)
		return false;
	if (isLockable())
	{
		myLockedScreen = this;
		return true;
	}
	else
		return false;
}

void BasicScreen::unlock()
{
	if (myInactiveScreen && myInactiveScreen != myLockedScreen)
		myScreen = myInactiveScreen;
	if (myScreen != myLockedScreen)
		myLockedScreen->switchTo();
	myLockedScreen = 0;
	myInactiveScreen = 0;
}

/***********************************************************************/

void applyToVisibleWindows(void (BasicScreen::*f)())
{
	if (myLockedScreen && myScreen->isMergable())
	{
		if (myScreen == myLockedScreen)
		{
			if (myInactiveScreen)
				(myInactiveScreen->*f)();
		}
		else
			(myLockedScreen->*f)();
	}
	(myScreen->*f)();
}

void updateInactiveScreen(BasicScreen *screen_to_be_set)
{
	if (myInactiveScreen && myLockedScreen != myInactiveScreen && myLockedScreen == screen_to_be_set)
	{
		// if we're here, the following conditions are (or at least should be) met:
		// 1. screen is split (myInactiveScreen is not null)
		// 2. current screen (myScreen) is not splittable, ie. is stacked on top of split screens
		// 3. current screen was activated while master screen was active
		// 4. we are returning to master screen
		// in such case we want to keep slave screen visible, so we never set it to null
		// as in "else" case. we also need to refresh it and redraw separator between
		// them as stacked screen probably has overwritten part ot it.
		myInactiveScreen->refresh();
		drawScreenSeparator(COLS*Config.locked_screen_width_part);
	}
	else
	{
		if (myLockedScreen == screen_to_be_set)
			myInactiveScreen = 0;
		else
			myInactiveScreen = myLockedScreen;
	}
}

bool isVisible(BasicScreen *screen)
{
	assert(screen != 0);
	if (myLockedScreen && myScreen->isMergable())
		return screen == myScreen || screen == myInactiveScreen || screen == myLockedScreen;
	else
		return screen == myScreen;
}