first draft of working task bar
[reactos.git] / reactos / subsys / system / explorer / explorer.cpp
1 /*
2 * Copyright 2003 Martin Fuchs
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 */
18
19
20 //
21 // Explorer clone
22 //
23 // explorer.cpp
24 //
25 // Martin Fuchs, 23.07.2003
26 //
27 // Credits: Thanks to Leon Finker for his explorer window example
28 //
29
30
31 #include "utility/utility.h"
32 #include "utility/shellclasses.h"
33
34 #include "explorer.h"
35 #include "globals.h"
36
37 #include "explorer_intres.h"
38 #include "externals.h"
39
40
41 ExplorerGlobals g_Globals;
42
43
44 ExplorerGlobals::ExplorerGlobals()
45 {
46 _hInstance = 0;
47 _hframeClass = 0;
48 _cfStrFName = 0;
49 _hMainWnd = 0;
50 _prescan_nodes = false;
51 _desktop_mode = false;
52 }
53
54
55 ResString::ResString(UINT nid)
56 {
57 TCHAR buffer[BUFFER_LEN];
58
59 int len = LoadString(g_Globals._hInstance, nid, buffer, sizeof(buffer)/sizeof(TCHAR));
60
61 assign(buffer, len);
62 }
63
64
65 void explorer_show_frame(HWND hwndDesktop, int cmdshow)
66 {
67 if (g_Globals._hMainWnd)
68 return;
69
70 g_Globals._prescan_nodes = false;
71
72 HMENU hMenuFrame = LoadMenu(g_Globals._hInstance, MAKEINTRESOURCE(IDM_MAINFRAME));
73
74 // create main window
75 g_Globals._hMainWnd = Window::Create(WINDOW_CREATOR(MainFrame), 0,
76 (LPCTSTR)(int)g_Globals._hframeClass, ResString(IDS_TITLE), WS_OVERLAPPEDWINDOW,
77 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
78 0/*hwndDesktop*/, hMenuFrame);
79
80 ShowWindow(g_Globals._hMainWnd, cmdshow);
81
82 UpdateWindow(g_Globals._hMainWnd);
83
84 // Open the first child window after initialiszing the whole application
85 PostMessage(g_Globals._hMainWnd, WM_OPEN_WINDOW, 0, 0);
86 }
87
88
89 static void InitInstance(HINSTANCE hinstance)
90 {
91 g_Globals._hInstance = hinstance;
92
93 setlocale(LC_COLLATE, ""); // set collating rules to local settings for compareName
94
95
96 // register frame window class
97
98 WindowClass wcFrame(CLASSNAME_FRAME);
99
100 wcFrame.hIcon = LoadIcon(hinstance, MAKEINTRESOURCE(IDI_EXPLORER));
101 wcFrame.hCursor = LoadCursor(0, IDC_ARROW);
102 wcFrame.hIconSm = (HICON)LoadImage(hinstance,
103 MAKEINTRESOURCE(IDI_EXPLORER),
104 IMAGE_ICON,
105 GetSystemMetrics(SM_CXSMICON),
106 GetSystemMetrics(SM_CYSMICON),
107 LR_SHARED);
108
109 g_Globals._hframeClass = wcFrame.Register();
110
111
112 // register child windows class
113
114 WindowClass wcChild(CLASSNAME_CHILDWND);
115
116 wcChild.style = CS_CLASSDC|CS_DBLCLKS|CS_VREDRAW;
117 wcChild.hCursor = LoadCursor(0, IDC_ARROW);
118
119 wcChild.Register();
120
121
122 // register tree windows class
123
124 WindowClass wcTreeChild(CLASSNAME_WINEFILETREE);
125
126 wcTreeChild.style = CS_CLASSDC|CS_DBLCLKS|CS_VREDRAW;
127 wcTreeChild.hCursor = LoadCursor(0, IDC_ARROW);
128
129 wcTreeChild.Register();
130
131
132 g_Globals._cfStrFName = RegisterClipboardFormat(CFSTR_FILENAME);
133 }
134
135
136 int explorer_main(HINSTANCE hinstance, HWND hwndDesktop, int cmdshow)
137 {
138 // initialize COM and OLE
139 OleInit usingCOM;
140
141 // initialize Common Controls library
142 CommonControlInit usingCmnCtrl(ICC_LISTVIEW_CLASSES|ICC_TREEVIEW_CLASSES|ICC_BAR_CLASSES);
143
144 try {
145 MSG msg;
146
147 InitInstance(hinstance);
148
149 if (hwndDesktop)
150 g_Globals._desktop_mode = true;
151
152 if (cmdshow != SW_HIDE) {
153 #ifndef _ROS_ // don't maximize if being called from the ROS desktop
154 if (cmdshow == SW_SHOWNORMAL)
155 /*TODO: read window placement from registry */
156 cmdshow = SW_MAXIMIZE;
157 #endif
158
159 explorer_show_frame(hwndDesktop, cmdshow);
160 }
161
162 while(GetMessage(&msg, 0, 0, 0)) {
163 if (g_Globals._hMainWnd && SendMessage(g_Globals._hMainWnd, WM_TRANSLATE_MSG, 0, (LPARAM)&msg))
164 continue;
165
166 TranslateMessage(&msg);
167
168 try {
169 DispatchMessage(&msg);
170 } catch(COMException& e) {
171 HandleException(e, g_Globals._hMainWnd);
172 }
173 }
174
175 return msg.wParam;
176
177 } catch(COMException& e) {
178 HandleException(e, g_Globals._hMainWnd);
179 }
180
181 return -1;
182 }
183
184
185 int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nShowCmd)
186 {
187 // create desktop window and task bar only, if there is no other shell and we are
188 // the first explorer instance
189 BOOL startup_desktop = !IsAnyDesktopRunning();
190
191 // If there is given the command line option "-desktop", create desktop window anyways
192 if (!lstrcmp(lpCmdLine,TEXT("-desktop")))
193 startup_desktop = TRUE;
194
195 if (!lstrcmp(lpCmdLine,TEXT("-noexplorer"))) {
196 nShowCmd = SW_HIDE;
197 startup_desktop = TRUE;
198 }
199
200 HWND hwndDesktop = 0;
201
202 if (startup_desktop)
203 {
204 hwndDesktop = create_desktop_window(hInstance);
205
206 // Initialize the explorer bar
207 HWND hwndExplorerBar = InitializeExplorerBar(hInstance);
208
209 // Load plugins
210 // LoadAvailablePlugIns(hwndExplorerBar);
211
212 #ifndef _DEBUG //MF: disabled for debugging
213 {
214 char* argv[] = {""};
215 startup(1, argv);
216 }
217 #endif
218 }
219
220 int ret = explorer_main(hInstance, hwndDesktop, nShowCmd);
221
222 // ReleaseAvailablePlugIns();
223
224 return ret;
225 }