893cb7a026a92598459b498478ec7ff3cf1be102
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 TranslateMessage(&msg
);
71 DispatchMessage(&msg
);
80 // Add a item to our tree
81 int AddItem (int id
, const char* name
, int parent
, int icon
)
83 TV_INSERTSTRUCT tvins
;
85 tvins
.item
.lParam
= (UINT
)id
;
86 tvins
.item
.mask
= TVIF_TEXT
|TVIF_PARAM
;
87 tvins
.item
.pszText
= (WCHAR
*)name
; //that is ok
88 tvins
.item
.cchTextMax
= strlen(name
);
89 tvins
.hInsertAfter
= TVI_LAST
;
93 tvins
.item
.iImage
= icon
;
94 tvins
.item
.iSelectedImage
= icon
;
95 tvins
.item
.mask
|= TVIF_IMAGE
| TVIF_SELECTEDIMAGE
;
99 tvins
.hParent
= TVI_ROOT
;
101 tvins
.hParent
= nodes
[parent
];
103 nodes
[id
] = (HTREEITEM
)SendMessage(hTree
, TVM_INSERTITEMA
, 0, (LPARAM
)&tvins
);
108 // Load the Help from file and display it
113 ifstream
file("help.txt", ios_base::in
);
114 getline(file
, source
, '\0');
116 SetText(source
.c_str());
119 // Create our Controls
120 void InitControls (HWND hwnd
)
123 HINSTANCE hinst
= GetModuleHandle(NULL
);
125 // Create the controls
126 hTree
= CreateWindowEx(0, WC_TREEVIEW
, L
"TreeView", WS_CHILD
|WS_VISIBLE
|WS_BORDER
|TVS_HASLINES
|TVS_LINESATROOT
|TVS_HASBUTTONS
,
127 0, 0, 0, 0, hwnd
, NULL
, hinst
, NULL
);
129 hEdit
= CreateWindowEx(WS_EX_CLIENTEDGE
, L
"edit", PML_TransError(IDS_LOAD
), WS_CHILD
|WS_VISIBLE
|ES_MULTILINE
,
130 0, 0, 100, 100, hwnd
, NULL
, hinst
, NULL
);
132 hPopup
= LoadMenu(hinst
, MAKEINTRESOURCE(IDR_POPUP
));
135 HIMAGELIST hIcon
= ImageList_Create(16,16,ILC_COLOR32
,1,1);
136 SendMessage(hTree
, TVM_SETIMAGELIST
, TVSIL_NORMAL
, (LPARAM
)(HIMAGELIST
)hIcon
);
138 ImageList_AddIcon(hIcon
, LoadIcon(hinst
, MAKEINTRESOURCE(1)));
139 ImageList_AddIcon(hIcon
, LoadIcon(hinst
, MAKEINTRESOURCE(11)));
140 ImageList_AddIcon(hIcon
, LoadIcon(hinst
, MAKEINTRESOURCE(12)));
141 ImageList_AddIcon(hIcon
, LoadIcon(hinst
, MAKEINTRESOURCE(13)));
142 ImageList_AddIcon(hIcon
, LoadIcon(hinst
, MAKEINTRESOURCE(14)));
144 ImageList_AddIcon(hIcon
, LoadIcon(hinst
, MAKEINTRESOURCE(2)));
145 ImageList_AddIcon(hIcon
, LoadIcon(hinst
, MAKEINTRESOURCE(3)));
146 ImageList_AddIcon(hIcon
, LoadIcon(hinst
, MAKEINTRESOURCE(4)));
147 ImageList_AddIcon(hIcon
, LoadIcon(hinst
, MAKEINTRESOURCE(5)));
148 ImageList_AddIcon(hIcon
, LoadIcon(hinst
, MAKEINTRESOURCE(6)));
149 ImageList_AddIcon(hIcon
, LoadIcon(hinst
, MAKEINTRESOURCE(7)));
150 ImageList_AddIcon(hIcon
, LoadIcon(hinst
, MAKEINTRESOURCE(8)));
151 ImageList_AddIcon(hIcon
, LoadIcon(hinst
, MAKEINTRESOURCE(9)));
152 ImageList_AddIcon(hIcon
, LoadIcon(hinst
, MAKEINTRESOURCE(10)));
155 RegisterHotKey(hwnd
, 1, MOD_CONTROL
, VK_1
);
156 RegisterHotKey(hwnd
, 2, MOD_CONTROL
, VK_2
);
157 RegisterHotKey(hwnd
, 3, MOD_CONTROL
, VK_3
);
158 RegisterHotKey(hwnd
, 4, MOD_CONTROL
, VK_4
);
159 RegisterHotKey(hwnd
, 0, MOD_CONTROL
, VK_0
);
163 int SetIcon (int id
, int icon
)
167 item
.hItem
= nodes
[id
];
169 item
.iSelectedImage
= icon
;
170 item
.mask
= TVIF_IMAGE
| TVIF_SELECTEDIMAGE
;
172 TreeView_SetItem(hTree
, &item
);
177 // En- or Disable a Button inside of the toolbar and the Context Menu
178 int SetButton (DWORD id
, BOOL state
)
180 // Change the Toorbar Button
183 ti
.cbSize
= sizeof (ti
);
184 ti
.dwMask
= TBIF_STATE
;
187 ti
.fsState
= TBSTATE_ENABLED
;
189 ti
.fsState
= TBSTATE_INDETERMINATE
;
191 SendMessage (hTBar
, TB_SETBUTTONINFO
, id
, (LPARAM
)&ti
);
193 // Change the Context Menu item
196 mi
.cbSize
= sizeof (mi
);
197 mi
.fMask
= MIIM_STATE
;
200 mi
.fState
= MFS_ENABLED
;
203 mi
.fState
= MFS_GRAYED
;
205 SetMenuItemInfo(hPopup
, id
, FALSE
, &mi
);
210 // Set the text of the text box
211 int SetText (const char* text
)
214 string source
= text
;
216 // the windows does not need "\n"
217 // for new lines but "\r\n"
218 for(i
=0; source
[i
]; i
++)
219 if(source
[i
]=='\n' && source
[i
]!='\r')
220 source
.insert (i
++, "\r");
222 SetWindowTextA(hEdit
, source
.c_str());
227 // Windows Message Callback (this is where most things happen)
228 LRESULT CALLBACK
WndProc (HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
232 // at the very beginning ...
239 // calculate the size of the controls
243 SendMessage(hTBar
, TB_AUTOSIZE
, 0L, 0L);
244 GetWindowRect(hTBar
, &rcl
);
246 int win_top
= rcl
.bottom
- rcl
.top
;
247 int win_hight
= HIWORD(lParam
) - win_top
;
249 MoveWindow(hTree
, 0, win_top
, LOWORD(lParam
), splitter_pos
*win_hight
/100, TRUE
);
250 MoveWindow(hEdit
, 0, (splitter_pos
*win_hight
/100)+win_top
, LOWORD(lParam
), win_hight
, TRUE
);
257 if(((LPNMHDR
)lParam
)->code
== TVN_SELCHANGED
)
259 selected
= ((LPNMTREEVIEW
)lParam
)->itemNew
.lParam
;
260 PML_LoadPackage (tree
, selected
, SetButton
, SetText
);
263 else if ((int)(((LPNMHDR
)lParam
)->code
) == NM_RCLICK
) // <= ahhh LISP
265 // which item has been click on
266 HTREEITEM item
= TreeView_GetDropHilight(hTree
);
270 // mark the one as seleacted
271 SendMessage (hTree
, TVM_SELECTITEM
, TVGN_CARET
, (LPARAM
)item
);
272 TreeView_EnsureVisible (hTree
, item
);
275 // create the context menu
280 TrackPopupMenu (GetSubMenu(hPopup
, 0), 0, (UINT
)pt
.x
, (UINT
)pt
.y
, 0, hwnd
, NULL
);
290 if(LOWORD(wParam
) <= 5 && LOWORD(wParam
) >= 1)
293 if(PML_SetAction(tree
, selected
, LOWORD(wParam
)-1, SetIcon
) == ERR_OK
)
296 MessageBeep(MB_ICONHAND
);
300 else if(LOWORD(wParam
)==6)
302 if(PML_DoIt(tree
, SetStatus
) == ERR_OK
)
303 DialogBox(GetModuleHandle(NULL
), MAKEINTRESOURCE(IDD_DOIT
), hwnd
, StatusProc
);
305 MessageBeep(MB_ICONHAND
);
309 else if(LOWORD(wParam
)==7)
313 else if(LOWORD(wParam
)==8)
314 DialogBox(GetModuleHandle(NULL
), MAKEINTRESOURCE(IDD_OPTIONS
), hwnd
, OptionsProc
);
324 if(PML_SetAction(tree
, selected
, wParam
, SetIcon
) != ERR_OK
)
325 MessageBeep(MB_ICONHAND
);
329 // ... at the very end
337 return DefWindowProc (hwnd
, message
, wParam
, lParam
);
340 // Warning: This function is called from another thread
341 int SetStatus (int status1
, int status2
, WCHAR
* text
)
343 // Set the Rage to 1000
344 SendMessage(GetDlgItem(hStatus
, IDC_STATUS1
), PBM_SETRANGE32
, 0, 1000);
345 SendMessage(GetDlgItem(hStatus
, IDC_STATUS2
), PBM_SETRANGE32
, 0, 1000);
347 // The prozessbars and the text filds
349 SetDlgItemText(hStatus
, IDC_TSTATUS
, text
);
352 SendMessage(GetDlgItem(hStatus
, IDC_STATUS1
), PBM_SETPOS
, status1
, 0);
355 SendMessage(GetDlgItem(hStatus
, IDC_STATUS2
), PBM_SETPOS
, status2
, 0);
357 // If the Status is 1000 very thing is done
360 EndDialog(hStatus
, TRUE
);
361 MessageBox(0,PML_TransError(status2
),0,0);
367 // Callback for the Status Dialog
368 INT_PTR CALLBACK
StatusProc (HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
378 case WM_COMMAND
: // can only be the about button
379 case WM_CLOSE
: // the close-window-[x]
382 EndDialog(hwnd
, TRUE
);
390 // Callback for the Options Dialog
391 INT_PTR CALLBACK
OptionsProc (HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
396 EndDialog(hwnd
, TRUE
);