The Artima Developer Community
Sponsored Link

Agile Buzz Forum
Getting at Windows

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
James Robertson

Posts: 29924
Nickname: jarober61
Registered: Jun, 2003

David Buck, Smalltalker at large
Getting at Windows Posted: Feb 25, 2007 3:07 AM
Reply to this message Reply

This post originated from an RSS feed registered with Agile Buzz by James Robertson.
Original Post: Getting at Windows
Feed Title: Travis Griggs - Blog
Feed URL: http://www.cincomsmalltalk.com/rssBlog/travis-rss.xml
Feed Description: This TAG Line is Extra
Latest Agile Buzz Posts
Latest Agile Buzz Posts by James Robertson
Latest Posts From Travis Griggs - Blog

Advertisement

Now days, there's many things you'd like to ask of the underlying OS to do with your GUI application. It would be nice of VisualWorks made all of each OSes features very transparent and easy to access, but the truth is, it doesn't. So you often have to step outside of the stock interface provided by the VisualWorks VM. I've found that over the years, the most popular starting point, is OS features that manipulate windows. Having just gone through how to get at the pieces of data that the host OS seems to want to manipulate VW windows for all 3 major windowing platforms, I thought I'd pass along.

Windows

This is probably the most common and most known. Sending the message windowHandle to a VisualWorks window running under the Windows Operation System, will return a the pointer address of the Windows HWND structure. This is used by many of the Win32 APIs. It's often nice to work with the HDC of a window as well. Support for this can be found in the Win95SystemSupport object. Do ssomething like:
	winp := CVoidType void pointerType newOfAddress: aWindow windowHandle.
	hdc := Win95SystemSupport new GetDC: winp.
One thing I've noticed is that this HDC can go "stale" from time to time, seemingly after pop up menus have covered the window. If anyone knows why this is or how to get around it, I would be much obliged.

OSX Aqua (Cocoa)

You can get the handle to an NSWindow associated with a VisualWorks window by sending windowHandle to a VisualWorks Window instance when running under OSX Aqua. After that, it's just sending messsages to it to manipulate it or get other associated objects. See the previous post.

XWindows (X11)

This is the most "obscure" of the 3. X interfaces want a variety of things, and X Windows have a variety of opaque structures different APIs seem to want. Things like the Visual, or the Display, or the VisualInfo, or possibly a Drawable. At first blush, it's not obvious at all how to get this information. It turns out that by chance, sending windowHandle to a Window instance running under X11, will return the pointer address to the Drawable structure. If that's all you need, then you're set. I've never found that to be enough. What happens when you send windowHandle to a Window is that it sends key to the window's GraphicsHandle. GraphicsHandle is just an UninterpretedBytes object. And when you send key to it, it just returns the unsigned int found in the first 4 bytes of of the object. For other platforms, the GraphicsHandle is indeed just 4 bytes. So it makes sense. GraphicsHandle even "prints" itself as those first four bytes. But when you inspect the GraphicsHandle of an XWindows window, you'll find that it's actually 28 bytes big! It turns out that the VM (for X11) builds and keeps a structure of 7 elements to go along with each window instance. And the GraphicsHandle has a copy of all of those bytes in it. The structure it's mirroring is defined as:
typedef struct {
 	   Drawable drawable;
 	   GC gc;
 	   Display *display;
 	   XVisualInfo *visualInfo;
 	   q8 drawableType;
  	  q8 clipMode;
 	   XRectangle clipRectangle;
	} drawableData;
So, if you want the Display of an X11 Window under VisualWorks, you get it's handle (you may have to add an accessor for this), and send unsignedLongAt: 9 to it. or unsignedLongAt: 13 to get the XVisualInfo. Which you can in turn interogate for the Visual.

Read: Getting at Windows

Topic: Continuous Integration And Build Telemetry For Open Source Projects Previous Topic   Next Topic Topic: Cracks in the DRM Ice

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use