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