/////////////////////////////////////////////////////////////////////////////
// Name:        wxTabbedWindow, wxPagingCtrl
// Purpose:     Contrib. demo
// Author:      Aleksandras Gluchovas
// Modified by: 19990908 : mj10777@mj10777.de
//              19990909 :
//              - rename to tabpgwin
//              - restruction of Variable declaration
//              - to prevent Warnings under MingGW32
// Modified by: 19990909 : Mark Johnson, mj10777@mj10777.de
//              - mNoVertScroll TRUE = no / FALSE = Original Code
//                the Original Code Paints a Vertical Scroll in wxPagingCtrl
//                which is not needed in this Version. Use TRUE for this.
// Modified by: 20000401 : mj10777@mj10777.de
//              - Added a member Variable in class twTabInfo
//                - int       mTabID;     // tab ID Number
//              - Added a Variable Parameter to class wxTabbedWindow::AddTab
//                - int       tabID,
//              In this way a Tab can be identified by a unique ID-Number :
//              - The unique ID-Number for a View is the same as a Menu-ID
//              - The Menu has been activated
//              - A routine can look through all the Tabs looking for the ID
//                - if found     : the Tab will be activated : SetActiveTab(num)
//                - if not found : the View should be created
// Modified by: 20001001 : mj10777@mj10777.de
//              - Support for Transparity-Colour in Tab
//              - Support for Right-Mouse click  in Tab
// Created:     07/09/98
// Copyright:   (c) Aleksandras Gluchovas
// Licence:     wxWindows license
// RCS-ID:      $Id: pagectrl.h,v 1.2 2001/04/23 19:23:11 hansvl Exp $
/////////////////////////////////////////////////////////////////////////////

#ifndef __PAGECTRL_G__
#define __PAGECTRL_G__

#ifdef __GNUG__
#pragma interface "pagectrl.h"
#endif

#include "wx/defs.h"
#include "wx/window.h"
#include "wx/string.h"

#define WXCONTROLAREA_VERSION      1.0

// layout types for title bars of the tabs
// (are selected up by evaluating the available free space)

class twTabInfo; // forward decl.

#define wxTITLE_IMG_AND_TEXT 0
#define wxTITLE_IMG_ONLY     1
#define wxTITLE_BORDER_ONLY  2

/*
 * class manages and decorates contained "tab"-windows.
 * Draws decorations similar to those in "Project Workplace"
 * of Microsoft Developer Studio 4.xx
 */

class wxTabbedWindow : public wxPanel
{
public:
	wxTabbedWindow( wxWindow* parent, wxWindowID id, 
					const wxPoint& pos = wxDefaultPosition, 
					const wxSize& size = wxDefaultSize, 
					long style = 0, const wxString& name = "tabbedwnd" );
	
	wxTabbedWindow();
	virtual ~wxTabbedWindow();
	
	// tabs can be also added when the window is
	// already displayed - "on the fly"
	
	virtual void AddTab(wxWindow* pContent,           // contained window
						wxString  tabText,            // tab label
						int       tabID,              // tab ID Number  
						wxString  imageFileName = "", // if "", only text label is displayed
						long      imageType     = wxBITMAP_TYPE_BMP);
	
	// NOTE:: if this AddTab(..) overload is called, the
	//        image bitmap will not be serialized (if performed),
	//        use the above method instead, so that images could
	//        be restored using the given file names
	
	virtual void AddTab(wxWindow* pContent,
						wxString  tabText,
						int       tabID,              // tab ID Number  
						wxBitmap* pImage = NULL);
	
	virtual void RemoveTab(int tabNo);
	
	/* misc accessors */
	
	virtual int GetTabCount();
	virtual wxWindow* GetTab(int tabNo);
	virtual wxWindow* GetActiveTab();
	virtual void SetActiveTab(int tabNo);
	
	virtual void SetGenerateMasks(bool on);
	virtual bool GetGenerateMasks();
	virtual void SetMaskColor(const wxColour& col);
	virtual wxColour& GetMaskColor();
	
