From 1c52d8f898a221afca246a808df86266023d022e Mon Sep 17 00:00:00 2001 From: Jean-Marc Lasgouttes Date: Sun, 21 Jul 2002 15:51:07 +0000 Subject: [PATCH] toc support reorganization; changes to xform_helpers; aspect ratio patch from herbert git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@4732 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/ChangeLog | 14 ++ src/LyXAction.C | 5 +- src/Makefile.am | 2 + src/buffer.C | 64 --------- src/buffer.h | 35 ----- src/frontends/controllers/ChangeLog | 4 + src/frontends/controllers/ControlToc.C | 50 ++----- src/frontends/controllers/ControlToc.h | 17 +-- src/frontends/xforms/ChangeLog | 18 +++ src/frontends/xforms/DropDown.C | 2 +- src/frontends/xforms/FormCitation.C | 4 +- src/frontends/xforms/FormForks.C | 23 ++-- src/frontends/xforms/FormGraphics.C | 30 ++--- src/frontends/xforms/FormMinipage.C | 2 +- src/frontends/xforms/FormParagraph.C | 12 +- src/frontends/xforms/FormRef.C | 5 +- src/frontends/xforms/FormSendto.C | 6 +- src/frontends/xforms/FormSpellchecker.C | 4 +- src/frontends/xforms/FormToc.C | 56 ++++---- src/frontends/xforms/FormToc.h | 4 +- src/frontends/xforms/Menubar_pimpl.C | 27 ++-- src/frontends/xforms/xforms_helpers.C | 119 ++++++++--------- src/frontends/xforms/xforms_helpers.h | 23 +--- src/graphics/ChangeLog | 6 + src/graphics/GraphicsImage.C | 80 +++++++++--- src/graphics/GraphicsParams.C | 16 ++- src/graphics/GraphicsParams.h | 1 + src/insets/ChangeLog | 11 ++ src/insets/insetfloatlist.C | 14 +- src/insets/insetgraphicsParams.C | 85 +++++------- src/insets/insettoc.C | 18 +-- src/lyxfunc.C | 12 +- src/support/ChangeLog | 4 + src/support/lstrings.h | 8 +- src/toc.C | 165 ++++++++++++++++++++++++ src/toc.h | 94 ++++++++++++++ 36 files changed, 593 insertions(+), 447 deletions(-) create mode 100644 src/toc.C create mode 100644 src/toc.h diff --git a/src/ChangeLog b/src/ChangeLog index 0194c8595f..4d79eccbe4 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,17 @@ +2002-07-21 Jean-Marc Lasgouttes + + * 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 * MenuBackend.C (getMenubar): new method: return the menubar of diff --git a/src/LyXAction.C b/src/LyXAction.C index 05bf7e9474..acfaee94c5 100644 --- a/src/LyXAction.C +++ b/src/LyXAction.C @@ -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'; diff --git a/src/Makefile.am b/src/Makefile.am index ff2276faf9..1cc4428494 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -194,6 +194,8 @@ lyx_SOURCES = \ texrow.h \ text.C \ text2.C \ + toc.C \ + toc.h \ trans.C \ trans.h \ trans_decl.h \ diff --git a/src/buffer.C b/src/buffer.C index 26898f514c..50d669717e 100644 --- a/src/buffer.C +++ b/src/buffer.C @@ -3762,70 +3762,6 @@ vector 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(*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 > const Buffer::getBibkeyList() const { diff --git a/src/buffer.h b/src/buffer.h index b3af29f343..90004d0d7e 100644 --- a/src/buffer.h +++ b/src/buffer.h @@ -280,23 +280,6 @@ public: /// std::vector > 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 SingleList; - /// - typedef std::map Lists; - /// - Lists const getLists() const; - /// std::vector 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, diff --git a/src/frontends/controllers/ChangeLog b/src/frontends/controllers/ChangeLog index c68e8d5490..2fe29e1e87 100644 --- a/src/frontends/controllers/ChangeLog +++ b/src/frontends/controllers/ChangeLog @@ -1,3 +1,7 @@ +2002-07-21 Jean-Marc Lasgouttes + + * ControlToc.C: remove getType + 2002-07-20 John Levon * ControlCommandBuffer.C: don't add "" to history diff --git a/src/frontends/controllers/ControlToc.C b/src/frontends/controllers/ControlToc.C index 50cf2a5cb3..7af987fad6 100644 --- a/src/frontends/controllers/ControlToc.C +++ b/src/frontends/controllers/ControlToc.C @@ -18,79 +18,47 @@ #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 const ControlToc::getTypes() const { - vector 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 diff --git a/src/frontends/controllers/ControlToc.h b/src/frontends/controllers/ControlToc.h index 6047ce2c39..b0aedf76ad 100644 --- a/src/frontends/controllers/ControlToc.h +++ b/src/frontends/controllers/ControlToc.h @@ -19,8 +19,9 @@ #pragma interface #endif +#include #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 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 diff --git a/src/frontends/xforms/ChangeLog b/src/frontends/xforms/ChangeLog index 603295763d..4b5d20d05f 100644 --- a/src/frontends/xforms/ChangeLog +++ b/src/frontends/xforms/ChangeLog @@ -1,3 +1,21 @@ +2002-07-21 Jean-Marc Lasgouttes + + * 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 * XFormsView.C: move autosave timer to LyXView.C diff --git a/src/frontends/xforms/DropDown.C b/src/frontends/xforms/DropDown.C index 6fe29e7788..44dcd6e49f 100644 --- a/src/frontends/xforms/DropDown.C +++ b/src/frontends/xforms/DropDown.C @@ -177,7 +177,7 @@ void DropDown::completed() { XUngrabPointer(fl_get_display(), CurrentTime); fl_hide_form(form_); - result(getSelectedStringFromBrowser(browser_)); + result(getString(browser_)); } diff --git a/src/frontends/xforms/FormCitation.C b/src/frontends/xforms/FormCitation.C index 9a2ce6e751..d4cc950828 100644 --- a/src/frontends/xforms/FormCitation.C +++ b/src/frontends/xforms/FormCitation.C @@ -49,7 +49,7 @@ void fillChoice(FD_citation * dialog, vector vec) // Check whether the current contents of the browser will be // changed by loading the contents of the vec... vector 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 browser_keys = getVectorFromBrowser(browser); + vector browser_keys = getVector(browser); if (browser_keys == keys) return; diff --git a/src/frontends/xforms/FormForks.C b/src/frontends/xforms/FormForks.C index cf4df6491e..a1242a808a 100644 --- a/src/frontends/xforms/FormForks.C +++ b/src/frontends/xforms/FormForks.C @@ -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 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::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 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 const kill_vec = - getVectorFromBrowser(dialog_->browser_kill); + getVector(dialog_->browser_kill); vector::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 const child_vec = - getVectorFromBrowser(dialog_->browser_children); + getVector(dialog_->browser_children); vector::const_iterator it = find_if(child_vec.begin(), child_vec.end(), FindPID(pid_str)); @@ -295,7 +295,7 @@ namespace { vector const getPIDvector(FL_OBJECT * ob) { - vector vec = getVectorFromBrowser(ob); + vector 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 const kill_vec = - getVectorFromBrowser(dialog_->browser_kill); + getVector(dialog_->browser_kill); vector::const_iterator it = find(kill_vec.begin(), kill_vec.end(), pid_str); diff --git a/src/frontends/xforms/FormGraphics.C b/src/frontends/xforms/FormGraphics.C index 22d9e46ab5..dc93935c0d 100644 --- a/src/frontends/xforms/FormGraphics.C +++ b/src/frontends/xforms/FormGraphics.C @@ -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); diff --git a/src/frontends/xforms/FormMinipage.C b/src/frontends/xforms/FormMinipage.C index eb37a93b8e..7a5d2a1275 100644 --- a/src/frontends/xforms/FormMinipage.C +++ b/src/frontends/xforms/FormMinipage.C @@ -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!")); diff --git a/src/frontends/xforms/FormParagraph.C b/src/frontends/xforms/FormParagraph.C index 4b5da5d60a..5261614445 100644 --- a/src/frontends/xforms/FormParagraph.C +++ b/src/frontends/xforms/FormParagraph.C @@ -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; diff --git a/src/frontends/xforms/FormRef.C b/src/frontends/xforms/FormRef.C index 99fc14dd2d..86a7ded32e 100644 --- a/src/frontends/xforms/FormRef.C +++ b/src/frontends/xforms/FormRef.C @@ -97,7 +97,7 @@ void FormRef::update() // Get the available buffers vector const buffers = controller().getBufferList(); vector 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 const & akeys) const if (fl_get_button(dialog_->check_sort)) sort(keys.begin(), keys.end()); - vector browser_keys = - getVectorFromBrowser(dialog_->browser_refs); + vector browser_keys = getVector(dialog_->browser_refs); if (browser_keys == keys) return; diff --git a/src/frontends/xforms/FormSendto.C b/src/frontends/xforms/FormSendto.C index 1d8615d7e0..e126ced8d6 100644 --- a/src/frontends/xforms/FormSendto.C +++ b/src/frontends/xforms/FormSendto.C @@ -69,7 +69,7 @@ void FormSendto::update() } vector 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); diff --git a/src/frontends/xforms/FormSpellchecker.C b/src/frontends/xforms/FormSpellchecker.C index 7dbfa0fca4..de1c2c9a19 100644 --- a/src/frontends/xforms/FormSpellchecker.C +++ b/src/frontends/xforms/FormSpellchecker.C @@ -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; diff --git a/src/frontends/xforms/FormToc.C b/src/frontends/xforms/FormToc.C index d7ad86b254..c37e7bc183 100644 --- a/src/frontends/xforms/FormToc.C +++ b/src/frontends/xforms/FormToc.C @@ -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 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); diff --git a/src/frontends/xforms/FormToc.h b/src/frontends/xforms/FormToc.h index 308af3bdad..bde4789861 100644 --- a/src/frontends/xforms/FormToc.h +++ b/src/frontends/xforms/FormToc.h @@ -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 diff --git a/src/frontends/xforms/Menubar_pimpl.C b/src/frontends/xforms/Menubar_pimpl.C index 6c6ed7eb34..cb6f94f73b 100644 --- a/src/frontends/xforms/Menubar_pimpl.C +++ b/src/frontends/xforms/Menubar_pimpl.C @@ -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 @@ -206,15 +206,13 @@ string const fixlabel(string const & str) void add_toc2(int menu, string const & extra_label, vector & smn, Window win, - vector 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); diff --git a/src/frontends/xforms/xforms_helpers.C b/src/frontends/xforms/xforms_helpers.C index cfc3474e80..e4f20f6234 100644 --- a/src/frontends/xforms/xforms_helpers.C +++ b/src/frontends/xforms/xforms_helpers.C @@ -46,80 +46,65 @@ void setEnabled(FL_OBJECT * ob, bool enable) } -// Given an fl_choice, create a vector of its entries -vector const getVectorFromChoice(FL_OBJECT * ob) +// Given an fl_choice or an fl_browser, create a vector of its entries +vector const getVector(FL_OBJECT * ob) { - vector 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 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 const getVectorFromBrowser(FL_OBJECT * ob) -{ - vector 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 const vec = getVectorFromChoice(choice); + vector const vec = getVector(choice); vector::const_iterator it = std::find(vec.begin(), vec.end(), unit); if (it != vec.end()) { diff --git a/src/frontends/xforms/xforms_helpers.h b/src/frontends/xforms/xforms_helpers.h index f5a7d9993c..d651815512 100644 --- a/src/frontends/xforms/xforms_helpers.h +++ b/src/frontends/xforms/xforms_helpers.h @@ -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 const getVectorFromChoice(FL_OBJECT *); - -/// Given an fl_browser, create a vector of its entries -std::vector 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 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); diff --git a/src/graphics/ChangeLog b/src/graphics/ChangeLog index 8918c67806..a1b2bceb48 100644 --- a/src/graphics/ChangeLog +++ b/src/graphics/ChangeLog @@ -1,3 +1,9 @@ +2002-07-21 Herbert Voss + + * GraphicsImage.C: get the LyXAspectRatio run. + + * GraphicsParams.[Ch]: add bool keepLyXXAspectRatio + 2002-07-20 Jean-Marc Lasgouttes * PreviewLoader.C (startLoading): pass an interger as resolution diff --git a/src/graphics/GraphicsImage.C b/src/graphics/GraphicsImage.C index 71d54f698a..8b5be6fae0 100644 --- a/src/graphics/GraphicsImage.C +++ b/src/graphics/GraphicsImage.C @@ -5,6 +5,7 @@ * * \author Baruch Even * \author Angus Leeming + * \author Herbert Voss */ #include @@ -15,6 +16,10 @@ #include "GraphicsImage.h" #include "GraphicsParams.h" +#include "debug.h" + +using std::endl; +using std::abs; namespace grfx { @@ -29,32 +34,71 @@ boost::function0 Image::loadableFormats; std::pair 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 + diff --git a/src/graphics/GraphicsParams.C b/src/graphics/GraphicsParams.C index c8e106efa9..896332759e 100644 --- a/src/graphics/GraphicsParams.C +++ b/src/graphics/GraphicsParams.C @@ -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); } diff --git a/src/graphics/GraphicsParams.h b/src/graphics/GraphicsParams.h index 611fe99598..302125344c 100644 --- a/src/graphics/GraphicsParams.h +++ b/src/graphics/GraphicsParams.h @@ -64,6 +64,7 @@ struct Params unsigned int width; unsigned int height; unsigned int scale; + bool keepLyXAspectRatio; /// Rotation angle. int angle; diff --git a/src/insets/ChangeLog b/src/insets/ChangeLog index 4f52aa7ea4..e831ee35f8 100644 --- a/src/insets/ChangeLog +++ b/src/insets/ChangeLog @@ -1,3 +1,14 @@ +2002-07-21 Herbert Voss + + * insetgraphicsParams.C: fet the keepLyXAspectRatio run. Move the + image relevant part into graphics/GraphicsImgae.C + +2002-07-21 Jean-Marc Lasgouttes + + * 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 * insettext.C (localDispatch): BufferView::Dispatch has been diff --git a/src/insets/insetfloatlist.C b/src/insets/insetfloatlist.C index 2bebacd114..a64693664f 100644 --- a/src/insets/insetfloatlist.C +++ b/src/insets/insetfloatlist.C @@ -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; diff --git a/src/insets/insetgraphicsParams.C b/src/insets/insetgraphicsParams.C index c9d31047f9..4bdb4be32a 100644 --- a/src/insets/insetgraphicsParams.C +++ b/src/insets/insetgraphicsParams.C @@ -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; } diff --git a/src/insets/insettoc.C b/src/insets/insettoc.C index 77153639fe..b658a3bd80 100644 --- a/src/insets/insettoc.C +++ b/src/insets/insettoc.C @@ -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; diff --git a/src/lyxfunc.C b/src/lyxfunc.C index 3a76379fd0..8fe242caae 100644 --- a/src/lyxfunc.C +++ b/src/lyxfunc.C @@ -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 (")) diff --git a/src/support/ChangeLog b/src/support/ChangeLog index efa10968e6..3ea893de92 100644 --- a/src/support/ChangeLog +++ b/src/support/ChangeLog @@ -1,3 +1,7 @@ +2002-07-21 Jean-Marc Lasgouttes + + * lstrings.h: correct comments for token and tokenPos + 2002-07-20 Dekel Tsur * lyxstring.C (operator>>): replace code which works only with diff --git a/src/support/lstrings.h b/src/support/lstrings.h index 4e2627f85b..e20d0d80e5 100644 --- a/src/support/lstrings.h +++ b/src/support/lstrings.h @@ -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 index 0000000000..53e55d80f3 --- /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 + * \author Jean-Marc Lasgouttes + */ + +#include + +#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(*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 const getTypes(Buffer const * buffer) +{ + vector 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 index 0000000000..78ec77afa9 --- /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 + * \author Jean-Marc Lasgouttes + */ + +#ifndef TOC_H +#define TOC_H + +#ifdef __GNUG__ +#pragma interface +#endif + +#include "support/LOstream.h" +#include "LString.h" + +#include +#include + +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 Toc; +/// +typedef std::map TocList; + +/// +TocList const getTocList(Buffer const *); + +/// +std::vector 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 -- 2.39.2