added combo box text
This commit is contained in:
parent
b3826ce30c
commit
91ef563dd6
|
@ -21,7 +21,7 @@
|
|||
#
|
||||
#
|
||||
# Author : $Author: maroy $
|
||||
# Version : $Revision: 1.5 $
|
||||
# Version : $Revision: 1.6 $
|
||||
# Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/widgets/etc/Makefile.in,v $
|
||||
#
|
||||
# @configure_input@
|
||||
|
@ -112,6 +112,7 @@ WIDGETS_LIB_OBJS = ${TMP_DIR}/ImageButton.o \
|
|||
${TMP_DIR}/BlueBin.o \
|
||||
${TMP_DIR}/WhiteWindow.o \
|
||||
${TMP_DIR}/CornerImages.o \
|
||||
${TMP_DIR}/ComboBoxText.o \
|
||||
${TMP_DIR}/WidgetFactory.o
|
||||
TEST_EXE_OBJS = ${TMP_DIR}/TestWindow.o \
|
||||
${TMP_DIR}/main.o
|
||||
|
|
|
@ -0,0 +1,309 @@
|
|||
/*------------------------------------------------------------------------------
|
||||
|
||||
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/ComboBoxText.h,v $
|
||||
|
||||
------------------------------------------------------------------------------*/
|
||||
#ifndef LiveSupport_Widgets_ComboBoxText_h
|
||||
#define LiveSupport_Widgets_ComboBoxText_h
|
||||
|
||||
#ifndef __cplusplus
|
||||
#error This is a C++ include file
|
||||
#endif
|
||||
|
||||
|
||||
/* ============================================================ include files */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "configure.h"
|
||||
#endif
|
||||
|
||||
#include <gtkmm/label.h>
|
||||
#include <gtkmm/menu.h>
|
||||
#include <gtkmm/comboboxtext.h>
|
||||
|
||||
#include "LiveSupport/Core/Ptr.h"
|
||||
|
||||
|
||||
namespace LiveSupport {
|
||||
namespace Widgets {
|
||||
|
||||
using namespace LiveSupport::Core;
|
||||
|
||||
/* ================================================================ constants */
|
||||
|
||||
|
||||
/* =================================================================== macros */
|
||||
|
||||
|
||||
/* =============================================================== data types */
|
||||
|
||||
/**
|
||||
* A combo box holding text entries.
|
||||
*
|
||||
* @author $Author: maroy $
|
||||
* @version $Revision: 1.1 $
|
||||
*/
|
||||
class ComboBoxText : public Gtk::ComboBoxText
|
||||
{
|
||||
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 text displayed inside the button.
|
||||
*/
|
||||
Ptr<Gtk::Label>::Ref label;
|
||||
|
||||
/**
|
||||
* The X coordinate of the label.
|
||||
*/
|
||||
int labelX;
|
||||
|
||||
/**
|
||||
* The Y coordinate of the label.
|
||||
*/
|
||||
int labelY;
|
||||
|
||||
/**
|
||||
* The drop-down menu for the combo box.
|
||||
*/
|
||||
Ptr<Gtk::Menu>::Ref menu;
|
||||
|
||||
/**
|
||||
* The left image of the widget.
|
||||
*/
|
||||
Glib::RefPtr<Gdk::Pixbuf> leftImage;
|
||||
|
||||
/**
|
||||
* The image behind the text display.
|
||||
*/
|
||||
Glib::RefPtr<Gdk::Pixbuf> centerImage;
|
||||
|
||||
/**
|
||||
* The right image for the widget.
|
||||
*/
|
||||
Glib::RefPtr<Gdk::Pixbuf> rightImage;
|
||||
|
||||
/**
|
||||
* Default constructor.
|
||||
*/
|
||||
ComboBoxText(void) throw ()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the popup menu position.
|
||||
*
|
||||
* @param x the X coordinate for the menu.
|
||||
* @param y the Y coordinate for the menu.
|
||||
* @param pushIn don't know what this does.
|
||||
*/
|
||||
void
|
||||
onMenuPosition(int & x,
|
||||
int & y,
|
||||
bool & pushIn) throw ();
|
||||
|
||||
/**
|
||||
* Event handler for the combo box being clicked.
|
||||
*
|
||||
* @param event the button click event.
|
||||
* @return true if the the event was handled, false otherwise.
|
||||
*/
|
||||
bool
|
||||
onBoxClicked(GdkEventButton * event) throw ();
|
||||
|
||||
/**
|
||||
* Event handler for the menu item selected.
|
||||
*/
|
||||
void
|
||||
onMenuItemSelected(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.
|
||||
*
|
||||
* @param leftImage the left image of the widget.
|
||||
* @param centerImage the image under the text display.
|
||||
* @param rightImage the right image for the widget.
|
||||
*/
|
||||
ComboBoxText(Glib::RefPtr<Gdk::Pixbuf> leftImage,
|
||||
Glib::RefPtr<Gdk::Pixbuf> centerImage,
|
||||
Glib::RefPtr<Gdk::Pixbuf> rightImage) throw ();
|
||||
|
||||
/**
|
||||
* A virtual destructor.
|
||||
*/
|
||||
virtual
|
||||
~ComboBoxText(void) throw ();
|
||||
|
||||
/**
|
||||
* Append a new text entry to the combo box menu.
|
||||
*
|
||||
* @param text the text entry to append.
|
||||
*/
|
||||
void
|
||||
append_text(const Glib::ustring &text) throw ();
|
||||
|
||||
/**
|
||||
* Return the active text.
|
||||
*
|
||||
* @return the active text of the combo box.
|
||||
*/
|
||||
Glib::ustring
|
||||
get_active_text(void) const throw ();
|
||||
|
||||
/**
|
||||
* Insert a new text entry at a given position.
|
||||
*
|
||||
* @param position the position where to insert the text.
|
||||
* @param text the text to insert.
|
||||
*/
|
||||
void
|
||||
insert_text(int position,
|
||||
const Glib::ustring & text) throw ();
|
||||
|
||||
/**
|
||||
* Set the active text.
|
||||
*
|
||||
* @param text the text to select as active.
|
||||
*/
|
||||
void
|
||||
set_active_text(const Glib::ustring & text) throw ();
|
||||
|
||||
};
|
||||
|
||||
|
||||
/* ================================================= external data structures */
|
||||
|
||||
|
||||
/* ====================================================== function prototypes */
|
||||
|
||||
|
||||
} // namespace Widgets
|
||||
} // namespace LiveSupport
|
||||
|
||||
#endif // LiveSupport_Widgets_ComboBoxText_h
|
||||
|
|
@ -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/WidgetFactory.h,v $
|
||||
|
||||
------------------------------------------------------------------------------*/
|
||||
|
@ -47,6 +47,7 @@
|
|||
#include "LiveSupport/Widgets/CornerImages.h"
|
||||
#include "LiveSupport/Widgets/Button.h"
|
||||
#include "LiveSupport/Widgets/ImageButton.h"
|
||||
#include "LiveSupport/Widgets/ComboBoxText.h"
|
||||
#include "LiveSupport/Widgets/BlueBin.h"
|
||||
|
||||
|
||||
|
@ -82,7 +83,7 @@ using namespace LiveSupport::Core;
|
|||
* </code></pre>
|
||||
*
|
||||
* @author $Author: maroy $
|
||||
* @version $Revision: 1.3 $
|
||||
* @version $Revision: 1.4 $
|
||||
*/
|
||||
class WidgetFactory :
|
||||
virtual public Configurable
|
||||
|
@ -155,6 +156,21 @@ class WidgetFactory :
|
|||
*/
|
||||
Ptr<CornerImages>::Ref whiteWindowImages;
|
||||
|
||||
/**
|
||||
* The combo box left image.
|
||||
*/
|
||||
Glib::RefPtr<Gdk::Pixbuf> comboBoxLeftImage;
|
||||
|
||||
/**
|
||||
* The combo box center image.
|
||||
*/
|
||||
Glib::RefPtr<Gdk::Pixbuf> comboBoxCenterImage;
|
||||
|
||||
/**
|
||||
* The combo box right image.
|
||||
*/
|
||||
Glib::RefPtr<Gdk::Pixbuf> comboBoxRightImage;
|
||||
|
||||
/**
|
||||
* The default constructor.
|
||||
*/
|
||||
|
@ -233,6 +249,14 @@ class WidgetFactory :
|
|||
Ptr<ImageButton>::Ref
|
||||
createButton(ButtonType type) throw ();
|
||||
|
||||
/**
|
||||
* Create a combo box, that holds text entries.
|
||||
*
|
||||
* @return a combo box, that holds text entries.
|
||||
*/
|
||||
Ptr<ComboBoxText>::Ref
|
||||
createComboBoxText(void) throw ();
|
||||
|
||||
/**
|
||||
* Create and return a blue singular container.
|
||||
*
|
||||
|
|
|
@ -0,0 +1,450 @@
|
|||
/*------------------------------------------------------------------------------
|
||||
|
||||
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/ComboBoxText.cxx,v $
|
||||
|
||||
------------------------------------------------------------------------------*/
|
||||
|
||||
/* ============================================================ include files */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "configure.h"
|
||||
#endif
|
||||
|
||||
#include "LiveSupport/Widgets/ComboBoxText.h"
|
||||
|
||||
|
||||
using namespace LiveSupport::Core;
|
||||
using namespace LiveSupport::Widgets;
|
||||
|
||||
/* =================================================== local data structures */
|
||||
|
||||
|
||||
/* ================================================ local constants & macros */
|
||||
|
||||
|
||||
/* =============================================== local function prototypes */
|
||||
|
||||
|
||||
/* ============================================================= module code */
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Constructor.
|
||||
*----------------------------------------------------------------------------*/
|
||||
ComboBoxText :: ComboBoxText(Glib::RefPtr<Gdk::Pixbuf> leftImage,
|
||||
Glib::RefPtr<Gdk::Pixbuf> centerImage,
|
||||
Glib::RefPtr<Gdk::Pixbuf> rightImage)
|
||||
throw ()
|
||||
{
|
||||
set_flags(Gtk::NO_WINDOW);
|
||||
|
||||
this->leftImage = leftImage;
|
||||
this->centerImage = centerImage;
|
||||
this->rightImage = rightImage;
|
||||
|
||||
label.reset(new Gtk::Label(""));
|
||||
label->set_parent(*this);
|
||||
|
||||
// specify a white background
|
||||
Gdk::Color bgColor = Gdk::Color();
|
||||
bgColor.set_rgb(0xffff, 0xffff, 0xffff);
|
||||
Glib::RefPtr<Gdk::Colormap> colormap = get_default_colormap();
|
||||
colormap->alloc_color(bgColor);
|
||||
|
||||
menu.reset(new Gtk::Menu());
|
||||
menu->modify_bg(Gtk::STATE_NORMAL, bgColor);
|
||||
|
||||
// register the event handler for the mouse click
|
||||
add_events(Gdk::BUTTON_PRESS_MASK);
|
||||
signal_button_press_event().connect(sigc::mem_fun(*this,
|
||||
&ComboBoxText::onBoxClicked));
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Destructor.
|
||||
*----------------------------------------------------------------------------*/
|
||||
ComboBoxText :: ~ComboBoxText(void) throw ()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Handle the size request event.
|
||||
*----------------------------------------------------------------------------*/
|
||||
void
|
||||
ComboBoxText :: on_size_request(Gtk::Requisition* requisition) throw ()
|
||||
{
|
||||
*requisition = Gtk::Requisition();
|
||||
|
||||
// get the required size from the label
|
||||
Gtk::Requisition childRequisition = label->size_request();;
|
||||
|
||||
// iterate through the menu elements, and get the biggest size
|
||||
Gtk::Menu::MenuList & list = menu->items();
|
||||
Gtk::Menu::MenuList::iterator it = list.begin();
|
||||
Gtk::Menu::MenuList::iterator end = list.end();
|
||||
while (it != end) {
|
||||
Gtk::MenuItem & item = *it;
|
||||
Gtk::Requisition itemRequisition = item.size_request();
|
||||
if (childRequisition.width < itemRequisition.width) {
|
||||
childRequisition.width = itemRequisition.width;
|
||||
}
|
||||
if (childRequisition.height < itemRequisition.height) {
|
||||
childRequisition.height = itemRequisition.height;
|
||||
}
|
||||
|
||||
++it;
|
||||
}
|
||||
|
||||
requisition->width = leftImage->get_width()
|
||||
+ childRequisition.width
|
||||
+ rightImage->get_width();
|
||||
requisition->height = centerImage->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
|
||||
ComboBoxText :: on_size_allocate(Gtk::Allocation& allocation) throw ()
|
||||
{
|
||||
allocation.set_height(centerImage->get_height());
|
||||
set_allocation(allocation);
|
||||
|
||||
if (gdkWindow) {
|
||||
gdkWindow->move_resize( allocation.get_x(),
|
||||
allocation.get_y(),
|
||||
allocation.get_width(),
|
||||
allocation.get_height() );
|
||||
}
|
||||
|
||||
Gtk::Allocation labelAlloc;
|
||||
|
||||
labelX = leftImage->get_width();
|
||||
// put it 1 pixel lower, so that it looks good
|
||||
labelY = 1 + ((allocation.get_height() - centerImage->get_height()) / 2);
|
||||
|
||||
labelAlloc.set_x(labelX);
|
||||
labelAlloc.set_y(labelY);
|
||||
labelAlloc.set_width(allocation.get_width()
|
||||
- leftImage->get_width()
|
||||
- rightImage->get_width());
|
||||
labelAlloc.set_height(centerImage->get_height());
|
||||
|
||||
label->size_allocate(labelAlloc);
|
||||
|
||||
Gtk::ComboBoxText::on_size_allocate(allocation);
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Execute a function on all the children.
|
||||
* As this widget has no children, don't do anything.
|
||||
*----------------------------------------------------------------------------*/
|
||||
void
|
||||
ComboBoxText :: forall_vfunc(gboolean includeInternals,
|
||||
GtkCallback callback,
|
||||
gpointer callbackData) throw ()
|
||||
{
|
||||
callback((GtkWidget*) label->gobj(), callbackData);
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Handle the add child widget event.
|
||||
* As this widget has no children, don't do anything.
|
||||
*----------------------------------------------------------------------------*/
|
||||
void
|
||||
ComboBoxText :: on_add(Gtk::Widget* child) throw ()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Handle the remove child widget event.
|
||||
* As this widget has no children, don't do anything.
|
||||
*----------------------------------------------------------------------------*/
|
||||
void
|
||||
ComboBoxText :: on_remove(Gtk::Widget* child) throw ()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Return what kind of widgets can be added to this container.
|
||||
* As this widget has no children, return G_TYPE_NONE always.
|
||||
*----------------------------------------------------------------------------*/
|
||||
GtkType
|
||||
ComboBoxText :: child_type_vfunc() const throw ()
|
||||
{
|
||||
return G_TYPE_NONE;
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Handle the map event.
|
||||
*----------------------------------------------------------------------------*/
|
||||
void
|
||||
ComboBoxText :: on_map() throw ()
|
||||
{
|
||||
Gtk::ComboBoxText::on_map();
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Handle the unmap event.
|
||||
*----------------------------------------------------------------------------*/
|
||||
void
|
||||
ComboBoxText :: on_unmap() throw ()
|
||||
{
|
||||
Gtk::ComboBoxText::on_unmap();
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Handle the realize event.
|
||||
*----------------------------------------------------------------------------*/
|
||||
void
|
||||
ComboBoxText :: on_realize() throw ()
|
||||
{
|
||||
Gtk::ComboBoxText::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);
|
||||
|
||||
// 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
|
||||
ComboBoxText :: on_unrealize() throw ()
|
||||
{
|
||||
gdkWindow.clear();
|
||||
gc.clear();
|
||||
|
||||
Gtk::ComboBoxText::on_unrealize();
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Handle the expose event.
|
||||
*----------------------------------------------------------------------------*/
|
||||
bool
|
||||
ComboBoxText :: on_expose_event(GdkEventExpose* event) throw ()
|
||||
{
|
||||
if (event->count > 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (gdkWindow) {
|
||||
gdkWindow->clear();
|
||||
|
||||
// draw everything vertically centered, but horizontally stretched
|
||||
// out
|
||||
int x = 0;
|
||||
int y = (get_height() - centerImage->get_height()) / 2;
|
||||
int maxX = get_width() - rightImage->get_width();
|
||||
|
||||
// draw the left image
|
||||
leftImage->render_to_drawable(gdkWindow,
|
||||
get_style()->get_black_gc(),
|
||||
0, 0,
|
||||
x,
|
||||
y,
|
||||
leftImage->get_width(),
|
||||
leftImage->get_height(),
|
||||
Gdk::RGB_DITHER_NONE,
|
||||
0, 0);
|
||||
|
||||
// draw as many center images, as necessary
|
||||
for (x = leftImage->get_width();
|
||||
x < maxX;
|
||||
x += centerImage->get_width()) {
|
||||
|
||||
centerImage->render_to_drawable(gdkWindow,
|
||||
get_style()->get_black_gc(),
|
||||
0, 0,
|
||||
x,
|
||||
y,
|
||||
centerImage->get_width(),
|
||||
centerImage->get_height(),
|
||||
Gdk::RGB_DITHER_NONE,
|
||||
0, 0);
|
||||
}
|
||||
|
||||
// draw the right image
|
||||
rightImage->render_to_drawable(gdkWindow,
|
||||
get_style()->get_black_gc(),
|
||||
0, 0,
|
||||
maxX,
|
||||
y,
|
||||
rightImage->get_width(),
|
||||
rightImage->get_height(),
|
||||
Gdk::RGB_DITHER_NONE,
|
||||
0, 0);
|
||||
|
||||
// draw the label itself
|
||||
gdkWindow->draw_layout(gc, labelX, labelY, label->get_layout());
|
||||
}
|
||||
|
||||
Gtk::ComboBoxText::on_expose_event(event);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Return the menu position.
|
||||
*----------------------------------------------------------------------------*/
|
||||
void
|
||||
ComboBoxText :: onMenuPosition(int & x,
|
||||
int & y,
|
||||
bool & pushIn) throw ()
|
||||
{
|
||||
int windowX;
|
||||
int windowY;
|
||||
|
||||
gdkWindow->get_origin(windowX, windowY);
|
||||
|
||||
x = windowX + labelX;
|
||||
y = windowY + labelY;
|
||||
pushIn = false;
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Return the menu position.
|
||||
*----------------------------------------------------------------------------*/
|
||||
bool
|
||||
ComboBoxText :: onBoxClicked(GdkEventButton * event) throw ()
|
||||
{
|
||||
if (event->button == 1) {
|
||||
// display the menu
|
||||
menu->popup(sigc::mem_fun(*this, &ComboBoxText::onMenuPosition),
|
||||
0, 0);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Event handler for the menu item selected.
|
||||
*----------------------------------------------------------------------------*/
|
||||
void
|
||||
ComboBoxText :: onMenuItemSelected(void) throw ()
|
||||
{
|
||||
Gtk::MenuItem * item = menu->get_active();
|
||||
Gtk::Label * selected = (Gtk::Label*) item->get_child();
|
||||
set_active_text(selected->get_text());
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Append a new text entry to the combo box menu.
|
||||
*----------------------------------------------------------------------------*/
|
||||
void
|
||||
ComboBoxText :: append_text(const Glib::ustring &text) throw ()
|
||||
{
|
||||
Gtk::Menu::MenuList& list = menu->items();
|
||||
|
||||
list.push_back(Gtk::Menu_Helpers::MenuElem(text,
|
||||
sigc::mem_fun(*this,
|
||||
&ComboBoxText::onMenuItemSelected)));
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Return the active text.
|
||||
*----------------------------------------------------------------------------*/
|
||||
Glib::ustring
|
||||
ComboBoxText :: get_active_text(void) const throw ()
|
||||
{
|
||||
// TODO: this may actually be bogus data
|
||||
return label->get_text();
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Insert a new text entry at a given position.
|
||||
*----------------------------------------------------------------------------*/
|
||||
void
|
||||
ComboBoxText :: insert_text(int position,
|
||||
const Glib::ustring & text) throw ()
|
||||
{
|
||||
// TODO: this probably doesn't work, the menu->insert() function seems
|
||||
// to be broken
|
||||
Gtk::MenuItem item(text);
|
||||
menu->insert(item, position);
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Set the active text.
|
||||
*----------------------------------------------------------------------------*/
|
||||
void
|
||||
ComboBoxText :: set_active_text(const Glib::ustring & text) throw ()
|
||||
{
|
||||
// TODO: the activate function probably doesn't work, it seems to be broken
|
||||
Gtk::MenuItem item(text);
|
||||
menu->activate_item(item);
|
||||
|
||||
label->set_text(text);
|
||||
}
|
||||
|
|
@ -22,7 +22,7 @@
|
|||
|
||||
|
||||
Author : $Author: maroy $
|
||||
Version : $Revision: 1.7 $
|
||||
Version : $Revision: 1.8 $
|
||||
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/widgets/src/TestWindow.cxx,v $
|
||||
|
||||
------------------------------------------------------------------------------*/
|
||||
|
@ -69,6 +69,13 @@ TestWindow :: TestWindow (void)
|
|||
// create a button
|
||||
button = widgetFactory->createButton("Hello, World!");
|
||||
|
||||
// create a combo box
|
||||
comboBoxText = 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 blue container
|
||||
blueBin = widgetFactory->createDarkBlueBin();
|
||||
|
||||
|
@ -76,6 +83,7 @@ TestWindow :: TestWindow (void)
|
|||
layout.reset(new Gtk::Table());
|
||||
layout->attach(*imageButton, 0, 1, 0, 1);
|
||||
layout->attach(*button, 0, 1, 1, 2);
|
||||
layout->attach(*comboBoxText, 0, 1, 2, 3);
|
||||
|
||||
blueBin->add(*layout);
|
||||
add(*blueBin);
|
||||
|
|
|
@ -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/TestWindow.h,v $
|
||||
|
||||
------------------------------------------------------------------------------*/
|
||||
|
@ -47,6 +47,7 @@
|
|||
|
||||
#include "LiveSupport/Widgets/Button.h"
|
||||
#include "LiveSupport/Widgets/ImageButton.h"
|
||||
#include "LiveSupport/Widgets/ComboBoxText.h"
|
||||
#include "LiveSupport/Widgets/BlueBin.h"
|
||||
#include "LiveSupport/Widgets/WhiteWindow.h"
|
||||
|
||||
|
@ -68,7 +69,7 @@ using namespace LiveSupport::Core;
|
|||
* A window, enabling interactive testing of UI components.
|
||||
*
|
||||
* @author $Author: maroy $
|
||||
* @version $Revision: 1.4 $
|
||||
* @version $Revision: 1.5 $
|
||||
*/
|
||||
class TestWindow : public WhiteWindow
|
||||
{
|
||||
|
@ -88,6 +89,11 @@ class TestWindow : public WhiteWindow
|
|||
*/
|
||||
Ptr<Button>::Ref button;
|
||||
|
||||
/**
|
||||
* A combo box.
|
||||
*/
|
||||
Ptr<ComboBoxText>::Ref comboBoxText;
|
||||
|
||||
/**
|
||||
* A blue container.
|
||||
*/
|
||||
|
|
|
@ -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/WidgetFactory.cxx,v $
|
||||
|
||||
------------------------------------------------------------------------------*/
|
||||
|
@ -114,6 +114,21 @@ static const std::string deleteButtonPassiveName = "imageButton/delete.png";
|
|||
*/
|
||||
static const std::string deleteButtonRollName = "imageButton/deleteRoll.png";
|
||||
|
||||
/**
|
||||
* The name of the combo box left image.
|
||||
*/
|
||||
static const std::string comboBoxLeftName = "combo/left.png";
|
||||
|
||||
/**
|
||||
* The name of the combo box center image.
|
||||
*/
|
||||
static const std::string comboBoxCenterName = "combo/center.png";
|
||||
|
||||
/**
|
||||
* The name of the combo box right image.
|
||||
*/
|
||||
static const std::string comboBoxRightName = "combo/right.png";
|
||||
|
||||
|
||||
/* =============================================== local function prototypes */
|
||||
|
||||
|
@ -163,6 +178,11 @@ WidgetFactory :: configure(const xmlpp::Element & element)
|
|||
buttonRollImageCenter = loadImage(buttonRollCenterName);
|
||||
buttonRollImageRight = loadImage(buttonRollRightName);
|
||||
|
||||
// load the combo box images
|
||||
comboBoxLeftImage = loadImage(comboBoxLeftName);
|
||||
comboBoxCenterImage = loadImage(comboBoxCenterName);
|
||||
comboBoxRightImage = loadImage(comboBoxRightName);
|
||||
|
||||
// load the images for the bins
|
||||
blueBinImages.reset(new CornerImages(path + blueBinPath));
|
||||
darkBlueBinImages.reset(new CornerImages(path + darkBlueBinPath));
|
||||
|
@ -207,6 +227,20 @@ WidgetFactory :: createButton(const Glib::ustring & label) throw ()
|
|||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Create a combo box
|
||||
*----------------------------------------------------------------------------*/
|
||||
Ptr<ComboBoxText>::Ref
|
||||
WidgetFactory :: createComboBoxText(void) throw ()
|
||||
{
|
||||
Ptr<ComboBoxText>::Ref comboBox(new ComboBoxText(comboBoxLeftImage,
|
||||
comboBoxCenterImage,
|
||||
comboBoxRightImage));
|
||||
|
||||
return comboBox;
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Create a blue bin
|
||||
*----------------------------------------------------------------------------*/
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 2.8 KiB |
Binary file not shown.
After Width: | Height: | Size: 2.9 KiB |
Binary file not shown.
After Width: | Height: | Size: 3.4 KiB |
Loading…
Reference in New Issue