Hi,

Due to an unexpected bout of insomnia, I've replaced the deprecated
Combo with a ComboBox in GToolbar.[Ch].

John
Index: ChangeLog
===================================================================
RCS file: /cvs/lyx/lyx-devel/src/frontends/gtk/ChangeLog,v
retrieving revision 1.62
diff -u -3 -p -r1.62 ChangeLog
--- ChangeLog	2004/09/27 19:04:17	1.62
+++ ChangeLog	2004/09/28 05:56:26
@@ -1,3 +1,8 @@
+2004-09-28  John Spray  <[EMAIL PROTECTED]>
+
+	* GToolbar.[Ch]: Use ComboBox instead of deprecated Combo for
+	GLayoutBox class
+
 2004-09-27  Lars Gullik Bjønnes  <[EMAIL PROTECTED]>
 
 	* lyx_gui.C (start): change comment
Index: GToolbar.C
===================================================================
RCS file: /cvs/lyx/lyx-devel/src/frontends/gtk/GToolbar.C,v
retrieving revision 1.19
diff -u -3 -p -r1.19 GToolbar.C
--- GToolbar.C	2004/09/27 00:08:33	1.19
+++ GToolbar.C	2004/09/28 05:56:26
@@ -46,21 +46,6 @@ LyXTextClass const & getTextClass(LyXVie
 	return lv.buffer()->params().getLyXTextClass();
 }
 
-
-void comboClear(Gtk::Combo & combo)
-{
-	std::vector<Glib::ustring> strings;
-	strings.push_back("");
-	combo.set_popdown_strings(strings);
-}
-
-
-bool comboIsEmpty(Gtk::Combo & combo)
-{
-	std::vector<Glib::ustring> strings = combo.get_popdown_strings();
-	return (strings.empty() || (strings.size() == 1 && strings[0] == ""));
-}
-
 char const * gToolData = "tool_data";
 
 } // namespace anon
