/*
 ============================================================================
 xoblite -> an alternative shell based on Blackbox for Windows
 Copyright  2002-2005 Karl-Henrik Henriksson [qwilk]
 Copyright  2001-2004 The Blackbox for Windows Development Team
 http://xoblite.net/ - #bb4win on irc.freenode.net
 ============================================================================

  Blackbox for Windows is free software, released under the
  GNU General Public License (GPL version 2 or later), with an extension
  that allows linking of proprietary modules under a controlled interface.
  What this means is that plugins etc. are allowed to be released
  under any license the author wishes. Please note, however, that the
  original Blackbox gradient math code used in Blackbox for Windows
  is available under the BSD license.

  http://www.fsf.org/licenses/gpl.html
  http://www.fsf.org/licenses/gpl-faq.html#LinkingOverControlledInterface
  http://www.xfree86.org/3.3.6/COPYRIGHT2.html#5

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  GNU General Public License for more details.

  For additional license information, please read the included license.html

 ============================================================================
*/

#include "SpecialFolder.h" 
#include "MenuMaker.h" 
#include "Menu.h" 
//#include "HeaderItem.h"

//===========================================================================

SpecialFolder::SpecialFolder(LPSTR pszPath, MenuMaker* pMenuMaker, LPSTR pszTitle, int menuType) : FolderItem(NULL, pszTitle)
{
        m_pszPath = pszPath ? strdup(pszPath) : NULL;
        m_pMenuMaker = pMenuMaker;
        m_MenuType = menuType;
}

SpecialFolder::~SpecialFolder()
{
        if(m_pszPath) free(m_pszPath);
        m_pszPath = NULL;

        if(m_pSubMenu)
        {
                m_pParent->RemoveChild(m_pSubMenu);
                delete m_pSubMenu;
        }
        m_pSubMenu = NULL;
}

//===========================================================================

void SpecialFolder::Invoke(int button)
{
        char folder[MAX_LINE_LENGTH], arg[MAX_LINE_LENGTH];
        strcpy(folder, m_pszPath);

        if (button == 2)
        {
                m_pParent->Hide(HIDE_PARENTS);
                MenuItem::Invoke(button);

                if (strchr(folder, '|'))
                {
                        // If this is a merged [path] item we use
                        // the first path when right clicking on it...
                        Tokenize(folder, arg, "|");
                        strcpy(folder, arg); // Note: Just using arg as a temp variable here...
                }

                if (folder[0] == '\"') StrRemoveEncap(folder);
                strcpy(arg, "/e,");
                strcat(arg, folder);

                BBExecute(GetDesktopWindow(), NULL, "explorer.exe", arg, folder, SW_SHOWNORMAL, false);
        }
        else if (button == 3)
        {
                if (folder[0] == '\"') StrRemoveEncap(folder);
                CopyStringToClipboard(folder);
        }
}

//====================

bool SpecialFolder::Active(bool bActivate)
{ 
        if (m_bActive == bActivate && m_pSubMenu)
                if (IsWindowVisible(m_pSubMenu->GetWindow()))
                        return bActivate;

                if (bActivate)
                {
                        if (m_pSubMenu)
                        {
                                ShowWindow(m_pSubMenu->GetWindow(), SW_HIDE);
                                m_pParent->RemoveChild(m_pSubMenu);
                                delete m_pSubMenu;
                        }
                        m_pSubMenu = m_pMenuMaker->LoadFolder(m_pszTitle, m_pszPath, m_MenuType);
                        m_pParent->AddChild(m_pSubMenu);
                        m_pSubMenu->SetParent(m_pParent);
                }

                return FolderItem::Active(bActivate);
}

//====================

void SpecialFolder::Attached(Menu* pMenu)
{
        m_pParent = pMenu;
}

//===========================================================================





syntax highlighting by

w e b c p p
web c plus plus