[comp.sys.amiga.tech] RAW: windows

carolyn@cbmvax.UUCP (Carolyn Scheppner CATS) (05/27/88)

In article <1162@pur-phy> ng@newton.physics.purdue.edu.UUCP (Nicholas J. Giordano) writes:
>
>I am working on a program which opens a raw: window for input and
>output.  Even though I make it a certain size when I open it, it is possible
>for the user to change the size later.  How can my program determine the
>actual size? 

Check out the ConUnit stuff in this example.  The ConUnit structure
is defined in devices/conunit.h and contains all kinds of useful
information including the current and maximum X and Y character positions 
for your window.  When the user resizes the window, the maximums change.

This example shows how to make DOS tell you the window pointer and the
console IORequest pointer (and ConUnit) of your AmigaDOS window.


/* ConPackets.c -  C. Scheppner, A. Finkel, P. Lindsay  CBM
 *   DOS packet example
 *   Requires 1.2
 */

#include "exec/types.h"
#include "exec/memory.h"
#include "libraries/dos.h"
#include "libraries/dosextens.h"
#include "devices/conunit.h"

#define ACTION_SCREEN_MODE  994L
#define DOSTRUE  -1L
#define DOSFALSE  0L

/* Used for checking version */
ULONG DosBase;

/* Globals initialized by findWindow() */
struct Window  *conWindow;
struct ConUnit *conUnit;

main()
   {
   LONG  infile;
   WORD  curX, curY;

   if(!(DosBase=(OpenLibrary("dos.library",33))))
      cleanexit("\nVersion 1.2 required\n");

   if((infile = Input()) <= 0)
      cleanexit("\nNo stdin ... Did you RUN this ???\n");

   if (! findWindow()) cleanexit("\nNot enough free memory\n");

   printf("\033[0 p\014");  /* Turn off cursor, home and clear */
   printf("Window = $%lx   ConUnit = $%lx\n\n",conWindow, conUnit);
   printf("CURSOR LIMITS:  XMax = %ld   YMax = %ld\n",
              conUnit->cu_XMax + 1, conUnit->cu_YMax + 1);
   curX = conUnit->cu_XCCP;
   curY = conUnit->cu_YCCP;
   printf("*<--- here cursor was at position %ld,%ld\n",curX,curY);

   /* Move to first position of last line and clear to EOL */
   clearLast();
   printf("ABSOLUTE CURSOR POSITIONING...");
   Delay(100);
   clearLast();
   setRawCon(DOSTRUE);
   printf("RAW MODE: Press ANY key...");
   printf(" Hex value = %02lx",(UBYTE)getchar());
   /* Maybe they pressed a string key - if so, get rest */
   while(WaitForChar(infile,100L)) printf(" %02lx",(UBYTE)getchar());

   setRawCon(DOSFALSE);
   printf("\nShort demo --- That's it\n");
   cleanup();
   }


clearLast()
   {
   printf("\033[%ld;%0H\033[M", conUnit->cu_YMax + 1);
   }


cleanexit(s)
char *s;
   {
   if(*s)    printf(s);    /* Print error */
   cleanup();
   exit(0);
   }

cleanup()
   {
   setRawCon(DOSFALSE);
   printf("\033[1 p\n"); /* Turn cursor on */
   if(DosBase) CloseLibrary(DosBase);
   }



/* sendpkt code - A. Finkel, P. Lindsay, C. Scheppner  CBM */

LONG setRawCon(toggle)
LONG toggle;     /* DOSTRUE (-1L)  or  DOSFALSE (0L) */
   {
   struct MsgPort *conid;
   struct Process *me;
   LONG myargs[8] ,nargs, res1;

   me = (struct Process *) FindTask(NULL);
   conid = (struct MsgPort *) me->pr_ConsoleTask;

   myargs[0]=toggle;
   nargs = 1;
   res1 = (LONG)sendpkt(conid,ACTION_SCREEN_MODE,myargs,nargs);
   return(res1);
   }


LONG findWindow() /* inits conWindow and conUnit (global vars) */
   {
   struct InfoData *id;
   struct MsgPort  *conid;
   struct Process  *me;
   LONG myargs[8] ,nargs, res1;

   /* Alloc to insure longword alignment */
   id = (struct InfoData *)AllocMem(sizeof(struct InfoData),
                                       MEMF_PUBLIC|MEMF_CLEAR);
   if(! id) return(0);
   me = (struct Process *) FindTask(NULL);
   conid = (struct MsgPort *) me->pr_ConsoleTask;

   myargs[0]=((ULONG)id) >> 2;
   nargs = 1;
   res1 = (LONG)sendpkt(conid,ACTION_DISK_INFO,myargs,nargs);
   conWindow = (struct Window *)id->id_VolumeNode;
   conUnit = (struct ConUnit *)
                 ((struct IOStdReq *)id->id_InUse)->io_Unit;
   FreeMem(id,sizeof(struct InfoData));
   return(res1);
   }


