home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 144.lha / VScreen_Src / wMove.c < prev    next >
Encoding:
C/C++ Source or Header  |  1986-11-21  |  3.2 KB  |  108 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. #define INTUITION_REV   0L
  7. --MORE--(84%)extern struct IntuitionBase *IntuitionBase;
  8. extern struct IntuitionBase *OpenLibrary();
  9. static void ShowUsage()
  10. {
  11.    printf("Usage:  WMOVE dx dy [window [screen]]\n");
  12.    exit(10L);
  13. }
  14. static void GetInt(i,s)
  15. long *i;
  16. char *s;
  17. {
  18.    if (sscanf(s,"%ld",i) != 1) ShowUsage();
  19. }
  20. static struct Screen *FindScreen(ScreenName)
  21. char *ScreenName;
  22. {
  23.    struct Screen *theScreen;
  24. --MORE--(84%)   if (ScreenName && ScreenName[0])
  25.    {
  26.       theScreen = IntuitionBase->FirstScreen;
  27.       while (theScreen && (theScreen->Title == NULL ||
  28.              stricmp(theScreen->Title,ScreenName) != 0))
  29.                 theScreen = theScreen->NextScreen;
  30.    } else {
  31.       theScreen = IntuitionBase->ActiveScreen;
  32.    }
  33.    if (theScreen == NULL)
  34.    {
  35.       Permit();
  36.       printf("Can't find screen '%s'\n",ScreenName);
  37.       exit(10L);
  38.    }
  39.    return(theScreen);
  40. }
  41. static struct Window *FindWindow(WindowName,theScreen)
  42. char *WindowName;
  43. struct Screen *theScreen;
  44. --MORE--(86%){
  45.    struct Window *theWindow;
  46.    if (WindowName && WindowName[0])
  47.    {
  48.       theWindow = theScreen->FirstWindow;
  49.       while (theWindow && (theWindow->Title == NULL ||
  50.              stricmp(theWindow->Title,WindowName) != 0))
  51.                 theWindow = theWindow->NextWindow;
  52.    } else {
  53.       theWindow = IntuitionBase->ActiveWindow;
  54.    }
  55.    if (theWindow == NULL)
  56.    {
  57.       Permit();
  58.       printf("Can't find window '%s' on screen '%s'\n",
  59.          WindowName,theScreen->Title);
  60.       exit(10L);
  61.    }
  62.    Permit();
  63.    return(theWindow);
  64. }
  65. --MORE--(87%)
  66. void main(argc,argv)
  67. int argc;
  68. char *argv[];
  69. {
  70.    char *WindowName = NULL;
  71.    char *ScreenName = NULL;
  72.    long dx,dy;
  73.    struct Window *theWindow;
  74.    struct Screen *theScreen;
  75.    if (argc < 3 || argc > 5) ShowUsage();
  76.    GetInt(&dx,argv[1]);
  77.    GetInt(&dy,argv[2]);
  78.    if (argc > 3 && argv[3] && argv[3][0] != '\0') WindowName = argv[3];
  79.    if (argc > 4 && argv[4] && argv[4][0] != '\0') ScreenName = argv[4];
  80.    
  81.    IntuitionBase = OpenLibrary("intuition.library",INTUITION_REV);
  82.    if (IntuitionBase)
  83.    {
  84.       Forbid();
  85.       theScreen = FindScreen(ScreenName);
  86. --MORE--(88%)      theWindow = FindWindow(WindowName,theScreen);
  87.       Permit();
  88.       if (dx < -(theWindow->LeftEdge)) dx = -(theWindow->LeftEdge);
  89.       if (dy < -(theWindow->TopEdge))  dy = -(theWindow->TopEdge);
  90.       
  91.       if (theWindow->LeftEdge + dx + theWindow->Width > theScreen->Width)
  92.          dx = theScreen->Width - theWindow->Width - theWindow->LeftEdge;
  93.       if (theWindow->TopEdge + dy + theWindow->Height > theScreen->Height)
  94.          dy = theScreen->Height - theWindow->Height - theWindow->TopEdge;
  95.       printf("\nWindow '%s' on Screen '%s'\n",
  96.          theWindow->Title,theWindow->WScreen->Title);
  97.       printf("   Old position:  (%d,%d)\n",
  98.          theWindow->LeftEdge,theWindow->TopEdge);
  99.       if (dx || dy)
  100.       {
  101.          printf("   New position:  (%d,%d)\n   Changed:       (%d,%d)\n\n",
  102.             theWindow->LeftEdge+dx,theWindow->TopEdge+dy,dx,dy);
  103.          MoveWindow(theWindow,dx,dy);
  104.       }
  105.       CloseLibrary(IntuitionBase);
  106.    }
  107. --MORE--(90%)}
  108.