Null Ptr In Gdk::Window Initializer?



I'm sure I'll be embarrassed when someone shows me what I'm missing, but. . . 

I'm writing a Scrabble (R) program in GTKMM & need to display board squares/tiles. It's pretty simple: a square w/ a colored background, a border, one big letter in the middle, & a small number in the lower right corner.

I'm using a Gdk::Window (Gtk::Image needs an event box to capture mouse clicks), planning to use a PangoLayout to draw the characters, but I can't even construct the window! The Gdk::Window constructor is protected, so I derived ImageSquot1, & this is where I am stuck.

Code:

(header for derived class:)
#include <gtkmm.h>

class ImageSquot1 : public Gdk::Window
{
public:
  ImageSquot1( const Glib::RefPtr<Window> &parent,		// pass on
				GdkWindowAttr *attributes,	// Gdk::Window
				int attributes_mask );		// constructor

private:
  char _letter;  
};

(implementation:)
#include "imagesquot1.h"

ImageSquot1::ImageSquot1( const Glib::RefPtr<Window> &parent,
				GdkWindowAttr *attributes,
				int attributes_mask )
	: Gdk::Window( parent, attributes, attributes_mask )
{
}

(header for testwindow, a Gtk toplevel to hold the Gdk::Window-derived ImageSquot1 object:)
#include "imagesquot1.h"

class ImageSquot1TestWindow : public Gtk::Window
{
public:
  ImageSquot1TestWindow();
protected:
  //Signal handlers:

private:	//children:
  ImageSquot1 *_squot;

};

(implementation:)
#include "imagesquot1testwindow.h"

ImageSquot1TestWindow::ImageSquot1TestWindow()
{
  GdkWindowAttr attrs;

  attrs.title = NULL; 			// title; unused
  attrs.event_mask = 0;			// all events?
  attrs.x = 0;				// x co-ord, masked off
  attrs.y = 0;				// y co-ord; masked off
  attrs.width = 48;			// width
  attrs.height = 48;			// height
  attrs.wclass = GDK_INPUT_OUTPUT;	// window class
  attrs.visual = NULL;			// visual -- will inherit
  attrs.colormap = NULL;		// colormap, will inherit
  attrs.window_type = GDK_WINDOW_CHILD;	// not a toplevel
  attrs.cursor = NULL;			// cursor, will inherit
  attrs.wmclass_name = NULL;		// unused
  attrs.wmclass_class = NULL;		// unused
  attrs.override_redirect = FALSE;	// no-redirect
  attrs.type_hint = (GdkWindowTypeHint) 0;	// window type hint, don't use

  set_title("ImageSquot1 Test");

  Glib::RefPtr<Gdk::Window> window = get_window();
  _squot = new ImageSquot1( window, &attrs, 0 );

  show_all_children();
}

(main program:)
#include "imagesquot1testwindow.h"

int main(int argc, char *argv[])
{
  Gtk::Main kit(argc, argv);

  ImageSquot1TestWindow window;
  window.resize( 500, 250 );
  //Shows the window and returns when it is closed.
  Gtk::Main::run(window);

  return 0;
}

(end of code)

-- Unfortunately the initializer blows up w/ a "segmentation fault" message, which probably means trying to use a null pointer. The backtrace shows:

(gdb) bt
#0  0xb73686d3 in Gdk::Window::Window () from /usr/lib/libgdkmm-2.4.so.1
#1  0x0804d6f4 in ImageSquot1 (this=0x8178708, parent= 0xbfb21028, 
    attributes=0xbfb20fec, attributes_mask=0) at imagesquot1.cpp:6
#2  0x0804cb3d in ImageSquot1TestWindow (this=0xbfb2105c)
    at imagesquot1testwindow.cpp:26
#3  0x0804d056 in main (argc=0, argv=0x0) at imagesquot1testwindow_main.cpp:7

-- which are all initializers. 

If I have read the docs correctly, with attributes_mask = 0, only gint x, gint y, GdkWindowClass wclass, and GdkWindowType window_type are required (I'm not sure abt event_mask, but I think zero means "all events," and the window manager will get the events anyway because override_redirect is masked off -- and it's not a pointer, anyway).

Can anyone help?

Thanks,
Ed Rippy



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