home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / tk42r2s.zip / tk4.2 / os2 / tkOS2Init.c < prev    next >
C/C++ Source or Header  |  1999-07-27  |  7KB  |  227 lines

  1. /* 
  2.  * tkOS2Init.c --
  3.  *
  4.  *    This file contains OS/2-specific interpreter initialization
  5.  *    functions.
  6.  *
  7.  * Copyright (c) 1996-1998 Illya Vaes
  8.  * Copyright (c) 1995 Sun Microsystems, Inc.
  9.  *
  10.  * See the file "license.terms" for information on usage and redistribution
  11.  * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
  12.  */
  13.  
  14.  
  15. #include "tkOS2Int.h"
  16.  
  17. /*
  18.  * Global variables necessary in modules in the DLL
  19.  */
  20. HAB        hab;            /* Anchor block (instance handle) */
  21. HMQ        hmq;            /* Handle to message queue */
  22. LONG        aDevCaps[CAPS_DEVICE_POLYSET_POINTS];  /* Device Capabilities */
  23. LONG        nextLogicalFont = 1;    /* First free logical font ID */
  24. PFNWP        oldFrameProc = NULL;    /* subclassed frame procedure */
  25. LONG        xScreen;        /* System Value Screen width */
  26. LONG        yScreen;        /* System Value Screen height */
  27. LONG        titleBar;        /* System Value Title Bar */
  28. LONG        xBorder;        /* System Value X nominal border */
  29. LONG        yBorder;        /* System Value Y nominal border */
  30. LONG        xSizeBorder;        /* System Value X Sizing border */
  31. LONG        ySizeBorder;        /* System Value Y Sizing border */
  32. LONG        xDlgBorder;        /* System Value X dialog-frame border */
  33. LONG        yDlgBorder;        /* System Value Y dialog-frame border */
  34. HDC        hScreenDC;        /* Device Context for screen */
  35. HPS        globalPS;        /* Global PS for Fonts (Gpi*Char*) */
  36. HBITMAP        globalBitmap;        /* Bitmap for global PS */
  37. TkOS2Font    logfonts[255];        /* List of logical fonts */
  38. LONG        nextColor;        /* Next free index in color table */
  39. #ifdef IGNOREPMRES
  40.     LONG        overrideResolution= 72; /* If IGNOREPMRES is defined */
  41. #endif
  42. LONG        rc;            /* For checking return values */
  43.  
  44. /*
  45.  * The following string is the startup script executed in new
  46.  * interpreters.  It looks on disk in several different directories
  47.  * for a script "tk.tcl" that is compatible with this version
  48.  * of Tk.  The tk.tcl script does all of the real work of
  49.  * initialization.
  50.  */
  51. static char *initScript =
  52. "proc init {} {\n\
  53.     global tk_library tk_version tk_patchLevel env\n\
  54.     rename init {}\n\
  55.     set dirs {}\n\
  56.     if [info exists env(TK_LIBRARY)] {\n\
  57.         lappend dirs $env(TK_LIBRARY)\n\
  58.     }\n\
  59.     lappend dirs $tk_library\n\
  60.     lappend dirs [file dirname [info library]]/lib/tk$tk_version\n\
  61.     lappend dirs [file dirname [file dirname [info nameofexecutable]]]/lib/tk$tk_version\n\
  62.     if [string match {*[ab]*} $tk_patchLevel] {\n\
  63.         set lib tk$tk_patchLevel\n\
  64.     } else {\n\
  65.         set lib tk$tk_version\n\
  66.     }\n\
  67.     lappend dirs [file dirname [file dirname [pwd]]]/$lib/library\n\
  68.     lappend dirs [file dirname [pwd]]/library\n\
  69.     foreach i $dirs {\n\
  70.         set tk_library $i\n\
  71.         if ![catch {uplevel #0 source [list $i/tk.tcl]}] {\n\
  72.             return\n\
  73.         }\n\
  74.     }\n\
  75.     set msg \"Can't find a usable tk.tcl in the following directories: \n\"\n\
  76.     append msg \"    $dirs\n\"\n\
  77.     append msg \"This probably means that Tk wasn't installed properly.\n\"\n\
  78.     error $msg\n\
  79. }\n\
  80. init";
  81.  
  82. /*
  83.  *----------------------------------------------------------------------
  84.  *
  85.  * TkPlatformInit --
  86.  *
  87.  *    Performs OS/2-specific interpreter initialization related to the
  88.  *      tk_library variable.
  89.  *
  90.  * Results:
  91.  *    A standard Tcl completion code (TCL_OK or TCL_ERROR).  Also
  92.  *      leaves information in interp->result.
  93.  *
  94.  * Side effects:
  95.  *    Sets "tk_library" Tcl variable, runs "tk.tcl" script.
  96.  *
  97.  *----------------------------------------------------------------------
  98.  */
  99.  
  100. int
  101. TkPlatformInit(interp)
  102.     Tcl_Interp *interp;
  103. {
  104.     char *libDir;
  105.  
  106.     /*
  107.      * If the path doesn't exist, look for the library relative to the
  108.      * tk.dll library.
  109.      */
  110.  
  111.     libDir = Tcl_GetVar(interp, "tk_library", TCL_GLOBAL_ONLY);
  112.     if (libDir == NULL) {
  113.         Tcl_SetVar(interp, "tk_library", ".", TCL_GLOBAL_ONLY);
  114.     }
  115.  
  116.     return Tcl_Eval(interp, initScript);
  117. }
  118.  
  119. /*
  120.  *----------------------------------------------------------------------
  121.  *
  122.  * TkOS2InitPM --
  123.  *
  124.  *    Performs OS/2 Presentation Manager intialisation.
  125.  *
  126.  * Results:
  127.  *    None.
  128.  *
  129.  * Side effects:
  130.  *    Fills the global variables hab and hmq.
  131.  *
  132.  *----------------------------------------------------------------------
  133.  */
  134.  
  135. void
  136. TkOS2InitPM (void)
  137. {
  138.     BOOL rc;
  139.     HDC hScreenDC;
  140.     LONG lStart, lCount;
  141.     DEVOPENSTRUC doStruc= {0L, (PSZ)"DISPLAY", NULL, 0L, 0L, 0L, 0L, 0L, 0L};
  142.     SIZEL sizel = {0,0};
  143.     BITMAPINFOHEADER2 bmpInfo;
  144. #ifdef IGNOREPMRES
  145.     char *tkPmPixRes;
  146. #endif
  147.  
  148.     /* Initialize PM */
  149.     hab = WinInitialize (0);
  150.  
  151.     /* Create message queue, increased size from 10 */
  152.     hmq= WinCreateMsgQueue (hab, 64);
  153.  
  154.     /* Determine system values */
  155.     xScreen = WinQuerySysValue(HWND_DESKTOP, SV_CXSCREEN);
  156.     yScreen = WinQuerySysValue(HWND_DESKTOP, SV_CYSCREEN);
  157.     titleBar = WinQuerySysValue(HWND_DESKTOP, SV_CYTITLEBAR);
  158.     xBorder = WinQuerySysValue(HWND_DESKTOP, SV_CXBORDER);
  159.     yBorder = WinQuerySysValue(HWND_DESKTOP, SV_CYBORDER);
  160.     xSizeBorder = WinQuerySysValue(HWND_DESKTOP, SV_CXSIZEBORDER);
  161.     ySizeBorder = WinQuerySysValue(HWND_DESKTOP, SV_CYSIZEBORDER);
  162.     xDlgBorder = WinQuerySysValue(HWND_DESKTOP, SV_CXDLGFRAME);
  163.     yDlgBorder = WinQuerySysValue(HWND_DESKTOP, SV_CYDLGFRAME);
  164.  
  165.     /* Get device characteristics from PM */
  166.     hScreenDC= DevOpenDC(hab, OD_MEMORY, (PSZ)"*", 0, (PDEVOPENDATA)&doStruc,
  167.                          NULLHANDLE);
  168.     lStart= CAPS_FAMILY; lCount= CAPS_DEVICE_POLYSET_POINTS;
  169.     rc= DevQueryCaps (hScreenDC, lStart, lCount, aDevCaps);
  170. #ifdef IGNOREPMRES
  171.     s = getenv("TK_PM_PIXRES");
  172.     if (s) {
  173.         overrideResolution = atol(s);
  174.     }
  175. #endif
  176.     globalPS = GpiCreatePS(hab, hScreenDC, &sizel,
  177.                            PU_PELS | GPIT_MICRO | GPIA_ASSOC);
  178.  
  179.     if (globalPS == GPI_ERROR) {
  180.         return;
  181.     }
  182.     GpiSetCharMode(globalPS, CM_MODE2);
  183.     bmpInfo.cbFix = 16L;
  184.     bmpInfo.cx = xScreen;
  185.     bmpInfo.cy = yScreen;
  186.     bmpInfo.cPlanes = 1;
  187.     bmpInfo.cBitCount = aDevCaps[CAPS_COLOR_BITCOUNT];
  188.     globalBitmap = GpiCreateBitmap(globalPS, &bmpInfo, 0L, NULL, NULL);
  189.     rc = GpiSetBitmap(globalPS, globalBitmap);
  190.     /* Determine color table if no palette support but color table support */
  191.     if (!(aDevCaps[CAPS_ADDITIONAL_GRAPHICS] & CAPS_PALETTE_MANAGER) &&
  192.         aDevCaps[CAPS_COLOR_TABLE_SUPPORT]) {
  193.         LONG aClrData[4];
  194.  
  195.         nextColor = 16;    /* Assume VGA color table */
  196.         rc = GpiQueryColorData(globalPS, 4, aClrData);
  197.         nextColor = aClrData[QCD_LCT_HIINDEX] + 1;
  198.     }
  199. }
  200.  
  201. /*
  202.  *----------------------------------------------------------------------
  203.  *
  204.  * TkOS2ExitPM --
  205.  *
  206.  *    Performs OS/2 Presentation Manager sign-off routines.
  207.  *
  208.  * Results:
  209.  *    None.
  210.  *
  211.  * Side effects:
  212.  *    Resets global variables hab and hmq.
  213.  *
  214.  *----------------------------------------------------------------------
  215.  */
  216.  
  217. void
  218. TkOS2ExitPM (void)
  219. {
  220.     GpiSetBitmap(globalPS, NULLHANDLE);
  221.     GpiDestroyPS(globalPS);
  222.     DevCloseDC(hScreenDC);
  223.     WinDestroyMsgQueue(hmq);
  224.     WinTerminate(hab);
  225.     hmq= hab= 0;
  226. }
  227.