Ejemplo n.º 1
0
PUBLIC void
put_scrap_helper_dib (void *lp)
{
  PicHandle pich;

  pich = pict_from_lp (lp);
  if (pich)
    {
      GWorldPtr gp;

      gp = gworld_from_pict (pich);
      if (gp)
	{
	  SDL_Surface *surfp;

	  surfp = surface_from_gworld (gp);
	  if (surfp)
	    {
	      write_surfp_to_clipboard (surfp);
	      SDL_FreeSurface (surfp);
	    }
	  DisposeGWorld (gp);
	}
      DisposHandle ((Handle) pich);
    }
}
Ejemplo n.º 2
0
PUBLIC int
get_scrap_helper_dib (void *vh, void *lp)
{
  SDL_Surface *surfp;
  GWorldPtr gp;
  PicHandle pich;
  Handle h;
  int retval;
  int len;

  surfp = surface_from_dib (lp);
  gp = gworld_from_surface (surfp);
  SDL_FreeSurface (surfp);
  pich = pict_from_gworld (gp, &len);
  DisposeGWorld (gp);
  h = (Handle) vh;
  len = GetHandleSize ((Handle) pich);
  ReallocHandle (h, len);
  if (MemErr != noErr)
    retval = -1;
  else
    {
      memcpy (STARH (h), STARH (pich), len);
      retval = len;
    }
  DisposHandle ((Handle) pich);
  return retval;
}
Ejemplo n.º 3
0
PRIVATE PicHandle
pict_from_lp (const void *lp)
{
  PicHandle retval;

  if (!lp)
    retval = NULL;
  else
    {
      int len;

      len = *(int *)lp;
      retval = (PicHandle) NewHandle (len);
      if (retval)
	{
	  char *p;

	  p = (char *) STARH (retval);
	  if (p)
	    memcpy (p, (char *)lp+sizeof(int), len);
	  else
	    {
	      warning_unexpected (NULL_STRING);
	      DisposHandle ((Handle) retval);
	      retval = NULL;
	    }
	}
    }

  return retval;
}
Ejemplo n.º 4
0
void
disposedirwindow (WindowPtr wp)
{
  SendBehind (g_hotband, (WindowPtr) 0);
  if ((**g_selection)[0] != 0 && (*(**g_selection)[0])->contrlOwner == wp)
    (**g_selection)[0] = 0;
  DisposHandle ((*(opendirinfo **) ((WindowPeek) wp)->refCon)->path);
  DisposeWindow (wp);
  showviewmenu (FrontWindow () != g_hotband);
}
Ejemplo n.º 5
0
/* ----------------------------------------------------------------------------
   tbitShutdown 
   Terminate TPS off-screen bitmap subsystem at shutdown. 
   Returns nothing.                
   ---------------------------------------------------------------------------- */
