home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-08-29 | 23.1 KB | 965 lines | [TEXT/KAHL] |
- /****
- * CNeoDemoDoc.c
- *
- * Document methods for a typical application.
- *
- * Copyright © 1992 NeoLogic Systems. All rights reserved.
- *
- ****/
-
- #include "NeoTypes.h"
- #include <string.h>
- #include <Packages.h>
- #include <stdlib.h>
- #include <stdio.h>
- #include <Timer.h>
- #include "Global.h"
- #include "Constants.h"
- #include "CError.h"
- #include "Commands.h"
- #include "CDesktop.h"
- #include "CBartender.h"
- #include "CScrollBar.h"
- #include "CPopupMenu.h"
- #include "CDecorator.h"
- #include CNeoMetaClassH
- #include CNeoDatabaseNativeH
- #include "CNeoScrapStream.h"
- #include "CNDCamera.h"
- #include "CNDImagePICT.h"
- #include "CNDImageTIFF.h"
- #include "CNDImageGIF.h"
- #include "CNeoDemoDoc.h"
- #include "CNDPicture.h"
- #include "CNDFilePicture.h"
- #include "CNeoDialogText.h"
- #include "CNeoDLOGDialog.h"
- #include "CNeoDemoApp.h"
- #include "CNeoPopupPane.h"
- #include "CNeoDemoScrollPane.h"
-
- #define kNeoDemoDialog 1000 // resource ID of dialog
-
- #define kMaxSSpeeds 10
- short sSpeedCnt = 0;
- short sSpeedMenu2IDTable[kMaxSSpeeds] = {0};
-
- static Boolean gMarkDirty = TRUE;
-
- extern CBartender * gBartender; /* The menu handling object */
- extern CDecorator * gDecorator; /* Window dressing object */
- extern CDesktop * gDesktop; /* The enclosure for all windows */
- extern CBureaucrat * gGopher; /* The current boss in the chain of command */
-
- /***
- * CNeoDemoDoc
- *
- * This is your document's initialization method.
- * If your document has its own instance variables, initialize
- * them here.
- *
- * The least you need to do is invoke the default method.
- *
- ***/
- CNeoDemoDoc::CNeoDemoDoc(CApplication *aSupervisor, const Boolean aPrintable, const Boolean aNewFile, const Boolean aRemote)
- #ifdef qNeoShare
- : CNeoDocShareTCL(kNeoDemoSig, kNeoDemoFileType, aPrintable, aNewFile, aRemote)
- #else
- : CNeoDocTCL(kNeoDemoSig, kNeoDemoFileType, aPrintable, aNewFile, TRUE, aRemote)
- #endif
- {
- short index;
- CArray * array;
- CNeoDatabase * file;
-
- /* set up the image array */
- array = new (CArray);
- fImageArray = array;
- array->IArray(sizeof(NeoID));
-
- fIndex = 0;
- fSelectKey = nil;
- }
-
- CNeoDemoDoc::~CNeoDemoDoc(void)
- {
- if (fImageArray) {
- emptyImageArray();
- delete fImageArray;
- fImageArray = nil;
- }
-
- if (fSelectKey) {
- delete fSelectKey;
- fSelectKey = nil;
- }
- }
-
- /***
- * buildWindow
- *
- * This is the auxiliary window-building method that the
- * NewFile() and OpenFile() methods use to create a window.
- *
- ***/
-
- void CNeoDemoDoc::buildWindow(void)
-
- {
- CNeoDLOGDialog *dlog;
-
- /**
- ** First create the window and initialize
- ** it. The first argument is the resource ID
- ** of the window. The second argument specifies
- ** whether the window is a floating window.
- ** The third argument is the window's enclosure; it
- ** should always be gDesktop. The last argument is
- ** the window's supervisor in the Chain of Command;
- ** it should always be the Document object.
- **
- **/
-
- dlog = new CNeoDLOGDialog(kNeoDemoDialog, gDesktop, this);
- itsWindow = dlog;
-
- // set the main pane to the dialog panorama
- itsMainPane = (CPane*) dlog->FindViewByID(kDialogPanoramaID);
-
- itsGopher = itsMainPane;
-
- /**
- ** Use CenterWindow to center the window in the middle
- ** of the screen.
- **/
-
- gDecorator->CenterWindow(itsWindow);
-
- inherited::buildWindow();
- }
-
- /***
- * DoSave
- *
- * This method handles what happens when the user chooses Save from the
- * File menu. This method should return TRUE if the file save was successful.
- * If there is no file associated with the document, you should send a
- * DoSaveFileAs() message.
- *
- ***/
-
- Boolean CNeoDemoDoc::DoSave(void)
- {
- CNDImage * image;
-
- if (itsWindow &&
- fIndex) {
- image = getImage(fIndex);
- if (image) {
- updateImage(image);
- image->unrefer();
- }
- }
-
- return inherited::DoSave();
- }
-
-
- /***
- * NewFile
- *
- * When the user chooses New from the File menu, the createDocument()
- * method in your Application class will send a newly created document
- * this message. This method needs to create a new window, ready to
- * work on a new document.
- *
- * Since this method and the OpenFile() method share the code for creating
- * the window, you should use an auxiliary window-building method.
- *
- ***/
- void CNeoDemoDoc::NewFile(void)
- {
- short exposures[10];
- CNDCamera * camera;
- CNeoDatabase * file;
-
- inherited::NewFile();
-
- /**
- ** Add application-specific classes to the file
- **/
- if (fNewDatabase) {
- file = ((CNeoDatabase *)itsFile);
-
- exposures[0] = -500; /* 1/500 */
- exposures[1] = -125; /* 1/125 */
- exposures[2] = -64; /* 1/64 */
- exposures[3] = -32; /* 1/32 */
- exposures[4] = -16; /* 1/16 */
- exposures[5] = -8; /* 1/8 */
- exposures[6] = -4; /* 1/4 */
- exposures[7] = -2; /* 1/2 */
- exposures[8] = 1; /* 1 */
- camera = new CNDCamera("\pCanon", 9, exposures);
- camera->fID = 1;
- file->addObject(camera);
- camera->unrefer();
-
- exposures[0] = -1000; /* 1/1000 */
- exposures[1] = -500; /* 1/500 */
- exposures[2] = -125; /* 1/125 */
- exposures[3] = -64; /* 1/64 */
- exposures[4] = -16; /* 1/16 */
- exposures[5] = -4; /* 1/4 */
- exposures[6] = 1; /* 1 */
- camera = new CNDCamera("\pHasselblad", 7, exposures);
- camera->fID = 2;
- ((CNeoDatabase *)itsFile)->addObject(camera);
- camera->unrefer();
-
- exposures[0] = -125; /* 1/125 */
- camera = new CNDCamera("\pKodak", 1, exposures);
- camera->fID = 3;
- file->addObject(camera);
- camera->unrefer();
-
- exposures[0] = -1000; /* 1/1000 */
- exposures[1] = -500; /* 1/500 */
- exposures[2] = -125; /* 1/125 */
- exposures[3] = -64; /* 1/64 */
- exposures[4] = -32; /* 1/32 */
- exposures[5] = -16; /* 1/16 */
- exposures[6] = -8; /* 1/8 */
- exposures[7] = -4; /* 1/4 */
- exposures[8] = -2; /* 1/2 */
- exposures[9] = 1; /* 1 */
- camera = new CNDCamera("\pNikon", 10, exposures);
- camera->fID = 4;
- file->addObject(camera);
- camera->unrefer();
- }
-
- buildCameraMenu();
- setItems(nil); /* initialize picture to empty & all strings to empty */
- }
-
-
- /***
- * OpenFile
- *
- * When the user chooses Open… from the File menu, the OpenDocument()
- * method in your Application class will let the user choose a file
- * and then send a newly created document this message. The information
- * about the file is in the SFReply record.
- *
- * In this method, you need to open the file and display its contents
- * in a window. This method uses the auxiliary window-building method.
- *
- ***/
-
- void CNeoDemoDoc::OpenFile(SFReply *macSFReply)
- {
- NEOTRY
- {
- fOpenMode = fsRdWrPerm;
- inherited::OpenFile(macSFReply);
-
- buildCameraMenu();
- setSelectionByKeyword(kNDImageID, "");
-
- itsWindow->Select(); /* Don't forget to make the window active */
- }
-
- NEOCATCH
- {
- /*
- * This exception handler will be executed if an exception occurs
- * anywhere within the scope of the TRY node above.
- * You should perform any cleanup of things that won't be needed
- * since the document could not be opened. By convention,
- * the creator of an object is responsible for sending it
- * the unrefer message. This means that we should only dispose
- * of things that would not be taken care of in unrefer.
- * In this case, we just make sure that the Handle theData
- * has been disposed of. The exception will propagate up to
- * CApplications's exception handler, which handles displaying
- * an error alert.
- */
- }
- NEOENDTRY;
- }
-
-
- /***
- * UpdateMenus
- *
- * In this method you can enable menu commands that apply when
- * your document is active.
- *
- * Be sure to call the inherited method to get the default behavior.
- * The inherited method enables these commands: cmdClose, cmdSaveAs,
- * cmdSave, cmdRevert, cmdPageSetup, cmdPrint, cmdUndo.
- *
- ***/
-
- void CNeoDemoDoc::UpdateMenus()
-
- {
- inherited::UpdateMenus();
-
- /* Enable your menu commands here (enable each one with a call to
- gBartender->EnableCmd(command_number)).
- */
- gBartender->EnableCmd(cmdCut);
- gBartender->EnableCmd(cmdCopy);
- gBartender->EnableCmd(cmdPaste);
- gBartender->DisableCmd(cmdRevert);
- gBartender->DisableCmd(cmdUndo);
-
- }
-
- void CNeoDemoDoc::Zoom(Boolean aOut)
- {
- fSignal->Zoom(aOut);
- }
-
- /* Rebuild the camera menu */
- void CNeoDemoDoc::buildCameraMenu(void)
- {
- short index;
- MenuHandle menu = fPopBody->GetMenu()->GetMacMenu();
-
- /* delete all items in the exposures menu except "Unknown" */
- for (index = CountMItems(menu); index > 1; index--)
- DelMenuItem(menu, index);
- CNDCamera::ClearCameraTable();
-
- CNeoPersist::FindEvery(((CNeoDatabase *)itsFile), kNDCameraID, FALSE, (NeoTestFunc1)CNDCamera::MakeCameraMenu, (void *)menu);
- }
-
- /* Rebuild the shutter speed menu */
- void CNeoDemoDoc::buildShutterMenu(const NeoID aCameraID)
- {
- short index;
- short count;
- short item;
- float shutter;
- MenuHandle menu;
- CNDCamera * camera;
- CNeoString string;
-
- /* delete all items in the exposures menu except "Unknown" */
- NeoFailNil(menu = fPopExposure->GetMenu()->GetMacMenu());
- for (index = CountMItems(menu); index > 1; index--)
- DelMenuItem(menu, index);
-
- if (aCameraID) {
- camera = (CNDCamera *)CNeoPersist::FindByID((CNeoDatabase *)itsFile, kNDCameraID, aCameraID, FALSE, nil, nil);
- if (!camera)
- return;
-
- count = camera->getShutterCount();
- for (index = 0; index < count; index++) {
- if (index < kMaxSSpeeds) {
- item = index +2;
- shutter = camera->getShutter(index);
- sSpeedMenu2IDTable[index] = shutter;
- if (shutter > 0) {
- if (shutter == 1)
- string[0] = sprintf((char *)&string[1],"1 Sec.");
- else
- string[0] = sprintf((char *)&string[1],"%ld Secs.", (long)shutter);
- }
- else
- string[0] = sprintf((char *)&string[1],"1/%ldth Sec.", (long)-shutter);
- AppendMenu(menu, "\pfoo");
- SetItem(menu, item, string);
- if (shutter == -125) { /* make 1/125 the default */
- fPopExposure->SelectItem(item, pmForceOn);
- fPopExposure->NewMenuSelection(item);
- }
- }
- }
- sSpeedCnt = count;
- camera->unrefer();
- }
- }
-
- Boolean CNeoDemoDoc::doCutCopy(const Boolean aCut)
- {
- Boolean pass = TRUE;
- Handle scrap = nil;
- CNDImage * image;
- CNeoScrapStream stream('IMGE'); // stream object that reads images
-
- if (!fIndex) // If there is no current image
- return pass; // then there is nothing to do.
-
- image = getImage(fIndex); // Get the current image.
- if (image) { // It better be there!
- updateImage(image); // Just in case user has changed it.
-
- image->writeObject(&stream, kNeoAllTag); // Write it to scrap.
-
- if (aCut) { // Is this a Cut operation?
- ((CNeoDatabase*)itsFile)->removeObject(image);
- removeImage(fIndex); // Remove the image from the file.
- }
- image->unrefer(); // Remove our reference to it.
- pass = FALSE; // No need to pass this command on.
- }
-
- return pass;
- }
-
- Boolean CNeoDemoDoc::doPaste(void)
- {
- Boolean pass = TRUE;
- long length;
- Handle scrap;
- PicHandle pict;
- CNDImage * image;
- CNeoScrapStream stream('IMGE');
-
- if (fIndex > 0)
- updateImage(nil);
-
- switch(getImageType()) {
- case kNDImage: /* use a default type */
- case kNDImagePICT:
- image = (CNDImage*)new CNDImagePICT;
- break;
-
- case kNDImageTIFF:
- image =(CNDImage*) new CNDImageTIFF;
- break;
-
- case kNDImageGIF:
- image = (CNDImage*)new CNDImageGIF;
- break;
- }
-
- image->fID = ((CNeoDatabase *)itsFile)->getUniqueID();
- fIndex++; /* make new image object after current one being viewed */
- fImageArray->InsertAtIndex(&image->fID, fIndex);/* insert object into doc's image array */
- image->setDirty(); /* set dirty so that updateImage really works */
- dirty = TRUE; /* Mark document dirty as well. */
- inherited::UpdateMenus();
- if (fIndex == 1)
- updateImage(image);
-
- image->readObject(&stream, kNeoAllTag);
-
- pict = (PicHandle)image->getBlob();
- if (pict) {
- showBorders(TRUE);
- ((CNeoDatabase *)itsFile)->addObject(image); // add it to file
- setItems(image); // OK, so let's see it
- pass = FALSE; // no need to pass it on
- }
- else { // false paste
- fImageArray->DeleteItem(fIndex); // remove from array
- fIndex--; // go back to previous
- }
- image->unrefer(); // remove reference
-
- return pass;
- }
-
- void CNeoDemoDoc::emptyImageArray(void)
- {
- short index;
-
- if (fImageArray &&
- fImageArray->numItems)
- for (index = fImageArray->numItems; index > 0; index--)
- fImageArray->DeleteItem(index);
- }
-
- NeoID CNeoDemoDoc::getCameraID(void)
- {
- NeoID id;
- CNDImage * image;
-
- if (fIndex) {
- image = getImage(fIndex);
- NeoAssert(image);
- id = image->fCamera;
- image->unrefer();
- }
- else
- id = 0;
-
- return id;
- }
-
- CNDImage *CNeoDemoDoc::getImage(const short aIndex)
- {
- NeoID id;
-
- NeoAssert(aIndex >= 0 && aIndex <= fImageArray->numItems);
-
- fImageArray->GetArrayItem(&id, aIndex);
-
- return (CNDImage *)CNeoPersist::FindByID((CNeoDatabase*)itsFile, kNDImageID, id, TRUE, nil, nil);
- }
-
- short CNeoDemoDoc::getImageCount(void)
- {
- return fImageArray->numItems;
- }
-
- /* return item# of type selected in dialog popup menu */
- short CNeoDemoDoc::getImageType(void)
- {
- /* 1=PICT 2=TIFF 3=GIF 4=Any */
- return fPopObj->GetCheckedItem();
- }
-
- void CNeoDemoDoc::gotoImage(short aIndex, const Boolean aRedraw)
- {
- Boolean update;
- CNDImage * image;
- CBureaucrat * gopher;
-
- if (fIndex == aIndex)
- return;
-
- fIndex = aIndex;
-
- NeoAssert(aIndex <= fImageArray->numItems);
- if (!aIndex) { /* may not be any image objects */
- setItems(nil);
- return;
- }
-
- // Hide text edit borders
- showBorders(FALSE);
-
- // Make the dialog the gopher (to turn caret blinking off).
- if (gGopher &&
- itsMainPane == gGopher) {
- gopher = gGopher;
- gGopher->BecomeGopher(FALSE);
- gopher->itsSupervisor->BecomeGopher(TRUE);
- }
-
- image = getImage(aIndex);
- if (image) { /* retrieve image object from image array */
- gMarkDirty = FALSE;
- setItems(image);
- gMarkDirty = TRUE;
- image->unrefer();
- }
-
- if (aRedraw)
- itsWindow->Update();
- }
-
- /* Return a keyword select key that matches the specified keyword value.
- */
- CNeoKeywordSelect *CNeoDemoDoc::getKeywordKey(char *aKeyword)
- {
- short index;
- char keyword[33];
-
- /* Translate the keyword to lower case */
- for (index = 0; aKeyword[index]; index++)
- if (aKeyword[index] >= 'A' &&
- aKeyword[index] <= 'Z')
- keyword[index] = aKeyword[index] +32;
- else
- keyword[index] = aKeyword[index];
- keyword[index] = 0;
-
- if (fSelectKey)
- fSelectKey->setKeyword(keyword);
- else
- NeoFailNil(fSelectKey = CNDImage::GetKeywordKey(keyword));
-
- return fSelectKey;
- }
-
- void CNeoDemoDoc::removeImage(const short aIndex)
- {
- Boolean redraw = FALSE;
- short index;
- Str255 str;
-
- fImageArray->DeleteItem(aIndex); /* gone from current list */
-
- if (fIndex == aIndex) {
- redraw = TRUE;
- if (fIndex > fImageArray->numItems)
- fIndex = fImageArray->numItems;
- }
- else if (aIndex < fIndex)
- fIndex--;
-
- fScrollObj->itsHorizSBar->SetMaxValue(fImageArray->numItems -1); /* adjust scroll bar limit */
- fScrollObj->itsHorizSBar->SetValue(fIndex -1);
- fScrollObj->Refresh();
-
- /* set static text object for "<picture#> / <max#>" */
- str[0] = sprintf((char *)&str[1], "%ld / %ld", (long)fIndex, (long)fImageArray->numItems);
- fTextInfo->SetTextString(str);
- fTextInfo->Refresh();
-
- dirty = TRUE; /* Mark document dirty as well. */
-
- if (redraw) {
- inherited::UpdateMenus();
- index = fIndex;
- fIndex = -1; /* invalidate fIndex so that gotoImage redraws */
- gotoImage(index, FALSE); /* get one after deleted image on screen */
- }
- }
-
- void CNeoDemoDoc::setCameraID(const NeoID aID)
- {
- Boolean found = FALSE;
- short item = aID;
- short max;
- short index;
-
- if (item) {
- max = fPopBody->GetMenu()->GetNumItems() +1;
- if (item)
- for (index = 2; index < max; index++) // one-based indexing with the first being the "unknown" menu item
- if (CNDCamera::GetCameraID(index) == item) {
- item = index;
- found = TRUE;
- break;
- }
- if (!found)
- item = 1; // select "Unknown"
- }
- else
- item = 1;
-
- if (fPopBody->GetCheckedItem() != item) {
- fPopBody->SelectItem(item, pmForceOn);
- fPopBody->NewMenuSelection(item);
-
- /* Rebuild the shutter speed menu */
- buildShutterMenu(aID);
- }
- fPopBody->Refresh();
- }
-
- void CNeoDemoDoc::setImageDirty(CCollaborator *aProvider, void* aParam, const Boolean aMenu)
- {
- short item;
- NeoID cameraID;
- CNDImage * image;
- CNeoDatabase * database;
-
- if (aMenu) {
- item = *(short *)aParam;
- if (!item)
- return;
-
- if ((CPopupPane *)aProvider == fPopBody) {
- if (item > 1)
- cameraID = CNDCamera::GetCameraID(item);
- else
- cameraID = 0;
- buildShutterMenu(cameraID);
- }
- if (!gMarkDirty)
- return;
- }
-
- if (fIndex &&
- fIndex <= fImageArray->numItems) {
- image = getImage(fIndex);
- if (image) {
- database = gNeoDatabase;
- gNeoDatabase = (CNeoDatabase *)itsFile;
- image->setDirty();
- image->unrefer();
- dirty = TRUE; // Mark Document dirty as well.
- inherited::UpdateMenus();
- gNeoDatabase = database;
- }
- }
- }
-
- void CNeoDemoDoc::setItems(CNDImage *aImage)
- {
- Boolean found;
- short item;
- short index;
- short max;
- unsigned long secs;
- Handle handle;
- PicHandle pict;
- Str255 str;
- char text[255];
-
- fScrollObj->itsHorizSBar->SetMaxValue(aImage ? fImageArray->numItems -1 : 0);
- fScrollObj->itsHorizSBar->SetValue(aImage ? fIndex -1 : 0); /* adjust scroll bar value */
- fScrollObj->Refresh();
-
- if (aImage) {
- switch(aImage->getClassID()) {
- case kNDImageID: /* use a default type */
- case kNDImagePICTID:
- Neostrncpy((char *)str, (char *)"\pPICT", 5);
- break;
-
- case kNDImageTIFFID:
- Neostrncpy((char *)str, (char *)"\pTIFF", 5);
- break;
-
- case kNDImageGIFID:
- Neostrncpy((char *)str, (char *)"\pGIF", 4);
- break;
- }
- }
- else
- str[0] = 0;
-
- fTextType->SetTextString(str);
- fTextType->Refresh();
-
- /* reset CNDFilePicture object's image pointer */
- fPictObj->setImage(aImage);
- fPictObj->Refresh();
-
- /* set static text object for "<picture#> / <max#>" */
- str[0] = sprintf((char *)&str[1], "%ld / %ld", (long)fIndex, (long)fImageArray->numItems);
- fTextInfo->SetTextString(str);
- fTextInfo->Refresh();
-
- /* set static text for picture editable fields */
- if (aImage)
- BlockMove((unsigned char *)aImage->fName, str, aImage->fName[0] +1);
- else
- str[0] = 0;
- fTextName->SetTextString(str);
- fTextName->Refresh();
-
- if (aImage &&
- aImage->fBy[0])
- BlockMove((unsigned char *)aImage->fBy, str, aImage->fBy[0] +1);
- else {
- handle = GetResource('STR ',-16096); /* system user name in system resource */
- BlockMove(*(unsigned char **)handle, str, **(unsigned char **)handle +1);
- }
- fTextBy->SetTextString(str);
- fTextBy->Refresh();
-
- if (aImage &&
- aImage->fDate[0])
- BlockMove((unsigned char *)aImage->fDate, str, aImage->fDate[0] +1);
- else {
- GetDateTime(&secs);
- IUDateString(secs, 0, str);
- }
- fTextDate->SetTextString(str);
- fTextDate->Refresh();
-
- if (aImage)
- item = aImage->fFilm;
- else
- item = 1;
- if (fPopFilm->GetCheckedItem() != item) {
- fPopFilm->SelectItem(item, pmForceOn);
- fPopFilm->NewMenuSelection(item);
- }
-
- if (aImage)
- BlockMove((unsigned char *)aImage->fCatalog, str, aImage->fCatalog[0] +1);
- else
- str[0] = 0;
- fTextCatalog->SetTextString(str);
- fTextCatalog->Refresh();
-
- setCameraID(aImage ? aImage->fCamera : 0);
-
- if (aImage)
- item = aImage->fExposure;
- else
- item = 0;
- found = FALSE;
- max = fPopExposure->GetMenu()->GetNumItems() -1;
- if (item != 0)
- for (index = 0; index < max; index++)
- if (sSpeedMenu2IDTable[index] == item) {
- item = index +2;
- found = TRUE;
- break;
- }
- if (!found)
- item = 1; // select "Unknown"
- fPopExposure->SelectItem(item, pmForceOn);
- fPopExposure->NewMenuSelection(item);
-
- if (aImage)
- item = aImage->fFocal;
- else
- item = 1;
- if (fPopFocal->GetCheckedItem() != item) {
- fPopFocal->SelectItem(item, pmForceOn);
- fPopFocal->NewMenuSelection(item);
- }
-
- if (aImage)
- item = aImage->fFStop;
- else
- item = 1;
- if (fPopFStop->GetCheckedItem() != item) {
- fPopFStop->SelectItem(item, pmForceOn);
- fPopFStop->NewMenuSelection(item);
- }
-
- if (aImage) {
- aImage->buildKeyWordStr((char *)&str[1]); /* construct single string from keywords array */
- str[0] = 'a';
- str[0] = strlen((char *)str) -1;
- }
- else
- str[0] = 0;
- fTextKeywords->SetTextString(str);
- fTextKeywords->Refresh();
- }
-
- /* empty our image list - add all items matching the popup type (including 'any')
- that also match the ID.
- NeoID is kNDImagePICTID, kNDImageTIFFID, kNDImageGIFID, or kNDImageID.
- */
- short CNeoDemoDoc::setSelectionByID(const NeoID aClassID, const NeoID aID)
- {
- /* get current data into image object of database before starting search */
- updateImage(nil);
-
- emptyImageArray();
-
- CNeoPersist::FindByID((CNeoDatabase*)itsFile, aClassID, aID, (aClassID == kNDImageID), (NeoTestFunc1)CNDImage::GetImageID, (void *)fImageArray);
-
- fIndex = 0;
- fScrollObj->itsHorizSBar->SetMaxValue(fImageArray->numItems -1);
-
- if (fImageArray->numItems > 0)
- gotoImage(1, FALSE);
- else
- setItems(nil);
-
- return fImageArray->numItems;
- }
-
- /* empty our image list - add all items matching the popup type (including 'any')
- that also match the text in 'keyword' edit box.
- Called from 'CNDButton::DoClick' method.
- NeoID is kNDImagePICTID, kNDImageTIFFID, kNDImageGIFID, or kNDImageID.
- */
- short CNeoDemoDoc::setSelectionByKeyword(const NeoID aClassID, char *aKeyword)
- {
- CNeoKeywordSelect * key;
-
- // get current data into image object of database before starting search
- updateImage(nil);
-
- emptyImageArray();
-
- key = getKeywordKey(aKeyword);
- getDatabase()->findObject(aClassID, key, (aClassID == kNDImageID), (NeoTestFunc1)CNDImage::GetImageID, (void *)fImageArray);
-
- fIndex = 0;
- fScrollObj->itsHorizSBar->SetMaxValue(fImageArray->numItems -1);
-
- if (fImageArray->numItems > 0)
- gotoImage(1, FALSE);
- else
- setItems(nil);
-
- return fImageArray->numItems;
- }
-
- void CNeoDemoDoc::showBorders(const Boolean aShow)
- {
- fTextName->showBorder(aShow);
- fTextBy->showBorder(aShow);
- fTextDate->showBorder(aShow);
- fTextCatalog->showBorder(aShow);
- fTextKeywords->showBorder(aShow);
- }
-
- /* before scroll, find, or quit */
- void CNeoDemoDoc::updateImage(CNDImage *aImage)
- {
- short item;
- long length;
- Handle text;
- CNDImage * image;
- char keywords[256];
-
- if (aImage) {
- image = aImage;
- image->referTo();
- }
- else if (!fImageArray->numItems)
- return;
- else {
- image = getImage(fIndex);
- if (!image)
- return;
- }
-
- if (!image->isDirty()) {
- image->unrefer();
- return;
- }
-
- text = fTextName->GetTextHandle();
- length = fTextName->GetLength();
- NeoBlockMove(*text, (char *)&image->fName[1], length);
- image->fName[0] = length;
-
- text = fTextBy->GetTextHandle();
- length = fTextBy->GetLength();
- NeoBlockMove(*text, (char *)&image->fBy[1], length);
- image->fBy[0] = length;
-
- text = fTextDate->GetTextHandle();
- length = fTextDate->GetLength();
- NeoBlockMove(*text, (char *)&image->fDate[1], length);
- image->fDate[0] = length;
-
- image->fFilm = fPopFilm->GetCheckedItem();
-
- text = fTextCatalog->GetTextHandle();
- length = fTextCatalog->GetLength();
- NeoBlockMove(*text, (char *)&image->fCatalog[1], length);
- image->fCatalog[0] = length;
-
- item = fPopBody->GetCheckedItem();
- if (item > 1)
- image->fCamera = CNDCamera::GetCameraID(item);
- else
- image->fCamera = 0;
-
- image->fFocal = fPopFocal->GetCheckedItem();
-
- image->fFStop = fPopFStop->GetCheckedItem();
-
- item = fPopExposure->GetCheckedItem();
- if (item > 1)
- image->fExposure = sSpeedMenu2IDTable[item -2];
- else
- image->fExposure = 0;
-
- text = fTextKeywords->GetTextHandle();
- length = fTextKeywords->GetLength();
- if (length > 255)
- length = 255;
-
- /* parse comma delimited keywords string */
- NeoBlockMove(*text, keywords, length);
- keywords[length] = 0;
- image->parseKeywords(keywords);
- image->unrefer();
- }
-
-