- string paper;
-
- char real_papersize = buffer->params.papersize;
- if (real_papersize == BufferParams::PAPER_DEFAULT)
- real_papersize = lyxrc->default_papersize;
-
- switch (real_papersize) {
- case BufferParams::PAPER_USLETTER:
- paper = "us";
- break;
- case BufferParams::PAPER_A3PAPER:
- paper = "a3";
- break;
- case BufferParams::PAPER_A4PAPER:
- paper = "a4";
- break;
- case BufferParams::PAPER_A5PAPER:
- paper = "a5";
- break;
- case BufferParams::PAPER_B5PAPER:
- paper = "b5";
- break;
- case BufferParams::PAPER_EXECUTIVEPAPER:
- paper = "foolscap";
- break;
- case BufferParams::PAPER_LEGALPAPER:
- paper = "legal";
- break;
- default: /* If nothing else fits, keep the empty value */
- break;
- }
-
- if (paper.empty()) {
- if (buffer->params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
- // we HAVE to give a size when the page is in
- // landscape, so use USletter.
- paper = " -paper usr";
- } else {
- paper = " -paper " + paper;
- if (buffer->params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
- paper+= 'r';
- }
-
- // push directorypath, if necessary
- string path = OnlyPath(buffer->fileName());
- if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)){
- path = buffer->tmppath;
- }
- Path p(path);
- // Run dvi-viewer
- string command = lyxrc->view_dvi_command + paper ;
- bool ret = RunScript(buffer, false, command);
- return ret;
-}
-
-
-void MenuMakeLaTeX(Buffer * buffer)
-{
- if (!current_view->text)
- return;
-
- // Get LaTeX-Filename
- string s = buffer->getLatexName(false);
-
- FileInfo fi(s);
- if (fi.readable() &&
- !AskQuestion(_("File already exists:"),
- MakeDisplayPath(s, 50),
- _("Do you want to overwrite the file?"))) {
- current_view->owner()->getMiniBuffer()->Set(_("Canceled"));
- return;
- }
-
- if (buffer->isDocBook())
- current_view->owner()->getMiniBuffer()->Set(
- _("DocBook does not have a latex backend"));
- else {
- if (buffer->isLinuxDoc())
- RunLinuxDoc(0, buffer->fileName());
- else
- buffer->makeLaTeXFile(s, string(), true);
- current_view->owner()->getMiniBuffer()->Set(
- _("Nice LaTeX file saved as"), MakeDisplayPath(s));
- buffer->markDviDirty();
- }
-}
-
-
-void MenuMakeLinuxDoc(Buffer * buffer)
-{
- if (!current_view->text) return;
-
- if (!buffer->isLinuxDoc()) {
- WriteAlert(_("Error!"), _("Document class must be linuxdoc."));
- return;
- }
-
- // Get LinuxDoc-Filename
- string s = ChangeExtension (buffer->fileName(),
- ".sgml", false);
-
- FileInfo fi(s);
- if (fi.readable() &&
- !AskQuestion(_("File already exists:"),
- MakeDisplayPath(s, 50),
- _("Do you want to overwrite the file?"))) {
- current_view->owner()->getMiniBuffer()->Set(_("Canceled"));
- return;
- }
-
- current_view->owner()->getMiniBuffer()->Set(
- _("Building LinuxDoc SGML file `"), MakeDisplayPath(s),"'...");
-
- buffer->makeLinuxDocFile(s, 65);
- buffer->redraw();
- current_view->owner()->getMiniBuffer()->Set(
- _("LinuxDoc SGML file save as"), MakeDisplayPath(s));
-}
-
-
-void MenuMakeDocBook(Buffer * buffer)
-{
- if (!current_view->text) return;
-
- if (!buffer->isDocBook()) {
- WriteAlert(_("Error!"),
- _("Document class must be docbook."));
- return;
- }
-
- // Get DocBook-Filename
- string s = ChangeExtension (buffer->fileName(),
- ".sgml", false);
-
- FileInfo fi(s);
- if (fi.readable() &&
- !AskQuestion(_("File already exists:"),
- MakeDisplayPath(s, 50),
- _("Do you want to overwrite the file?"))) {
- current_view->owner()->getMiniBuffer()->Set(_("Canceled"));
- return;
- }
-
- current_view->owner()->getMiniBuffer()->Set(_("Building DocBook SGML file `"),
- MakeDisplayPath(s), "'...");
-
- buffer->makeDocBookFile(s, 65);
- buffer->redraw();
- current_view->owner()->getMiniBuffer()->Set(_("DocBook SGML file save as"),
- MakeDisplayPath(s));
-}
-
-
-void MenuMakeAscii(Buffer * buffer)
-{
- if (!current_view->text) return;
-
- /* get LaTeX-Filename */
- string s = ChangeExtension (buffer->fileName(),
- ".txt", false);
-
- FileInfo fi(s);
- if (fi.readable() &&
- !AskQuestion(_("File already exists:"),
- MakeDisplayPath(s, 50),
- _("Do you want to overwrite the file?"))) {
- current_view->owner()->getMiniBuffer()->Set(_("Canceled"));
- return;
- }
-
- buffer->writeFileAscii(s, lyxrc->ascii_linelen);
-
- current_view->owner()->getMiniBuffer()->Set(_("Ascii file saved as"), MakeDisplayPath(s));
-}
-
-
-void MenuPrint(Buffer * buffer)
-{
- if (!current_view->text)
- return;
-
- string input_file = ChangeExtension(buffer->fileName(),
- lyxrc->print_file_extension,
- true);
- fl_set_input(fd_form_print->input_file, input_file.c_str());
-
- if (fd_form_print->form_print->visible) {
- fl_raise_form(fd_form_print->form_print);
- }
- else {
- fl_show_form(fd_form_print->form_print,
- FL_PLACE_MOUSE, FL_FULLBORDER,
- _("Print"));
- }
-}
-
-void MenuMakeHTML(Buffer * buffer)
-{
- // First, create LaTeX file
- MenuMakeLaTeX(buffer);
-
- // And now, run the converter
- string file = buffer->fileName();
- Path path(OnlyPath(file));
- // 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 infile = buffer->getLatexName(false);
- string tmp = lyxrc->html_command;
- tmp = subst(tmp, "$$FName", infile);
- tmp = subst(tmp, "$$OutName", result);
- Systemcalls one;
- int res = one.startscript(Systemcalls::System, tmp);
- if (res == 0) {
- current_view->owner()->getMiniBuffer()->Set(_("Document exported as HTML to file `")
- + MakeDisplayPath(result) +'\'');
- } else {
- current_view->owner()->getMiniBuffer()->Set(_("Unable to convert to HTML the file `")
- + MakeDisplayPath(infile)
- + '\'');
- }
-
-}
-
-void MenuExport(Buffer * buffer, string const & extyp)
-{
- // latex
- if (extyp == "latex") {
- // make sure that this buffer is not linuxdoc
- MenuMakeLaTeX(buffer);
- }
- // linuxdoc
- else if (extyp == "linuxdoc") {
- // make sure that this buffer is not latex
- MenuMakeLinuxDoc(buffer);
- }
- // docbook
- else if (extyp == "docbook") {
- // make sure that this buffer is not latex or linuxdoc
- MenuMakeDocBook(buffer);
- }
- // dvi
- else if (extyp == "dvi") {
- // Run LaTeX as "Update dvi..." Bernhard.
- // We want the dvi in the current directory. This
- // is achieved by temporarily disabling use of
- // temp directory. As a side-effect, we get
- // *.log and *.aux files also. (Asger)
- bool flag = lyxrc->use_tempdir;
- lyxrc->use_tempdir = false;
- MenuRunLaTeX(buffer);
- lyxrc->use_tempdir = flag;
- }
- // postscript
- else if (extyp == "postscript") {
- // Start Print-dialog. Not as good as dvi... Bernhard.
- MenuPrint(buffer);
- // Since the MenuPrint is a pop-up, we can't use
- // the same trick as above. (Asger)
- // MISSING: Move of ps-file :-(
- }
- // ascii
- else if (extyp == "ascii") {
- MenuMakeAscii(buffer);
- }
- else if (extyp == "custom") {
- MenuSendto();
- }
- // HTML
- else if (extyp == "html") {
- MenuMakeHTML(buffer);
- }
- else {
- current_view->owner()->getMiniBuffer()->Set(_("Unknown export type: ")+ extyp);
- }
-}
-
-
-void QuitLyX()
-{
- lyxerr.debug() << "Running QuitLyX." << endl;
-
- if (!bufferlist.QwriteAll())
- return;
-
- lastfiles->writeFile(lyxrc->lastfiles);
-
- // Set a flag that we do quitting from the program,
- // so no refreshes are necessary.
- quitting = true;
-
- // close buffers first
- bufferlist.closeAll();
-
- // do any other cleanup procedures now
- lyxerr.debug() << "Deleting tmp dir " << system_tempdir << endl;
-
- DestroyLyXTmpDir(system_tempdir);
-
- finished = true;
-}
-
-
-
-void AutoSave()
- // should probably be moved into BufferList (Lgb)
- // Perfect target for a thread...
-{
- if (!current_view->getScreen() || !current_view->available())
- return;
-
- if (current_view->buffer()->isBakClean()
- || current_view->buffer()->isReadonly()) {
- // We don't save now, but we'll try again later
- current_view->owner()->resetAutosaveTimer();
- return;
- }
-
- current_view->owner()->getMiniBuffer()->Set(_("Autosaving current document..."));
-
- // create autosave filename
- string fname = OnlyPath(current_view->buffer()->fileName());
- fname += "#";
- fname += OnlyFilename(current_view->buffer()->fileName());
- fname += "#";
-
- // tmp_ret will be located (usually) in /tmp
- // will that be a problem?
- string tmp_ret = tmpnam(0);
-
- pid_t pid = fork(); // If you want to debug the autosave
- // you should set pid to -1, and comment out the
- // fork.
- if (pid == 0 || pid == -1) {
- // pid = -1 signifies that lyx was unable
- // to fork. But we will do the save
- // anyway.
- bool failed = false;
- if (!tmp_ret.empty()) {
- current_view->buffer()->writeFile(tmp_ret, 1);
- // assume successful write of tmp_ret
- if (rename(tmp_ret.c_str(), fname.c_str()) == -1) {
- failed = true;
- // most likely couldn't move between filesystems
- // unless write of tmp_ret failed
- // so remove tmp file (if it exists)
- remove(tmp_ret.c_str());
- }
- } else {
- failed = true;
- }
-
- if (failed) {
- // failed to write/rename tmp_ret so try writing direct
- if (!current_view->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!"));
- }
- }
- if (pid == 0) { // we are the child so...
- _exit(0);
- }
- }
-
- current_view->buffer()->markBakClean();
- current_view->owner()->resetAutosaveTimer();
-}
-
-
-//
-// (c) CHT Software Service GmbH
-// Uwe C. Schroeder
-//
-// create new file with template
-// SERVERCMD !
-//
-Buffer * NewLyxFile(string const & filename)
-{
- // Split argument by :
- string name;
- string tmpname = split(filename, name, ':');
-#ifdef __EMX__ // Fix me! lyx_cb.C may not be low level enough to allow this.
- if (name.length() == 1
- && isalpha(static_cast<unsigned char>(name[0]))
- && (prefixIs(tmpname, "/") || prefixIs(tmpname, "\\"))) {
- name += ':';
- name += token(tmpname, ':', 0);
- tmpname = split(tmpname, ':');
- }
-#endif
- lyxerr.debug() << "Arg is " << filename
- << "\nName is " << name
- << "\nTemplate is " << tmpname << endl;
-
- // find a free buffer
- Buffer * tmpbuf = bufferlist.newFile(name, tmpname);
- if (tmpbuf)
- lastfiles->newFile(tmpbuf->fileName());
- return tmpbuf;
-}
-
-
-// Insert ascii file (if filename is empty, prompt for one)
-void InsertAsciiFile(string const & f, bool asParagraph)
-{
- string fname = f;
- LyXFileDlg fileDlg;
-
- if (!current_view->getScreen()) return;
-
- if (fname.empty()) {
- ProhibitInput();
- fname = fileDlg.Select(_("File to Insert"),
- current_view->owner()->buffer()->filepath,
- "*");
- AllowInput();
- if (fname.empty()) return;
- }
-
- FileInfo fi(fname);
-
- if (!fi.readable()) {
- WriteFSAlert(_("Error! Specified file is unreadable: "),
- MakeDisplayPath(fname, 50));
- return;
- }
-
- FilePtr myfile(fname, FilePtr::read);
- if (!myfile()) {
- WriteFSAlert(_("Error! Cannot open specified file: "),
- MakeDisplayPath(fname, 50));
- return;
- }
- LyXParagraph * tmppar = new LyXParagraph;
- tmppar->readSimpleWholeFile(myfile);
-
- // set the end of the string
-#ifdef WITH_WARNINGS
-#warning why do we do this?
-#endif
- // I don't think this is needed. Actually it might be plain wrong.
- tmppar->InsertChar(tmppar->text.size() - 1, '\0');
-
- // insert the string
- current_view->getScreen()->HideCursor();
-
- // clear the selection
- BeforeChange();
- if (!asParagraph)
- current_view->text->InsertStringA(tmppar->text);
- else
- current_view->text->InsertStringB(tmppar->text);
- delete tmppar;
- current_view->update(1);
-}
-
-
-void MenuShowTableOfContents()
-{
- static int ow = -1, oh;
-
- TocUpdateCB(0, 0);
- if (fd_form_toc->form_toc->visible) {
- fl_raise_form(fd_form_toc->form_toc);
- } else {
- fl_show_form(fd_form_toc->form_toc,
- FL_PLACE_MOUSE | FL_FREE_SIZE, FL_FULLBORDER,
- _("Table Of Contents"));
- if (ow < 0) {
- ow = fd_form_toc->form_toc->w;
- oh = fd_form_toc->form_toc->h;
- }
- fl_set_form_minsize(fd_form_toc->form_toc, ow, oh);
- }
-}
-
-
-void MenuInsertLabel(char const * arg)
-{
- string label = arg;
- ProhibitInput();
- if (label.empty()) {
- pair<bool, string>
- result = askForText(_("Enter new label to insert:"));
- if (result.first) {
- label = frontStrip(strip(result.second));
- }
- }
- if (!label.empty()) {
- InsetLabel * new_inset = new InsetLabel;
- new_inset->setContents(label);
- current_view->buffer()->insertInset(new_inset);
- }
- AllowInput();
-}
-
-
-void MenuInsertRef()
-{
- static int ow = -1, oh;
-
- RefUpdateCB(0, 0);
- if (fd_form_ref->form_ref->visible) {
- fl_raise_form(fd_form_ref->form_ref);
- } else {
- fl_show_form(fd_form_ref->form_ref,
- FL_PLACE_MOUSE | FL_FREE_SIZE, FL_FULLBORDER,
- _("Insert Reference"));
- if (ow < 0) {
- ow = fd_form_ref->form_ref->w;
- oh = fd_form_ref->form_ref->h;
- }
- fl_set_form_minsize(fd_form_ref->form_ref, ow, oh);
- }
-}
-
-
-void MenuPasteSelection(char at)
-{
- if (!current_view->getScreen())
- return;
-
- ascii_type = at;
-
- Atom data_prop = XInternAtom(fl_display,
- "LyX_Primary",
- false);
- if (data_prop == None)
- return;
- XConvertSelection(fl_display,
- XA_PRIMARY, XA_STRING, data_prop,
- current_view->owner()->getForm()->window, 0);
- XFlush(fl_display);
-}
-
-
-// candidate for move to BufferView
-extern "C" void FootCB(FL_OBJECT *, long)
-{
- if (!current_view->available())
- return;
-
- current_view->owner()->getMiniBuffer()->Set(_("Inserting Footnote..."));
- current_view->getScreen()->HideCursor();
- current_view->update(-2);
- current_view->text->InsertFootnoteEnvironment(LyXParagraph::FOOTNOTE);
- current_view->update(1);
-}
-
-
-// candidate for move to LyXView
-void LayoutsCB(int sel, void *)
-{
- string tmp = tostr(sel);
- current_view->owner()->getLyXFunc()->Dispatch(LFUN_LAYOUTNO,
- tmp.c_str());
-}
-
-
-/*
- * SGML Linuxdoc support:
- * (flag == -1) import SGML file
- * (flag == 0) make TeX output
- * (flag == 1) make dvi output
- */
-int RunLinuxDoc(int flag, string const & filename)
-{
- string name;
- string s2;
- string path;
- string add_flags;
-
- int errorcode = 0;
-
- /* generate a path-less extension name */
- name = ChangeExtension (filename, ".sgml", true);
- path = OnlyPath (filename);
- if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)) {
- path = current_view->buffer()->tmppath;
- }
- Path p(path);
-
- if (flag != -1) {
- if (!current_view->available())
- return 0;
- current_view->buffer()->makeLinuxDocFile(name, 0);
-#ifdef WITH_WARNINGS
-#warning remove this once we have a proper geometry class
-#endif
- BufferParams::PAPER_SIZE ps = static_cast<BufferParams::PAPER_SIZE>(current_view->buffer()->params.papersize);
- switch (ps) {
- case BufferParams::PAPER_A4PAPER:
- add_flags = "-p a4";
- break;
- case BufferParams::PAPER_USLETTER:
- add_flags = "-p letter";
- break;
- default: /* nothing to be done yet ;-) */ break;
- }
- }
-
- ProhibitInput();
-
- Systemcalls one;
- switch (flag) {
- case -1: /* Import file */
- current_view->owner()->getMiniBuffer()->Set(_("Importing LinuxDoc SGML file `"),
- MakeDisplayPath(filename), "'...");
- s2 = "sgml2lyx " + lyxrc->sgml_extra_options + ' '
- + name;
- if (one.startscript(Systemcalls::System, s2))
- errorcode = 1;
- break;
- case 0: /* TeX output asked */
- current_view->owner()->getMiniBuffer()->Set(_("Converting LinuxDoc SGML to TeX file..."));
- s2 = "sgml2latex " + add_flags + " -o tex "
- + lyxrc->sgml_extra_options + ' ' + name;
- if (one.startscript(Systemcalls::System, s2))
- errorcode = 1;
- break;
- case 1: /* dvi output asked */
- current_view->owner()->getMiniBuffer()->Set(_("Converting LinuxDoc SGML to dvi file..."));
- s2 = "sgml2latex " + add_flags + " -o dvi "
- + lyxrc->sgml_extra_options + ' ' + name;
- if (one.startscript(Systemcalls::System, s2)) {
- errorcode = 1;
- } else
- current_view->buffer()->markDviClean();
- break;
- default: /* unknown output */
- break;
- }
-
- AllowInput();
-
- current_view->buffer()->redraw();
- return errorcode;
-}
-
-
-/*
- * SGML DocBook support:
- * (flag == 1) make dvi output
- */
-int RunDocBook(int flag, string const & filename)
-{
- /* generate a path-less extension name */
- string name = ChangeExtension (filename, ".sgml", true);
- string path = OnlyPath (filename);
- if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)) {
- path = current_view->buffer()->tmppath;
- }
- Path p(path);
-
- if (!current_view->available())
- return 0;
-
- current_view->buffer()->makeDocBookFile(name, 0);
-
- // Shall this code go or should it stay? (Lgb)
-// string add_flags;
-// LYX_PAPER_SIZE ps = (LYX_PAPER_SIZE) current_view->buffer()->params.papersize;
-// switch (ps) {
-// case BufferParams::PAPER_A4PAPER: add_flags = "-p a4"; break;
-// case BufferParams::PAPER_USLETTER: add_flags = "-p letter"; break;
-// default: /* nothing to be done yet ;-) */ break;
-// }
- ProhibitInput();
-
- int errorcode = 0;
- Systemcalls one;
- switch (flag) {
- case 1: /* dvi output asked */
- {
- current_view->owner()->getMiniBuffer()->Set(_("Converting DocBook SGML to dvi file..."));
- string s2 = "sgmltools --backend dvi " + name;
- if (one.startscript(Systemcalls::System, s2)) {
- errorcode = 1;
- } else
- current_view->buffer()->markDviClean();
- }
- break;
- default: /* unknown output */
- break;
- }
-
- AllowInput();
-
- current_view->buffer()->redraw();
- return errorcode;
-}
-
-
-// candidate for move to BufferView
-void AllFloats(char flag, char figmar)
-{
- if (!current_view->available())
- return;
-
- LyXCursor cursor = current_view->text->cursor;
-
- if (!flag && cursor.par->footnoteflag != LyXParagraph::NO_FOOTNOTE
- && ((figmar
- && cursor.par->footnotekind != LyXParagraph::FOOTNOTE
- && cursor.par->footnotekind != LyXParagraph::MARGIN)
- || (!figmar
- && cursor.par->footnotekind != LyXParagraph::FIG
- && cursor.par->footnotekind != LyXParagraph::TAB
- && cursor.par->footnotekind != LyXParagraph::WIDE_FIG
- && cursor.par->footnotekind != LyXParagraph::WIDE_TAB
- && cursor.par->footnotekind != LyXParagraph::ALGORITHM)))
- ToggleFloat();
- else
- BeforeChange();
-
- LyXCursor tmpcursor = cursor;
- cursor.par = tmpcursor.par->ParFromPos(tmpcursor.pos);
- cursor.pos = tmpcursor.par->PositionInParFromPos(tmpcursor.pos);
-
- LyXParagraph *par = current_view->buffer()->paragraph;
- while (par) {
- if (flag) {
- if (par->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE
- && ((figmar
- && par->footnotekind != LyXParagraph::FOOTNOTE
- && par->footnotekind != LyXParagraph::MARGIN)
- || (!figmar
- && par->footnotekind != LyXParagraph::FIG
- && par->footnotekind != LyXParagraph::TAB
- && par->footnotekind != LyXParagraph::WIDE_FIG
- && par->footnotekind != LyXParagraph::WIDE_TAB
- && par->footnotekind != LyXParagraph::ALGORITHM
- )
- )
- ) {
- if (par->previous
- && par->previous->footnoteflag !=
- LyXParagraph::CLOSED_FOOTNOTE){ /* should be */
- current_view->text
- ->SetCursorIntern(par
- ->previous,
- 0);
- current_view->text->OpenFootnote();
- }
- }
- }
- else {
- if (par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE
- && (
- (figmar
- &&
- par->footnotekind != LyXParagraph::FOOTNOTE
- &&
- par->footnotekind != LyXParagraph::MARGIN
- )
- ||
- (!figmar
- &&
- par->footnotekind != LyXParagraph::FIG
- &&
- par->footnotekind != LyXParagraph::TAB
- &&
- par->footnotekind != LyXParagraph::WIDE_FIG
- &&
- par->footnotekind != LyXParagraph::WIDE_TAB
- &&
- par->footnotekind != LyXParagraph::ALGORITHM
- )
- )
- ) {
- current_view->text->SetCursorIntern(par, 0);
- current_view->text->CloseFootnote();
- }
- }
- par = par->next;
- }
-
- current_view->text->SetCursorIntern(cursor.par, cursor.pos);
- current_view->redraw();
- current_view->fitCursor();
- current_view->updateScrollbar();
-}
-
-
-void MenuLayoutCharacter()
-{
- static int ow = -1, oh;
-
- if (fd_form_character->form_character->visible) {
- fl_raise_form(fd_form_character->form_character);
- } else {
- fl_show_form(fd_form_character->form_character,
- FL_PLACE_MOUSE | FL_FREE_SIZE, FL_FULLBORDER,
- _("Character Style"));
- if (ow < 0) {
- ow = fd_form_character->form_character->w;
- oh = fd_form_character->form_character->h;
- }
- fl_set_form_minsize(fd_form_character->form_character, ow, oh);
- }
-}
-
-
-inline void DeactivateParagraphButtons ()
-{
- fl_deactivate_object (fd_form_paragraph->button_ok);
- fl_deactivate_object (fd_form_paragraph->button_apply);
- fl_set_object_lcol (fd_form_paragraph->button_ok, FL_INACTIVE);
- fl_set_object_lcol (fd_form_paragraph->button_apply, FL_INACTIVE);
-}
-
-
-inline void ActivateParagraphButtons ()
-{
- fl_activate_object (fd_form_paragraph->button_ok);
- fl_activate_object (fd_form_paragraph->button_apply);
- fl_set_object_lcol (fd_form_paragraph->button_ok, FL_BLACK);
- fl_set_object_lcol (fd_form_paragraph->button_apply, FL_BLACK);
-}
-
-
-inline void DisableParagraphLayout ()
-{
- DeactivateParagraphButtons();
- fl_deactivate_object (fd_form_paragraph->input_labelwidth);
- fl_deactivate_object (fd_form_paragraph->check_lines_top);
- fl_deactivate_object (fd_form_paragraph->check_lines_bottom);
- fl_deactivate_object (fd_form_paragraph->check_pagebreaks_top);
- fl_deactivate_object (fd_form_paragraph->check_pagebreaks_bottom);
- fl_deactivate_object (fd_form_paragraph->check_noindent);
- fl_deactivate_object (fd_form_paragraph->group_radio_alignment);
- fl_deactivate_object (fd_form_paragraph->radio_align_right);
- fl_deactivate_object (fd_form_paragraph->radio_align_left);
- fl_deactivate_object (fd_form_paragraph->radio_align_block);
- fl_deactivate_object (fd_form_paragraph->radio_align_center);
- fl_deactivate_object (fd_form_paragraph->input_space_above);
- fl_deactivate_object (fd_form_paragraph->input_space_below);
- fl_deactivate_object (fd_form_paragraph->choice_space_above);
- fl_deactivate_object (fd_form_paragraph->choice_space_below);
- fl_deactivate_object (fd_form_paragraph->check_space_above);
- fl_deactivate_object (fd_form_paragraph->check_space_below);
-}
-
-
-inline void EnableParagraphLayout ()
-{
- ActivateParagraphButtons();
- fl_activate_object (fd_form_paragraph->input_labelwidth);
- fl_activate_object (fd_form_paragraph->check_lines_top);
- fl_activate_object (fd_form_paragraph->check_lines_bottom);
- fl_activate_object (fd_form_paragraph->check_pagebreaks_top);
- fl_activate_object (fd_form_paragraph->check_pagebreaks_bottom);
- fl_activate_object (fd_form_paragraph->check_noindent);
- fl_activate_object (fd_form_paragraph->group_radio_alignment);
- fl_activate_object (fd_form_paragraph->radio_align_right);
- fl_activate_object (fd_form_paragraph->radio_align_left);
- fl_activate_object (fd_form_paragraph->radio_align_block);
- fl_activate_object (fd_form_paragraph->radio_align_center);
- fl_activate_object (fd_form_paragraph->input_space_above);
- fl_activate_object (fd_form_paragraph->input_space_below);
- fl_activate_object (fd_form_paragraph->choice_space_above);
- fl_activate_object (fd_form_paragraph->choice_space_below);
- fl_activate_object (fd_form_paragraph->check_space_above);
- fl_activate_object (fd_form_paragraph->check_space_below);
-}
-
-
-bool UpdateLayoutParagraph()
-{
- if (!current_view->getScreen() || !current_view->available()) {
- if (fd_form_paragraph->form_paragraph->visible)
- fl_hide_form(fd_form_paragraph->form_paragraph);
- return false;
- }
-
- Buffer * buf = current_view->buffer();
-
- fl_set_input(fd_form_paragraph->input_labelwidth,
- current_view->text->cursor.par->GetLabelWidthString().c_str());
- fl_set_button(fd_form_paragraph->radio_align_right, 0);
- fl_set_button(fd_form_paragraph->radio_align_left, 0);
- fl_set_button(fd_form_paragraph->radio_align_center, 0);
- fl_set_button(fd_form_paragraph->radio_align_block, 0);
-
- int align = current_view->text->cursor.par->GetAlign();
- if (align == LYX_ALIGN_LAYOUT)
- align = textclasslist.Style(buf->params.textclass,
- current_view->text->cursor.par->GetLayout()).align;
-
- switch (align) {
- case LYX_ALIGN_RIGHT:
- fl_set_button(fd_form_paragraph->radio_align_right, 1);
- break;
- case LYX_ALIGN_LEFT:
- fl_set_button(fd_form_paragraph->radio_align_left, 1);
- break;
- case LYX_ALIGN_CENTER:
- fl_set_button(fd_form_paragraph->radio_align_center, 1);
- break;
- default:
- fl_set_button(fd_form_paragraph->radio_align_block, 1);
- break;
- }
-
- fl_set_button(fd_form_paragraph->check_lines_top,
- current_view->text->cursor.par->FirstPhysicalPar()->line_top);
- fl_set_button(fd_form_paragraph->check_lines_bottom,
- current_view->text->cursor.par->FirstPhysicalPar()->line_bottom);
- fl_set_button(fd_form_paragraph->check_pagebreaks_top,
- current_view->text->cursor.par->FirstPhysicalPar()->pagebreak_top);
- fl_set_button(fd_form_paragraph->check_pagebreaks_bottom,
- current_view->text->cursor.par->FirstPhysicalPar()->pagebreak_bottom);
- fl_set_button(fd_form_paragraph->check_noindent,
- current_view->text->cursor.par->FirstPhysicalPar()->noindent);
- fl_set_input (fd_form_paragraph->input_space_above, "");
-
- switch (current_view->text->cursor.par->FirstPhysicalPar()->added_space_top.kind()) {
- case VSpace::NONE:
- fl_set_choice (fd_form_paragraph->choice_space_above, 1);
- break;
- case VSpace::DEFSKIP:
- fl_set_choice (fd_form_paragraph->choice_space_above, 2);
- break;
- case VSpace::SMALLSKIP:
- fl_set_choice (fd_form_paragraph->choice_space_above, 3);
- break;
- case VSpace::MEDSKIP:
- fl_set_choice (fd_form_paragraph->choice_space_above, 4);
- break;
- case VSpace::BIGSKIP:
- fl_set_choice (fd_form_paragraph->choice_space_above, 5);
- break;
- case VSpace::VFILL:
- fl_set_choice (fd_form_paragraph->choice_space_above, 6);
- break;
- case VSpace::LENGTH:
- fl_set_choice (fd_form_paragraph->choice_space_above, 7);
- fl_set_input (fd_form_paragraph->input_space_above,
- current_view->text->cursor.par->FirstPhysicalPar()->added_space_top.length().asString().c_str());
- break;
- }
- fl_set_button (fd_form_paragraph->check_space_above,
- current_view->text->cursor.par->FirstPhysicalPar()->added_space_top.keep());
- fl_set_input (fd_form_paragraph->input_space_below, "");
- switch (current_view->text->cursor.par->FirstPhysicalPar()->added_space_bottom.kind()) {
- case VSpace::NONE:
- fl_set_choice (fd_form_paragraph->choice_space_below,
- 1);
- break;
- case VSpace::DEFSKIP:
- fl_set_choice (fd_form_paragraph->choice_space_below,
- 2);
- break;
- case VSpace::SMALLSKIP:
- fl_set_choice (fd_form_paragraph->choice_space_below,
- 3);
- break;
- case VSpace::MEDSKIP:
- fl_set_choice (fd_form_paragraph->choice_space_below,
- 4);
- break;
- case VSpace::BIGSKIP:
- fl_set_choice (fd_form_paragraph->choice_space_below,
- 5);
- break;
- case VSpace::VFILL:
- fl_set_choice (fd_form_paragraph->choice_space_below,
- 6);
- break;
- case VSpace::LENGTH:
- fl_set_choice (fd_form_paragraph->choice_space_below,
- 7);
- fl_set_input (fd_form_paragraph->input_space_below,
- current_view->text->cursor.par->FirstPhysicalPar()->added_space_bottom.length().asString().c_str());
- break;
- }
- fl_set_button (fd_form_paragraph->check_space_below,
- current_view->text->cursor.par->FirstPhysicalPar()->added_space_bottom.keep());
-
- fl_set_button(fd_form_paragraph->check_noindent,
- current_view->text->cursor.par->FirstPhysicalPar()->noindent);
-
- if (current_view->buffer()->isReadonly()) {
- DisableParagraphLayout();
- } else {
- EnableParagraphLayout();
- }
- return true;
-}
-
-
-void MenuLayoutParagraph()
-{
- if (UpdateLayoutParagraph()) {
- if (fd_form_paragraph->form_paragraph->visible) {
- fl_raise_form(fd_form_paragraph->form_paragraph);
- } else {
- fl_show_form(fd_form_paragraph->form_paragraph,
- FL_PLACE_MOUSE, FL_FULLBORDER,
- _("Paragraph Environment"));
- }
- }
-}
-
-
-inline
-void DeactivateDocumentButtons ()
-{
- fl_deactivate_object (fd_form_document->button_ok);
- fl_deactivate_object (fd_form_document->button_apply);
- fl_set_object_lcol (fd_form_document->button_ok, FL_INACTIVE);
- fl_set_object_lcol (fd_form_document->button_apply, FL_INACTIVE);
-}
-
-
-inline
-void ActivateDocumentButtons ()
-{
- fl_activate_object (fd_form_document->button_ok);
- fl_activate_object (fd_form_document->button_apply);
- fl_set_object_lcol (fd_form_document->button_ok, FL_BLACK);
- fl_set_object_lcol (fd_form_document->button_apply, FL_BLACK);
-}
-
-
-inline
-void DisableDocumentLayout ()
-{
- DeactivateDocumentButtons ();
- fl_deactivate_object (fd_form_document->group_radio_separation);
- fl_deactivate_object (fd_form_document->radio_indent);
- fl_deactivate_object (fd_form_document->radio_skip);
- fl_deactivate_object (fd_form_document->choice_class);
- fl_deactivate_object (fd_form_document->choice_pagestyle);
- fl_deactivate_object (fd_form_document->choice_fonts);
- fl_deactivate_object (fd_form_document->choice_fontsize);
- fl_deactivate_object (fd_form_document->input_float_placement);
- fl_deactivate_object (fd_form_document->choice_postscript_driver);
- fl_deactivate_object (fd_form_document->choice_inputenc);
- fl_deactivate_object (fd_form_document->group_radio_sides);
- fl_deactivate_object (fd_form_document->radio_sides_one);
- fl_deactivate_object (fd_form_document->radio_sides_two);
- fl_deactivate_object (fd_form_document->group_radio_columns);
- fl_deactivate_object (fd_form_document->radio_columns_one);
- fl_deactivate_object (fd_form_document->radio_columns_two);
- fl_deactivate_object (fd_form_document->input_extra);
- fl_deactivate_object (fd_form_document->choice_language);
- combo_language->deactivate();
- fl_deactivate_object (fd_form_document->input_default_skip);
- fl_deactivate_object (fd_form_document->choice_default_skip);
- fl_deactivate_object (fd_form_document->slider_secnumdepth);
- fl_deactivate_object (fd_form_document->slider_tocdepth);
- fl_deactivate_object (fd_form_document->choice_spacing);
- fl_deactivate_object (fd_form_document->input_spacing);
- fl_deactivate_object (fd_form_document->check_use_amsmath);
-}
-
-
-inline
-void EnableDocumentLayout ()
-{
- ActivateDocumentButtons ();
- fl_activate_object (fd_form_document->group_radio_separation);
- fl_activate_object (fd_form_document->radio_indent);
- fl_activate_object (fd_form_document->radio_skip);
- fl_activate_object (fd_form_document->choice_class);
- fl_activate_object (fd_form_document->choice_pagestyle);
- fl_activate_object (fd_form_document->choice_fonts);
- fl_activate_object (fd_form_document->choice_fontsize);
- fl_activate_object (fd_form_document->input_float_placement);
- fl_activate_object (fd_form_document->choice_postscript_driver);
- fl_activate_object (fd_form_document->choice_inputenc);
- fl_activate_object (fd_form_document->group_radio_sides);
- fl_activate_object (fd_form_document->radio_sides_one);
- fl_activate_object (fd_form_document->radio_sides_two);
- fl_activate_object (fd_form_document->group_radio_columns);
- fl_activate_object (fd_form_document->radio_columns_one);
- fl_activate_object (fd_form_document->radio_columns_two);
- fl_activate_object (fd_form_document->input_extra);
- fl_activate_object (fd_form_document->choice_language);
- combo_language->activate();
- fl_activate_object (fd_form_document->input_default_skip);
- fl_activate_object (fd_form_document->choice_default_skip);
- fl_activate_object (fd_form_document->slider_secnumdepth);
- fl_activate_object (fd_form_document->slider_tocdepth);
- fl_activate_object (fd_form_document->choice_spacing);
- fl_activate_object (fd_form_document->input_spacing);
- fl_activate_object (fd_form_document->check_use_amsmath);
-}
-
-
-bool UpdateLayoutDocument(BufferParams * params)
-{
- if (!current_view->getScreen() || !current_view->available()) {
- if (fd_form_document->form_document->visible)
- fl_hide_form(fd_form_document->form_document);
- return false;
- }
-
- if (params == 0)
- params = ¤t_view->buffer()->params;
- LyXTextClass const & tclass = textclasslist.TextClass(params->textclass);
-
- fl_set_choice_text(fd_form_document->choice_class,
- textclasslist.DescOfClass(params->textclass).c_str());
- combo_language->select_text(params->language.c_str());
-
- fl_set_choice_text(fd_form_document->choice_fonts,
- params->fonts.c_str());
- fl_set_choice_text(fd_form_document->choice_inputenc,
- params->inputenc.c_str());
- fl_set_choice_text(fd_form_document->choice_postscript_driver,
- params->graphicsDriver.c_str());
-
- // ale970405+lasgoutt970513
- fl_clear_choice(fd_form_document->choice_fontsize);
- fl_addto_choice(fd_form_document->choice_fontsize, "default");
- fl_addto_choice(fd_form_document->choice_fontsize,
- tclass.opt_fontsize().c_str());
- fl_set_choice(fd_form_document->choice_fontsize,
- tokenPos(tclass.opt_fontsize(), '|', params->fontsize) + 2);
-
- // ale970405+lasgoutt970513
- fl_clear_choice(fd_form_document->choice_pagestyle);
- fl_addto_choice(fd_form_document->choice_pagestyle, "default");
- fl_addto_choice(fd_form_document->choice_pagestyle,
- tclass.opt_pagestyle().c_str());
-
- fl_set_choice(fd_form_document->choice_pagestyle,
- tokenPos(tclass.opt_pagestyle(), '|', params->pagestyle) + 2);
-
- fl_set_button(fd_form_document->radio_indent, 0);
- fl_set_button(fd_form_document->radio_skip, 0);
-
-
- fl_set_button(fd_form_document->check_use_amsmath, params->use_amsmath);
-
- if (params->paragraph_separation == BufferParams::PARSEP_INDENT)
- fl_set_button(fd_form_document->radio_indent, 1);
- else
- fl_set_button(fd_form_document->radio_skip, 1);
-
- switch (params->getDefSkip().kind()) {
- case VSpace::SMALLSKIP:
- fl_set_choice (fd_form_document->choice_default_skip, 1);
- break;
- case VSpace::MEDSKIP:
- fl_set_choice (fd_form_document->choice_default_skip, 2);
- break;
- case VSpace::BIGSKIP:
- fl_set_choice (fd_form_document->choice_default_skip, 3);
- break;
- case VSpace::LENGTH:
- fl_set_choice (fd_form_document->choice_default_skip, 4);
- fl_set_input (fd_form_document->input_default_skip,
- params->getDefSkip().asLyXCommand().c_str());
- break;
- default:
- fl_set_choice (fd_form_document->choice_default_skip, 2);
- break;
- }
-
- fl_set_button(fd_form_document->radio_sides_one, 0);
- fl_set_button(fd_form_document->radio_sides_two, 0);
-
- if (params->sides == 2)
- fl_set_button(fd_form_document->radio_sides_two, 1);
- else
- fl_set_button(fd_form_document->radio_sides_one, 1);
-
- fl_set_button(fd_form_document->radio_columns_one, 0);
- fl_set_button(fd_form_document->radio_columns_two, 0);
-
- if (params->columns == 2)
- fl_set_button(fd_form_document->radio_columns_two, 1);
- else
- fl_set_button(fd_form_document->radio_columns_one, 1);
-
- fl_set_input(fd_form_document->input_spacing, "");
- switch (params->spacing.getSpace()) {
- case Spacing::Single:
- {
- // \singlespacing
- fl_set_choice(fd_form_document->choice_spacing, 1);
- break;
- }
- case Spacing::Onehalf:
- {
- // \onehalfspacing
- fl_set_choice(fd_form_document->choice_spacing, 2);
- break;
- }
- case Spacing::Double:
- {
- // \ doublespacing
- fl_set_choice(fd_form_document->choice_spacing, 3);
- break;
- }
- case Spacing::Other:
- {
- fl_set_choice(fd_form_document->choice_spacing, 4);
- char sval[20];
- sprintf(sval, "%g", params->spacing.getValue());
- fl_set_input(fd_form_document->input_spacing, sval);
- break;
- }
- }
-
-
- fl_set_counter_value(fd_form_document->slider_secnumdepth,
- params->secnumdepth);
- fl_set_counter_value(fd_form_document->slider_tocdepth,
- params->tocdepth);
- if (!params->float_placement.empty()) { // buffer local (Lgb)
- fl_set_input(fd_form_document->input_float_placement,
- params->float_placement.c_str());
- } else {
- fl_set_input(fd_form_document->input_float_placement, "");
- }
- if (!params->options.empty())
- fl_set_input(fd_form_document->input_extra,
- params->options.c_str());
- else
- fl_set_input(fd_form_document->input_extra, "");
-
- if (current_view->buffer()->isSGML()) {
- // bullets not used in SGML derived documents
- fl_deactivate_object(fd_form_document->button_bullets);
- fl_set_object_lcol(fd_form_document->button_bullets,
- FL_INACTIVE);
- } else {
- fl_activate_object(fd_form_document->button_bullets);
- fl_set_object_lcol(fd_form_document->button_bullets,
- FL_BLACK);
- }
-
- if (current_view->buffer()->isReadonly()) {
- DisableDocumentLayout();
- } else {
- EnableDocumentLayout();
- }
-
- return true;
-}
-
-
-void MenuLayoutDocument()
-{
- if (UpdateLayoutDocument()) {
- if (fd_form_document->form_document->visible) {
- fl_raise_form(fd_form_document->form_document);
- } else {
- fl_show_form(fd_form_document->form_document,
- FL_PLACE_MOUSE, FL_FULLBORDER,
- _("Document Layout"));
- }
- }
-}
-
-
-bool UpdateLayoutQuotes()
-{
- bool update = true;
- if (!current_view->getScreen()
- || !current_view->available()
- || current_view->buffer()->isReadonly())
- update = false;
-
- if (update) {
- fl_set_choice(fd_form_quotes->choice_quotes_language,
- current_view->buffer()->params.quotes_language + 1);
- fl_set_button(fd_form_quotes->radio_single, 0);
- fl_set_button(fd_form_quotes->radio_double, 0);
-
- if (current_view->buffer()->params.quotes_times == InsetQuotes::SingleQ)
- fl_set_button(fd_form_quotes->radio_single, 1);
- else
- fl_set_button(fd_form_quotes->radio_double, 1);
- } else if (fd_form_quotes->form_quotes->visible) {
- fl_hide_form(fd_form_quotes->form_quotes);
- }
- return update;
-}
-
-
-void MenuLayoutQuotes()
-{
- if (UpdateLayoutQuotes()) {
- if (fd_form_quotes->form_quotes->visible) {
- fl_raise_form(fd_form_quotes->form_quotes);
- } else {
- fl_show_form(fd_form_quotes->form_quotes,
- FL_PLACE_MOUSE, FL_FULLBORDER,
- _("Quotes"));
- }
- }
-}
-
-
-bool UpdateLayoutPreamble()
-{
- bool update = true;
- if (!current_view->getScreen() || ! current_view->available())
- update = false;
-
- if (update) {
- fl_set_input(fd_form_preamble->input_preamble,
- current_view->buffer()->params.preamble.c_str());
-
- if (current_view->buffer()->isReadonly()) {
- fl_deactivate_object(fd_form_preamble->input_preamble);
- fl_deactivate_object(fd_form_preamble->button_ok);
- fl_deactivate_object(fd_form_preamble->button_apply);
- fl_set_object_lcol(fd_form_preamble->button_ok, FL_INACTIVE);
- fl_set_object_lcol(fd_form_preamble->button_apply, FL_INACTIVE);
- }
- else {
- fl_activate_object(fd_form_preamble->input_preamble);
- fl_activate_object(fd_form_preamble->button_ok);
- fl_activate_object(fd_form_preamble->button_apply);
- fl_set_object_lcol(fd_form_preamble->button_ok, FL_BLACK);
- fl_set_object_lcol(fd_form_preamble->button_apply, FL_BLACK);
- }
- } else if (fd_form_preamble->form_preamble->visible) {
- fl_hide_form(fd_form_preamble->form_preamble);
- }
- return update;
-}
-
-void MenuLayoutPreamble()
-{
- static int ow = -1, oh;
-
- if (UpdateLayoutPreamble()) {
- if (fd_form_preamble->form_preamble->visible) {
- fl_raise_form(fd_form_preamble->form_preamble);
- } else {
- fl_show_form(fd_form_preamble->form_preamble,
- FL_PLACE_MOUSE | FL_FREE_SIZE,
- FL_FULLBORDER,
- _("LaTeX Preamble"));
- if (ow < 0) {
- ow = fd_form_preamble->form_preamble->w;
- oh = fd_form_preamble->form_preamble->h;
- }
- fl_set_form_minsize(fd_form_preamble->form_preamble,
- ow, oh);
- }
- }
-}
-
-
-void MenuLayoutSave()
-{
- if (!current_view->getScreen() || ! current_view->available())
- return;
-
- if (AskQuestion(_("Do you want to save the current settings"),
- _("for Character, Document, Paper and Quotes"),
- _("as default for new documents?")))
- current_view->buffer()->saveParamsAsDefaults();
-}
-
-
-// candidate for move to BufferView
-void NoteCB()
-{
- InsetInfo * new_inset = new InsetInfo();
- current_view->buffer()->insertInset(new_inset);
- new_inset->Edit(0, 0);
-}
-
-
-// candidate for move to BufferView
-void OpenStuff()
-{
- if (current_view->available()) {
- current_view->owner()->getMiniBuffer()->Set(_("Open/Close..."));
- current_view->getScreen()->HideCursor();
- BeforeChange();
- current_view->update(-2);
- current_view->text->OpenStuff();
- current_view->update(0);
- }
-}
-
-
-// candidate for move to BufferView
-void ToggleFloat()
-{
- if (current_view->available()) {
- current_view->owner()->getMiniBuffer()->Set(_("Open/Close..."));
- current_view->getScreen()->HideCursor();
- BeforeChange();
- current_view->update(-2);
- current_view->text->ToggleFootnote();
- current_view->update(0);
- }
-}
-
-
-// candidate for move to BufferView
-void MenuUndo()
-{
-/* if (current_view->buffer()->the_locking_inset) {
- current_view->owner()->getMiniBuffer()->Set(_("Undo not yet supported in math mode"));
- return;
- }*/
-
- if (current_view->available()) {
- current_view->owner()->getMiniBuffer()->Set(_("Undo"));
- current_view->getScreen()->HideCursor();
- BeforeChange();
- current_view->update(-2);
- if (!current_view->text->TextUndo())
- current_view->owner()->getMiniBuffer()->Set(_("No further undo information"));
- else
- current_view->update(-1);
- }
-}
-
-
-// candidate for move to BufferView
-void MenuRedo()
-{
- if (current_view->buffer()->the_locking_inset) {
- current_view->owner()->getMiniBuffer()->Set(_("Redo not yet supported in math mode"));
- return;
- }
-
- if (current_view->available()) {
- current_view->owner()->getMiniBuffer()->Set(_("Redo"));
- current_view->getScreen()->HideCursor();
- BeforeChange();
- current_view->update(-2);
- if (!current_view->text->TextRedo())
- current_view->owner()->getMiniBuffer()->Set(_("No further redo information"));
- else
- current_view->update(-1);
- }
-}
-
-
-// candidate for move to BufferView
-void HyphenationPoint()
-{
- if (current_view->available()) {
- current_view->getScreen()->HideCursor();
- current_view->update(-2);
- InsetSpecialChar * new_inset =
- new InsetSpecialChar(InsetSpecialChar::HYPHENATION);
- current_view->buffer()->insertInset(new_inset);
- }
-}
-
-
-// candidate for move to BufferView
-void Ldots()
-{
- if (current_view->available()) {
- current_view->getScreen()->HideCursor();
- current_view->update(-2);
- InsetSpecialChar * new_inset =
- new InsetSpecialChar(InsetSpecialChar::LDOTS);
- current_view->buffer()->insertInset(new_inset);
- }
-}
-
-
-// candidate for move to BufferView
-void EndOfSentenceDot()
-{
- if (current_view->available()) {
- current_view->getScreen()->HideCursor();
- current_view->update(-2);
- InsetSpecialChar * new_inset =
- new InsetSpecialChar(InsetSpecialChar::END_OF_SENTENCE);
- current_view->buffer()->insertInset(new_inset);
- }
-}
-
-
-// candidate for move to BufferView
-void MenuSeparator()
-{
- if (current_view->available()) {
- current_view->getScreen()->HideCursor();
- current_view->update(-2);
- InsetSpecialChar * new_inset =
- new InsetSpecialChar(InsetSpecialChar::MENU_SEPARATOR);
- current_view->buffer()->insertInset(new_inset);
- }
-}
-
-
-// candidate for move to BufferView
-void Newline()
-{
- if (current_view->available()) {
- current_view->getScreen()->HideCursor();
- current_view->update(-2);
- current_view->text->InsertChar(LyXParagraph::META_NEWLINE);
- current_view->update(-1);
- }
-}
-
-
-// candidate for move to BufferView
-void ProtectedBlank()
-{
- if (current_view->available()) {
- current_view->getScreen()->HideCursor();
- current_view->update(-2);
- current_view->text->InsertChar(LyXParagraph::META_PROTECTED_SEPARATOR);
- current_view->update(-1);
- }
-}
-
-
-// candidate for move to BufferView
-void HFill()
-{
- if (current_view->available()) {
- current_view->getScreen()->HideCursor();
- current_view->update(-2);
- current_view->text->InsertChar(LyXParagraph::META_HFILL);
- current_view->update(-1);
- }
-}
-
-
-/* -------> These CB's use ToggleFree() as the (one and only?) font-changer.
- They also show the current font state. */
-
-static
-void ToggleAndShow(LyXFont const &);
-
-
-void FontSizeCB(string const & size)
-{
- LyXFont font(LyXFont::ALL_IGNORE);
- font.setGUISize(size);
- ToggleAndShow(font);
-}
-
-
-void EmphCB()
-{
- LyXFont font(LyXFont::ALL_IGNORE);
- font.setEmph(LyXFont::TOGGLE);
- ToggleAndShow(font);
-}
-
-
-void NounCB()
-{
- LyXFont font(LyXFont::ALL_IGNORE);
- font.setNoun(LyXFont::TOGGLE);
- ToggleAndShow(font);
-}
-
-
-void BoldCB()
-{
- LyXFont font(LyXFont::ALL_IGNORE);
- font.setSeries(LyXFont::BOLD_SERIES);
- ToggleAndShow(font);
-}
-
-
-void UnderlineCB()
-{
- LyXFont font(LyXFont::ALL_IGNORE);
- font.setUnderbar(LyXFont::TOGGLE);
- ToggleAndShow(font);
-}
-
-
-void CodeCB()
-{
- LyXFont font(LyXFont::ALL_IGNORE);
- font.setFamily(LyXFont::TYPEWRITER_FAMILY); // no good
- ToggleAndShow(font);
-}
-
-
-void SansCB()
-{
- LyXFont font(LyXFont::ALL_IGNORE);
- font.setFamily(LyXFont::SANS_FAMILY);
- ToggleAndShow(font);
-}
-
-
-void RomanCB()
-{
- LyXFont font(LyXFont::ALL_IGNORE);
- font.setFamily(LyXFont::ROMAN_FAMILY);
- ToggleAndShow(font);
-}
-
-
-void TexCB()
-{
- LyXFont font(LyXFont::ALL_IGNORE);
- font.setLatex (LyXFont::TOGGLE);
- ToggleAndShow(font);
-}
-
-
-void StyleResetCB()
-{
- LyXFont font(LyXFont::ALL_INHERIT);
- ToggleAndShow(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(LyXFont const & font)
-{
- if (current_view->available()) {
- current_view->getScreen()->HideCursor();
- current_view->update(-2);
- current_view->text->ToggleFree(font, toggleall);
- current_view->update(1);
- }
- // removed since it overrides the ToggleFree Message about the style
- // Since Styles are more "High Level" than raw fonts I think the user
- // prefers it like this Matthias
- // FontStateShowCB( 0, 0 );
-}
-
-
-// candidate for move to BufferView
-extern "C" void MarginCB(FL_OBJECT *, long)
-{
- if (current_view->available()) {
- current_view->owner()->getMiniBuffer()->Set(_("Inserting margin note..."));
- current_view->getScreen()->HideCursor();
- current_view->update(-2);
- current_view->text->InsertFootnoteEnvironment(LyXParagraph::MARGIN);
- current_view->update(1);
- }
-}
-
-
-extern "C" void FigureCB(FL_OBJECT *, long)
-{
- 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"));
- }
-}
-
-
-extern "C" void TableCB(FL_OBJECT *, long)
-{
- 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 CopyEnvironmentCB()
-{
- if (current_view->available()) {
- current_view->text->copyEnvironmentType();
- /* clear the selection, even if mark_set */
- current_view->getScreen()->ToggleSelection();
- current_view->text->ClearSelection();
- current_view->update(-2);
- current_view->owner()->getMiniBuffer()->Set(_("Paragraph environment type copied"));
- }
-}
-
-
-// candidate for move to BufferView
-void PasteEnvironmentCB()
-{
- if (current_view->available()) {
- current_view->text->pasteEnvironmentType();
- current_view->owner()->getMiniBuffer()->Set(_("Paragraph environment type set"));
- current_view->update(1);
- }
-}
-
-
-// candidate for move to BufferView
-void CopyCB()
-{
- if (current_view->available()) {
- current_view->text->CopySelection();
- /* clear the selection, even if mark_set */
- current_view->getScreen()->ToggleSelection();
- current_view->text->ClearSelection();
- current_view->update(-2);
- current_view->owner()->getMiniBuffer()->Set(_("Copy"));
- }
-}
-
-
-// candidate for move to BufferView
-void CutCB()
-{
- if (current_view->available()) {
- current_view->getScreen()->HideCursor();
- current_view->update(-2);
- current_view->text->CutSelection();
- current_view->update(1);
- current_view->owner()->getMiniBuffer()->Set(_("Cut"));
- }
-}
-
-
-// candidate for move to BufferView
-void PasteCB()
-{
- if (!current_view->available()) return;
-
- current_view->owner()->getMiniBuffer()->Set(_("Paste"));
- current_view->getScreen()->HideCursor();
- /* clear the selection */
- current_view->getScreen()->ToggleSelection();
- current_view->text->ClearSelection();
- current_view->update(-2);
-
- /* paste */
- current_view->text->PasteSelection();
- current_view->update(1);
-
- /* clear the selection */
- current_view->getScreen()->ToggleSelection();
- current_view->text->ClearSelection();
- current_view->update(-2);
-}
-
-
-// candidate for move to BufferView
-extern "C" void MeltCB(FL_OBJECT *, long)
-{
- if (!current_view->available()) return;
-
- current_view->owner()->getMiniBuffer()->Set(_("Melt"));
- current_view->getScreen()->HideCursor();
- BeforeChange();
- current_view->update(-2);
- current_view->text->MeltFootnoteEnvironment();
- current_view->update(1);
-}
-
-
-// candidate for move to BufferView
-// Change environment depth.
-// if decInc == 0, depth change taking mouse button number into account
-// if decInc == 1, increment depth
-// if decInc == -1, decrement depth
-extern "C" void DepthCB(FL_OBJECT * ob, long decInc)
-{
- int button = 1;
-
- /* When decInc != 0, fake a mouse button. This allows us to
- implement depth-plus and depth-min commands. RVDK_PATCH_5. */
- /* check out wether ob is defined, too (Matthias) */
- if ( decInc < 0 )
- button = 0;
- else if (!decInc && ob) {
- button = fl_get_button_numb(ob);
- }
-
- if (current_view->available()) {
- current_view->getScreen()->HideCursor();
- current_view->update(-2);
- if (button == 1)
- current_view->text->IncDepth();
- else
- current_view->text->DecDepth();
- current_view->update(1);
- current_view->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()
-{
- LyXFont font(LyXFont::ALL_IGNORE);
-
- int pos = fl_get_choice(fd_form_character->choice_family);
- switch(pos) {
- case 1: font.setFamily(LyXFont::IGNORE_FAMILY); break;
- case 2: font.setFamily(LyXFont::ROMAN_FAMILY); break;
- case 3: font.setFamily(LyXFont::SANS_FAMILY); break;
- case 4: font.setFamily(LyXFont::TYPEWRITER_FAMILY); break;
- case 5: font.setFamily(LyXFont::INHERIT_FAMILY); break;
- }
-
- pos = fl_get_choice(fd_form_character->choice_series);
- switch(pos) {
- case 1: font.setSeries(LyXFont::IGNORE_SERIES); break;
- case 2: font.setSeries(LyXFont::MEDIUM_SERIES); break;
- case 3: font.setSeries(LyXFont::BOLD_SERIES); break;
- case 4: font.setSeries(LyXFont::INHERIT_SERIES); break;
- }
-
- pos = fl_get_choice(fd_form_character->choice_shape);
- switch(pos) {
- case 1: font.setShape(LyXFont::IGNORE_SHAPE); break;
- case 2: font.setShape(LyXFont::UP_SHAPE); break;
- case 3: font.setShape(LyXFont::ITALIC_SHAPE); break;
- case 4: font.setShape(LyXFont::SLANTED_SHAPE); break;
- case 5: font.setShape(LyXFont::SMALLCAPS_SHAPE); break;
- case 6: font.setShape(LyXFont::INHERIT_SHAPE); break;
- }
-
- pos = fl_get_choice(fd_form_character->choice_size);
- switch(pos) {
- case 1: font.setSize(LyXFont::IGNORE_SIZE); break;
- case 2: font.setSize(LyXFont::SIZE_TINY); break;
- case 3: font.setSize(LyXFont::SIZE_SCRIPT); break;
- case 4: font.setSize(LyXFont::SIZE_FOOTNOTE); break;
- case 5: font.setSize(LyXFont::SIZE_SMALL); break;
- case 6: font.setSize(LyXFont::SIZE_NORMAL); break;
- case 7: font.setSize(LyXFont::SIZE_LARGE); break;
- case 8: font.setSize(LyXFont::SIZE_LARGER); break;
- case 9: font.setSize(LyXFont::SIZE_LARGEST); break;
- case 10: font.setSize(LyXFont::SIZE_HUGE); break;
- case 11: font.setSize(LyXFont::SIZE_HUGER); break;
- case 12: font.setSize(LyXFont::INCREASE_SIZE); break;
- case 13: font.setSize(LyXFont::DECREASE_SIZE); break;
- case 14: font.setSize(LyXFont::INHERIT_SIZE); break;
- }
-
- pos = fl_get_choice(fd_form_character->choice_bar);
- switch(pos) {
- case 1: font.setEmph(LyXFont::IGNORE);
- font.setUnderbar(LyXFont::IGNORE);
- font.setNoun(LyXFont::IGNORE);
- font.setLatex(LyXFont::IGNORE);
- break;
- case 2: font.setEmph(LyXFont::TOGGLE); break;
- case 3: font.setUnderbar(LyXFont::TOGGLE); break;
- case 4: font.setNoun(LyXFont::TOGGLE); break;
- case 5: font.setLatex(LyXFont::TOGGLE); break;
- case 6: font.setEmph(LyXFont::INHERIT);
- font.setUnderbar(LyXFont::INHERIT);
- font.setNoun(LyXFont::INHERIT);
- font.setLatex(LyXFont::INHERIT);
- break;
- }
-
- pos = fl_get_choice(fd_form_character->choice_color);
- switch(pos) {
- case 1: font.setColor(LyXFont::IGNORE_COLOR); break;
- case 2: font.setColor(LyXFont::NONE); break;
- case 3: font.setColor(LyXFont::BLACK); break;
- case 4: font.setColor(LyXFont::WHITE); break;
- case 5: font.setColor(LyXFont::RED); break;
- case 6: font.setColor(LyXFont::GREEN); break;
- case 7: font.setColor(LyXFont::BLUE); break;
- case 8: font.setColor(LyXFont::CYAN); break;
- case 9: font.setColor(LyXFont::MAGENTA); break;
- case 10: font.setColor(LyXFont::YELLOW); break;
- case 11: font.setColor(LyXFont::INHERIT_COLOR); break;
- }
-
- return font;
-}
-
-
-void FreeCB()
-{
- ToggleAndShow(UserFreeFont());
-}
-
-
-/* callbacks for form form_title */
-extern "C" void TimerCB(FL_OBJECT *, long)
-{
- // only if the form still exists
- if (fd_form_title->form_title != 0) {
- if (fd_form_title->form_title->visible) {
- fl_hide_form(fd_form_title->form_title);
- }
- fl_free_form(fd_form_title->form_title);
- fd_form_title->form_title = 0;
- }
-}
-
-
-/* callbacks for form form_paragraph */
-
-extern "C" void ParagraphVSpaceCB(FL_OBJECT * obj, long )
-{
- // "Synchronize" the choices and input fields, making it
- // impossible to commit senseless data.
-
- FD_form_paragraph const * fp = fd_form_paragraph;
-
- if (obj == fp->choice_space_above) {
- if (fl_get_choice (fp->choice_space_above) != 7) {
- fl_set_input (fp->input_space_above, "");
- ActivateParagraphButtons();
- }
- } else if (obj == fp->choice_space_below) {
- if (fl_get_choice (fp->choice_space_below) != 7) {
- fl_set_input (fp->input_space_below, "");
- ActivateParagraphButtons();
- }
- } else if (obj == fp->input_space_above) {
- string input = fl_get_input (fp->input_space_above);
-
- if (input.empty()) {
- fl_set_choice (fp->choice_space_above, 1);
- ActivateParagraphButtons();
- }
- else if (isValidGlueLength (input)) {
- fl_set_choice (fp->choice_space_above, 7);
- ActivateParagraphButtons();
- }
- else {
- fl_set_choice (fp->choice_space_above, 7);
- DeactivateParagraphButtons();
- }
- } else if (obj == fp->input_space_below) {
- string input = fl_get_input (fp->input_space_below);
-
- if (input.empty()) {
- fl_set_choice (fp->choice_space_below, 1);
- ActivateParagraphButtons();
- }
- else if (isValidGlueLength (input)) {
- fl_set_choice (fp->choice_space_below, 7);
- ActivateParagraphButtons();
- }
- else {
- fl_set_choice (fp->choice_space_below, 7);
- DeactivateParagraphButtons();
- }
- }
-}
-
-
-extern "C" void ParagraphApplyCB(FL_OBJECT *, long)
-{
- if (!current_view->available())
- return;
-
- VSpace space_top, space_bottom;
- LyXAlignment align;
- string labelwidthstring;
- bool noindent;
-
- // If a vspace kind is "Length" but there's no text in
- // the input field, reset the kind to "None".
- if (fl_get_choice (fd_form_paragraph->choice_space_above) == 7
- && !*(fl_get_input (fd_form_paragraph->input_space_above))) {
- fl_set_choice (fd_form_paragraph->choice_space_above, 1);
- }
- if (fl_get_choice (fd_form_paragraph->choice_space_below) == 7
- && !*(fl_get_input (fd_form_paragraph->input_space_below))) {
- fl_set_choice (fd_form_paragraph->choice_space_below, 1);
- }
-
- bool line_top = fl_get_button(fd_form_paragraph->check_lines_top);
- bool line_bottom = fl_get_button(fd_form_paragraph->check_lines_bottom);
- bool pagebreak_top = fl_get_button(fd_form_paragraph->check_pagebreaks_top);
- bool pagebreak_bottom = fl_get_button(fd_form_paragraph->check_pagebreaks_bottom);
- switch (fl_get_choice (fd_form_paragraph->choice_space_above)) {
- case 1: space_top = VSpace(VSpace::NONE); break;
- case 2: space_top = VSpace(VSpace::DEFSKIP); break;
- case 3: space_top = VSpace(VSpace::SMALLSKIP); break;
- case 4: space_top = VSpace(VSpace::MEDSKIP); break;
- case 5: space_top = VSpace(VSpace::BIGSKIP); break;
- case 6: space_top = VSpace(VSpace::VFILL); break;
- case 7: space_top = VSpace(LyXGlueLength (fl_get_input (fd_form_paragraph->input_space_above))); break;
- }
- if (fl_get_button (fd_form_paragraph->check_space_above))
- space_top.setKeep (true);
- switch (fl_get_choice (fd_form_paragraph->choice_space_below)) {
- case 1: space_bottom = VSpace(VSpace::NONE); break;
- case 2: space_bottom = VSpace(VSpace::DEFSKIP); break;
- case 3: space_bottom = VSpace(VSpace::SMALLSKIP); break;
- case 4: space_bottom = VSpace(VSpace::MEDSKIP); break;
- case 5: space_bottom = VSpace(VSpace::BIGSKIP); break;
- case 6: space_bottom = VSpace(VSpace::VFILL); break;
- case 7: space_bottom = VSpace(LyXGlueLength (fl_get_input (fd_form_paragraph->input_space_below))); break;
- }
- if (fl_get_button (fd_form_paragraph->check_space_below))
- space_bottom.setKeep (true);
-
- if (fl_get_button(fd_form_paragraph->radio_align_left))
- align = LYX_ALIGN_LEFT;
- else if (fl_get_button(fd_form_paragraph->radio_align_right))
- align = LYX_ALIGN_RIGHT;
- else if (fl_get_button(fd_form_paragraph->radio_align_center))
- align = LYX_ALIGN_CENTER;
- else
- align = LYX_ALIGN_BLOCK;
-
- labelwidthstring = fl_get_input(fd_form_paragraph->input_labelwidth);
- noindent = fl_get_button(fd_form_paragraph->check_noindent);
-
- current_view->text->SetParagraph(line_top,
- line_bottom,
- pagebreak_top,
- pagebreak_bottom,
- space_top,
- space_bottom,
- align,
- labelwidthstring,
- noindent);
- current_view->update(1);
- current_view->owner()->getMiniBuffer()->Set(_("Paragraph layout set"));
-}
-
-
-extern "C" void ParagraphCancelCB(FL_OBJECT *, long)
-{
- fl_hide_form(fd_form_paragraph->form_paragraph);
-}
-
-
-extern "C" void ParagraphOKCB(FL_OBJECT *ob, long data)
-{
- ParagraphApplyCB(ob, data);
- ParagraphCancelCB(ob, data);
-}
-
-
-/* callbacks for form form_character */
-
-extern "C" void CharacterApplyCB(FL_OBJECT *, long)
-{
- // we set toggleall locally here, since it should be true for
- // all other uses of ToggleAndShow() (JMarc)
- toggleall = fl_get_button(fd_form_character->check_toggle_all);
- ToggleAndShow( UserFreeFont());
- toggleall = true;
-}
-
-
-extern "C" void CharacterCloseCB(FL_OBJECT *, long)
-{
- fl_hide_form(fd_form_character->form_character);
-}
-
-
-extern "C" void CharacterOKCB(FL_OBJECT *ob, long data)
-{
- CharacterApplyCB(ob, data);
- CharacterCloseCB(ob, data);
-}
-
-
-/* callbacks for form form_document */
-
-void UpdateDocumentButtons(BufferParams const & params)
-{
- fl_set_choice(fd_form_document->choice_pagestyle, 1);
-
- if (params.sides == 2)
- fl_set_button(fd_form_document->radio_sides_two, 1);
- else
- fl_set_button(fd_form_document->radio_sides_one, 1);
-
- if (params.columns == 2)
- fl_set_button(fd_form_document->radio_columns_two, 1);
- else
- fl_set_button(fd_form_document->radio_columns_one, 1);
-
- fl_set_input(fd_form_document->input_extra, params.options.c_str());
- fl_set_counter_value(fd_form_document->slider_secnumdepth,
- params.secnumdepth);
- fl_set_counter_value(fd_form_document->slider_tocdepth,
- params.tocdepth);
-
-}
-
-extern "C" void ChoiceClassCB(FL_OBJECT * ob, long)
-{
- ProhibitInput();
- if (textclasslist.Load(fl_get_choice(ob)-1)) {
- if (AskQuestion(_("Should I set some parameters to"),
- fl_get_choice_text(ob),
- _("the defaults of this document class?"))) {
- BufferParams params = BufferParams();
- params.textclass = fl_get_choice(ob)-1;
- params.useClassDefaults();
- UpdateLayoutDocument(¶ms);
- UpdateDocumentButtons(params);
- }
- } else {
- // unable to load new style
- WriteAlert(_("Conversion Errors!"),
- _("Unable to switch to new document class."),
- _("Reverting to original document class."));
- fl_set_choice(fd_form_document->choice_class,
- GetCurrentTextClass() + 1);
- }
- AllowInput();
-}
-
-
-extern "C" void DocumentDefskipCB(FL_OBJECT * obj, long)
-{
- // "Synchronize" the choice and the input field, so that it
- // is impossible to commit senseless data.
- FD_form_document const * fd = fd_form_document;
-
- if (obj == fd->choice_default_skip) {
- if (fl_get_choice (fd->choice_default_skip) != 4) {
- fl_set_input (fd->input_default_skip, "");
- ActivateDocumentButtons();
- }
- } else if (obj == fd->input_default_skip) {
-
- char const * input = fl_get_input (fd->input_default_skip);
-
- if (!*input) {
- fl_set_choice (fd->choice_default_skip, 2);
- ActivateDocumentButtons();
- } else if (isValidGlueLength (input)) {
- fl_set_choice (fd->choice_default_skip, 4);
- ActivateDocumentButtons();
- } else {
- fl_set_choice (fd->choice_default_skip, 4);
- DeactivateDocumentButtons();
- }
- }
-}
-
-
-extern "C" void DocumentSpacingCB(FL_OBJECT * obj, long)
-{
- // "Synchronize" the choice and the input field, so that it
- // is impossible to commit senseless data.
- FD_form_document const * fd = fd_form_document;
-
- if (obj == fd->choice_spacing
- && fl_get_choice (fd->choice_spacing) != 4) {
- fl_set_input(fd->input_spacing, "");
- } else if (obj == fd->input_spacing) {
-
- const char* input = fl_get_input (fd->input_spacing);
-
- if (!*input) {
- fl_set_choice (fd->choice_spacing, 1);
- } else {
- fl_set_choice (fd->choice_spacing, 4);