[7d4fbcd] | 1 | #include "owl.h" |
---|
| 2 | |
---|
[1aee7d9] | 3 | static const char fileIdent[] = "$Id$"; |
---|
| 4 | |
---|
[b2b0773] | 5 | int owl_popwin_init(owl_popwin *pw) |
---|
| 6 | { |
---|
[7d4fbcd] | 7 | pw->active=0; |
---|
| 8 | pw->needsfirstrefresh=0; |
---|
| 9 | pw->lines=0; |
---|
| 10 | pw->cols=0; |
---|
| 11 | return(0); |
---|
| 12 | } |
---|
| 13 | |
---|
[b2b0773] | 14 | int owl_popwin_up(owl_popwin *pw) |
---|
| 15 | { |
---|
[7d4fbcd] | 16 | int glines, gcols, startcol, startline; |
---|
| 17 | |
---|
| 18 | /* calculate the size of the popwin */ |
---|
| 19 | glines=owl_global_get_lines(&g); |
---|
| 20 | gcols=owl_global_get_cols(&g); |
---|
| 21 | if (glines > 24) { |
---|
| 22 | pw->lines=glines/2; |
---|
| 23 | startline=glines/4; |
---|
| 24 | } else { |
---|
| 25 | pw->lines=(glines*3)/4; |
---|
| 26 | startline=glines/8; |
---|
| 27 | } |
---|
| 28 | |
---|
| 29 | pw->cols=(gcols*15)/16; |
---|
| 30 | startcol=gcols/32; |
---|
| 31 | if (pw->cols > 100) { |
---|
| 32 | pw->cols=100; |
---|
| 33 | startcol=(gcols-100)/2; |
---|
| 34 | } |
---|
| 35 | |
---|
| 36 | pw->borderwin=newwin(pw->lines, pw->cols, startline, startcol); |
---|
| 37 | pw->popwin=newwin(pw->lines-2, pw->cols-2, startline+1, startcol+1); |
---|
| 38 | pw->needsfirstrefresh=1; |
---|
| 39 | |
---|
| 40 | meta(pw->popwin,TRUE); |
---|
| 41 | nodelay(pw->popwin, 1); |
---|
| 42 | keypad(pw->popwin, TRUE); |
---|
| 43 | |
---|
| 44 | werase(pw->popwin); |
---|
| 45 | werase(pw->borderwin); |
---|
| 46 | box(pw->borderwin, 0, 0); |
---|
| 47 | wnoutrefresh(pw->popwin); |
---|
| 48 | wnoutrefresh(pw->borderwin); |
---|
| 49 | owl_global_set_needrefresh(&g); |
---|
| 50 | pw->active=1; |
---|
| 51 | return(0); |
---|
| 52 | } |
---|
| 53 | |
---|
[b2b0773] | 54 | int owl_popwin_display_text(owl_popwin *pw, char *text) |
---|
| 55 | { |
---|
[7d4fbcd] | 56 | waddstr(pw->popwin, text); |
---|
| 57 | wnoutrefresh(pw->popwin); |
---|
| 58 | touchwin(pw->borderwin); |
---|
| 59 | wnoutrefresh(pw->borderwin); |
---|
| 60 | owl_global_set_needrefresh(&g); |
---|
| 61 | return(0); |
---|
| 62 | } |
---|
| 63 | |
---|
[b2b0773] | 64 | int owl_popwin_close(owl_popwin *pw) |
---|
| 65 | { |
---|
[7d4fbcd] | 66 | delwin(pw->popwin); |
---|
| 67 | delwin(pw->borderwin); |
---|
| 68 | pw->active=0; |
---|
| 69 | owl_global_set_needrefresh(&g); |
---|
| 70 | owl_mainwin_redisplay(owl_global_get_mainwin(&g)); |
---|
| 71 | owl_function_full_redisplay(&g); |
---|
| 72 | return(0); |
---|
| 73 | } |
---|
| 74 | |
---|
[b2b0773] | 75 | int owl_popwin_is_active(owl_popwin *pw) |
---|
| 76 | { |
---|
[7d4fbcd] | 77 | if (pw->active==1) return(1); |
---|
| 78 | return(0); |
---|
| 79 | } |
---|
| 80 | |
---|
[b2b0773] | 81 | /* this will refresh the border as well as the text area */ |
---|
| 82 | int owl_popwin_refresh(owl_popwin *pw) |
---|
| 83 | { |
---|
[7d4fbcd] | 84 | touchwin(pw->borderwin); |
---|
| 85 | touchwin(pw->popwin); |
---|
| 86 | |
---|
| 87 | wnoutrefresh(pw->borderwin); |
---|
| 88 | wnoutrefresh(pw->popwin); |
---|
| 89 | owl_global_set_needrefresh(&g); |
---|
| 90 | return(0); |
---|
| 91 | } |
---|
| 92 | |
---|
[b2b0773] | 93 | void owl_popwin_set_handler(owl_popwin *pw, void (*func)(int ch)) |
---|
| 94 | { |
---|
[7d4fbcd] | 95 | pw->handler=func; |
---|
| 96 | } |
---|
| 97 | |
---|
[b2b0773] | 98 | void owl_popwin_unset_handler(owl_popwin *pw) |
---|
| 99 | { |
---|
[7d4fbcd] | 100 | pw->handler=NULL; |
---|
| 101 | } |
---|
| 102 | |
---|
[b2b0773] | 103 | WINDOW *owl_popwin_get_curswin(owl_popwin *pw) |
---|
| 104 | { |
---|
[7d4fbcd] | 105 | return(pw->popwin); |
---|
| 106 | } |
---|
| 107 | |
---|
[b2b0773] | 108 | int owl_popwin_get_lines(owl_popwin *pw) |
---|
| 109 | { |
---|
[7d4fbcd] | 110 | return(pw->lines-2); |
---|
| 111 | } |
---|
| 112 | |
---|
[b2b0773] | 113 | int owl_popwin_get_cols(owl_popwin *pw) |
---|
| 114 | { |
---|
[7d4fbcd] | 115 | return(pw->cols-2); |
---|
| 116 | } |
---|
| 117 | |
---|
[b2b0773] | 118 | int owl_popwin_needs_first_refresh(owl_popwin *pw) |
---|
| 119 | { |
---|
[7d4fbcd] | 120 | if (pw->needsfirstrefresh) return(1); |
---|
| 121 | return(0); |
---|
| 122 | } |
---|
| 123 | |
---|
[b2b0773] | 124 | void owl_popwin_no_needs_first_refresh(owl_popwin *pw) |
---|
| 125 | { |
---|
[7d4fbcd] | 126 | pw->needsfirstrefresh=0; |
---|
| 127 | } |
---|