#include "CObjectCombo.h"
#include "Macro.h"
#include "../x/Objstr.h"
#include "utils.h"
#include "container.h"
#include "CObjectSlideBar.h"
#include "CObjectList.h"
#include "CObjectCheck.h"
#include "CObjectText.h"
#include "CObjectBitmap.h"
#include "CObjLayerFont.h"

extern int OBJNODE;
extern mmachine mm;



#define COMB_LIST	0
#define COMB_CHECK	1
#define COMB_BMP	2
#define COMB_TEXT	3

CObjectCombo::CObjectCombo(container * cont,Layer *layer,int x,int y,int w,int h, int flags,int contflags, int transp):CObjectBase(cont,layer,x,y,w,h,flags,contflags,transp)
{
}

CObjectCombo::~CObjectCombo()
{
}

// le combo n'est pas un vrai objet
int CObjectCombo::IsMouseOnObject(int x,int y, int p_tab)
{
	return 0;
}

int CObjectCombo::CursorMove(int x,int y,int keyFlags, int p_tab,int redrawobject)
{
	return 0;
}

int CObjectCombo::CursorMoveIn(int x,int y,int keyFlags, int p_tab,int redrawobject)
{
	return 0;
}

int CObjectCombo::CursorMoveInWithBtnPushed(int x,int y,int keyFlags, int p_tab,int redrawobject)
{
	return 0;
}

int CObjectCombo::CursorMoveOut(int x,int y,int keyFlags, int p_tab,int redrawobject)
{
	return 0;
}

int CObjectCombo::CursorMoveOutWithBtnPushed(int x,int y,int keyFlags, int p_tab,int redrawobject)
{
	return 0;
}

int CObjectCombo::CursorMoveOutsideWithBtnPushed(int x,int y,int keyFlags, int p_tab,int redrawobject)
{
	return 0;
}

int CObjectCombo::ClickIn(int x,int y,int btn,int keyFlags, int p_tab,int redrawobject)
{
	return 0;
}

int CObjectCombo::UnClickIn(int x,int y,int btn,int keyFlags, int p_tab,int redrawobject)
{
	return 0;
}
	
int CObjectCombo::ClickOut(int x,int y,int btn,int keyFlags, int p_tab,int redrawobject)
{
	return 0;
}

int CObjectCombo::UnClickOut(int x,int y,int btn,int keyFlags, int p_tab,int redrawobject)
{
	return 0;
}

int CObjectCombo::DblClickIn(int x,int y,int btn,int keyFlags, int p_tab,int redrawobject)
{
	return 0;
}

int CObjectCombo::MouseWheel(int delta,int x,int y,int keyFlags,int p_tab,int redrawobject)
{
	return 0;
}


int CObjectCombo::KeyUp(UINT vk,int cRepeat, UINT flags, int p_tab)
{
	return 0;
}

int CObjectCombo::KeyDown(UINT vk,int keysys,int cRepeat, UINT flags, int p_tab)
{
	return 0;
}

int CObjectCombo::SetFocus(int reset,int p_tab,int redraw)
{
	return 0;
}

int CObjectCombo::KillFocus(int p_tab,int redraw)
{
	return 0;
}

int CObjectCombo::Timer( int timerID )
{
	return 0;
}

Layer *CObjectCombo::GetLayer(mmachine m,int p_tab)
{
	return NULL;
}
	
Layer *CObjectCombo::GetLayerPart(mmachine m,Rect2D *area2redraw,int p_tab)
{
	return NULL;
}

int CObjectCombo::DestroyAllLayers()
{
	return 0;
}

int CObjectCombo::ResizeLayer(int w,int h,int p_tab)
{
	return 0;
}
	
// fonctions Scol

