/*
 ============================================================================
 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 "TitleItem.h" 
#include "MenuItem.h" 
#include "MenuMaker.h" 
#include "../Settings.h" 

extern MenuMaker *pMenuMaker;
extern Settings *pSettings;

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

TitleItem::TitleItem(char* pszTitle, int type)
{
        m_pszTitle = pszTitle ? strdup(pszTitle) : NULL;
        itemType = type;

        // Set a higher sort priority for [separator] items to make
        // sort before any regular menu items (i.e. between folders
        // regular menu items)
        if (itemType == MENU_SEPARATOR) SetSortPriority(2);
        else if (itemType == MENU_HEADER) SetSortPriority(255);
}

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

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

LRESULT TitleItem::NcHitTest(int x, int y)
{
        if (IsOver(x, y))
        {
                if ((itemType == MENU_HEADER) && !m_pParent->GetParent()) return HTCAPTION;
                else return HTCLIENT;
        }
        else return HTCLIENT;
}

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

void TitleItem::Invoke(int button)
{
        if ((itemType == MENU_HEADER) && (button == 2)) pMenuMaker->Hide();
}

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

void TitleItem::Paint(HDC hDC)
{
        RECT r;
        GetTitleRect(&r);
        MenuItem::Paint(hDC);

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

        if (itemType == MENU_HEADER)
        {
                DrawTextWithShadow(hDC, m_pszTitle, r, GetDrawTextFormat(), pSettings->MenuTitle->TextColor, pSettings->menuTitleShadowColor, pSettings->MenuTitle->FontShadow);
        }

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

        else if (itemType == MENU_SEPARATOR)
        {
                HPEN hPen, hOldPen;
                hPen = CreatePen(PS_SOLID, 1, pSettings->menuSeparatorColor);
                hOldPen = (HPEN) SelectObject(hDC, hPen);

                int fromX = m_nLeft + pMenuMaker->m_nBorderWidth + 3;
                int toX = m_nLeft + GetWidth() - pMenuMaker->m_nBorderWidth - 3;
                int lineY = m_nTop + 3;

                MoveToEx(hDC, fromX, lineY, NULL);
                LineTo (hDC, toX, lineY);

                SelectObject(hDC, hOldPen);
                DeleteObject(hPen);
                DeleteObject(hOldPen);
        }

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

        else if (itemType == MENU_NOP) DrawTextWithShadow(hDC, m_pszTitle, r, GetDrawTextFormat(), pSettings->MenuFrame->TextColor, pSettings->menuFrameShadowColor, pSettings->MenuFrame->FontShadow);

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

        else // MENU_DEFAULT
        {
                if (IsActive()) DrawTextWithShadow(hDC, m_pszTitle, r, GetDrawTextFormat(), pSettings->MenuHilite->TextColor, pSettings->menuHiliteShadowColor, pSettings->MenuHilite->FontShadow);
                else DrawTextWithShadow(hDC, m_pszTitle, r, GetDrawTextFormat(), pSettings->MenuFrame->TextColor, pSettings->menuFrameShadowColor, pSettings->MenuFrame->FontShadow);
        }
}

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

void TitleItem::GetTitleRect(RECT* r)
{
        if (itemType == MENU_HEADER) // Header items
        {
                r->top = m_nTop;
//              r->left = m_nLeft + pMenuMaker->m_nBorderWidth + pSettings->bevelWidth + 2;
                r->left = m_nLeft + pMenuMaker->m_nBorderWidth + 3;
                r->bottom = m_nTop + GetHeight();
//              r->right = m_nLeft + GetWidth() - pMenuMaker->m_nBorderWidth - pSettings->bevelWidth - 2;
                r->right = m_nLeft + GetWidth() - pMenuMaker->m_nBorderWidth - 3;
                if (!stricmp(pSettings->MenuTitle->Font, "nu")) r->bottom--;
        }

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

        else // Normal items
        {
                r->top = m_nTop;
                r->left = m_nLeft + GetIndent();
                r->bottom = m_nTop + GetHeight();
                r->right = m_nLeft + GetWidth() - GetRightIndent();
        }
}

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

UINT TitleItem::GetDrawTextFormat()
{
        if (itemType == MENU_HEADER) // Header items
                return GetTitleAlignment() | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS | DT_NOCLIP;
        else // Normal items
                return GetAlignment() | DT_VCENTER | DT_NOPREFIX | DT_SINGLELINE | DT_END_ELLIPSIS | DT_NOCLIP;
}

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

void TitleItem::SetTitle(char* pszTitle)
{
        if(m_pszTitle) free(m_pszTitle);
        m_pszTitle = NULL;
        m_pszTitle = pszTitle ? strdup(pszTitle) : NULL;
}

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





syntax highlighting by

w e b c p p
web c plus plus