/*
 ============================================================================
 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 "ConfigMenu.h" 
#include "CommandItem.h" 
#include "FolderItem.h" 
#include "Menu.h" 
#include "MenuMaker.h" 
#include "../Slit.h" 
#include "../Settings.h" 

extern Slit *pSlit;
extern Settings *pSettings;

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

ConfigMenu::ConfigMenu(LPCSTR pszTitle, MenuMaker *pMenuMaker) : Menu(pMenuMaker->hInst)
{
        m_pMenuMaker = pMenuMaker;
        m_pszTitle = pszTitle ? strdup(pszTitle) : NULL;
        UpdateFolder();
}

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

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

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

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

        Visibility *Vsblt = new Visibility("Visibility", m_pMenuMaker);
        Vsblt->SetActivePainter(m_pMenuMaker->m_pSelEntry);
        Vsblt->SetPainter(m_pMenuMaker->m_pEntry);
        Vsblt->SetHeight(m_pMenuMaker->m_nSubmenuHeight);
        AddMenuItem(Vsblt);

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

        FocusModel *FModel = new FocusModel("Window focus model", m_pMenuMaker);
        FModel->SetActivePainter(m_pMenuMaker->m_pSelEntry);
        FModel->SetPainter(m_pMenuMaker->m_pEntry);
        FModel->SetHeight(m_pMenuMaker->m_nSubmenuHeight);
        AddMenuItem(FModel);

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

//      m_pMenuMaker->CreateMenuItem(this, "<config_menu_item>", "ImageDithering", "Image dithering", pSettings->imageDither);
//      m_pMenuMaker->CreateMenuItem(this, "<config_menu_item>", "FocusNewWindows", "Focus new windows", pSettings->focusNewWindows);
//      m_pMenuMaker->CreateMenuItem(this, "<config_menu_item>", "FocusLastWindow", "Focus window on workspace change", pSettings->focusLastWindow);

        m_pMenuMaker->CreateMenuItem(this, "<config_menu_item>", "OpaqueWindowMoving", "Opaque window moving", pSettings->opaqueMove);
        m_pMenuMaker->CreateMenuItem(this, "<config_menu_item>", "FullMaximization", "Full maximization", pSettings->fullMaximization);
        m_pMenuMaker->CreateMenuItem(this, "<config_menu_item>", "FollowActive", "Follow active task", pSettings->followActive);

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

        m_pMenuMaker->CreateMenuItem(this, "<config_menu_item>", "MidClickStylesMenu", "MidClick styles menu", pSettings->midclickStylesMenu);
        m_pMenuMaker->CreateMenuItem(this, "<config_menu_item>", "SlimlineMetrics", "Slimline metrics", pSettings->slimlineMetrics);
        m_pMenuMaker->CreateMenuItem(this, "<config_menu_item>", "AlternativeBullets", "Alternative bullets", pSettings->alternativeBullets);
        m_pMenuMaker->CreateMenuItem(this, "<config_menu_item>", "MenuSeparators", "Menu separators", pSettings->menuSeparators);
        m_pMenuMaker->CreateMenuItem(this, "<config_menu_item>", "ToggleFontShadows", "Force font shadows", pSettings->forceFontShadows);

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

        m_pMenuMaker->CreateMenuItem(this, "<config_menu_item>", "WriteProtection", "Write protection", pSettings->writeProtection);
        m_pMenuMaker->CreateMenuItem(this, "<config_menu_item>", "DisableRootCommands", "Disable rootCommands", pSettings->disableRootCommands);
        m_pMenuMaker->CreateMenuItem(this, "<config_menu_item>", "DisableScriptSupport", "Disable @Script support", pSettings->disableScriptSupport);

        if (!pSettings->underExplorer && !pSettings->systrayDisabled)
                m_pMenuMaker->CreateMenuItem(this, "<config_menu_item>", "DisableXobloonNotifications", "Disable xobloon notifications", !pSettings->systembarXobloonNotifications);

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

//      if (!pSettings->underExplorer)
                m_pMenuMaker->CreateMenuItem(this, "<config_menu_item>", "DisableSysTray", "Disable SysTray", (pSettings->systrayDisabled || pSettings->underExplorer));
        if (!pSettings->underExplorer)
                m_pMenuMaker->CreateMenuItem(this, "<config_menu_item>", "RunStartupApps", "Run startup programs", pSettings->runStartupApps);

/*
        char command[MAX_LINE_LENGTH], title[MAX_LINE_LENGTH];
        sprintf(command, "\"@xoblite SetEditor\" %s", pSettings->preferredEditor);
        sprintf(title, "Editor: <%s>", pSettings->preferredEditor);
        m_pMenuMaker->CreateMenuItem(this, "<edit-string>", command, title, false);
*/
        m_pMenuMaker->AddBottomItem(this);
        Invalidate();
        Validate();
}

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

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

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

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

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

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

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

        m_pMenuMaker->CreateMenuItem(m_pSubMenu, "[toggletoolbar]", NULL, "Toolbar", pSettings->toolbarHidden ? false : true);
        m_pMenuMaker->CreateMenuItem(m_pSubMenu, "[togglesystembar]", NULL, "Systembar", pSettings->systembarHidden ? false : true);
        if (pSlit->SlitPlugins.size() > 0) m_pMenuMaker->CreateMenuItem(m_pSubMenu, "[toggleslit]", NULL, "Slit", pSettings->slitHidden ? false : true);
        m_pMenuMaker->CreateMenuItem(m_pSubMenu, "[toggleplugins]", NULL, "Plugins", pSettings->pluginsHidden ? false : true);

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

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

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

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

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

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

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

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

        m_pMenuMaker->CreateMenuItem(m_pSubMenu, "<config_menu_item>", "ClickToFocus", "Click to focus", (!stricmp(pSettings->focusModel, "ClickToFocus")) ? true : false);
        m_pMenuMaker->CreateMenuItem(m_pSubMenu, "<config_menu_item>", "SloppyFocus", "Sloppy focus", (!stricmp(pSettings->focusModel, "SloppyFocus")) ? true : false);
        m_pMenuMaker->CreateMenuItem(m_pSubMenu, "<config_menu_item>", "AutoRaiseSloppyFocus", "Auto raise", (!stricmp(pSettings->focusModel, "AutoRaiseSloppyFocus")) ? true : 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