/********************************************************************************
*                                                                               *
*                    R o l l  O u t  P a n e  W i d g e t                       *
*                                                                               *
*********************************************************************************
* Roll Out Pane Widget Copyright (C) 2000-2003 by Petri Hodju.                  *
*********************************************************************************
* This library is free software; you can redistribute it and/or                 *
* modify it under the terms of the GNU Library General Public                   *
* License as published by the Free Software Foundation; either                  *
* version 2 of the License, or (at your option) any later version.              *
*                                                                               *
* This library 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             *
* Library General Public License for more details.                              *
*                                                                               *
* You should have received a copy of the GNU Library General Public             *
* License along with this library; if not, write to the Free                    *
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.            *
*********************************************************************************
* $Id: FXRollOut.h,v 1.1 2004/02/14 03:11:28 baxter Exp $                                                                          *
********************************************************************************/

#ifndef FXROLLOUT_H
#define FXROLLOUT_H

// Flags specific for this widget
enum {
  SMOOTH_ROLLOUT=0x10000000,
  ROLLOUT_OPEN=0x20000000, // start with rollout open
};

// View types. FXRollOut has LIST_VIEW type of view and
// FXRollOutPanje has PANE_VIEW type of view
enum {
  LIST_VIEW=0,
  PANE_VIEW=1
};

// Pane currently opening, closing and scrolling flags 
enum {
  PANE_SCROLLING=1,
  PANE_EXPANDING=2,
  PANE_COLLAPSING=4,
  PANE_SCROLLBARGRAB=8
};

//**********************************************************************
// Class for drawing frames for FXRollout & FXRollOutPane widgets
//**********************************************************************

class FXRollOutFrame {
public:
  FXRollOutFrame(FXApp *app);
  ~FXRollOutFrame();
  void drawBorderRectangle(FXDCWindow& dc,FXint x,FXint y,FXint w,FXint h);
  void drawRaisedRectangle(FXDCWindow& dc,FXint x,FXint y,FXint w,FXint h);
  void drawSunkenRectangle(FXDCWindow& dc,FXint x,FXint y,FXint w,FXint h);
  void drawRidgeRectangle(FXDCWindow& dc,FXint x,FXint y,FXint w,FXint h);
  void drawGrooveRectangle(FXDCWindow& dc,FXint x,FXint y,FXint w,FXint h);
  void drawDoubleRaisedRectangle(FXDCWindow& dc,FXint x,FXint y,FXint w,FXint h);
  void drawDoubleSunkenRectangle(FXDCWindow& dc,FXint x,FXint y,FXint w,FXint h);
  void drawFrame(FXDCWindow& dc,FXuint opts,FXint x,FXint y,FXint w,FXint h);
  void drawFocusRectangle(FXDCWindow& dc,FXint x,FXint y,FXint w,FXint h);
private:
  FXColor backColor;
  FXColor baseColor;
  FXColor hiliteColor;
  FXColor shadowColor;
  FXColor borderColor;
};

//**********************************************************************
// Base class for content of FXRollOut & FXRollOutPane Widget
//**********************************************************************

class FXRollOutContent : public FXComposite {
  FXDECLARE(FXRollOutContent)
private:
  // Private interface
  FXRollOutContent(const FXRollOutContent&);
  FXRollOutContent& operator=(const FXRollOutContent&);
protected:
  // Protected interface
  FXRollOutContent();
public:
  // Public interface
  FXRollOutContent(FXComposite *p,FXWindow *tgt=0,FXuint opts=0,
		   FXint x=0,FXint y=0,FXint w=0,FXint h=0,
		   FXint pl=DEFAULT_SPACING,FXint pr=DEFAULT_SPACING,
		   FXint pt=DEFAULT_SPACING,FXint pb=DEFAULT_SPACING,
		   FXint hs=DEFAULT_SPACING,FXint vs=DEFAULT_SPACING);
  inline FXint getContentWidth(){return content_width;}
  inline FXint getContentHeight(){return content_height;}
  virtual FXint getDefaultWidth();
  virtual FXint getDefaultHeight();
  virtual void create();
  virtual void layout();
  virtual void enable();
  virtual void disable();
  void adjust(FXint w=0, FXint h=0);
  virtual ~FXRollOutContent();
private:
  // Private members
  FXint content_width,content_height;
  FXint padleft,padright,padtop,padbottom,border,vspacing,hspacing;
protected:
  // Protected members
public:
  // Public members
public:
  // Message Handlers
  long onPaint(FXObject *,FXSelector,void *);
  long onFocus(FXObject *,FXSelector,void *);
public:
  // Message IDs
};

