NEURON
ivocwin.cpp
Go to the documentation of this file.
1 #include <../../nrnconf.h>
2 #include "oc2iv.h"
3 
4 #if HAVE_IV
5 #include <IV-Win/MWlib.h>
6 #if defined(_MSC_VER)
7 #undef min
8 #undef max
9 #undef near
10 #define near mynear
11 
12 #else
13 #undef near
14 #endif
15 
16 #undef MOVE
17 #undef DELETE
18 #undef IGNORE
19 #define MOVE mlhmove
20 #define DELETE mlhdelete
21 #include <Dispatch/dispatcher.h>
22 #include <InterViews/window.h>
23 #include <IV-Win/window.h>
24 #include <InterViews/display.h>
25 #include <InterViews/cursor.h>
26 #include <IV-Win/canvas.h>
27 #include "apwindow.h"
28 #include "ivoc.h"
29 #include "rubband.h"
30 #include "symdir.h"
31 #undef max
32 #undef min
33 #include "graph.h"
34 
35 #ifdef MINGW
36 // the link step needs liboc after libivoc but liboc refers to some
37 // things in libivoc that wouldn't normally be linked because nothing
38 // refers to them while libivoc is linking. So force them to link here
39 int ivoc_list_look(Object*, Object*, char*, int);
41 static void dummy() {
44 }
45 #endif
46 
47 int iv_mswin_to_pixel(int);
48 int iv_pixel_to_mswin(int);
49 
50 void pwmimpl_redraw(Window* w) {
51  w->rep()->WMpaint(0, 0);
52 }
53 
54 void ivoc_bring_to_top(Window* w) {
55  BringWindowToTop(w->rep()->msWindow());
56 }
57 
58 void* mswin_setclip(Canvas* c, int x0, int y0, int x1, int y1) {
59  HRGN clip = CreateRectRgn(x0, y0, x1, y1);
60  SelectClipRgn(((MWcanvas*) c)->hdcOf(), clip);
61  return clip;
62 }
63 
64 void mswin_delete_object(void* v) {
65  DeleteObject((HRGN) v);
66 }
67 
68 //---------------------------------------------------------
69 
70 void ivoc_win32_cleanup() {
71  Oc::cleanup();
72 }
73 
74 void Oc::cleanup() {
75  if (help_cursor_) {
76  delete help_cursor_;
77  }
78 }
79 
80 #ifdef MINGW
81 static void hidewindow(void* v) {
82  HWND w = (HWND) v;
83  ShowWindow(w, SW_HIDE);
84 }
85 
86 static int gui_thread_xmove_x;
87 static int gui_thread_xmove_y;
88 void gui_thread_xmove(void* v) {
90  w->xmove(gui_thread_xmove_x, gui_thread_xmove_y);
91 }
92 
93 #endif
94 
95 void PrintableWindow::hide() {
96  if (is_mapped()) {
97  HWND hwnd = Window::rep()->msWindow();
98 // printf("hide %p\n", this);
99 #ifdef MINGW
100  if (!nrn_is_gui_thread()) {
101  nrn_gui_exec(hidewindow, hwnd);
102  return;
103  }
104 #endif
105  ShowWindow(hwnd, SW_HIDE);
106  }
107 }
108 
109 void PrintableWindow::xmove(int x, int y) {
110 #ifdef MINGW
111  if (!nrn_is_gui_thread()) {
112  gui_thread_xmove_x = x;
113  gui_thread_xmove_y = y;
114  nrn_gui_exec(gui_thread_xmove, this);
115  return;
116  }
117 #endif
118  HWND hwnd = Window::rep()->msWindow();
119  // int width = canvas()->pwidth();
120  // int height = canvas()->pheight();
121  RECT r;
122  GetWindowRect(hwnd, &r);
123  MoveWindow(
124  hwnd, iv_pixel_to_mswin(x), iv_pixel_to_mswin(y), r.right - r.left, r.bottom - r.top, TRUE);
125 }
126 int PrintableWindow::xleft() const {
127  WindowRep& w = *Window::rep();
128  if (w.bound()) {
129  HWND hwnd = w.msWindow();
130  RECT winRect;
131  GetWindowRect(hwnd, &winRect);
132  return iv_mswin_to_pixel(winRect.left);
133  } else {
134  return 0;
135  }
136 }
137 int PrintableWindow::xtop() const {
138  WindowRep& w = *Window::rep();
139  if (w.bound()) {
140  HWND hwnd = w.msWindow();
141  RECT winRect;
142  GetWindowRect(hwnd, &winRect);
143  return iv_mswin_to_pixel(winRect.top);
144  } else {
145  return 0;
146  }
147 }
148 
149 void PrintableWindow::xplace(int x, int y) {
150  WindowRep& wr = *Window::rep();
151  if (wr.bound()) {
152  xmove(x, y);
153  } else {
154  xplace_ = true;
155  xleft_ = x;
156  xtop_ = y;
157  }
158 }
160  DismissableWindow::default_geometry();
161  if (xplace_) {
162  pplace(iv_pixel_to_mswin(xleft_),
163  display()->pheight() - iv_pixel_to_mswin(xtop_) -
164  canvas()->to_pixels(height(), Dimension_Y));
165  }
166 }
167 #if 0
168 Object** Graph::new_vect(const DataVec*) {
169  return 0;
170 }
171 #endif
172 //#include "\nrn\src\mswin\winio\debug.h"
174  // DebugEnterMessage("Rubberband::rubber_on\n");
175  c->front_buffer();
176 }
178  c->back_buffer();
179 #ifdef WIN32
180  // this prevents failure for all future paints
181  c->damage_all();
182 #endif
183  // DebugExitMessage("Rubberband::rubber_off\n");
184 }
185 #if 0
186 double* ivoc_vector_ptr(Object*, int) {return 0;}
187 int ivoc_vector_size(Object*) {return 0;}
188 #endif
189 
190 #ifdef MINGW
191 IOHandler::IOHandler() {}
192 IOHandler::~IOHandler() {}
193 int IOHandler::inputReady(int) {
194  return 0;
195 }
196 int IOHandler::outputReady(int) {
197  return 0;
198 }
199 int IOHandler::exceptionRaised(int) {
200  return 0;
201 }
202 void IOHandler::timerExpired(long, long) {}
203 void IOHandler::childStatus(pid_t, int) {}
204 #endif // MINGW
205 
206 #ifdef MINGW
207 
208 #include <nrnmutdec.h>
209 static int bind_tid_;
210 void nrniv_bind_thread(void);
211 extern int (*iv_bind_enqueue_)(void (*)(void*), void* w);
212 extern void iv_bind_call(void* w, int type);
213 extern void nrnpy_setwindowtext(void*);
214 
215 extern void* (*nrnpy_save_thread)();
216 extern void (*nrnpy_restore_thread)(void*);
217 
218 static void* w_;
219 static void (*nrn_gui_exec_)(void*);
220 
221 static pthread_mutex_t* mut_;
222 static pthread_cond_t* cond_;
223 
224 bool nrn_is_gui_thread() {
225  if (cond_ && GetCurrentThreadId() != bind_tid_) {
226  return false;
227  }
228  return true;
229 }
230 
231 int iv_bind_enqueue(void (*cb)(void*), void* w) {
232  // printf("iv_bind_enqueue %p thread %d\n", w, GetCurrentThreadId());
233  if (GetCurrentThreadId() == bind_tid_) {
234  return 0;
235  }
236  nrn_gui_exec(cb, w);
237  return 1;
238 }
239 
240 void nrn_gui_exec(void (*cb)(void*), void* v) {
241  assert(GetCurrentThreadId() != bind_tid_);
242  // wait for the gui thread to handle the operation
243  void* gs = (*nrnpy_save_thread)();
244  pthread_mutex_lock(mut_);
245  w_ = v;
246  nrn_gui_exec_ = cb;
247  while (w_) {
248  pthread_cond_wait(cond_, mut_);
249  }
250  pthread_mutex_unlock(mut_);
251  (*nrnpy_restore_thread)(gs);
252 }
253 
254 void nrniv_bind_call() {
255  if (!cond_) {
256  return;
257  }
258  void* w;
259  pthread_mutex_lock(mut_);
260  w = w_;
261  if (w_) {
262  w_ = NULL;
263  (*nrn_gui_exec_)(w);
264  pthread_cond_signal(cond_);
265  }
266  pthread_mutex_unlock(mut_);
267 }
268 
269 
270 #endif // MINGW
271 
272 #endif // HAVE_IV
273 
275 #if HAVE_IV
276  IFGUI
277  bind_tid_ = int(*hoc_getarg(1));
278  // printf("nrniv_bind_thread %d\n", bind_tid_);
279  iv_bind_enqueue_ = iv_bind_enqueue;
280  cond_ = new pthread_cond_t;
281  mut_ = new pthread_mutex_t;
282  pthread_cond_init(cond_, NULL);
283  pthread_mutex_init(mut_, NULL);
284  w_ = NULL;
285  ENDGUI
286 #endif
287  hoc_pushx(1.);
288  hoc_ret();
289 }
290 
292 #if HAVE_IV
293  IFGUI
294  static DWORD main_threadid = -1;
295  if (main_threadid == -1) {
296  main_threadid = GetCurrentThreadId();
297  return 1;
298  }
299  PostThreadMessage(main_threadid, WM_QUIT, 0, 0);
300  ENDGUI
301 #endif
302  return 1;
303 }
#define Window
Definition: _defines.h:333
#define Canvas
Definition: _defines.h:65
#define WindowRep
Definition: _defines.h:335
void cb(const char *s)
Definition: bbstest.cpp:5
short type
Definition: cabvars.h:9
Definition: graph.h:200
static Cursor * help_cursor_
Definition: ivoc.h:86
static void cleanup()
Definition: ivocmac.cpp:177
void xmove(int left, int top)
Definition: ivocmac.cpp:187
void xplace(int left, int top)
Definition: ivocmac.cpp:242
virtual void default_geometry()
Definition: ivocmac.cpp:258
int xleft() const
Definition: ivocmac.cpp:195
int xtop() const
Definition: ivocmac.cpp:218
virtual void hide()
Definition: ivocmac.cpp:183
void rubber_off(Canvas *)
Definition: ivocmac.cpp:281
void rubber_on(Canvas *)
Definition: ivocmac.cpp:270
#define c
#define TRUE
Definition: err.c:57
static void display(int imenu)
Definition: fmenu.cpp:400
@ Dimension_Y
Definition: geometry.h:43
int ivoc_list_look(Object *ob, Object *oblook, char *path, int)
Definition: oclist.cpp:503
void hoc_class_registration(void)
Definition: classreg.cpp:27
void hoc_ret()
#define assert(ex)
Definition: hocassrt.h:32
#define IFGUI
Definition: hocdec.h:372
#define ENDGUI
Definition: hocdec.h:373
void
void(* nrnpy_restore_thread)(void *)
Definition: ivoc.cpp:43
void pwmimpl_redraw(Window *w)
carbon
Definition: ivocmac.cpp:166
void ivoc_bring_to_top(Window *w)
Definition: ivocmac.cpp:170
void hoc_pushx(double)
double * ivoc_vector_ptr(Object *o, int index)
Definition: ivocvect.cpp:3941
int ivoc_vector_size(Object *o)
Definition: ivocvect.cpp:3936
void nrniv_bind_thread()
Definition: ivocwin.cpp:274
int stdin_event_ready()
Definition: ivocwin.cpp:291
#define v
Definition: md1redef.h:4
static N_Vector w_
static double clip
Definition: axis.cpp:171
static double dummy
Definition: ocptrvector.cpp:27
#define NULL
Definition: sptree.h:16
Definition: hocdec.h:227