int _CRcompCombo( mmachine m )
{
	int tmp_res;
	int p_slidebar, p_list, p_check,p_combo;
	int flags_creation,flags_handler,p_objpere,p_container;
	int resize_flags;
	CObjectBase *obj_root,*obj_father,* new_object, *combo;
	container * co;
	int p_coordinates,x,y,w,h,button_w,text_h,nbre_etats;
	int itemsvisible, bitmaps_reserved_space;
	CObjLayerFont *layer_font;

//***********************************
#if DEBUG_LIB2D
MMechostr (0, "\n_CRcompCombo");
#endif
//***********************************

	// pile: Chn ObjContainer ObjNode [I I] I I I I ObjFont [I I I] [I I] [I AlphaBitmap] [I I I] [I AlphaBitmap [I I I]] // 14 elts

	// les differents tests de non validité
	if ((MMget(m,13))==NIL)
	{
		MMechostr(MSKTRACE,"_CRcompCombo: channel is nil\n");
		m->pp += 13;
		MMset(m,0,NIL);
		return 0;	
	}
	if ((MMget(m,12))==NIL)
	{
		MMechostr(MSKTRACE,"_CRcompCombo: container is nil\n");
		m->pp += 13;
		MMset(m,0,NIL);
		return 0;
	}
	if ((MMget(m,5))==NIL)
	{
		MMechostr(MSKTRACE,"_CRcompCombo: font is nil\n");
		m->pp += 13;
		MMset(m,0,NIL);
		return 0;
	}
	if ((MMget(m,2))==NIL)
	{
		MMechostr(MSKTRACE,"_CRcompCombo: button information is nil\n");
		m->pp += 13;
		MMset(m,0,NIL);
		return 0;
	}
	if ((MMget(m,1))==NIL)
	{
		MMechostr(MSKTRACE,"_CRcompCombo: list information is nil\n");
		m->pp += 13;
		MMset(m,0,NIL);
		return 0;
	}

#if DEBUG_OBJNODE
		MMechostr(MSKTRACE,"DEBUG_OBJNODE _CRcompCombo\n");
#endif

	if ( (h = MTOI( MMget( m, 6 )) ) == NIL ) h = 0;
	if ( (w = MTOI( MMget( m, 7 )) ) == NIL ) w = 0;
	if ((flags_handler=MTOI(MMget( m, 8 )))==NIL)  flags_handler =0;
	if ((flags_creation=MTOI(MMget( m, 9 )))==NIL) flags_creation=OBJ_ENABLE|OBJ_VISIBLE;
	resize_flags=GetResizeFlags(flags_creation);
	
	// les coordonnées
	if ((p_coordinates=MTOP(MMget(m,10)))==NIL)
	{
		x=0;
		y=0;
	}
	else
	{
		x=MTOI(MMfetch(m,p_coordinates,0));
		y=MTOI(MMfetch(m,p_coordinates,1));
	}

	// le container et le pere
	p_objpere=MTOP(MMget(m,11));
	p_container=MTOP(MMget(m,12));

	// on verifie que les infos pour chaque sous objet sont valides
	p_slidebar = MTOP( MMget( m, 0 ) );
	if ( p_slidebar != NIL && (MMfetch( m, p_slidebar, 1 ) == NIL || MMfetch( m, p_slidebar, 2 ) == NIL) )
	{
		MMechostr(MSKTRACE,"_CRcompCombo: slidebar information is invalid\n");
		m->pp += 13;
		MMset(m,0,NIL);
		return 0;
	}
	p_list = MTOP( MMget( m, 1 ) );
	if ( MMfetch( m, p_list, 1 ) == NIL )
	{
		MMechostr(MSKTRACE,"_CRcompCombo: list information is invalid\n");
		m->pp += 13;
		MMset(m,0,NIL);
		return 0;
	}
	if ( MMfetch ( m, p_list, 3 ) == NIL )
	{
		MMechostr(MSKTRACE,"_CRcompCombo: list bitmap is nil\n");
		m->pp += 13;
		MMset(m,0,NIL);
		return 0;
	}
	p_check = MTOP( MMget( m, 2 ) );
	if ( MMfetch( m, p_check, 1 ) == NIL )
	{
		MMechostr(MSKTRACE,"_CRcompCombo: button information is invalid\n");
		m->pp += 13;
		MMset(m,0,NIL);
		return 0;
	}

	// a ce stade toutes les valeurs des arguments ont ete verifiees
	// on va avoir besoin de la largeur et de la hauteur du bouton
	button_w = GET_PTR_OBJ_BITMAP( MTOP( MMfetch( m, MTOP( MMfetch( m, MTOP( MMget( m, 2 ) ), 1 ) ), 0 ) ) )->TailleW / 2;
	text_h = GET_PTR_OBJ_BITMAP( MTOP( MMfetch( m, MTOP( MMfetch( m, MTOP( MMget( m, 2 ) ), 1 ) ), 0 ) ) )->TailleH;
	// evaluation de la taille du bouton du CompCheck
	nbre_etats = 3;
	flags_creation = MTOI(MMfetch( m, p_check, 0 ));
	if (flags_creation&ROL_MASK) nbre_etats++;
	if (flags_creation&ROL_DISABLE) nbre_etats++;
	text_h=text_h/nbre_etats;
	
	obj_father=GetObjectBase(m,p_objpere);
	if ((p_objpere!=NIL)&&(obj_father==NULL))
	{
		MMechostr(MSKTRACE,"_CRcompCombo: object father already destroyed\n");
		m->pp += 13;
		MMset(m,0,NIL);
		return 0;
	}
	else if ((co=RetrievePtrContainer(m,p_container))==NULL)
	{
		MMechostr(MSKTRACE,"_CRcompCombo: container already destroyed\n");
		m->pp += 13;
		MMset(m,0,NIL);
		return 0;
	}
	else if (!co->OwnsObject(obj_father))
	{
		MMechostr(MSKTRACE,"_CRcompCombo: father object was not created in this container!\n");
		m->pp += 13;
		MMset(m,0,NIL);
		return 0;
	}
	else
	{
		// creation du CompCombo
		obj_root=co->Root();
		
		// le Channel
		CHECK( MMpush( m, MMget( m, 13 ) ) );
		CHECK( MMpush( m, NIL ) );
		CHECK( MMpush( m, NIL ) );
		CHECK( MMpush( m, NIL ) );
		CHECK( MMpush( m, NIL ) );

		// creation du nouvel objet
		new_object=new CObjectCombo(co,NULL,x,y,0,0,flags_creation,flags_handler,NO_TRANSPARENCY);
		// ajout de l'objet et creation du nouvel OBJNODE
		CHECK( AddNode(m,obj_root,obj_father,new_object,4) ); // on stockera le CompList pour le retrouver facilement
		combo = new_object;
	}

	// pile: Chn ObjContainer ObjNode [I I] I I I I ObjFont [I I I I] [I I] [I AlphaBitmap] [I I I AlphaBitmap] [I AlphaBitmap [I I I]] CompCombo// 15 elts

	// creation du CompBitmap de fond de la liste
	// le fond est caché par défaut au début
	
	flags_creation = resize_flags|OBJ_DISABLE|OBJ_HIDE;

	CHECK( MMpush( m, MMget( m, 14 ) ) );	// Chn
	CHECK( MMpush( m, MMget( m, 14 ) ) );	// ObjContainer
	CHECK( MMpush( m, MMget( m, 2 ) ) );    // ObjNode pere : le CompCombo
	// [I I] coordonnees
	CHECK( MMpush( m, ITOM( 0 ) ) );
	CHECK( MMpush( m, ITOM( text_h ) ) );
	CHECK( MMpush( m, ITOM( 2 ) ) );
	CHECK( MBdeftab( m ) );
	CHECK( MMpush( m, ITOM( flags_creation ) ) );
	CHECK( MMpush( m, ITOM( flags_handler ) ) );
	p_list = MTOP( MMget( m, 8 ) );
	CHECK( MMpush( m, MMfetch( m, p_list, 3 ) ) ); // alphaBitmap
	CHECK( MMpush( m, ITOM( 0 ) ) ); // sx
	CHECK( MMpush( m, ITOM( 0 ) ) ); // sy
	CHECK( MMpush( m, ITOM( w ) ) ); // sw
	CHECK( MMpush( m, ITOM( h ) ) ); // sh
	
	CHECK( _CRcompBitmap( m ) );
	
	// mise à jour du p_tab de l'objet combo en memorisant le
	// pointeur scol du bitmap
	p_combo = MTOP(MMget(m,1));
	MMstore(m,GetTab(m,p_combo),COMB_BMP,MMget(m,0));

	// pile: Chn ObjContainer ObjNode [I I] I I I I ObjFont [I I I I] [I I] [I AlphaBitmap] [I I I AlphaBitmap] [I AlphaBitmap [I I I]] CompCombo CompBitmap
	// creation du CompList
	p_list = MTOP( MMget( m, 3 ) );
	if ((flags_creation=MTOI(MMfetch( m, p_list, 0 )))==NIL) flags_creation=0;
	flags_creation |= OBJ_ENABLE|OBJ_VISIBLE;
	flags_creation -= flags_creation&OBJ_DISABLE;
	flags_creation -= flags_creation&OBJ_HIDE;

	itemsvisible = MTOI( MMfetch( m, p_list, 1 ) );
	bitmaps_reserved_space = MTOI( MMfetch( m, p_list, 2 ) );

	CHECK( MMpush( m, MMget( m, 15 ) ) );	// Chn
	CHECK( MMpush( m, MMget( m, 15 ) ) );	// ObjContainer
	CHECK( MMpush( m, MMget( m, 2 ) ) );    // ObjNode pere : le CompBitmap
	// [I I] coordonnees
	CHECK( MMpush( m, ITOM( 0 ) ) );
	CHECK( MMpush( m, ITOM( 0 ) ) );
	CHECK( MMpush( m, ITOM( 2 ) ) );
	CHECK( MBdeftab( m ) );
	CHECK( MMpush( m, ITOM( flags_creation ) ) );
	CHECK( MMpush( m, ITOM( flags_handler ) ) );
	if ( p_slidebar != NIL )
	{
		CHECK( MMpush( m, ITOM( w - button_w ) ) );
	}
	else
	{
		CHECK( MMpush( m, ITOM( w ) ) );
	}
	CHECK( MMpush( m, ITOM( h - text_h ) ) );
	CHECK( MMpush( m, ITOM( itemsvisible ) ) );
	CHECK( MMpush( m, ITOM( LST_VERTICAL ) ) );
	CHECK( MMpush( m, MMget( m, 17 ) ) ); // ObjFont
	CHECK( MMpush( m, ITOM( bitmaps_reserved_space ) ) );
	CHECK( MMpush( m, MMget( m, 18 ) ) ); // info de texte
	CHECK( MMpush( m, MMget( m, 18 ) ) ); // info de selection
	// [I I] coordonnees
	if ( p_slidebar != NIL )
	{
	// pile: Chn ObjContainer ObjNode [I I] I I I I ObjFont [I I I I] [I I] [I AlphaBitmap] [I I I AlphaBitmap] [I AlphaBitmap [I I I]] CompCombo CompBitmap
	//		 Chn ObjContainer ObjNode [I I] I I I I I I ObjFont I [texte] [selection]
		int p_coords, new_p_slidebar;

		// coordonnees du slidebar
		if ((p_coords = MMmalloc(m, 2, TYPETAB )) < 0) return p_coords;
		MMstore( m, p_coords, 0, ITOM( w - button_w ) );
		MMstore( m, p_coords, 1, ITOM( 0 ) );
		CHECK( MMpush( m, PTOM( p_coords ) ) );

		if ((new_p_slidebar = MMmalloc( m, 4, TYPETAB )) < 0) return new_p_slidebar;
		p_slidebar = MTOP( MMget( m, 17 ) );
		MMstore( m, new_p_slidebar, 0, MMpull( m ) ); // les coordonnees
		MMstore( m, new_p_slidebar, 1, MMfetch( m, p_slidebar, 0 ) );
		MMstore( m, new_p_slidebar, 2, MMfetch( m, p_slidebar, 1 ) );
		MMstore( m, new_p_slidebar, 3, MMfetch( m, p_slidebar, 2 ) );

		CHECK( MMpush( m, PTOM( new_p_slidebar ) ) );
	}
	else
	{
		CHECK( MMpush( m, NIL ) );
	}
	CHECK( _CRcompList( m ) );

	// mise à jour du p_tab de l'objet combo en memorisant le
	// pointeur scol de la liste
	p_combo = MTOP(MMget(m,2));
	MMstore(m,GetTab(m,p_combo),COMB_LIST,MMget(m,0));

	// pile: Chn ObjContainer ObjNode [I I] I I I I ObjFont [I I I I] [I I] [I AlphaBitmap] [I I I AlphaBitmap] [I AlphaBitmap [I I I]] CompCombo CompBitmap CompList

	// creation du CompCheck
	p_check = MTOP( MMget( m, 5 ) );
	if ((flags_creation=MTOI(MMfetch( m, p_check, 0 )))==NIL) flags_creation=OBJ_ENABLE|OBJ_VISIBLE;

	CHECK( MMpush( m, MMget( m, 16 ) ) );	// Chn
	CHECK( MMpush( m, MMget( m, 16 ) ) );	// ObjContainer
	CHECK( MMpush( m, MMget( m, 4 ) ) );	// ObjNode pere
	// [I I] coordonnees
	CHECK( MMpush( m, ITOM( w - button_w - 1 ) ) );
	CHECK( MMpush( m, ITOM( 0 ) ) );
	CHECK( MMpush( m, ITOM( 2 ) ) );
	CHECK( MBdeftab( m ) );
	CHECK( MMpush( m, ITOM( flags_creation ) ) );
	CHECK( MMpush( m, ITOM( flags_handler ) ) );
	p_check = MTOP( MMget( m, 11 ) );
	CHECK( MMpush( m, MMfetch( m, p_check, 1 ) ) );

	CHECK( _CRcompCheck( m ) );
	
	// mise à jour du p_tab de l'objet combo en memorisant le
	// pointeur scol du checkbox
	p_combo = MTOP(MMget(m,3));
	MMstore(m,GetTab(m,p_combo),COMB_CHECK,MMget(m,0));

	// creation du CompText
	// pile: Chn ObjContainer ObjNode [I I] I I I I ObjFont [I I I I] [I I] [I AlphaBitmap] [I I I AlphaBitmap] [I AlphaBitmap [I I I]] CompCombo CompBitmap CompList CompCheck
	flags_creation = resize_flags|OBJ_ENABLE|OBJ_VISIBLE|CT_LABEL|CT_LEFT;

	CHECK( MMpush( m, MMget( m, 17 ) ) );	// Chn
	CHECK( MMpush( m, MMget( m, 17 ) ) );	// ObjContainer
	CHECK( MMpush( m, MMget( m, 5 ) ) );    // ObjNode pere
	// [I I] coordonnees
	CHECK( MMpush( m, ITOM( bitmaps_reserved_space ) ) );        // decalage donne par le decalage de la liste

	// calculons la hauteur de la police
	layer_font=Lib2dFontService.getLayerFont(GET_PTR_OBJ_FONT(MTOP( MMget( m, 13 ) )));
	CHECK( MMpush( m, ITOM( (text_h - layer_font->CLFaverageCharHeight)/2 ) ) );
	CHECK( MMpush( m, ITOM( 2 ) ) );
	CHECK( MBdeftab( m ) );
	CHECK( MMpush( m, ITOM( flags_creation ) ) );
	CHECK( MMpush( m, ITOM( flags_handler ) ) );
	CHECK( MMpush( m, ITOM( w - button_w - bitmaps_reserved_space ) ) );
	CHECK( MMpush( m, ITOM( layer_font->CLFaverageCharHeight ) ) );
	Lib2dFontService.delLayerFont(layer_font);
	CHECK( MMpush( m, NIL ) );
	CHECK( MMpush( m, MMget( m, 18 ) ) );   // ObjFont
	CHECK( MMpush( m, MMget( m, 18 ) ) );   // infos de texte
	CHECK( MMpush( m, MMget( m, 18 ) ) );   // infos de selection
	CHECK( MMpush( m, NIL ) );				// slidebar vertical
	CHECK( MMpush( m, NIL ) );				// slidebar horizontal

	CHECK( _CRcompText( m ) );
	
	// mise à jour du p_tab de l'objet combo en memorisant le
	// pointeur scol du bitmap
	p_combo = MTOP(MMget(m,4));
	MMstore(m,GetTab(m,p_combo),COMB_TEXT,MMget(m,0));

	// les liens entre les sous-objets
	// pile: ... CompCombo CompBitmap CompList CompCheck CompText
	CHECK( MMpush( m, MMget( m, 2 ) ) );
	// pile: ... CompCombo CompBitmap CompList CompCheck CompText CompList
	CHECK( MMpush( m, ITOM( LINK_STRING_SELECT ) ) );
	CHECK( _CRnodeLink( m ) );
	MMpull( m );
	// pile: ... CompCombo CompBitmap CompList CompCheck
	CHECK( MMpush( m, MMget( m, 0 ) ) );
	INVERT( m, 1, 3 );
	// pile: ... CompCombo CompCheck CompList CompBitmap CompCheck
	CHECK( MMpush( m, ITOM( LINK_HIDE_AND_SHOW ) ) );
	CHECK( _CRnodeLink( m ) );
	MMpull( m );
	// pile: ... CompCombo CompCheck CompList
	CHECK( MMpush( m, ITOM( LINK_HIDE_AND_SHOW ) ) );
	CHECK( _CRnodeLink( m ) );
	MMpull( m );

	// nettoyage
	INVERT( m, 0, 14 );
	m->pp += 14;
	
//***********************************
#if DEBUG_LIB2D
MMechostr (0, "\n_CRcompCombo end");
#endif
//***********************************

	return 0;
}






