// Revision: 19 1.15 source/ui/basectl/inotebk.hpp, notebook, ioc.v400, 980918  
#ifndef _INOTEBK_
#define _INOTEBK_
/*******************************************************************************
* FILE NAME: inotebk.hpp                                                       *
*                                                                              *
* DESCRIPTION:                                                                 *
*   Declaration of the classes:                                                *
*     IPageHandle                                                              *
*     INotebook                                                                *
*     INotebook::Cursor                                                        *
*     INotebook::PageSettings                                                  *
*                                                                              *
* COPYRIGHT:                                                                   *
*   IBM Open Class Library                                                     *
*   (C) Copyright International Business Machines Corporation 1992, 1996       *
*   Licensed Material - Program-Property of IBM - All Rights Reserved.         *
*   US Government Users Restricted Rights - Use, duplication, or disclosure    *
*   restricted by GSA ADP Schedule Contract with IBM Corp.                     *
*                                                                              *
*******************************************************************************/
#include <icontrol.hpp>
#include <irect.hpp>
#include <istring.hpp>
#include <ihandle.hpp>
#include <ipoint.hpp>

#if __IBMCPP__ >= 400
#pragma namemangling(compat)
#endif

class IResourceId;
class ITabBitmapMgr;
class INotebookData;
class INotebookCursorData;
class INotebookPageSettingsData;
class INotebookDrawItemEvent;
class IColor;

#ifdef IC_WIN
  class IPageClipWindow;
  class INotebookPageSequence;
#endif

#pragma enum(4)
#pragma pack(push,4)

class IPageHandle : public IHandle {
typedef IHandle
  Inherited;
public:
/*------------------------------- Constructors -------------------------------*/
  IPageHandle ( Value pageId = 0 );

/*-------------------------------- Page Handle -------------------------------*/
  operator Value ( ) const;

}; // class IPageHandle


