/*
 ============================================================================
 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 "../BBApi.h" 
#include "MenuMaker.h" 
#include "ToolbarMenu.h" 
#include "MenuItem.h" 
#include "CommandItem.h" 
#include "FolderItem.h" 
#include "SystembarMenu.h" 
#include "../Systembar.h" 
#include "../Slit.h" 
#include "../Settings.h" 

extern MenuMaker *pMenuMaker;
extern Systembar *pSystembar;
extern Slit *pSlit;
extern Settings *pSettings;

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

ToolbarMenu::ToolbarMenu(const char *pszTitle, MenuMaker *pMenuMaker) : Menu(pMenuMaker->hInst)
{
        m_pMenuMaker = pMenuMaker;
        m_pszTitle = pszTitle ? strdup(pszTitle) : NULL;
}

ToolbarMenu::~ToolbarMenu()
{
        if(m_pszTitle) free(m_pszTitle);
        m_pszTitle = NULL;
}

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

void ToolbarMenu::OnShow(bool fShow)
{
        if(fShow) UpdateFolder();
}

void ToolbarMenu::UpdateFolder()
{
        DeleteMenuItems();
        m_pMenuMaker->AddHeaderItem(this, m_pszTitle);

        ToolbarPlacement *TPlacement = new ToolbarPlacement("Placement", m_pMenuMaker);
        TPlacement->SetActivePainter(m_pMenuMaker->m_pSelEntry);
        TPlacement->SetPainter(m_pMenuMaker->m_pEntry);
        TPlacement->SetHeight(m_pMenuMaker->m_nSubmenuHeight);
        AddMenuItem(TPlacement);

        SystembarTaskbar *STaskbar = new SystembarTaskbar("Taskbar", m_pMenuMaker);
        STaskbar->SetActivePainter(m_pMenuMaker->m_pSelEntry);
        STaskbar->SetPainter(m_pMenuMaker->m_pEntry);
        STaskbar->SetHeight(m_pMenuMaker->m_nSubmenuHeight);
        AddMenuItem(STaskbar);

        m_pMenuMaker->CreateMenuItem(this, "[separator]", NULL, NULL, false);
/*
        char command[MAX_LINE_LENGTH], title[MAX_LINE_LENGTH];
        sprintf(command, "\"@xoblite SetClockFormat\" %s", pSettings->strftimeFormat);
        sprintf(title, "Clock format: <%s>", pSettings->strftimeFormat);
        m_pMenuMaker->CreateMenuItem(this, "<edit-string>", command, title, false);
*/
        m_pMenuMaker->CreateMenuItem(this, "<toolbar_menu_item>", "AlwaysOnTop", "Always on top", pSettings->toolbarOnTop);
        if (pSettings->toolbarPlacement[0] == 'M') // Manual positioning?
                m_pMenuMaker->CreateMenuItem(this, "<toolbar_menu_item>", "SnapToEdges", "Snap to screen edges", pSettings->toolbarSnapToEdges);
        else m_pMenuMaker->CreateMenuItem(this, "<toolbar_menu_item>", "AutoHide", "Auto hide", pSettings->toolbarAutoHide);
//      m_pMenuMaker->CreateMenuItem(this, "<toolbar_menu_item>", "EditWorkspaceName", "Edit current workspace name", false);

        char command[50];
        sprintf(command, "\"@xoblite Toolbar Transparency\" %d 1 255", pSettings->toolbarTransparencyAlpha);
        m_pMenuMaker->CreateMenuItem(this, "<edit-int>", command, "Transparency:", false);

        m_pMenuMaker->CreateMenuItem(this, "[separator]", NULL, NULL, false);

        if (!pSystembar->DockedToSlit)
        {
                if (pSettings->systembarHidden) m_pMenuMaker->CreateMenuItem(this, "[togglesystembar]", NULL, "Show Systembar", false);
                else m_pMenuMaker->CreateMenuItem(this, "[togglesystembar]", NULL, "Hide Systembar", false);
        }

        if (pSlit->SlitPlugins.size() > 0)
        {
                if (pSettings->slitHidden) m_pMenuMaker->CreateMenuItem(this, "[toggleslit]", NULL, "Show Slit", false);
                else m_pMenuMaker->CreateMenuItem(this, "[toggleslit]", NULL, "Hide Slit", false);
        }

        if (pSettings->pluginsHidden) m_pMenuMaker->CreateMenuItem(this, "[toggleplugins]", NULL, "Show Plugins", false);
        else m_pMenuMaker->CreateMenuItem(this, "[toggleplugins]", NULL, "Hide Plugins", false);

        m_pMenuMaker->AddBottomItem(this);
        Invalidate();
        Validate();
}

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

ToolbarPlacement::ToolbarPlacement(char* pszTitle, MenuMaker *pMenuMaker) : FolderItem(NULL, pszTitle)
{
        m_pMenuMaker = pMenuMaker;
}

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

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

bool ToolbarPlacement::Active(bool bActivate)
{
        if (bActivate && !m_bActive) UpdateFolder();
        return FolderItem::Active(bActivate);
}

void ToolbarPlacement::Attached(Menu* pMenu)
{
        m_pParent = pMenu;
        m_pSubMenu = new Menu(m_pMenuMaker->hInst);
        m_pParent->AddChild(m_pSubMenu);
        m_pSubMenu->SetParent(m_pParent);
}

void ToolbarPlacement::UpdateFolder()
{
        m_pSubMenu->DeleteMenuItems();
        m_pMenuMaker->AddHeaderItem(m_pSubMenu, m_pszTitle);

        if (pSettings->toolbarPlacement[0] == 'M')
        {
                m_pMenuMaker->CreateMenuItem(m_pSubMenu, "<toolbar_menu_item>", "ManualPositioning", pSettings->toolbarPlacement, true);
                m_pMenuMaker->CreateMenuItem(m_pSubMenu, "[separator]", NULL, NULL, false);
        }
        m_pMenuMaker->CreateMenuItem(m_pSubMenu, "<toolbar_menu_item>", "TopLeft", "Top Left", (!stricmp(pSettings->toolbarPlacement, "TopLeft")));
        m_pMenuMaker->CreateMenuItem(m_pSubMenu, "<toolbar_menu_item>", "BottomLeft", "Bottom Left", (!stricmp(pSettings->toolbarPlacement, "BottomLeft")));
        m_pMenuMaker->CreateMenuItem(m_pSubMenu, "[separator]", NULL, NULL, false);
        m_pMenuMaker->CreateMenuItem(m_pSubMenu, "<toolbar_menu_item>", "TopCenter", "Top Center", (!stricmp(pSettings->toolbarPlacement, "TopCenter")));
        m_pMenuMaker->CreateMenuItem(m_pSubMenu, "<toolbar_menu_item>", "BottomCenter", "Bottom Center", (!stricmp(pSettings->toolbarPlacement, "BottomCenter")));
        m_pMenuMaker->CreateMenuItem(m_pSubMenu, "[separator]", NULL, NULL, false);
        m_pMenuMaker->CreateMenuItem(m_pSubMenu, "<toolbar_menu_item>", "TopRight", "Top Right", (!stricmp(pSettings->toolbarPlacement, "TopRight")));
        m_pMenuMaker->CreateMenuItem(m_pSubMenu, "<toolbar_menu_item>", "BottomRight", "Bottom Right", (!stricmp(pSettings->toolbarPlacement, "BottomRight")));

        m_pMenuMaker->AddBottomItem(m_pSubMenu);
        m_pSubMenu->Invalidate();
        m_pSubMenu->Validate();
}

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





syntax highlighting by

w e b c p p
web c plus plus