2016-03-04 19:22:35 +00:00
|
|
|
/*
|
|
|
|
* Program Manager
|
|
|
|
*
|
|
|
|
* Copyright 1996 Ulrich Schmid
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
2016-05-11 22:21:53 +00:00
|
|
|
/*
|
|
|
|
* PROJECT: ReactOS Program Manager
|
|
|
|
* COPYRIGHT: GPL - See COPYING in the top level directory
|
|
|
|
* FILE: base/shell/progman/program.c
|
|
|
|
* PURPOSE: Program items helper functions
|
|
|
|
* PROGRAMMERS: Ulrich Schmid
|
|
|
|
* Hermes Belusca-Maito (hermes.belusca@sfr.fr)
|
|
|
|
*/
|
|
|
|
|
2016-03-04 19:22:35 +00:00
|
|
|
#include "progman.h"
|
|
|
|
|
2016-05-11 22:21:53 +00:00
|
|
|
#if 0
|
2016-03-04 19:22:35 +00:00
|
|
|
|
|
|
|
static LRESULT CALLBACK PROGRAM_ProgramWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
|
|
|
{
|
|
|
|
switch (msg)
|
|
|
|
{
|
|
|
|
case WM_NCLBUTTONDOWN:
|
|
|
|
{
|
|
|
|
HLOCAL hProgram = (HLOCAL) GetWindowLongPtrW(hWnd, 0);
|
|
|
|
PROGRAM *program = LocalLock(hProgram);
|
|
|
|
PROGGROUP *group = LocalLock(program->hGroup);
|
|
|
|
group->hActiveProgram = hProgram;
|
|
|
|
EnableMenuItem(Globals.hFileMenu, PM_MOVE , MF_ENABLED);
|
|
|
|
EnableMenuItem(Globals.hFileMenu, PM_COPY , MF_ENABLED);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case WM_NCLBUTTONDBLCLK:
|
|
|
|
{
|
|
|
|
PROGRAM_ExecuteProgram((HLOCAL) GetWindowLongPtrW(hWnd, 0));
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
case WM_PAINTICON:
|
|
|
|
case WM_NCPAINT:
|
|
|
|
{
|
|
|
|
PROGRAM *program;
|
|
|
|
PAINTSTRUCT ps;
|
|
|
|
HDC hdc;
|
|
|
|
hdc = BeginPaint(hWnd,&ps);
|
|
|
|
program = LocalLock((HLOCAL) GetWindowLongPtrW(hWnd, 0));
|
|
|
|
if (program->hIcon)
|
|
|
|
DrawIcon(hdc, 0, 0, program->hIcon);
|
|
|
|
EndPaint(hWnd,&ps);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return DefWindowProcW(hWnd, msg, wParam, lParam);
|
|
|
|
}
|
|
|
|
|
2016-05-11 22:21:53 +00:00
|
|
|
#endif
|
|
|
|
|
2016-03-04 19:22:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
*
|
|
|
|
* PROGRAM_NewProgram
|
|
|
|
*/
|
|
|
|
|
2016-05-11 22:21:53 +00:00
|
|
|
VOID PROGRAM_NewProgram(PROGGROUP* hGroup)
|
2016-03-04 19:22:35 +00:00
|
|
|
{
|
2016-05-11 22:21:53 +00:00
|
|
|
HICON hIcon = NULL;
|
|
|
|
INT nIconIndex = 0;
|
|
|
|
INT nHotKey = 0;
|
|
|
|
INT nCmdShow = SW_SHOWNORMAL;
|
|
|
|
BOOL bNewVDM = FALSE;
|
|
|
|
WCHAR szTitle[MAX_PATHNAME_LEN] = L"";
|
|
|
|
WCHAR szCmdLine[MAX_PATHNAME_LEN] = L"";
|
|
|
|
WCHAR szIconFile[MAX_PATHNAME_LEN] = L"";
|
|
|
|
WCHAR szWorkDir[MAX_PATHNAME_LEN] = L"";
|
|
|
|
|
|
|
|
if (!DIALOG_ProgramAttributes(szTitle, szCmdLine, szWorkDir, szIconFile,
|
|
|
|
&hIcon, &nIconIndex, &nHotKey, &nCmdShow, &bNewVDM,
|
|
|
|
MAX_PATHNAME_LEN))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2016-03-04 19:22:35 +00:00
|
|
|
|
2016-05-11 22:21:53 +00:00
|
|
|
if (!hIcon)
|
|
|
|
hIcon = LoadIconW(NULL, MAKEINTRESOURCEW(IDI_WINLOGO));
|
2016-03-04 19:22:35 +00:00
|
|
|
|
2016-05-11 22:21:53 +00:00
|
|
|
if (!PROGRAM_AddProgram(hGroup, hIcon, szTitle, -1, -1, szCmdLine, szIconFile,
|
|
|
|
nIconIndex, szWorkDir, nHotKey, nCmdShow, bNewVDM))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2016-03-04 19:22:35 +00:00
|
|
|
|
2016-05-11 22:21:53 +00:00
|
|
|
GRPFILE_WriteGroupFile(hGroup);
|
2016-03-04 19:22:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
*
|
|
|
|
* PROGRAM_ModifyProgram
|
|
|
|
*/
|
|
|
|
|
2016-05-11 22:21:53 +00:00
|
|
|
VOID PROGRAM_ModifyProgram(PROGRAM* hProgram)
|
2016-03-04 19:22:35 +00:00
|
|
|
{
|
2016-05-11 22:21:53 +00:00
|
|
|
LVITEMW lvItem;
|
|
|
|
WCHAR szName[MAX_PATHNAME_LEN];
|
|
|
|
WCHAR szWorkDir[MAX_PATHNAME_LEN];
|
|
|
|
WCHAR szCmdLine[MAX_PATHNAME_LEN];
|
|
|
|
WCHAR szIconFile[MAX_PATHNAME_LEN];
|
|
|
|
|
|
|
|
lstrcpynW(szName , hProgram->hName , ARRAYSIZE(szName));
|
|
|
|
lstrcpynW(szCmdLine , hProgram->hCmdLine , ARRAYSIZE(szCmdLine));
|
|
|
|
lstrcpynW(szIconFile, hProgram->hIconFile, ARRAYSIZE(szIconFile));
|
|
|
|
lstrcpynW(szWorkDir , hProgram->hWorkDir , ARRAYSIZE(szWorkDir));
|
|
|
|
|
|
|
|
if (!DIALOG_ProgramAttributes(szName, szCmdLine, szWorkDir, szIconFile,
|
|
|
|
&hProgram->hIcon, &hProgram->nIconIndex,
|
|
|
|
&hProgram->nHotKey, &hProgram->nCmdShow,
|
|
|
|
&hProgram->bNewVDM, MAX_PATHNAME_LEN))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
MAIN_ReplaceString(&hProgram->hName , szName);
|
|
|
|
MAIN_ReplaceString(&hProgram->hCmdLine , szCmdLine);
|
|
|
|
MAIN_ReplaceString(&hProgram->hIconFile, szIconFile);
|
|
|
|
MAIN_ReplaceString(&hProgram->hWorkDir , szWorkDir);
|
|
|
|
|
|
|
|
ZeroMemory(&lvItem, sizeof(lvItem));
|
|
|
|
lvItem.mask = LVIF_TEXT;
|
|
|
|
lvItem.iSubItem = 0;
|
|
|
|
lvItem.pszText = szName;
|
|
|
|
SendMessageW(hProgram->hGroup->hListView, LVM_SETITEMTEXTW, hProgram->iItem, (LPARAM)&lvItem);
|
|
|
|
|
|
|
|
GRPFILE_WriteGroupFile(hProgram->hGroup);
|
2016-03-04 19:22:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
*
|
|
|
|
* PROGRAM_AddProgram
|
|
|
|
*/
|
|
|
|
|
2016-05-11 22:21:53 +00:00
|
|
|
PROGRAM*
|
|
|
|
PROGRAM_AddProgram(PROGGROUP* hGroup, HICON hIcon, LPCWSTR lpszName,
|
|
|
|
INT x, INT y, LPCWSTR lpszCmdLine, LPCWSTR lpszIconFile, INT nIconIndex,
|
|
|
|
LPCWSTR lpszWorkDir, INT nHotKey, INT nCmdShow, BOOL bNewVDM)
|
2016-03-04 19:22:35 +00:00
|
|
|
{
|
2016-05-11 22:21:53 +00:00
|
|
|
PROGRAM* hProgram;
|
|
|
|
PROGRAM* hPrior;
|
|
|
|
PROGRAM** p;
|
|
|
|
LPWSTR hCmdLine;
|
|
|
|
LPWSTR hIconFile;
|
|
|
|
LPWSTR hName;
|
|
|
|
LPWSTR hWorkDir;
|
|
|
|
LVITEMW lvItem;
|
|
|
|
INT iItem;
|
|
|
|
|
|
|
|
hProgram = Alloc(HEAP_ZERO_MEMORY, sizeof(*hProgram));
|
|
|
|
hName = Alloc(HEAP_ZERO_MEMORY, (wcslen(lpszName) + 1) * sizeof(WCHAR));
|
|
|
|
hCmdLine = Alloc(HEAP_ZERO_MEMORY, (wcslen(lpszCmdLine) + 1) * sizeof(WCHAR));
|
|
|
|
hIconFile = Alloc(HEAP_ZERO_MEMORY, (wcslen(lpszIconFile) + 1) * sizeof(WCHAR));
|
|
|
|
hWorkDir = Alloc(HEAP_ZERO_MEMORY, (wcslen(lpszWorkDir) + 1) * sizeof(WCHAR));
|
|
|
|
if (!hProgram || !hName || !hCmdLine || !hIconFile || !hWorkDir)
|
2016-03-04 19:22:35 +00:00
|
|
|
{
|
2016-05-11 22:21:53 +00:00
|
|
|
MAIN_MessageBoxIDS(IDS_OUT_OF_MEMORY, IDS_ERROR, MB_OK);
|
|
|
|
if (hProgram) Free(hProgram);
|
|
|
|
if (hName) Free(hName);
|
|
|
|
if (hCmdLine) Free(hCmdLine);
|
|
|
|
if (hIconFile) Free(hIconFile);
|
|
|
|
if (hWorkDir) Free(hWorkDir);
|
|
|
|
return NULL;
|
2016-03-04 19:22:35 +00:00
|
|
|
}
|
2016-05-11 22:21:53 +00:00
|
|
|
memcpy(hName , lpszName , (wcslen(lpszName) + 1) * sizeof(WCHAR));
|
|
|
|
memcpy(hCmdLine , lpszCmdLine , (wcslen(lpszCmdLine) + 1) * sizeof(WCHAR));
|
|
|
|
memcpy(hIconFile, lpszIconFile, (wcslen(lpszIconFile) + 1) * sizeof(WCHAR));
|
|
|
|
memcpy(hWorkDir , lpszWorkDir , (wcslen(lpszWorkDir) + 1) * sizeof(WCHAR));
|
|
|
|
|
|
|
|
hGroup->hActiveProgram = hProgram;
|
|
|
|
|
|
|
|
hPrior = NULL;
|
|
|
|
for (p = &hGroup->hPrograms; *p; p = &hPrior->hNext)
|
|
|
|
hPrior = *p;
|
|
|
|
*p = hProgram;
|
|
|
|
|
|
|
|
hProgram->hGroup = hGroup;
|
|
|
|
hProgram->hPrior = hPrior;
|
|
|
|
hProgram->hNext = NULL;
|
|
|
|
hProgram->hName = hName;
|
|
|
|
hProgram->hCmdLine = hCmdLine;
|
|
|
|
hProgram->hIconFile = hIconFile;
|
|
|
|
hProgram->nIconIndex = nIconIndex;
|
|
|
|
hProgram->hWorkDir = hWorkDir;
|
|
|
|
hProgram->hIcon = hIcon;
|
|
|
|
hProgram->nCmdShow = nCmdShow;
|
|
|
|
hProgram->nHotKey = nHotKey;
|
|
|
|
hProgram->bNewVDM = bNewVDM;
|
|
|
|
hProgram->TagsSize = 0;
|
|
|
|
hProgram->Tags = NULL;
|
|
|
|
|
|
|
|
ZeroMemory(&lvItem, sizeof(lvItem));
|
|
|
|
lvItem.mask = LVIF_PARAM | LVIF_IMAGE | LVIF_TEXT;
|
|
|
|
lvItem.pszText = (LPWSTR)lpszName;
|
|
|
|
lvItem.lParam = (LPARAM)hProgram;
|
|
|
|
lvItem.iImage = ImageList_ReplaceIcon(hGroup->hListLarge, -1, hIcon);
|
|
|
|
DestroyIcon(hIcon);
|
|
|
|
|
|
|
|
lvItem.iItem = SendMessageA(hGroup->hListView, LVM_GETITEMCOUNT, 0, 0);
|
|
|
|
iItem = SendMessageW(hGroup->hListView, LVM_INSERTITEMW, 0, (LPARAM)&lvItem);
|
|
|
|
hProgram->iItem = iItem;
|
|
|
|
if (x != -1 && y != -1)
|
|
|
|
SendMessageA(hGroup->hListView, LVM_SETITEMPOSITION, lvItem.iItem, MAKELPARAM(x, y));
|
|
|
|
|
|
|
|
return hProgram;
|
|
|
|
}
|
2016-03-04 19:22:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
*
|
|
|
|
* PROGRAM_CopyMoveProgram
|
|
|
|
*/
|
|
|
|
|
2016-05-11 22:21:53 +00:00
|
|
|
VOID PROGRAM_CopyMoveProgram(PROGRAM* hProgram, BOOL bMove)
|
2016-03-04 19:22:35 +00:00
|
|
|
{
|
2016-05-11 22:21:53 +00:00
|
|
|
PROGGROUP* hGroup;
|
|
|
|
|
|
|
|
hGroup = DIALOG_CopyMove(hProgram, bMove);
|
|
|
|
if (!hGroup)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* FIXME: shouldn't be necessary */
|
|
|
|
OpenIcon(hGroup->hWnd);
|
|
|
|
|
|
|
|
if (!PROGRAM_AddProgram(hGroup,
|
|
|
|
hProgram->hIcon,
|
|
|
|
hProgram->hName,
|
|
|
|
hProgram->x,
|
|
|
|
hProgram->y,
|
|
|
|
hProgram->hCmdLine,
|
|
|
|
hProgram->hIconFile,
|
|
|
|
hProgram->nIconIndex,
|
|
|
|
hProgram->hWorkDir,
|
|
|
|
hProgram->nHotKey,
|
|
|
|
hProgram->nCmdShow,
|
|
|
|
hProgram->bNewVDM))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2016-03-04 19:22:35 +00:00
|
|
|
|
2016-05-11 22:21:53 +00:00
|
|
|
GRPFILE_WriteGroupFile(hGroup);
|
2016-03-04 19:22:35 +00:00
|
|
|
|
2016-05-11 22:21:53 +00:00
|
|
|
if (bMove)
|
|
|
|
PROGRAM_DeleteProgram(hProgram, TRUE);
|
2016-03-04 19:22:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
*
|
|
|
|
* PROGRAM_ExecuteProgram
|
|
|
|
*/
|
|
|
|
|
2016-05-11 22:21:53 +00:00
|
|
|
VOID PROGRAM_ExecuteProgram(PROGRAM* hProgram)
|
2016-03-04 19:22:35 +00:00
|
|
|
{
|
2016-05-11 22:21:53 +00:00
|
|
|
// TODO: Use a (private?) shell API with which one can use hProgram->bNewVDM
|
2016-03-04 19:22:35 +00:00
|
|
|
|
2016-05-11 22:21:53 +00:00
|
|
|
ShellExecuteW(NULL, NULL, hProgram->hCmdLine, NULL, hProgram->hWorkDir, hProgram->nCmdShow);
|
2016-03-04 19:22:35 +00:00
|
|
|
|
2016-05-11 22:21:53 +00:00
|
|
|
if (Globals.bMinOnRun)
|
|
|
|
CloseWindow(Globals.hMainWnd);
|
2016-03-04 19:22:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
*
|
|
|
|
* PROGRAM_DeleteProgram
|
|
|
|
*/
|
|
|
|
|
2016-05-11 22:21:53 +00:00
|
|
|
VOID PROGRAM_DeleteProgram(PROGRAM* hProgram, BOOL bUpdateGrpFile)
|
2016-03-04 19:22:35 +00:00
|
|
|
{
|
2016-05-11 22:21:53 +00:00
|
|
|
PROGGROUP* group;
|
|
|
|
|
|
|
|
group = hProgram->hGroup;
|
|
|
|
if (hProgram->hGroup->hActiveProgram == hProgram)
|
|
|
|
group->hActiveProgram = NULL;
|
2016-03-04 19:22:35 +00:00
|
|
|
|
2016-05-11 22:21:53 +00:00
|
|
|
SendMessageA(group->hListView, LVM_DELETEITEM, hProgram->iItem, 0);
|
2016-03-04 19:22:35 +00:00
|
|
|
|
2016-05-11 22:21:53 +00:00
|
|
|
if (hProgram->hPrior)
|
|
|
|
hProgram->hPrior->hNext = hProgram->hNext;
|
|
|
|
else
|
|
|
|
hProgram->hGroup->hPrograms = hProgram->hNext;
|
2016-03-04 19:22:35 +00:00
|
|
|
|
2016-05-11 22:21:53 +00:00
|
|
|
if (hProgram->hNext)
|
|
|
|
hProgram->hNext->hPrior = hProgram->hPrior;
|
2016-03-04 19:22:35 +00:00
|
|
|
|
2016-05-11 22:21:53 +00:00
|
|
|
if (bUpdateGrpFile)
|
|
|
|
GRPFILE_WriteGroupFile(hProgram->hGroup);
|
2016-03-04 19:22:35 +00:00
|
|
|
|
|
|
|
#if 0
|
2016-05-11 22:21:53 +00:00
|
|
|
DestroyWindow(program->hWnd);
|
|
|
|
if (program->hIcon)
|
|
|
|
DestroyIcon(program->hIcon);
|
2016-03-04 19:22:35 +00:00
|
|
|
#endif
|
|
|
|
|
2016-05-11 22:21:53 +00:00
|
|
|
if (hProgram->Tags)
|
|
|
|
Free(hProgram->Tags);
|
|
|
|
Free(hProgram->hName);
|
|
|
|
Free(hProgram->hCmdLine);
|
|
|
|
Free(hProgram->hIconFile);
|
|
|
|
Free(hProgram->hWorkDir);
|
|
|
|
Free(hProgram);
|
2016-03-04 19:22:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
*
|
|
|
|
* PROGRAM_ActiveProgram
|
|
|
|
*/
|
|
|
|
|
2016-05-11 22:21:53 +00:00
|
|
|
PROGRAM* PROGRAM_ActiveProgram(PROGGROUP* hGroup)
|
2016-03-04 19:22:35 +00:00
|
|
|
{
|
2016-05-11 22:21:53 +00:00
|
|
|
if (!hGroup) return NULL;
|
|
|
|
if (IsIconic(hGroup->hWnd)) return NULL;
|
|
|
|
return hGroup->hActiveProgram;
|
2016-03-04 19:22:35 +00:00
|
|
|
}
|