Bug Summary

File:fe-text/gui-windows.c
Location:line 87, column 9
Description:Value stored to 'empty_window' is never read

Annotated Source Code

1/*
2 gui-windows.c : irssi
3
4 Copyright (C) 1999-2001 Timo Sirainen
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License along
17 with this program; if not, write to the Free Software Foundation, Inc.,
18 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19*/
20
21#include "module.h"
22#include "signals.h"
23#include "misc.h"
24#include "settings.h"
25#include "special-vars.h"
26
27#include "term.h"
28#include "gui-entry.h"
29#include "gui-windows.h"
30#include "gui-printtext.h"
31
32static int window_create_override;
33
34static GUI_WINDOW_REC *gui_window_init(WINDOW_REC *window,
35 MAIN_WINDOW_REC *parent)
36{
37 GUI_WINDOW_REC *gui;
38
39 window->width = parent->width;
40 window->height = MAIN_WINDOW_TEXT_HEIGHT(parent)((parent)->height-(parent)->statusbar_lines);
41
42 gui = g_new0(GUI_WINDOW_REC, 1)((GUI_WINDOW_REC *) g_malloc0 (((gsize) sizeof (GUI_WINDOW_REC
)) * ((gsize) (1))))
;
43 gui->parent = parent;
44 gui->view = textbuffer_view_create(textbuffer_create(),
45 window->width, window->height,
46 settings_get_bool("scroll"),
47 term_type == TERM_TYPE_UTF81);
48 textbuffer_view_set_default_indent(gui->view,
49 settings_get_int("indent"),
50 !settings_get_bool("indent_always"),
51 get_default_indent_func());
52 if (parent->active == window)
53 textbuffer_view_set_window(gui->view, parent->screen_win);
54 return gui;
55}
56
57static void gui_window_deinit(GUI_WINDOW_REC *gui)
58{
59 textbuffer_view_destroy(gui->view);
60 g_free(gui);
61}
62
63static void sig_window_create_override(gpointer tab)
64{
65 window_create_override = GPOINTER_TO_INT(tab)((gint) (tab));
66}
67
68static void gui_window_created(WINDOW_REC *window, void *automatic)
69{
70 MAIN_WINDOW_REC *parent;
71 int empty_window, new_parent;
72
73 g_return_if_fail(window != NULL)do{ if (window != ((void *)0)) { } else { g_return_if_fail_warning
(((gchar*) 0), __PRETTY_FUNCTION__, "window != NULL"); return
; }; }while (0)
;
74
75 new_parent = window_create_override == 0 ||
76 window_create_override == 2 ||
77 active_win == NULL((void *)0) || WINDOW_GUI(active_win)((GUI_WINDOW_REC *) ((active_win)->gui_data)) == NULL((void *)0);
78 parent = !new_parent ? WINDOW_MAIN(active_win)(((GUI_WINDOW_REC *) ((active_win)->gui_data))->parent) : mainwindow_create();
79 if (parent == NULL((void *)0)) {
80 /* not enough space for new window, but we really can't
81 abort creation of the window anymore, so create hidden
82 window instead. */
83 parent = WINDOW_MAIN(active_win)(((GUI_WINDOW_REC *) ((active_win)->gui_data))->parent);
84 }
85 window_create_override = -1;
86
87 empty_window = parent->active == NULL((void *)0);
Value stored to 'empty_window' is never read
88
89 if (parent->active == NULL((void *)0)) parent->active = window;
90 window->gui_data = gui_window_init(window, parent);
91
92 /* set only non-automatic windows sticky so that the windows
93 irssi creates at startup wont get sticky. */
94 if (automatic == NULL((void *)0) &&
95 (parent->sticky_windows ||
96 (new_parent && settings_get_bool("autostick_split_windows"))))
97 gui_window_set_sticky(window);
98
99 signal_emit("gui window created", 1, window);
100}
101
102static void gui_window_destroyed(WINDOW_REC *window)
103{
104 MAIN_WINDOW_REC *parent;
105 GUI_WINDOW_REC *gui;
106
107 g_return_if_fail(window != NULL)do{ if (window != ((void *)0)) { } else { g_return_if_fail_warning
(((gchar*) 0), __PRETTY_FUNCTION__, "window != NULL"); return
; }; }while (0)
;
108
109 gui = WINDOW_GUI(window)((GUI_WINDOW_REC *) ((window)->gui_data));
110 parent = gui->parent;
111
112 gui_window_set_unsticky(window);
113
114 signal_emit("gui window destroyed", 1, window);
115
116 gui_window_deinit(gui);
117 window->gui_data = NULL((void *)0);
118
119 if (parent->active == window)
120 mainwindow_change_active(parent, window);
121}
122
123void gui_window_resize(WINDOW_REC *window, int width, int height)
124{
125 GUI_WINDOW_REC *gui;
126
127 if (window->width == width && window->height == height)
128 return;
129
130 gui = WINDOW_GUI(window)((GUI_WINDOW_REC *) ((window)->gui_data));
131
132 irssi_set_dirty();
133 WINDOW_MAIN(window)(((GUI_WINDOW_REC *) ((window)->gui_data))->parent)->dirty = TRUE(!(0));
134
135 window->width = width;
136 window->height = height;
137 textbuffer_view_resize(gui->view, width, height);
138}
139
140void gui_window_scroll(WINDOW_REC *window, int lines)
141{
142 g_return_if_fail(window != NULL)do{ if (window != ((void *)0)) { } else { g_return_if_fail_warning
(((gchar*) 0), __PRETTY_FUNCTION__, "window != NULL"); return
; }; }while (0)
;
143
144 textbuffer_view_scroll(WINDOW_GUI(window)((GUI_WINDOW_REC *) ((window)->gui_data))->view, lines);
145 signal_emit("gui page scrolled", 1, window);
146}
147
148void gui_window_scroll_line(WINDOW_REC *window, LINE_REC *line)
149{
150 g_return_if_fail(window != NULL)do{ if (window != ((void *)0)) { } else { g_return_if_fail_warning
(((gchar*) 0), __PRETTY_FUNCTION__, "window != NULL"); return
; }; }while (0)
;
151 g_return_if_fail(line != NULL)do{ if (line != ((void *)0)) { } else { g_return_if_fail_warning
(((gchar*) 0), __PRETTY_FUNCTION__, "line != NULL"); return;
}; }while (0)
;
152
153 textbuffer_view_scroll_line(WINDOW_GUI(window)((GUI_WINDOW_REC *) ((window)->gui_data))->view, line);
154 signal_emit("gui page scrolled", 1, window);
155}
156
157void gui_window_set_sticky(WINDOW_REC *window)
158{
159 GUI_WINDOW_REC *gui = WINDOW_GUI(window)((GUI_WINDOW_REC *) ((window)->gui_data));
160
161 if (!gui->sticky) {
162 gui->sticky = TRUE(!(0));
163 gui->parent->sticky_windows++;
164 }
165}
166
167void gui_window_set_unsticky(WINDOW_REC *window)
168{
169 GUI_WINDOW_REC *gui = WINDOW_GUI(window)((GUI_WINDOW_REC *) ((window)->gui_data));
170
171 if (gui->sticky) {
172 gui->sticky = FALSE(0);
173 gui->parent->sticky_windows--;
174 }
175}
176
177void gui_window_reparent(WINDOW_REC *window, MAIN_WINDOW_REC *parent)
178{
179 MAIN_WINDOW_REC *oldparent;
180
181 oldparent = WINDOW_MAIN(window)(((GUI_WINDOW_REC *) ((window)->gui_data))->parent);
182 if (oldparent == parent)
183 return;
184
185 gui_window_set_unsticky(window);
186 textbuffer_view_set_window(WINDOW_GUI(window)((GUI_WINDOW_REC *) ((window)->gui_data))->view, NULL((void *)0));
187
188 WINDOW_MAIN(window)(((GUI_WINDOW_REC *) ((window)->gui_data))->parent) = parent;
189 if (parent->sticky_windows)
190 gui_window_set_sticky(window);
191
192 if (MAIN_WINDOW_TEXT_HEIGHT(parent)((parent)->height-(parent)->statusbar_lines) !=
193 MAIN_WINDOW_TEXT_HEIGHT(oldparent)((oldparent)->height-(oldparent)->statusbar_lines) ||
194 parent->width != oldparent->width) {
195 gui_window_resize(window, parent->width,
196 MAIN_WINDOW_TEXT_HEIGHT(parent)((parent)->height-(parent)->statusbar_lines));
197 }
198}
199
200void gui_windows_reset_settings(void)
201{
202 GSList *tmp;
203
204 for (tmp = windows; tmp != NULL((void *)0); tmp = tmp->next) {
205 WINDOW_REC *rec = tmp->data;
206 GUI_WINDOW_REC *gui = WINDOW_GUI(rec)((GUI_WINDOW_REC *) ((rec)->gui_data));
207
208 textbuffer_view_set_default_indent(gui->view,
209 settings_get_int("indent"),
210 !settings_get_bool("indent_always"),
211 get_default_indent_func());
212
213 textbuffer_view_set_scroll(gui->view,
214 gui->use_scroll ? gui->scroll :
215 settings_get_bool("scroll"));
216 }
217}
218
219static MAIN_WINDOW_REC *mainwindow_find_unsticky(void)
220{
221 GSList *tmp;
222
223 for (tmp = mainwindows; tmp != NULL((void *)0); tmp = tmp->next) {
224 MAIN_WINDOW_REC *rec = tmp->data;
225
226 if (!rec->sticky_windows)
227 return rec;
228 }
229
230 /* all windows are sticky, fallback to active window */
231 return active_mainwin;
232}
233
234static void signal_window_changed(WINDOW_REC *window)
235{
236 MAIN_WINDOW_REC *parent;
237 WINDOW_REC *old_window;
238
239 g_return_if_fail(window != NULL)do{ if (window != ((void *)0)) { } else { g_return_if_fail_warning
(((gchar*) 0), __PRETTY_FUNCTION__, "window != NULL"); return
; }; }while (0)
;
240
241 if (quitting) return;
242
243 parent = WINDOW_MAIN(window)(((GUI_WINDOW_REC *) ((window)->gui_data))->parent);
244 if (is_window_visible(window)(((GUI_WINDOW_REC *) ((window)->gui_data))->parent->
active == (window))
) {
245 /* already visible */
246 active_mainwin = parent;
247 } else if (active_mainwin == NULL((void *)0)) {
248 /* no main window set yet */
249 active_mainwin = parent;
250 } else if (WINDOW_GUI(window)((GUI_WINDOW_REC *) ((window)->gui_data))->sticky) {
251 /* window is sticky, switch to correct main window */
252 if (parent != active_mainwin)
253 active_mainwin = parent;
254 } else {
255 /* move window to active main window */
256 if (active_mainwin->sticky_windows) {
257 /* active mainwindow is sticky, we'll need to
258 set the window active somewhere else */
259 active_mainwin = mainwindow_find_unsticky();
260 }
261 gui_window_reparent(window, active_mainwin);
262 }
263
264 old_window = active_mainwin->active;
265 if (old_window != NULL((void *)0) && old_window != window)
266 textbuffer_view_set_window(WINDOW_GUI(old_window)((GUI_WINDOW_REC *) ((old_window)->gui_data))->view, NULL((void *)0));
267
268 active_mainwin->active = window;
269
270 textbuffer_view_set_window(WINDOW_GUI(window)((GUI_WINDOW_REC *) ((window)->gui_data))->view,
271 active_mainwin->screen_win);
272 if (WINDOW_GUI(window)((GUI_WINDOW_REC *) ((window)->gui_data))->view->dirty)
273 active_mainwin->dirty = TRUE(!(0));
274}
275
276static void read_settings(void)
277{
278 gui_windows_reset_settings();
279}
280
281void gui_windows_init(void)
282{
283 settings_add_bool("lookandfeel", "autostick_split_windows", TRUE)settings_add_bool_module("fe-text", "lookandfeel", "autostick_split_windows"
, (!(0)))
;
284 settings_add_int("lookandfeel", "indent", 10)settings_add_int_module("fe-text", "lookandfeel", "indent", 10
)
;
285 settings_add_bool("lookandfeel", "indent_always", FALSE)settings_add_bool_module("fe-text", "lookandfeel", "indent_always"
, (0))
;
286 settings_add_bool("lookandfeel", "scroll", TRUE)settings_add_bool_module("fe-text", "lookandfeel", "scroll", (
!(0)))
;
287
288 window_create_override = -1;
289
290 read_settings();
291 signal_add("gui window create override", (SIGNAL_FUNC) sig_window_create_override)signal_add_full("fe-text", 0, ("gui window create override"),
(SIGNAL_FUNC) ((SIGNAL_FUNC) sig_window_create_override), ((
void *)0))
;
292 signal_add("window created", (SIGNAL_FUNC) gui_window_created)signal_add_full("fe-text", 0, ("window created"), (SIGNAL_FUNC
) ((SIGNAL_FUNC) gui_window_created), ((void *)0))
;
293 signal_add("window destroyed", (SIGNAL_FUNC) gui_window_destroyed)signal_add_full("fe-text", 0, ("window destroyed"), (SIGNAL_FUNC
) ((SIGNAL_FUNC) gui_window_destroyed), ((void *)0))
;
294 signal_add_first("window changed", (SIGNAL_FUNC) signal_window_changed)signal_add_full("fe-text", -100, ("window changed"), (SIGNAL_FUNC
) ((SIGNAL_FUNC) signal_window_changed), ((void *)0))
;
295 signal_add("setup changed", (SIGNAL_FUNC) read_settings)signal_add_full("fe-text", 0, ("setup changed"), (SIGNAL_FUNC
) ((SIGNAL_FUNC) read_settings), ((void *)0))
;
296}
297
298void gui_windows_deinit(void)
299{
300 while (windows != NULL((void *)0))
301 window_destroy(windows->data);
302
303 signal_remove("gui window create override", (SIGNAL_FUNC) sig_window_create_override)signal_remove_full(("gui window create override"), (SIGNAL_FUNC
) ((SIGNAL_FUNC) sig_window_create_override), ((void *)0))
;
304 signal_remove("window created", (SIGNAL_FUNC) gui_window_created)signal_remove_full(("window created"), (SIGNAL_FUNC) ((SIGNAL_FUNC
) gui_window_created), ((void *)0))
;
305 signal_remove("window destroyed", (SIGNAL_FUNC) gui_window_destroyed)signal_remove_full(("window destroyed"), (SIGNAL_FUNC) ((SIGNAL_FUNC
) gui_window_destroyed), ((void *)0))
;
306 signal_remove("window changed", (SIGNAL_FUNC) signal_window_changed)signal_remove_full(("window changed"), (SIGNAL_FUNC) ((SIGNAL_FUNC
) signal_window_changed), ((void *)0))
;
307 signal_remove("setup changed", (SIGNAL_FUNC) read_settings)signal_remove_full(("setup changed"), (SIGNAL_FUNC) ((SIGNAL_FUNC
) read_settings), ((void *)0))
;
308}