home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-11-21 | 7.2 KB | 250 lines | [TEXT/MPS ] |
- /*
- File: RegisteredObjectsWindow.cp
-
- Contains: Implementation of TRegisteredObjectsWindow. A window that displays a list
- of TRegisteredObjects.
-
- Copyright: © 1991-1993 by Apple Computer, Inc., all rights reserved.
-
- */
-
- #ifndef __WINDOWS__
- #include <Windows.h>
- #endif
- #ifndef __LIST__
- #include <List.h>
- #endif
- #ifndef __EVENTS__
- #include <Events.h>
- #endif
- #ifndef __TOOLUTILS__
- #include <ToolUtils.h>
- #endif
- #ifndef __FONTS__
- #include <Fonts.h>
- #endif
-
- #ifndef __REGISTEREDOBJECTSWINDOW__
- #include <RegisteredObjectsWindow.h>
- #endif
- #ifndef __REGISTEREDOBJECTS__
- #include <RegisteredObjects.h>
- #endif
- #ifndef __STRING__
- #include <string.h>
- #endif
-
- /**********************************************************************
- ** PUBLIC Constructor/Destructor
- ***********************************************************************/
-
- TRegisteredObjectsWindow::TRegisteredObjectsWindow()
- {
- fList = NULL;
- fRegisteredObjects = NULL;
- }
-
- TRegisteredObjectsWindow::TRegisteredObjectsWindow(short resID,
- TRegisteredObjects *theObjects) : TDocument(resID)
- {
- InitRegisteredObjectsWindow(theObjects);
- }
-
- TRegisteredObjectsWindow::~TRegisteredObjectsWindow()
- {
- //Trace("Disposing TRegisteredObjectsWindow\n");
- fRegisteredObjects->SetRegisteredObjectsWindow(NULL); /* we no longer exist */
- HideWindow(fDocWindow);
- delete fList;
- }
-
- /**********************************************************************
- ** PRIVATE InitRegisteredObjectsWindow
- ***********************************************************************/
-
- void TRegisteredObjectsWindow::InitRegisteredObjectsWindow(TRegisteredObjects *theObjects)
- {
- GrafPtr savedPort;
- GetPort(&savedPort);
- SetPort(fDocWindow);
- TextFont(monaco);
-
- /* set the windows title */
-
- char theName[256];
- strcpy(&theName[1],theObjects->GetClassName());
- theName[0] = strlen(&theName[1]);
- SetWTitle(GetDocWindow(),StringPtr(theName));
-
- /* setup the List Manager list */
-
- Rect listRect = fDocWindow->portRect;
- listRect.right -= 15; // scroll bar space
- listRect.bottom -= 15; // scroll bar space
- listRect.left += kButtonSpace; // button space
- Rect dataBounds = {0,0,0,1}; // empty 1 column list
- Point cSize = {0,0}; // let list manager decide cell size
- fList = new TList(&listRect,&dataBounds,cSize,0,fDocWindow,
- true/*drawit*/, true/*hasgrow*/, false/*hScroll*/, true/*vScroll*/);
- fList->SetSelFlags(lOnlyOne); // only allow one cell to be selected
- (**fList->GetList()).cellSize.h = 16383;
-
- fRegisteredObjects = theObjects;
- theObjects->SetRegisteredObjectsWindow(this); /* it needs a pointer to us */
- UpdateList();
-
- SetPort(savedPort);
- }
-
- /**********************************************************************
- ** PUBLIC DoContent
- ***********************************************************************/
-
- void TRegisteredObjectsWindow::DoContent(EventRecord* theEvent)
- {
- //Trace("TRegisteredObjectsWindow::DoContent\n");
- Point mouse;
-
- SetPort(fDocWindow);
- mouse = theEvent->where; // get the click position
- GlobalToLocal(&mouse);
- Rect listRect = GetListRect();
- listRect.right += 15; // 15 for the scrollbars
- listRect.bottom += 15; // 15 for the scrollbars
- if (PtInRect(mouse,&listRect)) { // did we click in list regions?
- if (fList->Click(mouse,theEvent->modifiers)) { // did we double click?
- Cell theCell = fList->LastClick(); // what cell did we double click in
- //*fRegisteredObjects[theCell.v]->Dump(); // dump the object
- TDynamic* theObj = (*fRegisteredObjects)[theCell.v];
- //delete theObj;
- }
- }
- }
-
- /**********************************************************************
- ** PUBLIC DoGrow
- ***********************************************************************/
-
- void TRegisteredObjectsWindow::DoGrow(EventRecord* theEvent)
- {
- Rect sizeRect = {100,175, 32767, 32767};
- Rect oldRect = fDocWindow->portRect;
- long result = GrowWindow(fDocWindow, theEvent->where, &sizeRect);
- if (result) {
- short h = LoWord(result);
- short v = HiWord(result);
- SizeWindow(fDocWindow, h, v, true);
- fList->DoDraw(false);
- fList->Size(h - 15 - kButtonSpace, v - 15);
- fList->DoDraw(true);
- DrawWindow();
- }
- }
-
- /**********************************************************************
- ** PUBLIC DoActivate
- ***********************************************************************/
-
- void TRegisteredObjectsWindow::DoActivate(Boolean becomingActive)
- {
- DrawGrowIcon();
- fList->Activate(becomingActive);
- }
-
- /**********************************************************************
- ** PUBLIC DoUpdate
- ***********************************************************************/
-
- void TRegisteredObjectsWindow::DoUpdate()
- {
- BeginUpdate(fDocWindow); // this sets up the visRgn
- if (!EmptyRgn(fDocWindow->visRgn)) { // draw if updating needs to be done
- fList->Update(fDocWindow->visRgn);
- }
- DrawGrowIcon();
- MoveTo(fDocWindow->portRect.left + kButtonSpace - 1, fDocWindow->portRect.top);
- LineTo(fDocWindow->portRect.left + kButtonSpace - 1, fDocWindow->portRect.bottom);
- EndUpdate(fDocWindow);
- }
-
- /**********************************************************************
- ** PUBLIC DrawWindow
- ***********************************************************************/
-
- // Draw the contents of an application window.
-
- void TRegisteredObjectsWindow::DrawWindow()
- {
- Rect tRect;
-
- SetPort(fDocWindow);
- tRect = fDocWindow->portRect;
- EraseRect(&tRect);
- InvalRect(&tRect);
- }
-
- /**********************************************************************
- ** PUBLIC UpdateList
- ***********************************************************************/
-
- void TRegisteredObjectsWindow::UpdateList()
- {
- GrafPtr savedPort;
- GetPort(&savedPort);
- SetPort(GrafPtr(GetDocWindow()));
-
- EraseRect(&(**fList->GetList()).rView);
-
- fList->DoDraw(false); // turn off list drawing
- fList->DelRow(0,0); // delete the entire list
- unsigned long count = fRegisteredObjects->GetCount();
- fList->AddRow(short(count)); // make space for the cells
- for (int row = 0; row<count; row++) {
- fRegisteredObjects->GetSemaphore()->Grab(); // don't let list change on us
- if (fRegisteredObjects->GetCount() > row) { // make sure list has index "row"
- char theData[256];
- (*fRegisteredObjects)[row]->GetVerboseName(theData); // get the text for the new cell
- fRegisteredObjects->GetSemaphore()->Release(); // ok, it can change now
-
- Cell cell = {0,0}; // {row,0} won't work!!!
- cell.v = row; // we'll add the cell to the end
- fList->SetCell(theData,strlen(theData),cell);
- }
- else
- fRegisteredObjects->GetSemaphore()->Release();
- }
-
- // force the list to be updated
-
- fList->DoDraw(true); // turn on list drawing
- InvalRect(&(**fList->GetList()).rView);
- SetPort(savedPort);
- }
-
- /**********************************************************************
- ** PUBLIC GetListRect
- ***********************************************************************/
-
- Rect TRegisteredObjectsWindow::GetListRect()
- {
- return fList->GetListRect();
- }
-
-
- /**********************************************************************
- ** PUBLIC DrawGrowIcon
- ***********************************************************************/
-
- void TRegisteredObjectsWindow::DrawGrowIcon()
- {
- ::DrawGrowIcon(fDocWindow);
-
- /* get rid of extra "grow icon" section in lower left corner */
- Rect r = fDocWindow->portRect;
- r.top = r.bottom - 16;
- r.bottom -=14;
- r.right = r.left + kButtonSpace - 1;
- EraseRect(&r);
- }
-
-