added Notebook

This commit is contained in:
maroy 2005-02-25 16:32:32 +00:00
parent 0e0e9e164f
commit 00d2670b10
23 changed files with 1139 additions and 182 deletions

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/Button.h,v $
------------------------------------------------------------------------------*/
@ -44,6 +44,7 @@
#include <gtkmm/label.h>
#include "LiveSupport/Core/Ptr.h"
#include "LiveSupport/Widgets/ButtonImages.h"
namespace LiveSupport {
@ -63,7 +64,7 @@ using namespace LiveSupport::Core;
* A button holding a text.
*
* @author $Author: maroy $
* @version $Revision: 1.3 $
* @version $Revision: 1.4 $
*/
class Button : public Gtk::Button
{
@ -73,6 +74,11 @@ class Button : public Gtk::Button
*/
typedef enum { passiveState, rollState, selectedState } State;
/**
* The font definition used in the button.
*/
static const std::string fontDefinition;
/**
* The Gdk::Window object, used to draw inside this button.
*/
@ -84,9 +90,14 @@ class Button : public Gtk::Button
Glib::RefPtr<Gdk::GC> gc;
/**
* The text displayed inside the button.
* The widget inside the button.
*/
Gtk::Label * label;
Gtk::Widget * child;
/**
* The text label for the button.
*/
Glib::ustring label;
/**
* The state of the button.
@ -94,34 +105,15 @@ class Button : public Gtk::Button
State state;
/**
* The left image for the passive state of the button.
* The non-interactive state of the button
* (not rollover, either passive or selected)
*/
Glib::RefPtr<Gdk::Pixbuf> passiveImageLeft;
State stationaryState;
/**
* The center image for the passive state of the button.
* The button images.
*/
Glib::RefPtr<Gdk::Pixbuf> passiveImageCenter;
/**
* The right image for the passive state of the button.
*/
Glib::RefPtr<Gdk::Pixbuf> passiveImageRight;
/**
* The left image of the button, when the mouse hovers above it.
*/
Glib::RefPtr<Gdk::Pixbuf> rollImageLeft;
/**
* The center image of the button, when the mouse hovers above it.
*/
Glib::RefPtr<Gdk::Pixbuf> rollImageCenter;
/**
* The right image of the button, when the mouse hovers above it.
*/
Glib::RefPtr<Gdk::Pixbuf> rollImageRight;
Ptr<ButtonImages>::Ref buttonImages;
/**
* Default constructor.
@ -240,34 +232,19 @@ class Button : public Gtk::Button
* Constructor, with only one state.
*
* @param label the text to display in the button
* @param leftImage the left image for the button
* @param centerImage the center image for the button
* @param rightImage the right image for the button
* @param buttonImages the images of the button
*/
Button(const Glib::ustring & label,
Glib::RefPtr<Gdk::Pixbuf> leftImage,
Glib::RefPtr<Gdk::Pixbuf> centerImage,
Glib::RefPtr<Gdk::Pixbuf> rightImage) throw ();
Ptr<ButtonImages>::Ref buttonImages) throw ();
/**
* Constructor, with a rollover state.
* Passive and rollover images are expected to be of the same size.
* Constructor, with only one state.
*
* @param label the text to display in the button
* @param passiveImageLeft the left image for the button, passive
* @param passiveImageCenter the center image for the button, passive
* @param passiveImageRight the right image for the button, passive
* @param rollImageLeft the left image for the button, onmouseover
* @param rollImageCenter the center image for the button, onmouseover
* @param rollImageRight the right image for the button, onmouseover
* @param child the widget that should be displayed inside the button.
* @param buttonImages the images of the button
*/
Button(const Glib::ustring & label,
Glib::RefPtr<Gdk::Pixbuf> passiveImageLeft,
Glib::RefPtr<Gdk::Pixbuf> passiveImageCenter,
Glib::RefPtr<Gdk::Pixbuf> passiveImageRight,
Glib::RefPtr<Gdk::Pixbuf> rollImageLeft,
Glib::RefPtr<Gdk::Pixbuf> rollImageCenter,
Glib::RefPtr<Gdk::Pixbuf> rollImageRight) throw ();
Button(Gtk::Widget * child,
Ptr<ButtonImages>::Ref buttonImages) throw ();
/**
* A virtual destructor.
@ -283,7 +260,13 @@ class Button : public Gtk::Button
virtual void
set_label(const Glib::ustring & label) throw ()
{
this->label->set_label(label);
if (child && child->is_managed_()) {
delete child;
}
this->label = label;
child = Gtk::manage(new Gtk::Label(label));
child->modify_font(Pango::FontDescription(fontDefinition));
child->set_parent(*this);
}
/**
@ -294,7 +277,27 @@ class Button : public Gtk::Button
Glib::ustring
get_label(void) const throw ()
{
return this->label->get_label();
return label;
}
/**
* Change the state of the button to selected.
*/
void
select(void) throw ()
{
state = selectedState;
stationaryState = selectedState;
}
/**
* Change the state of the button to passive.
*/
void
unselect(void) throw ()
{
state = passiveState;
stationaryState = passiveState;
}
};

