[7d4fbcd] | 1 | #include "owl.h" |
---|
| 2 | |
---|
[b2b0773] | 3 | int owl_popwin_init(owl_popwin *pw) |
---|
| 4 | { |
---|
[7d4fbcd] | 5 | pw->active=0; |
---|
| 6 | return(0); |
---|
| 7 | } |
---|
| 8 | |
---|
[b2b0773] | 9 | int owl_popwin_up(owl_popwin *pw) |
---|
| 10 | { |
---|
[68f63a2] | 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); |
---|
[7d4fbcd] | 14 | |
---|
[68f63a2] | 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); |
---|
[7d4fbcd] | 19 | |
---|
[68f63a2] | 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); |
---|
[fe67f1f] | 24 | |
---|
[68f63a2] | 25 | pw->active=1; |
---|
| 26 | return(0); |
---|
| 27 | } |
---|
| 28 | |
---|
| 29 | void 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; |
---|
[7d4fbcd] | 34 | |
---|
[68f63a2] | 35 | owl_window_get_position(screen, &glines, &gcols, 0, 0); |
---|
[7d4fbcd] | 36 | |
---|
[68f63a2] | 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 | |
---|
| 45 | void owl_popwin_resize_content(owl_window *w, void *user_data) |
---|
| 46 | { |
---|
[d3814ff] | 47 | int lines, cols; |
---|
[68f63a2] | 48 | owl_popwin *pw = user_data; |
---|
[d3814ff] | 49 | owl_window_get_position(w, &lines, &cols, 0, 0); |
---|
| 50 | owl_window_set_position(pw->content, lines-2, cols-2, 1, 1); |
---|
[68f63a2] | 51 | } |
---|
| 52 | |
---|
| 53 | void owl_popwin_draw_border(owl_window *w, WINDOW *borderwin, void *user_data) |
---|
| 54 | { |
---|
[1383b58] | 55 | int lines, cols; |
---|
| 56 | owl_window_get_position(w, &lines, &cols, 0, 0); |
---|
[c15bbfb] | 57 | if (owl_global_is_fancylines(&g)) { |
---|
[dffb8b8] | 58 | box(borderwin, 0, 0); |
---|
[c15bbfb] | 59 | } else { |
---|
[dffb8b8] | 60 | box(borderwin, '|', '-'); |
---|
| 61 | wmove(borderwin, 0, 0); |
---|
| 62 | waddch(borderwin, '+'); |
---|
[1383b58] | 63 | wmove(borderwin, lines-1, 0); |
---|
[dffb8b8] | 64 | waddch(borderwin, '+'); |
---|
[1383b58] | 65 | wmove(borderwin, lines-1, cols-1); |
---|
[dffb8b8] | 66 | waddch(borderwin, '+'); |
---|
[1383b58] | 67 | wmove(borderwin, 0, cols-1); |
---|
[dffb8b8] | 68 | waddch(borderwin, '+'); |
---|
[c15bbfb] | 69 | } |
---|
[7d4fbcd] | 70 | } |
---|
| 71 | |
---|
[b2b0773] | 72 | int owl_popwin_close(owl_popwin *pw) |
---|
| 73 | { |
---|
[68f63a2] | 74 | owl_window_delete(pw->border); |
---|
| 75 | pw->border = 0; |
---|
| 76 | pw->content = 0; |
---|
[7d4fbcd] | 77 | pw->active=0; |
---|
[68f63a2] | 78 | owl_window_set_resize_cb(owl_window_get_screen(), 0, 0, 0); |
---|
[7d4fbcd] | 79 | return(0); |
---|
| 80 | } |
---|
| 81 | |
---|
[9c01a5e] | 82 | int owl_popwin_is_active(const owl_popwin *pw) |
---|
[b2b0773] | 83 | { |
---|
[06cc8d9] | 84 | return pw->active; |
---|
[7d4fbcd] | 85 | } |
---|
| 86 | |
---|
[68f63a2] | 87 | owl_window *owl_popwin_get_content(const owl_popwin *pw) |
---|
[b2b0773] | 88 | { |
---|
[68f63a2] | 89 | return pw->content; |
---|
[7d4fbcd] | 90 | } |
---|