NEURON
pwman.cpp
Go to the documentation of this file.
1 #include <../../nrnconf.h>
2 #include "gui-redirect.h"
3 
4 extern char* ivoc_get_temp_file();
5 extern int hoc_return_type_code;
6 
7 #if HAVE_IV
8 #if (MAC && !defined(carbon)) || defined(WIN32)
9 #define MACPRINT 1
10 #else
11 #define MACPRINT 0
12 #endif
13 
14 #if defined(WIN32) || MAC
15 #define SNAPSHOT 0
16 #else
17 #define SNAPSHOT 1
18 #endif
19 
20 #define DECO 2 // 1 means default on, 2 off. for Carnvale,Hines book figures
21 
22 #include <ivstream.h>
23 #include <string.h>
24 #include "ivoc.h"
25 #endif // HAVE_IV
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include "classreg.h"
29 #include "oc2iv.h"
30 
31 #if HAVE_IV
32 #include "utility.h"
33 
34 void single_event_run();
35 extern char** hoc_strpop();
36 
37 #ifdef MINGW
38 #include <IV-Win/mprinter.h>
39 void iv_display_scale(float);
40 void iv_display_scale(Coord, Coord); // Make if fit into the screen
41 extern "C" char* hoc_back2forward(char*);
42 #endif
43 
44 #if MAC && !defined(carbon)
45 #include <fstream.h>
46 #include <file_io.h>
47 #undef IOS_OUT
48 #define IOS_OUT (ios::out | ios::trunc)
49 extern char* mktemp(char*);
50 extern int unlink(const char*);
51 #include <IV-Mac/mprinter.h>
52 extern void debugfile(const char*, ...);
53 #else //! MAC
54 #include <unistd.h>
55 #define Output output
56 #endif // MAC
57 
58 
59 #include <IV-look/kit.h>
60 #include <IV-look/dialogs.h>
61 #include <InterViews/layout.h>
62 #include <InterViews/hit.h>
63 #include <InterViews/display.h>
64 #include <InterViews/session.h>
65 #include <InterViews/color.h>
66 #include <InterViews/brush.h>
67 #include <InterViews/font.h>
68 #include <InterViews/event.h>
69 #include <InterViews/handler.h>
70 #include <InterViews/printer.h>
71 #include <InterViews/style.h>
72 #include <InterViews/background.h>
73 #include <InterViews/label.h>
74 #include <OS/string.h>
75 #include "apwindow.h"
76 #include "scenevie.h"
77 #include "rect.h"
78 #include "ivoc.h"
79 #include "utility.h"
80 #include "ocbox.h"
81 #include "idraw.h"
82 #include "mymath.h"
83 #include "graph.h"
84 #include "oc2iv.h"
85 #include "rubband.h"
86 
87 // PGH begin
88 // static const float Scl = 10.;
89 // static const float pr_scl = 8.;
90 static float Scl;
91 static float pr_scl;
92 static PixelCoord pixres = 0;
93 // PGH end
94 
95 #if SNAPSHOT
96 extern bool (*ivoc_snapshot_)(const Event*);
97 static bool ivoc_snapshot(const Event*);
98 #endif
99 
100 #define PWM_help_ "help"
101 #define PWM_do_print_ "Print PWM"
102 #define PWM_ScreenItem_ "ScreenItem PWM"
103 #define PWM_PaperItem_ "PaperItem PWM"
104 #define PWM_landscape_ "LandPort Other"
105 #define PWM_virt_screen_ "VirtualScreen Other"
106 #define PWM_printer_control_ "SelectPrinter Other"
107 #define PWM_file_control_ "PostScript PrintToFile"
108 #define PWM_idraw_control_ "Idraw PrintToFile"
109 #define PWM_save_control2_ "SaveAll Session"
110 #define PWM_save_control1_ "SaveSelected Session"
111 #define PWM_retrieve_control_ "Retrieve Session"
112 #define PWM_tray_ "Tray Other"
113 #define PWM_ascii_ "Ascii PrintToFile"
114 #define PWM_quit_ "Quit Other"
115 
116 #define pwm_impl PrintableWindowManager::current()->pwmi_
117 class HocPanel {
118  public:
119  static void save_all(ostream&);
120 };
121 
122 int inside(Coord x, Coord y, const Allocation& a) {
123  if (x >= a.left() && x <= a.right() && y >= a.bottom() && y <= a.top()) {
124  return true;
125  } else {
126  return false;
127  }
128 }
129 
130 #define DBG 0
131 void print_alloc(Canvas* c, char* s, const Allocation& a) {
132 #if DBG || 1
133  printf("%s allocation %g %g %g %g\n", s, a.left(), a.bottom(), a.right(), a.top());
134  if (c) {
135  Extension e;
136  e.set(c, a);
137  printf(" canvas %g %g %g %g\n", e.left(), e.bottom(), e.right(), e.top());
138  }
139 #endif
140 }
141 
142 /* static */ class ScreenScene: public Scene {
143  public:
144  ScreenScene(Coord, Coord, Coord, Coord, Glyph* g = NULL);
145  virtual void pick(Canvas*, const Allocation&, int depth, Hit&);
146  virtual Coord mbs() const;
147 };
148 
149 /* static */ class PaperScene: public Scene {
150  public:
151  PaperScene(Coord, Coord, Coord, Coord, Glyph* g = NULL);
152  virtual Coord mbs() const;
153 };
154 
155 /* static */ class ScreenSceneHandler: public Handler {
156  public:
157  ScreenSceneHandler(Coord, Coord);
158  virtual bool event(Event&);
159 
160  private:
161  Coord x_, y_;
162 };
163 
164 class PaperItem;
165 
166 /*static*/ class ScreenItem: public Glyph {
167  public:
168  friend class PaperItem;
169  ScreenItem(PrintableWindow*);
170  ~ScreenItem();
171  virtual void request(Requisition&) const;
172  virtual void allocate(Canvas*, const Allocation&, Extension&);
173  virtual void draw(Canvas*, const Allocation&) const;
174  virtual void pick(Canvas*, const Allocation&, int depth, Hit&);
175  PrintableWindow* window() {
176  return w_;
177  }
178  void relabel(GlyphIndex);
179  // void reconfigured(Scene*);
180  PaperItem* paper_item() const {
181  return pi_;
182  }
183  GlyphIndex index() const {
184  return i_;
185  }
186  Object* group_obj_;
187  bool iconify_via_hide_;
188 
189  private:
190  Glyph* label_;
191  GlyphIndex i_;
193  PaperItem* pi_;
194 };
195 
196 /*static*/ class PaperItem: public Glyph {
197  public:
198  PaperItem(ScreenItem*);
199  ~PaperItem();
200  virtual void request(Requisition&) const;
201  virtual void allocate(Canvas*, const Allocation&, Extension&);
202  virtual void draw(Canvas*, const Allocation&) const;
203  // virtual void print(Printer*, const Allocation&) const;
204  virtual void pick(Canvas*, const Allocation&, int depth, Hit&);
205  void scale(float s) {
206  scale_ = s;
207  }
208  float scale() {
209  return scale_;
210  }
211  ScreenItem* screen_item() const {
212  return si_;
213  }
214  Coord width(); /* width of icon in pixels */
215  static Coord fsize_; // font height
216  private:
217 #if 1
218  friend class ScreenItem;
219 #else
220  // I prefer this but the SGI compiler doesn't like it
221  friend ScreenItem::~ScreenItem();
222 #endif
223  ScreenItem* si_;
224  float scale_;
225 };
226 
227 /*static*/ class PWMImpl {
228  public:
229  void append_paper(ScreenItem*);
230  void remove_paper(PaperItem*);
231  void unshow_paper(PaperItem*);
232  GlyphIndex paper_index(PaperItem*);
233  PaperScene* paper() {
234  return paper_;
235  }
236  ScreenScene* screen() {
237  return screen_;
238  }
239 
240  void help();
241 #if SNAPSHOT
242  void snapshot(const Event*);
243  Window* snap_owned(Printer*, Window*);
244  void snap(Printer*, Window*);
245  void snap_cursor(Printer*, const Event*);
246 #endif
247  void do_print0();
248  void do_print(bool printer, const char* name);
249  void do_print_session(bool also_controller = true);
250  void do_print_session(bool printer, const char* name);
251  void ps_file_print(bool, const char*, bool, bool);
252  void common_print(Printer*, bool, bool);
253 #if DECO
254  void print_deco(Printer*, Allocation& a, const char*);
255 #endif
256 #if MACPRINT
257  void mac_do_print();
258  MacPrinter* mprinter();
259  void paperscale();
260 #endif
261  void select_tool();
262  EventButton tool(EventButton);
263  void move_tool();
264  void resize_tool();
265  void landscape();
266  void landscape(bool);
267  bool is_landscape() {
268  return landscape_;
269  }
270  void deco(int);
271  void virt_screen();
272  void tray();
273  void printer_control();
274  void file_control();
275 #if SNAPSHOT
276  void snapshot_control();
277 #endif
278  bool file_control1();
279  void idraw_control();
280  void idraw_write(const char* fname, bool ses_style = false);
281  void ascii_control();
282  void ascii_write(const char* fname, bool ses_style = false);
283  void quit_control();
284  void save_selected_control();
285  void save_all_control();
286  void save_control(int);
287  void save_session(int, const char*, const char* head = NULL);
288  int save_group(Object*, const char*);
289  void retrieve_control();
290  float round(float);
291  float round_factor() {
292  return round_factor_;
293  }
294  void map_all();
295  void unmap_all();
296  StandardWindow* window();
297  void window(StandardWindow* w) {
298  w_ = w;
299  }
300  void all_window_bounding_box(Extension&, bool with_screen = true, bool also_controller = true);
301  void view_screen(Coord, Coord);
302  FileChooser* fc_save_;
303  const Color* window_outline_;
304  CopyString cur_ses_name_;
305 #if carbon
306  void all2front();
307 #endif
308  private:
309  friend class PrintableWindowManager;
310  PWMImpl(ScreenScene*, PaperScene*, Rect*);
311  ~PWMImpl();
312  GlyphIndex index(void*);
313  void relabel();
314  GlyphIndex upper_left();
315  void redraw(Window*);
316  bool none_selected(const char*, const char*) const;
317  void ses_group(ScreenItem* si, ostream& o);
318  int ses_group_first_;
319  void save_begin(ostream&);
320  void save_list(int, ScreenItem**, ostream&);
321 
322  private:
324  ScreenScene* screen_;
325  PaperScene* paper_;
326  View* pview_;
327  bool landscape_;
328  Rect* prect_;
329  bool use_printer;
330  bool printer_control_accept_;
331  String printer_;
332  FieldDialog* b_printer_;
333  FileChooser* fc_print_;
334  FileChooser* fc_idraw_;
335  FileChooser* fc_ascii_;
336  FileChooser* fc_retrieve_;
337  Coord canvasheight_;
338  float round_factor_;
339  TelltaleState* p_title_;
340  Glyph* left_; // ugh
341  EventButton tool_;
342  const Event* snap_event_;
343  bool print_leader_flag_;
344 #if DECO
345  TelltaleState* p_deco_;
346 #endif
347  Rect* screen_rect_;
348 #if MACPRINT
349  MacPrinter* mprinter_;
350 #endif
351 };
352 
353 /* static */ class VirtualWindow: public DismissableWindow {
354  public:
355  static void makeVirtualWindow();
356  static void view();
357  virtual ~VirtualWindow();
358 
359  private:
360  VirtualWindow(View*, Glyph*);
361 
362  private:
363  static VirtualWindow* virt_win_;
364  View* view_;
365 };
366 
367 VirtualWindow* VirtualWindow::virt_win_;
368 
369 #ifdef WIN32
370 
371 /* static */ class VirtualWindowScale: public Action {
372  public:
373  VirtualWindowScale(float);
374  virtual void execute();
375 
376  private:
377  float scale_;
378 };
379 #endif
380 
381 /*static*/ class PaperItem_handler: public Handler {
382  public:
383  enum { resize, move };
384  PaperItem_handler(int type, Coord x, Coord y, PaperItem*, const Transformer&);
385  virtual ~PaperItem_handler();
386  virtual bool event(Event&);
387 
388  private:
389  void resize_action(Coord, Coord);
390  void move_action(Coord, Coord);
391 
392  private:
393  void (PaperItem_handler::*action_)(Coord, Coord);
394  Transformer t_;
395  PaperItem* pi_;
396  GlyphIndex index_;
397 };
398 
399 /*static*/ class ScreenItemHandler: public Handler {
400  public:
401  ScreenItemHandler(Coord x, Coord y, ScreenItem*, const Transformer&);
402  virtual ~ScreenItemHandler();
403  virtual bool event(Event&);
404 
405  private:
406  void move_action(bool, Coord, Coord);
407 
408  private:
409  Transformer t_;
410  ScreenItem* si_;
411 };
412 
414 
415 /*static*/ class PWMDismiss: public WinDismiss {
416  public:
417  PWMDismiss(DismissableWindow*);
418  virtual ~PWMDismiss();
419  virtual void execute();
420 };
421 PWMDismiss::PWMDismiss(DismissableWindow* w)
422  : WinDismiss(w) {}
423 PWMDismiss::~PWMDismiss() {}
424 void PWMDismiss::execute() {
426  pwm_impl->unmap_all();
427  } else {
428  PrintableWindow::leader()->iconify();
429  }
430 }
431 
432 #else //! HAVE_IV
433 #ifdef MINGW
434 extern "C" char* hoc_back2forward(char*);
435 #endif
436 #endif // HAVE_IV
437 
438 extern Object** (*nrnpy_gui_helper_)(const char* name, Object* obj);
439 extern double (*nrnpy_object_to_double_)(Object*);
440 extern char** (*nrnpy_gui_helper3_str_)(const char* name, Object* obj, int handle_strptr);
441 
442 static void* pwman_cons(Object*) {
443  TRY_GUI_REDIRECT_OBJ("PWManager", NULL);
444  void* v = NULL;
445 #if HAVE_IV
446  IFGUI
448  ENDGUI
449 #endif
450  return v;
451 }
452 static void pwman_destruct(void* v) {
453  TRY_GUI_REDIRECT_NO_RETURN("~PWManager", v);
454 }
455 
456 static double pwman_count(void* v) {
457  int cnt = 0;
458  hoc_return_type_code = 1; // integer
459  TRY_GUI_REDIRECT_ACTUAL_DOUBLE("PWManager.count", v);
460 #if HAVE_IV
461  IFGUI
463  cnt = p->screen()->count();
464  ENDGUI
465 #endif
466  return double(cnt);
467 }
468 static double pwman_is_mapped(void* v) {
469  hoc_return_type_code = 2; // boolean
470  TRY_GUI_REDIRECT_ACTUAL_DOUBLE("PWManager.is_mapped", v);
471 #if HAVE_IV
472  IFGUI
474  int i = (int) chkarg(1, 0, p->screen()->count() - 1);
475  ScreenItem* si = (ScreenItem*) p->screen()->component(i);
476  if (si->window()) {
477  return double(si->window()->is_mapped());
478  }
479  ENDGUI
480 #endif
481  return 0.;
482 }
483 static double pwman_map(void* v) {
484  TRY_GUI_REDIRECT_ACTUAL_DOUBLE("PWManager.map", v);
485 #if HAVE_IV
486  IFGUI
488  int i = (int) chkarg(1, 0, p->screen()->count() - 1);
489  ScreenItem* si = (ScreenItem*) p->screen()->component(i);
490  if (si->window()) {
491  si->window()->map();
492  }
493  ENDGUI
494 #endif
495  return 0.;
496 }
497 static double pwman_hide(void* v) {
498  TRY_GUI_REDIRECT_ACTUAL_DOUBLE("PWManager.hide", v);
499 #if HAVE_IV
500  IFGUI
502  int i = (int) chkarg(1, 0, p->screen()->count() - 1);
503  ScreenItem* si = (ScreenItem*) p->screen()->component(i);
504  if (si->window()) {
505  si->window()->hide();
506  }
507  ENDGUI
508 #endif
509  return 0.;
510 }
511 static const char** pwman_name(void* v) {
512  TRY_GUI_REDIRECT_ACTUAL_STR("PWManager.name", v);
513 #if HAVE_IV
514  IFGUI
516  int i = (int) chkarg(1, 0, p->screen()->count() - 1);
517  ScreenItem* si = (ScreenItem*) p->screen()->component(i);
518  char** ps = hoc_temp_charptr();
519  if (si->window()) {
520  *ps = (char*) si->window()->name();
521  }
522  return (const char**) ps;
523  ENDGUI
524 #endif
525  return 0;
526 }
527 static double pwman_close(void* v) {
528  TRY_GUI_REDIRECT_ACTUAL_DOUBLE("PWManager.close", v);
529 #if HAVE_IV
530  IFGUI
532  int i = (int) chkarg(1, 0, p->screen()->count() - 1);
533  ScreenItem* si = (ScreenItem*) p->screen()->component(i);
534  if (p->window() == si->window()) {
535  p->window(NULL);
536  }
537  si->window()->dismiss();
538  ENDGUI
539 #endif
540  return 0.;
541 }
542 #ifdef MINGW
543 static void pwman_iconify1(void* v) {
544 #if HAVE_IV
545  IFGUI((PrintableWindow*) v)->dismiss();
546  ENDGUI
547 #endif
548 }
549 #endif
550 
551 static double pwman_iconify(void* v) {
552  TRY_GUI_REDIRECT_ACTUAL_DOUBLE("PWManager.iconify", v);
553 #if HAVE_IV
554  IFGUI
556 #ifdef MINGW
557  if (!nrn_is_gui_thread()) {
558  nrn_gui_exec(pwman_iconify1, pw);
559  return 0.;
560  }
561 #endif
562  pw->dismiss();
563  ENDGUI
564 #endif
565  return 0.;
566 }
567 static double pwman_deiconify(void* v) {
568  TRY_GUI_REDIRECT_ACTUAL_DOUBLE("PWManager.deiconify", v);
569 #if HAVE_IV
570  IFGUI
572  pw->map();
573  ENDGUI
574 #endif
575  return 0.;
576 }
577 static double pwman_leader(void* v) {
578  hoc_return_type_code = 1; // integer
579  TRY_GUI_REDIRECT_ACTUAL_DOUBLE("PWManager.leader", v);
580 #if HAVE_IV
581  IFGUI
584  int i, cnt = p->screen()->count();
585  for (i = 0; i < cnt; ++i) {
586  ScreenItem* si = (ScreenItem*) p->screen()->component(i);
587  if (si->window() == pw) {
588  return double(i);
589  }
590  }
591  ENDGUI
592 #endif
593  return -1.;
594 }
595 static double pwman_manager(void* v) {
596  hoc_return_type_code = 1; // integer
597  TRY_GUI_REDIRECT_ACTUAL_DOUBLE("PWManager.manager", v);
598 #if HAVE_IV
599  IFGUI
601  PrintableWindow* pw = p->window();
602  int i, cnt = p->screen()->count();
603  for (i = 0; i < cnt; ++i) {
604  ScreenItem* si = (ScreenItem*) p->screen()->component(i);
605  if (si->window() == pw) {
606  return double(i);
607  }
608  }
609  ENDGUI
610 #endif
611  return -1.;
612 }
613 
614 static double pwman_save(void* v) {
615  TRY_GUI_REDIRECT_ACTUAL_DOUBLE("PWManager.save", v);
616  int n = 0;
617 #if HAVE_IV
618  IFGUI
619  // if arg2 is an object then save all windows with that group_obj
620  // if arg2 is 1 then save all windows.
621  // if arg2 is 0 then save selected (on paper) windows.
623  if (ifarg(2)) {
624  if (hoc_is_object_arg(2)) {
625  n = p->save_group(*hoc_objgetarg(2), gargstr(1));
626  } else {
627  n = (int) chkarg(2, 0, 1);
628  p->save_session((n ? 2 : 0), gargstr(1), (ifarg(3) ? gargstr(3) : NULL));
629  }
630  }
631  ENDGUI
632 #endif
633  return (double) n;
634 }
635 
636 static Object** pwman_group(void* v) {
637  TRY_GUI_REDIRECT_ACTUAL_OBJ("PWManager.group", v);
638 #if HAVE_IV
639  IFGUI
641  int i;
642  i = int(chkarg(1, 0, p->screen()->count() - 1));
643  ScreenItem* si = (ScreenItem*) p->screen()->component(i);
644  if (ifarg(2)) {
645  hoc_obj_unref(si->group_obj_);
646  si->group_obj_ = *hoc_objgetarg(2);
647  hoc_obj_ref(si->group_obj_);
648  }
649  return hoc_temp_objptr(si->group_obj_);
650  ENDGUI
651 #endif
652  return hoc_temp_objptr(0);
653 }
654 
655 static double pwman_snap(void* v) {
656  TRY_GUI_REDIRECT_ACTUAL_DOUBLE("PWManager.snap", v);
657 #if HAVE_IV
658  IFGUI
659 #if SNAPSHOT
661  if (!ifarg(1)) {
662  p->snapshot_control();
663  }
664 #endif
665  return 1.;
666  ENDGUI
667 #endif
668  return 0;
669 }
670 
671 #ifdef MINGW
672 static double scale_;
673 static void pwman_scale1(void*) {
674 #if HAVE_IV
675  IFGUI
676  iv_display_scale(scale_);
677  ENDGUI
678 #endif
679 }
680 #endif
681 
682 static double pwman_scale(void* v) {
683  TRY_GUI_REDIRECT_ACTUAL_DOUBLE("PWManager.scale", v);
684  double scale = chkarg(1, .01, 100);
685 #if HAVE_IV
686  IFGUI
687 #if defined(WIN32)
688 #ifdef MINGW
689  if (!nrn_is_gui_thread()) {
690  scale_ = scale;
691  nrn_gui_exec(pwman_scale1, (void*) ((intptr_t) 1));
692  return scale;
693  }
694 #endif
695  iv_display_scale(scale);
696 #endif
697  ENDGUI
698 #endif
699  return scale;
700 }
701 
702 static double pwman_window_place(void* v) {
703  TRY_GUI_REDIRECT_ACTUAL_DOUBLE("PWManager.window_place", v);
704 #if HAVE_IV
705  IFGUI
706  int i;
708  i = int(chkarg(1, 0, p->screen()->count() - 1));
709  ScreenItem* si = (ScreenItem*) p->screen()->component(i);
710  if (si->window()) {
711  si->window()->xmove(int(*getarg(2)), int(*getarg(3)));
712  }
713  ENDGUI
714 #endif
715  return 1.;
716 }
717 
718 static double pwman_paper_place(void* v) {
719  TRY_GUI_REDIRECT_ACTUAL_DOUBLE("PWManager.paper_place", v);
720 #if HAVE_IV
721  IFGUI
722  // index, show=0 or 1
723  // index, x, y, scale where x and y in inches from left bottom
724  int i;
726  i = int(chkarg(1, 0, p->screen()->count() - 1));
727  ScreenItem* si = (ScreenItem*) p->screen()->component(i);
728  p->append_paper(si);
729  PaperItem* pi = si->paper_item();
730  if (!ifarg(3)) {
731  if ((int(chkarg(2, 0, 1))) == 0) {
732  p->unshow_paper(pi);
733  }
734  } else {
735  pi->scale(chkarg(4, 1e-4, 1e4));
736  p->paper()->move(p->paper_index(pi), *getarg(2) / pr_scl, *getarg(3) / pr_scl);
737  }
738  ENDGUI
739 #endif
740  return 1.;
741 }
742 
743 static double pwman_printfile(void* v) {
744  TRY_GUI_REDIRECT_ACTUAL_DOUBLE("PWManager.printfile", v);
745 #if HAVE_IV
746  IFGUI
747  // first arg is filename
748  // second arg is 0,1,2 refers to postscript, idraw, ascii mode
749  // third arg is 0,1 refers to selected, all
751  bool ses_style = false;
752  if (ifarg(3)) {
753  ses_style = int(chkarg(3, 0, 1)) ? true : false;
754  }
755  char* fname = gargstr(1);
756  switch ((int) chkarg(2, 0, 2)) {
757  case 0:
758  p->ps_file_print(false, fname, p->is_landscape(), ses_style);
759  break;
760  case 1:
761  p->idraw_write(fname, ses_style);
762  break;
763  case 2:
764  p->ascii_write(fname, ses_style);
765  break;
766  }
767  ENDGUI
768 #endif
769  return 1.;
770 }
771 
772 static double pwman_landscape(void* v) {
773  TRY_GUI_REDIRECT_ACTUAL_DOUBLE("PWManager.landscape", v);
774 #if HAVE_IV
775  IFGUI
777  p->landscape(int(chkarg(1, 0, 1)) ? true : false);
778  ENDGUI
779 #endif
780  return 1.;
781 }
782 
783 static double pwman_deco(void* v) {
784  TRY_GUI_REDIRECT_ACTUAL_DOUBLE("PWManager.deco", v);
785 #if HAVE_IV
786  IFGUI
788  p->deco(int(chkarg(1, 0, 2)));
789  ENDGUI
790 #endif
791  return 1.;
792 }
793 
794 static Member_func members[] = {"count",
795  pwman_count,
796  "is_mapped",
798  "map",
799  pwman_map,
800  "hide",
801  pwman_hide,
802  "close",
803  pwman_close,
804  "iconify",
806  "deiconify",
808  "leader",
809  pwman_leader,
810  "manager",
812  "save",
813  pwman_save,
814  "snap",
815  pwman_snap,
816  "scale",
817  pwman_scale,
818  "window_place",
820  "paper_place",
822  "printfile",
824  "landscape",
826  "deco",
827  pwman_deco,
828  0,
829  0};
830 
831 static Member_ret_obj_func retobj_members[] = {"group", pwman_group, 0, 0};
832 
833 static Member_ret_str_func s_memb[] = {"name", pwman_name, 0, 0};
834 
837 }
838 
839 #if HAVE_IV // almost to end of file
840 
841 // PaperItem_handler
842 
843 PaperItem_handler::PaperItem_handler(int type,
844  Coord x,
845  Coord y,
846  PaperItem* pi,
847  const Transformer& t) {
848  // printf("PaperItem_handler\n");
849  t_ = t;
850  pi_ = pi;
851  Resource::ref(pi);
852  index_ = pwm_impl->paper_index(pi);
853  Coord left, bottom;
854  pwm_impl->paper()->location(index_, left, bottom);
855  t_.invert();
856  switch (type) {
857  case resize:
858  action_ = &PaperItem_handler::resize_action;
859  break;
860  case move:
861  t_.translate(left - x, bottom - y);
862  action_ = &PaperItem_handler::move_action;
863  break;
864  }
865 }
866 
867 PaperItem_handler::~PaperItem_handler() {
868  // printf("~PaperItem_handler\n");
869  Resource::unref(pi_);
870 }
871 
872 bool PaperItem_handler::event(Event& e) {
873  // printf("PaperItem_handler::event (%g, %g)\n", e.pointer_x(), e.pointer_y());
874  switch (e.type()) {
875  case Event::down:
876  e.grab(this);
877 #ifdef WIN32
878  e.window()->grab_pointer();
879 #endif
880  (this->*action_)(e.pointer_x(), e.pointer_y());
881  break;
882  case Event::up:
883  e.ungrab(this);
884 #ifdef WIN32
885  e.window()->ungrab_pointer();
886 #endif
887  break;
888  case Event::motion:
889  (this->*action_)(e.pointer_x(), e.pointer_y());
890  break;
891  }
892  return true;
893 }
894 
895 void PaperItem_handler::move_action(Coord x, Coord y) {
896  // printf("move_action\n");
897  Coord xs, ys;
898  t_.transform(x, y, xs, ys);
899  xs = pwm_impl->round(xs);
900  ys = pwm_impl->round(ys);
901  pwm_impl->paper()->move(index_, xs, ys);
902 }
903 
904 void PaperItem_handler::resize_action(Coord x, Coord y) {
905  Allotment ax;
906  pwm_impl->paper()->allotment(index_, Dimension_X, ax);
907  Allotment ay;
908  pwm_impl->paper()->allotment(index_, Dimension_Y, ay);
909  Coord xs, ys;
910  t_.transform(x, y, xs, ys);
911  float scl = Math::max((xs - ax.begin()) / ax.span(), (ys - ay.begin()) / ay.span());
912  // printf("scl = %g\n", scl);
913  scl = pi_->scale() * scl;
914  scl = (scl > .1) ? scl : .1;
915  Coord w1;
916  w1 = pwm_impl->round(scl * pi_->width());
917  w1 = Math::max(w1, pwm_impl->round_factor());
918  scl = w1 / pi_->width();
919  pi_->scale(scl);
920  pwm_impl->paper()->modified(index_);
921 }
922 
923 VirtualWindow::VirtualWindow(View* v, Glyph* g)
924  : DismissableWindow(g, true) {
925  view_ = v;
926  view_->ref();
927 #ifdef WIN32
928  if (!style()) {
929  style(new Style(Session::instance()->style()));
930  style()->attribute("nrn_virtual_screen", "0");
931  }
932 
933  MenuItem* mi = append_menubar("Scale");
934  WidgetKit& wk = *WidgetKit::instance();
935  Menu* m = wk.pulldown();
936  mi->menu(m);
937 
938  mi = K::menu_item("normal");
939  mi->action(new VirtualWindowScale(1.0));
940  m->append_item(mi);
941 
942  mi = K::menu_item("see all");
943  mi->action(new VirtualWindowScale(fil));
944  m->append_item(mi);
945 
946  mi = K::menu_item("1.2");
947  mi->action(new VirtualWindowScale(1.2));
948  m->append_item(mi);
949 
950  mi = K::menu_item("1.5");
951  mi->action(new VirtualWindowScale(1.5));
952  m->append_item(mi);
953 
954  mi = K::menu_item("2.0");
955  mi->action(new VirtualWindowScale(2.0));
956  m->append_item(mi);
957 #endif
958 }
959 
960 VirtualWindow::~VirtualWindow() {
961  view_->unref();
962  virt_win_ = NULL;
963 }
964 #if defined(WIN32) || carbon
965 extern void ivoc_bring_to_top(Window*);
966 #endif
967 
968 void VirtualWindow::makeVirtualWindow() {
969  if (!virt_win_) {
970  View* v = new View(pwm_impl->screen());
971  virt_win_ = new VirtualWindow(v,
972  LayoutKit::instance()->variable_span(
973  new Background(v, WidgetKit::instance()->background())));
974  virt_win_->map();
975  }
976 #ifdef WIN32
977  ivoc_bring_to_top(virt_win_);
978 #endif
979 }
980 
981 void virtual_window_top() {
982  VirtualWindow::makeVirtualWindow();
983 }
984 
985 void VirtualWindow::view() {
986  if (virt_win_) {
987  View* v = virt_win_->view_;
988  Scene* s = v->scene();
989  v->size(s->x1(), s->y1(), s->x2(), s->y2());
990  virt_win_->canvas()->damage_all();
991  }
992 }
993 
994 #ifdef WIN32
995 VirtualWindowScale::VirtualWindowScale(float scale) {
996  scale_ = scale;
997 }
998 
1000  float scale = scale_;
1001  if (scale_ >= fil / 10.) {
1002  Extension e;
1003  pwm_impl->all_window_bounding_box(e);
1004  iv_display_scale(e.right() - e.left(), e.top() - e.bottom());
1005  } else {
1006  iv_display_scale(scale);
1007  }
1008 }
1009 #endif
1010 
1011 // ScreenItemHandler
1012 
1013 ScreenItemHandler::ScreenItemHandler(Coord x, Coord y, ScreenItem* si, const Transformer& t) {
1014  // printf("ScreenItemHandler\n");
1015  t_ = t;
1016  si_ = si;
1017  Resource::ref(si);
1018  Coord left, bottom;
1019  pwm_impl->screen()->location(si_->index(), left, bottom);
1020  t_.invert();
1021  t_.translate(left - x, bottom - y);
1022 }
1023 
1024 ScreenItemHandler::~ScreenItemHandler() {
1025  // printf("~ScreenItemHandler\n");
1026  Resource::unref(si_);
1027 }
1028 
1029 bool ScreenItemHandler::event(Event& e) {
1030  // printf("ScreenItemHandler::event (%g, %g)\n", e.pointer_x(), e.pointer_y());
1031  switch (e.type()) {
1032  case Event::down:
1033  e.grab(this);
1034 #ifdef WIN32
1035  e.window()->grab_pointer();
1036 #endif
1037  move_action(false, e.pointer_x(), e.pointer_y());
1038  break;
1039  case Event::up:
1040  e.ungrab(this);
1041 #ifdef WIN32
1042  e.window()->ungrab_pointer();
1043 #endif
1044  move_action(true, e.pointer_x(), e.pointer_y());
1045  break;
1046  case Event::motion:
1047  move_action(false, e.pointer_x(), e.pointer_y());
1048  break;
1049  }
1050  return true;
1051 }
1052 
1053 void ScreenItemHandler::move_action(bool doit, Coord x, Coord y) {
1054  // printf("move_action\n");
1055  Coord xs, ys;
1056  t_.transform(x, y, xs, ys);
1057  if (doit) {
1058  if (si_->window()) {
1059  si_->window()->move(xs * Scl, ys * Scl);
1060  }
1061  } else {
1062  pwm_impl->screen()->move(si_->index(), xs, ys);
1063  }
1064 }
1065 
1066 ScreenScene::ScreenScene(Coord x1, Coord y1, Coord x2, Coord y2, Glyph* g)
1067  : Scene(x1, y1, x2, y2, g) {}
1068 
1069 void ScreenScene::pick(Canvas* c, const Allocation& a, int depth, Hit& h) {
1070  if (pwm_impl->tool(h.event()->pointer_button()) == Event::middle) {
1071  if (h.event()->type() == Event::down) {
1072  h.target(depth, this, 0, new ScreenSceneHandler(h.left() * Scl, h.bottom() * Scl));
1073  }
1074  } else {
1075  Scene::pick(c, a, depth, h);
1076  }
1077 }
1078 
1079 Coord ScreenScene::mbs() const {
1080  return 0.;
1081 }
1082 
1083 PaperScene::PaperScene(Coord x1, Coord y1, Coord x2, Coord y2, Glyph* g)
1084  : Scene(x1, y1, x2, y2, g) {}
1085 
1086 Coord PaperScene::mbs() const {
1087  return 0.;
1088 }
1089 
1090 ScreenSceneHandler::ScreenSceneHandler(Coord x, Coord y)
1091  : Handler() {
1092  x_ = x;
1093  y_ = y;
1094 }
1095 bool ScreenSceneHandler::event(Event&) {
1096  pwm_impl->view_screen(x_, y_);
1097  return true;
1098 }
1099 
1100 // PrintableWindowManager
1101 
1102 declareActionCallback(PWMImpl) implementActionCallback(PWMImpl)
1103 
1105  if (!current_) {
1107  }
1108  return current_;
1109 }
1110 
1112  LayoutKit& layout = *LayoutKit::instance();
1113  WidgetKit& kit = *WidgetKit::instance();
1114  PaperItem::fsize_ = kit.font()->size();
1115  current_ = this;
1116  Display* d = Session::instance()->default_display();
1117 
1118  // PGH begin
1119  Coord canvasheight;
1120  Style* q = Session::instance()->style();
1121  if (!q->find_attribute("pwm_canvas_height", canvasheight)) {
1122  canvasheight = 100.;
1123  }
1124  const Color* outline_color;
1125  String c;
1126  Display* dis = Session::instance()->default_display();
1127  if (!q->find_attribute("pwm_screen_outline_color", c) ||
1128  (outline_color = Color::lookup(dis, c)) == NULL) {
1129  outline_color = Color::lookup(dis, "#ff0000");
1130  }
1131  Scl = d->height() / canvasheight;
1132  Rect* sr = new Rect(0, 0, d->width() / Scl, d->height() / Scl, outline_color);
1133  sr->ref();
1134  ScreenScene* screen = new ScreenScene(-5, -2, d->width() / Scl + 5, d->height() / Scl + 2, sr);
1135  Coord pageheight;
1136  Coord pagewidth;
1137  if (!q->find_attribute("pwm_paper_height", pageheight)) {
1138  pageheight = 11.;
1139  }
1140  if (!q->find_attribute("pwm_paper_width", pagewidth)) {
1141  pagewidth = 8.5;
1142  }
1143  Coord wp1;
1144  if (pageheight > pagewidth)
1145  pr_scl = pageheight / canvasheight;
1146  else
1147  pr_scl = pagewidth / canvasheight;
1148 
1149  // width = max(d->width/Scl,pagewidth/prl_scl,pageheight/prl_scl)
1150  if (d->width() > d->height())
1151  wp1 = d->width() / Scl;
1152  else
1153  wp1 = canvasheight;
1154 
1155  Coord wp = pagewidth / pr_scl;
1156  Coord hp = pageheight / pr_scl;
1157  Coord max = Math::max(wp, hp);
1158  Rect* r = new Rect(0, 0, wp, hp, outline_color);
1159  // wp1 = wp1*1.2;
1160  // Scene* paper = new Scene(-5, -1, hp*1.2, hp+1, r);
1161  PaperScene* paper = new PaperScene(-5, -2, Math::max(max, d->width() / Scl), max + 2, r);
1162 
1163  // PGH end
1164  pwmi_ = new PWMImpl(screen, paper, r);
1165  if (!q->find_attribute("pwm_window_outline_color", c) ||
1166  (outline_color = Color::lookup(dis, c)) == NULL) {
1167  outline_color = Color::lookup(dis, "#0000ff");
1168  }
1169  outline_color->ref();
1170  pwmi_->window_outline_ = outline_color;
1171  pwmi_->screen_rect_ = sr;
1172  if (!q->find_attribute("pwm_paper_resolution", pwmi_->round_factor_)) {
1173  pwmi_->round_factor_ = .25;
1174  }
1175  pwmi_->canvasheight_ = canvasheight;
1176  pwmi_->round_factor_ /= pr_scl;
1177  long ltmp;
1178  if (q->find_attribute("pwm_pixel_resolution", ltmp)) {
1179  pixres = (PixelCoord) ltmp;
1180  }
1181 
1182  PolyGlyph* hb = layout.hbox(6);
1183  pwmi_->left_ = hb;
1184  pwmi_->left_->ref();
1185 
1186  Menu *mbar, *mprint, *mses, *mother;
1187 #if 0
1188 #if !MAC
1189  if (q->value_is_on("pwm_help")) {
1190  vb->append(kit.push_button("Help",
1191  new ActionCallback(PWMImpl)(pwmi_, &PWMImpl::help)
1192  ));
1193  }
1194 #endif
1195 #endif
1196  hb->append(mbar = kit.menubar());
1197 
1198  MenuItem* mi;
1199 
1200  mi = kit.menubar_item("Print");
1201  mbar->append_item(mi);
1202  mprint = kit.pulldown();
1203  mi->menu(mprint);
1204 
1205  mi = kit.menubar_item("Session");
1206  mbar->append_item(mi);
1207  mses = kit.pulldown();
1208  mi->menu(mses);
1209 
1210 #if 0
1211  mi = kit.menubar_item("Other");
1212  mbar->append_item(mi);
1213  mother = kit.pulldown();
1214  mi->menu(mother);
1215 #endif
1216 
1217  TelltaleGroup* ttg = new TelltaleGroup();
1218  mi = kit.radio_menu_item(ttg, "select");
1219  mbar->append_item(mi);
1220  mi->state()->set(TelltaleState::is_chosen, true);
1221  mi->action(new ActionCallback(PWMImpl)(pwmi_, &PWMImpl::select_tool));
1222 
1223  mi = kit.radio_menu_item(ttg, "move");
1224  mbar->append_item(mi);
1225  mi->action(new ActionCallback(PWMImpl)(pwmi_, &PWMImpl::move_tool));
1226 
1227  mi = kit.radio_menu_item(ttg, "resize");
1228  mbar->append_item(mi);
1229  mi->action(new ActionCallback(PWMImpl)(pwmi_, &PWMImpl::resize_tool));
1230 
1231  mi = K::menu_item("To Printer");
1232  mprint->append_item(mi);
1233  mi->action(new ActionCallback(PWMImpl)(pwmi_, &PWMImpl::do_print0));
1234 #if 1 || !MAC
1235  mi = K::menu_item("PostScript");
1236  mprint->append_item(mi);
1237  mi->action(new ActionCallback(PWMImpl)(pwmi_, &PWMImpl::file_control));
1238 
1239 #if SNAPSHOT
1240  mi = K::menu_item("PS snapshot");
1241  mprint->append_item(mi);
1242  mi->action(new ActionCallback(PWMImpl)(pwmi_, &PWMImpl::snapshot_control));
1243 #endif
1244 #endif
1245 
1246  mi = K::menu_item("Idraw");
1247  mprint->append_item(mi);
1248  mi->action(new ActionCallback(PWMImpl)(pwmi_, &PWMImpl::idraw_control));
1249 
1250  mi = K::menu_item("Ascii");
1251  mprint->append_item(mi);
1252  mi->action(new ActionCallback(PWMImpl)(pwmi_, &PWMImpl::ascii_control));
1253 #if MAC && !defined(carbon)
1254  mi = K::menu_item("Setup Printer");
1255  mprint->append_item(mi);
1256  mi->action(new ActionCallback(PWMImpl)(pwmi_, &PWMImpl::paperscale));
1257 #else
1258  mi = K::menu_item("Select Printer");
1259  mprint->append_item(mi);
1260  mi->action(new ActionCallback(PWMImpl)(pwmi_, &PWMImpl::printer_control));
1261 #endif
1262 
1263  mi = K::check_menu_item("Window Titles Printed");
1264  mprint->append_item(mi);
1265  pwmi_->p_title_ = mi->state();
1266 
1267 #if DECO
1268  mi = K::check_menu_item("Window Decorations Printed");
1269  mprint->append_item(mi);
1270  pwmi_->p_deco_ = mi->state();
1271  // automatically on. comment out otherwise
1272 #if DECO == 1
1273  pwmi_->p_deco_->set(TelltaleState::is_chosen, true);
1274 #else
1275  pwmi_->p_deco_->set(TelltaleState::is_chosen, false);
1276 #endif
1277 #endif
1278 
1279  mi = K::menu_item("Retrieve");
1280  mses->append_item(mi);
1281  mi->action(new ActionCallback(PWMImpl)(pwmi_, &PWMImpl::retrieve_control));
1282 
1283  mi = K::menu_item("Save selected");
1284  mses->append_item(mi);
1285  mi->action(new ActionCallback(PWMImpl)(pwmi_, &PWMImpl::save_selected_control));
1286 
1287  mi = K::menu_item("Save all");
1288  mses->append_item(mi);
1289  mi->action(new ActionCallback(PWMImpl)(pwmi_, &PWMImpl::save_all_control));
1290 
1291  mi = K::menu_item("VirtualScreen");
1292  mses->append_item(mi);
1293  mi->action(new ActionCallback(PWMImpl)(pwmi_, &PWMImpl::virt_screen));
1294 
1295 #if 1 || !MAC
1296  mi = K::menu_item("Land/Port");
1297  mprint->append_item(mi);
1298  mi->action(new ActionCallback(PWMImpl)(pwmi_, &PWMImpl::landscape));
1299 #endif
1300 
1301  mi = K::menu_item("Tray");
1302  mses->append_item(mi);
1303  mi->action(new ActionCallback(PWMImpl)(pwmi_, &PWMImpl::tray));
1304 
1305 #if 0
1306  mi = K::menu_item("Quit");
1307  mother->append_item(mi);
1308  mi->action(new ActionCallback(PWMImpl)(pwmi_, &PWMImpl::quit_control));
1309 #endif
1310  if (PrintableWindow::leader() == NULL) {
1311  pwmi_->window();
1313  if (PrintableWindow::leader() != pwmi_->w_) {
1314  pwmi_->w_->replace_dismiss_action(NULL);
1315  }
1316 #if OCSMALL
1317  pwmi_->w_->xplace(-800, 0);
1318 #else
1319 #if MAC
1320  pwmi_->w_->xplace(0, 40);
1321 #else
1322  pwmi_->w_->xplace(0, 0);
1323 #endif
1324 #endif
1325  // pwmi_->w_->map();
1327  }
1329 }
1330 
1331 void PWMImpl::select_tool() {
1332  tool_ = Event::right;
1333 }
1334 void PWMImpl::move_tool() {
1335  tool_ = Event::left;
1336 }
1337 void PWMImpl::resize_tool() {
1338  tool_ = Event::middle;
1339 }
1340 
1341 EventButton PWMImpl::tool(EventButton b) {
1342  if (b == Event::left) {
1343  return tool_;
1344  }
1345  return b;
1346 }
1347 
1348 StandardWindow* PWMImpl::window() {
1349  if (w_ == NULL) {
1350  LayoutKit& layout = *LayoutKit::instance();
1352  w_ = new StandardWindow(
1353 #if 1
1354  layout.hbox(layout.variable_span(new View(screen_)),
1355  layout.variable_span(pview_ = new View(paper_))),
1356 #else
1357  new View(screen_),
1358 #endif
1359  left_, // really info
1360  NULL,
1361  NULL,
1362  NULL);
1364  Style* s = new Style(Session::instance()->style());
1365  s->attribute("name", "Print & File Window Manager");
1366  w_->style(s);
1367  }
1368  return w_;
1369 }
1370 
1372  // printf("~PrintableWindowManager\n");
1373  delete pwmi_;
1374  if (current_ == this) {
1375  current_ = NULL;
1376  }
1377 }
1378 
1379 void hoc_pwman_place() {
1380  TRY_GUI_REDIRECT_DOUBLE("pwman_place", NULL);
1381 #if HAVE_IV
1382  IFGUI
1383  int x, y;
1384  x = int(*getarg(1));
1385  y = int(*getarg(2));
1386  bool m = (ifarg(3) && int(*getarg(3)) == 0) ? false : true;
1388  ENDGUI
1389 #endif
1390  hoc_ret();
1391  hoc_pushx(0.);
1392 }
1393 
1394 void hoc_save_session() {
1395  TRY_GUI_REDIRECT_DOUBLE("save_session", NULL);
1396 #if HAVE_IV
1397  IFGUI
1398  if (pwm_impl) {
1399  pwm_impl->save_session(2, gargstr(1), (ifarg(2) ? gargstr(2) : NULL));
1400  }
1401  ENDGUI
1402 #endif
1403  hoc_ret();
1404  hoc_pushx(0.);
1405 }
1406 const char* pwm_session_filename() {
1407  if (pwm_impl) {
1408  return pwm_impl->cur_ses_name_.string();
1409  }
1410  return 0;
1411 }
1412 
1413 void hoc_print_session() {
1414  TRY_GUI_REDIRECT_DOUBLE("print_session", NULL);
1415 #if HAVE_IV
1416  IFGUI
1417  if (pwm_impl) {
1418  if (ifarg(3) && chkarg(3, 0, 1) == 1.) {
1419  pwm_impl->do_print((int) chkarg(1, 0, 1), gargstr(2));
1420  } else if (ifarg(2)) {
1421  pwm_impl->do_print_session((int) chkarg(1, 0, 1), gargstr(2));
1422  } else {
1423  bool b = ifarg(1) ? (chkarg(1, 0, 1) == 1.) : true;
1424  pwm_impl->do_print_session(b);
1425  }
1426  }
1427  ENDGUI
1428 #endif
1429  hoc_ret();
1430  hoc_pushx(0.);
1431 }
1432 
1433 void PrintableWindowManager::xplace(int left, int top, bool m) {
1434  PrintableWindow* w = pwm_impl->window();
1435  if (!w->is_mapped()) {
1437  if (pw && pw->is_mapped() && pw != w) {
1438  if (w->is_transient()) {
1439  w->transient_for(pw);
1440  } else {
1441  w->group_leader(pw);
1442  }
1443  }
1444  w->xplace(left, top);
1445  }
1446  if (m) {
1447  w->map();
1448  w->xmove(left, top);
1449  } else {
1450  w->hide();
1451  }
1452 #if MAC
1453  reconfigured(w);
1454 #endif
1455 }
1456 
1459  // printf("PrintableWindowManager::update(%p)\n", w);
1460  reconfigured(w);
1461 #if carbon
1462  if (w->leader() == w) {
1463  pwmi_->all2front();
1464  }
1465 #endif
1466 }
1467 
1469  // printf("disconnect %p\n", (PrintableWindow*)o);
1470 }
1471 
1473  // printf("PrintableWindowManager::append(%p)\n", w);
1474  if (w == NULL) {
1475  return;
1476  }
1477  w->attach(this);
1478  pwmi_->screen_->append(new ScreenItem(w));
1479  pwmi_->relabel();
1481  if (pw && pw->is_mapped() && pw != w) {
1482  if (w->is_transient()) {
1483  w->transient_for(pw);
1484  // printf("transient for %p\n", pw);
1485  } else {
1486  w->group_leader(pw);
1487  // printf("group leader is %p\n", pw);
1488  }
1489  }
1490 }
1491 
1492 
1494  // printf("PrintableWindowManager::remove(%p)\n", w);
1495  PWMImpl* impl = pwmi_;
1496  if (w == impl->window()) {
1497  impl->w_ = NULL;
1498  }
1499  // printf("remove %p\n", w);
1500  w->detach(this);
1501  Scene* s = impl->screen_;
1502  if (s) {
1503  GlyphIndex i = impl->index(w);
1504  if (i >= 0)
1505  s->remove(i);
1506  }
1507  impl->relabel();
1508 }
1509 
1510 #define PIXROUND(x, y, r) x = int((y + r / 2) / r) * r
1511 
1513  // only if leader
1514  if (this == leader()) {
1515  PrintableWindowManager::current()->pwmi_->map_all();
1516  }
1517 }
1518 
1520  if (!pixres) {
1521  return;
1522  }
1523  PixelCoord x, y, x1, y1;
1524  x1 = xleft();
1525  y1 = xtop();
1526  PIXROUND(x, x1, pixres);
1527  PIXROUND(y, y1, pixres);
1528  if (x != x1 || y != y1) {
1529  xmove(x, y);
1530  }
1531 }
1532 
1533 void ViewWindow::reconfigured() {
1534  if (!pixres) {
1535  return;
1536  }
1537  PixelCoord x, y, w, h;
1538  w = canvas()->pwidth();
1539  h = canvas()->pheight();
1540  PIXROUND(x, w, pixres);
1541  PIXROUND(y, h, pixres);
1542  if (x == 0)
1543  x = pixres;
1544  if (y == 0)
1545  y = pixres;
1546  if (x != w || y != h) {
1547  canvas()->psize(x, y);
1548  Window::resize();
1549  }
1551 }
1552 
1554  PWMImpl* impl = pwmi_;
1555 
1556  GlyphIndex i = impl->index(w);
1557  if (i < 0)
1558  return; // mswin after a ShowWindow(hwnd, SW_HIDE);
1559  Coord l = w->left_pw();
1560  Coord r = l + w->width_pw();
1561  Coord b = w->bottom_pw();
1562  Coord t = b + w->height_pw();
1563  impl->screen_->move(i, l / Scl, b / Scl);
1564  impl->screen_->change(i);
1565  impl->screen_->show(i, w->is_mapped());
1566  ScreenItem* si = (ScreenItem*) impl->screen_->component(i);
1567  PaperItem* pi = si->paper_item();
1568  if (pi) {
1569  impl->paper_->change(impl->paper_index(pi));
1570  }
1571  Extension e;
1572  impl->all_window_bounding_box(e);
1573  impl->screen_->new_size(e.left() / Scl - 5,
1574  e.bottom() / Scl - 2,
1575  e.right() / Scl + 5,
1576  e.top() / Scl + 2);
1577  VirtualWindow::view();
1578 #if DBG
1579  Coord x, y;
1580  impl->screen_->location(i, x, y);
1581  printf("reconfigured %d %d %g %g\n", i, impl->screen_->showing(i), x, y);
1582 #endif
1583 }
1584 
1586  pwmi_->do_print0();
1587 }
1588 
1589 void PWMImpl::help() {
1591  Oc::helpmode(w_);
1592  if (Oc::helpmode()) {
1593  Oc::help(PWM_help_);
1594  }
1595 }
1596 
1597 void PWMImpl::all_window_bounding_box(Extension& e, bool with_screen, bool also_leader) {
1598  GlyphIndex i;
1599  PrintableWindow* w;
1600  Display* d = Session::instance()->default_display();
1601  if (with_screen) {
1602  e.set_xy(NULL, 0., 0., d->width(), d->height());
1603  } else {
1604  e.clear();
1605  }
1607  bool empty = true;
1608  for (i = 0; i < screen_->count(); i++) {
1609  w = ((ScreenItem*) (screen_->component(i)))->window();
1610  if (w && w->is_mapped() && w != wl) {
1611  e.merge_xy(
1612  NULL, w->left(), w->bottom(), w->left() + w->width(), w->bottom() + w->height());
1613  empty = false;
1614  }
1615  }
1616  w = wl;
1617  if (w && w->is_mapped() && (also_leader || empty)) {
1618  e.merge_xy(NULL, w->left(), w->bottom(), w->left() + w->width(), w->bottom() + w->height());
1619  print_leader_flag_ = true;
1620  } else {
1621  print_leader_flag_ = false;
1622  }
1623  screen_rect_->width(d->width() / Scl);
1624  screen_rect_->height(d->height() / Scl);
1625  // printf("all_window_bounding_box %g %g %g %g\n", e.left(), e.bottom(), e.right(), e.top());
1626 }
1627 
1628 void PWMImpl::view_screen(Coord x, Coord y) {
1629  int xp, yp;
1630  // printf("view_sceen %g %g\n", x, y);
1631  GlyphIndex i;
1632  PrintableWindow* w;
1633  Display* d = Session::instance()->default_display();
1634  xp = d->to_pixels(-x) + d->pwidth() / 2;
1635  yp = d->to_pixels(y) - d->pheight() / 2;
1636  for (i = 0; i < screen_->count(); i++) {
1637  ScreenItem* si = (ScreenItem*) screen_->component(i);
1638  if (si->window()) {
1639  w = si->window();
1640  if (w != window()) {
1641  w->xmove(w->xleft() + xp, w->xtop() + yp);
1642  }
1643  }
1644  }
1645 }
1646 
1647 void PWMImpl::do_print0() {
1648  if (Oc::helpmode()) {
1649  Oc::help(PWM_do_print_);
1650  return;
1651  }
1652  if (use_printer) {
1653  if (none_selected("No windows to print", "Print Anyway")) {
1654  return;
1655  }
1656 #if MAC && !defined(carbon)
1657  if (!mprinter_) {
1658  continue_dialog("First select SetupPrinter");
1659  } else {
1660  mac_do_print();
1661  }
1662 #else
1663  if (!b_printer_) {
1664  printer_control();
1665  if (!printer_control_accept_) {
1666  Resource::unref(b_printer_);
1667  b_printer_ = NULL;
1668  return;
1669  }
1670  }
1671  CopyString name(b_printer_->text()->string());
1672  do_print(use_printer, name.string());
1673 #endif
1674  } else {
1675  if (!fc_print_) {
1676  file_control();
1677  return; // file_control calls do_print
1678  }
1679  do_print(use_printer, fc_print_->selected()->string());
1680  }
1681 }
1682 
1683 void PWMImpl::do_print(bool use_printer, const char* name) {
1684 #if MAC && !defined(carbon)
1685  if (use_printer) {
1686  mac_do_print();
1687  return;
1688  }
1689 #endif
1690 #if defined(WIN32)
1691  if (use_printer && strcmp(name, "Windows") == 0) {
1692  mac_do_print();
1693  return;
1694  }
1695 #endif
1696  ps_file_print(use_printer, name, landscape_, false);
1697 }
1698 
1699 void PWMImpl::do_print_session(bool also_leader) {
1700  // must work for mac, mswin, unix. All windows on screen
1701  // scale so on paper
1702  bool p = true;
1703 #if DECO
1704  bool deco = p_deco_->test(TelltaleState::is_chosen);
1705  p_deco_->set(TelltaleState::is_chosen, true);
1706 #endif
1707 
1708 #if MACPRINT
1709  Extension e;
1710 #if defined(WIN32)
1711  if (!mprinter()->get()) {
1712  return;
1713  }
1714 #endif
1715  all_window_bounding_box(e, false, also_leader);
1716  // want 1/2 inch margins
1717  float s1 = (mprinter()->width() - 72.) / (e.right() - e.left() + 6.); // with deco
1718  float s2 = (mprinter()->height() - 72.) / (e.top() - e.bottom() + 23.); // with deco
1719  float sfac = (s1 < s2) ? s1 : s2;
1720  float xoff = mprinter()->width() / 2 / sfac - (e.right() + e.left() + 6.) / 2.;
1721  float yoff = mprinter()->height() / 2 / sfac - (e.top() + e.bottom() + 23.) / 2.;
1722  Transformer t;
1723  t.translate(xoff, yoff);
1724 #if MAC && !defined(carbon)
1725  mprinter()->prolog();
1726  t.scale(sfac, sfac);
1727 #else
1728  mprinter()->prolog(sfac);
1729 #endif
1730  mprinter()->push_transform();
1731  mprinter()->transform(t);
1732  common_print(mprinter(), false, true);
1733  mprinter()->pop_transform();
1734  mprinter()->epilog();
1735 #endif
1736 
1737 #if (!MAC || DARWIN) && !defined(WIN32)
1738  // must be a postscript printer so can use landscape mode
1739  if (!b_printer_) {
1740  printer_control();
1741  if (!printer_control_accept_) {
1742  Resource::unref(b_printer_);
1743  b_printer_ = NULL;
1744  p = false;
1745  }
1746  }
1747  if (p) {
1748  CopyString name(b_printer_->text()->string());
1749  ps_file_print(true, name.string(), true, true);
1750  }
1751 #endif
1752 
1753 #if DECO
1754  p_deco_->set(TelltaleState::is_chosen, deco);
1755 #endif
1756  print_leader_flag_ = true;
1757 }
1758 
1759 void PWMImpl::do_print_session(bool use_printer, const char* name) {
1760  print_leader_flag_ = true;
1761  ps_file_print(use_printer, name, true, true);
1762 }
1763 
1764 void PWMImpl::ps_file_print(bool use_printer, const char* name, bool land_style, bool ses_style) {
1765  Style* s = Session::instance()->style();
1766  static char* tmpfile = (char*) 0;
1767  filebuf obuf;
1768 #if MAC && !DARWIN
1769  obuf.open(name, IOS_OUT);
1770 #else
1771  if (!tmpfile) {
1772  tmpfile = ivoc_get_temp_file();
1773  }
1774 #ifdef WIN32
1775  unlink(tmpfile);
1776 #endif
1777  obuf.open(tmpfile, IOS_OUT);
1778 #endif
1779  ostream o(&obuf);
1780  Printer* pr = new Printer(&o);
1781  pr->prolog();
1782 
1783  if (ses_style) {
1784 #if DECO
1785  bool deco = p_deco_->test(TelltaleState::is_chosen);
1786  p_deco_->set(TelltaleState::is_chosen, true);
1787 #endif
1788  Style* s = Session::instance()->style();
1789  Coord pageheight;
1790  Coord pagewidth;
1791  if (!s->find_attribute("pwm_paper_height", pageheight)) {
1792  pageheight = 11.;
1793  }
1794  if (!s->find_attribute("pwm_paper_width", pagewidth)) {
1795  pagewidth = 8.5;
1796  }
1797  Extension e;
1798  all_window_bounding_box(e, false, true);
1799  // want 1/2 inch margins
1800  float s1 = (pagewidth * 72 - 72.) / (e.right() - e.left() + 6.); // with deco
1801  float s2 = (pageheight * 72 - 72.) / (e.top() - e.bottom() + 23.); // with deco
1802  float sfac = (s1 < s2) ? s1 : s2;
1803  float xoff = pagewidth * 72 / 2 / sfac - (e.right() + e.left() + 6.) / 2.;
1804  float yoff = pageheight * 72 / 2 / sfac - (e.top() + e.bottom() + 23.) / 2.;
1805  Transformer t;
1806  t.translate(xoff, yoff);
1807  t.scale(sfac, sfac);
1808  pr->push_transform();
1809  pr->transform(t);
1810  common_print(pr, false, ses_style);
1811  pr->pop_transform();
1812 #if DECO
1813  p_deco_->set(TelltaleState::is_chosen, deco);
1814 #endif
1815  } else {
1816  common_print(pr, land_style, ses_style);
1817  }
1818  pr->epilog();
1819  obuf.close();
1820 #if !MAC || DARWIN
1821  String filt("cat");
1822  s->find_attribute("pwm_postscript_filter", filt);
1823  char* buf = new char[200 + strlen(name) + strlen(filt.string()) + 2 * strlen(tmpfile)];
1824 
1825  if (use_printer) {
1826 #ifdef WIN32
1827  sprintf(buf, "%s %s %s", filt.string(), tmpfile, name);
1828 #else
1829  sprintf(buf, "%s < %s | %s ; rm %s", filt.string(), tmpfile, name, tmpfile);
1830 #endif
1831  } else {
1832 #ifdef WIN32
1833  sprintf(buf, "%s %s > %s", filt.string(), tmpfile, name);
1834 #else
1835  sprintf(buf, "%s < %s > %s ; rm %s", filt.string(), tmpfile, name, tmpfile);
1836 #endif
1837  }
1838  // printf("%s\n", buf);
1839  nrnignore = system(buf);
1840  delete[] buf;
1841 #ifdef WIN32
1842  unlink(tmpfile);
1843 #endif
1844 #endif
1845  delete pr; // input handlers later crash doing pr->damage()
1846 }
1847 
1848 #ifdef WIN32
1849 extern bool hoc_copyfile(const char*, const char*);
1850 #endif
1851 
1852 #if MACPRINT
1853 void PWMImpl::mac_do_print() {
1854 #if defined(WIN32)
1855  if (!mprinter()->get()) {
1856  return;
1857  }
1858 #endif
1859  mprinter()->prolog();
1860  common_print(mprinter(), landscape_, false);
1861  mprinter()->epilog();
1862 }
1863 #endif
1864 
1865 void PWMImpl::common_print(Printer* pr, bool land_style, bool ses_style) {
1866  Scene* p;
1867  if (ses_style) {
1868  p = screen();
1869  } else {
1870  p = paper();
1871  }
1872  Style* s = Session::instance()->style();
1873  Coord pageheight;
1874  Coord pagewidth;
1875  if (!s->find_attribute("pwm_paper_height", pageheight)) {
1876  pageheight = 11.;
1877  }
1878  if (!s->find_attribute("pwm_paper_width", pagewidth)) {
1879  pagewidth = 8.5;
1880  }
1881  pr->resize(0, 0, pagewidth * 72, pageheight * 72);
1882  if (land_style) {
1883  Transformer t;
1884  t.rotate(-90);
1885  // t.translate(0, pageheight*72);
1886  if (ses_style) {
1887  t.translate(20, pr->height() - 70);
1888  } else {
1889  t.translate(0, pr->height());
1890  }
1891  pr->transform(t);
1892  }
1893  GlyphIndex count = p->count();
1894  for (GlyphIndex i = 0; i < count; ++i) {
1895  if (!p->showing(i)) {
1896  continue;
1897  }
1898  PrintableWindow* pw;
1899  float sfac;
1900  Transformer t;
1901  Coord x, y, x1, y1;
1902  if (ses_style) {
1903  ScreenItem* pi = (ScreenItem*) p->component(i);
1904  pw = pi->window();
1905  if (!pw->is_mapped()) {
1906  continue;
1907  } // probably the PFWM
1908  if (!print_leader_flag_ && pw == PrintableWindow::leader()) {
1909  continue;
1910  }
1911  float sfac = .9 * pagewidth * 72 / pw->display()->height();
1912  sfac = 1.;
1913  x = pw->left_pw();
1914  y = pw->bottom_pw();
1915  t.translate(x, y);
1916  t.scale(sfac, sfac);
1917  x1 = (x) *sfac;
1918  y1 = (y + pw->height_pw()) * sfac;
1919  } else {
1920  PaperItem* pi = (PaperItem*) p->component(i);
1921  pw = pi->screen_item()->window();
1922  float sfac = pr_scl * 72 * pi->scale() / Scl;
1923  p->location(i, x, y);
1924  t.scale(sfac, sfac);
1925  t.translate(72 * x * pr_scl, 72 * y * pr_scl);
1926  // t.translate((pr->width() - pagewidth*72)/2, (pr->height() - pageheight*72)/2);
1927  x1 = 72 * (x) *pr_scl;
1928  y1 = 72 * (y + pi->width() * pw->height_pw() / pw->width_pw() * pi->scale()) * pr_scl;
1929  }
1930  Requisition req;
1931  pw->print_glyph()->request(req);
1932  float align_x = req.x_requirement().alignment();
1933  float align_y = req.y_requirement().alignment();
1934  Allotment ax(align_x * pw->width_pw(), pw->width_pw(), align_x);
1935  Allotment ay(align_y * pw->height_pw(), pw->height_pw(), align_y);
1936  Allocation a;
1937  a.allot_x(ax);
1938  a.allot_y(ay);
1939 
1940  pr->push_transform();
1941  pr->transform(t);
1942  pr->push_clipping();
1943  pr->clip_rect(0, 0, pw->width_pw(), pw->height_pw());
1944 
1945  pw->print_glyph()->print(pr, a); // FieldEditor glyphs crash
1946  pr->pop_clipping();
1947 #if DECO
1948  if (p_deco_->test(TelltaleState::is_chosen) == true) {
1949  print_deco(pr, a, pw->name());
1950  }
1951 #endif
1952  pr->pop_transform();
1953 
1954  // flush the allocation tables for InputHandler glyphs so
1955  // no glyphs try to use the Printer after it has been deleted
1956  pw->print_glyph()->undraw();
1957 #if !MAC
1958  redraw(pw);
1959 #endif
1960  // print the window titles
1961  if ((ses_style || p_title_->test(TelltaleState::is_chosen) == true)
1962 #if DECO
1963  && p_deco_->test(TelltaleState::is_chosen) == false
1964 #endif
1965  ) {
1966  WidgetKit& wk = *WidgetKit::instance();
1967  Label label(pw->name(), wk.font(), wk.foreground());
1968  Requisition r;
1969  label.request(r);
1970  Allocation al;
1971  Allotment& alx = al.x_allotment();
1972  Allotment& aly = al.y_allotment();
1973  alx.origin(x1);
1974  alx.span(r.x_requirement().natural());
1975  aly.origin(y1);
1976  aly.span(r.y_requirement().natural());
1977  label.draw(pr, al);
1978  }
1979  }
1980 }
1981 
1982 #if DECO
1983 // for Carnevale, Hines book figures
1984 
1985 void PWMImpl::print_deco(Printer* pr, Allocation& a, const char* title) {
1986  WidgetKit& wk = *WidgetKit::instance();
1987  Coord l, b, r, t, w, h, s, x, y, dx, xx;
1988 
1989  // attributes
1990  static const Color* ctitle;
1991  static const Color* ctitlebar;
1992  static const Color* coutline;
1993  static const Color* bright;
1994  static const Color* dark;
1995  static const Font* ftitle;
1996  static const Brush* br;
1997  static int first = 1;
1998 
1999  w = 3;
2000  h = 20; // width of outer deco, height of title bar
2001  s = 2; // close button offset from bottom of title bar
2002  xx = 10; // x part of close button size
2003 
2004  if (first) {
2005  first = 0;
2006  bright = new Color(.9, .9, .9, 1.);
2007  bright->ref();
2008  dark = new Color(.1, .1, .1, 1.);
2009  dark->ref();
2010  ctitle = new Color(0., 0., 0., 1.);
2011  ctitle->ref();
2012  ctitlebar = new Color(.8, .8, .8, 1.);
2013  ctitlebar->ref();
2014  coutline = new Color(.7, .7, .7, 1.);
2015  coutline->ref();
2016  br = new Brush(1);
2017  br->ref();
2018  ftitle = wk.font();
2019  ftitle->ref();
2020  }
2021 
2022  l = a.left();
2023  b = a.bottom();
2024  r = a.right();
2025  t = a.top(); // inside
2026 
2027  // title bar
2028  pr->fill_rect(l, t, r, t + h, ctitlebar);
2029 
2030  // title
2031  Label label(title, ftitle, ctitle);
2032  Requisition req;
2033  label.request(req);
2034  x = req.x_requirement().natural();
2035  y = req.y_requirement().natural();
2036  Allocation al;
2037  Coord xo = (l + r) / 2 - x / 2;
2038  xo = (xo < h) ? h : xo;
2039  al.allot_x(Allotment(xo, x, 0.));
2040  al.allot_y(Allotment(t + h / 2 - y / 3, y, 0.));
2041  // clip the title
2042  pr->push_clipping();
2043  pr->clip_rect(l + h, t, r, t + h);
2044  label.draw(pr, al);
2045  pr->pop_clipping();
2046 
2047  // outline
2048  pr->fill_rect(l, b - w, l - w, t + h + w, coutline); // left
2049  pr->fill_rect(r, b - w, r + w, t + h + w, coutline); // right
2050  pr->fill_rect(l, b, r, b - w, coutline); // bottom
2051  pr->fill_rect(l, t + h, r, t + h + w, coutline); // top
2052  pr->rect(l - w, b - w, r + w, t + h + w, dark, br); // outside boundary
2053 
2054  // close button
2055  x = (l + (l + h - s)) / 2;
2056  y = (t + s + t + h) / 2;
2057  dx = (h - s) / 2;
2058  pr->rect(x - dx, y - dx, x + dx, y + dx, bright, br);
2059  dx = xx / 2;
2060  pr->line(x - dx, y - dx, x + dx, y + dx, bright, br); // the x
2061  pr->line(x - dx, y + dx, x + dx, y - dx, bright, br); // the x
2062 }
2063 #endif
2064 
2065 void PrintableWindowManager::psfilter(const char* filename) {
2066  static char* tmpfile = (char*) 0;
2067  if (!tmpfile) {
2068  tmpfile = ivoc_get_temp_file();
2069  }
2070  Style* s = Session::instance()->style();
2071  char buf[512];
2072  String filt("cat");
2073  if (s->find_attribute("pwm_postscript_filter", filt)) {
2074  sprintf(
2075  buf, "cat %s > %s; %s < %s > %s", filename, tmpfile, filt.string(), tmpfile, filename);
2076  nrnignore = system(buf);
2077  unlink(tmpfile);
2078  }
2079 }
2080 
2081 #if defined(WIN32) || MAC
2082 void pwmimpl_redraw(Window* pw);
2083 #endif
2084 
2085 void PWMImpl::redraw(Window* pw) {
2086  // redraw the canvas so HocValEditor fields show up
2087  if (!pw->is_mapped()) {
2088  return;
2089  }
2090  Canvas* c = pw->canvas();
2091  c->damage_all();
2092 #if defined(WIN32) || MAC
2093  pwmimpl_redraw(pw);
2094 #else
2095  Requisition req;
2096  Allocation a;
2097  Coord xsize = c->width();
2098  Coord ysize = c->height();
2099  pw->glyph()->request(req);
2100  Coord ox = xsize * req.x_requirement().alignment();
2101  Coord oy = ysize * req.y_requirement().alignment();
2102  a.allot_x(Allotment(ox, xsize, ox / xsize));
2103  a.allot_y(Allotment(oy, ysize, oy / ysize));
2104  Transformer t1;
2105  c->push_transform();
2106  c->transformer(t1);
2107  pw->glyph()->draw(c, a);
2108  c->pop_transform();
2109 #endif
2110 }
2111 
2112 // ScreenItem
2113 ScreenItem::ScreenItem(PrintableWindow* w) {
2114  w_ = w;
2115  label_ = NULL;
2116  pi_ = NULL;
2117  i_ = -1;
2118  group_obj_ = NULL;
2119  iconify_via_hide_ = false;
2120 }
2121 
2122 ScreenItem::~ScreenItem() {
2123  // printf("~ScreenItem\n");
2124  if (pi_) {
2125  pi_->si_ = NULL;
2126  if (pwm_impl) {
2127  pwm_impl->remove_paper(pi_);
2128  }
2129  Resource::unref(pi_);
2130  pi_ = NULL;
2131  }
2132  hoc_obj_unref(group_obj_);
2133  Resource::unref(label_);
2134 }
2135 
2136 void ScreenItem::relabel(GlyphIndex i) {
2137  char buf[10];
2138  sprintf(buf, "%ld", i);
2139  i_ = i;
2140  Glyph* g = WidgetKit::instance()->label(buf);
2141  Resource::ref(g);
2142  Resource::unref(label_);
2143  label_ = g;
2144 }
2145 
2146 #if 0
2147 void ScreenItem::reconfigured(Scene* s) {
2148  Coord l = w_->left_pw();
2149  Coord r = l + w_->width_pw();
2150  Coord b = w_->bottom_pw();
2151  Coord t = b + w_->height_pw();
2152  s->move(i, l/Scl, b/Scl);
2153  Coord x, y;
2154  s->location(i, x, y);
2155 #if DBG
2156  printf("reconfigured %d %d %g %g\n", i, s->showing(i), x, y);
2157 #endif
2158  if (w_->is_mapped()) {
2159  impl->w_->canvas()->damage_all();
2160  }
2161 }
2162 #endif
2163 
2164 void ScreenItem::request(Requisition& req) const {
2165  Coord w, h;
2166  if (w_) {
2167  w = w_->width_pw() / Scl;
2168  h = w_->height_pw() / Scl;
2169  }
2170  Requirement rx(w + 2);
2171  Requirement ry(h + 2);
2172  req.require_x(rx);
2173  req.require_y(ry);
2174 #if DBG
2175  printf("ScreenItem::request %d\n", index());
2176 #endif
2177 }
2178 
2179 void ScreenItem::allocate(Canvas* c, const Allocation& a, Extension& ext) {
2180  ext.set(c, a);
2181  MyMath::extend(ext, 1);
2182 #if DBG
2183  printf("ScreenItem::allocate %d\n", index());
2184 #endif
2185 }
2186 
2187 void ScreenItem::draw(Canvas* c, const Allocation& a) const {
2188 #if DBG
2189  printf("ScreenItem::draw %d\n", i_);
2190 // print_alloc(c,"draw", a);
2191 #endif
2192  Coord x = a.x();
2193  Coord y = a.y();
2194  if (w_) {
2195  c->rect(x,
2196  y,
2197  x + (w_->width_pw()) / Scl,
2198  y + (w_->height_pw()) / Scl,
2199  pwm_impl->window_outline_,
2200  NULL);
2201  }
2202  label_->draw(c, a);
2203 }
2204 
2205 void ScreenItem::pick(Canvas* c, const Allocation& a, int depth, Hit& h) {
2206  Coord x = h.left();
2207  Coord y = h.bottom();
2208  // if (x >= 0 && x <= w_->width_pw() && y >= 0 && y <= w_->height_pw()) {
2209  if (inside(x, y, a)) {
2210  h.target(depth, this, 0);
2211  if (h.event()->type() == Event::down) {
2212  if (Oc::helpmode()) {
2213  Oc::help(PWM_ScreenItem_);
2214  return;
2215  }
2216  switch (pwm_impl->tool(h.event()->pointer_button())) {
2217  case Event::left:
2218  h.target(depth, this, 0, new ScreenItemHandler(x, y, this, c->transformer()));
2219  break;
2220  case Event::right:
2221  if (w_) {
2222  pwm_impl->append_paper(this);
2223  }
2224  break;
2225  }
2226 #if DBG
2227  printf("ScreenItem::pick %d hit(%g,%g)\n", i_, x, y);
2228  print_alloc(NULL, "ScreenItem", a);
2229 #endif
2230  }
2231  }
2232 }
2233 
2234 
2235 // PaperItem
2236 PaperItem::PaperItem(ScreenItem* s) {
2237  scale_ = 1.;
2238  si_ = s;
2239  s->pi_ = this;
2240  ref();
2241 }
2242 PaperItem::~PaperItem() {
2243  // printf("~PaperItem\n");
2244  if (si_) {
2245  si_->pi_ = NULL;
2246  }
2247  si_ = NULL;
2248 }
2249 
2250 Coord PaperItem::width() {
2251  return si_->w_->width_pw() / Scl;
2252 }
2253 Coord PaperItem::fsize_;
2254 
2255 void PaperItem::request(Requisition& req) const {
2256  Requirement rx(scale_ * si_->w_->width_pw() / Scl);
2257  Requirement ry(Math::max(fsize_, scale_ * si_->w_->height_pw() / Scl));
2258  req.require_x(rx);
2259  req.require_y(ry);
2260 #if DBG
2261  printf("PaperItem::request %d\n", screen_item()->index());
2262 #endif
2263 }
2264 
2265 void PaperItem::allocate(Canvas* c, const Allocation& a, Extension& ext) {
2266  ext.set(c, a);
2267  MyMath::extend(ext, 1);
2268 #if DBG
2269  printf("PaperItem::allocate %d\n", screen_item()->index());
2270 #endif
2271 }
2272 
2273 void PaperItem::draw(Canvas* c, const Allocation& a) const {
2274 #if DBG
2275  printf("PaperItem::draw %d\n", si_->i_);
2276 #endif
2277  Coord x = a.x();
2278  Coord y = a.y();
2279  c->rect(x,
2280  y,
2281  x + scale_ * (si_->w_->width_pw()) / Scl,
2282  y + scale_ * (si_->w_->height_pw()) / Scl,
2283  pwm_impl->window_outline_,
2284  NULL);
2285  si_->label_->draw(c, a);
2286 }
2287 
2288 #if 0
2289 void PaperItem::print(Printer* pr, const Allocation& a) const {
2290  Coord x = a.x();
2291  Coord y = a.y();
2292  pr->rect(x, y, x + scale_*(si_->w_->width_pw())/Scl, y + scale_*(si_->w_->height_pw())/Scl, blue, NULL);
2293  pr->push_transform();
2294  Transformer t(scale_/Scl, 0, 0, scale_/Scl, 0, 0);
2295  Allocation b = a;
2296  pr->transform(t);
2297  si_->w_->glyph()->print(pr, a);
2298  pr->pop_transform();
2299 }
2300 #endif
2301 void PaperItem::pick(Canvas* c, const Allocation& a, int depth, Hit& h) {
2302  Coord x = h.left();
2303  Coord y = h.bottom();
2304  if (::inside(x, y, a)) {
2305  h.target(depth, this, 0);
2306  if (h.event()->type() == Event::down) {
2307  if (Oc::helpmode()) {
2308  Oc::help(PWM_PaperItem_);
2309  return;
2310  }
2311  switch (pwm_impl->tool(h.event()->pointer_button())) {
2312  case Event::left:
2313  h.target(
2314  depth,
2315  this,
2316  0,
2317  new PaperItem_handler(PaperItem_handler::move, x, y, this, c->transformer()));
2318  break;
2319  case Event::middle:
2320  h.target(
2321  depth,
2322  this,
2323  0,
2324  new PaperItem_handler(PaperItem_handler::resize, x, y, this, c->transformer()));
2325  break;
2326  case Event::right:
2327  pwm_impl->unshow_paper(this);
2328  break;
2329  }
2330 #if DBG
2331  printf("PaperItem::pick %d hit(%g, %g)\n", si_->i_, x, y);
2332 #endif
2333  }
2334  }
2335 }
2336 
2337 // PWMImpl
2338 PWMImpl::PWMImpl(ScreenScene* screen, PaperScene* paper, Rect* prect) {
2339  screen_ = screen;
2340  paper_ = paper;
2341  Resource::ref(screen);
2342  Resource::ref(paper);
2343  w_ = NULL;
2344  landscape_ = false;
2345  prect_ = prect;
2346  printer_ = "lp";
2347  use_printer = true;
2348  printer_control_accept_ = true;
2349  b_printer_ = NULL;
2350  fc_print_ = NULL;
2351  fc_idraw_ = NULL;
2352  fc_ascii_ = NULL;
2353  fc_save_ = NULL;
2354  fc_retrieve_ = NULL;
2355  p_title_ = NULL;
2356 #if MACPRINT
2357  mprinter_ = NULL;
2358 #endif
2359  tool_ = Event::right;
2360 }
2361 
2362 PWMImpl::~PWMImpl() {
2363  // printf("~PWMImpl\n");
2364  Resource::unref(screen_);
2365  screen_ = NULL;
2366  Resource::unref(paper_);
2367  paper_ = NULL;
2368  Resource::unref(b_printer_);
2369  Resource::unref(fc_print_);
2370  Resource::unref(fc_idraw_);
2371  Resource::unref(fc_ascii_);
2372  Resource::unref(fc_save_);
2373  Resource::unref(fc_retrieve_);
2374  Resource::unref(screen_rect_);
2375 #if MACPRINT
2376  if (mprinter_) {
2377  delete mprinter_;
2378  }
2379 #endif
2380 }
2381 
2382 #if MACPRINT
2383 MacPrinter* PWMImpl::mprinter() {
2384  if (!mprinter_) {
2385  mprinter_ = new MacPrinter();
2386  }
2387  return mprinter_;
2388 }
2389 #endif
2390 
2391 #if carbon
2392 void PWMImpl::all2front() {
2393  int i;
2394  PrintableWindow* w;
2395  if (screen_)
2396  for (i = 0; i < screen_->count(); ++i) {
2397  ScreenItem* si = (ScreenItem*) (screen_->component(i));
2398  w = si->window();
2399  if (w && w != w->leader() && w->is_mapped()) {
2400  ivoc_bring_to_top(w);
2401  }
2402  }
2403 }
2404 #endif
2405 
2406 void PWMImpl::map_all() {
2407  GlyphIndex i;
2409  PrintableWindow* w;
2410  if (screen_)
2411  for (i = 0; i < screen_->count(); i++) {
2412  ScreenItem* si = (ScreenItem*) (screen_->component(i));
2413  w = si->window();
2414  if (w) {
2415  if (w != pw) {
2416  if (si->iconify_via_hide_ == true) {
2417  w->map();
2418  }
2419  } else {
2420  // w->deiconify();
2421  }
2422  }
2423  }
2424 }
2425 void PWMImpl::unmap_all() {
2426  GlyphIndex i;
2428  PrintableWindow* w;
2429  if (screen_)
2430  for (i = 0; i < screen_->count(); i++) {
2431  ScreenItem* si = (ScreenItem*) (screen_->component(i));
2432  w = si->window();
2433  if (w) {
2434  if (w != pw) {
2435  if (screen_->showing(i)) {
2436  w->hide();
2437  si->iconify_via_hide_ = true;
2438  } else {
2439  si->iconify_via_hide_ = false;
2440  }
2441  } else {
2442  w->iconify();
2443  }
2444  }
2445  }
2446 }
2447 
2448 GlyphIndex PWMImpl::index(void* w) {
2449  GlyphIndex i;
2450  if (screen_)
2451  for (i = 0; i < screen_->count(); i++) {
2452  ScreenItem* si = (ScreenItem*) screen_->component(i);
2453  if (w == (void*) si->window()) {
2454  return i;
2455  }
2456  }
2457  return -1;
2458 }
2459 
2460 void PWMImpl::relabel() {
2461  GlyphIndex i;
2462  for (i = 0; i < screen_->count(); i++) {
2463  ((ScreenItem*) screen_->component(i))->relabel(i);
2464  }
2465  // if (w_) {
2466  // w_->canvas()->damage_all();
2467  // };
2468 }
2469 
2470 void PWMImpl::append_paper(ScreenItem* si) {
2471  PaperItem* pi = si->paper_item();
2472  GlyphIndex i;
2473  if (pi) {
2474  i = paper_index(pi);
2475  paper_->show(i, true);
2476  } else {
2477  pi = new PaperItem(si);
2478  pi->scale(.9);
2479  paper_->append(pi);
2480  i = paper_index(pi);
2481  Coord x = si->window()->left_pw() / Scl;
2482  Coord y = si->window()->bottom_pw() / Scl;
2483  x = (x < 0.) ? 0. : x;
2484  y = (y < 0.) ? 0. : y;
2485  x = (x > paper_->x2() * .8) ? paper_->x2() * .8 : x;
2486  y = (y > paper_->y2() * .8) ? paper_->y2() * .8 : y;
2487  paper_->move(i, x, y);
2488  }
2489  paper_->change(i);
2490 }
2491 
2492 void PWMImpl::unshow_paper(PaperItem* pi) {
2493  paper_->show(paper_index(pi), false);
2494 }
2495 
2496 void PWMImpl::remove_paper(PaperItem* pi) {
2497  GlyphIndex i = paper_index(pi);
2498  if (paper_ && i != -1) {
2499  paper_->remove(i);
2500  }
2501 }
2502 
2503 GlyphIndex PWMImpl::paper_index(PaperItem* pi) {
2504  GlyphIndex i;
2505  if (paper_)
2506  for (i = 0; i < paper_->count(); i++) {
2507  if (pi == (PaperItem*) paper_->component(i)) {
2508  return i;
2509  }
2510  }
2511  return -1;
2512 }
2513 
2514 float PWMImpl::round(float x) {
2515  return Math::round(x / round_factor_) * round_factor_;
2516 }
2517 
2518 #if MACPRINT
2519 void PWMImpl::paperscale() {
2520  mprinter()->setup();
2521  Coord w, h, x;
2522  w = mprinter()->width() / 72.;
2523  x = h = mprinter()->height() / 72.;
2524  if (w > h) {
2525  x = w;
2526  }
2527  x = x / canvasheight_;
2528  prect_->width(w / pr_scl);
2529  prect_->height(h / pr_scl);
2530  pview_->box_size(-.2, -.2, prect_->width() + .2, prect_->height() + .2);
2531 
2532  paper_->damage_all();
2533 }
2534 #endif
2535 
2536 
2537 void PWMImpl::landscape() {
2538  if (Oc::helpmode()) {
2539  Oc::help(PWM_landscape_);
2540  }
2541  Coord w, h;
2542  w = prect_->width();
2543  h = prect_->height();
2544  prect_->width(h);
2545  prect_->height(w);
2546  paper_->damage_all();
2547  landscape_ = !landscape_;
2548 }
2549 
2550 void PWMImpl::landscape(bool b) {
2551  if (landscape_ != b) {
2552  landscape();
2553  }
2554 }
2555 
2556 void PWMImpl::deco(int i) {
2557  p_title_->set(TelltaleState::is_chosen, false);
2558  p_deco_->set(TelltaleState::is_chosen, false);
2559  if (i == 1) {
2560  p_title_->set(TelltaleState::is_chosen, true);
2561  } else if (i == 2) {
2562  p_deco_->set(TelltaleState::is_chosen, true);
2563  }
2564 }
2565 
2566 void PWMImpl::virt_screen() {
2567  if (Oc::helpmode()) {
2568  Oc::help(PWM_virt_screen_);
2569  return;
2570  }
2571  VirtualWindow::makeVirtualWindow();
2572 }
2573 
2574 // grabbed from unidraw dialogs.cpp
2575 static const char* DefaultPrintCmd() {
2576 #ifdef WIN32
2577  Style* style = Session::instance()->style();
2578  static String str;
2579  if (style->find_attribute("printer_command", str)) {
2580  ;
2581  } else {
2582  str = " > prn";
2583  }
2584  return str.string();
2585 #else
2586  static char buf[200];
2587  static const char* print_cmd = getenv("PRINT_CMD");
2588  if (print_cmd == NULL) {
2589  const char* printer_name = getenv("PRINTER");
2590 
2591  if (printer_name == NULL) {
2592  sprintf(buf, "lpr");
2593  } else {
2594  sprintf(buf, "lpr -P%s", printer_name);
2595  }
2596  print_cmd = buf;
2597  }
2598  return print_cmd;
2599 #endif
2600 }
2601 
2602 void PWMImpl::printer_control() {
2603  if (Oc::helpmode()) {
2604  Oc::help(PWM_printer_control_);
2605  }
2606  if (!b_printer_) {
2607  Style* style = new Style(Session::instance()->style());
2608  style->attribute("caption", "Postscript Printer Command");
2609  b_printer_ = FieldDialog::field_dialog_instance(DefaultPrintCmd(), style);
2610  b_printer_->ref();
2611  }
2612  use_printer = true;
2613  bool b;
2614  if (w_ && w_->is_mapped()) {
2615  b = b_printer_->post_for(w_);
2616  } else {
2617  Coord x, y, ax, ay;
2618  if (nrn_spec_dialog_pos(x, y)) {
2619  ax = 0.0;
2620  ay = 0.0;
2621  } else { // original default
2622  x = 300.;
2623  y = 500.;
2624  ax = 0.5;
2625  ay = 0.5;
2626  }
2627 
2628  b = b_printer_->post_at_aligned(x, y, ax, ay);
2629  }
2630  if (b) {
2631  printer_control_accept_ = true;
2632  } else {
2633  printer_control_accept_ = false;
2634  }
2635 }
2636 
2637 void PWMImpl::quit_control() {
2638  if (Oc::helpmode()) {
2639  Oc::help(PWM_quit_);
2640  return;
2641  }
2642 
2643  if (boolean_dialog("Quit. Are you sure?", "Yes", "No", w_)) {
2644  Oc oc;
2645  oc.run("quit()\n");
2646  }
2647 }
2648 
2649 #if SNAPSHOT
2650 void PWMImpl::snapshot_control() {
2651  if (file_control1()) {
2652  ivoc_snapshot_ = ivoc_snapshot;
2653  }
2654 }
2655 #endif
2656 
2657 bool PWMImpl::file_control1() {
2658  if (Oc::helpmode()) {
2659  Oc::help(PWM_file_control_);
2660  }
2661  if (!fc_print_) {
2662  Style* style = new Style(Session::instance()->style());
2663  String str;
2664  if (style->find_attribute("pwm_print_file_filter", str)) {
2665  style->attribute("filter", "true");
2666  style->attribute("filterPattern", str);
2667  }
2668  style->attribute("caption", "Print Postscript to file");
2669  style->attribute("open", "Print to file");
2670  fc_print_ = DialogKit::instance()->file_chooser("./", style);
2671  fc_print_->ref();
2672  } else {
2673  fc_print_->reread();
2674  }
2675  while (fc_print_->post_for(w_)) {
2676  if (ok_to_write(*fc_print_->selected(), w_)) {
2677  return true;
2678  }
2679  }
2680  return false;
2681 }
2682 
2683 void PWMImpl::file_control() {
2684  if (none_selected("No windows to save", "Save Anyway")) {
2685  return;
2686  }
2687  if (file_control1()) {
2688  use_printer = false;
2689  do_print0();
2690  use_printer = true;
2691  }
2692 }
2693 
2694 #if SNAPSHOT
2695 void PWMImpl::snapshot(const Event* e) {
2696  snap_event_ = e;
2697  filebuf obuf;
2698  obuf.open(fc_print_->selected()->string(), IOS_OUT);
2699  ostream o(&obuf);
2700  Printer* pr = new Printer(&o);
2701  pr->prolog();
2702  pr->resize(0, 0, 1200, 1000);
2703  Window* w = e->window();
2704  snap_owned(pr, w);
2705  // for (w = e->window(); w; w = snap_owned(w)) {
2706  // snap(pr, w);
2707  // }
2708  snap_cursor(pr, e);
2709  pr->epilog();
2710  obuf.close();
2711  delete pr;
2712 }
2713 
2714 void PWMImpl::snap(Printer* pr, Window* w) {
2715  Transformer t;
2716  t.translate(w->left(), w->bottom());
2717  Requisition req;
2718  Glyph* g = w->Window::glyph();
2719  g->request(req);
2720  float align_x = req.x_requirement().alignment();
2721  float align_y = req.y_requirement().alignment();
2722  Allotment ax(align_x * w->width(), w->width(), align_x);
2723  Allotment ay(align_y * w->width(), w->height(), align_y);
2724  Allocation a;
2725  a.allot_x(ax);
2726  a.allot_y(ay);
2727  // printf("left=%g right=%g top=%g bottom=%g\n", a.left(), a.right(), a.top(), a.bottom());
2728  t.translate(a.left(), -a.bottom());
2729  Style* s = w->style();
2730  String str;
2731  bool pd = false;
2732  if (s && s->find_attribute("name", str)) {
2733  pd = true;
2734  pr->comment(str.string());
2735  }
2736  char buf[256];
2737  if (pd) {
2738  sprintf(buf,
2739  "BoundingBox: %g %g %g %g",
2740  w->left() - 3,
2741  w->bottom() - 3,
2742  w->left() + w->width() + 3,
2743  w->bottom() + w->height() + 20 + 3);
2744  pr->comment(buf);
2745  sprintf(buf, "\\begin{picture}(%g, %g)", w->width() + 6, w->height() + 23);
2746  pr->comment(buf);
2747  } else {
2748  sprintf(buf,
2749  "BoundingBox: %g %g %g %g",
2750  w->left(),
2751  w->bottom(),
2752  w->left() + w->width(),
2753  w->bottom() + w->height());
2754  pr->comment(buf);
2755  sprintf(buf, "\\begin{picture}(%g, %g)", w->width(), w->height());
2756  pr->comment(buf);
2757  }
2758  pr->push_transform();
2759  pr->transform(t);
2760  g->print(pr, a);
2761  if (pd) {
2762  print_deco(pr, a, str.string());
2763  }
2764  g->undraw();
2765  pr->pop_transform();
2766  // at this point cursor will be below any pop up windows so must be done last
2767  // if (w == snap_event_->window()) {
2768  // snap_cursor(pr, snap_event_);
2769  // }
2770  pr->comment("End BoundingBox");
2771 }
2772 
2773 void PWMImpl::snap_cursor(Printer* pr, const Event* e) {
2775  if (rb && rb->canvas()->window() == e->window()) {
2776  pr->comment("Begin Rubberband");
2777  Transformer t1;
2778  t1.translate(e->window()->left(), e->window()->bottom());
2779  pr->push_transform();
2780  pr->transform(t1);
2781  rb->snapshot(pr);
2782  pr->pop_transform();
2783  pr->comment("End Rubberband");
2784  }
2785 
2786  Coord x, y;
2787  x = e->pointer_x();
2788  y = e->pointer_y();
2789 
2790  Transformer t;
2791  t.rotate(30);
2792  t.translate(e->window()->left(), e->window()->bottom());
2793  t.translate(x, y);
2794  pr->comment("Begin cursor");
2795  pr->push_transform();
2796  pr->transform(t);
2797  pr->new_path();
2798  pr->move_to(0, 0);
2799  pr->line_to(8, -14);
2800  pr->line_to(2, -12);
2801  pr->line_to(2, -20);
2802  pr->line_to(-2, -20);
2803  pr->line_to(-2, -12);
2804  pr->line_to(-8, -14);
2805  pr->close_path();
2806  pr->fill(WidgetKit::instance()->foreground());
2807  pr->stroke(WidgetKit::instance()->background(), Appear::default_brush());
2808  pr->pop_transform();
2809  pr->comment("End cursor");
2810 }
2811 #endif
2812 
2813 void PWMImpl::idraw_control() {
2814  if (Oc::helpmode()) {
2815  Oc::help(PWM_idraw_control_);
2816  }
2817  if (!fc_idraw_) {
2818  Style* style = new Style(Session::instance()->style());
2819  String str;
2820  if (style->find_attribute("pwm_idraw_file_filter", str)) {
2821  style->attribute("filter", "true");
2822  style->attribute("filterPattern", str);
2823  }
2824  style->attribute("caption", "Idraw format to file");
2825  style->attribute("open", "Write to file");
2826  fc_idraw_ = DialogKit::instance()->file_chooser("./", style);
2827  fc_idraw_->ref();
2828  } else {
2829  fc_idraw_->reread();
2830  }
2831  if (none_selected("No windows to save", "Save Anyway")) {
2832  return;
2833  }
2834  while (fc_idraw_->post_for(w_)) {
2835  if (ok_to_write(*fc_idraw_->selected(), w_)) {
2836  idraw_write(fc_idraw_->selected()->string());
2837  break;
2838  }
2839  }
2840 }
2841 
2842 void PWMImpl::idraw_write(const char* fname, bool ses_style) {
2843 #ifdef WIN32
2844  unlink(fname);
2845 #endif
2846  filebuf obuf;
2847  obuf.open(fname, IOS_OUT);
2848  ostream o(&obuf);
2851  Scene* p = paper();
2852  GlyphIndex count = p->count();
2853  if (ses_style) {
2854  for (GlyphIndex i = 0; i < screen()->count(); ++i) {
2855  ScreenItem* pi = (ScreenItem*) screen()->component(i);
2856  redraw(pi->window());
2857  }
2858  } else {
2859  for (GlyphIndex i = 0; i < count; ++i) {
2860  if (!p->showing(i)) {
2861  continue;
2862  }
2863  PaperItem* pi = (PaperItem*) p->component(i);
2864  redraw(pi->screen_item()->window());
2865  }
2866  }
2867  OcIdraw::epilog();
2868  obuf.close();
2870 }
2871 
2872 void PWMImpl::ascii_control() {
2873  if (Oc::helpmode()) {
2874  Oc::help(PWM_ascii_);
2875  }
2876  if (!fc_ascii_) {
2877  Style* style = new Style(Session::instance()->style());
2878  String str;
2879  if (style->find_attribute("pwm_ascii_file_filter", str)) {
2880  style->attribute("filter", "true");
2881  style->attribute("filterPattern", str);
2882  }
2883  style->attribute("caption", "Ascii format to file");
2884  style->attribute("open", "Write to file");
2885  fc_ascii_ = DialogKit::instance()->file_chooser("./", style);
2886  fc_ascii_->ref();
2887  } else {
2888  fc_ascii_->reread();
2889  }
2890  if (none_selected("No windows to save", "Save Anyway")) {
2891  return;
2892  }
2893  while (fc_ascii_->post_for(w_)) {
2894  if (ok_to_write(*fc_ascii_->selected(), w_)) {
2895  ascii_write(fc_ascii_->selected()->string());
2896  break;
2897  }
2898  }
2899 }
2900 
2901 void PWMImpl::ascii_write(const char* fname, bool ses_style) {
2902  filebuf obuf;
2903 #ifdef WIN32
2904  unlink(fname);
2905 #endif
2906  obuf.open(fname, IOS_OUT);
2907  ostream o(&obuf);
2908  Graph::ascii(&o);
2909  Scene* p = paper();
2910  GlyphIndex count = p->count();
2911  if (ses_style) {
2912  for (GlyphIndex i = 0; i < screen()->count(); ++i) {
2913  ScreenItem* pi = (ScreenItem*) screen()->component(i);
2914  redraw(pi->window());
2915  }
2916  } else {
2917  for (GlyphIndex i = 0; i < count; ++i) {
2918  if (!p->showing(i) && !ses_style) {
2919  continue;
2920  }
2921  PaperItem* pi = (PaperItem*) p->component(i);
2922  redraw(pi->screen_item()->window());
2923  }
2924  }
2925  obuf.close();
2926  Graph::ascii(NULL);
2927 }
2928 
2929 ostream* Oc::save_stream;
2930 
2931 void PWMImpl::save_selected_control() {
2932  save_control(1);
2933 }
2934 void PWMImpl::save_all_control() {
2935  save_control(2);
2936 }
2937 bool PWMImpl::none_selected(const char* title, const char* accept) const {
2938  int i, n = 0;
2939  if (paper_)
2940  for (i = 0; i < paper_->count(); ++i) {
2941  if (paper_->showing(i)) {
2942  ++n;
2943  }
2944  }
2945  if (n == 0) {
2946  if (!boolean_dialog(title, accept, "Cancel", w_)) {
2947  return true;
2948  }
2949  }
2950  return false;
2951 }
2952 
2953 void PWMImpl::save_control(int mode) {
2954  if (Oc::helpmode()) {
2955  if (mode == 2) {
2956  Oc::help(PWM_save_control2_);
2957  } else {
2958  Oc::help(PWM_save_control1_);
2959  }
2960  }
2961  if (!fc_save_) {
2962  if (mode == 1) {
2963  if (none_selected("No windows to save", "Save Anyway")) {
2964  return;
2965  }
2966  }
2967  Style* style = new Style(Session::instance()->style());
2968  String str;
2969  if (style->find_attribute("pwm_save_file_filter", str)) {
2970  style->attribute("filter", "true");
2971  style->attribute("filterPattern", str);
2972  }
2973  style->attribute("caption", "Save windows on paper icon to file");
2974  style->attribute("open", "Save to file");
2975  fc_save_ = DialogKit::instance()->file_chooser("./", style);
2976  fc_save_->ref();
2977  } else {
2978  fc_save_->reread();
2979  }
2980  while (fc_save_->post_for(w_)) {
2981  if (ok_to_write(*fc_save_->selected(), w_)) {
2982  save_session(mode, fc_save_->selected()->string());
2983  break;
2984  }
2985  }
2986 }
2987 
2988 int PWMImpl::save_group(Object* ho, const char* filename) {
2989  int i;
2990  ScreenItem* si;
2991  ScreenItem** sivec = NULL;
2992  int nwin = 0;
2993  if (screen_ && screen_->count()) {
2994  sivec = new ScreenItem*[screen_->count()];
2995  for (i = 0; i < screen_->count(); i++) {
2996  si = (ScreenItem*) (screen_->component(i));
2997  if (si->group_obj_ == ho) {
2998  sivec[nwin++] = si;
2999  }
3000  }
3001  }
3002  if (nwin > 0) {
3003  cur_ses_name_ = filename;
3004  filebuf obuf;
3005 #ifdef WIN32
3006  unlink(filename);
3007 #endif
3008  obuf.open(filename, IOS_OUT);
3009  ostream o(&obuf);
3010  save_begin(o);
3011  save_list(nwin, sivec, o);
3012  obuf.close();
3013  }
3014  if (sivec) {
3015  delete[] sivec;
3016  }
3017  return nwin;
3018 }
3019 
3020 void PWMImpl::save_session(int mode, const char* filename, const char* head) {
3021  int nwin = 0;
3022  ScreenItem* si;
3023  ScreenItem** sivec = NULL;
3024 
3025  filebuf obuf;
3026  cur_ses_name_ = filename;
3027 #ifdef WIN32
3028  unlink(filename);
3029 #endif
3030  obuf.open(filename, IOS_OUT);
3031  if (!obuf.is_open()) {
3032  hoc_execerror(filename, "is not open for writing");
3033  }
3034  ostream o(&obuf);
3035  if (head) {
3036  o << head << endl;
3037  }
3038  save_begin(o);
3039 
3040  PrintableWindow* w;
3041  GlyphIndex i;
3042  if (mode == 2) {
3043  if (screen_ && screen_->count()) {
3044  sivec = new ScreenItem*[screen_->count()];
3045  for (i = 0; i < screen_->count(); i++) {
3046  si = (ScreenItem*) (screen_->component(i));
3047  w = si->window();
3048  if (w) {
3049  if (/*w->is_mapped() &&*/ w != PrintableWindow::leader()) {
3050  if (w_ != w) {
3051  sivec[nwin++] = si;
3052  } else {
3053  char buf[100];
3054  sprintf(buf,
3055  "{pwman_place(%d,%d,%d)}\n",
3056  w->xleft(),
3057  w->xtop(),
3058  w->is_mapped() ? 1 : 0);
3059  o << buf;
3060  }
3061  }
3062  }
3063  }
3064  }
3065  } else {
3066  if (paper_ && paper_->count()) {
3067  sivec = new ScreenItem*[paper_->count()];
3068  for (i = 0; i < paper_->count(); i++) {
3069  if (paper_->showing(i)) {
3070  si = ((PaperItem*) (paper_->component(i)))->screen_item();
3071  w = si->window();
3072  if (w) {
3073  if (w_ != w) {
3074  sivec[nwin++] = si;
3075  } else {
3076  char buf[100];
3077  sprintf(buf, "{pwman_place(%d,%d)}\n", w->xleft(), w->xtop());
3078  o << buf;
3079  }
3080  }
3081  }
3082  }
3083  }
3084  }
3085  save_list(nwin, sivec, o); // sivec deleted here
3086  obuf.close();
3087  if (sivec) {
3088  delete[] sivec;
3089  }
3090 }
3091 
3092 void PWMImpl::save_begin(ostream& o) {
3093  Oc::save_stream = &o;
3094  Scene::save_all(o);
3095  HocPanel::save_all(o);
3096  o << "objectvar ocbox_, ocbox_list_, scene_, scene_list_" << endl;
3097  o << "{ocbox_list_ = new List() scene_list_ = new List()}" << endl;
3098 }
3099 
3100 void PWMImpl::save_list(int nwin, ScreenItem** sivec, ostream& o) {
3101  // save highest first, only a few priorities
3102  OcGlyph* ocg;
3103  int i, pri, max, working;
3104  ses_group_first_ = 1;
3105  // printf("will save %d windows\n", nwin);
3106  for (working = 10000; working >= 0; working = max) {
3107  // printf("working = %d\n", working);
3108  max = -1;
3109  for (i = 0; i < nwin; ++i) {
3110  if (sivec[i]->window()) {
3111  ocg = (OcGlyph*) sivec[i]->window()->glyph();
3112  pri = ocg->session_priority();
3113  }
3114  if (pri == working) {
3115  // printf("saving item %d with priority %d\n", i, pri);
3116  if (sivec[i]->window()) {
3117  ocg->save(o);
3118  }
3119  ses_group(sivec[i], o);
3120  }
3121  if (pri < working && pri > max) {
3122  max = pri;
3123  }
3124  }
3125  }
3127  o << "objectvar scene_vector_[1]\n{doNotify()}" << endl;
3128 }
3129 
3130 void PWMImpl::ses_group(ScreenItem* si, ostream& o) {
3131  char buf[512];
3132  char* name;
3133  if (si->group_obj_) {
3134  name = Oc2IV::object_str("name", si->group_obj_);
3135  sprintf(buf,
3136  "{WindowMenu[0].ses_gid(%d, %d, %d, \"%s\")}\n",
3137  ses_group_first_,
3138  si->group_obj_->index,
3139  (screen()->showing(si->index()) ? 1 : 0),
3140  name);
3141  o << buf;
3142  ses_group_first_ = 0;
3143  }
3144 }
3145 
3146 void PWMImpl::retrieve_control() {
3147  if (Oc::helpmode()) {
3148  Oc::help(PWM_retrieve_control_);
3149  }
3150  if (!fc_retrieve_) {
3151  Style* style = new Style(Session::instance()->style());
3152  String str;
3153  if (style->find_attribute("pwm_save_file_filter", str)) {
3154  style->attribute("filter", "true");
3155  style->attribute("filterPattern", str);
3156  }
3157  style->attribute("caption", "Retrieve windows from file");
3158  style->attribute("open", "Retrieve from file");
3159  fc_retrieve_ = DialogKit::instance()->file_chooser("./", style);
3160  fc_retrieve_->ref();
3161  } else {
3162  fc_retrieve_->reread();
3163  }
3164  while (fc_retrieve_->post_for(w_)) {
3165  if (ok_to_read(*fc_retrieve_->selected(), w_)) {
3166  Oc oc;
3167  char buf[256];
3168  sprintf(buf, "{load_file(1, \"%s\")}\n", fc_retrieve_->selected()->string());
3169  if (!oc.run(buf)) {
3170  break;
3171  }
3172  }
3173  }
3174 }
3175 
3176 class OcLabelGlyph: public OcGlyph {
3177  public:
3178  OcLabelGlyph(const char*, OcGlyph*, Glyph*);
3179  virtual ~OcLabelGlyph();
3180  virtual void save(ostream&);
3181 
3182  private:
3183  CopyString label_;
3184  OcGlyph* og_;
3185 };
3186 
3187 OcLabelGlyph::OcLabelGlyph(const char* label, OcGlyph* og, Glyph* g) {
3188  label_ = label;
3189  og_ = og;
3190  og_->parents(true);
3191  Resource::ref(og_);
3192  body(g);
3193 }
3194 
3195 OcLabelGlyph::~OcLabelGlyph() {
3196  og_->parents(false);
3197  Resource::unref(og_);
3198 }
3199 
3200 void OcLabelGlyph::save(ostream& o) {
3201  char buf[256];
3202  o << "{xpanel(\"\")" << endl;
3203  sprintf(buf, "xlabel(\"%s\")", label_.string());
3204  o << buf << endl;
3205  o << "xpanel()}" << endl;
3206  og_->save(o);
3207 }
3208 
3209 /*static*/ class TrayDismiss: public WinDismiss {
3210  public:
3211  TrayDismiss(DismissableWindow*);
3212  virtual ~TrayDismiss();
3213  virtual void execute();
3214 };
3215 
3216 class OcTray: public OcBox {
3217  public:
3218  OcTray(GlyphIndex cnt);
3219  virtual ~OcTray();
3220  virtual PrintableWindow* make_window(Coord = -1, Coord = -1, Coord = -1, Coord = -1);
3221  virtual void start_vbox();
3222  virtual void win(PrintableWindow*);
3223  virtual void dissolve(Coord, Coord);
3224 
3225  private:
3226  PolyGlyph* pg_;
3227  OcBox* v_;
3228  float *x_, *y_;
3229 };
3230 
3231 TrayDismiss::TrayDismiss(DismissableWindow* w)
3232  : WinDismiss(w) {}
3233 TrayDismiss::~TrayDismiss() {}
3234 void TrayDismiss::execute() {
3235  if (boolean_dialog("Dismiss or Dissolve into components?", "Dissolve", "Dismiss", win_)) {
3236  OcTray* t = (OcTray*) win_->glyph();
3237  t->dissolve(win_->left(), win_->bottom());
3238  }
3240 }
3241 OcTray::OcTray(GlyphIndex cnt)
3242  : OcBox(OcBox::H) {
3243  x_ = new float[cnt];
3244  y_ = new float[cnt];
3245  pg_ = new PolyGlyph();
3246  pg_->ref();
3247  v_ = NULL;
3248 }
3249 
3250 OcTray::~OcTray() {
3251  pg_->unref();
3252  delete[] x_;
3253  delete[] y_;
3254 }
3255 
3256 void OcTray::dissolve(Coord left, Coord bottom) {
3257  Window* w;
3258  Coord l, b;
3259  OcGlyph* g;
3260  Requisition req;
3261  GlyphIndex i, cnt = pg_->count();
3262  for (i = 0; i < cnt; ++i) {
3263  l = left;
3264  b = bottom;
3265  g = (OcGlyph*) pg_->component(i);
3266  g->request(req);
3267  w = g->make_window(l + x_[i] - x_[0],
3268  b + y_[i] - y_[0],
3269  req.x_requirement().natural(),
3270  req.y_requirement().natural());
3271  w->map();
3272  }
3273 }
3274 
3275 void OcTray::start_vbox() {
3276  v_ = new OcBox(OcBox::V);
3277  box_append(v_);
3278 }
3279 
3280 void OcTray::win(PrintableWindow* w) {
3281  LayoutKit* lk = LayoutKit::instance();
3282  WidgetKit* wk = WidgetKit::instance();
3283  wk->begin_style("_tray_panel");
3284  GlyphIndex n = pg_->count();
3285  pg_->append(w->glyph());
3286  x_[n] = w->left();
3287  y_[n] = w->bottom();
3288  v_->box_append(new OcLabelGlyph(w->name(),
3289  (OcGlyph*) w->glyph(),
3290  lk->vbox(wk->label(w->name()),
3291  lk->fixed(w->glyph(), w->width(), w->height()))));
3292  wk->end_style();
3293 }
3294 
3295 PrintableWindow* OcTray::make_window(Coord left, Coord bottom, Coord width, Coord height) {
3296  PrintableWindow* w = OcGlyph::make_window(left, bottom, width, height);
3297  w->replace_dismiss_action(new TrayDismiss(w));
3298  w->type("Tray");
3299  w->name("Tray");
3300  return w;
3301 }
3302 
3303 void PWMImpl::tray() {
3304  if (Oc::helpmode()) {
3305  Oc::help(PWM_tray_);
3306  return;
3307  }
3308  GlyphIndex count;
3309 
3310  count = paper_->count();
3311  // don't make a tray containing the main manager
3312 
3313  // build hbox(vbox) of the individual panels
3314  long index;
3315  Coord minleft = -1000;
3316  Coord top = -1000.;
3317  OcTray* tray = new OcTray(count);
3318  while ((index = upper_left()) != -1) {
3319  PaperItem* pi = (PaperItem*) paper_->component(index);
3320  PrintableWindow* w = pi->screen_item()->window();
3321  Coord l, b;
3322  l = w->left();
3323  b = w->bottom();
3324  if (minleft < l) {
3325  tray->start_vbox();
3326  minleft = l + w->width() / 2.;
3327  }
3328  if (top < 0) {
3329  top = b + w->height();
3330  }
3331  tray->win(w);
3332  paper_->show(index, false);
3333  w->dismiss();
3334  }
3335  Window* w = tray->make_window();
3336  w->map();
3337 }
3338 
3339 GlyphIndex PWMImpl::upper_left() {
3340  GlyphIndex index = -1;
3341  Coord minleft = 1e10;
3342  Coord maxbottom = -1e10;
3343  GlyphIndex count = paper_->count();
3344  for (GlyphIndex i = 0; i < count; ++i) {
3345  PaperItem* pi = (PaperItem*) paper_->component(i);
3346  PrintableWindow* w = pi->screen_item()->window();
3347  Coord l, b;
3348  if (!paper_->showing(i))
3349  continue;
3350  if (w == pwm_impl->w_) {
3351  continue;
3352  }
3353  // paper_->location(i, l, b);
3354  // l *= Scl;
3355  // b *= Scl;
3356  l = w->left();
3357  b = w->bottom();
3358  if (l < minleft - 50.) {
3359  index = i;
3360  minleft = l;
3361  maxbottom = b;
3362  } else if (l < minleft + 50.) {
3363  if (maxbottom < b) {
3364  index = i;
3365  minleft = l;
3366  maxbottom = b;
3367  }
3368  }
3369  }
3370  return index;
3371 }
3372 
3373 #if 0
3374 void PWMImpl::dissolve() {
3375  for (long i = 0; i < panelList_.count(); i++) {
3376  new HocWin(panelList_.item(i));
3377  }
3378  dismiss();
3379 }
3380 #endif
3381 
3382 #if SNAPSHOT
3383 bool ivoc_snapshot(const Event* e) {
3384  char buf[4];
3385  e->mapkey(buf, 1);
3386  if (buf[0] == 'p') {
3387  ivoc_snapshot_ = NULL;
3388  PWMImpl* p = PrintableWindowManager::current()->pwmi_;
3389  p->snapshot(e);
3390  return true;
3391  }
3392  return false;
3393 }
3394 
3395 #if 1
3396 #include <OS/table.h>
3397 #include <InterViews/enter-scope.h>
3398 #include <IV-X11/Xlib.h>
3399 #include <IV-X11/xdisplay.h>
3400 
3401 declareTable(WindowTable, XWindow, Window*)
3402 
3403 
3404  Window* PWMImpl::snap_owned(Printer* pr, Window* wp) {
3405  WindowTable* wt = Session::instance()->default_display()->rep()->wtable_;
3406  for (TableIterator(WindowTable) i(*wt); i.more(); i.next()) {
3407  Window* w = i.cur_value();
3408  if (w->is_mapped()) {
3409  snap(pr, w);
3410  }
3411  }
3412  return NULL;
3413 }
3414 #endif
3415 #endif // SNAPSHOT
3416 
3417 #else
3418 
3419 #include <string.h>
3420 #include <stdio.h>
3421 #include <stdlib.h>
3422 #include <unistd.h>
3423 #include <InterViews/resource.h>
3424 #include "oc2iv.h"
3425 
3426 #endif // HAVE_IV
3427 
3429  char* tmpfile;
3430 #if MAC && !defined(carbon)
3431  FSSpec spec;
3432  tmpfile = new char[512];
3433  __temp_file_name(tmpfile, &spec);
3434 #else
3435  const char* tdir = getenv("TEMP");
3436  if (!tdir) {
3437  tdir = "/tmp";
3438  }
3439 #if defined(WIN32) && defined(__MWERKS__)
3440  char tname[L_tmpnam + 1];
3441  tmpnam(tname);
3442  tmpfile = new char[strlen(tdir) + 1 + strlen(tname) + 1];
3443  sprintf(tmpfile, "%s/%s", tdir, tname);
3444 #else
3445  tmpfile = new char[strlen(tdir) + 1 + 9 + 1];
3446  sprintf(tmpfile, "%s/nrnXXXXXX", tdir);
3447 #if HAVE_MKSTEMP
3448  int fd;
3449  if ((fd = mkstemp(tmpfile)) == -1) {
3450  hoc_execerror("Could not create temporary file:", tmpfile);
3451  }
3452  close(fd);
3453 #else
3454  mktemp(tmpfile);
3455 #endif
3456 #endif
3457 #if defined(WIN32)
3458  tmpfile = hoc_back2forward(tmpfile);
3459 #endif
3460 #endif
3461  return tmpfile;
3462 }
#define PixelCoord
Definition: _defines.h:25
#define Window
Definition: _defines.h:333
#define TelltaleState
Definition: _defines.h:296
#define Handler
Definition: _defines.h:146
#define Background
Definition: _defines.h:43
#define Color
Definition: _defines.h:74
#define Menu
Definition: _defines.h:176
#define Transformer
Definition: _defines.h:316
#define WindowTable
Definition: _defines.h:336
#define Canvas
Definition: _defines.h:65
#define Style
Definition: _defines.h:281
#define Label
Definition: _defines.h:159
#define Allotment
Definition: _defines.h:38
#define Coord
Definition: _defines.h:19
#define Brush
Definition: _defines.h:59
#define Hit
Definition: _defines.h:147
#define FileChooser
Definition: _defines.h:116
#define Display
Definition: _defines.h:97
#define WidgetKit
Definition: _defines.h:331
#define Printer
Definition: _defines.h:211
#define GlyphIndex
Definition: _defines.h:23
#define MenuItem
Definition: _defines.h:179
#define Event
Definition: _defines.h:107
#define EventButton
Definition: _defines.h:21
#define PolyGlyph
Definition: _defines.h:207
#define Font
Definition: _defines.h:120
#define TelltaleGroup
Definition: _defines.h:295
#define LayoutKit
Definition: _defines.h:161
#define Action
Definition: _defines.h:27
#define Glyph
Definition: _defines.h:132
short index
Definition: cabvars.h:10
short type
Definition: cabvars.h:9
Coord right() const
Definition: geometry.h:293
Coord top() const
Definition: geometry.h:295
Coord x() const
Definition: geometry.h:290
void allot_y(const Allotment &)
Definition: geometry.h:283
Coord left() const
Definition: geometry.h:292
Coord bottom() const
Definition: geometry.h:294
Coord y() const
Definition: geometry.h:291
Allotment & x_allotment()
Definition: geometry.h:285
Allotment & y_allotment()
Definition: geometry.h:286
void allot_x(const Allotment &)
Definition: geometry.h:282
Coord begin() const
Definition: geometry.h:274
void origin(Coord)
Definition: geometry.h:266
void span(Coord)
Definition: geometry.h:269
static const Brush * default_brush()
virtual Glyph * glyph() const
Definition: apwindow.h:47
virtual const char * name() const
virtual void dismiss()
static bool is_transient()
Definition: apwindow.h:54
virtual void replace_dismiss_action(WinDismiss *)
void set(Canvas *, const Allocation &)
static FieldDialog * field_dialog_instance(const char *, Style *, Glyph *extra=NULL)
static std::ostream * ascii()
static MenuItem * menu_item(const char *)
static MenuItem * check_menu_item(const char *)
static int round(float)
static void extend(Extension &, Coord)
Definition: mymath.h:82
virtual void attach(Observer *)
Definition: observe.cpp:54
virtual void detach(Observer *)
Definition: observe.cpp:63
static char * object_str(const char *symname, Object *=NULL)
Definition: oc2iv.cpp:14
Definition: ocbox.h:11
@ V
Definition: ocbox.h:13
virtual void save(std::ostream &)
void parents(bool)
virtual PrintableWindow * make_window(Coord left=-1, Coord bottom=-1, Coord width=-1, Coord height=-1)
int session_priority()
Definition: ocglyph.h:34
Definition: ivoc.h:36
static void help(const char *)
int run(int argc, const char **argv)
static ostream * save_stream
Definition: ivoc.h:77
static bool helpmode()
Definition: ivoc.h:70
static ostream * idraw_stream
Definition: idraw.h:85
static void prologue()
static void epilog()
virtual Coord width_pw() const
void type(const char *)
virtual void reconfigured()
void xmove(int left, int top)
Definition: ivocmac.cpp:187
static OcGlyphContainer * intercept(OcGlyphContainer *)
static PrintableWindow * leader()
Definition: apwindow.h:96
void xplace(int left, int top)
Definition: ivocmac.cpp:242
int xleft() const
Definition: ivocmac.cpp:195
int xtop() const
Definition: ivocmac.cpp:218
virtual Coord height_pw() const
virtual void map_notify()
virtual Coord bottom_pw() const
virtual void hide()
Definition: ivocmac.cpp:183
virtual Glyph * print_glyph()
virtual Coord left_pw() const
virtual void map()
void xplace(int, int, bool map=true)
static PrintableWindowManager * current()
void append(PrintableWindow *)
void psfilter(const char *filename)
static PrintableWindowManager * current_
Definition: apwindow.h:160
virtual ~PrintableWindowManager()
void reconfigured(PrintableWindow *)
virtual void disconnect(Observable *)
void remove(PrintableWindow *)
virtual void update(Observable *)
Definition: rect.h:44
void alignment(float)
Definition: geometry.h:241
void natural(Coord)
Definition: geometry.h:235
void require_x(const Requirement &)
Definition: geometry.h:247
const Requirement & x_requirement() const
Definition: geometry.h:249
void require_y(const Requirement &)
Definition: geometry.h:248
const Requirement & y_requirement() const
Definition: geometry.h:250
virtual void ref() const
Definition: resource.cpp:47
virtual void unref() const
Definition: resource.cpp:52
void canvas(Canvas *)
static Rubberband * current()
Definition: rubband.h:57
virtual void snapshot(Printer *)
virtual void pick(Canvas *, const Allocation &, int depth, Hit &)
void move(GlyphIndex, Coord x, Coord y)
virtual Coord y2() const
Definition: scenevie.h:366
virtual Coord y1() const
Definition: scenevie.h:363
bool showing(GlyphIndex) const
void location(GlyphIndex, Coord &x, Coord &y) const
virtual Coord x2() const
Definition: scenevie.h:360
virtual void remove(GlyphIndex)
virtual Coord x1() const
Definition: scenevie.h:357
static void save_all(std::ostream &)
virtual Coord mbs() const
Definition: string.h:34
const char * string() const
Definition: string.h:139
Definition: scenevie.h:203
virtual void reconfigured()
virtual void execute()
void execute(Inst *p)
Definition: code.cpp:2661
#define fil
Definition: coord.h:42
double t
Definition: cvodeobj.cpp:59
sprintf(buf, " if (secondorder) {\n" " int _i;\n" " for (_i = 0; _i < %d; ++_i) {\n" " _p[_slist%d[_i]] += dt*_p[_dlist%d[_i]];\n" " }}\n", numeqn, listnum, listnum)
double chkarg(int, double low, double high)
Definition: code2.cpp:638
#define c
static int first
Definition: fmenu.cpp:190
void hoc_execerror(const char *, const char *)
Definition: hoc.cpp:754
@ Dimension_Y
Definition: geometry.h:43
@ Dimension_X
Definition: geometry.h:43
char buf[512]
Definition: init.cpp:13
int hoc_is_object_arg(int narg)
Definition: code.cpp:756
void hoc_ret()
char ** hoc_temp_charptr(void)
Definition: code.cpp:642
void hoc_obj_ref(Object *obj)
Definition: hoc_oop.cpp:1810
int nrnignore
Definition: hoc.cpp:26
void hoc_obj_unref(Object *obj)
Definition: hoc_oop.cpp:1828
#define TRY_GUI_REDIRECT_ACTUAL_DOUBLE(name, obj)
Definition: gui-redirect.h:71
#define TRY_GUI_REDIRECT_DOUBLE(name, obj)
Definition: gui-redirect.h:58
#define TRY_GUI_REDIRECT_NO_RETURN(name, obj)
Definition: gui-redirect.h:47
#define TRY_GUI_REDIRECT_OBJ(name, obj)
Definition: gui-redirect.h:12
#define TRY_GUI_REDIRECT_ACTUAL_STR(name, obj)
Definition: gui-redirect.h:82
#define TRY_GUI_REDIRECT_ACTUAL_OBJ(name, obj)
Definition: gui-redirect.h:93
static void help(const char *)
Definition: hel2mos.cpp:107
#define IFGUI
Definition: hocdec.h:372
#define getarg
Definition: hocdec.h:15
#define gargstr
Definition: hocdec.h:14
#define ENDGUI
Definition: hocdec.h:373
Object ** hoc_objgetarg(int)
Definition: code.cpp:1587
void
void pwmimpl_redraw(Window *w)
carbon
Definition: ivocmac.cpp:166
char * mktemp(char *)
Definition: ivocmac.cpp:27
void ivoc_bring_to_top(Window *w)
Definition: ivocmac.cpp:170
int ifarg(int)
Definition: code.cpp:1581
void hoc_pushx(double)
#define IOS_OUT
Definition: ivstream.h:8
void debugfile(const char *,...)
char * getenv(const char *s)
Definition: macprt.cpp:67
int hoc_copyfile(const char *src, const char *dest)
Definition: macprt.cpp:81
Object ** hoc_temp_objptr(Object *)
Definition: code.cpp:216
#define max(a, b)
Definition: matrix.h:154
#define v
Definition: md1redef.h:4
#define i
Definition: md1redef.h:12
Item * title
Definition: model.cpp:39
char * name
Definition: init.cpp:16
int get()
Definition: units.cpp:1110
#define printf
Definition: mwprefix.h:26
static double inside(void *)
Definition: mymath.cpp:21
void single_event_run()
int const size_t const size_t n
Definition: nrngsl.h:11
size_t q
size_t p
void class2oc(const char *, void *(*cons)(Object *), void(*destruct)(void *), Member_func *, int(*checkpoint)(void **), Member_ret_obj_func *, Member_ret_str_func *)
Definition: hoc_oop.cpp:1560
char * hoc_back2forward(char *s)
char ** hoc_strpop()
Definition: code.cpp:879
static N_Vector y_
static N_Vector w_
static void pr(N_Vector x)
static N_Vector x_
const char * pwm_session_filename()
static double save(void *v)
Definition: ocbox.cpp:346
static double ref(void *v)
Definition: ocbox.cpp:383
virtual void move(const Event &e)
Definition: ocinput.h:26
void hoc_save_session()
Definition: ocnoiv1.cpp:157
void hoc_print_session()
Definition: ocnoiv1.cpp:164
void hoc_pwman_place()
Definition: ocnoiv1.cpp:150
static double resize(void *v)
static double working(void *v)
Definition: ocbbs.cpp:210
#define g
Definition: passive0.cpp:21
#define e
Definition: passive0.cpp:22
static void pwman_destruct(void *v)
Definition: pwman.cpp:452
static double pwman_deco(void *v)
Definition: pwman.cpp:783
static double pwman_deiconify(void *v)
Definition: pwman.cpp:567
static double pwman_close(void *v)
Definition: pwman.cpp:527
static double pwman_paper_place(void *v)
Definition: pwman.cpp:718
static double pwman_scale(void *v)
Definition: pwman.cpp:682
char * ivoc_get_temp_file()
Definition: pwman.cpp:3428
static double pwman_leader(void *v)
Definition: pwman.cpp:577
static double pwman_map(void *v)
Definition: pwman.cpp:483
static double pwman_window_place(void *v)
Definition: pwman.cpp:702
static double pwman_save(void *v)
Definition: pwman.cpp:614
static Member_func members[]
Definition: pwman.cpp:794
double(* nrnpy_object_to_double_)(Object *)
Definition: xmenu.cpp:14
static double pwman_hide(void *v)
Definition: pwman.cpp:497
static double pwman_is_mapped(void *v)
Definition: pwman.cpp:468
static double pwman_iconify(void *v)
Definition: pwman.cpp:551
static const char ** pwman_name(void *v)
Definition: pwman.cpp:511
static Member_ret_str_func s_memb[]
Definition: pwman.cpp:833
void PWManager_reg()
Definition: pwman.cpp:835
int hoc_return_type_code
Definition: code.cpp:42
static Member_ret_obj_func retobj_members[]
Definition: pwman.cpp:831
static double pwman_landscape(void *v)
Definition: pwman.cpp:772
static void * pwman_cons(Object *)
Definition: pwman.cpp:442
static Object ** pwman_group(void *v)
Definition: pwman.cpp:636
static double pwman_manager(void *v)
Definition: pwman.cpp:595
static double pwman_count(void *v)
Definition: pwman.cpp:456
static double pwman_printfile(void *v)
Definition: pwman.cpp:743
static double pwman_snap(void *v)
Definition: pwman.cpp:655
#define left
Definition: rbtqueue.cpp:45
#define right
Definition: rbtqueue.cpp:46
#define Rect
Definition: rect.h:5
#define lookup
Definition: redef.h:90
#define print
Definition: redef.h:109
o
Definition: seclist.cpp:175
#define cnt
Definition: spt2queue.cpp:19
#define NULL
Definition: sptree.h:16
Definition: hocdec.h:227
bool nrn_spec_dialog_pos(Coord &x, Coord &y)
true if Style 'dialog_spec_position: on' and fills x,y with dialog_left_position and dialog_bottom_po...
bool ok_to_write(const String &, Window *w=NULL)
bool ok_to_read(const String &, Window *w=NULL)
bool boolean_dialog(const char *label, const char *accept, const char *cancel, Window *w=NULL, Coord x=400., Coord y=400.)
void continue_dialog(const char *label, Window *w=NULL, Coord x=400., Coord y=400.)
static const char * fname(const char *name)
Definition: nrnbbs.cpp:113