View file

@ -0,0 +1,200 @@
/*------------------------------------------------------------------------------
Copyright (c) 2004 Media Development Loan Fund
This file is part of the LiveSupport project.
http://livesupport.campware.org/
To report bugs, send an e-mail to bugs@campware.org
LiveSupport is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
LiveSupport is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with LiveSupport; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Author : $Author: maroy $
Version : $Revision: 1.1 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/widgets/include/LiveSupport/Widgets/ButtonImages.h,v $
------------------------------------------------------------------------------*/
#ifndef LiveSupport_Widgets_ButtonImages_h
#define LiveSupport_Widgets_ButtonImages_h
#ifndef __cplusplus
#error This is a C++ include file
#endif
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#include <stdexcept>
#include "gdkmm/pixbuf.h"
namespace LiveSupport {
namespace Widgets {
/* ================================================================ constants */
/* =================================================================== macros */
/* =============================================================== data types */
/**
* A helper class to hold a set of images related to buttons.
*
* @author $Author: maroy $
* @version $Revision: 1.1 $
*/
class ButtonImages
{
private:
/**
* Load an image relative the path, and signal error if not found.
*
* @param path the path to find the image for.
* @param imageName the name of the image, relative to path
* @return the loaded image
* @exception std::invalid_argument if the image was not found
*/
Glib::RefPtr<Gdk::Pixbuf>
loadImage(const std::string path,
const std::string imageName)
throw (std::invalid_argument);
public:
/**
* The passive left image for the button.
*/
Glib::RefPtr<Gdk::Pixbuf> passiveImageLeft;
/**
* The passive center image for the button.
*/
Glib::RefPtr<Gdk::Pixbuf> passiveImageCenter;
/**
* The passive right image for the button.
*/
Glib::RefPtr<Gdk::Pixbuf> passiveImageRight;
/**
* The rollover left image for the button.
*/
Glib::RefPtr<Gdk::Pixbuf> rollImageLeft;
/**
* The rollover center image for the button.
*/
Glib::RefPtr<Gdk::Pixbuf> rollImageCenter;
/**
* The rollover right image for the button.
*/
Glib::RefPtr<Gdk::Pixbuf> rollImageRight;
/**
* The selected left image for the button.
*/
Glib::RefPtr<Gdk::Pixbuf> selectedImageLeft;
/**
* The selected center image for the button.
*/
Glib::RefPtr<Gdk::Pixbuf> selectedImageCenter;
/**
* The selected right image for the button.
*/
Glib::RefPtr<Gdk::Pixbuf> selectedImageRight;
/**
* The default constructor.
*/
ButtonImages(void) throw ()
{
}
/**
* Constructor with image references.
* If any of the images is not available, the result is undefined.
*
* @param passiveImageLeft the passive left image
* @param passiveImageCenter the passive center image
* @param passiveImageRight the passive right image
* @param rollImageLeft the left rollover image
* @param rollImageCenter the center rollover image
* @param rollImageRight the right rollover image
* @param selectedImageLeft the left rollover image
* @param selectedImageCenter the center rollover image
* @param selectedImageRight the right rollover image
*/
ButtonImages(Glib::RefPtr<Gdk::Pixbuf> passiveImageLeft,
Glib::RefPtr<Gdk::Pixbuf> passiveImageCenter,
Glib::RefPtr<Gdk::Pixbuf> passiveImageRight,
Glib::RefPtr<Gdk::Pixbuf> rollImageLeft,
Glib::RefPtr<Gdk::Pixbuf> rollImageCenter,
Glib::RefPtr<Gdk::Pixbuf> rollImageRight,
Glib::RefPtr<Gdk::Pixbuf> selectedImageLeft,
Glib::RefPtr<Gdk::Pixbuf> selectedImageCenter,
Glib::RefPtr<Gdk::Pixbuf> selectedImageRight)
throw ()
{
this->passiveImageLeft = passiveImageLeft;
this->passiveImageCenter = passiveImageCenter;
this->passiveImageRight = passiveImageRight;
this->rollImageLeft = rollImageLeft;
this->rollImageCenter = rollImageCenter;
this->rollImageRight = rollImageRight;
this->selectedImageLeft = selectedImageLeft;
this->selectedImageCenter = selectedImageCenter;
this->selectedImageRight = selectedImageRight;
}
/**
* Constructor based on a path, where all the images can be loaded
* from.
*
* @param path the path where all the images can be loaded from.
*/
ButtonImages(const std::string path) throw ();
/**
* A virtual destructor, as this class has virtual functions.
*/
virtual
~ButtonImages(void) throw ()
{
}
};
/* ================================================= external data structures */
/* ====================================================== function prototypes */
} // namespace Widgets
} // namespace LiveSupport
#endif // LiveSupport_Widgets_ButtonImages_h

