source: popwin.c @ 9b9efa2b

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