1 ////////////////////////////////////////////////////////
5 // Implementation of the Package Manager GUI
8 // Maarten Bosma, 09.01.2004
9 // maarten.paul@bosma.de
11 ////////////////////////////////////////////////////////////////////
16 // Application's Entry Point
17 int WINAPI
WinMain (HINSTANCE hinst
, HINSTANCE hPrevInstance
, PSTR szCmdLine
, int iCmdShow
)
24 wc
.cbSize
= sizeof(WNDCLASSEX
);
25 wc
.lpszClassName
= L
"pgkmgr";
26 wc
.style
= CS_HREDRAW
| CS_VREDRAW
;
27 wc
.lpfnWndProc
= (WNDPROC
)WndProc
;
29 wc
.hIcon
= LoadIcon(hinst
, MAKEINTRESOURCE(IDI_MAIN
));
30 wc
.hbrBackground
= (HBRUSH
)(COLOR_SCROLLBAR
);
34 hwnd
= CreateWindow(L
"pgkmgr",
35 L
"ReactOS - Package Manager v0.3",
48 hTBar
= CreateToolbarEx(hwnd
, WS_CHILD
|WS_VISIBLE
|TBSTYLE_FLAT
, 0, 8, hinst
, IDB_TOOLBAR
,
49 Buttons
, sizeof(Buttons
)/sizeof(TBBUTTON
), TBSIZE
, TBSIZE
, TBSIZE
, TBSIZE
, sizeof(TBBUTTON
));
52 ShowWindow(hwnd
, SW_SHOW
);
56 int error
= PML_LoadTree(&tree
, "tree.xml", AddItem
);
60 MessageBox(0,PML_TransError(error
),0,0);
67 // Start getting messages
68 while(GetMessage(&msg
,NULL
,0,0))
70 if(!TranslateAccelerator(hwnd
, hHotKeys
, &msg
))
72 TranslateMessage(&msg
);
73 DispatchMessage(&msg
);
83 // Add a item to our tree
84 int AddItem (int id
, const char* name
, int parent
, int icon
)
86 TV_INSERTSTRUCT tvins
;
88 tvins
.item
.lParam
= (UINT
)id
;
89 tvins
.item
.mask
= TVIF_TEXT
|TVIF_PARAM
;
90 tvins
.item
.pszText
= (WCHAR
*)name
; //that is ok
91 tvins
.item
.cchTextMax
= strlen(name
);
92 tvins
.hInsertAfter
= TVI_LAST
;
96 tvins
.item
.iImage
= icon
;
97 tvins
.item
.iSelectedImage
= icon
;
98 tvins
.item
.mask
|= TVIF_IMAGE
| TVIF_SELECTEDIMAGE
;
102 tvins
.hParent
= TVI_ROOT
;
104 tvins
.hParent
= nodes
[parent
];
106 nodes
[id
] = (HTREEITEM
)SendMessage(hTree
, TVM_INSERTITEMA
, 0, (LPARAM
)&tvins
);
111 // Load the Help from file and display it
116 FILE* file
= fopen ("help.txt", "r");
121 for(i
=0; i
<2000; i
++)
123 buffer
[i
] = getc(file
);
124 if(!buffer
[i
]) break;
130 // Create our Controls
131 void InitControls (HWND hwnd
)
134 HINSTANCE hinst
= GetModuleHandle(NULL
);
136 // Create the controls
137 hTree
= CreateWindowEx(0, WC_TREEVIEW
, L
"TreeView", WS_CHILD
|WS_VISIBLE
|WS_BORDER
|TVS_HASLINES
|TVS_LINESATROOT
|TVS_HASBUTTONS
,
138 0, 0, 0, 0, hwnd
, NULL
, hinst
, NULL
);
140 hEdit
= CreateWindowEx(WS_EX_CLIENTEDGE
, L
"edit", PML_TransError(IDS_LOAD
), WS_CHILD
|WS_VISIBLE
|ES_MULTILINE
,
141 0, 0, 100, 100, hwnd
, NULL
, hinst
, NULL
);
143 hPopup
= LoadMenu(hinst
, MAKEINTRESOURCE(IDR_POPUP
));
146 HIMAGELIST hIcon
= ImageList_Create(16,16,ILC_COLOR32
,1,1);
147 SendMessage(hTree
, TVM_SETIMAGELIST
, TVSIL_NORMAL
, (LPARAM
)(HIMAGELIST
)hIcon
);
149 ImageList_AddIcon(hIcon
, LoadIcon(hinst
, MAKEINTRESOURCE(1)));
150 ImageList_AddIcon(hIcon
, LoadIcon(hinst
, MAKEINTRESOURCE(11)));
151 ImageList_AddIcon(hIcon
, LoadIcon(hinst
, MAKEINTRESOURCE(12)));
152 ImageList_AddIcon(hIcon
, LoadIcon(hinst
, MAKEINTRESOURCE(13)));
153 ImageList_AddIcon(hIcon
, LoadIcon(hinst
, MAKEINTRESOURCE(14)));
155 ImageList_AddIcon(hIcon
, LoadIcon(hinst
, MAKEINTRESOURCE(2)));
156 ImageList_AddIcon(hIcon
, LoadIcon(hinst
, MAKEINTRESOURCE(3)));
157 ImageList_AddIcon(hIcon
, LoadIcon(hinst
, MAKEINTRESOURCE(4)));
158 ImageList_AddIcon(hIcon
, LoadIcon(hinst
, MAKEINTRESOURCE(5)));
159 ImageList_AddIcon(hIcon
, LoadIcon(hinst
, MAKEINTRESOURCE(6)));
160 ImageList_AddIcon(hIcon
, LoadIcon(hinst
, MAKEINTRESOURCE(7)));
161 ImageList_AddIcon(hIcon
, LoadIcon(hinst
, MAKEINTRESOURCE(8)));
162 ImageList_AddIcon(hIcon
, LoadIcon(hinst
, MAKEINTRESOURCE(9)));
163 ImageList_AddIcon(hIcon
, LoadIcon(hinst
, MAKEINTRESOURCE(10)));
166 hHotKeys
= LoadAccelerators (hinst
, MAKEINTRESOURCE(IDR_HOTKEYS
));
170 int SetIcon (int id
, int icon
)
174 item
.hItem
= nodes
[id
];
176 item
.iSelectedImage
= icon
;
177 item
.mask
= TVIF_IMAGE
| TVIF_SELECTEDIMAGE
;
179 TreeView_SetItem(hTree
, &item
);
185 int Ask (const WCHAR
* message
)
187 int ans
= MessageBox (0,message
,0,MB_YESNO
);
195 // En- or Disable a Button inside of the toolbar and the Context Menu
196 int SetButton (DWORD id
, BOOL state
)
198 // Change the Toorbar Button
201 ti
.cbSize
= sizeof (ti
);
202 ti
.dwMask
= TBIF_STATE
;
205 MessageBox(0,L"on",0,0);
206 else if(!state&&id==1)
207 MessageBox(0,L"off",0,0);
210 ti
.fsState
= TBSTATE_ENABLED
;
212 ti
.fsState
= TBSTATE_INDETERMINATE
;
214 SendMessage (hTBar
, TB_SETBUTTONINFO
, id
, (LPARAM
)&ti
);
216 // Change the Context Menu item
219 mi
.cbSize
= sizeof (mi
);
220 mi
.fMask
= MIIM_STATE
;
223 mi
.fState
= MFS_ENABLED
;
226 mi
.fState
= MFS_GRAYED
;
228 SetMenuItemInfo(hPopup
, id
, FALSE
, &mi
);
233 // Set the text of the text box
234 int SetText (const char* text
)
242 // the windows does not need "\n"
243 // for new lines but "\r\n"
244 for(i
=0,j
=0; text
[i
]; i
++,j
++)
247 if(buffer
[j
] == '\n')
252 SetWindowTextA(hEdit
, buffer
);
257 // Windows Message Callback (this is where most things happen)
258 LRESULT CALLBACK
WndProc (HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
262 // at the very beginning ...
269 // calculate the size of the controls
273 SendMessage(hTBar
, TB_AUTOSIZE
, 0L, 0L);
274 GetWindowRect(hTBar
, &rcl
);
276 int win_top
= rcl
.bottom
- rcl
.top
;
277 int win_hight
= HIWORD(lParam
) - win_top
;
279 MoveWindow(hTree
, 0, win_top
, LOWORD(lParam
), splitter_pos
*win_hight
/100, TRUE
);
280 MoveWindow(hEdit
, 0, (splitter_pos
*win_hight
/100)+win_top
, LOWORD(lParam
), win_hight
, TRUE
);
287 if(((LPNMHDR
)lParam
)->code
== TVN_SELCHANGED
)
289 selected
= ((LPNMTREEVIEW
)lParam
)->itemNew
.lParam
;
290 PML_LoadPackage (tree
, selected
, SetButton
);
291 SetText(PML_GetDescription (tree
, selected
));
294 else if ((int)(((LPNMHDR
)lParam
)->code
) == NM_RCLICK
) // <= aarrggg LISP
296 // which item has been click on
297 HTREEITEM item
= TreeView_GetDropHilight(hTree
);
301 // mark the one as seleacted
302 SendMessage (hTree
, TVM_SELECTITEM
, TVGN_CARET
, (LPARAM
)item
);
303 TreeView_EnsureVisible (hTree
, item
);
306 // create the context menu
311 TrackPopupMenu (GetSubMenu(hPopup
, 0), 0, (UINT
)pt
.x
, (UINT
)pt
.y
, 0, hwnd
, NULL
);
321 if(LOWORD(wParam
) <= 5 && LOWORD(wParam
) >= 1)
324 if(PML_SetAction(tree
, selected
, LOWORD(wParam
)-1, SetIcon
, Ask
) == ERR_OK
)
327 MessageBeep(MB_ICONHAND
);
331 else if(LOWORD(wParam
)==6)
333 if(PML_DoIt(tree
, SetStatus
, Ask
) == ERR_OK
)
334 DialogBox(GetModuleHandle(NULL
), MAKEINTRESOURCE(IDD_DOIT
), hwnd
, StatusProc
);
336 MessageBeep(MB_ICONHAND
);
340 else if(LOWORD(wParam
)==7)
344 else if(LOWORD(wParam
)==8)
345 DialogBox(GetModuleHandle(NULL
), MAKEINTRESOURCE(IDD_OPTIONS
), hwnd
, OptionsProc
);
352 if(PML_SetAction(tree
, selected
, wParam
, SetIcon
, Ask
) != ERR_OK
)
353 MessageBeep(MB_ICONHAND
);
357 // ... at the very end
365 return DefWindowProc (hwnd
, message
, wParam
, lParam
);
368 // Warning: This function is called from another thread
369 int SetStatus (int status1
, int status2
, WCHAR
* text
)
371 // Set the Rage to 1000
372 SendMessage(GetDlgItem(hStatus
, IDC_STATUS1
), PBM_SETRANGE32
, 0, 1000);
373 SendMessage(GetDlgItem(hStatus
, IDC_STATUS2
), PBM_SETRANGE32
, 0, 1000);
375 // The prozessbars and the text filds
377 SetDlgItemText(hStatus
, IDC_TSTATUS
, text
);
380 SendMessage(GetDlgItem(hStatus
, IDC_STATUS1
), PBM_SETPOS
, status1
, 0);
383 SendMessage(GetDlgItem(hStatus
, IDC_STATUS2
), PBM_SETPOS
, status2
, 0);
385 // If the Status is 1000 very thing is done
388 EndDialog(hStatus
, TRUE
);
389 MessageBox(0,PML_TransError(status2
),0,0);
395 // Callback for the Status Dialog
396 INT_PTR CALLBACK
StatusProc (HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
406 case WM_COMMAND
: // can only be the about button
407 case WM_CLOSE
: // the close-window-[x]
410 EndDialog(hwnd
, TRUE
);
418 // Callback for the Options Dialog
419 INT_PTR CALLBACK
OptionsProc (HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
424 EndDialog(hwnd
, TRUE
);