X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Flyx_cb.C;h=f93db63ab5b4820201290c8b340f2205e44cfc99;hb=609a11852e193730db57ebbd2115c9ca8fb4549d;hp=975c51f4973557a381f13b2fad601a90ea2b62ad;hpb=76938908d7da15b92bad3908e71eb969c9449c0e;p=lyx.git diff --git a/src/lyx_cb.C b/src/lyx_cb.C index 975c51f497..f93db63ab5 100644 --- a/src/lyx_cb.C +++ b/src/lyx_cb.C @@ -15,45 +15,37 @@ #include #include "LString.h" -#include "support/lstrings.h" -#include "lyx_main.h" #include FORMS_H_LOCATION #include "lyx.h" #include "layout_forms.h" #include "bullet_forms.h" #include "print_form.h" #include "form1.h" -#include "spellchecker.h" -#include "version.h" +#include "lyx_main.h" #include "lyx_cb.h" -#include "credits.h" #include "insets/insetref.h" -#include "insets/insetquotes.h" #include "insets/insetlabel.h" #include "insets/figinset.h" #include "lyxfunc.h" -#include "latexoptions.h" -#include "lyxfont.h" #include "minibuffer.h" #include "combox.h" #include "bufferlist.h" -#include "support/filetools.h" -#include "support/path.h" #include "filedlg.h" #include "lyx_gui_misc.h" #include "LyXView.h" +#include "BufferView.h" #include "lastfiles.h" +#include "bufferview_funcs.h" #include "support/FileInfo.h" -#include "debug.h" #include "support/syscall.h" -#include "support/lyxlib.h" +#include "support/filetools.h" +#include "support/path.h" #include "lyxserver.h" #include "FontLoader.h" #include "lyxrc.h" #include "lyxtext.h" -#include "gettext.h" -#include "layout.h" -#include "language.h" +#include "CutAndPaste.h" +#include "TextCache.h" using std::ifstream; using std::copy; @@ -63,8 +55,12 @@ using std::cout; using std::ios; using std::istream_iterator; using std::pair; +using std::vector; +using std::sort; +using std::equal; extern Combox * combo_language; +extern Combox * combo_language2; extern BufferList bufferlist; extern void show_symbols_form(); extern FD_form_title * fd_form_title; @@ -82,6 +78,8 @@ extern FD_form_ref * fd_form_ref; extern FD_LaTeXOptions * fd_latex_options; extern FD_form_bullet * fd_form_bullet; +#define XFORMS_CLIPBOARD 1 + extern BufferView * current_view; // called too many times in this file... extern void DeleteSimpleCutBuffer(); /* for the cleanup when exiting */ @@ -99,15 +97,6 @@ char ascii_type; /* for selection notify callbacks */ bool scrolling = false; -char updatetimer = 0; - -/* whether the work area should get callbacks */ -bool input_prohibited = false; - -/* the selection possible is needed, that only motion events are -* used, where the bottom press event was on the drawing area too */ -bool selection_possible = false; - // This is used to make the dreaded font toggle problem hopefully go // away. Definitely not the best solution, but I think it sorta works. bool toggleall = true; @@ -195,82 +184,12 @@ void ShowMessage(Buffer * buf, } } -// How should this actually work? Should it prohibit input in all BufferViews, -// or just in the current one? If "just the current one", then it should be -// placed in BufferView. If "all BufferViews" then LyXGUI (I think) should -// run "ProhibitInput" on all LyXViews which will run prohibitInput on all -// BufferViews. Or is it perhaps just the (input in) BufferViews in the -// current LyxView that should be prohibited (Lgb) (This applies to -// "AllowInput" as well.) -void ProhibitInput() -{ - input_prohibited = true; - current_view->hideCursor(); - - static Cursor cursor; - static bool cursor_undefined = true; - - if (cursor_undefined){ - cursor = XCreateFontCursor(fl_display, XC_watch); - XFlush(fl_display); - cursor_undefined = false; - } - - /* set the cursor to the watch for all forms and the canvas */ - XDefineCursor(fl_display, current_view->owner()->getForm()->window, - cursor); - if (fd_form_paragraph->form_paragraph->visible) - XDefineCursor(fl_display, - fd_form_paragraph->form_paragraph->window, - cursor); - if (fd_form_character->form_character->visible) - XDefineCursor(fl_display, - fd_form_character->form_character->window, - cursor); - - XFlush(fl_display); - fl_deactivate_all_forms(); -} - - -// Should find a way to move this into BufferView.C -void SetXtermCursor(Window win) -{ - static Cursor cursor; - static bool cursor_undefined = true; - if (cursor_undefined){ - cursor = XCreateFontCursor(fl_display, XC_xterm); - XFlush(fl_display); - cursor_undefined = false; - } - XDefineCursor(fl_display, win, cursor); - XFlush(fl_display); -} - -void AllowInput() -{ - input_prohibited = false; - - /* reset the cursor from the watch for all forms and the canvas */ - - XUndefineCursor(fl_display, current_view->owner()->getForm()->window); - if (fd_form_paragraph->form_paragraph->visible) - XUndefineCursor(fl_display, - fd_form_paragraph->form_paragraph->window); - if (fd_form_character->form_character->visible) - XUndefineCursor(fl_display, - fd_form_character->form_character->window); - - // What to do about this? (Lgb) - if (current_view->belowMouse()) - SetXtermCursor(current_view->owner()->getForm()->window); - - XFlush(fl_display); - fl_activate_all_forms(); -} +// only called from this file, LyXView and LyXFunc +char updatetimer = 0; +// only called from BufferView_pimpl and LyXFunc void FreeUpdateTimer() { /* a real free timer would be better but I don't know @@ -279,6 +198,7 @@ void FreeUpdateTimer() } +// Only called from LyXFunc void SetUpdateTimer(float time) { fl_set_timer(current_view->owner()->getMainForm()->timer_update, time); @@ -324,7 +244,7 @@ void MenuWriteAs(Buffer * buffer) string oldname = fname; LyXFileDlg fileDlg; - ProhibitInput(); + ProhibitInput(current_view); fileDlg.SetButton(0, _("Documents"), lyxrc.document_path); fileDlg.SetButton(1, _("Templates"), lyxrc.template_path); @@ -335,7 +255,7 @@ void MenuWriteAs(Buffer * buffer) OnlyPath(fname), "*.lyx", OnlyFilename(fname)); - AllowInput(); + AllowInput(current_view); if (fname.empty()) { return; @@ -489,10 +409,10 @@ int MakeLaTeXOutput(Buffer * buffer) if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) { path = buffer->tmppath; } - if (!buffer->isDviClean()) { + //if (!buffer->isDviClean()) { Path p(path); ret = MenuRunLaTeX(buffer); - } + //} return ret; } @@ -515,8 +435,7 @@ bool RunScript(Buffer * buffer, bool wait, return false; /* get DVI-Filename */ if (name.empty()) - name = ChangeExtension(buffer->getLatexName(), - ".dvi", true); + name = ChangeExtension(buffer->getLatexName(), ".dvi"); path = OnlyPath(name); if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) { @@ -565,9 +484,7 @@ bool RunScript(Buffer * buffer, bool wait, // the return code of the command. This means that all // the code I added in PrintApplyCB is currently // useless... -#ifdef WITH_WARNINGS -#warning What should we do here? -#endif + // CHECK What should we do here? ShowMessage(buffer, _("Executing command:"), cmd); result = one.startscript(Systemcalls::System, cmd); } else { @@ -586,16 +503,16 @@ bool CreatePostscript(Buffer * buffer, bool wait = false) //if (!bv->text) // return false; - ProhibitInput(); + ProhibitInput(current_view); // Generate dvi file if (MakeLaTeXOutput(buffer) > 0) { - AllowInput(); + AllowInput(current_view); return false; } // Generate postscript file - string psname = ChangeExtension (buffer->fileName(), - ".ps_tmp", true); + string psname = OnlyFilename(ChangeExtension (buffer->fileName(), + ".ps_tmp")); string paper; @@ -662,7 +579,7 @@ bool CreatePostscript(Buffer * buffer, bool wait = false) } Path p(path); bool ret = RunScript(buffer, wait, command); - AllowInput(); + AllowInput(current_view); return ret; } @@ -681,9 +598,9 @@ bool PreviewPostscript(Buffer * buffer) } // Start postscript viewer - ProhibitInput(); - string ps = ChangeExtension (buffer->fileName(), - ".ps_tmp", true); + ProhibitInput(current_view); + string ps = OnlyFilename(ChangeExtension (buffer->fileName(), + ".ps_tmp")); // push directorypath, if necessary string path = OnlyPath(buffer->fileName()); if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)){ @@ -691,7 +608,7 @@ bool PreviewPostscript(Buffer * buffer) } Path p(path); bool ret = RunScript(buffer, false, lyxrc.view_ps_command, ps); - AllowInput(); + AllowInput(current_view); return ret; } @@ -708,7 +625,8 @@ void MenuFax(Buffer * buffer) } // Send fax - string ps = ChangeExtension (buffer->fileName(), ".ps_tmp", true); + string ps = OnlyFilename(ChangeExtension (buffer->fileName(), + ".ps_tmp")); string path = OnlyPath (buffer->fileName()); if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) { path = buffer->tmppath; @@ -805,6 +723,7 @@ bool AskOverwrite(Buffer * buffer, string const & s) return true; } + void MenuMakeLaTeX(Buffer * buffer) { // Why care about this? @@ -842,8 +761,7 @@ void MenuMakeLinuxDoc(Buffer * buffer) } // Get LinuxDoc-Filename - string s = ChangeExtension(buffer->fileName(), - ".sgml", false); + string s = ChangeExtension(buffer->fileName(), ".sgml"); if (!AskOverwrite(buffer, s)) return; @@ -870,8 +788,7 @@ void MenuMakeDocBook(Buffer * buffer) } // Get DocBook-Filename - string s = ChangeExtension(buffer->fileName(), - ".sgml", false); + string s = ChangeExtension(buffer->fileName(), ".sgml"); if (!AskOverwrite(buffer, s)) return; @@ -892,8 +809,7 @@ void MenuMakeAscii(Buffer * buffer) //if (!bv->text) return; /* get LaTeX-Filename */ - string s = ChangeExtension (buffer->fileName(), - ".txt", false); + string s = ChangeExtension (buffer->fileName(), ".txt"); if (!AskOverwrite(buffer, s)) @@ -911,9 +827,8 @@ void MenuPrint(Buffer * buffer) //if (!bv->text) // return; - string input_file = ChangeExtension(buffer->fileName(), - lyxrc.print_file_extension, - true); + string input_file = OnlyFilename(ChangeExtension(buffer->fileName(), + lyxrc.print_file_extension)); fl_set_input(fd_form_print->input_file, input_file.c_str()); if (fd_form_print->form_print->visible) { @@ -926,6 +841,7 @@ void MenuPrint(Buffer * buffer) } } + void MenuMakeHTML(Buffer * buffer) { // First, create LaTeX file @@ -937,7 +853,7 @@ void MenuMakeHTML(Buffer * buffer) // the tex file name has to be correct for // latex, but the html file name can be // anything. - string result = ChangeExtension(file, ".html", false); + string result = ChangeExtension(file, ".html"); string infile = buffer->getLatexName(false); string tmp = lyxrc.html_command; tmp = subst(tmp, "$$FName", infile); @@ -955,6 +871,7 @@ void MenuMakeHTML(Buffer * buffer) } + void MenuMakeHTML_LinuxDoc(Buffer * buffer) { // First, create LinuxDoc file @@ -963,8 +880,8 @@ void MenuMakeHTML_LinuxDoc(Buffer * buffer) // And now, run the converter string file = buffer->fileName(); - string result = ChangeExtension(file, ".html", false); - string infile = ChangeExtension(file, ".sgml", false); + string result = ChangeExtension(file, ".html"); + string infile = ChangeExtension(file, ".sgml"); string tmp = lyxrc.linuxdoc_to_html_command; tmp = subst(tmp, "$$FName", infile); tmp = subst(tmp, "$$OutName", result); @@ -988,8 +905,8 @@ void MenuMakeHTML_DocBook(Buffer * buffer) // And now, run the converter string file = buffer->fileName(); - string result = ChangeExtension(file, ".html", false); - string infile = ChangeExtension(file, ".sgml", false); + string result = ChangeExtension(file, ".html"); + string infile = ChangeExtension(file, ".sgml"); string tmp = lyxrc.docbook_to_html_command; tmp = subst(tmp, "$$FName", infile); tmp = subst(tmp, "$$OutName", result); @@ -1006,6 +923,7 @@ void MenuMakeHTML_DocBook(Buffer * buffer) } + void MenuExport(Buffer * buffer, string const & extyp) { // latex @@ -1095,26 +1013,26 @@ void QuitLyX() -void AutoSave() +void AutoSave(BufferView * bv) // should probably be moved into BufferList (Lgb) // Perfect target for a thread... { - if (!current_view->available()) + if (!bv->available()) return; - if (current_view->buffer()->isBakClean() - || current_view->buffer()->isReadonly()) { + if (bv->buffer()->isBakClean() + || bv->buffer()->isReadonly()) { // We don't save now, but we'll try again later - current_view->owner()->resetAutosaveTimer(); + bv->owner()->resetAutosaveTimer(); return; } - current_view->owner()->getMiniBuffer()->Set(_("Autosaving current document...")); + bv->owner()->getMiniBuffer()->Set(_("Autosaving current document...")); // create autosave filename - string fname = OnlyPath(current_view->buffer()->fileName()); + string fname = OnlyPath(bv->buffer()->fileName()); fname += "#"; - fname += OnlyFilename(current_view->buffer()->fileName()); + fname += OnlyFilename(bv->buffer()->fileName()); fname += "#"; // tmp_ret will be located (usually) in /tmp @@ -1130,7 +1048,7 @@ void AutoSave() // anyway. bool failed = false; if (!tmp_ret.empty()) { - current_view->buffer()->writeFile(tmp_ret, 1); + bv->buffer()->writeFile(tmp_ret, 1); // assume successful write of tmp_ret if (rename(tmp_ret.c_str(), fname.c_str()) == -1) { failed = true; @@ -1145,11 +1063,11 @@ void AutoSave() if (failed) { // failed to write/rename tmp_ret so try writing direct - if (!current_view->buffer()->writeFile(fname, 1)) { + if (!bv->buffer()->writeFile(fname, 1)) { // It is dangerous to do this in the child, // but safe in the parent, so... if (pid == -1) - current_view->owner()->getMiniBuffer()->Set(_("Autosave Failed!")); + bv->owner()->getMiniBuffer()->Set(_("Autosave Failed!")); } } if (pid == 0) { // we are the child so... @@ -1157,8 +1075,8 @@ void AutoSave() } } - current_view->buffer()->markBakClean(); - current_view->owner()->resetAutosaveTimer(); + bv->buffer()->markBakClean(); + bv->owner()->resetAutosaveTimer(); } @@ -1204,11 +1122,11 @@ void InsertAsciiFile(BufferView * bv, string const & f, bool asParagraph) if (!bv->available()) return; if (fname.empty()) { - ProhibitInput(); + ProhibitInput(bv); fname = fileDlg.Select(_("File to Insert"), bv->owner()->buffer()->filepath, "*"); - AllowInput(); + AllowInput(bv); if (fname.empty()) return; } @@ -1270,7 +1188,7 @@ void MenuShowTableOfContents() void MenuInsertLabel(char const * arg) { string label = arg; - ProhibitInput(); + ProhibitInput(current_view); if (label.empty()) { pair result = askForText(_("Enter new label to insert:")); @@ -1283,7 +1201,7 @@ void MenuInsertLabel(char const * arg) new_inset->setContents(label); current_view->insertInset(new_inset); } - AllowInput(); + AllowInput(current_view); } @@ -1307,11 +1225,11 @@ void MenuInsertRef() } +#ifndef XFORMS_CLIPBOARD void MenuPasteSelection(char at) { if (!current_view->available()) return; - ascii_type = at; Atom data_prop = XInternAtom(fl_display, @@ -1323,22 +1241,10 @@ void MenuPasteSelection(char at) XA_PRIMARY, XA_STRING, data_prop, current_view->owner()->getForm()->window, 0); XFlush(fl_display); -} - -// candidate for move to BufferView -void Foot(BufferView * bv) -{ - if (!bv->available()) - return; - - bv->owner()->getMiniBuffer() - ->Set(_("Inserting Footnote...")); - bv->hideCursor(); - bv->update(-2); - bv->text->InsertFootnoteEnvironment(LyXParagraph::FOOTNOTE); - bv->update(1); } +#endif + // candidate for move to LyXView @@ -1364,7 +1270,7 @@ int RunLinuxDoc(BufferView * bv, int flag, string const & filename) int errorcode = 0; /* generate a path-less extension name */ - string name = ChangeExtension (filename, ".sgml", true); + string name = OnlyFilename(ChangeExtension (filename, ".sgml")); string path = OnlyPath (filename); if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) { path = bv->buffer()->tmppath; @@ -1374,10 +1280,11 @@ int RunLinuxDoc(BufferView * bv, int flag, string const & filename) if (!bv->available()) return 0; bv->buffer()->makeLinuxDocFile(name, 0); -#ifdef WITH_WARNINGS -#warning remove this once we have a proper geometry class -#endif - BufferParams::PAPER_SIZE ps = static_cast(bv->buffer()->params.papersize); + + // CHECK remove this once we have a proper geometry class + + BufferParams::PAPER_SIZE ps = + static_cast(bv->buffer()->params.papersize); switch (ps) { case BufferParams::PAPER_A4PAPER: add_flags = "-p a4"; @@ -1388,7 +1295,7 @@ int RunLinuxDoc(BufferView * bv, int flag, string const & filename) default: /* nothing to be done yet ;-) */ break; } - ProhibitInput(); + ProhibitInput(bv); Systemcalls one; switch (flag) { @@ -1410,7 +1317,7 @@ int RunLinuxDoc(BufferView * bv, int flag, string const & filename) break; } - AllowInput(); + AllowInput(bv); bv->buffer()->redraw(); return errorcode; @@ -1424,7 +1331,7 @@ int RunLinuxDoc(BufferView * bv, int flag, string const & filename) int RunDocBook(int flag, string const & filename) { /* generate a path-less extension name */ - string name = ChangeExtension (filename, ".sgml", true); + string name = OnlyFilename(ChangeExtension (filename, ".sgml")); string path = OnlyPath (filename); if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) { path = current_view->buffer()->tmppath; @@ -1445,7 +1352,7 @@ int RunDocBook(int flag, string const & filename) // case BufferParams::PAPER_USLETTER: add_flags = "-p letter"; break; // default: /* nothing to be done yet ;-) */ break; // } - ProhibitInput(); + ProhibitInput(current_view); int errorcode = 0; Systemcalls one; @@ -1464,7 +1371,7 @@ int RunDocBook(int flag, string const & filename) break; } - AllowInput(); + AllowInput(current_view); current_view->buffer()->redraw(); return errorcode; @@ -1875,6 +1782,7 @@ bool UpdateLayoutDocument(BufferParams * params) fl_set_input(fd_form_document->input_spacing, ""); switch (params->spacing.getSpace()) { + case Spacing::Default: // nothing bad should happen with this case Spacing::Single: { // \singlespacing @@ -2069,219 +1977,6 @@ void MenuLayoutSave() } -/* -------> These CB's use ToggleFree() as the (one and only?) font-changer. - They also show the current font state. */ - -static -void ToggleAndShow(BufferView *, LyXFont const &); - - -void FontSize(string const & size) -{ - LyXFont font(LyXFont::ALL_IGNORE); - font.setGUISize(size); - ToggleAndShow(current_view, font); -} - - -void Emph() -{ - LyXFont font(LyXFont::ALL_IGNORE); - font.setEmph(LyXFont::TOGGLE); - ToggleAndShow(current_view, font); -} - - -void Noun() -{ - LyXFont font(LyXFont::ALL_IGNORE); - font.setNoun(LyXFont::TOGGLE); - ToggleAndShow(current_view, font); -} - - -void Bold() -{ - LyXFont font(LyXFont::ALL_IGNORE); - font.setSeries(LyXFont::BOLD_SERIES); - ToggleAndShow(current_view, font); -} - - -void Underline() -{ - LyXFont font(LyXFont::ALL_IGNORE); - font.setUnderbar(LyXFont::TOGGLE); - ToggleAndShow(current_view, font); -} - - -void Code() -{ - LyXFont font(LyXFont::ALL_IGNORE); - font.setFamily(LyXFont::TYPEWRITER_FAMILY); // no good - ToggleAndShow(current_view, font); -} - - -void Sans() -{ - LyXFont font(LyXFont::ALL_IGNORE); - font.setFamily(LyXFont::SANS_FAMILY); - ToggleAndShow(current_view, font); -} - - -void Roman() -{ - LyXFont font(LyXFont::ALL_IGNORE); - font.setFamily(LyXFont::ROMAN_FAMILY); - ToggleAndShow(current_view, font); -} - - -void Tex() -{ - LyXFont font(LyXFont::ALL_IGNORE); - font.setLatex (LyXFont::TOGGLE); - ToggleAndShow(current_view, font); -} - -void LangCB(string const & l) -{ - LyXFont font(LyXFont::ALL_IGNORE); - Languages::iterator lit = languages.find(l); - if (lit != languages.end()) { - font.setLanguage(&(*lit).second); - ToggleAndShow(current_view, font); - } else - WriteAlert(_("Error! unknown language"),l); -} - - -void StyleReset() -{ - LyXFont font(LyXFont::ALL_INHERIT, ignore_language); - ToggleAndShow(current_view, font); -} - - -/* -------> Returns the current font and depth by printing a message. In the - * future perhaps we could try to implement a callback to the button-bar. - * That is, `light' the bold button when the font is currently bold, etc. - */ -string CurrentState() -{ - string state; - if (current_view->available()) { - // I think we should only show changes from the default - // font. (Asger) - Buffer * buffer = current_view->buffer(); - LyXFont font = current_view->text->real_current_font; - LyXFont defaultfont = textclasslist.TextClass(buffer-> - params.textclass).defaultfont(); - font.reduce(defaultfont); - state = _("Font: ") + font.stateText(); - - int depth = current_view->text->GetDepth(); - if (depth > 0) - state += string(_(", Depth: ")) + tostr(depth); - } - return state; -} - - -// candidate for move to BufferView -/* -------> Does the actual toggle job of the XxxCB() calls above. - * Also shows the current font state. - */ -static -void ToggleAndShow(BufferView * bv, LyXFont const & font) -{ - if (bv->available()) { - bv->hideCursor(); - bv->update(-2); - if (bv->the_locking_inset) - bv->the_locking_inset->SetFont(bv, font, toggleall); - else - bv->text->ToggleFree(font, toggleall); - bv->update(1); - } -} - - -// candidate for move to BufferView -void Margin(BufferView * bv) -{ - if (bv->available()) { - bv->owner()->getMiniBuffer()->Set(_("Inserting margin note...")); - bv->hideCursor(); - bv->update(-2); - bv->text->InsertFootnoteEnvironment(LyXParagraph::MARGIN); - bv->update(1); - } -} - - -void Figure() -{ - if (fd_form_figure->form_figure->visible) { - fl_raise_form(fd_form_figure->form_figure); - } else { - fl_show_form(fd_form_figure->form_figure, - FL_PLACE_MOUSE, FL_FULLBORDER, - _("Insert Figure")); - } -} - - -void Table() -{ - if (fd_form_table->form_table->visible) { - fl_raise_form(fd_form_table->form_table); - } else { - fl_show_form(fd_form_table->form_table, - FL_PLACE_MOUSE, FL_FULLBORDER, - _("Insert Table")); - } -} - - -// candidate for move to BufferView -void Melt(BufferView * bv) -{ - if (!bv->available()) return; - - bv->owner()->getMiniBuffer()->Set(_("Melt")); - bv->hideCursor(); - bv->beforeChange(); - bv->update(-2); - bv->text->MeltFootnoteEnvironment(); - bv->update(1); -} - - -// candidate for move to BufferView -// Change environment depth. -// if decInc >= 0, increment depth -// if decInc < 0, decrement depth -void changeDepth(BufferView * bv, int decInc) -{ - if (!bv->available()) return; - - bv->hideCursor(); - bv->update(-2); - if (decInc >= 0) - bv->text->IncDepth(); - else - bv->text->DecDepth(); - bv->update(1); - bv->owner()->getMiniBuffer() - ->Set(_("Changed environment depth" - " (in possible range, maybe not)")); -} - - // This is both GUI and LyXFont dependent. Don't know where to put it. (Asger) // Well, it's mostly GUI dependent, so I guess it will stay here. (Asger) LyXFont UserFreeFont() @@ -2366,14 +2061,18 @@ LyXFont UserFreeFont() case 11: font.setColor(LColor::inherit); break; } + string language = combo_language2->getline(); + Languages::iterator lit = languages.find(language); + if (lit != languages.end()) + font.setLanguage(&(*lit).second); + else + font.setLanguage(ignore_language); + + return font; } -void Free() -{ - ToggleAndShow(current_view, UserFreeFont()); -} /* callbacks for form form_title */ @@ -2538,6 +2237,7 @@ extern "C" void CharacterApplyCB(FL_OBJECT *, long) // all other uses of ToggleAndShow() (JMarc) toggleall = fl_get_button(fd_form_character->check_toggle_all); ToggleAndShow(current_view, UserFreeFont()); + current_view->setState(); toggleall = true; } @@ -2585,7 +2285,7 @@ void UpdateDocumentButtons(BufferParams const & params) extern "C" void ChoiceClassCB(FL_OBJECT * ob, long) { - ProhibitInput(); + ProhibitInput(current_view); if (textclasslist.Load(fl_get_choice(ob)-1)) { if (AskQuestion(_("Should I set some parameters to"), fl_get_choice_text(ob), @@ -2604,7 +2304,7 @@ extern "C" void ChoiceClassCB(FL_OBJECT * ob, long) fl_set_choice(fd_form_document->choice_class, current_view->buffer()->params.textclass + 1); } - AllowInput(); + AllowInput(current_view); } @@ -2664,12 +2364,28 @@ extern "C" void DocumentApplyCB(FL_OBJECT *, long) bool redo = false; BufferParams * params = &(current_view->buffer()->params); + Language const * old_language = params->language_info; params->language = combo_language->getline(); Languages::iterator lit = languages.find(params->language); + + Language const * new_language; if (lit != languages.end()) - params->language_info = &(*lit).second; + new_language = &(*lit).second; else - params->language_info = default_language; + new_language = default_language; + + if (current_view->available()) { + if (old_language != new_language && + old_language->RightToLeft == new_language->RightToLeft && + ! current_view->buffer()->isMultiLingual() ) + current_view->buffer()->ChangeLanguage(old_language, + new_language); + if (old_language != new_language) { + //current_view->buffer()->redraw(); + redo = true; + } + } + params->language_info = new_language; // If default skip is a "Length" but there's no text in the // input field, reset the kind to "Medskip", which is the default. @@ -2698,9 +2414,10 @@ extern "C" void DocumentApplyCB(FL_OBJECT *, long) if (!current_view->available()) return; - current_view->text->SetCursor(current_view->text->cursor.par, - current_view->text->cursor.pos); - current_view->setState(); + + current_view->text->SetCursor(current_view->text->cursor.par, + current_view->text->cursor.pos); + current_view->setState(); LyXTextClassList::ClassList::size_type new_class = fl_get_choice(fd_form_document->choice_class) - 1; @@ -2710,13 +2427,13 @@ extern "C" void DocumentApplyCB(FL_OBJECT *, long) if (textclasslist.Load(new_class)) { // successfully loaded redo = true; - current_view->owner()->getMiniBuffer()->Set(_("Converting document to new document class...")); - int ret = current_view->text-> - SwitchLayoutsBetweenClasses(current_view->buffer()-> - params.textclass, - new_class, - current_view->buffer()-> - paragraph); + current_view->owner()->getMiniBuffer()-> + Set(_("Converting document to new document class...")); + CutAndPaste cap; + int ret = cap.SwitchLayoutsBetweenClasses( + current_view->buffer()->params.textclass, + new_class, + current_view->buffer()->paragraph); if (ret) { string s; @@ -2994,7 +2711,7 @@ extern "C" void TableApplyCB(FL_OBJECT *, long) Language const * lang = current_view->text->cursor.par->getParLanguage(); - LyXFont font(LyXFont::ALL_INHERIT,lang); + LyXFont font(LyXFont::ALL_INHERIT, lang); for (int i = 0; i < xsize * ysize - 1; ++i) { current_view->text->cursor.par->InsertChar(0, LyXParagraph::META_NEWLINE); current_view->text->cursor.par->SetFont(0, font); @@ -3033,13 +2750,7 @@ extern "C" void PrintCancelCB(FL_OBJECT *, long) static bool stringOnlyContains (string const & LStr, char const * cset) { -#if 0 - char const * cstr = LStr.c_str(); - - return strspn(cstr, cset) == strlen(cstr); -#else return LStr.find_first_not_of(cset) == string::npos; -#endif } @@ -3209,6 +2920,30 @@ extern "C" void PrintOKCB(FL_OBJECT * ob, long data) } +void Figure() +{ + if (fd_form_figure->form_figure->visible) { + fl_raise_form(fd_form_figure->form_figure); + } else { + fl_show_form(fd_form_figure->form_figure, + FL_PLACE_MOUSE, FL_FULLBORDER, + _("Insert Figure")); + } +} + + +void Table() +{ + if (fd_form_table->form_table->visible) { + fl_raise_form(fd_form_table->form_table); + } else { + fl_show_form(fd_form_table->form_table, + FL_PLACE_MOUSE, FL_FULLBORDER, + _("Insert Table")); + } +} + + /* callbacks for form form_figure */ extern "C" void FigureApplyCB(FL_OBJECT *, long) { @@ -3303,10 +3038,17 @@ extern "C" void ScreenApplyCB(FL_OBJECT *, long) lyxrc.font_norm = fl_get_input(fd_form_screen->input_font_norm); lyxrc.zoom = atoi(fl_get_input(fd_form_screen->intinput_size)); fontloader.update(); - + + // Of course we should only to the resize and the textcahce.clear + // if values really changed...but not very important right now. (Lgb) + // All buffers will need resize bufferlist.resize(); - + // We also need to empty the textcache so that + // the buffer will be formatted correctly after + // a zoom change. + textcache.clear(); + current_view->owner()->getMiniBuffer()->Set(_("Screen options set")); } @@ -3365,14 +3107,7 @@ void Reconfigure(BufferView * bv) // Table of Contents // -struct TocList { - int counter[6]; - bool appendix; - TocList * next; -}; - - -static TocList * toclist = 0; +static vector toclist; extern "C" void TocSelectCB(FL_OBJECT * ob, long) @@ -3380,40 +3115,19 @@ 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); + TocUpdateCB(0, 0); + unsigned int choice = fl_get_browser(ob); + if (0 < choice && choice - 1 < toclist.size()) { + current_view->beforeChange(); + current_view->text->SetCursor(toclist[choice-1].par, 0); current_view->text->sel_cursor = current_view->text->cursor; current_view->update(0); - } - else { + } else { WriteAlert(_("Error"), _("Couldn't find this label"), _("in current document.")); } - } @@ -3423,106 +3137,54 @@ extern "C" void TocCancelCB(FL_OBJECT *, long) } -extern "C" void TocUpdateCB(FL_OBJECT *, long) +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()) { + toclist.clear(); + fl_clear_browser(fd_form_toc->browser_toc); 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; + + vector > tmp = + current_view->buffer()->getTocList(); + int type = fl_get_choice(fd_form_toc->toctype)-1; + //if (toclist == tmp[type]) + // return; + if (toclist.size() == tmp[type].size()) { + // Check if all elements are the same. + unsigned int i = 0; + for (; i < toclist.size(); ++i) { + if (toclist[i] != tmp[type][i]) + break; } - par = par->LastPhysicalPar()->Next(); - + if (i >= toclist.size()) return; } - delete[] line; + + toclist = tmp[type]; + + static Buffer * buffer = 0; + int topline = 0; + int line = 0; + if (buffer == current_view->buffer()) { + topline = fl_get_browser_topline(fd_form_toc->browser_toc); + line = fl_get_browser(fd_form_toc->browser_toc); + } else + buffer = current_view->buffer(); + + fl_clear_browser(fd_form_toc->browser_toc); + fl_hide_object(fd_form_toc->browser_toc); + + for (vector::const_iterator it = toclist.begin(); + it != toclist.end(); ++it) + fl_add_browser_line(fd_form_toc->browser_toc, + (string(4*(*it).depth,' ')+ + (*it).str).c_str()); + fl_set_browser_topline(fd_form_toc->browser_toc, topline); + fl_select_browser_line(fd_form_toc->browser_toc, line); fl_show_object(fd_form_toc->browser_toc); } @@ -3541,18 +3203,28 @@ extern "C" void RefSelectCB(FL_OBJECT *, long data) if (s.empty()) return; - if (data == 2) { + if (data == 5) { current_view->owner()->getLyXFunc()->Dispatch(LFUN_REFGOTO, s.c_str()); + if (!current_view->NoSavedPositions()) { + fl_activate_object(fd_form_ref->back); + fl_set_object_lcol(fd_form_ref->back, FL_BLACK); + } return; - } - - string t; - if (data == 0) - t += "\\ref"; - else - t += "\\pageref"; + } else if (data >= 6) { + current_view->owner()->getLyXFunc()->Dispatch(LFUN_REFBACK); + if (current_view->NoSavedPositions()) { + fl_deactivate_object(fd_form_ref->back); + fl_set_object_lcol(fd_form_ref->back, FL_INACTIVE); + } + return; + } + + static string const commands[5] + = { "\\ref", "\\pageref", "\\vref", "\\vpageref", + "\\prettyref"}; + string t = commands[data]; - if(current_view->buffer()->isSGML()) + if (current_view->buffer()->isSGML()) t += "[" + u + "]" + "{" + s + "}"; else t += "{" + s + "}"; @@ -3578,11 +3250,16 @@ extern "C" void RefUpdateCB(FL_OBJECT *, long) string currentstr = btmp ? btmp : ""; fl_clear_browser(brow); + fl_hide_object(brow); - string refs = current_view->buffer()->getReferenceList('\n'); - int topline = 1; + vector refs = current_view->buffer()->getLabelList(); + if (fl_get_button(fd_form_ref->sort)) + sort(refs.begin(),refs.end()); + for (vector::const_iterator it = refs.begin(); + it != refs.end(); ++it) + fl_add_browser_line(brow, (*it).c_str()); - fl_addto_browser_chars(brow, refs.c_str()); + int topline = 1; int total_lines = fl_get_browser_maxline(brow); for (int i = 1; i <= total_lines ; ++i) { if (fl_get_browser_line(brow, i) == currentstr) { @@ -3592,27 +3269,68 @@ extern "C" void RefUpdateCB(FL_OBJECT *, long) } fl_set_browser_topline(brow, topline); - if (!fl_get_browser_maxline(brow)) { + bool empty = refs.empty(); + bool sgml = current_view->buffer()->isSGML(); + bool readonly = current_view->buffer()->isReadonly(); + + if (current_view->NoSavedPositions()) { + fl_deactivate_object(fd_form_ref->back); + fl_set_object_lcol(fd_form_ref->back, FL_INACTIVE); + } else { + fl_activate_object(fd_form_ref->back); + fl_set_object_lcol(fd_form_ref->back, FL_BLACK); + } + + if (empty) { fl_add_browser_line(brow, _("*** No labels found in document ***")); fl_deactivate_object(brow); + fl_deactivate_object(fd_form_ref->gotoref); + fl_set_object_lcol(fd_form_ref->gotoref, FL_INACTIVE); } else { fl_select_browser_line(brow, topline); fl_activate_object(brow); + fl_activate_object(fd_form_ref->gotoref); + fl_set_object_lcol(fd_form_ref->gotoref, FL_BLACK); } - 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 (empty || readonly) { + fl_deactivate_object(fd_form_ref->ref); + fl_set_object_lcol(fd_form_ref->ref, FL_INACTIVE); + fl_deactivate_object(fd_form_ref->pageref); + fl_set_object_lcol(fd_form_ref->pageref, FL_INACTIVE); + } else { + fl_activate_object(fd_form_ref->ref); + fl_set_object_lcol(fd_form_ref->ref, FL_BLACK); + fl_activate_object(fd_form_ref->pageref); + fl_set_object_lcol(fd_form_ref->pageref, FL_BLACK); } - if (!current_view->buffer()->isSGML()) { - fl_deactivate_object(fd_form_ref->ref_name); - fl_set_object_lcol(fd_form_ref->ref_name, FL_INACTIVE); + + if (empty || readonly || sgml) { + fl_deactivate_object(fd_form_ref->vref); + fl_set_object_lcol(fd_form_ref->vref, FL_INACTIVE); + fl_deactivate_object(fd_form_ref->vpageref); + fl_set_object_lcol(fd_form_ref->vpageref, FL_INACTIVE); + fl_deactivate_object(fd_form_ref->prettyref); + fl_set_object_lcol(fd_form_ref->prettyref, FL_INACTIVE); + } else { + fl_activate_object(fd_form_ref->vref); + fl_set_object_lcol(fd_form_ref->vref, FL_BLACK); + fl_activate_object(fd_form_ref->vpageref); + fl_set_object_lcol(fd_form_ref->vpageref, FL_BLACK); + fl_activate_object(fd_form_ref->prettyref); + fl_set_object_lcol(fd_form_ref->prettyref, FL_BLACK); } - else { + + if (sgml) { fl_activate_object(fd_form_ref->ref_name); fl_set_object_lcol(fd_form_ref->ref_name, FL_BLACK); + } else { + fl_deactivate_object(fd_form_ref->ref_name); + fl_set_object_lcol(fd_form_ref->ref_name, FL_INACTIVE); } + + fl_show_object(brow); }