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
This commit is contained in:
Angus Leeming 2002-05-01 09:25:51 +00:00
parent 53499b74fd
commit c2388650ed
10 changed files with 109 additions and 57 deletions

View File

@ -1,3 +1,8 @@
2002-04-30 Angus Leeming <a.leeming@ic.ac.uk>
* ControlGraphics.[Ch] (getRotationOriginData): new helper function.
Enables the gui's to internationalise these strings.
2002-04-30 John Levon <moz@compsoc.man.ac.uk>
* frnt_lang.C: fix build

View File

@ -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<RotationOriginPair> getRotationOriginData()
{
static vector<RotationOriginPair> 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

View File

@ -21,6 +21,8 @@
#endif
#include "ControlInset.h"
#include <utility>
#include <vector>
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<string, string> RotationOriginPair;
///
std::vector<RotationOriginPair> getRotationOriginData();
} // namespace frnt
#endif // CONTROLGRAPHICS_H

View File

@ -1,3 +1,18 @@
2002-04-30 Angus Leeming <a.leeming@ic.ac.uk>
* 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<string> 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 <a.leeming@ic.ac.uk>
* FormCharacter.C:

View File

@ -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<class A>
typename vector<A>::size_type findPos(vector<A> const & vec, A const & val)
{
typename vector<A>::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()));

View File

@ -1090,21 +1090,6 @@ void FormDocument::class_update(BufferParams const & params)
}
namespace {
template<class A>
typename vector<A>::size_type findPos(vector<A> const & vec, A const & val)
{
typename vector<A>::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())

View File

@ -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<RotationOriginPair> 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,

View File

@ -19,6 +19,7 @@
#include "FormBase.h"
#include "RadioButtonGroup.h"
#include <vector>
class ControlGraphics;
struct FD_form_graphics;
@ -74,6 +75,9 @@ private:
boost::scoped_ptr<FD_form_bbox> bbox_;
///
boost::scoped_ptr<FD_form_special> special_;
/// Store the LaTeX names for the rotation origins.
std::vector<string> origins_;
};
#endif // FORMGRAPHICS_H

View File

@ -1758,21 +1758,6 @@ bool FormPreferences::Language::input(FL_OBJECT const * const ob)
}
namespace {
template<class A>
typename vector<A>::size_type findPos(vector<A> const & vec, A const & val)
{
typename vector<A>::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,

View File

@ -19,6 +19,7 @@
#include "Color.h"
#include "LString.h"
#include <algorithm>
#include <vector>
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<class A>
typename std::vector<A>::size_type
findPos(std::vector<A> const & vec, A const & val)
{
typename std::vector<A>::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);