	void DrawShadedRect(int x, int y, int width, int height,
		wxPen& upperPen, wxPen& lowerPen, wxDC& dc);
	
	virtual void DrawDecorations(wxDC& dc);
	
	// return -1, if non of the title bars was hitted,
	// otherwise the index of the hitted tab title bar
	
	virtual int HitTest(const wxPoint& pos);
	
	// should be invoked to redisplay window with changed properties
	
	virtual void RecalcLayout(bool andRepaint = TRUE);
	
	// event handlers
	
	void OnPaint(wxPaintEvent& event);
	void OnSize (wxSizeEvent& event);
	
	void OnBkErase(wxEraseEvent& event);
	virtual void OnLButtonDown(wxMouseEvent& event);
	virtual void OnRButtonDown(wxMouseEvent& event);
	
	DECLARE_EVENT_TABLE()
		
protected:
	void PrepareBitmap(wxBitmap& bmp);
	
	DECLARE_DYNAMIC_CLASS(wxTabbedWindow)
		
public:
	friend class wxTabbedWindowSerializer;
	
	wxList mTabs;
	void HideInactiveTabs(bool andRepaint);
	
	// overrride,to provide different font for tab-labels
	
	virtual wxFont GetLabelingFont();
	
	// FOR NOW:: scrollbars are actually related to wxPagingCtrl
	
	wxScrollBar* mpTabScroll;
	wxScrollBar* mpHorizScroll;
	wxScrollBar* mpVertScroll;
	
public:
	// public properties (invoke ReclaclLayout(TRUE) to apply changes)
	
	int    mVertGap;         // default: 3
	int    mHorizGap;        // default: 5
	int    mTitleVertGap;    // default: 3
	int    mTitleHorizGap;   // default: 4
	int    mImageTextGap;    // default: 2
	int    mFirstTitleGap;   // default: 11
	int    mBorderOnlyWidth; // default: 8
	
	wxPen  mWhitePen;        // default: RGB(255,255,255)
	wxPen  mGrayPen;         // default: RGB(192,192,192)
	wxPen  mDarkPen;         // default: RGB(128,128,128)
	wxPen  mBlackPen;        // default: RGB( 0,  0,  0)
	
	int    mActiveTab;
	int    mTitleHeight;
	int    mLayoutType;
	
	// notifications (can be handled by derivatives)
	
	virtual void OnTabAdded(twTabInfo* pInfo) {}
	
	virtual void SizeTabs(int x,int y, int width, int height, bool repant);
	
	void DoInitTabbedWindow();
	
protected:
	bool mGenerateMasks;
	wxColour mMaskColor;
	
};

/*
 * class manages and decorates contained "sheets" (or pages).
 * Draws decorations similar to those in "Output window"
 * of Microsoft Developer Studio 4.xx
 */

class wxPagingCtrl : public wxTabbedWindow
{
public:
	 wxPagingCtrl();
	 
	 wxPagingCtrl( wxWindow* parent, wxWindowID id, 
				const wxPoint& pos = wxDefaultPosition, 
				const wxSize& size = wxDefaultSize, 
				long style = 0, const wxString& name = "pagectrl" );
	 
	 ~wxPagingCtrl();
	 
	 // NOTE:: use public methods of the base class
	 //        to add "pages" to this window
	 
	 /* misc accessors */
	 
	 // below two methods should be called after
	 // the tabs were added (AddTab(..)). Set up
	 // these scrollbars to match the needs of the
	 // tabs added into this area
	 
	 wxScrollBar& GetVerticalScrollBar();
	 wxScrollBar& GetHorizontalScrollBar();
	 
	 virtual void DrawDecorations(wxDC& dc);
	 
	 // return -1, if non of the title bars was hitted,
	 // otherwise the index of the hitted tab title bar
	 
	 virtual int HitTest(const wxPoint& pos);
	 
	 virtual void RecalcLayout(bool andRepaint = TRUE);
	 
	 // This function is to have interaction with a 
	 // wxPagingCtrl aware object.
	 bool ResultLastScrollAction();
	 void SetNextCaller(wxWindow *caller);
	 
	 // Virtual function need by the embed control to 
	 // handel scrolling
	 
