source: popwin.c @ 3e0147f

release-1.10release-1.7release-1.8release-1.9
Last change on this file since 3e0147f was 05ca0d8, checked in by David Benjamin <davidben@mit.edu>, 15 years ago
Implement our own owl_signal_connect_object This is actually more code, but that's because of comments. It'll be MUCH less error-prone.
  • Property mode set to 100644
File size: 2.2 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  owl_signal_connect_object(owl_window_get_screen(), "resized", G_CALLBACK(owl_popwin_size_border), pw->border, 0);
15  owl_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  pw->border = 0;
76  pw->content = 0;
77  pw->active=0;
78  return(0);
79}
80
81int owl_popwin_is_active(const owl_popwin *pw)
82{
83  return pw->active;
84}
85
86owl_window *owl_popwin_get_content(const owl_popwin *pw)
87{
88  return pw->content;
89}
Note: See TracBrowser for help on using the repository browser.