NEURON
xdep.cpp
Go to the documentation of this file.
1 #include <../../nrnconf.h>
2 #if HAVE_IV // to end of file
3 
4 #include <IV-X11/xcanvas.h>
5 #include <IV-X11/xwindow.h>
6 #include <IV-X11/xdisplay.h>
7 #include <InterViews/display.h>
8 #include <InterViews/session.h>
9 #include <InterViews/style.h>
10 
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include "rubband.h"
14 #include "scenevie.h"
15 #include "apwindow.h"
16 
17 void get_position(XDisplay* dpy, XWindow window, int* rx, int* ry);
18 
19 static bool r_unbound;
21  if (c->rep()->copybuffer_ == CanvasRep::unbound) {
22  r_unbound = true;
23  return;
24  }
25  c->rep()->unbind();
26  c->rep()->bind(0);
27 }
28 
30  if (r_unbound == true) {
31  r_unbound = false;
32  return;
33  }
34  c->rep()->unbind();
35  c->rep()->bind(1);
36  c->damage_all();
37 }
38 
39 void XYView::rebind() {
40  canvas()->rep()->unbind();
41  canvas()->rep()->bind(1);
42 }
43 
44 //-----------------------------------
45 
46 void PrintableWindow::hide() {
47  if (bound()) {
48  if (is_mapped()) {
49  xplace(xleft(), xtop());
50  // printf("hide %p %d %d\n", this, xleft_, xtop_);
51  WindowRep& w = *((Window*) this)->rep();
52  XWithdrawWindow(display()->rep()->display_, w.xwindow_, display()->rep()->screen_);
53  }
54  }
55 }
56 
57 int PrintableWindow::xleft() const {
58  int x, y;
59  if (bound()) {
60  WindowRep& w = *((Window*) this)->rep();
61  get_position(display()->rep()->display_, w.xwindow_, &x, &y);
62  } else if (xplace_) {
63  x = xleft_;
64  } else {
65  x = 0;
66  }
67  return x;
68 }
69 
70 int PrintableWindow::xtop() const {
71  int x, y;
72  if (bound()) {
73  WindowRep& w = *((Window*) this)->rep();
74  get_position(display()->rep()->display_, w.xwindow_, &x, &y);
75  } else if (xplace_) {
76  y = xtop_;
77  } else {
78  y = 0;
79  }
80  return y;
81 }
82 
83 void PrintableWindow::xplace(int left, int top) {
84  xplace_ = true;
85  xleft_ = left;
86  xtop_ = top;
87 }
88 
89 #if 1
90 static int xoff = -999, yoff = -999;
91 
92 void PrintableWindow::xmove(int left1, int top) {
93  const Display& d = *display();
94  WindowRep& w = *((Window*) this)->rep();
95  Style* q = Session::instance()->style();
96  Coord WMOffsetX, WMOffsetY;
97 
98  if (xoff == -999 && yoff == -999) {
99  if (!q->find_attribute("window_manager_offset_x", WMOffsetX)) {
100  WMOffsetX = 5.;
101  }
102  if (!q->find_attribute("window_manager_offset_y", WMOffsetY)) {
103  WMOffsetY = 26.;
104  }
105  xoff = (int) WMOffsetX;
106  yoff = (int) WMOffsetY;
107  }
108  xoff = yoff = 0;
109  // printf("%p xmove(%d,%d) XMoveWindow(%d,%d)\n", this,left1, top, left1+xoff, top+yoff);
110  XMoveWindow(d.rep()->display_, w.xwindow_, left1 + xoff, top + yoff);
111 }
112 #else
113 static Bool WaitForEvent(XDisplay* dpy, XEvent* event, char* type) {
114  return (Bool) (event->type == (int) type);
115 }
116 
117 void PrintableWindow::xmove(int left1, int top) {
118  const Display& d = *display();
119  XEvent event;
120 
121  int x = 0, y = 0;
122  static int xoff = 0, yoff = 0;
123  WindowRep& w = *((Window*) this)->rep();
124  get_position(d.rep()->display_, w.xwindow_, &x, &y);
125 
126  for (int i = 0; (left1 != x || top != y) && i < 10; i++) {
127  XMoveWindow(d.rep()->display_, w.xwindow_, left1 + xoff, top + yoff);
128  XPeekIfEvent(d.rep()->display_, &event, WaitForEvent, (char*) ConfigureNotify);
129  get_position(d.rep()->display_, w.xwindow_, &x, &y);
130 
131  if (left1 != x || top != y) {
132  XIfEvent(d.rep()->display_, &event, WaitForEvent, (char*) ConfigureNotify);
133  xoff = left1 - x;
134  yoff = top - y;
135  }
136  printf("x=%d y=%d, left1=%d top=%d xoff = %d yoff = %d\n", x, y, left1, top, xoff, yoff);
137  }
138 }
139 #endif
140 
142  WindowRep& w = *Window::rep();
143  const Display& d = *w.display_;
144  w.glyph_->request(w.shape_);
145  Coord width = w.shape_.requirement(Dimension_X).natural();
146  Coord height = w.shape_.requirement(Dimension_Y).natural();
147  ((OcGlyph*) glyph())->def_size(width, height);
148 
149  w.canvas_->size(width, height);
150  if (xplace_) {
151  w.placed_ = true;
152  w.left_ = d.to_coord(xleft_);
153  w.bottom_ = d.to_coord(d.pheight() - xtop_ - w.canvas_->pheight());
154  }
155  w.xpos_ = d.to_pixels(w.left_);
156  w.ypos_ = d.pheight() - d.to_pixels(w.bottom_) - w.canvas_->pheight();
157  if (w.aligned_) {
158  w.xpos_ -= d.to_pixels(w.xalign_ * width);
159  w.ypos_ += d.to_pixels(w.yalign_ * height);
160  }
161  if (w.placed_) {
162  Display& d = *w.display_;
163  PixelCoord l = w.xpos_, b = w.ypos_;
164  PixelCoord pw = d.to_pixels(width), ph = d.to_pixels(height);
165  l = (l < d.pwidth() - pw) ? l : d.pwidth() - pw;
166  b = (b < d.pheight() - ph) ? b : d.pheight() - ph;
167  l = (l > 0) ? l : 0;
168  b = (b > 0) ? b : 0;
169  w.xpos_ = l;
170  w.ypos_ = b;
171  }
172 }
173 
174 //---------------------------
175 #if 0
176 #include <X11/Xlib.h>
177 #include <X11/Xutil.h>
178 #include <X11/Xatom.h>
179 #include <X11/Xos.h>
180 #include <X11/extensions/shape.h>
181 #include <X11/Xmu/WinUtil.h>
182 #include <stdio.h>
183 #endif
184 
185 void get_position(XDisplay* dpy, XWindow window, int* rx, int* ry) {
186  XWindowAttributes win_attributes;
187  XWindow junkwin;
188 
189  if (!XGetWindowAttributes(dpy, window, &win_attributes)) {
190  fprintf(stderr, "Can't get window attributes.");
191  exit(1);
192  }
193  (void) XTranslateCoordinates(
194  dpy, window, win_attributes.root, -win_attributes.x, -win_attributes.y, rx, ry, &junkwin);
195 
196  // printf("get_position %p %d %d\n", window, *rx, *ry);
197  // if (xoff != -999) {
198  // *rx -= xoff;
199  // *ry -= yoff;
200  //}
201 }
202 
203 #endif
#define PixelCoord
Definition: _defines.h:23
#define Window
Definition: _defines.h:330
#define Canvas
Definition: _defines.h:63
#define Style
Definition: _defines.h:278
#define Coord
Definition: _defines.h:17
#define WindowRep
Definition: _defines.h:332
#define Display
Definition: _defines.h:95
virtual Glyph * glyph() const
Definition: apwindow.h:47
virtual void default_geometry()
void xmove(int left, int top)
void xplace(int left, int top)
virtual void hide()
int xleft() const
int xtop() const
void rubber_off(Canvas *)
void rubber_on(Canvas *)
Canvas * canvas()
void rebind()
#define i
Definition: md1redef.h:19
@ Dimension_Y
Definition: geometry.h:39
@ Dimension_X
Definition: geometry.h:39
static int c
Definition: hoc.cpp:169
printf
Definition: extdef.h:5
size_t q
short type
Definition: cabvars.h:10