added custom cell renderer (doesn't do anything yet)

This commit is contained in:
fgerlits 2005-04-13 17:36:33 +00:00
parent 827d6ed31d
commit c034ca25e2
6 changed files with 373 additions and 7 deletions

View file

@ -21,7 +21,7 @@
#
#
# Author : $Author: fgerlits $
# Version : $Revision: 1.11 $
# Version : $Revision: 1.12 $
# Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/widgets/etc/Makefile.in,v $
#
# @configure_input@
@ -118,6 +118,7 @@ WIDGETS_LIB_OBJS = ${TMP_DIR}/ImageButton.o \
${TMP_DIR}/Notebook.o \
${TMP_DIR}/WidgetFactory.o \
${TMP_DIR}/ZebraTreeView.o \
${TMP_DIR}/ZebraCellRenderer.o \
${TMP_DIR}/Colors.o
TEST_EXE_OBJS = ${TMP_DIR}/TestWindow.o \
${TMP_DIR}/main.o

View file

@ -0,0 +1,120 @@
/*------------------------------------------------------------------------------
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: fgerlits $
Version : $Revision: 1.1 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/widgets/include/LiveSupport/Widgets/ZebraCellRenderer.h,v $
------------------------------------------------------------------------------*/
#ifndef LiveSupport_Widgets_ZebraCellRenderer_h
#define LiveSupport_Widgets_ZebraCellRenderer_h
#ifndef __cplusplus
#error This is a C++ include file
#endif
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#include "gtkmm/cellrenderertext.h"
namespace LiveSupport {
namespace Widgets {
/* ================================================================ constants */
/* =================================================================== macros */
/* =============================================================== data types */
/**
* A custom cell renderer for blue-gray striped TreeView's.
*
* @author $Author: fgerlits $
* @version $Revision: 1.1 $
*/
class ZebraCellRenderer : public Gtk::CellRendererText
{
public:
/**
* Default constructor.
*/
ZebraCellRenderer() throw ();
/**
* A virtual destructor.
*/
virtual ~ZebraCellRenderer() throw ();
protected:
/**
* Calculate the size of the cell.
*/
virtual void get_size_vfunc(Gtk::Widget& widget,
const Gdk::Rectangle* cell_area,
int* x_offset, int* y_offset,
int* width, int* height) const
throw ();
/**
* Draw the cell.
*/
virtual void render_vfunc(const Glib::RefPtr<Gdk::Drawable>& window,
Gtk::Widget& widget,
const Gdk::Rectangle& background_area,
const Gdk::Rectangle& cell_area,
const Gdk::Rectangle& expose_area,
Gtk::CellRendererState flags)
throw ();
/**
* The user clicked on the cell.
*/
virtual bool activate_vfunc(GdkEvent* event,
Gtk::Widget& widget,
const Glib::ustring& path,
const Gdk::Rectangle& background_area,
const Gdk::Rectangle& cell_area,
Gtk::CellRendererState flags)
throw ();
};
/* ================================================= external data structures */
/* ====================================================== function prototypes */
} // namespace Widgets
} // namespace LiveSupport
#endif // LiveSupport_Widgets_ZebraCellRenderer_h

View file

@ -22,7 +22,7 @@
Author : $Author: fgerlits $
Version : $Revision: 1.4 $
Version : $Revision: 1.5 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/widgets/include/LiveSupport/Widgets/ZebraTreeView.h,v $
------------------------------------------------------------------------------*/
@ -72,7 +72,7 @@ using namespace LiveSupport::Core;
* A list of items, in rows colored alternately grey and light blue.
*
* @author $Author: fgerlits $
* @version $Revision: 1.4 $
* @version $Revision: 1.5 $
*/
class ZebraTreeView : public Gtk::TreeView
{
@ -109,6 +109,18 @@ class ZebraTreeView : public Gtk::TreeView
virtual
~ZebraTreeView(void) throw ();
/**
* Add a column to the TreeView.
*
* @param title the title of the column
* @param modelColumn the model column this view will display
* @return the number of columns after adding this one
*/
int
appendColumn(const Glib::ustring& title,
const Gtk::TreeModelColumn<Glib::ustring>& modelColumn)
throw ();
/**
* Set the callback function for every column.
*/

View file

@ -0,0 +1,213 @@
/*------------------------------------------------------------------------------
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: fgerlits $
Version : $Revision: 1.1 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/widgets/src/ZebraCellRenderer.cxx,v $
------------------------------------------------------------------------------*/
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#include <iostream>
#include "LiveSupport/Widgets/ZebraCellRenderer.h"
using namespace LiveSupport::Widgets;
/* =================================================== local data structures */
/* ================================================ local constants & macros */
/* =============================================== local function prototypes */
/* ============================================================= module code */
/*------------------------------------------------------------------------------
* Constructor.
*----------------------------------------------------------------------------*/
ZebraCellRenderer::ZebraCellRenderer() throw ()
:
Glib::ObjectBase (typeid(ZebraCellRenderer)),
Gtk::CellRendererText ()
{
// std::cerr << "### constructor\n";
}
/*------------------------------------------------------------------------------
* Destructor.
*----------------------------------------------------------------------------*/
ZebraCellRenderer::~ZebraCellRenderer() throw ()
{
std::cerr << "### destructor\n";
}
/*------------------------------------------------------------------------------
* Calculate the size of the cell.
*----------------------------------------------------------------------------*/
void
ZebraCellRenderer::get_size_vfunc(Gtk::Widget& widget,
const Gdk::Rectangle* cell_area,
int* x_offset, int* y_offset,
int* width, int* height) const
throw ()
{
std::cerr << "### get_size_vfunc()...\n";
// call the parent method
Gtk::CellRendererText::get_size_vfunc(widget, cell_area,
x_offset, y_offset,
width, height);
std::cerr << "... done.\n";
/*
enum { TOGGLE_WIDTH = 12 };
const int calc_width = property_xpad() * 2 + TOGGLE_WIDTH;
const int calc_height = property_ypad() * 2 + TOGGLE_WIDTH;
if(width)
*width = calc_width;
if(height)
*height = calc_height;
if(cell_area)
{
if(x_offset)
{
*x_offset = int(property_xalign() * (cell_area->get_width() - calc_width));
*x_offset = std::max(0, *x_offset);
}
if(y_offset)
{
*y_offset = int(property_yalign() * (cell_area->get_height() - calc_height));
*y_offset = std::max(0, *y_offset);
}
}
*/
}
/*------------------------------------------------------------------------------
* Draw the cell.
*----------------------------------------------------------------------------*/
void
ZebraCellRenderer::render_vfunc(const Glib::RefPtr<Gdk::Drawable>& window,
Gtk::Widget& widget,
const Gdk::Rectangle& background_area,
const Gdk::Rectangle& cell_area,
const Gdk::Rectangle& expose_area,
Gtk::CellRendererState flags)
throw ()
{
std::cerr << "### render_vfunc()...\n";
// call the parent function
Gtk::CellRendererText::render_vfunc(window, widget, background_area,
cell_area, expose_area, flags);
std::cerr << "... done.\n";
/*
const unsigned int cell_xpad = property_xpad();
const unsigned int cell_ypad = property_ypad();
int x_offset = 0, y_offset = 0, width = 0, height = 0;
get_size(widget, cell_area, x_offset, y_offset, width, height);
width -= cell_xpad * 2;
height -= cell_ypad * 2;
if(width <= 0 || height <= 0)
return;
Gtk::StateType state = Gtk::STATE_INSENSITIVE;
if(property_activatable_)
state = Gtk::STATE_NORMAL;
if((flags & Gtk::CELL_RENDERER_SELECTED) != 0)
state = (widget.has_focus()) ? Gtk::STATE_SELECTED : Gtk::STATE_ACTIVE;
const Gtk::ShadowType shadow = (property_active_) ? Gtk::SHADOW_IN : Gtk::SHADOW_OUT;
//Cast the drawable to a Window. TODO: Maybe paint_option() should take a Drawable? murrayc.
Glib::RefPtr<Gdk::Window> window_casted = Glib::RefPtr<Gdk::Window>::cast_dynamic<>(window);
if(window_casted)
{
if(property_radio_)
{
widget.get_style()->paint_option(
window_casted, state, shadow,
cell_area, widget, "cellradio",
cell_area.get_x() + x_offset + cell_xpad,
cell_area.get_y() + y_offset + cell_ypad,
width - 1, height - 1);
}
else
{
widget.get_style()->paint_check(
window_casted, state, shadow,
cell_area, widget, "cellcheck",
cell_area.get_x() + x_offset + cell_xpad,
cell_area.get_y() + y_offset + cell_ypad,
width - 1, height - 1);
}
}
*/
}
/*------------------------------------------------------------------------------
* The user clicked on the cell.
*----------------------------------------------------------------------------*/
bool ZebraCellRenderer::activate_vfunc(GdkEvent* event,
Gtk::Widget& widget,
const Glib::ustring& path,
const Gdk::Rectangle& background_area,
const Gdk::Rectangle& cell_area,
Gtk::CellRendererState flags)
throw ()
{
std::cerr << "### activate_vfunc()...\n";
// call the parent function
Gtk::CellRendererText::activate_vfunc(event, widget, path,
background_area, cell_area, flags);
std::cerr << "... done.\n";
/*
if(property_activatable_)
{
signal_toggled_(path);
return true;
}
return false;
*/
}

View file

@ -22,7 +22,7 @@
Author : $Author: fgerlits $
Version : $Revision: 1.4 $
Version : $Revision: 1.5 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/widgets/src/ZebraTreeView.cxx,v $
------------------------------------------------------------------------------*/
@ -37,6 +37,7 @@
#include "LiveSupport/Widgets/WidgetFactory.h"
#include "LiveSupport/Widgets/ZebraTreeModelColumnRecord.h"
#include "LiveSupport/Widgets/ZebraCellRenderer.h"
#include "LiveSupport/Widgets/ZebraTreeView.h"
@ -73,6 +74,25 @@ ZebraTreeView :: ~ZebraTreeView(void) throw ()
}
/*------------------------------------------------------------------------------
* Add a column to the TreeView.
*----------------------------------------------------------------------------*/
int
ZebraTreeView :: appendColumn(
const Glib::ustring& title,
const Gtk::TreeModelColumn<Glib::ustring>& modelColumn)
throw ()
{
ZebraCellRenderer* renderer = Gtk::manage(new ZebraCellRenderer);
// the constructor packs the renderer into the TreeViewColumn
Gtk::TreeViewColumn* viewColumn = Gtk::manage(new
Gtk::TreeViewColumn(title, *renderer) );
// and then we associate this renderer with the model column
viewColumn->set_renderer(*renderer, modelColumn);
return append_column(*viewColumn);
}
/*------------------------------------------------------------------------------
* Set the callback function for every column.
*----------------------------------------------------------------------------*/

View file

@ -22,7 +22,7 @@
Author : $Author: fgerlits $
Version : $Revision: 1.3 $
Version : $Revision: 1.4 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/gLiveSupport/src/ScratchpadWindow.cxx,v $
------------------------------------------------------------------------------*/
@ -116,9 +116,9 @@ ScratchpadWindow :: ScratchpadWindow (Ptr<GLiveSupport>::Ref gLiveSupport,
// Add the TreeView's view columns:
try {
treeView->append_column(*getResourceUstring("typeColumnLabel"),
treeView->appendColumn(*getResourceUstring("typeColumnLabel"),
modelColumns.typeColumn);
treeView->append_column(*getResourceUstring("titleColumnLabel"),
treeView->appendColumn(*getResourceUstring("titleColumnLabel"),
modelColumns.titleColumn);
} catch (std::invalid_argument &e) {
std::cerr << e.what() << std::endl;