TPSAPI_DECLP( void )  tbitShutdown (void)
{
sWORD				i;
PixMapHandle 	hPixMap; 

	for (i = 0; i < _NrTPorts; i++)
	{
		if (_TPorts[i].pPort != nil)
		{
			SetPort((GrafPtr)_TPorts[i].pPort);
			SetPortPix(_TPorts[i].hOldPixMap);
			CloseCPort(_TPorts[i].pPort);
		}
	}
	tmemFreeNativePtr(_TPorts);
	_TPorts = nil;
	_NrTPorts = 0;
    if (_hTBitDevice != nil)
    {
    	hPixMap = (**_hTBitDevice).gdPMap;
    	if (hPixMap != nil)  
    	{
    		if ((**hPixMap).pmTable != nil)  
            	DisposCTable((**hPixMap).pmTable);
    		if ((**hPixMap).baseAddr != nil)  
            	DisposHandle((Handle)(**hPixMap).baseAddr);
        	DisposHandle((Handle)hPixMap);
    	}
    	if ((**_hTBitDevice).gdITable != nil)
        	DisposHandle((Handle)(**_hTBitDevice).gdITable);
        DisposHandle((Handle)_hTBitDevice);
		_hTBitDevice = nil;
    }
    if (_hColorTable != nil)
		DisposCTable(_hColorTable);
    _hColorTable = nil;
	TpsAssertW((_NrAllocBitmap == 0), "Internal bipmaps not freed by application!", &_NrAllocBitmap, 1);
	SetGDevice(_hStartupDevice);
	SetPort(_pStartupPort);
}
Ejemplo n.º 6
0
void SRGP_loadColorTable
(int startentry, int count,
 unsigned short *redi,
 unsigned short *greeni,
 unsigned short *bluei)
{
    register int i, j;
    RGBColor rgb;
    ReqListRec **rl;
    CTabHandle ctab;


    DEBUG_AIDS{
        SRGP_trace (SRGP_logStream, "SRGP_loadColorTable  %d  %d  %x %x %x\n",
        startentry, count, redi, greeni, bluei);

        /* PERFORM CHECKING LEGALITY OF THE RANGE OF INDICES. */
        srgp_check_pixel_value (startentry, "start");
        srgp_check_pixel_value (startentry+count-1, "end");
        LeaveIfNonFatalErr();
    }

#ifdef COLOR_QUICKDRAW
    InitMacColorTable (startentry, startentry+count-1, &ctab);

    for (i=startentry,j=0; j<count; i++,j++) {
        rgb.red = redi[j];
        rgb.green = greeni[j];
        rgb.blue = bluei[j];
        (**srgpmac__applctab).ctTable[i].rgb = rgb;
        (**ctab).ctTable[j].rgb = rgb;
    }

    InitReqList (startentry, startentry+count-1, &rl);
    RestoreEntries (ctab, NULL, *rl);
    DisposHandle (rl);
    DisposHandle (ctab);
#endif
}
Ejemplo n.º 7
0
static void getWordCountVerb (void) {
	
	Handle htext;
	short wordcount;
	
	if (!IACgettextparam ((OSType) keyDirectObject, &htext))
		return;
	
	indexNthWord (htext, 32767, &wordcount);
	
	IACreturnshort (wordcount);
	
	DisposHandle (htext);
	} /*getWordCountVerb*/
Ejemplo n.º 8
0
static void indexNthWordVerb (void) {
	
	Handle htext;
	short n;
	short wordcount;
	
	if (!IACgettextparam ((OSType) keyDirectObject, &htext))
		return;
	
	if (!IACgetshortparam ((OSType) 'n   ', &n))
		return;
		
	IACreturnshort (indexNthWord (htext, n, &wordcount));
	
	DisposHandle (htext);
	} /*indexNthWordVerb*/
Ejemplo n.º 9
0
static void getNthWordVerb (void) {
	
	Handle htext;
	short n;
	short wordcount;
	Str255 word;
	
	if (!IACgettextparam ((OSType) keyDirectObject, &htext))
		return;
	
	if (!IACgetshortparam ((OSType) 'n   ', &n))
		return;

	getword (htext, indexNthWord (htext, n, &wordcount), word);
	
	IACreturnstring (word);
	
	DisposHandle (htext);
	} /*getNthWordVerb*/
Ejemplo n.º 10
0
P1(PUBLIC pascal trap, void, LDispose, ListHandle, list)	/* IMIV-271 */
{
  if (list)
    {
      LISTDECL();
      LISTBEGIN(list);
      LISTCALL(lCloseMsg, FALSE, (Rect *)0, * (Cell *) &HxX(list, clikLoc), 0,
	       0, list);
      LISTEND(list);

      DisposHandle((Handle) HxP(list, cells));
      if (HxP(list, hScroll))
	DisposeControl(HxP(list, hScroll));
      if (HxP(list, vScroll))
	DisposeControl(HxP(list, vScroll));
    }
#if defined (LIST_DEBUG)
  delete_list (list);
#endif  
}
Ejemplo n.º 11
0
/* ----------------------------------------------------------------------------
   tbitAlloc 
   Open a bitmap. 
   Returns trasparent handle to an internal bitmap or nil.                
   ---------------------------------------------------------------------------- */
