source: popwin.c @ 053f751

release-1.7release-1.8release-1.9
Last change on this file since 053f751 was 053f751, checked in by David Benjamin <davidben@mit.edu>, 11 years ago
For prototyping, use a GObject-backed owl_window It gives us many signals and refcounting conveniences. This first iteration doesn't use any of these features but gets it barely working quickly.
  • Property mode set to 100644
File size: 2.1 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  owl_window_set_redraw_cb(pw->border, owl_popwin_draw_border, pw, 0);
14  owl_window_set_size_cb(pw->border, owl_popwin_size_border, 0, 0);
15  owl_window_set_size_cb(pw->content, owl_popwin_size_content, 0, 0);
16  owl_window_show_all(pw->border);
17
18  pw->active=1;
19  return(0);
20}
21
22void owl_popwin_size_border(owl_window *border, void *user_data)
23{
24  int lines, cols, startline, startcol;
25  int glines, gcols;
26  owl_window *parent = owl_window_get_parent(border);
27
28  owl_window_get_position(parent, &glines, &gcols, 0, 0);
29
30  lines = owl_util_min(glines,24)*3/4 + owl_util_max(glines-24,0)/2;
31  startline = (glines-lines)/2;
32  cols = owl_util_min(gcols,90)*15/16 + owl_util_max(gcols-90,0)/2;
33  startcol = (gcols-cols)/2;
34
35  owl_window_set_position(border, lines, cols, startline, startcol);
36}
37
38void owl_popwin_size_content(owl_window *content, void *user_data)
39{
40  int lines, cols;
41  owl_window *parent = owl_window_get_parent(content);
42  owl_window_get_position(parent, &lines, &cols, 0, 0);
43  owl_window_set_position(content, lines-2, cols-2, 1, 1);
44}
45
46void owl_popwin_draw_border(owl_window *w, WINDOW *borderwin, void *user_data)
47{
48  int lines, cols;
49  owl_window_get_position(w, &lines, &cols, 0, 0);
50  if (owl_global_is_fancylines(&g)) {
51    box(borderwin, 0, 0);
52  } else {
53    box(borderwin, '|', '-');
54    wmove(borderwin, 0, 0);
55    waddch(borderwin, '+');
56    wmove(borderwin, lines-1, 0);
57    waddch(borderwin, '+');
58    wmove(borderwin, lines-1, cols-1);
59    waddch(borderwin, '+');
60    wmove(borderwin, 0, cols-1);
61    waddch(borderwin, '+');
62  }
63}
64
65int owl_popwin_close(owl_popwin *pw)
66{
67  owl_window_unlink(pw->border);
68  g_object_unref(pw->border);
69  g_object_unref(pw->content);
70  pw->border = 0;
71  pw->content = 0;
72  pw->active=0;
73  return(0);
74}
75
76int owl_popwin_is_active(const owl_popwin *pw)
77{
78  return pw->active;
79}
80
81owl_window *owl_popwin_get_content(const owl_popwin *pw)
82{
83  return pw->content;
84}
Note: See TracBrowser for help on using the repository browser.