Re: ComboBox(), again!



Jamiil Abduqadir wrote:
It has been my intention to create a class that will simplify the inclusion of combo widgets in my programs, the class derives from 'Gtk::VBox' and then add to it a 'Gtk::ComboBoxEntryText', like this:

------ HPP FILE
// ALL THE INCLUDES ARE HERE //
namespace jme{
class Combo : virtual public Gtk::VBox{
private:
    virtual void Init();
    void Pack();
    Glib::ustring str;
    Gtk::Label* label;
    Gtk::ComboBoxEntryText* text_box;

public:
//!Constructor
    Combo(Glib::ustring&);
//!Destructor
    virtual ~Combo();
};// Class
}// Namespace
#endif
----- CPP FILE
void jme::Combo::Init() {
    // Instantiate object widgets
    label     = Gtk::manage(new Gtk::Label(str.data(), Gtk::ALIGN_LEFT ));
    if(label == NULL) {
        DO SOMETHING
    }
    text_box  = Gtk::manage(new Gtk::ComboBoxEntryText());
    if(text_box == NULL) {
        DO SOMETHING
    }
    this->pack_start(*label);
    this->pack_start(*text_box);

}
jme::Combo::Combo(Glib:
:ustring& s) {
     ...
    str = s;
    this->Init();
   ...
}
jme::Combo::~Combo() { }


Later on another class I declare my hand dandy class (jme::Combo* entryboxFirstName;) , then I instantiate it like this 'entryboxFirstName = Gtk::manage(new jme::Combo("sometext"));' to add it to a 'Gtk::Frame' (someFrame->pack_start(*entryboxFirstName);

This works just fine, however, the size of the combo box is too high, high enough to fit two lines of text. Is this a normal behaviour in GTKmm?

Please advice, thanks in advance.


I would only say two things: First, did you know that if you declare your class members (for example your "label" above) as regular class types instead of pointer types (in other words, "Gtk::Label label" instead of "Gtk::Label* label") they are created and destroyed when the class is also instantiated and then destroyed (you wouldn't need to use manage)? In the same way, if you declare your entryboxFirstName as jme::Combo instead of jme::Combo* that class will disappear automatically when the parent class disappears (if it's member of a parent class). You would need to use manage, however, when the widget you're creating is not a member of a class.

Second, I think you have to look into the different packing options that containers have. See for example the VBox docs, specially pack_start() <cid:part1.00010608.05040203@cox.net> and pack_end() <cid:part2.04010306.08010204@cox.net>.
<cid:part1.00010608.05040203@cox.net>

--
Happiness has many doors, and when one of them closes another opens, yet we spent so much time looking at the one that is shut that we don't see the one that just opened.
------------------------------------------------------------------------

_______________________________________________
gtkmm-list mailing list
gtkmm-list gnome org
http://mail.gnome.org/mailman/listinfo/gtkmm-list


--
José Alburquerque
jaalburquerque cox net



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]