/*! \file objstr.h
*	\brief Scol Objects structure
*   \author Fred Manisse
*/

//
// Modifications History
//
//$ LB (13/06/2002) : changed the objbitmap struct to manage the GDI problem.
//
//
//$LB (16/12/2003) : add a background bitmap to the ObjWindow struct, in order to simulate
//                   the windows transparency (Win95, 98, Me). (WinXp, win2k : doesn't have to be
//                   simulated). 


#ifndef OBJSTR_H
#define OBJSTR_H

#include <commctrl.h>

#define MAX_TEXT        32000

#define OBJ_TYPE_NULL                   0
#define OBJ_TYPE_WINDOW                 1
#define OBJ_TYPE_TEXT                   2
#define OBJ_TYPE_EDIT_LINE              3
#define OBJ_TYPE_EDIT_TEXT              4
#define OBJ_TYPE_PUSHBUTTON             5
#define OBJ_TYPE_MENU                   6
#define OBJ_TYPE_CHECK_BOX              7
#define OBJ_TYPE_COMBO_BOX              8
#define OBJ_TYPE_FONT                   9
#define OBJ_TYPE_RICH_TEXT              10
#define OBJ_TYPE_BITMAP                 11
#define OBJ_TYPE_PUSH_BUTTON_BITMAP     12
#define OBJ_TYPE_LIST_BOX               14
#define OBJ_TYPE_MENU_ITEM              15
#define OBJ_TYPE_CURSOR                 16
#define OBJ_TYPE_TREE                   17
#define OBJ_TYPE_LISTBITMAP             18
#define OBJ_TYPE_LISTTAB                19
#define OBJ_TYPE_HEADER                 20

/* Window states flags */
#define WINDOW_MINIMIZED                1
#define WINDOW_MAXIMIZED                2
#define WINDOW_RESTORED                 3
#define WINDOW_HIDDEN                   4
#define WINDOW_UNHIDDEN                 5

/* Window creation flags */
#define WN_MINIMIZE                     (1<<0)
#define WN_NOBORDER                     (1<<1)
#define WN_NOCAPTION                    (1<<2)
#define WN_NOCLIPCHILDREN               (1<<3)
#define WN_CHILD                        (1<<4)
#define WN_ACTIVEX                      (1<<5)
#define WN_MINBOX                       (1<<6)
#define WN_SIZEBOX                      (1<<7)
#define WN_MENU                         (1<<8)
#define WN_NOCURSOR                     (1<<9)
#define WN_NOFOCUS                      (1<<10)
#define WN_DRAGDROP                     (1<<11)
#define WN_CHILDMENU                    (1<<12)
#define WN_HIDE                         (1<<13)
#define WN_DIALOG                       (1<<14)
#define WN_DOWN                         (1<<15)
#define WN_GROUP                        (1<<16)
#define WN_MAXBOX                       (1<<17)
#define WN_MODAL                        (1<<18)
#define WN_HSCROLL                      (1<<19)
#define WN_VSCROLL                      (1<<20)
#define WN_CHILDSCROLL                  (1<<21)
#define WN_NOBACKGROUND					        (1<<22)
#define WN_NOSCOL                       (1<<24)
#define WN_EX_LAYERED                   (1<<25)
#define WN_TOPMOST											(1<<26)
#define BUFFER_FLAG_DOWN 1


/* le buffer est de bas de en haut , et non de haut en bas */

/****************************************************************************************/
/*                                                                                      */
/*              Structure ObjVoid : base structure, common to all objects               */
/*                                                                                      */
/****************************************************************************************/

struct ObjVoid {

        int     Type            ; /* Object type					                    */       
        int     Father          ; /* Scol pointer to father                             */
        int     Buffer          ; /* TYPEBUF data type                                  */
        int     Tab             ; /* TYPETAB data type		                            */
} ;


typedef struct ObjVoid *PtrObjVoid ;





/****************************************************************************************/
/*                                                                                      */
/*              Constantes definissant les differents types d'objets                    */
/*              Ces constantes correspondent au champ type de l'objet de base           */
/*                                                                                      */
/****************************************************************************************/

#define OBJ_TYPE_NULL                   0


#define OBJ_MAX_TYPE 1



/****************************************************************************************/
/*                                                                                      */
/*     Structure for bitmap type                                                         */
/*                                                                                      */
/****************************************************************************************/

//$ LB (13/06/2002) : changed the objbitmap struct to manage the GDI problem.
//$ LB (12/07/2003) : 16 bits to 24 bits


typedef unsigned char* OBJBITMAP_BUFFER;

