source: popwin.c @ 68f63a2

release-1.7release-1.8release-1.9
Last change on this file since 68f63a2 was 68f63a2, checked in by David Benjamin <davidben@mit.edu>, 11 years ago
Port owl_viewwin to owl_window A number of hacks. This is just a test run of the API.
  • 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  owl_popwin *pw = user_data;
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, pw->lines-1, 0);
64    waddch(borderwin, '+');
65    wmove(borderwin, pw->lines-1, pw->cols-1);
66    waddch(borderwin, '+');
67    wmove(borderwin, 0, pw->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}
91
92int owl_popwin_get_lines(const owl_popwin *pw)
93{
94  return(pw->lines-2);
95}
96
97int owl_popwin_get_cols(const owl_popwin *pw)
98{
99  return(pw->cols-2);
100}
Note: See TracBrowser for help on using the repository browser.