This source file includes following definitions.
- hline_adjust_cols
- hline_callback
- hline_new
- hline_set_text
- hline_set_textv
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 #include <config.h>
36
37 #include <stdarg.h>
38 #include <stdlib.h>
39
40 #include "lib/global.h"
41 #include "lib/tty/tty.h"
42 #include "lib/tty/color.h"
43 #include "lib/skin.h"
44 #include "lib/strutil.h"
45 #include "lib/widget.h"
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61 static void
62 hline_adjust_cols (WHLine *l)
63 {
64 if (l->auto_adjust_cols)
65 {
66 Widget *wl = WIDGET (l);
67 const Widget *o = CONST_WIDGET (wl->owner);
68 WRect *w = &wl->rect;
69 const WRect *wo = &o->rect;
70
71 if (CONST_DIALOG (o)->compact)
72 {
73 w->x = wo->x;
74 w->cols = wo->cols;
75 }
76 else
77 {
78 w->x = wo->x + 1;
79 w->cols = wo->cols - 2;
80 }
81 }
82 }
83
84
85
86 static cb_ret_t
87 hline_callback (Widget *w, Widget *sender, widget_msg_t msg, int parm, void *data)
88 {
89 WHLine *l = HLINE (w);
90
91 switch (msg)
92 {
93 case MSG_INIT:
94 hline_adjust_cols (l);
95 return MSG_HANDLED;
96
97 case MSG_RESIZE:
98 hline_adjust_cols (l);
99 w->rect.y = RECT (data)->y;
100 return MSG_HANDLED;
101
102 case MSG_DRAW:
103 if (l->transparent)
104 tty_setcolor (DEFAULT_COLOR);
105 else
106 {
107 const int *colors;
108
109 colors = widget_get_colors (w);
110 tty_setcolor (colors[DLG_COLOR_NORMAL]);
111 }
112
113 tty_draw_hline (w->rect.y, w->rect.x + 1, ACS_HLINE, w->rect.cols - 2);
114
115 if (l->auto_adjust_cols)
116 {
117 widget_gotoyx (w, 0, 0);
118 tty_print_alt_char (ACS_LTEE, FALSE);
119 widget_gotoyx (w, 0, w->rect.cols - 1);
120 tty_print_alt_char (ACS_RTEE, FALSE);
121 }
122
123 if (l->text != NULL)
124 {
125 int text_width;
126
127 text_width = str_term_width1 (l->text);
128 widget_gotoyx (w, 0, (w->rect.cols - text_width) / 2);
129 tty_print_string (l->text);
130 }
131 return MSG_HANDLED;
132
133 case MSG_DESTROY:
134 g_free (l->text);
135 return MSG_HANDLED;
136
137 default:
138 return widget_default_callback (w, sender, msg, parm, data);
139 }
140 }
141
142
143
144
145
146 WHLine *
147 hline_new (int y, int x, int width)
148 {
149 WRect r = { y, x, 1, width };
150 WHLine *l;
151 Widget *w;
152
153 l = g_new (WHLine, 1);
154 w = WIDGET (l);
155 r.cols = width < 0 ? 1 : width;
156 widget_init (w, &r, hline_callback, NULL);
157 l->text = NULL;
158 l->auto_adjust_cols = (width < 0);
159 l->transparent = FALSE;
160
161 return l;
162 }
163
164
165
166 void
167 hline_set_text (WHLine *l, const char *text)
168 {
169 g_free (l->text);
170
171 if (text == NULL || *text == '\0')
172 l->text = NULL;
173 else
174 l->text = g_strdup (text);
175
176 widget_draw (WIDGET (l));
177 }
178
179
180
181 void
182 hline_set_textv (WHLine *l, const char *format, ...)
183 {
184 va_list args;
185 char buf[BUF_1K];
186
187 va_start (args, format);
188 g_vsnprintf (buf, sizeof (buf), format, args);
189 va_end (args);
190
191 hline_set_text (l, buf);
192 }
193
194