eliminate GCC warning about initialization order
[reactos.git] / reactos / subsys / system / explorer / shell / shellbrowser.h
index 652508b..1de9369 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2003, 2004 Martin Fuchs
+ * Copyright 2003, 2004, 2005 Martin Fuchs
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -18,7 +18,7 @@
 
 
  //
- // Explorer clone, lean version
+ // Explorer clone
  //
  // shellbrowser.h
  //
@@ -34,6 +34,13 @@ struct ShellPathInfo
 {
        ShellPathInfo(int mode=0) : _open_mode(mode) {}
 
+       ShellPathInfo(const ShellChildWndInfo& info)
+        :      _shell_path(info._shell_path),
+               _root_shell_path(info._root_shell_path),
+               _open_mode(info._open_mode)
+       {
+       }
+
        ShellPath       _shell_path;
        ShellPath       _root_shell_path;
 
@@ -41,11 +48,22 @@ struct ShellPathInfo
 };
 
 
+struct BrowserCallback
+{
+       virtual ~BrowserCallback() {}
+       virtual void entry_selected(Entry* entry) = 0;
+};
+
+
  /// Implementation of IShellBrowserImpl interface in explorer child windows
-struct ShellBrowserChild : public IShellBrowserImpl
+struct ShellBrowser : public IShellBrowserImpl
+#ifndef __MINGW32__    // IShellFolderViewCB missing in MinGW (as of 25.09.2005)
+       ,       public IComSrvBase<IShellFolderViewCB, ShellBrowser>, public SimpleComObject
+#endif
 {
-       ShellBrowserChild(HWND hwnd, HWND left_hwnd, WindowHandle& right_hwnd, ShellPathInfo& create_info);
-       virtual ~ShellBrowserChild();
+       ShellBrowser(HWND hwnd, HWND hwndFrame, HWND left_hwnd, WindowHandle& right_hwnd, ShellPathInfo& create_info,
+                                       BrowserCallback* cb, CtxMenuInterfaces& cm_ifs);
+       virtual ~ShellBrowser();
 
        //IOleWindow
        virtual HRESULT STDMETHODCALLTYPE GetWindow(HWND* lphwnd)
@@ -72,7 +90,7 @@ struct ShellBrowserChild : public IShellBrowserImpl
                        return S_OK;
                }
 
