source: popwin.c @ c93b8b5

release-1.10release-1.7release-1.8release-1.9
Last change on this file since c93b8b5 was 05ca0d8, checked in by David Benjamin <davidben@mit.edu>, 15 years ago
Implement our own owl_signal_connect_object This is actually more code, but that's because of comments. It'll be MUCH less error-prone.
  • Property mode set to 100644
File size: 2.2 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{
[d106110]11  pw->border = owl_window_new(NULL);
12  pw->content = owl_window_new(pw->border);
[7a6e6c7]13  g_signal_connect(pw->border, "redraw", G_CALLBACK(owl_popwin_draw_border), 0);
[05ca0d8]14  owl_signal_connect_object(owl_window_get_screen(), "resized", G_CALLBACK(owl_popwin_size_border), pw->border, 0);
15  owl_signal_connect_object(pw->border, "resized", G_CALLBACK(owl_popwin_size_content), pw->content, 0);
[7a6e6c7]16
17  /* bootstrap sizing */
18  owl_popwin_size_border(owl_window_get_screen(), pw->border);
19
[402ed3d3]20  owl_window_show_all(pw->border);
[fe67f1f]21
[68f63a2]22  pw->active=1;
23  return(0);
24}
25
[7a6e6c7]26void owl_popwin_size_border(owl_window *parent, void *user_data)
[68f63a2]27{
28  int lines, cols, startline, startcol;
29  int glines, gcols;
[7a6e6c7]30  owl_window *border = user_data;
[7d4fbcd]31
[d106110]32  owl_window_get_position(parent, &glines, &gcols, 0, 0);
[7d4fbcd]33
[68f63a2]34  lines = owl_util_min(glines,24)*3/4 + owl_util_max(glines-24,0)/2;
35  startline = (glines-lines)/2;
36  cols = owl_util_min(gcols,90)*15/16 + owl_util_max(gcols-90,0)/2;
37  startcol = (gcols-cols)/2;
38
[d106110]39  owl_window_set_position(border, lines, cols, startline, startcol);
[68f63a2]40}
41
[7a6e6c7]42void owl_popwin_size_content(owl_window *parent, void *user_data)
[68f63a2]43{
[d3814ff]44  int lines, cols;
[7a6e6c7]45  owl_window *content = user_data;
[d106110]46  owl_window_get_position(parent, &lines, &cols, 0, 0);
47  owl_window_set_position(content, lines-2, cols-2, 1, 1);
[68f63a2]48}
49
50void owl_popwin_draw_border(owl_window *w, WINDOW *borderwin, void *user_data)
51{
[1383b58]52  int lines, cols;
53  owl_window_get_position(w, &lines, &cols, 0, 0);
[c15bbfb]54  if (owl_global_is_fancylines(&g)) {
[dffb8b8]55    box(borderwin, 0, 0);
[c15bbfb]56  } else {
[dffb8b8]57    box(borderwin, '|', '-');
58    wmove(borderwin, 0, 0);
59    waddch(borderwin, '+');
[1383b58]60    wmove(borderwin, lines-1, 0);
[dffb8b8]61    waddch(borderwin, '+');
[1383b58]62    wmove(borderwin, lines-1, cols-1);
[dffb8b8]63    waddch(borderwin, '+');
[1383b58]64    wmove(borderwin, 0, cols-1);
[dffb8b8]65    waddch(borderwin, '+');
[c15bbfb]66  }
[7d4fbcd]67}
68
[b2b0773]69int owl_popwin_close(owl_popwin *pw)
70{
[3da1f4f]71  owl_window_unlink(pw->border);
[053f751]72  g_object_unref(pw->border);
73  g_object_unref(pw->content);
[7a6e6c7]74
[68f63a2]75  pw->border = 0;
76  pw->content = 0;
[7d4fbcd]77  pw->active=0;
78  return(0);
79}
80
[9c01a5e]81int owl_popwin_is_active(const owl_popwin *pw)
[b2b0773]82{
[06cc8d9]83  return pw->active;
[7d4fbcd]84}
85
[68f63a2]86owl_window *owl_popwin_get_content(const owl_popwin *pw)
[b2b0773]87{
[68f63a2]88  return pw->content;
[7d4fbcd]89}
Note: See TracBrowser for help on using the repository browser.