I've attached a custom cell renderer which renders EAN13 barcodes to
give you an idea how to accomplish this.
What you're trying to do is quite a difficult task that requires some
Gtk# experience. The difficult part is that the widget that is shown
when the cell is in editing mode needs to implement CellEditable; You
will have to get familiar with GInterface implementation. A date editing
widget for Gtk# is already available as part of the HollyWidgets
library, but you'd have to modify it to implement CellEditable to use it
for your cell renderer.
When you're done, it would be great if you shared your code with the
community as date editing widgets are one of the few things(amongst
databinding) that Gtk#/Gtk+ lack :-)
cm9x4 schrieb:
Thanks! It really works! But I have described just a part of my problem. I
need to create cutomcelrenderer for date editing that shows basicly like
date string and like Calendar in edit mode. I have no idea how i can do
this.
// EAN13Renderer.cs
//
// Copyright (C) 2008 Christian Hoff
//
// This program 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 3 of the License, or
// (at your option) any later version.
//
// This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
//
namespace Bestandsverwaltung.DataWidgets.Renderer
{
public class EAN13Renderer : Gtk.CellRenderer
{
public event EditedHandler Edited;
public EAN13Renderer (Pango.FontDescription font, int BarcodeHeight, int PixelsPerLineUnit) : base ()
{
this.Font = font;
this.BarcodeHeight = BarcodeHeight;
this.PixelsPerLineUnit = PixelsPerLineUnit;
this.Mode = Gtk.CellRendererMode.Editable;
}
private Pango.FontDescription _font;
public Pango.FontDescription Font
{
get {
return _font;
}
set {
if (value == null)
throw (new System.ArgumentNullException ());
_font = value;
}
}
private int _barcodeHeight;
public int BarcodeHeight
{
get {
return _barcodeHeight;
}
set {
if (value <= 0)
throw (new System.ArgumentOutOfRangeException ());
_barcodeHeight = value;
}
}
private int _pixelsPerLineUnit;
public int PixelsPerLineUnit
{
get {
return _pixelsPerLineUnit;
}
set {
if (value <= 0)
throw (new System.ArgumentOutOfRangeException ());
_pixelsPerLineUnit = value;
}
}
Bestandsverwaltung.Barcodes.EAN13 _ean;
[GLib.Property ("EAN", "Get/Set ean", "This is the description")]
public Bestandsverwaltung.Barcodes.EAN13 EAN
{
get {
return _ean;
}
set {
_ean = value;
}
}
public void RenderBarcode (Cairo.Context CairoContext, int height)
{
Pango.Layout PangoLayout = Pango.CairoHelper.CreateLayout (CairoContext);
PangoLayout.FontDescription = _font;
Cairo.Rectangle DrawingRect = new Cairo.Rectangle (0, 0, 0, height);
Bestandsverwaltung.BarcodeImageCairo.BarcodeImage.RenderEAN13ImageWithLabel (this.EAN, CairoContext, PangoLayout, ref DrawingRect, _pixelsPerLineUnit);
PangoLayout.FontDescription.Dispose ();
PangoLayout.Context.Dispose ();
PangoLayout.Dispose ();
}
protected override void Render (Gdk.Drawable drawable, Gtk.Widget widget, Gdk.Rectangle background_area, Gdk.Rectangle cell_area, Gdk.Rectangle expose_area, Gtk.CellRendererState flags)
{
if (_ean == null)
return;
Gdk.Rectangle pix_rect = Gdk.Rectangle.Zero;
this.GetSize (widget, ref cell_area, out pix_rect.X, out pix_rect.Y, out pix_rect.Width, out pix_rect.Height);
// Take care of padding
pix_rect.X += cell_area.X + (int) this.Xpad;
pix_rect.Y += cell_area.Y + (int) this.Ypad;
// Remove left, right, top and buttom borders which were added to the returned width
pix_rect.Width -= (int) this.Xpad * 2;
pix_rect.Height -= (int) this.Ypad * 2;
Cairo.Context context = Gdk.CairoHelper.Create (drawable);
context.Translate (pix_rect.X, pix_rect.Y);
RenderBarcode (context, pix_rect.Height);
(context as System.IDisposable).Dispose ();
}
public override void GetSize (Gtk.Widget widget, ref Gdk.Rectangle cell_area, out int x_offset, out int y_offset, out int width, out int height)
{
width = (int) this.Xpad * 2 + Bestandsverwaltung.BarcodeImageCairo.BarcodeImage.CalculateBarcodeWidth (widget.PangoContext, _font, 1);
height = (int) this.Ypad * 2 + _barcodeHeight;
if (cell_area != Gdk.Rectangle.Zero) {
if (widget.Direction == Gtk.TextDirection.Rtl)
x_offset = (int) ((1.0 - this.Xalign) * (cell_area.Width - width));
else
x_offset = (int) (this.Xalign * (cell_area.Width - width));
x_offset = System.Math.Max (x_offset, 0);
y_offset = (int) (this.Yalign * (cell_area.Height - height));
y_offset = System.Math.Max (y_offset, 0);
} else {
x_offset = 0;
y_offset = 0;
}
}
/*
public override Gtk.CellEditable StartEditing (Gdk.Event evnt, Gtk.Widget widget, string path, Gdk.Rectangle background_area, Gdk.Rectangle cell_area, Gtk.CellRendererState flags)
{
}
*/
}
}
_______________________________________________
Gtk-sharp-list maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/gtk-sharp-list