Displaying wirdgets - Differently?
- From: jalqadir netscape net
- To: gtkmm-list gnome org
- Subject: Displaying wirdgets - Differently?
- Date: Thu, 23 Feb 2006 15:08:23 -0500
In order to automate the use of enter boxes, I have created two classes that will handle the input and display of data, see below, the problem with this approach is that, with virtually identical Gtk::Frame, the widgets are displayed with a minor, but anaesthetic, difference; the title of the Gtk::Entry and Gtk::Combo is not at the left bottom and the Entry and Combo widgets are not at the Left-Top position of the Gtk::HBox.
I have spent a considerable amount of time researching all kinds of documents, but my inexperience in GUI programming combined with my lack of knowledge of GTKmm gets in the way.
I am posting the code, in the hope that someone here will be able to point me in the right direction.
Thanks
namespace jme{
//! \brief This class is thrown in the case of an exception
//* < This is the only part of the code I don't need to show, since the parent class is a simple exception handler. > *//
class BoxEntryEx : public virtual jme::Exception {
public:
BoxEntryEx( jme::error_t ec, const std::string& f,
const std::string& m, size_t l ) {
setException( ec, f, m, l );
}
virtual ~BoxEntryEx()throw(){}
};//Class
class IOBoxBase : public Gtk::VBox{
protected:
virtual void Init() throw(jme::BoxEntryEx );
void setTitle(const char*) throw(jme::BoxEntryEx);
int max_len;
int height;
int width;
Glib::ustring title;
Glib::ustring text;
Gtk::Label* label;
public:
IOBoxBase(){Init();}
virtual ~IOBoxBase(){};
//Gtk::VBox* getHandle()const{return this;}
};
class TextEntry : virtual public IOBoxBase{
virtual void Init() throw(jme::BoxEntryEx );
Gtk::Entry* entry;
void setMaxLen(const int) throw(jme::BoxEntryEx);
public:
TextEntry();
TextEntry(const gchar*, // Title;
const gchar* , // Text to be displayed if any
gint, // Number of characters
gint, // Horizontal pading
gint); // Vertical padding
virtual ~TextEntry(){}
const char* getText()const;
virtual Gtk::Entry* getHandle(){return entry;}
};
class ComboBox : virtual public jme::IOBoxBase{
private:
protected:
virtual void Init() throw(jme::BoxEntryEx );
Gtk::Combo* combo_box;
public:
ComboBox(){Init();}
ComboBox(const gchar*, //Title
gint) //Vertical padding
throw(jme::BoxEntryEx ); //Exception
virtual ~ComboBox(){}
virtual Gtk::Combo* getHandle() {return combo_box;}
}; // class
} // namespace
/////////////////////////////////////
void jme::IOBoxBase::Init()
throw(jme::BoxEntryEx ){
try{
label = Gtk::manage(new Gtk::Label());
}catch(...){
jme::BoxEntryEx e( mem_alloc, FILE, METHOD, LINE );
e.record("error_log.txt");
throw e;
}
text = "unknown";
label->set_label(text);
label->set_alignment(Gtk::ALIGN_LEFT, Gtk::ALIGN_BOTTOM);
}
void jme::IOBoxBase::setTitle(const char* c)
throw(jme::BoxEntryEx ){
title.assign(c);
if(title.empty()){
title.clear();
jme::BoxEntryEx e( str_empty, FILE, METHOD, LINE );
throw e;
}
label->set_label(title);
}
/////////////////////// TextEntry /////////////////////////////
void jme::TextEntry::Init()
throw(jme::BoxEntryEx ){
try{
entry = Gtk::manage(new Gtk::Entry());
}catch(...){
jme::BoxEntryEx e( mem_alloc, FILE, METHOD, LINE );
e.record("error_log.txt");
throw e;
}
entry->set_has_frame( true );
entry->set_visibility( true );
entry->set_max_length(30);
this->ensure_style();
}
void jme::TextEntry::setMaxLen(const int i)
throw(jme::BoxEntryEx){
if(i <= 0){
jme::BoxEntryEx e( jme::num_invalid, FILE, METHOD, LINE );
throw e;
}
max_len = i;
entry->set_max_length(max_len);
}
jme::TextEntry::TextEntry(){
this->Init();
}
jme::TextEntry::TextEntry(const gchar* cp, const gchar* text,
const gint i, const gint hpad,
const gint vpad){
this->Init();
this->setMaxLen(i);
this->setTitle(cp);
label->ensure_style();
this->set_size_request (width, //width_pixels
height); //height_pixels);
this->pack_start(*label);
this->pack_start(*entry);
}
const char* jme::TextEntry::getText()const{
Glib::ustring tmp = entry->get_text();
tmp.c_str();
}
/////////////////////// ComboBox ///////////////////////////
void jme::ComboBox::Init()
throw(jme::BoxEntryEx ){
try{
combo_box = Gtk::manage(new Gtk::Combo());
}catch(...){
jme::BoxEntryEx e( mem_alloc, FILE, METHOD, LINE );
e.record("error_log.txt");
throw e;
}
}
jme::ComboBox::ComboBox(const gchar* title, gint pad)
throw(jme::BoxEntryEx ){
Init();
setTitle(title);
this->set_size_request (25, //width_pixels
25); //height_pixels);
this->pack_start(*label);
this->pack_start(*combo_box);
}
namespace jme{
//! \brief This class is thrown in the case of an exception
class FrameEx : public virtual jme::Exception {
public:
FrameEx( jme::error_t ec, const std::string& f,
const std::string& m, size_t l ) {
setException( ec, f, m, l );
}
virtual ~FrameEx()throw(){}
};//Class
class NameFrame : virtual public Gtk::Frame{
private:
//! Among other things this method takes care of the initialization of
//! variables and memory allocation.
virtual void Init() throw(jme::FrameEx);
//! Manages the properties for the ComboBox object
void ComboBoxFName();
//! Manages the properties for the Entry object
void AddressFrame();
protected:
Glib::ustring version;
Gtk::VBox* boxBase;
Gtk::HBox* hboxOne;
Gtk::HBox* hboxTwo;
jme::ComboBox* cbFirstName;
jme::TextEntry* entryMiddleName;
public:
NameFrame();
virtual ~NameFrame();
}; //class
class NetworkFrame : virtual public Gtk::Frame{
private:
virtual void Init() throw(jme::FrameEx);
Glib::ustring version;
Gtk::VBox* boxBase;
Gtk::HBox* hboxOne;
Gtk::HBox* hboxTwo;
jme::TextEntry* entryEmail1;
jme::TextEntry* entryEmail2;
jme::TextEntry* entryUrl;
public:
NetworkFrame();
~NetworkFrame();
};
void jme::NameFrame::Init()throw(jme::FrameEx){
version = "0.0.1";
this->set_label("Name");
this->set_shadow_type(Gtk::SHADOW_OUT );
try{
boxBase = Gtk::manage(new Gtk::VBox());
hboxOne = Gtk::manage(new Gtk::HBox());
cbFirstName = Gtk::manage(new jme::ComboBox("First Name",
10));
entryMiddleName = Gtk::manage(new jme::TextEntry("Middle Name","nada",
30,25,25));
}catch ( std::bad_alloc & x ) {
jme::FrameEx e( mem_alloc, FILE, METHOD, LINE );
e.record("error_log.txt");
throw e;
}
}
jme::NameFrame::NameFrame(){
int pad = 10;
this->Init();
this->grab_default();
cbFirstName->set_flags(Gtk::CAN_FOCUS);
cbFirstName->grab_focus();
set_focus_child (*cbFirstName);
hboxOne->pack_start(*cbFirstName, true, true, pad);
hboxOne->pack_start(*entryMiddleName,true, true, pad);
boxBase->pack_start(*hboxOne);
this->add(dynamic_cast<Gtk::Widget&>(*boxBase));
this->set_focus_child(dynamic_cast<Gtk::Widget&>(*cbFirstName));
this->set_flags(Gtk::HAS_DEFAULT);
}
jme::NameFrame::~NameFrame(){}
/////////////////////////////////////////////////////
void jme::NetworkFrame::Init()throw(jme::FrameEx){
version = "0.0.1";
try{
boxBase = Gtk::manage(new Gtk::VBox());
hboxOne = Gtk::manage(new Gtk::HBox());
hboxTwo = Gtk::manage(new Gtk::HBox());
entryEmail1 = Gtk::manage(new jme::TextEntry("Primary Eamil","nada",30,25,25));
entryEmail2 = Gtk::manage(new jme::TextEntry("Secondary Email","nada",30,25,25));
entryUrl = Gtk::manage(new jme::TextEntry("URL","nada",90,25,25));
}catch ( std::bad_alloc & x ) {
jme::FrameEx e( mem_alloc, FILE, METHOD, LINE );
e.record("error_log.txt");
throw e;
}
}
jme::NetworkFrame::NetworkFrame(){
int pad = 10;
this->Init();
this->set_label("Network");
this->set_shadow_type(Gtk::SHADOW_OUT );
hboxOne->pack_start(*entryEmail1,true,true,pad);
hboxOne->pack_start(*entryEmail2,true,true,pad);
hboxTwo->pack_start(*entryUrl,true,true,pad);
boxBase->pack_start(*hboxOne, Gtk::PACK_EXPAND_WIDGET);
boxBase->pack_start(*hboxTwo, Gtk::PACK_EXPAND_WIDGET);
this->add(dynamic_cast<Gtk::Widget&>(*boxBase));
}
jme::NetworkFrame::~NetworkFrame(){}
Should you need some more information please do not hesitate to ask.
--
* You cannot exercise your power to a point of humiliation.
- Jean Chretien
* It's amazing how the small seeds of distrust and misunderstanding
can yield a crop of hate and death...
* If that document has fine printing anywhere, just chuck it in the garbage
- Jorge Escalante
Ma'assalama! Adiós! bye!
__________________________________________________________________
Switch to Netscape Internet Service.
As low as $9.95 a month -- Sign up today at http://isp.netscape.com/register
Netscape. Just the Net You Need.
New! Netscape Toolbar for Internet Explorer
Search from anywhere on the Web and block those annoying pop-ups.
Download now at http://channels.netscape.com/ns/search/install.jsp
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]