LONG sendpkt(pid,action,args,nargs)
struct MsgPort *pid;  /* process indentifier ... (handlers message port ) */
LONG action,          /* packet type ... (what you want handler to do )   */
     args[],          /* a pointer to a argument list */
     nargs;           /* number of arguments in list  */
   {
   struct MsgPort        *replyport;
   struct StandardPacket *packet;
 
   LONG  count, *pargs, res1;

   replyport = (struct MsgPort *) CreatePort(NULL,0);
   if(!replyport) return(NULL);

   packet = (struct StandardPacket *) 
      AllocMem((long)sizeof(struct StandardPacket),MEMF_PUBLIC|MEMF_CLEAR);
   if(!packet) 
      {
      DeletePort(replyport);
      return(NULL);
      }

   packet->sp_Msg.mn_Node.ln_Name = (char *)&(packet->sp_Pkt);
   packet->sp_Pkt.dp_Link         = &(packet->sp_Msg);
   packet->sp_Pkt.dp_Port         = replyport;
   packet->sp_Pkt.dp_Type         = action;

   /* copy the args into the packet */
   pargs = &(packet->sp_Pkt.dp_Arg1);       /* address of first argument */
   for(count=0;count < nargs;count++) 
      pargs[count]=args[count];
 
   PutMsg(pid,packet); /* send packet */

   WaitPort(replyport);
   GetMsg(replyport); 

   res1 = packet->sp_Pkt.dp_Res1;

   FreeMem(packet,(long)sizeof(struct StandardPacket));
   DeletePort(replyport); 

   return(res1);
   }




-- 
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Carolyn Scheppner -- CATS   >>Commodore Amiga Technical Support<<
                     UUCP  ...{allegra,ihnp4,rutgers}!cbmvax!carolyn 
                     PHONE 215-431-9180
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

toebes@sas.UUCP (John Toebes) (05/27/88)

In reference to finding the size of a RAW: window:

I know this isn't the answer that you are looking for, but I would
recommend that you look into using console.device directly with a
window that you open.  The code for dealing with the window as a normal
RAW: window is quite simple - I put an example of doing a simple
printf, puts, getchar etc. in the article I wrote for Ami-Transactor.
This will ultimately give you the most flexibility and control over what
happens to the window.  It will also open the path for improving the
Amiga interface with less work.

However IF you do want to go with a RAW: window, I suggest 3 things:
  1) Get CONMAN.  You can control quite explicitely how the window is
     to be opened (no sizing gadget or borders, etc) as well as
     a close gadget.
  2) Use the info packet (sample posted by Andy Finkel some time back)
     to obtain the window pointer from the handler.  Given this, you
     can get the size by just looking at the structure.  (Someone
     else scream if this seems distasteful)
  3) Use the raw events sequence to get back all the resizing events so
     that you can track them.  You will find these documented in the
     AmigaDOS reference manual.

See, it isn't that painless, you have at least 4 attacks on the problem.
These certainly aren't the only ones, I would suggest that you experiment
to find out what works best for you.
 |_o_o|\\   John A. Toebes, VIII       usenet:..mcnc!rti!sas!toebes
 |. o.| ||
 | .  | ||  Coordinator of ...
 | o  | ||    The Software Distillery
 |  . |//     USnail: 235 Trillingham Ln, Cary NC 27513
 ======       BBS: (919)-471-6436

kodiak@amiga.UUCP (Robert R. Burns) (05/27/88)

In article <3881@cbmvax.UUCP> carolyn@cbmvax.UUCP (Carolyn Scheppner CATS) writes:
>In article <1162@pur-phy> ng@newton.physics.purdue.edu.UUCP (Nicholas J. Giordano) writes:
>>
>>I am working on a program which opens a raw: window for input and
>>output.  Even though I make it a certain size when I open it, it is possible
>>for the user to change the size later.  How can my program determine the
>>actual size? 
>
>Check out the ConUnit stuff in this example.

But if you just want to know the character bounds, write "\233 q" or "\033[ q"
to the console, and read back and parse something that looks like
"\2331;1;24;77 r" where the four numbers 1;1;24;77 are the row/col one-based
indices of the upper right and lower left corners.  Currently, the upper left
is always 1;1, and the lower right varies depending on the window size
(in this example 24 rows by 77 columns).

- Kodiak