This commit was manufactured by cvs2svn to create branch 'captive'.
[reactos.git] / subsys / system / explorer / Seashell / MainFrm.cpp
1 // MainFrm.cpp : implementation of the CMainFrame class
2 //
3
4 #include "stdafx.h"
5 #include "SeaShell.h"
6 #include "MFCExplorerDlg.h"
7 #include "FilterDlg.h"
8 #include "ShellTreeDlg.h"
9 #include "MainFrm.h"
10 #include "LeftView.h"
11 #include "SeaShellView.h"
12
13 #ifdef _DEBUG
14 #define new DEBUG_NEW
15 #undef THIS_FILE
16 static char THIS_FILE[] = __FILE__;
17 #endif
18
19 /////////////////////////////////////////////////////////////////////////////
20 // CMainFrame
21
22 IMPLEMENT_DYNCREATE(CMainFrame, CUIExplorerFrameWnd)
23
24 BEGIN_MESSAGE_MAP(CMainFrame, CUIExplorerFrameWnd)
25         //{{AFX_MSG_MAP(CMainFrame)
26         ON_WM_CREATE()
27         ON_COMMAND(ID_VIEW_EXPLORERDIALOG, OnViewExplorerdialog)
28         ON_COMMAND(ID_VIEW_FILEFILTER, OnViewFilefilter)
29         ON_COMMAND(ID_VIEW_TREEDIALOG, OnViewTreedialog)
30         //}}AFX_MSG_MAP
31         ON_UPDATE_COMMAND_UI_RANGE(AFX_ID_VIEW_MINIMUM, AFX_ID_VIEW_MAXIMUM, OnUpdateViewStyles)
32         ON_COMMAND_RANGE(AFX_ID_VIEW_MINIMUM, AFX_ID_VIEW_MAXIMUM, OnViewStyle)
33         ON_MESSAGE(WM_SETTINGCHANGE,OnSettingChange)
34 END_MESSAGE_MAP()
35
36 static UINT indicators[] =
37 {
38         ID_SEPARATOR,           // status line indicator
39         ID_INDICATOR_CAPS,
40         ID_INDICATOR_NUM,
41         ID_INDICATOR_SCRL,
42 };
43
44 /////////////////////////////////////////////////////////////////////////////
45 // CMainFrame construction/destruction
46
47 CMainFrame::CMainFrame()
48 {
49         // TODO: add member initialization code here
50         m_IDToolbar = IDR_MAINFRAME;
51         SetExplorerView(RUNTIME_CLASS(CSeaShellView));
52 }
53
54 CMainFrame::~CMainFrame()
55 {
56 }
57
58 void CMainFrame::CreateCoolBar()
59 {
60         if (m_pwndCoolBar == NULL)
61                 m_pwndCoolBar = new CWebBrowserCoolBar;
62         // hook up the frame window for notification messages
63         ((CWebBrowserCoolBar*)m_pwndCoolBar)->GetComboBox().SetTreeCtrlWnd(GetSafeHwnd());
64 }
65
66 int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
67 {
68         if (CUIExplorerFrameWnd::OnCreate(lpCreateStruct) == -1)
69                 return -1;
70         return 0;       
71 }
72
73 BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
74 {
75         if( !CUIExplorerFrameWnd::PreCreateWindow(cs) )
76                 return FALSE;
77         // TODO: Modify the Window class or styles here by modifying
78         //  the CREATESTRUCT cs
79
80         return TRUE;
81 }
82
83 /////////////////////////////////////////////////////////////////////////////
84 // CMainFrame diagnostics
85
86 #ifdef _DEBUG
87 void CMainFrame::AssertValid() const
88 {
89         CUIExplorerFrameWnd::AssertValid();
90 }
91
92 void CMainFrame::Dump(CDumpContext& dc) const
93 {
94         CUIExplorerFrameWnd::Dump(dc);
95 }
96
97 #endif //_DEBUG
98
99 /////////////////////////////////////////////////////////////////////////////
100 // CMainFrame message handlers
101
102 CSeaShellView* CMainFrame::GetRightPane()
103 {
104         CWnd* pWnd = GetSplitterWnd().GetPane(0, 1);
105         CSeaShellView* pView = DYNAMIC_DOWNCAST(CSeaShellView, pWnd);
106         return pView;
107 }
108
109 void CMainFrame::OnUpdateViewStyles(CCmdUI* pCmdUI)
110 {
111         // TODO: customize or extend this code to handle choices on the
112         // View menu.
113
114         CSeaShellView* pView = GetRightPane(); 
115
116         // if the right-hand pane hasn't been created or isn't a view,
117         // disable commands in our range
118
119         if (pView == NULL)
120                 pCmdUI->Enable(FALSE);
121         else
122         {
123                 DWORD dwStyle = pView->GetListCtrl().GetViewType();
124
125                 // if the command is ID_VIEW_LINEUP, only enable command
126                 // when we're in LVS_ICON or LVS_SMALLICON mode
127
128                 if (pCmdUI->m_nID == ID_VIEW_LINEUP)
129                 {
130                         if (dwStyle == LVS_ICON || dwStyle == LVS_SMALLICON)
131                                 pCmdUI->Enable();
132                         else
133                                 pCmdUI->Enable(FALSE);
134                 }
135                 else
136                 {
137                         // otherwise, use dots to reflect the style of the view
138                         pCmdUI->Enable();
139                         BOOL bChecked = FALSE;
140
141                         switch (pCmdUI->m_nID)
142                         {
143                         case ID_VIEW_DETAILS:
144                                 bChecked = (dwStyle == LVS_REPORT);
145                                 break;
146
147                         case ID_VIEW_SMALLICON:
148                                 bChecked = (dwStyle == LVS_SMALLICON);
149                                 break;
150
151                         case ID_VIEW_LARGEICON:
152                                 bChecked = (dwStyle == LVS_ICON);
153                                 break;
154
155                         case ID_VIEW_LIST:
156                                 bChecked = (dwStyle == LVS_LIST);
157                                 break;
158
159                         default:
160                                 bChecked = FALSE;
161                                 break;
162                         }
163
164                         pCmdUI->SetRadio(bChecked ? 1 : 0);
165                 }
166         }
167 }
168
169
170 void CMainFrame::OnViewStyle(UINT nCommandID)
171 {
172         // TODO: customize or extend this code to handle choices on the
173         // View menu.
174         CSeaShellView* pView = (CSeaShellView*)theApp.GetView(RUNTIME_CLASS(CSeaShellView));;
175
176         // if the right-hand pane has been created and is a CSeaShellView,
177         // process the menu commands...
178         if (pView != NULL)
179         {
180                 DWORD dwStyle = -1;
181
182                 switch (nCommandID)
183                 {
184                 case ID_VIEW_LINEUP:
185                         {
186                                 // ask the list control to snap to grid
187                                 CListCtrl& refListCtrl = pView->GetListCtrl();
188                                 refListCtrl.Arrange(LVA_SNAPTOGRID);
189                         }
190                         break;
191
192                 // other commands change the style on the list control
193                 case ID_VIEW_DETAILS:
194                         dwStyle = LVS_REPORT;
195                         break;
196
197                 case ID_VIEW_SMALLICON:
198                         dwStyle = LVS_SMALLICON;
199                         break;
200
201                 case ID_VIEW_LARGEICON:
202                         dwStyle = LVS_ICON;
203                         break;
204
205                 case ID_VIEW_LIST:
206                         dwStyle = LVS_LIST;
207                         break;
208                 }
209
210                 // change the style; window will repaint automatically
211                 if (dwStyle != -1)
212                         pView->GetListCtrl().SetViewType(dwStyle);
213         }
214 }
215
216 LRESULT CMainFrame::OnSettingChange(WPARAM wParam, LPARAM lParam)
217 {
218         TRACE(_T("OnSettingChange\n"));
219         CSeaShellView *pListView = (CSeaShellView*)theApp.GetView(RUNTIME_CLASS(CSeaShellView));
220         if (pListView)
221                 pListView->GetListCtrl().SendMessage(WM_SETTINGCHANGE,wParam,lParam);           
222         return 1;
223 }
224
225 void CMainFrame::OnViewExplorerdialog() 
226 {
227         // TODO: Add your command handler code here
228         CLeftView *pTreeView = (CLeftView*)theApp.GetView(RUNTIME_CLASS(CLeftView));
229         CMFCExplorerDlg dlg;
230         if (pTreeView && pTreeView->GetShellTreeCtrl().GetSelectedItem() != pTreeView->GetShellTreeCtrl().GetRootItem())
231         {
232                 dlg.SetPath(pTreeView->GetShellTreeCtrl().GetSelectedPath());
233         }
234         dlg.DoModal();          
235 }
236
237 void CMainFrame::OnViewFilefilter() 
238 {
239         // TODO: Add your command handler code here
240         CSeaShellView *pListView = (CSeaShellView*)theApp.GetView(RUNTIME_CLASS(CSeaShellView));
241         if (pListView)
242         {
243                 CFilterDlg dlg;
244                 dlg.m_Filter = pListView->GetShellListCtrl().GetFileFilter();
245                 if (!pListView->GetShellListCtrl().GetExcludedFileTypes().IsEmpty())
246                         dlg.m_FileType = pListView->GetShellListCtrl().GetExcludedFileTypes().GetHead();
247                 if (dlg.DoModal() == IDOK)
248                 {
249                         if (!dlg.m_FileType.IsEmpty())
250                                 pListView->GetShellListCtrl().ExcludeFileType(dlg.m_FileType);          
251                         pListView->GetShellListCtrl().SetFileFilter(dlg.m_Filter);              
252                         pListView->GetShellListCtrl().Refresh();
253                 }
254         }       
255 }
256
257 void CMainFrame::OnViewTreedialog() 
258 {
259         // TODO: Add your command handler code here
260         CShellTreeDlg dlg;
261         dlg.DoModal();
262 }