Exemplo n.º 1
0
void
edit_interface_rep::draw_graphics (renderer ren) {
  if (got_focus || full_screen) {
    cursor cu= get_cursor();
    if (over_graphics(cu->ox, cu->oy) && inside_active_graphics ()) {
      eval ("(graphics-reset-context 'graphics-cursor)");
      draw_graphical_object (ren);
      string tm_curs= as_string (eval ("graphics-texmacs-pointer"));
      if (tm_curs != "none") {
	if (tm_curs == "graphics-cross") {
	  ren->set_line_style (pixel);
	  ren->set_color (red);
	  ren->line (cu->ox, cu->oy-5*pixel, cu->ox, cu->oy+5*pixel);
	  ren->line (cu->ox-5*pixel, cu->oy, cu->ox+5*pixel, cu->oy);
        }
	else if (tm_curs == "graphics-cross-arrows") {
	  static int s= 6*pixel, a= 2*pixel;
	  ren->set_line_style (pixel);
	  ren->set_color (red);
	  ren->line (cu->ox, cu->oy-s, cu->ox, cu->oy+s);
	  ren->line (cu->ox-s, cu->oy, cu->ox+s, cu->oy);
	  ren->line (cu->ox, cu->oy-s,cu->ox-a, cu->oy-s+a);
	  ren->line (cu->ox, cu->oy-s, cu->ox+a, cu->oy-s+a);
	  ren->line (cu->ox, cu->oy+s, cu->ox-a, cu->oy+s-a);
	  ren->line (cu->ox, cu->oy+s, cu->ox+a, cu->oy+s-a);
	  ren->line (cu->ox-s, cu->oy, cu->ox-s+a, cu->oy+a);
	  ren->line (cu->ox-s, cu->oy, cu->ox-s+a, cu->oy-a);
	  ren->line (cu->ox+s, cu->oy, cu->ox+s-a, cu->oy+a);
	  ren->line (cu->ox+s, cu->oy, cu->ox+s-a, cu->oy-a);
        }
      }
    }
    else eval ("(graphics-reset-context 'text-cursor)");
  }
}
Exemplo n.º 2
0
void
edit_select_rep::selection_cut (string key) {
  if (inside_active_graphics ()) {
    if (key != "none") {
      tree t= as_tree (eval ("(graphics-cut)"));
      selection_set (key, t);
    }
  }
  else if (selection_active_any ()) {
    path p1, p2;
    if (selection_active_table ()) {
      p1= start_p; p2= end_p;
      if(key != "none") {
        tree sel= selection_get ();
        selection_set (key, sel);
      }
    }
    else {
      selection_get (p1, p2);
      go_to (p2);
      if (p2 == p1) return;
      if (key != "none") {
        tree sel= selection_compute (et, p1, p2);
        selection_set (key, simplify_correct (sel));
      }
    }
    cut (p1, p2);
  }
}
Exemplo n.º 3
0
void
edit_interface_rep::key_press (string gkey) {
  string zero= "a"; zero[0]= '\0';
  string key= replace (gkey, "<#0>", zero);
  if (pre_edit_mark != 0) {
    ASSERT (sh_mark == 0, "invalid shortcut during pre-edit");
    mark_cancel (pre_edit_mark);
    pre_edit_s= "";
    pre_edit_mark= 0;
  }
  if (starts (key, "pre-edit:") ) {
    interrupt_shortcut ();
    string s= key (9, N(key));
    if (s == "") return;
    int i, n= N(s), pos= N(s);
    for (i=0; i<n; i++)
      if (s[i] == ':' && is_int (s (0, i))) {
        int k= as_int (s (0, i));
        s= s (i+1, n);
        pos= 0;
        for (int j=0; j<k && pos<N(s); j++)
          tm_char_forwards (s, pos);
        break;
      }
    pre_edit_s= s;
    pre_edit_mark= new_marker ();
    mark_start (pre_edit_mark);
    archive_state ();
    insert_tree (compound ("pre-edit", s), path (0, pos));
    return;
  }
  
  string new_sh= N(sh_s)==0? key: sh_s * " " * key;
  if (try_shortcut (new_sh)) return;
  if (new_sh != key) {
    interrupt_shortcut ();
    if (try_shortcut (key)) return;
  }
  
  string rew= sv->kbd_post_rewrite (key);
  if (N(rew) == 1) {
    int i ((unsigned char) rew[0]);
    if ((i >= 32 && i <= 127) || (i >= 128 && i <= 255) || (i == 25))
      if (!inside_active_graphics ()) {
        archive_state ();
        call ("kbd-insert", rew);
      }
    interrupt_shortcut ();
  }
  else if (contains_unicode_char (rew)) {
    archive_state ();
    call ("kbd-insert", key);
    interrupt_shortcut ();    
  }
  else if (DEBUG_KEYBOARD)
    debug_keyboard
      << "unrecognized key " << key << ". "
      << "Undefined shortcut or key missing in the encoding files.\n";
}
Exemplo n.º 4
0
void
edit_select_rep::selection_paste (string key) {
  tree t; string s;
  (void) ::get_selection (key, t, s, selection_import);
  if (inside_active_graphics ()) {
    if (is_tuple (t, "texmacs", 3))
      call ("graphics-paste", t[1]);
    return;
  }
  if (is_tuple (t, "extern", 1)) {
    string mode= get_env_string (MODE);
    string lan = get_env_string (MODE_LANGUAGE (mode));
    if ((selection_import == "latex") && (mode == "prog")) mode= "verbatim";
    if ((selection_import == "latex") && (mode == "math")) mode= "latex-math";
    if ((selection_import == "html") && (mode == "prog")) mode= "verbatim";
    string fm= selection_import * "-snippet";
    tree doc= generic_to_tree (selection_decode(lan, as_string(t[1])), fm);
    if (is_func (doc, DOCUMENT, 1)) doc= doc[0]; // temporary fix
    insert_tree (doc);
  }
  if (is_tuple (t, "texmacs", 3)) {
    string mode= get_env_string (MODE);
    string lan = get_env_string (MODE_LANGUAGE (mode));
    if (is_compound (t[1], "text", 1) && mode == "text")
      t= tuple ("texmacs", t[1][0], "text", lan);
    if (is_compound (t[1], "math", 1) && mode == "math")
      t= tuple ("texmacs", t[1][0], "math", lan);
    if (mode == "math" && t[2] == "text")
      set_message ("Error: invalid paste of text into a formula", "paste");
    else if (mode == "prog" && t[2] == "math") {
      tree in= tuple (lan, t[1]);
      tree r= stree_to_tree (call ("plugin-math-input", tree_to_stree (in)));
      insert_tree (r);
    }
    else {
      if ((t[2] != mode) && (t[2] != "src") && (mode != "src") &&
	  ((t[2] == "math") || (mode == "math"))) {
        if (t[2] == "math")
          insert_tree (compound ("math", ""), path (0, 0));
        else if (t[2] == "text")
          insert_tree (compound ("text", ""), path (0, 0));
        else
          insert_tree (tree (WITH, copy (MODE), copy (t[2]), ""), path (2, 0));
      }
      if (is_func (t[1], TFORMAT) || is_func (t[1], TABLE)) {
	int row, col;
	path fp= search_format (row, col);
	if (is_nil (fp)) insert_tree (compound (copy (TABULAR), t[1]));
	else table_write_subtable (fp, row, col, t[1]);
      }
      else insert_tree (t[1]);
    }
  }
}
Exemplo n.º 5
0
void
edit_select_rep::selection_copy (string key) {
  if (inside_active_graphics ()) {
    tree t= as_tree (eval ("(graphics-copy)"));
    selection_set (key, t);
    return;
  }
  if (selection_active_any ()) {
    path old_tp= tp;
    selection sel; selection_get (sel);
    go_to (sel->end);
    tree t= selection_get ();
    go_to (sel->start);
    selection_set (key, t);
    go_to (old_tp);
  }
}
Exemplo n.º 6
0
void
edit_interface_rep::draw_with_stored (rectangle r) {
  renderer win= get_renderer (this);
  //cout << "Redraw " << (r/(sfactor*PIXEL)) << "\n";

  /* Verify whether the backing store is still valid */
  if (!is_nil (stored_rects)) {
    SI w1, h1, w2, h2;
    win   -> get_extents (w1, h1);
    stored -> get_extents (w2, h2);
    if (stored->ox != win->ox || stored->oy != win->oy ||
	w1 != w2 || h1 != h2) {
      // cout << "x"; cout.flush ();
      stored_rects= rectangles ();
    }
  }

  /* Either draw with backing store or regenerate */
  rectangle sr= r / sfactor;
  if (is_nil (rectangles (r) - stored_rects) && !is_nil (stored_rects)) {
    // cout << "*"; cout.flush ();
    win->new_shadow (shadow);
    win->get_shadow (shadow, sr->x1, sr->y1, sr->x2, sr->y2);
    shadow->put_shadow (stored, sr->x1, sr->y1, sr->x2, sr->y2);
    draw_post (shadow, r);
    win->put_shadow (shadow, sr->x1, sr->y1, sr->x2, sr->y2);
  }
  else {
    // cout << "."; cout.flush ();
    draw_with_shadow (r);
    if (!win->interrupted ()) {
      if (inside_active_graphics ()) {
	shadow->new_shadow (stored);
	shadow->get_shadow (stored, sr->x1, sr->y1, sr->x2, sr->y2);
	//stored_rects= /*stored_rects |*/ rectangles (r);
	stored_rects= simplify (rectangles (r, stored_rects));
	//cout << "Stored: " << stored_rects << "\n";
	//cout << "M"; cout.flush ();
      }
      draw_post (shadow, r);
      win->put_shadow (shadow, sr->x1, sr->y1, sr->x2, sr->y2);
    }
    else draw_post (win, r);
  }
}
Exemplo n.º 7
0
void
edit_interface_rep::draw_cursor (renderer ren) {
  if (!temp_invalid_cursor && (got_focus || full_screen)) {
    cursor cu= get_cursor();
    if (!inside_active_graphics ()) {
      cu->y1 -= 2*pixel; cu->y2 += 2*pixel;
      SI x1= cu->ox + ((SI) (cu->y1 * cu->slope)), y1= cu->oy + cu->y1;
      SI x2= cu->ox + ((SI) (cu->y2 * cu->slope)), y2= cu->oy + cu->y2;
      ren->set_line_style (pixel);
      string mode= get_env_string (MODE);
      string family, series;
      if ((mode == "text") || (mode == "src")) {
	family= get_env_string (FONT_FAMILY);
	series= get_env_string (FONT_SERIES);
      }
      else if (mode == "math") {
	family= get_env_string (MATH_FONT_FAMILY);
	series= get_env_string (MATH_FONT_SERIES);
      }
      else if (mode == "prog") {
	family= get_env_string (PROG_FONT_FAMILY);
	series= get_env_string (PROG_FONT_SERIES);
      }
      if (cu->valid) {
	if (mode == "math")
	  ren->set_color (rgb_color (192, 0, 255));
	else ren->set_color (red);
      }
      else ren->set_color (green);
      SI lserif= (series=="bold"? 2*pixel: pixel), rserif= pixel;
      if (family == "ss") lserif= rserif= 0;
      ren->line (x1-lserif, y1, x1+rserif, y1);
      if (y1<=y2-pixel) {
	ren->line (x1, y1, x2, y2-pixel);
	if (series == "bold") ren->line (x1-pixel, y1, x2-pixel, y2-pixel);
	ren->line (x2-lserif, y2-pixel, x2+rserif, y2-pixel);
      }
    }
  }
}