NEURON
ivocmac.cpp
Go to the documentation of this file.
1 #include <../../nrnconf.h>
2 
3 #if defined(carbon)
4 #include <Carbon/Carbon.h>
5 #else
6 #include <CodeFragments.h>
7 #endif
8 
9 
10 #include <stdio.h>
11 #include "apwindow.h"
12 #include "ivoc.h"
13 #include "rubband.h"
14 #include "symdir.h"
15 #include "oc2iv.h"
16 #include "graph.h"
17 #include <InterViews/window.h>
18 #include <IV-Mac/window.h>
19 #include <InterViews/display.h>
20 #include <InterViews/cursor.h>
21 #include <Dispatch/dispatcher.h>
22 
23 typedef void (*NrnBBSCallback)(const char*);
24 
25 
26 #if !defined(carbon)
27 char* mktemp(char*) {
28  return NULL;
29 }
30 #endif
31 
33  return false;
34 }
37  return false;
38 }
39 
40 void nrnbbs_post(const char*) {}
41 void nrnbbs_post_int(const char*, int) {}
42 void nrnbbs_post_string(const char*, const char*) {}
43 
44 bool nrnbbs_take(const char*) {
45  return false;
46 }
47 bool nrnbbs_take_int(const char*, int*) {
48  return false;
49 }
50 bool nrnbbs_take_string(const char*, char*) {
51  return false;
52 }
53 
54 bool nrnbbs_look(const char*) {
55  return false;
56 }
57 
58 void nrnbbs_exec(const char*) {}
59 
60 void nrnbbs_notify(const char*, NrnBBSCallback) {}
61 
62 void nrnbbs_wait(bool* pflag = (bool*) 0) {}
63 
64 #if !carbon
65 bool is_mac_dll(FSSpec*);
66 bool mac_open_dll(const char*, FSSpec*);
67 #endif
68 
69 #if !carbon
70 bool is_mac_dll(FSSpec* fs) {
71  FInfo finfo;
72  FSpGetFInfo(fs, &finfo);
73  return finfo.fdType == 'shlb';
74 }
75 
77 extern OSErr __path2fss(const char* name, FSSpec*);
78 extern void hoc_nrn_load_dll();
79 
80 static long fsspec2id(FSSpec* fs) {
81  CInfoPBRec ci;
82  Str255 name;
83  int i;
84  for (i = 0; i < 64; ++i) {
85  name[i] = fs->name[i];
86  }
87  ci.hFileInfo.ioCompletion = 0;
88  ci.hFileInfo.ioNamePtr = name;
89  ci.hFileInfo.ioVRefNum = fs->vRefNum;
90  ci.hFileInfo.ioDirID = fs->parID;
91  ci.hFileInfo.ioFDirIndex = 0;
92  OSErr err = PBGetCatInfo(&ci, false);
93  return ci.hFileInfo.ioDirID;
94 }
95 static int ndll;
96 static long dllid[10];
97 
98 bool mac_open_dll(const char* name, FSSpec* fs) {
99  CFragConnectionID id;
100  Ptr mainaddr;
101  Str255 sname;
102  int j;
103  long fid = fsspec2id(fs);
104  for (j = 0; j < ndll; ++j) {
105  if (dllid[j] == fid) {
106  printf("%s DLL already loaded\n", name);
107  return false;
108  }
109  }
110  dllid[ndll] = fid;
111  ndll = (ndll < 10) ? ndll + 1 : 10;
112  printf("Loading DLL %s\n", name);
113 #if 1
114  OSErr myErr = GetDiskFragment(fs, 0, kCFragGoesToEOF, 0, kLoadCFrag, &id, &mainaddr, sname);
115  if (myErr) {
116  sname[sname[0] + 1] = '\0';
117  printf("dll load error %d\n%s\n", myErr, sname + 1);
118  return false;
119  }
120  // printf("successfully loaded %s\n", name);
121  // printf("mainaddr=%p\n", mainaddr);
122  mainaddr = NULL;
123  long cnt;
124  myErr = CountSymbols(id, &cnt);
125  // printf("symbols exported = %d\n", cnt);
126  for (long i = 0; i < cnt; ++i) {
127  Ptr symaddr;
128  CFragSymbolClass symclass;
129  myErr = GetIndSymbol(id, i, sname, &symaddr, &symclass);
130  sname[sname[0] + 1] = '\0';
131  if (strcmp((sname + 1), "main") == 0) {
132  mainaddr = symaddr;
133  }
134  // printf("symbol %d name %s\n", i, sname+1);
135  }
136 // printf("mainaddr=%p\n", mainaddr);
137 #if 1
138  if (mainaddr) {
139  Symlist* sav = hoc_symlist;
142  (*(Pfri) mainaddr)();
144  hoc_symlist = sav;
145  return true;
146  }
147 #endif
148 #endif
149  return false;
150 }
151 
152 bool mac_load_dll(const char* name) {
153  FSSpec fss;
154  if ((__path2fss(name, &fss) != fnfErr) && is_mac_dll(&fss)) {
155  return mac_open_dll(name, &fss);
156  }
157  return false;
158 }
159 
161  int b = mac_load_dll(expand_env_var(gargstr(1)));
162  ret((double) b);
163 }
164 #endif //! carbon
165 
167  w->rep()->MACpaint();
168 }
169 
171  BringToFront(w->rep()->macWindow());
172 }
173 
174 //---------------------------------------------------------
175 
176 
177 void Oc::cleanup() {
178  if (help_cursor_) {
179  delete help_cursor_;
180  }
181 }
182 
184  unmap();
185 }
186 
187 void PrintableWindow::xmove(int x, int y) {
188 #if carbon
189  MoveWindowStructure(Window::rep()->macWindow(), x, y);
190 #else
191  WindowPtr theWin = Window::rep()->macWindow();
192  MoveWindow(theWin, (x + 1), (y + 17), true);
193 #endif
194 }
196  WindowRep& w = *Window::rep();
197  if (w.bound()) {
198 #if carbon
199  Rect r;
200  GetWindowBounds(w.macWindow(), kWindowStructureRgn, &r);
201  return r.left;
202 #else
203  GrafPtr oldPort;
204  GetPort(&oldPort);
205  WindowPtr theWin = w.macWindow();
206  w.setport();
207  Point upperLeft;
208  upperLeft.h = theWin->portRect.left;
209  upperLeft.v = theWin->portRect.top;
210  LocalToGlobal(&upperLeft);
211  SetPort(oldPort);
212  return upperLeft.h - 1;
213 #endif
214  } else {
215  return 0;
216  }
217 }
219  WindowRep& w = *Window::rep();
220  if (w.bound()) {
221 #if carbon
222  Rect r;
223  GetWindowBounds(w.macWindow(), kWindowStructureRgn, &r);
224  return r.top;
225 #else
226  GrafPtr oldPort;
227  GetPort(&oldPort);
228  WindowPtr theWin = w.macWindow();
229  w.setport();
230  Point upperLeft;
231  upperLeft.h = theWin->portRect.left;
232  upperLeft.v = theWin->portRect.top;
233  LocalToGlobal(&upperLeft);
234  SetPort(oldPort);
235  return upperLeft.v - 17;
236 #endif
237  } else {
238  return 0;
239  }
240 }
241 
242 void PrintableWindow::xplace(int x, int y) {
243  WindowRep& wr = *Window::rep();
244  // printf("xplace %d %d %d\n", x, y,wr.bound());
245  if (wr.bound()) {
246  xmove(x, y);
247  } else {
248  xplace_ = true;
249 #if carbon
250  xleft_ = x;
251  xtop_ = y;
252 #else
253  xleft_ = x + 1;
254  xtop_ = y + 17;
255 #endif
256  }
257 }
259  DismissableWindow::default_geometry();
260  // the problem is that at this point the canvas size is not necessarly correct.
261  if (xplace_) {
262  pplace(xleft_, display()->pheight() - xtop_ - canvas()->pheight());
263  }
264 }
265 
266 // following analogy to MACwindow::MACpaint
267 static CGrafPtr cg_;
268 static GDHandle gd_;
269 
271  // printf("Rubberband::rubber_on\n");
272  // c->front_buffer();
273  GetGWorld(&cg_, &gd_);
274  WindowPtr mw = c->window()->rep()->macWindow();
275 #if carbon
276  SetGWorld(GetWindowPort(mw), GetMainDevice());
277 #else
278  SetGWorld((CGrafPort*) mw, GetMainDevice());
279 #endif
280 }
282  // c->back_buffer();
283  SetGWorld(cg_, gd_);
284 #ifdef MAC
285  // this prevents failure for all future paints ... I am not sure this is what we want
286  c->damage_all();
287 #endif
288  // printf("Rubberband::rubber_off\n");
289 }
290 
291 #if !defined(carbon)
292 IOHandler::IOHandler() {}
293 IOHandler::~IOHandler() {}
294 int IOHandler::inputReady(int) {
295  return 0;
296 }
297 int IOHandler::outputReady(int) {
298  return 0;
299 }
300 int IOHandler::exceptionRaised(int) {
301  return 0;
302 }
303 void IOHandler::timerExpired(long, long) {}
304 void IOHandler::childStatus(pid_t, int) {}
305 #endif
#define Window
Definition: _defines.h:333
#define Point
Definition: _defines.h:9
#define Canvas
Definition: _defines.h:65
#define WindowRep
Definition: _defines.h:335
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
virtual void unmap()
int xleft() const
Definition: ivocmac.cpp:195
int xtop() const
Definition: ivocmac.cpp:218
virtual void hide()
Definition: ivocmac.cpp:183
Definition: rect.h:44
Coord top() const
Definition: rect.h:153
Coord left() const
Definition: rect.h:144
void rubber_off(Canvas *)
Definition: ivocmac.cpp:281
void rubber_on(Canvas *)
Definition: ivocmac.cpp:270
#define c
static void display(int imenu)
Definition: fmenu.cpp:400
const char * expand_env_var(const char *s)
Definition: fileio.cpp:122
#define gargstr
Definition: hocdec.h:14
int(* Pfri)(void)
Definition: hocdec.h:39
void
bool mac_load_dll(const char *name)
Definition: ivocmac.cpp:152
void nrnbbs_post(const char *)
Definition: ivocmac.cpp:40
void nrnbbs_post_int(const char *, int)
Definition: ivocmac.cpp:41
void pwmimpl_redraw(Window *w)
carbon
Definition: ivocmac.cpp:166
bool is_mac_dll(FSSpec *)
Definition: ivocmac.cpp:70
void nrnbbs_exec(const char *)
Definition: ivocmac.cpp:58
void(* NrnBBSCallback)(const char *)
Definition: ivocmac.cpp:23
bool nrnbbs_take_int(const char *, int *)
Definition: ivocmac.cpp:47
static CGrafPtr cg_
Definition: ivocmac.cpp:267
void nrnbbs_disconnect()
Definition: ivocmac.cpp:35
bool nrnbbs_connect()
Definition: ivocmac.cpp:32
static int ndll
Definition: ivocmac.cpp:95
bool nrnbbs_take(const char *)
Definition: ivocmac.cpp:44
OSErr __path2fss(const char *name, FSSpec *)
void nrnbbs_wait(bool *pflag=(bool *) 0)
Definition: ivocmac.cpp:62
bool nrnbbs_look(const char *)
Definition: ivocmac.cpp:54
static GDHandle gd_
Definition: ivocmac.cpp:268
static long dllid[10]
Definition: ivocmac.cpp:96
void nrnbbs_post_string(const char *, const char *)
Definition: ivocmac.cpp:42
char * mktemp(char *)
Definition: ivocmac.cpp:27
bool nrnbbs_take_string(const char *, char *)
Definition: ivocmac.cpp:50
bool mac_open_dll(const char *, FSSpec *)
Definition: ivocmac.cpp:98
Symlist * hoc_built_in_symlist
Definition: ivocmac.cpp:76
void hoc_nrn_load_dll()
Definition: ivocmac.cpp:160
void nrnbbs_notify(const char *, NrnBBSCallback)
Definition: ivocmac.cpp:60
Symlist * hoc_symlist
void ivoc_bring_to_top(Window *w)
Definition: ivocmac.cpp:170
static long fsspec2id(FSSpec *fs)
Definition: ivocmac.cpp:80
bool nrnbbs_connected()
Definition: ivocmac.cpp:36
#define id
Definition: md1redef.h:33
#define i
Definition: md1redef.h:12
char * name
Definition: init.cpp:16
#define printf
Definition: mwprefix.h:26
size_t j
#define ret
Definition: redef.h:123
#define cnt
Definition: spt2queue.cpp:19
#define NULL
Definition: sptree.h:16
Definition: hocdec.h:84