	 // Sets the scrollbar properties of a built-in or external scrollbar.
	 virtual void SetScrollbar(int orientation, int position, int thumbSize, int range, bool refresh = FALSE);
	 // Sets the position of one of the built-in or external scrollbars
	 virtual void SetScrollPos(int orientation, int pos, bool refresh = FALSE);
	 
	 // Returns the built-in or external scrollbar thumb size
	 virtual int GetScrollThumb(int orientation);
	 // Returns the built-in or external scrollbar position.
	 virtual int GetScrollPos(int orientation);
	 // Returns the built-in or external scrollbar range.
	 virtual int GetScrollRange(int orientation);
	 
	 // event handlers
	 
	 void OnPaint(wxPaintEvent& event);
	 void OnSize (wxSizeEvent& event);
	 void OnLButtonDown(wxMouseEvent& event);
	 void OnLButtonUp  (wxMouseEvent& event);
	 void OnMouseMove  (wxMouseEvent& event);
	 void OnScroll     (wxScrollEvent& event);
	 
	 DECLARE_EVENT_TABLE()
	 DECLARE_DYNAMIC_CLASS(wxPagingCtrl)
		 
protected:
	 void DoInitPagingCtrl();
	 
	 // the protected: public: changes prevents Warnings in gcc
protected:
	 bool         mScrollEventInProgress;
	 bool		  mScrollResult;
	 wxWindow*	  mCaller;
	 
public:
	 int          mTabTrianGap;
	 wxBrush      mWhiteBrush;
	 wxBrush      mGrayBrush;
	 int          mCurentRowOfs;
	 int          mAdjustableTitleRowLen; // setup by dragging mini-sash
	 // with the mosue pointer
protected:
	 // drag&drop state variables
	 bool         mIsDragged;
	 int          mDagOrigin;
	 bool         mCursorChanged;
	 wxCursor     mResizeCursor;
	 wxCursor     mNormalCursor;
	 int          mOriginalTitleRowLen;
	 
public:
	 int          mTitleRowStart;
	 int          mResizeNailGap;
	 int          mTitleRowLen;               // actual title row length
	 int          mNoVertScroll;              // No Vertical Scroll  TRUE/FALSE
	 
public:
	 void DrawPaperBar(twTabInfo& tab, int x, int y,
		 wxBrush& brush, wxPen& pen, wxDC& dc);
	 
	 int GetWholeTabRowLen();
	 
	 // adjusts scorllbars to fit around tabs
	 
	 virtual void OnTabAdded(twTabInfo* pInfo);
	 
	 // sets smaller font for page-labels
	 
	 virtual wxFont GetLabelingFont();

};

// helper structure of wxTabbedWindow

class twTabInfo : public wxObject
{
	DECLARE_DYNAMIC_CLASS(twTabInfo)

public:
	twTabInfo();
	~twTabInfo();
	int ImgWidth();
	int ImgHeight();
	int ImageToTxtGap(int prefGap);
	
	bool HasImg();
	wxBitmap& GetImg();
	// bool HasText();
	unsigned int HasText();
	wxString& GetText();
	wxWindow& GetContent();
	
public:
	wxWindow* mpContent;
	wxBitmap  mBitMap;
	
	int       mTabID;     // tab ID Number
	wxString  mText;
	wxSize    mDims;
	
	// used for serialization
	wxString  mImageFile;
	long      mImageType;
	
};

enum PAGE_CONTROL_COMMAND_EVENTS
{
	wxEVT_TAB_RIGHT_CLICKED = 2000, //wxEVT_USER_FIRST,
	wxEVT_TAB_LEFT_CLICKED
};

#define EVT_TAB_RIGHT_CLICKED(id, fn) { wxEVT_TAB_RIGHT_CLICKED, id, -1, \
    (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) & fn, \
    (wxObject *) NULL },

#define EVT_TAB_LEFT_CLICKED(id, fn) { wxEVT_TAB_LEFT_CLICKED, id, -1, \
    (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) & fn, \
    (wxObject *) NULL },


#endif // __PAGECTRL_G__