added BlueBin

This commit is contained in:
maroy 2005-01-26 16:41:52 +00:00
parent 8941c30c27
commit d9f37bf0b5
13 changed files with 720 additions and 7 deletions

View File

@ -21,7 +21,7 @@
#
#
# Author : $Author: maroy $
# Version : $Revision: 1.2 $
# Version : $Revision: 1.3 $
# Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/widgets/etc/Makefile.in,v $
#
# @configure_input@
@ -107,7 +107,8 @@ LDFLAGS = @LDFLAGS@ -pthread \
# Dependencies
#-------------------------------------------------------------------------------
WIDGETS_LIB_OBJS = ${TMP_DIR}/ImageButton.o \
${TMP_DIR}/Button.o
${TMP_DIR}/Button.o \
${TMP_DIR}/BlueBin.o
TEST_EXE_OBJS = ${TMP_DIR}/TestWindow.o \
${TMP_DIR}/main.o

View File

@ -0,0 +1,271 @@
/*------------------------------------------------------------------------------
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/BlueBin.h,v $
------------------------------------------------------------------------------*/
#ifndef LiveSupport_Widgets_BlueBin_h
#define LiveSupport_Widgets_BlueBin_h
#ifndef __cplusplus
#error This is a C++ include file
#endif
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#include <gtkmm/bin.h>
#include "LiveSupport/Core/Ptr.h"
namespace LiveSupport {
namespace Widgets {
using namespace LiveSupport::Core;
/* ================================================================ constants */
/* =================================================================== macros */
/* =============================================================== data types */
/**
* A container holding exactly one child, habing a light blue border to it.
*
* @author $Author: maroy $
* @version $Revision: 1.1 $
*/
class BlueBin : public Gtk::Bin
{
private:
/**
* The Gdk::Window object, used to draw inside this button.
*/
Glib::RefPtr<Gdk::Window> gdkWindow;
/**
* The Graphics Context, used to draw.
*/
Glib::RefPtr<Gdk::GC> gc;
/**
* The widget contained inside this container.
*/
Gtk::Widget * child;
/**
* The background color of the widget.
*/
Gdk::Color bgColor;
/**
* The top left image of the border.
*/
Glib::RefPtr<Gdk::Pixbuf> topLeftImage;
/**
* The left image of the border.
*/
Glib::RefPtr<Gdk::Pixbuf> leftImage;
/**
* The top image of the border.
*/
Glib::RefPtr<Gdk::Pixbuf> topImage;
/**
* The top right image of the border.
*/
Glib::RefPtr<Gdk::Pixbuf> topRightImage;
/**
* The right image of the border.
*/
Glib::RefPtr<Gdk::Pixbuf> rightImage;
/**
* The bottom left image of the border.
*/
Glib::RefPtr<Gdk::Pixbuf> bottomLeftImage;
/**
* The bottom image of the border.
*/
Glib::RefPtr<Gdk::Pixbuf> bottomImage;
/**
* The bottom right image of the border.
*/
Glib::RefPtr<Gdk::Pixbuf> bottomRightImage;
/**
* Default constructor.
*/
BlueBin(void) throw ()
{
}
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 ();
public:
/**
* Constructor, with only one state.
*
* @param topLeftImage the top left image of the border
* @param leftImage the left image of the border
* @param topImage the top image of the border
* @param topRightImage the top right image of the border
* @param rightImage the right image of the border
* @param bottomLeftImage the bottom left image of the border
* @param bottomImage the bottom image of the border
* @param bottomRightImage the bottom right image of the border
*/
BlueBin(Glib::RefPtr<Gdk::Pixbuf> topLeftImage,
Glib::RefPtr<Gdk::Pixbuf> leftImage,
Glib::RefPtr<Gdk::Pixbuf> topImage,
Glib::RefPtr<Gdk::Pixbuf> topRightImage,
Glib::RefPtr<Gdk::Pixbuf> rightImage,
Glib::RefPtr<Gdk::Pixbuf> bottomLeftImage,
Glib::RefPtr<Gdk::Pixbuf> bottomImage,
Glib::RefPtr<Gdk::Pixbuf> bottomRightImage)
throw ();
/**
* A virtual destructor.
*/
virtual
~BlueBin(void) throw ();
};
/* ================================================= external data structures */
/* ====================================================== function prototypes */
} // namespace Widgets
} // namespace LiveSupport
#endif // LiveSupport_Widgets_BlueBin_h