//**********************************************************************
// View class for FXRollOut & FXRollOutPane classes
//**********************************************************************

class FXRollOutView : public FXComposite {
  FXDECLARE(FXRollOutView)
    friend class FXRollOut;
    friend class FXRollOutPane;
    friend class FXRollOutContent;
private:
  // Private interface
  FXRollOutView(const FXRollOutView&);
  FXRollOutView& operator=(const FXRollOutView&);
protected:
  // Protected interface
  FXRollOutView();
  FXRollOutView(FXComposite *p,FXWindow *tgt=0,FXuint opts=0,
		FXint x=0,FXint y=0,FXint w=0,FXint h=0,
    FXint pl=DEFAULT_SPACING,FXint pr=DEFAULT_SPACING,
		FXint pt=DEFAULT_SPACING,FXint pb=DEFAULT_SPACING,
		FXint hs=DEFAULT_SPACING,FXint vs=DEFAULT_SPACING);
  inline void setViewType(FXint view_type){viewType=view_type;}
  inline FXint getViewType(){return viewType;}
public:
  // Public interface
  void scrollContent(FXint dx, FXint dy);
  inline FXRollOutContent *getContent(){return content;}
  inline FXint getContentWidth(){return content->getContentWidth();}
  inline FXint getContentHeight(){return content->getContentHeight();}
  virtual FXint getDefaultWidth();
  virtual FXint getDefaultHeight();
  virtual void create();
  virtual void layout();
  virtual ~FXRollOutView();
private:
  // Private members
  FXRollOutContent *content;
  FXint viewType;
protected:
  // Protected members
public:
  // Public members
public:
  // Message Handlers
  long onPaint(FXObject *,FXSelector,void *);
  long onFocus(FXObject *,FXSelector,void *);
public:
  // Message IDs
};

//**********************************************************************
// Class for expand/collapse style dialog  
//**********************************************************************

class FXRollOutPane : public FXComposite {
  FXDECLARE(FXRollOutPane)
private:
  // Private interface
  FXRollOutPane(const FXRollOutPane&);
  FXRollOutPane& operator=(const FXRollOutPane&);
protected:
  // Protected interface
  FXRollOutPane();
public:
  // Public interface
  FXRollOutPane(FXComposite *p,
    const FXString& text1,const FXString& text2,
    FXIcon *ic=NULL,FXIcon *ic2=NULL,
    FXWindow *tgt=0,
		FXuint opts=0,FXuint btn_opts=FRAME_RAISED|FRAME_THICK|JUSTIFY_NORMAL|ICON_BEFORE_TEXT,
    FXint x=0,FXint y=0,FXint w=0,FXint h=0);
  inline FXRollOutContent* getContent(){return view->getContent();}
  inline FXint getContentWidth(){return view->getContentWidth();}
  inline FXint getContentHeight(){return view->getContentHeight();}
  virtual FXint getDefaultWidth();
  virtual FXint getDefaultHeight();
  virtual void create();
  virtual void layout();
  virtual void enable();
  virtual void disable();
  void adjust(FXint w=0, FXint h=0);
  void rollout();
  void rollup();
  virtual ~FXRollOutPane();
private:
  // Private members
  FXToggleButton *button;
  FXRollOutView *view;
  FXRollOutFrame *frame;
  FXTimer *timer;
  FXint border,lrborder,mode,scrolling;
  FXint cch,chc;
protected:
  // Protected members
public:
  // Public members
public:
  // Message Handlers
  long onPaint(FXObject *,FXSelector,void *);
  long onButton(FXObject *,FXSelector,void *);
  long onTimeout(FXObject *,FXSelector,void *);
  long onFocusUp(FXObject *,FXSelector,void *);
public:
  // Message IDs
  enum {
    ID_PANE_BUTTON=FXComposite::ID_LAST,
    ID_PANE_TIMEOUT,
    ID_PANE_OPENING,
    ID_PANE_EXPAND,
    ID_PANE_CLOSING,
    ID_PANE_COLLAPSE,
    ID_LAST
  };
};

