-
-
-//
-// Table of Contents
-//
-
-struct TocList {
- int counter[6];
- bool appendix;
- TocList * next;
-};
-
-
-static TocList * toclist = 0;
-
-
-extern "C" void TocSelectCB(FL_OBJECT * ob, long)
-{
- if (!current_view->available())
- return;
-
- TocList * tmptoclist = toclist;
- int i = fl_get_browser(ob);
- for (int a = 1; a < i && tmptoclist->next; ++a) {
- tmptoclist = tmptoclist->next;
- }
-
- if (!tmptoclist)
- return;
-
-
- LyXParagraph * par = current_view->buffer()->paragraph;
- while (par && (par->GetFirstCounter(0) != tmptoclist->counter[0] ||
- par->GetFirstCounter(1) != tmptoclist->counter[1] ||
- par->GetFirstCounter(2) != tmptoclist->counter[2] ||
- par->GetFirstCounter(3) != tmptoclist->counter[3] ||
- par->GetFirstCounter(4) != tmptoclist->counter[4] ||
- par->GetFirstCounter(5) != tmptoclist->counter[5] ||
- par->appendix != tmptoclist->appendix)) {
- par = par->LastPhysicalPar()->Next();
- }
-
- if (par) {
- current_view->beforeChange();
- current_view->text->SetCursor(par, 0);
- current_view->text->sel_cursor =
- current_view->text->cursor;
- current_view->update(0);
- }
- else {
- WriteAlert(_("Error"),
- _("Couldn't find this label"),
- _("in current document."));
- }
-
-}
-
-
-extern "C" void TocCancelCB(FL_OBJECT *, long)
-{
- fl_hide_form(fd_form_toc->form_toc);
-}
-
-
-extern "C" void TocUpdateCB(FL_OBJECT *, long)
-{
- static LyXParagraph * stapar = 0;
- TocList * tmptoclist = 0;
-
- /* deleted the toclist */
- if (toclist){
- while (toclist){
- tmptoclist = toclist->next;
- delete toclist;
- toclist = tmptoclist;
- }
- }
- toclist = 0;
- tmptoclist = toclist;
-
-
- fl_clear_browser(fd_form_toc->browser_toc);
- if (!current_view->available()) {
- fl_add_browser_line(fd_form_toc->browser_toc,
- _("*** No Document ***"));
- return;
- }
- fl_hide_object(fd_form_toc->browser_toc);
- /* get the table of contents */
- LyXParagraph * par = current_view->buffer()->paragraph;
- char labeltype;
- char * line = new char[200];
- int pos = 0;
- unsigned char c;
- int topline = 0;
-
- if (stapar == par)
- topline = fl_get_browser_topline(fd_form_toc->browser_toc);
- stapar = par;
-
- while (par) {
- labeltype = textclasslist.Style(current_view->buffer()->params.textclass,
- par->GetLayout()).labeltype;
-
- if (labeltype >= LABEL_COUNTER_CHAPTER
- && labeltype <= LABEL_COUNTER_CHAPTER +
- current_view->buffer()->params.tocdepth) {
- /* insert this into the table of contents */
- /* first indent a little bit */
-
- for (pos = 0;
- pos < (labeltype -
- textclasslist.TextClass(current_view->buffer()->
- params.textclass).maxcounter()) * 4 + 2;
- ++pos)
- line[pos] = ' ';
-
- // Then the labestring
- if (!par->labelstring.empty()) {
- string::size_type i = 0;
- while (pos < 199 && i < par->labelstring.length()) {
- line[pos] = par->labelstring[i];
- ++i;
- ++pos;
- }
- }
-
- line[pos] = ' ';
- ++pos;
-
- /* now the contents */
- LyXParagraph::size_type i = 0;
- while (pos < 199 && i < par->size()) {
- c = par->GetChar(i);
- if (isprint(c) || c >= 128) {
- line[pos] = c;
- ++pos;
- }
- ++i;
- }
- line[pos] = '\0';
- fl_add_browser_line(fd_form_toc->browser_toc, line);
-
- /* make a toclist entry */
- if (!tmptoclist){
- tmptoclist = new TocList;
- toclist = tmptoclist;
- } else {
- tmptoclist->next = new TocList;
- tmptoclist = tmptoclist->next;
- }
-
- tmptoclist->next = 0;
- int a = 0;
- for (a = 0; a < 6; ++a) {
- tmptoclist->counter[a] = par->GetFirstCounter(a);
- }
- tmptoclist->appendix = par->appendix;
- }
- par = par->LastPhysicalPar()->Next();
-
- }
- delete[] line;
- fl_set_browser_topline(fd_form_toc->browser_toc, topline);
- fl_show_object(fd_form_toc->browser_toc);
-}
-
-
-/* callbacks for form form_ref */
-extern "C" void RefSelectCB(FL_OBJECT *, long data)
-{
- if (!current_view->available())
- return;
-
- string s =
- fl_get_browser_line(fd_form_ref->browser_ref,
- fl_get_browser(fd_form_ref->browser_ref));
- string u = frontStrip(strip(fl_get_input(fd_form_ref->ref_name)));
-
- if (s.empty())
- return;
-
- if (data == 2) {
- current_view->owner()->getLyXFunc()->Dispatch(LFUN_REFGOTO, s.c_str());
- return;
- }
-
- string t;
- if (data == 0)
- t += "\\ref";
- else
- t += "\\pageref";
-
- if(current_view->buffer()->isSGML())
- t += "[" + u + "]" + "{" + s + "}";
- else
- t += "{" + s + "}";
-
- Inset * new_inset =
- new InsetRef(t, current_view->buffer());
- current_view->insertInset(new_inset);
-}
-
-
-extern "C" void RefUpdateCB(FL_OBJECT *, long)
-{
- if (!current_view->available()) {
- fl_clear_browser(fd_form_ref->browser_ref);
- return;
- }
-
- FL_OBJECT * brow = fd_form_ref->browser_ref;
-
- // Get the current line, in order to restore it later
- char const * const btmp = fl_get_browser_line(brow,
- fl_get_browser(brow));
- string currentstr = btmp ? btmp : "";
-
- fl_clear_browser(brow);
-
- string refs = current_view->buffer()->getReferenceList('\n');
- int topline = 1;
-
- fl_addto_browser_chars(brow, refs.c_str());
- int total_lines = fl_get_browser_maxline(brow);
- for (int i = 1; i <= total_lines ; ++i) {
- if (fl_get_browser_line(brow, i) == currentstr) {
- topline = i;
- break;
- }
- }
- fl_set_browser_topline(brow, topline);
-
- if (!fl_get_browser_maxline(brow)) {
- fl_add_browser_line(brow,
- _("*** No labels found in document ***"));
- fl_deactivate_object(brow);
- } else {
- fl_select_browser_line(brow, topline);
- fl_activate_object(brow);
- }
- if (current_view->buffer()->isReadonly()) {
- // would be better to de/activate insert buttons
- // but that's more work... besides this works. ARRae
- fl_hide_form(fd_form_ref->form_ref);
- }
- if (!current_view->buffer()->isSGML()) {
- fl_deactivate_object(fd_form_ref->ref_name);
- fl_set_object_lcol(fd_form_ref->ref_name, FL_INACTIVE);
- }
- else {
- fl_activate_object(fd_form_ref->ref_name);
- fl_set_object_lcol(fd_form_ref->ref_name, FL_BLACK);
- }
-}
-
-
-extern "C" void RefHideCB(FL_OBJECT *, long)
-{
- fl_hide_form(fd_form_ref->form_ref);
-}
-
-#ifdef WITH_WARNINGS
-#warning UGLY!!
-#endif
-// I know we shouldn't put anything in here but this seems the fastest
-// way to do this (and the cleanest for now). This function just inserts
-// a newline in the string and the inserts 'depth'-spaces so that the
-// code is indented in the right way!!!
-void addNewlineAndDepth(string & file, int const depth)
-{
- file += '\n';
- file.append(depth, ' ');
-}