@@ -72,65 +57,90 @@ GLayoutBox::GLayoutBox(LyXView & owner,
 	: owner_(owner),
 	  internal_(false)
 {
-	combo_.set_value_in_list();
-	combo_.get_entry()->set_editable(false);
-	combo_.unset_flags(Gtk::CAN_FOCUS | Gtk::CAN_DEFAULT);
-	combo_.get_entry()->unset_flags(Gtk::CAN_FOCUS | Gtk::CAN_DEFAULT);
-	comboClear(combo_);
-
-	combo_.get_entry()->signal_changed().connect(
+	combo_.signal_changed().connect(
 		sigc::mem_fun(*this,&GLayoutBox::selected));
 
-	combo_.show();
+	cols_ = new stringcolumns;
+	model_ = Gtk::ListStore::create(*cols_);
+	combo_.set_model(model_);
+	Gtk::CellRendererText * cell = new Gtk::CellRendererText;
+	combo_.pack_start(*cell, true);
+	combo_.add_attribute(*cell,"text",0);
+	combo_.set_wrap_width(2);
+	//Initially there's nothing in the liststore, so set the size
+	//to avoid it jumping too much when the user does something that
+	//causes the first update()
+	combo_.set_size_request(130,-1);
 
+
 	combo_.set_data(
 		gToolData,
 		reinterpret_cast<void*>(&const_cast<FuncRequest &>(func)));
 
+	combo_.show();
+
 	Gtk::ToolItem * toolitem = Gtk::manage(new Gtk::ToolItem);
 	toolitem->add(combo_);
-	toolbar.insert(*toolitem,-1);
+	toolbar.append(*toolitem);
 }
 
 void GLayoutBox::set(string const & layout)
 {
 	LyXTextClass const & tc = getTextClass(owner_);
+	std::string const target = tc[layout]->name();
 
 	internal_ = true;
-	combo_.get_entry()->set_text(tc[layout]->name());
+	Gtk::TreeModel::iterator it = model_->children().begin();
+	Gtk::TreeModel::iterator end = model_->children().end();
+	for (; it != end; ++it) {
+		if ((*it)[cols_->name] == target){
+			combo_.set_active(it);
+			internal_ = false;
+			return;
+		}
+	}
 	internal_ = false;
+
+	lyxerr << "ERROR (GLayoutBox::set): layout not found! name: "
+	       << target << std::endl;
 }
 
 
 void GLayoutBox::update()
 {
-	LyXTextClass const & tc = getTextClass(owner_);
+	clear();
 
-	std::vector<Glib::ustring> strings;
+	LyXTextClass const & tc = getTextClass(owner_);
 
 	LyXTextClass::const_iterator it = tc.begin();
 	LyXTextClass::const_iterator const end = tc.end();
-	for (; it != end; ++it)
-		if ((*it)->obsoleted_by().empty())
-			strings.push_back(
-				Glib::locale_to_utf8((*it)->name()));
+
 	internal_ = true;
-	combo_.set_popdown_strings(strings);
+	for (; it != end; ++it)
+		if ((*it)->obsoleted_by().empty()) {
+			Gtk::TreeModel::iterator iter = model_->append();
+			Gtk::TreeModel::Row row = *iter;
+			row[cols_->name] = Glib::locale_to_utf8((*it)->name());
+		}
 	internal_ = false;
+
+	//now that we've loaded something into the combobox, forget
+	//the initial fixed size and let GTK decide.
+	combo_.set_size_request(-1,-1);
 }
 
 
 void GLayoutBox::clear()
 {
 	internal_ = true;
-	comboClear(combo_);
+	model_->clear();
 	internal_ = false;
 }
 
 
 void GLayoutBox::open()
 {
-	combo_.get_list()->activate();
+	combo_.popup();
 }
 
 
@@ -144,8 +154,9 @@ void GLayoutBox::selected()
 {
 	if (internal_)
 		return;
+
+	Glib::ustring layoutGuiName = (*(combo_.get_active()))[cols_->name];
 
-	string layoutGuiName = combo_.get_entry()->get_text();
 	// we get two signal, one of it is empty and useless
 	if (layoutGuiName.empty())
 		return;
@@ -208,7 +219,7 @@ void GToolbar::add(FuncRequest const & f
 	case ToolbarBackend::SEPARATOR: {
 		Gtk::SeparatorToolItem * space =
 			Gtk::manage(new Gtk::SeparatorToolItem);
-		toolbar_.insert(*space,-1);
+		toolbar_.append(*space);
 		break;
 	}
 
@@ -241,7 +252,7 @@ void GToolbar::add(FuncRequest const & f
 		tooltips_.set_tip(*toolbutton, tip, tip);
 		toolbutton->signal_clicked().connect(sigc::bind(sigc::mem_fun(*this,
 			&GToolbar::clicked), FuncRequest(func)));
-		toolbar_.insert(*toolbutton,-1);
+		toolbar_.append(*toolbutton);
 		break;
 	}
 
Index: GToolbar.h
===================================================================
RCS file: /cvs/lyx/lyx-devel/src/frontends/gtk/GToolbar.h,v
retrieving revision 1.11
diff -u -3 -p -r1.11 GToolbar.h
--- GToolbar.h	2004/09/26 18:36:07	1.11
+++ GToolbar.h	2004/09/28 05:56:26
@@ -24,6 +24,17 @@ namespace frontend {
 
 class GView;
 
+class stringcolumns : public Gtk::TreeModel::ColumnRecord {
+public:
+	stringcolumns()
+	{
+		add(name);
+	}
+
+	Gtk::TreeModelColumn<Glib::ustring> name;
+};
+
+
 class GLayoutBox: public LayoutBox, public sigc::trackable {
 public:
 	GLayoutBox(LyXView &, Gtk::Toolbar &, FuncRequest const &);
@@ -41,8 +52,11 @@ public:
 private:
 	///
 	void selected();
+
+	Gtk::ComboBox combo_;
+	Glib::RefPtr<Gtk::ListStore> model_;
+	stringcolumns * cols_;
 
-	Gtk::Combo combo_;
 	LyXView & owner_;
 	bool internal_;
 };

Reply via email to