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_bare.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_MASK
|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 return (int)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 ti
.fsState
= TBSTATE_ENABLED
;
229 ti
.fsState
= TBSTATE_INDETERMINATE
;
231 SendMessage (hTBar
, TB_SETBUTTONINFO
, id
, (LPARAM
)&ti
);
233 // Change the Context Menu item
236 mi
.cbSize
= sizeof (mi
);
237 mi
.fMask
= MIIM_STATE
;
240 mi
.fState
= MFS_ENABLED
;
243 mi
.fState
= MFS_GRAYED
;
245 SetMenuItemInfo(hPopup
, id
, FALSE
, &mi
);
250 // Set the text of the text box
251 int SetText (const char* text
)
259 // the windows does not need "\n"
260 // for new lines but "\r\n"
261 for(i
=0,j
=0; text
[i
]; i
++,j
++)
264 if(buffer
[j
] == '\n')
272 SetWindowTextA(hEdit
, buffer
);
277 // Windows Message Callback (this is where most things happen)
278 LRESULT CALLBACK
WndProc (HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
282 // at the very beginning ...
289 // calculate the size of the controls
293 SendMessage(hTBar
, TB_AUTOSIZE
, 0L, 0L);
294 GetWindowRect(hTBar
, &rcl
);
296 int win_top
= rcl
.bottom
- rcl
.top
;
297 int win_hight
= HIWORD(lParam
) - win_top
;
299 MoveWindow(hTree
, 0, win_top
, LOWORD(lParam
), splitter_pos
*win_hight
/100, TRUE
);
300 MoveWindow(hEdit
, 0, (splitter_pos
*win_hight
/100)+win_top
, LOWORD(lParam
), win_hight
, TRUE
);
307 if(((LPNMHDR
)lParam
)->code
== TVN_SELCHANGED
)
309 selected
= ((LPNMTREEVIEW
)lParam
)->itemNew
.lParam
;
310 PML_LoadPackage (tree
, selected
, SetButton
);
311 SetText(PML_GetDescription (tree
, selected
));
314 else if ((int)(((LPNMHDR
)lParam
)->code
) == NM_RCLICK
) // <= aarrggg LISP
316 // which item has been click on
317 HTREEITEM item
= TreeView_GetDropHilight(hTree
);
321 // mark the one as selected
322 SendMessage (hTree
, TVM_SELECTITEM
, TVGN_CARET
, (LPARAM
)item
);
323 (void)TreeView_EnsureVisible (hTree
, item
);
326 // create the context menu
331 TrackPopupMenu (GetSubMenu(hPopup
, 0), 0, (UINT
)pt
.x
, (UINT
)pt
.y
, 0, hwnd
, NULL
);
341 if(LOWORD(wParam
) <= 5 && LOWORD(wParam
) >= 1)
344 if(PML_SetAction(tree
, selected
, LOWORD(wParam
)-1, SetIcon
, Ask
) == ERR_OK
)
347 MessageBeep(MB_ICONHAND
);
351 else if(LOWORD(wParam
)==6)
353 if(PML_DoIt(tree
, SetStatus
, Ask
) == ERR_OK
)
354 DialogBox(GetModuleHandle(NULL
), MAKEINTRESOURCE(IDD_DOIT
), hwnd
, StatusProc
);
356 MessageBeep(MB_ICONHAND
);
360 else if(LOWORD(wParam
)==7)
364 else if(LOWORD(wParam
)==8)
365 DialogBox(GetModuleHandle(NULL
), MAKEINTRESOURCE(IDD_OPTIONS
), hwnd
, OptionsProc
);
372 if(PML_SetAction(tree
, selected
, wParam
, SetIcon
, Ask
) != ERR_OK
)
373 MessageBeep(MB_ICONHAND
);
377 // ... at the very end
385 return DefWindowProc (hwnd
, message
, wParam
, lParam
);
388 // Warning: This function is called from another thread
389 int SetStatus (int status1
, int status2
, WCHAR
* text
)
393 // Set the Rage to 1000
394 SendMessage(GetDlgItem(hStatus
, IDC_STATUS1
), PBM_SETRANGE32
, 0, 1000);
395 SendMessage(GetDlgItem(hStatus
, IDC_STATUS2
), PBM_SETRANGE32
, 0, 1000);
397 // The prozessbars and the text filds
399 SetDlgItemText(hStatus
, IDC_TSTATUS
, text
);
402 SendMessage(GetDlgItem(hStatus
, IDC_STATUS1
), PBM_SETPOS
, status1
, 0);
405 SendMessage(GetDlgItem(hStatus
, IDC_STATUS2
), PBM_SETPOS
, status2
, 0);
407 // If the Status is 1000 everything is done
410 EndDialog(hStatus
, TRUE
);
411 MessageBox(0,PML_TransError(status2
, errbuf
, sizeof(errbuf
)/sizeof(WCHAR
)),0,0);
417 // Callback for the Status Dialog
418 INT_PTR CALLBACK
StatusProc (HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
428 case WM_COMMAND
: // can only be the about button
429 case WM_CLOSE
: // the close-window-[x]
432 EndDialog(hwnd
, TRUE
);
440 // Callback for the Options Dialog
441 INT_PTR CALLBACK
OptionsProc (HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
446 EndDialog(hwnd
, TRUE
);