source: popwin.c @ 6425d43

release-1.10release-1.7release-1.8release-1.9
Last change on this file since 6425d43 was 6425d43, checked in by David Benjamin <davidben@mit.edu>, 14 years ago
Don't cause confusion if owl_popwin_up on an active popwin Likewise, inactive popwins should not be closeable. The function returns int, so we may as well return an error, but no one checks that.
  • Property mode set to 100644
File size: 2.3 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  g_signal_connect(pw->border, "redraw", G_CALLBACK(owl_popwin_draw_border), 0);
16  owl_signal_connect_object(owl_window_get_screen(), "resized", G_CALLBACK(owl_popwin_size_border), pw->border, 0);
17  owl_signal_connect_object(pw->border, "resized", G_CALLBACK(owl_popwin_size_content), pw->content, 0);
18
19  /* bootstrap sizing */
20  owl_popwin_size_border(owl_window_get_screen(), pw->border);
21
22  owl_window_show_all(pw->border);
23
24  pw->active=1;
25  return(0);
26}
27
28void owl_popwin_size_border(owl_window *parent, void *user_data)
29{
30  int lines, cols, startline, startcol;
31  int glines, gcols;
32  owl_window *border = user_data;
33
34  owl_window_get_position(parent, &glines, &gcols, 0, 0);
35
36  lines = owl_util_min(glines,24)*3/4 + owl_util_max(glines-24,0)/2;
37  startline = (glines-lines)/2;
38  cols = owl_util_min(gcols,90)*15/16 + owl_util_max(gcols-90,0)/2;
39  startcol = (gcols-cols)/2;
40
41  owl_window_set_position(border, lines, cols, startline, startcol);
42}
43
44void owl_popwin_size_content(owl_window *parent, void *user_data)
45{
46  int lines, cols;
47  owl_window *content = user_data;
48  owl_window_get_position(parent, &lines, &cols, 0, 0);
49  owl_window_set_position(content, lines-2, cols-2, 1, 1);
50}
51
52void owl_popwin_draw_border(owl_window *w, WINDOW *borderwin, void *user_data)
53{
54  int lines, cols;
55  owl_window_get_position(w, &lines, &cols, 0, 0);
56  if (owl_global_is_fancylines(&g)) {
57    box(borderwin, 0, 0);
58  } else {
59    box(borderwin, '|', '-');
60    wmove(borderwin, 0, 0);
61    waddch(borderwin, '+');
62    wmove(borderwin, lines-1, 0);
63    waddch(borderwin, '+');
64    wmove(borderwin, lines-1, cols-1);
65    waddch(borderwin, '+');
66    wmove(borderwin, 0, cols-1);
67    waddch(borderwin, '+');
68  }
69}
70
71int owl_popwin_close(owl_popwin *pw)
72{
73  if (!pw->active)
74    return 1;
75  owl_window_unlink(pw->border);
76  g_object_unref(pw->border);
77  g_object_unref(pw->content);
78
79  pw->border = 0;
80  pw->content = 0;
81  pw->active=0;
82  return(0);
83}
84
85int owl_popwin_is_active(const owl_popwin *pw)
86{
87  return pw->active;
88}
89
90owl_window *owl_popwin_get_content(const owl_popwin *pw)
91{
92  return pw->content;
93}
Note: See TracBrowser for help on using the repository browser.