source: popwin.c @ 385cce2

release-1.10release-1.7release-1.8release-1.9
Last change on this file since 385cce2 was 03ca005, checked in by David Benjamin <davidben@mit.edu>, 14 years ago
Create a new owl_popwin every time instead of rewiring the old one Constantly rewiring things is weird.
  • Property mode set to 100644
File size: 2.7 KB
RevLine 
[7d4fbcd]1#include "owl.h"
2
[03ca005]3owl_popwin *owl_popwin_new(void)
[b2b0773]4{
[03ca005]5  owl_popwin *pw = owl_malloc(sizeof(owl_popwin));
6  memset(pw, 0, sizeof(*pw));
[7d4fbcd]7
[d106110]8  pw->border = owl_window_new(NULL);
9  pw->content = owl_window_new(pw->border);
[b3b1b05]10  /* To be thorough, we ensure each signal is disconnected when we close. */
11  pw->sig_redraw_id =
12    g_signal_connect(pw->border, "redraw", G_CALLBACK(owl_popwin_draw_border), 0);
13  pw->sig_resize_id =
14    g_signal_connect(pw->border, "resized", G_CALLBACK(owl_popwin_size_content), pw);
[05ca0d8]15  owl_signal_connect_object(owl_window_get_screen(), "resized", G_CALLBACK(owl_popwin_size_border), pw->border, 0);
[7a6e6c7]16
17  /* bootstrap sizing */
18  owl_popwin_size_border(owl_window_get_screen(), pw->border);
19
[03ca005]20  owl_window_show(pw->content);
[fe67f1f]21
[03ca005]22  return pw;
23}
24
25int owl_popwin_up(owl_popwin *pw)
26{
27  if (owl_window_is_shown(pw->border))
28    return 1;
29  owl_window_show(pw->border);
30  return 0;
[68f63a2]31}
32
[7a6e6c7]33void owl_popwin_size_border(owl_window *parent, void *user_data)
[68f63a2]34{
35  int lines, cols, startline, startcol;
36  int glines, gcols;
[7a6e6c7]37  owl_window *border = user_data;
[7d4fbcd]38
[d106110]39  owl_window_get_position(parent, &glines, &gcols, 0, 0);
[7d4fbcd]40
[68f63a2]41  lines = owl_util_min(glines,24)*3/4 + owl_util_max(glines-24,0)/2;
42  startline = (glines-lines)/2;
43  cols = owl_util_min(gcols,90)*15/16 + owl_util_max(gcols-90,0)/2;
44  startcol = (gcols-cols)/2;
45
[d106110]46  owl_window_set_position(border, lines, cols, startline, startcol);
[68f63a2]47}
48
[7a6e6c7]49void owl_popwin_size_content(owl_window *parent, void *user_data)
[68f63a2]50{
[d3814ff]51  int lines, cols;
[b3b1b05]52  owl_popwin *pw = user_data;
[d106110]53  owl_window_get_position(parent, &lines, &cols, 0, 0);
[b3b1b05]54  owl_window_set_position(pw->content, lines-2, cols-2, 1, 1);
[68f63a2]55}
56
57void owl_popwin_draw_border(owl_window *w, WINDOW *borderwin, void *user_data)
58{
[1383b58]59  int lines, cols;
60  owl_window_get_position(w, &lines, &cols, 0, 0);
[c15bbfb]61  if (owl_global_is_fancylines(&g)) {
[dffb8b8]62    box(borderwin, 0, 0);
[c15bbfb]63  } else {
[dffb8b8]64    box(borderwin, '|', '-');
65    wmove(borderwin, 0, 0);
66    waddch(borderwin, '+');
[1383b58]67    wmove(borderwin, lines-1, 0);
[dffb8b8]68    waddch(borderwin, '+');
[1383b58]69    wmove(borderwin, lines-1, cols-1);
[dffb8b8]70    waddch(borderwin, '+');
[1383b58]71    wmove(borderwin, 0, cols-1);
[dffb8b8]72    waddch(borderwin, '+');
[c15bbfb]73  }
[7d4fbcd]74}
75
[b2b0773]76int owl_popwin_close(owl_popwin *pw)
77{
[03ca005]78  if (!owl_window_is_shown(pw->border))
[6425d43]79    return 1;
[03ca005]80  owl_window_hide(pw->border);
81  return 0;
82}
83
84void owl_popwin_delete(owl_popwin *pw)
85{
86  owl_popwin_close(pw);
87
88  /* Remove everything that references us. */
[b3b1b05]89  g_signal_handler_disconnect(pw->border, pw->sig_resize_id);
90  g_signal_handler_disconnect(pw->border, pw->sig_redraw_id);
[3da1f4f]91  owl_window_unlink(pw->border);
[053f751]92  g_object_unref(pw->border);
93  g_object_unref(pw->content);
[7a6e6c7]94
[03ca005]95  owl_free(pw);
[7d4fbcd]96}
97
[9c01a5e]98int owl_popwin_is_active(const owl_popwin *pw)
[b2b0773]99{
[03ca005]100  return owl_window_is_shown(pw->border);
[7d4fbcd]101}
102
[68f63a2]103owl_window *owl_popwin_get_content(const owl_popwin *pw)
[b2b0773]104{
[68f63a2]105  return pw->content;
[7d4fbcd]106}
Note: See TracBrowser for help on using the repository browser.