View file

@ -0,0 +1,326 @@
/*------------------------------------------------------------------------------
Copyright (c) 2004 Media Development Loan Fund
This file is part of the LiveSupport project.
http://livesupport.campware.org/
To report bugs, send an e-mail to bugs@campware.org
LiveSupport is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
LiveSupport is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with LiveSupport; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Author : $Author: maroy $
Version : $Revision: 1.1 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/widgets/include/LiveSupport/Widgets/Notebook.h,v $
------------------------------------------------------------------------------*/
#ifndef LiveSupport_Widgets_Notebook_h
#define LiveSupport_Widgets_Notebook_h
#ifndef __cplusplus
#error This is a C++ include file
#endif
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#include <vector>
#include <gtkmm/table.h>
#include <gtkmm/buttonbox.h>
#include <gtkmm/alignment.h>
#include "LiveSupport/Core/Ptr.h"
#include "LiveSupport/Widgets/CornerImages.h"
#include "LiveSupport/Widgets/ImageButton.h"
namespace LiveSupport {
namespace Widgets {
using namespace LiveSupport::Core;
/* ================================================================ constants */
/* =================================================================== macros */
/* =============================================================== data types */
/**
* A container holding a range of children, showing one a time, in tabs.
*
* After adding pages to a Notebook object, call the function pagesAdded().
*
* @author $Author: maroy $
* @version $Revision: 1.1 $
*/
class Notebook : public Gtk::Alignment
{
private:
/**
* A container class, holding all that is needed to represent
* a page in the notepad.
*
* @author $Author: maroy $
* @version $Revision: 1.1 $
*/
class Page
{
public:
/**
* The Notebook this page is contained in.
*/
Notebook * notebook;
/**
* The index of the page.
*/
unsigned int index;
/**
* The container for the widget.
*/
Gtk::Alignment * container;
/**
* The contents of the page.
*/
Gtk::Widget * widget;
/**
* The button of the page.
*/
Button * button;
/**
* Signal handler for the tab button clicked.
*/
virtual void
onTabClicked(void) throw ()
{
notebook->activatePage(index);
}
/**
* Constructor.
*
* @param notebook the notebook this page is contained in.
* @param index the index of the page.
* @param widget the widget of the page.
* @param button the button of the page.
*/
Page(Notebook * notebook,
unsigned int index,
Gtk::Widget * widget,
Button * button) throw ()
{
this->notebook = notebook;
this->index = index;
this->widget = widget;
this->button = button;
container = new Gtk::Alignment;
container->add(*widget);
}
/**
* Destructor.
*/
virtual
~Page(void) throw ()
{
delete container;
}
};
/**
* The list type, for the list of pages.
*/
typedef std::vector<Page*> PageList;
/**
* The list of pages in the notebook.
*/
PageList pageList;
/**
* The layout of the window.
*/
Gtk::Table * layout;
/**
* The horizontal box holding the tabs.
*/
Gtk::HBox * tabBox;
/**
* The container for the displaying a page at a time.
*/
Gtk::Alignment * pageHolder;
/**
* The index of the current active page.
*/
unsigned int activePage;
protected:
/**
* Handle the size request event.
*
* @param requisition the size request, also being the ouptut
* parameter.
*/
virtual void
on_size_request(Gtk::Requisition* requisition)
throw ();
/**
* Handle the size allocate event.
*
* @param allocation the allocated size.
*/
virtual void
on_size_allocate(Gtk::Allocation& allocation)
throw ();
/**
* Handle the map event.
*/
virtual void
on_map() throw ();
/**
* Handle the unmap event.
*/
virtual void
on_unmap() throw ();
/**
* Handle the realize event.
*/
virtual void
on_realize() throw ();
/**
* Handle the unrealize event.
*/
virtual void
on_unrealize() throw ();
/**
* Handle the expose event.
*
* @param event the actual expose event recieved.
* @return true if something was drawn (?)
*/
virtual bool
on_expose_event(GdkEventExpose* event) throw ();
/**
* Execute a function on all children of this container.
*
* @param includeInternals true if the callback function should
* also be called on the internals, false otherwise.
* @param callback the callback function to execute on the children.
* @param callbackData the data passed to the callback function.
*/
virtual void
forall_vfunc(gboolean includeInternals,
GtkCallback callback,
gpointer callbackData)
throw ();
/**
* Handle the add event.
*
* @param child the child being added to the widget.
*/
virtual void
on_add(Gtk::Widget* child) throw ();
/**
* Handle the remove event.
*
* @param child the child to remove from the widget.
*/
virtual void
on_remove(Gtk::Widget* child) throw ();
/**
* Tell what kind of children this container accepts.
*
* @return the type of children this container accepts.
*/
virtual GtkType
child_type_vfunc() const throw ();
/**
* Call this function after finished adding pages to this object.
* This call will make the object prepare the visuals to display.
*/
virtual void
pagesAdded(void) throw ();
/**
* Make a specific page active.
*
* @param pageNo the index of the page to make active.
*/
virtual void
activatePage(unsigned int pageNo) throw ();
public:
/**
* Constructor.
*/
Notebook() throw ();
/**
* A virtual destructor.
*/
virtual
~Notebook(void) throw ();
/**
* Append a page to the notebook.
*
* @param widget the widget that is the page itself.
* @param label the label of the page.
*/
void
appendPage(Gtk::Widget & widget,
const Glib::ustring & label) throw ();
};
/* ================================================= external data structures */
/* ====================================================== function prototypes */
} // namespace Widgets
} // namespace LiveSupport
#endif // LiveSupport_Widgets_Notebook_h

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/include/LiveSupport/Widgets/WidgetFactory.h,v $
------------------------------------------------------------------------------*/
@ -45,6 +45,7 @@
#include "LiveSupport/Core/Configurable.h"
#include "LiveSupport/Widgets/CornerImages.h"
#include "LiveSupport/Widgets/ButtonImages.h"
#include "LiveSupport/Widgets/Button.h"
#include "LiveSupport/Widgets/ImageButton.h"
#include "LiveSupport/Widgets/ComboBoxText.h"
@ -84,7 +85,7 @@ using namespace LiveSupport::Core;
* </code></pre>
*
* @author $Author: maroy $
* @version $Revision: 1.6 $
* @version $Revision: 1.7 $
*/
class WidgetFactory :
virtual public Configurable
@ -93,7 +94,12 @@ class WidgetFactory :
/**
* The types of available buttons.
*/
typedef enum { deleteButton } ButtonType;
typedef enum { pushButton, tabButton } ButtonType;
/**
* The types of available image buttons.
*/
typedef enum { deleteButton } ImageButtonType;
private:
@ -113,34 +119,14 @@ class WidgetFactory :
std::string path;
/**
* The passive left image for the button.
* The images for the standard button.
*/
Glib::RefPtr<Gdk::Pixbuf> buttonPassiveImageLeft;
Ptr<ButtonImages>::Ref buttonImages;
/**
* The passive center image for the button.
* The images for the tab button.
*/
Glib::RefPtr<Gdk::Pixbuf> buttonPassiveImageCenter;
/**
* The passive right image for the button.
*/
Glib::RefPtr<Gdk::Pixbuf> buttonPassiveImageRight;
/**
* The rollover left image for the button.
*/
Glib::RefPtr<Gdk::Pixbuf> buttonRollImageLeft;
/**
* The rollover center image for the button.
*/
Glib::RefPtr<Gdk::Pixbuf> buttonRollImageCenter;
/**
* The rollover right image for the button.
*/
Glib::RefPtr<Gdk::Pixbuf> buttonRollImageRight;
Ptr<ButtonImages>::Ref tabButtonImages;
/**
* The corner images for the blue bin.
@ -245,10 +231,13 @@ class WidgetFactory :
* object properly.
*
* @param label the label shown inside the button.
* @param type the type of the button to create
* @return a button with the specified label.
*/
Button *
createButton(const Glib::ustring & label) throw ();
createButton(const Glib::ustring & label,
ButtonType type = pushButton)
throw ();
/**
* Create a stock button.
@ -259,7 +248,7 @@ class WidgetFactory :
* @return a button of the requested type, or 0
*/
ImageButton *
createButton(ButtonType type) throw ();
createButton(ImageButtonType type) throw ();
/**
* Create a combo box, that holds text entries.