-               HWND hwnd = (HWND)SendMessage(_hWndFrame, PM_GET_CONTROLWINDOW, id, 0);
+               HWND hwnd = (HWND)SendMessage(_hwndFrame, PM_GET_CONTROLWINDOW, id, 0);
 
                if (hwnd) {
                        *lphwnd = hwnd;
@@ -87,7 +105,7 @@ struct ShellBrowserChild : public IShellBrowserImpl
                if (!pret)
                        return E_POINTER;
 
-               HWND hstatusbar = (HWND)SendMessage(_hWndFrame, PM_GET_CONTROLWINDOW, id, 0);
+               HWND hstatusbar = (HWND)SendMessage(_hwndFrame, PM_GET_CONTROLWINDOW, id, 0);
 
                if (hstatusbar) {
                        *pret = ::SendMessage(hstatusbar, uMsg, wParam, lParam);
@@ -99,57 +117,158 @@ struct ShellBrowserChild : public IShellBrowserImpl
 
        const Root& get_root() const {return _root;}
 
+       void    OnTreeGetDispInfo(int idCtrl, LPNMHDR pnmh);
+       void    OnTreeItemExpanding(int idCtrl, LPNMTREEVIEW pnmtv);
+       void    OnTreeItemRClick(int idCtrl, LPNMHDR pnmh);
+       void    OnTreeItemSelected(int idCtrl, LPNMTREEVIEW pnmtv);
+
+       void    Init();
+
+       int             InsertSubitems(HTREEITEM hParentItem, Entry* entry, IShellFolder* pParentFolder);
+
+       bool    jump_to_pidl(LPCITEMIDLIST pidl);
+
+       HRESULT OnDefaultCommand(LPIDA pida);
+
+       void    UpdateFolderView(IShellFolder* folder);
+       HTREEITEM select_entry(HTREEITEM hitem, Entry* entry, bool expand=true);
+
+       bool    select_folder(Entry* entry, bool expand);
+
+        // for SDIMainFrame
+       void    jump_to(LPCITEMIDLIST pidl);
+
+       void    invalidate_cache();
+
 protected:
-       HWND    _hwnd;
-       HWND    _left_hwnd;
-       WindowHandle& _right_hwnd;
-       ShellPathInfo& _create_info;
+       HWND                    _hwnd;
+       HWND                    _hwndFrame;
+       HWND                    _left_hwnd;
+       WindowHandle&   _right_hwnd;
+       ShellPathInfo&  _create_info;
+       HIMAGELIST              _himl;
+       HIMAGELIST              _himl_old;
+       BrowserCallback* _callback;
 
-       Root    _root;
+       ShellFolder             _folder;
 
-       WindowHandle _hWndFrame;
-       ShellFolder     _folder;
+       IShellView*             _pShellView;    // current hosted shellview
+       TreeDropTarget* _pDropTarget;
 
-       IShellView*     _pShellView;    // current hosted shellview
-       HIMAGELIST      _himlSmall;             // list
-//     HIMAGELIST      _himlLarge;             // shell image
-       TreeDropTarget* _pDropTarget;
+       HTREEITEM               _last_sel;
 
-       HTREEITEM _last_sel;
+       Root                    _root;
+       ShellDirectory* _cur_dir;
 
-public:
-       LRESULT WndProc(UINT nmsg, WPARAM wparam, LPARAM lparam);
-       int             Command(int id, int code);
-       int     Notify(int id, NMHDR* pnmh);
+       CtxMenuInterfaces& _cm_ifs;
 
-       LRESULT Init(HWND hWndFrame);
        void    InitializeTree();
-       int             InsertSubitems(HTREEITEM hParentItem, Entry* entry, IShellFolder* pParentFolder);
        bool    InitDragDrop();
 
-       HRESULT OnDefaultCommand(LPIDA pida);
+#ifndef __MINGW32__    // IShellFolderViewCB missing in MinGW (as of 25.09.2005)
+       typedef IComSrvBase<IShellFolderViewCB, ShellBrowser> super;
 
-       void    OnTreeGetDispInfo(int idCtrl, LPNMHDR pnmh);
-       void    OnTreeItemExpanding(int idCtrl, LPNMTREEVIEW pnmtv);
-       void    OnTreeItemRClick(int idCtrl, LPNMHDR pnmh);
-       void    OnTreeItemSelected(int idCtrl, LPNMTREEVIEW pnmtv);
+        // IShellFolderViewCB
+       virtual HRESULT STDMETHODCALLTYPE MessageSFVCB(UINT uMsg, WPARAM wParam, LPARAM lParam);
+#endif
 
-       void    UpdateFolderView(IShellFolder* folder);
-       void    Tree_DoItemMenu(HWND hwndTreeView, HTREEITEM hItem, LPPOINT pptScreen);
-       bool    expand_folder(ShellDirectory* entry);
+       map<int, int> _image_map;
+
+       int             get_image_idx(int icon_id);
+};
 
-       // SDI integration
-public:
-       int     _split_pos;
-       int             _last_split;
-       RECT    _clnt_rect;
 
-       /*virtual*/ void resize_children();
-       /*virtual*/ void jump_to(LPCTSTR path);
-       /*virtual*/ void jump_to(LPCITEMIDLIST pidl);
+#define        C_DRIVE_STR TEXT("C:\\")
 
-       void    jump_to(Entry* entry);
+ // work around GCC's wide string constant bug
+#ifdef __GNUC__
+extern const LPCTSTR C_DRIVE;
+#else
+#define        C_DRIVE C_DRIVE_STR
+#endif
+
+template<typename BASE> struct ShellBrowserChildT
+ : public BASE, public BrowserCallback
+{
+       typedef BASE super;
+
+        // constructor for SDIMainFrame
+       ShellBrowserChildT(HWND hwnd)
+        :      super(hwnd)
+       {
+       }
+
+        // constructor for MDIShellBrowserChild
+       ShellBrowserChildT(HWND hwnd, const ShellChildWndInfo& info)
+        :      super(hwnd, info)
+       {
+       }
 
 protected:
-       ShellDirectory* _cur_dir;
+       auto_ptr<ShellBrowser> _shellBrowser;
+
+       LRESULT WndProc(UINT nmsg, WPARAM wparam, LPARAM lparam)
+       {
+               switch(nmsg) {
+                 case PM_GET_SHELLBROWSER_PTR:
+                       return (LRESULT)&*_shellBrowser;
+
+                 case WM_GETISHELLBROWSER:     // for Registry Explorer Plugin
+                       return (LRESULT)static_cast<IShellBrowser*>(&*_shellBrowser);
+
+                 default:
+                       return super::WndProc(nmsg, wparam, lparam);
+               }
+
+               return 0;
+       }
+
+       int Notify(int id, NMHDR* pnmh)
+       {
+               if (_shellBrowser.get())
+                       switch(pnmh->code) {
+                         case TVN_GETDISPINFO:         _shellBrowser->OnTreeGetDispInfo(id, pnmh);                                     break;
+                         case TVN_SELCHANGED:          _shellBrowser->OnTreeItemSelected(id, (LPNMTREEVIEW)pnmh);      break;
+                         case TVN_ITEMEXPANDING:       _shellBrowser->OnTreeItemExpanding(id, (LPNMTREEVIEW)pnmh);     break;
+                         case NM_RCLICK:                       _shellBrowser->OnTreeItemRClick(id, pnmh);                                      break;
+                         default:                                      return super::Notify(id, pnmh);
+                       }
+               else
+                       return super::Notify(id, pnmh);
+
+               return 0;
+       }
 };
+
+
+#ifndef _NO_MDI
+
+struct MDIShellBrowserChild : public ExtContextMenuHandlerT<
+                               ShellBrowserChildT<ChildWindow>
+                       >
+{
+       typedef ExtContextMenuHandlerT<
+                               ShellBrowserChildT<ChildWindow>
+                       > super;
+
+       MDIShellBrowserChild(HWND hwnd, const ShellChildWndInfo& info);
+
+       static MDIShellBrowserChild* create(const ShellChildWndInfo& info);
+
+       LRESULT Init(LPCREATESTRUCT);
+
+       virtual String jump_to_int(LPCTSTR url);
+
+protected:
+       ShellChildWndInfo _create_info;
+       ShellPathInfo   _shellpath_info;
+
+       LRESULT WndProc(UINT nmsg, WPARAM wparam, LPARAM lparam);
+
+       void    update_shell_browser();
+
+        // interface BrowserCallback
+       virtual void entry_selected(Entry* entry);
+};
+
+#endif