int _DScompCombo( mmachine m )
{
	int p;

//***********************************
#if DEBUG_LIB2D
MMechostr (0, "\n_DScompCombo");
#endif
//***********************************

	if ((p=MTOP(MMpull(m)))!=NIL)
	{
		DsNode(m,p);
		return MMpush(m,0);
	}
	else
		return MMpush(m,NIL);
}





int _ADDcompCombo( mmachine m )
{
	int tmp_res, p_obj = MTOP( MMget( m, 2 ) );

//***********************************
#if DEBUG_LIB2D
MMechostr (0, "\n_ADDcompCombo");
#endif
//***********************************

	if ( p_obj != NIL )
	{
		if ( GetObjectBase(m,p_obj) == NULL )
		{
			MMpull( m );
			MMpull( m );
			MMset( m, 0, NIL );
			MMechostr(MSKTRACE,"_ADDcompCombo: Object already destroyed.\n");
			return 0;
		}
		CHECK( MMpush( m, MMfetch( m, GetTab( m, p_obj ), COMB_LIST ) ) );
		INVERT( m, 0, 1 );
		INVERT( m, 1, 2 );
		CHECK( _ADDcompList( m ) );
	}
	else
		MMpull( m );

	MMpull( m );

//***********************************
#if DEBUG_LIB2D
MMechostr (0, "\n_ADDcompCombo end");
#endif
//***********************************

	return 0;
}





