Problem creating a gtk widget



Hello,

I want to write a new widget for an application I'm working on,
I inherited GtkFrame, everything compiles without warnings, but
if I want to run the application I get:

------
Gtk-WARNING **: invalid cast from `GmtvAudiopanel' to `GtkFrame'

Gtk-CRITICAL **: file gtkframe.c: line 221 (gtk_frame_set_label): assertion `GTK_IS_FRAME (frame)' failed.

Gtk-WARNING **: invalid cast from `GmtvAudiopanel' to `GtkFrame'

Gtk-CRITICAL **: file gtkframe.c: line 301 (gtk_frame_set_shadow_type): assertion `GTK_IS_FRAME (frame)' failed.

Gtk-WARNING **: invalid cast from `GmtvAudiopanel' to `GtkContainer'

Gtk-CRITICAL **: file gtkcontainer.c: line 712 (gtk_container_add): assertion `GTK_IS_CONTAINER (container)' failed.

Gtk-CRITICAL **: file gtkwidget.c: line 4502 (gtk_widget_real_realize): assertion `GTK_WIDGET_NO_WINDOW (widget)' failed.

Gtk-CRITICAL **: file gtkwidget.c: line 4455 (gtk_widget_real_map): assertion `GTK_WIDGET_REALIZED (widget) == TRUE' failed.
------

at the console. I cannot see what I forgot. I used gnome-app.h
gnome-app.c as an example.
I attach the source code. Can somebody tell me what I did wrong.

Thanks

Jan Dittberner
#include "config.h"
#include <gnome.h>

#include "audiopanel.h"

static void gmtv_audiopanel_class_init (GmtvAudiopanelClass *klass);
static void gmtv_audiopanel_init       (GmtvAudiopanel      *audiopanel);
static void gmtv_audiopanel_destroy    (GtkObject           *object);

/* GtkObject functions */

/* Utility functions */

static GtkFrameClass *parent_class;

GtkType gmtv_audiopanel_get_type(void){
  static GtkType audiopanel_type = 0;

  if(!audiopanel_type){
    static const GtkTypeInfo audiopanel_info = {
      "GmtvAudiopanel",
      sizeof(GmtvAudiopanel),
      sizeof(GmtvAudiopanelClass),
      (GtkClassInitFunc) gmtv_audiopanel_class_init,
      (GtkObjectInitFunc) gmtv_audiopanel_init,
      /* reserved 1 */ NULL,
      /* reserved 2 */ NULL,
      (GtkClassInitFunc) NULL,
    };

    audiopanel_type = gtk_type_unique(gtk_widget_get_type(), &audiopanel_info);
  }

  return audiopanel_type;
}

static void gmtv_audiopanel_class_init(GmtvAudiopanelClass *klass){
  GtkObjectClass *object_class;
  GtkWidgetClass *widget_class;

  object_class = (GtkObjectClass*) klass;
  widget_class = (GtkWidgetClass*) klass;

  parent_class = gtk_type_class(gtk_frame_get_type());

  object_class->destroy = gmtv_audiopanel_destroy;
}

static void gmtv_audiopanel_init(GmtvAudiopanel *audiopanel){
  gtk_frame_set_label(GTK_FRAME(audiopanel), _("audio information"));
  gtk_frame_set_shadow_type(GTK_FRAME(audiopanel), GTK_SHADOW_ETCHED_IN);
  audiopanel->vbox=gtk_vbox_new(FALSE, 0);

  gtk_container_add(GTK_CONTAINER(audiopanel), audiopanel->vbox);

  audiopanel->mode=gtk_label_new(_("unknown"));
  gtk_box_pack_start(GTK_BOX(audiopanel->vbox), audiopanel->mode,
		     TRUE, FALSE, 0);

  audiopanel->layer=gtk_label_new((const gchar*)g_strdup_printf(_("layer %d"), 0));
  gtk_box_pack_start(GTK_BOX(audiopanel->vbox), audiopanel->layer,
		     TRUE, FALSE, 0);

  audiopanel->bitrate=gtk_label_new((const gchar*)g_strdup_printf(_("%d bit/s"), 0));
  gtk_box_pack_start(GTK_BOX(audiopanel->vbox), audiopanel->bitrate,
		     TRUE, FALSE, 0);

  audiopanel->samplingrate=gtk_label_new((const gchar*)g_strdup_printf(_("%.2f Hz"), 0));
  gtk_box_pack_start(GTK_BOX(audiopanel->vbox), audiopanel->samplingrate,
		     TRUE, FALSE, 0);

  audiopanel->bbox=gtk_vbutton_box_new();
  gtk_box_pack_start(GTK_BOX(audiopanel->vbox), audiopanel->bbox,
		     TRUE, FALSE, 0);

  audiopanel->copyright=gtk_check_button_new_with_label(_("copyright"));
  gtk_toggle_button_set_mode(GTK_TOGGLE_BUTTON(audiopanel->copyright), FALSE);
  gtk_widget_set_sensitive(GTK_WIDGET(audiopanel->copyright), FALSE);
  gtk_box_pack_start(GTK_BOX(audiopanel->bbox), audiopanel->copyright,
		     TRUE, TRUE, 0);

  audiopanel->original=gtk_check_button_new_with_label(_("original"));;
  gtk_toggle_button_set_mode(GTK_TOGGLE_BUTTON(audiopanel->original), FALSE);
  gtk_widget_set_sensitive(GTK_WIDGET(audiopanel->original), FALSE);
  gtk_box_pack_start(GTK_BOX(audiopanel->bbox), audiopanel->original,
		     TRUE, TRUE, 0);

  audiopanel->protected=gtk_check_button_new_with_label(_("protected"));
  gtk_toggle_button_set_mode(GTK_TOGGLE_BUTTON(audiopanel->protected), FALSE);
  gtk_widget_set_sensitive(GTK_WIDGET(audiopanel->protected), FALSE);
  gtk_box_pack_start(GTK_BOX(audiopanel->bbox), audiopanel->protected,
		     TRUE, TRUE, 0);
}

GtkWidget *gmtv_audiopanel_new(void){
  GmtvAudiopanel *audiopanel;

  audiopanel=gtk_type_new(gmtv_audiopanel_get_type());

  return GTK_WIDGET(audiopanel);
}

static void gmtv_audiopanel_destroy(GtkObject *object){
  GmtvAudiopanel* audiopanel;

  g_return_if_fail(object != NULL);
  g_return_if_fail(GMTV_IS_AUDIOPANEL(object));

  audiopanel=GMTV_AUDIOPANEL(object);

  if(GTK_OBJECT_CLASS(parent_class)->destroy)
    (*GTK_OBJECT_CLASS(parent_class)->destroy)(object);
}

void gmtv_audiopanel_set_mode(GmtvAudiopanel *audiopanel, gchar *mode){
  gtk_label_set_text(GTK_LABEL(audiopanel->mode),
		     g_strdup_printf("%s", mode));
}

void gmtv_audiopanel_set_layer(GmtvAudiopanel *audiopanel, gchar *layer){
  gtk_label_set_text(GTK_LABEL(audiopanel->layer),
		     g_strdup_printf(_("layer %s"), layer));
}

void gmtv_audiopanel_set_bitrate(GmtvAudiopanel *audiopanel, guint bitrate){
  gtk_label_set_text(GTK_LABEL(audiopanel->bitrate),
		     g_strdup_printf(_("%d bit/s"), bitrate));
}

void gmtv_audiopanel_set_samplingrate(GmtvAudiopanel *audiopanel, gdouble samplingrate){
  gtk_label_set_text(GTK_LABEL(audiopanel->samplingrate),
		     g_strdup_printf(_("%.2f Hz"), samplingrate));
}

void gmtv_audiopanel_set_copyright(GmtvAudiopanel *audiopanel, gboolean copyright){
  gtk_toggle_button_set_mode(GTK_TOGGLE_BUTTON(audiopanel->copyright), copyright);
}

void gmtv_audiopanel_set_original(GmtvAudiopanel *audiopanel, gboolean original){
  gtk_toggle_button_set_mode(GTK_TOGGLE_BUTTON(audiopanel->original), original);
}

void gmtv_audiopanel_set_protected(GmtvAudiopanel *audiopanel, gboolean protected){
  gtk_toggle_button_set_mode(GTK_TOGGLE_BUTTON(audiopanel->protected), protected);
}


/*
 * gmtv audiopanel widget
 */

#ifndef GMTV_AUDIOPANEL_H
#define GMTV_AUDIOPANEL_H

#include <gtk/gtkframe.h>

#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */

#define GMTV_TYPE_AUDIOPANEL           (gmtv_audiopanel_get_type())
#define GMTV_AUDIOPANEL(obj)           (GTK_CHECK_CAST((obj), GMTV_TYPE_AUDIOPANEL, GmtvAudiopanel))
#define GMTV_AUDIOPANEL_CLASS(klass)   (GTK_CHECK_CLASS_CAST((klass), GMTV_TYPE_AUDIOPANEL, GmtvAudiopanelClass))
#define GMTV_IS_AUDIOPANEL(obj)        (GTK_CHECK_TYPE((obj), GMTV_TYPE_AUDIOPANEL))
#define GMTV_IS_AUDIOPANEL_CLASS(klass)(GTK_CHECK_CLASS_TYPE((klass), GMTV_TYPE_AUDIOPANEL))

  typedef struct _GmtvAudiopanel      GmtvAudiopanel;
  typedef struct _GmtvAudiopanelClass GmtvAudiopanelClass;

  struct _GmtvAudiopanel{
    GtkFrame  parent_object;

    GtkWidget *vbox;
    GtkWidget *bbox;

    GtkWidget *mode;
    GtkWidget *layer;
    GtkWidget *bitrate;
    GtkWidget *samplingrate;
    GtkWidget *copyright;
    GtkWidget *original;
    GtkWidget *protected;
  };

  struct _GmtvAudiopanelClass{
    GtkFrameClass parent_class;
  };

  GtkType    gmtv_audiopanel_get_type (void);
  GtkWidget* gmtv_audiopanel_new(void);
  void       gmtv_audiopanel_set_mode(GmtvAudiopanel *audiopanel, gchar *mode);
  void       gmtv_audiopanel_set_layer(GmtvAudiopanel *audiopanel, gchar *layer);
  void       gmtv_audiopanel_set_bitrate(GmtvAudiopanel *audiopanel, guint bitrate);
  void       gmtv_audiopanel_set_samplingrate(GmtvAudiopanel *audiopanel, gdouble samplingrate);
  void       gmtv_audiopanel_set_copyright(GmtvAudiopanel *audiopanel, gboolean copyright);
  void       gmtv_audiopanel_set_original(GmtvAudiopanel *audiopanel, gboolean original);
  void       gmtv_audiopanel_set_protected(GmtvAudiopanel *audiopanel, gboolean protected);

#ifdef __cplusplus
}
#endif

#endif /* GMTV_AUDIOPANEL_H */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]