home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / opendc12.zip / od124os2.exe / od12osp1.exe / src / basecntr / iodbcvwt.cpp < prev    next >
Text File  |  1997-04-02  |  17KB  |  475 lines

  1. // @(#) 1.3 com/src/samples/basecntr/iodbcvwt.cpp, odbasepart, od96os2, odos29712d 3/17/97 20:15:34 [3/21/97 17:51:34]
  2.  
  3. //====START_GENERATED_PROLOG======================================
  4. //
  5. //
  6. //   COMPONENT_NAME: odbasepart
  7. //
  8. //   CLASSES: none
  9. //
  10. //   ORIGINS: 82,27
  11. //
  12. //
  13. //   (C) COPYRIGHT International Business Machines Corp. 1995,1996
  14. //   All Rights Reserved
  15. //   Licensed Materials - Property of IBM
  16. //   US Government Users Restricted Rights - Use, duplication or
  17. //   disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  18. //
  19. //   IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  20. //   ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  21. //   PURPOSE. IN NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  22. //   CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
  23. //   USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
  24. //   OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE
  25. //   OR PERFORMANCE OF THIS SOFTWARE.
  26. //
  27. //
  28. //====END_GENERATED_PROLOG========================================
  29. //
  30.  
  31. //----------------------------------------------------------------------------- 
  32. //  IODBCVWT.CPP
  33. //  This file contains methods for displaying the view types of BaseContainer.
  34. //----------------------------------------------------------------------------- 
  35.  
  36. // -------------------------------------------------------------------------
  37. // BaseContainer --> AdjustViewTypeShapes
  38. //
  39. //      Adjusts the frame shape of the part according to the viewType.
  40. //      Keeps track of the last frame shape, to restore it when changing
  41. //      from icon to frame view.
  42. //
  43. //      -> This method is a private method of BaseContainer
  44. // -------------------------------------------------------------------------
  45. SOM_Scope void  SOMLINK BaseContainerAdjustViewTypeShapes(BaseContainer *somSelf,
  46.                                                           Environment *ev,
  47.                                                           ODFrame* frame)
  48. {
  49.     BaseContainerData *somThis = BaseContainerGetData(somSelf);
  50.     BaseContainerMethodDebug("BaseContainer","BaseContainerAdjustViewTypeShapes");
  51.  
  52.     try
  53.     {
  54.  
  55.       // Do not change frame shape if this is a root frame
  56.       if(frame->IsRoot(ev)) return;
  57.  
  58.       // Prevent infinite recursion of frame negotiation
  59.       if(_fInFrameNegotiation) return;
  60.  
  61.  
  62.       ODRect rect;
  63.       ODTypeToken newViewType = frame->GetViewType(ev);
  64.       TempODShape newShape = frame->CreateShape(ev);
  65.  
  66.       TempODShape currShape = frame->AcquireFrameShape(ev, kODNULL);
  67.       currShape->GetBoundingBox(ev, &rect);
  68.  
  69.  
  70.       if((_fPrevViewType == _fFrameView) && (_fPrevViewType == newViewType))
  71.       {
  72.          // This is an adjustment due to a resize or reconnect.
  73.          // Just store the new frame shape.
  74.          _lastFrameRect = rect;
  75.  
  76.          // Do not attempt any frame negotiation.
  77.          return;
  78.       }
  79.       somSelf->SetViewTypeRect(ev, newViewType, &rect);
  80.       newShape->SetRectangle(ev, &rect);
  81.  
  82.  
  83.       // Get the facet from the frame
  84.       ODFrameFacetIterator  *facetIter = frame->CreateFacetIterator(ev);
  85.       ODFacet *facet = facetIter->First(ev);
  86.       delete facetIter;
  87.  
  88.       _fInFrameNegotiation = kODTrue;
  89.  
  90.       // Change the frame shape
  91.       TempODShape finalShape = frame->RequestFrameShape(ev, newShape, kODNULL);
  92.  
  93.       _fInFrameNegotiation = kODFalse;
  94.  
  95.       // Container has the last word on frame shape. If the returned frame
  96.       // is not the one requested, reset the lastFrameRect.
  97.       if(!finalShape->IsSameAs(ev, newShape) && (newViewType == _fFrameView))
  98.       {
  99.          finalShape->GetBoundingBox(ev, &_lastFrameRect);
  100.       }
  101.  
  102.       _fPrevViewType = newViewType;
  103.     }
  104.     catch(ODException _exception)
  105.     {
  106.     }
  107. }
  108.  
  109.  
  110. // -------------------------------------------------------------------------
  111. // BaseContainer --> SetViewTypeRect
  112. //
  113. //      Determines the size of the frame's bounding box according to the
  114. //      viewType.
  115. //
  116. //      -> This method is a private method of BaseContainer
  117. // -------------------------------------------------------------------------
  118. SOM_Scope void  SOMLINK BaseContainerSetViewTypeRect(BaseContainer *somSelf,
  119.                                                      Environment *ev,
  120.                                                      ODTypeToken viewType,
  121.                                                      ODRect* rect)
  122. {
  123.     BaseContainerData *somThis = BaseContainerGetData(somSelf);
  124.     BaseContainerMethodDebug("BaseContainer","BaseContainerSetViewTypeRect");
  125.  
  126.     int viewSize;
  127.  
  128.     if(viewType == _fSmallIconView) {
  129.        viewSize = kODSmallIconSize;
  130.     } else if(viewType == _fLargeIconView) {
  131.        viewSize = kODLargeIconSize;
  132.     } else if(viewType == _fThumbnailView) {
  133.        viewSize = kODThumbnailSize;
  134.     } else {
  135.        *rect = _lastFrameRect;
  136.        return;
  137.     }
  138.  
  139.     rect->right = IntToFixed((FixedToInt(rect->left)) + viewSize);
  140. #ifdef _PLATFORM_OS2_
  141.     rect->bottom = IntToFixed(0);
  142.     rect->top    = IntToFixed(viewSize);
  143. #else
  144.     rect->bottom = IntToFixed(viewSize);
  145.     rect->top    = IntToFixed(0);
  146. #endif
  147. }
  148.  
  149.  
  150. // -------------------------------------------------------------------------
  151. // BaseContainer --> DrawFrame
  152. //
  153. //      Draws our contents in frame view.
  154. //
  155. //      -> This method is a private method of BaseContainer
  156. // -------------------------------------------------------------------------
  157. SOM_Scope void  SOMLINK BaseContainerDrawFrame(BaseContainer *somSelf,
  158.                                             Environment *ev,
  159.                                             ODFacet* facet,
  160.                                             ODShape* invalidShape)
  161. {
  162.     BaseContainerData *somThis = BaseContainerGetData(somSelf);
  163.     BaseContainerMethodDebug("BaseContainer","BaseContainerDrawFrame");
  164.  
  165.     // Use the focuslib code to set up transforms and clipping
  166.     somSelf->DrawContents (ev, facet, invalidShape);
  167.     somSelf->DrawSelectionBorder (ev, facet, invalidShape);
  168. }
  169.  
  170.  
  171. // -------------------------------------------------------------------------
  172. // BaseContainer --> DrawThumbnail
  173. //
  174. //      Draws a static, scaled version of the current contents to the facet.
  175. //
  176. //      -> This method is a private method of BaseContainer
  177. // -------------------------------------------------------------------------
  178. SOM_Scope void  SOMLINK BaseContainerDrawThumbnail(BaseContainer *somSelf,
  179.                                             Environment *ev,
  180.                                             ODFacet* facet,
  181.                                             ODShape* invalidShape)
  182. {
  183.     BaseContainerData *somThis = BaseContainerGetData(somSelf);
  184.     BaseContainerMethodDebug("BaseContainer","BaseContainerDrawThumbnail");
  185.  
  186.     // Not yet implemented
  187.     somSelf->DrawIcon(ev, facet, invalidShape, _fThumbnailView);
  188. }
  189.  
  190.  
  191. // -------------------------------------------------------------------------
  192. // BaseContainer --> DrawIcon
  193. //
  194. //      Draws the icon corresponding to the given viewType on the facet.
  195. //
  196. //      -> This method is a private method of BaseContainer
  197. // -------------------------------------------------------------------------
  198. SOM_Scope void  SOMLINK BaseContainerDrawIcon(BaseContainer *somSelf,
  199.                                               Environment *ev,
  200.                                               ODFacet* facet,
  201.                                               ODShape* invalidShape,
  202.                                               ODTypeToken viewType)
  203. {
  204.     BaseContainerData *somThis = BaseContainerGetData(somSelf);
  205.     BaseContainerMethodDebug("BaseContainer","BaseContainerDrawIcon");
  206.  
  207.  
  208.     HIconView *hIcon;
  209.     short iconSize;
  210.  
  211.     if(viewType == _fSmallIconView)
  212.     {
  213.       hIcon = &_hSmallIcon;
  214.       iconSize = kODSmallIconSize;
  215.     }
  216.     else
  217.     {
  218.       hIcon = &_hLargeIcon;
  219.       iconSize = kODLargeIconSize;
  220.     }
  221.  
  222.     HDraw hDraw;
  223.     CFocus f(facet, invalidShape, &hDraw);     // Set up drawing environment
  224.  
  225.     // Create the icon if it does not exist.
  226.     if(*hIcon == kODNULL) somSelf->CreateIcon(ev, facet, invalidShape, viewType);
  227.  
  228. #if defined(_PLATFORM_OS2_)||defined(_PLATFORM_WIN32_)
  229.     ODRect iconODRect;
  230.     Rect iconRect;
  231.     TempODShape frameShape = facet->GetFrame(ev)->AcquireFrameShape(ev,kODNULL);
  232.     frameShape->GetBoundingBox(ev, &iconODRect);
  233.  
  234. #endif
  235. #ifdef _PLATFORM_OS2_
  236.     HAB hab = WinInitialize(0);
  237.     WinSetRect(hab,&iconRect, FixedToInt(iconODRect.left),
  238.                               FixedToInt(iconODRect.bottom),
  239.                               FixedToInt(iconODRect.right),
  240.                               FixedToInt(iconODRect.top));
  241.  
  242.     ODFixed xscale, yscale;
  243.     Get72DPIToScreenScale( _fSession, &xscale, &yscale);
  244.  
  245.     Point aPoints[4] = {{iconRect.xLeft,iconRect.yBottom},            // bottom-left of target
  246.                         {iconRect.xRight,iconRect.yTop},              // top-right of target
  247.                         {0,0},                                        // bottom-left of source
  248.                         {FixedToInt(ODFixedMultiply(xscale, IntToFixed(iconSize))), // top-right of source
  249.                          FixedToInt(ODFixedMultiply(yscale, IntToFixed(iconSize)))}};
  250.  
  251.     LONG lHits = GpiWCBitBlt(hDraw,
  252.                              *hIcon,
  253.                              4,
  254.                              aPoints,
  255.                              ROP_SRCCOPY,
  256.                              BBO_IGNORE);
  257.  
  258. #elif defined(_PLATFORM_WIN32_)
  259.     SetRect(&iconRect, FixedToInt(iconODRect.left),
  260.                        FixedToInt(iconODRect.top),
  261.                        FixedToInt(iconODRect.right),
  262.                        FixedToInt(iconODRect.bottom));
  263.  
  264.     // Color white the background to cover places where the icon is transparent
  265.  
  266.     // Create a solid brush
  267.     HBRUSH hbr = CreateSolidBrush (RGB(255,255,255));
  268.  
  269.     // Fill the rectangle with the brush
  270.     FillRect (hDraw, &iconRect, hbr);
  271.  
  272.     // Get rid of the brush
  273.     DeleteObject (hbr);
  274.  
  275.     BOOL success = DrawIconEx(hDraw,
  276.                               iconRect.left,
  277.                               iconRect.top,
  278.                               *hIcon,
  279.                               iconSize,
  280.                               iconSize,
  281.                               0,
  282.                               NULL,
  283.                               DI_NORMAL);
  284.  
  285. #elif defined(_PLATFORM_UNIX_)
  286.                                     
  287.     // Get the AIX Window canvas
  288.     ODAIXWindowCanvas *aixwincanvas =
  289.       (ODAIXWindowCanvas *)(facet->GetCanvas(ev)->GetPlatformCanvas(ev, kODAIX));
  290.  
  291.     // Get the canvas display
  292.     Display *display = aixwincanvas->GetDisplay(ev);
  293.  
  294.     // Get the canvas widget
  295.     Widget widget = aixwincanvas->GetWidget(ev);
  296.  
  297.     // Create the icon widget if it doesn't exist
  298.     Arg args[3];
  299.     if(!_iconWidget) {
  300.  
  301.        XtSetArg(args[0], XmNlabelType, XmPIXMAP);
  302.        XtSetArg(args[1], XmNlabelPixmap, *hIcon);
  303.        XtSetArg(args[2], XmNlabelInsensitivePixmap, *hIcon);
  304.  
  305.        // Create a label widget on which to display the pixmaps
  306.        _iconWidget = XmCreateLabel( widget, "BCIconWidget", args, 3);
  307.  
  308.        // Display the pixmap
  309.        XtManageChild(_iconWidget);
  310.  
  311.     } else {
  312.        // The widget exists already. Just assign the corresponding
  313.        // pixmap to it.
  314.        XtSetArg(args[0], XmNlabelPixmap, *hIcon);
  315.        XtSetArg(args[1], XmNlabelInsensitivePixmap, *hIcon);
  316.        XtSetValues(_iconWidget, args, 2);
  317.  
  318.     }
  319.  
  320. #endif
  321. }
  322.  
  323.  
  324. // -------------------------------------------------------------------------
  325. // BaseContainer --> CreateIcon
  326. //
  327. //      Creates the icon corresponding to the given viewType. Stores the 
  328. //      resulting icon handle in the corresponding part instance variable.
  329. //
  330. //      -> This method is a private method of BaseContainer
  331. // -------------------------------------------------------------------------
  332. SOM_Scope void  SOMLINK BaseContainerCreateIcon(BaseContainer *somSelf,
  333.                                                 Environment *ev,
  334.                                                 ODFacet* facet,
  335.                                                 ODShape* invalidShape,
  336.                                                 ODTypeToken viewType)
  337.  
  338. {
  339.     BaseContainerData *somThis = BaseContainerGetData(somSelf);
  340.     BaseContainerMethodDebug("BaseContainer","BaseContainerCreateIcon");
  341.  
  342. #if defined(_PLATFORM_OS2_) || defined(_PLATFORM_WIN32_)
  343.  
  344.     somSelf->LoadIconsFromModule(ev,
  345.                                  "iodbasec",
  346.                                  kODIcon);
  347. #else
  348.                                     
  349.     // Get the AIX Window canvas
  350.     ODAIXWindowCanvas *aixwincanvas =
  351.       (ODAIXWindowCanvas *)(facet->GetCanvas(ev)->GetPlatformCanvas(ev, kODAIX));
  352.  
  353.     // Get the canvas display
  354.     Display *display = aixwincanvas->GetDisplay(ev);
  355.  
  356.     // Get the screen
  357.     Screen *screen = _fSession->GetWindowState(ev)->GetScreen(ev);
  358.  
  359.     // Get the default colormap for the screen
  360.     Colormap map = XDefaultColormapOfScreen(screen);
  361.  
  362.     // Create pixel values for monochrome bitmap
  363.     XColor def, def2;
  364.     Pixel foreground, background;
  365.     Status stat = XAllocNamedColor(display, map, "white" , &def, &def2);
  366.     background = def.pixel;
  367.     stat = XAllocNamedColor(display, map, "black" , &def, &def2);
  368.     foreground = def.pixel;
  369.  
  370.  
  371.     // On AIX we may not create both icons at the same time.
  372.     // Create the bitmaps separately because they depend
  373.     // on the window attributes which are different
  374.     // for each viewtype.
  375.     if(viewType ==  _fSmallIconView)
  376.     {
  377.         _hSmallIcon = XmGetPixmap(screen,
  378.                                   "iodbasec.t.pm",
  379.                                   foreground,
  380.                                   background);
  381.     }
  382.     else
  383.     {
  384.        _hLargeIcon = XmGetPixmap(screen,
  385.                                  "iodbasec.m.pm",
  386.                                  foreground,
  387.                                  background);
  388.     }
  389.  
  390. #endif
  391. }
  392.  
  393.  
  394. // -------------------------------------------------------------------------
  395. // BaseContainer --> LoadIconsFromModule
  396. //
  397. //      Creates the small and large icons of the part by loading them from
  398. //      the resource module.
  399. //
  400. //      -> This method is a private method of BaseContainer
  401. // -------------------------------------------------------------------------
  402. SOM_Scope void  SOMLINK BaseContainerLoadIconsFromModule(BaseContainer *somSelf,
  403.                                                          Environment *ev,
  404.                                                          string moduleName,
  405.                                                          long iconID)
  406. {
  407.     BaseContainerData *somThis = BaseContainerGetData(somSelf);
  408.     BaseContainerMethodDebug("BaseContainer","BaseContainerLoadIconsFromModule");
  409.  
  410. #ifdef _PLATFORM_OS2_
  411.     CHAR errBuffer[CCHMAXPATH];
  412.     if(moduleName)
  413.     {
  414.       DosLoadModule(errBuffer,
  415.                     sizeof(errBuffer),
  416.                     moduleName,
  417.                     &_hResModule);
  418.     }
  419.  
  420.     HPOINTER hptr = WinLoadPointer(HWND_DESKTOP,
  421.                                    _hResModule,
  422.                                    iconID);
  423.  
  424.     POINTERINFO pi;
  425.     WinQueryPointerInfo( hptr, &pi );
  426.     _hLargeIcon = pi.hbmColor;
  427.     _hSmallIcon = pi.hbmMiniColor;
  428.  
  429. #elif defined(_PLATFORM_WIN32_)
  430.     if(moduleName)
  431.     {
  432.       _hResModule = LoadLibrary(moduleName);
  433.     }
  434.  
  435.     _hSmallIcon = LoadImage(_hResModule,
  436.                        MAKEINTRESOURCE(iconID),
  437.                        IMAGE_ICON,
  438.                        kODSmallIconSize,
  439.                        kODSmallIconSize,
  440.                        LR_DEFAULTCOLOR);
  441.     _hLargeIcon = LoadImage(_hResModule,
  442.                        MAKEINTRESOURCE(iconID),
  443.                        IMAGE_ICON,
  444.                        kODLargeIconSize,
  445.                        kODLargeIconSize,
  446.                        LR_DEFAULTCOLOR);
  447. #endif
  448.  
  449. }
  450.  
  451.  
  452. // -------------------------------------------------------------------------
  453. // BaseContainer --> FreeResModule
  454. //
  455. //      Releases the resource module, if its loaded.
  456. //
  457. //      -> This method is a private method of BaseContainer
  458. // -------------------------------------------------------------------------
  459. SOM_Scope void  SOMLINK BaseContainerFreeResModule(BaseContainer *somSelf,
  460.                                                    Environment *ev)
  461. {
  462.     BaseContainerData *somThis = BaseContainerGetData(somSelf);
  463.     BaseContainerMethodDebug("BaseContainer","BaseContainerFreeResModule");
  464.  
  465.     if(_hResModule)
  466.     {
  467. #ifdef _PLATFORM_OS2_
  468.       DosFreeModule(_hResModule);
  469. #elif defined(_PLATFORM_WIN32_)
  470.       FreeLibrary(_hResModule);
  471. #endif
  472.     }
  473. }
  474.  
  475.