home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: WPS_PM / WPS_PM.zip / xfld085s.zip / main / xfdisk.c < prev    next >
C/C++ Source or Header  |  1999-02-23  |  17KB  |  453 lines

  1.  
  2. /*
  3.  *@@sourcefile xfdisk.c:
  4.  *      This file contains the following major XFolder parts:
  5.  *      --  XFldDisk SOM stuff
  6.  *
  7.  *      Check the other files starting with xf* for the
  8.  *      other XFolder classes.
  9.  *
  10.  *      XFldDisk is needed mainly to modify the popup menus
  11.  *      of Disk objects also. Since these are not instances
  12.  *      of WPFolder, we need an extra subclass.
  13.  *
  14.  *      This class must always be installed.
  15.  *
  16.  *@@somclass XFldDisk xfdisk_
  17.  *@@somclass M_XFldDisk xfdiskM_
  18.  */
  19.  
  20. /*
  21.  *      Copyright (C) 1997-99 Ulrich Möller.
  22.  *      This file is part of the XFolder source package.
  23.  *      XFolder is free software; you can redistribute it and/or modify
  24.  *      it under the terms of the GNU General Public License as published
  25.  *      by the Free Software Foundation, in version 2 as it comes in the
  26.  *      "COPYING" file of the XFolder main distribution.
  27.  *      This program is distributed in the hope that it will be useful,
  28.  *      but WITHOUT ANY WARRANTY; without even the implied warranty of
  29.  *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  30.  *      GNU General Public License for more details.
  31.  */
  32.  
  33. /*
  34.  *  This file was generated by the SOM Compiler and Emitter Framework.
  35.  *  Generated using:
  36.  *      SOM Emitter emitctm: 2.42
  37.  */
  38.  
  39. #ifndef SOM_Module_xfdisk_Source
  40. #define SOM_Module_xfdisk_Source
  41. #endif
  42. #define XFldDisk_Class_Source
  43. #define M_XFldDisk_Class_Source
  44.  
  45. /*
  46.  *  Suggested #include order:
  47.  *  1)  os2.h
  48.  *  2)  C library headers
  49.  *  3)  SOM headers which work with precompiled header files
  50.  *  4)  headers in /helpers
  51.  *  5)  headers in /main with dlgids.h and common.h first
  52.  *  6)  #pragma hdrstop to prevent VAC++ crashes
  53.  *  7)  other needed SOM headers
  54.  *  8)  for non-SOM-class files: corresponding header (e.g. classlst.h)
  55.  */
  56.  
  57. #define INCL_DOSPROCESS         // DosSleep, priorities, PIDs etc.
  58. #define INCL_DOSSEMAPHORES      // needed for xthreads.h
  59. #define INCL_DOSEXCEPTIONS
  60. #define INCL_DOSERRORS
  61. #define INCL_DOSMISC            // DosGetMessage etc.
  62. #define INCL_DOSDEVICES
  63. #define INCL_DOSDEVIOCTL
  64. #define INCL_WIN
  65. #include  <os2.h>
  66.  
  67. // C library headers
  68. #include <stdio.h>
  69.  
  70. // headers in /helpers
  71. #include "undoc.h"              // some undocumented stuff
  72.  
  73. // SOM headers which don't crash with prec. header files
  74. #include "xfdisk.ih"
  75. #include "xfldr.h"
  76.  
  77. // headers in /main
  78. #include "common.h"             // the majestic XFolder include file
  79.  
  80. #include "menus.h"              // common XFolder context menu logic
  81. #include "statbars.h"           // status bar translation logic
  82.  
  83. // other SOM headers
  84. #include "xwps.h"               // XFolder pseudo SOM functions
  85.  
  86.  
  87. // global array of all awake Disk objects
  88. XFldDisk* apDrives[27];
  89.  
  90. /* ******************************************************************
  91.  *                                                                  *
  92.  *   here come the XFldDsk instance methods                         *
  93.  *                                                                  *
  94.  ********************************************************************/
  95.  
  96. /*
  97.  *@@ wpFilterPopupMenu:
  98.  *           remove default entries for disks according to Global Settings
  99.  */
  100.  
  101. SOM_Scope ULONG  SOMLINK xfdisk_wpFilterPopupMenu(XFldDisk *somSelf,
  102.                                                 ULONG ulFlags,
  103.                                                 HWND hwndCnr,
  104.                                                 BOOL fMultiSelect)
  105. {
  106.     PGLOBALSETTINGS pGlobalSettings = cmnQueryGlobalSettings();
  107.     // XFldDiskData *somThis = XFldDiskGetData(somSelf);
  108.     XFldDiskMethodDebug("XFldDisk","xfdisk_wpFilterPopupMenu");
  109.  
  110.     return (XFldDisk_parent_WPDisk_wpFilterPopupMenu(somSelf,
  111.                                                      ulFlags,
  112.                                                      hwndCnr,
  113.                                                      fMultiSelect)
  114.         & ~(pGlobalSettings->DefaultMenuItems)
  115.         );
  116. }
  117.  
  118. /*
  119.  *@@ wpModifyPopupMenu:
  120.  *           this method allows an object to modify a context
  121.  *           menu. We add the various XFolder menu entries here
  122.  *           by calling mnuModifyPopupMenu in menus.c,
  123.  *           which is also used by the XFolder class.
  124.  */
  125.  
  126. SOM_Scope BOOL  SOMLINK xfdisk_wpModifyPopupMenu(XFldDisk *somSelf,
  127.                                                HWND hwndMenu,
  128.                                                HWND hwndCnr,
  129.                                                ULONG iPosition)
  130. {
  131.     PGLOBALSETTINGS pGlobalSettings = cmnQueryGlobalSettings();
  132.     BOOL            rc;
  133.  
  134.     // get the "root folder" of the WPDisk object; that is the
  135.     // folder which is opened when the disk object is opened
  136.     // (i.e. the folder of the root directory). This returns
  137.     // NULL if the drive is not ready.
  138.     XFolder         *pFolder = _wpQueryRootFolder(somSelf);
  139.  
  140.     // XFldDiskData *somThis = XFldDiskGetData(somSelf);
  141.     XFldDiskMethodDebug("XFldDisk","xfdisk_wpModifyPopupMenu");
  142.  
  143.     rc = XFldDisk_parent_WPDisk_wpModifyPopupMenu(somSelf,hwndMenu,hwndCnr,iPosition);
  144.  
  145.     if (pGlobalSettings->RemoveFormatDiskItem) {
  146.         WinSendMsg(hwndMenu, MM_REMOVEITEM,
  147.                 MPFROM2SHORT(ID_WPMI_FORMATDISK, FALSE),
  148.                 0);
  149.     }
  150.  
  151.     if (pGlobalSettings->RemoveCheckDiskItem) {
  152.         WinSendMsg(hwndMenu, MM_REMOVEITEM,
  153.                 MPFROM2SHORT(ID_WPMI_CHECKDISK, FALSE),
  154.                 0);
  155.     }
  156.  
  157.     if (pFolder) {
  158.         // drive ready
  159.         rc = mnuModifyPopupMenu(pFolder, hwndMenu, hwndCnr, iPosition);
  160.     }
  161.  
  162.     return (rc);
  163. }
  164.  
  165. /*
  166.  *@@ wpMenuItemSelected:
  167.  *           process input when any menu item was selected;
  168.  *           we pass the input to mnuMenuItemSelected in menus.c.
  169.  */
  170.  
  171. SOM_Scope BOOL  SOMLINK xfdisk_wpMenuItemSelected(XFldDisk *somSelf,
  172.                                                 HWND hwndFrame,
  173.                                                 ULONG ulMenuId)
  174. {
  175.     XFolder         *pFolder = _wpQueryRootFolder(somSelf);
  176.     // XFldDiskData *somThis = XFldDiskGetData(somSelf);
  177.     XFldDiskMethodDebug("XFldDisk","xfdisk_wpMenuItemSelected");
  178.  
  179.     if (mnuMenuItemSelected(pFolder, hwndFrame, ulMenuId))
  180.         return TRUE;
  181.     else
  182.         return (XFldDisk_parent_WPDisk_wpMenuItemSelected(somSelf, hwndFrame,
  183.                                                    ulMenuId));
  184. }
  185.  
  186. /*
  187.  *@@ wpMenuItemHelpSelected:
  188.  *           display help for a context menu item;
  189.  *           we pass the input to mnuMenuItemHelpSelected in menus.c.
  190.  */
  191.  
  192. SOM_Scope BOOL  SOMLINK xfdisk_wpMenuItemHelpSelected(XFldDisk *somSelf,
  193.                                                     ULONG MenuId)
  194. {
  195.     XFolder         *pFolder = _wpQueryRootFolder(somSelf);
  196.     // XFldDiskData *somThis = XFldDiskGetData(somSelf);
  197.     XFldDiskMethodDebug("XFldDisk","xfdisk_wpMenuItemHelpSelected");
  198.  
  199.     if (mnuMenuItemHelpSelected(pFolder, MenuId))
  200.         return TRUE;
  201.     else
  202.         return (XFldDisk_parent_WPDisk_wpMenuItemHelpSelected(somSelf,
  203.                                                            MenuId));
  204. }
  205.  
  206. /*
  207.  *@@ wpViewObject:
  208.  *           this either opens a view of the given Disk object
  209.  *           as a root folder (using wpOpen) or resurfaces an
  210.  *           already open view.
  211.  *           This gets called every time the user tries to open
  212.  *           a disk object, e.g. by double-clicking on one in the
  213.  *           "Drives" folder.
  214.  *           The WPS seems to be doing no drive checking in here,
  215.  *           which leads to the annoying "Drive not ready" popups.
  216.  *           So we try to implement this here.
  217.  */
  218.  
  219. SOM_Scope HWND  SOMLINK xfdisk_wpViewObject(XFldDisk *somSelf,
  220.                                             HWND hwndCnr, ULONG ulView,
  221.                                             ULONG param)
  222. {
  223.     HWND            hwndFrame = NULLHANDLE; // default: error occured
  224.     APIRET          arc = NO_ERROR;
  225.     XFolder*        pRootFolder;
  226.     ULONG           mbrc = MBID_OK;
  227.  
  228.     /* XFldDiskData *somThis = XFldDiskGetData(somSelf); */
  229.     XFldDiskMethodDebug("XFldDisk","xfdisk_wpViewObject");
  230.  
  231.     // query root folder (WPRootFolder class, which is a descendant
  232.     // of WPFolder/XFolder); each WPDisk is paired with one of those,
  233.     // and the actual display is done by this class, so we will pass
  234.     // pRootFolder instead of somSelf to most following method calls.
  235.     // We use xwpsQueryRootFolder instead of wpQueryRootFolder to
  236.     // avoid the "Drive not ready" popups which the WPS/OS/2 normally
  237.     // displays in this method.
  238.     do {
  239.         HPOINTER hptrOld = WinQueryPointer(HWND_DESKTOP);
  240.         WinSetPointer(HWND_DESKTOP, WinQuerySysPointer(HWND_DESKTOP, SPTR_WAIT, FALSE));
  241.         pRootFolder = xwpsQueryRootFolder(somSelf, &arc);
  242.         WinSetPointer(HWND_DESKTOP, hptrOld);
  243.  
  244.         mbrc = MBID_OK;
  245.  
  246.         if (pRootFolder == NULL) {
  247.             // drive not ready:
  248.             CHAR    szError[400],
  249.                     szTitle[400];
  250.             ULONG   ulLen = 0;
  251.             DosGetMessage(NULL, 0,       // no string replacements
  252.                     szError, sizeof(szError),
  253.                     arc,
  254.                     "OSO001.MSG",        // default OS/2 message file
  255.                     &ulLen);
  256.  
  257.             cmnGetMessage(NULL, 0, szTitle, sizeof(szTitle), 104);
  258.                             // "XFolder: Error"
  259.             sprintf(szTitle + strlen(szTitle),
  260.                     " (\"%s\")", _wpQueryTitle(somSelf));
  261.                             // append drive name in brackets
  262.             mbrc = cmnMessageBox(HWND_DESKTOP,
  263.                     szTitle,
  264.                     szError,
  265.                     MB_RETRYCANCEL);
  266.         }
  267.     } while (mbrc == MBID_RETRY);
  268.  
  269.     if (pRootFolder)
  270.         hwndFrame = XFldDisk_parent_WPDisk_wpViewObject(somSelf, hwndCnr,
  271.                                                 ulView, param);
  272.  
  273.     return (hwndFrame);
  274. }
  275.  
  276. /*
  277.  *@@ wpOpen:
  278.  *           this method gets called when wpViewObject thinks a
  279.  *           new view of the object needs to be opened.
  280.  *           We call the parent first and then subclass the
  281.  *           resulting frame window, similar to what we're doing
  282.  *           with folder views (see XFolder::wpOpen).
  283.  */
  284.  
  285. SOM_Scope HWND  SOMLINK xfdisk_wpOpen(XFldDisk *somSelf, HWND hwndCnr,
  286.                                        ULONG ulView, ULONG param)
  287. {
  288.     HWND            hwndNewFrame = NULLHANDLE; // default: error occured
  289.     APIRET          arc = NO_ERROR;
  290.     XFolder*        pRootFolder;
  291.     // XFldDiskData *somThis = XFldDiskGetData(somSelf);
  292.     XFldDiskMethodDebug("XFldDisk","xfdisk_wpOpen");
  293.  
  294.     // query root folder (WPRootFolder class, which is a descendant
  295.     // of WPFolder/XFolder); each WPDisk is paired with one of those,
  296.     // and the actual display is done by this class, so we will pass
  297.     // pRootFolder instead of somSelf to most following method calls.
  298.     // We use xwpsQueryRootFolder instead of wpQueryRootFolder to
  299.     // avoid "Drive not ready" popups.
  300.     pRootFolder = xwpsQueryRootFolder(somSelf, &arc);
  301.  
  302.     if (pRootFolder) {
  303.         // drive ready: call parent to get frame handle
  304.         hwndNewFrame = XFldDisk_parent_WPDisk_wpOpen(somSelf, hwndCnr, ulView,
  305.                                               param);
  306.  
  307.         if (hwndNewFrame)
  308.         {
  309.             // open successful:
  310.             if (   (ulView == OPEN_CONTENTS)
  311.                 || (ulView == OPEN_TREE)
  312.                 || (ulView == OPEN_DETAILS)
  313.                )
  314.             {
  315.                 PSUBCLASSEDLISTITEM psli;
  316.                 PGLOBALSETTINGS     pGlobalSettings = cmnQueryGlobalSettings();
  317.  
  318.                 // subclass frame window; this is the same
  319.                 // proc which is used for normal folder frames,
  320.                 // we just use pRootFolder instead.
  321.                 // However, we pass somSelf as the "real" object
  322.                 // which will then be stored in *psli.
  323.                 psli = cmnSubclassFolderFrame(hwndNewFrame, pRootFolder, somSelf, ulView);
  324.  
  325.                 // add status bar, if allowed: as opposed to
  326.                 // XFolder's, for XFldDisk's we only check the
  327.                 // global setting, because there's no instance
  328.                 // setting for this with XFldDisk's
  329.                 if (pGlobalSettings->StatusBar)
  330.                     // assert that subclassed list item is valid
  331.                     if (psli)
  332.                         // add status bar only if allowed for the current view type
  333.                         if (    (   (ulView == OPEN_CONTENTS)
  334.                                  && (pGlobalSettings->SBForViews & SBV_ICON)
  335.                                 )
  336.                              || (   (ulView == OPEN_TREE)
  337.                                  && (pGlobalSettings->SBForViews & SBV_TREE)
  338.                                 )
  339.                              || (   (ulView == OPEN_DETAILS)
  340.                                  && (pGlobalSettings->SBForViews & SBV_DETAILS)
  341.                                 )
  342.                             )
  343.                             // this reformats the window with the status bar
  344.                             _xfShowStatusBar(pRootFolder, psli, TRUE);
  345.  
  346.                 // extended sort functions
  347.                 if (pGlobalSettings->ReplaceSort)
  348.                 {
  349.                     hwndCnr = xwpsQueryCnrFromFrame(hwndNewFrame);
  350.                     if (hwndCnr)
  351.                         _xfSetCnrSort(pRootFolder, hwndCnr, FALSE);
  352.                 }
  353.             }
  354.         }
  355.     }
  356.  
  357.     return (hwndNewFrame);
  358. }
  359.  
  360. /*
  361.  *@@ wpInitData:
  362.  *           initialize XFldDisk instance data
  363.  */
  364.  
  365. SOM_Scope void  SOMLINK xfdisk_wpInitData(XFldDisk *somSelf)
  366. {
  367.     // XFldDiskData *somThis = XFldDiskGetData(somSelf);
  368.     XFldDiskMethodDebug("XFldDisk","xfdisk_wpInitData");
  369.  
  370.     XFldDisk_parent_WPDisk_wpInitData(somSelf);
  371.  
  372.     // _szFSType[0] = '\0';
  373. }
  374.  
  375. /*
  376.  *@@ wpObjectReady:
  377.  *           this instance method is called by the system when
  378.  *           object awakening is complete and object data seems
  379.  *           to be stable in memory.
  380.  *           We will have this object's pointer stored in a
  381.  *           global array to be able to find the Disk object for
  382.  *           a given object (xfclsQueryDiskObject).
  383.  */
  384.  
  385. SOM_Scope void  SOMLINK xfdisk_wpObjectReady(XFldDisk *somSelf,
  386.                                              ULONG ulCode, WPObject* refObject)
  387. {
  388.     ULONG ulDisk;
  389.     // XFldDiskData *somThis = XFldDiskGetData(somSelf);
  390.     XFldDiskMethodDebug("XFldDisk","xfdisk_wpObjectReady");
  391.  
  392.     XFldDisk_parent_WPDisk_wpObjectReady(somSelf, ulCode, refObject);
  393.  
  394.     ulDisk = _wpQueryLogicalDrive(somSelf);
  395.     apDrives[ulDisk] = somSelf;
  396.  
  397.     /* XFldDisk_parent_XFldObject_wpObjectReady(somSelf, ulCode,
  398.                                              refObject); */
  399. }
  400.  
  401. /* ******************************************************************
  402.  *                                                                  *
  403.  *   here come the xfdisk class methods                            *
  404.  *                                                                  *
  405.  ********************************************************************/
  406.  
  407. /*
  408.  *@@ xfclsQueryDisk:
  409.  *           since I have no idea what the default wpQueryDisk
  410.  *           is for (why the hell does it return a WPFileSystem?),
  411.  *           this is a proper method which returns the disk object
  412.  *           which corresponds to the drive on which the object
  413.  *           resides. This works for both abstract and file-system
  414.  *           objects.
  415.  *           Returns NULL upon errors.
  416.  *           Note: this method only works after the Drives folder
  417.  *           has been populated because it relies on our
  418.  *           wpObjectReady override for XFldDisk. Otherwise you'll
  419.  *           get NULL back.
  420.  *           The WPS normally populates that folder a few seconds
  421.  *           after the Desktop is up.
  422.  */
  423.  
  424. SOM_Scope XFldDisk*  SOMLINK xfdiskM_xfclsQueryDiskObject(M_XFldDisk *somSelf,
  425.                                                           WPObject* pObject)
  426. {
  427.     ULONG ulLogicalDrive = xwpsQueryLogicalDriveNumber(pObject);
  428.     /* M_XFldDiskData *somThis = M_XFldDiskGetData(somSelf); */
  429.     M_XFldDiskMethodDebug("M_XFldDisk","xfdiskM_xfclsQueryDiskObject");
  430.  
  431.     // _Pmpf(("xfclsQueryDiskObject: ulDrive = %d", ulLogicalDrive));
  432.     return (apDrives[ulLogicalDrive]);
  433. }
  434.  
  435. /*
  436.  *@@ wpclsInitData:
  437.  *           initialize class instance data
  438.  */
  439.  
  440. SOM_Scope void  SOMLINK xfdiskM_wpclsInitData(M_XFldDisk *somSelf)
  441. {
  442.     // M_XFldDiskData *somThis = M_XFldDiskGetData(somSelf);
  443.     M_XFldDiskMethodDebug("M_XFldDisk","xfdiskM_wpclsInitData");
  444.  
  445.     M_XFldDisk_parent_M_WPDisk_wpclsInitData(somSelf);
  446.     // M_XFldDisk_parent_M_XFldObject_wpclsInitData(somSelf);
  447.  
  448.     // szWPDiskStatusBarMnemonics[0] = '\0';
  449.     memset(&apDrives, 0, sizeof(apDrives));
  450. }
  451.  
  452.  
  453.