source: popwin.c @ 785ee77

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