source: popwin.c @ b3b1b05

release-1.7release-1.8release-1.9
Last change on this file since b3b1b05 was b3b1b05, checked in by David Benjamin <davidben@mit.edu>, 11 years ago
To be thorough, track all signal ids in the popwin This isn't actually necessary here, but it's more correct. The awkwardness suggests that we want the widgets to be GObjects so that owl_signal_connect_object may do this automatically.
  • Property mode set to 100644
File size: 2.5 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  if (pw->active)
12    return 1;
13  pw->border = owl_window_new(NULL);
14  pw->content = owl_window_new(pw->border);
15  /* To be thorough, we ensure each signal is disconnected when we close. */
16  pw->sig_redraw_id =
17    g_signal_connect(pw->border, "redraw", G_CALLBACK(owl_popwin_draw_border), 0);
18  pw->sig_resize_id =
19    g_signal_connect(pw->border, "resized", G_CALLBACK(owl_popwin_size_content), pw);
20  owl_signal_connect_object(owl_window_get_screen(), "resized", G_CALLBACK(owl_popwin_size_border), pw->border, 0);
21
22  /* bootstrap sizing */
23  owl_popwin_size_border(owl_window_get_screen(), pw->border);
24
25  owl_window_show_all(pw->border);
26
27  pw->active=1;
28  return(0);
29}
30
31void owl_popwin_size_border(owl_window *parent, void *user_data)
32{
33  int lines, cols, startline, startcol;
34  int glines, gcols;
35  owl_window *border = user_data;
36
37  owl_window_get_position(parent, &glines, &gcols, 0, 0);
38
39  lines = owl_util_min(glines,24)*3/4 + owl_util_max(glines-24,0)/2;
40  startline = (glines-lines)/2;
41  cols = owl_util_min(gcols,90)*15/16 + owl_util_max(gcols-90,0)/2;
42  startcol = (gcols-cols)/2;
43
44  owl_window_set_position(border, lines, cols, startline, startcol);
45}
46
47void owl_popwin_size_content(owl_window *parent, void *user_data)
48{
49  int lines, cols;
50  owl_popwin *pw = user_data;
51  owl_window_get_position(parent, &lines, &cols, 0, 0);
52  owl_window_set_position(pw->content, lines-2, cols-2, 1, 1);
53}
54
55void owl_popwin_draw_border(owl_window *w, WINDOW *borderwin, void *user_data)
56{
57  int lines, cols;
58  owl_window_get_position(w, &lines, &cols, 0, 0);
59  if (owl_global_is_fancylines(&g)) {
60    box(borderwin, 0, 0);
61  } else {
62    box(borderwin, '|', '-');
63    wmove(borderwin, 0, 0);
64    waddch(borderwin, '+');
65    wmove(borderwin, lines-1, 0);
66    waddch(borderwin, '+');
67    wmove(borderwin, lines-1, cols-1);
68    waddch(borderwin, '+');
69    wmove(borderwin, 0, cols-1);
70    waddch(borderwin, '+');
71  }
72}
73
74int owl_popwin_close(owl_popwin *pw)
75{
76  if (!pw->active)
77    return 1;
78  g_signal_handler_disconnect(pw->border, pw->sig_resize_id);
79  g_signal_handler_disconnect(pw->border, pw->sig_redraw_id);
80  owl_window_unlink(pw->border);
81  g_object_unref(pw->border);
82  g_object_unref(pw->content);
83
84  pw->border = 0;
85  pw->content = 0;
86  pw->active=0;
87  return(0);
88}
89
90int owl_popwin_is_active(const owl_popwin *pw)
91{
92  return pw->active;
93}
94
95owl_window *owl_popwin_get_content(const owl_popwin *pw)
96{
97  return pw->content;
98}
Note: See TracBrowser for help on using the repository browser.