source: popwin.c @ 7a6e6c7

release-1.7release-1.8release-1.9
Last change on this file since 7a6e6c7 was 7a6e6c7, checked in by David Benjamin <davidben@mit.edu>, 11 years ago
Use signals for redraw and resize
  • Property mode set to 100644
File size: 2.6 KB
Line 
1#include "owl.h"
2
3int owl_popwin_init(owl_popwin *pw)
4{
5  pw->active=0;
6  return(0);
7}
8
9int owl_popwin_up(owl_popwin *pw)
10{
11  pw->border = owl_window_new(NULL);
12  pw->content = owl_window_new(pw->border);
13  g_signal_connect(pw->border, "redraw", G_CALLBACK(owl_popwin_draw_border), 0);
14  pw->screen_resize_id = g_signal_connect_object(owl_window_get_screen(), "resized", G_CALLBACK(owl_popwin_size_border), pw->border, 0);
15  g_signal_connect_object(pw->border, "resized", G_CALLBACK(owl_popwin_size_content), pw->content, 0);
16
17  /* bootstrap sizing */
18  owl_popwin_size_border(owl_window_get_screen(), pw->border);
19
20  owl_window_show_all(pw->border);
21
22  pw->active=1;
23  return(0);
24}
25
26void owl_popwin_size_border(owl_window *parent, void *user_data)
27{
28  int lines, cols, startline, startcol;
29  int glines, gcols;
30  owl_window *border = user_data;
31
32  owl_window_get_position(parent, &glines, &gcols, 0, 0);
33
34  lines = owl_util_min(glines,24)*3/4 + owl_util_max(glines-24,0)/2;
35  startline = (glines-lines)/2;
36  cols = owl_util_min(gcols,90)*15/16 + owl_util_max(gcols-90,0)/2;
37  startcol = (gcols-cols)/2;
38
39  owl_window_set_position(border, lines, cols, startline, startcol);
40}
41
42void owl_popwin_size_content(owl_window *parent, void *user_data)
43{
44  int lines, cols;
45  owl_window *content = user_data;
46  owl_window_get_position(parent, &lines, &cols, 0, 0);
47  owl_window_set_position(content, lines-2, cols-2, 1, 1);
48}
49
50void owl_popwin_draw_border(owl_window *w, WINDOW *borderwin, void *user_data)
51{
52  int lines, cols;
53  owl_window_get_position(w, &lines, &cols, 0, 0);
54  if (owl_global_is_fancylines(&g)) {
55    box(borderwin, 0, 0);
56  } else {
57    box(borderwin, '|', '-');
58    wmove(borderwin, 0, 0);
59    waddch(borderwin, '+');
60    wmove(borderwin, lines-1, 0);
61    waddch(borderwin, '+');
62    wmove(borderwin, lines-1, cols-1);
63    waddch(borderwin, '+');
64    wmove(borderwin, 0, cols-1);
65    waddch(borderwin, '+');
66  }
67}
68
69int owl_popwin_close(owl_popwin *pw)
70{
71  owl_window_unlink(pw->border);
72  g_object_unref(pw->border);
73  g_object_unref(pw->content);
74
75  /* See comment on g_signal_connect_object; it only prevents the closure from
76   * being invoked. The signal handler itself still gets leaked. The other
77   * signal is okay, since we delete both at the same time. */
78  if (g_signal_handler_is_connected(owl_window_get_screen(), pw->screen_resize_id))
79      g_signal_handler_disconnect(owl_window_get_screen(), pw->screen_resize_id);
80
81  pw->border = 0;
82  pw->content = 0;
83  pw->active=0;
84  return(0);
85}
86
87int owl_popwin_is_active(const owl_popwin *pw)
88{
89  return pw->active;
90}
91
92owl_window *owl_popwin_get_content(const owl_popwin *pw)
93{
94  return pw->content;
95}
Note: See TracBrowser for help on using the repository browser.