Esempio n. 1
0
void
PrinterAttributes::SetFromNode(DataNode *parentNode)
{
    if(parentNode == 0)
        return;

    DataNode *searchNode = parentNode->GetNode("PrinterAttributes");
    if(searchNode == 0)
        return;

    DataNode *node;
    if((node = searchNode->GetNode("printerName")) != 0)
        SetPrinterName(node->AsString());
    if((node = searchNode->GetNode("printProgram")) != 0)
        SetPrintProgram(node->AsString());
    if((node = searchNode->GetNode("documentName")) != 0)
        SetDocumentName(node->AsString());
    if((node = searchNode->GetNode("creator")) != 0)
        SetCreator(node->AsString());
    if((node = searchNode->GetNode("numCopies")) != 0)
        SetNumCopies(node->AsInt());
    if((node = searchNode->GetNode("portrait")) != 0)
        SetPortrait(node->AsBool());
    if((node = searchNode->GetNode("printColor")) != 0)
        SetPrintColor(node->AsBool());
    if((node = searchNode->GetNode("outputToFile")) != 0)
        SetOutputToFile(node->AsBool());
    if((node = searchNode->GetNode("outputToFileName")) != 0)
        SetOutputToFileName(node->AsString());
    if((node = searchNode->GetNode("pageSize")) != 0)
        SetPageSize(node->AsInt());
}
/*
    constructor
    -----------

    if "szPath" is NULL then we create an untitled document and default object
    
    the type is "doctypeNew" if "lhDoc" is NULL and "doctypeEmbedded" if
    "lhDoc" is non NULL
    
    if "szPath" is non NULL we create a document of type "doctypeFromFile"
    and initialize it from file "szPath"
    
    if "lhDoc" is NULL then we call OleRegisterServerDoc() otherwise we
    just use "lhDoc" as our registration handle
*/
TOLEDocument::TOLEDocument (TOLEServer &server,
                            LHSERVERDOC lhDoc,
                            LPSTR       szPath,
                            BOOL        dirty)
{
  szName = 0;
  lpvtbl = &_vtbl;
  fRelease = FALSE;
  fDirty = dirty;

  server.pDocument = this;

  //
  // since we only have one object we can create it now...
  //
  pObject = new TOLEObject;

  if (szPath)
    LoadFromFile (szPath);

  else {
    SetDocumentName (UNNAMED_DOC);

    type = lhDoc ? doctypeEmbedded : doctypeNew;
  }

  if (lhDoc != 0)
    this->lhDoc = lhDoc;  // use registration handle we were given

  else
  	OleRegisterServerDoc (server.lhServer, szName, this, (LHSERVERDOC FAR *) &this->lhDoc);
}
/*
    LoadFromFile
    ------------

    returns TRUE if successful and FALSE otherwise

    SIDE EFFECTS: if successful sets type to "objtypeFromFile" and sets "szName"
                  to "szPath"
*/
BOOL
TOLEDocument::LoadFromFile (LPSTR szPath)
{
  char      buf[MAXPATHLENGTH];
  TOLEApp  *pApp = (TOLEApp *) GetApplicationObject();

  //
  // in small model if I want to use C++ streams I need to have a near
  // pointer...
  //
  lstrcpy (buf, szPath);

  ifstream  in (buf);

  if (in.fail()) {
      wsprintf (buf, "Cannot open file %s!", szPath);
      MessageBeep (0);
      MessageBox (pApp->MainWindow->HWindow,
                  buf,
                  szAppName, 
                  MB_OK | MB_ICONEXCLAMATION);
    return FALSE;

  } else {
    //
    // read in the signature
    //
    in.read (buf, sizeof (szClassKey) - 1);

    if (strncmp (buf, szClassKey, sizeof (szClassKey) - 1) != 0) {
      wsprintf (buf,
                "File %s is not an \"%s\" file!",
                szPath,
                (LPSTR) szAppName);
      MessageBeep (0);
      MessageBox (pApp->MainWindow->HWindow,
                  buf,
                  szAppName, 
                  MB_OK | MB_ICONEXCLAMATION);

      return FALSE;

    } else {
      in >> *pObject;
      type = doctypeFromFile;
      SetDocumentName (szPath);
    }

    return TRUE;
  }
}
/*
    Reset
    -----

    the only reason that we need this routine is that we re-use the document
    object. if your app doesn't then you would delete the old object and create
    a new one...

    SIDE EFFECTS: sets "fDirty" flag to FALSE and "fRelease" to FALSE

    if "lhDoc" is NULL then call OleRegisterServerDoc()
*/
void
TOLEDocument::Reset (LPSTR szPath)
{
  if (!szPath || !LoadFromFile (szPath)) {
    ((TWindowServer *) GetApplicationObject()->MainWindow)->ShapeChange (objEllipse);

    pObject->native.type = objEllipse;
    pObject->native.version = 1;

    type = doctypeNew;
    SetDocumentName (UNNAMED_DOC);
  }

  if (lhDoc == 0) {
    TOLEApp  *pApp = (TOLEApp *) GetApplicationObject();

  	OleRegisterServerDoc (pApp->pServer->lhServer, szName, this, (LHSERVERDOC FAR *) &lhDoc);
  }

  fDirty = fRelease = FALSE;
}
/*
    SaveAs
    ------

    calls the common Windows dialog function to prompt the user for the
    filename to use
*/
void
TOLEDocument::SaveAs ()
{
  char          path[MAXPATHLENGTH];  // result of GetSaveFileName()
  OPENFILENAME  fnStruct;

  Setup (&fnStruct);
  fnStruct.Flags |= OFN_HIDEREADONLY | OFN_PATHMUSTEXIST;
  wsprintf (path, "*.%s", (LPSTR) szFileExt);
  fnStruct.lpstrFile = path;

  if (GetSaveFileName (&fnStruct)) {
    type = doctypeFromFile;
    SetDocumentName (path);  // we must do this BEFORE we call SaveDoc()
    SaveDoc();

    //
    // now inform the server library that we have renamed the document
    //
    OleRenameServerDoc (lhDoc, szName);
  }
}