home *** CD-ROM | disk | FTP | other *** search
/ cyber.net 2 / cybernet2.ISO / qtw111 / pviewer / pictkids.c < prev    next >
C/C++ Source or Header  |  1994-01-11  |  49KB  |  1,314 lines

  1.  
  2. // ---------------------------------------------------------------------
  3. //
  4. // PictKids.c - Picture Viewer - QuickTime for Windows
  5. //
  6. //              Version 1.0
  7. //
  8. //              (c) 1988-1992 Apple Computer, Inc. All Rights Reserved.
  9. //
  10. // ---------------------------------------------------------------------
  11.  
  12.  
  13. // Includes
  14. // --------
  15. #define NOMINMAX
  16. #include <Windows.H> // Required by Windows
  17. #include <stdlib.h>  // Required for abs function
  18.  
  19. #include <qtole.h>  // Interface to qtole dll
  20. #include <qtw.h>    // Interface to QuickTime
  21. #include "common.h" // Interface to common.c
  22.  
  23. #include "viewer.h"  // Interface to *.c files
  24. #include "viewer.hr" // Defines used in *.rc files
  25. #include "picture.h" // Interface to picture window
  26.                      // child window processing
  27.  
  28.  
  29. // Constants
  30. // -----------------------
  31. #define BANNER_TEXT_HEIGHT      9 // Banner text height in points
  32. #define TEXT_EXTRA_SPACING      1 // Extra spacing in number text
  33.  
  34. // Message-Persistent Data
  35. // -----------------------
  36. static struct // Hungarian notation: g
  37.   {WORD        wScrollBarWidth;     // Vertical scroll bar width
  38.    WORD        wScrollBarHeight;    // Horizontal scroll bar height
  39.    WORD        wBannerBarHeight;    // Banner bar height
  40.    WORD        wZoomWndWidth;       // Width of zoom scroll bar window
  41.    WORD        wMinWndHeight;       // Minimum height of window
  42.    HBITMAP     hbmpGrowBox;         // Grow box bitmap
  43.    BOOL        bLimitGrowBoxResize; // Flag to turn on max resize limits
  44.                                     // using grow box
  45.    POINT       ptMaxGrowBoxResize;  // Max size for grow box resizing
  46.  
  47.    RECT        rcResizeRect;   // Maximized wnd grow box resize rect
  48.    POINT       ptCursorOffset; // Offset of cursor from edge of window
  49.                                // used during maximized wnd grow box resize
  50.   } g;
  51.  
  52.  
  53. // Exported callback function
  54. // ----------------------------
  55. LONG __export CALLBACK PictureBannerWndProc  (HWND, UINT, WPARAM, LPARAM);
  56.  
  57. // Internal Function Declarations
  58. // ------------------------------
  59. static VOID    NEAR UpdateScrollingParms    (HWND, NPPICTUREDATA, LPRECT);
  60. static HBITMAP NEAR GetGrowBoxBitmap        (HDC, NPPICTUREDATA);
  61. static VOID    NEAR DrawTheFrameRect        (LPRECT);
  62.  
  63.  
  64. // Function: ResizeKids - Resizes the child windows whenever the picture
  65. //                        window is resized
  66. // --------------------------------------------------------------------
  67. // Parameters: HWND    hwndPicture       Handle of picture window
  68. //             WORD    wClientWidth      Width of client rect
  69. //             WORD    wClientHeight     Height of client rect
  70. //
  71. // Returns:    0L
  72. // --------------------------------------------------------------------
  73. VOID FAR ResizeKids
  74.     ( HWND hwndPicture, WORD wClientWidth, WORD wClientHeight )
  75.  
  76. {
  77.     NPPICTUREDATA   pPictureData; // -> picture data struct
  78.     RECT            rcPicture;    // Picture rect in picture coordinates
  79.     HDWP            hdwp;         // Handle to defer wnd pos struct
  80.     int             xBrdr;        // Width of non resizable border
  81.     int             yBrdr;        // Height of non resizable border
  82.  
  83.     // Note: All the extra terms involving xBrdr and yBrdr are used to make
  84.     // the control boundaries match up correctly without heavy lines 
  85.     // appearing between the controls
  86.  
  87.     xBrdr = GetSystemMetrics( SM_CXBORDER );
  88.     yBrdr = GetSystemMetrics( SM_CYBORDER );
  89.  
  90.     if( !(pPictureData =
  91.         (NPPICTUREDATA) GetWindowWord( hwndPicture, 0 ))) {
  92.         CommonTellUser( ViewerQueryResources(),
  93.             VIEWER_STRING_NOPICDATA, VIEWER_STRING_CAPTION, MB_OK );
  94.         return;
  95.     }
  96.  
  97.     if( ( hdwp = BeginDeferWindowPos( 5 )) &&
  98.         // Zoom window. This control has a constant size
  99.         ( hdwp = DeferWindowPos( hdwp, pPictureData->zsZoomScroll.hwnd,
  100.         NULL,
  101.         -xBrdr,
  102.         wClientHeight - g.wScrollBarHeight + yBrdr,
  103.         g.wZoomWndWidth,
  104.         g.wScrollBarHeight, 
  105.         SWP_NOZORDER )) &&
  106.         // Banner bar. This control has a constant height
  107.         ( hdwp = DeferWindowPos( hdwp, pPictureData->hwndBanner, 
  108.         NULL,
  109.         0,
  110.         0,
  111.         wClientWidth,
  112.         g.wBannerBarHeight,
  113.         SWP_NOZORDER )) && 
  114.         // Vertical scroll bar. This control has a constant width
  115.         ( hdwp = DeferWindowPos( hdwp, pPictureData->spmsVScroll.hwnd,
  116.         NULL, 
  117.         wClientWidth - g.wScrollBarWidth + xBrdr,
  118.         g.wBannerBarHeight - yBrdr,
  119.         g.wScrollBarWidth,
  120.         wClientHeight - g.wScrollBarHeight
  121.         - g.wBannerBarHeight + 3 * yBrdr,
  122.         SWP_NOZORDER )) && 
  123.         // Horizontal scroll bar. This control has a constant height
  124.         ( hdwp = DeferWindowPos( hdwp, pPictureData->spmsHScroll.hwnd,
  125.         NULL, 
  126.         g.wZoomWndWidth - 2 * xBrdr,
  127.         wClientHeight - g.wScrollBarHeight + yBrdr,
  128.         wClientWidth - g.wZoomWndWidth - 
  129.         g.wScrollBarWidth + 4 * xBrdr,
  130.         g.wScrollBarHeight,
  131.         SWP_NOZORDER ))) {
  132.         EndDeferWindowPos( hdwp );
  133.     } 
  134.     else { // Zoom window. This control has a constant size
  135.         MoveWindow( pPictureData->zsZoomScroll.hwnd,
  136.             -xBrdr, wClientHeight - g.wScrollBarHeight + yBrdr,
  137.             g.wZoomWndWidth, g.wScrollBarHeight, TRUE );
  138.  
  139.         // Banner bar. This control has a constant height
  140.         MoveWindow( pPictureData->hwndBanner, 0, 0,
  141.             wClientWidth, g.wBannerBarHeight, TRUE );
  142.  
  143.         // Vertical scroll bar. This control has a constant width
  144.         MoveWindow( pPictureData->spmsVScroll.hwnd,
  145.             wClientWidth - g.wScrollBarWidth + xBrdr,
  146.             g.wBannerBarHeight - yBrdr, g.wScrollBarWidth,
  147.             wClientHeight - g.wScrollBarHeight -
  148.             g.wBannerBarHeight + 3 * yBrdr, TRUE );
  149.  
  150.         // Horizontal scroll bar. This control has a constant height
  151.         MoveWindow( pPictureData->spmsHScroll.hwnd,
  152.             g.wZoomWndWidth - 2 * xBrdr,
  153.             wClientHeight - g.wScrollBarHeight + yBrdr,
  154.             wClientWidth - g.wZoomWndWidth -
  155.             g.wScrollBarWidth + 4 * xBrdr,
  156.             g.wScrollBarHeight, TRUE );
  157.     }
  158.  
  159.     pPictureData->rcGrowBox.left = wClientWidth  - 
  160.         g.wScrollBarWidth + 2 * xBrdr;
  161.     pPictureData->rcGrowBox.top  = wClientHeight -
  162.         g.wScrollBarHeight + 2 * yBrdr;
  163.     pPictureData->rcGrowBox.right  = wClientWidth;
  164.     pPictureData->rcGrowBox.bottom = wClientHeight;
  165.  
  166.     rcPicture.left   = rcPicture.top = 0;
  167.     rcPicture.right  = wClientWidth;
  168.     rcPicture.bottom = wClientHeight;
  169.     PictureRectFromClient( &rcPicture );
  170.  
  171.     UpdateScrollingParms( hwndPicture, pPictureData, &rcPicture );
  172.  
  173.     // Force these to get painted now to avoid long delay while
  174.     // waiting for the picture to be painted. This improves the 
  175.     // appearance of the window during resizing
  176.     UpdateWindow( pPictureData->zsZoomScroll.hwnd );
  177.     UpdateWindow( pPictureData->hwndBanner );
  178.     UpdateWindow( pPictureData->spmsHScroll.hwnd );
  179.     UpdateWindow( pPictureData->spmsVScroll.hwnd );
  180.  
  181.     return;
  182. }
  183.  
  184.  
  185. // Function: CreateViewerKids - Creates the child windows for the picture
  186. //                              window
  187. // --------------------------------------------------------------------
  188. // Parameters: HWND           hwndPicture     Handle of picture window
  189. //             NPPICTUREDATA  pPictureData    -> to picture data struct
  190. //
  191. // Returns:    LONG           0l if OK
  192. // --------------------------------------------------------------------
  193. LONG FAR CreateViewerKids( HWND hwndPicture, NPPICTUREDATA pPictureData )
  194.  
  195. {
  196.     WORD    wIDError; // Resource error string id
  197.  
  198.     g.wScrollBarWidth  = (WORD) GetSystemMetrics( SM_CXVSCROLL );
  199.     g.wScrollBarHeight = (WORD) GetSystemMetrics( SM_CYHSCROLL );
  200.     g.wBannerBarHeight = (WORD) GetSystemMetrics( SM_CYMENU );
  201.     g.wMinWndHeight    = (WORD) ( GetSystemMetrics( SM_CYCAPTION ) +
  202.         g.wBannerBarHeight + g.wScrollBarHeight + 
  203.         3 * GetSystemMetrics( SM_CYVSCROLL ));
  204.  
  205.  
  206.     wIDError = VIEWER