diff options
author | Vladimir Glazounov <vg@openoffice.org> | 2007-09-20 15:06:28 +0000 |
---|---|---|
committer | Vladimir Glazounov <vg@openoffice.org> | 2007-09-20 15:06:28 +0000 |
commit | d9608817f2eab222ea7f1f3cf84d8f34fc2147bc (patch) | |
tree | b85c22c4c047caaa1685cb50812c82ec08ad6028 /vcl | |
parent | df7c008ebd14b6592c8c707de86e1741a45da011 (diff) |
INTEGRATION: CWS os2port01 (1.2.2); FILE ADDED
2006/11/29 14:34:00 ydario 1.2.2.1: Initial OS/2 import.
Diffstat (limited to 'vcl')
-rw-r--r-- | vcl/os2/source/app/salshl.cxx | 163 | ||||
-rw-r--r-- | vcl/os2/source/app/salsound.cxx | 460 | ||||
-rw-r--r-- | vcl/os2/source/app/salsys.cxx | 287 |
3 files changed, 910 insertions, 0 deletions
diff --git a/vcl/os2/source/app/salshl.cxx b/vcl/os2/source/app/salshl.cxx new file mode 100644 index 000000000000..a6b001351207 --- /dev/null +++ b/vcl/os2/source/app/salshl.cxx @@ -0,0 +1,163 @@ +/************************************************************************* + * + * $RCSfile: salshl.cxx,v $ + * + * $Revision: 1.3 $ + * + * last change: $Author: vg $ $Date: 2007-09-20 16:06:07 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#include <svpm.h> + +#define _SV_SALSHL_CXX + +#ifndef _SV_SALDATA_HXX +#include <saldata.hxx> +#endif + +#ifndef _TOOLS_DEBUG_HXX +#include <tools/debug.hxx> +#endif + +// ======================================================================= + +SalShlData aSalShlData; + +HMODULE ImplGetModule(void); +static HMODULE mhMod = ImplGetModule(); + +// ======================================================================= + +APIRET APIENTRY DosQueryModFromEIP (HMODULE *phMod, ULONG *pObjNum, + ULONG BuffLen, PCHAR pBuff, ULONG *pOffset, ULONG Address); + +HMODULE ImplGetModule(void) +{ + HMODULE hMod; + ULONG ObjNum; + CHAR Buff[2*_MAX_PATH]; + ULONG Offset; + APIRET rc; + + // get module handle (and name) + rc = DosQueryModFromEIP( &hMod, &ObjNum, sizeof( Buff), Buff, &Offset, (ULONG)ImplGetModule); + if (rc) + return NULL; + // return module handle + aSalShlData.mhMod = hMod; + return hMod; +} + +// ======================================================================= + +HPOINTER ImplLoadSalCursor( int nId ) +{ + DBG_ASSERT( aSalShlData.mhMod, "no DLL instance handle" ); + + HPOINTER hPointer = WinLoadPointer( HWND_DESKTOP, aSalShlData.mhMod, nId ); + + DBG_ASSERT( hPointer, "pointer not found in sal resource" ); +#if OSL_DEBUG_LEVEL>0 + if (!hPointer) + debug_printf( "ImplLoadSalCursor: pointer %d not found in sal resource\n", nId); +#endif + return hPointer; +} + +// ----------------------------------------------------------------------- + +BOOL ImplLoadSalIcon( int nId, HPOINTER& rIcon) +{ + DBG_ASSERT( aSalShlData.mhMod, "no DLL instance handle" ); + + SalData* pSalData = GetSalData(); + + // check the cache first + SalIcon *pSalIcon = pSalData->mpFirstIcon; + while( pSalIcon ) + { + if( pSalIcon->nId != nId ) + pSalIcon = pSalIcon->pNext; + else + { + rIcon = pSalIcon->hIcon; + return (rIcon != 0); + } + } + + // Try at first to load the icons from the application exe file + rIcon = WinLoadPointer( HWND_DESKTOP, NULL, nId ); + if ( !rIcon ) + { + // If the application don't provide these icons, then we try + // to load the icon from the VCL resource + rIcon = WinLoadPointer( HWND_DESKTOP, aSalShlData.mhMod, nId ); + } + + if( rIcon ) + { + // add to icon cache + pSalIcon = new SalIcon(); + pSalIcon->nId = nId; + pSalIcon->hIcon = rIcon; + pSalIcon->pNext = pSalData->mpFirstIcon; + pSalData->mpFirstIcon = pSalIcon; + } + + return (rIcon != 0); +} + +// ======================================================================= + diff --git a/vcl/os2/source/app/salsound.cxx b/vcl/os2/source/app/salsound.cxx new file mode 100644 index 000000000000..f42aee9b18fe --- /dev/null +++ b/vcl/os2/source/app/salsound.cxx @@ -0,0 +1,460 @@ +/************************************************************************* + * + * $RCSfile: salsound.cxx,v $ + * + * $Revision: 1.3 $ + * + * last change: $Author: vg $ $Date: 2007-09-20 16:06:17 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#define _SV_SALSOUND_CXX + +// ------------ +// - Includes - +// ------------ + +#include <string.h> + +#define INCL_DOSMODULEMGR +#include <svpm.h> + +#ifndef _SV_SALDATA_HXX +#include <saldata.hxx> +#endif +#ifndef _SV_SALINST_H +#include <salinst.h> +#endif +#ifndef _SV_SALSOUND_H +#include <salsound.h> +#endif + +#define INCL_MCIOS2 +#include <os2me.h> + +// --------- +// - Names - +// --------- + +#define SOUND_LIBNAME "MDM" +#define SOUND_PROCNAME "mciSendCommand" + +// ------------ +// - Fnc cast - +// ------------ + +typedef ULONG (_cdecl *SALMCIPROC)( USHORT nDeviceId, USHORT nMessage, ULONG nFlags, void* pParam, USHORT ); +#define MCIFNC ( (SALMCIPROC) Os2SalSound::mpMCIFnc ) + +// ----------------- +// - Statics init. - +// ----------------- + +HMODULE Os2SalSound::mhMCILib = 0; +ULONG Os2SalSound::mnSoundState = SOUND_STATE_UNLOADED; +void* Os2SalSound::mpMCIFnc = NULL; + +// ------------------- +// - Window-Callback - +// ------------------- + +MRESULT EXPENTRY SoundWndProc( HWND hWnd, ULONG nMsg, MPARAM nPar1, MPARAM nPar2 ) +{ + if( MM_MCINOTIFY == nMsg ) + { + USHORT nNotify = (USHORT)(ULONG) nPar1; + SoundNotification eNotification; + BOOL bNotify = TRUE; + + switch( nNotify ) + { + case( MCI_NOTIFY_SUCCESSFUL ): + eNotification = SOUND_NOTIFY_SUCCESS; + break; + + case( MCI_NOTIFY_ABORTED ): + eNotification = SOUND_NOTIFY_ABORTED; + break; + + case( MCI_NOTIFY_SUPERSEDED ): + bNotify = FALSE; + break; + + default: + eNotification = SOUND_NOTIFY_ERROR; + break; + } + + if( bNotify ) + ( (Os2SalSound*) WinQueryWindowULong( hWnd, 0 ) )->ImplNotify( eNotification, 0 ); + } + + return WinDefWindowProc( hWnd, nMsg, nPar1, nPar2 ); +} + +// ------------ +// - Os2SalSound - +// ------------ + +Os2SalSound::Os2SalSound() : + mpProc ( NULL ), + mhSoundWnd ( 0 ), + mnDeviceId ( 0 ), + mbLoop ( FALSE ), + mbPaused ( FALSE ) +{ +} + +// ------------------------------------------------------------------------ + +Os2SalSound::~Os2SalSound() +{ + Stop(); + + if( mnDeviceId ) + { + MCI_GENERIC_PARMS aGenericParams; + memset( &aGenericParams, 0, sizeof( aGenericParams ) ); + aGenericParams.hwndCallback = mhSoundWnd; + MCIFNC( mnDeviceId, MCI_CLOSE, MCI_WAIT, &aGenericParams, 0 ); + } + + if( mhSoundWnd ) + WinDestroyWindow( mhSoundWnd ); +} + +// ------------------------------------------------------------------------ + +void Os2SalSound::ImplSetError( ULONG nMciErr ) +{ + struct aMapper { DWORD nMci; ULONG nSv; }; + + ULONG nError = SOUNDERR_GENERAL_ERROR; + static aMapper aErrArr[] = + { + { 0, SOUNDERR_SUCCESS }, + { MCIERR_CANNOT_LOAD_DRIVER, SOUNDERR_CANNOT_LOAD_DRIVER }, + { MCIERR_DEVICE_LOCKED, SOUNDERR_DEVICE_LOCKED }, + { MCIERR_DEVICE_NOT_READY, SOUNDERR_DEVICE_NOT_READY }, + { MCIERR_DEVICE_TYPE_REQUIRED, SOUNDERR_DEVICE_NOT_FOUND }, + { MCIERR_DRIVER, SOUNDERR_CANNOT_LOAD_DRIVER }, + { MCIERR_DRIVER_INTERNAL, SOUNDERR_CANNOT_LOAD_DRIVER }, + { MCIERR_EXTENSION_NOT_FOUND, SOUNDERR_SOUND_NOT_FOUND }, + { MCIERR_FILE_NOT_FOUND, SOUNDERR_SOUND_NOT_FOUND }, + { MCIERR_HARDWARE, SOUNDERR_HARDWARE_ERROR }, + { MCIERR_INVALID_DEVICE_NAME, SOUNDERR_DEVICE_NOT_FOUND }, + { MCIERR_OUT_OF_MEMORY, SOUNDERR_OUT_OF_MEMORY }, + { MCIERR_UNSUPPORTED_FUNCTION, SOUNDERR_UNSUPPORTED_FUNCTION } + }; + + for( USHORT n=0; n < (sizeof( aErrArr ) / sizeof( aMapper ) ); n++ ) + { + if( aErrArr[ n ].nMci == nMciErr ) + { + nError = aErrArr[ n ].nSv; + break; + } + } + + if( nError ) + ImplNotify( SOUND_NOTIFY_ERROR, nError ); +} + +// ------------------------------------------------------------------------ + +void Os2SalSound::ImplNotify( SoundNotification eNotification, ULONG nError ) +{ + if( mbLoop && ( SOUND_NOTIFY_SUCCESS == eNotification ) && !nError ) + Play( mnStartTime, mnPlayLen, TRUE ); + + if( mpProc && mpInst ) + mpProc( mpInst, eNotification, nError ); +} + +// ------------------------------------------------------------------------ + +BOOL Os2SalSound::Create() +{ + SalData* pData = GetSalData(); + BOOL bRet = FALSE; + + if( SOUND_STATE_UNLOADED == Os2SalSound::mnSoundState ) + { + if( DosLoadModule( 0, 0, (PCSZ)SOUND_LIBNAME, &Os2SalSound::mhMCILib ) == 0 && + DosQueryProcAddr( Os2SalSound::mhMCILib, 0, (PCSZ)SOUND_PROCNAME, (PFN*) &Os2SalSound::mpMCIFnc ) == 0 ) + { + char* pszClassName = "SoundWin"; + PFNWP pWindowProc = SoundWndProc; + + WinRegisterClass( pData->mhAB, (PCSZ)pszClassName, pWindowProc, 0L, 4 ); + Os2SalSound::mnSoundState = SOUND_STATE_VALID; + bRet = TRUE; + } + else + { + if( Os2SalSound::mhMCILib ) + DosFreeModule( Os2SalSound::mhMCILib ); + + Os2SalSound::mnSoundState = SOUND_STATE_INVALID; + ImplNotify( SOUND_NOTIFY_ERROR, SOUNDERR_CANNOT_LOAD_DRIVER ); + } + } + else if( SOUND_STATE_VALID == Os2SalSound::mnSoundState ) + bRet = TRUE; + + if( bRet ) + { + mhSoundWnd = WinCreateWindow( HWND_OBJECT, (PCSZ)"SoundWin", (PCSZ)"Sound", 0, 0, 0, 0, 0, HWND_DESKTOP, HWND_BOTTOM, 0, 0, 0 ); + WinSetWindowULong( mhSoundWnd, 0, (ULONG) this ); + } + else + mhSoundWnd = 0; + + return bRet; +} + +// ------------------------------------------------------------------------ + +void Os2SalSound::Release() +{ + if( Os2SalSound::mhMCILib ) + DosFreeModule( Os2SalSound::mhMCILib ); + + Os2SalSound::mnSoundState = SOUND_STATE_UNLOADED; +} + +// ------------------------------------------------------------------------ + +bool Os2SalSound::IsValid() +{ + return (Os2SalSound::mnSoundState == SOUND_STATE_VALID); +} + +// ------------------------------------------------------------------------ + +bool Os2SalSound::Init( const XubString& rSoundName, ULONG& rSoundLen ) +{ + MCI_OPEN_PARMS aOpenParams; + ULONG nMciErr = 0; + + rSoundLen = 0; + + // clear old device + if( mnDeviceId ) + { + Stop(); + + MCI_GENERIC_PARMS aGenericParams; + memset( &aGenericParams, 0, sizeof( aGenericParams ) ); + aGenericParams.hwndCallback = mhSoundWnd; + nMciErr = MCIFNC( mnDeviceId, MCI_CLOSE, MCI_WAIT, &aGenericParams, 0 ); + mnDeviceId = 0; + } + + if( rSoundName.Len() ) + { + // init new device with sound name + memset( &aOpenParams, 0, sizeof( aOpenParams ) ); + aOpenParams.pszElementName = (PSZ) rSoundName.GetBuffer(); + aOpenParams.hwndCallback = mhSoundWnd; + nMciErr = MCIFNC( 0, MCI_OPEN, MCI_WAIT | MCI_OPEN_ELEMENT, &aOpenParams, 0 ); + + if( !nMciErr ) + { + // set time format + MCI_SET_PARMS aSetParams; + memset( &aSetParams, 0, sizeof( aSetParams ) ); + mnDeviceId = aOpenParams.usDeviceID; + aSetParams.ulTimeFormat = MCI_FORMAT_MILLISECONDS; + nMciErr = MCIFNC( mnDeviceId, MCI_SET, MCI_WAIT | MCI_SET_TIME_FORMAT, &aSetParams, 0 ); + + if( !nMciErr ) + { + // get length of sound + MCI_STATUS_PARMS aStatus; + memset( &aStatus, 0, sizeof( aStatus ) ); + aStatus.ulItem = MCI_STATUS_LENGTH; + MCIFNC( mnDeviceId, MCI_STATUS, MCI_WAIT | MCI_STATUS_ITEM, &aStatus, 0 ); + rSoundLen = (ULONG) aStatus.ulReturn; + } + } + } + + if( nMciErr ) + ImplSetError( nMciErr ); + + return( nMciErr ? FALSE : TRUE ); +} + +// ------------------------------------------------------------------------ +#if 0 +BOOL Os2SalSound::Init( SalFrame* pFrame, const BYTE* pSound, ULONG nDataLen, ULONG& rSoundLen ) +{ + rSoundLen = 0UL; + ImplSetError( MCIERR_FILE_NOT_FOUND ); + + return FALSE; +} +#endif + +// ------------------------------------------------------------------------ + +void Os2SalSound::Play( ULONG nStartTime, ULONG nPlayLen, bool bLoop ) +{ + if( mnDeviceId ) + { + ULONG nMciErr = 0; + + if( !mbPaused ) + { + MCI_SEEK_PARMS aSeekParams; + memset( &aSeekParams, 0, sizeof( aSeekParams ) ); + aSeekParams.hwndCallback = mhSoundWnd; + aSeekParams.ulTo = 0; + nMciErr = MCIFNC( mnDeviceId, MCI_SEEK,MCI_WAIT | MCI_TO, &aSeekParams, 0 ); + } + + mnStartTime = nStartTime; + mnPlayLen = nPlayLen; + mbLoop = bLoop; + mbPaused = FALSE; + + if( !nMciErr ) + { + MCI_PLAY_PARMS aPlayParams; + DWORD nFlags = MCI_NOTIFY; + + memset( &aPlayParams, 0, sizeof( aPlayParams ) ); + aPlayParams.hwndCallback = mhSoundWnd; + + if( nStartTime ) + { + aPlayParams.ulFrom = nStartTime; + nFlags |= MCI_FROM; + } + + if( nPlayLen != SOUND_PLAYALL ) + { + aPlayParams.ulTo = nStartTime + nPlayLen; + nFlags |= MCI_TO; + } + + nMciErr = MCIFNC( mnDeviceId, MCI_PLAY, nFlags, &aPlayParams, 0 ); + + if( !nMciErr ) + mbPaused = FALSE; + } + + if( nMciErr ) + ImplSetError( nMciErr ); + } + else + ImplSetError( MCIERR_EXTENSION_NOT_FOUND ); +} + +// ------------------------------------------------------------------------ + +void Os2SalSound::Stop() +{ + if( mnDeviceId ) + { + MCI_GENERIC_PARMS aGenericParams; + memset( &aGenericParams, 0, sizeof( aGenericParams ) ); + aGenericParams.hwndCallback = mhSoundWnd; + mbLoop = mbPaused = FALSE; + MCIFNC( mnDeviceId, MCI_STOP, MCI_WAIT, &aGenericParams, 0 ); + } +} + +// ------------------------------------------------------------------------ + +void Os2SalSound::Pause() +{ + if( mnDeviceId ) + { + MCI_GENERIC_PARMS aGenericParams; + memset( &aGenericParams, 0, sizeof( aGenericParams ) ); + aGenericParams.hwndCallback = mhSoundWnd; + mbPaused = TRUE; + MCIFNC( mnDeviceId, MCI_PAUSE, MCI_WAIT, &aGenericParams, 0 ); + } +} + +// ------------------------------------------------------------------------ + +void Os2SalSound::Continue() +{ + Play( 0, 0, mbLoop ); +} + +// ------------------------------------------------------------------------ + +bool Os2SalSound::IsLoopMode() const +{ + return mbLoop; +} + +// ------------------------------------------------------------------------ + +bool Os2SalSound::IsPlaying() const +{ + return !mbPaused; +} + +// ------------------------------------------------------------------------ + +bool Os2SalSound::IsPaused() const +{ + return mbPaused; +} diff --git a/vcl/os2/source/app/salsys.cxx b/vcl/os2/source/app/salsys.cxx new file mode 100644 index 000000000000..5b2d7a1b012b --- /dev/null +++ b/vcl/os2/source/app/salsys.cxx @@ -0,0 +1,287 @@ +/************************************************************************* + * + * $RCSfile: salsys.cxx,v $ + * + * $Revision: 1.3 $ + * + * last change: $Author: vg $ $Date: 2007-09-20 16:06:28 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#define _SV_SALSYS_CXX + +#include <string.h> + +#define INCL_DOS +#define INCL_DOSERRORS +#ifndef _SVPM_H +#include <svpm.h> +#endif +#ifndef _SV_SALDATA_HXX +#include <saldata.hxx> +#endif +#ifndef _SV_SALINST_HXX +#include <salinst.hxx> +#endif +#ifndef _SV_SALFRAME_HXX +#include <salframe.hxx> +#endif +#ifndef _SV_SALBMP_HXX +#include <salbmp.hxx> +#endif +#ifndef _SV_SALSYS_HXX +#include <salsys.hxx> +#endif +#ifndef _VOS_PROCESS_HXX +#include <vos/process.hxx> +#endif +#ifndef _TOOLS_FASTFSYS_HXX +#include <tools/fastfsys.hxx> +#endif + +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <ctype.h> + +// ======================================================================= + +SalSystem* SalInstance::CreateSystem() +{ + return new SalSystem(); +} + +// ----------------------------------------------------------------------- + +void SalInstance::DestroySystem( SalSystem* pSystem ) +{ + delete pSystem; +} + +// ----------------------------------------------------------------------- + +SalSystem::SalSystem() +{ +} + +// ----------------------------------------------------------------------- + +SalSystem::~SalSystem() +{ +} + +// ----------------------------------------------------------------------- + +BOOL SalSystem::StartProcess( SalFrame* pFrame, const XubString& rFileName, + const XubString& rParam, + const XubString& rWorkingDirectory ) +{ + ItemIDPath aFile(rFileName); + + // + // first check if item has a context menu with open command + // + + ItemIDPath aParent, aChild; + + if(aFile.Split(aParent, aChild)) + { + IfcContextMenu *pConMenu = Folder(aParent).GetContextMenu(1, &aChild); + + if(pConMenu) + { + UINT32 nCount = pConMenu->GetItemCount(); + + for(UINT32 n = 0; n < nCount; n++) + { + MenuItem aMenuItem; + + if(pConMenu->GetMenuItem(n, aMenuItem) && + aMenuItem.aVerb.Compare("open") == COMPARE_EQUAL) + { + return pConMenu->ExecuteCommand(aMenuItem.aCommand); + } + } + } + } + + // Dateinamen mit Wildcards lehnen wir ab + if ( (rFileName.Search( '*' ) != STRING_NOTFOUND) || + (rFileName.Search( '?' ) != STRING_NOTFOUND) ) + return FALSE; + + XubString aFileName = aFile.GetHostNotationPath(); + char* aStdExtAry[] = { "exe", "com", "cmd", "bat" }; + const char* pStdExt; + const xub_Unicode* pFileName = aFileName.GetStr(); + const xub_Unicode* pParam = rParam.GetStr(); + XubString aSearchFileName; + XubString aExt; + BOOL bExe = FALSE; + BOOL bProcess = FALSE; + BOOL bRet = FALSE; + BOOL bExtension; + int i; + + // Parameter und Extension ermitteln + if ( !rParam.Len() ) + pParam = NULL; + // Wenn keine Extension, dann versuchen wir eine zu ermitteln, + // indem wir nach EXE-, COM-, CMD- oder BAT-Dateien suchen. + bExtension = ImplSalGetExtension( aFileName, aExt ); + if ( !bExtension ) + { + i = 0; + do + { + pStdExt = aStdExtAry[i]; + aSearchFileName = aFileName; + aSearchFileName += '.'; + aSearchFileName += pStdExt; + if ( ImplSalFindFile( aSearchFileName.GetStr(), aSearchFileName ) ) + { + pFileName = aSearchFileName.GetStr(); + bExtension = ImplSalGetExtension( aSearchFileName, aExt ); + break; + } + i++; + } + while ( i < 4 ); + } + else + { + // Ansonsten Filename im Pfad suchen + if ( ImplSalFindFile( pFileName, aSearchFileName ) ) + { + pFileName = aSearchFileName.GetStr(); + bExtension = ImplSalGetExtension( aSearchFileName, aExt ); + } + } + // Wenn wir eine Extension haben, testen wir, ob es eine + // Standard-Extension ist, womit wir einen Process starten koennen + if ( bExtension ) + { + aExt.ToLower(); + i = 0; + do + { + if ( aExt == aStdExtAry[i] ) + { + bExe = TRUE; + break; + } + i++; + } + while ( i < 4 ); + } + + // change to path of executable if no working dir set + XubString aWorkingDir(rWorkingDirectory); + + if(aWorkingDir.Len() == 0) + { + USHORT nIndex; + + aWorkingDir = pFileName; + nIndex = aWorkingDir.SearchCharBackward("\\/:"); + + if(nIndex == STRING_NOTFOUND) + nIndex = 0; + else if(aWorkingDir.GetChar(nIndex) == ':') + aWorkingDir[nIndex++] = '\\'; + + aWorkingDir.Erase(nIndex); + } + + // start executables with process execute + if ( bExe ) + { + NAMESPACE_VOS( OProcess )::TProcessError nProcessError; + NAMESPACE_VOS( OProcess ) aProcess( pFileName, pParam ); + + aProcess.setDirectory(aWorkingDir.GetStr()); + + nProcessError = aProcess.execute( (NAMESPACE_VOS(OProcess)::TProcessOption) + (NAMESPACE_VOS(OProcess)::TOption_Detached) ); + bRet = nProcessError == NAMESPACE_VOS( OProcess )::E_None; + } + + // when not startet, start programm with WPS + if ( !bRet ) + { + HOBJECT hObject = WinQueryObject( pFileName ); + if ( hObject ) + { + if ( WinOpenObject( hObject, 0, FALSE ) ) + bRet = TRUE; + } + } + + return bRet; +} + +// ----------------------------------------------------------------------- + +BOOL SalSystem::AddRecentDoc( SalFrame* pFrame, const XubString& rFileName ) +{ + return FALSE; +} + +// ----------------------------------------------------------------------- + +String SalSystem::GetSummarySystemInfos( ULONG nFlags ) +{ + return String(); +} + |