//**********************************************************************
//**********************************************************************

class FXRollOut : public FXComposite {
  FXDECLARE(FXRollOut)
private:
  // Private interface
  FXRollOut(const FXRollOut&);
  FXRollOut& operator=(const FXRollOut&);
  FXint restrictX(FXint dx);
  FXint restrictY(FXint dy);
  void updateScrollbar();
  void checkViewPosition(FXRollOutPane *pane, FXint action);
  FXint dragFromView(FXint dy);
  FXint dragFromScrollbar(FXint dy);
  void drawScrollbar();
protected:
  // Protected interface
  FXRollOut();
  void setCursor(FXCursor *cursor,FXWindow *wnd=0);
public:
  // Public interface
  FXRollOut(FXComposite *p,const FXString& text,FXuint opts=0,
	    FXint x=0,FXint y=0,FXint w=0,FXint h=0,
      FXint pl=DEFAULT_PAD,FXint pr=DEFAULT_PAD,FXint pt=DEFAULT_PAD,FXint pb=DEFAULT_PAD);
  FXRollOutContent* createPane(const FXString& text,FXIcon *ic=NULL,FXuint opts=0,
    FXuint btn_opts=FRAME_RAISED|FRAME_THICK|JUSTIFY_NORMAL|ICON_BEFORE_TEXT);
  FXRollOutContent* createPane(const FXString& text, const FXString&text2, FXIcon *ic=NULL, FXIcon *ic2=NULL, 
    FXuint opts=0,FXuint btn_opts=FRAME_RAISED|FRAME_THICK|JUSTIFY_NORMAL|ICON_BEFORE_TEXT);
  void addPane(FXWindow *wnd, FXWindow *tgt=0);
  void scrollContent(FXint dx,FXint dy);
  virtual FXint getDefaultWidth();
  virtual FXint getDefaultHeight();
  virtual void create();
  virtual void layout();
  virtual ~FXRollOut();
private:
  // Private members
protected:
  // Protected members
  FXRollOutView *view;
  FXRollOutFrame *frame;
  FXCursor *nodrag,*drag,*current;
  FXFont *font;
  FXString title;
  FXint border,fonthfix,scrolling,mouse_y;
  FXint sby,sbh;
  FXint inHandler;      // flag to prevent infinite recursion
  FXint   padtop;       // Top padding
  FXint   padbottom;    // Bottom padding
  FXint   padleft;      // Left padding
  FXint   padright;     // right padding

public:
  // Public members
public:
  // Message Handlers
  long onPaint(FXObject *,FXSelector,void *);
  long onUpdate(FXObject *,FXSelector,void *);
  long onCommand(FXObject *,FXSelector,void *);
  long onMouseWheel(FXObject *,FXSelector,void *);
  long onLeftBtnPress(FXObject *,FXSelector,void *);
  long onLeftBtnRelease(FXObject *,FXSelector,void *);
  long onRightBtnPress(FXObject *,FXSelector,void *);
  long onRightBtnRelease(FXObject *,FXSelector,void *);
  long onMouseMove(FXObject *,FXSelector,void *);
  long onConfigure(FXObject *,FXSelector,void *);
  long onKeyPress(FXObject *,FXSelector,void *);
  long onKeyRelease(FXObject *,FXSelector,void *);
  long onFocusSelf(FXObject *,FXSelector,void *);
  long onFocusIn(FXObject *,FXSelector,void *);
  long onFocusOut(FXObject *,FXSelector,void *);
  long onFocusUp(FXObject *,FXSelector,void *);
  long onFocusDown(FXObject *,FXSelector,void *);
public:
  // Message IDs
  enum {
    ID_EXPAND=FXComposite::ID_LAST,
    ID_COLLAPSE,
    ID_PANEUPDATE,
    ID_LAST
  };
};

#endif

