implemented context menus for 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
33 #include "explorer.h"
34 #include "globals.h"
35 #include "externals.h"
36
37 #include "explorer_intres.h"
38
39
40 ExplorerGlobals g_Globals;
41
42
43 ExplorerGlobals::ExplorerGlobals()
44 {
45 _hInstance = 0;
46 _hframeClass = 0;
47 _cfStrFName = 0;
48 _hMainWnd = 0;
49 _prescan_nodes = false;
50 _desktop_mode = false;
51 }
52
53
54 ResString::ResString(UINT nid)
55 {
56 TCHAR buffer[BUFFER_LEN];
57
58 int len = LoadString(g_Globals._hInstance, nid, buffer, sizeof(buffer)/sizeof(TCHAR));
59
60 assign(buffer, len);
61 }
62
63
64 ResIcon::ResIcon(UINT nid)
65 {
66 _hIcon = LoadIcon(g_Globals._hInstance, MAKEINTRESOURCE(nid));
67 }
68
69 SmallIcon::SmallIcon(UINT nid)
70 {
71 _hIcon = (HICON)LoadImage(g_Globals._hInstance, MAKEINTRESOURCE(nid), IMAGE_ICON, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_SHARED);
72 }
73
74
75 void explorer_show_frame(HWND hwndDesktop, int cmdshow)
76 {
77 if (g_Globals._hMainWnd)
78 return;
79
80 g_Globals._prescan_nodes = false;
81
82 // create main window
83 g_Globals._hMainWnd = MainFrame::Create();
84
85 ShowWindow(g_Globals._hMainWnd, cmdshow);
86
87 UpdateWindow(g_Globals._hMainWnd);
88
89 // Open the first child window after initialiszing the whole application
90 PostMessage(g_Globals._hMainWnd, PM_OPEN_WINDOW, 0, 0);
91 }
92
93
94 static void InitInstance(HINSTANCE hInstance)
95 {
96 setlocale(LC_COLLATE, ""); // set collating rules to local settings for compareName
97
98 // register frame window class
99 g_Globals._hframeClass = IconWindowClass(CLASSNAME_FRAME,IDI_EXPLORER);
100
101 // register child windows class
102 WindowClass(CLASSNAME_CHILDWND, CS_CLASSDC|CS_DBLCLKS|CS_VREDRAW).Register();
103
104 // register tree windows class
105 WindowClass(CLASSNAME_WINEFILETREE, CS_CLASSDC|CS_DBLCLKS|CS_VREDRAW).Register();
106
107 g_Globals._cfStrFName = RegisterClipboardFormat(CFSTR_FILENAME);
108 }
109
110
111 int explorer_main(HINSTANCE hInstance, HWND hwndDesktop, int cmdshow)
112 {
113 // initialize COM and OLE
114 OleInit usingCOM;
115
116 // initialize Common Controls library
117 CommonControlInit usingCmnCtrl;
118
119 try {
120 InitInstance(hInstance);
121 } catch(COMException& e) {
122 HandleException(e, g_Globals._hMainWnd);
123 return -1;
124 }
125
126 if (hwndDesktop)
127 g_Globals._desktop_mode = true;
128
129 if (cmdshow != SW_HIDE) {
130 #ifndef _ROS_ // don't maximize if being called from the ROS desktop
131 if (cmdshow == SW_SHOWNORMAL)
132 /*TODO: read window placement from registry */
133 cmdshow = SW_MAXIMIZE;
134 #endif
135
136 explorer_show_frame(hwndDesktop, cmdshow);
137 }
138
139 return Window::MessageLoop();
140 }
141
142
143 int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nShowCmd)
144 {
145 // create desktop window and task bar only, if there is no other shell and we are
146 // the first explorer instance
147 BOOL startup_desktop = !IsAnyDesktopRunning();
148
149 // If there is given the command line option "-desktop", create desktop window anyways
150 if (!lstrcmp(lpCmdLine,TEXT("-desktop")))
151 startup_desktop = TRUE;
152
153 if (!lstrcmp(lpCmdLine,TEXT("-noexplorer"))) {
154 nShowCmd = SW_HIDE;
155 startup_desktop = TRUE;
156 }
157
158 g_Globals._hInstance = hInstance;
159
160 HWND hwndDesktop = 0;
161
162 if (startup_desktop)
163 {
164 hwndDesktop = create_desktop_window();
165
166 // Initialize the explorer bar
167 HWND hwndExplorerBar = InitializeExplorerBar(hInstance);
168
169 // Load plugins
170 // LoadAvailablePlugIns(hwndExplorerBar);
171
172 #ifndef _DEBUG //MF: disabled for debugging
173 {
174 char* argv[] = {""};
175 startup(1, argv);
176 }
177 #endif
178 }
179
180 int ret = explorer_main(hInstance, hwndDesktop, nShowCmd);
181
182 // ReleaseAvailablePlugIns();
183
184 return ret;
185 }