home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d4xx / d494 / vscreen.lha / vScreen / Utilities / Source / wMove.c < prev    next >
C/C++ Source or Header  |  1991-06-06  |  3KB  |  124 lines

  1. #include <exec/types.h>
  2. #include <intuition/intuitionbase.h>
  3. #include <intuition/screens.h>
  4. #include <proto/intuition.h>
  5. #include <proto/exec.h>
  6.  
  7. #define INTUITION_REV   0L
  8. extern struct IntuitionBase *IntuitionBase;
  9. extern struct IntuitionBase *OpenLibrary();
  10.  
  11.  
  12. static void ShowUsage()
  13. {
  14.    printf("Usage:  WMOVE dx dy [window [screen]]\n");
  15.    exit(10L);
  16. }
  17.  
  18.  
  19. static void GetInt(i,s)
  20. long *i;
  21. char *s;
  22. {
  23.    if (sscanf(s,"%ld",i) != 1) ShowUsage();
  24. }
  25.  
  26. static struct Screen *FindScreen(ScreenName)
  27. char *ScreenName;
  28. {
  29.    struct Screen *theScreen;
  30.  
  31.    if (ScreenName && ScreenName[0])
  32.    {
  33.       theScreen = IntuitionBase->FirstScreen;
  34.       while (theScreen && (theScreen->Title == NULL ||
  35.              stricmp(theScreen->Title,ScreenName) != 0))
  36.                 theScreen = theScreen->NextScreen;
  37.    } else {
  38.       theScreen = IntuitionBase->ActiveScreen;
  39.    }
  40.  
  41.    if (theScreen == NULL)
  42.    {
  43.       Permit();
  44.       printf("Can't find screen '%s'\n",ScreenName);
  45.       exit(10L);
  46.    }
  47.    return(theScreen);
  48. }
  49.  
  50.  
  51. static struct Window *FindWindow(WindowName,theScreen)
  52. char *WindowName;
  53. struct Screen *theScreen;
  54. {
  55.    struct Window *theWindow;
  56.  
  57.    if (WindowName && WindowName[0])
  58.    {
  59.       theWindow = theScreen->FirstWindow;
  60.       while (theWindow && (theWindow->Title == NULL ||
  61.              stricmp(theWindow->Title,WindowName) != 0))
  62.                 theWindow = theWindow->NextWindow;
  63.    } else {
  64.       theWindow = IntuitionBase->ActiveWindow;
  65.    }
  66.  
  67.    if (theWindow == NULL)
  68.    {
  69.       Permit();
  70.       printf("Can't find window '%s' on screen '%s'\n",
  71.          WindowName,theScreen->Title);
  72.       exit(10L);
  73.    }
  74.    Permit();
  75.    return(theWindow);
  76. }
  77.  
  78.  
  79. void main(argc,argv)
  80. int argc;
  81. char *argv[];
  82. {
  83.    char *WindowName = NULL;
  84.    char *ScreenName = NULL;
  85.    long dx,dy;
  86.    struct Window *theWindow;
  87.    struct Screen *theScreen;
  88.  
  89.    if (argc < 3 || argc > 5) ShowUsage();
  90.    GetInt(&dx,argv[1]);
  91.    GetInt(&dy,argv[2]);
  92.    if (argc > 3 && argv[3] && argv[3][0] != '\0') WindowName = argv[3];
  93.    if (argc > 4 && argv[4] && argv[4][0] != '\0') ScreenName = argv[4];
  94.    
  95.    IntuitionBase = OpenLibrary("intuition.library",INTUITION_REV);
  96.    if (IntuitionBase)
  97.    {
  98.       Forbid();
  99.       theScreen = FindScreen(ScreenName);
  100.       theWindow = FindWindow(WindowName,theScreen);
  101.       Permit();
  102.  
  103.       if (dx < -(theWindow->LeftEdge)) dx = -(theWindow->LeftEdge);
  104.       if (dy < -(theWindow->TopEdge))  dy = -(theWindow->TopEdge);
  105.       
  106.       if (theWindow->LeftEdge + dx + theWindow->Width > theScreen->Width)
  107.          dx = theScreen->Width - theWindow->Width - theWindow->LeftEdge;
  108.       if (theWindow->TopEdge + dy + theWindow->Height > theScreen->Height)
  109.          dy = theScreen->Height - theWindow->Height - theWindow->TopEdge;
  110.  
  111.       printf("\nWindow '%s' on Screen '%s'\n",
  112.          theWindow->Title,theWindow->WScreen->Title);
  113.       printf("   Old position:  (%d,%d)\n",
  114.          theWindow->LeftEdge,theWindow->TopEdge);
  115.       if (dx || dy)
  116.       {
  117.          printf("   New position:  (%d,%d)\n   Changed:       (%d,%d)\n\n",
  118.             theWindow->LeftEdge+dx,theWindow->TopEdge+dy,dx,dy);
  119.          MoveWindow(theWindow,dx,dy);
  120.       }
  121.       CloseLibrary(IntuitionBase);
  122.    }
  123. }
  124.