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
)
45 wc
.cbSize
= sizeof(WNDCLASSEX
);
46 wc
.lpszClassName
= L
"pgkmgr";
47 wc
.style
= CS_HREDRAW
| CS_VREDRAW
;
48 wc
.lpfnWndProc
= (WNDPROC
)WndProc
;
50 wc
.hIcon
= LoadIcon(hinst
, MAKEINTRESOURCE(IDI_MAIN
));
51 wc
.hbrBackground
= (HBRUSH
)(COLOR_SCROLLBAR
);
55 hwnd
= CreateWindow(L
"pgkmgr",
56 L
"ReactOS - Package Manager v0.3",
69 hTBar
= CreateToolbarEx(hwnd
, WS_CHILD
|WS_VISIBLE
|TBSTYLE_FLAT
, 0, 8, hinst
, IDB_TOOLBAR
,
70 Buttons
, sizeof(Buttons
)/sizeof(TBBUTTON
), TBSIZE
, TBSIZE
, TBSIZE
, TBSIZE
, sizeof(TBBUTTON
));
73 ShowWindow(hwnd
, SW_SHOW
);
77 int error
= PML_LoadTree(&tree
, "tree.xml", AddItem
);
81 MessageBox(0,PML_TransError(error
),0,0);
88 // Start getting messages
89 while(GetMessage(&msg
,NULL
,0,0))
91 if(!TranslateAccelerator(hwnd
, hHotKeys
, &msg
))
93 TranslateMessage(&msg
);
94 DispatchMessage(&msg
);
104 // Add a item to our tree
105 int AddItem (int id
, const char* name
, int parent
, int icon
)
107 TV_INSERTSTRUCT tvins
;
109 tvins
.item
.lParam
= (UINT
)id
;
110 tvins
.item
.mask
= TVIF_TEXT
|TVIF_PARAM
;
111 tvins
.item
.pszText
= (WCHAR
*)name
; //that is ok
112 tvins
.item
.cchTextMax
= strlen(name
);
113 tvins
.hInsertAfter
= TVI_LAST
;
117 tvins
.item
.iImage
= icon
;
118 tvins
.item
.iSelectedImage
= icon
;
119 tvins
.item
.mask
|= TVIF_IMAGE
| TVIF_SELECTEDIMAGE
;
123 tvins
.hParent
= TVI_ROOT
;
125 tvins
.hParent
= nodes
[parent
];
127 nodes
[id
] = (HTREEITEM
)SendMessage(hTree
, TVM_INSERTITEMA
, 0, (LPARAM
)&tvins
);
132 // Load the Help from file and display it
137 FILE* file
= fopen ("help.txt", "r");
142 for(i
=0; i
<2000; i
++)
144 buffer
[i
] = getc(file
);
145 if(buffer
[i
]==EOF
) break;
152 // Create our Controls
153 void InitControls (HWND hwnd
)
156 HINSTANCE hinst
= GetModuleHandle(NULL
);
158 // Create the controls
159 hTree
= CreateWindowEx(0, WC_TREEVIEW
, L
"TreeView", WS_CHILD
|WS_VISIBLE
|WS_BORDER
|TVS_HASLINES
|TVS_LINESATROOT
|TVS_HASBUTTONS
,
160 0, 0, 0, 0, hwnd
, NULL
, hinst
, NULL
);
162 hEdit
= CreateWindowEx(WS_EX_CLIENTEDGE
, L
"edit", PML_TransError(IDS_LOAD
), WS_CHILD
|WS_VISIBLE
|ES_MULTILINE
,
163 0, 0, 100, 100, hwnd
, NULL
, hinst
, NULL
);
165 hPopup
= LoadMenu(hinst
, MAKEINTRESOURCE(IDR_POPUP
));
168 HIMAGELIST hIcon
= ImageList_Create(16,16,ILC_COLOR32
,1,1);
169 SendMessage(hTree
, TVM_SETIMAGELIST
, TVSIL_NORMAL
, (LPARAM
)(HIMAGELIST
)hIcon
);
171 ImageList_AddIcon(hIcon
, LoadIcon(hinst
, MAKEINTRESOURCE(1)));
172 ImageList_AddIcon(hIcon
, LoadIcon(hinst
, MAKEINTRESOURCE(11)));
173 ImageList_AddIcon(hIcon
, LoadIcon(hinst
, MAKEINTRESOURCE(12)));
174 ImageList_AddIcon(hIcon
, LoadIcon(hinst
, MAKEINTRESOURCE(13)));
175 ImageList_AddIcon(hIcon
, LoadIcon(hinst
, MAKEINTRESOURCE(14)));
177 ImageList_AddIcon(hIcon
, LoadIcon(hinst
, MAKEINTRESOURCE(2)));
178 ImageList_AddIcon(hIcon
, LoadIcon(hinst
, MAKEINTRESOURCE(3)));
179 ImageList_AddIcon(hIcon
, LoadIcon(hinst
, MAKEINTRESOURCE(4)));
180 ImageList_AddIcon(hIcon
, LoadIcon(hinst
, MAKEINTRESOURCE(5)));
181 ImageList_AddIcon(hIcon
, LoadIcon(hinst
, MAKEINTRESOURCE(6)));
182 ImageList_AddIcon(hIcon
, LoadIcon(hinst
, MAKEINTRESOURCE(7)));
183 ImageList_AddIcon(hIcon
, LoadIcon(hinst
, MAKEINTRESOURCE(8)));
184 ImageList_AddIcon(hIcon
, LoadIcon(hinst
, MAKEINTRESOURCE(9)));
185 ImageList_AddIcon(hIcon
, LoadIcon(hinst
, MAKEINTRESOURCE(10)));
188 hHotKeys
= LoadAccelerators (hinst
, MAKEINTRESOURCE(IDR_HOTKEYS
));
192 int SetIcon (int id
, int icon
)
196 item
.hItem
= nodes
[id
];
198 item
.iSelectedImage
= icon
;
199 item
.mask
= TVIF_IMAGE
| TVIF_SELECTEDIMAGE
;
201 TreeView_SetItem(hTree
, &item
);
207 int Ask (const WCHAR
* message
)
209 int ans
= MessageBox (0,message
,0,MB_YESNO
);
217 // En- or Disable a Button inside of the toolbar and the Context Menu
218 int SetButton (DWORD id
, BOOL state
)
220 // Change the Toorbar Button
223 ti
.cbSize
= sizeof (ti
);
224 ti
.dwMask
= TBIF_STATE
;
227 MessageBox(0,L"on",0,0);
228 else if(!state&&id==1)
229 MessageBox(0,L"off",0,0);
232 ti
.fsState
= TBSTATE_ENABLED
;
234 ti
.fsState
= TBSTATE_INDETERMINATE
;
236 SendMessage (hTBar
, TB_SETBUTTONINFO
, id
, (LPARAM
)&ti
);
238 // Change the Context Menu item
241 mi
.cbSize
= sizeof (mi
);
242 mi
.fMask
= MIIM_STATE
;
245 mi
.fState
= MFS_ENABLED
;
248 mi
.fState
= MFS_GRAYED
;
250 SetMenuItemInfo(hPopup
, id
, FALSE
, &mi
);
255 // Set the text of the text box
256 int SetText (const char* text
)
264 // the windows does not need "\n"
265 // for new lines but "\r\n"
266 for(i
=0,j
=0; text
[i
]; i
++,j
++)
269 if(buffer
[j
] == '\n')
277 SetWindowTextA(hEdit
, buffer
);
282 // Windows Message Callback (this is where most things happen)
283 LRESULT CALLBACK
WndProc (HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
287 // at the very beginning ...
294 // calculate the size of the controls
298 SendMessage(hTBar
, TB_AUTOSIZE
, 0L, 0L);
299 GetWindowRect(hTBar
, &rcl
);
301 int win_top
= rcl
.bottom
- rcl
.top
;
302 int win_hight
= HIWORD(lParam
) - win_top
;
304 MoveWindow(hTree
, 0, win_top
, LOWORD(lParam
), splitter_pos
*win_hight
/100, TRUE
);
305 MoveWindow(hEdit
, 0, (splitter_pos
*win_hight
/100)+win_top
, LOWORD(lParam
), win_hight
, TRUE
);
312 if(((LPNMHDR
)lParam
)->code
== TVN_SELCHANGED
)
314 selected
= ((LPNMTREEVIEW
)lParam
)->itemNew
.lParam
;
315 PML_LoadPackage (tree
, selected
, SetButton
);
316 SetText(PML_GetDescription (tree
, selected
));
319 else if ((int)(((LPNMHDR
)lParam
)->code
) == NM_RCLICK
) // <= aarrggg LISP
321 // which item has been click on
322 HTREEITEM item
= TreeView_GetDropHilight(hTree
);
326 // mark the one as seleacted
327 SendMessage (hTree
, TVM_SELECTITEM
, TVGN_CARET
, (LPARAM
)item
);
328 TreeView_EnsureVisible (hTree
, item
);
331 // create the context menu
336 TrackPopupMenu (GetSubMenu(hPopup
, 0), 0, (UINT
)pt
.x
, (UINT
)pt
.y
, 0, hwnd
, NULL
);
346 if(LOWORD(wParam
) <= 5 && LOWORD(wParam
) >= 1)
349 if(PML_SetAction(tree
, selected
, LOWORD(wParam
)-1, SetIcon
, Ask
) == ERR_OK
)
352 MessageBeep(MB_ICONHAND
);
356 else if(LOWORD(wParam
)==6)
358 if(PML_DoIt(tree
, SetStatus
, Ask
) == ERR_OK
)
359 DialogBox(GetModuleHandle(NULL
), MAKEINTRESOURCE(IDD_DOIT
), hwnd
, StatusProc
);
361 MessageBeep(MB_ICONHAND
);
365 else if(LOWORD(wParam
)==7)
369 else if(LOWORD(wParam
)==8)
370 DialogBox(GetModuleHandle(NULL
), MAKEINTRESOURCE(IDD_OPTIONS
), hwnd
, OptionsProc
);
377 if(PML_SetAction(tree
, selected
, wParam
, SetIcon
, Ask
) != ERR_OK
)
378 MessageBeep(MB_ICONHAND
);
382 // ... at the very end
390 return DefWindowProc (hwnd
, message
, wParam
, lParam
);
393 // Warning: This function is called from another thread
394 int SetStatus (int status1
, int status2
, WCHAR
* text
)
396 // Set the Rage to 1000
397 SendMessage(GetDlgItem(hStatus
, IDC_STATUS1
), PBM_SETRANGE32
, 0, 1000);
398 SendMessage(GetDlgItem(hStatus
, IDC_STATUS2
), PBM_SETRANGE32
, 0, 1000);
400 // The prozessbars and the text filds
402 SetDlgItemText(hStatus
, IDC_TSTATUS
, text
);
405 SendMessage(GetDlgItem(hStatus
, IDC_STATUS1
), PBM_SETPOS
, status1
, 0);
408 SendMessage(GetDlgItem(hStatus
, IDC_STATUS2
), PBM_SETPOS
, status2
, 0);
410 // If the Status is 1000 very thing is done
413 EndDialog(hStatus
, TRUE
);
414 MessageBox(0,PML_TransError(status2
),0,0);
420 // Callback for the Status Dialog
421 INT_PTR CALLBACK
StatusProc (HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
431 case WM_COMMAND
: // can only be the about button
432 case WM_CLOSE
: // the close-window-[x]
435 EndDialog(hwnd
, TRUE
);
443 // Callback for the Options Dialog
444 INT_PTR CALLBACK
OptionsProc (HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
449 EndDialog(hwnd
, TRUE
);