int _DELcompCombo( mmachine m )
{
	int tmp_res, p_obj = MTOP( MMget( m, 1 ) );


//***********************************
#if DEBUG_LIB2D
MMechostr (0, "\n_DELcompCombo");
#endif
//***********************************

	if ( p_obj != NIL )
	{
		if ( GetObjectBase(m,p_obj) == NULL )
		{
			MMpull( m );
			MMset( m, 0, NIL );
			MMechostr(MSKTRACE,"_DELcompCombo: Object already destroyed.\n");
			return 0;
		}
		CHECK( MMpush( m, MMfetch( m, GetTab( m, p_obj ), COMB_LIST ) ) );
		INVERT( m, 0, 1 );
		CHECK( _DELcompList( m ) );
	}

	MMpull( m );

//***********************************
#if DEBUG_LIB2D
MMechostr (0, "\n_DELcompCombo end");
#endif
//***********************************

	return 0;
}






int _SDELcompCombo( mmachine m )
{
	int tmp_res, p_obj = MTOP( MMget( m, 1 ) );


//***********************************
#if DEBUG_LIB2D
MMechostr (0, "\n_SDELcompCombo");
#endif
//***********************************

	if ( p_obj != NIL )
	{
		if ( GetObjectBase(m,p_obj) == NULL )
		{
			MMpull( m );
			MMset( m, 0, NIL );
			MMechostr(MSKTRACE,"_SDELcompCombo: Object already destroyed.\n");
			return 0;
		}
		CHECK( MMpush( m, MMfetch( m, GetTab( m, p_obj ), COMB_LIST ) ) );
		INVERT( m, 0, 1 );
		CHECK( _SDELcompList( m ) );
	}

	MMpull( m );

//***********************************
#if DEBUG_LIB2D
MMechostr (0, "\n_SDELcompCombo end");
#endif
//***********************************

	return 0;
}