TPSAPI_DECLP( HTBIT )  tbitAlloc (uWORD depth, TRECT *Bounds, uWORD flags)
{
HTBIT				hTBit;
short				bytesPerRow; 						// bytes per row in PixMap 
TBitPtr				pTBit;
Rect				box;
PixMapHandle 		hPixMap = nil;						// handle to new off-screen PixMap 
Handle     			hDataBits;  

/**  validations  **/
	TpsAssert(((flags & ~kAllFlagsMASK) == 0), "Bad flags!");
	TpsAssert(((flags & TBIT_Virtual) == 0), "Virtual bitmaps not supported!");
	TpsAssert(((flags & TBIT_Purgeable) == 0), "Purgable bitmaps not supported!");
	TpsAssert(((flags & TBIT_DefaultColorTable) != 0), "Default color table is the only option!");
	TpsAssert((depth == 1 || depth == 2 || depth == 4 || depth == 8 || depth == 16 || depth == 32), "Bad depth!");
	TpsAssert((Bounds != nil), "Bounding box not existant!");
	TpsAssert(((Bounds->top == 0) && (Bounds->left == 0)), "Bounding box not zero based!");
	TpsAssert(((Bounds->bottom > 0) && (Bounds->right > 0)), "Bounding box empty!");

/**  compute row bytes  **/
	bytesPerRow = tbitCalcRowBytes((Bounds->right - Bounds->left), depth, flags);
	TpsAssert((bytesPerRow < kMaxRowBytes), "Bytes per row > 16,382!");	// maximum number of bytes per row is 16,382 

/**  allocate a new PixMap  **/
	SetRect(&box, Bounds->left, Bounds->top, Bounds->right, Bounds->bottom);
    if ((hPixMap = (PixMapHandle)NewHandleClear(sizeof(PixMap))) == nil)
        return nil;
	if (_SetUpPixMap(depth, &box, _hColorTable, bytesPerRow, hPixMap) != noErr)
	{
        if (hPixMap != nil)  
            DisposHandle((Handle)hPixMap);
        return nil;
	}
	hDataBits = (Handle)(**hPixMap).baseAddr;			// handle to pixel image

/**  create internal bitmap record  **/
//	if ((hTBit = tmemAlloc(sizeof(TBitRec), (TMEM_AFNONPURGEABLE | TMEM_AFNONVIRTUAL | TMEM_AFNONSUBALLOC | TMEM_AFZEROINIT))) == nil)
	if ((hTBit = tmemAlloc(sizeof(TBitRec), TMEM_AFZEROINIT)) == nil)
	{
        if (hPixMap != nil)  
        {
            DisposCTable((**hPixMap).pmTable);
            DisposHandle((Handle)hDataBits);
            DisposHandle((Handle)hPixMap);
        }
		return nil;
	}	

/**  load bitmap data  **/
	pTBit = TBitDeRef(hTBit);
	pTBit->Flags = 0;    								// no state flags yet
	pTBit->Depth = depth;								// bits per pixel
	pTBit->InPort = -1;									// no internal port in use yet
	pTBit->BytesPerRow = bytesPerRow; 					// bytes per row
	pTBit->Bounds = box;         						// bounding box 
	pTBit->hPixMap = hPixMap;      						// pixel image
	pTBit->hDataBits = hDataBits;						// reference to image 
	pTBit->hGDevice = _hTBitDevice;						// reference to subsystem device 
	pTBit->ForeColor.red = 0x000;						// initailize foreground color to black
	pTBit->ForeColor.green = 0x000;
	pTBit->ForeColor.blue = 0x000;
	pTBit->BackColor.red = 0xFFFF;						// initailize background color to white
	pTBit->BackColor.green = 0xFFFF;
	pTBit->BackColor.blue = 0xFFFF;
	SetPt(&pTBit->Pen.pnLoc, 0, 0);						// pen normal
	SetPt(&pTBit->Pen.pnSize, 1, 1);
	pTBit->Pen.pnMode = patCopy;
	pTBit->Pen.pnPat = qd.black;
	pTBit->Text.Font = 0;								// default system font 
	pTBit->Text.Face = 0;								// plain
	pTBit->Text.Mode = srcCopy;							// overwrite
	pTBit->Text.Size = 0;								// default font size
	pTBit->LockCount = 0;    							// unlocked  
	pTBit->MagicKey = kMagicBitmapKey;					// bitmap magic
	Debug( _NrAllocBitmap++; )
Ejemplo n.º 12
0
/* ----------------------------------------------------------------------------
   tbitStartup 
   Initialize TPS off-screen bitmap subsystem at startup. 
   Returns error code indicating success.                
   ---------------------------------------------------------------------------- */
TPSAPI_DECLP( BOOLEAN )  tbitStartup (uWORD NrPorts, uWORD depth, HNATIVE hColor)
{
sWORD				i;
Rect				Bounds;
OSErr				osError = noErr; 
SignedByte			saveState; 
PixMapHandle 		hPixMap = nil;						// handle to new off-screen PixMap 
short				bytesPerRow; 						// bytes per row in PixMap 

	fHasColorQuickdraw = tsysMacHasCQD(true);
/**  validations/initializations  **/
	TpsAssert((_TPorts == nil), "Bitmap subsystem was already been started up!");
	TpsAssert((hColor != nil), "Bitmap subsystem color table must be provided!");
	TpsAssert(tsysMacHasSys7(), "System 7 or greater required!");
	TpsAssert(fHasColorQuickdraw, "32Bit Color QuickDraw required!");
	TpsAssert(tsysMacHasGWorlds(), "QuickDraw Color GWorlds required!");
	GetPort(&_pStartupPort);
	_hStartupDevice = GetGDevice();

/**  clone the clut (to be used throughout)  **/
    saveState = HGetState((Handle)hColor);				// save color tableÕs current state
    HNoPurge((Handle)hColor);							// make sure it isnÕt purgeable 
    _hColorTable = (CTabHandle)hColor;
    osError = HandToHand((Handle *)&_hColorTable);
    HSetState((Handle)hColor, saveState);				// restore color tableÕs state
    if (osError != noErr)
	{
//		terrSetErrorCode(TERR_TMEMSECTION, TMEM_ERRALLOC);
		return FALSE;
	}

/**  create device (to be used throughout)  **/
	//SetRect(&Bounds, 0, 0, 1, 1);
	Bounds.left = 0;
	Bounds.top = 0;
	Bounds.right = 1;
	Bounds.bottom = 1;

	bytesPerRow = 16;									// 16 byte align rowbytes
    if ((hPixMap = (PixMapHandle)NewHandleClear(sizeof(PixMap))) == nil)
		goto Failure;
	if (_SetUpPixMap(depth, &Bounds, _hColorTable, bytesPerRow, hPixMap) != noErr)
		goto Failure;
    if ((_hTBitDevice = (GDHandle)NewHandleClear(sizeof(GDevice))) == nil)
		goto Failure;
	if (_CreateGDevice(hPixMap, _hTBitDevice) != noErr)
		goto Failure;

/**  create internal port list  **/
	if ((_TPorts = (TBitPort *)NewPtrClear(sizeof(TBitPort) * (NrPorts + 1))) == nil)
		goto Failure;
	
/**  create pool of off-screen ports  **/
	//SetRect(&Bounds, 0, 0, 1, 1);
	Bounds.left = 0;
	Bounds.top = 0;
	Bounds.right = 1;
	Bounds.bottom = 1;

	for (i = 0; i < NrPorts; i++)
	{
		if ((_TPorts[i].pPort = (CGrafPtr)NewPtrClear(sizeof(CGrafPort))) == nil)
			goto Failure;
	    OpenCPort(_TPorts[i].pPort); 
		_TPorts[i].hOldPixMap = (_TPorts[i].pPort)->portPixMap;
		SetPortPix(nil);
	}

/**  clean up and out  **/
	SetPort(_pStartupPort);
	SetGDevice(_hStartupDevice);
	_NrTPorts = NrPorts; 
	return TRUE;

Failure:
    if (hPixMap != nil)  
    {
    	if ((**hPixMap).pmTable != nil)  
            DisposCTable((**hPixMap).pmTable);
    	if ((**hPixMap).baseAddr != nil)  
            DisposHandle((Handle)(**hPixMap).baseAddr);
        DisposHandle((Handle)hPixMap);
    }
    if (_hTBitDevice != nil)
    {
    	if ((**_hTBitDevice).gdITable != nil)
			DisposHandle((Handle)(**_hTBitDevice).gdITable);
        DisposHandle((Handle)_hTBitDevice);
		_hTBitDevice = nil;
    }
	if (_TPorts != nil)
	{
		for (i = 0; i < NrPorts; i++)
		{
			if (_TPorts[i].pPort != nil)
			{
				SetPort((GrafPtr)_TPorts[i].pPort);
				SetPortPix(_TPorts[i].hOldPixMap);
				CloseCPort(_TPorts[i].pPort);
			}
		}
		tmemFreeNativePtr(_TPorts);
		_TPorts = nil;
	}
    if (_hColorTable != nil)
		DisposCTable(_hColorTable);
	SetGDevice(_hStartupDevice);
	SetPort(_pStartupPort);
//	terrSetErrorCode(TERR_TMEMSECTION, TMEM_ERRALLOC);
	return FALSE;
}
Ejemplo n.º 13
0
void
hashicons (ControlHandle c)
{
/* todo: worry about filenames in FREFs */
  /* get FREF, BNDL, ICN#, ics#, icl8, ics8, icl4, ics4 */
  /* BNDL is:
     4 bytes of signature
     2 bytes of 0 [signature resource id?]
     2 bytes of <number of main entries - 1> (almost always 1)
     numberofmainentries *
     4 bytes of 'ICN#' or 'FREF'
     2 bytes of <number of entries - 1>
     numberofentries *
     2 bytes of localid
     2 bytes of resid
   */
/* todo: see what happens with multiple BNDLs */

  char *p;
  short i, j, spacemade, nummain, numbndls;
  unsigned short hashval;
  iconentry **iconarray;
  icontableentry **node;
  Handle h;
  OSType signature;
  short refnum, sigid;
  unsigned char state;
  applist **ah;

  refnum = openappres (c);
  numbndls = Count1Resources ('BNDL');
  for (i = 1; i <= numbndls; i++)
    {
      h = (Handle) Get1IndResource ('BNDL', i);
      state = HGetState (h);
      HLock (h);
      p = *h;
      signature = *(OSType *) p;
      p += 4;
      sigid = *(short *) p;
      p += 2;

      hashval = (unsigned long) signature % SIGARRAYSIZE;
#define CONTROLPROBLEMS
#ifndef CONTROLPROBLEMS
      for (ah = sigowners[hashval]; ah != 0 && (*ah)->sig != signature; ah = (*ah)->next)
	;
      if (ah == 0)
	{
#endif /* CONTROLPROBLEMS */
	  ah = sigowners[hashval];
	  sigowners[hashval] = (applist **) NewHandle (sizeof (applist));
	  (*sigowners[hashval])->next = ah;
	  (*sigowners[hashval])->parid = (*(item **) (*c)->contrlData)->ioparid;
	  (*sigowners[hashval])->vrefnum = (*(item **) (*c)->contrlData)->vrefnum;
	  (*sigowners[hashval])->sig = signature;
	  mystr255copy ((*sigowners[hashval])->name, (*c)->contrlTitle);
#ifndef CONTROLPROBLEMS
	}
#endif /* CONTROLPROBLEMS */

/* todo: find out if nummain must == 2 */
      nummain = *(short *) p + 1;
      p += 2;

      spacemade = 0;
      for (j = 0; j < nummain; j++)
	{
	  dobundle (&spacemade, &iconarray, &p);
	}

      for (j = 0; j < spacemade; j++)
	{
	  hashval = ((unsigned long) signature + (unsigned long) (*iconarray)[j].type)
	    % ICONTABLESIZE;
	  for (node = icontable[hashval]; node != 0 &&
	       ((*node)->sig != signature || (*node)->type != (*iconarray)[j].type);
	       node = (*node)->next)
	    ;
	  if (node == 0)
	    {
	      node = (icontableentry **) NewHandle (sizeof (icontableentry));
	      (*node)->sig = signature;
	      (*node)->type = (*iconarray)[j].type;
	      (*node)->next = icontable[hashval];
	      geticons (node, (*iconarray)[j].resid);
	      icontable[hashval] = node;
	    }
	}
      DisposHandle ((Handle) iconarray);
      HSetState (h, state);
      ReleaseResource (h);
    }
  CloseResFile (refnum);
}
Ejemplo n.º 14
0
P9(PUBLIC pascal trap, ListHandle,  LNew, Rect *, rview,	/* IMIV-270 */
	    Rect *, bounds, Point, csize, INTEGER, proc, WindowPtr, wind,
	      BOOLEAN, draw, BOOLEAN, grow, BOOLEAN, scrollh, BOOLEAN, scrollv)
{
    ListHandle retval;
    ListPtr lp;
    INTEGER noffs, min, max;
    INTEGER *ip;
    Rect r;
    int i;
    DataHandle tempdatah;
    Handle temph;
    LISTDECL();

    noffs = (CW(bounds->right) - CW(bounds->left)) *
				     (CW(bounds->bottom) - CW(bounds->top)) +1;
    retval = (ListHandle) NewHandle(sizeof(ListRec) -
	         sizeof(HxX(retval, cellArray)) + (noffs+1) * sizeof(INTEGER));
    if (!retval)
/*-->*/	return 0;	/* couldn't allocate memory */

    temph = RM(GetResource(TICK("LDEF"), proc));
    if (!(HxX(retval, listDefProc) = temph)) {
	DisposHandle((Handle) retval);
/*-->*/	return 0;	/* spooey list definition proc */
    }

    TRAPBEGIN();
    tempdatah = RM((DataHandle) NewHandle(0));
    HxX(retval, cells) = tempdatah;
    HLock((Handle) retval);
    lp = STARH(retval);

    lp->dataBounds  = *bounds;
    lp->rView       = *rview;
    lp->port        = RM(wind);
    lp->indent.h    = 0;
    lp->indent.v    = 0;
    lp->selFlags    = 0;
#if defined (STEF_lActivefix)
    lp->lActive     = TRUE;
#else
    lp->lActive     = FrontWindow() == wind;
#endif
    lp->lReserved   = 0;
    lp->clikTime    = 0;
    lp->clikLoc.h   = CWC(-32768);
    lp->clikLoc.v   = CWC(-32768);
    lp->mouseLoc.h  = -1;
    lp->mouseLoc.v  = -1;
    lp->lClikLoop   = 0;
    lp->lastClick.h = -1;
    lp->lastClick.v = -1;
    lp->refCon      = 0;
    lp->userHandle  = (Handle) 0;
    lp->maxIndex    = -1;	/* What is this anyway? */
    ip = (INTEGER *) lp->cellArray;
    for (i = 0; i <= noffs; i++)
        *ip++ = 0;

    lp->visible.top  = bounds->top;
    lp->visible.left = bounds->left;
    lp->vScroll = 0;
    lp->hScroll = 0;
    C_LCellSize(csize, retval);	/* sets cellSize and visible */

    lp->listFlags = draw ? DODRAW : 0;
    if (scrollv) {
	r = lp->rView;
	r.top = CW(CW(r.top) - 1);
	r.left = r.right;
	r.right = CW(CW(r.right) + (16));
	r.bottom = CW(CW(r.bottom) + 1);
	ROMlib_vminmax(&min, &max, lp);
	lp->vScroll = RM(NewControl((WindowPtr) wind, &r, (StringPtr) "",
	       draw && lp->lActive, min, min, max, scrollBarProc, (LONGINT) 0));
	STARH(MR(lp->vScroll))->contrlRfCon = RM((LONGINT) (long) retval);
	lp->listFlags |= lDoVAutoscroll;
    }

    if (scrollh) {
	r = lp->rView;
	r.left = CW(CW(r.left) - 1);
	r.top = r.bottom;
	r.bottom = CW(CW(r.bottom) + (16));
	r.right = CW(CW(r.right) + 1);
	ROMlib_hminmax(&min, &max, lp);
	lp->hScroll = RM(NewControl((WindowPtr) wind, &r, (StringPtr) "",
	       draw && lp->lActive, min, min, max, scrollBarProc, (LONGINT) 0));
	STARH(MR(lp->hScroll))->contrlRfCon = RM((LONGINT) (long) retval);
	lp->listFlags |= lDoHAutoscroll;
    }

    HUnlock((Handle) retval);
    LISTBEGIN(retval);
    LISTCALL(lInitMsg, FALSE, (Rect *)0, * (Cell *)&lp->clikLoc, 0, 0, retval);
    LISTEND(retval);
    TRAPEND();
#if defined (LIST_DEBUG)
    add_list (retval);
#endif
    return retval;
}
Ejemplo n.º 15
0
P1 (PUBLIC pascal trap, void, DisposCTable,
    CTabHandle, ctab)
{
  DisposHandle ((Handle) ctab);
}