This source file includes following definitions.
- frame_adjust
- frame_draw
- frame_new
- frame_callback
- frame_set_title
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 #include <config.h>
31
32 #include <stdlib.h>
33
34 #include "lib/global.h"
35 #include "lib/tty/tty.h"
36 #include "lib/tty/color.h"
37 #include "lib/skin.h"
38 #include "lib/strutil.h"
39 #include "lib/util.h"
40 #include "lib/widget.h"
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56 static void
57 frame_adjust (WFrame *f)
58 {
59 Widget *w = WIDGET (f);
60
61 w->rect = WIDGET (w->owner)->rect;
62 w->pos_flags |= WPOS_KEEP_ALL;
63 }
64
65
66
67 static void
68 frame_draw (const WFrame *f)
69 {
70 const Widget *wf = CONST_WIDGET (f);
71 const WRect *w = &wf->rect;
72 int d = f->compact ? 0 : 1;
73 const int *colors;
74
75 colors = widget_get_colors (wf);
76
77 if (mc_global.tty.shadows)
78 tty_draw_box_shadow (w->y, w->x, w->lines, w->cols, SHADOW_COLOR);
79
80 tty_setcolor (colors[FRAME_COLOR_NORMAL]);
81 tty_fill_region (w->y, w->x, w->lines, w->cols, ' ');
82 tty_draw_box (w->y + d, w->x + d, w->lines - 2 * d, w->cols - 2 * d, f->single);
83
84 if (f->title != NULL)
85 {
86
87 tty_setcolor (colors[FRAME_COLOR_TITLE]);
88 widget_gotoyx (f, d, (w->cols - str_term_width1 (f->title)) / 2);
89 tty_print_string (f->title);
90 }
91 }
92
93
94
95
96
97 WFrame *
98 frame_new (int y, int x, int lines, int cols, const char *title, gboolean single, gboolean compact)
99 {
100 WRect r = { y, x, lines, cols };
101 WFrame *f;
102 Widget *w;
103
104 f = g_new (WFrame, 1);
105 w = WIDGET (f);
106 widget_init (w, &r, frame_callback, NULL);
107
108 f->single = single;
109 f->compact = compact;
110
111 f->title = NULL;
112 frame_set_title (f, title);
113
114 return f;
115 }
116
117
118
119 cb_ret_t
120 frame_callback (Widget *w, Widget *sender, widget_msg_t msg, int parm, void *data)
121 {
122 WFrame *f = FRAME (w);
123
124 switch (msg)
125 {
126 case MSG_INIT:
127 frame_adjust (f);
128 return MSG_HANDLED;
129
130 case MSG_DRAW:
131 frame_draw (f);
132 return MSG_HANDLED;
133
134 case MSG_DESTROY:
135 g_free (f->title);
136 return MSG_HANDLED;
137
138 default:
139 return widget_default_callback (w, sender, msg, parm, data);
140 }
141 }
142
143
144
145 void
146 frame_set_title (WFrame *f, const char *title)
147 {
148 MC_PTR_FREE (f->title);
149
150
151 if (title != NULL && *title != '\0')
152 {
153 char *t;
154
155 t = g_strstrip (g_strdup (title));
156 if (*t != '\0')
157 f->title = g_strdup_printf (" %s ", t);
158 g_free (t);
159 }
160
161 widget_draw (WIDGET (f));
162 }
163
164