int _RSTcompCombo( mmachine m )
{
	int tmp_res, p_obj = MTOP( MMget( m, 0 ) );


//***********************************
#if DEBUG_LIB2D
MMechostr (0, "\n_RSTcompCombo");
#endif
//***********************************

	if ( p_obj != NIL )
	{
		if ( GetObjectBase(m,p_obj) == NULL )
		{
			MMset( m, 0, NIL );
			MMechostr(MSKTRACE,"_RSTcompCombo: Object already destroyed.\n");
			return 0;
		}
		CHECK( MMpush( m, MMfetch( m, GetTab( m, p_obj ), COMB_LIST ) ) );
		CHECK( _RSTcompList( m ) );
		MMpull( m );
	}


//***********************************
#if DEBUG_LIB2D
MMechostr (0, "\n_RSTcompCombo end");
#endif
//***********************************

	return 0;
}





int _GETcompComboCount( mmachine m )
{
	int tmp_res, p_obj = MTOP( MMget( m, 0 ) );


//***********************************
#if DEBUG_LIB2D
MMechostr (0, "\n_GETcompComboCount");
#endif
//***********************************

	if ( p_obj != NIL )
	{
		if ( GetObjectBase(m,p_obj) == NULL )
		{
			MMset( m, 0, NIL );
			MMechostr(MSKTRACE,"_GETcompComboCount: Object already destroyed.\n");
			return 0;
		}
		MMset( m, 0, MMfetch( m, GetTab( m, p_obj ), COMB_LIST ) );
		CHECK( _GETcompListCount( m ) );
	}


//***********************************
#if DEBUG_LIB2D
MMechostr (0, "\n_GETcompComboCount end");
#endif
//***********************************

	return 0;
}





