//	Zinc Application Framework - Z_COMBO.HPP
//	COPYRIGHT (C) 1990-1999.  All Rights Reserved.
//	Zinc Software Incorporated.  Pleasant Grove, Utah  USA

#if !defined(Z_COMBO_HPP)
#define Z_COMBO_HPP
#include <z_vlist.hpp>

// --------------------------------------------------------------------------
// ----- ZafComboBox --------------------------------------------------------
// --------------------------------------------------------------------------

class ZAF_EXPORT ZafComboBox : public ZafWindow
{
public:
	// --- General members ---
	ZafVtList *list;

	ZafComboBox(int left, int top, int width, int height,
		int maxListHeight = -1);
	ZafComboBox(const ZafComboBox &copy);
	virtual ~ZafComboBox(void);

	// --- Persistent members ---
	virtual ZafWindowObject *Duplicate(void);
#if defined(USE_ZAF_PERSISTENCE)
	ZafComboBox(const ZafIChar *name, ZafObjectPersistence &persist);
	static ZafElement *Read(const ZafIChar *name, ZafObjectPersistence &persist);
	virtual void Write(ZafObjectPersistence &persist);
#endif

	// --- Attributes & data access ---
	// get
	bool AutoSortData(void) const;
	virtual void ConvertCoordinates(ZafCoordinateType coordinateType);
	virtual ZafRegionStruct ListRegion(void) const;
	virtual int MaximumListHeight(void) const;
	virtual int ListWidth(void) const;
	bool ViewOnly(void) const;
	// set
	virtual bool SetAutoSortData(bool autoSortData);
	virtual void SetListRegion(const ZafRegionStruct &region);
	virtual int SetListWidth(int maxListHeight);
	virtual int SetMaximumListHeight(int maxListHeight);
	virtual void SetRegion(const ZafRegionStruct &region);
	virtual bool SetViewOnly(bool viewOnly);

	// --- Window members ---
	virtual void BroadcastEvent(const ZafEventStruct &event, int levels = 0);
	virtual ZafWindowObject *GetObject(ZafNumberID numberID);
	virtual ZafWindowObject *GetObject(const ZafIChar *stringID);
	virtual bool SetDestroyable(bool destroyable);
	virtual bool SetLocked(bool locked);
	virtual bool SetMaximized(bool maximized);
	virtual bool SetMinimized(bool minimized);
	virtual bool SetModal(bool modal);
	virtual bool SetMoveable(bool moveable);
	virtual bool SetNormalHotKeys(bool normalHotKeys);
	virtual ZafWindow *SetOwner(ZafWindow *owner);
	virtual ZafSelectionType SetSelectionType(ZafSelectionType selectionType);
	virtual bool SetSizeable(bool sizeable);
	virtual bool SetTemporary(bool temporary);

	// --- Window object members ---
	virtual bool Changed(void) const;
	virtual ZafEventType Event(const ZafEventStruct &event);
	ZafLogicalEvent LogicalEvent(const ZafEventStruct &event);
	virtual ZafWindowObject *FocusObject(void) const;
	virtual const ZafIChar *Text(void);
	virtual bool SetAcceptDrop(bool acceptDrop);
	virtual bool SetAutomaticUpdate(bool automaticUpdate);
	virtual ZafLogicalColor SetBackgroundColor(ZafLogicalColor color, ZafLogicalColor mono = ZAF_MONO_NULL);
	virtual bool SetBordered(bool bordered);
	virtual bool SetChanged(bool changed);
	virtual ZafCoordinateType SetCoordinateType(ZafCoordinateType coordinateType);
	virtual bool SetCopyDraggable(bool copyDraggable);
	virtual bool SetDisabled(bool disabled);
	virtual bool SetFocus(bool currentFocus);
	virtual ZafLogicalFont SetFont(ZafLogicalFont font);
	virtual const ZafIChar *SetHelpContext(const ZafIChar *helpContext);
	virtual const ZafIChar *SetHelpObjectTip(const ZafIChar *helpObjectTip);
	virtual bool SetLinkDraggable(bool linkDraggable);
	virtual bool SetMoveDraggable(bool moveDraggable);
	virtual bool SetNoncurrent(bool noncurrent);
	virtual bool SetOSDraw(bool osDraw);
	virtual const ZafIChar *SetQuickTip(const ZafIChar *quickTip);
	virtual ZafError SetText(const ZafIChar *text);
	virtual ZafLogicalColor SetTextColor(ZafLogicalColor color, ZafLogicalColor mono = ZAF_MONO_NULL);
	virtual bool SetVisible(bool visible);

	// --- Advanced event handling ---
#	if defined(ZAF_MACINTOSH)
	virtual ZafEventType DispatchMouseEvent(const ZafEventStruct &event);
#	elif defined(ZAF_INDEPENDENT) || defined(ZAF_CURSES)
	virtual ZafEventType DispatchMouseEvent(const ZafEventStruct &event);
	virtual ZafWindowObject *FindMouseObject(const ZafEventStruct &event);
#	endif

