From c2388650ed573dbab215522151774df514d6aa51 Mon Sep 17 00:00:00 2001 From: Angus Leeming Date: Wed, 1 May 2002 09:25:51 +0000 Subject: [PATCH] Internationalise the rotation origin strings in the graphics dialog in the same manner as has been used already for the language names in a number of dialogs. Move repeated copies of the findPos template to xforms_helpers.h. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@4098 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/frontends/controllers/ChangeLog | 5 +++ src/frontends/controllers/ControlGraphics.C | 40 ++++++++++++++++++++- src/frontends/controllers/ControlGraphics.h | 10 ++++++ src/frontends/xforms/ChangeLog | 15 ++++++++ src/frontends/xforms/FormCharacter.C | 16 +-------- src/frontends/xforms/FormDocument.C | 15 -------- src/frontends/xforms/FormGraphics.C | 31 ++++++++++------ src/frontends/xforms/FormGraphics.h | 4 +++ src/frontends/xforms/FormPreferences.C | 15 -------- src/frontends/xforms/xforms_helpers.h | 15 ++++++++ 10 files changed, 109 insertions(+), 57 deletions(-) diff --git a/src/frontends/controllers/ChangeLog b/src/frontends/controllers/ChangeLog index c4479ef0bf..c156c434dd 100644 --- a/src/frontends/controllers/ChangeLog +++ b/src/frontends/controllers/ChangeLog @@ -1,3 +1,8 @@ +2002-04-30 Angus Leeming + + * ControlGraphics.[Ch] (getRotationOriginData): new helper function. + Enables the gui's to internationalise these strings. + 2002-04-30 John Levon * frnt_lang.C: fix build diff --git a/src/frontends/controllers/ControlGraphics.C b/src/frontends/controllers/ControlGraphics.C index a834b41486..1bec50fde5 100644 --- a/src/frontends/controllers/ControlGraphics.C +++ b/src/frontends/controllers/ControlGraphics.C @@ -48,9 +48,9 @@ using std::pair; using std::make_pair; using std::ifstream; +using std::vector; namespace { -using std::vector; // FIXME: currently we need the second '|' to prevent mis-interpretation! // All supported graphic formats with their file-extension and the @@ -181,3 +181,41 @@ bool ControlGraphics::isFilenameValid(string const & fname) const string const name = MakeAbsPath(fname, lv_.buffer()->filePath()); return IsFileReadable(name); } + + +namespace frnt { + +namespace { + +char const * const rorigin_latex_strs[] = { + "center", "leftTop", "leftBottom", "leftBaseline", + "centerTop", "centerBottom", "centerBaseline", + "rightTop", "rightBottom", "rightBaseline" }; + +char const * const rorigin_gui_strs[] = { + N_("center"), + N_("left top"), N_("left bottom"), N_("left baseline"), + N_("center top"), N_("center bottom"), N_("center baseline"), + N_("right top"), N_("right bottom"), N_("right baseline") }; + +size_t rorigin_size = sizeof(rorigin_latex_strs) / sizeof(char *); + +} // namespace anon + +vector getRotationOriginData() +{ + static vector data; + if (!data.empty()) + return data; + + data.resize(rorigin_size); + for (lyx::size_type i = 0; i < rorigin_size; ++i) { + data[i] = std::make_pair(_(rorigin_gui_strs[i]), + rorigin_latex_strs[i]); + } + + return data; +} + +} // namespace frnt + diff --git a/src/frontends/controllers/ControlGraphics.h b/src/frontends/controllers/ControlGraphics.h index 9a6cc481d9..3e5d4663af 100644 --- a/src/frontends/controllers/ControlGraphics.h +++ b/src/frontends/controllers/ControlGraphics.h @@ -21,6 +21,8 @@ #endif #include "ControlInset.h" +#include +#include class InsetGraphics; class InsetGraphicsParams; @@ -42,6 +44,7 @@ public: bool bbChanged; /// test if file exist bool isFilenameValid(string const & fname) const; + private: /// Dispatch the changed parameters to the kernel. virtual void applyParamsToInset(); @@ -53,4 +56,11 @@ private: virtual InsetGraphicsParams const getParams(InsetGraphics const &); }; +namespace frnt { + /// The (tranlated) GUI string and it's LaTeX equivalent. + typedef std::pair RotationOriginPair; + /// + std::vector getRotationOriginData(); +} // namespace frnt + #endif // CONTROLGRAPHICS_H diff --git a/src/frontends/xforms/ChangeLog b/src/frontends/xforms/ChangeLog index 168f22e163..1c062df87d 100644 --- a/src/frontends/xforms/ChangeLog +++ b/src/frontends/xforms/ChangeLog @@ -1,3 +1,18 @@ +2002-04-30 Angus Leeming + + * FormCharacter.C: + * FormDocument.C: + * FormPreferences.C (findPos): remove this template to xforms_helpers.h. + + * xforms_helpers.h (findPos): new template. + + * FormGraphics.h: store a vector origins_ of the LaTeX names + for the rotation origins. + + * FormGraphics.C: internationalise the rotation origin strings in the + choice using the same approach as used for the language names in the + Character, Document, Preferences dialogs. + 2002-04-30 Angus Leeming * FormCharacter.C: diff --git a/src/frontends/xforms/FormCharacter.C b/src/frontends/xforms/FormCharacter.C index 0bf8a2964d..ecd8add69a 100644 --- a/src/frontends/xforms/FormCharacter.C +++ b/src/frontends/xforms/FormCharacter.C @@ -22,6 +22,7 @@ #include "gettext.h" #include "combox.h" #include "helper_funcs.h" +#include "xforms_helpers.h" #include "frnt_lang.h" #include "support/lstrings.h" @@ -144,21 +145,6 @@ void FormCharacter::apply() } -namespace { - -template -typename vector::size_type findPos(vector const & vec, A const & val) -{ - typename vector::const_iterator it = - find(vec.begin(), vec.end(), val); - if (it == vec.end()) - return 0; - return it - vec.begin(); -} - -} // namespace anon - - void FormCharacter::update() { int pos = int(findPos(family_, controller().getFamily())); diff --git a/src/frontends/xforms/FormDocument.C b/src/frontends/xforms/FormDocument.C index a4cd1bd808..4a8159c5ba 100644 --- a/src/frontends/xforms/FormDocument.C +++ b/src/frontends/xforms/FormDocument.C @@ -1090,21 +1090,6 @@ void FormDocument::class_update(BufferParams const & params) } -namespace { - -template -typename vector::size_type findPos(vector const & vec, A const & val) -{ - typename vector::const_iterator it = - std::find(vec.begin(), vec.end(), val); - if (it == vec.end()) - return 0; - return it - vec.begin(); -} - -} // namespace anon - - void FormDocument::language_update(BufferParams const & params) { if (!language_.get()) diff --git a/src/frontends/xforms/FormGraphics.C b/src/frontends/xforms/FormGraphics.C index 6b43148610..c927be9a99 100644 --- a/src/frontends/xforms/FormGraphics.C +++ b/src/frontends/xforms/FormGraphics.C @@ -20,6 +20,7 @@ #include "Alert.h" #include "xforms_helpers.h" +#include "helper_funcs.h" #include "input_validators.h" #include "debug.h" // for lyxerr #include "support/lstrings.h" // for strToDbl & tostr @@ -28,6 +29,7 @@ #include "lyxrc.h" // for lyxrc.display_graphics using std::endl; +using std::vector; namespace { @@ -94,12 +96,15 @@ void FormGraphics::build() setPrehandler(file_->input_subcaption); setPrehandler(file_->input_rotate_angle); - string const choice_origin = - "center|" // c - "leftTop|leftBottom|leftBaseline|" // lt lb lB - "centerTop|centerBottom|centerBaseline|" // ct cb cB - "rightTop|rightBottom|rightBaseline"; // rt rb rB - fl_addto_choice(file_->choice_origin, choice_origin.c_str()); + using namespace frnt; + vector origindata = getRotationOriginData(); + + // Store the identifiers for later + origins_ = getSecond(origindata); + + string const choice = + " " + getStringFromVector(getFirst(origindata), " | ") +" "; + fl_addto_choice(file_->choice_origin, choice.c_str()); bc().addReadOnly(file_->button_browse); bc().addReadOnly(file_->check_subcaption); @@ -211,10 +216,12 @@ void FormGraphics::apply() igp.rotateAngle -= 360.0; } } - if (fl_get_choice(file_->choice_origin) > 0) - igp.rotateOrigin = fl_get_choice_text(file_->choice_origin); + int const pos = fl_get_choice(file_->choice_origin); + if (pos > 0) + igp.rotateOrigin = origins_[pos-1]; else igp.rotateOrigin = string(); + igp.draft = fl_get_button(file_->check_draft); igp.noUnzip = fl_get_button(file_->check_nounzip); @@ -296,7 +303,6 @@ void FormGraphics::apply() } - void FormGraphics::update() { // Update dialog with details from inset InsetGraphicsParams & igp = controller().params(); @@ -312,8 +318,11 @@ void FormGraphics::update() { tostr(igp.rotateAngle).c_str()); if (igp.rotateOrigin.empty()) fl_set_choice(file_->choice_origin,1); - else - fl_set_choice_text(file_->choice_origin,igp.rotateOrigin.c_str()); + else { + int pos = int(findPos(origins_, igp.rotateOrigin)); + fl_set_choice(file_->choice_origin, pos+1); + } + setEnabled(file_->input_rotate_angle, fl_get_button(file_->check_rotate)); setEnabled(file_->choice_origin, diff --git a/src/frontends/xforms/FormGraphics.h b/src/frontends/xforms/FormGraphics.h index db5fccd4b3..9aaf826b89 100644 --- a/src/frontends/xforms/FormGraphics.h +++ b/src/frontends/xforms/FormGraphics.h @@ -19,6 +19,7 @@ #include "FormBase.h" #include "RadioButtonGroup.h" +#include class ControlGraphics; struct FD_form_graphics; @@ -74,6 +75,9 @@ private: boost::scoped_ptr bbox_; /// boost::scoped_ptr special_; + + /// Store the LaTeX names for the rotation origins. + std::vector origins_; }; #endif // FORMGRAPHICS_H diff --git a/src/frontends/xforms/FormPreferences.C b/src/frontends/xforms/FormPreferences.C index 3e7000d6d5..b468715e39 100644 --- a/src/frontends/xforms/FormPreferences.C +++ b/src/frontends/xforms/FormPreferences.C @@ -1758,21 +1758,6 @@ bool FormPreferences::Language::input(FL_OBJECT const * const ob) } -namespace { - -template -typename vector::size_type findPos(vector const & vec, A const & val) -{ - typename vector::const_iterator it = - std::find(vec.begin(), vec.end(), val); - if (it == vec.end()) - return 0; - return it - vec.begin(); -} - -} // namespace anon - - void FormPreferences::Language::update() { fl_set_button(dialog_->check_use_kbmap, diff --git a/src/frontends/xforms/xforms_helpers.h b/src/frontends/xforms/xforms_helpers.h index c8fb815c3f..7e0acc9ed0 100644 --- a/src/frontends/xforms/xforms_helpers.h +++ b/src/frontends/xforms/xforms_helpers.h @@ -19,6 +19,7 @@ #include "Color.h" #include "LString.h" +#include #include class LyXLength; @@ -82,6 +83,20 @@ void updateWidgetsFromLength(FL_OBJECT * input, FL_OBJECT * choice, string const & default_unit); +/** Return the position of val in the vector if found. + If not found, return 0. + */ +template +typename std::vector::size_type +findPos(std::vector const & vec, A const & val) +{ + typename std::vector::const_iterator it = + std::find(vec.begin(), vec.end(), val); + if (it == vec.end()) + return 0; + return std::distance(vec.begin(), it); +} + /// Called from Preferences when the cursor color is changed. void setCursorColor(int color);