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 static void
60 hline_adjust_cols (WHLine * l)
61 {
62 if (l->auto_adjust_cols)
63 {
64 Widget *w = WIDGET (l);
65 Widget *wo = WIDGET (w->owner);
66
67 if (DIALOG (wo)->compact)
68 {
69 w->x = wo->x;
70 w->cols = wo->cols;
71 }
72 else
73 {
74 w->x = wo->x + 1;
75 w->cols = wo->cols - 2;
76 }
77 }
78 }
79
80
81
82 static cb_ret_t
83 hline_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data)
84 {
85 WHLine *l = HLINE (w);
86
87 switch (msg)
88 {
89 case MSG_INIT:
90 hline_adjust_cols (l);
91 return MSG_HANDLED;
92
93 case MSG_RESIZE:
94 hline_adjust_cols (l);
95 w->y = RECT (data)->y;
96 return MSG_HANDLED;
97
98 case MSG_DRAW:
99 if (l->transparent)
100 tty_setcolor (DEFAULT_COLOR);
101 else
102 {
103 const int *colors;
104
105 colors = widget_get_colors (w);
106 tty_setcolor (colors[DLG_COLOR_NORMAL]);
107 }
108
109 tty_draw_hline (w->y, w->x + 1, ACS_HLINE, w->cols - 2);
110
111 if (l->auto_adjust_cols)
112 {
113 widget_gotoyx (w, 0, 0);
114 tty_print_alt_char (ACS_LTEE, FALSE);
115 widget_gotoyx (w, 0, w->cols - 1);
116 tty_print_alt_char (ACS_RTEE, FALSE);
117 }
118
119 if (l->text != NULL)
120 {
121 int text_width;
122
123 text_width = str_term_width1 (l->text);
124 widget_gotoyx (w, 0, (w->cols - text_width) / 2);
125 tty_print_string (l->text);
126 }
127 return MSG_HANDLED;
128
129 case MSG_DESTROY:
130 g_free (l->text);
131 return MSG_HANDLED;
132
133 default:
134 return widget_default_callback (w, sender, msg, parm, data);
135 }
136 }
137
138
139
140
141
142 WHLine *
143 hline_new (int y, int x, int width)
144 {
145 WHLine *l;
146 Widget *w;
147 int lines = 1;
148
149 l = g_new (WHLine, 1);
150 w = WIDGET (l);
151 widget_init (w, y, x, lines, width < 0 ? 1 : width, hline_callback, NULL);
152 l->text = NULL;
153 l->auto_adjust_cols = (width < 0);
154 l->transparent = FALSE;
155
156 return l;
157 }
158
159
160
161 void
162 hline_set_text (WHLine * l, const char *text)
163 {
164 g_free (l->text);
165
166 if (text == NULL || *text == '\0')
167 l->text = NULL;
168 else
169 l->text = g_strdup (text);
170
171 widget_draw (WIDGET (l));
172 }
173
174
175
176 void
177 hline_set_textv (WHLine * l, const char *format, ...)
178 {
179 va_list args;
180 char buf[BUF_1K];
181
182 va_start (args, format);
183 g_vsnprintf (buf, sizeof (buf), format, args);
184 va_end (args);
185
186 hline_set_text (l, buf);
187 }
188
189