source: popwin.c @ 78b9503

release-1.8release-1.9
Last change on this file since 78b9503 was 6829afc, checked in by David Benjamin <davidben@mit.edu>, 10 years ago
Define CALLER_OWN macro Replace our exising uses of G_GNUC_WARN_UNUSED_RESULT with it. The old macro is just way too long. This also more clearly specifies the intent.
  • Property mode set to 100644
File size: 2.7 KB
Line 
1#include "owl.h"
2
3CALLER_OWN owl_popwin *owl_popwin_new(void)
4{
5  owl_popwin *pw = g_new0(owl_popwin, 1);
6
7  pw->border = owl_window_new(NULL);
8  pw->content = owl_window_new(pw->border);
9  /* To be thorough, we ensure each signal is disconnected when we close. */
10  pw->sig_redraw_id =
11    g_signal_connect(pw->border, "redraw", G_CALLBACK(owl_popwin_draw_border), 0);
12  pw->sig_resize_id =
13    g_signal_connect(pw->border, "resized", G_CALLBACK(owl_popwin_size_content), pw);
14  owl_signal_connect_object(owl_window_get_screen(), "resized", G_CALLBACK(owl_popwin_size_border), pw->border, 0);
15
16  /* bootstrap sizing */
17  owl_popwin_size_border(owl_window_get_screen(), pw->border);
18
19  owl_window_show(pw->content);
20
21  return pw;
22}
23
24int owl_popwin_up(owl_popwin *pw)
25{
26  if (owl_window_is_shown(pw->border))
27    return 1;
28  owl_window_show(pw->border);
29  return 0;
30}
31
32void owl_popwin_size_border(owl_window *parent, void *user_data)
33{
34  int lines, cols, startline, startcol;
35  int glines, gcols;
36  owl_window *border = user_data;
37
38  owl_window_get_position(parent, &glines, &gcols, 0, 0);
39
40  lines = MIN(glines, 24) * 3/4 + MAX(glines - 24, 0) / 2;
41  startline = (glines-lines)/2;
42  cols = MIN(gcols, 90) * 15 / 16 + MAX(gcols - 90, 0) / 2;
43  startcol = (gcols-cols)/2;
44
45  owl_window_set_position(border, lines, cols, startline, startcol);
46}
47
48void owl_popwin_size_content(owl_window *parent, void *user_data)
49{
50  int lines, cols;
51  owl_popwin *pw = user_data;
52  owl_window_get_position(parent, &lines, &cols, 0, 0);
53  owl_window_set_position(pw->content, lines-2, cols-2, 1, 1);
54}
55
56void owl_popwin_draw_border(owl_window *w, WINDOW *borderwin, void *user_data)
57{
58  int lines, cols;
59  owl_window_get_position(w, &lines, &cols, 0, 0);
60  if (owl_global_is_fancylines(&g)) {
61    box(borderwin, 0, 0);
62  } else {
63    box(borderwin, '|', '-');
64    wmove(borderwin, 0, 0);
65    waddch(borderwin, '+');
66    wmove(borderwin, lines-1, 0);
67    waddch(borderwin, '+');
68    wmove(borderwin, lines-1, cols-1);
69    waddch(borderwin, '+');
70    wmove(borderwin, 0, cols-1);
71    waddch(borderwin, '+');
72  }
73}
74
75int owl_popwin_close(owl_popwin *pw)
76{
77  if (!owl_window_is_shown(pw->border))
78    return 1;
79  owl_window_hide(pw->border);
80  return 0;
81}
82
83void owl_popwin_delete(owl_popwin *pw)
84{
85  owl_popwin_close(pw);
86
87  /* Remove everything that references us. */
88  g_signal_handler_disconnect(pw->border, pw->sig_resize_id);
89  g_signal_handler_disconnect(pw->border, pw->sig_redraw_id);
90  owl_window_unlink(pw->border);
91  g_object_unref(pw->border);
92  g_object_unref(pw->content);
93
94  g_free(pw);
95}
96
97int owl_popwin_is_active(const owl_popwin *pw)
98{
99  return owl_window_is_shown(pw->border);
100}
101
102owl_window *owl_popwin_get_content(const owl_popwin *pw)
103{
104  return pw->content;
105}
Note: See TracBrowser for help on using the repository browser.