	// --- List members ---
	virtual ZafWindowObject *Add(ZafWindowObject *object, ZafWindowObject *position = ZAF_NULLP(ZafWindowObject));
	virtual ZafCompareFunction CompareFunction(void) const;
	int Count(void) { return (list->Count()); }
	ZafWindowObject *Current(void) const { return ((ZafWindowObject *)list->Current()); }
	virtual void Destroy(void);
	ZafWindowObject *First(void) const { return (list->First()); }
	ZafWindowObject *Get(int index) { return ((ZafWindowObject *)list->ZafList::Get(index)); }
	int Index(ZafWindowObject const *element) { return (list->Index(element)); }
	ZafWindowObject *Last(void) const { return(list->Last()); }
	virtual ZafCompareFunction SetCompareFunction(ZafCompareFunction compareFunction);
	void SetCurrent(ZafWindowObject *object) { list->SetCurrent(object); }
	virtual void Sort(void);
	virtual ZafWindowObject *Subtract(ZafWindowObject *object);

	ZafComboBox &operator+(ZafWindowObject *object) { Add(object); return(*this); }
	ZafComboBox &operator-(ZafWindowObject *object) { Subtract(object); return(*this); }

	// --- Class identification ---
	static ZafClassID classID;
	static ZafClassNameChar ZAF_FARDATA className[];
	virtual ZafClassID ClassID(void) const { return (classID); }
	virtual ZafClassName ClassName(void) const { return (className); }
	virtual bool IsA(ZafClassID compareID) const;
	virtual bool IsA(ZafClassName compareName) const;

	// --- Special OS members ---
	virtual OSWindowID OSScreenID(ZafScreenIDType type = ZAF_SCREENID) const;
	virtual ZafError OSUpdatePalettes(ZafPaletteType zafTypes, ZafPaletteType osTypes);

	// --- Unicode support ---
#	if defined(ZAF_UNICODE)
	virtual ZafWindowObject *GetObject(const char *stringID);
#	endif

protected:
	friend class ZAF_EXPORT OSComboBox;

	// --- General members ---
	bool viewOnly;
	int maxListHeight;
	int listWidth;

#if defined(ZAF_INDEPENDENT) || defined(ZAF_CURSES)
	int listHeight;
#endif

	ZafWindowObject *ComboCurrent(void) const { return ((ZafWindowObject *)current); }
	ZafWindowObject *ComboFirst(void) const { return ((ZafWindowObject *)first); }
	ZafWindowObject *ComboLast(void) const { return ((ZafWindowObject *)last); }

	virtual ZafRegionStruct ConvertToDrawRegion(const ZafWindowObject *object,
		const ZafRegionStruct *zafRegion = ZAF_NULLP(ZafRegionStruct)) const;
	virtual ZafEventType DragDropEvent(const ZafEventStruct &event);
	virtual ZafEventType DrawBorder(ZafRegionStruct &region, ZafEventType ccode);
	virtual ZafEventType DrawFocus(ZafRegionStruct &region, ZafEventType ccode);
	virtual ZafEventType Draw(const ZafEventStruct &event, ZafEventType ccode);
	virtual void GetClip(ZafWindowObject *object, ZafRegionStruct &clip, ZafRegionStruct &viewPort);
	virtual const ZafPaletteStruct *MapClassPalette(ZafPaletteType type, ZafPaletteState state);
	ZafWindowObject *MatchInput(ZafIChar matchValue);
	virtual ZafWindowObject *NotifyFocus(ZafWindowObject *object, bool focus);
	virtual ZafWindowObject *NotifySelection(ZafWindowObject *object, bool selected);
	virtual ZafEventType ScrollEvent(const ZafEventStruct &event) { return (list->ScrollEvent(event)); }

	// --- Special OS members ---
	virtual void OSDestroy(void);
	virtual ZafEventType OSEvent(const ZafEventStruct &event);
	virtual ZafError OSGetText(void);
	virtual void OSMapPalette(ZafPaletteStruct &palette, ZafPaletteType type, ZafPaletteState state);
	virtual void OSRegisterObject(void);
	virtual ZafError OSSetText(void);
	virtual void OSSize(void);
	virtual void OSSort(void);

#if defined(USE_ZAF_PERSISTENCE)
	// --- Persistent members ---
	void ReadData(ZafObjectPersistence &persist);
	virtual ZafObjectConstructor ReadFunction(void) { return (ZafComboBox::Read); }
	void WriteData(ZafObjectPersistence &persist);
#endif

#	if defined(ZAF_MSWINDOWS)
	ZafStringData stringData;
#	elif defined(ZAF_MOTIF)
	int listHeight;
	ZafStringData stringData;
	ZafRegionStruct selectRegion;
	ZafWindowObject *comboItem;
	void DrawArrow(bool depressed);
#	elif defined(ZAF_INDEPENDENT) || defined(ZAF_CURSES)
	ZafWindowObject *comboString, *comboButton, *mouseObject;
#	elif defined(ZAF_MACINTOSH)
	ZafWindowObject *comboString;
#	endif

private:
	static ZafPaletteMap ZAF_FARDATA defaultPaletteMap[];
	static ZafEventMap ZAF_FARDATA defaultEventMap[];
};

// --- inline functions ---
inline bool ZafComboBox::AutoSortData(void) const { return list->AutoSortData(); }
inline bool ZafComboBox::ViewOnly(void) const { return viewOnly; }

#endif // Z_COMBO_HPP
