/*
 ============================================================================
 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 "CommandItem.h" 
#include "TitleItem.h" 
#include "Menu.h" 
#include "MenuMaker.h" 
#include "../BBApi.h" 
#include "../Settings.h" 
#include "../Toolbar.h" 
#include "../Systembar.h" 
#include "../TrayManager.h" 
#include "../PluginManager.h" 
#include "../Slit.h" 
#include <process.h> 

extern MenuMaker *pMenuMaker;
extern Settings *pSettings;
extern Toolbar *pToolbar;
extern Systembar *pSystembar;
extern TrayManager *pTrayManager;
extern BImage *pBImage;
extern PluginManager *pPluginManager;
extern Slit *pSlit;

int CommandItem::m_nBulletPosition = DT_RIGHT;

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

#ifndef SPI_SETACTIVEWINDOWTRACKING 
#define SPI_SETACTIVEWINDOWTRACKING             0x1001 
#endif 
#ifndef SPI_SETACTIVEWNDTRKZORDER 
#define SPI_SETACTIVEWNDTRKZORDER               0x100D 
#endif 

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

// Creates a command item object
// pszCommand = the command associated with this command item
// pszArgument optional argument to pszCommand
// pszTitle the text to be drawn on the menu item

CommandItem::CommandItem(char* pszCommand, char* pszArgument, char* pszTitle, bool isSelected) : TitleItem(pszTitle, MENU_DEFAULT)
{
        m_pszCommand = pszCommand ? strdup(pszCommand) : NULL;
        m_pszOriginalTitle = pszTitle ? strdup(pszTitle) : NULL;
        m_isSelected = isSelected;

        if (!stricmp(m_pszCommand, "<edit-int>")) // Used by MakeMenuItemInt...
        {
                char Cmd[MAX_LINE_LENGTH], val[10], minval[10], maxval[10];
                LPSTR tokens[3];
                tokens[0] = Cmd;
                tokens[1] = val;
                tokens[2] = minval;

                Cmd[0] = val[0] = minval[0] = maxval[0] = '\0';
                BBTokenize (pszArgument, tokens, 3, maxval);

                m_pszArgument = Cmd ? strdup(Cmd) : NULL;

                m_currentValue = atoi(val);
                m_minValue = atoi(minval);
                m_maxValue = atoi(maxval);

                char itemstring[MAX_LINE_LENGTH];
                sprintf(itemstring, "%s <%d>", m_pszOriginalTitle, m_currentValue);
                this->SetTitle(itemstring);
        }
        else m_pszArgument = pszArgument ? strdup(pszArgument) : NULL;
}

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

CommandItem::~CommandItem()
{
        if(m_pszCommand) free(m_pszCommand);
        m_pszCommand = NULL;
        if(m_pszArgument) free(m_pszArgument);
        m_pszArgument = NULL;
        if(m_pszOriginalTitle) free(m_pszOriginalTitle);
        m_pszOriginalTitle = NULL;
}

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

// Paints the folder item, the parent class will paint first
void CommandItem::Paint(HDC hDC)
{
        TitleItem::Paint(hDC);
        if (m_isSelected)
                PaintIndicator(hDC, m_nTop);
}

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

void CommandItem::PaintIndicator(HDC hDC, int nTop)
{
        RECT tempRect;

        int x;
        if (m_nBulletPosition == DT_RIGHT)
        {
                x = GetWidth() - pMenuMaker->m_nBorderWidth - 7;
                if (!pSettings->slimlineMetrics) x -= pSettings->MenuFrame->marginWidth;
        }
        else
        {
                x = pMenuMaker->m_nBorderWidth + 7;
                if (!pSettings->slimlineMetrics) x += pSettings->MenuFrame->marginWidth;
        }

        int y = nTop + ((GetHeight()) / 2);

        tempRect.left = x - 3;
        tempRect.top = y - 3;
        tempRect.right = x + 3;
        tempRect.bottom = y + 3;

        pBImage->CreateGradientByRect(hDC, tempRect, pSettings->MenuIndicator->type, pSettings->MenuIndicator->Color, pSettings->MenuIndicator->ColorTo, pSettings->MenuIndicator->interlaced, pSettings->MenuIndicator->bevelstyle, pSettings->MenuIndicator->bevelposition, pSettings->bevelWidth);
}

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

 // Executes the menu item object...
void CommandItem::Invoke(int button)
{
        if (button == 1) m_pParent->Hide(HIDE_PARENTS);
                
        for (;;)
        {
                // Normal menu commands...

                if (!strncmp(m_pszCommand, "[", 1))
                {
                        //===========================================================================

                        if (!stricmp(m_pszCommand, "[exec]"))
                        {
                                if (button == 2) // Right mouse button...
                                {
                                        if (!strlen(m_pszArgument)) return;
                                        if (m_pszArgument[0] == '@') return;

                                        // We only need to check the last 4 characters to get the extension...
                                        char path[MAX_LINE_LENGTH];
                                        strcpy(path, m_pszArgument);
                                        if (path[0] == '\"') StrRemoveEncap(path);
                                        int pointer = strlen(path) - 4;

                                        if (!stricmp(&path[pointer], ".jpg")
                                                || !stricmp(&path[pointer], ".png")
                                                || !stricmp(&path[pointer], ".bmp")
                                                || !stricmp(&path[pointer], ".gif")
                                                || !stricmp(&path[pointer], ".tif")
                                                || !stricmp(&path[pointer], "jpeg"))
                                        {
                                                // If the file is a JPEG, PNG, BMP, TIF or GIF
                                                // we use bsetbg to set it as wallpaper...
                                                // (please note that we leave the menu open)

                                                char arguments[MAX_LINE_LENGTH];

                                                if (GetAsyncKeyState(VK_CONTROL) & 0x8000) // Is the control key held down? -> center mode
                                                        strcpy(arguments, "-center ");
                                                else if (GetAsyncKeyState(VK_SHIFT) & 0x8000) // Is the shift key held down? -> stretch mode
                                                        strcpy(arguments, "-full ");
                                                else strcpy(arguments, "-tile "); // Default -> tile mode

                                                if (strchr(path, ' '))
                                                {
                                                        // Add quotes if the path contains spaces...
                                                        strcat(arguments, "\"");
                                                        strcat(arguments, path);
                                                        strcat(arguments, "\"");
                                                }
                                                else strcat(arguments, path);

                                                // bsetbg.exe should be located in the same folder as
                                                // xoblite.exe, so we use that as the working directory...
                                                char bbpath[MAX_LINE_LENGTH];
                                                GetBlackboxPath(bbpath, sizeof(bbpath));
                                                BBExecute(GetDesktopWindow(), NULL, "bsetbg.exe", arguments, bbpath, SW_SHOWNORMAL, false);
                                                return;
                                        }
                                        else
                                        {
                                                // ...otherwise we open an Explorer
                                                // window where the file is selected...

                                                if (IsInString(path, "http://")) return;

                                                m_pParent->Hide(HIDE_PARENTS);
                                                MenuItem::Invoke(button);

                                                char arg[MAX_LINE_LENGTH];
                                                strcpy(arg, "/e,/select,");
                                                strcat(arg, path);
                                                BBExecute(GetDesktopWindow(), NULL, "explorer.exe", arg, NULL, SW_SHOWNORMAL, false);
                                                return;
                                        }
                                }

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

                                else if (button == 3) // Mid mouse button...
                                {
                                        if (!strlen(m_pszArgument)) return;
                                        if (m_pszArgument[0] == '@') return;

                                        char string[MAX_LINE_LENGTH];
                                        strcpy(string, m_pszArgument);
                                        if (string[0] == '\"') StrRemoveEncap(string);

                                        // Is the control key held down? -> copy path *without* the Blackbox
                                        // or current theme directory, adding quotes to enable portability
                                        // (useful for e.g. wallpaper rootCommands)
                                        if (GetAsyncKeyState(VK_CONTROL) & 0x8000)
                                        {
                                                char string2[MAX_LINE_LENGTH];

                                                if (!pSettings->usingDefaultTheme && IsInString(string, pSettings->SF_currentThemePath))
                                                {
                                                        strcpy(string2, "\"$CurrentTheme$");
                                                        strcat(string2, &string[strlen(pSettings->SF_currentThemePath)]);
                                                        strcat(string2, "\"");
                                                }
                                                else if (IsInString(string, pSettings->SF_blackboxPath))
                                                {
//                                                      strcpy(string2, "\"$Blackbox$");
                                                        strcpy(string2, "\"");
                                                        strcat(string2, &string[strlen(pSettings->SF_blackboxPath)+1]);
                                                        strcat(string2, "\"");
                                                }
                                                else
                                                {
                                                        strcpy(string2, "\"");
                                                        strcat(string2, string);
                                                        strcat(string2, "\"");
                                                }

                                                // If the alt key is held down too we create a
                                                // bsetbg -full command including the path as argument...
                                                if (GetAsyncKeyState(VK_MENU) & 0x8000)
                                                {
                                                        strcpy(string, "rootCommand: bsetbg -full ");
                                                        strcat(string, string2);
                                                        CopyStringToClipboard(string);
                                                }
                                                else CopyStringToClipboard(string2);
                                        }
                                        // ...if not we copy the full path to the file (without quotes)...
                                        else CopyStringToClipboard(string);
                                }

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

                                else // Left mouse button...
                                {
                                        // First we set focus to the toolbar to prevent
                                        // the focus from going back to the previous task
                                        // after the menu is closed...
                                        if (pSettings->followActive) SetForegroundWindow(pToolbar->hToolbarWnd);

                                        MenuItem::Invoke(button);

                                        if (!strlen(m_pszArgument)) return;
                                        if (m_pszArgument[0] == '@')
                                        {
                                                SendMessage(GetBBWnd(), BB_BROADCAST, 0, (LPARAM)m_pszArgument);
                                                return;
                                        }

                                        char command[MAX_LINE_LENGTH], arguments[MAX_LINE_LENGTH], workingdir[MAX_LINE_LENGTH];
                                        LPSTR tokens[1];
                                        tokens[0] = command;
                                        command[0] = arguments[0] = workingdir[0] = '\0';
                                        BBTokenize (m_pszArgument, tokens, 1, arguments);
                                        if (command[1] == ':')
                                        {
                                                strcpy(workingdir, command);
                                                int nLen = strlen(workingdir) - 1;
                                                while (nLen >0 && workingdir[nLen] != '\\') nLen--;
                                                workingdir[nLen + 1] = 0;
                                        }
                                        BBExecute(GetDesktopWindow(), NULL, command, arguments, workingdir, SW_SHOWNORMAL, false);
                                        return;
                                }
                        }

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

                        else if (!stricmp(m_pszCommand, "[shutdown]")) {
                                MenuItem::Invoke(button);
                                PostMessage(GetBBWnd(), BB_SHUTDOWN, 0, 0);
                                return;
                        }
                        else if (!stricmp(m_pszCommand, "[reboot]")) {
                                MenuItem::Invoke(button);
                                PostMessage(GetBBWnd(), BB_SHUTDOWN, 1, 0);
                                break;
                        }
                        else if (!stricmp(m_pszCommand, "[logoff]")) {
                                MenuItem::Invoke(button);
                                PostMessage(GetBBWnd(), BB_SHUTDOWN, 2, 0);
                                break;
                        }
                        else if (!stricmp(m_pszCommand, "[hibernate]")) {
                                MenuItem::Invoke(button);
                                PostMessage(GetBBWnd(), BB_SHUTDOWN, 3, 0);
                                break;
                        }
                        else if (!stricmp(m_pszCommand, "[suspend]")) {
                                MenuItem::Invoke(button);
                                PostMessage(GetBBWnd(), BB_SHUTDOWN, 4, 0);
                                break;
                        }
                        else if (!stricmp(m_pszCommand, "[lockworkstation]")) {
                                MenuItem::Invoke(button);
                                PostMessage(GetBBWnd(), BB_SHUTDOWN, 5, 0);
                                break;
                        }

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

                        else if (!stricmp(m_pszCommand, "[run]")) {
                                MenuItem::Invoke(button);
                                PostMessage(GetBBWnd(), BB_RUN, 0, 0);
                                break;
                        }

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

                        else if (!stricmp(m_pszCommand, "[restart]"))
                        {
                                if (strchr(m_pszArgument, '.'))
                                {
                                        MenuItem::Invoke(button);
                                        // This next line caused many headaches...
                                        // I was SendMessaging first which was hanging things up;
                                        // it would send the restart message and wait for a return
                                        // at which point it would then try to finish off the rest of the
                                        // popup mouse calls, killing the system
                                        // Posting lets it send to the stack and finish before a restart
                                        PostMessage(GetBBWnd(), BB_RESTART, 0, 0);
                                        //                              this->ShellExecute();

                                        char command[MAX_LINE_LENGTH], arguments[MAX_LINE_LENGTH], workingdir[MAX_LINE_LENGTH];
                                        LPSTR tokens[1];
                                        tokens[0] = command;
                                        command[0] = arguments[0] = workingdir[0] = '\0';
                                        BBTokenize (m_pszArgument, tokens, 1, arguments);
                                        if (command[1] == ':')
                                        {
                                                strcpy(workingdir, command);
                                                int nLen = strlen(workingdir) - 1;
                                                while (nLen >0 && workingdir[nLen] != '\\') nLen--;
                                                workingdir[nLen + 1] = 0;
                                        }
                                        BBExecute(GetDesktopWindow(), NULL, command, arguments, workingdir, SW_SHOWNORMAL, false);
                                        break;
                                }
                                else
                                {
                                        MenuItem::Invoke(button);
                                        PostMessage(GetBBWnd(), BB_RESTART, 0, 0);
                                        break;
                                }
                        }
                        else if (!stricmp(m_pszCommand, "[reconfig]")) {
                                MenuItem::Invoke(button);
                                // When Blackbox receives a null BB_SETSTYLE message it will refresh
                                // the current style's settings and then broadcast BB_RECONFIGURE to
                                // make all GUI elements update themselves
                                PostMessage(GetBBWnd(), BB_SETSTYLE, 0, 0);
                                break;
                        }
                        else if (!stricmp(m_pszCommand, "[exit]")) {
                                MenuItem::Invoke(button);
                                PostMessage(GetBBWnd(), BB_QUIT, 0, 0);
                                break;
                        }

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

                        else if (!stricmp(m_pszCommand, "[style]"))
                        {
                                if (button == 2) // Right mouse button
                                {
                                        m_pParent->Hide(HIDE_PARENTS);
                                        MenuItem::Invoke(button);
                                        // Open the chosen style in the preferred editor...
                                        BBExecute(GetDesktopWindow(), NULL, pSettings->preferredEditor, m_pszArgument, NULL, SW_SHOWNORMAL, false);
                                }
                                else if (button == 3) // Mid mouse button
                                {
                                        if (!strlen(m_pszArgument)) return;
                                        if (m_pszArgument[0] == '@') return;

                                        char string[MAX_LINE_LENGTH];
                                        strcpy(string, m_pszArgument);
                                        if (string[0] == '\"') StrRemoveEncap(string);
                                        CopyStringToClipboard(string);
                                }
                                else // Left mouse button
                                {
                                        MenuItem::Invoke(button);
                                        PostMessage(GetBBWnd(), BB_SETSTYLE, 0, (LPARAM)m_pszArgument);
                                }

                                return;
                        }

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

                        else if (!stricmp(m_pszCommand, "[theme]"))
                        {
                                MenuItem::Invoke(button);
                                PostMessage(GetBBWnd(), BB_SETTHEME, 0, (LPARAM)m_pszArgument);
                                break;
                        }

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

                        else if (!stricmp(m_pszCommand, "[loadplugin]")) {
                                MenuItem::Invoke(button);
                                pPluginManager->loadPluginDialog();
                                break;
                        }

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

                        else if (!stricmp(m_pszCommand, "[editstyle]")) {
                                MenuItem::Invoke(button);
                                PostMessage(GetBBWnd(), BB_EDITFILE, 0, 0);
                                break;
                        }
                        else if (!stricmp(m_pszCommand, "[editmenu]")) {
                                MenuItem::Invoke(button);
                                PostMessage(GetBBWnd(), BB_EDITFILE, 1, 0);
                                break;
                        }
                        else if (!stricmp(m_pszCommand, "[editplugins]")) {
                                MenuItem::Invoke(button);
                                PostMessage(GetBBWnd(), BB_EDITFILE, 2, 0);
                                break;
                        }
                        else if (!stricmp(m_pszCommand, "[editextensions]")) {
                                MenuItem::Invoke(button);
                                PostMessage(GetBBWnd(), BB_EDITFILE, 3, 0);
                                break;
                        }
                        else if (!stricmp(m_pszCommand, "[editblackbox]")) {
                                MenuItem::Invoke(button);
                                PostMessage(GetBBWnd(), BB_EDITFILE, 4, 0);
                                break;
                        }

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

                        else if (!stricmp(m_pszCommand, "[aboutstyle]")) {
                                MenuItem::Invoke(button);
                                char temp[MAX_LINE_LENGTH], a1[MAX_LINE_LENGTH], a2[MAX_LINE_LENGTH], a3[MAX_LINE_LENGTH], a4[MAX_LINE_LENGTH], a5[MAX_LINE_LENGTH];
                                strcpy(a1, ReadString(pSettings->styleFile, "style.name:", "[Style name not specified]"));
                                strcpy(a2, ReadString(pSettings->styleFile, "style.author:", "[Author not specified]"));
                                strcpy(a3, ReadString(pSettings->styleFile, "style.date:", ""));
                                strcpy(a4, ReadString(pSettings->styleFile, "style.credits:", ""));
                                strcpy(a5, ReadString(pSettings->styleFile, "style.comments:", ""));
                                sprintf(temp, "%s   \nby %s   \n%s   \n%s   \n%s   ", a1, a2, a3, a4, a5);
                                MessageBox(GetBBWnd(), temp, "xoblite: Style information", MB_OK | MB_SETFOREGROUND | MB_ICONINFORMATION);
                                break;
                        }
                        else if (!stricmp(m_pszCommand, "[aboutplugins]")) {
                                MenuItem::Invoke(button);
                                pPluginManager->aboutPlugins();
                                break;
                        }

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

                        else if (!stricmp(m_pszCommand, "[toggletoolbar]")) {
                                MenuItem::Invoke(button);
                                if (!stricmp(pSettings->systembarPlacement, "DockedToToolbar") && !pSettings->systembarHidden && !pSettings->toolbarHidden) PostMessage(GetBBWnd(), BB_TOGGLESYSTEMBAR, 0, 0);
                                PostMessage(GetBBWnd(), BB_TOGGLETOOLBAR, 0, 0);
                                break;
                        }
                        else if (!stricmp(m_pszCommand, "[togglesystembar]")) {
                                MenuItem::Invoke(button);
                                if (!stricmp(pSettings->systembarPlacement, "DockedToToolbar") && pSettings->systembarHidden && pSettings->toolbarHidden) PostMessage(GetBBWnd(), BB_TOGGLETOOLBAR, 0, 0);
                                PostMessage(GetBBWnd(), BB_TOGGLESYSTEMBAR, 0, 0);
                                break;
                        }
                        else if (!stricmp(m_pszCommand, "[toggleplugins]")) {
                                MenuItem::Invoke(button);
                                PostMessage(GetBBWnd(), BB_TOGGLEPLUGINS, 0, 0);
                                break;
                        }
                        else if (!stricmp(m_pszCommand, "[toggleslit]")) {
                                MenuItem::Invoke(button);
                                PostMessage(GetBBWnd(), BB_TOGGLESLIT, 0, 0);
                                break;
                        }

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

                        else if (!stricmp(m_pszCommand, "[add]")) {
                                MenuItem::Invoke(button);
                                PostMessage(GetBBWnd(), BB_WORKSPACE, 2, 0);
                                break;
                        }
                        else if (!stricmp(m_pszCommand, "[del]")) {
                                MenuItem::Invoke(button);
                                PostMessage(GetBBWnd(), BB_WORKSPACE, 3, 0);
                                break;
                        }
                        else if (!stricmp(m_pszCommand, "[gather]")) {
                                MenuItem::Invoke(button);
                                PostMessage(GetBBWnd(), BB_WORKSPACE, 5, 0);
                                break;
                        }
                        else MenuItem::Invoke(1); // The command was unvalid -> close the menu!
                }

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

                // xoblite internal menu handling...

                else if (!strncmp(m_pszCommand, "<", 1))
                {
                        //====================

                        if (!stricmp(m_pszCommand, "<edit-int>")) // Used by MakeMenuItemInt...
                        {
                                if (button == 2) // Right mouse button...
                                {
                                        if (this->m_mousePos.x > (this->m_nWidth / 2))
                                        {
                                                if ((GetAsyncKeyState(VK_CONTROL) & 0x8000))
                                                {
                                                        if (m_currentValue <= (m_maxValue - 10)) m_currentValue = m_currentValue + 10;
                                                        else m_currentValue = m_maxValue;
                                                }
                                                else if (m_currentValue < m_maxValue) m_currentValue++;
                                        }
                                        else
                                        {
                                                if ((GetAsyncKeyState(VK_CONTROL) & 0x8000))
                                                {
                                                        if (m_currentValue >= (m_minValue + 10)) m_currentValue = m_currentValue - 10;
                                                        else m_currentValue = m_minValue;
                                                }
                                                else if (m_currentValue > m_minValue) m_currentValue--;
                                        }

                                        char temp[MAX_LINE_LENGTH];
                                        sprintf(temp, "%s <%d>", m_pszOriginalTitle, m_currentValue);
                                        this->SetTitle(temp);

                                        this->m_pParent->Invalidate();
                                        this->m_pParent->Validate();
                                        this->m_bActive = false;
                                        MenuItem::Active(true);

                                        sprintf(temp, "%s %d", m_pszArgument, m_currentValue);
                                        SendMessage(GetBBWnd(), BB_BROADCAST, 0, (LPARAM)temp);
                                }
//                              else // Left mouse button...
//                              {
//                                      MenuItem::Invoke(button);
//                                      char temp[MAX_LINE_LENGTH];
//                                      sprintf(temp, "%s %d", m_pszArgument, (m_maxValue+1));
//                                      SendMessage(GetBBWnd(), BB_BROADCAST, 0, (LPARAM)temp);
//                              }

                                return;
                        }

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

                        // Toolbar menu handling...

                        else if (!stricmp(m_pszCommand, "<toolbar_menu_item>"))
                        {
                                if (!stricmp(m_pszArgument, "ManualPositioning")) break;
                                else if (!stricmp(m_pszArgument, "TopLeft")) {
                                        MenuItem::Invoke(button);
                                        strcpy(pSettings->toolbarPlacement, "TopLeft");
                                        pToolbar->UpdatePosition();
                                        if (!pSystembar->DockedToSlit) pSystembar->UpdatePosition();
                                        if (!stricmp(pSettings->slitPlacement, "OppositeToolbar")) pSlit->UpdatePosition();
                                        break;
                                }
                                else if (!stricmp(m_pszArgument, "TopCenter")) {
                                        MenuItem::Invoke(button);
                                        strcpy(pSettings->toolbarPlacement, "TopCenter");
                                        pToolbar->UpdatePosition();
                                        if (!pSystembar->DockedToSlit) pSystembar->UpdatePosition();
                                        if (!stricmp(pSettings->slitPlacement, "OppositeToolbar")) pSlit->UpdatePosition();
                                        break;
                                }
                                else if (!stricmp(m_pszArgument, "TopRight")) {
                                        MenuItem::Invoke(button);
                                        strcpy(pSettings->toolbarPlacement, "TopRight");
                                        pToolbar->UpdatePosition();
                                        if (!pSystembar->DockedToSlit) pSystembar->UpdatePosition();
                                        if (!stricmp(pSettings->slitPlacement, "OppositeToolbar")) pSlit->UpdatePosition();
                                        break;
                                }
                                else if (!stricmp(m_pszArgument, "BottomLeft")) {
                                        MenuItem::Invoke(button);
                                        strcpy(pSettings->toolbarPlacement, "BottomLeft");
                                        pToolbar->UpdatePosition();
                                        if (!pSystembar->DockedToSlit) pSystembar->UpdatePosition();
                                        if (!stricmp(pSettings->slitPlacement, "OppositeToolbar")) pSlit->UpdatePosition();
                                        break;
                                }
                                else if (!stricmp(m_pszArgument, "BottomCenter")) {
                                        MenuItem::Invoke(button);
                                        strcpy(pSettings->toolbarPlacement, "BottomCenter");
                                        pToolbar->UpdatePosition();
                                        if (!pSystembar->DockedToSlit) pSystembar->UpdatePosition();
                                        if (!stricmp(pSettings->slitPlacement, "OppositeToolbar")) pSlit->UpdatePosition();
                                        break;
                                }
                                else if (!stricmp(m_pszArgument, "BottomRight")) {
                                        MenuItem::Invoke(button);
                                        strcpy(pSettings->toolbarPlacement, "BottomRight");
                                        pToolbar->UpdatePosition();
                                        if (!pSystembar->DockedToSlit) pSystembar->UpdatePosition();
                                        if (!stricmp(pSettings->slitPlacement, "OppositeToolbar")) pSlit->UpdatePosition();
                                        break;
                                }
                                else if (!stricmp(m_pszArgument, "AlwaysOnTop")) {
                                        MenuItem::Invoke(button);
                                        pToolbar->ToggleAlwaysOnTop();
                                        if (!stricmp(pSettings->systembarPlacement, "DockedToToolbar")) pSystembar->ToggleAlwaysOnTop();
                                        break;
                                }
                                else if (!stricmp(m_pszArgument, "SnapToEdges")) {
                                        MenuItem::Invoke(button);
                                        if (!pSettings->toolbarSnapToEdges) pSettings->toolbarSnapToEdges = true;
                                        else pSettings->toolbarSnapToEdges = false;
                                        WriteBool(pSettings->extrcFile, "xoblite.toolbar.snapToEdges:", pSettings->toolbarSnapToEdges);
                                        break;
                                }
                                else if (!stricmp(m_pszArgument, "AutoHide")) {
                                        MenuItem::Invoke(button);
                                        if (!pSettings->toolbarAutoHide) pSettings->toolbarAutoHide = true;
                                        else pSettings->toolbarAutoHide = false;
                                        pToolbar->UpdatePosition();
//                                      if (!stricmp(pSettings->systembarPlacement, "DockedToToolbar")) pSystembar->UpdatePosition();
                                        WriteBool(bbrcPath(), "session.screen0.toolbar.autoHide:", pSettings->toolbarAutoHide);
                                        break;
                                }
//                              else if (!stricmp(m_pszArgument, "EditWorkspaceName")) {
//                                      MenuItem::Invoke(button);
//                                      BBExecute(GetDesktopWindow(), NULL, pSettings->preferredEditor, bbrcPath(), NULL, SW_SHOWNORMAL, false);
//                                      break;
//                              }
                        }

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

                        // Systembar menu handling...

                        else if (!stricmp(m_pszCommand, "<systembar_menu_item>"))
                        {
                                if (!stricmp(m_pszArgument, "ManualPositioning")) break;
                                else if (!stricmp(m_pszArgument, "DockedToToolbar")) {
                                        MenuItem::Invoke(button);
                                        strcpy(pSettings->systembarPlacement, "DockedToToolbar");
                                        pSystembar->UpdatePosition();
                                        break;
                                }
                                else if (!stricmp(m_pszArgument, "OppositeToolbar")) {
                                        MenuItem::Invoke(button);
                                        strcpy(pSettings->systembarPlacement, "OppositeToolbar");
                                        pSystembar->UpdatePosition();
                                        break;
                                }
                                else if (!stricmp(m_pszArgument, "DockedToSlit")) {
                                        MenuItem::Invoke(button);
                                        strcpy(pSettings->systembarPlacement, "DockedToSlit");
                                        pSystembar->UpdatePosition();
                                        break;
                                }
                                else if (!stricmp(m_pszArgument, "TopLeft")) {
                                        MenuItem::Invoke(button);
                                        strcpy(pSettings->systembarPlacement, "TopLeft");
                                        pSystembar->UpdatePosition();
                                        break;
                                }
                                else if (!stricmp(m_pszArgument, "TopCenter")) {
                                        MenuItem::Invoke(button);
                                        strcpy(pSettings->systembarPlacement, "TopCenter");
                                        pSystembar->UpdatePosition();
                                        break;
                                }
                                else if (!stricmp(m_pszArgument, "TopRight")) {
                                        MenuItem::Invoke(button);
                                        strcpy(pSettings->systembarPlacement, "TopRight");
                                        pSystembar->UpdatePosition();
                                        break;
                                }
                                else if (!stricmp(m_pszArgument, "BottomLeft")) {
                                        MenuItem::Invoke(button);
                                        strcpy(pSettings->systembarPlacement, "BottomLeft");
                                        pSystembar->UpdatePosition();
                                        break;
                                }
                                else if (!stricmp(m_pszArgument, "BottomCenter")) {
                                        MenuItem::Invoke(button);
                                        strcpy(pSettings->systembarPlacement, "BottomCenter");
                                        pSystembar->UpdatePosition();
                                        break;
                                }
                                else if (!stricmp(m_pszArgument, "BottomRight")) {
                                        MenuItem::Invoke(button);
                                        strcpy(pSettings->systembarPlacement, "BottomRight");
                                        pSystembar->UpdatePosition();
                                        break;
                                }
                                else if (!stricmp(m_pszArgument, "ToggleTaskbar")) {
                                        MenuItem::Invoke(button);
                                        if (!pSettings->taskbarHidden) pSettings->taskbarHidden = true;
                                        else pSettings->taskbarHidden = false;
                                        if (pSettings->taskbarOnToolbar && pToolbar) InvalidateRect(pToolbar->hToolbarWnd, NULL, false);
                                        else if (pSystembar) InvalidateRect(pSystembar->hSystembarWnd, NULL, false);
                                        WriteBool(pSettings->extrcFile, "xoblite.taskbar.hidden:", pSettings->taskbarHidden);
                                        break;
                                }
                                else if (!stricmp(m_pszArgument, "TaskbarTogglePlacement")) {
                                        MenuItem::Invoke(button);
                                        if (!pSettings->taskbarOnToolbar) pSettings->taskbarOnToolbar = true;
                                        else pSettings->taskbarOnToolbar = false;
                                        pToolbar->UpdatePosition();
                                        if (stricmp(pSettings->systembarPlacement, "DockedToToolbar")) pSystembar->UpdatePosition();
                                        if (pSettings->taskbarOnToolbar) WriteString(pSettings->extrcFile, "xoblite.taskbar.placement:", "Toolbar");
                                        else WriteString(pSettings->extrcFile, "xoblite.taskbar.placement:", "Systembar");
                                        break;
                                }
                                else if (!stricmp(m_pszArgument, "TaskbarModeBars")) {
                                        MenuItem::Invoke(button);
                                        pSystembar->ChangeTaskbarMode(1);
                                        break;
                                }
                                else if (!stricmp(m_pszArgument, "TaskbarModeIcons")) {
                                        MenuItem::Invoke(button);
                                        pSystembar->ChangeTaskbarMode(2);
                                        break;
                                }
                                else if (!stricmp(m_pszArgument, "TaskbarModeBarsIcons")) {
                                        MenuItem::Invoke(button);
                                        pSystembar->ChangeTaskbarMode(3);
                                        break;
                                }
                                else if (!stricmp(m_pszArgument, "ActiveSatHue")) {
                                        MenuItem::Invoke(button);
                                        if (!pSettings->taskbarActiveSatHue) pSettings->taskbarActiveSatHue = true;
                                        else pSettings->taskbarActiveSatHue = false;
                                        if (pSettings->taskbarOnToolbar && pToolbar) InvalidateRect(pToolbar->hToolbarWnd, NULL, false);
                                        else if (pSystembar) InvalidateRect(pSystembar->hSystembarWnd, NULL, false);
                                        WriteBool(pSettings->extrcFile, "xoblite.taskbar.active.SatHue:", pSettings->taskbarActiveSatHue);
                                        break;
                                }
                                else if (!stricmp(m_pszArgument, "InactiveBackground")) {
                                        MenuItem::Invoke(button);
                                        if (!pSettings->taskbarInactiveBackground) pSettings->taskbarInactiveBackground = true;
                                        else pSettings->taskbarInactiveBackground = false;
                                        if (pSettings->taskbarOnToolbar && pToolbar) InvalidateRect(pToolbar->hToolbarWnd, NULL, false);
                                        else if (pSystembar) InvalidateRect(pSystembar->hSystembarWnd, NULL, false);
                                        WriteBool(pSettings->extrcFile, "xoblite.taskbar.inactive.background:", pSettings->taskbarInactiveBackground);
                                        break;
                                }
                                else if (!stricmp(m_pszArgument, "CurrentOnly")) {
                                        MenuItem::Invoke(button);
                                        pSystembar->ToggleCurrentOnly();
                                        break;
                                }
                                else if (!stricmp(m_pszArgument, "ToggleFlashing")) {
                                        MenuItem::Invoke(button);
                                        if (!pSettings->taskbarFlashing) pSettings->taskbarFlashing = true;
                                        else pSettings->taskbarFlashing = false;
                                        WriteBool(pSettings->extrcFile, "xoblite.taskbar.flashing:", pSettings->taskbarFlashing);
                                        break;
                                }
                                else if (!stricmp(m_pszArgument, "ToggleSysTray")) {
                                        MenuItem::Invoke(button);
                                        pSystembar->ToggleSysTray();
                                        break;
                                }
                                else if (!stricmp(m_pszArgument, "AlwaysOnTop")) {
                                        MenuItem::Invoke(button);
                                        pSystembar->ToggleAlwaysOnTop();
                                        break;
                                }
                                else if (!stricmp(m_pszArgument, "SnapToEdges")) {
                                        MenuItem::Invoke(button);
                                        if (!pSettings->systembarSnapToEdges) pSettings->systembarSnapToEdges = true;
                                        else pSettings->systembarSnapToEdges = false;
                                        WriteBool(pSettings->extrcFile, "xoblite.systembar.snapToEdges:", pSettings->systembarSnapToEdges);
                                        break;
                                }
                                else if (!stricmp(m_pszArgument, "Tooltips")) {
                                        MenuItem::Invoke(button);
                                        pSystembar->ToggleTooltips();
                                        break;
                                }
                                else if (!stricmp(m_pszArgument, "FirstInSlit")) {
                                        MenuItem::Invoke(button);
                                        if (!pSettings->systembarFirstInSlit) pSettings->systembarFirstInSlit = true;
                                        else pSettings->systembarFirstInSlit = false;
                                        WriteBool(pSettings->extrcFile, "xoblite.systembar.firstInSlit:", pSettings->systembarFirstInSlit);
                                        PostMessage(GetBBWnd(), BB_RESTART, 0, 0);
                                        break;
                                }
                        }

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

                        // Slit menu handling...

                        else if (!stricmp(m_pszCommand, "<slit_menu_item>"))
                        {
                                if (IsInString(m_pszArgument, "CheckForPluginUpdates"))
                                {
                                        MenuItem::Invoke(button);
                                        bool silent = false;
                                        _beginthread(checkForUpdates, 0, &silent);
                                        break;
                                }
                                else if (IsInString(m_pszArgument, "UnloadPlugin"))
                                {
                                        if (button == 2)
                                        {
                                                int pluginNumber = atoi(&m_pszArgument[strlen("UnloadPlugin")]);
                                                pPluginManager->updatePlugin(NULL, pluginNumber, true);
                                        }
                                        else
                                        {
                                                MenuItem::Invoke(button);
                                                int pluginNumber = atoi(&m_pszArgument[strlen("UnloadPlugin")]);
                                                if (pPluginManager->pluginList[pluginNumber].UpdateAvailable)
                                                {
                                                        pPluginManager->updatePlugin(NULL, pluginNumber, false);
                                                }
                                                else
                                                {
                                                        // Force update...
                                                        if ((GetAsyncKeyState(VK_CONTROL) & 0x8000))
                                                        {
                                                                pPluginManager->updatePlugin(NULL, pluginNumber, true);
                                                                break;
                                                        }

                                                        char msg[MAX_LINE_LENGTH], pluginName[MAX_LINE_LENGTH];
                                                        strcpy(pluginName, pPluginManager->getPluginInfo(pluginNumber, PLUGIN_NAME));
                                                        sprintf(msg, "Are you sure you want to unload %s?   ", pluginName);

                                                        if (MessageBox(GetBBWnd(), msg, "xoblite", MB_YESNO | MB_ICONQUESTION | MB_SETFOREGROUND | MB_TOPMOST) == IDYES)
                                                        {
                                                                pPluginManager->unloadPlugin(NULL, pluginNumber);
                                                        }
                                                }
                                        }
                                        return;
                                }
                                else if (!stricmp(m_pszArgument, "ManualPositioning")) break;
                                else if (!stricmp(m_pszArgument, "TopLeft")) {
                                        MenuItem::Invoke(button);
                                        strcpy(pSettings->slitPlacement, "TopLeft");
                                        pSlit->UpdatePosition();
                                        break;
                                }
                                else if (!stricmp(m_pszArgument, "TopCenter")) {
                                        MenuItem::Invoke(button);
                                        strcpy(pSettings->slitPlacement, "TopCenter");
                                        pSlit->UpdatePosition();
                                        break;
                                }
                                else if (!stricmp(m_pszArgument, "TopRight")) {
                                        MenuItem::Invoke(button);
                                        strcpy(pSettings->slitPlacement, "TopRight");
                                        pSlit->UpdatePosition();
                                        break;
                                }
                                else if (!stricmp(m_pszArgument, "CenterLeft")) {
                                        MenuItem::Invoke(button);
                                        strcpy(pSettings->slitPlacement, "CenterLeft");
                                        pSlit->UpdatePosition();
                                        break;
                                }
                                else if (!stricmp(m_pszArgument, "CenterRight")) {
                                        MenuItem::Invoke(button);
                                        strcpy(pSettings->slitPlacement, "CenterRight");
                                        pSlit->UpdatePosition();
                                        break;
                                }
                                else if (!stricmp(m_pszArgument, "BottomLeft")) {
                                        MenuItem::Invoke(button);
                                        strcpy(pSettings->slitPlacement, "BottomLeft");
                                        pSlit->UpdatePosition();
                                        break;
                                }
                                else if (!stricmp(m_pszArgument, "BottomCenter")) {
                                        MenuItem::Invoke(button);
                                        strcpy(pSettings->slitPlacement, "BottomCenter");
                                        pSlit->UpdatePosition();
                                        break;
                                }
                                else if (!stricmp(m_pszArgument, "BottomRight")) {
                                        MenuItem::Invoke(button);
                                        strcpy(pSettings->slitPlacement, "BottomRight");
                                        pSlit->UpdatePosition();
                                        break;
                                }
                                else if (!stricmp(m_pszArgument, "OppositeToolbar")) {
                                        MenuItem::Invoke(button);
                                        strcpy(pSettings->slitPlacement, "OppositeToolbar");
                                        pSlit->UpdatePosition();
                                        break;
                                }
                                else if (!stricmp(m_pszArgument, "Vertical")) {
                                        MenuItem::Invoke(button);
                                        strcpy(pSettings->slitDirection, "Vertical");
                                        pSlit->SlitVertical = true;
                                        pSlit->UpdatePluginPositions();
                                        break;
                                }
                                else if (!stricmp(m_pszArgument, "Horizontal")) {
                                        MenuItem::Invoke(button);
                                        strcpy(pSettings->slitDirection, "Horizontal");
                                        pSlit->SlitVertical = false;
                                        pSlit->UpdatePluginPositions();
                                        break;
                                }
                                else if (!stricmp(m_pszArgument, "Positioning")) {
                                        MenuItem::Invoke(button);
                                        if (!stricmp(pSettings->slitPositioning, "SideBySide")) strcpy(pSettings->slitPositioning, "Puzzle");
                                        else strcpy(pSettings->slitPositioning, "SideBySide");
                                        WriteString(pSettings->extrcFile, "xoblite.slit.positioning:", pSettings->slitPositioning);
                                        pSlit->UpdatePluginPositions();
                                        break;
                                }
                                else if (!stricmp(m_pszArgument, "AlwaysOnTop")) {
                                        MenuItem::Invoke(button);
                                        pSlit->ToggleAlwaysOnTop();
                                        break;
                                }
                                else if (!stricmp(m_pszArgument, "SnapToEdges")) {
                                        MenuItem::Invoke(button);
                                        if (!pSettings->slitSnapToEdges) pSettings->slitSnapToEdges = true;
                                        else pSettings->slitSnapToEdges = false;
                                        WriteBool(pSettings->extrcFile, "xoblite.slit.snapToEdges:", pSettings->slitSnapToEdges);
                                        break;
                                }
                                else if (!stricmp(m_pszArgument, "AutoHide")) {
                                        MenuItem::Invoke(button);
                                        if (!pSettings->slitAutoHide) pSettings->slitAutoHide = true;
                                        else pSettings->slitAutoHide = false;
                                        pSlit->UpdatePosition();
                                        WriteBool(bbrcPath(), "session.screen0.slit.autoHide:", pSettings->slitAutoHide);
                                        break;
                                }
                        }

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

                        // Configuration menu handling...

                        else if (!stricmp(m_pszCommand, "<config_menu_item>"))
                        {
                                if (!stricmp(m_pszArgument, "ClickToFocus")) {
                                        MenuItem::Invoke(button);
                                        strcpy(pSettings->focusModel, "ClickToFocus");
                                        SystemParametersInfo(SPI_SETACTIVEWINDOWTRACKING, 0, (PVOID)false, SPIF_SENDCHANGE);
                                        SystemParametersInfo(SPI_SETACTIVEWNDTRKZORDER, 0, (PVOID)false, SPIF_SENDCHANGE);
                                        WriteString(bbrcPath(), "session.screen0.focusModel:", pSettings->focusModel);
                                        break;
                                }
                                else if (!stricmp(m_pszArgument, "SloppyFocus")) {
                                        MenuItem::Invoke(button);
                                        strcpy(pSettings->focusModel, "SloppyFocus");
                                        SystemParametersInfo(SPI_SETACTIVEWINDOWTRACKING, 0, (PVOID)true, SPIF_SENDCHANGE);
                                        SystemParametersInfo(SPI_SETACTIVEWNDTRKZORDER, 0, (PVOID)false, SPIF_SENDCHANGE);
                                        WriteString(bbrcPath(), "session.screen0.focusModel:", pSettings->focusModel);
                                        break;
                                }
                                else if (!stricmp(m_pszArgument, "AutoRaiseSloppyFocus")) {
                                        MenuItem::Invoke(button);
                                        strcpy(pSettings->focusModel, "AutoRaiseSloppyFocus");
                                        SystemParametersInfo(SPI_SETACTIVEWINDOWTRACKING, 0, (PVOID)true, SPIF_SENDCHANGE);
                                        SystemParametersInfo(SPI_SETACTIVEWNDTRKZORDER, 0, (PVOID)true, SPIF_SENDCHANGE);
                                        WriteString(bbrcPath(), "session.screen0.focusModel:", pSettings->focusModel);
                                        break;
                                }
/*
                                else if (!stricmp(m_pszArgument, "SmartPlacementRows")) {
                                        MenuItem::Invoke(button);
                                        strcpy(pSettings->windowPlacement, "RowSmartPlacement");
                                        WriteString(bbrcPath(), "session.screen0.windowPlacement:", pSettings->windowPlacement);
                                        break;
                                }
                                else if (!stricmp(m_pszArgument, "SmartPlacementColumns")) {
                                        MenuItem::Invoke(button);
                                        strcpy(pSettings->windowPlacement, "ColSmartPlacement");
                                        WriteString(bbrcPath(), "session.screen0.windowPlacement:", pSettings->windowPlacement);
                                        break;
                                }
                                else if (!stricmp(m_pszArgument, "CascadePlacement")) {
                                        MenuItem::Invoke(button);
                                        strcpy(pSettings->windowPlacement, "CascadePlacement");
                                        WriteString(bbrcPath(), "session.screen0.windowPlacement:", pSettings->windowPlacement);
                                        break;
                                }
                                else if (!stricmp(m_pszArgument, "LeftToRight")) {
                                        MenuItem::Invoke(button);
                                        strcpy(pSettings->rowPlacementDirection, "LeftToRight");
                                        WriteString(bbrcPath(), "session.screen0.rowPlacementDirection:", pSettings->rowPlacementDirection);
                                        break;
                                }
                                else if (!stricmp(m_pszArgument, "RightToLeft")) {
                                        MenuItem::Invoke(button);
                                        strcpy(pSettings->rowPlacementDirection, "RightToLeft");
                                        WriteString(bbrcPath(), "session.screen0.rowPlacementDirection:", pSettings->rowPlacementDirection);
                                        break;
                                }
                                else if (!stricmp(m_pszArgument, "TopToBottom")) {
                                        MenuItem::Invoke(button);
                                        strcpy(pSettings->colPlacementDirection, "TopToBottom");
                                        WriteString(bbrcPath(), "session.screen0.colPlacementDirection:", pSettings->colPlacementDirection);
                                        break;
                                }
                                else if (!stricmp(m_pszArgument, "BottomToTop")) {
                                        MenuItem::Invoke(button);
                                        strcpy(pSettings->colPlacementDirection, "BottomToTop");
                                        WriteString(bbrcPath(), "session.screen0.colPlacementDirection:", pSettings->colPlacementDirection);
                                        break;
                                }
                                else if (!stricmp(m_pszArgument, "ImageDithering")) {
                                        MenuItem::Invoke(button);
                                        if (!pSettings->imageDither) pSettings->imageDither = true;
                                        else pSettings->imageDither = false;
                                        WriteBool(bbrcPath(), "session.imageDither:", pSettings->imageDither);
                                        break;
                                }
*/
                                else if (!stricmp(m_pszArgument, "OpaqueWindowMoving")) {
                                        MenuItem::Invoke(button);
                                        if (!pSettings->opaqueMove) pSettings->opaqueMove = true;
                                        else pSettings->opaqueMove = false;
                                        SystemParametersInfo(SPI_SETDRAGFULLWINDOWS, pSettings->opaqueMove, NULL, SPIF_SENDCHANGE);
                                        WriteBool(bbrcPath(), "session.opaqueMove:", pSettings->opaqueMove);
                                        break;
                                }
                                else if (!stricmp(m_pszArgument, "FullMaximization")) {
                                        MenuItem::Invoke(button);
                                        if (!pSettings->fullMaximization) pSettings->fullMaximization = true;
                                        else pSettings->fullMaximization = false;
                                        pToolbar->UpdateDesktopArea();
                                        WriteBool(bbrcPath(), "session.screen0.fullMaximization:", pSettings->fullMaximization);
                                        break;
                                }
                                else if (!stricmp(m_pszArgument, "FollowActive")) {
                                        MenuItem::Invoke(button);
                                        if (!pSettings->followActive) pSettings->followActive = true;
                                        else pSettings->followActive = false;
                                        WriteBool(pSettings->extrcDefaultFile, "xoblite.tasks.followActive:", pSettings->followActive);
                                        break;
                                }
                                else if (!stricmp(m_pszArgument, "MidClickStylesMenu")) {
                                        MenuItem::Invoke(button);
                                        if (!pSettings->midclickStylesMenu) pSettings->midclickStylesMenu = true;
                                        else pSettings->midclickStylesMenu = false;
                                        WriteBool(pSettings->extrcDefaultFile, "xoblite.midclick.stylesMenu:", pSettings->midclickStylesMenu);
                                        break;
                                }
                                else if (!stricmp(m_pszArgument, "AlternativeBullets")) {
                                        MenuItem::Invoke(button);
                                        if (!pSettings->alternativeBullets) pSettings->alternativeBullets = true;
                                        else pSettings->alternativeBullets = false;
                                        InvalidateRect(pToolbar->hToolbarWnd, NULL, false);
                                        WriteBool(pSettings->extrcFile, "xoblite.alternative.bullets:", pSettings->alternativeBullets);
                                        break;
                                }
                                else if (!stricmp(m_pszArgument, "SlimlineMetrics")) {
                                        MenuItem::Invoke(button);
                                        if (!pSettings->slimlineMetrics) pSettings->slimlineMetrics = true;
                                        else pSettings->slimlineMetrics = false;
                                        WriteBool(pSettings->extrcDefaultFile, "xoblite.slimline.metrics:", pSettings->slimlineMetrics);
                                        PostMessage(GetBBWnd(), BB_RESTART, 0, 0);
                                        break;
                                }
                                else if (!stricmp(m_pszArgument, "MenuSeparators")) {
                                        MenuItem::Invoke(button);
                                        if (!pSettings->menuSeparators) pSettings->menuSeparators = true;
                                        else pSettings->menuSeparators = false;
                                        WriteBool(pSettings->extrcFile, "xoblite.menu.separators:", pSettings->menuSeparators);
                                        PostMessage(GetBBWnd(), BB_RESTART, 0, 0);
                                        break;
                                }
                                else if (!stricmp(m_pszArgument, "ToggleFontShadows"))
                                {
                                        MenuItem::Invoke(button);
                                        if (!pSettings->forceFontShadows) pSettings->forceFontShadows = true;
                                        else pSettings->forceFontShadows = false;
                                        WriteBool(pSettings->extrcFile, "xoblite.force.font.shadows:", pSettings->forceFontShadows);

                                        if (pSettings->forceFontShadows)
                                        {
                                                pSettings->MenuTitle->FontShadow = pSettings->MenuFrame->FontShadow = pSettings->MenuHilite->FontShadow = true;
                                                pSettings->ToolbarLabel->FontShadow = pSettings->ToolbarWindowLabel->FontShadow = pSettings->ToolbarClock->FontShadow = true;
                                                pSettings->ActiveTask->FontShadow = pSettings->InactiveTask->FontShadow = true;
                                                InvalidateRect(pToolbar->hToolbarWnd, NULL, false);
                                                InvalidateRect(pSystembar->hSystembarWnd, NULL, false);
                                                InvalidateRect(pSlit->hSlitWnd, NULL, false);
                                        }
                                        else PostMessage(GetBBWnd(), BB_SETSTYLE, 0, 0);

                                        break;
                                }
                                else if (!stricmp(m_pszArgument, "WriteProtection")) {
                                        MenuItem::Invoke(button);
                                        if (!pSettings->writeProtection)
                                        {
                                                WriteBool(pSettings->extrcFile, "xoblite.write.protection:", true);
                                                pSettings->writeProtection = true;
                                                MessageBox(GetBBWnd(), "Write protection enabled.   ", "xoblite", MB_OK | MB_ICONINFORMATION | MB_SETFOREGROUND | MB_TOPMOST);
                                        }
                                        else
                                        {
                                                pSettings->writeProtection = false;
                                                WriteBool(pSettings->extrcFile, "xoblite.write.protection:", false);
                                                MessageBox(GetBBWnd(), "Write protection disabled.   ", "xoblite", MB_OK | MB_ICONINFORMATION | MB_SETFOREGROUND | MB_TOPMOST);
                                        }

                                        if (pSettings->taskbarOnToolbar && pSystembar) InvalidateRect(pSystembar->hSystembarWnd, NULL, false);
                                        else if (pToolbar) InvalidateRect(pToolbar->hToolbarWnd, NULL, false);

                                        break;
                                }
                                else if (!stricmp(m_pszArgument, "DisableRootCommands")) {
                                        MenuItem::Invoke(button);
                                        if (!pSettings->disableRootCommands) pSettings->disableRootCommands = true;
                                        else pSettings->disableRootCommands = false;
                                        WriteBool(pSettings->extrcDefaultFile, "xoblite.disable.rootCommands:", pSettings->disableRootCommands);
                                        break;
                                }
                                else if (!stricmp(m_pszArgument, "DisableScriptSupport")) {
                                        MenuItem::Invoke(button);
                                        if (!pSettings->disableScriptSupport) pSettings->disableScriptSupport = true;
                                        else pSettings->disableScriptSupport = false;
                                        WriteBool(pSettings->extrcFile, "xoblite.disable.script.support:", pSettings->disableScriptSupport);
                                        break;
                                }
