home *** CD-ROM | disk | FTP | other *** search
- /*****************************************************************************
-
- mac_scrap.c: Copyright (c) Kevin Hammond 1993. All rights reserved.
-
- Scrap Handling.
-
- This file contains routines to show/hide the clipboard,
- and load the scrap from the TE private scrap or vice-versa
- as necessary.
-
- *****************************************************************************/
-
-
- #pragma segment Scrap
-
- #include "mac.h"
-
- Boolean scrapVisible = FALSE, /* Whether the scrap is visible */
- copyscrap = FALSE; /* Set when the scrap must be copied */
-
-
- /*
- Show or hide the clipboard.
- */
-
-
- showhideclipboard()
- {
- if(!scrapVisible)
- {
- ShowWindow(WINDOW(scrap));
- SelectWindow(WINDOW(scrap));
- setitem(Menu_Edit,MItem_Show_Clipboard,"Hide Clipboard");
- }
- else
- {
- HideWindow(WINDOW(scrap));
- setitem(Menu_Edit,MItem_Show_Clipboard,"Show Clipboard");
- }
- scrapVisible = !scrapVisible;
- }
-
-
- /*
- Load the clipboard scrap from the actual scrap record.
- */
-
-
- long scrapTextLength = 0;
-
- loadscrap()
- {
- static short lastscrapcount = 0;
- short newscrapcount;
-
- TEHandle scrapTE;
- Handle scrapText;
-
- static Boolean scrapError = FALSE;
-
- long dummyOffset = 0;
-
- /* See if the scrap has changed */
- newscrapcount = InfoScrap()->scrapCount;
- if (newscrapcount == lastscrapcount)
- return;
-
- /* If so, remember the scrapCount and get a handle to its text */
- lastscrapcount = newscrapcount;
- scrapTE = TEHANDLE(scrap);
- scrapText = NewHandle(0);
- scrapTextLength = GetScrap(scrapText,'TEXT',&dummyOffset);
-
- if(scrapTextLength > 32767)
- {
- /* Don't give more than one error for the same scrap overflow */
- if(!scrapError)
- {
- Error("","Clipboard contents too large for Gofer to handle");
- scrapError = TRUE;
- }
- }
- else
- {
- scrapError = FALSE;
- /* Now plug the handle into the scrap's TE record and notify TE */
- DisposeHandle((**scrapTE).hText);
- (**scrapTE).hText = scrapText;
- TECalText(scrapTE);
-
- AdjustScrollBars(scrap);
- AdjustText(scrap);
-
- if(scrapVisible)
- {
- /* The window must be the current port for invalidation */
- GrafPtr saveport;
-
- /* Invalidate the visible region here */
- GetPort(&saveport);
- SetPort(WINDOW(scrap));
-
- EraseRgn(WINDOW(scrap)->visRgn);
- InvalRgn(WINDOW(scrap)->visRgn);
-
- SetPort(saveport);
- }
- }
- }
-
-
- doscrap()
- {
- if(copyscrap)
- {
- long err;
- if((err=ZeroScrap()) != noErr)
- AbortErrorN("Unexpected result (%d) from ZeroScrap",err);
- if((err=TEToScrap()) != noErr)
- AbortErrorN("Unexpected result (%d) from TEToScrap",err);
- else
- {
- loadscrap();
- copyscrap = FALSE;
- }
- }
- }
-