int _GETcompComboValue( mmachine m )
{
	int tmp_res, p_obj = MTOP( MMget( m, 1 ) );

//***********************************
#if DEBUG_LIB2D
MMechostr (0, "\n_GETcompComboValue");
#endif
//***********************************


	if ( p_obj != NIL )
	{
		if ( GetObjectBase(m,p_obj) == NULL )
		{
			MMpull( m );
			MMset( m, 0, NIL );
			MMechostr(MSKTRACE,"_GETcompComboValue: Object already destroyed.\n");
			return 0;
		}
		MMset( m, 1, MMfetch( m, GetTab( m, p_obj ), COMB_LIST ) );
		CHECK( _GETcompListValue( m ) );
	}

//***********************************
#if DEBUG_LIB2D
MMechostr (0, "\n_GETcompComboValue end");
#endif
//***********************************

	return 0;
}





int _SETcompComboValue( mmachine m )
{
	int tmp_res, p_obj = MTOP( MMget( m, 2 ) );

//***********************************
#if DEBUG_LIB2D
MMechostr (0, "\n_SETcompComboValue");
#endif
//***********************************


	if ( p_obj != NIL )
	{
		if ( GetObjectBase(m,p_obj) == NULL )
		{
			MMpull( m );
			MMpull( m );
			MMset( m, 0, NIL );
			MMechostr(MSKTRACE,"_SETcompComboValue: Object already destroyed.\n");
			return 0;
		}
		CHECK( MMpush( m, MMfetch( m, GetTab( m, p_obj ), COMB_LIST ) ) );
		INVERT( m, 0, 1 );
		INVERT( m, 1, 2 );
		CHECK( _SETcompListValue( m ) );
	}
	else
		MMpull( m );

	MMpull( m );

//***********************************
#if DEBUG_LIB2D
MMechostr (0, "\n_SETcompComboValue end");
#endif
//***********************************

	return 0;
}





int _SSETcompComboValue( mmachine m )
{
	int tmp_res, p_obj = MTOP( MMget( m, 2 ) );

//***********************************
#if DEBUG_LIB2D
MMechostr (0, "\n_SSETcompComboValue");
#endif
//***********************************

	if ( p_obj != NIL )
	{
		if ( GetObjectBase(m,p_obj) == NULL )
		{
			MMpull( m );
			MMpull( m );
			MMset( m, 0, NIL );
			MMechostr(MSKTRACE,"_SSETcompComboValue: Object already destroyed.\n");
			return 0;
		}
		CHECK( MMpush( m, MMfetch( m, GetTab( m, p_obj ), COMB_LIST ) ) );
		INVERT( m, 0, 1 );
		INVERT( m, 1, 2 );
		CHECK( _SSETcompListValue( m ) );
	}
	else
		MMpull( m );

	MMpull( m );

//***********************************
#if DEBUG_LIB2D
MMechostr (0, "\n_SSETcompComboValue end");
#endif
//***********************************

	return 0;
}





