-
-
-/* these functions are for the spellchecker */
-char* NextWord(float &value)
-{
- if (!current_view->available()){
- value = 1;
- return 0;
- }
-
- char* string = current_view->currentBuffer()->text->SelectNextWord(value);
-
- return string;
-}
-
-
-void SelectLastWord()
-{
- if (!current_view->available())
- return;
-
- current_view->getScreen()->HideCursor();
- BeforeChange();
- current_view->currentBuffer()->text->SelectSelectedWord();
- current_view->getScreen()->ToggleSelection(false);
- current_view->currentBuffer()->update(0);
-}
-
-
-void EndOfSpellCheck()
-{
- if (!current_view->available())
- return;
-
- current_view->getScreen()->HideCursor();
- BeforeChange();
- current_view->currentBuffer()->text->SelectSelectedWord();
- current_view->currentBuffer()->text->ClearSelection();
- current_view->currentBuffer()->update(0);
-}
-
-
-void ReplaceWord(string const & replacestring)
-{
- if (!current_view->getScreen())
- return;
-
- current_view->getScreen()->HideCursor();
- current_view->currentBuffer()->update(-2);
-
- /* clear the selection (if there is any) */
- current_view->getScreen()->ToggleSelection(false);
- current_view->currentBuffer()->text->
- ReplaceSelectionWithString(replacestring.c_str());
-
- current_view->currentBuffer()->text->SetSelectionOverString(replacestring.c_str());
-
- // Go back so that replacement string is also spellchecked
- for (string::size_type i = 0; i < replacestring.length() + 1; ++i) {
- current_view->currentBuffer()->text->CursorLeftIntern();
- }
- current_view->currentBuffer()->update(1);
-}
-// End of spellchecker stuff
-
-
-
-//
-// 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);
- int a = 0;
-
- for (a=1; a<i && tmptoclist->next; a++){
- tmptoclist = tmptoclist->next;
- }
-
- if (!tmptoclist)
- return;
-
-
- LyXParagraph *par = current_view->currentBuffer()->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) {
- BeforeChange();
- current_view->currentBuffer()->text->SetCursor(par, 0);
- current_view->currentBuffer()->text->sel_cursor =
- current_view->currentBuffer()->text->cursor;
- current_view->currentBuffer()->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->currentBuffer()->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->currentBuffer()->params.textclass,
- par->GetLayout()).labeltype;
-
- if (labeltype >= LABEL_COUNTER_CHAPTER
- && labeltype <= LABEL_COUNTER_CHAPTER +
- current_view->currentBuffer()->params.tocdepth) {
- /* insert this into the table of contents */
- /* first indent a little bit */
-
- for (pos=0;
- pos < (labeltype -
- textclasslist.TextClass(current_view->currentBuffer()->
- 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 */
-#ifdef NEW_TEXT
- LyXParagraph::size_type i = 0;
- while (pos < 199 && i < par->size()) {
-#else
- int i = 0;
- while (pos < 199 && i < par->last) {
-#endif
- 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->getOwner()->getLyXFunc()->Dispatch(LFUN_REFGOTO, s.c_str());
- return;
- }
-
- string t;
- if (data==0)
- t += "\\ref";
- else
- t += "\\pageref";
-
- if(current_view->currentBuffer()->isSGML())
- t += "[" + u + "]" + "{" + s + "}";
- else
- t += "{" + s + "}";
-
- Inset *new_inset =
- new InsetRef(t, current_view->currentBuffer());
- current_view->currentBuffer()->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 : "";
- //string currentstr = fl_get_browser_line(brow,
- // fl_get_browser(brow));
-
- fl_clear_browser(brow);
-
- string refs = current_view->currentBuffer()->getReferenceList('\n');
- int topline = 1;
-
-#if FL_REVISION > 85
- 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);
-#else
- // Keep the old ugly code for xforms 0.81 compatibility
- string curr_ref;
- int ref_num = 0;
-
- while(true) {
- curr_ref = refs.token('\n',ref_num);
- if (curr_ref.empty())
- break;
- fl_add_browser_line(brow,curr_ref.c_str());
- ref_num++;
- }
-#endif
-
- 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->currentBuffer()->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->currentBuffer()->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);
-}
-
-
-void UpdateInset(Inset* inset, bool mark_dirty)
-{
- if (!inset)
- return;
-
- /* very first check for locking insets*/
- if (current_view->currentBuffer()->the_locking_inset == inset){
- if (current_view->currentBuffer()->text->UpdateInset(inset)){
- current_view->update();
- if (mark_dirty){
- if (current_view->currentBuffer()->isLyxClean())
- minibuffer->setTimer(4);
- current_view->currentBuffer()->markDirty();
- }
- current_view->updateScrollbar();
- return;
- }
- }
-
- /* first check the current buffer */
- if (current_view->available()){
- current_view->getScreen()->HideCursor();
- current_view->currentBuffer()->update(-3);
- if (current_view->currentBuffer()->text->UpdateInset(inset)){
- if (mark_dirty)
- current_view->currentBuffer()->update(1);
- else
- current_view->currentBuffer()->update(3);
- return;
- }
- }
-
- // check all buffers
- bufferlist.updateInset(inset, mark_dirty);
-
-}
-
-
-/* these functions return 1 if an error occured,
- otherwise 0 */
-int LockInset(UpdatableInset* inset)
-{
- if (!current_view->currentBuffer()->the_locking_inset && inset){
- current_view->currentBuffer()->the_locking_inset = inset;
- return 0;
- }
- return 1;
-}
-
-
-void ShowLockedInsetCursor(long x, long y, int asc, int desc)
-{
- if (current_view->currentBuffer()->the_locking_inset &&
- current_view->getScreen()){
- y += current_view->currentBuffer()->text->cursor.y;
- current_view->getScreen()->ShowManualCursor(x, y,
- asc, desc);
- }
-}
-
-
-void HideLockedInsetCursor(long x, long y, int asc, int desc)
-{
- if (current_view->currentBuffer()->the_locking_inset &&
- current_view->getScreen()){
- y += current_view->currentBuffer()->text->cursor.y;
- current_view->getScreen()->HideManualCursor(x, y,
- asc, desc);
- }
-}
-
-
-void FitLockedInsetCursor(long x, long y, int asc, int desc)
-{
- if (current_view->currentBuffer()->the_locking_inset &&
- current_view->getScreen()){
- y += current_view->currentBuffer()->text->cursor.y;
- if (current_view->getScreen()->FitManualCursor(x, y, asc, desc))
- current_view->updateScrollbar();
- }
-}
-
-
-int UnlockInset(UpdatableInset* inset)
-{
- if (inset &&
- current_view->currentBuffer()->the_locking_inset == inset){
- inset->InsetUnlock();
- current_view->currentBuffer()->the_locking_inset = 0;
- current_view->currentBuffer()->text->FinishUndo();
- return 0;
- }
- return bufferlist.unlockInset(inset);
-}
-
-
-void LockedInsetStoreUndo(Undo::undo_kind kind)
-{
- if (!current_view->currentBuffer()->the_locking_inset)
- return; // shouldn't happen
- if (kind == Undo::EDIT) // in this case insets would not be stored!
- kind = Undo::FINISH;
- current_view->currentBuffer()->text->SetUndo(kind,
- current_view->currentBuffer()->text->cursor.par->
- ParFromPos(current_view->currentBuffer()->text->cursor.pos)->previous,
- current_view->currentBuffer()->text->cursor.par->
- ParFromPos(current_view->currentBuffer()->text->cursor.pos)->next);
-}
-
-
-void PutInsetIntoInsetUpdateList(Inset* inset)
-{
- if (inset) {
- InsetUpdateStruct* tmp = new InsetUpdateStruct();
- tmp->inset = inset;
- tmp->next = InsetUpdateList;
- InsetUpdateList = tmp;
- }
-}
-
-
-void UpdateInsetUpdateList()
-{
- InsetUpdateStruct *tmp = InsetUpdateList;
- while (tmp) {
- UpdateInset(tmp->inset, false); // "false" because no document change
- tmp = tmp->next;
- }
-
- /* delete the update list */
- while (InsetUpdateList) {
- tmp = InsetUpdateList;
- InsetUpdateList = InsetUpdateList->next;
- delete tmp;
- }
- InsetUpdateList = 0;
-}
-
-#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, ' ');
-}
-
-