"Vincent van Ravesteijn - TNW" <[EMAIL PROTECTED]> writes:
> See:
>
> "Why doesn't overloading work for derived classes?" at
>
> http://www.research.att.com/~bs/bs_faq2.html#overloadderived

Yes, it works! I am not convinced by the argument, but it is OK.

JMarc

PS: here is my updated insetinfo patch with further simplifications.

svndiff src/insets/InsetInfo.cpp src/insets/InsetInfo.h lib/layouts/stdinsets.inc

Index: src/insets/InsetInfo.cpp
===================================================================
--- src/insets/InsetInfo.cpp	(revision 26565)
+++ src/insets/InsetInfo.cpp	(working copy)
@@ -45,13 +45,47 @@ using namespace lyx::support;
 
 namespace lyx {
 
+namespace {
+
+typedef Translator<InsetInfo::info_type, string> NameTranslator;
+
+NameTranslator const initTranslator()
+{	
+	NameTranslator translator(InsetInfo::UNKNOWN_INFO, "unknown");
+
+	translator.addPair(InsetInfo::SHORTCUTS_INFO, "shortcuts");
+	translator.addPair(InsetInfo::SHORTCUT_INFO, "shortcut");
+	translator.addPair(InsetInfo::LYXRC_INFO, "lyxrc");
+	translator.addPair(InsetInfo::PACKAGE_INFO, "package");
+	translator.addPair(InsetInfo::TEXTCLASS_INFO, "textclass");
+	translator.addPair(InsetInfo::MENU_INFO, "menu");
+	translator.addPair(InsetInfo::ICON_INFO, "icon");
+	translator.addPair(InsetInfo::BUFFER_INFO, "buffer");
+
+	return translator;
+}
 
+/// The translator between the information type enum and corresponding string.
+NameTranslator const & nameTranslator()
+{
+	static NameTranslator const translator = initTranslator();
+	return translator;
+}
+
+} // namespace anon
+
+/////////////////////////////////////////////////////////////////////////
+//
+// InsetInfo
+//
+/////////////////////////////////////////////////////////////////////////
+
+
+	
 InsetInfo::InsetInfo(Buffer const & buf, string const & name) 
-	: InsetText(buf), type_(UNKNOWN_INFO), name_(),
-	  mouse_hover_(false)
+	: InsetCollapsable(buf, Collapsed), type_(UNKNOWN_INFO), name_()
 {
 	setAutoBreakRows(true);
-	setDrawFrame(true);
 	setInfo(name);
 }
 
@@ -59,19 +93,19 @@ InsetInfo::InsetInfo(Buffer const & buf,
 Inset * InsetInfo::editXY(Cursor & cur, int x, int y)
 {
 	cur.push(*this);
-	return InsetText::editXY(cur, x, y);
+	return InsetCollapsable::editXY(cur, x, y);
 }
 
 
-void InsetInfo::draw(PainterInfo & pi, int x, int y) const
+string InsetInfo::infoType() const
 {
-	InsetText::draw(pi, x, y); 
+	return nameTranslator().find(type_);
 }
 
 
-string InsetInfo::infoType() const
+docstring InsetInfo::name() const 
 {
-	return nameTranslator().find(type_);
+	return from_ascii("Info:" + infoType());
 }
 
 
@@ -79,40 +113,10 @@ docstring InsetInfo::toolTip(BufferView 
 {
 	odocstringstream os;
 	os << _("Information regarding ")
-	   << _(nameTranslator().find(type_))
-	   << " " << from_utf8(name_);
+	   << _(infoType()) << " " << from_utf8(name_);
 	return os.str();
 }
 
-namespace {
-
-Translator<InsetInfo::info_type, string> const initTranslator()
-{	
-	Translator<InsetInfo::info_type, string> 
-		translator(InsetInfo::UNKNOWN_INFO, "unknown");
-
-	translator.addPair(InsetInfo::SHORTCUTS_INFO, "shortcuts");
-	translator.addPair(InsetInfo::SHORTCUT_INFO, "shortcut");
-	translator.addPair(InsetInfo::LYXRC_INFO, "lyxrc");
-	translator.addPair(InsetInfo::PACKAGE_INFO, "package");
-	translator.addPair(InsetInfo::TEXTCLASS_INFO, "textclass");
-	translator.addPair(InsetInfo::MENU_INFO, "menu");
-	translator.addPair(InsetInfo::ICON_INFO, "icon");
-	translator.addPair(InsetInfo::BUFFER_INFO, "buffer");
-
-	return translator;
-}
-
-} // namespace anon
-
-Translator<InsetInfo::info_type, string> 
-	const & InsetInfo::nameTranslator() const
-{
-	static Translator<info_type, string> const translator = initTranslator();
-	return translator;
-}
-
-	
 
 void InsetInfo::read(Lexer & lex)
 {
@@ -136,14 +140,14 @@ void InsetInfo::read(Lexer & lex)
 			_("Missing \\end_inset at this point."),
 			from_utf8(token));
 	}
+	setLayout(buffer().params());
 	updateInfo();
 }
 
 
 void InsetInfo::write(ostream & os) const
 {
-	os << "Info\ntype  \"" << nameTranslator().find(type_)
-	   << "\"\narg   \"" << name_ << '\"';
+	os << "Info\ntype  \"" << infoType() << "\"\narg   \"" << name_ << '\"';
 }
 
 
@@ -194,7 +198,7 @@ bool InsetInfo::getStatus(Cursor & cur, 
 	case LFUN_MOUSE_TRIPLE:
 	case LFUN_COPY:
 	case LFUN_INSET_SETTINGS:
-		return InsetText::getStatus(cur, cmd, flag);
+		return InsetCollapsable::getStatus(cur, cmd, flag);
 
 	case LFUN_INSET_MODIFY:
 		flag.setEnabled(true);
@@ -218,7 +222,7 @@ void InsetInfo::doDispatch(Cursor & cur,
 	case LFUN_MOUSE_TRIPLE:
 	case LFUN_COPY:
 	case LFUN_INSET_SETTINGS:
-		InsetText::doDispatch(cur, cmd);
+		InsetCollapsable::doDispatch(cur, cmd);
 		break;
 
 	case LFUN_INSET_MODIFY:
@@ -240,27 +244,25 @@ void InsetInfo::setInfo(string const & n
 	string type;
 	name_ = trim(split(name, type, ' '));
 	type_ = nameTranslator().find(type);
+	setLayout(buffer().params());
 	updateInfo();
 }
 
 
 void InsetInfo::error(string const & err)
 {
-	InsetText::setText(bformat(_(err), from_utf8(name_)), buffer().params().getFont(),
-		false);
+	setText(bformat(_(err), from_utf8(name_)), Font(inherit_font), false);
 }
 
 
 void InsetInfo::setText(docstring const & str)
 {
-	InsetText::setText(str, buffer().params().getFont(), false);
+	setText(str, Font(inherit_font), false);
 }
 
 
 void InsetInfo::updateInfo()
 {
-	InsetText::clear();
-
 	BufferParams const & bp = buffer().params();	
 
 	switch (type_) {
@@ -281,9 +283,11 @@ void InsetInfo::updateInfo()
 			break;
 		}
 		if (type_ == SHORTCUT_INFO)
-			setText(bindings.rbegin()->print(KeySequence::Portable));
+			setText(bindings.rbegin()->print(KeySequence::Portable),
+				Font(getLayout().font()), false);
 		else
-			setText(theTopLevelKeymap().printBindings(func));
+			setText(theTopLevelKeymap().printBindings(func), 
+				Font(getLayout().font()), false);
 		break;
 	}
 	case LYXRC_INFO: {
@@ -319,17 +323,17 @@ void InsetInfo::updateInfo()
 			error("No menu entry for action %1$s");
 			break;
 		}
-		// if find, return its path.
-		InsetText::clear();
+		// if found, return its path.
+		clear();
 		Paragraph & info = paragraphs().front();
-		unsigned int i = 0;
+		size_type i = 0;
 		while (!names.empty()) {
 			// do not insert > for the top level menu item
 			if (i != 0)
 				info.insertInset(0, new InsetSpecialChar(InsetSpecialChar::MENU_SEPARATOR),
 					Change(Change::UNCHANGED));
 			for (i = 0; i != names.back().length(); ++i)
-				info.insertChar(i, names.back()[i], bp.getFont(), false);
+				info.insertChar(i, names.back()[i], Font(getLayout().font()), false);
 			names.pop_back();
 		}
 		break;
@@ -337,17 +341,20 @@ void InsetInfo::updateInfo()
 	case ICON_INFO: {
 		FuncRequest func = lyxaction.lookupFunc(name_);
 		docstring icon_name = theApp()->iconName(func, true);
-		//FIXME: We should use the icon directly instead of going through
-		// FileName. The code below won't work if the icon is embedded in the
-		// executable through the Qt resource system.
+		//FIXME: We should use the icon directly instead of
+		// going through FileName. The code below won't work
+		// if the icon is embedded in the executable through
+		// the Qt resource system.
 		FileName file(to_utf8(icon_name));
 		if (!file.exists())
 			break;
+		InsetGraphics * inset = new InsetGraphics(buffer());
 		InsetGraphicsParams igp;
 		igp.filename = file;
-		InsetGraphics * inset = new InsetGraphics(buffer());
 		inset->setParams(igp);
-		paragraphs().front().insertInset(0, inset, Change(Change::UNCHANGED));
+		clear();
+		paragraphs().front().insertInset(0, inset, 
+						 Change(Change::UNCHANGED));
 		break;
 	}
 	case BUFFER_INFO: {
@@ -362,15 +369,6 @@ void InsetInfo::updateInfo()
 		break;
 	}
 	}
-	// remove indent
-	paragraphs().begin()->params().noindent(true);
-}
-
-
-bool InsetInfo::setMouseHover(bool mouse_hover)
-{
-	mouse_hover_ = mouse_hover;
-	return true;
 }
 
 
@@ -379,4 +377,5 @@ docstring InsetInfo::contextMenu(BufferV
 	return from_ascii("context-info");
 }
 
+
 } // namespace lyx