int _POScompCombo( mmachine m )
{
	int tmp_res, p_obj = MTOP( MMget( m, 1 ) );

//***********************************
#if DEBUG_LIB2D
MMechostr (0, "\n_POScompCombo");
#endif
//***********************************

	if ( p_obj != NIL )
	{
		if ( GetObjectBase(m,p_obj) == NULL )
		{
			MMpull( m );
			MMset( m, 0, NIL );
			MMechostr(MSKTRACE,"_POScompCombo: Object already destroyed.\n");
			return 0;
		}
		MMset( m, 1, MMfetch( m, GetTab( m, p_obj ), COMB_LIST ) );
	}
	CHECK( _POScompList( m ) );

//***********************************
#if DEBUG_LIB2D
MMechostr (0, "\n_POScompCombo");
#endif
//***********************************

	return 0;
}





int _GETcompComboClicked( mmachine m )
{
	int tmp_res, p_obj = MTOP( MMget( m, 0 ) );

//***********************************
#if DEBUG_LIB2D
MMechostr (0, "\n_GETcompComboClicked");
#endif
//***********************************

	if ( p_obj != NIL )
	{
		if ( GetObjectBase(m,p_obj) == NULL )
		{
			MMset( m, 0, NIL );
			MMechostr(MSKTRACE,"_GETcompComboClicked: Object already destroyed.\n");
			return 0;
		}
		MMset( m, 0, MMfetch( m, GetTab( m, p_obj ), COMB_LIST ) );
		CHECK( _GETcompListClicked( m ) );
	}

//***********************************
#if DEBUG_LIB2D
MMechostr (0, "\n_GETcompComboClicked end");
#endif
//***********************************

	return 0;
}






int _SETcompComboClicked( mmachine m )
{
	int tmp_res, p_obj = MTOP( MMget( m, 1 ) );

//***********************************
#if DEBUG_LIB2D
MMechostr (0, "\n_SETcompComboClicked");
#endif
//***********************************

	if ( p_obj != NIL )
	{
		if ( GetObjectBase(m,p_obj) == NULL )
		{
			MMpull( m );
			MMset( m, 0, NIL );
			MMechostr(MSKTRACE,"_SETcompComboClicked: Object already destroyed.\n");
			return 0;
		}
		CHECK( MMpush( m, MMfetch( m, GetTab( m, p_obj ), COMB_LIST ) ) );
		INVERT( m, 0, 1 );
		CHECK( _SETcompListClicked( m ) );
	}

	MMpull( m );

//***********************************
#if DEBUG_LIB2D
MMechostr (0, "\n_SETcompComboClicked end");
#endif
//***********************************

	return 0;
}






int _SSETcompComboClicked( mmachine m )
{
	int tmp_res, p_obj = MTOP( MMget( m, 1 ) );

//***********************************
#if DEBUG_LIB2D
MMechostr (0, "\n_SSETcompComboClicked");
#endif
//***********************************

	if ( p_obj != NIL )
	{
		if ( GetObjectBase(m,p_obj) == NULL )
		{
			MMpull( m );
			MMset( m, 0, NIL );
			MMechostr(MSKTRACE,"_SSETcompComboClicked: Object already destroyed.\n");
			return 0;
		}
		CHECK( MMpush( m, MMfetch( m, GetTab( m, p_obj ), COMB_LIST ) ) );
		INVERT( m, 0, 1 );
		CHECK( _SSETcompListClicked( m ) );
	}

	MMpull( m );

//***********************************
#if DEBUG_LIB2D
MMechostr (0, "\n_SSETcompComboClicked end");
#endif
//***********************************

	return 0;
}





int _SETcompComboState( mmachine m )
{
	int tmp_res, p_obj = MTOP( MMget( m, 1 ) );

//***********************************
#if DEBUG_LIB2D
MMechostr (0, "\n_SETcompComboState");
#endif
//***********************************

	if ( p_obj != NIL )
	{
		if ( GetObjectBase(m,p_obj) == NULL )
		{
			MMpull( m );
			MMset( m, 0, NIL );
			MMechostr(MSKTRACE,"_SETcompComboState: Object already destroyed.\n");
			return 0;
		}
		CHECK( MMpush( m, MMfetch( m, GetTab( m, p_obj ), COMB_CHECK ) ) );
		INVERT( m, 0, 1 );
		CHECK( _SETcompCheckState( m ) );
	}

	MMpull( m );

//***********************************
#if DEBUG_LIB2D
MMechostr (0, "\n_SETcompComboState end");
#endif
//***********************************

	return 0;
}






int _CBcompComboClick( mmachine m )
{
//***********************************
#if DEBUG_LIB2D
MMechostr (0, "\n_CBcompComboClick");
#endif
//***********************************

	return OBJaddreflex( m, OBJNODE, RFLOBJNODE_CLICK );
}





int _CONVERTcompComboToObjNode( mmachine m )
{

//***********************************
#if DEBUG_LIB2D
MMechostr (0, "\n_CONVERTcompComboToObjNode");
#endif
//***********************************

	return 0;
}






