home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / languages / tcl / tk3.3b1 / tkGeometry.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-06-16  |  5.2 KB  |  171 lines

  1. /* 
  2.  * tkGeometry.c --
  3.  *
  4.  *    This file contains code generic Tk code for geometry
  5.  *    management, plus code to manage the geometry of top-level
  6.  *    windows (by reflecting information up to the window
  7.  *    manager).
  8.  *
  9.  * Copyright (c) 1990-1993 The Regents of the University of California.
  10.  * All rights reserved.
  11.  *
  12.  * Permission is hereby granted, without written agreement and without
  13.  * license or royalty fees, to use, copy, modify, and distribute this
  14.  * software and its documentation for any purpose, provided that the
  15.  * above copyright notice and the following two paragraphs appear in
  16.  * all copies of this software.
  17.  * 
  18.  * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
  19.  * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
  20.  * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
  21.  * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  22.  *
  23.  * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
  24.  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
  25.  * AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
  26.  * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
  27.  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
  28.  */
  29.  
  30. #ifndef lint
  31. static char rcsid[] = "$Header: /user6/ouster/wish/RCS/tkGeometry.c,v 1.19 93/06/16 17:15:00 ouster Exp $ SPRITE (Berkeley)";
  32. #endif
  33.  
  34. #include "tkConfig.h"
  35. #include "tkInt.h"
  36.  
  37. /*
  38.  *--------------------------------------------------------------
  39.  *
  40.  * Tk_ManageGeometry --
  41.  *
  42.  *    Arrange for a particular procedure to handle geometry
  43.  *    requests for a given window.
  44.  *
  45.  * Results:
  46.  *    None.
  47.  *
  48.  * Side effects:
  49.  *    Proc becomes the new geometry manager for tkwin, replacing
  50.  *    any previous geometry manager.  In the future, whenever
  51.  *    Tk_GeometryRequest is called for tkwin, proc will be
  52.  *    invoked to handle the request.  Proc should have the
  53.  *    following structure:
  54.  *
  55.  *    void
  56.  *    proc(clientData, tkwin)
  57.  *    {
  58.  *    }
  59.  *
  60.  *    The clientData argument will be the same as the clientData
  61.  *    argument to this procedure, and the tkwin arguments will
  62.  *    be the same as the corresponding argument to
  63.  *    Tk_GeometryRequest.  Information about the desired
  64.  *    geometry for tkwin is avilable to proc using macros such
  65.  *    as Tk_ReqWidth.  Proc should do the best it can to meet
  66.  *    the request within the constraints of its geometry-management
  67.  *    algorithm, but it is not obligated to meet the request.
  68.  *
  69.  *--------------------------------------------------------------
  70.  */
  71.  
  72. void
  73. Tk_ManageGeometry(tkwin, proc, clientData)
  74.     Tk_Window tkwin;        /* Window whose geometry is to
  75.                  * be managed by proc.  */
  76.     Tk_GeometryProc *proc;    /* Procedure to manage geometry.
  77.                  * NULL means make tkwin unmanaged. */
  78.     ClientData clientData;    /* Arbitrary one-word argument to
  79.                  * pass to proc. */
  80. {
  81.     register TkWindow *winPtr = (TkWindow *) tkwin;
  82.  
  83.     winPtr->geomProc = proc;
  84.     winPtr->geomData = clientData;
  85. }
  86.  
  87. /*
  88.  *--------------------------------------------------------------
  89.  *
  90.  * Tk_GeometryRequest --
  91.  *
  92.  *    This procedure is invoked by widget code to indicate
  93.  *    its preferences about the size of a window it manages.
  94.  *    In general, widget code should call this procedure
  95.  *    rather than Tk_ResizeWindow.
  96.  *
  97.  * Results:
  98.  *    None.
  99.  *
  100.  * Side effects:
  101.  *    The geometry manager for tkwin (if any) is invoked to
  102.  *    handle the request.  If possible, it will reconfigure
  103.  *    tkwin and/or other windows to satisfy the request.  The
  104.  *    caller gets no indication of success or failure, but it
  105.  *    will get X events if the window size was actually
  106.  *    changed.
  107.  *
  108.  *--------------------------------------------------------------
  109.  */
  110.  
  111. void
  112. Tk_GeometryRequest(tkwin, reqWidth, reqHeight)
  113.     Tk_Window tkwin;        /* Window that geometry information
  114.                  * pertains to. */
  115.     int reqWidth, reqHeight;    /* Minimum desired dimensions for
  116.                  * window, in pixels. */
  117. {
  118.     register TkWindow *winPtr = (TkWindow *) tkwin;
  119.  
  120.     if ((reqWidth == winPtr->reqWidth) && (reqHeight == winPtr->reqHeight)) {
  121.     return;
  122.     }
  123.     winPtr->reqWidth = reqWidth;
  124.     winPtr->reqHeight = reqHeight;
  125.     if (winPtr->geomProc != NULL) {
  126.     (*winPtr->geomProc)(winPtr->geomData, tkwin);
  127.     }
  128. }
  129.  
  130. /*
  131.  *----------------------------------------------------------------------
  132.  *
  133.  * Tk_SetInternalBorder --
  134.  *
  135.  *    Notify relevant geometry managers that a window has an internal
  136.  *    border of a given width and that child windows should not be
  137.  *    placed on that border.
  138.  *
  139.  * Results:
  140.  *    None.
  141.  *
  142.  * Side effects:
  143.  *    The border width is recorded for the window, and all geometry
  144.  *    managers of all children are notified so that can re-layout, if
  145.  *    necessary.
  146.  *
  147.  *----------------------------------------------------------------------
  148.  */
  149.  
  150. void
  151. Tk_SetInternalBorder(tkwin, width)
  152.     Tk_Window tkwin;        /* Window that will have internal border. */
  153.     int width;            /* Width of internal border, in pixels. */
  154. {
  155.     register TkWindow *winPtr = (TkWindow *) tkwin;
  156.  
  157.     if (width == winPtr->internalBorderWidth) {
  158.     return;
  159.     }
  160.     if (width < 0) {
  161.     width = 0;
  162.     }
  163.     winPtr->internalBorderWidth = width;
  164.     for (winPtr = winPtr->childList; winPtr != NULL;
  165.         winPtr = winPtr->nextPtr) {
  166.     if (winPtr->geomProc != NULL) {
  167.         (*winPtr->geomProc)(winPtr->geomData, (Tk_Window) winPtr);
  168.     }
  169.     }
  170. }
  171.