4 * Copyright 1996 Ulrich Schmid
12 /***********************************************************************
14 * PROGRAM_ProgramWndProc
17 static LRESULT
PROGRAM_ProgramWndProc (HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
21 case WM_NCLBUTTONDOWN
:
23 HLOCAL hProgram
= (HLOCAL
) GetWindowLong(hWnd
, 0);
24 PROGRAM
*program
= LocalLock(hProgram
);
25 GROUP
*group
= LocalLock(program
->hGroup
);
26 group
->hActiveProgram
= hProgram
;
27 EnableMenuItem(Globals
.hFileMenu
, PM_MOVE
, MF_ENABLED
);
28 EnableMenuItem(Globals
.hFileMenu
, PM_COPY
, MF_ENABLED
);
31 case WM_NCLBUTTONDBLCLK
:
33 PROGRAM_ExecuteProgram((HLOCAL
) GetWindowLong(hWnd
, 0));
43 hdc
= BeginPaint(hWnd
,&ps
);
44 program
= LocalLock((HLOCAL
) GetWindowLong(hWnd
, 0));
46 DrawIcon(hdc
, 0, 0, program
->hIcon
);
51 return(DefWindowProc(hWnd
, msg
, wParam
, lParam
));
54 /***********************************************************************
56 * PROGRAM_RegisterProgramWinClass
59 ATOM
PROGRAM_RegisterProgramWinClass()
63 class.style
= CS_HREDRAW
| CS_VREDRAW
;
64 class.lpfnWndProc
= PROGRAM_ProgramWndProc
;
66 class.cbWndExtra
= sizeof(LONG
);
67 class.hInstance
= Globals
.hInstance
;
69 class.hCursor
= LoadCursor (0, IDC_ARROW
);
70 class.hbrBackground
= GetStockObject (WHITE_BRUSH
);
71 class.lpszMenuName
= 0;
72 class.lpszClassName
= STRING_PROGRAM_WIN_CLASS_NAME
;
74 return RegisterClass(&class);
77 /***********************************************************************
82 VOID
PROGRAM_NewProgram(HLOCAL hGroup
)
84 INT nCmdShow
= SW_SHOWNORMAL
;
87 CHAR szName
[MAX_PATHNAME_LEN
] = "";
88 CHAR szCmdLine
[MAX_PATHNAME_LEN
] = "";
89 CHAR szIconFile
[MAX_PATHNAME_LEN
] = "";
90 CHAR szWorkDir
[MAX_PATHNAME_LEN
] = "";
93 if (!DIALOG_ProgramAttributes(szName
, szCmdLine
, szWorkDir
, szIconFile
,
94 &hIcon
, &nIconIndex
, &nHotKey
,
95 &nCmdShow
, MAX_PATHNAME_LEN
))
98 if (!hIcon
) hIcon
= LoadIcon(0, MAKEINTRESOURCE(OIC_WINEICON
));
101 if (!PROGRAM_AddProgram(hGroup
, hIcon
, szName
, 0, 0, szCmdLine
, szIconFile
,
102 nIconIndex
, szWorkDir
, nHotKey
, nCmdShow
))
105 GRPFILE_WriteGroupFile(hGroup
);
108 /***********************************************************************
110 * PROGRAM_ModifyProgram
113 VOID
PROGRAM_ModifyProgram(HLOCAL hProgram
)
115 PROGRAM
*program
= LocalLock(hProgram
);
116 CHAR szName
[MAX_PATHNAME_LEN
];
117 CHAR szCmdLine
[MAX_PATHNAME_LEN
];
118 CHAR szIconFile
[MAX_PATHNAME_LEN
];
119 CHAR szWorkDir
[MAX_PATHNAME_LEN
];
121 lstrcpyn(szName
, LocalLock(program
->hName
), MAX_PATHNAME_LEN
);
122 lstrcpyn(szCmdLine
, LocalLock(program
->hCmdLine
), MAX_PATHNAME_LEN
);
123 lstrcpyn(szIconFile
, LocalLock(program
->hIconFile
), MAX_PATHNAME_LEN
);
124 lstrcpyn(szWorkDir
, LocalLock(program
->hWorkDir
), MAX_PATHNAME_LEN
);
126 if (!DIALOG_ProgramAttributes(szName
, szCmdLine
, szWorkDir
, szIconFile
,
127 &program
->hIcon
, &program
->nIconIndex
,
128 &program
->nHotKey
, &program
->nCmdShow
,
132 MAIN_ReplaceString(&program
->hName
, szName
);
133 MAIN_ReplaceString(&program
->hCmdLine
, szCmdLine
);
134 MAIN_ReplaceString(&program
->hIconFile
, szIconFile
);
135 MAIN_ReplaceString(&program
->hWorkDir
, szWorkDir
);
137 SetWindowText(program
->hWnd
, szName
);
138 UpdateWindow(program
->hWnd
);
140 GRPFILE_WriteGroupFile(program
->hGroup
);
145 /***********************************************************************
150 HLOCAL
PROGRAM_AddProgram(HLOCAL hGroup
, HICON hIcon
, LPCSTR lpszName
,
151 INT x
, INT y
, LPCSTR lpszCmdLine
,
152 LPCSTR lpszIconFile
, INT nIconIndex
,
153 LPCSTR lpszWorkDir
, INT nHotKey
, INT nCmdShow
)
155 GROUP
*group
= LocalLock(hGroup
);
158 HLOCAL hProgram
= LocalAlloc(LMEM_FIXED
, sizeof(PROGRAM
));
159 HLOCAL hName
= LocalAlloc(LMEM_FIXED
, 1 + lstrlen(lpszName
));
160 HLOCAL hCmdLine
= LocalAlloc(LMEM_FIXED
, 1 + lstrlen(lpszCmdLine
));
161 HLOCAL hIconFile
= LocalAlloc(LMEM_FIXED
, 1 + lstrlen(lpszIconFile
));
162 HLOCAL hWorkDir
= LocalAlloc(LMEM_FIXED
, 1 + lstrlen(lpszWorkDir
));
163 if (!hProgram
|| !hName
|| !hCmdLine
|| !hIconFile
|| !hWorkDir
)
165 MAIN_MessageBoxIDS(IDS_OUT_OF_MEMORY
, IDS_ERROR
, MB_OK
);
166 if (hProgram
) LocalFree(hProgram
);
167 if (hName
) LocalFree(hName
);
168 if (hCmdLine
) LocalFree(hCmdLine
);
169 if (hIconFile
) LocalFree(hIconFile
);
170 if (hWorkDir
) LocalFree(hWorkDir
);
173 hmemcpy16(LocalLock(hName
), lpszName
, 1 + lstrlen(lpszName
));
174 hmemcpy16(LocalLock(hCmdLine
), lpszCmdLine
, 1 + lstrlen(lpszCmdLine
));
175 hmemcpy16(LocalLock(hIconFile
), lpszIconFile
, 1 + lstrlen(lpszIconFile
));
176 hmemcpy16(LocalLock(hWorkDir
), lpszWorkDir
, 1 + lstrlen(lpszWorkDir
));
178 group
->hActiveProgram
= hProgram
;
181 p
= &group
->hPrograms
;
185 p
= &((PROGRAM
*)LocalLock(hPrior
))->hNext
;
189 program
= LocalLock(hProgram
);
190 program
->hGroup
= hGroup
;
191 program
->hPrior
= hPrior
;
193 program
->hName
= hName
;
194 program
->hCmdLine
= hCmdLine
;
195 program
->hIconFile
= hIconFile
;
196 program
->nIconIndex
= nIconIndex
;
197 program
->hWorkDir
= hWorkDir
;
198 program
->hIcon
= hIcon
;
199 program
->nCmdShow
= nCmdShow
;
200 program
->nHotKey
= nHotKey
;
203 CreateWindow (STRING_PROGRAM_WIN_CLASS_NAME
, (LPSTR
)lpszName
,
204 WS_CHILD
| WS_CAPTION
,
205 x
, y
, CW_USEDEFAULT
, CW_USEDEFAULT
,
206 group
->hWnd
, 0, Globals
.hInstance
, 0);
208 SetWindowLong(program
->hWnd
, 0, (LONG
) hProgram
);
210 ShowWindow (program
->hWnd
, SW_SHOWMINIMIZED
);
211 SetWindowPos (program
->hWnd
, 0, x
, y
, 0, 0, SWP_NOZORDER
| SWP_NOACTIVATE
| SWP_NOSIZE
);
212 UpdateWindow (program
->hWnd
);
217 /***********************************************************************
219 * PROGRAM_CopyMoveProgram
222 VOID
PROGRAM_CopyMoveProgram(HLOCAL hProgram
, BOOL bMove
)
224 PROGRAM
*program
= LocalLock(hProgram
);
225 GROUP
*fromgroup
= LocalLock(program
->hGroup
);
226 HLOCAL hGroup
= DIALOG_CopyMove(LocalLock(program
->hName
),
227 LocalLock(fromgroup
->hName
), bMove
);
230 /* FIXME shouldn't be necessary */
231 OpenIcon(((GROUP
*)LocalLock(hGroup
))->hWnd
);
233 if (!PROGRAM_AddProgram(hGroup
,
235 CopyIcon(program
->hIcon
),
239 LocalLock(program
->hName
),
240 program
->x
, program
->y
,
241 LocalLock(program
->hCmdLine
),
242 LocalLock(program
->hIconFile
),
244 LocalLock(program
->hWorkDir
),
245 program
->nHotKey
, program
->nCmdShow
)) return;
246 GRPFILE_WriteGroupFile(hGroup
);
248 if (bMove
) PROGRAM_DeleteProgram(hProgram
, TRUE
);
251 /***********************************************************************
253 * PROGRAM_ExecuteProgram
256 VOID
PROGRAM_ExecuteProgram(HLOCAL hProgram
)
258 PROGRAM
*program
= LocalLock(hProgram
);
259 LPSTR lpszCmdLine
= LocalLock(program
->hCmdLine
);
260 LPSTR lpszWorkDir
= LocalLock(program
->hWorkDir
);
262 /* FIXME set working directory */
263 lpszWorkDir
= lpszWorkDir
;
265 WinExec(lpszCmdLine
, program
->nCmdShow
);
266 if (Globals
.bMinOnRun
) CloseWindow(Globals
.hMainWnd
);
269 /***********************************************************************
271 * PROGRAM_DeleteProgram
274 VOID
PROGRAM_DeleteProgram(HLOCAL hProgram
, BOOL bUpdateGrpFile
)
276 PROGRAM
*program
= LocalLock(hProgram
);
277 GROUP
*group
= LocalLock(program
->hGroup
);
279 group
->hActiveProgram
= 0;
282 ((PROGRAM
*)LocalLock(program
->hPrior
))->hNext
= program
->hNext
;
284 ((GROUP
*)LocalLock(program
->hGroup
))->hPrograms
= program
->hNext
;
287 ((PROGRAM
*)LocalLock(program
->hNext
))->hPrior
= program
->hPrior
;
290 GRPFILE_WriteGroupFile(program
->hGroup
);
292 DestroyWindow(program
->hWnd
);
295 DestroyIcon(program
->hIcon
);
297 LocalFree(program
->hName
);
298 LocalFree(program
->hCmdLine
);
299 LocalFree(program
->hIconFile
);
300 LocalFree(program
->hWorkDir
);
304 /***********************************************************************
306 * PROGRAM_FirstProgram
309 HLOCAL
PROGRAM_FirstProgram(HLOCAL hGroup
)
312 if (!hGroup
) return(0);
313 group
= LocalLock(hGroup
);
314 return(group
->hPrograms
);
317 /***********************************************************************
319 * PROGRAM_NextProgram
322 HLOCAL
PROGRAM_NextProgram(HLOCAL hProgram
)
325 if (!hProgram
) return(0);
326 program
= LocalLock(hProgram
);
327 return(program
->hNext
);
330 /***********************************************************************
332 * PROGRAM_ActiveProgram
335 HLOCAL
PROGRAM_ActiveProgram(HLOCAL hGroup
)
338 if (!hGroup
) return(0);
339 group
= LocalLock(hGroup
);
340 if (IsIconic(group
->hWnd
)) return(0);
342 return(group
->hActiveProgram
);
345 /***********************************************************************
347 * PROGRAM_ProgramName
350 LPCSTR
PROGRAM_ProgramName(HLOCAL hProgram
)
353 if (!hProgram
) return(0);
354 program
= LocalLock(hProgram
);
355 return(LocalLock(program
->hName
));
358 /* Local Variables: */
359 /* c-file-style: "GNU" */