int _CBcompComboResizeResource(mmachine m)
{
	// pile : CompCombo fun1 p1 fun2 p2 fun3 p3
	int p_obj,tmp_res;

//***********************************
#if DEBUG_LIB2D
MMechostr (0, "\n_CBcompComboResizeResource");
#endif
//***********************************

	if ((p_obj=MTOP(MMget(m,6)))==NIL)
	{
		MMechostr(1,"_CBcompComboResizeResource: CompCombo is nil\n");
		m->pp += 6;
		MMset(m,0,NIL);
	}
	else if (GetObjectBase(m,p_obj)==NULL)
	{
		MMechostr(1,"_CBcompComboResizeResource: CompCombo already destroyed\n");
		m->pp += 6;
		MMset(m,0,NIL);
	}
	else
	{
		// pile  CompCombo fun1 p1 fun2 p2 fun3 p3
		int p_tab=GetTab(m,p_obj);
		CHECK(MMpush(m,MMfetch(m,p_tab,COMB_LIST)));
		INVERT(m,0,1);
		INVERT(m,1,2);
		// pile CompCombo fun1 p1 slb2 fun2 p2 list fun3 p3
		CHECK(_CBcompListResizeResource(m));
		MMpull(m);

		//pile CompCombo fun1 p1 fun2 p2
		p_tab=GetTab(m,MTOP(MMget(m,4)));
		CHECK(MMpush(m,MMfetch(m,p_tab,COMB_BMP)));
		INVERT(m,0,1);
		INVERT(m,1,2);
		CHECK(_CBcompBitmapResizeResource(m));
		MMpull(m);
		
		//pile CompCombo fun1 p1
		p_tab=GetTab(m,MTOP(MMget(m,2)));
		CHECK(MMpush(m,MMfetch(m,p_tab,COMB_CHECK)));
		INVERT(m,0,1);
		INVERT(m,1,2);
		CHECK(_CBcompCheckResizeResource(m));
		MMpull(m);

		//pile CompCombo
	}


//***********************************
#if DEBUG_LIB2D
MMechostr (0, "\n_CBcompComboResizeResource end");
#endif
//***********************************

	return 0;
}










int _CBcompComboResize(mmachine m)
{
	// pile : CompCombo fun1 p1 fun2 p2 fun3 p3 fun4 u4 fun5 p5
	int p_obj,tmp_res;


//***********************************
#if DEBUG_LIB2D
MMechostr (0, "\n_CBcompComboResize");
#endif
//***********************************

	if ((p_obj=MTOP(MMget(m,10)))==NIL)
	{
		MMechostr(1,"_CBcompComboResizeResource: CompCombo is nil\n");
		m->pp += 10;
		MMset(m,0,NIL);
	}
	else if (GetObjectBase(m,p_obj)==NULL)
	{
		MMechostr(1,"_CBcompComboResizeResource: CompCombo already destroyed\n");
		m->pp += 10;
		MMset(m,0,NIL);
	}
	else
	{
		// pile  CompCombo fun1 p1 fun2 p2 fun3 p3 fun4 p4 fun5 p5
		int p_tab=GetTab(m,p_obj);
		CHECK(MMpush(m,MMfetch(m,p_tab,COMB_LIST)));
		INVERT(m,0,1);
		INVERT(m,1,2);
		INVERT(m,2,3);
		INVERT(m,3,4);
		CHECK(_CBcompListResize(m));
		MMpull(m);

		
		// pile  CompCombo fun1 p1 fun2 p2 fun3 p3
		p_tab=GetTab(m,MTOP(MMget(m,6)));
		CHECK(MMpush(m,MMfetch(m,p_tab,COMB_BMP)));
		INVERT(m,0,1);
		INVERT(m,1,2);
		CHECK(_CBcompBitmapResize(m));
		MMpull(m);
				
		//pile CompCombo fun1 p1 fun2 p2		
		p_tab=GetTab(m,MTOP(MMget(m,4)));
		CHECK(MMpush(m,MMfetch(m,p_tab,COMB_CHECK)));
		INVERT(m,0,1);
		INVERT(m,1,2);
		CHECK(_CBcompCheckResize(m));
		MMpull(m);
		
		//pile CompCombo fun1 p1
		p_tab=GetTab(m,MTOP(MMget(m,2)));
		CHECK(MMpush(m,MMfetch(m,p_tab,COMB_TEXT)));
		INVERT(m,0,1);
		INVERT(m,1,2);
		CHECK(MMpush(m,NIL));
		CHECK(MMpush(m,NIL));
		CHECK(MMpush(m,NIL));
		CHECK(MMpush(m,NIL));
		
		// pile CompCombo txt fun1 p1 nil nil nil nil
		CHECK(_CBcompTextResize(m));
		MMpull(m);

		//pile CompCombo
	}

//***********************************
#if DEBUG_LIB2D
MMechostr (0, "\n_CBcompComboResize end");
#endif
//***********************************

	return 0;
}