"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/Edit/Interface/edit_interface.cpp" between
TeXmacs-1.99.4-src.tar.gz and TeXmacs-1.99.5-src.tar.gz

About: GNU TeXmacs is a what-you-see-is-what-you-get scientific text editor, which was both inspired by TeX and GNU Emacs.

edit_interface.cpp  (TeXmacs-1.99.4-src):edit_interface.cpp  (TeXmacs-1.99.5-src)
skipping to change at line 29 skipping to change at line 29
#include "drd_mode.hpp" #include "drd_mode.hpp"
#include "message.hpp" #include "message.hpp"
#include "tree_traverse.hpp" #include "tree_traverse.hpp"
#include "boot.hpp" #include "boot.hpp"
#ifdef EXPERIMENTAL #ifdef EXPERIMENTAL
#include "../../Style/Evaluate/evaluate_main.hpp" #include "../../Style/Evaluate/evaluate_main.hpp"
#endif #endif
#include "gui.hpp" // for gui_interrupted #include "gui.hpp" // for gui_interrupted
extern void (*env_next_prog)(void); extern void (*env_next_prog)(void);
extern void set_snap_mode (tree t);
extern void set_snap_distance (SI d);
/*static*/ string /*static*/ string
MODE_LANGUAGE (string mode) { MODE_LANGUAGE (string mode) {
if (mode == "text") return LANGUAGE; if (mode == "text") return LANGUAGE;
else if (mode == "math") return MATH_LANGUAGE; else if (mode == "math") return MATH_LANGUAGE;
else if (mode == "prog") return PROG_LANGUAGE; else if (mode == "prog") return PROG_LANGUAGE;
else if (mode == "src") return LANGUAGE; else if (mode == "src") return LANGUAGE;
std_error << "Invalid mode " << mode << ", assuming text mode instead\n"; std_error << "Invalid mode " << mode << ", assuming text mode instead\n";
return LANGUAGE; return LANGUAGE;
} }
/****************************************************************************** /******************************************************************************
* Main edit_interface routines * Main edit_interface routines
******************************************************************************/ ******************************************************************************/
edit_interface_rep::edit_interface_rep (): edit_interface_rep::edit_interface_rep ():
editor_rep (), // NOTE: ignored by the compiler, but suppresses warning
env_change (0), env_change (0),
last_change (texmacs_time()), last_update (last_change-1), last_change (texmacs_time()), last_update (last_change-1),
do_animate (false), next_animate (last_change-1), anim_next (1.0e12),
full_screen (false), got_focus (false), full_screen (false), got_focus (false),
sh_s (""), sh_mark (0), pre_edit_s (""), pre_edit_mark (0), sh_s (""), sh_mark (0), pre_edit_s (""), pre_edit_mark (0),
popup_win (), popup_win (),
message_l (""), message_r (""), last_l (""), last_r (""), message_l (""), message_r (""), last_l (""), last_r (""),
zoomf (sv->get_default_zoom_factor ()), zoomf (sv->get_default_zoom_factor ()),
magf (zoomf / std_shrinkf), magf (zoomf / std_shrinkf),
pixel ((SI) tm_round ((std_shrinkf * PIXEL) / zoomf)), copy_always (), pixel ((SI) tm_round ((std_shrinkf * PIXEL) / zoomf)), copy_always (),
last_x (0), last_y (0), last_t (0), last_x (0), last_y (0), last_t (0),
table_selection (false), mouse_adjusting (false), table_selection (false), mouse_adjusting (false),
oc (0, 0), temp_invalid_cursor (false), oc (0, 0), temp_invalid_cursor (false),
skipping to change at line 229 skipping to change at line 232
stored_rects= rectangles (); stored_rects= rectangles ();
copy_always = rectangles (); copy_always = rectangles ();
SERVER (set_extents ((SI) floor (x1*magf), (SI) floor (y1*magf), SERVER (set_extents ((SI) floor (x1*magf), (SI) floor (y1*magf),
(SI) ceil (x2*magf), (SI) ceil (y2*magf))); (SI) ceil (x2*magf), (SI) ceil (y2*magf)));
} }
/****************************************************************************** /******************************************************************************
* Scroll so as to make the cursor and the selection visible * Scroll so as to make the cursor and the selection visible
******************************************************************************/ ******************************************************************************/
static SI absval (SI x) { return max (x, -x); }
void void
edit_interface_rep::cursor_visible () { edit_interface_rep::cursor_visible () {
path sp= find_innermost_scroll (eb, tp); path sp= find_innermost_scroll (eb, tp);
cursor cu= get_cursor (); cursor cu= get_cursor ();
if (is_nil (sp)) { if (is_nil (sp)) {
update_visible (); update_visible ();
cu->y1 -= 2*pixel; cu->y2 += 2*pixel; cu->y1 -= 2*pixel; cu->y2 += 2*pixel;
if ((cu->ox+ ((SI) (cu->y1 * cu->slope)) < vx1) || bool must_update=
(cu->ox+ ((SI) (cu->y2 * cu->slope)) >= vx2) || (cu->ox+ ((SI) (cu->y1 * cu->slope)) < vx1) ||
(cu->oy+ cu->y1 < vy1) || (cu->ox+ ((SI) (cu->y2 * cu->slope)) >= vx2) ||
(cu->oy+ cu->y2 >= vy2)) (cu->oy+ cu->y1 < vy1) ||
{ (cu->oy+ cu->y2 >= vy2);
scroll_to (cu->ox, cu->oy);
send_invalidate_all (this); box pages= eb[0];
if (N(pages) > 1) {
SI vw= vx2 - vx1, vh= vy2 - vy1;
for (int i=0; i<N(pages); i++) {
SI scx, scy;
SERVER (scroll_where (scx, scy));
scx= (SI) (scx / magf);
scy= (SI) (scy / magf);
SI x1= eb->sy(0)+ pages->sx1 (i);
SI x2= eb->sy(0)+ pages->sx2 (i);
SI y1= eb->sy(0)+ pages->sy1 (i);
SI y2= eb->sy(0)+ pages->sy2 (i);
SI pw= x2 - x1, ph= y2 - y1;
if (cu->ox >= x1 && x2 > cu->ox &&
cu->oy >= y1 && y2 > cu->oy &&
5*vw > 3*pw && 5*vh > 3*ph) {
if (!must_update) {
SI d= 5*pixel;
if (pw >= vw) {
if (vx1 > x1 + d && absval (x2 - vx2) > d) must_update= true;
if (x2 > vx2 + d && absval (x1 - vx1) > d) must_update= true;
}
else if (vx1 > x1 + d || x2 > vx2 + d) must_update= true;
if (ph >= vh) {
if (vy1 > y1 + d && absval (y2 - vy2) > d) must_update= true;
if (y2 > vy2 + d && absval (y1 - vy1) > d) must_update= true;
}
else if (vy1 > y1 + d || y2 > vy2 + d) must_update= true;
}
if (must_update) {
//cout << "Cursor on page " << i << LF;
//cout << "Visual " << vx1/PIXEL << ", " << vy1/PIXEL
// << "; " << vx2/PIXEL << ", " << vy2/PIXEL << LF;
//cout << "Page " << x1/PIXEL << ", " << y1/PIXEL
// << "; " << x2/PIXEL << ", " << y2/PIXEL << LF;
SI mx= (x1 + x2) >> 1, my= (y1 + y2) >> 1;
if (pw >= vw) {
if (cu->ox > mx) mx= x2 - ((vx2 - vx1) >> 1);
else mx= x1 + ((vx2 - vx1) >> 1);
}
if (ph >= vh) {
if (cu->oy > my) my= y2 - ((vy2 - vy1) >> 1);
else my= y1 + ((vy2 - vy1) >> 1);
}
scroll_to (mx, my);
send_invalidate_all (this);
return;
}
}
} }
}
if (must_update) {
scroll_to (cu->ox, cu->oy);
send_invalidate_all (this);
}
} }
else { else {
SI x, y, sx, sy; SI x, y, sx, sy;
rectangle outer, inner; rectangle outer, inner;
find_canvas_info (eb, sp, x, y, sx, sy, outer, inner); find_canvas_info (eb, sp, x, y, sx, sy, outer, inner);
if ((cu->ox+ ((SI) (cu->y1 * cu->slope)) < x + outer->x1) || if ((cu->ox+ ((SI) (cu->y1 * cu->slope)) < x + outer->x1) ||
(cu->ox+ ((SI) (cu->y2 * cu->slope)) > x + outer->x2)) (cu->ox+ ((SI) (cu->y2 * cu->slope)) > x + outer->x2))
{ {
SI tx= inner->x2 - inner->x1; SI tx= inner->x2 - inner->x1;
SI cx= outer->x2 - outer->x1; SI cx= outer->x2 - outer->x1;
skipping to change at line 300 skipping to change at line 359
} }
} }
} }
void void
edit_interface_rep::selection_visible () { edit_interface_rep::selection_visible () {
update_visible (); update_visible ();
if ((vx2 - vx1 <= 80*pixel) || (vy2 - vy1 <= 80*pixel)) return; if ((vx2 - vx1 <= 80*pixel) || (vy2 - vy1 <= 80*pixel)) return;
SI extra= (cur_sb == 1? 20 * pixel: 0); SI extra= (cur_sb == 1? 20 * pixel: 0);
/*
bool scroll_x= (end_x < vx1 + extra) || (end_x >= vx2 - extra); bool scroll_x= (end_x < vx1 + extra) || (end_x >= vx2 - extra);
bool scroll_y= (end_y < vy1 + extra) || (end_y >= vy2 - extra); bool scroll_y= (end_y < vy1 + extra) || (end_y >= vy2 - extra);
SI new_x= vx1;
if (scroll_x) new_x= end_x - ((vx2-vx1)>>1);
SI new_y= vy2;
if (scroll_y) new_y= end_y + ((vy2-vy1)>>1);
if (scroll_x || scroll_y) { if (scroll_x || scroll_y) {
SI new_x = (scroll_x)? end_x : (vx1+vx2)/2;
SI new_y = (scroll_y)? end_y : (vy1+vy2)/2;
*/
// trying a "proportional" scroll
SI mx = max (-end_x + vx1 + extra, max (end_x - vx2 + extra, 0));
SI my = max (-end_y + vy1 + extra, max (end_y - vy2 + extra, 0));
if ((mx>0) || (my>0)) {
SI vxc = (vx1+vx2)/2, dx = end_x - vxc;
SI vyc = (vy1+vy2)/2, dy = end_y - vyc;
SI new_x = vxc+ ((extra)? (mx*dx)/extra: dx);
SI new_y = vyc+ ((extra)? (my*dy)/extra: dy);
//end change
scroll_to (new_x, new_y); scroll_to (new_x, new_y);
send_invalidate_all (this); send_invalidate_all (this);
SI old_vx1= vx1, old_vy1= vy1; SI old_vx1= vx1, old_vy1= vy1;
update_visible (); update_visible ();
end_x += vx1- old_vx1; end_x += vx1- old_vx1;
end_y += vy1- old_vy1; end_y += vy1- old_vy1;
} }
} }
/****************************************************************************** /******************************************************************************
* Computation of environment rectangles * Computation of environment rectangles
******************************************************************************/ ******************************************************************************/
static bool static bool
is_graphical (tree t) { is_graphical (tree t) {
return return
is_func (t, _POINT) || is_func (t, _POINT) ||
is_func (t, LINE) || is_func (t, CLINE) || is_func (t, LINE) || is_func (t, CLINE) ||
is_func (t, ARC) || is_func (t, CARC) || is_func (t, ARC) || is_func (t, CARC) ||
is_func (t, SPLINE) || is_func (t, CSPLINE); is_func (t, SPLINE) || is_func (t, CSPLINE) ||
is_func (t, BEZIER) || is_func (t, CBEZIER) ||
is_func (t, SMOOTH) || is_func (t, CSMOOTH);
} }
static void static void
correct_adjacent (rectangles& rs1, rectangles& rs2) { correct_adjacent (rectangles& rs1, rectangles& rs2) {
if (N(rs1) != 1 || N(rs2) != 1) return; if (N(rs1) != 1 || N(rs2) != 1) return;
SI bot1= rs1->item->y1; SI bot1= rs1->item->y1;
SI top2= rs2->item->y2; SI top2= rs2->item->y2;
if (rs1->item->y1 <= rs2->item->y1) { if (rs1->item->y1 <= rs2->item->y1) {
//cout << "Discard " << rs1->item->y1 << ", " << rs2->item->y1 << "\n"; //cout << "Discard " << rs1->item->y1 << ", " << rs2->item->y1 << "\n";
return; return;
skipping to change at line 351 skipping to change at line 421
return; return;
} }
SI mid= (bot1 + top2) >> 1; SI mid= (bot1 + top2) >> 1;
rs1->item->y1= mid; rs1->item->y1= mid;
rs2->item->y2= mid; rs2->item->y2= mid;
} }
void void
edit_interface_rep::compute_env_rects (path p, rectangles& rs, bool recurse) { edit_interface_rep::compute_env_rects (path p, rectangles& rs, bool recurse) {
if (p == rp) return; if (p == rp) return;
tree pt= subtree (et, path_up (p));
tree st= subtree (et, p); tree st= subtree (et, p);
if ((is_func (st, TABLE) || is_func (st, SUBTABLE)) && if ((is_func (st, TABLE) || is_func (st, SUBTABLE)) &&
recurse && get_preference ("show table cells") == "on") { recurse && get_preference ("show table cells") == "on") {
rectangles rl; rectangles rl;
for (int i=0; i<N(st); i++) { for (int i=0; i<N(st); i++) {
if (is_func (st[i], ROW)) if (is_func (st[i], ROW))
for (int j=0; j<N(st[i]); j++) { for (int j=0; j<N(st[i]); j++) {
selection sel= eb->find_check_selection (p*i*j*0, p*i*j*1); selection sel= eb->find_check_selection (p*i*j*0, p*i*j*1);
rectangles rsel= copy (thicken (sel->rs, 0, 2 * pixel)); rectangles rsel= copy (thicken (sel->rs, 0, 2 * pixel));
if (i > 0 && is_func (st[i-1], ROW) && j < N(st[i-1])) { if (i > 0 && is_func (st[i-1], ROW) && j < N(st[i-1])) {
skipping to change at line 386 skipping to change at line 457
if (recurse) compute_env_rects (path_up (p), rs, recurse); if (recurse) compute_env_rects (path_up (p), rs, recurse);
} }
else if (is_atomic (st) || else if (is_atomic (st) ||
drd->is_child_enforcing (st) || drd->is_child_enforcing (st) ||
//is_document (st) || is_concat (st) || //is_document (st) || is_concat (st) ||
is_func (st, TABLE) || is_func (st, SUBTABLE) || is_func (st, TABLE) || is_func (st, SUBTABLE) ||
is_func (st, ROW) || is_func (st, TFORMAT) || is_func (st, ROW) || is_func (st, TFORMAT) ||
is_graphical (st) || is_graphical (st) ||
(is_func (st, WITH) && is_graphical (st[N(st)-1])) || (is_func (st, WITH) && is_graphical (st[N(st)-1])) ||
(is_func (st, WITH) && is_graphical_text (st[N(st)-1])) || (is_func (st, WITH) && is_graphical_text (st[N(st)-1])) ||
(is_func (pt, GRAPHICS) &&
(is_compound (st, "anim-edit") ||
is_compound (st, "anim-static") ||
is_compound (st, "anim-dynamic"))) ||
is_compound (st, "shared", 3) || is_compound (st, "shared", 3) ||
(is_compound (st, "math", 1) && (is_compound (st, "math", 1) &&
is_compound (subtree (et, path_up (p)), "input"))) is_compound (subtree (et, path_up (p)), "input")))
compute_env_rects (path_up (p), rs, recurse); compute_env_rects (path_up (p), rs, recurse);
else { else {
int new_mode= DRD_ACCESS_NORMAL; int new_mode= DRD_ACCESS_NORMAL;
if (get_init_string (MODE) == "src") new_mode= DRD_ACCESS_SOURCE; if (get_init_string (MODE) == "src") new_mode= DRD_ACCESS_SOURCE;
int old_mode= set_access_mode (new_mode); int old_mode= set_access_mode (new_mode);
tree st= subtree (et, p); tree st= subtree (et, p);
if (is_accessible_cursor (et, p * right_index (st)) || in_source ()) { if (is_accessible_cursor (et, p * right_index (st)) || in_source ()) {
skipping to change at line 451 skipping to change at line 526
return texmacs_time () - last_change; return texmacs_time () - last_change;
else return 0; else return 0;
} }
int int
edit_interface_rep::change_time () { edit_interface_rep::change_time () {
return last_change; return last_change;
} }
void void
edit_interface_rep::update_menus () {
SERVER (menu_main ("(horizontal (link texmacs-menu))"));
SERVER (menu_icons (0, "(horizontal (link texmacs-main-icons))"));
SERVER (menu_icons (1, "(horizontal (link texmacs-mode-icons))"));
SERVER (menu_icons (2, "(horizontal (link texmacs-focus-icons))"));
SERVER (menu_icons (3, "(horizontal (link texmacs-extra-icons))"));
if (use_side_tools)
{ SERVER (side_tools (0, "(vertical (link texmacs-side-tools))")); }
SERVER (bottom_tools (0, "(vertical (link texmacs-bottom-tools))"));
set_footer ();
if (has_current_window ()) {
array<url> ws= buffer_to_windows (
window_to_buffer (
abstract_window (concrete_window ())));
int n= N(ws);
bool ns= need_save ();
for (int i=0; i<n; i++)
concrete_window (ws[i])->set_modified (ns);
}
if (!gui_interrupted ()) drd_update ();
cache_memorize ();
last_update= last_change;
save_user_preferences ();
}
void
edit_interface_rep::apply_changes () { edit_interface_rep::apply_changes () {
//cout << "Apply changes\n"; //cout << "Apply changes\n";
//cout << "et= " << et << "\n"; //cout << "et= " << et << "\n";
//cout << "tp= " << tp << "\n"; //cout << "tp= " << tp << "\n";
//cout << HRULE << "\n"; //cout << HRULE << "\n";
if (env_change == 0) { if (env_change == 0) {
if (last_change-last_update > 0 && if (last_change-last_update > 0 &&
idle_time (INTERRUPTED_EVENT) >= 1000/6) idle_time (INTERRUPTED_EVENT) >= 1000/6)
{ update_menus ();
SERVER (menu_main ("(horizontal (link texmacs-menu))"));
SERVER (menu_icons (0, "(horizontal (link texmacs-main-icons))"));
SERVER (menu_icons (1, "(horizontal (link texmacs-mode-icons))"));
SERVER (menu_icons (2, "(horizontal (link texmacs-focus-icons))"));
SERVER (menu_icons (3, "(horizontal (link texmacs-extra-icons))"));
if (use_side_tools)
{ SERVER (side_tools (0, "(vertical (link texmacs-side-tools))")); }
SERVER (bottom_tools (0, "(vertical (link texmacs-bottom-tools))"));
set_footer ();
if (has_current_window ()) {
array<url> ws= buffer_to_windows (
window_to_buffer (
abstract_window (concrete_window ())));
int n= N(ws);
bool ns= need_save ();
for (int i=0; i<n; i++)
concrete_window (ws[i])->set_modified (ns);
}
if (!gui_interrupted ()) drd_update ();
cache_memorize ();
last_update= last_change;
save_user_preferences ();
}
return; return;
} }
// cout << "Applying changes " << env_change << " to " << get_name() << "\n"; // cout << "Applying changes " << env_change << " to " << get_name() << "\n";
// time_t t1= texmacs_time (); // time_t t1= texmacs_time ();
// cout << "Always\n"; // cout << "Always\n";
update_visible (); update_visible ();
// cout << "Handling automatic resizing\n"; // cout << "Handling automatic resizing\n";
skipping to change at line 777 skipping to change at line 855
} }
if (inside_active_graphics ()) { if (inside_active_graphics ()) {
SI gx1, gy1, gx2, gy2; SI gx1, gy1, gx2, gy2;
if (find_graphical_region (gx1, gy1, gx2, gy2)) { if (find_graphical_region (gx1, gy1, gx2, gy2)) {
rectangle gr= rectangle (gx1, gy1, gx2, gy2); rectangle gr= rectangle (gx1, gy1, gx2, gy2);
if (!is_nil (gr - stored_rects)) if (!is_nil (gr - stored_rects))
invalidate (gx1, gy1, gx2, gy2); invalidate (gx1, gy1, gx2, gy2);
} }
} }
// cout << "Graphics snapping\n";
if (inside_active_graphics ()) {
tree t= as_tree (call ("graphics-get-snap-mode"));
set_snap_mode (t);
string val= as_string (call ("graphics-get-snap-distance"));
set_snap_distance (as_length (val));
}
// cout << "Handling environment changes\n"; // cout << "Handling environment changes\n";
if (env_change & THE_ENVIRONMENT) if (env_change & THE_ENVIRONMENT)
send_invalidate_all (this); send_invalidate_all (this);
// cout << "Handling menus\n";
if (env_change & THE_MENUS)
update_menus ();
// cout << "Applied changes\n"; // cout << "Applied changes\n";
// time_t t2= texmacs_time (); // time_t t2= texmacs_time ();
// if (t2 - t1 >= 10) cout << "apply_changes took " << t2-t1 << "ms\n"; // if (t2 - t1 >= 10) cout << "apply_changes took " << t2-t1 << "ms\n";
env_change = 0; env_change = 0;
last_change = texmacs_time (); last_change = texmacs_time ();
last_update = last_change-1; last_update = last_change-1;
manual_focus_release (); manual_focus_release ();
} }
/****************************************************************************** /******************************************************************************
* Animations * Animations
******************************************************************************/ ******************************************************************************/
void void
edit_interface_rep::animate () { edit_interface_rep::animate () {
// cout << do_animate << ", " << next_animate << "\n"; if (((double) texmacs_time ()) >= anim_next) {
if (do_animate && texmacs_time () - next_animate >= 0) { rectangles rs= eb->anim_invalid ();
bool flag= false; invalidate (rs);
time_t at= 0; stored_rects= rectangles ();
rectangles rs;
eb->anim_get_invalid (flag, at, rs);
if (flag && texmacs_time () - at >= 0)
invalidate (rs);
do_animate = flag;
next_animate= at;
} }
} }
/****************************************************************************** /******************************************************************************
* Miscellaneous routines * Miscellaneous routines
******************************************************************************/ ******************************************************************************/
void void
edit_interface_rep::full_screen_mode (bool flag) { edit_interface_rep::full_screen_mode (bool flag) {
full_screen= flag; full_screen= flag;
 End of changes. 17 change blocks. 
48 lines changed or deleted 132 lines changed or added

Home  |  About  |  All  |  Newest  |  Fossies Dox  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTPS