1 | /* Copyright (c) 2002,2003,2004,2009 James M. Kretchmar |
---|
2 | * |
---|
3 | * This file is part of Owl. |
---|
4 | * |
---|
5 | * Owl 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 3 of the License, or |
---|
8 | * (at your option) any later version. |
---|
9 | * |
---|
10 | * Owl 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 Owl. If not, see <http://www.gnu.org/licenses/>. |
---|
17 | * |
---|
18 | * --------------------------------------------------------------- |
---|
19 | * |
---|
20 | * As of Owl version 2.1.12 there are patches contributed by |
---|
21 | * developers of the the branched BarnOwl project, Copyright (c) |
---|
22 | * 2006-2008 The BarnOwl Developers. All rights reserved. |
---|
23 | */ |
---|
24 | |
---|
25 | #include "owl.h" |
---|
26 | |
---|
27 | static const char fileIdent[] = "$Id$"; |
---|
28 | |
---|
29 | int owl_popwin_init(owl_popwin *pw) |
---|
30 | { |
---|
31 | pw->active=0; |
---|
32 | pw->needsfirstrefresh=0; |
---|
33 | pw->lines=0; |
---|
34 | pw->cols=0; |
---|
35 | return(0); |
---|
36 | } |
---|
37 | |
---|
38 | int owl_popwin_up(owl_popwin *pw) |
---|
39 | { |
---|
40 | int glines, gcols, startcol, startline; |
---|
41 | |
---|
42 | /* calculate the size of the popwin */ |
---|
43 | glines=owl_global_get_lines(&g); |
---|
44 | gcols=owl_global_get_cols(&g); |
---|
45 | |
---|
46 | pw->lines = owl_util_min(glines,24)*3/4 + owl_util_max(glines-24,0)/2; |
---|
47 | startline = (glines-pw->lines)/2; |
---|
48 | |
---|
49 | pw->cols = owl_util_min(gcols,90)*15/16 + owl_util_max(gcols-90,0)/2; |
---|
50 | startcol = (gcols-pw->cols)/2; |
---|
51 | |
---|
52 | pw->borderwin=newwin(pw->lines, pw->cols, startline, startcol); |
---|
53 | pw->popwin=newwin(pw->lines-2, pw->cols-2, startline+1, startcol+1); |
---|
54 | pw->needsfirstrefresh=1; |
---|
55 | |
---|
56 | meta(pw->popwin,TRUE); |
---|
57 | nodelay(pw->popwin, 1); |
---|
58 | keypad(pw->popwin, TRUE); |
---|
59 | |
---|
60 | werase(pw->popwin); |
---|
61 | werase(pw->borderwin); |
---|
62 | if (owl_global_is_fancylines(&g)) { |
---|
63 | box(pw->borderwin, 0, 0); |
---|
64 | } else { |
---|
65 | box(pw->borderwin, '|', '-'); |
---|
66 | wmove(pw->borderwin, 0, 0); |
---|
67 | waddch(pw->borderwin, '+'); |
---|
68 | wmove(pw->borderwin, pw->lines-1, 0); |
---|
69 | waddch(pw->borderwin, '+'); |
---|
70 | wmove(pw->borderwin, pw->lines-1, pw->cols-1); |
---|
71 | waddch(pw->borderwin, '+'); |
---|
72 | wmove(pw->borderwin, 0, pw->cols-1); |
---|
73 | waddch(pw->borderwin, '+'); |
---|
74 | } |
---|
75 | |
---|
76 | wnoutrefresh(pw->popwin); |
---|
77 | wnoutrefresh(pw->borderwin); |
---|
78 | owl_global_set_needrefresh(&g); |
---|
79 | pw->active=1; |
---|
80 | return(0); |
---|
81 | } |
---|
82 | |
---|
83 | int owl_popwin_display_text(owl_popwin *pw, char *text) |
---|
84 | { |
---|
85 | waddstr(pw->popwin, text); |
---|
86 | wnoutrefresh(pw->popwin); |
---|
87 | touchwin(pw->borderwin); |
---|
88 | wnoutrefresh(pw->borderwin); |
---|
89 | owl_global_set_needrefresh(&g); |
---|
90 | return(0); |
---|
91 | } |
---|
92 | |
---|
93 | int owl_popwin_close(owl_popwin *pw) |
---|
94 | { |
---|
95 | delwin(pw->popwin); |
---|
96 | delwin(pw->borderwin); |
---|
97 | pw->active=0; |
---|
98 | owl_global_set_needrefresh(&g); |
---|
99 | owl_mainwin_redisplay(owl_global_get_mainwin(&g)); |
---|
100 | owl_function_full_redisplay(&g); |
---|
101 | return(0); |
---|
102 | } |
---|
103 | |
---|
104 | int owl_popwin_is_active(owl_popwin *pw) |
---|
105 | { |
---|
106 | if (pw->active==1) return(1); |
---|
107 | return(0); |
---|
108 | } |
---|
109 | |
---|
110 | /* this will refresh the border as well as the text area */ |
---|
111 | int owl_popwin_refresh(owl_popwin *pw) |
---|
112 | { |
---|
113 | touchwin(pw->borderwin); |
---|
114 | touchwin(pw->popwin); |
---|
115 | |
---|
116 | wnoutrefresh(pw->borderwin); |
---|
117 | wnoutrefresh(pw->popwin); |
---|
118 | owl_global_set_needrefresh(&g); |
---|
119 | return(0); |
---|
120 | } |
---|
121 | |
---|
122 | void owl_popwin_set_handler(owl_popwin *pw, void (*func)(int ch)) |
---|
123 | { |
---|
124 | pw->handler=func; |
---|
125 | } |
---|
126 | |
---|
127 | void owl_popwin_unset_handler(owl_popwin *pw) |
---|
128 | { |
---|
129 | pw->handler=NULL; |
---|
130 | } |
---|
131 | |
---|
132 | WINDOW *owl_popwin_get_curswin(owl_popwin *pw) |
---|
133 | { |
---|
134 | return(pw->popwin); |
---|
135 | } |
---|
136 | |
---|
137 | int owl_popwin_get_lines(owl_popwin *pw) |
---|
138 | { |
---|
139 | return(pw->lines-2); |
---|
140 | } |
---|
141 | |
---|
142 | int owl_popwin_get_cols(owl_popwin *pw) |
---|
143 | { |
---|
144 | return(pw->cols-2); |
---|
145 | } |
---|
146 | |
---|
147 | int owl_popwin_needs_first_refresh(owl_popwin *pw) |
---|
148 | { |
---|
149 | if (pw->needsfirstrefresh) return(1); |
---|
150 | return(0); |
---|
151 | } |
---|
152 | |
---|
153 | void owl_popwin_no_needs_first_refresh(owl_popwin *pw) |
---|
154 | { |
---|
155 | pw->needsfirstrefresh=0; |
---|
156 | } |
---|