1 #include <../../nrnconf.h> 8 #if (MAC && !defined(carbon)) || defined(WIN32) 14 #if defined(WIN32)|| MAC 20 #define DECO 2 // 1 means default on, 2 off. for Carnvale,Hines book figures 38 #include <IV-Win/mprinter.h> 39 void iv_display_scale(
float);
44 #if defined(WIN32) && !defined(CYGWIN) 45 #include <IV-Win/mprinter.h> 46 #include "../winio/debug.h" 47 void iv_display_scale(
float);
49 #if defined(__MWERKS__) 50 #include <OS/dirent.h> 51 extern char *
mktemp(
char *);
52 extern int unlink(
const char *);
62 #define IOS_OUT (ios::out) 65 #if MAC && !defined(carbon)
69 #define IOS_OUT (ios::out | ios::trunc) 70 extern char *
mktemp(
char *);
71 extern int unlink(
const char *);
72 #include <IV-Mac/mprinter.h> 80 #include <IV-look/kit.h> 81 #include <IV-look/dialogs.h> 82 #include <InterViews/layout.h> 83 #include <InterViews/hit.h> 84 #include <InterViews/display.h> 85 #include <InterViews/session.h> 86 #include <InterViews/color.h> 87 #include <InterViews/brush.h> 88 #include <InterViews/font.h> 89 #include <InterViews/event.h> 90 #include <InterViews/handler.h> 91 #include <InterViews/printer.h> 92 #include <InterViews/style.h> 93 #include <InterViews/background.h> 94 #include <InterViews/label.h> 117 extern bool (*ivoc_snapshot_)(
const Event*);
118 static bool ivoc_snapshot(
const Event*);
121 #define PWM_help_ "help" 122 #define PWM_do_print_ "Print PWM" 123 #define PWM_ScreenItem_ "ScreenItem PWM" 124 #define PWM_PaperItem_ "PaperItem PWM" 125 #define PWM_landscape_ "LandPort Other" 126 #define PWM_virt_screen_ "VirtualScreen Other" 127 #define PWM_printer_control_ "SelectPrinter Other" 128 #define PWM_file_control_ "PostScript PrintToFile" 129 #define PWM_idraw_control_ "Idraw PrintToFile" 130 #define PWM_save_control2_ "SaveAll Session" 131 #define PWM_save_control1_ "SaveSelected Session" 132 #define PWM_retrieve_control_ "Retrieve Session" 133 #define PWM_tray_ "Tray Other" 134 #define PWM_ascii_ "Ascii PrintToFile" 135 #define PWM_quit_ "Quit Other" 137 #define pwm_impl PrintableWindowManager::current()->pwmi_ 140 static void save_all(ostream&);
165 class ScreenScene :
public Scene {
169 virtual Coord mbs()
const;
172 class PaperScene :
public Scene {
175 virtual Coord mbs()
const;
178 class ScreenSceneHandler :
public Handler {
181 virtual bool event(
Event&);
187 extern char** (*p_java2nrn_smeth)(
Object* ho,
Symbol* method);
188 const char* (*p_java2nrn_classname)(
Object* ho);
195 JavaWindow(
const char*,
Object*);
196 virtual ~JavaWindow();
200 virtual void pmove(
int l,
int t);
201 virtual void presize(
int w,
int h);
202 virtual int priority();
203 virtual void save_session(
const char*
fname, ostream&
o);
209 bool is_mapped, reffing_, closing_;
215 class ScreenItem :
public Glyph {
217 friend class PaperItem;
219 ScreenItem(JavaWindow*);
226 JavaWindow* jwindow() {
return jw_;}
229 PaperItem* paper_item()
const {
return pi_;}
232 bool iconify_via_hide_;
241 class PaperItem :
public Glyph {
243 PaperItem(ScreenItem*);
250 void scale(
float s) { scale_ =
s; }
251 float scale() {
return scale_; }
252 ScreenItem* screen_item()
const {
return si_;}
257 friend class ScreenItem;
260 friend ScreenItem::~ScreenItem();
268 void append_paper(ScreenItem*);
269 void remove_paper(PaperItem*);
270 void unshow_paper(PaperItem*);
272 PaperScene* paper() {
return paper_;}
273 ScreenScene* screen() {
return screen_; }
277 void snapshot(
const Event*);
283 void do_print(
bool printer,
const char*
name);
284 void do_print_session(
bool also_controller =
true);
285 void do_print_session(
bool printer,
const char*
name);
286 void ps_file_print(
bool,
const char*,
bool,
bool);
287 void common_print(
Printer*,
bool,
bool);
293 MacPrinter* mprinter();
301 void landscape(
bool);
302 bool is_landscape() {
return landscape_; }
306 void printer_control();
309 void snapshot_control();
311 bool file_control1();
312 void idraw_control();
313 void idraw_write(
const char*
fname,
bool ses_style =
false);
314 void ascii_control();
315 void ascii_write(
const char*
fname,
bool ses_style =
false);
317 void save_selected_control();
318 void save_all_control();
319 void save_control(
int);
320 void save_session(
int,
const char*,
const char* head =
NULL);
321 int save_group(
Object*,
const char*);
322 void retrieve_control();
324 float round_factor() {
return round_factor_;}
329 void all_window_bounding_box(
Extension&,
bool with_screen =
true,
bool also_controller =
true);
332 const Color* window_outline_;
339 PWMImpl(ScreenScene*, PaperScene*,
Rect*);
345 bool none_selected(
const char*,
const char*)
const;
346 void ses_group(ScreenItem* si, ostream&
o);
int ses_group_first_;
347 void save_begin(ostream&);
348 void save_list(
int, ScreenItem**, ostream&);
351 ScreenScene* screen_;
357 bool printer_control_accept_;
369 const Event* snap_event_;
370 bool print_leader_flag_;
376 MacPrinter* mprinter_;
382 static void makeVirtualWindow();
384 virtual ~VirtualWindow();
388 static VirtualWindow* virt_win_;
392 VirtualWindow* VirtualWindow::virt_win_;
396 class VirtualWindowScale :
public Action {
398 VirtualWindowScale(
float);
405 class PaperItem_handler :
public Handler {
409 virtual ~PaperItem_handler();
410 virtual bool event(
Event&);
422 class ScreenItemHandler :
public Handler {
425 virtual ~ScreenItemHandler();
426 virtual bool event(
Event&);
439 virtual ~PWMDismiss();
443 PWMDismiss::~PWMDismiss() {}
446 pwm_impl->unmap_all();
460 extern char** (*nrnpy_gui_helper3_str_)(
const char*
name,
Object* obj,
int handle_strptr);
483 cnt = p->screen()->count();
494 int i = (
int)
chkarg(1, 0, p->screen()->count()-1);
495 ScreenItem* si = (ScreenItem*)p->screen()->component(i);
497 return double(si->window()->is_mapped());
499 return double(si->jwindow()->is_mapped);
510 int i = (
int)
chkarg(1, 0, p->screen()->count()-1);
511 ScreenItem* si = (ScreenItem*)p->screen()->component(i);
515 si->jwindow()->map();
526 int i = (
int)
chkarg(1, 0, p->screen()->count()-1);
527 ScreenItem* si = (ScreenItem*)p->screen()->component(i);
529 si->window()->hide();
531 si->jwindow()->hide();
542 int i = (
int)
chkarg(1, 0, p->screen()->count()-1);
543 ScreenItem* si = (ScreenItem*)p->screen()->component(i);
546 *ps = (
char*)si->window()->name();
548 *ps = si->jwindow()->title;
550 return (
const char**) ps;
560 int i = (
int)
chkarg(1, 0, p->screen()->count()-1);
561 ScreenItem* si = (ScreenItem*)p->screen()->component(i);
562 if (p->window() == si->window()) {
565 si->window()->dismiss();
571 static void pwman_iconify1(
void*
v) {
586 if (!nrn_is_gui_thread()) {
587 nrn_gui_exec(pwman_iconify1, pw);
613 int i,
cnt = p->screen()->count();
614 for (i=0; i <
cnt; ++
i) {
615 ScreenItem* si = (ScreenItem*)p->screen()->component(i);
616 if (si->window() == pw) {
631 int i,
cnt = p->screen()->count();
632 for (i=0; i <
cnt; ++
i) {
633 ScreenItem* si = (ScreenItem*)p->screen()->component(i);
634 if (si->window() == pw) {
672 i =
int(
chkarg(1, 0, p->screen()->count()-1));
673 ScreenItem* si = (ScreenItem*)p->screen()->component(i);
692 p->snapshot_control();
712 int i,
cnt = p->screen()->count();
713 for (i=0; i <
cnt; ++
i) {
714 ScreenItem* si = (ScreenItem*)p->screen()->component(i);
715 JavaWindow* jw = si->jwindow();
719 if (
chkarg(2,0,1) == 0.) {
732 static double scale_;
733 static void pwman_scale1(
void*) {
736 iv_display_scale(scale_);
744 double scale =
chkarg(1, .01, 100);
749 if (!nrn_is_gui_thread()) {
751 nrn_gui_exec(pwman_scale1, (
void*)((intptr_t)1));
755 iv_display_scale(scale);
768 i =
int(
chkarg(1, 0, p->screen()->count()-1));
769 ScreenItem* si = (ScreenItem*)p->screen()->component(i);
788 i =
int(
chkarg(1, 0, p->screen()->count()-1));
789 ScreenItem* si = (ScreenItem*)p->screen()->component(i);
791 PaperItem* pi = si->paper_item();
793 if ((
int(
chkarg(2, 0, 1))) == 0) {
797 pi->scale(
chkarg(4, 1e-4, 1e4));
798 p->paper()->move(p->paper_index(pi), *
getarg(2)/pr_scl, *
getarg(3)/pr_scl);
813 bool ses_style =
false;
815 ses_style =
int(
chkarg(3, 0, 1))?
true:
false;
818 switch ((
int)
chkarg(2, 0, 2)) {
820 p->ps_file_print(
false, fname, p->is_landscape(), ses_style);
823 p->idraw_write(fname, ses_style);
826 p->ascii_write(fname, ses_style);
839 p->landscape(
int(
chkarg(1, 0, 1))?
true:
false);
850 p->deco(
int(
chkarg(1, 0, 2)));
890 retobj_members, s_memb);
893 #if HAVE_IV // almost to end of file 897 PaperItem_handler::PaperItem_handler(
int type,
Coord x,
Coord y, PaperItem* pi,
903 index_ = pwm_impl->paper_index(pi);
905 pwm_impl->paper()->location(index_, left, bottom);
909 action_ = &PaperItem_handler::resize_action;
break;
911 t_.translate(left - x, bottom - y);
912 action_ = &PaperItem_handler::move_action;
break;
917 PaperItem_handler::~PaperItem_handler() {
922 bool PaperItem_handler::event(
Event& e) {
928 e.window()->grab_pointer();
930 (this->*action_)(e.pointer_x(), e.pointer_y());
935 e.window()->ungrab_pointer();
939 (this->*action_)(e.pointer_x(), e.pointer_y());
945 void PaperItem_handler::move_action(
Coord x,
Coord y) {
948 t_.transform(x, y, xs, ys);
949 xs = pwm_impl->round(xs);
950 ys = pwm_impl->round(ys);
951 pwm_impl->paper()->move(index_, xs, ys);
954 void PaperItem_handler::resize_action(
Coord x,
Coord y) {
956 pwm_impl->paper()->allotment(index_,
Dimension_X, ax);
958 pwm_impl->paper()->allotment(index_,
Dimension_Y, ay);
960 t_.transform(x, y, xs, ys);
964 scl = pi_->scale() * scl;
965 scl = (scl > .1) ? scl : .1;
967 w1 = pwm_impl->round(scl*pi_->width());
968 w1 =
Math::max(w1, pwm_impl->round_factor());
969 scl = w1/pi_->width();
971 pwm_impl->paper()->modified(index_);
979 style(
new Style(Session::instance()->style()));
980 style()->attribute(
"nrn_virtual_screen",
"0");
983 MenuItem* mi = append_menubar(
"Scale");
985 Menu* m = wk.pulldown();
989 mi->action(
new VirtualWindowScale(1.0));
993 mi->action(
new VirtualWindowScale(
fil));
997 mi->action(
new VirtualWindowScale(1.2));
1001 mi->action(
new VirtualWindowScale(1.5));
1005 mi->action(
new VirtualWindowScale(2.0));
1010 VirtualWindow::~VirtualWindow() {
1014 #if defined(WIN32) || carbon 1018 void VirtualWindow::makeVirtualWindow() {
1020 View* v =
new View(pwm_impl->screen());
1021 virt_win_ =
new VirtualWindow(v, LayoutKit::instance()->variable_span(
1022 new Background( v, WidgetKit::instance()->background())
1031 void virtual_window_top() {
1032 VirtualWindow::makeVirtualWindow();
1035 void VirtualWindow::view() {
1037 View* v = virt_win_->view_;
1040 virt_win_->canvas()->damage_all();
1045 VirtualWindowScale::VirtualWindowScale(
float scale) {
1050 float scale = scale_;
1051 if (scale_ >=
fil/10.) {
1053 pwm_impl->all_window_bounding_box(e);
1056 iv_display_scale(scale);
1064 ScreenItemHandler::ScreenItemHandler(
Coord x,
Coord y, ScreenItem* si,
1071 pwm_impl->screen()->location(si_->index(),
left, bottom);
1073 t_.translate(left - x, bottom - y);
1076 ScreenItemHandler::~ScreenItemHandler() {
1081 bool ScreenItemHandler::event(
Event& e) {
1087 e.window()->grab_pointer();
1089 move_action(
false, e.pointer_x(), e.pointer_y());
1094 e.window()->ungrab_pointer();
1096 move_action(
true, e.pointer_x(), e.pointer_y());
1099 move_action(
false, e.pointer_x(), e.pointer_y());
1105 void ScreenItemHandler::move_action(
bool doit,
Coord x,
Coord y) {
1108 t_.transform(x, y, xs, ys);
1110 if (si_->window()) {
1111 si_->window()->move(xs*Scl, ys*Scl);
1113 si_->jwindow()->move(xs*Scl, ys*Scl);
1116 pwm_impl->screen()->move(si_->index(), xs, ys);
1121 :
Scene(x1, y1, x2, y2, g) {
1125 if (pwm_impl->tool(h.event()->pointer_button()) == Event::middle) {
1126 if (h.event()->type() == Event::down) {
1127 h.target(depth,
this, 0,
1128 new ScreenSceneHandler(h.left()*Scl, h.bottom()*Scl));
1135 Coord ScreenScene::mbs()
const {
return 0.; }
1138 :
Scene(x1, y1, x2, y2, g) {
1141 Coord PaperScene::mbs()
const {
return 0.; }
1147 bool ScreenSceneHandler::event(
Event&) {
1148 pwm_impl->view_screen(
x_,
y_);
1154 declareActionCallback(PWMImpl)
1155 implementActionCallback(PWMImpl)
1165 LayoutKit& layout = *LayoutKit::instance();
1166 WidgetKit& kit = *WidgetKit::instance();
1167 PaperItem::fsize_ = kit.font()->size();
1169 Display* d = Session::instance()->default_display();
1173 Style*
q = Session::instance()->style();
1174 if (!q->find_attribute(
"pwm_canvas_height", canvasheight)) {
1175 canvasheight = 100.;
1177 const Color* outline_color;
1179 Display* dis = Session::instance()->default_display();
1180 if (!q->find_attribute(
"pwm_screen_outline_color", c)
1184 Scl = d->height()/canvasheight;
1185 Rect* sr =
new Rect(0, 0 ,d->width()/Scl , d->height()/Scl, outline_color);
1187 ScreenScene* screen =
new ScreenScene(-5, -2, d->width()/Scl + 5, d->height()/Scl + 2,
1191 if (!q->find_attribute(
"pwm_paper_height", pageheight)) {
1194 if (!q->find_attribute(
"pwm_paper_width", pagewidth)) {
1198 if (pageheight > pagewidth) pr_scl = pageheight/canvasheight;
1199 else pr_scl = pagewidth/canvasheight;
1202 if (d->width() > d->height()) wp1 = d->width()/Scl;
1203 else wp1 = canvasheight;
1205 Coord wp = pagewidth/pr_scl;
1206 Coord hp = pageheight/pr_scl;
1208 Rect* r =
new Rect(0,0,wp,hp, outline_color);
1211 PaperScene* paper =
new PaperScene(-5, -2,
Math::max(max,d->width()/Scl),
1215 pwmi_ =
new PWMImpl(screen, paper, r);
1216 if (!q->find_attribute(
"pwm_window_outline_color", c)
1220 outline_color->ref();
1221 pwmi_->window_outline_ = outline_color;
1222 pwmi_->screen_rect_ = sr;
1223 if (!q->find_attribute(
"pwm_paper_resolution",
pwmi_->round_factor_)) {
1224 pwmi_->round_factor_ = .25;
1226 pwmi_->canvasheight_ = canvasheight;
1227 pwmi_->round_factor_ /= pr_scl;
1229 if (q->find_attribute(
"pwm_pixel_resolution", ltmp)) {
1235 pwmi_->left_->ref();
1237 Menu* mbar, *mprint, *mses, *mother;
1240 if (q->value_is_on(
"pwm_help")) {
1241 vb->append(kit.push_button(
"Help",
1247 hb->append(mbar = kit.menubar());
1251 mi = kit.menubar_item(
"Print");
1252 mbar->append_item(mi);
1253 mprint = kit.pulldown();
1256 mi = kit.menubar_item(
"Session");
1257 mbar->append_item(mi);
1258 mses = kit.pulldown();
1262 mi = kit.menubar_item(
"Other");
1263 mbar->append_item(mi);
1264 mother = kit.pulldown();
1269 mi = kit.radio_menu_item(ttg,
"select");
1270 mbar->append_item(mi);
1271 mi->state()->set(TelltaleState::is_chosen,
true);
1272 mi->action(
new ActionCallback(PWMImpl)(
pwmi_, &PWMImpl::select_tool));
1274 mi = kit.radio_menu_item(ttg,
"move");
1275 mbar->append_item(mi);
1276 mi->action(
new ActionCallback(PWMImpl)(
pwmi_, &PWMImpl::move_tool));
1278 mi = kit.radio_menu_item(ttg,
"resize");
1279 mbar->append_item(mi);
1280 mi->action(
new ActionCallback(PWMImpl)(
pwmi_, &PWMImpl::resize_tool));
1283 mprint->append_item(mi);
1284 mi->action(
new ActionCallback(PWMImpl)(
pwmi_, &PWMImpl::do_print0));
1287 mprint->append_item(mi);
1288 mi->action(
new ActionCallback(PWMImpl)(
pwmi_, &PWMImpl::file_control));
1292 mprint->append_item(mi);
1293 mi->action(
new ActionCallback(PWMImpl)(
pwmi_, &PWMImpl::snapshot_control));
1298 mprint->append_item(mi);
1299 mi->action(
new ActionCallback(PWMImpl)(
pwmi_, &PWMImpl::idraw_control));
1302 mprint->append_item(mi);
1303 mi->action(
new ActionCallback(PWMImpl)(
pwmi_, &PWMImpl::ascii_control));
1304 #if MAC && !defined(carbon) 1306 mprint->append_item(mi);
1307 mi->action(
new ActionCallback(PWMImpl)(
pwmi_, &PWMImpl::paperscale));
1310 mprint->append_item(mi);
1311 mi->action(
new ActionCallback(PWMImpl)(
pwmi_, &PWMImpl::printer_control));
1315 mprint->append_item(mi);
1316 pwmi_->p_title_ = mi->state();
1320 mprint->append_item(mi);
1321 pwmi_->p_deco_ = mi->state();
1324 pwmi_->p_deco_->set(TelltaleState::is_chosen,
true);
1326 pwmi_->p_deco_->set(TelltaleState::is_chosen,
false);
1331 mses->append_item(mi);
1332 mi->action(
new ActionCallback(PWMImpl)(
pwmi_, &PWMImpl::retrieve_control));
1335 mses->append_item(mi);
1336 mi->action(
new ActionCallback(PWMImpl)(
pwmi_, &PWMImpl::save_selected_control));
1339 mses->append_item(mi);
1340 mi->action(
new ActionCallback(PWMImpl)(
pwmi_, &PWMImpl::save_all_control));
1343 mses->append_item(mi);
1344 mi->action(
new ActionCallback(PWMImpl)(
pwmi_, &PWMImpl::virt_screen));
1348 mprint->append_item(mi);
1349 mi->action(
new ActionCallback(PWMImpl)(
pwmi_, &PWMImpl::landscape));
1353 mses->append_item(mi);
1354 mi->action(
new ActionCallback(PWMImpl)(
pwmi_, &PWMImpl::tray));
1358 mother->append_item(mi);
1359 mi->action(
new ActionCallback(PWMImpl)(
pwmi_, &PWMImpl::quit_control));
1365 pwmi_->w_->replace_dismiss_action(
NULL);
1368 pwmi_->w_->xplace(-800, 0);
1371 pwmi_->w_->xplace(0,40);
1373 pwmi_->w_->xplace(0,0);
1382 void PWMImpl::select_tool() {
1385 void PWMImpl::move_tool() {
1388 void PWMImpl::resize_tool() {
1389 tool_ = Event::middle;
1401 LayoutKit& layout = *LayoutKit::instance();
1406 layout.variable_span(
new View(screen_)),
1407 layout.variable_span(pview_ =
new View(paper_))
1418 Style* s =
new Style(Session::instance()->style());
1419 s->attribute(
"name",
"Print & File Window Manager");
1462 return pwm_impl->cur_ses_name_.string();
1474 }
else if (
ifarg(2)) {
1477 bool b =
ifarg(1) ? (
chkarg(1, 0, 1) == 1.) :
true;
1478 pwm_impl->do_print_session(b);
1489 if (!w->is_mapped()) {
1491 if (pw && pw->is_mapped() && pw != w) {
1493 w->transient_for(pw);
1495 w->group_leader(pw);
1502 w->
xmove(left, top);
1533 pwmi_->screen_->append(
new ScreenItem(w));
1536 if (pw && pw->is_mapped() && pw != w) {
1538 w->transient_for(pw);
1541 w->group_leader(pw);
1552 pwmi_->screen_->append(
new ScreenItem(w));
1558 PWMImpl* impl =
pwmi_;
1559 if (w == impl->window()) {
1564 Scene* s = impl->screen_;
1567 if (i >= 0) s->
remove(i);
1573 PWMImpl* impl =
pwmi_;
1575 Scene* s = impl->screen_;
1578 if (i >= 0) s->
remove(i);
1584 #define PIXROUND(x,y,r) x = int((y + r/2)/r) * r 1588 if (
this == leader()) {
1600 PIXROUND(x, x1, pixres);
1601 PIXROUND(y, y1, pixres);
1602 if (x != x1 || y != y1) {
1612 w = canvas()->pwidth();
1613 h = canvas()->pheight();
1614 PIXROUND(x, w, pixres);
1615 PIXROUND(y, h, pixres);
1616 if (x == 0) x = pixres;
1617 if (y == 0) y = pixres;
1618 if (x != w || y != h) {
1619 canvas()->psize(x, y);
1626 PWMImpl* impl =
pwmi_;
1634 impl->screen_->move(i, l/Scl, b/Scl);
1635 impl->screen_->change(i);
1636 impl->screen_->show(i, w->is_mapped());
1637 ScreenItem* si = (ScreenItem*)impl->screen_->component(i);
1638 PaperItem* pi = si->paper_item();
1640 impl->paper_->change(impl->paper_index(pi));
1643 impl->all_window_bounding_box(e);
1644 impl->screen_->new_size(e.
left()/Scl - 5, e.
bottom()/Scl - 2,
1645 e.
right()/Scl + 5, e.
top()/Scl + 2);
1646 VirtualWindow::view();
1649 impl->screen_->location(i, x, y);
1650 printf(
"reconfigured %d %d %g %g\n", i, impl->screen_->showing(i), x, y);
1655 PWMImpl* impl =
pwmi_;
1661 Coord r = l + w->w();
1663 Coord t = b + w->h();
1664 impl->screen_->move(i, l/Scl, b/Scl);
1665 impl->screen_->change(i);
1666 impl->screen_->show(i, w->is_mapped);
1667 ScreenItem* si = (ScreenItem*)impl->screen_->component(i);
1668 PaperItem* pi = si->paper_item();
1670 impl->paper_->change(impl->paper_index(pi));
1673 impl->all_window_bounding_box(e);
1674 impl->screen_->new_size(e.
left()/Scl - 5, e.
bottom()/Scl - 2,
1675 e.
right()/Scl + 5, e.
top()/Scl + 2);
1676 VirtualWindow::view();
1679 impl->screen_->location(i, x, y);
1680 printf(
"reconfigured %d %d %g %g\n", i, impl->screen_->showing(i), x, y);
1697 void PWMImpl::all_window_bounding_box(
Extension& e,
bool with_screen,
bool also_leader) {
1700 Display* d = Session::instance()->default_display();
1702 e.
set_xy(
NULL, 0., 0., d->width(), d->height());
1708 for (i=0; i < screen_->count(); i++) {
1709 w = ((ScreenItem*)(screen_->component(i)))->window();
1710 if (w && w->is_mapped() && w != wl) {
1712 w->left() + w->width(), w->bottom() + w->height());
1717 if (w && w->is_mapped() && (also_leader || empty)) {
1719 w->left() + w->width(), w->bottom() + w->height());
1720 print_leader_flag_ =
true;
1722 print_leader_flag_ =
false;
1724 screen_rect_->width(d->width()/Scl);
1725 screen_rect_->height(d->height()/Scl);
1729 void PWMImpl::view_screen(
Coord x,
Coord y) {
1734 Display* d = Session::instance()->default_display();
1735 xp = d->to_pixels(-x) + d->pwidth()/2;
1736 yp = d->to_pixels(y) - d->pheight()/2;
1737 for (i=0; i < screen_->count(); i++) {
1738 ScreenItem* si = (ScreenItem*)screen_->component(i);
1741 if (w != window()) {
1745 JavaWindow* jw = si->jwindow();
1747 l = jw->l() + d->to_coord(xp);
1748 b = jw->b() - d->to_coord(yp);
1754 void PWMImpl::do_print0() {
1760 if (none_selected(
"No windows to print",
"Print Anyway")) {
1763 #if MAC && !defined(carbon) 1772 if (!printer_control_accept_) {
1779 do_print(use_printer, name.string());
1786 do_print(use_printer, fc_print_->selected()->string());
1790 void PWMImpl::do_print(
bool use_printer,
const char* name) {
1791 #if MAC && !defined(carbon) 1798 if (use_printer && strcmp(name,
"Windows") == 0) {
1803 ps_file_print(use_printer, name, landscape_,
false);
1806 void PWMImpl::do_print_session(
bool also_leader) {
1811 bool deco = p_deco_->test(TelltaleState::is_chosen);
1812 p_deco_->set(TelltaleState::is_chosen,
true);
1818 if (!mprinter()->
get()) {
return; }
1820 all_window_bounding_box(e,
false, also_leader);
1822 float s1 = (mprinter()->width() - 72.)/(e.
right() - e.
left() + 6.);
1823 float s2 = (mprinter()->height() - 72.)/(e.
top() - e.
bottom() + 23.);
1824 float sfac = (s1 < s2) ? s1 : s2;
1825 float xoff = mprinter()->width()/2/sfac - (e.
right() + e.
left() + 6.)/2.;
1826 float yoff = mprinter()->height()/2/sfac - (e.
top() + e.
bottom() + 23.)/2.;
1828 t.translate(xoff, yoff);
1829 #if MAC && !defined(carbon) 1830 mprinter()->prolog();
1831 t.scale(sfac, sfac);
1833 mprinter()->prolog(sfac);
1835 mprinter()->push_transform();
1836 mprinter()->transform(t);
1837 common_print(mprinter(),
false,
true);
1838 mprinter()->pop_transform();
1839 mprinter()->epilog();
1842 #if (!MAC || DARWIN) && !defined(WIN32) 1846 if (!printer_control_accept_) {
1854 ps_file_print(
true, name.string(),
true,
true);
1859 p_deco_->set(TelltaleState::is_chosen, deco);
1861 print_leader_flag_ =
true;
1864 void PWMImpl::do_print_session(
bool use_printer,
const char* name) {
1865 print_leader_flag_ =
true;
1866 ps_file_print(use_printer, name,
true,
true);
1869 void PWMImpl::ps_file_print(
bool use_printer,
const char* name,
bool land_style,
bool ses_style) {
1870 Style* s = Session::instance()->style();
1871 static char* tmpfile = (
char*)0;
1890 bool deco = p_deco_->test(TelltaleState::is_chosen);
1891 p_deco_->set(TelltaleState::is_chosen,
true);
1893 Style* s = Session::instance()->style();
1896 if (!s->find_attribute(
"pwm_paper_height", pageheight)) {
1899 if (!s->find_attribute(
"pwm_paper_width", pagewidth)) {
1903 all_window_bounding_box(e,
false,
true);
1905 float s1 = (pagewidth*72 - 72.)/(e.
right() - e.
left() + 6.);
1906 float s2 = (pageheight*72 - 72.)/(e.
top() - e.
bottom() + 23.);
1907 float sfac = (s1 < s2) ? s1 : s2;
1908 float xoff = pagewidth*72/2/sfac - (e.
right() + e.
left() + 6.)/2.;
1909 float yoff = pageheight*72/2/sfac - (e.
top() + e.
bottom() + 23.)/2.;
1911 t.translate(xoff, yoff);
1912 t.scale(sfac, sfac);
1913 pr->push_transform();
1915 common_print(pr,
false, ses_style);
1916 pr->pop_transform();
1918 p_deco_->set(TelltaleState::is_chosen, deco);
1921 common_print(pr, land_style, ses_style);
1927 s->find_attribute(
"pwm_postscript_filter", filt);
1928 char*
buf =
new char[200 + strlen(name) + strlen(filt.
string()) + 2*strlen(tmpfile)];
1935 sprintf(buf,
"%s < %s | %s ; rm %s", filt.
string(), tmpfile,
1943 sprintf(buf,
"%s < %s > %s ; rm %s", filt.
string(), tmpfile,
1962 void PWMImpl::mac_do_print() {
1964 if (!mprinter()->
get()) {
return; }
1966 mprinter()->prolog();
1967 common_print(mprinter(), landscape_,
false);
1968 mprinter()->epilog();
1972 void PWMImpl::common_print(
Printer*
pr,
bool land_style,
bool ses_style) {
1979 Style* s = Session::instance()->style();
1982 if (!s->find_attribute(
"pwm_paper_height", pageheight)) {
1985 if (!s->find_attribute(
"pwm_paper_width", pagewidth)) {
1988 pr->resize(0, 0, pagewidth*72, pageheight*72);
1994 t.translate(20, pr->height() - 70);
1996 t.translate(0, pr->height());
2010 ScreenItem* pi = (ScreenItem*)p->
component(
i);
2012 if (!pw->is_mapped()) {
continue; }
2016 float sfac = .9*pagewidth*72/pw->display()->height();
2021 t.scale(sfac, sfac);
2026 pw = pi->screen_item()->window();
2027 float sfac = pr_scl*72*pi->scale()/Scl;
2029 t.scale(sfac, sfac);
2030 t.translate(72*x*pr_scl, 72*y*pr_scl);
2045 pr->push_transform();
2047 pr->push_clipping();
2053 if (p_deco_->test(TelltaleState::is_chosen) ==
true) {
2054 print_deco(pr, a, pw->
name());
2057 pr->pop_transform();
2066 if ((ses_style || p_title_->test(TelltaleState::is_chosen) ==
true)
2068 && p_deco_->test(TelltaleState::is_chosen) ==
false 2072 Label label(pw->
name(), wk.font(), wk.foreground());
2078 alx.
origin(x1); alx.
span(r.x_requirement().natural());
2079 aly.
origin(y1); aly.
span(r.y_requirement().natural());
2090 Coord l,b,r,
t,w,h,
s,x,y,dx,xx;
2093 static const Color* ctitle;
2094 static const Color* ctitlebar;
2095 static const Color* coutline;
2096 static const Color* bright;
2097 static const Color* dark;
2098 static const Font* ftitle;
2099 static const Brush* br;
2100 static int first = 1;
2108 bright =
new Color(.9,.9,.9,1.); bright->ref();
2109 dark =
new Color(.1,.1,.1,1.); dark->ref();
2110 ctitle =
new Color(0.,0.,0.,1.); ctitle->ref();
2111 ctitlebar =
new Color(.8,.8,.8,1.); ctitlebar->ref();
2112 coutline =
new Color(.7,.7,.7,1.); coutline->ref();
2113 br =
new Brush(1); br->ref();
2114 ftitle = wk.font(); ftitle->ref();
2120 pr->fill_rect(l, t, r, t+h, ctitlebar);
2123 Label label(title, ftitle, ctitle);
2129 Coord xo = (l + r)/2 - x/2;
2130 xo = (xo < h) ? h : xo;
2134 pr->push_clipping();
2135 pr->clip_rect(l+h, t, r, t+h);
2140 pr->fill_rect(l,b-w,l-w,t+h+w,coutline);
2141 pr->fill_rect(r,b-w,r+w,t+h+w,coutline);
2142 pr->fill_rect(l,b,r,b-w,coutline);
2143 pr->fill_rect(l,t+h,r,t+h+w,coutline);
2144 pr->rect(l-w,b-w,r+w,t+h+w,dark, br);
2147 x = (l + (l+h-
s))/2;
2150 pr->rect(x-dx,y-dx,x+dx,y+dx,bright,br);
2152 pr->line(x-dx,y-dx,x+dx,y+dx, bright,br);
2153 pr->line(x-dx,y+dx,x+dx,y-dx, bright,br);
2158 static char* tmpfile = (
char*)0;
2162 Style* s = Session::instance()->style();
2165 if (s->find_attribute(
"pwm_postscript_filter", filt)) {
2166 #if defined(WIN32) && !defined(CYGWIN) 2168 hoc_warning(
"CopyFile failed.",
"Did not run pwm_postscript_filter");
2172 filt.
string(), tmpfile, filename);
2174 sprintf(buf,
"cat %s > %s; %s < %s > %s",
2176 filt.
string(), tmpfile, filename);
2183 #if defined(WIN32) || MAC 2187 void PWMImpl::redraw(
Window* pw) {
2189 if (!pw->is_mapped()){
2192 Canvas* c = pw->canvas();
2194 #if defined(WIN32) || MAC 2199 Coord xsize = c->width();
2200 Coord ysize = c->height();
2201 pw->glyph()->request(req);
2207 c->push_transform();
2209 pw->glyph()->draw(c, a);
2222 iconify_via_hide_ =
false;
2224 ScreenItem::ScreenItem(JavaWindow* w) {
2231 iconify_via_hide_ =
false;
2234 ScreenItem::~ScreenItem(){
2239 pwm_impl->remove_paper(pi_);
2252 Glyph* g = WidgetKit::instance()->label(buf);
2259 void ScreenItem::reconfigured(
Scene* s) {
2263 Coord t = b +
w_->height_pw();
2264 s->
move(i, l/Scl, b/Scl);
2268 printf(
"reconfigured %d %d %g %g\n", i, s->
showing(i), x, y);
2270 if (
w_->is_mapped()) {
2271 impl->w_->canvas()->damage_all();
2276 void ScreenItem::request(
Requisition& req)
const {
2279 w =
w_->width_pw()/Scl;
2280 h =
w_->height_pw()/Scl;
2304 printf(
"ScreenItem::draw %d\n", i_);
2310 c->rect(x, y, x + (
w_->width_pw())/Scl, y + (
w_->height_pw())/Scl, pwm_impl->window_outline_,
NULL);
2312 c->rect(x, y, x + (jw_->w())/Scl, y + (jw_->h())/Scl, pwm_impl->window_outline_,
NULL);
2319 Coord y = h.bottom();
2322 h.target(depth,
this, 0);
2323 if (h.event()->type() == Event::down) {
2328 switch (pwm_impl->tool(h.event()->pointer_button())) {
2330 h.target(depth,
this, 0,
2331 new ScreenItemHandler(
2332 x, y,
this, c->transformer()
2338 pwm_impl->append_paper(
this);
2343 printf(
"ScreenItem::pick %d hit(%g,%g)\n", i_, x, y);
2344 print_alloc(
NULL,
"ScreenItem", a);
2352 PaperItem::PaperItem(ScreenItem* s) {
2358 PaperItem::~PaperItem(){
2366 Coord PaperItem::width() {
return si_->w_->width_pw()/Scl;}
2367 Coord PaperItem::fsize_;
2375 printf(
"PaperItem::request %d\n", screen_item()->
index());
2383 printf(
"PaperItem::allocate %d\n", screen_item()->
index());
2389 printf(
"PaperItem::draw %d\n", si_->i_);
2393 c->rect(x, y, x + scale_*(si_->w_->width_pw())/Scl, y + scale_*(si_->w_->height_pw())/Scl, pwm_impl->window_outline_,
NULL);
2394 si_->label_->draw(c, a);
2401 pr->rect(x, y, x + scale_*(si_->w_->width_pw())/Scl, y + scale_*(si_->w_->height_pw())/Scl, blue,
NULL);
2402 pr->push_transform();
2406 si_->w_->glyph()->print(pr, a);
2407 pr->pop_transform();
2412 Coord y = h.bottom();
2414 h.target(depth,
this, 0);
2415 if (h.event()->type() == Event::down) {
2420 switch (pwm_impl->tool(h.event()->pointer_button())) {
2424 new PaperItem_handler(
2426 x, y,
this, c->transformer()
2433 new PaperItem_handler(
2435 x, y,
this, c->transformer()
2440 pwm_impl->unshow_paper(
this);
2444 printf(
"PaperItem::pick %d hit(%g, %g)\n", si_->i_, x, y);
2451 PWMImpl::PWMImpl(ScreenScene* screen, PaperScene* paper,
Rect* prect) {
2461 printer_control_accept_ =
true;
2467 fc_retrieve_ =
NULL;
2475 PWMImpl::~PWMImpl() {
2496 MacPrinter* PWMImpl::mprinter() {
2498 mprinter_ =
new MacPrinter();
2505 void PWMImpl::all2front() {
2508 if (screen_)
for (i=0; i < screen_->count(); ++
i) {
2509 ScreenItem* si = (ScreenItem*)(screen_->component(i));
2511 if (w && w != w->
leader() && w->is_mapped()) {
2518 void PWMImpl::map_all() {
2522 if (screen_)
for (i=0; i < screen_->count(); i++) {
2523 ScreenItem* si = (ScreenItem*)(screen_->component(i));
2527 if (si->iconify_via_hide_ ==
true) {
2534 si->jwindow()->map();
2538 void PWMImpl::unmap_all() {
2542 if (screen_)
for (i=0; i < screen_->count(); i++) {
2543 ScreenItem* si = (ScreenItem*)(screen_->component(i));
2547 if (screen_->showing(i)) {
2549 si->iconify_via_hide_ =
true;
2551 si->iconify_via_hide_ =
false;
2557 si->jwindow()->hide();
2564 if (screen_)
for (i=0; i < screen_->count(); i++) {
2565 ScreenItem* si = (ScreenItem*)screen_->component(i);
2566 if (w == (
void*)si->window() || w == (
void*)si->jwindow()) {
2573 void PWMImpl::relabel() {
2575 for (i=0; i < screen_->count(); i++) {
2576 ((ScreenItem*)screen_->component(i))->relabel(i);
2583 void PWMImpl::append_paper(ScreenItem* si) {
2584 PaperItem* pi = si->paper_item();
2587 i = paper_index(pi);
2588 paper_->show(i,
true);
2590 pi =
new PaperItem(si);
2593 i = paper_index(pi);
2594 Coord x = si->window()->left_pw()/Scl;
2595 Coord y = si->window()->bottom_pw()/Scl;
2596 x = (x < 0.) ? 0. : x;
2597 y = (y < 0.) ? 0. : y;
2598 x = (x > paper_->x2()*.8) ? paper_->x2()*.8 : x;
2599 y = (y > paper_->y2()*.8) ? paper_->y2()*.8 : y;
2600 paper_->move(i, x, y);
2605 void PWMImpl::unshow_paper(PaperItem* pi) {
2606 paper_->show(paper_index(pi),
false);
2609 void PWMImpl::remove_paper(PaperItem* pi) {
2611 if (paper_ && i != -1) {
2616 GlyphIndex PWMImpl::paper_index(PaperItem* pi) {
2618 if (paper_)
for (i=0; i < paper_->count(); i++) {
2619 if (pi == (PaperItem*)paper_->component(i)) {
2626 float PWMImpl::round(
float x) {
2627 return Math::round(x/round_factor_) * round_factor_;
2631 void PWMImpl::paperscale() {
2632 mprinter()->setup();
2634 w = mprinter()->width()/72.;
2635 x = h = mprinter()->height()/72.;
2639 x = x/canvasheight_;
2640 prect_->width(w/pr_scl);
2641 prect_->height(h/pr_scl);
2642 pview_->box_size(-.2, -.2, prect_->width() + .2, prect_->height() + .2);
2644 paper_->damage_all();
2649 void PWMImpl::landscape() {
2654 w = prect_->width();
2655 h = prect_->height();
2658 paper_->damage_all();
2659 landscape_ = !landscape_;
2662 void PWMImpl::landscape(
bool b) {
2663 if (landscape_ != b) {
2668 void PWMImpl::deco(
int i) {
2669 p_title_->set(TelltaleState::is_chosen,
false);
2670 p_deco_->set(TelltaleState::is_chosen,
false);
2672 p_title_->set(TelltaleState::is_chosen,
true);
2674 p_deco_->set(TelltaleState::is_chosen,
true);
2678 void PWMImpl::virt_screen() {
2683 VirtualWindow::makeVirtualWindow();
2687 static const char* DefaultPrintCmd () {
2689 Style* style = Session::instance()->style();
2691 if (style->find_attribute(
"printer_command", str)) {
2698 static char buf[200];
2699 static const char* print_cmd =
getenv(
"PRINT_CMD");
2700 if (print_cmd ==
NULL) {
2701 const char* printer_name =
getenv(
"PRINTER");
2703 if (printer_name ==
NULL) {
2706 sprintf(buf,
"lpr -P%s", printer_name);
2714 void PWMImpl::printer_control() {
2719 Style* style =
new Style(Session::instance()->style());
2720 style->attribute(
"caption",
"Postscript Printer Command");
2722 DefaultPrintCmd(), style);
2727 if (
w_ &&
w_->is_mapped()) {
2728 b = b_printer_->post_for(
w_);
2741 b = b_printer_->post_at_aligned(x, y, ax, ay);
2744 printer_control_accept_ =
true;
2746 printer_control_accept_ =
false;
2750 void PWMImpl::quit_control() {
2763 void PWMImpl::snapshot_control() {
2764 if (file_control1()) {
2765 ivoc_snapshot_ = ivoc_snapshot;
2770 bool PWMImpl::file_control1() {
2775 Style* style =
new Style(Session::instance()->style());
2777 if (style->find_attribute(
"pwm_print_file_filter", str)) {
2778 style->attribute(
"filter",
"true");
2779 style->attribute(
"filterPattern", str);
2781 style->attribute(
"caption",
"Print Postscript to file");
2782 style->attribute(
"open",
"Print to file");
2783 fc_print_ = DialogKit::instance()->file_chooser(
"./", style);
2786 fc_print_->reread();
2788 while (fc_print_->post_for(
w_)) {
2796 void PWMImpl::file_control() {
2797 if (none_selected(
"No windows to save",
"Save Anyway")) {
2800 if (file_control1()) {
2801 use_printer =
false;
2808 void PWMImpl::snapshot(
const Event* e) {
2811 obuf.open(fc_print_->selected()->string(),
IOS_OUT);
2815 pr->resize(0,0,1200, 1000);
2829 t.translate(w->left(), w->bottom());
2831 Glyph* g = w->Window::glyph();
2835 Allotment ax(align_x*w->width(), w->width(), align_x);
2836 Allotment ay(align_y*w->width(), w->height(), align_y);
2841 t.translate(a.left(), -a.bottom());
2842 Style* s = w->style();
2845 if (s && s->find_attribute(
"name", str)) {
2847 pr->comment(str.
string());
2851 sprintf(buf,
"BoundingBox: %g %g %g %g",
2852 w->left() - 3, w->bottom() - 3,
2853 w->left() + w->width() + 3,
2854 w->bottom() + w->height() + 20 + 3);
2856 sprintf(buf,
"\\begin{picture}(%g, %g)",
2857 w->width() + 6, w->height() + 23);
2860 sprintf(buf,
"BoundingBox: %g %g %g %g", w->left(), w->bottom(),
2861 w->left() + w->width(), w->bottom() + w->height());
2863 sprintf(buf,
"\\begin{picture}(%g, %g)",
2864 w->width(), w->height());
2867 pr->push_transform();
2871 print_deco(pr, a, str.
string());
2874 pr->pop_transform();
2879 pr->comment(
"End BoundingBox");
2882 void PWMImpl::snap_cursor(
Printer* pr,
const Event* e) {
2884 if (rb && rb->
canvas()->window() == e->window()) {
2885 pr->comment(
"Begin Rubberband");
2887 t1.translate(e->window()->left(), e->window()->bottom());
2888 pr->push_transform();
2891 pr->pop_transform();
2892 pr->comment(
"End Rubberband");
2901 t.translate(e->window()->left(), e->window()->bottom());
2903 pr->comment(
"Begin cursor");
2904 pr->push_transform();
2908 pr->line_to(8, -14);
2909 pr->line_to(2, -12);
2910 pr->line_to(2, -20);
2911 pr->line_to(-2, -20);
2912 pr->line_to(-2, -12);
2913 pr->line_to(-8, -14);
2915 pr->fill(WidgetKit::instance()->foreground());
2917 pr->pop_transform();
2918 pr->comment(
"End cursor");
2922 void PWMImpl::idraw_control() {
2927 Style* style =
new Style(Session::instance()->style());
2929 if (style->find_attribute(
"pwm_idraw_file_filter", str)) {
2930 style->attribute(
"filter",
"true");
2931 style->attribute(
"filterPattern", str);
2933 style->attribute(
"caption",
"Idraw format to file");
2934 style->attribute(
"open",
"Write to file");
2935 fc_idraw_ = DialogKit::instance()->file_chooser(
"./", style);
2938 fc_idraw_->reread();
2940 if (none_selected(
"No windows to save",
"Save Anyway")) {
2943 while (fc_idraw_->post_for(
w_)) {
2945 idraw_write(fc_idraw_->selected()->string());
2951 void PWMImpl::idraw_write(
const char*
fname,
bool ses_style) {
2963 for (
GlyphIndex i = 0; i < screen()->count(); ++
i) {
2964 ScreenItem* pi = (ScreenItem*)screen()->component(i);
2965 redraw(pi->window());
2972 PaperItem* pi = (PaperItem*)p->
component(i);
2973 redraw(pi->screen_item()->window());
2981 void PWMImpl::ascii_control() {
2986 Style* style =
new Style(Session::instance()->style());
2988 if (style->find_attribute(
"pwm_ascii_file_filter", str)) {
2989 style->attribute(
"filter",
"true");
2990 style->attribute(
"filterPattern", str);
2992 style->attribute(
"caption",
"Ascii format to file");
2993 style->attribute(
"open",
"Write to file");
2994 fc_ascii_ = DialogKit::instance()->file_chooser(
"./", style);
2997 fc_ascii_->reread();
2999 if (none_selected(
"No windows to save",
"Save Anyway")) {
3002 while (fc_ascii_->post_for(
w_)) {
3004 ascii_write(fc_ascii_->selected()->string());
3010 void PWMImpl::ascii_write(
const char* fname,
bool ses_style) {
3021 for (
GlyphIndex i = 0; i < screen()->count(); ++
i) {
3022 ScreenItem* pi = (ScreenItem*)screen()->component(i);
3023 redraw(pi->window());
3027 if (!p->
showing(i) && !ses_style) {
3030 PaperItem* pi = (PaperItem*)p->
component(i);
3031 redraw(pi->screen_item()->window());
3040 void PWMImpl::save_selected_control() {
3043 void PWMImpl::save_all_control() {
3046 bool PWMImpl::none_selected(
const char* title,
const char* accept)
const{
3048 if (paper_)
for (i=0; i < paper_->count(); ++
i) {
3049 if (paper_->showing(i)) {
3061 void PWMImpl::save_control(
int mode) {
3071 if (none_selected(
"No windows to save",
"Save Anyway")) {
3075 Style* style =
new Style(Session::instance()->style());
3077 if (style->find_attribute(
"pwm_save_file_filter", str)) {
3078 style->attribute(
"filter",
"true");
3079 style->attribute(
"filterPattern", str);
3081 style->attribute(
"caption",
"Save windows on paper icon to file");
3082 style->attribute(
"open",
"Save to file");
3083 fc_save_ = DialogKit::instance()->file_chooser(
"./", style);
3088 while (fc_save_->post_for(
w_)) {
3090 save_session(mode, fc_save_->selected()->string());
3096 int PWMImpl::save_group(
Object* ho,
const char* filename) {
3099 ScreenItem** sivec =
NULL;
3101 if (screen_ && screen_->count()) {
3102 sivec =
new ScreenItem*[screen_->count()];
3103 for (i=0; i < screen_->count(); i++) {
3104 si = (ScreenItem*)(screen_->component(i));
3105 if (si->group_obj_ == ho) {
3111 cur_ses_name_ = filename;
3119 save_list(nwin, sivec, o);
3128 void PWMImpl::save_session(
int mode,
const char* filename,
const char* head) {
3131 ScreenItem** sivec =
NULL;
3134 cur_ses_name_ = filename;
3139 if (!obuf.is_open()) {
3151 if (screen_ && screen_->count()) {
3152 sivec =
new ScreenItem*[screen_->count()];
3153 for (i=0; i < screen_->count(); i++) {
3154 si = (ScreenItem*)(screen_->component(i));
3162 sprintf(buf,
"{pwman_place(%d,%d,%d)}\n", w->
xleft(), w->
xtop(), w->is_mapped() ? 1 : 0);
3166 }
else if (si->jwindow()){
3172 if (paper_ && paper_->count()) {
3173 sivec =
new ScreenItem*[paper_->count()];
3174 for (i=0; i < paper_->count(); i++) {
3175 if (paper_->showing(i)) {
3176 si = ((PaperItem*)(paper_->component(i)))->screen_item();
3186 }
else if (si->jwindow()){
3194 save_list(nwin, sivec, o);
3201 void PWMImpl::save_begin(ostream& o) {
3202 Oc::save_stream = &
o;
3204 HocPanel::save_all(o);
3205 o <<
"objectvar ocbox_, ocbox_list_, scene_, scene_list_" << endl;
3206 o <<
"{ocbox_list_ = new List() scene_list_ = new List()}" << endl;
3209 void PWMImpl::save_list(
int nwin, ScreenItem** sivec, ostream& o) {
3213 ses_group_first_ = 1;
3215 for (working = 10000; working >= 0; working =
max) {
3218 for (i=0; i < nwin; ++
i) {
3219 if (sivec[i]->window()) {
3220 ocg = (
OcGlyph*)sivec[i]->window()->glyph();
3223 pri = sivec[
i]->jwindow()->priority();
3225 if (pri == working) {
3227 if (sivec[i]->window()) {
3230 sivec[
i]->jwindow()->save_session(cur_ses_name_.string(),
o);
3232 ses_group(sivec[i], o);
3234 if (pri < working && pri > max) {
3239 Oc::save_stream =
NULL;
3240 o <<
"objectvar scene_vector_[1]\n{doNotify()}" << endl;
3243 void PWMImpl::ses_group(ScreenItem* si, ostream& o) {
3246 if (si->group_obj_) {
3248 sprintf(buf,
"{WindowMenu[0].ses_gid(%d, %d, %d, \"%s\")}\n",
3249 ses_group_first_, si->group_obj_->index,
3250 (screen()->showing(si->index()) ? 1 : 0),
name);
3252 ses_group_first_ = 0;
3256 void PWMImpl::retrieve_control() {
3260 if (!fc_retrieve_) {
3261 Style* style =
new Style(Session::instance()->style());
3263 if (style->find_attribute(
"pwm_save_file_filter", str)) {
3264 style->attribute(
"filter",
"true");
3265 style->attribute(
"filterPattern", str);
3267 style->attribute(
"caption",
"Retrieve windows from file");
3268 style->attribute(
"open",
"Retrieve from file");
3269 fc_retrieve_ = DialogKit::instance()->file_chooser(
"./", style);
3270 fc_retrieve_->ref();
3272 fc_retrieve_->reread();
3274 while (fc_retrieve_->post_for(
w_)) {
3278 sprintf(buf,
"{load_file(1, \"%s\")}\n", fc_retrieve_->selected()->string());
3279 if( ! oc.
run(buf)) {
3286 class OcLabelGlyph :
public OcGlyph {
3289 virtual ~OcLabelGlyph();
3290 virtual void save(ostream&);
3296 OcLabelGlyph::OcLabelGlyph(
const char* label,
OcGlyph* og,
Glyph* g){
3304 OcLabelGlyph::~OcLabelGlyph(){
3305 og_->parents(
false);
3311 o <<
"{xpanel(\"\")" << endl;
3312 sprintf(buf,
"xlabel(\"%s\")", label_.string());
3314 o <<
"xpanel()}" << endl;
3321 virtual ~TrayDismiss();
3325 class OcTray :
public OcBox {
3330 virtual void start_vbox();
3340 TrayDismiss::~TrayDismiss() {}
3342 if (
boolean_dialog(
"Dismiss or Dissolve into components?",
"Dissolve",
3344 OcTray* t = (OcTray*)win_->glyph();
3345 t->dissolve(win_->left(), win_->bottom());
3351 x_ =
new float[
cnt];
3352 y_ =
new float[
cnt];
3364 void OcTray::dissolve(
Coord left,
Coord bottom) {
3370 for (i=0; i <
cnt; ++
i) {
3373 g = (
OcGlyph*)pg_->component(i);
3385 void OcTray::start_vbox() {
3393 wk->begin_style(
"_tray_panel");
3395 pg_->append(w->
glyph());
3397 y_[
n] = w->bottom();
3398 v_->box_append (
new OcLabelGlyph(
3402 wk->label(w->
name()),
3403 lk->fixed(w->
glyph(), w->width(), w->height())
3418 void PWMImpl::tray() {
3425 count = paper_->count();
3430 Coord minleft = -1000;
3432 OcTray* tray =
new OcTray(count);
3433 while ( (index = upper_left()) != -1) {
3434 PaperItem* pi = (PaperItem*)paper_->component(index);
3441 minleft = l + w->width()/2.;
3444 top = b + w->height();
3447 paper_->show(index,
false);
3450 Window* w = tray->make_window();
3456 Coord minleft = 1e10;
3457 Coord maxbottom = -1e10;
3460 PaperItem* pi = (PaperItem*)paper_->component(i);
3463 if (!paper_->showing(i))
continue;
3464 if (w == pwm_impl->w_) {
3472 if (l < minleft - 50.) {
3476 }
else if (l < minleft + 50.) {
3477 if (maxbottom < b) {
3488 void PWMImpl::dissolve() {
3489 for (
long i = 0; i < panelList_.count(); i++) {
3490 new HocWin(panelList_.item(i));
3497 bool ivoc_snapshot(
const Event* e) {
3500 if (buf[0] ==
'p') {
3501 ivoc_snapshot_ =
NULL;
3512 #include <IV-X11/Xlib.h> 3513 #include <IV-X11/xdisplay.h> 3519 WindowTable* wt = Session::instance()->default_display()->rep()->wtable_;
3521 Window* w = i.cur_value();
3522 if (w->is_mapped()) {
3531 JavaWindow::JavaWindow(
const char* s,
Object* o) {
3533 title =
new char[strlen(s) + 1];
3536 pl = pt = 0; pw = ph = 100;
3542 JavaWindow::~JavaWindow() {
3550 Coord JavaWindow::l() {
3551 return Session::instance()->default_display()->to_coord(pl);
3554 Coord JavaWindow::b() {
3555 Display* d = Session::instance()->default_display();
3556 return d->to_coord(d->pheight() - (pt + ph));
3559 Coord JavaWindow::w() {
3560 return Session::instance()->default_display()->to_coord(pw);
3563 Coord JavaWindow::h() {
3564 return Session::instance()->default_display()->to_coord(ph);
3568 (*nrnjava_pwm_setwin)(
this, 1, 0, 0);
3570 void JavaWindow::hide() {
3571 (*nrnjava_pwm_setwin)(
this, 2, 0, 0);
3574 Display* d = Session::instance()->default_display();
3575 int left = d->to_pixels(x);
3576 int top = d->pheight() - d->to_pixels(y) - ph;
3577 (*nrnjava_pwm_setwin)(
this, 3,
left, top);
3579 void JavaWindow::pmove(
int l,
int t) {
3580 (*nrnjava_pwm_setwin)(
this, 3, l,
t);
3582 void JavaWindow::presize(
int w,
int h) {
3583 (*nrnjava_pwm_setwin)(
this, 4, w, h);
3602 int JavaWindow::priority() {
3616 void JavaWindow::save_session(
const char* fname, ostream& o) {
3623 if (!ho ) {
return; }
3625 o <<
"/*Begin " << title <<
" */\n";
3626 sprintf(buf,
"{load_java(\"%s\", \"%s\")}\n",
3628 ho->ctemplate->sym->name);
3630 sprintf(buf,
"ocbox_ = new %s()\n", ho->ctemplate->sym->name);
3637 char* b2 =
new char[strlen(fname)+1];
3640 char** cpp = (*p_java2nrn_smeth)(ho,
s);
3646 sprintf(buf,
"{PWManager[0].jwindow(ocbox_, %d, %d, %d, %d, %d)}\n",
3647 is_mapped?1:0, pl, pt, pw, ph);
3649 o <<
"objref ocbox_\n";
3650 o <<
"/*End " << title <<
" */\n";
3654 JavaWindow* jw =
new JavaWindow(s, ho);
3661 JavaWindow* jw = (JavaWindow*)ic;
3663 if (type >= 3 && type <= 6) {
3672 jw->closing_ =
true;
3676 jw->is_mapped =
false;
3687 jw->is_mapped =
false;
3693 jw->is_mapped =
true;
3698 jw->is_mapped =
true;
3718 #if MAC && !defined(carbon) 3720 tmpfile =
new char[512];
3721 __temp_file_name(tmpfile, &spec);
3723 const char* tdir =
getenv(
"TEMP");
3727 #if defined(WIN32) && defined(__MWERKS__) 3728 char tname[L_tmpnam+1];
3730 tmpfile =
new char[strlen(tdir) + 1 + strlen(tname) + 1];
3731 sprintf(tmpfile,
"%s/%s", tdir, tname);
3733 tmpfile =
new char[strlen(tdir) + 1 + 9 + 1];
3734 sprintf(tmpfile,
"%s/nrnXXXXXX", tdir);
3737 if ((fd = mkstemp(tmpfile)) == -1) {
void allot_x(const Allotment &)
static MenuItem * menu_item(const char *)
const char *(* p_java2nrn_classname)(Object *ho)
static ostream * idraw_stream
void xmove(int left, int top)
static void unref(Object *obj)
virtual void update(Observable *)
double max(double a, double b)
static double pwman_hide(void *v)
virtual Glyph * component(GlyphIndex) const
static Member_func members[]
static double pwman_snap(void *v)
static char * object_str(const char *symname, Object *=NULL)
void set(Canvas *, const Allocation &)
bool ok_to_write(const String &, Window *w=NULL)
virtual PrintableWindow * make_window(Coord left=-1, Coord bottom=-1, Coord width=-1, Coord height=-1)
static Member_ret_str_func s_memb[]
char * hoc_back2forward(char *s)
void pwmimpl_redraw(Window *w)
carbon
#define TRY_GUI_REDIRECT_NO_RETURN(name, obj)
static double pwman_landscape(void *v)
static double pwman_deco(void *v)
static double pwman_jwindow(void *v)
void psfilter(const char *filename)
#define TRY_GUI_REDIRECT_ACTUAL_STR(name, obj)
void append(PrintableWindow *)
static double inside(void *)
void xplace(int, int, bool map=true)
void reconfigured(PrintableWindow *)
void(* nrnjava_pwm_setwin)(void *, int, int, int)
static void help(const char *)
void set_xy(Canvas *, Coord left, Coord bottom, Coord right, Coord top)
const char * pwm_session_filename()
static MenuItem * check_menu_item(const char *)
virtual Coord width_pw() const
static void save_all(std::ostream &)
const Requirement & x_requirement() const
virtual Glyph * glyph() const
sprintf(buf," if (secondorder) {\ " int _i;\" " for(_i=0;_i< %d;++_i) {\" " _p[_slist%d[_i]]+=dt *_p[_dlist%d[_i]];\" " }}\", numeqn, listnum, listnum)
int system(const char *s)
static void pr(N_Vector x)
#define TRY_GUI_REDIRECT_ACTUAL_DOUBLE(name, obj)
virtual const char * name() const
void size(Coord x1, Coord y1, Coord x2, Coord y2)
static double pwman_manager(void *v)
const char * string() const
virtual void save(std::ostream &)
char * ivoc_get_temp_file()
#define declareTable(Table, Key, Value)
static double map(void *v)
virtual Coord height_pw() const
static const Brush * default_brush()
void nrnjava_pwm_event(size_t, int, int, int, int, int)
static double pwman_printfile(void *v)
void * nrnjava_pwm_listen(const char *, Object *)
static double pwman_scale(void *v)
void allot_y(const Allotment &)
virtual void reconfigured()
static double pwman_save(void *v)
static double ref(void *v)
int const size_t const size_t n
#define TRY_GUI_REDIRECT_DOUBLE(name, obj)
const Requirement & y_requirement() const
static ostream * save_stream
double(* nrnpy_object_to_double_)(Object *)
static std::ostream * ascii()
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...
static const char ** pwman_name(void *v)
void class2oc(const char *, void *(*cons)(Object *), void(*destruct)(void *), Member_func *, int(*checkpoint)(void **), Member_ret_obj_func *, Member_ret_str_func *)
void hoc_obj_unref(Object *obj)
static Rubberband * current()
virtual Coord left_pw() const
void hoc_warning(const char *, const char *)
virtual void reconfigured()
static double pwman_close(void *v)
static const char * fname(const char *name)
virtual void attach(Observer *)
void hoc_execerror(const char *, const char *)
void location(GlyphIndex, Coord &x, Coord &y) const
void require_y(const Requirement &)
char * getenv(const char *s)
void move(GlyphIndex, Coord x, Coord y)
static void extend(Extension &, Coord)
static double pwman_iconify(void *v)
virtual void unref() const
static void * pwman_cons(Object *)
virtual void disconnect(Observable *)
static double pwman_leader(void *v)
void hoc_obj_ref(Object *obj)
void xplace(int left, int top)
static double resize(void *v)
bool ok_to_read(const String &, Window *w=NULL)
static double pwman_count(void *v)
bool showing(GlyphIndex) const
virtual void map_notify()
void remove(PrintableWindow *)
static double pwman_window_place(void *v)
#define TableIterator(Table)
void ivoc_bring_to_top(Window *w)
void require_x(const Requirement &)
static bool is_transient()
#define TRY_GUI_REDIRECT_OBJ(name, obj)
virtual Scene * scene() const
static FieldDialog * field_dialog_instance(const char *, Style *, Glyph *extra=NULL)
static double save(void *v)
void continue_dialog(const char *label, Window *w=NULL, Coord x=400., Coord y=400.)
#define TRY_GUI_REDIRECT_ACTUAL_OBJ(name, obj)
double(* p_java2nrn_dmeth)(Object *ho, Symbol *method)
static double pwman_paper_place(void *v)
virtual void remove(GlyphIndex)
Symbol * hoc_table_lookup(const char *, Symlist *)
virtual ~PrintableWindowManager()
virtual void pick(Canvas *, const Allocation &, int depth, Hit &)
virtual void detach(Observer *)
static PrintableWindowManager * current()
static PrintableWindow * leader()
virtual void snapshot(Printer *)
Allotment & x_allotment()
int hoc_copyfile(const char *src, const char *dest)
bool(* p_java2nrn_identity)(Object *o1, Object *o2)
bool boolean_dialog(const char *label, const char *accept, const char *cancel, Window *w=NULL, Coord x=400., Coord y=400.)
static Object ** pwman_group(void *v)
static double pwman_map(void *v)
virtual GlyphIndex count() const
static OcGlyphContainer * intercept(OcGlyphContainer *)
int hoc_is_object_arg(int narg)
void hoc_pushstr(char **d)
virtual void replace_dismiss_action(WinDismiss *)
void merge_xy(Canvas *, Coord left, Coord bottom, Coord right, Coord top)
Allotment & y_allotment()
Object ** hoc_temp_objptr(Object *)
static double pwman_deiconify(void *v)
char ** hoc_temp_charptr(void)
int run(int argc, const char **argv)
void debugfile(const char *,...)
static PrintableWindowManager * current_
static void pwman_destruct(void *v)
Object ** hoc_objgetarg(int)
static Member_ret_obj_func retobj_members[]
double chkarg(int, double low, double high)
virtual Glyph * print_glyph()
static double pwman_is_mapped(void *v)
static double working(void *v)
virtual Coord bottom_pw() const