struct ObjBitmap {

        int PosX ;
        int PosY ;
        int TailleW ;
        int TailleH ;
        int BPP , BytesPP, BPL ;
        int Flags ;
        HWND WHandler ;        
        int Couleurs ;		   // number of colors

		int handler;           // new global handler
		OBJBITMAP_BUFFER bits; // bitmap buffer
		PALETTEENTRY *table;   // table of colors
        HBITMAP DIBhandler;    // handler of the DIBSection
};

typedef struct ObjBitmap * PtrObjBitmap ;




//$LB (16/12/2003)
extern PtrObjBitmap LIB2DtransBkg; /* background bitmap for simulated window transparency */


struct Palette {
    unsigned char R [ 256 ] ;
    unsigned char G [ 256 ] ;
    unsigned char B [ 256 ] ;
} ;

typedef struct Palette * PtrPalette ;
#define GET_RED(pal,num)  ((pal)->R[num]) 
#define GET_GREEN(pal,num) ((pal)->G[num])
#define GET_BLUE(pal,num) ((pal)->B[num])





/****************************************************************************************/ 
/*                                                                                      */ 
/*              Structure ObjWindow : structure de donnees buffer d'un objet window     */ 
/*                                                                                      */ 
/****************************************************************************************/ 

//$LB (16/12/2003) : add a background bitmap to the ObjWindow struct, in order to simulate
//                   the windows transparency (Win95, 98, Me). (WinXp, win2k : doesn't have to be
//                   simulated). 
struct ObjWindow {

        int     PosX            ; /* position X a l'ecran                               */ 
        int     PosY            ; /* position Y a l'ecran                               */ 
        int     TailleW         ; /* taille horizontale de la fenetre                   */ 
        int     TailleH         ; /* tailel verticale de la fenetre                     */ 
        int     Flags           ; /* flags de la fenetre                                */ 
        HWND    WHandler        ; /* Handler Windows                                    */ 
        int     MinW            ; /* taille minimale horizontale de la fenetre          */ 
        int     MinH            ; /* taille minimale verticale de la fenetre            */ 
        int     MaxW            ; /* taille maximale horizontale de la fenetre          */ 
        int     MaxH            ; /* taille maximale verticale de la fenetre            */ 
        HWND    Child           ; /* fenetre fille pour le scrolling                    */ 
        HCURSOR Cursor           ; /* fenetre fille pour le scrolling                    */ 

		//$LB(16/12/2003)
		unsigned char tSimulated; /* 1 if simulated (Win95,98,ME,NT),                    */
		PtrObjBitmap  tBuf      ; /* bitmap buffer for simulated transpary               */
		PtrObjBitmap  tBkg      ; /* point to LIB2DtransBkg                              */
		int           tX, tY    ; /* <=> window coordinates <=> coordinates of the LIB2DtransBkg area to draw */
		unsigned char tColorB   ; /* transparency color R G B                            */
		unsigned char tColorG   ;
		unsigned char tColorR   ; 
		unsigned char tfactor   ; /* alpha blending factor                                    */
		int           tflags    ; /* transparency flags : transparency color | alpha blending */

        };        

typedef struct ObjWindow *PtrObjWindow ;






/****************************************************************************************/
/*                                                                                      */
/*            Structure pour le type Font                                               */
/*                                                                                      */
/****************************************************************************************/

struct ObjFont {

        int Height ;
        int Direction ;
        int Flags ;
        HFONT WHandler ;
} ;

typedef struct ObjFont * PtrObjFont ;
                




//$LB (11/11/2003)
/****************************************************************************************/
/*                                                                                      */
/*      Structure pour le type cursor                                                   */
/*                                                                                      */
/****************************************************************************************/

struct ObjCursor {

    HCURSOR HCursor ;
    int X ;
    int Y ;  
} ;

typedef struct ObjCursor * PtrObjCursor ;





//-----------------------------------------------------------------------------
// Miscellaneous helper functions
//-----------------------------------------------------------------------------
#define SAFE_DELETE(p)        { if(p) { delete (p);     (p)=NULL; } }
#define SAFE_DELETE_ARRAY(p)  { if(p) { delete[] (p);   (p)=NULL; } }
#define SAFE_RELEASE(p)       { if(p) { (p)->Release(); (p)=NULL; } }
#define SAFE_CLOSE_HANDLE(p)  { if(p) { CloseHandle(p); (p)=NULL; } }
#define SAFE_DELETE_BUFFER(p) { if(p) { if( (p)->buffer ) delete[] (p)->buffer; delete (p); (p)=NULL; } }

#endif


