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>, 12 years ago
Look up lines/cols information from the window
  • Property mode set to 100644
File size: 2.4 KB
RevLine 
[7d4fbcd]1#include "owl.h"
2
[b2b0773]3int owl_popwin_init(owl_popwin *pw)
4{
[7d4fbcd]5  pw->active=0;
6  pw->lines=0;
7  pw->cols=0;
8  return(0);
9}
10
[b2b0773]11int owl_popwin_up(owl_popwin *pw)
12{
[68f63a2]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);
[7d4fbcd]16
[68f63a2]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);
[7d4fbcd]21
[68f63a2]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);
[fe67f1f]26
[68f63a2]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;
[7d4fbcd]36
[68f63a2]37  owl_window_get_position(screen, &glines, &gcols, 0, 0);
[7d4fbcd]38
[68f63a2]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{
[1383b58]56  int lines, cols;
57  owl_window_get_position(w, &lines, &cols, 0, 0);
[c15bbfb]58  if (owl_global_is_fancylines(&g)) {
[dffb8b8]59    box(borderwin, 0, 0);
[c15bbfb]60  } else {
[dffb8b8]61    box(borderwin, '|', '-');
62    wmove(borderwin, 0, 0);
63    waddch(borderwin, '+');
[1383b58]64    wmove(borderwin, lines-1, 0);
[dffb8b8]65    waddch(borderwin, '+');
[1383b58]66    wmove(borderwin, lines-1, cols-1);
[dffb8b8]67    waddch(borderwin, '+');
[1383b58]68    wmove(borderwin, 0, cols-1);
[dffb8b8]69    waddch(borderwin, '+');
[c15bbfb]70  }
[7d4fbcd]71}
72
[b2b0773]73int owl_popwin_close(owl_popwin *pw)
74{
[68f63a2]75  owl_window_delete(pw->border);
76  pw->border = 0;
77  pw->content = 0;
[7d4fbcd]78  pw->active=0;
[68f63a2]79  owl_window_set_resize_cb(owl_window_get_screen(), 0, 0, 0);
[7d4fbcd]80  return(0);
81}
82
[9c01a5e]83int owl_popwin_is_active(const owl_popwin *pw)
[b2b0773]84{
[06cc8d9]85  return pw->active;
[7d4fbcd]86}
87
[68f63a2]88owl_window *owl_popwin_get_content(const owl_popwin *pw)
[b2b0773]89{
[68f63a2]90  return pw->content;
[7d4fbcd]91}
92
[9c01a5e]93int owl_popwin_get_lines(const owl_popwin *pw)
[b2b0773]94{
[7d4fbcd]95  return(pw->lines-2);
96}
97
[9c01a5e]98int owl_popwin_get_cols(const owl_popwin *pw)
[b2b0773]99{
[7d4fbcd]100  return(pw->cols-2);
101}
Note: See TracBrowser for help on using the repository browser.