/*
 ============================================================================
 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 "SlitMenu.h" 
#include "PluginMenu.h" 
#include "MenuItem.h" 
#include "CommandItem.h" 
#include "FolderItem.h" 
#include "ConfigMenu.h" 
#include "../Systembar.h" 
#include "../Slit.h" 
#include "../Settings.h" 
#include "../PluginManager.h" 

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

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

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

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

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

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

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

        PluginMenu *SPluginMenu = new PluginMenu("Plugins", m_pMenuMaker);
        SPluginMenu->SetActivePainter(m_pMenuMaker->m_pSelEntry);
        SPluginMenu->SetPainter(m_pMenuMaker->m_pEntry);
        SPluginMenu->SetHeight(m_pMenuMaker->m_nSubmenuHeight);
        AddMenuItem(SPluginMenu);

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

        SlitOrientation *SOrientation = new SlitOrientation("Orientation", m_pMenuMaker);
        SOrientation->SetActivePainter(m_pMenuMaker->m_pSelEntry);
        SOrientation->SetPainter(m_pMenuMaker->m_pEntry);
        SOrientation->SetHeight(m_pMenuMaker->m_nSubmenuHeight);
        AddMenuItem(SOrientation);

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

        m_pMenuMaker->CreateMenuItem(this, "<slit_menu_item>", "Positioning", "Puzzle positioning", !stricmp(pSettings->slitPositioning, "Puzzle"));
        m_pMenuMaker->CreateMenuItem(this, "<slit_menu_item>", "AlwaysOnTop", "Always on top", pSettings->slitOnTop);
        if (pSettings->slitPlacement[0] == 'M') // Manual positioning?
                m_pMenuMaker->CreateMenuItem(this, "<slit_menu_item>", "SnapToEdges", "Snap to screen edges", pSettings->slitSnapToEdges);
        else m_pMenuMaker->CreateMenuItem(this, "<slit_menu_item>", "AutoHide", "Auto hide", pSettings->slitAutoHide);

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

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

        if (pSettings->toolbarHidden) m_pMenuMaker->CreateMenuItem(this, "[toggletoolbar]", NULL, "Show Toolbar", false);
        else m_pMenuMaker->CreateMenuItem(this, "[toggletoolbar]", NULL, "Hide Toolbar", 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 (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();
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        m_pMenuMaker->CreateMenuItem(m_pSubMenu, "<slit_menu_item>", "Vertical", "Vertical", (!stricmp(pSettings->slitDirection, "Vertical")));
        m_pMenuMaker->CreateMenuItem(m_pSubMenu, "<slit_menu_item>", "Horizontal", "Horizontal", (!stricmp(pSettings->slitDirection, "Horizontal")));

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

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





syntax highlighting by

w e b c p p
web c plus plus