source: popwin.c @ d3814ff

release-1.10release-1.7release-1.8release-1.9
Last change on this file since d3814ff was d3814ff, checked in by David Benjamin <davidben@mit.edu>, 14 years ago
Don't remember lines/cols in popwin The window already retains this information
  • 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  /* make them zero-size for now */
12  pw->border = owl_window_new(0, 0, 0, 0, 0);
13  pw->content = owl_window_new(pw->border, 0, 0, 0, 0);
14
15  owl_window_set_redraw_cb(pw->border, owl_popwin_draw_border, pw, 0);
16  owl_window_set_resize_cb(pw->border, owl_popwin_resize_content, pw, 0);
17  /* HACK */
18  owl_window_set_resize_cb(owl_window_get_screen(), owl_popwin_reposition, pw, 0);
19
20  /* calculate position, THEN map the windows maybe setting a resize hook
21   * should just cause it to get called? */
22  owl_popwin_reposition(owl_window_get_screen(), pw);
23  owl_window_map(pw->border, 1);
24
25  pw->active=1;
26  return(0);
27}
28
29void owl_popwin_reposition(owl_window *screen, void *user_data)
30{
31  owl_popwin *pw = user_data;
32  int lines, cols, startline, startcol;
33  int glines, gcols;
34
35  owl_window_get_position(screen, &glines, &gcols, 0, 0);
36
37  lines = owl_util_min(glines,24)*3/4 + owl_util_max(glines-24,0)/2;
38  startline = (glines-lines)/2;
39  cols = owl_util_min(gcols,90)*15/16 + owl_util_max(gcols-90,0)/2;
40  startcol = (gcols-cols)/2;
41
42  owl_window_set_position(pw->border, lines, cols, startline, startcol);
43}
44
45void owl_popwin_resize_content(owl_window *w, void *user_data)
46{
47  int lines, cols;
48  owl_popwin *pw = user_data;
49  owl_window_get_position(w, &lines, &cols, 0, 0);
50  owl_window_set_position(pw->content, lines-2, cols-2, 1, 1);
51}
52
53void owl_popwin_draw_border(owl_window *w, WINDOW *borderwin, void *user_data)
54{
55  int lines, cols;
56  owl_window_get_position(w, &lines, &cols, 0, 0);
57  if (owl_global_is_fancylines(&g)) {
58    box(borderwin, 0, 0);
59  } else {
60    box(borderwin, '|', '-');
61    wmove(borderwin, 0, 0);
62    waddch(borderwin, '+');
63    wmove(borderwin, lines-1, 0);
64    waddch(borderwin, '+');
65    wmove(borderwin, lines-1, cols-1);
66    waddch(borderwin, '+');
67    wmove(borderwin, 0, cols-1);
68    waddch(borderwin, '+');
69  }
70}
71
72int owl_popwin_close(owl_popwin *pw)
73{
74  owl_window_delete(pw->border);
75  pw->border = 0;
76  pw->content = 0;
77  pw->active=0;
78  owl_window_set_resize_cb(owl_window_get_screen(), 0, 0, 0);
79  return(0);
80}
81
82int owl_popwin_is_active(const owl_popwin *pw)
83{
84  return pw->active;
85}
86
87owl_window *owl_popwin_get_content(const owl_popwin *pw)
88{
89  return pw->content;
90}
Note: See TracBrowser for help on using the repository browser.