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 #if defined(CYGWIN)
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 #if defined(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 #if defined(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 #if defined(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(hwnd,
124  iv_pixel_to_mswin(x), iv_pixel_to_mswin(y),
125  r.right - r.left, r.bottom - r.top, TRUE);
126 }
127 int PrintableWindow::xleft() const {
128  WindowRep& w = *Window::rep();
129  if (w.bound()) {
130  HWND hwnd = w.msWindow();
131  RECT winRect;
132  GetWindowRect(hwnd, &winRect);
133  return iv_mswin_to_pixel(winRect.left);
134  }else{
135  return 0;
136  }
137 }
138 int PrintableWindow::xtop() const {
139  WindowRep& w = *Window::rep();
140  if (w.bound()) {
141  HWND hwnd = w.msWindow();
142  RECT winRect;
143  GetWindowRect(hwnd, &winRect);
144  return iv_mswin_to_pixel(winRect.top);
145  }else{
146  return 0;
147  }
148 }
149 
150 void PrintableWindow::xplace(int x, int y) {
151  WindowRep& wr = *Window::rep();
152  if (wr.bound()) {
153  xmove(x, y);
154  }else{
155  xplace_ = true;
156  xleft_ = x;
157  xtop_ = y;
158  }
159 }
161  DismissableWindow::default_geometry();
162  if (xplace_) {
163  pplace(iv_pixel_to_mswin(xleft_),
164  display()->pheight() - iv_pixel_to_mswin(xtop_)
165  - canvas()->to_pixels(height(),Dimension_Y));
166  }
167 }
168 #if 0
169 Object** Graph::new_vect(const DataVec*) {
170  return 0;
171 }
172 #endif
173 //#include "\nrn\src\mswin\winio\debug.h"
174 void Rubberband::rubber_on(Canvas* c) {
175 // DebugEnterMessage("Rubberband::rubber_on\n");
176  c->front_buffer();
177 }
179  c->back_buffer();
180 #ifdef WIN32
181 // this prevents failure for all future paints
182  c->damage_all();
183 #endif
184 // DebugExitMessage("Rubberband::rubber_off\n");
185 }
186 #if 0
187 double* ivoc_vector_ptr(Object*, int) {return 0;}
188 int ivoc_vector_size(Object*) {return 0;}
189 #endif
190 
191 #ifdef MINGW
192 IOHandler::IOHandler(){}
193 IOHandler::~IOHandler(){}
194 int IOHandler::inputReady(int){return 0;}
195 int IOHandler::outputReady(int){return 0;}
196 int IOHandler::exceptionRaised(int){return 0;}
197 void IOHandler::timerExpired(long, long){}
198 void IOHandler::childStatus(pid_t, int){}
199 #endif // MINGW
200 
201 #ifdef MINGW
202 
203 #include <nrnmutdec.h>
204 static int bind_tid_;
205 void nrniv_bind_thread(void);
206 extern int (*iv_bind_enqueue_)(void(*)(void*), void* w);
207 extern void iv_bind_call(void* w, int type);
208 extern void nrnpy_setwindowtext(void*);
209 
210 extern void* (*nrnpy_save_thread)();
211 extern void (*nrnpy_restore_thread)(void*);
212 
213 static void* w_;
214 static void (*nrn_gui_exec_)(void*);
215 
216 static pthread_mutex_t* mut_;
217 static pthread_cond_t* cond_;
218 
219 bool nrn_is_gui_thread() {
220  if (cond_ && GetCurrentThreadId() != bind_tid_) {
221  return false;
222  }
223  return true;
224 }
225 
226 int iv_bind_enqueue(void(*cb)(void*), void* w) {
227  //printf("iv_bind_enqueue %p thread %d\n", w, GetCurrentThreadId());
228  if (GetCurrentThreadId() == bind_tid_) {
229  return 0;
230  }
231  nrn_gui_exec(cb, w);
232  return 1;
233 }
234 
235 void nrn_gui_exec(void (*cb)(void*), void* v) {
236  assert(GetCurrentThreadId() != bind_tid_);
237  // wait for the gui thread to handle the operation
238  void* gs = (*nrnpy_save_thread)();
239  pthread_mutex_lock(mut_);
240  w_ = v;
241  nrn_gui_exec_ = cb;
242  while (w_) {
243  pthread_cond_wait(cond_, mut_);
244  }
245  pthread_mutex_unlock(mut_);
246  (*nrnpy_restore_thread)(gs);
247 }
248 
249 void nrniv_bind_call() {
250  if (!cond_) { return; }
251  void* w;
252  pthread_mutex_lock(mut_);
253  w = w_;
254  if (w_) {
255  w_ = NULL;
256  (*nrn_gui_exec_)(w);
257  pthread_cond_signal(cond_);
258  }
259  pthread_mutex_unlock(mut_);
260 }
261 
262 
263 #endif // MINGW
264 
265 #endif //HAVE_IV
266 
268 #if HAVE_IV
269 IFGUI
270  bind_tid_ = int(*hoc_getarg(1));
271  //printf("nrniv_bind_thread %d\n", bind_tid_);
272  iv_bind_enqueue_ = iv_bind_enqueue;
273  cond_ = new pthread_cond_t;
274  mut_ = new pthread_mutex_t;
275  pthread_cond_init(cond_, NULL);
276  pthread_mutex_init(mut_, NULL);
277  w_ = NULL;
278 ENDGUI
279 #endif
280  hoc_pushx(1.);
281  hoc_ret();
282 }
283 
285 #if HAVE_IV
286 IFGUI
287  static DWORD main_threadid = -1;
288  if (main_threadid == -1) {
289  main_threadid = GetCurrentThreadId();
290  return 1;
291  }
292  PostThreadMessage(main_threadid, WM_QUIT, 0, 0);
293 ENDGUI
294 #endif
295  return 1;
296 }
297 
void xmove(int left, int top)
Definition: ivocmac.cpp:174
#define assert(ex)
Definition: hocassrt.h:26
short type
Definition: cabvars.h:10
static Cursor * help_cursor_
Definition: ivoc.h:79
void pwmimpl_redraw(Window *w)
carbon
Definition: ivocmac.cpp:153
int xleft() const
Definition: ivocmac.cpp:182
void
static void cleanup()
Definition: ivocmac.cpp:164
static double clip
Definition: axis.cpp:171
#define TRUE
Definition: err.c:57
#define WindowRep
Definition: _defines.h:335
Definition: graph.h:163
static double dummy
Definition: ocptrvector.cpp:27
#define v
Definition: md1redef.h:4
int ivoc_list_look(Object *ob, Object *oblook, char *path, int)
Definition: oclist.cpp:511
int ivoc_vector_size(Object *o)
Definition: ivocvect.cpp:3712
void hoc_ret()
static N_Vector w_
void(* nrnpy_restore_thread)(void *)
Definition: ivoc.cpp:44
int
Definition: nrnmusic.cpp:71
#define ENDGUI
Definition: hocdec.h:352
#define Canvas
Definition: _defines.h:65
void nrniv_bind_thread()
Definition: ivocwin.cpp:267
void hoc_class_registration(void)
Definition: classreg.cpp:27
void cb(const char *s)
Definition: bbstest.cpp:5
void xplace(int left, int top)
Definition: ivocmac.cpp:229
void hoc_pushx(double)
void ivoc_bring_to_top(Window *w)
Definition: ivocmac.cpp:157
static void display(int imenu)
Definition: fmenu.cpp:394
void rubber_off(Canvas *)
Definition: ivocmac.cpp:269
Definition: hocdec.h:226
#define c
virtual void hide()
Definition: ivocmac.cpp:170
#define Window
Definition: _defines.h:333
virtual void default_geometry()
Definition: ivocmac.cpp:245
void rubber_on(Canvas *)
Definition: ivocmac.cpp:257
#define IFGUI
Definition: hocdec.h:351
int stdin_event_ready()
Definition: ivocwin.cpp:284
return NULL
Definition: cabcode.cpp:461
double * ivoc_vector_ptr(Object *o, int index)
Definition: ivocvect.cpp:3717
int xtop() const
Definition: ivocmac.cpp:205