/******************************************************************************\
*
* File: ColorStock.h
* Creation date: January 05, 2004 20:02
* Author: Mel Viso
* 2004
* Purpose: Declaration of class 'ColorStock'
*
* Modifications: @INSERT_MODIFICATIONS(* )
* June 22, 2004 05:53 Mel Viso
* Update comment header
* January 05, 2004 21:53 Mel Viso
* Added method 'CyclePalette'
* Added member 'm_pLOGPALETTE'
* Added member 'm_offset'
* January 05, 2004 20:20 Mel Viso
* Added method 'GetHPal'
* Added member 'm_hPal'
* January 05, 2004 20:02 Mel Viso
* Added method 'FindColorEntry'
* Added method 'DestructorInclude'
* Added method 'ConstructorInclude'
* Added method 'ColorFromIndex'
* Added method '~ColorStock'
* Added method 'ColorStock'
* Added relation 'ColorStock <>-->> ColorEntry'
*
*Copyright (C) 2004, Mel Viso
*
*This program is free software; you can redistribute it and/or
*modify it under the terms of the GNU General Public License
*as published by the Free Software Foundation; either version 2
*of the License, or (at your option) any later version.
*
*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.
*
*You should have received a copy of the GNU General Public License (LICENSE.TXT)
*along with this program; if not, write to the Free Software
*Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
\******************************************************************************/
#ifndef _COLORSTOCK_H
#define _COLORSTOCK_H
//@START_USER1
//@END_USER1
class ColorStock
{
// RELATION_UNIQUEVALUETREE_OWNED_ACTIVE(ColorStock, ColorStock, ColorEntry, ColorEntry)
private:
CB_PTR(ColorEntry) _firstColorEntry;
int _countColorEntry;
protected:
public:
void AddColorEntry(ColorEntry* item);
void RemoveColorEntry(ColorEntry* item);
void DeleteAllColorEntry();
void ReplaceColorEntry(ColorEntry* item, ColorEntry* newItem);
ColorEntry* GetFirstColorEntry() const;
ColorEntry* GetLastColorEntry() const;
ColorEntry* GetNextColorEntry(ColorEntry* pos) const;
ColorEntry* GetPrevColorEntry(ColorEntry* pos) const;
int GetColorEntryCount() const;
class ColorEntryIterator
{
private:
ColorEntry* _refColorEntry;
ColorEntry* _prevColorEntry;
ColorEntry* _nextColorEntry;
const ColorStock* _iterColorStock;
ColorEntryIterator* _prev;
ColorEntryIterator* _next;
int (ColorEntry::*_method)() const;
static ColorEntryIterator* _first;
static ColorEntryIterator* _last;
public:
ColorEntryIterator(const ColorStock* iterColorStock,
int (ColorEntry::*method)() const = 0,
ColorEntry* refColorEntry = 0);
ColorEntryIterator(const ColorStock& iterColorStock,
int (ColorEntry::*method)() const = 0,
ColorEntry* refColorEntry = 0);
ColorEntryIterator(const ColorEntryIterator& iterator__,
int (ColorEntry::*method)() const = 0);
~ColorEntryIterator();
ColorEntryIterator& operator= (const ColorEntryIterator& iterator__)
{
_iterColorStock = iterator__._iterColorStock;
_refColorEntry = iterator__._refColorEntry;
_prevColorEntry = iterator__._prevColorEntry;
_nextColorEntry = iterator__._nextColorEntry;
_method = iterator__._method;
return *this;
}
ColorEntry* operator++ ()
{
_nextColorEntry = _iterColorStock->GetNextColorEntry(_nextColorEntry);
if (_method != 0)
{
while (_nextColorEntry && !(_nextColorEntry->*_method)())
_nextColorEntry = _iterColorStock->GetNextColorEntry(_nextColorEntry);
}
_refColorEntry = _prevColorEntry = _nextColorEntry;
return _refColorEntry;
}
ColorEntry* operator-- ()
{
_prevColorEntry = _iterColorStock->GetPrevColorEntry(_prevColorEntry);
if (_method != 0)
{
while (_prevColorEntry && !(_prevColorEntry->*_method)())
_prevColorEntry = _iterColorStock->GetPrevColorEntry(_prevColorEntry);
}
_refColorEntry = _nextColorEntry = _prevColorEntry;
return _refColorEntry;
}
operator ColorEntry*() { return _refColorEntry; }
ColorEntry* operator-> () { return _refColorEntry; }
ColorEntry* Get() { return _refColorEntry; }
void Reset() { _refColorEntry = _prevColorEntry = _nextColorEntry = (ColorEntry*)0; }
int IsLast() { return (_iterColorStock->GetLastColorEntry() == _refColorEntry); }
int IsFirst() { return (_iterColorStock->GetFirstColorEntry() == _refColorEntry); }
static void Check(ColorEntry* itemColorEntry);
static void Check(ColorEntry* itemColorEntry, ColorEntry* newItemColorEntry);
};
//@START_USER2
//@END_USER2
// Members
private:
HPALETTE m_hPal;
int m_offset;
LOGPALETTE* m_pLOGPALETTE;
protected:
public:
// Methods
private:
void ConstructorInclude();
void DestructorInclude();
protected:
public:
ColorStock();
virtual ~ColorStock();
COLORREF ColorFromIndex(double index);
void CyclePalette(HDC hDC);
HPALETTE GetHPal() const;
ColorEntry* FindColorEntry(COLORREF color);
};
#endif
#ifdef CB_INLINES
#ifndef _COLORSTOCK_H_INLINES
#define _COLORSTOCK_H_INLINES
/*@NOTE_1133
Returns the value of member 'm_hPal'.
*/
inline HPALETTE ColorStock::GetHPal() const
{//@CODE_1133
return m_hPal;
}//@CODE_1133
//@START_USER3
//@END_USER3
#endif
#endif