1 ////////////////////////////////////////////////////////
5 // Implementation of the Package Manager GUI
8 // Maarten Bosma, 09.01.2004
9 // maarten.paul@bosma.de
11 ////////////////////////////////////////////////////////////////////
15 // This is the struct where the toolbar is defined
16 const TBBUTTON Buttons
[] =
18 {0, 0, TBSTATE_ENABLED
, TBSTYLE_SEP
},
20 {0, 1, TBSTATE_INDETERMINATE
, TBSTYLE_BUTTON
}, // No Action
21 {1, 2, TBSTATE_INDETERMINATE
, TBSTYLE_BUTTON
}, // Install
22 {2, 3, TBSTATE_INDETERMINATE
, TBSTYLE_BUTTON
}, // Install from source
23 {3, 4, TBSTATE_INDETERMINATE
, TBSTYLE_BUTTON
}, // Update
24 {4, 5, TBSTATE_INDETERMINATE
, TBSTYLE_BUTTON
}, // Unistall
26 {0, 0, TBSTATE_ENABLED
, TBSTYLE_SEP
},
27 {5, 6, TBSTATE_ENABLED
, TBSTYLE_BUTTON
}, // DoIt (tm)
28 {0, 0, TBSTATE_ENABLED
, TBSTYLE_SEP
},
30 {6, 7, TBSTATE_ENABLED
, TBSTYLE_BUTTON
}, // Help
31 {7, 8, TBSTATE_ENABLED
, TBSTYLE_BUTTON
}, // Options
33 {0, 0, TBSTATE_ENABLED
, TBSTYLE_SEP
},
37 // Application's Entry Point
38 int WINAPI
WinMain (HINSTANCE hinst
, HINSTANCE hPrevInstance
, PSTR szCmdLine
, int iCmdShow
)
46 wc
.cbSize
= sizeof(WNDCLASSEX
);
47 wc
.lpszClassName
= L
"pgkmgr";
48 wc
.style
= CS_HREDRAW
| CS_VREDRAW
;
49 wc
.lpfnWndProc
= (WNDPROC
)WndProc
;
51 wc
.hIcon
= LoadIcon(hinst
, MAKEINTRESOURCE(IDI_MAIN
));
52 wc
.hbrBackground
= (HBRUSH
)(COLOR_SCROLLBAR
);
56 hwnd
= CreateWindow(L
"pgkmgr",
57 L
"ReactOS - Package Manager v0.3",
70 hTBar
= CreateToolbarEx(hwnd
, WS_CHILD
|WS_VISIBLE
|TBSTYLE_FLAT
, 0, 8, hinst
, IDB_TOOLBAR
,
71 Buttons
, sizeof(Buttons
)/sizeof(TBBUTTON
), TBSIZE
, TBSIZE
, TBSIZE
, TBSIZE
, sizeof(TBBUTTON
));
74 ShowWindow(hwnd
, SW_SHOW
);
78 int error
= PML_LoadTree(&tree
, "tree.xml", AddItem
);
82 MessageBox(0,PML_TransError(error
, errbuf
, sizeof(errbuf
)/sizeof(WCHAR
)),0,0);
89 // Start getting messages
90 while(GetMessage(&msg
,NULL
,0,0))
92 if(!TranslateAccelerator(hwnd
, hHotKeys
, &msg
))
94 TranslateMessage(&msg
);
95 DispatchMessage(&msg
);
100 PML_CloseTree (tree
);
105 // Add a item to our tree
106 int AddItem (int id
, const char* name
, int parent
, int icon
)
108 TV_INSERTSTRUCT tvins
;
110 tvins
.item
.lParam
= (UINT
)id
;
111 tvins
.item
.mask
= TVIF_TEXT
|TVIF_PARAM
;
112 tvins
.item
.pszText
= (WCHAR
*)name
; //that is ok
113 tvins
.item
.cchTextMax
= strlen(name
);
114 tvins
.hInsertAfter
= TVI_LAST
;
118 tvins
.item
.iImage
= icon
;
119 tvins
.item
.iSelectedImage
= icon
;
120 tvins
.item
.mask
|= TVIF_IMAGE
| TVIF_SELECTEDIMAGE
;
124 tvins
.hParent
= TVI_ROOT
;
126 tvins
.hParent
= nodes
[parent
];
128 nodes
[id
] = (HTREEITEM
)SendMessage(hTree
, TVM_INSERTITEMA
, 0, (LPARAM
)&tvins
);
133 // Load the Help from file and display it
138 FILE* file
= fopen ("help.txt", "r");
143 for(i
=0; i
<2000; i
++)
145 buffer
[i
] = getc(file
);
146 if(buffer
[i
]==EOF
) break;
153 // Create our Controls
154 void InitControls (HWND hwnd
)
157 HINSTANCE hinst
= GetModuleHandle(NULL
);
160 // Create the controls
161 hTree
= CreateWindowEx(0, WC_TREEVIEW
, L
"TreeView", WS_CHILD
|WS_VISIBLE
|WS_BORDER
|TVS_HASLINES
|TVS_LINESATROOT
|TVS_HASBUTTONS
,
162 0, 0, 0, 0, hwnd
, NULL
, hinst
, NULL
);
164 hEdit
= CreateWindowEx(WS_EX_CLIENTEDGE
, L
"edit", PML_TransError(IDS_LOAD
, errbuf
, sizeof(errbuf
)/sizeof(WCHAR
)), WS_CHILD
|WS_VISIBLE
|ES_MULTILINE
,
165 0, 0, 100, 100, hwnd
, NULL
, hinst
, NULL
);
167 hPopup
= LoadMenu(hinst
, MAKEINTRESOURCE(IDR_POPUP
));
170 HIMAGELIST hIcon
= ImageList_Create(16,16,ILC_COLOR32
,1,1);
171 SendMessage(hTree
, TVM_SETIMAGELIST
, TVSIL_NORMAL
, (LPARAM
)(HIMAGELIST
)hIcon
);
173 ImageList_AddIcon(hIcon
, LoadIcon(hinst
, MAKEINTRESOURCE(1)));
174 ImageList_AddIcon(hIcon
, LoadIcon(hinst
, MAKEINTRESOURCE(11)));
175 ImageList_AddIcon(hIcon
, LoadIcon(hinst
, MAKEINTRESOURCE(12)));
176 ImageList_AddIcon(hIcon
, LoadIcon(hinst
, MAKEINTRESOURCE(13)));
177 ImageList_AddIcon(hIcon
, LoadIcon(hinst
, MAKEINTRESOURCE(14)));
179 ImageList_AddIcon(hIcon
, LoadIcon(hinst
, MAKEINTRESOURCE(2)));
180 ImageList_AddIcon(hIcon
, LoadIcon(hinst
, MAKEINTRESOURCE(3)));
181 ImageList_AddIcon(hIcon
, LoadIcon(hinst
, MAKEINTRESOURCE(4)));
182 ImageList_AddIcon(hIcon
, LoadIcon(hinst
, MAKEINTRESOURCE(5)));
183 ImageList_AddIcon(hIcon
, LoadIcon(hinst
, MAKEINTRESOURCE(6)));
184 ImageList_AddIcon(hIcon
, LoadIcon(hinst
, MAKEINTRESOURCE(7)));
185 ImageList_AddIcon(hIcon
, LoadIcon(hinst
, MAKEINTRESOURCE(8)));
186 ImageList_AddIcon(hIcon
, LoadIcon(hinst
, MAKEINTRESOURCE(9)));
187 ImageList_AddIcon(hIcon
, LoadIcon(hinst
, MAKEINTRESOURCE(10)));
190 hHotKeys
= LoadAccelerators (hinst
, MAKEINTRESOURCE(IDR_HOTKEYS
));
194 int SetIcon (int id
, int icon
)
198 item
.hItem
= nodes
[id
];
200 item
.iSelectedImage
= icon
;
201 item
.mask
= TVIF_IMAGE
| TVIF_SELECTEDIMAGE
;
203 TreeView_SetItem(hTree
, &item
);
209 int Ask (const WCHAR
* message
)
211 int ans
= MessageBox (0,message
,0,MB_YESNO
);
219 // En- or Disable a Button inside of the toolbar and the Context Menu
220 int SetButton (DWORD id
, BOOL state
)
222 // Change the Toorbar Button
225 ti
.cbSize
= sizeof (ti
);
226 ti
.dwMask
= TBIF_STATE
;
229 ti
.fsState
= TBSTATE_ENABLED
;
231 ti
.fsState
= TBSTATE_INDETERMINATE
;
233 SendMessage (hTBar
, TB_SETBUTTONINFO
, id
, (LPARAM
)&ti
);
235 // Change the Context Menu item
238 mi
.cbSize
= sizeof (mi
);
239 mi
.fMask
= MIIM_STATE
;
242 mi
.fState
= MFS_ENABLED
;
245 mi
.fState
= MFS_GRAYED
;
247 SetMenuItemInfo(hPopup
, id
, FALSE
, &mi
);
252 // Set the text of the text box
253 int SetText (const char* text
)
261 // the windows does not need "\n"
262 // for new lines but "\r\n"
263 for(i
=0,j
=0; text
[i
]; i
++,j
++)
266 if(buffer
[j
] == '\n')
274 SetWindowTextA(hEdit
, buffer
);
279 // Windows Message Callback (this is where most things happen)
280 LRESULT CALLBACK
WndProc (HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
284 // at the very beginning ...
291 // calculate the size of the controls
295 SendMessage(hTBar
, TB_AUTOSIZE
, 0L, 0L);
296 GetWindowRect(hTBar
, &rcl
);
298 int win_top
= rcl
.bottom
- rcl
.top
;
299 int win_hight
= HIWORD(lParam
) - win_top
;
301 MoveWindow(hTree
, 0, win_top
, LOWORD(lParam
), splitter_pos
*win_hight
/100, TRUE
);
302 MoveWindow(hEdit
, 0, (splitter_pos
*win_hight
/100)+win_top
, LOWORD(lParam
), win_hight
, TRUE
);
309 if(((LPNMHDR
)lParam
)->code
== TVN_SELCHANGED
)
311 selected
= ((LPNMTREEVIEW
)lParam
)->itemNew
.lParam
;
312 PML_LoadPackage (tree
, selected
, SetButton
);
313 SetText(PML_GetDescription (tree
, selected
));
316 else if ((int)(((LPNMHDR
)lParam
)->code
) == NM_RCLICK
) // <= aarrggg LISP
318 // which item has been click on
319 HTREEITEM item
= TreeView_GetDropHilight(hTree
);
323 // mark the one as seleacted
324 SendMessage (hTree
, TVM_SELECTITEM
, TVGN_CARET
, (LPARAM
)item
);
325 TreeView_EnsureVisible (hTree
, item
);
328 // create the context menu
333 TrackPopupMenu (GetSubMenu(hPopup
, 0), 0, (UINT
)pt
.x
, (UINT
)pt
.y
, 0, hwnd
, NULL
);
343 if(LOWORD(wParam
) <= 5 && LOWORD(wParam
) >= 1)
346 if(PML_SetAction(tree
, selected
, LOWORD(wParam
)-1, SetIcon
, Ask
) == ERR_OK
)
349 MessageBeep(MB_ICONHAND
);
353 else if(LOWORD(wParam
)==6)
355 if(PML_DoIt(tree
, SetStatus
, Ask
) == ERR_OK
)
356 DialogBox(GetModuleHandle(NULL
), MAKEINTRESOURCE(IDD_DOIT
), hwnd
, StatusProc
);
358 MessageBeep(MB_ICONHAND
);
362 else if(LOWORD(wParam
)==7)
366 else if(LOWORD(wParam
)==8)
367 DialogBox(GetModuleHandle(NULL
), MAKEINTRESOURCE(IDD_OPTIONS
), hwnd
, OptionsProc
);
374 if(PML_SetAction(tree
, selected
, wParam
, SetIcon
, Ask
) != ERR_OK
)
375 MessageBeep(MB_ICONHAND
);
379 // ... at the very end
387 return DefWindowProc (hwnd
, message
, wParam
, lParam
);
390 // Warning: This function is called from another thread
391 int SetStatus (int status1
, int status2
, WCHAR
* text
)
395 // Set the Rage to 1000
396 SendMessage(GetDlgItem(hStatus
, IDC_STATUS1
), PBM_SETRANGE32
, 0, 1000);
397 SendMessage(GetDlgItem(hStatus
, IDC_STATUS2
), PBM_SETRANGE32
, 0, 1000);
399 // The prozessbars and the text filds
401 SetDlgItemText(hStatus
, IDC_TSTATUS
, text
);
404 SendMessage(GetDlgItem(hStatus
, IDC_STATUS1
), PBM_SETPOS
, status1
, 0);
407 SendMessage(GetDlgItem(hStatus
, IDC_STATUS2
), PBM_SETPOS
, status2
, 0);
409 // If the Status is 1000 very thing is done
412 EndDialog(hStatus
, TRUE
);
413 MessageBox(0,PML_TransError(status2
, errbuf
, sizeof(errbuf
)/sizeof(WCHAR
)),0,0);
419 // Callback for the Status Dialog
420 INT_PTR CALLBACK
StatusProc (HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
430 case WM_COMMAND
: // can only be the about button
431 case WM_CLOSE
: // the close-window-[x]
434 EndDialog(hwnd
, TRUE
);
442 // Callback for the Options Dialog
443 INT_PTR CALLBACK
OptionsProc (HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
448 EndDialog(hwnd
, TRUE
);