[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.platform.swt] Re: Painting an image in Eclipse plugin

Hi, Prakash. Sorry to take so long to answer.

The way we usually paint an image in a widget is to add a paint listener to 
the widget.
When the OS calls the listener to do the painting, the PaintEvent parameter 
will have a GC in it.
At this point, we can call gc.drawImage(image, x, y) or some other image 
drawing routine in the org.eclipse.swt.graphics.GC class.
For example:
   widget.addPaintListener(new PaintListener() {
      public void paintControl(PaintEvent e) {
       e.gc.drawImage(image, x, y);
      }
     });
This is the usual way, and note that you do not have to dispose the gc.
This uses the SWT API so that the code is portable across all of the OS's.

If for some reason you need to paint an image at some random time (and not 
just when the OS calls paint) you can create a GC for the widget and draw 
the image on that. For example:
   GC gc = new GC(widget);
   gc.drawImage(image, x, y);
   gc.dispose();
Note that in this case, you do need to dispose the gc because you created 
it.

In general, application code should not need to (or want to <g>) look at 
handles, because that can lead to platform-specific code.

Hope this helps,
Carolyn

"Prakash Raghavendra" <praghave@xxxxxxxxx> wrote in message 
news:2ec15e9094eafc690f5b0e5c12f55646$1@xxxxxxxxxxxxxxxxxx
> Hi All,
>
> I needed a help in getting the right widget-window where I can paint an 
> image (using XPutImage on X). Now, what I have is a "handle" from eclipse 
> port onto Linux and my plugin to eclipse has this "handle" from eclipse.
>
> On Windows, I see that this handle actually is HWND and on Mac its 
> HIViewRef.
>
> However on Linux, I found that this is actually a pointer to GtkWidget.
>
> Now, in my plugin case, this pointer actually points to window which has 
> many widgets and one of them happens to be the window where I need to 
> paint my image.
>
> I was trying to find out the right widget by using 
> gtk_widget_get_ancestor(widget, <TYPE>)
>
> However the issue is there are plenty of types which I could try and find 
> out whether we have such a type or not.
> Is there a elegant way of doing this ? Something like:
>
> GtkWidget *mywidget = (GtkWidget *) handle;
> mywindow = <Search for all widgets to get the right type> (mywidget);
> myXwin = mywindow->window;
> display = GDK_WINDOW_XDISPLAY(myXwin);
> screen = DefaultScreen(display);
> XPutImage (display, window, .... <image created>);
>
> So, how do I search for widgets housed within the widget given by eclispe 
> handle and find the right window ?
>
> Thanks for any quick help.
> Regards
> Prakash
>