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

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

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

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

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

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

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

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

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

        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);

        if (!pSettings->systrayDisabled)
        {
                SystembarSysTray *SSysTray = new SystembarSysTray("System tray", m_pMenuMaker);
                SSysTray->SetActivePainter(m_pMenuMaker->m_pSelEntry);
                SSysTray->SetPainter(m_pMenuMaker->m_pEntry);
                SSysTray->SetHeight(m_pMenuMaker->m_nSubmenuHeight);
                AddMenuItem(SSysTray);
        }

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

        m_pMenuMaker->CreateMenuItem(this, "<systembar_menu_item>", "Tooltips", "Tooltips", !pSettings->systembarTooltipsDisabled);

        if (!IsInString(pSettings->systembarPlacement, "DockedTo")) // Inherit AlwaysOnTop and transparency alpha if docked to slit or toolbar...
        {
                m_pMenuMaker->CreateMenuItem(this, "<systembar_menu_item>", "AlwaysOnTop", "Always on top", pSettings->systembarOnTop);
                if (pSettings->systembarPlacement[0] == 'M') // Manual positioning?
                        m_pMenuMaker->CreateMenuItem(this, "<systembar_menu_item>", "SnapToEdges", "Snap to screen edges", pSettings->systembarSnapToEdges);

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

        if (pSystembar->DockedToSlit)
                m_pMenuMaker->CreateMenuItem(this, "<systembar_menu_item>", "FirstInSlit", "First in the slit", pSettings->systembarFirstInSlit);

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

        if (stricmp(pSettings->systembarPlacement, "DockedToToolbar")) // Do not show the toggle toolbar item if DockedToToolbar...
        {
                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 && (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();
}

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

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

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

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

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

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

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

        if (pSettings->systembarPlacement[0] == 'M')
        {
                m_pMenuMaker->CreateMenuItem(m_pSubMenu, "<systembar_menu_item>", "ManualPositioning", pSettings->systembarPlacement, true);
                m_pMenuMaker->CreateMenuItem(m_pSubMenu, "[separator]", NULL, NULL, false);
        }
        m_pMenuMaker->CreateMenuItem(m_pSubMenu, "<systembar_menu_item>", "DockedToToolbar", "Docked To Toolbar", (!stricmp(pSettings->systembarPlacement, "DockedToToolbar")));
        m_pMenuMaker->CreateMenuItem(m_pSubMenu, "<systembar_menu_item>", "DockedToSlit", "Docked To Slit", (!stricmp(pSettings->systembarPlacement, "DockedToSlit")));
        m_pMenuMaker->CreateMenuItem(m_pSubMenu, "<systembar_menu_item>", "OppositeToolbar", "Opposite Toolbar", (!stricmp(pSettings->systembarPlacement, "OppositeToolbar")));
        m_pMenuMaker->CreateMenuItem(m_pSubMenu, "[separator]", NULL, NULL, false);
        m_pMenuMaker->CreateMenuItem(m_pSubMenu, "<systembar_menu_item>", "TopLeft", "Top Left", (!stricmp(pSettings->systembarPlacement, "TopLeft")));
        m_pMenuMaker->CreateMenuItem(m_pSubMenu, "<systembar_menu_item>", "BottomLeft", "Bottom Left", (!stricmp(pSettings->systembarPlacement, "BottomLeft")));
        m_pMenuMaker->CreateMenuItem(m_pSubMenu, "[separator]", NULL, NULL, false);
        m_pMenuMaker->CreateMenuItem(m_pSubMenu, "<systembar_menu_item>", "TopCenter", "Top Center", (!stricmp(pSettings->systembarPlacement, "TopCenter")));
        m_pMenuMaker->CreateMenuItem(m_pSubMenu, "<systembar_menu_item>", "BottomCenter", "Bottom Center", (!stricmp(pSettings->systembarPlacement, "BottomCenter")));
        m_pMenuMaker->CreateMenuItem(m_pSubMenu, "[separator]", NULL, NULL, false);
        m_pMenuMaker->CreateMenuItem(m_pSubMenu, "<systembar_menu_item>", "TopRight", "Top Right", (!stricmp(pSettings->systembarPlacement, "TopRight")));
        m_pMenuMaker->CreateMenuItem(m_pSubMenu, "<systembar_menu_item>", "BottomRight", "Bottom Right", (!stricmp(pSettings->systembarPlacement, "BottomRight")));

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

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

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

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

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

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

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

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

        if (!pSettings->taskbarHidden)
        {
                m_pMenuMaker->CreateMenuItem(m_pSubMenu, "<systembar_menu_item>", "TaskbarTogglePlacement", "Taskbar<->WindowLabel", pSettings->taskbarOnToolbar);

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

                m_pMenuMaker->CreateMenuItem(m_pSubMenu, "<systembar_menu_item>", "TaskbarModeBars", "Bars mode", (pSettings->taskbarMode == 1));
                m_pMenuMaker->CreateMenuItem(m_pSubMenu, "<systembar_menu_item>", "TaskbarModeIcons", "Icons mode", (pSettings->taskbarMode == 2));
                m_pMenuMaker->CreateMenuItem(m_pSubMenu, "<systembar_menu_item>", "TaskbarModeBarsIcons", "Bars+Icons mode", (pSettings->taskbarMode == 3));

                m_pMenuMaker->CreateMenuItem(m_pSubMenu, "<systembar_menu_item>", "CurrentOnly", "Current workspace only", pSettings->taskbarCurrentOnly);
                m_pMenuMaker->CreateMenuItem(m_pSubMenu, "<systembar_menu_item>", "ToggleFlashing", "Disable task flashing", !pSettings->taskbarFlashing);

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

                char command[50];
                sprintf(command, "\"@xoblite Systembar TaskbarSat\" %d 0 255", pSettings->taskbarSaturationValue);
                m_pMenuMaker->CreateMenuItem(m_pSubMenu, "<edit-int>", command, "Saturation:", false);
                sprintf(command, "\"@xoblite Systembar TaskbarHue\" %d 0 255", pSettings->taskbarHueIntensity);
                m_pMenuMaker->CreateMenuItem(m_pSubMenu, "<edit-int>", command, "Hue:", false);
                m_pMenuMaker->CreateMenuItem(m_pSubMenu, "<systembar_menu_item>", "ActiveSatHue", "Active task sat/hue", pSettings->taskbarActiveSatHue);

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

                m_pMenuMaker->CreateMenuItem(m_pSubMenu, "<systembar_menu_item>", "InactiveBackground", "Inactive task background", pSettings->taskbarInactiveBackground);

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

                m_pMenuMaker->CreateMenuItem(m_pSubMenu, "<systembar_menu_item>", "ToggleTaskbar", "Hide taskbar", false);
        }
        else m_pMenuMaker->CreateMenuItem(m_pSubMenu, "<systembar_menu_item>", "ToggleTaskbar", "Show taskbar", false);

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

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

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

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

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

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

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

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

        if (!pSettings->systrayHidden)
        {
                char command[50];
                sprintf(command, "\"@xoblite Systembar SysTraySat\" %d 0 255", pSettings->systraySaturationValue);
                m_pMenuMaker->CreateMenuItem(m_pSubMenu, "<edit-int>", command, "Saturation:", false);
                sprintf(command, "\"@xoblite Systembar SysTrayHue\" %d 0 255", pSettings->systrayHueIntensity);
                m_pMenuMaker->CreateMenuItem(m_pSubMenu, "<edit-int>", command, "Hue:", false);

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

                m_pMenuMaker->CreateMenuItem(m_pSubMenu, "<systembar_menu_item>", "ToggleSysTray", "Hide system tray", false);
        }
        else m_pMenuMaker->CreateMenuItem(m_pSubMenu, "<systembar_menu_item>", "ToggleSysTray", "Show system tray", false);

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

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





syntax highlighting by

w e b c p p
web c plus plus