Index: src/insets/InsetInfo.h
===================================================================
--- src/insets/InsetInfo.h	(revision 26565)
+++ src/insets/InsetInfo.h	(working copy)
@@ -12,8 +12,7 @@
 #ifndef INSET_INFO_H
 #define INSET_INFO_H
 
-#include "InsetText.h"
-#include "RenderButton.h"
+#include "InsetCollapsable.h"
 #include "Cursor.h"
 
 #include "support/gettext.h"
@@ -78,7 +77,7 @@ namespace lyx {
 
 /** Used to insert index labels
   */
-class InsetInfo : public InsetText {
+class InsetInfo : public InsetCollapsable {
 public:
 	enum info_type {
 		UNKNOWN_INFO,   // Invalid type
@@ -95,12 +94,14 @@ public:
 	///
 	InsetInfo(Buffer const & buf, std::string const & info = std::string());
 	///
+	InsetCode lyxCode() const { return INFO_CODE; }
+	///
+	docstring name() const;
+	///
 	Inset * editXY(Cursor & cur, int x, int y);
 	///
 	EDITABLE editable() const { return NOT_EDITABLE; }
 	///
-	void draw(PainterInfo & pi, int x, int y) const;
-	///
 	void read(Lexer & lex);
 	///
 	void write(std::ostream & os) const;
@@ -117,33 +118,29 @@ public:
 	///
 	void doDispatch(Cursor & cur, FuncRequest & cmd);
 	///
-	InsetCode lyxCode() const { return INFO_CODE; }
-	///
 	void setInfo(std::string const & info);
 	/// update info_ and text
 	void updateInfo();
 	///
-	bool setMouseHover(bool mouse_hover);
-	///
 	docstring toolTip(BufferView const & bv, int x, int y) const;
 	///
 	docstring contextMenu(BufferView const &, int, int) const;
+	/// should paragraph indendation be ommitted in any case?
+	bool neverIndent() const { return true; }
 
 private:
-	/// The translator between the information type enum and corresponding string.
-	Translator<info_type, std::string> const & nameTranslator() const;
 	///
 	virtual Inset * clone() const { return new InsetInfo(*this); }
 	///
 	void error(std::string const & err);
 	///
 	void setText(docstring const & str);
+	// make sure that the other version of setText is still available.
+	using InsetCollapsable::setText;
 	///
 	info_type type_;
 	///
 	std::string name_;
-	///
-	bool mouse_hover_;
 };
 
 
Index: lib/layouts/stdinsets.inc
===================================================================
--- lib/layouts/stdinsets.inc	(revision 26565)
+++ lib/layouts/stdinsets.inc	(working copy)
@@ -273,3 +273,43 @@ InsetLayout OptArg
 	EndFont
 	MultiPar              false
 End
+
+InsetLayout Info
+	Decoration	      conglomerate
+End
+
+InsetLayout Info:menu
+	LatexType             command
+	LatexName             menuitem
+	Preamble
+	  \providecommand{\menuitem}[1]{\textsf{#1}}
+	EndPreamble
+	Decoration	      conglomerate
+	Font
+	  Family              sans
+	EndFont
+End
+
+InsetLayout Info:shortcut
+	LatexType             command
+	LatexName             shortcut
+	Preamble
+	  \providecommand{\shortcut}[1]{\textsf{#1}}
+	EndPreamble
+	Decoration	      conglomerate
+	Font
+	  Family              sans
+	EndFont
+End
+
+InsetLayout Info:shortcuts
+	LatexType             command
+	LatexName             shortcut
+	Preamble
+	  \providecommand{\shortcut}[1]{\textsf{#1}}
+	EndPreamble
+	Decoration	      conglomerate
+	Font
+	  Family              sans
+	EndFont
+End

Reply via email to