home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 …ember: Reference Library / Apple Developer Reference Library (December 1999) (Disk 1).iso / pc / technical documentation / develop / develop issue 28 / develop issue 28 code / sketch / source / main / documents.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-08-11  |  1.5 KB  |  84 lines

  1. /****************************************************************************
  2.  * 
  3.  * Documents.c
  4.  * 
  5.  ****************************************************************************/
  6.  
  7. #include <stdlib.h>
  8. #include <string.h>
  9. #include <stdio.h>
  10.  
  11. #include "Structs.h"
  12. #include "Documents.h"
  13. #include "DocumentADT.h"
  14.  
  15. #include "StringUtils.h"
  16.  
  17. #include "ResID.h"
  18.  
  19. #define    kMOVE_TO_FRONT            (WindowPtr)-1
  20.  
  21. // ---------------------------------------------------------------
  22.  
  23. DocumentReference
  24. MakeNewDocument(StringPtr name)
  25. {
  26.     OSErr                    error = noErr;
  27.     WindowPtr            window;
  28.     DocumentReference document;
  29.     
  30.     static                documentNumber = 0L;
  31.     
  32.     window     = nil;
  33.     document = nil;
  34.     
  35.     window = GetNewCWindow(rMainWindow, (Ptr)0L, kMOVE_TO_FRONT);
  36.     if (window == nil) 
  37.     {
  38.         error     = memFullErr;
  39.         document = nil;
  40.     }
  41.     else
  42.     {
  43.         Str255 documentName;
  44.         Str255 string;
  45.  
  46.         SetPort(window);
  47.         
  48.         if (name != NULL)
  49.         {
  50.             PStringCopy(name, documentName);
  51.         }
  52.         else
  53.         {
  54.             documentNumber++;
  55.             
  56.             PStringCopy("\pUntitled ", documentName);
  57.             NumToString(documentNumber, string);
  58.             PStringConcat(documentName, string);
  59.         }
  60.         
  61.         document = CreateDocument(GetDocumentList(), kEtchDocument);
  62.         if (document == nil) 
  63.         {
  64.             error = memFullErr;
  65.             DisposeWindow(window);
  66.         }
  67.         else
  68.         {
  69.             // Establish 2-way link between document and window
  70.             SetDocumentWindow(document, window);
  71.             SetWRefCon(window, (long)document);
  72.             
  73.             // Set document name and window title
  74.             SetDocumentName(document, documentName);
  75.         }
  76.     }
  77.     
  78.     return document;
  79. }
  80.  
  81. // ---------------------------------------------------------------
  82.  
  83.  
  84.