Re: [gtkmm] custom cellrenderer bug
- From: Markus Gerwinski <markus gerwinski de>
- To: Peter Gasper <pgasper designadvantage com>
- Cc: "gtkmm-list gnome org" <gtkmm-list gnome org>
- Subject: Re: [gtkmm] custom cellrenderer bug
- Date: Fri, 8 Aug 2003 14:08:42 +0200
Peter Gasper wrote:
> The above was the most helpful. However there seems to be a bug in it which is also
> present in my attempts at custom cellrenderers. If one selects
> a combo cell and hits enter it changes to its editable state. But if you want to use
> the keyboard keys up/down to navigate it you are forced to click on it,
> otherwise it arrows out of that cell. Nor can you type in the combo until you physically
> click it with the mouse.
Maybe my version of a CellRendererCombo can help you here... It's somewhat
different from the approach in the example, since I encapsulate a Gtk::Combo
instead of combining an entry and a separate dropdown window to emulate one. I
attached the sources to this mail. (Don't wonder about the namespace -- The
files are part of a library I will completely upload to my web site as soon as
it's ready.)
However, you'll have to be careful with your signal handling, since the
"edited" signal is already sent when you open the dropdown list. (It's a
feature of the Gtk::Entry.) You'll have to use the signals of the combo itself
(the get_entry()'s "changed" signal or the get_list()'s selection signals), and
they're messy to use.
HTH
Markus
#ifndef MAGECAPE_CELLRENDERERCOMBO_H
#define MAGECAPE_CELLRENDERERCOMBO_H
/*
cellrenderercombo.h
Copyright (C) 2003 Markus Gerwinski
This file is part of Magecape.
Magecape is free software. You can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later
version.
This library 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
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <gdk/gdkevents.h>
#include <gdkmm/rectangle.h>
#include <glibmm/ustring.h>
#include <gtkmm/celleditable.h>
#include <gtkmm/cellrenderertext.h>
#include <gtkmm/combo.h>
#include <gtkmm/eventbox.h>
#include <gtkmm/widget.h>
using namespace Gdk;
using namespace Glib;
using namespace Gtk;
namespace Magecape {
class CellEditableCombo: public EventBox, public CellEditable {
public:
CellEditableCombo ( Combo *a_combo );
Combo *get_combo ();
protected:
virtual void start_editing_vfunc ( GdkEvent *event );
private:
Combo *f_combo;
void _remove_widget ();
}; // CellEditableCombo
class CellRendererCombo: public CellRendererText {
public:
CellRendererCombo ( Combo *a_combo );
Combo *get_combo ();
protected:
virtual CellEditable *start_editing_vfunc (
GdkEvent *event, Widget &widget, const ustring &path,
const Gdk::Rectangle &background_area, const Gdk::Rectangle &cell_area,
CellRendererState flags );
private:
CellEditableCombo *f_editable;
}; // CellRendererCombo
} // Magecape
#endif//ndef
/*
cellrenderercombo.cc
Copyright (C) 2003 Markus Gerwinski
This file is part of Magecape.
Magecape is free software. You can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later
version.
This library 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
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "cellrenderercombo.h"
#include <stdexcept>
using namespace std;
namespace Magecape {
CellEditableCombo::CellEditableCombo ( Combo *a_combo ):
ObjectBase ( typeid ( CellEditableCombo ) ), EventBox (), CellEditable () {
if ( !a_combo ) {
throw invalid_argument ( "CellRendererCombo (): a_combo = NULL" );
} // if
f_combo = a_combo;
Entry *entry = f_combo -> get_entry ();
entry -> set_has_frame ( false );
entry -> signal_remove_widget () .connect (
SigC::slot ( *this, &CellEditableCombo::_remove_widget ) );
f_combo -> show ();
add ( *f_combo );
} // CellEditableCombo::CellEditableCombo
Combo* CellEditableCombo::get_combo () {
return f_combo;
} // CellEditableCombo::get_combo
void CellEditableCombo::start_editing_vfunc ( GdkEvent *event ) {
f_combo -> get_entry () -> start_editing ( event );
f_combo -> get_entry () -> grab_focus ();
} // CellEditableCombo::start_editing_vfunc
void CellEditableCombo::_remove_widget () {
hide ();
} // CellEditableCombo::_remove_widget
CellRendererCombo::CellRendererCombo ( Combo *a_combo ) {
f_editable = new CellEditableCombo ( a_combo );
} // CellRendererCombo::CellRendererCombo
Combo* CellRendererCombo::get_combo () {
return f_editable -> get_combo ();
} // CellRendererCombo::get_combo
CellEditable* CellRendererCombo::start_editing_vfunc (
GdkEvent *event, Widget &widget, const ustring &path,
const Gdk::Rectangle &background_area, const Gdk::Rectangle &cell_area,
CellRendererState flags
) {
CellEditableCombo *editable = NULL;
if ( property_editable () ) {
editable = f_editable;
ustring text = property_text ();
Entry *entry = editable -> get_combo () -> get_entry ();
entry -> set_text ( text );
entry -> select_region ( 0, -1 );
editable -> show ();
} // if
return editable;
} // CellRendererCombo::start_editing_vfunc
} // Magecape
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]