/*
                                else if (!stricmp(m_pszArgument, "FocusNewWindows")) {
                                        MenuItem::Invoke(button);
                                        if (!pSettings->focusNewWindows) pSettings->focusNewWindows = true;
                                        else pSettings->focusNewWindows = false;
                                        WriteBool(bbrcPath(), "session.screen0.focusNewWindows:", pSettings->focusNewWindows);
                                        break;
                                }
                                else if (!stricmp(m_pszArgument, "FocusLastWindow")) {
                                        MenuItem::Invoke(button);
                                        if (!pSettings->focusLastWindow) pSettings->focusLastWindow = true;
                                        else pSettings->focusLastWindow = false;
                                        WriteBool(bbrcPath(), "session.screen0.focusLastWindow:", pSettings->focusLastWindow);
                                        break;
                                }
*/
                                else if (!stricmp(m_pszArgument, "DisableSysTray")) {
                                        MenuItem::Invoke(button);
                                        if (!pSettings->systrayDisabled) pSettings->systrayDisabled = true;
                                        else pSettings->systrayDisabled = false;
                                        WriteBool(pSettings->extrcDefaultFile, "xoblite.systray.disable:", pSettings->systrayDisabled);
                                        if (pSettings->systrayDisabled) MessageBox(GetBBWnd(), "The internal system tray will be disabled   \nthe next time you launch xoblite.   ", "xoblite", MB_OK | MB_ICONINFORMATION | MB_TOPMOST);
                                        else MessageBox(GetBBWnd(), "The internal system tray will be enabled   \nthe next time you launch xoblite   \n(however, please note that it is always   \ndisabled when running on top of Explorer).   ", "xoblite", MB_OK | MB_ICONINFORMATION | MB_TOPMOST);
                                        break;
                                }
                                else if (!stricmp(m_pszArgument, "DisableXobloonNotifications")) {
                                        MenuItem::Invoke(button);
                                        if (!pSettings->systembarXobloonNotifications) pSettings->systembarXobloonNotifications = true;
                                        else pSettings->systembarXobloonNotifications = false;
                                        if (!pSettings->systrayDisabled)
                                        {
                                                if (pTrayManager->ShowBalloonTooltip)
                                                {
                                                        pTrayManager->ShowBalloonTooltip = false;
                                                        if (pTrayManager->BalloonTooltipItem.hWnd != NULL)
                                                        {
                                                                // Dismiss the notification and inform the parent application that
                                                                // the balloon tooltip has been dismissed because of timing out...
                                                                if (pTrayManager->BalloonTooltipItem.hWnd != NULL)
                                                                {
                                                                        PostMessage(pTrayManager->BalloonTooltipItem.hWnd, pTrayManager->BalloonTooltipItem.uCallbackMessage, pTrayManager->BalloonTooltipItem.uID, NIN_BALLOONTIMEOUT);
                                                                }
                                                        }
                                                        InvalidateRect(pSystembar->hSystembarWnd, NULL, false);
                                                }
                                        }
                                        WriteBool(pSettings->extrcFile, "xoblite.systembar.xobloon.notifications:", pSettings->systembarXobloonNotifications);
                                        break;
                                }
                                else if (!stricmp(m_pszArgument, "RunStartupApps")) {
                                        MenuItem::Invoke(button);
                                        if (!pSettings->runStartupApps) pSettings->runStartupApps = true;
                                        else pSettings->runStartupApps = false;
                                        WriteBool(pSettings->extrcDefaultFile, "xoblite.startup.programs:", pSettings->runStartupApps);
                                        break;
                                }
                        }
                        else if (!stricmp(m_pszCommand, "<task_item>"))
                        {
                                MenuItem::Invoke(button);

                                // Convert the hexadecimal format string back to HWND... (pretty cool, eh? :D )
                                HWND hWnd = (HWND)strtoul(m_pszArgument, 0, 16);
                                // ...and bring the window to the front of the z-order!
                                if (IsIconic(hWnd)) ShowWindow(hWnd, SW_RESTORE);
                                SetForegroundWindow(hWnd);
                                SendMessage(GetBBWnd(), BB_BRINGTOFRONT, 0, (LPARAM)hWnd);

                                break;
                        }
                }

                break;
        }
}

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

unsigned int CommandItem::GetDrawTextFormat()
{
        return TitleItem::GetDrawTextFormat();
}

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





syntax highlighting by

w e b c p p
web c plus plus