home *** CD-ROM | disk | FTP | other *** search
- /*
- *
- * Main Source file for class CWProgFolder
- *
- * (C) Chris Wohlgenuth 1999
- *
- * This class is intended for programmers and provides functions for some
- * common tasks like:
- * - Adding dialogs as frame controls to WPS folders
- * - Showing 'About'-dialogs
- * - Checking of object pointers
- * - ...
- *
- * Use IBM VAC++ V3.00 and Gnu-make 3.74.1 to compile
- *
- */
-
- /*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; see the file COPYING. If not, write to
- * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
- */
- #define INCL_DOSQUEUES
- #include "progfolder.h"
- #include "progfolder.hh"
- #include <stdlib.h>
- #include <stdio.h>
-
- MRESULT EXPENTRY folderFrameProcedure(HWND hwnd,ULONG msg, MPARAM mp1,MPARAM mp2);
- HWND createStoreWindow(HWND hwndCLF);
- HWND createLeechFrame(HWND hwndCLF);
-
- /**************************************************************/
- /* */
- /* This function returns the module handle of our class-dll */
- /* */
- /**************************************************************/
- HMODULE queryModuleHandle(void)
- {
- static HMODULE hmod=0;
-
- if(!hmod) {
- PSZ pathname=SOMClassMgrObject //Query Pathname of class file
- ->somLocateClassFile(somIdFromString("CWProgFolder"),1,2);
- DosQueryModuleHandle(pathname,&hmod); //Query module handle
- }
- return hmod;
- }
-
- /**************************************************************/
- /* */
- /* Overriden function: wpclsQueryStyle() */
- /* */
- /* This class doesn't need a template. */
- /* */
- /**************************************************************/
- ULONG M_CWProgFolder::wpclsQueryStyle()
- {
- ULONG rc;
- rc=M_WPFolder::wpclsQueryStyle();
- rc|=CLSSTYLE_NEVERTEMPLATE;
- return rc;
- }
-
- /**************************************************************/
- /* */
- /* Overriden function: wpclsQueryTitle() */
- /* */
- /* Returns our class name */
- /* */
- /**************************************************************/
- PSZ M_CWProgFolder::wpclsQueryTitle()
- {
- return "Support-Folder";
- }
-
- /*
- MRESULT EXPENTRY dialogProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
- {
-
- return WinDefDlgProc(hwnd, msg, mp1, mp2);
- }
- */
-
- /* This Funktion is called when the close button of the */
- /* frame is pressed or if the user chooses 'close' from */
- /* the menu. Apparently the wpClose() method isn't */
- /* called when choosing close. Seems that it is only */
- /* used if the WPS want's to close a folder. */
- BOOL CWProgFolder::cwClose()
- {
- return TRUE;
- }
-
- /**************************************************************/
- /* */
- /* Overriden function: wpOpen() */
- /* */
- /* This function subclasses the folder frame window and */
- /* prepares it for the addition of frame controls. */
- /* */
- /**************************************************************/
- HWND CWProgFolder::wpOpen(HWND hwndCnr,ULONG ulView,ULONG ulParam)
- {
- HWND hwnd;
- HWND hwndStore;
- PFNWP orgFrameProc;
-
- // hwnd=WPFolder::wpOpen(hwndCnr, ulView, ulParam);/* Call parent to build folder window */
- hwnd=((somTD_WPObject_wpOpen)
- somParentNumResolve(__ClassObject->somGetPClsMtabs(),
- 1,
- __ClassObject->
- somGetMethodToken(somIdFromString
- ("wpOpen")))
- )(this,hwndCnr, ulView, ulParam);
-
- if(ulView==OPEN_SETTINGS)
- /* We only build frame controls for folder frame windows */
- return hwnd;
- if(WinWindowFromID(hwnd,ID_FOLDERSTOREWINDOW))
- return hwnd;/* Already subclassed */
-
- hwndStore=createStoreWindow(hwnd);/* This holds our object pointer */
- if(hwndStore){
- /* Save 'this' ptr. */
- WinSetWindowPtr(hwndStore,0,this);
- /* Subclass the folder frame window */
- orgFrameProc=WinSubclassWindow(hwnd,&folderFrameProcedure);
- /* Save the old window procedure in our store window */
- WinSetWindowPtr(hwndStore,QWP_ORGFRAMEPROC,orgFrameProc);
- /* Save a ptr. to private control data */
- WinSetWindowPtr(hwndStore,QWP_FCTRLDATA,malloc(sizeof(FRAMECTRLDATA)));
- }
- return hwnd;
- }
-
- /**************************************************************/
- /* */
- /* This member function returns the count of additional frame */
- /* controls we have added to the frame. This fuction is */
- /* called from the frame window procedure */
- /* */
- /**************************************************************/
- ULONG CWProgFolder::cwNumAdditionalFrameControls(HWND hwndFolder)
- {
- ULONG rc;
- FRAMECTRLDATA * fctrlData;
-
- fctrlData=(FRAMECTRLDATA*)WinQueryWindowPtr(WinWindowFromID(hwndFolder, ID_FOLDERSTOREWINDOW),QWP_FCTRLDATA);
- if(!fctrlData) return 0;
-
- rc=0;
-
- if(fctrlData->bLeft)rc++;
- if(fctrlData->bRight)rc++;
- if(fctrlData->bTop)rc++;
- if(fctrlData->bBottom)rc++;
-
- return rc;
- }
-
- /**************************************************************/
- /* */
- /* This function adjusts the size and position of the client. */
- /* It is called from the frame window procedure */
- /* */
- /**************************************************************/
- BOOL CWProgFolder::cwCalculateClient(HWND hwndFolder, PRECTL pRectl)
- {
- FRAMECTRLDATA * fctrlData;
-
- fctrlData=(FRAMECTRLDATA*)WinQueryWindowPtr(WinWindowFromID(hwndFolder, ID_FOLDERSTOREWINDOW),QWP_FCTRLDATA);
- if(!fctrlData) return FALSE;
-
- if(fctrlData->bLeft)
- pRectl->xLeft+=fctrlData->sizelLeftFrame.cx;
- if(fctrlData->bRight)
- pRectl->xRight-=fctrlData->sizelRightFrame.cx;
- if(fctrlData->bTop)
- pRectl->yTop-=fctrlData->sizelTopFrame.cy;
- if(fctrlData->bBottom)
- pRectl->yBottom+=fctrlData->sizelBottomFrame.cy;
-
- return TRUE;/* Everything's ok */
- }
-
- /**************************************************************/
- /* */
-
- /* */
- /**************************************************************/
- ULONG CWProgFolder::cwFormatFrame(HWND hwndFolder, USHORT countSWP,PSWP pswp)
- {
- /* countSWP: number of standard framecontrols
- pswp: Array of SWP describing the framecontrols.
- Since we added the number of our controls to the
- standard controls in the framecontrol there is
- space for the new controls.
- */
- ULONG rc;
- PSWP pswpClient=0, pswpFrameCtl=0;
- int iCount;
- FRAMECTRLDATA * fctrlData;
- int a;
-
- /* The data of our framecontrols is stored in a structure.
- Get a pointer from the window words of the invisible child. */
- fctrlData=(FRAMECTRLDATA*)WinQueryWindowPtr(WinWindowFromID(hwndFolder, ID_FOLDERSTOREWINDOW),QWP_FCTRLDATA);
- if(!fctrlData) return 0;
-
- iCount=0;
- rc=0;
-
- for (a = 0; a < countSWP; a++)
- {
- /* Find the client window */
- if ( WinQueryWindowUShort( pswp[a].hwnd, QWS_ID ) == 0x8008 ) // FID_CLIENT )
- {
- pswpClient=&pswp[a];
-
- /* Framecontrol at the top */
- if(fctrlData->bTop){
- pswpFrameCtl=&pswp[countSWP+iCount++];/* First free position */
-
- /* Adjust client and insert the new control into the array of SWPs */
-
- /* Decrease the height of the client to have place for the new control */
- pswp[a].cy -= fctrlData->sizelTopFrame.cy;
-
- /* Insert the HWND of the new control into the structure */
- pswpFrameCtl->hwnd=fctrlData->hwndCtlTop;
-
- /* The x-position is the same as that of the client */
- pswpFrameCtl->x = pswpClient->x;
-
- /* The control is placed above the client */
- pswpFrameCtl->y = pswpClient->y + pswpClient->cy;
-
- /* The control is as wide as the client */
- pswpFrameCtl->cx = pswpClient->cx;
-
- /* Insert the height of the control */
- pswpFrameCtl->cy = fctrlData->sizelTopFrame.cy;
-
- /* Place the control on top of all windows */
- pswpFrameCtl->hwndInsertBehind = HWND_TOP;
-
- /* Insert necessary flags */
- pswpFrameCtl->fl = SWP_MOVE | SWP_SIZE | SWP_NOADJUST | SWP_ZORDER |SWP_SHOW;
-
- /* Adjust position if flags are set. It's possible to place
- the control above the controls on the left and right or let these controls
- cover the full height of the folder. */
- if(fctrlData->bLeft){
- /* There is a frame control on the left side */
- if(!(fctrlData->ulFlagsLeft & FCTL_POSBELOW)) {
- pswpFrameCtl->x += fctrlData->sizelLeftFrame.cx;
- pswpFrameCtl->cx -= fctrlData->sizelLeftFrame.cx;
- }
- }
- /* framecontrol on the right side */
- if(!(fctrlData->ulFlagsRight & FCTL_POSBELOW) && fctrlData->bRight)
- pswpFrameCtl->cx -= fctrlData->sizelRightFrame.cx;
- /* One new control added */
- rc++;
- }/* end of if(fctrlData->bTop) */
-
- /* Left frame control */
- if(fctrlData->bLeft){
- pswpFrameCtl=&pswp[countSWP+iCount++];/* First free position */
-
- pswpClient->cx -= fctrlData->sizelLeftFrame.cx;/* Size client */
- pswpFrameCtl->hwnd=fctrlData->hwndCtlLeft;
-
- pswpFrameCtl->x =pswpClient->x;
- pswpClient->x += fctrlData->sizelLeftFrame.cx;/* Size client */
- pswpFrameCtl->y =pswpClient->y;
-
- pswpFrameCtl->cx = fctrlData->sizelLeftFrame.cx;
- pswpFrameCtl->cy =pswpClient->cy;
-
- pswpFrameCtl->hwndInsertBehind = HWND_TOP;
- pswpFrameCtl->fl = SWP_MOVE | SWP_SIZE | SWP_NOADJUST | SWP_ZORDER |SWP_SHOW;
-
- /* Position this frame control above bottom ctrl if requested */
- if((fctrlData->ulFlagsLeft & FCTL_POSABOVE) && fctrlData->bBottom){
- pswpFrameCtl->y +=fctrlData->sizelBottomFrame.cy;
- pswpFrameCtl->cy -=fctrlData->sizelBottomFrame.cy;
- }
- /* Position this frame control below top ctrl if requested */
- if(!(fctrlData->ulFlagsLeft & FCTL_POSBELOW) && fctrlData->bTop){
- pswpFrameCtl->cy +=fctrlData->sizelTopFrame.cy;
- }
- rc++;
- }/* end of if(fctrlData->bLeft) */
-
- /* Bottom frame control */
- if(fctrlData->bBottom){
- pswpFrameCtl=&pswp[countSWP+iCount++];/* First free position */
-
- pswpClient->cy -= fctrlData->sizelBottomFrame.cy;
- pswpFrameCtl->hwnd=fctrlData->hwndCtlBottom;
-
- pswpFrameCtl->x = pswpClient->x;
- pswpFrameCtl->y = pswpClient->y;
- pswpClient->y += fctrlData->sizelBottomFrame.cy;
-
- pswpFrameCtl->cx = pswpClient->cx;
- pswpFrameCtl->cy = fctrlData->sizelBottomFrame.cy;
-
- pswpFrameCtl->hwndInsertBehind = HWND_TOP;
- pswpFrameCtl->fl = SWP_MOVE | SWP_SIZE | SWP_NOADJUST | SWP_ZORDER |SWP_SHOW;
-
- /* Adjust position if flags are set */
- if(fctrlData->bLeft){
- if((fctrlData->ulFlagsLeft & FCTL_POSABOVE)) {
- pswpFrameCtl->cx +=fctrlData->sizelLeftFrame.cx;
- pswpFrameCtl->x -= fctrlData->sizelLeftFrame.cx;
- }
- }
- if(!(fctrlData->ulFlagsRight & FCTL_POSABOVE)&& fctrlData->bRight) {
- pswpFrameCtl->cx -= fctrlData->sizelRightFrame.cx;
- }
- rc++;
- }/* end of if(fctrlData->bBottom) */
-
- /* Right frame control */
- if(fctrlData->bRight){
- pswpFrameCtl=&pswp[countSWP+iCount++];/* First free position */
-
- pswpClient->cx -= fctrlData->sizelRightFrame.cx;/* Size client */
- pswpFrameCtl->hwnd=fctrlData->hwndCtlRight;
-
- pswpFrameCtl->x =pswpClient->x+pswpClient->cx;
- pswpFrameCtl->y =pswpClient->y;
-
- pswpFrameCtl->cx = fctrlData->sizelRightFrame.cx;
- pswpFrameCtl->cy =pswpClient->cy;
-
- pswpFrameCtl->hwndInsertBehind = HWND_TOP;
- pswpFrameCtl->fl = SWP_MOVE | SWP_SIZE | SWP_NOADJUST | SWP_ZORDER |SWP_SHOW;
-
- /* Position this frame control above bottom ctrl only if requested */
- if(!(fctrlData->ulFlagsRight & FCTL_POSABOVE) && fctrlData->bBottom){
- pswpFrameCtl->y -=fctrlData->sizelBottomFrame.cy;
- pswpFrameCtl->cy +=fctrlData->sizelBottomFrame.cy;
- }
- /* Position this frame control below top ctrl only if requested */
- if(!(fctrlData->ulFlagsRight & FCTL_POSBELOW) && fctrlData->bTop){
- pswpFrameCtl->cy +=fctrlData->sizelTopFrame.cy;
- }
- rc++;
- }/* end of if(fctrlData->bRight) */
- }
- }
- return rc;/* Return additional controls */
- }
-
-
- /**************************************************************/
- /* */
- /* This function adds a frame control at the specified */
- /* position. */
- /* */
- /**************************************************************/
- BOOL CWProgFolder::cwAddFrameCtl(HWND hwndFolder, HWND hwndNewCtl,SIZEL sizel, ULONG ulPos, ULONG ulFlags)
- {
- FRAMECTRLDATA * fctrlData;
-
- /* Get the framecontrol datastructure from the invisible control window */
- fctrlData=(FRAMECTRLDATA*)WinQueryWindowPtr(WinWindowFromID(hwndFolder, ID_FOLDERSTOREWINDOW),QWP_FCTRLDATA);
- if(!fctrlData) return FALSE;
-
- /* Fill in the values into the structure */
- /* This is the dialog at the left */
- if(ulPos & FCTL_LEFT) {
- /* The HWND of the dialog used as a framcontrol */
- fctrlData->hwndCtlLeft=hwndNewCtl;
- /* The size of the dialog. Actually only sizel.cx is used
- since this is a dialog at the left which always has
- got the height of the client. */
- fctrlData->sizelLeftFrame=sizel;
- /* A flag which determines the positioning of the dialog.
- If there is a dialog at the top you may tell the folder
- to move it sizel.cx pixel to the right to allow the
- control at the left to cover the full height of the folder.
- The same is with the control at the bottom. This gives
- you the ability to finetune the appearance of the
- folder. Just try the flags FCTL_POSBELOW, FCTL_POSABOVE as
- defined in progfolder.h in conjunction with framecontrols
- at different positions of the folder.
- */
- fctrlData->ulFlagsLeft=ulFlags;
- /* Tell the frame procedure that there's a framecontrol
- at the left. */
- fctrlData->bLeft=TRUE;
- if(!fctrlData->hwndCtlLeft)
- /* If this method is called with hwndNewCtl=NULL the framecontrol
- is disabled. */
- fctrlData->bLeft=FALSE;
- }
- /* This is the dialog at the right */
- if(ulPos & FCTL_RIGHT){
- fctrlData->hwndCtlRight=hwndNewCtl;
- fctrlData->sizelRightFrame=sizel;
- fctrlData->ulFlagsRight=ulFlags;
- fctrlData->bRight=TRUE;
- if(!fctrlData->hwndCtlRight)
- fctrlData->bRight=FALSE;
- }
- if(ulPos & FCTL_TOP){
- fctrlData->hwndCtlTop=hwndNewCtl;
- fctrlData->sizelTopFrame=sizel;
- fctrlData->bTop=TRUE;
- if(!fctrlData->hwndCtlTop)
- fctrlData->bTop=FALSE;
- }
- if(ulPos & FCTL_BOTTOM){
- fctrlData->hwndCtlBottom=hwndNewCtl;
- fctrlData->sizelBottomFrame=sizel;
- fctrlData->bBottom=TRUE;
- if(!fctrlData->hwndCtlBottom)
- fctrlData->bBottom=FALSE;
- }
- return TRUE;
- }
-
-
- /**************************************************************/
- /* */
- /* This function returns information about the specified */
- /* private frame control. */
- /* */
- /**************************************************************/
- HWND CWProgFolder::cwQueryFrameCtl(HWND hwndFolder, SIZEL* sizel, ULONG ulPos, ULONG * ulFlags)
- {
- FRAMECTRLDATA * fctrlData;
-
- fctrlData=(FRAMECTRLDATA*)WinQueryWindowPtr(WinWindowFromID(hwndFolder, ID_FOLDERSTOREWINDOW),QWP_FCTRLDATA);
- if(!fctrlData) return FALSE;
-
-
- if(ulPos & FCTL_LEFT){
- *sizel=fctrlData->sizelLeftFrame;
- *ulFlags= fctrlData->ulFlagsLeft;
- return fctrlData->hwndCtlLeft;
- }
- if(ulPos & FCTL_RIGHT){
- *sizel=fctrlData->sizelRightFrame;
- *ulFlags=fctrlData->ulFlagsRight;
- return fctrlData->hwndCtlRight;
- }
- if(ulPos & FCTL_TOP){
- *sizel=fctrlData->sizelTopFrame;
- *ulFlags=0;
- return fctrlData->hwndCtlTop;
- }
- if(ulPos & FCTL_BOTTOM){
- *sizel=fctrlData->sizelBottomFrame;
- *ulFlags=0;
- return fctrlData->hwndCtlBottom;
- }
- return NULL;
- }
-
- /**************************************************************/
- /* */
- /* This function requests an update of frame controls so */
- /* added frame controls will become visible. */
- /* You must call this function after calling cwAddFrameCtl(). */
- /* */
- /**************************************************************/
- void CWProgFolder::cwUpdateFrame(HWND hwndFolder)
- {
- WinSendMsg(hwndFolder,WM_UPDATEFRAME,0,0);
- }
-
- /**************************************************************/
- /* */
- /* This function returns the pointer to a file system object */
- /* or NULL. */
- /* It follows shadow objects and returns the object handle */
- /* of the linked object if it's a file system object */
- /* */
- /**************************************************************/
- WPObject* CWProgFolder::cwGetFileSystemObject(WPObject* wpObject)
- {
- if(!wpObject) return NULL;//No object given
-
- /* Check if it's a shadow */
- if(somResolveByName(wpObject,"wpQueryShadowedObject")){
- /* Yes, it's a shadow. Query the linked object. */
- wpObject=((WPShadow*)wpObject)->wpQueryShadowedObject(FALSE);
- }
-
- if(!wpObject) return NULL;//The link is broken
-
- /* Check if it's a file system object */
- if(somResolveByName(wpObject, "wpQueryRealName")){
- return wpObject;/* Yes */
- }
- else
- return NULL;
- }
-
-
- /**************************************************************/
- /* */
-
- /* */
- /**************************************************************/
- MRESULT EXPENTRY aboutDlgProc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 )
- {
- switch( msg )
- {
- case WM_INITDLG:
- return (MRESULT) TRUE;
- case WM_DESTROY:
- break;
- case WM_CLOSE:
- break;
- case WM_COMMAND:
- {
- switch( SHORT1FROMMP( mp1 ) )
- {
- default:
- break;
- }
- }
- break;
- return (MRESULT) TRUE;
- }
- return( WinDefDlgProc( hwnd, msg, mp1, mp2 ) );
- }
-
- /**************************************************************/
- /* */
-
- /* */
- /**************************************************************/
- ULONG CWProgFolder::cwShowAboutDlg(HMODULE hModule, ULONG idDialog)
- {
- return (WinDlgBox( HWND_DESKTOP, HWND_DESKTOP, aboutDlgProc, hModule,idDialog, 0));
- }
-
- /**************************************************************/
- /* */
- /* This funktion returns the CD-Drives in the system */
- /* */
- /* iNumCD (output): # of CD-Drives */
- /* cFirstDrive (output): first cd-Drive letter */
- /* returns TRUE: We have cd-drives */
- /* */
- /**************************************************************/
- BOOL CWProgFolder::cwQueryCDDrives(int *iNumCD, char * cFirstDrive)
- {
- HFILE hfDevice;
- ULONG ulAction;
- ULONG ulLen;
- static char cFirst=0;
- static int iNumCDLocal=0;
- static BOOL haveCD=FALSE;
- static BOOL done=FALSE;
- struct
- {
- USHORT usCountCD;
- USHORT usFirstCD;
- } CDInfo;
-
- if(!done){
- ulLen = sizeof(CDInfo);
- if(!DosOpen("\\DEV\\CD-ROM2$", &hfDevice, &ulAction, 0,
- FILE_NORMAL, OPEN_ACTION_OPEN_IF_EXISTS,
- OPEN_SHARE_DENYNONE | OPEN_ACCESS_READONLY, NULL))
- {
- if(!DosDevIOCtl(hfDevice, 0x82, 0x60, NULL, 0, NULL, &CDInfo, ulLen, &ulLen))
- {
- if(CDInfo.usCountCD) {
- haveCD=TRUE;
- iNumCDLocal=CDInfo.usCountCD;
- cFirst='A'+ CDInfo.usFirstCD;
- }
- }
- DosClose(hfDevice);
- }
- done=TRUE;
- }
- *iNumCD=iNumCDLocal;
- *cFirstDrive=cFirst;
- return haveCD;
- }
-
- /*ULONG CWProgFolder::cwQueryAudioCDInfo(char * drive)
- {
- HFILE hfCD = 0;
- ULONG ulAction;
- ULONG ulParamLen=4;
- ULONG ulDataLen;
- ULONG rc;
-
- rc = DosOpen(drive, &hfCD, &ulAction, 0,
- FILE_NORMAL, OPEN_ACTION_OPEN_IF_EXISTS,
- OPEN_SHARE_DENYNONE | OPEN_ACCESS_READONLY |
- OPEN_FLAGS_DASD, NULL);
-
- if(rc)
- return 0;//Error
- ulDataLen=0;
-
- rc = DosDevIOCtl(hCDDrive, IOCTL_CDROMAUDIO, CDROMAUDIO_GETAUDIODISK,
- "CD01", 4, &ulParamLen, cdInfo,
- sizeof(*cdInfo), &ulDataLen);
-
- if(rc) {
- DosClose(hfCD);
- return 0;//Error
- }
-
- DosClose(hfCD);
- return 0;
-
- }
- */
-
-
-
-
-
-
-
-
-
-
-