Just popping in
Joined: 2009/2/21 14:27 Last Login
: 5/23 13:10
Group:
Registered Users
|
Hi all,
I'm trying to 'dock' two windows to each other, i.e. when you move the 'master' window then the 'slave' window moves along with it.
I've done this by trapping WMHI_CHANGEWINDOW on the main window and then calling SetAttrs() for the slave window with the new position.
However, the slave window doesn't move along with the main window while dragging. Instead, when I release the main window then the slave window will follow the track that the main window took. This looks quite funny but certainly isn't right. Am I doing something wrong? Is there some better way to achieve this?
Thanks for your help.
Here's the code:
;/* WindowMoveTest gcc -o WindowMoveTest WindowMoveTest.c -lauto quit */
#include <stdio.h> #include <stdlib.h> #include <string.h>
#include <dos/dos.h> #include <classes/window.h> #include <gadgets/button.h> #include <gadgets/layout.h>
#include <proto/intuition.h> #include <proto/exec.h> #include <proto/window.h> #include <proto/layout.h> #include <proto/button.h>
enum { WID_MASTER = 0, WID_SLAVE, WID_LAST };
enum { OID_MASTER = 0, OID_SLAVE, OID_LAST };
int main() { ULONG mxpos; ULONG mypos;
// Make sure class files were loaded. if ( WindowBase == NULL || LayoutBase == NULL || ButtonBase == NULL) { return RETURN_FAIL; }
struct Window *windows[WID_LAST]; Object *objects[OID_LAST];
objects[OID_MASTER] = IIntuition->NewObject(NULL, "window.class", WA_ScreenTitle, "MasterWin", WA_Title, "MasterWin", WA_Activate, TRUE, WA_DepthGadget, TRUE, WA_DragBar, TRUE, WA_CloseGadget, TRUE, WA_SizeGadget, FALSE, WA_Left, 100, WA_Top, 100, WA_Width, 200, WA_Height, 100, TAG_DONE);
objects[OID_SLAVE] = IIntuition->NewObject(NULL, "window.class", WA_ScreenTitle, "SlaveWin", WA_Title, "SlaveWin", WA_Activate, FALSE, WA_DepthGadget, TRUE, WA_DragBar, TRUE, WA_CloseGadget, FALSE, WA_SizeGadget, FALSE, WA_Left, 100, WA_Top, 200, WA_Width, 200, WA_Height, 100, TAG_DONE);
if (objects[OID_MASTER] != NULL && objects[OID_SLAVE] != NULL) { // Open the windows. windows[WID_MASTER] = (struct Window *)IIntuition->IDoMethod(objects[OID_MASTER], WM_OPEN); windows[WID_SLAVE] = (struct Window *)IIntuition->IDoMethod(objects[OID_SLAVE], WM_OPEN);
if (windows[WID_MASTER] != NULL && windows[WID_SLAVE] != NULL) { // Obtain the master window wait signal mask.
uint32 signal = 0; IIntuition->GetAttr(WINDOW_SigMask, objects[OID_MASTER], &signal);
// Input Event Loop
BOOL done = FALSE;
while (!done) { uint32 wait = IExec->Wait(signal | SIGBREAKF_CTRL_C);
if ( wait & SIGBREAKF_CTRL_C ) { done = TRUE; break; }
if ( wait & signal ) { uint32 result = WMHI_LASTMSG; int16 code = 0;
while ((result = IIntuition->IDoMethod(objects[OID_MASTER], WM_HANDLEINPUT, &code)) != WMHI_LASTMSG) { switch (result & WMHI_CLASSMASK) { case WMHI_CLOSEWINDOW: windows[WID_MASTER] = NULL; done = TRUE; break;
case WMHI_ICONIFY: IIntuition->IDoMethod(objects[OID_MASTER], WM_ICONIFY); windows[WID_MASTER] = NULL; break;
case WMHI_UNICONIFY: windows[WID_MASTER] = (struct Window *)IIntuition->IDoMethod(objects[OID_MASTER], WM_OPEN); break;
case WMHI_CHANGEWINDOW: IIntuition->GetAttrs(objects[OID_MASTER], WA_Left, &mxpos, WA_Top, &mypos, TAG_END); IIntuition->SetAttrs(objects[OID_SLAVE], WA_Left, mxpos, WA_Top, mypos+100, TAG_END); break; } } } } }
/* Disposing of the window object will also close the window if it is * already opened, and it will dispose of the layout object attached to it. */ IIntuition->DisposeObject(objects[OID_SLAVE]); IIntuition->DisposeObject(objects[OID_MASTER]); }
return RETURN_OK; }
|