]> git.lyx.org Git - features.git/commitdiff
toc support reorganization; changes to xform_helpers; aspect ratio patch from herbert
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Sun, 21 Jul 2002 15:51:07 +0000 (15:51 +0000)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Sun, 21 Jul 2002 15:51:07 +0000 (15:51 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@4732 a592a061-630c-0410-9148-cb99ea01b6c8

36 files changed:
src/ChangeLog
src/LyXAction.C
src/Makefile.am
src/buffer.C
src/buffer.h
src/frontends/controllers/ChangeLog
src/frontends/controllers/ControlToc.C
src/frontends/controllers/ControlToc.h
src/frontends/xforms/ChangeLog
src/frontends/xforms/DropDown.C
src/frontends/xforms/FormCitation.C
src/frontends/xforms/FormForks.C
src/frontends/xforms/FormGraphics.C
src/frontends/xforms/FormMinipage.C
src/frontends/xforms/FormParagraph.C
src/frontends/xforms/FormRef.C
src/frontends/xforms/FormSendto.C
src/frontends/xforms/FormSpellchecker.C
src/frontends/xforms/FormToc.C
src/frontends/xforms/FormToc.h
src/frontends/xforms/Menubar_pimpl.C
src/frontends/xforms/xforms_helpers.C
src/frontends/xforms/xforms_helpers.h
src/graphics/ChangeLog
src/graphics/GraphicsImage.C
src/graphics/GraphicsParams.C
src/graphics/GraphicsParams.h
src/insets/ChangeLog
src/insets/insetfloatlist.C
src/insets/insetgraphicsParams.C
src/insets/insettoc.C
src/lyxfunc.C
src/support/ChangeLog
src/support/lstrings.h
src/toc.C [new file with mode: 0644]
src/toc.h [new file with mode: 0644]

index 0194c8595f816e8f22aa7604a09f2c49244f18a4..4d79eccbe44bee107a3315c03280889377b6de42 100644 (file)
@@ -1,3 +1,17 @@
+2002-07-21  Jean-Marc Lasgouttes  <lasgouttes@freesurf.fr>
+
+       * toc.[Ch]: new files, containing helper functions to handle table
+       of contents
+
+       * lyxfunc.C (dispatch): no need to remove spaces around command
+       given as a string
+       (getStatus): handle LFUN_SEQUENCE by returning the status of the
+       first command of the sequence; it is not very clever, but I do not
+       have a better idea, actually
+
+       * LyXAction.C (LookupFunc): make sure to remove space at the
+       beginning and end of the command
+
 2002-07-20  Jean-Marc Lasgouttes  <lasgouttes@freesurf.fr>
 
        * MenuBackend.C (getMenubar): new method: return the menubar of
index 05bf7e9474e2cb525ad6011e732fb61109142d84..acfaee94c5c6b905dc30238b693c50aeb38508a7 100644 (file)
@@ -535,11 +535,12 @@ kb_action LyXAction::retrieveActionArg(int pseudo, string & arg) const
 // Returns an action tag from a string.
 int LyXAction::LookupFunc(string const & func) const
 {
-       if (func.empty()) return LFUN_NOACTION;
+       string const func2 = frontStrip(strip(func));
+       if (func2.empty()) return LFUN_NOACTION;
 
        // split action and arg
        string actstr;
-       string const argstr = split(func, actstr, ' ');
+       string const argstr = split(func2, actstr, ' ');
        lyxerr[Debug::ACTION] << "Action: " << actstr << '\n';
        lyxerr[Debug::ACTION] << "Arg   : " << argstr << '\n';
 
index ff2276faf9f84a01903ef5aef0d5c069402fd8e5..1cc442849476bf16ee942cbe1017f354bcf5e5c9 100644 (file)
@@ -194,6 +194,8 @@ lyx_SOURCES = \
        texrow.h \
        text.C \
        text2.C \
+       toc.C \
+       toc.h \
        trans.C \
        trans.h \
        trans_decl.h \
index 26898f514c7fae9e60d9ad05a1705be577654b35..50d669717ea92f3ee7c1300cc72ab7808c7a8737 100644 (file)
@@ -3762,70 +3762,6 @@ vector<string> const Buffer::getLabelList()
 }
 
 
-Buffer::Lists const Buffer::getLists() const
-{
-       Lists l;
-       Paragraph * par = paragraph;
-
-       LyXTextClass const & textclass = textclasslist[params.textclass];
-       bool found = textclass.hasLayout("Caption");
-       string const layout("Caption");
-
-       while (par) {
-#ifdef WITH_WARNINGS
-#warning bogus type (Lgb)
-#endif
-               char const labeltype = par->layout()->labeltype;
-
-               if (labeltype >= LABEL_COUNTER_CHAPTER
-                   && labeltype <= LABEL_COUNTER_CHAPTER + params.tocdepth) {
-                               // insert this into the table of contents
-                       SingleList & item = l["TOC"];
-                       int depth = max(0, labeltype - textclass.maxcounter());
-                       item.push_back(TocItem(par, depth,
-                                              par->asString(this, true)));
-               }
-               // For each paragraph, traverse its insets and look for
-               // FLOAT_CODE
-
-               if (found) {
-                       Paragraph::inset_iterator it =
-                               par->inset_iterator_begin();
-                       Paragraph::inset_iterator end =
-                               par->inset_iterator_end();
-
-                       for (; it != end; ++it) {
-                               if ((*it)->lyxCode() == Inset::FLOAT_CODE) {
-                                       InsetFloat * il =
-                                               static_cast<InsetFloat*>(*it);
-
-                                       string const type = il->type();
-
-                                       // Now find the caption in the float...
-                                       // We now tranverse the paragraphs of
-                                       // the inset...
-                                       Paragraph * tmp = il->inset.paragraph();
-                                       while (tmp) {
-                                               if (tmp->layout()->name() == layout) {
-                                                       SingleList & item = l[type];
-                                                       string const str =
-                                                               tostr(item.size()+1) + ". " + tmp->asString(this, false);
-                                                       item.push_back(TocItem(tmp, 0 , str));
-                                               }
-                                               tmp = tmp->next();
-                                       }
-                               }
-                       }
-               } else {
-                       lyxerr << "Caption not found" << endl;
-               }
-
-               par = par->next();
-       }
-       return l;
-}
-
-
 // This is also a buffer property (ale)
 vector<pair<string, string> > const Buffer::getBibkeyList() const
 {
index b3af29f343f38c4911de6937e4432d7c5365c5f1..90004d0d7eba16ca92cfb8f9310a0ce5c2d7bbe4 100644 (file)
@@ -280,23 +280,6 @@ public:
        ///
        std::vector<std::pair<string, string> > const getBibkeyList() const;
        ///
-       struct TocItem {
-               TocItem(Paragraph * p, int d, string const & s)
-                       : par(p), depth(d), str(s) {}
-               ///
-               Paragraph * par;
-               ///
-               int depth;
-               ///
-               string str;
-       };
-       ///
-       typedef std::vector<TocItem> SingleList;
-       ///
-       typedef std::map<string, SingleList> Lists;
-       ///
-       Lists const getLists() const;
-       ///
        std::vector<string> const getLabelList();
 
        /** This will clearly have to change later. Later we can have more
@@ -578,24 +561,6 @@ void Buffer::setParentName(string const & name)
 }
 
 
-///
-inline
-bool operator==(Buffer::TocItem const & a, Buffer::TocItem const & b)
-{
-       return a.par == b.par && a.str == b.str;
-       // No need to compare depth.
-}
-
-
-///
-inline
-bool operator!=(Buffer::TocItem const & a, Buffer::TocItem const & b)
-{
-       return !(a == b);
-       // No need to compare depth.
-}
-
-
 ///
 inline
 bool operator==(Buffer::inset_iterator const & iter1,
index c68e8d5490569942c1a323b058c5fbf3135597f9..2fe29e1e87c13cfb5debd743b020b5a317b9545a 100644 (file)
@@ -1,3 +1,7 @@
+2002-07-21  Jean-Marc Lasgouttes  <lasgouttes@freesurf.fr>
+
+       * ControlToc.C: remove getType
+
 2002-07-20  John Levon  <moz@compsoc.man.ac.uk>
 
        * ControlCommandBuffer.C: don't add "" to history
index 50cf2a5cb30c2aaa8fb1ad67ca9292580eb3bbc6..7af987fad6a710079c5803d66405e6ea436e283e 100644 (file)
 #endif
 
 #include "ControlToc.h"
-#include "buffer.h"
+#include "toc.h"
 #include "Dialogs.h"
-#include "lyxfunc.h"
-#include "gettext.h"
 #include "BufferView.h"
 
 #include "support/lstrings.h" // tostr
 
 using std::vector;
 
+class Buffer;
 
 ControlToc::ControlToc(LyXView & lv, Dialogs & d)
        : ControlCommand(lv, d, LFUN_TOC_INSERT)
 {}
 
 
-void ControlToc::Goto(int const & id) const
+void ControlToc::goTo(toc::TocItem const & item) const
 {
-       string const tmp = tostr(id);
-       lv_.getLyXFunc()->dispatch(LFUN_GOTO_PARAGRAPH, tmp);
+       item.goTo(lv_);
 }
 
 
 vector<string> const ControlToc::getTypes() const
 {
-       vector<string> types;
-
-       Buffer::Lists const tmp = lv_.view()->buffer()->getLists();
-
-       Buffer::Lists::const_iterator cit = tmp.begin();
-       Buffer::Lists::const_iterator end = tmp.end();
-
-       for (; cit != end; ++cit) {
-               types.push_back(cit->first);
-       }
-
-       return types;
+       return toc::getTypes(lv_.view()->buffer());
 }
 
 
-Buffer::SingleList const ControlToc::getContents(string const & type) const
+toc::Toc const ControlToc::getContents(string const & type) const
 {
-       Buffer::SingleList empty_list;
+       toc::Toc empty_list;
 
        // This shouldn't be possible...
        if (!lv_.view()->available()) {
                return empty_list;
        }
 
-       Buffer::Lists tmp = lv_.view()->buffer()->getLists();
-
-       Buffer::Lists::iterator it = tmp.find(type);
-
+       toc::TocList tmp = toc::getTocList(lv_.view()->buffer());
+       toc::TocList::iterator it = tmp.find(type);
        if (it == tmp.end()) {
                return empty_list;
        }
 
        return it->second;
 }
-
-
-namespace toc
-{
-
-string const getType(string const & cmdName)
-{
-       string type = cmdName;
-
-       // special case
-       if (cmdName == "tableofcontents")
-               type = "TOC";
-
-       return type;
-}
-
-} // namespace toc
index 6047ce2c396974f47d36bce2d5b4b27066aa937d..b0aedf76ad43dd6f76be2dbdd9e94c177940f4a9 100644 (file)
@@ -19,8 +19,9 @@
 #pragma interface
 #endif
 
+#include <vector>
 #include "ControlCommand.h"
-#include "buffer.h" // Buffer::SingleList
+#include "toc.h"
 
 /** A controller for TOC dialogs.
  */
@@ -31,21 +32,13 @@ public:
        ControlToc(LyXView &, Dialogs &);
 
        /// Goto this paragraph id
-       void Goto(int const & id) const;
+       void goTo(toc::TocItem const &) const;
 
-       /// Returns a vector of list types in the document
+       /// Return the list of types available
        std::vector<string> const getTypes() const;
 
        /// Given a type, returns the contents
-       Buffer::SingleList const getContents(string const & type) const;
+       toc::Toc const getContents(string const & type) const;
 };
 
-namespace toc
-{
-    /** Given the cmdName of the TOC param, returns the type used
-       by ControlToc::getContents() */
-       string const getType(string const & cmdName);
-
-} // namespace toc
-
 #endif // CONTROLTOC_H
index 603295763d6260f5a8b6a4688008462076f2b4b0..4b5d20d05f3d9f42f164fdb876067d7ae38975c2 100644 (file)
@@ -1,3 +1,21 @@
+2002-07-21  Jean-Marc Lasgouttes  <lasgouttes@freesurf.fr>
+
+       * FormSendto.C: 
+       * FormParagraph.C: 
+       * FormMinipage.C: 
+       * FormGraphics.C: 
+       * FormForks.C: 
+       * FormCitation.C:
+       * DropDown.C: update to use new getString and getVector
+
+       * xforms_helpers.[Ch]: replace getVectorFromChoice and
+       getVectorFromBrowser by getVector; replace getStringFromInput,
+       getStringFromBrowser and getSelectedStringFromBrowser with
+       getString, which works with input, choice and browser objects
+
+       * Menubar_pimpl.C: 
+       * FormToc.C: update to use new toc.[Ch]
+
 2002-07-21  John Levon  <moz@compsoc.man.ac.uk>
 
        * XFormsView.C: move autosave timer to LyXView.C
index 6fe29e778868f6f26be4574648e822dcb449caed..44dcd6e49ff67d3e7c1c02e9b5b8f531f241f57d 100644 (file)
@@ -177,7 +177,7 @@ void DropDown::completed()
 {
        XUngrabPointer(fl_get_display(), CurrentTime);
        fl_hide_form(form_);
-       result(getSelectedStringFromBrowser(browser_));
+       result(getString(browser_));
 }
 
 
index 9a2ce6e7516ede4a1d090e4f01a1baa84ad8f3f8..d4cc950828f796b190cac7f056ef1717c2a59d45 100644 (file)
@@ -49,7 +49,7 @@ void fillChoice(FD_citation * dialog, vector<string> vec)
        // Check whether the current contents of the browser will be
        // changed by loading the contents of the vec...
        vector<string> const choice_style =
-               getVectorFromChoice(dialog->choice_style);
+               getVector(dialog->choice_style);
 
        if (vec == choice_style)
                return;
@@ -485,7 +485,7 @@ void FormCitation::updateBrowser(FL_OBJECT * browser,
 {
        // Check whether the current contents of the browser will be
        // changed by loading the contents of the vec...
-       vector<string> browser_keys = getVectorFromBrowser(browser);
+       vector<string> browser_keys = getVector(browser);
 
        if (browser_keys == keys)
                return;
index cf4df6491e51c7df16bde9e068baaed6751c0f23..a1242a808a3a0636aefba5b1fd11e5f926ff4992 100644 (file)
@@ -75,7 +75,7 @@ void FormForks::update()
                return;
 
        string const current_pid_str =
-               getSelectedStringFromBrowser(dialog_->browser_kill);
+               getString(dialog_->browser_kill);
        pid_t const current_pid = strToInt(current_pid_str);
 
        vector<pid_t> pids = controller().getPIDs();
@@ -101,7 +101,7 @@ void FormForks::update()
        for (int i = 1; i <= fl_get_browser_maxline(dialog_->browser_kill);
             ++i) {
                string const pid_str =
-                       getStringFromBrowser(dialog_->browser_kill, i);
+                       getString(dialog_->browser_kill, i);
                pid_t const pid = strToInt(pid_str);
                vector<pid_t>::const_iterator it =
                        find(pids.begin(), pids.end(), pid);
@@ -136,7 +136,7 @@ void FormForks::apply()
 {
        // Get the list of all processes to kill.
        vector<string> const kill_vec =
-               getVectorFromBrowser(dialog_->browser_kill);
+               getVector(dialog_->browser_kill);
 
        if (kill_vec.empty())
                return;
@@ -145,7 +145,7 @@ void FormForks::apply()
        for (int i = 1; i <= fl_get_browser_maxline(dialog_->browser_children);
             ++i) {
                string const selection =
-                       getStringFromBrowser(dialog_->browser_children, i);
+                       getString(dialog_->browser_children, i);
                string pid_str;
                split(selection, pid_str, '\t');
 
@@ -209,12 +209,12 @@ ButtonPolicy::SMInput FormForks::input_browser_children()
        //    be added to this list if so desired.
 
        string const selection =
-               getSelectedStringFromBrowser(dialog_->browser_children);
+               getString(dialog_->browser_children);
        string pid_str;
        split(selection, pid_str, '\t');
 
        vector<string> const kill_vec =
-               getVectorFromBrowser(dialog_->browser_kill);
+               getVector(dialog_->browser_kill);
 
        vector<string>::const_iterator it =
                find(kill_vec.begin(), kill_vec.end(), pid_str);
@@ -268,11 +268,11 @@ ButtonPolicy::SMInput FormForks::input_browser_kill()
        // 3. Disable the add button.
 
        string const pid_str =
-               getSelectedStringFromBrowser(dialog_->browser_kill);
+               getString(dialog_->browser_kill);
 
        // Find this string in the list of all child processes
        vector<string> const child_vec =
-               getVectorFromBrowser(dialog_->browser_children);
+               getVector(dialog_->browser_children);
 
        vector<string>::const_iterator it =
                find_if(child_vec.begin(), child_vec.end(), FindPID(pid_str));
@@ -295,7 +295,7 @@ namespace {
 
 vector<string> const getPIDvector(FL_OBJECT * ob)
 {
-       vector<string> vec = getVectorFromBrowser(ob);
+       vector<string> vec = getVector(ob);
        if (vec.empty())
                return vec;
 
@@ -366,13 +366,12 @@ ButtonPolicy::SMInput FormForks::input_button_add()
 
        // 3. Deactivate the "add" button.
 
-       string const selection =
-               getSelectedStringFromBrowser(dialog_->browser_children);
+       string const selection = getString(dialog_->browser_children);
        string pid_str;
        split(selection, pid_str, '\t');
 
        vector<string> const kill_vec =
-               getVectorFromBrowser(dialog_->browser_kill);
+               getVector(dialog_->browser_kill);
 
        vector<string>::const_iterator it =
                find(kill_vec.begin(), kill_vec.end(), pid_str);
index 22d9e46ab5144741a883e6bc235f419fa31e7f18..dc93935c0d2d7c550dccf327cf2b36da8309a829 100644 (file)
@@ -205,12 +205,12 @@ void FormGraphics::apply()
        InsetGraphicsParams & igp = controller().params();
 
        // the file section
-       igp.filename = getStringFromInput(file_->input_filename);
+       igp.filename = getString(file_->input_filename);
        igp.subcaption = fl_get_button(file_->check_subcaption);
-       igp.subcaptionText = getStringFromInput(file_->input_subcaption);
+       igp.subcaptionText = getString(file_->input_subcaption);
        igp.rotate = fl_get_button(file_->check_rotate);
        igp.rotateAngle =
-               strToDbl(getStringFromInput(file_->input_rotate_angle));
+               strToDbl(getString(file_->input_rotate_angle));
        while (igp.rotateAngle < 0.0 || igp.rotateAngle > 360.0) {
                if (igp.rotateAngle < 0.0) {
                        igp.rotateAngle += 360.0;
@@ -252,7 +252,7 @@ void FormGraphics::apply()
        igp.lyxheight = getLyXLengthFromWidgets(lyxview_->input_lyxheight,
                                                lyxview_->choice_lyxheight);
 
-       igp.lyxscale = strToInt(getStringFromInput(lyxview_->input_lyxscale));
+       igp.lyxscale = strToInt(getString(lyxview_->input_lyxscale));
        igp.keepLyXAspectRatio = fl_get_button(lyxview_->check_lyxaspectratio);
 
        // the size section
@@ -269,7 +269,7 @@ void FormGraphics::apply()
        igp.height = getLyXLengthFromWidgets(size_->input_height,
                                   size_->choice_height);
 
-       igp.scale = strToInt(getStringFromInput(size_->input_scale));
+       igp.scale = strToInt(getString(size_->input_scale));
        igp.keepAspectRatio = fl_get_button(size_->check_aspectratio);
 
        // the bb section
@@ -277,22 +277,22 @@ void FormGraphics::apply()
                igp.bb = string();                      // don't write anything
        else {
                string bb;
-               if (getStringFromInput(bbox_->input_bb_x0).empty())
+               if (getString(bbox_->input_bb_x0).empty())
                        bb = "0 ";
                else
                        bb = getLengthFromWidgets(bbox_->input_bb_x0,
                                                  bbox_->choice_bb_units)+" ";
-               if (getStringFromInput(bbox_->input_bb_y0).empty())
+               if (getString(bbox_->input_bb_y0).empty())
                        bb += "0 ";
                else
                        bb += (getLengthFromWidgets(bbox_->input_bb_y0,
                                                    bbox_->choice_bb_units)+" ");
-               if (getStringFromInput(bbox_->input_bb_x1).empty())
+               if (getString(bbox_->input_bb_x1).empty())
                        bb += "0 ";
                else
                        bb += (getLengthFromWidgets(bbox_->input_bb_x1,
                                                    bbox_->choice_bb_units)+" ");
-               if (getStringFromInput(bbox_->input_bb_y1).empty())
+               if (getString(bbox_->input_bb_y1).empty())
                        bb += "0 ";
                else
                        bb += (getLengthFromWidgets(bbox_->input_bb_y1,
@@ -302,7 +302,7 @@ void FormGraphics::apply()
        igp.clip = fl_get_button(bbox_->check_clip);
 
        // the special section
-       igp.special = getStringFromInput(special_->input_special);
+       igp.special = getString(special_->input_special);
 }
 
 
@@ -499,7 +499,7 @@ namespace {
 
 bool isValid(FL_OBJECT * ob)
 {
-       string const input = getStringFromInput(ob);
+       string const input = getString(ob);
        return input.empty() || isValidLength(input) || isStrDbl(input);
 }
 
@@ -512,7 +512,7 @@ ButtonPolicy::SMInput FormGraphics::input(FL_OBJECT * ob, long)
        // the file section
        if (ob == file_->button_browse) {
                // Get the filename from the dialog
-               string const in_name = getStringFromInput(file_->input_filename);
+               string const in_name = getString(file_->input_filename);
                string const out_name = controller().Browse(in_name);
                lyxerr[Debug::GRAPHICS] << "[FormGraphics]out_name: " << out_name << endl;
                if (out_name != in_name && !out_name.empty()) {
@@ -572,7 +572,7 @@ ButtonPolicy::SMInput FormGraphics::input(FL_OBJECT * ob, long)
                        updateWidgetsFromLength(lyxview_->input_lyxheight,
                                                lyxview_->choice_lyxheight,
                                                dummy, defaultUnit);
-                       string const scale = getStringFromInput(size_->input_scale);
+                       string const scale = getString(size_->input_scale);
                        fl_set_input(lyxview_->input_lyxscale, scale.c_str());
                        if (fl_get_button (size_->radio_asis) == 1) {
                                fl_set_button (lyxview_->radio_lyxasis, 1);
@@ -610,7 +610,7 @@ ButtonPolicy::SMInput FormGraphics::input(FL_OBJECT * ob, long)
                    ob == bbox_->input_bb_x1 || ob == bbox_->input_bb_y1)) {
                controller().bbChanged = true;
        } else if (ob == bbox_->button_getBB) {
-               string const filename = getStringFromInput(file_->input_filename);
+               string const filename = getString(file_->input_filename);
                if (!filename.empty()) {
                        string bb = controller().readBB(filename);
                        if (!bb.empty()) {
@@ -663,7 +663,7 @@ ButtonPolicy::SMInput FormGraphics::input(FL_OBJECT * ob, long)
                updateWidgetsFromLength(size_->input_height,
                                        size_->choice_height,
                                        dummy, defaultUnit);
-               string const scale = getStringFromInput(lyxview_->input_lyxscale);
+               string const scale = getString(lyxview_->input_lyxscale);
                fl_set_input(size_->input_scale, scale.c_str());
                if (fl_get_button (lyxview_->radio_lyxasis) == 1) {
                        fl_set_button (size_->radio_asis, 1);
index eb37a93b8e894de957108e4544618bd48797b742..7a5d2a1275cc9a36162d0fe82aa9cd30d380126a 100644 (file)
@@ -106,7 +106,7 @@ ButtonPolicy::SMInput FormMinipage::input(FL_OBJECT * ob, long)
        // disallow senseless data
        // warnings if input is senseless
        if (ob == dialog_->input_width) {
-               string const input = getStringFromInput(dialog_->input_width);
+               string const input = getString(dialog_->input_width);
                bool const invalid = !isValidLength(input) && !isStrDbl(input);
                if (invalid) {
                        postWarning(_("Invalid Length!"));
index 4b5da5d60af7eaf7b7e834e74d1c9bf9b400d569..52616144454afec96d87de41818ac78b60b38e77 100644 (file)
@@ -171,7 +171,7 @@ void validateVSpaceWidgets(FL_OBJECT * choice_type, FL_OBJECT * input_length)
 
        // If a vspace kind is "Length" but there's no text in
        // the input field, reset the kind to "None".
-       string const input = strip(getStringFromInput(input_length));
+       string const input = strip(getString(input_length));
        if (input.empty())
                fl_set_choice(choice_type, 1);
 }
@@ -235,7 +235,7 @@ void FormParagraph::apply()
 
        /* label width */
        string const labelwidthstring =
-               getStringFromInput(dialog_->input_labelwidth);
+               getString(dialog_->input_labelwidth);
        controller().params().labelWidthString(labelwidthstring);
 
        /* indendation */
@@ -260,7 +260,7 @@ void FormParagraph::apply()
                break;
        case 5:
                linespacing = Spacing::Other;
-               other = getStringFromInput(dialog_->input_linespacing);
+               other = getString(dialog_->input_linespacing);
                break;
        }
 
@@ -447,7 +447,7 @@ void synchronizeSpaceWidgets(FL_OBJECT * choice_type,
                setEnabled(input_length, true);
                setEnabled(choice_length, true);
 
-               string const length = getStringFromInput(input_length);
+               string const length = getString(input_length);
 
                if (strip(length).empty()) {
                        bool const metric = lyxrc.default_papersize > 3;
@@ -467,7 +467,7 @@ bool validSpaceWidgets(FL_OBJECT * choice_type, FL_OBJECT * input_length)
        if (fl_get_choice(choice_type) != 7)
                return true;
 
-       string const input = getStringFromInput(input_length);
+       string const input = getString(input_length);
        return (input.empty() ||
                isValidGlueLength(input) ||
                isStrDbl(input));
@@ -516,7 +516,7 @@ ButtonPolicy::SMInput FormParagraph::input(FL_OBJECT * ob, long)
        }
 
        double const spacing =
-               strToDbl(getStringFromInput(dialog_->input_linespacing));
+               strToDbl(getString(dialog_->input_linespacing));
 
        if (choice_spacing == 5 && int(spacing) == 0)
                valid = false;
index 99fc14dd2d8f158735bd53960f2523c39b47e3e0..86a7ded32e72e06a33f556dec56f4e1a9d1cfa0b 100644 (file)
@@ -97,7 +97,7 @@ void FormRef::update()
        // Get the available buffers
        vector<string> const buffers = controller().getBufferList();
        vector<string> const choice_buffers =
-               getVectorFromChoice(dialog_->choice_buffer);
+               getVector(dialog_->choice_buffer);
 
        // If different from the current contents of the choice, then update it
        if (buffers != choice_buffers) {
@@ -124,8 +124,7 @@ void FormRef::updateBrowser(vector<string> const & akeys) const
        if (fl_get_button(dialog_->check_sort))
                sort(keys.begin(), keys.end());
 
-       vector<string> browser_keys =
-               getVectorFromBrowser(dialog_->browser_refs);
+       vector<string> browser_keys = getVector(dialog_->browser_refs);
 
        if (browser_keys == keys)
                return;
index 1d8615d7e006531f53934fd71cc6dbe9ab8c9b2c..e126ced8d63ae9f92cc1e076f93be92ec6b5987a 100644 (file)
@@ -69,7 +69,7 @@ void FormSendto::update()
        }
 
        vector<string> const browser_keys =
-               getVectorFromBrowser(dialog_->browser_formats);
+               getVector(dialog_->browser_formats);
 
        if (browser_keys == keys)
                return;
@@ -92,7 +92,7 @@ ButtonPolicy::SMInput FormSendto::input(FL_OBJECT *, long)
        if (line < 1 || line > fl_get_browser_maxline(dialog_->browser_formats))
                return ButtonPolicy::SMI_INVALID;
 
-       string cmd = getStringFromInput(dialog_->input_command);
+       string cmd = getString(dialog_->input_command);
        cmd = strip(frontStrip(cmd));
        if (cmd.empty())
                return ButtonPolicy::SMI_INVALID;
@@ -107,7 +107,7 @@ void FormSendto::apply()
        if (line < 1 || line > fl_get_browser_maxline(dialog_->browser_formats))
                return;
 
-       string const cmd = getStringFromInput(dialog_->input_command);
+       string const cmd = getString(dialog_->input_command);
 
        controller().setFormat(all_formats_[line-1]);
        controller().setCommand(cmd);
index 7dbfa0fca438297996f94a49ebdedd88b6e414b0..de1c2c9a196dc31d88284c90ff710b86a14799e7 100644 (file)
@@ -62,7 +62,7 @@ void FormSpellchecker::update()
 ButtonPolicy::SMInput FormSpellchecker::input(FL_OBJECT * obj, long val)
 {
        if (obj == dialog_->button_replace) {
-               string const tmp = getStringFromInput(dialog_->input);
+               string const tmp = getString(dialog_->input);
                controller().replace(tmp);
 
        } else if (obj == dialog_->button_start) {
@@ -88,7 +88,7 @@ ButtonPolicy::SMInput FormSpellchecker::input(FL_OBJECT * obj, long val)
        } else if (obj == dialog_->browser) {
                int const line = fl_get_browser(dialog_->browser);
                string const tmp =
-                       getStringFromBrowser(dialog_->browser, line);
+                       getString(dialog_->browser, line);
                if (tmp.empty())
                        return ButtonPolicy::SMI_NOOP;
 
index d7ad86b2542e7e3998feed1a80146d52cb96f65d..c37e7bc1832a8653c25631465b4d06d801d2bd4a 100644 (file)
@@ -14,9 +14,9 @@
 
 #include "FormToc.h"
 #include "xformsBC.h"
+#include "xforms_helpers.h"
 #include "ControlToc.h"
 #include "forms/form_toc.h"
-#include "helper_funcs.h" // getStringFromVector
 #include "support/lstrings.h" // frontStrip, strip
 #include "debug.h"
 #include "gettext.h"
@@ -38,6 +38,9 @@ void FormToc::build()
 {
        dialog_.reset(build_toc(this));
 
+       vector<string> types = controller().getTypes();
+       
+       
        string const choice =
                " " + getStringFromVector(controller().getTypes(), " | ") + " ";
        fl_addto_choice(dialog_->choice_toc_type, choice.c_str());
@@ -59,8 +62,8 @@ ButtonPolicy::SMInput FormToc::input(FL_OBJECT * ob, long)
        if (ob == dialog_->browser_toc) {
                unsigned int const choice = fl_get_browser(dialog_->browser_toc);
 
-               if (choice - 1 < toclist_.size() && choice >= 1) {
-                       controller().Goto(toclist_[choice - 1].par->id());
+               if (choice - 1 < toc_.size() && choice >= 1) {
+                       controller().goTo(toc_[choice - 1]);
                }
                return ButtonPolicy::SMI_VALID;
        }
@@ -84,62 +87,51 @@ void FormToc::updateType()
 
        // And select the correct one
        string const type = toc::getType(controller().params().getCmdName());
-
-       fl_set_choice(dialog_->choice_toc_type, 1);
-       for (int i = 1;
-            i <= fl_get_choice_maxitems(dialog_->choice_toc_type); ++i) {
-               string const choice =
-                       fl_get_choice_item_text(dialog_->choice_toc_type, i);
-
-               if (choice == type) {
-                       fl_set_choice(dialog_->choice_toc_type, i);
-                       break;
-               }
-       }
+       fl_set_choice_text(dialog_->choice_toc_type, type.c_str());
 }
 
 
 void FormToc::updateContents()
 {
-       char const * tmp = fl_get_choice_text(dialog_->choice_toc_type);
-
-       if (!tmp) {
+       string const type = getString(dialog_->choice_toc_type);
+       if (type.empty()) {
                fl_clear_browser(dialog_->browser_toc);
                fl_add_browser_line(dialog_->browser_toc,
                                    _("*** No Lists ***"));
+               setEnabled(dialog_->browser_toc, false);
                return;
        }
 
-       string const type = frontStrip(strip(tmp));
+       toc::Toc const contents = controller().getContents(type);
 
-       Buffer::SingleList const contents = controller().getContents(type);
+       // Check if all elements are the same.
+       if (toc_ == contents) {
+               return;
+       }
+
+       // List has changed. Update browser
+       toc_ = contents;
 
        if (contents.empty()) {
                fl_clear_browser(dialog_->browser_toc);
                fl_add_browser_line(dialog_->browser_toc,
                                    _("*** No Lists ***"));
-       }
-
-       // Check if all elements are the same.
-       if (toclist_ == contents) {
+               setEnabled(dialog_->browser_toc, false);
                return;
        }
 
-       // List has changed. Update browser
-       toclist_ = contents;
-
        unsigned int const topline =
                fl_get_browser_topline(dialog_->browser_toc);
        unsigned int const line = fl_get_browser(dialog_->browser_toc);
 
        fl_clear_browser(dialog_->browser_toc);
+       setEnabled(dialog_->browser_toc, true);
 
-       Buffer::SingleList::const_iterator cit = toclist_.begin();
-       Buffer::SingleList::const_iterator end = toclist_.end();
-
+       toc::Toc::const_iterator cit = contents.begin();
+       toc::Toc::const_iterator end = contents.end();
        for (; cit != end; ++cit) {
-               string const line = string(4 * cit->depth, ' ') + cit->str;
-               fl_add_browser_line(dialog_->browser_toc, line.c_str());
+               fl_add_browser_line(dialog_->browser_toc,
+                                   cit->asString().c_str());
        }
 
        fl_set_browser_topline(dialog_->browser_toc, topline);
index 308af3bdad18feedf66dff4eaf4f3c0dd2ebd3ee..bde478986109efce72a00425448e2d89ec31e7d1 100644 (file)
@@ -15,7 +15,7 @@
 #endif
 
 #include "FormBase.h"
-#include "buffer.h"
+#include "toc.h"
 
 class ControlToc;
 struct FD_toc;
@@ -42,7 +42,7 @@ private:
        void updateContents();
 
        ///
-       Buffer::SingleList toclist_;
+       toc::Toc toc_;
 };
 
 #endif // FORMTOC_H
index 6c6ed7eb347afd2d42b2c2704d1f8419a64a92b7..cb6f94f73b25d2305bf1dce56345587c72784e0d 100644 (file)
@@ -16,7 +16,6 @@
 #include "MenuBackend.h"
 #include "LyXAction.h"
 #include "kbmap.h"
-#include "buffer.h"
 #include "Dialogs.h"
 #include "XFormsView.h"
 #include "lyxfunc.h"
@@ -25,6 +24,7 @@
 #include "support/LAssert.h"
 #include "gettext.h"
 #include "debug.h"
+#include "toc.h"
 #include FORMS_H_LOCATION
 
 #include <boost/scoped_ptr.hpp>
@@ -206,15 +206,13 @@ string const fixlabel(string const & str)
 
 void add_toc2(int menu, string const & extra_label,
              vector<int> & smn, Window win,
-             vector<Buffer::TocItem> const & toc_list,
+             toc::Toc const & toc_list,
              size_type from, size_type to, int depth)
 {
        int shortcut_count = 0;
        if (to - from <= max_number_of_items) {
                for (size_type i = from; i < to; ++i) {
-                       int const action = lyxaction.
-                               getPseudoAction(LFUN_GOTO_PARAGRAPH,
-                                               tostr(toc_list[i].par->id()));
+                       int const action = toc_list[i].action();
                        string label(4 * max(0, toc_list[i].depth - depth),' ');
                        label += fixlabel(toc_list[i].str);
                        label = limit_string_length(label);
@@ -250,9 +248,7 @@ void add_toc2(int menu, string const & extra_label,
                               toc_list[new_pos].depth > depth)
                                ++new_pos;
 
-                       int const action = lyxaction.
-                               getPseudoAction(LFUN_GOTO_PARAGRAPH,
-                                               tostr(toc_list[pos].par->id()));
+                       int const action = toc_list[pos].action();
                        string label(4 * max(0, toc_list[pos].depth - depth), ' ');
                        label += fixlabel(toc_list[pos].str);
                        label = limit_string_length(label);
@@ -296,9 +292,9 @@ void Menubar::Pimpl::add_toc(int menu, string const & extra_label,
 {
        if (!owner_->buffer())
                return;
-       Buffer::Lists toc_list = owner_->buffer()->getLists();
-       Buffer::Lists::const_iterator cit = toc_list.begin();
-       Buffer::Lists::const_iterator end = toc_list.end();
+       toc::TocList toc_list = toc::getTocList(owner_->buffer());
+       toc::TocList::const_iterator cit = toc_list.begin();
+       toc::TocList::const_iterator end = toc_list.end();
        for (; cit != end; ++cit) {
                // Handle this elsewhere
                if (cit->first == "TOC") continue;
@@ -306,8 +302,8 @@ void Menubar::Pimpl::add_toc(int menu, string const & extra_label,
                // All the rest is for floats
                int menu_first_sub = get_new_submenu(smn, win);
                int menu_current = menu_first_sub;
-               Buffer::SingleList::const_iterator ccit = cit->second.begin();
-               Buffer::SingleList::const_iterator eend = cit->second.end();
+               toc::Toc::const_iterator ccit = cit->second.begin();
+               toc::Toc::const_iterator eend = cit->second.end();
                size_type count = 0;
                for (; ccit != eend; ++ccit) {
                        ++count;
@@ -319,10 +315,7 @@ void Menubar::Pimpl::add_toc(int menu, string const & extra_label,
                                count = 1;
                                menu_current = menu_tmp;
                        }
-                       int const action =
-                               lyxaction
-                               .getPseudoAction(LFUN_GOTO_PARAGRAPH,
-                                                tostr(ccit->par->id()));
+                       int const action = ccit->action();
                        string label = fixlabel(ccit->str);
                        label = limit_string_length(label);
                        label += "%x" + tostr(action + action_offset);
index cfc3474e803bf51fb77bcf318ad92c8113640f59..e4f20f6234b0299b6327cfacf3cd1dae0c903db6 100644 (file)
@@ -46,80 +46,65 @@ void setEnabled(FL_OBJECT * ob, bool enable)
 }
 
 
-// Given an fl_choice, create a vector of its entries
-vector<string> const getVectorFromChoice(FL_OBJECT * ob)
+// Given an fl_choice or an fl_browser, create a vector of its entries
+vector<string> const getVector(FL_OBJECT * ob)
 {
-       vector<string> vec;
-       if (!ob || ob->objclass != FL_CHOICE)
-               return vec;
-
-       for(int i = 0; i < fl_get_choice_maxitems(ob); ++i) {
-               string const text = fl_get_choice_item_text(ob, i+1);
-               vec.push_back(strip(frontStrip(text)));
+       vector <string> vec;
+       
+       switch (ob->objclass) {
+       case FL_CHOICE:
+               for(int i = 0; i < fl_get_choice_maxitems(ob); ++i) {
+                       string const text = fl_get_choice_item_text(ob, i+1);
+                       vec.push_back(strip(frontStrip(text)));
+               }
+               break;
+       case FL_BROWSER:
+               for(int i = 0; i < fl_get_browser_maxline(ob); ++i) {
+                       string const text = fl_get_browser_line(ob, i+1);
+                       vec.push_back(strip(frontStrip(text)));
+               }
+               break;
+       default:
+               lyx::Assert(0);
        }
-
+       
        return vec;
 }
 
 
-/// Given an fl_input, return its contents.
-string const getStringFromInput(FL_OBJECT * ob)
-{
-       if (!ob || ob->objclass != FL_INPUT)
-               return string();
-
-       char const * tmp = fl_get_input(ob);
-       return (tmp) ? tmp : string();
-}
-
-
-// Given an fl_browser, return the contents of line
-string const getStringFromBrowser(FL_OBJECT * ob, int line)
+///
+string const getString(FL_OBJECT * ob, int line)
 {
-       if (!ob || ob->objclass != FL_BROWSER ||
-           line < 1 || line > fl_get_browser_maxline(ob))
-               return string();
-
-       char const * tmp = fl_get_browser_line(ob, line);
-       return (tmp) ? tmp : string();
+       char const * tmp = 0;
+
+       switch (ob->objclass) {
+       case FL_INPUT:
+               lyx::Assert(line == -1);
+               tmp = fl_get_input(ob);
+               break;
+       case FL_BROWSER:
+               if (line == -1)
+                       line = fl_get_browser(ob);
+                       
+               if (line >= 1 && line <= fl_get_browser_maxline(ob))
+                       tmp = fl_get_browser_line(ob, line);
+               break;
+                       
+       case FL_CHOICE:
+               if (line == -1)
+                       line = fl_get_choice(ob);
+                       
+               if (line >= 1 && line <= fl_get_choice_maxitems(ob))
+                       tmp = fl_get_choice_item_text(ob, line);
+               break;
+                       
+       default:
+               lyx::Assert(0);
+       }               
+
+       return (tmp) ? frontStrip(strip(tmp)) : string();
 }
-
-// Given an fl_browser, return the contents of the currently
-// highlighted line.
-// If nothing is selected, return an empty string
-string const getSelectedStringFromBrowser(FL_OBJECT * ob)
-{
-       if (!ob || ob->objclass != FL_BROWSER)
-               return string();
-
-       int const line = fl_get_browser(ob);
-       if (line < 1 || line > fl_get_browser_maxline(ob))
-               return string();
-
-       if (!fl_isselected_browser_line(ob, line))
-               return string();
-
-       char const * tmp = fl_get_browser_line(ob, line);
-       return (tmp) ? tmp : string();
-}
-
-
-// Given an fl_browser, create a vector of its entries
-vector<string> const getVectorFromBrowser(FL_OBJECT * ob)
-{
-       vector<string> vec;
-       if (!ob || ob->objclass != FL_BROWSER)
-               return vec;
-
-       for(int i = 0; i < fl_get_browser_maxline(ob); ++i) {
-               string const text = fl_get_browser_line(ob, i+1);
-               vec.push_back(strip(frontStrip(text)));
-       }
-
-       return vec;
-}
-
-
+       
 string getLengthFromWidgets(FL_OBJECT * input, FL_OBJECT * choice)
 {
        // Paranoia check
@@ -179,7 +164,7 @@ void updateWidgetsFromLength(FL_OBJECT * input, FL_OBJECT * choice,
                // Else set the choice to the default unit.
                string const unit = subst(stringFromUnit(len.unit()),"%","%%");
 
-               vector<string> const vec = getVectorFromChoice(choice);
+               vector<string> const vec = getVector(choice);
                vector<string>::const_iterator it =
                        std::find(vec.begin(), vec.end(), unit);
                if (it != vec.end()) {
index f5a7d9993cde5e4b24ed9372643fce294f9f2991..d65181551261188f6fc1c49ceca3da002cb1f303 100644 (file)
@@ -37,23 +37,12 @@ void setEnabled(FL_OBJECT *, bool enable);
 string formatted(string const &label, int w,
                 int = 12 /*FL_NORMAL_SIZE*/, int = 0 /*FL_NORMAL_STYLE*/);
 
-/// Given an fl_choice, create a vector of its entries
-std::vector<string> const getVectorFromChoice(FL_OBJECT *);
-
-/// Given an fl_browser, create a vector of its entries
-std::vector<string> const getVectorFromBrowser(FL_OBJECT *);
-
-/// Given an fl_input, return its contents.
-string const getStringFromInput(FL_OBJECT * ob);
-
-/** Given an fl_browser, return the contents of line
-    (xforms numbering convention; starts at 1).
-*/
-string const getStringFromBrowser(FL_OBJECT * ob, int line);
-/** Given an fl_browser, return the contents of the currently
-    highlighted line.
-*/
-string const getSelectedStringFromBrowser(FL_OBJECT * ob);
+/// Given an fl_choice or an fl_browser, create a vector of its entries
+std::vector<string> const getVector(FL_OBJECT *);
+
+/// Given an fl_input, an fl_choice or an fl_browser, return an entry
+/** \c num is the position for the string, where -1 means "current item" */
+string const getString(FL_OBJECT * ob, int num = -1);
 
 /// Given input and choice widgets, create a string such as "1cm"
 string getLengthFromWidgets(FL_OBJECT * input, FL_OBJECT * choice);
index 8918c67806f918f1070f79c9b23825c894d81b1d..a1b2bceb482848cab4e15da2711b55d72f0e394f 100644 (file)
@@ -1,3 +1,9 @@
+2002-07-21  Herbert Voss  <voss@lyx.org>
+
+       * GraphicsImage.C: get the LyXAspectRatio run.
+
+       * GraphicsParams.[Ch]: add bool keepLyXXAspectRatio
+
 2002-07-20  Jean-Marc Lasgouttes  <lasgouttes@freesurf.fr>
 
        * PreviewLoader.C (startLoading): pass an interger as resolution
index 71d54f698a8a686ba259270c258452e9136bb91b..8b5be6fae04f28fd04f87d5f6282b138de032c3c 100644 (file)
@@ -5,6 +5,7 @@
  *
  * \author Baruch Even <baruch.even@writeme.com>
  * \author Angus Leeming <leeming@lyx.org>
+ * \author Herbert Voss <voss@lyx.org>
  */
 
 #include <config.h>
 
 #include "GraphicsImage.h"
 #include "GraphicsParams.h"
+#include "debug.h"
+
+using std::endl;
+using std::abs;
 
 namespace grfx {
 
@@ -29,32 +34,71 @@ boost::function0<Image::FormatList> Image::loadableFormats;
 std::pair<unsigned int, unsigned int>
 Image::getScaledDimensions(Params const & params) const
 {
-       if (params.scale == 0 && params.width == 0 && params.height == 0)
-               // No scaling
+       lyxerr[Debug::GRAPHICS]
+               << "GraphicsImage::getScaledDImensions()"
+               << "\n\tparams.scale       : " << params.scale
+               << "\n\tparams.width       : " << params.width
+               << "\n\tparams.height      : " << params.height
+               << "\n\tkeepLyXAspectRatio : " << params.keepLyXAspectRatio
+               << std::endl;
+       if (params.width == 0 && params.height == 0 && params.scale == 0) {
+               // original size or scale/custom without any input
+               lyxerr[Debug::GRAPHICS]
+                       << "\treturn with the original values!\n";
                return std::make_pair(getWidth(), getHeight());
-
+       }
+       
        typedef unsigned int dimension;
        dimension width  = 0;
        dimension height = 0;
        if (params.scale != 0) {
-               width  = dimension(getWidth()  * params.scale / 100.0);
+               // GraphicsParams::Scale 
+               width  = dimension(double(getWidth())  * params.scale / 100.0);
                height = dimension(getHeight() * params.scale / 100.0);
-       } else {
-               width  = params.width;
-               height = params.height;
+               return std::make_pair(width, height);
+       } 
+       // GraphicsParams::WH
+       width  = (params.width > 0) ? params.width : getWidth();
+       height = (params.height > 0) ? params.height : getHeight(); 
+       if (!params.keepLyXAspectRatio)
+               return std::make_pair(width, height);
 
-               if (width == 0) {
-                       width = height * getWidth() / getHeight();
-               } else if (height == 0) {
-                       height = width * getHeight() / getWidth();
-               }
+       // calculate aspect ratio
+       float const rw  = getWidth();
+       float const rh = getHeight();
+       // there must be a width for the division
+       float const ratio = (rw > 0.001) ? rh/rw : 1.0;
+       lyxerr[Debug::GRAPHICS]
+               << "\tValue of LyXAspectRatio: " << ratio << std::endl;
+       // there are now four different cases
+       // w=0 & h=0 -> see above, no more possible at this place
+       // w>0 & h=0 -> calculate h
+       // w=0 & h>0 -> calculate w
+       // w>0 & h>0 -> the greatest difference to the original
+       //              value becomes the same
+       if (params.width > 0 && params.height > 0) {
+               // both widths are given and keepAspectRatio, too
+               int const diff_width = abs(int(getWidth() - params.width));
+               int const diff_height= abs(int(getHeight() - params.height));
+               if (diff_width > diff_height)
+                       height = int(ratio * params.width);
+               else
+                       width = int(ratio * params.height);
+               return std::make_pair(width, height);
        }
-
-       if (width == 0 || height == 0)
-               // Something is wrong!
-               return std::make_pair(getWidth(), getHeight());
-
-       return std::make_pair(width, height);
+       if (params.width > 0) {
+               width = params.width;
+               height = int(ratio * params.width);
+               return std::make_pair(width, height);
+       }
+       if (params.height > 0) {
+               height = params.height;
+               width = int(ratio * params.height);
+               return std::make_pair(width, height);
+       }
+       // all other cases ... kind of paranoia :-)
+       return std::make_pair(getWidth(), getHeight());
 }
 
 } // namespace grfx
+
index c8e106efa97af76e4dacd6718f210b2416bdf60a..896332759edf9b0816095a837c629f43a3224102 100644 (file)
@@ -27,19 +27,21 @@ Params::Params()
          width(0),
          height(0),
          scale(0),
+         keepLyXAspectRatio(false),
          angle(0)
 {}
 
 
 bool operator==(Params const & a, Params const & b)
 {
-       return (a.filename == b.filename &&
-               a.display  == b.display &&
-               a.bb       == b.bb &&
-               a.width    == b.width &&
-               a.height   == b.height &&
-               a.scale    == b.scale &&
-               a.angle    == b.angle);
+       return (a.filename           == b.filename &&
+               a.display            == b.display &&
+               a.bb                 == b.bb &&
+               a.width              == b.width &&
+               a.height             == b.height &&
+               a.scale              == b.scale &&
+               a.keepLyXAspectRatio == b.keepLyXAspectRatio &&
+               a.angle              == b.angle);
 }
 
 
index 611fe9959889b4548359b948920ee7d8793cd79d..302125344c00063f3f0c688dd40f7ba483a97f38 100644 (file)
@@ -64,6 +64,7 @@ struct Params
        unsigned int width;
        unsigned int height;
        unsigned int scale;
+       bool keepLyXAspectRatio;
 
        /// Rotation angle.
        int angle;
index 4f52aa7ea47ca481100ca3cccef1b676030d0066..e831ee35f8fe970c19a42610aa5ccb79e8de6d1f 100644 (file)
@@ -1,3 +1,14 @@
+2002-07-21  Herbert Voss  <voss@lyx.org>
+
+       * insetgraphicsParams.C: fet the keepLyXAspectRatio run. Move the
+       image relevant part into graphics/GraphicsImgae.C
+
+2002-07-21  Jean-Marc Lasgouttes  <lasgouttes@freesurf.fr>
+
+       * insettoc.C (ascii): 
+       * insetfloatlist.C (ascii): change to use the new Toc functions
+       instead of stuff that was in Buffer
+
 2002-07-20  Jean-Marc Lasgouttes  <lasgouttes@freesurf.fr>
 
        * insettext.C (localDispatch): BufferView::Dispatch has been
index 2bebacd11490036ede5cdc8dbf5eccedc8160321..a64693664f73e630697cad54527c5dbbaf3a16b6 100644 (file)
@@ -7,10 +7,11 @@
 #include "insetfloatlist.h"
 #include "FloatList.h"
 #include "LaTeXFeatures.h"
+#include "lyxlex.h"
 #include "frontends/Dialogs.h"
 #include "frontends/LyXView.h"
 #include "BufferView.h"
-#include "buffer.h"
+#include "toc.h"
 #include "gettext.h"
 #include "debug.h"
 
@@ -121,16 +122,7 @@ int InsetFloatList::ascii(Buffer const * buffer, ostream & os, int) const
 {
        os << getScreenLabel(buffer) << "\n\n";
 
-       Buffer::Lists const toc_list = buffer->getLists();
-       Buffer::Lists::const_iterator cit =
-               toc_list.find(getCmdName());
-       if (cit != toc_list.end()) {
-               Buffer::SingleList::const_iterator ccit = cit->second.begin();
-               Buffer::SingleList::const_iterator end = cit->second.end();
-               for (; ccit != end; ++ccit)
-                       os << string(4 * ccit->depth, ' ')
-                          << ccit->str << "\n";
-       }
+       toc::asciiTocList(getCmdName(), buffer, os);
 
        os << "\n";
        return 0;
index c9d31047f97b39ef61e88d876697b9dc728a3b46..4bdb4be32a8323a3740ea9e7a4fb0d084fe11771 100644 (file)
@@ -323,6 +323,7 @@ grfx::Params InsetGraphicsParams::as_grfxParams(string const & filepath) const
        pars.width    = 0;
        pars.height   = 0;
        pars.scale    = 0;
+       pars.keepLyXAspectRatio = false;
        pars.angle    = 0;
        pars.filename = filename;
 
@@ -366,73 +367,47 @@ grfx::Params InsetGraphicsParams::as_grfxParams(string const & filepath) const
        if (rotate)
                pars.angle = int(rotateAngle);
 
-       if (display == InsetGraphicsParams::DEFAULT) {
-
-               if (lyxrc.display_graphics == "mono")
-                       pars.display = grfx::MonochromeDisplay;
-               else if (lyxrc.display_graphics == "gray")
-                       pars.display = grfx::GrayscaleDisplay;
-               else if (lyxrc.display_graphics == "color")
-                       pars.display = grfx::ColorDisplay;
-               else
+       switch (display) {
+               case InsetGraphicsParams::NONE:
                        pars.display = grfx::NoDisplay;
+               break;
 
-       } else if (display == InsetGraphicsParams::NONE) {
-               pars.display = grfx::NoDisplay;
-
-       } else if (display == InsetGraphicsParams::MONOCHROME) {
-               pars.display = grfx::MonochromeDisplay;
+               case InsetGraphicsParams::MONOCHROME:
+                       pars.display = grfx::MonochromeDisplay;
+               break;
 
-       } else if (display == InsetGraphicsParams::GRAYSCALE) {
-               pars.display = grfx::GrayscaleDisplay;
+               case InsetGraphicsParams::GRAYSCALE: 
+                       pars.display = grfx::GrayscaleDisplay;
 
-       } else if (display == InsetGraphicsParams::COLOR) {
-               pars.display = grfx::ColorDisplay;
+               case InsetGraphicsParams::COLOR:
+                       pars.display = grfx::ColorDisplay;
+               break;
+
+               default: {
+                       if (lyxrc.display_graphics == "mono")
+                               pars.display = grfx::MonochromeDisplay;
+                       else if (lyxrc.display_graphics == "gray")
+                               pars.display = grfx::GrayscaleDisplay;
+                       else if (lyxrc.display_graphics == "color")
+                               pars.display = grfx::ColorDisplay;
+                       else
+                               pars.display = grfx::NoDisplay;
+               }
        }
-
+       
        // Override the above if we're not using a gui
        if (!lyxrc.use_gui) {
                pars.display = grfx::NoDisplay;
        }
-
+       
        if (lyxsize_type == InsetGraphicsParams::SCALE) {
                pars.scale = lyxscale;
-
+               
        } else if (lyxsize_type == InsetGraphicsParams::WH) {
-               if (!lyxwidth.zero())
-                       pars.width  = lyxwidth.inPixels(1, 1);
-               if (!lyxheight.zero())
-                       pars.height = lyxheight.inPixels(1, 1);
-
-               // inPixels returns a value scaled by lyxrc.zoom.
-               // We want, therefore, to undo this.
-               double const scaling_factor = 100.0 / double(lyxrc.zoom);
-               pars.width  = uint(scaling_factor * pars.width);
-               pars.height = uint(scaling_factor * pars.height);
-
-#if 0
-#warning Angus, could you please adapt this code? (JMarc)
-               if (keepLyXAspectRatio) {
-                       // get the imagesize from the cache
-                       grfx::Cache & gc = grfx::Cache::get();
-                       float const rw = gc.raw_width(filename);
-                       float const rh = gc.raw_height(filename);
-                       float const ratio = (rw > 0.001) ? rh/rw : 1.0;
-                       lyxerr[Debug::GRAPHICS]
-                               << "Value of LyXAspectRatio: "
-                               << ratio << std::endl;
-                       if (!lyxwidth.zero() && !lyxheight.zero()) {
-                               if (width < height)
-                                       height = int(ratio * width);
-                               else
-                                       width = int(ratio * height);
-                       } else if (lyxwidth.zero())
-                               width = int(ratio * height);
-                       else if (lyxheight.zero())
-                               height = int(ratio * width);
-               }
-#endif
-       }
+               pars.width = lyxwidth.inBP();
+               pars.height = lyxheight.inBP();
+               pars.keepLyXAspectRatio = keepLyXAspectRatio;
+       }
        
        return pars;
 }
index 77153639fe5b39b0eef27d1a6a3f9f6582dc8373..b658a3bd8064ed5e52a9792eefb5e6bebd397f92 100644 (file)
@@ -10,8 +10,7 @@
 #include "frontends/LyXView.h"
 #include "frontends/Dialogs.h"
 #include "debug.h"
-#include "buffer.h"
-
+#include "toc.h"
 
 using std::vector;
 using std::ostream;
@@ -52,20 +51,7 @@ int InsetTOC::ascii(Buffer const * buffer, ostream & os, int) const
 {
        os << getScreenLabel(buffer) << "\n\n";
 
-       string type;
-       string const cmdname = getCmdName();
-       if (cmdname == "tableofcontents")
-               type = "TOC";
-       Buffer::Lists const toc_list = buffer->getLists();
-       Buffer::Lists::const_iterator cit =
-               toc_list.find(type);
-       if (cit != toc_list.end()) {
-               Buffer::SingleList::const_iterator ccit = cit->second.begin();
-               Buffer::SingleList::const_iterator end = cit->second.end();
-               for (; ccit != end; ++ccit)
-                       os << string(4 * ccit->depth, ' ')
-                          << ccit->str << "\n";
-       }
+       toc::asciiTocList(toc::getType(getCmdName()), buffer, os);
 
        os << "\n";
        return 0;
index 3a76379fd07581bb5dfc41918b84e2cdb82ac397..8fe242caaec26a5a70103295041ad9ecdc151456 100644 (file)
@@ -601,7 +601,7 @@ FuncStatus LyXFunc::getStatus(kb_action action,
        }
 
        if (disable)
-                       flag.disabled(true);
+               flag.disabled(true);
 
        // A few general toggles
        switch (action) {
@@ -679,13 +679,21 @@ FuncStatus LyXFunc::getStatus(kb_action action,
                }
        }
 
+       // this one is difficult to get right. As a half-baked
+       // solution, we consider only the first action of the sequence
+       if (action == LFUN_SEQUENCE) {
+               // argument contains ';'-terminated commands
+               const int ac = lyxaction.LookupFunc(token(argument, ';', 0));
+               flag = getStatus(ac); 
+       }
+
        return flag;
 }
 
 
 void LyXFunc::dispatch(string const & s, bool verbose)
 {
-       int const action = lyxaction.LookupFunc(frontStrip(strip(s)));
+       int const action = lyxaction.LookupFunc(s);
 
        if (action == LFUN_UNKNOWN_ACTION) {
                string const msg = string(_("Unknown function ("))
index efa10968e6f3a62fa88cccfaf1df7ad998a24279..3ea893de92bfa334968851091bf74425ee2e6f31 100644 (file)
@@ -1,3 +1,7 @@
+2002-07-21  Jean-Marc Lasgouttes  <lasgouttes@freesurf.fr>
+
+       * lstrings.h: correct comments for token and tokenPos
+
 2002-07-20  Dekel Tsur  <dekelts@tau.ac.il>
 
        * lyxstring.C (operator>>): replace code which works only with
index 4e2627f85b4c9b2c56c12c109cf482e5bcf9d53e..e20d0d80e588ec6bb1b9b4ebc07f8f9ae6f6d8e3 100644 (file)
@@ -178,8 +178,8 @@ bool containsOnly(char const *, string const &);
     Doesn't modify the original string. Similar to strtok.
     Example:
     \code
-    "a;bc;d".token(';', 1) == "bc";
-    "a;bc;d".token(';', 2) == "d";
+    token("a;bc;d", ';', 1) == "bc";
+    token("a;bc;d", ';', 2) == "d";
     \endcode
 */
 string const token(string const & a, char delim, int n);
@@ -190,8 +190,8 @@ string const token(string const & a, char delim, int n);
     failure.
     Example:
     \code
-    "a;bc;d".tokenPos(';', "bc") == 1;
-    "a;bc;d".token(';', "d") == 2;
+    tokenPos("a;bc;d", ';', "bc") == 1;
+    tokenPos("a;bc;d", ';', "d") == 2;
     \endcode
 */
 int tokenPos(string const & a, char delim, string const & tok);
diff --git a/src/toc.C b/src/toc.C
new file mode 100644 (file)
index 0000000..53e55d8
--- /dev/null
+++ b/src/toc.C
@@ -0,0 +1,165 @@
+// -*- C++ -*-
+/* This file is part of
+ * ======================================================
+ *
+ *           LyX, The Document Processor
+ *
+ *           Copyright 2002 The LyX Team.
+ *
+ * ======================================================
+ *
+ * \file toc.C
+ * \author Angus Leeming <a.leeming@ic.ac.uk>
+ * \author Jean-Marc Lasgouttes <lasgouttes@freesurf.fr>
+ */
+
+#include <config.h>
+
+#ifdef __GNUG__
+#pragma implementation
+#endif
+
+#include "support/lstrings.h"
+#include "toc.h"
+#include "buffer.h"
+#include "frontends/LyXView.h"
+#include "lyxfunc.h"
+#include "LyXAction.h"
+#include "paragraph.h"
+#include "lyxtextclasslist.h"
+#include "insets/insetfloat.h"
+#include "debug.h"
+
+using std::vector;
+
+extern LyXAction lyxaction;
+
+namespace toc
+{
+
+string const TocItem::asString() const
+{
+       return string(4 * depth, ' ') + str;
+}
+
+       
+void TocItem::goTo(LyXView & lv_) const
+{
+       string const tmp = tostr(par->id());
+       lv_.getLyXFunc()->dispatch(LFUN_GOTO_PARAGRAPH, tmp, false);
+}
+
+
+int TocItem::action() const
+{
+       return lyxaction.getPseudoAction(LFUN_GOTO_PARAGRAPH,
+                                        tostr(par->id()));
+}
+
+
+string const getType(string const & cmdName)
+{
+       // special case
+       if (cmdName == "tableofcontents")
+               return "TOC";
+       else
+               return cmdName;
+}
+
+
+TocList const getTocList(Buffer const * buf)
+{
+       TocList toclist;
+       Paragraph * par = buf->paragraph;
+
+       LyXTextClass const & textclass = textclasslist[buf->params.textclass];
+       bool found = textclass.hasLayout("Caption");
+       string const layout("Caption");
+
+       while (par) {
+#ifdef WITH_WARNINGS
+#warning bogus type (Lgb)
+#endif
+               char const labeltype = par->layout()->labeltype;
+
+               if (labeltype >= LABEL_COUNTER_CHAPTER
+                   && labeltype <= LABEL_COUNTER_CHAPTER + buf->params.tocdepth) {
+                               // insert this into the table of contents
+                       const int depth = max(0, labeltype - textclass.maxcounter());
+                       TocItem const item(par, depth,
+                                          par->asString(buf, true));
+                       toclist["TOC"].push_back(item);
+               }
+               // For each paragraph, traverse its insets and look for
+               // FLOAT_CODE
+
+               if (found) {
+                       Paragraph::inset_iterator it =
+                               par->inset_iterator_begin();
+                       Paragraph::inset_iterator end =
+                               par->inset_iterator_end();
+
+                       for (; it != end; ++it) {
+                               if ((*it)->lyxCode() == Inset::FLOAT_CODE) {
+                                       InsetFloat * il =
+                                               static_cast<InsetFloat*>(*it);
+
+                                       string const type = il->type();
+
+                                       // Now find the caption in the float...
+                                       // We now tranverse the paragraphs of
+                                       // the inset...
+                                       Paragraph * tmp = il->inset.paragraph();
+                                       while (tmp) {
+                                               if (tmp->layout()->name() == layout) {
+                                                       string const str =
+                                                               tostr(toclist[type].size()+1) + ". " + tmp->asString(buf, false);
+                                                       TocItem const item(tmp, 0 , str);
+                                                       toclist[type].push_back(item);
+                                               }
+                                               tmp = tmp->next();
+                                       }
+                               }
+                       }
+               } else {
+                       lyxerr << "Caption not found" << endl;
+               }
+
+               par = par->next();
+       }
+       return toclist;
+}
+
+
+vector<string> const getTypes(Buffer const * buffer)
+{
+       vector<string> types;
+
+       TocList const tmp = getTocList(buffer);
+
+       TocList::const_iterator cit = tmp.begin();
+       TocList::const_iterator end = tmp.end();
+
+       for (; cit != end; ++cit) {
+               types.push_back(cit->first);
+       }
+
+       return types;
+}
+
+
+void asciiTocList(string const & type, Buffer const * buffer, ostream & os)
+{
+       TocList const toc_list = getTocList(buffer);
+       TocList::const_iterator cit = toc_list.find(type);
+       if (cit != toc_list.end()) {
+               Toc::const_iterator ccit = cit->second.begin();
+               Toc::const_iterator end = cit->second.end();
+               for (; ccit != end; ++ccit)
+                       os << ccit->asString() << '\n';
+       }
+}
+
+
+} // namespace toc
+
diff --git a/src/toc.h b/src/toc.h
new file mode 100644 (file)
index 0000000..78ec77a
--- /dev/null
+++ b/src/toc.h
@@ -0,0 +1,94 @@
+// -*- C++ -*-
+/* This file is part of
+ * ======================================================
+ *
+ *           LyX, The Document Processor
+ *
+ *           Copyright 2002 The LyX Team.
+ *
+ * ======================================================
+ *
+ * \file toc.h
+ * \author Angus Leeming <a.leeming@ic.ac.uk>
+ * \author Jean-Marc Lasgouttes <lasgouttes@freesurf.fr>
+ */
+
+#ifndef TOC_H
+#define TOC_H
+
+#ifdef __GNUG__
+#pragma interface
+#endif
+
+#include "support/LOstream.h"
+#include "LString.h"
+
+#include <map>
+#include <vector>
+
+class Buffer;
+class LyXView;
+class Paragraph;
+
+/** Nice functions and objects to handle TOCs
+ */
+namespace toc 
+{
+
+///
+struct TocItem {
+       TocItem(Paragraph * p, int d, string const & s)
+               : par(p), depth(d), str(s) {}
+       ///
+       string const asString() const;
+       /// set cursor in LyXView to this TocItem
+       void goTo(LyXView & lv_) const;
+       /// the action corresponding to the goTo above
+       int action() const;
+       ///
+       Paragraph * par;
+       ///
+       int depth;
+       ///
+       string str;
+};
+
+///
+typedef std::vector<TocItem> Toc;
+///
+typedef std::map<string, Toc> TocList;
+
+///
+TocList const getTocList(Buffer const *);
+
+///
+std::vector<string> const getTypes(Buffer const *);
+
+///
+void asciiTocList(string const &, Buffer const *, ostream &);
+       
+/** Given the cmdName of the TOC param, returns the type used
+    by ControlToc::getContents() */
+string const getType(string const & cmdName);
+
+///
+inline
+bool operator==(TocItem const & a, TocItem const & b)
+{
+       return a.par == b.par && a.str == b.str;
+       // No need to compare depth.
+}
+
+
+///
+inline
+bool operator!=(TocItem const & a, TocItem const & b)
+{
+       return !(a == b);
+       // No need to compare depth.
+}
+
+
+} // namespace toc
+
+#endif // CONTROLTOC_H