Logo Search packages:      
Sourcecode: cadabra version File versions

VisualCell * NotebookCanvas::add_cell ( Glib::RefPtr< DataCell dc,
Glib::RefPtr< DataCell ref,
bool  before = true 
)

Add a VisualCell corresponding to the given DataCell. The second and third element determine the position relative to another DataCell (or, by default, relative to the end marker).

Definition at line 389 of file window.cc.

References VisualCell::datacell, TeXInput::edit, ExpressionInput::edit, XCadabra::font_step, XCadabra::handle_editbox_output(), XCadabra::handle_on_grab_focus(), VisualCell::inbox, VisualCell::outbox, TeXInput::set_folded(), VisualCell::texbox, and TeXInput::texview.

      {
      VisualCell *newcell=new VisualCell;
      newcell->datacell=dc;

      // Temporarily remove bottom line marker.
//    scrollbox.remove(bottomline);

      // Find the correct place to insert the new cell in visualcells, and keep
      // track of the number so we can insert the widget at the right spot in the Gtk
      // container later.
      int cellnum=0;
      if(ref==0)
            visualcells.push_back(newcell);
      else {
            VisualCells_t::iterator it=visualcells.begin();
            while(it!=visualcells.end()) {
                  if((*it)->datacell==ref) {
                        if(!before) { // skip to the next input cell; NOTE: this should skip in the same way
                                      // as the XCadabra::add_cell method!
                              do {
                                    ++it;
                                    ++cellnum;
                                    } while(it!=visualcells.end() && 
                                                  ( /* (*it)->datacell->cell_type==DataCell::c_comment || */
                                                       (*it)->datacell->cell_type==DataCell::c_output ||
                                                       (*it)->datacell->cell_type==DataCell::c_error) );
                              }
                        visualcells.insert(it, newcell);
                        break;
                        }
                  ++it;
                  ++cellnum;
                  }
            }
      
#ifdef DEBUG
      std::cerr << "gtk logic" << std::endl;
#endif
      Gtk::VBox::BoxList bl=scrollbox.children();
      Gtk::VBox::BoxList::iterator gtkit;
      if(ref==0) gtkit=bl.end();
      else {
            gtkit=bl.begin();
            while(cellnum!=0) {
                  ++gtkit;
                  --cellnum;
                  }
            }

      // Insert the widget in the Gtk container and connect signals.
#ifdef DEBUG
      std::cerr << "inserting" << std::endl;
#endif
      switch(dc->cell_type) {
            case DataCell::c_input: {
#ifdef DEBUG
                  std::cerr << "incell" << std::endl;
#endif
                  std::ostringstream fstr;
                  fstr << THEFONT << " " << 12+(doc.font_step*2); 
                  newcell->inbox=manage( new ExpressionInput(dc->textbuf, fstr.str()) );
                  Gtk::VBox::BoxList::iterator newit=bl.insert(gtkit, *newcell->inbox);

                  gtk_box_set_child_packing(((Gtk::Box *)(&scrollbox))->gobj(), 
                                                                    ((Gtk::Widget *)(newcell->inbox))->gobj(),
                                                                    false, false, 0, GTK_PACK_START);

//                (*newit).set_options(Gtk::PACK_SHRINK);
                  
                  // Connect to signal for 'ctrl-enter pressed', i.e. 'feed this cell to the kernel'.
                  newcell->inbox->edit.emitter.connect(
                        sigc::bind<NotebookCanvas *, VisualCell *>(
                              sigc::mem_fun(doc, &XCadabra::handle_editbox_output), this, newcell));

                  // Connect signals such that we can grab focus and scroll the widget into view when necessary.
                  newcell->inbox->edit.signal_grab_focus().connect(
                        sigc::bind<NotebookCanvas *, VisualCell *>(
                              sigc::mem_fun(doc, &XCadabra::handle_on_grab_focus),
                              this, newcell));
                  newcell->inbox->edit.content_changed.connect(
                         sigc::bind<VisualCell *>(
                               sigc::mem_fun(this, &NotebookCanvas::scroll_into_view_callback), newcell));
      
//                newcell->inbox->show_all();
                  break;
                  }
            case DataCell::c_error:
            case DataCell::c_output:
            case DataCell::c_comment: {
                  newcell->outbox=manage( new TeXView(dc->texbuf) );
                  Gtk::VBox::BoxList::iterator newit=bl.insert(gtkit, *newcell->outbox);
// REPORT BUG: this sometimes segfaults
//                (*newit).set_options(Gtk::PACK_SHRINK);
                  gtk_box_set_child_packing(((Gtk::Box *)(&scrollbox))->gobj(), 
                                                                    ((Gtk::Widget *)(newcell->outbox))->gobj(),
                                                                    false, false, 0, GTK_PACK_START);
//                newcell->outbox->show_all();
                  
                  newcell->outbox->signal_button_release_event().connect( 
                        sigc::bind<NotebookCanvas *, VisualCell *>(
                              sigc::mem_fun(doc, &XCadabra::handle_outbox_select), this, newcell));
                  break;
                  }
            case DataCell::c_tex: {
                  std::ostringstream fstr;
                  fstr << THEFONT << " " << 12+(doc.font_step*2); 
                  newcell->texbox=manage( new TeXInput(dc->textbuf, dc->texbuf, fstr.str()) );
                  newcell->texbox->texview.signal_button_release_event().connect( 
                        sigc::bind<NotebookCanvas *, VisualCell *>(
                              sigc::mem_fun(doc, &XCadabra::handle_visibility_toggle), this, newcell));

                  // Connect signal requesting update of the TeX rendering.
                  newcell->texbox->edit.emitter.connect(
                        sigc::bind(
                              sigc::mem_fun(doc, &XCadabra::handle_tex_update_request), this, newcell));

                  Gtk::VBox::BoxList::iterator newit=bl.insert(gtkit, *newcell->texbox);

                  gtk_box_set_child_packing(((Gtk::Box *)(&scrollbox))->gobj(), 
                                                                    ((Gtk::Widget *)(newcell->texbox))->gobj(),
                                                                    false, false, 0, GTK_PACK_START);

// REPORT BUG: this sometimes segfaults
//                (*newit).set_options(Gtk::PACK_SHRINK);
                  newcell->texbox->edit.signal_grab_focus().connect(
                        sigc::bind<NotebookCanvas *, VisualCell *>(
                              sigc::mem_fun(doc, &XCadabra::handle_on_grab_focus),
                              this, newcell));

                  // Hide source depending on setting in the datacell.
                  newcell->texbox->set_folded(newcell->datacell->tex_hidden);
                  break;
                  }
            }

      // Restore bottom line marker 
//    scrollbox.pack_start(bottomline, Gtk::PACK_SHRINK);
//    bottomline.show();

      return newcell; //visualcells.back();
      }


Generated by  Doxygen 1.6.0   Back to index