2 * PROJECT: ReactOS Applications Manager
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: base/applications/rapps/winmain.c
5 * PURPOSE: Main program
6 * PROGRAMMERS: Dmitry Chapyshev (dmitry@reactos.org)
13 HIMAGELIST hImageListView
= NULL
;
14 HIMAGELIST hImageTreeView
= NULL
;
15 INT SelectedEnumType
= ENUM_ALL_COMPONENTS
;
20 EnumInstalledAppProc(INT ItemIndex
, LPWSTR lpName
, LPWSTR lpKeyName
, LPARAM lParam
)
22 WCHAR szText
[MAX_PATH
];
25 Index
= ListViewAddItem(ItemIndex
, 0, lpName
, lParam
);
27 /* Get version info */
28 GetApplicationString((HKEY
)lParam
, L
"DisplayVersion", szText
);
29 ListView_SetItemText(hListView
, Index
, 1, szText
);
31 GetApplicationString((HKEY
)lParam
, L
"Comments", szText
);
32 ListView_SetItemText(hListView
, Index
, 2, szText
);
38 FreeAvailableAppList(VOID
)
40 INT Count
= ListView_GetItemCount(hListView
) - 1;
45 Info
= ListViewGetlParam(Count
);
47 HeapFree(GetProcessHeap(), 0, Info
);
54 EnumAvailableAppProc(APPLICATION_INFO Info
)
56 PAPPLICATION_INFO ItemInfo
;
59 if (!IsInstalledApplication(Info
.szRegName
))
61 ItemInfo
= HeapAlloc(GetProcessHeap(), 0, sizeof(APPLICATION_INFO
));
62 if (!ItemInfo
) return FALSE
;
66 Index
= ListViewAddItem(Info
.Category
, 0, Info
.szName
, (LPARAM
)ItemInfo
);
67 ListView_SetItemText(hListView
, Index
, 1, Info
.szVersion
);
68 ListView_SetItemText(hListView
, Index
, 2, Info
.szDesc
);
75 UpdateApplicationsList(INT EnumType
)
77 WCHAR szBuffer1
[MAX_STR_LEN
], szBuffer2
[MAX_STR_LEN
];
80 if (hImageListView
) ImageList_Destroy(hImageListView
);
81 (VOID
) ListView_DeleteAllItems(hListView
);
83 /* Create image list */
84 hImageListView
= ImageList_Create(LISTVIEW_ICON_SIZE
,
86 GetSystemColorDepth() | ILC_MASK
,
89 hIcon
= LoadImage(hInst
,
90 MAKEINTRESOURCE(IDI_MAIN
),
96 ImageList_AddIcon(hImageListView
, hIcon
);
99 if (EnumType
== -1) EnumType
= SelectedEnumType
;
101 if (IS_INSTALLED_ENUM(EnumType
))
103 /* Enum installed applications and updates */
104 EnumInstalledApplications(EnumType
, EnumInstalledAppProc
);
106 else if (IS_AVAILABLE_ENUM(EnumType
))
108 if (IS_AVAILABLE_ENUM(SelectedEnumType
))
109 FreeAvailableAppList();
111 /* Enum availabled applications */
112 EnumAvailableApplications(EnumType
, EnumAvailableAppProc
);
115 /* Set image list for ListView */
116 (VOID
) ListView_SetImageList(hListView
, hImageListView
, LVSIL_SMALL
);
118 SelectedEnumType
= EnumType
;
120 LoadStringW(hInst
, IDS_APPS_COUNT
, szBuffer2
, sizeof(szBuffer2
) / sizeof(WCHAR
));
121 swprintf(szBuffer1
, szBuffer2
, ListView_GetItemCount(hListView
));
122 SetStatusBarText(szBuffer1
);
128 InitApplicationsList(VOID
)
130 WCHAR szText
[MAX_STR_LEN
];
132 /* Add columns to ListView */
133 LoadStringW(hInst
, IDS_APP_NAME
, szText
, sizeof(szText
) / sizeof(WCHAR
));
134 ListViewAddColumn(0, szText
, 200, LVCFMT_LEFT
);
136 LoadStringW(hInst
, IDS_APP_INST_VERSION
, szText
, sizeof(szText
) / sizeof(WCHAR
));
137 ListViewAddColumn(1, szText
, 90, LVCFMT_RIGHT
);
139 LoadStringW(hInst
, IDS_APP_DESCRIPTION
, szText
, sizeof(szText
) / sizeof(WCHAR
));
140 ListViewAddColumn(3, szText
, 250, LVCFMT_LEFT
);
142 UpdateApplicationsList(ENUM_ALL_COMPONENTS
);
146 AddCategory(HTREEITEM hRootItem
, UINT TextIndex
, UINT IconIndex
)
148 WCHAR szText
[MAX_STR_LEN
];
152 hIcon
= LoadImage(hInst
,
153 MAKEINTRESOURCE(IconIndex
),
157 LR_CREATEDIBSECTION
);
159 Index
= ImageList_AddIcon(hImageTreeView
, hIcon
);
162 LoadStringW(hInst
, TextIndex
, szText
, sizeof(szText
) / sizeof(TCHAR
));
164 return TreeViewAddItem(hRootItem
, szText
, Index
, Index
, TextIndex
);
168 InitCategoriesList(VOID
)
170 HTREEITEM hRootItem1
, hRootItem2
;
172 /* Create image list */
173 hImageTreeView
= ImageList_Create(TREEVIEW_ICON_SIZE
,
175 GetSystemColorDepth() | ILC_MASK
,
178 hRootItem1
= AddCategory(TVI_ROOT
, IDS_INSTALLED
, IDI_CATEGORY
);
179 AddCategory(hRootItem1
, IDS_APPLICATIONS
, IDI_APPS
);
180 AddCategory(hRootItem1
, IDS_UPDATES
, IDI_APPUPD
);
182 hRootItem2
= AddCategory(TVI_ROOT
, IDS_AVAILABLEFORINST
, IDI_CATEGORY
);
183 AddCategory(hRootItem2
, IDS_CAT_AUDIO
, IDI_CAT_AUDIO
);
184 AddCategory(hRootItem2
, IDS_CAT_VIDEO
, IDI_CAT_VIDEO
);
185 AddCategory(hRootItem2
, IDS_CAT_GRAPHICS
, IDI_CAT_GRAPHICS
);
186 AddCategory(hRootItem2
, IDS_CAT_GAMES
, IDI_CAT_GAMES
);
187 AddCategory(hRootItem2
, IDS_CAT_INTERNET
, IDI_CAT_INTERNET
);
188 AddCategory(hRootItem2
, IDS_CAT_OFFICE
, IDI_CAT_OFFICE
);
189 AddCategory(hRootItem2
, IDS_CAT_DEVEL
, IDI_CAT_DEVEL
);
190 AddCategory(hRootItem2
, IDS_CAT_EDU
, IDI_CAT_EDU
);
191 AddCategory(hRootItem2
, IDS_CAT_ENGINEER
, IDI_CAT_ENGINEER
);
192 AddCategory(hRootItem2
, IDS_CAT_FINANCE
, IDI_CAT_FINANCE
);
193 AddCategory(hRootItem2
, IDS_CAT_SCIENCE
, IDI_CAT_SCIENCE
);
194 AddCategory(hRootItem2
, IDS_CAT_TOOLS
, IDI_CAT_TOOLS
);
195 AddCategory(hRootItem2
, IDS_CAT_DRIVERS
, IDI_CAT_DRIVERS
);
196 AddCategory(hRootItem2
, IDS_CAT_LIBS
, IDI_CAT_LIBS
);
197 AddCategory(hRootItem2
, IDS_CAT_OTHER
, IDI_CAT_OTHER
);
199 (VOID
) TreeView_SetImageList(hTreeView
, hImageTreeView
, TVSIL_NORMAL
);
201 (VOID
) TreeView_Expand(hTreeView
, hRootItem2
, TVE_EXPAND
);
202 (VOID
) TreeView_Expand(hTreeView
, hRootItem1
, TVE_EXPAND
);
204 (VOID
) TreeView_SelectItem(hTreeView
, hRootItem1
);
208 InitControls(HWND hwnd
)
210 if (CreateStatusBar(hwnd
) &&
211 CreateToolBar(hwnd
) &&
212 CreateListView(hwnd
) &&
213 CreateTreeView(hwnd
) &&
214 CreateRichEdit(hwnd
) &&
215 CreateVSplitBar(hwnd
) &&
216 CreateHSplitBar(hwnd
))
218 WCHAR szBuffer1
[MAX_STR_LEN
], szBuffer2
[MAX_STR_LEN
];
220 InitApplicationsList();
222 InitCategoriesList();
224 LoadStringW(hInst
, IDS_APPS_COUNT
, szBuffer2
, sizeof(szBuffer2
) / sizeof(WCHAR
));
225 swprintf(szBuffer1
, szBuffer2
, ListView_GetItemCount(hListView
));
226 SetStatusBarText(szBuffer1
);
234 MainWndOnCommand(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
236 WORD wCommand
= LOWORD(wParam
);
238 if (lParam
== (LPARAM
)hSearchBar
)
240 WCHAR szBuf
[MAX_STR_LEN
];
242 switch (HIWORD(wParam
))
246 WCHAR szWndText
[MAX_STR_LEN
];
248 LoadStringW(hInst
, IDS_SEARCH_TEXT
, szBuf
, sizeof(szBuf
) / sizeof(WCHAR
));
249 GetWindowTextW(hSearchBar
, szWndText
, MAX_STR_LEN
);
250 if (wcscmp(szBuf
, szWndText
) == 0) SetWindowTextW(hSearchBar
, L
"");
256 GetWindowTextW(hSearchBar
, szBuf
, MAX_STR_LEN
);
257 if (wcslen(szBuf
) < 1)
259 LoadStringW(hInst
, IDS_SEARCH_TEXT
, szBuf
, sizeof(szBuf
) / sizeof(WCHAR
));
260 SetWindowTextW(hSearchBar
, szBuf
);
266 /* TODO: Implement search */
276 ShellExecuteW(hwnd
, L
"open", pLink
, NULL
, NULL
, SW_SHOWNOACTIVATE
);
277 HeapFree(GetProcessHeap(), 0, pLink
);
281 CopyTextToClipboard(pLink
);
282 HeapFree(GetProcessHeap(), 0, pLink
);
286 CreateSettingsDlg(hwnd
);
290 PostMessageW(hwnd
, WM_CLOSE
, 0, 0);
294 if (DownloadApplication(-1))
295 /* TODO: Implement install dialog
296 * if (InstallApplication(-1))
298 UpdateApplicationsList(-1);
302 if (UninstallApplication(-1, FALSE
))
303 UpdateApplicationsList(-1);
307 if (UninstallApplication(-1, TRUE
))
308 UpdateApplicationsList(-1);
312 UpdateApplicationsList(-1);
316 MessageBoxW(hwnd
, L
"Help not implemented yet", NULL
, MB_OK
);
326 MainWndOnSize(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
328 HDWP hdwp
= BeginDeferWindowPos(5);
329 INT SearchBarWidth
= GetWindowWidth(hSearchBar
);
330 INT RichPos
= GetWindowHeight(hRichEdit
);
331 INT NewPos
= GetClientWindowHeight(hMainWnd
) - (RichPos
+ SPLIT_WIDTH
+ GetWindowHeight(hStatusBar
));
334 /* Size status bar */
335 SendMessage(hStatusBar
, WM_SIZE
, 0, 0);
338 SendMessage(hToolBar
, TB_AUTOSIZE
, 0, 0);
341 MoveWindow(hSearchBar
, LOWORD(lParam
) - SearchBarWidth
- 4, 5, SearchBarWidth
, 22, TRUE
);
344 * HIWORD(lParam) - Height of main window
345 * LOWORD(lParam) - Width of main window
348 /* Size vertical splitter bar */
352 (VSplitterPos
= GetWindowWidth(hTreeView
)),
353 GetWindowHeight(hToolBar
),
355 HIWORD(lParam
) - GetWindowHeight(hToolBar
) - GetWindowHeight(hStatusBar
),
356 SWP_NOZORDER
|SWP_NOACTIVATE
);
363 GetWindowHeight(hToolBar
),
365 HIWORD(lParam
) - GetWindowHeight(hToolBar
) - GetWindowHeight(hStatusBar
),
366 SWP_NOZORDER
|SWP_NOACTIVATE
);
368 while (NewPos
< SPLIT_WIDTH
+ GetWindowHeight(hToolBar
))
371 NewPos
= GetClientWindowHeight(hMainWnd
) - (RichPos
+
372 SPLIT_WIDTH
+ GetWindowHeight(hStatusBar
));
374 SetHSplitterPos(NewPos
);
380 VSplitterPos
+ SPLIT_WIDTH
,
381 GetWindowHeight(hToolBar
),
382 LOWORD(lParam
) - (VSplitterPos
+ SPLIT_WIDTH
),
383 GetHSplitterPos() - GetWindowHeight(hToolBar
),
384 SWP_NOZORDER
|SWP_NOACTIVATE
);
390 VSplitterPos
+ SPLIT_WIDTH
,
391 GetHSplitterPos() + SPLIT_WIDTH
,
392 GetClientWindowWidth(hMainWnd
) - (VSplitterPos
+ SPLIT_WIDTH
),
394 SWP_NOZORDER
|SWP_NOACTIVATE
);
396 /* Size horizontal splitter bar */
400 VSplitterPos
+ SPLIT_WIDTH
,
402 GetClientWindowWidth(hMainWnd
) - (VSplitterPos
+ SPLIT_WIDTH
),
404 SWP_NOZORDER
|SWP_NOACTIVATE
);
406 EndDeferWindowPos(hdwp
);
410 MainWindowProc(HWND hwnd
, UINT Msg
, WPARAM wParam
, LPARAM lParam
)
415 if (!InitControls(hwnd
))
416 PostMessage(hwnd
, WM_CLOSE
, 0, 0);
420 MainWndOnCommand(hwnd
, wParam
, lParam
);
425 LPNMHDR data
= (LPNMHDR
)lParam
;
431 if (data
->hwndFrom
== hTreeView
)
433 switch (((LPNMTREEVIEW
)lParam
)->itemNew
.lParam
)
436 UpdateApplicationsList(ENUM_ALL_COMPONENTS
);
439 case IDS_APPLICATIONS
:
440 UpdateApplicationsList(ENUM_APPLICATIONS
);
444 UpdateApplicationsList(ENUM_UPDATES
);
447 case IDS_AVAILABLEFORINST
:
448 UpdateApplicationsList(ENUM_ALL_AVAILABLE
);
452 UpdateApplicationsList(ENUM_CAT_AUDIO
);
456 UpdateApplicationsList(ENUM_CAT_DEVEL
);
459 case IDS_CAT_DRIVERS
:
460 UpdateApplicationsList(ENUM_CAT_DRIVERS
);
464 UpdateApplicationsList(ENUM_CAT_EDU
);
467 case IDS_CAT_ENGINEER
:
468 UpdateApplicationsList(ENUM_CAT_ENGINEER
);
471 case IDS_CAT_FINANCE
:
472 UpdateApplicationsList(ENUM_CAT_FINANCE
);
476 UpdateApplicationsList(ENUM_CAT_GAMES
);
479 case IDS_CAT_GRAPHICS
:
480 UpdateApplicationsList(ENUM_CAT_GRAPHICS
);
483 case IDS_CAT_INTERNET
:
484 UpdateApplicationsList(ENUM_CAT_INTERNET
);
488 UpdateApplicationsList(ENUM_CAT_LIBS
);
492 UpdateApplicationsList(ENUM_CAT_OFFICE
);
496 UpdateApplicationsList(ENUM_CAT_OTHER
);
499 case IDS_CAT_SCIENCE
:
500 UpdateApplicationsList(ENUM_CAT_SCIENCE
);
504 UpdateApplicationsList(ENUM_CAT_TOOLS
);
508 UpdateApplicationsList(ENUM_CAT_VIDEO
);
517 LPNMLVKEYDOWN pnkd
= (LPNMLVKEYDOWN
) lParam
;
519 if (pnkd
->hdr
.hwndFrom
== hListView
)
521 INT ItemIndex
= (INT
) SendMessage(hListView
, LVM_GETNEXTITEM
, -1, LVNI_FOCUSED
);
523 if (pnkd
->wVKey
== VK_UP
) ItemIndex
-= 1;
524 if (pnkd
->wVKey
== VK_DOWN
) ItemIndex
+= 1;
526 if (IS_INSTALLED_ENUM(SelectedEnumType
))
527 ShowInstalledAppInfo(ItemIndex
);
528 if (IS_AVAILABLE_ENUM(SelectedEnumType
))
529 ShowAvailableAppInfo(ItemIndex
);
534 case LVN_COLUMNCLICK
:
536 LPNMLISTVIEW pnmv
= (LPNMLISTVIEW
) lParam
;
538 (VOID
) ListView_SortItems(hListView
, ListViewCompareFunc
, pnmv
->iSubItem
);
539 bAscending
= !bAscending
;
544 if (data
->hwndFrom
== hListView
)
546 if (IS_INSTALLED_ENUM(SelectedEnumType
))
547 ShowInstalledAppInfo(-1);
548 if (IS_AVAILABLE_ENUM(SelectedEnumType
))
549 ShowAvailableAppInfo(-1);
554 if (data
->hwndFrom
== hListView
)
555 ShowPopupMenu(hListView
, IDR_APPLICATIONMENU
);
559 RichEditOnLink(hwnd
, (ENLINK
*)lParam
);
562 case TTN_GETDISPINFO
:
563 ToolBarOnGetDispInfo((LPTOOLTIPTEXT
)lParam
);
574 if ((GetClientWindowHeight(hMainWnd
) - GetWindowHeight(hStatusBar
) - SPLIT_WIDTH
) < GetHSplitterPos())
576 INT NewSplitPos
= GetClientWindowHeight(hwnd
) - 100 - GetWindowHeight(hStatusBar
) - SPLIT_WIDTH
;
577 if (NewSplitPos
> GetWindowHeight(hToolBar
) + SPLIT_WIDTH
)
578 SetHSplitterPos(NewSplitPos
);
581 MainWndOnSize(hwnd
, wParam
, lParam
);
587 int RichEditHeight
= GetWindowHeight(hRichEdit
);
588 LPRECT pRect
= (LPRECT
)lParam
;
590 while (RichEditHeight
<= 100)
592 if (GetHSplitterPos() - 1 < GetWindowHeight(hToolBar
) + GetWindowHeight(hListView
) + SPLIT_WIDTH
)
594 SetHSplitterPos(GetHSplitterPos() - 1);
598 if (pRect
->right
-pRect
->left
< 565)
599 pRect
->right
= pRect
->left
+ 565;
601 if (pRect
->bottom
-pRect
->top
< 300)
602 pRect
->bottom
= pRect
->top
+ 300;
608 if (IS_AVAILABLE_ENUM(SelectedEnumType
))
609 FreeAvailableAppList();
610 if (hImageListView
) ImageList_Destroy(hImageListView
);
611 if (hImageTreeView
) ImageList_Destroy(hImageTreeView
);
618 return DefWindowProc(hwnd
, Msg
, wParam
, lParam
);
622 wWinMain(HINSTANCE hInstance
, HINSTANCE hPrevInstance
, LPWSTR lpCmdLine
, int nShowCmd
)
624 WNDCLASSEXW WndClass
= {0};
625 WCHAR szWindowClass
[] = L
"ROSAPPMGR";
626 WCHAR szWindowName
[MAX_STR_LEN
];
627 HANDLE hMutex
= NULL
;
630 hMutex
= CreateMutexW(NULL
, FALSE
, szWindowClass
);
631 if ((!hMutex
) || (GetLastError() == ERROR_ALREADY_EXISTS
))
633 /* If already started, it is found its window */
634 HWND hWindow
= FindWindowW(szWindowClass
, NULL
);
636 /* Activate window */
637 ShowWindow(hWindow
, SW_SHOWNORMAL
);
638 SetForegroundWindow(hWindow
);
644 InitCommonControls();
646 /* Create the window */
647 WndClass
.cbSize
= sizeof(WNDCLASSEXW
);
648 WndClass
.lpszClassName
= szWindowClass
;
649 WndClass
.lpfnWndProc
= MainWindowProc
;
650 WndClass
.hInstance
= hInstance
;
651 WndClass
.style
= CS_HREDRAW
| CS_VREDRAW
;
652 WndClass
.hIcon
= LoadIcon(hInstance
, MAKEINTRESOURCE(IDI_MAIN
));
653 WndClass
.hCursor
= LoadCursor(NULL
, IDC_ARROW
);
654 WndClass
.hbrBackground
= (HBRUSH
)(COLOR_BTNFACE
+ 1);
655 WndClass
.lpszMenuName
= MAKEINTRESOURCEW(IDR_MAINMENU
);
657 if (RegisterClassExW(&WndClass
) == (ATOM
)0) goto Exit
;
659 LoadStringW(hInst
, IDS_APPTITLE
, szWindowName
, sizeof(szWindowName
) / sizeof(WCHAR
));
661 hMainWnd
= CreateWindowExW(WS_EX_WINDOWEDGE
,
664 WS_OVERLAPPEDWINDOW
| WS_CLIPCHILDREN
| WS_CLIPSIBLINGS
,
674 if (!hMainWnd
) goto Exit
;
677 ShowWindow(hMainWnd
, SW_SHOW
);
678 UpdateWindow(hMainWnd
);
681 while (GetMessage(&Msg
, NULL
, 0, 0))
683 TranslateMessage(&Msg
);
684 DispatchMessage(&Msg
);
688 if (hMutex
) CloseHandle(hMutex
);