home *** CD-ROM | disk | FTP | other *** search
/ ftp.wwiv.com / ftp.wwiv.com.zip / ftp.wwiv.com / pub / MISC / LSW270SR.ZIP / widget / lswidget.c next >
Text File  |  2004-04-11  |  8KB  |  241 lines

  1. /*
  2.  *      Copyright (C) 1997-2004 Andrei Los.
  3.  *    Based on a sample XWorkplace widget by Ulrich Möller
  4.  *      This file is part of the lSwitcher source package.
  5.  *      lSwitcher is free software; you can redistribute it and/or modify
  6.  *      it under the terms of the GNU General Public License as published
  7.  *      by the Free Software Foundation, in version 2 as it comes in the
  8.  *      "COPYING" file of the lSwitcher main distribution.
  9.  *      This program is distributed in the hope that it will be useful,
  10.  *      but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.  *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.  *      GNU General Public License for more details.
  13.  */
  14.  
  15. /*
  16.  *      Any XCenter widget plugin DLL must export the
  17.  *      following procedures by ordinal:
  18.  *
  19.  *      -- Ordinal 1 (WgtInitModule): this must
  20.  *         return the widgets which this DLL provides.
  21.  *
  22.  *      -- Ordinal 2 (WgtUnInitModule): this must
  23.  *         clean up global DLL data.
  24.  *
  25.  *      Unless you start your own threads in your widget,
  26.  *      you can safely compile the widget with the VAC
  27.  *      subsystem libraries to reduce the DLL's size.
  28.  *      You can also import functions from XFLDR.DLL
  29.  *      to avoid code duplication.
  30.  *
  31.  *      This is all new with V0.9.7.
  32.  *
  33.  *@@added V0.9.7 (2000-12-31) [umoeller]
  34.  *@@header "shared\center.h"
  35.  */
  36.  
  37. #include <string.h>
  38. #include <stdlib.h>
  39.  
  40. #include "lswitch.h"
  41. #include "common.h"
  42. #include "taskbar.h"
  43. #include "settings.h"
  44. #include "prmdlg.h"
  45.  
  46. // XWorkplace implementation headers
  47. #include "center.h"              // public XCenter interfaces
  48.  
  49.  
  50. VOID EXPENTRY lswShowSettings(PWIDGETSETTINGSDLGDATA pData);
  51.  
  52. static XCENTERWIDGETCLASS G_WidgetClasses[] = {
  53.  LSWTASKBARCLASS,     // PM window class name
  54.   0,                          // additional flag, not used here
  55.   "lswWidget",                // internal widget class name
  56.   "lSwitcher",                // widget class name displayed to user
  57.   WGTF_UNIQUEGLOBAL,      // widget class flags
  58.   lswShowSettings
  59. };
  60.  
  61.  
  62. //global variable used by lSwitcher code
  63. //the widget DLL module handle
  64. HMODULE hmodWidgetDll;
  65.  
  66.  
  67. /* ******************************************************************
  68.  *
  69.  *   Callbacks stored in XCENTERWIDGETCLASS
  70.  *
  71.  ********************************************************************/
  72.  
  73. /*
  74.  *@@ WwgtShowSettingsDlg:
  75.  *      this displays the winlist widget's settings
  76.  *      dialog.
  77.  *
  78.  *      This procedure's address is stored in
  79.  *      XCENTERWIDGET so that the XCenter knows that
  80.  *      we can do this.
  81.  *
  82.  *      When calling this function, the XCenter expects
  83.  *      it to display a modal dialog and not return
  84.  *      until the dialog is destroyed. While the dialog
  85.  *      is displaying, it would be nice to have the
  86.  *      widget dynamically update itself.
  87.  */
  88.  
  89. VOID EXPENTRY lswShowSettings(PWIDGETSETTINGSDLGDATA pData)
  90. { LSWDATA *plswData;
  91.  
  92. /*    HWND hwnd = WinLoadDlg(HWND_DESKTOP,         // parent
  93.                            pData->hwndOwner,
  94.                            fnwpSettingsDlg,
  95.                            pcmnQueryNLSModuleHandle(FALSE),
  96.                            ID_CRD_WINLISTWGT_SETTINGS,
  97.                            // pass original setup string with WM_INITDLG
  98.                            (PVOID)pData);
  99.     if (hwnd) {
  100.         pcmnSetControlsFont(hwnd,1, 10000);
  101.         WinProcessDlg(hwnd);
  102.         WinDestroyWindow(hwnd);
  103.     }*/
  104.   if (DosGetNamedSharedMem((PVOID*)&plswData,SHAREMEM_NAME,PAG_READ | PAG_WRITE)==0 && plswData!=NULL) {
  105.     WinDlgBox(HWND_DESKTOP, HWND_DESKTOP, ParmDlgProc,
  106.               plswData->hmodRes, DLG_PARAMS, plswData);
  107.     DosFreeMem(plswData);
  108.   }
  109. }
  110.  
  111. /* ******************************************************************
  112.  *
  113.  *   Exported procedures
  114.  *
  115.  ********************************************************************/
  116.  
  117. /*
  118.  *@@ WgtInitModule:
  119.  *      required export with ordinal 1, which must tell
  120.  *      the XCenter how many widgets this DLL provides,
  121.  *      and give the XCenter an array of XCENTERWIDGETCLASS
  122.  *      structures describing the widgets.
  123.  *
  124.  *      With this call, you are given the module handle of
  125.  *      XFLDR.DLL. For convenience, you may resolve imports
  126.  *      for some useful functions which are exported thru
  127.  *      src\shared\xwp.def. See the code below.
  128.  *
  129.  *      This function must also register the PM window classes
  130.  *      which are specified in the XCENTERWIDGETCLASS array
  131.  *      entries. For this, you are given a HAB which you
  132.  *      should pass to WinRegisterClass. For the window
  133.  *      class style (4th param to WinRegisterClass),
  134.  *      you should specify
  135.  *
  136.  +          CS_PARENTCLIP | CS_SIZEREDRAW | CS_SYNCPAINT
  137.  *
  138.  *      Your widget window _will_ be resized, even if you're
  139.  *      not planning it to be.
  140.  *
  141.  *      This function only gets called _once_ when the widget
  142.  *      DLL has been successfully loaded by the XCenter. If
  143.  *      there are several instances of a widget running (in
  144.  *      the same or in several XCenters), this function does
  145.  *      not get called again. However, since the XCenter unloads
  146.  *      the widget DLLs again if they are no longer referenced
  147.  *      by any XCenter, this might get called again when the
  148.  *      DLL is re-loaded.
  149.  *
  150.  *      There will ever be only one load occurence of the DLL.
  151.  *      The XCenter manages sharing the DLL between several
  152.  *      XCenters. As a result, it doesn't matter if the DLL
  153.  *      has INITINSTANCE etc. set or not.
  154.  *
  155.  *      If this returns 0, this is considered an error, and the
  156.  *      DLL will be unloaded again immediately.
  157.  *
  158.  *      If this returns any value > 0, *ppaClasses must be
  159.  *      set to a static array (best placed in the DLL's
  160.  *      global data) of XCENTERWIDGETCLASS structures,
  161.  *      which must have as many entries as the return value.
  162.  */
  163.  
  164. ULONG EXPENTRY WgtInitModule(HAB hab,         // XCenter's anchor block
  165.                              HMODULE hmodPlugin, // module handle of the widget DLL
  166.                              HMODULE hmodXFLDR,    // XFLDR.DLL module handle
  167.                              PXCENTERWIDGETCLASS *ppaClasses,
  168.                              PSZ pszErrorMsg)  // if 0 is returned, 500 bytes of error msg
  169. { PVOID pData;
  170.   LONG lrc;
  171.  
  172.   if (queryAppInstance()) {
  173.     strcpy(pszErrorMsg, "lSwitcher is already loaded.");
  174.     return 0;
  175.   }
  176.  
  177.   hmodWidgetDll = hmodPlugin;
  178.   lrc = SwitcherInit(hab, 0, pszErrorMsg, 500, &pData, 1);
  179.  
  180.   if (lrc > 0) return 0;
  181.  
  182.   if (!WinRegisterClass(hab,LSWTASKBARCLASS,TaskBarWndProc,
  183.       CS_PARENTCLIP | CS_SIZEREDRAW | CS_SYNCPAINT | CS_CLIPCHILDREN,sizeof(PXCENTERWIDGET))) {
  184.     strcpy(pszErrorMsg,"WinRegisterClass(lswTaskBarClass)");
  185.     return 0;
  186.   }
  187.  
  188.   *ppaClasses = G_WidgetClasses;
  189. // return no. of classes in this DLL (one here):
  190.   return sizeof(G_WidgetClasses) / sizeof(G_WidgetClasses[0]);
  191. }
  192.  
  193. /*
  194.  *@@ WgtUnInitModule:
  195.  *      optional export with ordinal 2, which can clean
  196.  *      up global widget class data.
  197.  *
  198.  *      This gets called by the XCenter right before
  199.  *      a widget DLL gets unloaded. Note that this
  200.  *      gets called even if the "init module" export
  201.  *      returned 0 (meaning an error) and the DLL
  202.  *      gets unloaded right away.
  203.  */
  204.  
  205. VOID EXPENTRY WgtUnInitModule(VOID)
  206. { LSWDATA *plswData;
  207.  
  208.   if (DosGetNamedSharedMem((PVOID*)&plswData,SHAREMEM_NAME,PAG_READ | PAG_WRITE)==0 && plswData!=NULL) {
  209.     SwitcherTerm(plswData,2);
  210.     DosFreeMem(plswData);
  211.   }
  212. }
  213.  
  214. /*
  215.  *@@ WgtQueryVersion:
  216.  *      this new export with ordinal 3 can return the
  217.  *      XWorkplace version number which is required
  218.  *      for this widget to run. For example, if this
  219.  *      returns 0.9.10, this widget will not run on
  220.  *      earlier XWorkplace versions.
  221.  *
  222.  *      NOTE: This export was mainly added because the
  223.  *      prototype for the "Init" export was changed
  224.  *      with V0.9.9. If this returns 0.9.9, it is
  225.  *      assumed that the INIT export understands
  226.  *      the new FNWGTINITMODULE_099 format (see center.h).
  227.  *
  228.  *@@added V0.9.9 (2001-02-06) [umoeller]
  229.  */
  230.  
  231. VOID EXPENTRY WgtQueryVersion(PULONG pulMajor,
  232.                               PULONG pulMinor,
  233.                               PULONG pulRevision)
  234. {
  235.     *pulMajor = 0;
  236.     *pulMinor = 9;
  237.     *pulRevision = 13;
  238. }
  239.  
  240.  
  241.