class INotebook : public IControl {
typedef IControl
  Inherited;
public:
class Style;
/*------------------------------- Constructors -------------------------------*/
  INotebook   ( unsigned long        windowId,
                IWindow*             parent,
                IWindow*             owner,
                const IRectangle&    initial = IRectangle(),
                const Style&         style = defaultStyle() );

#ifdef IC_PMWIN
  INotebook   ( unsigned long        windowId,
                IWindow*             parentAndOwner );
  INotebook   ( const IWindowHandle& handle );
#endif

virtual
 ~INotebook   ( );

/*---------------------------------- Styles ----------------------------------*/
INESTEDBITFLAGCLASSDEF2(Style, INotebook, IWindow, IControl);
                                    // style class definition
static const Style
  IC_IMPORTU classDefaultStyle,
#ifndef IC_MOTIF_FLAGNOP
  IC_IMPORTU pmCompatible,
#endif
  IC_IMPORTU spiralBinding,
  IC_IMPORTU solidBinding,
  IC_IMPORTU backPagesBottomRight,
  IC_IMPORTU backPagesBottomLeft,
  IC_IMPORTU backPagesTopRight,
  IC_IMPORTU backPagesTopLeft,
  IC_IMPORTU majorTabsRight,
  IC_IMPORTU majorTabsLeft,
  IC_IMPORTU majorTabsTop,
  IC_IMPORTU majorTabsBottom,
  IC_IMPORTU squareTabs,
  IC_IMPORTU roundedTabs,
  IC_IMPORTU polygonTabs,
#ifndef IC_MOTIFPM_FLAGNOP
  IC_IMPORTU allTabsVisible,
  IC_IMPORTU handleDrawTabs,
#endif
  IC_IMPORTU statusTextLeft,
  IC_IMPORTU statusTextRight,
  IC_IMPORTU statusTextCenter,
  IC_IMPORTU tabTextLeft,
  IC_IMPORTU tabTextRight,
  IC_IMPORTU tabTextCenter;

static Style
  defaultStyle      ( );

static void
  setDefaultStyle   ( const Style&    style );

virtual unsigned long
  convertToGUIStyle ( const IBitFlag& style,
                      bool         extendedOnly = false ) const;

/*----------------------------- Status Text ------------------------------------*/
enum TextAlignment {
  left,
  right,
  center
};

virtual INotebook
 &setStatusTextAlignment ( TextAlignment       alignment ),
 &setStatusText          ( const IPageHandle&  referencePage,
                           const char*         statusText ),
 &setStatusText          ( const IPageHandle&  referencePage,
                           const IResourceId&  resourceId );

virtual TextAlignment
  statusTextAlignment    ( ) const;

/*------------------------------- Tab Support --------------------------------*/
enum TabShape {
  square,
  rounded,
  polygon
};

#ifndef IC_MOTIF_FLAGNOP
virtual INotebook
 &setTabShape         ( TabShape             tabShape ),
 &setMajorTabSize     ( const ISize&         sizeMajorTab ),
 &setMinorTabSize     ( const ISize&         sizeMinorTab );

virtual TabShape
  tabShape            ( ) const;
#endif

virtual INotebook
 &setTabTextAlignment ( TextAlignment        alignment ),
 &refreshTabs         ( ),
 &setTabText          ( const IPageHandle&   referencePage,
                        const char*          tabText ),
 &setTabText          ( const IPageHandle&   referencePage,
                        const IResourceId&   resourceId ),
 &setTabBitmap        ( const IPageHandle&   referencePage,
                        const IBitmapHandle& bitmap ),
 &setTabBitmap        ( const IPageHandle&   referencePage,
                        const IResourceId&   resourceId );

virtual TextAlignment
  tabTextAlignment    ( ) const;

#ifndef IC_MOTIFPM_FLAGNOP
bool
  areAllTabsVisible   ( ) const,
#endif
  isDrawTabsEnabled   ( ) const;

/*------------------------------ Page Button ---------------------------------*/
#ifndef IC_MOTIF_FLAGNOP
virtual INotebook
 &setPageButtonSize ( const ISize& sizePageButton );
#endif

/*----------------------------- Orientation ----------------------------------*/
enum Orientation {
  backpagesBottomTabsRight,
  backpagesTopTabsRight,
  backpagesBottomTabsLeft,
  backpagesTopTabsLeft,
  backpagesRightTabsTop,
  backpagesLeftTabsTop,
  backpagesRightTabsBottom,
  backpagesLeftTabsBottom
};

virtual INotebook
 &setOrientation   ( Orientation orientation );

virtual Orientation
  orientation      ( ) const;

/*----------------------------- Binding Support ------------------------------*/
enum Binding {
  spiral,
  solid
};

virtual INotebook
 &setBinding     ( Binding binding );

virtual Binding
  binding        ( ) const;

/*------------------------------ Colors --------------------------------------*/
virtual IColor
  backgroundColor              ( ) const,
  hiliteBackgroundColor        ( ) const,
  pageBackgroundColor          ( ) const,
  majorTabBackgroundColor      ( ) const,
  minorTabBackgroundColor      ( ) const,
  majorTabForegroundColor      ( ) const,
  minorTabForegroundColor      ( ) const;

virtual INotebook
 &setPageBackgroundColor       ( const IColor& color ),
 &setMajorTabBackgroundColor   ( const IColor& color ),
 &setMinorTabBackgroundColor   ( const IColor& color ),
 &setMajorTabForegroundColor   ( const IColor& color ),
 &setMinorTabForegroundColor   ( const IColor& color );

#ifdef IC_MOTIF
virtual INotebook
 &setBackgroundColor           ( const IColor& color ),
 &setForegroundColor           ( const IColor& color );
#endif

#ifndef IC_MOTIF_FLAGNOP
virtual INotebook
 &resetPageBackgroundColor     ( ),
 &resetMajorTabBackgroundColor ( ),
 &resetMinorTabBackgroundColor ( ),
 &resetMajorTabForegroundColor ( ),
 &resetMinorTabForegroundColor ( );
#endif

/*--------------------------- Native Control Support -------------------------*/
#ifndef IC_MOTIF_FLAGNOP
bool
  isPMCompatible ( ) const;
#endif


class PageSettings  {
friend class INotebook;
public:
/*-------------------------------- Attributes --------------------------------*/
INESTEDBITFLAGCLASSDEF0(Attribute, INotebook::PageSettings);
static const Attribute
  IC_IMPORTU autoPageSize,
  IC_IMPORTU statusTextOn,
  IC_IMPORTU majorTab,
  IC_IMPORTU minorTab,
  IC_IMPORTU noAttribute;

/*------------------------------- Constructors -------------------------------*/
  PageSettings  ( );
  PageSettings  ( const Attribute&               attribute );
  PageSettings  ( const char*                    tabText,
                  const char*                    statusText = 0,
                  const Attribute&               pageAttribute = noAttribute );
  PageSettings  ( const IBitmapHandle&           tabBitmap,
                  const char*                    statusText = 0,
                  const Attribute&               pageAttribute = noAttribute );
  PageSettings  ( const INotebook::PageSettings& pageSettings );
  PageSettings
   &operator =  ( const INotebook::PageSettings& pageSettings );

virtual
  ~PageSettings ( );


/*----------------------------- Status Text ------------------------------------*/
virtual INotebook::PageSettings
 &setStatusText     ( const char*        statusText ),
 &setStatusText     ( const IResourceId& resourceId );

virtual IString
  statusText        ( ) const;

bool
  isStatusTextOn    ( ) const;

/*--------------------------------- Tabs -------------------------------------*/
virtual INotebook::PageSettings
 &setTabText        ( const char*          tabText ),
 &setTabText        ( const IResourceId&   resourceId ),
 &setTabBitmap      ( const IBitmapHandle& bitmap ),
 &setTabBitmap      ( const IResourceId&   resourceId );

virtual IString
  tabText           ( ) const;

virtual IBitmapHandle
  tabBitmap         ( ) const;

bool
  isMajorTab        ( ) const,
  isMinorTab        ( ) const;


/*---------------------------- Application Data ------------------------------*/
virtual INotebook::PageSettings
 &setUserData       ( unsigned long userData );

virtual unsigned long
  userData          ( ) const;

/*---------------------------- Automatic Sizing ------------------------------*/
bool
  isAutoSize       ( ) const;

private:
/*-------------------------------- Private -----------------------------------*/
Attribute
  pageStyle;
IBitmapHandle
  savedTabBitmap;
unsigned long
  savedUserData;
IString
  savedStatusText,
  savedTabText;

INotebookPageSettingsData
 *fPageSettingsData;
}; // INotebook::PageSettings


class Cursor  {
public :
/*------------------------------- Constructors -------------------------------*/
  Cursor  ( const INotebook& notebook );

virtual
  ~Cursor ( );

/*------------------------------ Page Iteration ------------------------------*/
virtual bool
  setToFirst    ( ),
  setToNext     ( ),
  setToPrevious ( ),
  setToLast     ( ),
  isValid       ( ) const;

virtual void
  invalidate    ( );

/*------------------------------- Page Retrieval -----------------------------*/
virtual IPageHandle
  first      ( ),
  next       ( ),
  previous   ( ),
  last       ( ),
  current    ( ) const;

void
  setCurrent ( const IPageHandle& current );


private:
/*----------------------------- Hidden Members -------------------------------*/
Cursor       ( const Cursor& cursor );
Cursor
 &operator=  ( const Cursor& cursor );

/*--------------------------------- Private ----------------------------------*/
const INotebook
 &nbCl;
unsigned long
  ulClCurrentPageId;
unsigned long
  ulClReferences;

INotebookCursorData
 *fCursorData;
}; // INotebook::Cursor


/*------------------------------ Page Addition -------------------------------*/
virtual IPageHandle
  addFirstPage      ( const PageSettings& pageInfo,
                      IWindow*            pageWindow = 0 ),
  addLastPage       ( const PageSettings& pageInfo,
                      IWindow*            pageWindow = 0 ),
  addPageBefore     ( const PageSettings& pageInfo,
                      const IPageHandle&  referencePage,
                      IWindow*            pageWindow = 0 ),
  addPageAfter      ( const PageSettings& pageInfo,
                      const IPageHandle&  referencePage,
                      IWindow*            pageWindow = 0 ),
  addPageBefore     ( const PageSettings& pageInfo,
                      const Cursor&       cursor,
                      IWindow*            pageWindow = 0 ),
  addPageAfter      ( const PageSettings& pageInfo,
                      const Cursor&       cursor,
                      IWindow*            pageWindow = 0 );

/*------------------------------- Page Removal -------------------------------*/
virtual INotebook
 &removePage        ( const IPageHandle&  page ),
 &removePage        ( const Cursor&       cursor ),
 &removeAllPages    ( ),
 &removeTabSection  ( const IPageHandle&  page ),
 &removeTabSection  ( const Cursor&       cursor );

/*---------------------------- Page Manipulation -----------------------------*/
virtual INotebook
 &turnToPage        ( const IPageHandle&  page ),
 &turnToPage        ( const Cursor&       cursor );

virtual IPageHandle
  topPage           ( ) const,
  firstPage         ( ) const,
  lastPage          ( ) const,
  nextPage          ( const IPageHandle&  referencePage ) const,
  previousPage      ( const IPageHandle&  referencePage ) const;

/*---------------------------- Page Information ------------------------------*/
PageSettings
  pageSettings      ( const Cursor&       cursor ) const,
  pageSettings      ( const IPageHandle&  page ) const;

/*---------------------------- Application Data ------------------------------*/
virtual INotebook
 &setUserData       ( const IPageHandle& referencePage,
                      unsigned long      userData );

/*------------------------- Page Window Association --------------------------*/
virtual IWindow
 *window            ( const Cursor&      cursor ) const,
 *window            ( const IPageHandle& page ) const;

virtual INotebook
 &setWindow         ( const Cursor&      cursor,
                            IWindow*     pageWindow = 0 ),
 &setWindow         ( const IPageHandle& referencePage,
                            IWindow*     pageWindow = 0 );


/*------------------------------- Page Support -------------------------------*/
virtual ISize
  pageSize        ( ) const,
  notebookSize    ( const IPageHandle& page ) const;

virtual unsigned long
  totalPages      ( ) const,
  pagesToMajorTab ( const IPageHandle& page ) const,
  pagesToMajorTab ( const Cursor&      cursor ) const,
  pagesToMinorTab ( const IPageHandle& page ) const,
  pagesToMinorTab ( const Cursor&      cursor ) const,
  pagesToEnd      ( const IPageHandle& page ) const,
  pagesToEnd      ( const Cursor&      cursor ) const;

virtual bool
  isEmpty         ( ) const;

/*------------------------------ Layout Support ------------------------------*/
#ifdef IC_WIN
virtual INotebook
 &setLayoutDistorted  ( unsigned long layoutAttributesOn,
                        unsigned long layoutAttributesOff );
#endif // IC_WIN

/*------------------------------ Font Functions ------------------------------*/
#ifdef IC_MOTIF
virtual INotebook
 &setFont        ( const IFont& font );

virtual IFont
  font           ( ) const;
#endif //IC_MOTIF

/*-------------------------- Notification Members ----------------------------*/
static INotificationId const
  IC_IMPORTU pageBackgroundColorId,
  IC_IMPORTU majorTabBackgroundColorId,
  IC_IMPORTU minorTabBackgroundColorId,
  IC_IMPORTU majorTabForegroundColorId,
  IC_IMPORTU minorTabForegroundColorId,
  IC_IMPORTU orientationId;

virtual IWindow
 &enableNotification ( bool enable=true );

protected:
/*------------------------------ Layout Support ------------------------------*/
virtual ISize
  calcMinimumSize ( ) const;

/*-------------------------------- Color -------------------------------------*/
#ifdef IC_MOTIF
virtual INotebook
 &setColor         ( unsigned long colorArea,
                     const IColor& color );
#endif
private:
/*----------------------------- Hidden Members -------------------------------*/
INotebook   ( const INotebook& notebook );
INotebook
 &operator= ( const INotebook& notebook );

/*--------------------------------- Private ----------------------------------*/
INotebookData
 *fNotebookData;

static Style
  currentDefaultStyle;

#ifdef IC_PMWIN
unsigned long
  queryPage      ( void* mp1, void* mp2 ) const,
  insertPage     ( void* mp1, void* mp2 );

bool
  deletePage     ( void* mp1, void* mp2 );

short
  queryPageCount ( void* mp1, void* mp2 ) const;

IPageHandle
#ifdef IC_WIN
  insertPageInfo2 ( const PageSettings& pageInfo,
                    const IPageHandle&  referencePage,
                    IWindow*            window,
                    unsigned long       fPosition ),
#endif //IC_WIN
  insertPageInfo ( const PageSettings& pageInfo,
                   const IPageHandle&  referencePage,
                   IWindow*            window,
                   unsigned long       fPosition );
#endif  //IC_PMWIN

#ifdef IC_MOTIF
IPageHandle
   addPageAt( int                 pageNumber,
              const PageSettings& settings,
              IWindow*            newPage,
              bool                replacePage = false );
#endif

ITabBitmapMgr
 *bmClTabBitmapMgr;
unsigned long
  ulClValidate;

friend class INotebook::Cursor;
friend class INotebookHandler;

INESTEDBITFLAGCLASSDEF0(clrFlags, INotebook);
static const clrFlags
  IC_IMPORTU bgnPageColor,
  IC_IMPORTU bgnMajorColor,
  IC_IMPORTU bgnMinorColor,
  IC_IMPORTU fgnMajorColor,
  IC_IMPORTU fgnMinorColor;

INotebook::clrFlags
  colorFlags;

void setNotebookColors   ( unsigned long color,
                           unsigned long colorArea );
void storeNotebookColors ( unsigned long color,
                           unsigned long
                           colorArea );
IColor UnsignedLongAsRGB ( unsigned long color ) const;

struct NotebookColors
{
  unsigned long  pageBackgroundColor;
  unsigned long  majorTabBackgroundColor;
  unsigned long  minorTabBackgroundColor;
  unsigned long  majorTabForegroundColor;
  unsigned long  minorTabForegroundColor;
};
NotebookColors
 *pnotebookColors;


#ifdef IC_WIN
// Tab control related functions and members

friend class INotebookDrawItemEvent;
friend class IPageClipWindow;

static bool
  hasBeenRegistered;

IWindow
 *pageClippingWindow ( ) const;

bool
  processTabSelect   ( void*        pPageSelNotify,
                       bool      bSelectPending ) const;

void
  showTopPage        ( long         iPageIndex,
                       void*        pRect,
                       bool      bNotResizing = true ) const,
  adjustRect         ( bool      bTabCtrlSize,
                       void*        pRect ) const,
  tabControlResize   ( const ISize& newSize ) const;

INotebookPageSequence
  *pTabCtrlPageSeqCl;
unsigned long
  ulClPagesInserted;

INotebookPageSequence
 *tabPageHandleCollection ( ) const;

long
  tabPageIndex            ( const IPageHandle&  pageHandle ) const;

IPageHandle
  tabPageHandle           ( unsigned long       ulPosition ) const,
  insertTabPage           ( const PageSettings& pageInfo,
                            const IPageHandle&  referencePage,
                            unsigned long       ulPosition );

bool
  removeTabPage           ( const IPageHandle&  pageHandle );

#endif //IC_WIN

}; // INotebook

INESTEDBITFLAGCLASSFUNCS(Style, INotebook)

#pragma pack(pop)
#pragma enum(pop)

#if __IBMCPP__ >= 400
#pragma namemangling()
#endif

#include <inotebk.inl>

#endif /* _INOTEBK_ */
