home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Applications / UIFlow 1.0.1 / UIFlow Source / CFDFront / TInformationView.cp < prev    next >
Encoding:
Text File  |  1992-02-21  |  8.4 KB  |  195 lines  |  [TEXT/MPS ]

  1. #pragma segment UIFlow
  2. //*********************************************************************************
  3. //    Methods for TInformationView Class
  4. //*********************************************************************************
  5. // --------------------------------------------------------------------------------------------------
  6. //    Initialize the TControl Objects
  7. // --------------------------------------------------------------------------------------------------
  8. void TInformationView::IInformationView(TDocument * doc)
  9.     {
  10.     fDocument = doc;
  11.     XCoord = (TEditText *) this->FindSubView('XCor');                                // find XCor Box    
  12.     YCoord = (TEditText *) this->FindSubView('YCor');                                // find YCor Box
  13.     }    
  14.     
  15. pascal void TInformationView::IRes(TDocument *itsDocument, TView *itsSuperView, Ptr *itsParams)
  16.     {
  17.     inherited::IRes(itsDocument,itsSuperView,itsParams);
  18.     }
  19.     
  20. // --------------------------------------------------------------------------------------------------
  21. //    Draw the TControl Objects
  22. // --------------------------------------------------------------------------------------------------
  23. pascal void TInformationView::Draw(Rect * /*thisRect*/)                                // Draws the view seen in the window. 
  24.     {    
  25.     Point pen;
  26.     Rect  tRect;
  27.     pen.v = 1;     pen.h = 1;
  28.     tRect.top = 0;
  29.     tRect.left = 0;
  30.     tRect.right = (short) fSize.h;
  31.     tRect.bottom = (short) fSize.v;
  32.  
  33.     HLock((Handle) this);
  34.     RGBForeColor(&GridLineColor);                                                                    // set color
  35.     PenPixPat(GridLinePat);
  36.     
  37.     this->Adorn(&tRect,pen,adnLineTop);
  38.     this->Adorn(&tRect,pen,adnLineRight);
  39.     HUnlock((Handle) this);
  40.     this->Focus();
  41.     return;
  42.     } 
  43.     
  44. // --------------------------------------------------------------------------------------------------
  45. //    If the SuperView is changed want to move TinformationView
  46. // --------------------------------------------------------------------------------------------------
  47. pascal void TInformationView::SuperViewChangedSize(VPoint *delta, Boolean /*invalidate*/)
  48.     {
  49.     VPoint newLoc;
  50.     
  51.     newLoc.h = fLocation.h;
  52.     newLoc.v = fLocation.v + delta->v;
  53.     this->Locate(newLoc.h,newLoc.v,true);
  54.     newLoc.h = fSize.h + delta->h;
  55.     newLoc.v = fSize.v;
  56.     this->Resize(newLoc.h,newLoc.v,true);
  57.     return;    
  58.     }
  59.  
  60. // --------------------------------------------------------------------------------------------------
  61. //    Menu Command for Undoing & Redoing the edits
  62. // --------------------------------------------------------------------------------------------------
  63. pascal struct TCommand * TInformationView::DoMenuCommand(CmdNumber aCommand)
  64.     {
  65.     TGeomView * geomView;                                                                        // the geometry
  66.     geomView = (TGeomView *)(fSuperView->FindSubView ('geom'));            // get pointer to GeomView
  67.  
  68.     if (aCommand == 101 && geomView->lastCmd == 2)                             // Undo / Redo menu & lastCmd was infoview
  69.         {
  70.         this->StatusString(savePt);                                                                // display the points last coords
  71.         this->DoChoice(this,mButtonHit);                                                        // do DoChoice to move / change it.
  72.         return gNoChanges;
  73.         }
  74.     return inherited::DoMenuCommand(aCommand);                                    // process other menu commands.
  75.     }
  76.     
  77. // --------------------------------------------------------------------------------------------------
  78. //    Process the users action
  79. // --------------------------------------------------------------------------------------------------
  80. pascal void TInformationView::DoChoice(TView * origView, short itsChoice)
  81.     {
  82.     Str255 XPoint, YPoint;                                                                                // pascal string
  83.     StringPtr xText, yText;                                                                            // pascal string storage
  84.     char * XP, * YP;                                                                                        // pointer to pascal c format
  85.     short saveCmd;                                                                                        // temp storage
  86.     Point newPoint;                                                                                    // the newPoint
  87.     TGeomView * geomView;                                                                            // the geometry
  88.     
  89.     geomView = (TGeomView *)(fSuperView->FindSubView ('geom'));                // get pointer to GeomView
  90.     inherited::DoChoice(origView,itsChoice);                                                    // do inherited dochoice first
  91.     
  92.     if (itsChoice == mButtonHit)                                                                        // pressed the set button?
  93.         {
  94.         struct realPt info;                                                                                // define real coord structure
  95.         
  96.         saveCmd = geomView->lastCmd;                                                            // save the last command processed
  97.         geomView->lastCmd = 2;                                                                        // set last command to set button
  98.         XCoord->GetText(XPoint);                                                                    // get the coordinates entered by the user.    
  99.         YCoord->GetText(YPoint);
  100.         
  101.         XP = p2cstr((StringPtr) XPoint);                                                            // 1st convert pascal string to c string.
  102.         YP = p2cstr((StringPtr) YPoint);
  103.         info.x = atof(XP);                                                                                    // convert string to float
  104.         info.y = atof(YP);
  105.         
  106.         HLock((Handle) this);
  107.         newPoint = geomView->fCDocument->RealToView(&info);                            // convert real coords to view coords
  108. //        newPoint = transform(temp,geomView->fMagnify);
  109.         HUnlock((Handle) this);
  110.         if (newPoint.v == NULL)
  111.             {
  112.             geomView->lastCmd = saveCmd;                                                        // reset lastCmd
  113.             xText = c2pstr(XP);
  114.             yText = c2pstr(YP);
  115.             XCoord->SetText(xText,true);                                                            // reset x value
  116.             YCoord->SetText(yText,true);                                                            // reset y value
  117.             return;                                                                                                // return to caller
  118.             }
  119.         savePt = geomView->DragCurrent(newPoint);                                        // drag the current point & save old fStart
  120.         }
  121.     return;
  122.     }
  123.  
  124. // --------------------------------------------------------------------------------------------------
  125. //    Set the status string.
  126. // --------------------------------------------------------------------------------------------------
  127. void TInformationView::StatusString (Point thePoint)
  128.     {
  129.     char Xstrng[20], Ystrng[20];                                                                // c storage string
  130.     TGeomView * geomView;                                                                        // the geometry
  131.     StringPtr XStatus, YStatus;                                                                    // pascal storage string
  132.     struct realPt info;                                                                                // real number structure
  133.     Point temp;
  134.     
  135.     geomView = (TGeomView *)(fSuperView->FindSubView ('geom'));            // get pointer to GeomView
  136.     HLock((Handle) this);
  137.     temp = transform(thePoint,geomView->fMagnify);
  138.     geomView->fCDocument->ViewToReal(thePoint, &info);                        // convert point
  139.     HUnlock((Handle) this);
  140.     
  141.     sprintf (Xstrng,"%.4E",info.x);                                                            // create a c string containing x
  142.     XStatus = c2pstr (Xstrng);                                                                    // create a pascal type string
  143.     sprintf (Ystrng,"%.4E",info.y);                                                            // create a c string containing y
  144.     YStatus = c2pstr (Ystrng);    
  145.  
  146.     XCoord->SetText (XStatus, true);                                                            // display text
  147.     YCoord->SetText (YStatus, true);
  148.     return;
  149.     }
  150.     
  151. // --------------------------------------------------------------------------------------------------
  152. //    Set the information string
  153. // --------------------------------------------------------------------------------------------------
  154. void TInformationView::InfoString (char * theString)
  155.     {
  156.     StringPtr pText;                                                                                    // pascal storage string
  157.     
  158.     pText = c2pstr(theString);                                                                    // convert pascal to c
  159.     fInfoBox = (TStaticText *) this->FindSubView('gInf');                            // find the window
  160.     fInfoBox->SetText(pText,kRedraw);                                                        // draw the text
  161.     }
  162.  
  163. // --------------------------------------------------------------------------------------------------
  164. //    Clear the information string
  165. // --------------------------------------------------------------------------------------------------
  166. void TInformationView::ClrInfo (void)
  167.     {
  168.     char strg[2];
  169.     StringPtr pText;                                                                                    // pascal storage string
  170.     
  171.     strg[0] = 0;                                                                                            // create empty string
  172.     pText = c2pstr(strg);                                                                            // convert pascal to c
  173.     fInfoBox = (TStaticText *) this->FindSubView('gInf');                            // find the window
  174.     fInfoBox->SetText(pText,kRedraw);                                                        // draw the text
  175.     }
  176.  
  177. // --------------------------------------------------------------------------------------------------
  178. //    Display the number of boundry points defined in the geometry
  179. // --------------------------------------------------------------------------------------------------
  180. void TInformationView::ShowDimension (void)
  181.     {
  182.     char            x[155];                                                                                // c string
  183.     StringPtr    pText;                                                                                    // pascal string
  184.     short         fTop, fLeft;                                                                            // number of points on the boundry
  185.     
  186.     fTop = fLeft = 2;                                                                                    // init number of points
  187.     fLeft    = ((TCFDFrontDocument *) fDocument)->fPointMatrix->GetTColumn();
  188.     fTop    = (short) ((TCFDFrontDocument *) fDocument)->fPointMatrix->fSize;
  189.         
  190.     sprintf(x,"Points: R %d  C %d",fTop,fLeft);                                            // create the message
  191.     pText = c2pstr(x);                                                                                // convert message to pascal
  192.     fLocBox = (TStaticText *) this->FindSubView('LOCT');                            // find LOCT box
  193.     fLocBox->SetText(pText,kRedraw);                                                        // display message
  194.     }
  195.