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