View File

@ -0,0 +1,421 @@
/*------------------------------------------------------------------------------
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/src/BlueBin.cxx,v $
------------------------------------------------------------------------------*/
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#include "LiveSupport/Widgets/BlueBin.h"
using namespace LiveSupport::Core;
using namespace LiveSupport::Widgets;
/* =================================================== local data structures */
/* ================================================ local constants & macros */
/* =============================================== local function prototypes */
/* ============================================================= module code */
/*------------------------------------------------------------------------------
* Constructor.
*----------------------------------------------------------------------------*/
BlueBin :: BlueBin(Glib::RefPtr<Gdk::Pixbuf> topLeftImage,
Glib::RefPtr<Gdk::Pixbuf> leftImage,
Glib::RefPtr<Gdk::Pixbuf> topImage,
Glib::RefPtr<Gdk::Pixbuf> topRightImage,
Glib::RefPtr<Gdk::Pixbuf> rightImage,
Glib::RefPtr<Gdk::Pixbuf> bottomLeftImage,
Glib::RefPtr<Gdk::Pixbuf> bottomImage,
Glib::RefPtr<Gdk::Pixbuf> bottomRightImage)
throw ()
{
set_flags(Gtk::NO_WINDOW);
this->topLeftImage = topLeftImage;
this->leftImage = leftImage;
this->topImage = topImage;
this->topRightImage = topRightImage;
this->rightImage = rightImage;
this->bottomLeftImage = bottomLeftImage;
this->bottomImage = bottomImage;
this->bottomRightImage = bottomRightImage;
child = 0;
bgColor = Gdk::Color();
bgColor.set_rgb(0xcf00, 0xde00, 0xe700);
Glib::RefPtr<Gdk::Colormap> colormap = get_default_colormap();
colormap->alloc_color(bgColor);
}
/*------------------------------------------------------------------------------
* Destructor.
*----------------------------------------------------------------------------*/
BlueBin :: ~BlueBin(void) throw ()
{
}
/*------------------------------------------------------------------------------
* Handle the size request event.
*----------------------------------------------------------------------------*/
void
BlueBin :: on_size_request(Gtk::Requisition* requisition) throw ()
{
*requisition = Gtk::Requisition();
int width = 0;
int height = 0;
if (child) {
Gtk::Requisition childRequisition = child->size_request();
width = childRequisition.width;
height = childRequisition.height;
}
requisition->width = width
+ leftImage->get_width()
+ rightImage->get_width();
requisition->height = height
+ topImage->get_height()
+ bottomImage->get_height();
}
/*------------------------------------------------------------------------------
* Handle the size allocate event.
* We will not be given heights or widths less than we have requested,
* though we might get more.
*----------------------------------------------------------------------------*/
void
BlueBin :: on_size_allocate(Gtk::Allocation& allocation) throw ()
{
set_allocation(allocation);
if (gdkWindow) {
gdkWindow->move_resize( allocation.get_x(),
allocation.get_y(),
allocation.get_width(),
allocation.get_height() );
}
if (child) {
Gtk::Allocation childAlloc;
childAlloc.set_x(leftImage->get_width());
childAlloc.set_y(topImage->get_height());
childAlloc.set_width(allocation.get_width()
- leftImage->get_width()
- rightImage->get_width());
childAlloc.set_height(allocation.get_height()
- topImage->get_height()
- bottomImage->get_height());
child->size_allocate(childAlloc);
}
Gtk::Bin::on_size_allocate(allocation);
}
/*------------------------------------------------------------------------------
* Execute a function on all the children.
* As this widget has no children, don't do anything.
*----------------------------------------------------------------------------*/
void
BlueBin :: forall_vfunc(gboolean includeInternals,
GtkCallback callback,
gpointer callbackData) throw ()
{
if (child) {
callback(child->gobj(), callbackData);
}
}
/*------------------------------------------------------------------------------
* Handle the add child widget event.
* As this widget has no children, don't do anything.
*----------------------------------------------------------------------------*/
void
BlueBin :: on_add(Gtk::Widget* child) throw ()
{
if (!this->child) {
this->child = child;
this->child->set_parent(*this);
}
}
/*------------------------------------------------------------------------------
* Handle the remove child widget event.
* As this widget has no children, don't do anything.
*----------------------------------------------------------------------------*/
void
BlueBin :: on_remove(Gtk::Widget* child) throw ()
{
if (this->child == child) {
this->child = 0;
bool visible = child->is_visible();
child->unparent();
if (visible) {
queue_resize();
}
}
}
/*------------------------------------------------------------------------------
* Return what kind of widgets can be added to this container.
* As this widget has no children, return G_TYPE_NONE always.
*----------------------------------------------------------------------------*/
GtkType
BlueBin :: child_type_vfunc() const throw ()
{
return child ? G_TYPE_NONE : Gtk::Widget::get_type();
}
/*------------------------------------------------------------------------------
* Handle the map event.
*----------------------------------------------------------------------------*/
void
BlueBin :: on_map() throw ()
{
Gtk::Bin::on_map();
}
/*------------------------------------------------------------------------------
* Handle the unmap event.
*----------------------------------------------------------------------------*/
void
BlueBin :: on_unmap() throw ()
{
Gtk::Bin::on_unmap();
}
/*------------------------------------------------------------------------------
* Handle the realize event.
*----------------------------------------------------------------------------*/
void
BlueBin :: on_realize() throw ()
{
Gtk::Bin::on_realize();
if (!gdkWindow) {
// create the Gdk::Window, if it didn't exist before
GdkWindowAttr attributes;
memset(&attributes, 0, sizeof(attributes));
Gtk::Allocation allocation = get_allocation();
// set initial position and size of the Gdk::Window
attributes.x = allocation.get_x();
attributes.y = allocation.get_y();
attributes.width = allocation.get_width();
attributes.height = allocation.get_height();
attributes.event_mask = get_events () | Gdk::EXPOSURE_MASK;
attributes.window_type = GDK_WINDOW_CHILD;
attributes.wclass = GDK_INPUT_OUTPUT;
gdkWindow = Gdk::Window::create(get_window(),
&attributes,
GDK_WA_X | GDK_WA_Y);
unset_flags(Gtk::NO_WINDOW);
set_window(gdkWindow);
modify_bg(Gtk::STATE_NORMAL, bgColor);
// make the widget receive expose events
gdkWindow->set_user_data(gobj());
// allocate a GC for use in on_expose_event()
gc = Gdk::GC::create(gdkWindow);
}
}
/*------------------------------------------------------------------------------
* Handle the unrealize event.
*----------------------------------------------------------------------------*/
void
BlueBin :: on_unrealize() throw ()
{
gdkWindow.clear();
gc.clear();
Gtk::Bin::on_unrealize();
}
/*------------------------------------------------------------------------------
* Handle the expose event.
*----------------------------------------------------------------------------*/
bool
BlueBin :: on_expose_event(GdkEventExpose* event) throw ()
{
if (event->count > 0) {
return false;
}
if (gdkWindow) {
gdkWindow->clear();
int width = get_width();
int height = get_height();
int x;
int maxX;
int y;
int maxY;
topLeftImage->render_to_drawable(gdkWindow,
get_style()->get_black_gc(),
0, 0,
0,
0,
topLeftImage->get_width(),
topLeftImage->get_height(),
Gdk::RGB_DITHER_NONE,
0, 0);
// draw the top side as many times as necessary
x = topLeftImage->get_width();
maxX = width - topRightImage->get_width();
while (x < maxX) {
topImage->render_to_drawable(gdkWindow,
get_style()->get_black_gc(),
0, 0,
x,
0,
topImage->get_width(),
topImage->get_height(),
Gdk::RGB_DITHER_NONE,
0, 0);
x += topImage->get_width();
}
topRightImage->render_to_drawable(gdkWindow,
get_style()->get_black_gc(),
0, 0,
width - topRightImage->get_width(),
0,
topRightImage->get_width(),
topRightImage->get_height(),
Gdk::RGB_DITHER_NONE,
0, 0);
// draw the left side as many times as necessary
y = topLeftImage->get_height();
maxY = height - bottomLeftImage->get_height();
while (y < maxY) {
leftImage->render_to_drawable(gdkWindow,
get_style()->get_black_gc(),
0, 0,
0,
y,
leftImage->get_width(),
leftImage->get_height(),
Gdk::RGB_DITHER_NONE,
0, 0);
y += leftImage->get_height();
}
bottomLeftImage->render_to_drawable(gdkWindow,
get_style()->get_black_gc(),
0, 0,
0,
height - bottomLeftImage->get_height(),
bottomLeftImage->get_width(),
bottomLeftImage->get_height(),
Gdk::RGB_DITHER_NONE,
0, 0);
// draw the right side as many times as necessary
y = topRightImage->get_height();
maxY = height - bottomRightImage->get_height();
while (y < maxY) {
rightImage->render_to_drawable(gdkWindow,
get_style()->get_black_gc(),
0, 0,
width - rightImage->get_width(),
y,
rightImage->get_width(),
rightImage->get_height(),
Gdk::RGB_DITHER_NONE,
0, 0);
y += rightImage->get_height();
}
// draw the bottom side as many times as necessary
x = bottomLeftImage->get_width();
maxX = width - bottomRightImage->get_width();
while (x < maxX) {
bottomImage->render_to_drawable(gdkWindow,
get_style()->get_black_gc(),
0, 0,
x,
height - bottomImage->get_height(),
bottomImage->get_width(),
bottomImage->get_height(),
Gdk::RGB_DITHER_NONE,
0, 0);
x += bottomImage->get_width();
}
bottomRightImage->render_to_drawable(gdkWindow,
get_style()->get_black_gc(),
0, 0,
width - bottomRightImage->get_width(),
height - bottomRightImage->get_height(),
bottomRightImage->get_width(),
bottomRightImage->get_height(),
Gdk::RGB_DITHER_NONE,
0, 0);
}
Gtk::Bin::on_expose_event(event);
return false;
}

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/TestWindow.cxx,v $
------------------------------------------------------------------------------*/
@ -33,6 +33,8 @@
#include "configure.h"
#endif
#include <iostream>
#include "TestWindow.h"
@ -89,12 +91,24 @@ TestWindow :: TestWindow (void)
rollImageCenter,
rollImageRight));
// init the blue container
blueBin.reset(new BlueBin(
Gdk::Pixbuf::create_from_file("var/corner_topleft.png"),
Gdk::Pixbuf::create_from_file("var/corner_leftside.png"),
Gdk::Pixbuf::create_from_file("var/corner_topcentre.png"),
Gdk::Pixbuf::create_from_file("var/corner_topright.png"),
Gdk::Pixbuf::create_from_file("var/corner_rightside.png"),
Gdk::Pixbuf::create_from_file("var/corner_botleft.png"),
Gdk::Pixbuf::create_from_file("var/corner_botcentre.png"),
Gdk::Pixbuf::create_from_file("var/corner_botright.png")));
// create and set up the layout
layout.reset(new Gtk::Table());
layout->attach(*imageButton, 0, 1, 0, 1);
layout->attach(*button, 0, 1, 1, 2);
add(*layout);
blueBin->add(*layout);
add(*blueBin);
show_all();
}

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/TestWindow.h,v $
------------------------------------------------------------------------------*/
@ -47,6 +47,7 @@
#include "LiveSupport/Widgets/Button.h"
#include "LiveSupport/Widgets/ImageButton.h"
#include "LiveSupport/Widgets/BlueBin.h"
namespace LiveSupport {
@ -66,7 +67,7 @@ using namespace LiveSupport::Core;
* A window, enabling interactive testing of UI components.
*
* @author $Author: maroy $
* @version $Revision: 1.2 $
* @version $Revision: 1.3 $
*/
class TestWindow : public Gtk::Window
{
@ -86,6 +87,11 @@ class TestWindow : public Gtk::Window
*/
Ptr<Button>::Ref button;
/**
* A blue container.
*/
Ptr<BlueBin>::Ref blueBin;
public:
/**

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB