diff --git a/ChangeLog b/ChangeLog index d9348d3065..31aa95c7c5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,134 @@ +2000-11-08 Lars Gullik Bjønnes + + * src/support/filetools.C (DirList): implement using system functions + + * src/support/tempname.C: new file + + * src/support/Makefile.am (libsupport_la_SOURCES): add tempname.C + + * src/insets/insetexternal.C (InsetExternal): use lyx::tempName + + * src/graphics/GraphicsCacheItem_pimpl.C (renderXPM): use + lyx::tempName + + * src/frontends/xforms/ButtonController.C: new file + + * src/os2_defines.h: remove getcwd define + + * src/lyxvc.C: include support/lyxlib.h + (showLog): use lyx::tempName + + * src/lyx_cb.C: comment out includes that we don't need + (AutoSave): use lyx::tempName + + * src/filedlg.C: include support/lyxlib.h + (Reread): use lyx::getcwd + + * src/converter.C: include support/filetools.h + (add_options): change to static inline, make tail const + (Add): make old_viewer const + (GetAllFormats): make it a const method, use const_iterator + (enable): make static inline + (SplitFormat): make using_format const + + * src/LaTeX.C (run): use lyx::getcwd + + * configure.in: check for mkstemp as well + +2000-11-07 Angus Leeming + + * src/converter.[Ch] (GetAllCommands): new method. + + * src/support/filetools.[Ch] (DirList): new method. + + * src/frontends/xforms/FormPreferences.C: started (just!) adding + functionality to the converters tab. + The formats tab is now nearly complete. + The kbmap choices in Languages tab now display the contents of + system_lyxdir/kbd/*.kmap in readable form. + + * src/frontends/xforms/FormPreferences.h: made struct RGB private. + Moved some variables into the class. + + * src/frontends/xforms/forms/form_preferences.fd: Revert colour of + inactive tab folder to FL_COL1. Haven't yet worked out how to change + colour of active folder to lighter grey instead. Any takers? + (form_colours): added an "Apply" button. + (form_converters): added a "Flags" input field. + (form_formats): added a "Shortcut" input field. Note that we can't use + names such as "input_shortcut" as this buggers up the sed script stuff. + + * src/frontends/xforms/FormPreferences.C + +2000-11-07 Angus Leeming + + * src/LaTeXLog.C: + * src/LyXSendto.C: + * src/credits.C: + * src/filedlg.C: + * src/intl.C: + * src/lyx_cb.C: + * src/lyx_sendfax_main.C: + * src/lyxfr0.C: + * src/lyxvc.C: + * src/spellchecker.C: + * src/insets/figinset.C: + * src/insets/insetbib.C: + * src/insets/insetexternal.C: + * src/insets/insetinclude.C: + * src/insets/insetinfo.C: + * src/mathed/math_panel.C: + use FL_PLACE_MOUSE | FL_FREE_SIZE, FL_TRANSIENT in fl_show_form(), so + all "daughter" dialogs now have identical "feel". + +2000-11-07 Angus Leeming + + * src/lyx_gui_misc.[Ch] (IgnoreCloseBoxCB): removed as it's no longer + used (and was only used in one place prior to this patch. Incorrectly!) + + * src/frontends/xforms/FormDocument.C: changed some instances of + FL_RETURN_ALWAYS to FL_RETURN_CHANGED as I think that this makes more + sense. Also added fl_set_input_return() for class_->input_doc_extra and + for options_->input_float_placement. This fixes a bug reported by + Rob Lahaye. + + * src/frontends/xforms/FormGraphics.[Ch] (free): removed. Placed + functionality into d-tor. + + * src/frontends/xforms/input_validators.c (fl_lowercase_filter): allow + input of numerals also. + + * src/insets/insetinclude.C (Edit): use CancelCloseBoxCB in + fl_set_form_atclose(). Can now close dialog from window manager, + fixing a bug reported by Rob Lahaye. + +2000-11-06 Angus Leeming + + * src/frontends/xforms/forms/form_preferences.fd: Inactive tab folders + are no longer dark. Haven't yet worked out how to lighten the colour of + the active tabfolder. Any ideas anybody? + Adjusted Colours tab a little. + Added Shortcut field to converters tab. Note that we can't create an + fdesign label like "input_shortcut" as this buggers up the sed-script + stuff. + + * src/frontends/xforms/FormPreferences.[Ch]: + (feedback): fixed crash due to to ob=0. + (LanguagesXXX): the kbmap choices now contain the files + sytem_lyxdir/kbd/*.kmap. I think that these choices should eventually + be replaced by an input with a file browse button, but since the browse + buttons don'y yet work, this'll do for the moment. + (FormatsXXX): think that this is now nearly fully functional. + Some points/questions though: + 1. Does "Apply" remove formats if no longer present? + 2. I think that the browser should list the GUI names rather than the + format names. + 3. Must ensure that we can't delete Formats used by an existing + Converter. + + * src/support/filetools.[Ch] (DirList): new function. Not at all sure + if this is the best way to do this. + 2000-11-07 Jean-Marc Lasgouttes * lib/reLyX/acinclude.m4 (RELYX_CHECK_ERRORS): remove useless message. diff --git a/configure.in b/configure.in index c525a93a93..10410de357 100644 --- a/configure.in +++ b/configure.in @@ -252,6 +252,7 @@ if test "x$lyx_broken_headers" = "xyes"; then [Define on SunOS 4 and SCO, were some functions are missing from the headers]) fi AC_CHECK_FUNCS(memmove memset strchr putenv setenv mkfifo snprintf vsnprintf) +AC_CHECK_FUNCS(mkstemp) dnl Until this is fixed in autoconf we provide our own version LYX_FUNC_SELECT_ARGTYPES diff --git a/po/POTFILES.in b/po/POTFILES.in index cfcf301617..d18943019e 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -47,35 +47,35 @@ src/frontends/kde/refdlg.C src/frontends/kde/tocdlg.C src/frontends/kde/urldlg.C src/frontends/xforms/FormBase.h -src/frontends/xforms/FormCitation.C src/frontends/xforms/form_citation.C -src/frontends/xforms/FormCopyright.C +src/frontends/xforms/FormCitation.C src/frontends/xforms/form_copyright.C -src/frontends/xforms/FormDocument.C +src/frontends/xforms/FormCopyright.C src/frontends/xforms/form_document.C -src/frontends/xforms/FormError.C +src/frontends/xforms/FormDocument.C src/frontends/xforms/form_error.C -src/frontends/xforms/FormGraphics.C +src/frontends/xforms/FormError.C src/frontends/xforms/form_graphics.C -src/frontends/xforms/FormIndex.C +src/frontends/xforms/FormGraphics.C src/frontends/xforms/form_index.C +src/frontends/xforms/FormIndex.C src/frontends/xforms/FormInset.h -src/frontends/xforms/FormParagraph.C src/frontends/xforms/form_paragraph.C -src/frontends/xforms/FormPreferences.C +src/frontends/xforms/FormParagraph.C src/frontends/xforms/form_preferences.C -src/frontends/xforms/FormPrint.C +src/frontends/xforms/FormPreferences.C src/frontends/xforms/form_print.C -src/frontends/xforms/FormRef.C +src/frontends/xforms/FormPrint.C src/frontends/xforms/form_ref.C -src/frontends/xforms/FormTabular.C +src/frontends/xforms/FormRef.C src/frontends/xforms/form_tabular.C -src/frontends/xforms/FormTabularCreate.C +src/frontends/xforms/FormTabular.C src/frontends/xforms/form_tabular_create.C -src/frontends/xforms/FormToc.C +src/frontends/xforms/FormTabularCreate.C src/frontends/xforms/form_toc.C -src/frontends/xforms/FormUrl.C +src/frontends/xforms/FormToc.C src/frontends/xforms/form_url.C +src/frontends/xforms/FormUrl.C src/frontends/xforms/Menubar_pimpl.C src/gettext.h src/importer.C diff --git a/src/LaTeX.C b/src/LaTeX.C index 0db816277c..deaffae9ce 100644 --- a/src/LaTeX.C +++ b/src/LaTeX.C @@ -119,7 +119,7 @@ int LaTeX::run(TeXErrors & terr, MiniBuffer * minib) bool rerun = false; // rerun requested // The class LaTeX does not know the temp path. - bufferlist.updateIncludedTeXfiles(GetCWD()); + bufferlist.updateIncludedTeXfiles(lyx::getcwd()); //GetCWD()); // Never write the depfile if an error was encountered. diff --git a/src/LaTeXLog.C b/src/LaTeXLog.C index a791546c5a..f53b6719a5 100644 --- a/src/LaTeXLog.C +++ b/src/LaTeXLog.C @@ -50,7 +50,7 @@ void ShowLatexLog() fl_raise_form(fd_latex_log->LaTeXLog); } else { fl_show_form(fd_latex_log->LaTeXLog, - FL_PLACE_MOUSE | FL_FREE_SIZE, FL_FULLBORDER, + FL_PLACE_MOUSE | FL_FREE_SIZE, FL_TRANSIENT, use_build ? _("Build Program Log") : _("LaTeX Log")); if (ow < 0) { ow = fd_latex_log->LaTeXLog->w; diff --git a/src/LyXSendto.C b/src/LyXSendto.C index 5e7587c35d..881ad276eb 100644 --- a/src/LyXSendto.C +++ b/src/LyXSendto.C @@ -36,7 +36,7 @@ void MenuSendto() fl_raise_form(fd_form_sendto->form_sendto); } else { fl_show_form(fd_form_sendto->form_sendto, - FL_PLACE_MOUSE | FL_FREE_SIZE, FL_FULLBORDER, + FL_PLACE_MOUSE | FL_FREE_SIZE, FL_TRANSIENT, _("Send Document to Command")); if (ow < 0) { ow = fd_form_sendto->form_sendto->w; diff --git a/src/buffer.C b/src/buffer.C index 74c7d6eb58..62750128c6 100644 --- a/src/buffer.C +++ b/src/buffer.C @@ -1289,7 +1289,7 @@ void Buffer::writeFileAscii(string const & fname, int linelen) return; } - string const fname1 = TmpFileName(); + string const fname1 = lyx::tempName(); //TmpFileName(); LyXParagraph * par = paragraph; while (par) { int noparbreak = 0; diff --git a/src/converter.C b/src/converter.C index ac91f7cf7f..75d1808f4c 100644 --- a/src/converter.C +++ b/src/converter.C @@ -20,6 +20,7 @@ #include "lyxrc.h" #include "support/syscall.h" #include "support/path.h" +#include "support/filetools.h" #include "buffer.h" #include "bufferview_funcs.h" #include "LaTeX.h" @@ -41,11 +42,11 @@ using std::find_if; vector Converter::commands; string Converter::latex_command; -inline +static inline string const add_options(string const & command, string const & options) { string head; - string tail = split(command, head, ' '); + string const tail = split(command, head, ' '); return head + ' ' + options + ' ' + tail; } @@ -76,7 +77,7 @@ void Formats::Add(string const & name, string const & extension, return; } - string old_viewer = formats[name].viewer; + string const old_viewer = formats[name].viewer; formats[name] = Format(name, extension, prettyname, shortcut, old_viewer); } @@ -137,6 +138,8 @@ bool Formats::View(Buffer const * buffer, string const & filename, } +// This method should return a reference, and throw an exception +// if the format named name cannot be found (Lgb) Format * Formats::GetFormat(string const & name) { FormatList::iterator it = formats.find(name); @@ -168,18 +171,20 @@ string const Formats::Extension(string const & name) vector -const Formats::GetAllFormats() +const Formats::GetAllFormats() const { vector result; - for (FormatList::iterator it = formats.begin(); - it != formats.end(); ++it) - result.push_back(it->second); + for (FormatList::const_iterator cit = formats.begin(); + cit != formats.end(); ++cit) + result.push_back(cit->second); return result; } ////////////////////////////////////////////////////////////////////////////// +// Instead of storing an object we could just store an const reference. +// _but_ that is not guaranteed to work in all cases. (Lgb) class compare_Command { public: compare_Command(Command const & c) : com(c) {} @@ -262,7 +267,7 @@ void Converter::Add(string const & from, string const & to, } -inline +static inline bool enable(vector::iterator it, string const & from) { return find(it->disable.begin(), it->disable.end(), from) @@ -575,7 +580,7 @@ bool Converter::Convert(Buffer const * buffer, string const Converter::SplitFormat(string const & str, string & format) { - string using_format = split(str, format, ':'); + string const using_format = split(str, format, ':'); if (format.empty()) format = "dvi"; return using_format; @@ -778,6 +783,16 @@ void Converter::init() { } +vector const Converter::GetAllCommands() +{ + vector result; + for (vector::iterator it = commands.begin(); + it != commands.end(); ++it) + result.push_back(*it); + return result; +} + + /// The global instance Formats formats; diff --git a/src/converter.h b/src/converter.h index 37ac7d5ca5..fc84a7550d 100644 --- a/src/converter.h +++ b/src/converter.h @@ -122,7 +122,7 @@ public: /// string const Extension(string const & name); /// - std::vector const GetAllFormats(); + std::vector const GetAllFormats() const; private: /// FormatList formats; @@ -169,6 +169,9 @@ public: /// static void init(); + /// + static + std::vector const GetAllCommands(); private: /// static diff --git a/src/credits.C b/src/credits.C index 430e56c580..0bbb361a95 100644 --- a/src/credits.C +++ b/src/credits.C @@ -67,7 +67,7 @@ void ShowCredits() fl_raise_form(fd_form_credits->form_credits); } else { fl_show_form(fd_form_credits->form_credits, - FL_PLACE_MOUSE | FL_FREE_SIZE, FL_FULLBORDER, + FL_PLACE_MOUSE | FL_FREE_SIZE, FL_TRANSIENT, _("Credits")); } } diff --git a/src/filedlg.C b/src/filedlg.C index 97c78aee49..4c4d5adc7a 100644 --- a/src/filedlg.C +++ b/src/filedlg.C @@ -24,6 +24,7 @@ using std::sort; #include "lyx_gui_misc.h" // CancelCloseCB #include "support/FileInfo.h" +#include "support/lyxlib.h" #include "gettext.h" #ifdef HAVE_ERRNO_H @@ -190,7 +191,7 @@ void LyXFileDlg::Reread() if (!pDirectory) { WriteFSAlert(_("Warning! Couldn't open directory."), pszDirectory); - pszDirectory = GetCWD(); + pszDirectory = lyx::getcwd(); //GetCWD(); pDirectory = ::opendir(pszDirectory.c_str()); } @@ -700,8 +701,9 @@ string const LyXFileDlg::Select(string const & title, string const & path, fl_set_button(pFileDlgForm->Ready, 0); fl_set_focus_object(pFileDlgForm->FileDlg, pFileDlgForm->Filename); fl_deactivate_all_forms(); - fl_show_form(pFileDlgForm->FileDlg, FL_PLACE_MOUSE | FL_FREE_SIZE, - FL_FULLBORDER, title.c_str()); + fl_show_form(pFileDlgForm->FileDlg, + FL_PLACE_MOUSE | FL_FREE_SIZE, FL_TRANSIENT, + title.c_str()); isOk = RunDialog(); diff --git a/src/frontends/ButtonPolicies.C b/src/frontends/ButtonPolicies.C index fcb15da1bc..23812b42c1 100644 --- a/src/frontends/ButtonPolicies.C +++ b/src/frontends/ButtonPolicies.C @@ -98,6 +98,7 @@ PreferencesPolicy::PreferencesPolicy() void PreferencesPolicy::input(SMInput input) { + lyxerr << "PreferencesPolicy::input" << endl; // CANCEL and HIDE always take us to INITIAL for all cases. // Note that I didn't put that special case in the helper function // because it doesn't belong there. Some other @@ -159,6 +160,8 @@ OkCancelPolicy::OkCancelPolicy() void OkCancelPolicy::input(SMInput input) { + lyxerr << "OkCancelPolicy::input" << endl; + // CANCEL and HIDE always take us to INITIAL for all cases if (SMI_CANCEL == input || SMI_HIDE == input) { @@ -231,6 +234,8 @@ OkCancelReadOnlyPolicy::OkCancelReadOnlyPolicy() void OkCancelReadOnlyPolicy::input(SMInput input) { + lyxerr << "OkCancelReadOnlyPolicy" << endl; + // CANCEL and HIDE always take us to INITIAL for all cases if (SMI_CANCEL == input || SMI_HIDE == input) { @@ -307,6 +312,8 @@ NoRepeatedApplyReadOnlyPolicy::NoRepeatedApplyReadOnlyPolicy() void NoRepeatedApplyReadOnlyPolicy::input(SMInput input) { + lyxerr << "NoReapeatedApplyReadOnlyPolicy::input" << endl; + // CANCEL and HIDE always take us to INITIAL for all cases if (SMI_CANCEL == input || SMI_HIDE == input) { @@ -397,6 +404,8 @@ OkApplyCancelReadOnlyPolicy::OkApplyCancelReadOnlyPolicy() void OkApplyCancelReadOnlyPolicy::input(SMInput input) { + lyxerr << "OkApplyCancelReadOnlyPolicy::input" << endl; + // CANCEL and HIDE always take us to INITIAL for all cases if (SMI_CANCEL == input || SMI_HIDE == input) { @@ -461,6 +470,8 @@ OkApplyCancelPolicy::OkApplyCancelPolicy() void OkApplyCancelPolicy::input(SMInput input) { + lyxerr << "OkApplyCancelPolicy::input" << endl; + // CANCEL and HIDE always take us to INITIAL for all cases if (SMI_CANCEL == input || SMI_HIDE == input) { @@ -517,6 +528,8 @@ NoRepeatedApplyPolicy::NoRepeatedApplyPolicy() void NoRepeatedApplyPolicy::input(SMInput input) { + lyxerr << "NoRepeatedApplyPolicy::input" << endl; + // CANCEL and HIDE always take us to INITIAL for all cases if (SMI_CANCEL == input || SMI_HIDE == input) { diff --git a/src/frontends/ButtonPolicies.h b/src/frontends/ButtonPolicies.h index 45a12769ae..a552917fce 100644 --- a/src/frontends/ButtonPolicies.h +++ b/src/frontends/ButtonPolicies.h @@ -189,7 +189,7 @@ public: /// OkCancelPolicy(); /// - virtual ~OkCancelPolicy() {} + //virtual ~OkCancelPolicy() {} /// Trigger a transition with this input. virtual void input(SMInput); @@ -231,7 +231,7 @@ public: /// OkCancelReadOnlyPolicy(); /// - virtual ~OkCancelReadOnlyPolicy() {} + //virtual ~OkCancelReadOnlyPolicy() {} /// Trigger a transition with this input. virtual void input(SMInput); @@ -275,7 +275,7 @@ public: /// NoRepeatedApplyReadOnlyPolicy(); /// - virtual ~NoRepeatedApplyReadOnlyPolicy() {} + //virtual ~NoRepeatedApplyReadOnlyPolicy() {} /// Trigger a transition with this input. virtual void input(SMInput); @@ -316,7 +316,7 @@ public: /// OkApplyCancelReadOnlyPolicy(); /// - virtual ~OkApplyCancelReadOnlyPolicy() {} + //virtual ~OkApplyCancelReadOnlyPolicy() {} /// Trigger a transition with this input. virtual void input(SMInput); @@ -351,7 +351,7 @@ public: /// OkApplyCancelPolicy(); /// - virtual ~OkApplyCancelPolicy() {} + //virtual ~OkApplyCancelPolicy() {} /// Trigger a transition with this input. virtual void input(SMInput); @@ -383,7 +383,7 @@ public: /// NoRepeatedApplyPolicy(); /// - virtual ~NoRepeatedApplyPolicy() {} + //virtual ~NoRepeatedApplyPolicy() {} /// Trigger a transition with this input. virtual void input(SMInput); @@ -416,7 +416,7 @@ public: /// PreferencesPolicy(); /// - virtual ~PreferencesPolicy() {} + //virtual ~PreferencesPolicy() {} /// Trigger a transition with this input. virtual void input(SMInput); @@ -446,7 +446,7 @@ private: */ class IgnorantPolicy : public ButtonPolicy { public: - virtual ~IgnorantPolicy() {} + //virtual ~IgnorantPolicy() {} /// Trigger a transition with this input. virtual void input(SMInput) {} diff --git a/src/frontends/xforms/ButtonController.C b/src/frontends/xforms/ButtonController.C new file mode 100644 index 0000000000..e79abaa47e --- /dev/null +++ b/src/frontends/xforms/ButtonController.C @@ -0,0 +1,157 @@ +#include + +#include FORMS_H_LOCATION + +#ifdef __GNUG__ +#pragma implementation +#endif + +#include "ButtonController.h" +#include "support/LAssert.h" + + +ButtonController::ButtonController(ButtonPolicy * bp, + char const * cancel, char const * close) + : bp_(bp), okay_(0), apply_(0), cancel_(0), undo_all_(0), + read_only_(), cancel_label(cancel), close_label(close) +{ + Assert(bp); +} + + +void ButtonController::refresh() +{ + if (okay_) { + if (bp_->buttonStatus(ButtonPolicy::OKAY)) { + fl_activate_object(okay_); + fl_set_object_lcol(okay_, FL_BLACK); + } else { + fl_deactivate_object(okay_); + fl_set_object_lcol(okay_, FL_INACTIVE); + } + } + if (apply_) { + if (bp_->buttonStatus(ButtonPolicy::APPLY)) { + fl_activate_object(apply_); + fl_set_object_lcol(apply_, FL_BLACK); + } else { + fl_deactivate_object(apply_); + fl_set_object_lcol(apply_, FL_INACTIVE); + } + } + if (undo_all_) { + if (bp_->buttonStatus(ButtonPolicy::UNDO_ALL)) { + fl_activate_object(undo_all_); + fl_set_object_lcol(undo_all_, FL_BLACK); + } else { + fl_deactivate_object(undo_all_); + fl_set_object_lcol(undo_all_, + FL_INACTIVE); + } + } + if (cancel_) { + if (bp_->buttonStatus(ButtonPolicy::CANCEL)) { + fl_set_object_label(cancel_, + cancel_label); + } else { + fl_set_object_label(cancel_, + close_label); + } + } + if (!read_only_.empty()) { + if (bp_->isReadOnly()) { + std::list::iterator + end = read_only_.end(); + for (std::list::iterator + iter = read_only_.begin(); + iter != end; + ++iter) { + fl_deactivate_object(*iter); + fl_set_object_lcol(*iter, + FL_INACTIVE); + } + } else { + std::list::iterator + end = read_only_.end(); + for (std::list::iterator + iter = read_only_.begin(); + iter != end; + ++iter) { + fl_activate_object(*iter); + fl_set_object_lcol(*iter, + FL_BLACK); + } + } + } +} + + +void ButtonController::input(ButtonPolicy::SMInput in) +{ + bp_->input(in); + refresh(); +} + + +void ButtonController::ok() +{ + input(ButtonPolicy::SMI_OKAY); +} + + +void ButtonController::apply() +{ + input(ButtonPolicy::SMI_APPLY); +} + + +void ButtonController::cancel() +{ + input(ButtonPolicy::SMI_CANCEL); +} + + +void ButtonController::undoAll() +{ + input(ButtonPolicy::SMI_UNDO_ALL); +} + + +void ButtonController::hide() +{ + input(ButtonPolicy::SMI_HIDE); +} + + +bool ButtonController::readOnly(bool ro) +{ + if (ro) { + input(ButtonPolicy::SMI_READ_ONLY); + } else { + input(ButtonPolicy::SMI_READ_WRITE); + } + return ro; +} + + +void ButtonController::readWrite() +{ + readOnly(false); +} + + +bool ButtonController::valid(bool v) +{ + if (v) { + input(ButtonPolicy::SMI_VALID); + } else { + input(ButtonPolicy::SMI_INVALID); + } + return v; +} + + +void ButtonController::invalid() +{ + valid(false); +} diff --git a/src/frontends/xforms/ButtonController.h b/src/frontends/xforms/ButtonController.h index 5f4c6462a6..92e2982824 100644 --- a/src/frontends/xforms/ButtonController.h +++ b/src/frontends/xforms/ButtonController.h @@ -24,6 +24,10 @@ #include "ButtonPolicies.h" #include +#ifdef __GNUG__ +#pragma interface +#endif + /** General purpose button controller for up to four buttons. Controls the activation of the OK, Apply and Cancel buttons. Actually supports 4 buttons in all and it's up to the user to decide on @@ -44,11 +48,12 @@ public: you can just assign "Cancel" to both labels. Or even reuse this class for something completely different. */ - ButtonController(ButtonPolicy * bp, char const * cancel, char const * close) - : bp_(bp), okay_(0), apply_(0), cancel_(0), undo_all_(0), - read_only_(), cancel_label(cancel), close_label(close) {} - /// Somebody else owns the FL_OBJECTs we just manipulate them. - ~ButtonController() {} + ButtonController(ButtonPolicy * bp, + char const * cancel, char const * close); + + // Somebody else owns the FL_OBJECTs we just manipulate them. + // so? (Lgb) + //~ButtonController() {} /* Initialise Button Functions */ /// Call refresh() when finished setting the buttons. @@ -86,121 +91,28 @@ public: /* Action Functions */ /// force a refresh of the buttons - void refresh() { - if (okay_) { - if (bp_->buttonStatus(ButtonPolicy::OKAY)) { - fl_activate_object(okay_); - fl_set_object_lcol(okay_, FL_BLACK); - } else { - fl_deactivate_object(okay_); - fl_set_object_lcol(okay_, FL_INACTIVE); - } - } - if (apply_) { - if (bp_->buttonStatus(ButtonPolicy::APPLY)) { - fl_activate_object(apply_); - fl_set_object_lcol(apply_, FL_BLACK); - } else { - fl_deactivate_object(apply_); - fl_set_object_lcol(apply_, FL_INACTIVE); - } - } - if (undo_all_) { - if (bp_->buttonStatus(ButtonPolicy::UNDO_ALL)) { - fl_activate_object(undo_all_); - fl_set_object_lcol(undo_all_, FL_BLACK); - } else { - fl_deactivate_object(undo_all_); - fl_set_object_lcol(undo_all_, - FL_INACTIVE); - } - } - if (cancel_) { - if (bp_->buttonStatus(ButtonPolicy::CANCEL)) { - fl_set_object_label(cancel_, - cancel_label); - } else { - fl_set_object_label(cancel_, - close_label); - } - } - if (!read_only_.empty()) { - if (bp_->isReadOnly()) { - std::list::iterator - end = read_only_.end(); - for (std::list::iterator - iter = read_only_.begin(); - iter != end; - ++iter) { - fl_deactivate_object(*iter); - fl_set_object_lcol(*iter, - FL_INACTIVE); - } - } else { - std::list::iterator - end = read_only_.end(); - for (std::list::iterator - iter = read_only_.begin(); - iter != end; - ++iter) { - fl_activate_object(*iter); - fl_set_object_lcol(*iter, - FL_BLACK); - } - } - } - } + void refresh(); + /// - void input(ButtonPolicy::SMInput in) { - bp_->input(in); - refresh(); - } + void input(ButtonPolicy::SMInput in); /// - void ok() { - input(ButtonPolicy::SMI_OKAY); - } + void ok(); /// - void apply() { - input(ButtonPolicy::SMI_APPLY); - } + void apply(); /// - void cancel() { - input(ButtonPolicy::SMI_CANCEL); - } + void cancel(); /// - void undoAll() { - input(ButtonPolicy::SMI_UNDO_ALL); - } + void undoAll(); /// - void hide() { - input(ButtonPolicy::SMI_HIDE); - } + void hide(); /// Passthrough function -- returns its input value - bool readOnly(bool ro = true) { - if (ro) { - input(ButtonPolicy::SMI_READ_ONLY); - } else { - input(ButtonPolicy::SMI_READ_WRITE); - } - return ro; - } + bool readOnly(bool ro = true); /// - void readWrite() { - readOnly(false); - } + void readWrite(); /// Passthrough function -- returns its input value - bool valid(bool v = true) { - if (v) { - input(ButtonPolicy::SMI_VALID); - } else { - input(ButtonPolicy::SMI_INVALID); - } - return v; - } + bool valid(bool v = true); /// - void invalid() { - valid(false); - } + void invalid(); private: /// ButtonPolicy * bp_; diff --git a/src/frontends/xforms/Dialogs.C b/src/frontends/xforms/Dialogs.C index 0892d444b5..f7603e3844 100644 --- a/src/frontends/xforms/Dialogs.C +++ b/src/frontends/xforms/Dialogs.C @@ -49,13 +49,23 @@ Dialogs::Dialogs(LyXView * lv) hideAll.connect(hideBufferDependent.slot()); } + Dialogs::~Dialogs() { +#if 0 + // I belive that this is unsafe... for (vector::iterator iter = dialogs_.begin(); iter != dialogs_.end(); ++iter) { delete *iter; } +#else + // I think this is better... + while (!dialogs_.empty()) { + delete dialogs_.back(); + dialogs_.erase(dialogs_.end() - 1); + } +#endif } diff --git a/src/frontends/xforms/FormBase.C b/src/frontends/xforms/FormBase.C index 1583e7f960..2adf40dbac 100644 --- a/src/frontends/xforms/FormBase.C +++ b/src/frontends/xforms/FormBase.C @@ -21,6 +21,18 @@ #include "FormBase.h" #include "LyXView.h" #include "xform_macros.h" +#include "support/LAssert.h" + +// The current scheme muddles debugging. +// Can we please use some other means to create these functions? +// I really don't like to use the preprossessor for this. +// My suggestion: First of all move these functions into their own +// file (that can be included here if wanted, and use m4 to expand +// that file. So create a m4 function to do the expansion, a file +// that contains the calls to to this function and a script to run +// it and create the C++ file with the expanded functions. (Lgb) +// Possible startoff point: +// define([C_RETURNCB],[extern "C" int C_$1$2(FL_FORM * ob, void * d) { return $1::$2(ob, d); }]) C_RETURNCB (FormBase, WMHideCB) C_GENERICCB(FormBase, ApplyCB) @@ -34,7 +46,9 @@ FormBase::FormBase(LyXView * lv, Dialogs * d, string const & t, ButtonPolicy * bp, char const * close, char const * cancel) : lv_(lv), bc_(bp, cancel, close), d_(d), h_(0), title(t), bp_(bp), minw_(0), minh_(0) -{} +{ + Assert(lv && d && bp); +} FormBase::~FormBase() @@ -88,9 +102,11 @@ void FormBase::hide() int FormBase::WMHideCB(FL_FORM * form, void *) { + Assert(form); // Ensure that the signals (u and h) are disconnected even if the // window manager is used to close the dialog. FormBase * pre = static_cast(form->u_vdata); + Assert(pre); pre->hide(); pre->bc_.hide(); return FL_CANCEL; @@ -99,7 +115,9 @@ int FormBase::WMHideCB(FL_FORM * form, void *) void FormBase::ApplyCB(FL_OBJECT * ob, long) { + Assert(ob && ob->form); FormBase * pre = static_cast(ob->form->u_vdata); + Assert(pre); pre->apply(); pre->bc_.apply(); } @@ -107,7 +125,9 @@ void FormBase::ApplyCB(FL_OBJECT * ob, long) void FormBase::OKCB(FL_OBJECT * ob, long) { + Assert(ob && ob->form); FormBase * pre = static_cast(ob->form->u_vdata); + Assert(pre); pre->ok(); pre->bc_.ok(); } @@ -115,7 +135,9 @@ void FormBase::OKCB(FL_OBJECT * ob, long) void FormBase::CancelCB(FL_OBJECT * ob, long) { + Assert(ob && ob->form); FormBase * pre = static_cast(ob->form->u_vdata); + Assert(pre); pre->cancel(); pre->bc_.cancel(); } @@ -123,14 +145,18 @@ void FormBase::CancelCB(FL_OBJECT * ob, long) void FormBase::InputCB(FL_OBJECT * ob, long data ) { + Assert(ob && ob->form); FormBase * pre = static_cast(ob->form->u_vdata); - pre->bc_.valid( pre->input( ob, data ) ); + Assert(ob); + pre->bc_.valid(pre->input(ob, data)); } void FormBase::RestoreCB(FL_OBJECT * ob, long) { + Assert(ob && ob->form); FormBase * pre = static_cast(ob->form->u_vdata); + Assert(ob); pre->restore(); pre->bc_.undoAll(); } @@ -140,7 +166,9 @@ FormBaseBI::FormBaseBI(LyXView * lv, Dialogs * d, string const & t, ButtonPolicy * bp, char const * close, char const * cancel) : FormBase( lv, d, t, bp, close, cancel ) -{} +{ + Assert(lv && d && bp); +} void FormBaseBI::connect() @@ -161,7 +189,9 @@ FormBaseBD::FormBaseBD(LyXView * lv, Dialogs * d, string const & t, char const * close, char const * cancel) : FormBase( lv, d, t, bp, close, cancel ), u_(0) -{} +{ + Assert(lv && d && bp); +} void FormBaseBD::connect() diff --git a/src/frontends/xforms/FormBase.h b/src/frontends/xforms/FormBase.h index 6ac0321f99..6819daa863 100644 --- a/src/frontends/xforms/FormBase.h +++ b/src/frontends/xforms/FormBase.h @@ -28,7 +28,8 @@ class LyXView; #endif /** This class is an XForms GUI base class. - It is meant to be used solely as the parent class to FormBaseBI and FormBaseBD + It is meant to be used solely as the parent class to FormBaseBI + and FormBaseBD. @author Angus Leeming */ class FormBase : public DialogBase, public noncopyable { diff --git a/src/frontends/xforms/FormDocument.C b/src/frontends/xforms/FormDocument.C index e05395849d..dbeb364216 100644 --- a/src/frontends/xforms/FormDocument.C +++ b/src/frontends/xforms/FormDocument.C @@ -108,15 +108,15 @@ void FormDocument::build() "| A4 small Margins (only portrait) " "| A4 very small Margins (only portrait) " "| A4 very wide margins (only portrait) ")); - fl_set_input_return(paper_->input_custom_width, FL_RETURN_ALWAYS); - fl_set_input_return(paper_->input_custom_height, FL_RETURN_ALWAYS); - fl_set_input_return(paper_->input_top_margin, FL_RETURN_ALWAYS); - fl_set_input_return(paper_->input_bottom_margin, FL_RETURN_ALWAYS); - fl_set_input_return(paper_->input_left_margin, FL_RETURN_ALWAYS); - fl_set_input_return(paper_->input_right_margin, FL_RETURN_ALWAYS); - fl_set_input_return(paper_->input_head_height, FL_RETURN_ALWAYS); - fl_set_input_return(paper_->input_head_sep, FL_RETURN_ALWAYS); - fl_set_input_return(paper_->input_foot_skip, FL_RETURN_ALWAYS); + fl_set_input_return(paper_->input_custom_width, FL_RETURN_CHANGED); + fl_set_input_return(paper_->input_custom_height, FL_RETURN_CHANGED); + fl_set_input_return(paper_->input_top_margin, FL_RETURN_CHANGED); + fl_set_input_return(paper_->input_bottom_margin, FL_RETURN_CHANGED); + fl_set_input_return(paper_->input_left_margin, FL_RETURN_CHANGED); + fl_set_input_return(paper_->input_right_margin, FL_RETURN_CHANGED); + fl_set_input_return(paper_->input_head_height, FL_RETURN_CHANGED); + fl_set_input_return(paper_->input_head_sep, FL_RETURN_CHANGED); + fl_set_input_return(paper_->input_foot_skip, FL_RETURN_CHANGED); bc_.addReadOnly (paper_->choice_paperpackage); bc_.addReadOnly (paper_->greoup_radio_orientation); @@ -170,8 +170,9 @@ void FormDocument::build() "default|empty|plain|headings|fancy"); fl_addto_choice(class_->choice_doc_skip, _(" Smallskip | Medskip | Bigskip | Length ")); - fl_set_input_return(class_->input_doc_skip, FL_RETURN_ALWAYS); - fl_set_input_return(class_->input_doc_spacing, FL_RETURN_ALWAYS); + fl_set_input_return(class_->input_doc_extra, FL_RETURN_CHANGED); + fl_set_input_return(class_->input_doc_skip, FL_RETURN_CHANGED); + fl_set_input_return(class_->input_doc_spacing, FL_RETURN_CHANGED); bc_.addReadOnly (class_->radio_doc_indent); bc_.addReadOnly (class_->radio_doc_skip); @@ -223,6 +224,7 @@ void FormDocument::build() // the document options form options_ = build_doc_options(); + fl_set_input_return(options_->input_float_placement, FL_RETURN_CHANGED); fl_set_counter_bounds(options_->slider_secnumdepth,-2,5); fl_set_counter_bounds(options_->slider_tocdepth,-1,5); fl_set_counter_step(options_->slider_secnumdepth,1,1); diff --git a/src/frontends/xforms/FormError.C b/src/frontends/xforms/FormError.C index b481b29d3a..96c40cc2f2 100644 --- a/src/frontends/xforms/FormError.C +++ b/src/frontends/xforms/FormError.C @@ -19,11 +19,14 @@ #include "FormError.h" #include "form_error.h" #include "insets/inseterror.h" +#include "support/LAssert.h" -FormError::FormError( LyXView * lv, Dialogs * d ) - : FormInset( lv, d, _("LaTeX Error") ), + +FormError::FormError(LyXView * lv, Dialogs * d) + : FormInset( lv, d, _("LaTeX Error")), dialog_(0), inset_(0) { + Assert(lv && d); // let the dialog be shown // This is a permanent connection so we won't bother // storing a copy because we won't be disconnecting. @@ -39,7 +42,7 @@ FormError::~FormError() FL_FORM * FormError::form() const { - if (dialog_ ) return dialog_->form; + if (dialog_) return dialog_->form; return 0; } @@ -52,9 +55,9 @@ void FormError::disconnect() } -void FormError::showInset( InsetError * inset ) +void FormError::showInset(InsetError * inset) { - if (inset == 0) return; + if (inset == 0) return; // Is this _really_ allowed? (Lgb) // If connected to another inset, disconnect from it. if (inset_) diff --git a/src/frontends/xforms/FormError.h b/src/frontends/xforms/FormError.h index 4211bc8981..b0b62e255b 100644 --- a/src/frontends/xforms/FormError.h +++ b/src/frontends/xforms/FormError.h @@ -34,7 +34,7 @@ private: virtual void disconnect(); /// Slot launching dialog to an existing inset - void showInset( InsetError * ); + void showInset(InsetError *); /// Update dialog before showing it virtual void update(); /// Build the dialog diff --git a/src/frontends/xforms/FormGraphics.C b/src/frontends/xforms/FormGraphics.C index c5d8083139..886e309ed6 100644 --- a/src/frontends/xforms/FormGraphics.C +++ b/src/frontends/xforms/FormGraphics.C @@ -56,7 +56,13 @@ FormGraphics::FormGraphics(LyXView * lv, Dialogs * d) FormGraphics::~FormGraphics() { - free(); + // Remove all associations for the radio buttons + widthButtons.reset(); + heightButtons.reset(); + displayButtons.reset(); + + // Free the form. + delete dialog_; } @@ -172,20 +178,6 @@ void FormGraphics::showDialog(InsetGraphics * inset) } -void FormGraphics::free() -{ - // Remove all associations for the radio buttons - widthButtons.reset(); - heightButtons.reset(); - displayButtons.reset(); - - - // Free the form. - delete dialog_; - dialog_ = 0; -} - - void FormGraphics::apply() { Assert(inset_ != 0); diff --git a/src/frontends/xforms/FormGraphics.h b/src/frontends/xforms/FormGraphics.h index ce3b853ce7..e9aeb9002a 100644 --- a/src/frontends/xforms/FormGraphics.h +++ b/src/frontends/xforms/FormGraphics.h @@ -86,8 +86,6 @@ private: /// Save the active inset and show the dialog. void showDialog(InsetGraphics *); - /// Explicitly free the dialog. - void free(); /// Verify that the input is correct. If not disable ok/apply buttons. bool checkInput(); /// Open the file browse dialog to select an image file. diff --git a/src/frontends/xforms/FormPreferences.C b/src/frontends/xforms/FormPreferences.C index 134a6c264c..0d5f1dc05d 100644 --- a/src/frontends/xforms/FormPreferences.C +++ b/src/frontends/xforms/FormPreferences.C @@ -38,20 +38,21 @@ using SigC::slot; #endif using std::find; +using std::find_if; using std::getline; using std::istream; using std::pair; +using std::sort; using std::vector; -using std::find_if; extern string fmt(char const * fmtstr ...); +extern string system_lyxdir; extern Languages languages; -typedef pair X11Colour; - -static vector colourDB; static string const colourFile("/usr/lib/X11/rgb.txt"); - +vector FormPreferences::colourDB; +pair, vector > FormPreferences::dirlist; + FormPreferences::FormPreferences(LyXView * lv, Dialogs * d) : FormBaseBI(lv, d, _("Preferences"), new PreferencesPolicy), dialog_(0), @@ -261,13 +262,7 @@ void FormPreferences::apply() void FormPreferences::feedback( FL_OBJECT * ob ) { - // Angus, do you really want to allow ob to be 0? - // You set this in feedbackPost. Why? - if (!ob) return; // stop a segfault below. - // an alternative to the above is to check feedbackObj in - // FeedbackCB and not call this function at all. But that's a - // matter of deciding who should be checking the parameters for this - // function. + if( !ob ) return; string str; @@ -307,6 +302,8 @@ void FormPreferences::feedback( FL_OBJECT * ob ) bool FormPreferences::input(FL_OBJECT * ob, long) { + Assert(ob); + // whatever checks you need to ensure the user hasn't entered // some totally ridiculous value somewhere. Change activate to suit. // comments before each test describe what is _valid_ @@ -357,8 +354,7 @@ void FormPreferences::buildColours() { colours_ = build_colours(); - FL_OBJECT *obj; - obj = colours_->valslider_red; + FL_OBJECT * obj = colours_->valslider_red; fl_set_slider_bounds(obj, 0, 255); fl_set_slider_precision(obj, 0); fl_set_slider_return(obj, FL_RETURN_END_CHANGED); @@ -389,14 +385,17 @@ void FormPreferences::buildColours() } -string const FormPreferences::feedbackColours( FL_OBJECT const * const ) const +string const +FormPreferences::feedbackColours(FL_OBJECT const * const ob) const { + Assert(ob); return string(); } bool FormPreferences::inputColours( FL_OBJECT const * const ob ) { + Assert(ob); bool activate = true; if (ob == colours_->browser_x11) { @@ -458,7 +457,7 @@ bool FormPreferences::ColoursLoadBrowser(string const & filename) // remove redundant entries on the fly bool add = cols.empty(); if (!add) { - vector::const_iterator it = + vector::const_iterator it = find( cols.begin(), cols.end(), col ); add = (it == cols.end()); } @@ -533,14 +532,14 @@ int FormPreferences::ColoursSearchEntry(RGB const & col) const } -void FormPreferences::ColoursUpdateBrowser( int i ) +void FormPreferences::ColoursUpdateBrowser(int i) { fl_freeze_form(colours_->form); RGB col = colourDB[i].second; - fl_mapcolor(FL_FREE_COL4+i, col.r, col.g, col.b); - fl_mapcolor(FL_FREE_COL4, col.r, col.g, col.b); + fl_mapcolor(FL_FREE_COL4 + i, col.r, col.g, col.b); + fl_mapcolor(FL_FREE_COL4, col.r, col.g, col.b); fl_set_slider_value(colours_->valslider_red, col.r); fl_set_slider_value(colours_->valslider_green, col.g); fl_set_slider_value(colours_->valslider_blue, col.b); @@ -562,11 +561,11 @@ void FormPreferences::ColoursUpdateRGB() fl_mapcolor(FL_FREE_COL4, col.r, col.g, col.b); fl_redraw_object(colours_->button_colour); - int i = ColoursSearchEntry( col ); + int const i = ColoursSearchEntry( col ); // change topline only if necessary // int top = fl_get_browser_topline(colours_->browser_x11); // if (i < top || i > (top+15)) - fl_set_browser_topline(colours_->browser_x11, i-5); + fl_set_browser_topline(colours_->browser_x11, i - 5); fl_select_browser_line(colours_->browser_x11, i + 1); fl_unfreeze_form(colours_->form); @@ -584,19 +583,47 @@ void FormPreferences::applyConverters() const void FormPreferences::buildConverters() { converters_ = build_converters(); - + + fl_set_input_return(converters_->input_converter, FL_RETURN_CHANGED); + fl_set_input_return(converters_->input_flags, FL_RETURN_CHANGED); + + updateConverters(); } string const -FormPreferences::feedbackConverters( FL_OBJECT const * const ) const +FormPreferences::feedbackConverters( FL_OBJECT const * const ob) const { + Assert(ob); return string(); } void FormPreferences::updateConverters() -{} +{ + vector commands = Converter::GetAllCommands(); + + vector names; + for(vector::const_iterator cit = commands.begin(); + cit != commands.end(); ++cit) { + string from = cit->from->prettyname; + string to = cit->to->prettyname; + string name = from + " -> " + to; + names.push_back(name); + } + sort(names.begin(), names.end()); + + fl_clear_browser(converters_->browser_converters); + for (vector::const_iterator cit = names.begin(); + cit != names.end(); ++cit) + fl_addto_browser(converters_->browser_converters, + cit->c_str()); + fl_deactivate_object(converters_->button_add); + fl_set_object_lcol(converters_->button_add, FL_INACTIVE); + + fl_deactivate_object(converters_->button_delete); + fl_set_object_lcol(converters_->button_delete, FL_INACTIVE); +} void FormPreferences::applyFormats() const @@ -625,20 +652,23 @@ void FormPreferences::buildFormats() fl_set_input_return(formats_->input_format, FL_RETURN_CHANGED); fl_set_input_return(formats_->input_viewer, FL_RETURN_CHANGED); + fl_set_input_return(formats_->input_shrtcut, FL_RETURN_CHANGED); fl_set_input_return(formats_->input_gui_name, FL_RETURN_CHANGED); fl_set_input_return(formats_->input_extension, FL_RETURN_CHANGED); fl_set_input_filter(formats_->input_format, fl_lowercase_filter); - formats_vec = formats.GetAllFormats(); - for (vector::const_iterator it = formats_vec.begin(); - it != formats_vec.end(); ++it) - fl_addto_browser(formats_->browser_formats, it->name.c_str()); + updateFormats(); } -string const FormPreferences::feedbackFormats( FL_OBJECT const * const ) const +string const +FormPreferences::feedbackFormats(FL_OBJECT const * const ob) const { + Assert(ob); + + //if( !ob ) return; + string str; return str; @@ -647,44 +677,260 @@ string const FormPreferences::feedbackFormats( FL_OBJECT const * const ) const bool FormPreferences::inputFormats(FL_OBJECT const * const ob) { + Assert(ob); + + //if( !ob ) return false; + if (ob == formats_->browser_formats) { - int i = fl_get_browser(formats_->browser_formats); - if (i > 0) { - Format const & f = formats_vec[i-1]; - fl_set_input(formats_->input_format, f.name.c_str()); - fl_set_input(formats_->input_gui_name, f.prettyname.c_str()); - fl_set_input(formats_->input_extension, f.extension.c_str()); - fl_set_input(formats_->input_viewer, f.viewer.c_str()); - } + FormatsInputBrowser(); + + } else if (ob == formats_->input_format) { + FormatsInputInput(); + } else if (ob == formats_->button_add) { - string name = fl_get_input(formats_->input_format); - string prettyname = fl_get_input(formats_->input_gui_name); - string extension = fl_get_input(formats_->input_extension); - string viewer = fl_get_input(formats_->input_viewer); - string shortcut; - if (prettyname.empty()) - return false; - Format format(name, extension, prettyname, shortcut, viewer); - vector::iterator it = find_if(formats_vec.begin(), - formats_vec.end(), - compare_memfun(&Format::getname, name)); - if (it == formats_vec.end()) { - formats_vec.push_back(format); - fl_add_browser_line(formats_->browser_formats, - name.c_str()); - } else { - //if (*it == format) - // return false; - *it = format; - } - return true; + FormatsInputAdd(); + + } else if (ob == formats_->button_delete) { + FormatsInputDelete(); } return true; } void FormPreferences::updateFormats() -{} +{ + formats_vec = formats.GetAllFormats(); + + vector names; + for (vector::const_iterator it = formats_vec.begin(); + it != formats_vec.end(); ++it) + names.push_back( it->name.c_str() ); + sort(names.begin(), names.end()); + + fl_clear_browser(formats_->browser_formats); + for (vector::const_iterator it = names.begin(); + it != names.end(); ++it) + fl_addto_browser(formats_->browser_formats, it->c_str()); + + fl_deactivate_object(formats_->button_add); + fl_set_object_lcol(formats_->button_add, FL_INACTIVE); + + fl_deactivate_object(formats_->button_delete); + fl_set_object_lcol(formats_->button_delete, FL_INACTIVE); +} + + +bool FormPreferences::FormatsInputAdd() +{ + string name = fl_get_input(formats_->input_format); + string prettyname = fl_get_input(formats_->input_gui_name); + string extension = fl_get_input(formats_->input_extension); + string viewer = fl_get_input(formats_->input_viewer); + string shortcut = fl_get_input(formats_->input_shrtcut); + if (prettyname.empty()) + return false; + + Format format(name, extension, prettyname, shortcut, viewer); + vector::iterator it = + find_if(formats_vec.begin(), formats_vec.end(), + compare_memfun(&Format::getname, name)); + + if (it == formats_vec.end()) { + fl_freeze_form(formats_->form); + + formats_vec.push_back(format); + + vector names; + for (vector::const_iterator it = formats_vec.begin(); + it != formats_vec.end(); ++it) + names.push_back( it->name.c_str() ); + + sort( names.begin(), names.end() ); + + fl_clear_browser( formats_->browser_formats ); + for (vector::const_iterator it = names.begin(); + it != names.end(); ++it) + fl_addto_browser(formats_->browser_formats, + it->c_str()); + + fl_set_input(formats_->input_format, ""); + fl_set_input(formats_->input_gui_name, ""); + fl_set_input(formats_->input_shrtcut, ""); + fl_set_input(formats_->input_extension, ""); + fl_set_input(formats_->input_viewer, ""); + + fl_set_object_label( formats_->button_add, + idex(_("Add|#A")) ); + fl_set_button_shortcut( formats_->button_add, + scex(_("Add|#A")), 1); + + fl_deactivate_object(formats_->button_add); + fl_set_object_lcol(formats_->button_add, FL_INACTIVE); + + fl_deactivate_object(formats_->button_delete); + fl_set_object_lcol(formats_->button_delete, FL_INACTIVE); + + fl_unfreeze_form(formats_->form); + + } else { + //if (*it == format) + // return false; + *it = format; + } + return true; +} + + +bool FormPreferences::FormatsInputDelete() +{ + string name = fl_get_input(formats_->input_format); + vector::iterator it = + find_if(formats_vec.begin(), formats_vec.end(), + compare_memfun(&Format::getname, name)); + + fl_freeze_form(formats_->form); + + if (it == formats_vec.end()) { + fl_deactivate_object(formats_->button_delete); + fl_set_object_lcol(formats_->button_delete, FL_INACTIVE); + + } else { + int sel = 0; + for( int i = 0; + i < fl_get_browser_maxline(formats_->browser_formats); + ++i ) { + string str = fl_get_browser_line( formats_->browser_formats, i+1 ); + if( str == name ) { + sel = i+1; + break; + } + } + + if( sel != 0 ) { + fl_delete_browser_line(formats_->browser_formats, sel ); + + fl_set_input(formats_->input_format, ""); + fl_set_input(formats_->input_gui_name, ""); + fl_set_input(formats_->input_shrtcut, ""); + fl_set_input(formats_->input_extension, ""); + fl_set_input(formats_->input_viewer, ""); + + fl_set_object_label( formats_->button_add, + idex(_("Add|#A")) ); + fl_set_button_shortcut( formats_->button_add, + scex(_("Add|#A")), 1); + + fl_deactivate_object(formats_->button_add); + fl_set_object_lcol(formats_->button_add, FL_INACTIVE); + + fl_deactivate_object(formats_->button_delete); + fl_set_object_lcol(formats_->button_delete, + FL_INACTIVE); + } + } + + fl_unfreeze_form(formats_->form); + + return true; +} + + +bool FormPreferences::FormatsInputBrowser() +{ + int const i = fl_get_browser(formats_->browser_formats); + if( i <= 0 ) return true; + + string name = fl_get_browser_line(formats_->browser_formats, i); + vector::iterator it = + find_if(formats_vec.begin(), formats_vec.end(), + compare_memfun(&Format::getname, name)); + + if (it != formats_vec.end()) { + fl_freeze_form(formats_->form); + + fl_set_input(formats_->input_format, it->name.c_str()); + fl_set_input(formats_->input_gui_name, it->prettyname.c_str()); + fl_set_input(formats_->input_shrtcut, it->shortcut.c_str()); + fl_set_input(formats_->input_extension, it->extension.c_str()); + fl_set_input(formats_->input_viewer, it->viewer.c_str()); + + fl_set_object_label( formats_->button_add, + idex(_("Modify|#M")) ); + fl_set_button_shortcut( formats_->button_add, + scex(_("Modify|#M")), 1); + + fl_activate_object(formats_->button_add); + fl_set_object_lcol(formats_->button_add, FL_BLACK); + + fl_activate_object(formats_->button_delete); + fl_set_object_lcol(formats_->button_delete, FL_BLACK); + + fl_unfreeze_form(formats_->form); + } + return true; +} + + +bool FormPreferences::FormatsInputInput() +{ + string const name = fl_get_input(formats_->input_format); + vector::iterator it = + find_if(formats_vec.begin(), formats_vec.end(), + compare_memfun(&Format::getname, name)); + + fl_freeze_form(formats_->form); + + if (it == formats_vec.end()) { + fl_set_object_label( formats_->button_add, + idex(_("Add|#A")) ); + fl_set_button_shortcut( formats_->button_add, + scex(_("Add|#A")), 1); + + if( name.empty() ) { + fl_deactivate_object(formats_->button_add); + fl_set_object_lcol(formats_->button_add, FL_INACTIVE); + } else { + fl_activate_object(formats_->button_add); + fl_set_object_lcol(formats_->button_add, FL_BLACK); + } + + fl_deselect_browser(formats_->browser_formats); + + fl_deactivate_object(formats_->button_delete); + fl_set_object_lcol(formats_->button_delete, FL_INACTIVE); + + } else { + fl_set_object_label( formats_->button_add, + idex(_("Modify|#M")) ); + fl_set_button_shortcut( formats_->button_add, + scex(_("Modify|#M")), 1); + + int sel = 0; + for( int i = 0; + i < fl_get_browser_maxline(formats_->browser_formats); + ++i ) { + string str = fl_get_browser_line( formats_->browser_formats, i+1 ); + if( str == name ) { + sel = i+1; + break; + } + } + + int top = sel - 6; + if( top < 1 ) top = 0; + fl_set_browser_topline(formats_->browser_formats, top); + fl_select_browser_line(formats_->browser_formats, sel); + + fl_activate_object(formats_->button_add); + fl_set_object_lcol(formats_->button_add, FL_BLACK); + + fl_activate_object(formats_->button_delete); + fl_set_object_lcol(formats_->button_delete, FL_BLACK); + } + + fl_unfreeze_form(formats_->form); + return true; +} void FormPreferences::applyInputsMisc() const @@ -713,6 +959,10 @@ void FormPreferences::buildInputsMisc() string const FormPreferences::feedbackInputsMisc(FL_OBJECT const * const ob) const { + Assert(ob); + + //if( !ob ) return string(); + string str; if (ob == inputs_misc_->input_date_format ) @@ -779,6 +1029,10 @@ void FormPreferences::buildInterface() string const FormPreferences::feedbackInterface( FL_OBJECT const * const ob ) const { + Assert(ob); + + //if( !ob ) return string(); + string str; if (ob == interface_->input_popup_font ) @@ -815,16 +1069,28 @@ void FormPreferences::updateInterface() } -void FormPreferences::applyLanguage() const +void FormPreferences::applyLanguage() { lyxrc.default_language = combo_default_lang->getline(); int button = fl_get_button(language_->check_use_kbmap); + string name_1 = combo_kbmap_1->getline(); + string name_2 = combo_kbmap_2->getline(); + if( button ) + button = ( !name_1.empty() && !name_2.empty() ); lyxrc.use_kbmap = static_cast(button); if (button) { - lyxrc.primary_kbmap = combo_kbmap_1->getline(); - lyxrc.secondary_kbmap = combo_kbmap_2->getline(); + vector::iterator it = + find( dirlist.second.begin(), dirlist.second.end(), + name_1 ); + vector::size_type sel = it - dirlist.second.begin(); + lyxrc.primary_kbmap = dirlist.first[sel]; + + it = find( dirlist.second.begin(), dirlist.second.end(), + name_2 ); + sel = it - dirlist.second.begin(); + lyxrc.secondary_kbmap = dirlist.first[sel]; } button = fl_get_button(language_->check_rtl_support); @@ -842,6 +1108,9 @@ void FormPreferences::applyLanguage() const lyxrc.language_package = fl_get_input(language_->input_package); lyxrc.language_command_begin = fl_get_input(language_->input_command_begin); lyxrc.language_command_end = fl_get_input(language_->input_command_end); + + // Ensure that all is self-consistent. + updateLanguage(); } @@ -863,17 +1132,28 @@ void FormPreferences::buildLanguage() combo_default_lang->add(obj->x, obj->y, obj->w, obj->h, 400); combo_default_lang->shortcut("#L",1); combo_default_lang->setcallback(ComboLanguageCB, this); - LanguagesAdd( *combo_default_lang ); - + + for (Languages::const_iterator cit = languages.begin(); + cit != languages.end(); cit++) { + combo_default_lang->addto((*cit).second.lang()); + } + // ditto kbmap_1 + string dir = AddPath(system_lyxdir, "kbd"); + vector dirlist = DirList(dir , "kmap"); + obj = language_->choice_kbmap_1; fl_deactivate_object(language_->choice_kbmap_1); combo_kbmap_1 = new Combox(FL_COMBOX_DROPLIST); combo_kbmap_1->add(obj->x, obj->y, obj->w, obj->h, 400); combo_kbmap_1->shortcut("#1",1); combo_kbmap_1->setcallback(ComboLanguageCB, this); - LanguagesAdd( *combo_kbmap_1 ); - + + for (vector::const_iterator cit = dirlist.begin(); + cit != dirlist.end(); cit++) { + combo_kbmap_1->addto(*cit); + } + // ditto kbmap_2 obj = language_->choice_kbmap_2; fl_deactivate_object(language_->choice_kbmap_2); @@ -881,7 +1161,11 @@ void FormPreferences::buildLanguage() combo_kbmap_2->add(obj->x, obj->y, obj->w, obj->h, 400); combo_kbmap_2->shortcut("#2",1); combo_kbmap_2->setcallback(ComboLanguageCB, this); - LanguagesAdd( *combo_kbmap_2 ); + + for (vector::const_iterator cit = dirlist.begin(); + cit != dirlist.end(); cit++) { + combo_kbmap_2->addto(*cit); + } fl_end_form(); fl_unfreeze_form(language_->form); @@ -906,12 +1190,20 @@ void FormPreferences::buildLanguage() setPostHandler( language_->input_command_end ); fl_end_form(); + + // Activate/Deactivate the input fields dependent on the state of the + // buttons. + inputLanguage( 0 ); } string const FormPreferences::feedbackLanguage(FL_OBJECT const * const ob) const { + Assert(ob); + + //if( !ob ) return string(); + string str; if (reinterpret_cast(ob) == combo_default_lang ) @@ -967,11 +1259,21 @@ void FormPreferences::updateLanguage() combo_default_lang->select_text( lyxrc.default_language ); if (lyxrc.use_kbmap) { - combo_kbmap_1->select_text( lyxrc.primary_kbmap ); - combo_kbmap_2->select_text( lyxrc.secondary_kbmap ); + string fullpath = lyxrc.primary_kbmap; + vector::iterator it = + find( dirlist.first.begin(), dirlist.first.end(), + fullpath ); + vector::size_type sel = it - dirlist.first.begin(); + combo_kbmap_1->select_text( dirlist.second[sel] ); + + fullpath = lyxrc.secondary_kbmap; + it = find( dirlist.first.begin(), dirlist.first.end(), + fullpath ); + sel = it - dirlist.first.begin(); + combo_kbmap_2->select_text( dirlist.second[sel] ); } else { - combo_kbmap_1->select_text( lyxrc.default_language ); - combo_kbmap_2->select_text( lyxrc.default_language ); + combo_kbmap_1->select_text( "" ); + combo_kbmap_2->select_text( "" ); } fl_set_button(language_->check_rtl_support, lyxrc.rtl_support); @@ -993,15 +1295,6 @@ void FormPreferences::updateLanguage() } -void FormPreferences::LanguagesAdd( Combox & combo ) const -{ - for (Languages::const_iterator cit = languages.begin(); - cit != languages.end(); cit++) { - combo.addto((*cit).second.lang()); - } -} - - void FormPreferences::applyLnFmisc() const { lyxrc.show_banner = fl_get_button(lnf_misc_->check_banner); @@ -1009,7 +1302,7 @@ void FormPreferences::applyLnFmisc() const check_auto_region_delete); lyxrc.exit_confirmation = fl_get_button(lnf_misc_->check_exit_confirm); lyxrc.display_shortcuts = - fl_get_button(lnf_misc_->check_display_shortcuts); + fl_get_button(lnf_misc_->check_display_shrtcuts); lyxrc.new_ask_filename = fl_get_button(lnf_misc_->check_ask_new_file); lyxrc.cursor_follows_scrollbar = fl_get_button(lnf_misc_->check_cursor_follows_scrollbar); @@ -1035,7 +1328,7 @@ void FormPreferences::buildLnFmisc() setPostHandler( lnf_misc_->check_banner ); setPostHandler( lnf_misc_->check_auto_region_delete ); setPostHandler( lnf_misc_->check_exit_confirm ); - setPostHandler( lnf_misc_->check_display_shortcuts ); + setPostHandler( lnf_misc_->check_display_shrtcuts ); setPostHandler( lnf_misc_->counter_autosave ); setPostHandler( lnf_misc_->check_ask_new_file ); setPostHandler( lnf_misc_->check_cursor_follows_scrollbar ); @@ -1047,6 +1340,10 @@ void FormPreferences::buildLnFmisc() string const FormPreferences::feedbackLnFmisc(FL_OBJECT const * const ob) const { + Assert(ob); + + //if( !ob ) return string(); + string str; if (ob == lnf_misc_->check_banner ) @@ -1055,7 +1352,7 @@ string const FormPreferences::feedbackLnFmisc(FL_OBJECT const * const ob) const str = lyxrc.getDescription( LyXRC::RC_AUTOREGIONDELETE ); else if (ob == lnf_misc_->check_exit_confirm ) str = lyxrc.getDescription( LyXRC::RC_EXIT_CONFIRMATION ); - else if (ob == lnf_misc_->check_display_shortcuts ) + else if (ob == lnf_misc_->check_display_shrtcuts ) str = lyxrc.getDescription( LyXRC::RC_DISPLAY_SHORTCUTS ); else if (ob == lnf_misc_->check_ask_new_file ) str = lyxrc.getDescription( LyXRC::RC_NEW_ASK_FILENAME ); @@ -1078,7 +1375,7 @@ void FormPreferences::updateLnFmisc() lyxrc.auto_region_delete); fl_set_button(lnf_misc_->check_exit_confirm, lyxrc.exit_confirmation); - fl_set_button(lnf_misc_->check_display_shortcuts, + fl_set_button(lnf_misc_->check_display_shrtcuts, lyxrc.display_shortcuts); fl_set_button(lnf_misc_->check_ask_new_file, lyxrc.new_ask_filename); @@ -1137,6 +1434,10 @@ void FormPreferences::buildOutputsMisc() string const FormPreferences::feedbackOutputsMisc(FL_OBJECT const * const ob) const { + Assert(ob); + + //if( !ob ) return string(); + string str; if (ob == outputs_misc_->counter_line_len ) @@ -1256,6 +1557,10 @@ void FormPreferences::buildPaths() string const FormPreferences::feedbackPaths( FL_OBJECT const * const ob ) const { + Assert(ob); + + //if( !ob ) return string(); + string str; if (ob == paths_->input_default_path ) @@ -1285,6 +1590,10 @@ string const FormPreferences::feedbackPaths( FL_OBJECT const * const ob ) const bool FormPreferences::inputPaths( FL_OBJECT const * const ob ) { + // what kind of coding is this? Do you plan for a ob == NULL? + // When is that allowed? (Lgb) + //Assert(ob); + bool activate = true; if (!ob || ob == paths_->check_use_temp_dir) { @@ -1439,8 +1748,13 @@ void FormPreferences::applyPrinter() const } -string const FormPreferences::feedbackPrinter(FL_OBJECT const * const ob) const +string const +FormPreferences::feedbackPrinter(FL_OBJECT const * const ob) const { + Assert(ob); + + //if( !ob ) return string(); + string str; if (ob == printer_->input_command ) @@ -1761,6 +2075,10 @@ void FormPreferences::buildScreenFonts() string const FormPreferences::feedbackScreenFonts(FL_OBJECT const * const ob ) const { + Assert(ob); + + //if( !ob ) return string(); + string str; if (ob == screen_fonts_->input_roman ) @@ -1992,6 +2310,10 @@ void FormPreferences::buildSpellchecker() string const FormPreferences::feedbackSpellChecker(FL_OBJECT const * const ob) const { + Assert(ob); + + //if( !ob ) return string(); + string str; if (ob == spellchecker_->choice_spell_command ) @@ -2019,6 +2341,8 @@ FormPreferences::feedbackSpellChecker(FL_OBJECT const * const ob) const bool FormPreferences::inputSpellChecker( FL_OBJECT const * const ob ) { + // ditto ob! (Lgb) + // Allow/dissallow input // If spell checker == "none", disable all input. @@ -2093,7 +2417,7 @@ void FormPreferences::updateSpellChecker() choice = 3; fl_set_choice(spellchecker_->choice_spell_command, choice); - string str = string(); + string str; if (lyxrc.isp_use_alt_lang ) str = lyxrc.isp_alt_lang; fl_set_button(spellchecker_->check_alt_lang, @@ -2125,7 +2449,7 @@ void FormPreferences::updateSpellChecker() } -bool FormPreferences::WriteableDir( string const & name ) const +bool FormPreferences::WriteableDir(string const & name) const { bool success = true; string str; @@ -2155,7 +2479,7 @@ bool FormPreferences::WriteableDir( string const & name ) const } -bool FormPreferences::ReadableDir( string const & name ) const +bool FormPreferences::ReadableDir(string const & name) const { bool success = true; string str; @@ -2207,8 +2531,8 @@ bool FormPreferences::WriteableFile(string const & name, str = N_("WARNING! The absolute path is required."); } - // This is not a nice way to use FileInfo (Lgb) #if 0 + // This is not a nice way to use FileInfo (Lgb) FileInfo d; { @@ -2258,10 +2582,11 @@ bool FormPreferences::WriteableFile(string const & name, void FormPreferences::ComboLanguageCB(int, void * v, Combox * combox) { - FormPreferences * pre = static_cast(v); - // This is safe, as nothing is done to the pointer, other than - // to use its address in a block-if statement. - pre->bc_.valid( pre->input( reinterpret_cast(combox), 0 )); + Assert(v && combox); + FormPreferences * pre = static_cast(v); + // This is safe, as nothing is done to the pointer, other than + // to use its address in a block-if statement. + pre->bc_.valid(pre->input(reinterpret_cast(combox), 0)); } @@ -2271,8 +2596,14 @@ C_GENERICCB(FormPreferences, FeedbackCB) void FormPreferences::FeedbackCB(FL_OBJECT * ob, long) { + Assert(ob); + + //if( !ob ) return; + FormPreferences * pre = static_cast(ob->form->u_vdata); + Assert(pre); + pre->feedback( pre->feedbackObj ); } @@ -2284,6 +2615,7 @@ int C_FormPreferencesFeedbackPost(FL_OBJECT * ob, int event, // can occur when form is being deleted. This seems an easier fix than // a call "fl_set_object_posthandler(ob, 0)" for each and every object // in the destructor. + if (!ob ) return 0; if (!ob->form ) return 0; FormPreferences * pre = @@ -2296,8 +2628,12 @@ int C_FormPreferencesFeedbackPost(FL_OBJECT * ob, int event, // post_handler for feedback messages void FormPreferences::feedbackPost(FL_OBJECT * ob, int event) { + Assert(ob); + + //if( !ob ) return; + // We do not test for empty help here, since this can never happen - if (event == FL_ENTER){ + if (event == FL_ENTER) { // Used as a placeholder for ob, so that we don't have to // a horrible reinterpret_cast to long and pass it as an // argument in fl_set_object_callback. @@ -2306,8 +2642,7 @@ void FormPreferences::feedbackPost(FL_OBJECT * ob, int event) C_FormPreferencesFeedbackCB, 0); fl_set_timer(dialog_->timer_feedback, 0.5); - } - else if (event != FL_MOTION){ + } else if (event != FL_MOTION) { fl_set_timer(dialog_->timer_feedback, 0); feedbackObj = 0; fl_set_object_label(dialog_->text_warning, ""); @@ -2317,5 +2652,9 @@ void FormPreferences::feedbackPost(FL_OBJECT * ob, int event) void FormPreferences::setPostHandler(FL_OBJECT * ob) const { + Assert(ob); + + //if( !ob ) return; + fl_set_object_posthandler(ob, C_FormPreferencesFeedbackPost); } diff --git a/src/frontends/xforms/FormPreferences.h b/src/frontends/xforms/FormPreferences.h index 538946d363..f855cf0d80 100644 --- a/src/frontends/xforms/FormPreferences.h +++ b/src/frontends/xforms/FormPreferences.h @@ -58,6 +58,7 @@ public: /// void feedbackPost(FL_OBJECT *, int); +private: /// helper struct for Colours struct RGB { int r; @@ -66,8 +67,13 @@ public: RGB() : r(0), g(0), b(0) {} RGB(int red, int green, int blue) : r(red), g(green), b(blue) {} }; + /// + friend bool operator==(RGB const &, RGB const &); + /// + friend bool operator!=(RGB const &, RGB const &); + /// + typedef std::pair X11Colour; -private: /// Update the dialog. virtual void update(); /// @@ -99,7 +105,7 @@ private: /// void applyInterface() const; /// - void applyLanguage() const; + void applyLanguage(); // not const because calls updateLanguage! /// void applyLnFmisc() const; /// @@ -216,8 +222,6 @@ private: /** Some helper functions for specific folders. */ - /// - void LanguagesAdd( Combox & ) const; /// bool ColoursLoadBrowser( string const & ); /// @@ -226,6 +230,14 @@ private: void ColoursUpdateBrowser( int ); /// void ColoursUpdateRGB(); + /// + bool FormatsInputAdd(); + /// + bool FormatsInputBrowser(); + /// + bool FormatsInputDelete(); + /// + bool FormatsInputInput(); /// bool WriteableDir( string const & ) const; @@ -308,14 +320,21 @@ private: Combox * combo_kbmap_1; /// Combox * combo_kbmap_2; - /// + /// FL_OBJECT * feedbackObj; - /// + + /// A vector of Formats, to be manipulated in the Format browser. std::vector formats_vec; - + /// A vector of RGB colours and associated name. + static std::vector colourDB; + /** A collection of kmap files. + First entry is the file name, full path. + Second entry is the shorthand, as appears in the fl_choice. + Eg, system_lyxdir/kbd/american2.kmap, american2 + */ + static std::pair, std::vector > dirlist; }; - inline bool operator==(FormPreferences::RGB const & c1, FormPreferences::RGB const & c2) diff --git a/src/frontends/xforms/Makefile.am b/src/frontends/xforms/Makefile.am index cb0f918656..55519e774f 100644 --- a/src/frontends/xforms/Makefile.am +++ b/src/frontends/xforms/Makefile.am @@ -12,6 +12,7 @@ LYXDATADIRS = forms ETAGS_ARGS = --lang=c++ # Alphabetical order please. It makes it easier to figure out what's missing. libxforms_la_SOURCES = \ + ButtonController.C \ ButtonController.h \ Dialogs.C \ GUIRunTime.C \ diff --git a/src/frontends/xforms/form_preferences.C b/src/frontends/xforms/form_preferences.C index a54d23642c..edb737a1e3 100644 --- a/src/frontends/xforms/form_preferences.C +++ b/src/frontends/xforms/form_preferences.C @@ -27,7 +27,6 @@ FD_form_preferences * FormPreferences::build_preferences() obj = fl_add_box(FL_UP_BOX, 0, 0, 470, 500, ""); fdui->tabfolder_prefs = obj = fl_add_tabfolder(FL_TOP_TABFOLDER, 5, 10, 455, 375, ""); fl_set_object_boxtype(obj, FL_FLAT_BOX); - fl_set_object_color(obj, FL_BOTTOM_BCOL, FL_COL1); fdui->button_apply = obj = fl_add_button(FL_NORMAL_BUTTON, 270, 390, 90, 30, idex(_("Apply|#A"))); fl_set_button_shortcut(obj, scex(_("Apply|#A")), 1); fl_set_object_lsize(obj, FL_NORMAL_SIZE); @@ -72,7 +71,6 @@ FD_form_outer_tab * FormPreferences::build_outer_tab() obj = fl_add_box(FL_FLAT_BOX, 0, 0, 455, 375, ""); fdui->tabfolder_outer = obj = fl_add_tabfolder(FL_TOP_TABFOLDER, 0, 0, 455, 375, ""); fl_set_object_boxtype(obj, FL_FLAT_BOX); - fl_set_object_color(obj, FL_BOTTOM_BCOL, FL_COL1); fl_end_form(); fdui->form->fdui = fdui; @@ -413,22 +411,22 @@ FD_form_colours * FormPreferences::build_colours() fl_set_button_shortcut(obj, scex(_("Browse|#B")), 1); fl_set_object_lsize(obj, FL_NORMAL_SIZE); fl_set_object_callback(obj, C_FormBaseInputCB, 0); - fdui->button_colour = obj = fl_add_button(FL_NORMAL_BUTTON, 290, 230, 150, 30, ""); + fdui->button_colour = obj = fl_add_button(FL_NORMAL_BUTTON, 180, 230, 90, 30, ""); fl_set_object_boxtype(obj, FL_BORDER_BOX); fl_set_object_color(obj, FL_WHITE, FL_COL1); - fdui->valslider_red = obj = fl_add_valslider(FL_VERT_FILL_SLIDER, 180, 25, 30, 235, idex(_("R|#R"))); + fdui->valslider_red = obj = fl_add_valslider(FL_VERT_FILL_SLIDER, 180, 25, 30, 200, idex(_("R|#R"))); fl_set_button_shortcut(obj, scex(_("R|#R")), 1); fl_set_object_color(obj, FL_COL1, FL_RED); fl_set_object_lalign(obj, FL_ALIGN_TOP); fl_set_object_callback(obj, C_FormBaseInputCB, 0); fl_set_slider_size(obj, 0.15); - fdui->valslider_green = obj = fl_add_valslider(FL_VERT_FILL_SLIDER, 210, 25, 30, 235, idex(_("G|#G"))); + fdui->valslider_green = obj = fl_add_valslider(FL_VERT_FILL_SLIDER, 210, 25, 30, 200, idex(_("G|#G"))); fl_set_button_shortcut(obj, scex(_("G|#G")), 1); fl_set_object_color(obj, FL_COL1, FL_GREEN); fl_set_object_lalign(obj, FL_ALIGN_TOP); fl_set_object_callback(obj, C_FormBaseInputCB, 0); fl_set_slider_size(obj, 0.15); - fdui->valslider_blue = obj = fl_add_valslider(FL_VERT_FILL_SLIDER, 240, 25, 30, 235, idex(_("B|#B"))); + fdui->valslider_blue = obj = fl_add_valslider(FL_VERT_FILL_SLIDER, 240, 25, 30, 200, idex(_("B|#B"))); fl_set_button_shortcut(obj, scex(_("B|#B")), 1); fl_set_object_color(obj, FL_COL1, FL_BLUE); fl_set_object_lalign(obj, FL_ALIGN_TOP); @@ -439,6 +437,10 @@ FD_form_colours * FormPreferences::build_colours() fl_set_object_lsize(obj, FL_NORMAL_SIZE); fl_set_object_lalign(obj, FL_ALIGN_TOP); fl_set_object_callback(obj, C_FormBaseInputCB, 0); + fdui->button_modify = obj = fl_add_button(FL_NORMAL_BUTTON, 350, 230, 90, 30, idex(_("Modify|#M"))); + fl_set_button_shortcut(obj, scex(_("Modify|#M")), 1); + fl_set_object_lsize(obj, FL_NORMAL_SIZE); + fl_set_object_callback(obj, C_FormBaseInputCB, 0); fl_end_form(); fdui->form->fdui = fdui; @@ -487,6 +489,10 @@ FD_form_converters * FormPreferences::build_converters() fl_set_button_shortcut(obj, scex(_("To|#T")), 1); fl_set_object_boxtype(obj, FL_FRAME_BOX); fl_set_object_callback(obj, C_FormBaseInputCB, 0); + fdui->input_flags = obj = fl_add_input(FL_NORMAL_INPUT, 280, 150, 150, 30, idex(_("Flags|#F"))); + fl_set_button_shortcut(obj, scex(_("Flags|#F")), 1); + fl_set_object_lsize(obj, FL_NORMAL_SIZE); + fl_set_object_callback(obj, C_FormBaseInputCB, 0); fl_end_form(); fdui->form->fdui = fdui; @@ -531,14 +537,18 @@ FD_form_formats * FormPreferences::build_formats() fl_set_button_shortcut(obj, scex(_("Add|#A")), 1); fl_set_object_lsize(obj, FL_NORMAL_SIZE); fl_set_object_callback(obj, C_FormBaseInputCB, 0); - fdui->input_extension = obj = fl_add_input(FL_NORMAL_INPUT, 280, 110, 150, 30, idex(_("Extension|#E"))); + fdui->input_extension = obj = fl_add_input(FL_NORMAL_INPUT, 280, 150, 150, 30, idex(_("Extension|#E"))); fl_set_button_shortcut(obj, scex(_("Extension|#E")), 1); fl_set_object_lsize(obj, FL_NORMAL_SIZE); fl_set_object_callback(obj, C_FormBaseInputCB, 0); - fdui->input_viewer = obj = fl_add_input(FL_NORMAL_INPUT, 280, 150, 150, 30, idex(_("Viewer|#V"))); + fdui->input_viewer = obj = fl_add_input(FL_NORMAL_INPUT, 280, 190, 150, 30, idex(_("Viewer|#V"))); fl_set_button_shortcut(obj, scex(_("Viewer|#V")), 1); fl_set_object_lsize(obj, FL_NORMAL_SIZE); fl_set_object_callback(obj, C_FormBaseInputCB, 0); + fdui->input_shrtcut = obj = fl_add_input(FL_NORMAL_INPUT, 280, 110, 150, 30, idex(_("Shortcut|#S"))); + fl_set_button_shortcut(obj, scex(_("Shortcut|#S")), 1); + fl_set_object_lsize(obj, FL_NORMAL_SIZE); + fl_set_object_callback(obj, C_FormBaseInputCB, 0); fl_end_form(); fdui->form->fdui = fdui; @@ -577,7 +587,7 @@ FD_form_lnf_misc * FormPreferences::build_lnf_misc() fl_set_object_lsize(obj, FL_NORMAL_SIZE); fl_set_object_callback(obj, C_FormBaseInputCB, 0); fl_set_button(obj, 1); - fdui->check_display_shortcuts = obj = fl_add_checkbutton(FL_PUSH_BUTTON, 15, 105, 310, 30, _("Display keyboard shortcuts")); + fdui->check_display_shrtcuts = obj = fl_add_checkbutton(FL_PUSH_BUTTON, 15, 105, 310, 30, _("Display keyboard shortcuts")); fl_set_object_lsize(obj, FL_NORMAL_SIZE); fl_set_object_callback(obj, C_FormBaseInputCB, 0); fl_set_button(obj, 1); diff --git a/src/frontends/xforms/form_preferences.h b/src/frontends/xforms/form_preferences.h index 38a8d08af7..83ae9de509 100644 --- a/src/frontends/xforms/form_preferences.h +++ b/src/frontends/xforms/form_preferences.h @@ -136,6 +136,7 @@ struct FD_form_colours { FL_OBJECT *valslider_green; FL_OBJECT *valslider_blue; FL_OBJECT *browser_lyx_objs; + FL_OBJECT *button_modify; }; struct FD_form_converters { ~FD_form_converters(); @@ -147,6 +148,7 @@ struct FD_form_converters { FL_OBJECT *input_converter; FL_OBJECT *choice_from; FL_OBJECT *choice_to; + FL_OBJECT *input_flags; }; struct FD_form_formats { ~FD_form_formats(); @@ -159,6 +161,7 @@ struct FD_form_formats { FL_OBJECT *button_add; FL_OBJECT *input_extension; FL_OBJECT *input_viewer; + FL_OBJECT *input_shrtcut; }; struct FD_form_lnf_misc { ~FD_form_lnf_misc(); @@ -167,7 +170,7 @@ struct FD_form_lnf_misc { FL_OBJECT *check_banner; FL_OBJECT *check_auto_region_delete; FL_OBJECT *check_exit_confirm; - FL_OBJECT *check_display_shortcuts; + FL_OBJECT *check_display_shrtcuts; FL_OBJECT *counter_autosave; FL_OBJECT *check_ask_new_file; FL_OBJECT *check_cursor_follows_scrollbar; diff --git a/src/frontends/xforms/input_validators.c b/src/frontends/xforms/input_validators.c index 5acafa6fec..9f050030e5 100644 --- a/src/frontends/xforms/input_validators.c +++ b/src/frontends/xforms/input_validators.c @@ -33,7 +33,7 @@ int fl_lowercase_filter(FL_OBJECT * ob, int c) { if (c == 0 /* final test before handing contents to app */ - || strchr("abcdefghijklmnopqrstuvwxyz", c)) { + || strchr("abcdefghijklmnopqrstuvwxyz0123456789", c)) { /* since we only accept numerals then it must be valid */ return FL_VALID; } diff --git a/src/graphics/GraphicsCacheItem_pimpl.C b/src/graphics/GraphicsCacheItem_pimpl.C index d4e83b6211..42d7aca00d 100644 --- a/src/graphics/GraphicsCacheItem_pimpl.C +++ b/src/graphics/GraphicsCacheItem_pimpl.C @@ -107,7 +107,7 @@ GraphicsCacheItem_pimpl::renderXPM(string const & filename) temp = ChangeExtension(filename, string()); // Add some stuff to have it a unique temp file. - xpmfile = TmpFileName(string(), temp); + xpmfile = lyx::tempName(string(), temp); //TmpFileName(string(), temp); xpmfile = ChangeExtension(xpmfile, ".xpm"); command += xpmfile; diff --git a/src/insets/ExternalTemplate.C b/src/insets/ExternalTemplate.C index ffcdd43305..a323f8a0cd 100644 --- a/src/insets/ExternalTemplate.C +++ b/src/insets/ExternalTemplate.C @@ -19,8 +19,10 @@ #include "ExternalTemplate.h" #include "lyxlex.h" +#include "debug.h" #include "support/path.h" #include "support/LAssert.h" +#include "support/filetools.h" using std::endl; using std::ostream; diff --git a/src/insets/figinset.C b/src/insets/figinset.C index d4f5c9bc6d..1edd6043e1 100644 --- a/src/insets/figinset.C +++ b/src/insets/figinset.C @@ -1213,8 +1213,9 @@ void InsetFig::Edit(BufferView * bv, int, int, unsigned int) if (form->Figure->visible) { fl_raise_form(form->Figure); } else { - fl_show_form(form->Figure, FL_PLACE_MOUSE | FL_PLACE_SIZE, - FL_FULLBORDER, _("Figure")); + fl_show_form(form->Figure, + FL_PLACE_MOUSE | FL_FREE_SIZE, FL_TRANSIENT, + _("Figure")); } } diff --git a/src/insets/insetbib.C b/src/insets/insetbib.C index 32f8b7ae6e..e374b40c70 100644 --- a/src/insets/insetbib.C +++ b/src/insets/insetbib.C @@ -199,8 +199,8 @@ void InsetBibKey::Edit(BufferView * bv, int, int, unsigned int) if (bibitem_form->bibitem_form->visible) { fl_raise_form(bibitem_form->bibitem_form); } else { - fl_show_form(bibitem_form->bibitem_form, FL_PLACE_MOUSE, - FL_FULLBORDER, + fl_show_form(bibitem_form->bibitem_form, + FL_PLACE_MOUSE | FL_FREE_SIZE, FL_TRANSIENT, _("Bibliography item")); } } @@ -329,7 +329,7 @@ void InsetBibtex::Edit(BufferView * bv, int, int, unsigned int) fl_raise_form(bibitem_form->bibitem_form); } else { fl_show_form(bibitem_form->bibitem_form, - FL_PLACE_MOUSE, FL_FULLBORDER, + FL_PLACE_MOUSE | FL_FREE_SIZE, FL_TRANSIENT, _("BibTeX")); } } diff --git a/src/insets/insetexternal.C b/src/insets/insetexternal.C index 1d0590da69..77435740d2 100644 --- a/src/insets/insetexternal.C +++ b/src/insets/insetexternal.C @@ -36,7 +36,7 @@ using std::endl; InsetExternal::InsetExternal() : form_external(0) { - tempname = TmpFileName(); + tempname = lyx::tempName(); //TmpFileName(); } @@ -291,8 +291,8 @@ void InsetExternal::Edit(BufferView * bv, fl_raise_form(form_external->form_external); } else { fl_show_form(form_external->form_external, - FL_PLACE_MOUSE | FL_FREE_SIZE, - FL_FULLBORDER, _("Insert external inset")); + FL_PLACE_MOUSE | FL_FREE_SIZE, FL_TRANSIENT, + _("Insert external inset")); if (ow < 0) { ow = form_external->form_external->w; oh = form_external->form_external->h; diff --git a/src/insets/insetinclude.C b/src/insets/insetinclude.C index 718032141d..c084789425 100644 --- a/src/insets/insetinclude.C +++ b/src/insets/insetinclude.C @@ -252,7 +252,7 @@ void InsetInclude::Edit(BufferView * bv, int, int, unsigned int) if (!form) { form = create_form_include(); - fl_set_form_atclose(form->include, IgnoreCloseBoxCB, 0); + fl_set_form_atclose(form->include, CancelCloseBoxCB, 0); } form->include->u_vdata = this; @@ -272,7 +272,8 @@ void InsetInclude::Edit(BufferView * bv, int, int, unsigned int) if (form->include->visible) { fl_raise_form(form->include); } else { - fl_show_form(form->include, FL_PLACE_MOUSE, FL_FULLBORDER, + fl_show_form(form->include, + FL_PLACE_MOUSE | FL_FREE_SIZE, FL_TRANSIENT, _("Include")); } } diff --git a/src/insets/insetinfo.C b/src/insets/insetinfo.C index 66c7712191..da55067adf 100644 --- a/src/insets/insetinfo.C +++ b/src/insets/insetinfo.C @@ -226,7 +226,8 @@ void InsetInfo::Edit(BufferView *bv, int, int, unsigned int) if (form->visible) { fl_raise_form(form); } else { - fl_show_form(form, FL_PLACE_MOUSE | FL_FREE_SIZE, FL_FULLBORDER, + fl_show_form(form, + FL_PLACE_MOUSE | FL_FREE_SIZE, FL_TRANSIENT, _("Note")); if (ow < 0) { ow = form->w; diff --git a/src/intl.C b/src/intl.C index c25e33b5a0..2eb88498aa 100644 --- a/src/intl.C +++ b/src/intl.C @@ -357,6 +357,7 @@ void Intl::MenuKeymap() { if (fd_form_keymap->KeyMap->visible) { fl_raise_form(fd_form_keymap->KeyMap); - } else fl_show_form(fd_form_keymap->KeyMap, FL_PLACE_MOUSE, - FL_FULLBORDER, _("Key Mappings")); + } else fl_show_form(fd_form_keymap->KeyMap, + FL_PLACE_MOUSE | FL_FREE_SIZE, FL_TRANSIENT, + _("Key Mappings")); } diff --git a/src/lyx_cb.C b/src/lyx_cb.C index 440abb97c6..ecdf613ac1 100644 --- a/src/lyx_cb.C +++ b/src/lyx_cb.C @@ -17,10 +17,10 @@ #include FORMS_H_LOCATION #include "lyx.h" #include "layout_forms.h" -#include "form1.h" +//#include "form1.h" #include "lyx_main.h" #include "lyx_cb.h" -#include "insets/insetref.h" +//#include "insets/insetref.h" #include "insets/insetlabel.h" #include "insets/figinset.h" #include "lyxfunc.h" @@ -30,18 +30,19 @@ #include "filedlg.h" #include "lyx_gui_misc.h" #include "LyXView.h" -#include "BufferView.h" +//#include "BufferView.h" #include "lastfiles.h" #include "bufferview_funcs.h" #include "support/FileInfo.h" #include "support/syscall.h" #include "support/filetools.h" #include "support/path.h" -#include "lyxserver.h" +//#include "support/lyxlib.h" +//#include "lyxserver.h" #include "lyxrc.h" #include "lyxtext.h" -#include "CutAndPaste.h" -#include "exporter.h" +//#include "CutAndPaste.h" +//#include "exporter.h" using std::ifstream; using std::copy; @@ -74,7 +75,7 @@ extern bool send_fax(string const & fname, string const & sendcmd); extern void MenuSendto(); -extern LyXServer * lyxserver; +//extern LyXServer * lyxserver; // this should be static, but I need it in buffer.C bool quitting; // flag, that we are quitting the program @@ -398,8 +399,6 @@ void AutoSave(BufferView * bv) // 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. @@ -408,6 +407,8 @@ void AutoSave(BufferView * bv) // to fork. But we will do the save // anyway. bool failed = false; + + string tmp_ret = lyx::tempName(); if (!tmp_ret.empty()) { bv->buffer()->writeFile(tmp_ret, 1); // assume successful write of tmp_ret @@ -573,7 +574,7 @@ void MenuLayoutCharacter() 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, + FL_PLACE_MOUSE | FL_FREE_SIZE, FL_TRANSIENT, _("Character Style")); if (ow < 0) { ow = fd_form_character->form_character->w; @@ -625,7 +626,7 @@ void MenuLayoutPreamble() } else { fl_show_form(fd_form_preamble->form_preamble, FL_PLACE_MOUSE | FL_FREE_SIZE, - FL_FULLBORDER, + FL_TRANSIENT, _("LaTeX Preamble")); if (ow < 0) { ow = fd_form_preamble->form_preamble->w; @@ -821,7 +822,7 @@ void Figure() fl_raise_form(fd_form_figure->form_figure); } else { fl_show_form(fd_form_figure->form_figure, - FL_PLACE_MOUSE, FL_FULLBORDER, + FL_PLACE_MOUSE | FL_FREE_SIZE, FL_TRANSIENT, _("Insert Figure")); } } diff --git a/src/lyx_gui_misc.C b/src/lyx_gui_misc.C index 9d1dd98389..4f1ede6766 100644 --- a/src/lyx_gui_misc.C +++ b/src/lyx_gui_misc.C @@ -66,13 +66,6 @@ extern "C" int CancelCloseBoxCB(FL_FORM *, void *) } -// Prevents LyX from being killed when the close box is pressed in a popup. -extern "C" int IgnoreCloseBoxCB(FL_FORM *, void *) -{ - return FL_IGNORE; -} - - // Prevents LyX from crashing when no buffers available // This is also one of the functions that we _really_ dont want // we should try to finds way to help us with that. diff --git a/src/lyx_gui_misc.h b/src/lyx_gui_misc.h index 779167af41..f94836fc05 100644 --- a/src/lyx_gui_misc.h +++ b/src/lyx_gui_misc.h @@ -26,8 +26,6 @@ class MiniBuffer; /// Prevents LyX from being killed when the close box is pressed in a popup. extern "C" int CancelCloseBoxCB(FL_FORM *, void *); -/// Prevents LyX from being killed when the close box is pressed in a popup. -extern "C" int IgnoreCloseBoxCB(FL_FORM *, void *); /// Prevents LyX from crashing when no buffers available void CloseAllBufferRelatedDialogs(); diff --git a/src/lyx_sendfax_main.C b/src/lyx_sendfax_main.C index c7af0d64a9..8fca1ffa33 100644 --- a/src/lyx_sendfax_main.C +++ b/src/lyx_sendfax_main.C @@ -47,7 +47,7 @@ bool send_fax(string const & fname, string const & sendcmd) return false; path = OnlyPath(fname); if (path.empty() || path == "./") - filename = GetCWD() + "/" + fname; + filename = lyx::getcwd() /*GetCWD()*/ + "/" + fname; else filename = fname; @@ -83,7 +83,8 @@ bool send_fax(string const & fname, string const & sendcmd) /* show the first form */ fl_show_form(fd_xsendfax->xsendfax, - FL_PLACE_MOUSE, FL_FULLBORDER, title.c_str()); + FL_PLACE_MOUSE | FL_FREE_SIZE, FL_TRANSIENT, + title.c_str()); /* while(true) { obj = fl_do_forms(); @@ -114,7 +115,7 @@ bool button_send(string const & fname, string const & sendcmd) if (phone.empty()) return false; - string logfile = TmpFileName(OnlyPath(fname), "FAX"); + string logfile = lyx::tempName(OnlyPath(fname), "FAX"); //TmpFileName(OnlyPath(fname), "FAX"); string cmd = sendcmd + " >"; cmd += logfile + " 2>"; cmd += logfile; @@ -285,7 +286,7 @@ void show_logfile(string const & logfile, bool show_if_empty) fl_raise_form(fd_logfile->logfile); } else { fl_show_form(fd_logfile->logfile, - FL_PLACE_MOUSE | FL_FREE_SIZE, FL_FULLBORDER, + FL_PLACE_MOUSE | FL_FREE_SIZE, FL_TRANSIENT, _("Message-Window")); } } @@ -322,6 +323,7 @@ void FaxOpenPhonebookCB(FL_OBJECT *, long) if (!n) fl_addto_browser(fd_phonebook->browser, _("@L@b@cEmpty Phonebook")); - fl_show_form(fd_phonebook->phonebook, FL_PLACE_MOUSE, FL_FULLBORDER, + fl_show_form(fd_phonebook->phonebook, + FL_PLACE_MOUSE | FL_FREE_SIZE, FL_TRANSIENT, _("Phonebook")); } diff --git a/src/lyxfr0.C b/src/lyxfr0.C index 0b14d4c6ba..083e0c6a3a 100644 --- a/src/lyxfr0.C +++ b/src/lyxfr0.C @@ -90,7 +90,7 @@ void SearchForm::StartSearch(LyXFindReplace * lfr) fl_raise_form(search_form->form_search); } else { fl_show_form(search_form->form_search, - FL_PLACE_MOUSE | FL_FREE_SIZE, FL_FULLBORDER, + FL_PLACE_MOUSE | FL_FREE_SIZE, FL_TRANSIENT, _("Find & Replace")); // RVDK_PATCH_5 if (ow < 0) { ow = search_form->form_search->w; diff --git a/src/lyxvc.C b/src/lyxvc.C index 4ab17afc9c..de506a2c03 100644 --- a/src/lyxvc.C +++ b/src/lyxvc.C @@ -14,6 +14,7 @@ #include "buffer.h" #include "gettext.h" #include "support/filetools.h" +#include "support/lyxlib.h" #include "lyxfunc.h" #include "LyXView.h" @@ -279,7 +280,7 @@ void LyXVC::viewLog(string const & fil) fl_raise_form(browser->LaTeXLog); } else { fl_show_form(browser->LaTeXLog, - FL_PLACE_MOUSE | FL_FREE_SIZE, FL_FULLBORDER, + FL_PLACE_MOUSE | FL_FREE_SIZE, FL_TRANSIENT, _("VC History")); if (ow < 0) { ow = browser->LaTeXLog->w; @@ -292,7 +293,7 @@ void LyXVC::viewLog(string const & fil) void LyXVC::showLog() { - string tmpf = tmpnam(0); + string tmpf = lyx::tempName(); vcs->getLog(tmpf); viewLog(tmpf); lyx::unlink(tmpf); diff --git a/src/mathed/math_panel.C b/src/mathed/math_panel.C index c9e215a09b..4ae9b82cde 100644 --- a/src/mathed/math_panel.C +++ b/src/mathed/math_panel.C @@ -111,19 +111,27 @@ void button_cb(FL_OBJECT * ob, long data) lyxfunc->Dispatch(LFUN_INSERT_MATH, "sqrt"); break; case MM_DELIM: - fl_show_form(fd_delim->delim, FL_PLACE_MOUSE, FL_FULLBORDER, _("Delimiter")); + fl_show_form(fd_delim->delim, + FL_PLACE_MOUSE | FL_FREE_SIZE, FL_TRANSIENT, + _("Delimiter")); fl_set_form_atclose(fd_delim->delim, CancelCloseBoxCB, 0); break; case MM_DECO: - fl_show_form(fd_deco->deco, FL_PLACE_MOUSE, FL_FULLBORDER, _("Decoration")); + fl_show_form(fd_deco->deco, + FL_PLACE_MOUSE | FL_FREE_SIZE, FL_TRANSIENT, + _("Decoration")); fl_set_form_atclose(fd_deco->deco, CancelCloseBoxCB, 0); break; case MM_SPACE: - fl_show_form(fd_space->space, FL_PLACE_MOUSE, FL_FULLBORDER, _("Spacing")); + fl_show_form(fd_space->space, + FL_PLACE_MOUSE | FL_FREE_SIZE, FL_TRANSIENT, + _("Spacing")); fl_set_form_atclose(fd_space->space, CancelCloseBoxCB, 0); break; case MM_MATRIX: - fl_show_form(fd_matrix->matrix, FL_PLACE_MOUSE, FL_FULLBORDER, _("Matrix")); + fl_show_form(fd_matrix->matrix, + FL_PLACE_MOUSE | FL_FREE_SIZE, FL_TRANSIENT, + _("Matrix")); fl_set_form_atclose(fd_matrix->matrix, CancelCloseBoxCB, 0); break; case MM_EQU: @@ -364,7 +372,8 @@ void show_symbols_form(LyXFunc * lf) if (fd_panel->panel->visible) { fl_raise_form(fd_panel->panel); } else { - fl_show_form(fd_panel->panel, FL_PLACE_MOUSE, - FL_FULLBORDER, _("Math Panel")); + fl_show_form(fd_panel->panel, + FL_PLACE_MOUSE | FL_FREE_SIZE, FL_TRANSIENT, + _("Math Panel")); } } diff --git a/src/os2_defines.h b/src/os2_defines.h index 7a3cb1d47c..de9c6c6760 100644 --- a/src/os2_defines.h +++ b/src/os2_defines.h @@ -24,7 +24,6 @@ #define S_ISBLK(x) false #define readlink(s, t, l) (strcpy(t, s), strlen(t)) /*#define mkfifo(p, m) (0) *//* LyXserver is temporary disabled. */ -#define getcwd _getcwd2 #define chdir _chdir2 #define strcasecmp stricmp #if defined (__cplusplus) diff --git a/src/spellchecker.C b/src/spellchecker.C index 53492cefbe..908bdfd1e8 100644 --- a/src/spellchecker.C +++ b/src/spellchecker.C @@ -280,7 +280,7 @@ void SpellCheckerOptions() fl_raise_form(fd_form_spell_options->form_spell_options); } else { fl_show_form(fd_form_spell_options->form_spell_options, - FL_PLACE_MOUSE, FL_FULLBORDER, + FL_PLACE_MOUSE | FL_FREE_SIZE, FL_TRANSIENT, _("Spellchecker Options")); } } @@ -709,7 +709,7 @@ void ShowSpellChecker(BufferView * bv) fl_raise_form(fd_form_spell_check->form_spell_check); } else { fl_show_form(fd_form_spell_check->form_spell_check, - FL_PLACE_MOUSE, FL_FULLBORDER, + FL_PLACE_MOUSE | FL_FREE_SIZE, FL_TRANSIENT, _("Spellchecker")); } fl_deactivate_object(fd_form_spell_check->slider); diff --git a/src/support/Makefile.am b/src/support/Makefile.am index b4ba8c50f4..1aa751be3c 100644 --- a/src/support/Makefile.am +++ b/src/support/Makefile.am @@ -64,6 +64,7 @@ libsupport_la_SOURCES = \ syscontr.C \ syscontr.h \ syssingleton.C \ + tempname.C \ translator.h \ textutils.h \ unlink.C diff --git a/src/support/filetools.C b/src/support/filetools.C index c9605aa7f8..5d084b3141 100644 --- a/src/support/filetools.C +++ b/src/support/filetools.C @@ -32,6 +32,7 @@ #include "lyx_gui_misc.h" #include "FileInfo.h" #include "support/path.h" // I know it's OS/2 specific (SMiyata) +#include "support/syscall.h" #include "gettext.h" #include "lyxlib.h" @@ -57,6 +58,7 @@ using std::make_pair; using std::pair; using std::endl; using std::ifstream; +using std::vector; #if 0 using std::getenv; @@ -112,6 +114,7 @@ string const QuoteName(string const & name) } +#if 0 // Returns an unique name to be used as a temporary file. string const TmpFileName(string const & dir, string const & mask) {// With all these temporary variables, it should be safe enough :-) (JMarc) @@ -141,6 +144,7 @@ string const TmpFileName(string const & dir, string const & mask) lyxerr << "Not able to find a uniq tmpfile name." << endl; return string(); } +#endif // Is a file readable ? @@ -174,7 +178,7 @@ int IsFileWriteable (string const & path) // -1: error- couldn't find out int IsDirWriteable (string const & path) { - string const tmpfl(TmpFileName(path)); + string const tmpfl(lyx::tempName(path)); //TmpFileName(path)); if (tmpfl.empty()) { WriteFSAlert(_("LyX Internal Error!"), @@ -227,6 +231,71 @@ string const FileOpenSearch (string const & path, string const & name, } +/// Returns a vector of all files in directory dir having extension ext. +vector const DirList( string const & dir, string const & ext) +{ + // What what what???? + // where you tinking when you implemented this? +#if 0 + string lsCommand = "ls " + dir; + if (!ext.empty()) { + string::size_type sz = lsCommand.size(); + if (lsCommand[sz - 1] != '/') + lsCommand += '/'; + lsCommand += '*'; + if (ext[0] != '.') + lsCommand += '.'; + lsCommand += ext; + } + string tmpfile = system_tempdir + "/dirlist"; + lsCommand += " > " + tmpfile; + + Systemcalls(Systemcalls::System, lsCommand); + + string contents = GetFileContents(tmpfile); + string rmCommand = "rm " + tmpfile; + Systemcalls(Systemcalls::System, rmCommand); + + string tmp = strip(contents); + vector dirlist; + + while (!tmp.empty()) { + string file; + tmp = frontStrip(split(tmp, file, '\n')); + dirlist.push_back( file ); + } + return dirlist; +#else + // This is a non-error checking C/system implementation + // of the above. + string extension(ext); + if (extension[0] != '.') extension.insert(0u, 1u, '.'); + vector dirlist; + DIR * dirp = ::opendir(dir.c_str()); + dirent * dire; + while ((dire = ::readdir(dirp))) { + string fil = dire->d_name; + if (prefixIs(fil, extension)) { + dirlist.push_back(fil); + } + } + ::closedir(dirp); + return dirlist; + /* A C++ implementaion will look like this: + if (ext[0] != '.') ext.insert(0u, 1u, '.'); + directory_iterator dit("dir"); + while (dit != directory_iterator()) { + string fil = (*dit).filename; + if (prefixIs(fil, ext)) { + dirlist.push_back(fil); + } + ++dit; + } + */ +#endif +} + + // Returns the real name of file name in directory path, with optional // extension ext. string const FileSearch(string const & path, string const & name, @@ -417,9 +486,18 @@ int DeleteAllFilesInDir (string const & path) static string const CreateTmpDir(string const & tempdir, string const & mask) { - string const tmpfl(TmpFileName(tempdir, mask)); +#warning Possibly buggy (Lgb) + lyxerr << "CreateTmpDir: tempdir=`" << tempdir << "'" << endl; + lyxerr << "CreateTmpDir: mask=`" << mask << "'" << endl; - if ((tmpfl.empty()) || lyx::mkdir(tmpfl, 0777)) { + string const tmpfl(lyx::tempName(tempdir, mask)); + // lyx::tempName actually creates a file to make sure that it + // stays unique. So we have to delete it before we can create + // a dir with the same name. Note also that we are not thread + // safe because of the gap between unlink and mkdir. (Lgb) + lyx::unlink(tmpfl.c_str()); + + if (tmpfl.empty() || lyx::mkdir(tmpfl, 0777)) { WriteFSAlert(_("Error! Couldn't create temporary directory:"), tempdir); return string(); @@ -446,7 +524,7 @@ int DestroyTmpDir(string const & tmpdir, bool Allfiles) string const CreateBufferTmpDir(string const & pathfor) { - return CreateTmpDir(pathfor, "lyx_bufrtmp"); + return CreateTmpDir(pathfor, "lyx_tmpbuf"); } @@ -463,7 +541,7 @@ string const CreateLyXTmpDir(string const & deflt) #ifdef __EMX__ Path p(user_lyxdir); #endif - string const t(CreateTmpDir(deflt, "lyx_tmp")); + string const t(CreateTmpDir(deflt, "lyx_tmpdir")); return t; } else return deflt; @@ -471,7 +549,7 @@ string const CreateLyXTmpDir(string const & deflt) #ifdef __EMX__ Path p(user_lyxdir); #endif - string const t(CreateTmpDir("/tmp", "lyx_tmp")); + string const t(CreateTmpDir("/tmp", "lyx_tmpdir")); return t; } } @@ -502,6 +580,7 @@ bool createDirectory(string const & path, int permission) } +#if 0 // Returns current working directory string const GetCWD () { @@ -522,6 +601,7 @@ string const GetCWD () delete[] tbuf; return result; } +#endif // Strip filename from path name @@ -565,7 +645,7 @@ string const MakeAbsPath(string const & RelPath, string const & BasePath) delete[] with_drive; #endif } else - TempBase = GetCWD(); + TempBase = lyx::getcwd(); //GetCWD(); #ifdef __EMX__ if (AbsolutePath(TempRel)) return TempBase.substr(0, 2) + TempRel; @@ -674,7 +754,7 @@ string const ExpandPath(string const & path) RTemp = split(RTemp, Temp, '/'); if (Temp == ".") { - return GetCWD() + '/' + RTemp; + return lyx::getcwd() /*GetCWD()*/ + '/' + RTemp; } else if (Temp == "~") { return GetEnvPath("HOME") + '/' + RTemp; } else if (Temp == "..") { diff --git a/src/support/filetools.h b/src/support/filetools.h index d1329d89e6..f42c539749 100644 --- a/src/support/filetools.h +++ b/src/support/filetools.h @@ -15,6 +15,8 @@ #include #include +#include + #include "debug.h" #include "LString.h" #include "support/lstrings.h" @@ -53,6 +55,10 @@ string const FileOpenSearch (string const & path, string const & name, string const FileSearch(string const & path, string const & name, string const & ext = string()); +/// Returns a vector of all files in directory dir having extension ext. +std::vector const DirList(string const & dir, + string const & ext = string()); + /** Is directory read only? returns 1: dir writeable @@ -115,6 +121,7 @@ string const MakeLatexName(string const & file); /// Put the name in quotes suitable for the current shell string const QuoteName(string const & file); +#if 0 /** Returns an unique name to be used as a temporary file. If given, 'mask' should the prefix to the temporary file, the rest of the temporary filename will be made from the pid and three letters. @@ -122,6 +129,7 @@ string const QuoteName(string const & file); string const TmpFileName(string const & dir = string(), string const & mask = "lyx_tmp"); +#endif /// Is a filename/path absolute? bool AbsolutePath(string const & path); @@ -145,16 +153,17 @@ string const GetExtension(string const & name); /// Create absolute path. If impossible, don't do anything string const ExpandPath(string const & path); +#if 0 /// gets current working directory string const GetCWD(); - +#endif /** Convert relative path into absolute path based on a basepath. If relpath is absolute, just use that. If basepath doesn't exist use CWD. */ string const MakeAbsPath(string const & RelPath = string(), - string const & BasePath = string()); + string const & BasePath = string()); /** Creates a nice compact path for displaying. The parameter threshold, if given, specifies the maximal length of the path. diff --git a/src/support/getcwd.C b/src/support/getcwd.C index f8e096bba1..edf38b3ce5 100644 --- a/src/support/getcwd.C +++ b/src/support/getcwd.C @@ -1,10 +1,12 @@ #include +#include #include #include "support/lyxlib.h" -char * lyx::getcwd(char * buffer, size_t size) +static inline +char * l_getcwd(char * buffer, size_t size) { #ifndef __EMX__ return ::getcwd(buffer, size); @@ -12,3 +14,25 @@ char * lyx::getcwd(char * buffer, size_t size) return ::_getcwd2(buffer, size); #endif } + + +// Returns current working directory +string const lyx::getcwd() +{ + int n = 256; // Assume path is less than 256 chars + char * err; + char * tbuf = new char[n]; + + // Safe. Hopefully all getcwds behave this way! + while (((err = l_getcwd(tbuf, n)) == 0) && (errno == ERANGE)) { + // Buffer too small, double the buffersize and try again + delete[] tbuf; + n = 2 * n; + tbuf = new char[n]; + } + + string result; + if (err) result = tbuf; + delete[] tbuf; + return result; +} diff --git a/src/support/lyxlib.h b/src/support/lyxlib.h index befb7bd6f8..d178797b05 100644 --- a/src/support/lyxlib.h +++ b/src/support/lyxlib.h @@ -27,7 +27,7 @@ namespace lyx { struct lyx { #endif /// - OPT_STATIC char * getcwd(char * buffer, size_t size); + OPT_STATIC string const getcwd(); /// OPT_STATIC int chdir(string const & name); /// Returns false if it fails @@ -54,6 +54,9 @@ struct lyx { OPT_STATIC int rmdir(string const & file); /// OPT_STATIC int atoi(string const & nstr); + /// + OPT_STATIC string const tempName(string const & dir = string(), + string const & mask = string()); #ifdef CXX_WORKING_NAMESPACES } #else diff --git a/src/support/path.h b/src/support/path.h index ced3358c24..9e8f67ba8e 100644 --- a/src/support/path.h +++ b/src/support/path.h @@ -3,7 +3,7 @@ #define PATH_H #include "LString.h" -#include "filetools.h" +//#include "filetools.h" #include "lyxlib.h" #include @@ -20,7 +20,7 @@ public: : popped_(false) { if (!path.empty()) { - pushedDir_ = GetCWD(); + pushedDir_ = lyx::getcwd(); // GetCWD(); if (pushedDir_.empty() || lyx::chdir(path)) { // should throw an exception // throw DirChangeError(); diff --git a/src/support/tempname.C b/src/support/tempname.C new file mode 100644 index 0000000000..ee34988735 --- /dev/null +++ b/src/support/tempname.C @@ -0,0 +1,48 @@ +#include + +#include "LString.h" + +#include + +#include + +#include "lyxlib.h" +#include "debug.h" +#include "filetools.h" + +extern string system_tempdir; + +string const lyx::tempName(string const & dir, string const & mask) +{ +#if 0 + // the tmpnam version... + char const * const tmp = ::tmpnam(0); + return (tmp) ? tmp : string (); +#else + string tmpdir; + if (dir.empty()) + tmpdir = system_tempdir; + else + tmpdir = dir; + string tmpfl(AddName(tmpdir, mask)); + tmpfl += tostr(getpid()); + + // the supposedly safer mkstemp version + char * tmpl = new char[256]; + tmpfl += ".XXXXXX"; + ::strcpy(tmpl, tmpfl.c_str()); + int tmpf = ::mkstemp(tmpl); + if (tmpf != -1) { + string const t(tmpl); + ::close(tmpf); + delete [] tmpl; + lyxerr << "Temporary file `" << t << "' created." << endl; + return t; + } else { + lyxerr << "LyX Error: Unable to create temporary file." + << endl; + delete [] tmpl; + return string(); + } +#endif +} diff --git a/src/vc-backend.C b/src/vc-backend.C index 48f0d341b9..81efc9f6ce 100644 --- a/src/vc-backend.C +++ b/src/vc-backend.C @@ -12,6 +12,7 @@ #include "support/LRegex.h" #include "support/LSubstring.h" #include "support/path.h" +#include "support/filetools.h" #include "buffer.h" #include "LyXView.h" #include "lyxfunc.h"