source: popwin.c @ 1383b58

release-1.7release-1.8release-1.9
Last change on this file since 1383b58 was 1383b58, checked in by David Benjamin <davidben@mit.edu>, 11 years ago
Look up lines/cols information from the window
  • Property mode set to 100644
File size: 2.4 KB
Line 
1#include "owl.h"
2
3int owl_popwin_init(owl_popwin *pw)
4{
5  pw->active=0;
6  pw->lines=0;
7  pw->cols=0;
8  return(0);
9}
10
11int owl_popwin_up(owl_popwin *pw)
12{
13  /* make them zero-size for now */
14  pw->border = owl_window_new(0, 0, 0, 0, 0);
15  pw->content = owl_window_new(pw->border, 0, 0, 0, 0);
16
17  owl_window_set_redraw_cb(pw->border, owl_popwin_draw_border, pw, 0);
18  owl_window_set_resize_cb(pw->border, owl_popwin_resize_content, pw, 0);
19  /* HACK */
20  owl_window_set_resize_cb(owl_window_get_screen(), owl_popwin_reposition, pw, 0);
21
22  /* calculate position, THEN map the windows maybe setting a resize hook
23   * should just cause it to get called? */
24  owl_popwin_reposition(owl_window_get_screen(), pw);
25  owl_window_map(pw->border, 1);
26
27  pw->active=1;
28  return(0);
29}
30
31void owl_popwin_reposition(owl_window *screen, void *user_data)
32{
33  owl_popwin *pw = user_data;
34  int lines, cols, startline, startcol;
35  int glines, gcols;
36
37  owl_window_get_position(screen, &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(pw->border, lines, cols, startline, startcol);
45}
46
47void owl_popwin_resize_content(owl_window *w, void *user_data)
48{
49  owl_popwin *pw = user_data;
50  owl_window_get_position(w, &pw->lines, &pw->cols, 0, 0);
51  owl_window_set_position(pw->content, pw->lines-2, pw->cols-2, 1, 1);
52}
53
54void owl_popwin_draw_border(owl_window *w, WINDOW *borderwin, void *user_data)
55{
56  int lines, cols;
57  owl_window_get_position(w, &lines, &cols, 0, 0);
58  if (owl_global_is_fancylines(&g)) {
59    box(borderwin, 0, 0);
60  } else {
61    box(borderwin, '|', '-');
62    wmove(borderwin, 0, 0);
63    waddch(borderwin, '+');
64    wmove(borderwin, lines-1, 0);
65    waddch(borderwin, '+');
66    wmove(borderwin, lines-1, cols-1);
67    waddch(borderwin, '+');
68    wmove(borderwin, 0, cols-1);
69    waddch(borderwin, '+');
70  }
71}
72
73int owl_popwin_close(owl_popwin *pw)
74{
75  owl_window_delete(pw->border);
76  pw->border = 0;
77  pw->content = 0;
78  pw->active=0;
79  owl_window_set_resize_cb(owl_window_get_screen(), 0, 0, 0);
80  return(0);
81}
82
83int owl_popwin_is_active(const owl_popwin *pw)
84{
85  return pw->active;
86}
87
88owl_window *owl_popwin_get_content(const owl_popwin *pw)
89{
90  return pw->content;
91}
92
93int owl_popwin_get_lines(const owl_popwin *pw)
94{
95  return(pw->lines-2);
96}
97
98int owl_popwin_get_cols(const owl_popwin *pw)
99{
100  return(pw->cols-2);
101}
Note: See TracBrowser for help on using the repository browser.