updated code, so that all child widgets are Gtk::manage'd

This commit is contained in:
maroy 2005-02-18 13:54:24 +00:00
parent 9f224b6fb5
commit 59c4e916c0
15 changed files with 167 additions and 111 deletions

View File

@ -22,7 +22,7 @@
Author : $Author: maroy $
Version : $Revision: 1.4 $
Version : $Revision: 1.5 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/widgets/include/LiveSupport/Widgets/BlueBin.h,v $
------------------------------------------------------------------------------*/
@ -63,7 +63,7 @@ using namespace LiveSupport::Core;
* A container holding exactly one child, habing a light blue border to it.
*
* @author $Author: maroy $
* @version $Revision: 1.4 $
* @version $Revision: 1.5 $
*/
class BlueBin : public Gtk::Bin
{
@ -112,6 +112,7 @@ class BlueBin : public Gtk::Bin
int x,
int y) throw ();
protected:
/**
* Return the background color.

View File

@ -22,7 +22,7 @@
Author : $Author: maroy $
Version : $Revision: 1.2 $
Version : $Revision: 1.3 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/widgets/include/LiveSupport/Widgets/Button.h,v $
------------------------------------------------------------------------------*/
@ -63,7 +63,7 @@ using namespace LiveSupport::Core;
* A button holding a text.
*
* @author $Author: maroy $
* @version $Revision: 1.2 $
* @version $Revision: 1.3 $
*/
class Button : public Gtk::Button
{
@ -86,7 +86,7 @@ class Button : public Gtk::Button
/**
* The text displayed inside the button.
*/
Ptr<Gtk::Label>::Ref label;
Gtk::Label * label;
/**
* The state of the button.

View File

@ -22,7 +22,7 @@
Author : $Author: maroy $
Version : $Revision: 1.1 $
Version : $Revision: 1.2 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/widgets/include/LiveSupport/Widgets/ComboBoxText.h,v $
------------------------------------------------------------------------------*/
@ -64,7 +64,7 @@ using namespace LiveSupport::Core;
* A combo box holding text entries.
*
* @author $Author: maroy $
* @version $Revision: 1.1 $
* @version $Revision: 1.2 $
*/
class ComboBoxText : public Gtk::ComboBoxText
{
@ -82,7 +82,7 @@ class ComboBoxText : public Gtk::ComboBoxText
/**
* The text displayed inside the button.
*/
Ptr<Gtk::Label>::Ref label;
Gtk::Label * label;
/**
* The X coordinate of the label.

View File

@ -22,7 +22,7 @@
Author : $Author: maroy $
Version : $Revision: 1.1 $
Version : $Revision: 1.2 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/widgets/include/LiveSupport/Widgets/EntryBin.h,v $
------------------------------------------------------------------------------*/
@ -64,7 +64,7 @@ using namespace LiveSupport::Core;
* A container, holding a Gtk::Entry as its only child.
*
* @author $Author: maroy $
* @version $Revision: 1.1 $
* @version $Revision: 1.2 $
*/
class EntryBin : public BlueBin
{
@ -72,7 +72,7 @@ class EntryBin : public BlueBin
/**
* The text entry for this container.
*/
Ptr<Gtk::Entry>::Ref entry;
Gtk::Entry * entry;
public:
@ -97,7 +97,7 @@ class EntryBin : public BlueBin
*
* @return the entry held in this container.
*/
Ptr<Gtk::Entry>::Ref
Gtk::Entry *
getEntry(void) throw ()
{
return entry;

View File

@ -22,7 +22,7 @@
Author : $Author: maroy $
Version : $Revision: 1.3 $
Version : $Revision: 1.4 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/widgets/include/LiveSupport/Widgets/WhiteWindow.h,v $
------------------------------------------------------------------------------*/
@ -69,7 +69,7 @@ using namespace LiveSupport::Core;
* A container holding exactly one child, habing a light blue border to it.
*
* @author $Author: maroy $
* @version $Revision: 1.3 $
* @version $Revision: 1.4 $
*/
class WhiteWindow : public Gtk::Window
{
@ -77,42 +77,42 @@ class WhiteWindow : public Gtk::Window
/**
* The rounded container for the window.
*/
Ptr<BlueBin>::Ref blueBin;
BlueBin * blueBin;
/**
* The layout of the window.
*/
Ptr<Gtk::Table>::Ref layout;
Gtk::Table * layout;
/**
* The event box for the title, enabling capturing mouse events.
*/
Ptr<Gtk::EventBox>::Ref titleEventBox;
Gtk::EventBox * titleEventBox;
/**
* The left alignment contaner for the title.
*/
Ptr<Gtk::Alignment>::Ref titleAlignment;
Gtk::Alignment * titleAlignment;
/**
* The title of the window.
*/
Ptr<Gtk::Label>::Ref title;
Gtk::Label * title;
/**
* The right alignment contaner for the close button.
*/
Ptr<Gtk::Alignment>::Ref closeButtonAlignment;
Gtk::Alignment * closeButtonAlignment;
/**
* The close button.
*/
Ptr<ImageButton>::Ref closeButton;
ImageButton * closeButton;
/**
* Just a container for the main content of the window.
*/
Ptr<Gtk::Alignment>::Ref childContainer;
Gtk::Alignment * childContainer;
/**
* The event handler for the title being clicked on.
@ -247,6 +247,22 @@ class WhiteWindow : public Gtk::Window
*/
virtual
~WhiteWindow(void) throw ();
/**
* Set the title of the window.
*
* @param title the title of the window.
*/
void
set_title(const Glib::ustring & title) throw ();
/**
* Get the title of the window.
*
* @return the title of the window.
*/
Glib::ustring
get_title(void) const throw ();
};

View File

@ -22,7 +22,7 @@
Author : $Author: maroy $
Version : $Revision: 1.5 $
Version : $Revision: 1.6 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/widgets/include/LiveSupport/Widgets/WidgetFactory.h,v $
------------------------------------------------------------------------------*/
@ -84,7 +84,7 @@ using namespace LiveSupport::Core;
* </code></pre>
*
* @author $Author: maroy $
* @version $Revision: 1.5 $
* @version $Revision: 1.6 $
*/
class WidgetFactory :
virtual public Configurable
@ -241,50 +241,64 @@ class WidgetFactory :
/**
* Create and return a button.
* It is the reponsibility of the caller to dispose of the created
* object properly.
*
* @param label the label shown inside the button.
* @return a button with the specified label.
*/
Ptr<Button>::Ref
Button *
createButton(const Glib::ustring & label) throw ();
/**
* Create a stock button.
* It is the reponsibility of the caller to dispose of the created
* object properly.
*
* @param type the type of the button.
* @return a button of the requested type, or 0
*/
Ptr<ImageButton>::Ref
ImageButton *
createButton(ButtonType type) throw ();
/**
* Create a combo box, that holds text entries.
* It is the reponsibility of the caller to dispose of the created
* object properly.
*
* @return a combo box, that holds text entries.
*/
Ptr<ComboBoxText>::Ref
ComboBoxText *
createComboBoxText(void) throw ();
/**
* Create and return a blue singular container.
* It is the reponsibility of the caller to dispose of the created
* object properly.
*
* @return a blue singular container.
*/
Ptr<BlueBin>::Ref
BlueBin *
createBlueBin(void) throw ();
/**
* Create and return a dark blue singular container.
* It is the reponsibility of the caller to dispose of the created
* object properly.
*
* @return a dark blue singular container.
*/
Ptr<BlueBin>::Ref
BlueBin *
createDarkBlueBin(void) throw ();
/**
* Create and return a singular container holding a text entry.
* It is the reponsibility of the caller to dispose of the created
* object properly.
*
* @return a singular container holding a text entry.
*/
Ptr<EntryBin>::Ref
EntryBin *
createEntryBin(void) throw ();
/**

View File

@ -22,7 +22,7 @@
Author : $Author: maroy $
Version : $Revision: 1.4 $
Version : $Revision: 1.5 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/widgets/src/BlueBin.cxx,v $
------------------------------------------------------------------------------*/
@ -63,7 +63,7 @@ BlueBin :: BlueBin(unsigned int backgroundColor,
this->cornerImages = cornerImages;
child = 0;
bgColor = Gdk::Color();
unsigned int red = (backgroundColor & 0xff0000) >> 8;
unsigned int green = (backgroundColor & 0x00ff00);
@ -79,6 +79,7 @@ BlueBin :: BlueBin(unsigned int backgroundColor,
*----------------------------------------------------------------------------*/
BlueBin :: ~BlueBin(void) throw ()
{
on_remove(child);
}
@ -177,7 +178,7 @@ BlueBin :: on_add(Gtk::Widget* child) throw ()
void
BlueBin :: on_remove(Gtk::Widget* child) throw ()
{
if (this->child == child) {
if (child && this->child == child && child->get_parent() == this) {
this->child = 0;
bool visible = child->is_visible();
child->unparent();

View File

@ -22,7 +22,7 @@
Author : $Author: maroy $
Version : $Revision: 1.3 $
Version : $Revision: 1.4 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/widgets/src/Button.cxx,v $
------------------------------------------------------------------------------*/
@ -69,7 +69,7 @@ Button :: Button(const Glib::ustring & label,
this->rollImageCenter.clear();
this->rollImageRight.clear();
this->label.reset(new Gtk::Label(label));
this->label = Gtk::manage(new Gtk::Label(label));
this->label->set_parent(*this);
}
@ -96,7 +96,7 @@ Button :: Button(const Glib::ustring & label,
this->rollImageCenter = rollImageCenter;
this->rollImageRight = rollImageRight;
this->label.reset(new Gtk::Label(label));
this->label = Gtk::manage(new Gtk::Label(label));
this->label->modify_font(Pango::FontDescription("Bitstream Vera 10"));
this->label->set_parent(*this);
}

View File

@ -22,7 +22,7 @@
Author : $Author: maroy $
Version : $Revision: 1.1 $
Version : $Revision: 1.2 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/widgets/src/ComboBoxText.cxx,v $
------------------------------------------------------------------------------*/
@ -64,7 +64,7 @@ ComboBoxText :: ComboBoxText(Glib::RefPtr<Gdk::Pixbuf> leftImage,
this->centerImage = centerImage;
this->rightImage = rightImage;
label.reset(new Gtk::Label(""));
label = Gtk::manage(new Gtk::Label(""));
label->set_parent(*this);
// specify a white background

View File

@ -22,7 +22,7 @@
Author : $Author: maroy $
Version : $Revision: 1.1 $
Version : $Revision: 1.2 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/widgets/src/EntryBin.cxx,v $
------------------------------------------------------------------------------*/
@ -59,12 +59,20 @@ EntryBin :: EntryBin(unsigned int backgroundColor,
throw ()
: BlueBin(backgroundColor, cornerImages)
{
entry.reset(new Gtk::Entry());
entry = Gtk::manage(new Gtk::Entry());
entry->set_has_frame(false);
// TODO: this doesn't change the background color, for some reason :(
entry->modify_bg(Gtk::STATE_NORMAL, getBgColor());
Glib::RefPtr<Gtk::Style> style = entry->get_style();
style->set_base(Gtk::STATE_NORMAL, getBgColor());
style->set_base(Gtk::STATE_ACTIVE, getBgColor());
style->set_base(Gtk::STATE_PRELIGHT, getBgColor());
style->set_base(Gtk::STATE_SELECTED, getBgColor());
style->set_base(Gtk::STATE_INSENSITIVE, getBgColor());
entry->set_style(style);
add(*entry);
}

View File

@ -22,7 +22,7 @@
Author : $Author: maroy $
Version : $Revision: 1.9 $
Version : $Revision: 1.10 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/widgets/src/TestWindow.cxx,v $
------------------------------------------------------------------------------*/
@ -64,27 +64,28 @@ TestWindow :: TestWindow (void)
Ptr<WidgetFactory>::Ref widgetFactory = WidgetFactory::getInstance();
// init the imageButton
imageButton = widgetFactory->createButton(WidgetFactory::deleteButton);
imageButton = Gtk::manage(
widgetFactory->createButton(WidgetFactory::deleteButton));
// create a button
button = widgetFactory->createButton("Hello, World!");
button = Gtk::manage(widgetFactory->createButton("Hello, World!"));
// create a combo box
comboBoxText = widgetFactory->createComboBoxText();
comboBoxText = Gtk::manage(widgetFactory->createComboBoxText());
comboBoxText->append_text("item1");
comboBoxText->append_text("long item2");
comboBoxText->append_text("very very very long item3");
comboBoxText->set_active_text("item2");
// create a text entry, ant put it inside a blue bin
entryBin = widgetFactory->createEntryBin();
entryBin = Gtk::manage(widgetFactory->createEntryBin());
entry = entryBin->getEntry();
// create a blue container
blueBin = widgetFactory->createDarkBlueBin();
blueBin = Gtk::manage(widgetFactory->createDarkBlueBin());
// create and set up the layout
layout.reset(new Gtk::Table());
layout = Gtk::manage(new Gtk::Table());
layout->attach(*imageButton, 0, 1, 0, 1);
layout->attach(*button, 0, 1, 1, 2);
layout->attach(*comboBoxText, 0, 1, 2, 3);

View File

@ -22,7 +22,7 @@
Author : $Author: maroy $
Version : $Revision: 1.6 $
Version : $Revision: 1.7 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/widgets/src/TestWindow.h,v $
------------------------------------------------------------------------------*/
@ -71,7 +71,7 @@ using namespace LiveSupport::Core;
* A window, enabling interactive testing of UI components.
*
* @author $Author: maroy $
* @version $Revision: 1.6 $
* @version $Revision: 1.7 $
*/
class TestWindow : public WhiteWindow
{
@ -79,37 +79,37 @@ class TestWindow : public WhiteWindow
/**
* The layout used in the window.
*/
Ptr<Gtk::Table>::Ref layout;
Gtk::Table * layout;
/**
* An image button.
*/
Ptr<ImageButton>::Ref imageButton;
ImageButton * imageButton;
/**
* A button.
*/
Ptr<Button>::Ref button;
Button * button;
/**
* A combo box.
*/
Ptr<ComboBoxText>::Ref comboBoxText;
ComboBoxText * comboBoxText;
/**
* A text entry.
*/
Ptr<Gtk::Entry>::Ref entry;
Gtk::Entry * entry;
/**
* A container holding a text entry.
*/
Ptr<EntryBin>::Ref entryBin;
EntryBin * entryBin;
/**
* A blue container.
*/
Ptr<BlueBin>::Ref blueBin;
BlueBin * blueBin;
public:

View File

@ -22,7 +22,7 @@
Author : $Author: maroy $
Version : $Revision: 1.4 $
Version : $Revision: 1.5 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/widgets/src/WhiteWindow.cxx,v $
------------------------------------------------------------------------------*/
@ -66,7 +66,7 @@ WhiteWindow :: WhiteWindow(Glib::ustring title,
Ptr<WidgetFactory>::Ref wf = WidgetFactory::getInstance();
layout.reset(new Gtk::Table());
layout = Gtk::manage(new Gtk::Table());
// create the background color, as it is needed by the event box
Gdk::Color bgColor = Gdk::Color();
@ -78,12 +78,12 @@ WhiteWindow :: WhiteWindow(Glib::ustring title,
colormap->alloc_color(bgColor);
// set the window title
this->title.reset(new Gtk::Label(title));
this->title = Gtk::manage(new Gtk::Label(title));
this->title->modify_font(Pango::FontDescription("Bitstream Vera 10"));
titleAlignment.reset(new Gtk::Alignment(Gtk::ALIGN_LEFT,
Gtk::ALIGN_CENTER,
0, 0));
titleEventBox.reset(new Gtk::EventBox());
titleAlignment = Gtk::manage(new Gtk::Alignment(Gtk::ALIGN_LEFT,
Gtk::ALIGN_CENTER,
0, 0));
titleEventBox = Gtk::manage(new Gtk::EventBox());
titleEventBox->set_visible_window();
titleEventBox->modify_bg(Gtk::STATE_NORMAL, bgColor);
titleAlignment->add(*this->title);
@ -91,19 +91,19 @@ WhiteWindow :: WhiteWindow(Glib::ustring title,
layout->attach(*titleEventBox, 0, 1, 0, 1, Gtk::FILL, Gtk::SHRINK);
// create the close button
closeButton = wf->createButton(WidgetFactory::deleteButton);
closeButtonAlignment.reset(new Gtk::Alignment(Gtk::ALIGN_RIGHT,
Gtk::ALIGN_CENTER,
0, 0));
closeButton = Gtk::manage(wf->createButton(WidgetFactory::deleteButton));
closeButtonAlignment = Gtk::manage(new Gtk::Alignment(Gtk::ALIGN_RIGHT,
Gtk::ALIGN_CENTER,
0, 0));
closeButtonAlignment->add(*closeButton);
layout->attach(*closeButtonAlignment, 1, 2, 0, 1, Gtk::FILL, Gtk::SHRINK);
// add the child container
childContainer.reset(new Gtk::Alignment(Gtk::ALIGN_CENTER));
childContainer = Gtk::manage(new Gtk::Alignment(Gtk::ALIGN_CENTER));
layout->attach(*childContainer, 0, 2, 1, 2);
// add the corners
blueBin.reset(new BlueBin(backgroundColor, cornerImages));
blueBin = Gtk::manage(new BlueBin(backgroundColor, cornerImages));
blueBin->add(*layout);
Gtk::Window::add(*blueBin);
@ -126,6 +126,7 @@ WhiteWindow :: WhiteWindow(Glib::ustring title,
*----------------------------------------------------------------------------*/
WhiteWindow :: ~WhiteWindow(void) throw ()
{
on_remove(blueBin);
}
@ -169,7 +170,7 @@ WhiteWindow :: forall_vfunc(gboolean includeInternals,
void
WhiteWindow :: on_add(Gtk::Widget* child) throw ()
{
if (child == blueBin.get()) {
if (child == blueBin) {
Gtk::Window::on_add(child);
} else {
childContainer->add(*child);
@ -183,10 +184,12 @@ WhiteWindow :: on_add(Gtk::Widget* child) throw ()
void
WhiteWindow :: on_remove(Gtk::Widget* child) throw ()
{
if (child == blueBin.get()) {
Gtk::Window::on_remove(child);
} else {
childContainer->remove();
if (child) {
if (child == blueBin && child->get_parent() == this) {
Gtk::Window::on_remove(child);
} else if (child == childContainer->get_child()) {
childContainer->remove();
}
}
}
@ -278,3 +281,22 @@ WhiteWindow :: onCloseButtonClicked (void) throw ()
}
/*------------------------------------------------------------------------------
* Set the title of the window.
*----------------------------------------------------------------------------*/
void
WhiteWindow :: set_title(const Glib::ustring & title) throw ()
{
this->title->set_label(title);
}
/*------------------------------------------------------------------------------
* Get the title of the window.
*----------------------------------------------------------------------------*/
Glib::ustring
WhiteWindow :: get_title(void) const throw ()
{
return title->get_label();
}

View File

@ -22,7 +22,7 @@
Author : $Author: maroy $
Version : $Revision: 1.6 $
Version : $Revision: 1.7 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/widgets/src/WidgetFactory.cxx,v $
------------------------------------------------------------------------------*/
@ -220,75 +220,65 @@ WidgetFactory :: loadImage(const std::string imageName)
/*------------------------------------------------------------------------------
* Create a button
*----------------------------------------------------------------------------*/
Ptr<Button>::Ref
Button *
WidgetFactory :: createButton(const Glib::ustring & label) throw ()
{
Ptr<Button>::Ref button(new Button(label,
buttonPassiveImageLeft,
buttonPassiveImageCenter,
buttonPassiveImageRight,
buttonRollImageLeft,
buttonRollImageCenter,
buttonRollImageRight));
return button;
return new Button(label,
buttonPassiveImageLeft,
buttonPassiveImageCenter,
buttonPassiveImageRight,
buttonRollImageLeft,
buttonRollImageCenter,
buttonRollImageRight);
}
/*------------------------------------------------------------------------------
* Create a combo box
*----------------------------------------------------------------------------*/
Ptr<ComboBoxText>::Ref
ComboBoxText *
WidgetFactory :: createComboBoxText(void) throw ()
{
Ptr<ComboBoxText>::Ref comboBox(new ComboBoxText(comboBoxLeftImage,
comboBoxCenterImage,
comboBoxRightImage));
return comboBox;
return new ComboBoxText(comboBoxLeftImage,
comboBoxCenterImage,
comboBoxRightImage);
}
/*------------------------------------------------------------------------------
* Create a blue bin
*----------------------------------------------------------------------------*/
Ptr<BlueBin>::Ref
BlueBin *
WidgetFactory :: createBlueBin(void) throw ()
{
Ptr<BlueBin>::Ref blueBin(new BlueBin(0xcfdee7, blueBinImages));
return blueBin;
return new BlueBin(0xcfdee7, blueBinImages);
}
/*------------------------------------------------------------------------------
* Create a dark blue bin
*----------------------------------------------------------------------------*/
Ptr<BlueBin>::Ref
BlueBin *
WidgetFactory :: createDarkBlueBin(void) throw ()
{
Ptr<BlueBin>::Ref blueBin(new BlueBin(0x99cdff, darkBlueBinImages));
return blueBin;
return new BlueBin(0x99cdff, darkBlueBinImages);
}
/*------------------------------------------------------------------------------
* Create an entry bin
*----------------------------------------------------------------------------*/
Ptr<EntryBin>::Ref
EntryBin *
WidgetFactory :: createEntryBin(void) throw ()
{
Ptr<EntryBin>::Ref entryBin(new EntryBin(0x99cdff, entryBinImages));
return entryBin;
return new EntryBin(0xcfdfe7, entryBinImages);
}
/*------------------------------------------------------------------------------
* Create a stock button
*----------------------------------------------------------------------------*/
Ptr<ImageButton>::Ref
ImageButton *
WidgetFactory :: createButton(ButtonType type) throw ()
{
Glib::RefPtr<Gdk::Pixbuf> passiveImage;
@ -296,13 +286,14 @@ WidgetFactory :: createButton(ButtonType type) throw ()
switch (type) {
case deleteButton:
default:
passiveImage = loadImage(deleteButtonPassiveName);
rollImage = loadImage(deleteButtonRollName);
break;
default:
return 0;
}
Ptr<ImageButton>::Ref button(new ImageButton(passiveImage, rollImage));
return button;
return new ImageButton(passiveImage, rollImage);
}

View File

@ -22,7 +22,7 @@
Author : $Author: maroy $
Version : $Revision: 1.2 $
Version : $Revision: 1.3 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/widgets/src/main.cxx,v $
------------------------------------------------------------------------------*/
@ -166,8 +166,10 @@ int main ( int argc,
exit(EXIT_FAILURE);
}
TestWindow testWindow;
Gtk::Main::run(testWindow);
{
TestWindow testWindow;
Gtk::Main::run(testWindow);
}
exit(EXIT_SUCCESS);
}