source: popwin.c @ 4cf7b1b

release-1.7release-1.8release-1.9
Last change on this file since 4cf7b1b was 6425d43, checked in by David Benjamin <davidben@mit.edu>, 12 years ago
Don't cause confusion if owl_popwin_up on an active popwin Likewise, inactive popwins should not be closeable. The function returns int, so we may as well return an error, but no one checks that.
  • Property mode set to 100644
File size: 2.3 KB
RevLine 
[7d4fbcd]1#include "owl.h"
2
[b2b0773]3int owl_popwin_init(owl_popwin *pw)
4{
[7d4fbcd]5  pw->active=0;
6  return(0);
7}
8
[b2b0773]9int owl_popwin_up(owl_popwin *pw)
10{
[6425d43]11  if (pw->active)
12    return 1;
[d106110]13  pw->border = owl_window_new(NULL);
14  pw->content = owl_window_new(pw->border);
[7a6e6c7]15  g_signal_connect(pw->border, "redraw", G_CALLBACK(owl_popwin_draw_border), 0);
[05ca0d8]16  owl_signal_connect_object(owl_window_get_screen(), "resized", G_CALLBACK(owl_popwin_size_border), pw->border, 0);
17  owl_signal_connect_object(pw->border, "resized", G_CALLBACK(owl_popwin_size_content), pw->content, 0);
[7a6e6c7]18
19  /* bootstrap sizing */
20  owl_popwin_size_border(owl_window_get_screen(), pw->border);
21
[402ed3d3]22  owl_window_show_all(pw->border);
[fe67f1f]23
[68f63a2]24  pw->active=1;
25  return(0);
26}
27
[7a6e6c7]28void owl_popwin_size_border(owl_window *parent, void *user_data)
[68f63a2]29{
30  int lines, cols, startline, startcol;
31  int glines, gcols;
[7a6e6c7]32  owl_window *border = user_data;
[7d4fbcd]33
[d106110]34  owl_window_get_position(parent, &glines, &gcols, 0, 0);
[7d4fbcd]35
[68f63a2]36  lines = owl_util_min(glines,24)*3/4 + owl_util_max(glines-24,0)/2;
37  startline = (glines-lines)/2;
38  cols = owl_util_min(gcols,90)*15/16 + owl_util_max(gcols-90,0)/2;
39  startcol = (gcols-cols)/2;
40
[d106110]41  owl_window_set_position(border, lines, cols, startline, startcol);
[68f63a2]42}
43
[7a6e6c7]44void owl_popwin_size_content(owl_window *parent, void *user_data)
[68f63a2]45{
[d3814ff]46  int lines, cols;
[7a6e6c7]47  owl_window *content = user_data;
[d106110]48  owl_window_get_position(parent, &lines, &cols, 0, 0);
49  owl_window_set_position(content, lines-2, cols-2, 1, 1);
[68f63a2]50}
51
52void owl_popwin_draw_border(owl_window *w, WINDOW *borderwin, void *user_data)
53{
[1383b58]54  int lines, cols;
55  owl_window_get_position(w, &lines, &cols, 0, 0);
[c15bbfb]56  if (owl_global_is_fancylines(&g)) {
[dffb8b8]57    box(borderwin, 0, 0);
[c15bbfb]58  } else {
[dffb8b8]59    box(borderwin, '|', '-');
60    wmove(borderwin, 0, 0);
61    waddch(borderwin, '+');
[1383b58]62    wmove(borderwin, lines-1, 0);
[dffb8b8]63    waddch(borderwin, '+');
[1383b58]64    wmove(borderwin, lines-1, cols-1);
[dffb8b8]65    waddch(borderwin, '+');
[1383b58]66    wmove(borderwin, 0, cols-1);
[dffb8b8]67    waddch(borderwin, '+');
[c15bbfb]68  }
[7d4fbcd]69}
70
[b2b0773]71int owl_popwin_close(owl_popwin *pw)
72{
[6425d43]73  if (!pw->active)
74    return 1;
[3da1f4f]75  owl_window_unlink(pw->border);
[053f751]76  g_object_unref(pw->border);
77  g_object_unref(pw->content);
[7a6e6c7]78
[68f63a2]79  pw->border = 0;
80  pw->content = 0;
[7d4fbcd]81  pw->active=0;
82  return(0);
83}
84
[9c01a5e]85int owl_popwin_is_active(const owl_popwin *pw)
[b2b0773]86{
[06cc8d9]87  return pw->active;
[7d4fbcd]88}
89
[68f63a2]90owl_window *owl_popwin_get_content(const owl_popwin *pw)
[b2b0773]91{
[68f63a2]92  return pw->content;
[7d4fbcd]93}
Note: See TracBrowser for help on using the repository browser.