#include "layout.h" #include "menu.h" float borderS = 5; float borderN = 5; float borderE = 5; float borderW = 5; /********************************************************************* * adding members (layouts) */ void addmember(drawable m) { if (m.descendantof(/layout)) super.addmember(m); else @current_layout.addmember(m); } /********************************************************************* * layout methods */ int current_layout_index() { return max(0,arrayindex(members,@current_layout) - 1); } void new_layout() { struct layout l = (struct layout)newmember(/layout); members = (drawable *)arraydelete(members,length(members)); members = (drawable *)arrayinsert(members,current_layout_index + 2,l); goto_layout(l); } void goto_layout(any l) { switch (truedicttype(l)) { case /realtype: case /fixedtype: l = round((float)l); case /integertype: l = (layout)members[min(length(members)-2,cvi((int)l)) + 1]; break; default: l = (layout)find_object(l); break; } if ((arrayindex(members,l) > 0) && (l != @current_layout)) { if (edit_mode) Send stop_edit_ctx() to @edit_ctx; @current_layout.unmap(); @current_layout = (drawable)l; @current_layout.map(); if (edit_mode) Send start_edit_ctx() to @edit_ctx; } } void goto_next_layout() { int nr = current_layout_index(); goto_layout((nr + 1) % (length(members) - 1)); } void goto_previous_layout() { int nr = current_layout_index(); goto_layout((nr <= 0) ? (length(members) - 2) : (nr-1)); } void goto_first_layout() { goto_layout(members[1]); } void goto_last_layout() { goto_layout(members[length(members)-1]); } /********************************************************************* * Window plus layout methods */ void oninit() { if (!length(members)) { newmember(/layout); newmember(/layout); } @window = (drawable)soften(self); @window_layout = (drawable)soften(members[0]); @current_layout = (drawable)soften(members[1]); @first_layout = (drawable)soften(members[1]); @window_layout.map(); @current_layout.map(); super.oninit(); } void Paint() { super.Paint(); rectpath(insetstroke(-1,[borderW,borderS, w - (borderW + borderE),h - (borderS + borderN)])); setcolor(BG2); stroke(); } drawable hit(eventtype e) { drawable d; if (d = @current_layout.hit(e)) return d; if (d = @window_layout.hit(e)) return d; return self; } menu @menu() { return edit_mode ? @editmenu : @windowmenu; } /********************************************************************* * Edit mode stuff */ boolean edit_mode = false; void start_edit_mode() { if (!edit_mode) { edit_mode = true; Send start_edit_ctx() to @edit_ctx; } } void stop_edit_mode() { if (edit_mode) { Send stop_edit_ctx() to @edit_ctx; unpromote(/edit_mode); Send focus_change() to @focus; Send focus_change(); } } void flip_edit_mode() { if (edit_mode) stop_edit_mode(); else start_edit_mode(); } void set_edit_ctx(drawable d) { if (@edit_ctx != d) { if (edit_mode) Send stop_edit_ctx() to @edit_ctx; if (d == @current_layout) undef(@current_layout,/edit_ctx); else if (d == @window_layout) @current_layout[/edit_ctx] = null; else @current_layout[/edit_ctx] = d; if (edit_mode) Send start_edit_ctx() to @edit_ctx; } } void ctx_to_parent() { Send edit_ctx_parent() to @edit_ctx; } void ctx_to_selected() { Send edit_ctx_selected() to @edit_ctx; } void ctx_to_current_layout() { set_edit_ctx(@current_layout); } void ctx_to_window_layout() { set_edit_ctx(@window_layout); } void select_click() { if (@freezer) totop(); else if (arraycontains(mouseevent.KeyState,28536)) flip_edit_mode(); else if (edit_mode) Send gexec(/edit_select_click) to @edit_ctx; else super.select_click(); } void menu_click() { if (@freezer) totop(); else if (edit_mode) ((struct menu)@editmenu).showmenu(self); else super.menu_click(); } void paint() { super.paint(); if (edit_mode) Send gexec(/paint_edit_mode) to @edit_ctx; } void fix() { super.fix(); if (edit_mode) Send gexec(/paint_edit_mode) to @edit_ctx; }