PureBasic doesn't support overlapped gadgets, unfortunately. If you want to get a layout like that working, you have to separate the events received by the contained canvas from those for the canvas it's sitting on. How to do that?
The key is to ask the OS to treat the containing canvas as though the smaller canvas were not there. Or, more precisely, that the
clipping region occupied by the smaller canvas were not there. A "clipping region" defines an area of screen real estate that a given window (in this case canvas gadget) must maintain for:
a) drawing upkeep
b) mouse/keyboard events processing
When a window is first created, it is assigned a clipping region that covers its full rectangle, including both client and frame areas of the window. In order to separate events from an overlapping window, the original region must be modified to remove from it the real estate occupied by the usurping smaller window.
Mestnyi shows one way, a good one, that uses window style modifications to specify clipping details. There is a second way: Create a region the size of canvas 1, punch a hole in it the size and position of canvas 2, then apply the region to the larger canvas. Now canvas 1 has been told that the area occupied by canvas 2 does not fall within its drawing region and so it is excluded from all event processing and drawing. The smaller area is now free to host a second gadget, a gadget whose events will flow freely and, more importantly, readably.
My guess is that Mestnyi's approach and the one I've just described are identical in the end because when Windows reads the style changes being applied to the canvas, it makes the same region modifications "under the hood".
Code: Select all
EnableExplicit
Define.i one, two
Procedure onCallback_Canvas1()
Debug "onCallback_Canvas1"
EndProcedure
Procedure onCallback_Canvas2()
Debug "onCallback_Canvas2"
EndProcedure
one = CreateRectRgn_(0,0,128,64)
two = CreateRectRgn_(24,8,88,32)
CombineRgn_(one, one, two, #RGN_XOR)
If OpenWindow(0, 0, 0, 512, 512, "Test")
CanvasGadget(1, 8, 8, 128, 64, #PB_Canvas_Border)
SetWindowRgn_(GadgetID(1), one, #True)
BindGadgetEvent(1, @onCallback_Canvas1())
CanvasGadget(2, 32, 16, 64, 24, #PB_Canvas_Border)
BindGadgetEvent(2, @onCallback_Canvas2())
EndIf
Repeat
Define E = WaitWindowEvent()
Until E=#PB_Event_CloseWindow