home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / opendc12.zip / od124os2.exe / od12osp1.exe / src / dynamicp / bimaglay / dchgsize.c < prev    next >
Text File  |  1997-04-02  |  5KB  |  124 lines

  1. /*====START_GENERATED_PROLOG======================================
  2.  */
  3. /*
  4.  *   COMPONENT_NAME: oddynamicpart
  5.  *
  6.  *   CLASSES: none
  7.  *
  8.  *   ORIGINS: 82,27
  9.  *
  10.  *
  11.  *   (C) COPYRIGHT International Business Machines Corp. 1995,1996
  12.  *   All Rights Reserved
  13.  *   Licensed Materials - Property of IBM
  14.  *   US Government Users Restricted Rights - Use, duplication or
  15.  *   disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  16.  *
  17.  *   IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  18.  *   ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  19.  *   PURPOSE. IN NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  20.  *   CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
  21.  *   USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
  22.  *   OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE
  23.  *   OR PERFORMANCE OF THIS SOFTWARE.
  24.  */
  25. /*====END_GENERATED_PROLOG========================================
  26.  */
  27. /* @(#) 1.4 com/src/samples/dynamicp/bimaglay/dchgsize.c, oddynamicpart, od96os2, odos29712d 97/03/21 17:44:43 (97/02/18 13:54:11)
  28. *******************************************************************
  29. ** Name: void AdjustSize
  30. **
  31. ** Description:  Frame negotiation -- This part preferrs to be
  32. **               rectangular, so try to square up the frame
  33. **               whenever a new shape is requested.  Save
  34. **               frame shape related information in the instance
  35. **               data for use in rendering the part.
  36. **
  37. *******************************************************************
  38. */
  39. try {
  40.    ODRect frameRect;
  41.    ODCanvas* canvas = facet->GetCanvas(ev);
  42.    ODShape* frameShape;
  43.    /*
  44.     *  Negotiate the display frame size with its containing part.
  45.     */
  46.    frameShape = frame->AcquireFrameShape(ev, canvas);
  47.  
  48.    if (frame->IsRoot(ev)) {
  49.       // This is a root part, so use the frame shape as-is
  50.       //frameShape = frame->AcquireFrameShape(ev, canvas);
  51.    } else {
  52.       // not a root part, so
  53.       // calculate the preferred frame shape
  54.       if (_fFrameNegotiated == kODFalse) {
  55.           // determine our preferred initial shape
  56.           const int InitWidth  = 200;
  57.           const int InitHeight = 200;
  58.  
  59.           //
  60.           //  Set up initial Dynamic Part size using PM coordinates
  61.           //  and place in a new OpenDoc shape object.
  62.           //
  63.  
  64.          int contentExtent;   // use this to hide differences between OS/2 and Windows origins
  65.           #ifdef _PLATFORM_OS2_
  66.             contentExtent = 0; // OS/2 origin is bottom left
  67.           #elif defined(_PLATFORM_WIN32_)
  68.             contentExtent = InitHeight; // Windows origin is (strangely) top right
  69.           #endif
  70.           frameRect.left   = 0;
  71.           frameRect.top    = ODIntToFixed(InitHeight-contentExtent);
  72.           frameRect.right  = ODIntToFixed(InitWidth);
  73.           frameRect.bottom = ODIntToFixed(contentExtent);
  74.  
  75.           //
  76.           //  Set frame negotiated to True.  If the part was instantiated
  77.           //  either from its template or as a root part this flag was false.
  78.           //
  79.           _fFrameNegotiated = kODTrue;
  80.       } else {
  81.           // shape has changed, so square the frame
  82.           //frameShape = frame->AcquireFrameShape(ev, canvas);
  83.           frameShape->GetBoundingBox(ev, &frameRect);
  84.           if (ev->_major != NO_EXCEPTION) {somExceptionFree(ev); return;}
  85.           //frameShape->Release(ev);
  86.  
  87.           long cxFrame = frameRect.right - frameRect.left;
  88.           long cyFrame = abs(frameRect.top - frameRect.bottom);
  89.           if (cxFrame < cyFrame)
  90. #ifdef _PLATFORM_OS2_
  91.              frameRect.top = frameRect.bottom + cxFrame;
  92. #elif defined(_PLATFORM_WIN32_)
  93.              frameRect.bottom = frameRect.top + cxFrame;
  94. #endif
  95.           else if (cxFrame > cyFrame)
  96.              frameRect.right = frameRect.left  + cyFrame;
  97.  
  98.       }
  99.       // request the new frame shape //
  100.       if (frameShape!=kODNULL) {
  101.         ODRect orgFrameRect;
  102.         frameShape->GetBoundingBox(ev, &orgFrameRect);
  103.         frameShape->Release(ev);
  104.         // but only request new shape if the old shape is not already square
  105.         if (orgFrameRect.right-orgFrameRect.left != abs(orgFrameRect.top-orgFrameRect.bottom)) {
  106.           ODShape *requestedShape = frame->CreateShape(ev);
  107.           requestedShape->SetRectangle(ev, &frameRect);
  108.             if (ev->_major != NO_EXCEPTION) {somExceptionFree(ev); return;}
  109.           frameShape = frame->RequestFrameShape(ev, requestedShape, canvas);
  110.             if (ev->_major != NO_EXCEPTION) {somExceptionFree(ev); return;}
  111.         } /* endif */
  112.       } /* endif */
  113.    } /* endif */
  114.  
  115.    somSelf->CalcNewShape(ev, frame);
  116.    if (ev->_major != NO_EXCEPTION) {somExceptionFree(ev); return;}
  117.  
  118. } catch (IException &exc) {
  119.    reportIException(exc);
  120. } catch (...) {
  121.    reportAnyException(ev);
  122. } /* end try */
  123.  
  124.