/*********************************************/
/*                                           */
/* combo.c                                   */
/*                                           */
/* combo box management                      */
/*                                           */
/*********************************************/

#include "x/scolplugin.h"
#include "x/version.h"

#include <stdio.h>
#include <string.h>

#include "tests.h"
#include "objects/font.h"



#include "objstr.h"
   

//WNDPROC ComboProc = NULL ;

   
/****************************************************************************************/
/*                                                                                      */
/* HWND NewObjComboBox ( PtrObjCombo Cb , char * Name , HWND Parent )                   */
/*                                                                                      */
/* Cree un nouveau combo box a partir de sa description contenu dans la structure       */
/* PtrObjCombo                                                                          */
/*                                                                                      */
/****************************************************************************************/

HWND NewObjComboBox ( PtrObjCombo Cb , char * Name , HWND Parent , int Dialog )
{
    int Flags , FF ;
    int Ex_Flag =  0 ;

    Flags = CBS_HASSTRINGS | WS_VSCROLL ; FF = Cb->Flags  ;
    
    if ( Parent != NULL ) Flags |= WS_CHILD ;
    if (( Flags & CB_TABFOCUS ) && Dialog ) Flags |= WS_TABSTOP ;
    if ( Flags & CB_DOWN ) Ex_Flag |= WS_EX_CLIENTEDGE ;


    if ( FF & CB_NOEDIT ) Flags |= CBS_DROPDOWNLIST ; else Flags |= CBS_DROPDOWN ;
    
    if ( FF & CB_AHSCROLL ) Flags |= CBS_AUTOHSCROLL ;
    if ( FF & CB_SORT ) Flags |= CBS_SORT ;

    return CreateWindowEx ( Ex_Flag , "combobox" , Name , Flags ,
                        Cb->PosX , Cb->PosY  ,
                        Cb->TailleW , Cb->TailleH ,
                        Parent , NULL ,
                        (HINSTANCE)SCgetExtra("this_inst") , NULL );
}


/*****************************************************************************/
/*                                                                           */
/* int GRCreateComboBox ( mmachine m )                                       */
/*                                                                           */
/* correspond a la fonction magma Obj _create_combo_box (Obj Parent , I PosX */
/*  I PosY , I TailleW , I TailleH , I Flag , I Handler , S Name )           */
/*                                                                           */
/*****************************************************************************/

int GRCreateComboBox ( mmachine m )
{
   int s , s2 , l , dummy , res ;
   int dialog = 0 ;
   PtrObjVoid O , OP ;
   PtrObjCombo Cb ;
   PtrObjWindow PW ;
   HWND Parent , HW ;
   char Name [1024 ] ;


   /**************************** DEBUG 2D *********************************/
    #ifdef TRACE2D
        MMechostr( 1 , "DBG _create_combo_box\n" ) ;
        FDebug2D ( m ) ;
    #endif
    /************************************************************************/

    /* test channel NIL */
    if (MMget(m,7)==NIL)
    {
        MMechostr(MSKDEBUG,"_CRcombo : channel NIL\n");
        m->pp+=7;
        return 0;
    }

    /* test parent NIL */
    if ( MMget(m,6)==NIL)
    {
        MMechostr(MSKDEBUG,"_CRcombo : parent NIL\n");
        m->pp+=7;
        MMset(m,0,NIL);
        return 0;
    }

   /* saisie le libelle du check box */  
   dummy = MMpull(m) ;
   if ( dummy == NIL ) strcpy ( Name , "" ) ; else
   strcpy ( Name , ( char * ) MMstart(m, ( dummy >>1) + 1) ) ;

    l = ( sizeof ( struct ObjVoid ) + 3 ) >> 2 ;
    s = MMmallocCLR (m,l,TYPETAB) ;
    if ( s == NIL ) return MERRMEM ;
    if ( MMpush(m,(s<<1)+1)) return MERRMEM ;
    l = ( sizeof ( struct ObjCombo ) + 3 ) >> 2 ;
    s2 = MMmalloc ( m,l,TYPEBUF ) ;
    if ( s2 == NIL ) return MERRMEM ;
    s = MMpull(m) ;

    O = ( PtrObjVoid ) MMstart(m, (s>>1) ) ;
    Cb = ( PtrObjCombo ) MMstart(m, s2 ) ;
    O->Type = OBJ_TYPE_COMBO_BOX << 1 ;
    O->Buffer = ( s2 << 1 ) + 1 ;
    O->Tab = NIL ;    
    Cb->Flags = MMpull(m) >> 1 ;
    Cb->TailleH = MMpull(m) >> 1 ;
    Cb->TailleW = MMpull(m) >> 1 ;  
    Cb->PosY = MMpull(m) >> 1 ;
    Cb->PosX = MMpull(m) >> 1 ;
    O->Father = MMpull(m) ;

    /* recuperation du handler window du parent, si parent il y a */
    if ( O -> Father == NIL ) Parent = NULL ;
    else
    {
        OP = ( PtrObjVoid ) MMstart(m, (O->Father>>1) ) ;
        if ( OP->Type != OBJ_TYPE_WINDOW << 1 )
        {
            MMechostr ( 1 , "CreateComboBox : Parent is'nt a window\n" ) ;
			MMpull(m);
            return MMpush(m,NIL) ;
        }
        PW = ( PtrObjWindow ) MMstart(m, (OP->Buffer >> 1 ) ) ;
        if ( PW->Flags & WN_DIALOG ) dialog = 1 ;
        Parent = PW->WHandler ;
    }

    HW = NewObjComboBox ( Cb , Name , Parent , dialog ) ;    
    if ( ! HW )
    {
        MMechostr(MSKDEBUG,"_create_combo_box : Error in creating the WIN Object : Check the values\n" ) ;
		MMpull(m);
        return MMpush(m,NIL) ;
    }
    Cb->WHandler = HW ; 
 
    if ( DefaultFont != NULL ) 
      SendMessage ( HW , WM_SETFONT , ( WPARAM ) DefaultFont , ( LPARAM ) TRUE ) ;      

    ShowWindow(HW,SW_SHOW);
    UpdateWindow(HW);             
    MMpush ( m , s ) ;   
    res = OBJcreate ( m , OBJTYPCOMBOBOX,(int)HW,OBJTYPWINDOW,(int)Parent) ;

    /******************************* DEBUG 2D ********************/
    #ifdef TRACE2D
        FDebug2D ( m ) ;
        MMechostr( 1 , "DBG _create_combo_box\n" ) ;
    #endif
    /***************************************************************/

    return res ;


}           


/*****************************************************************************/
/*                                                                           */
/* int GRAddComboItem ( mmachine m ) ;                                       */
/*                                                                           */
/* correspond a la fonction magma Obj _add_combo_item ( Obj , S )            */
/* laquelle ajoute un element a une combo box                                */
/*                                                                           */
/*****************************************************************************/

int GRAddComboItem ( mmachine m )
{
    PtrObjVoid O ;
    PtrObjCombo Cb ;
    int res , s , pos ;
    char Item [ 33000 ] ;

    /*********************** DEBUG 2D ****************************/
    #ifdef TRACE2D
        MMechostr( 1 , "DBG_add_combo_item\n" ) ;
        FDebug2D ( m ) ;
    #endif
    /**************************************************************/
    
    s = MMpull (m ) ;
    if ( s != NIL ) strcpy ( Item , ( char * ) MMstart(m, (s>>1)+1)) ;
    else strcpy ( Item , "" ) ;
    pos = MMpull ( m ) ;
    s = MMpull(m) ;
    if( s == NIL )
    {
        MMechostr ( 1 , "AddComboItem : Combo Box is NIL\n" ) ;
        return MMpush(m,NIL) ;
    }
    O = ( PtrObjVoid ) MMstart(m, (s>>1)) ;
    Cb = ( PtrObjCombo ) MMstart(m, ( O->Buffer>>1) ) ;

    if (O->Type  != OBJ_TYPE_COMBO_BOX << 1)
    {
        MMechostr ( 1 , "AddComboItem : It is not a combo box\n" ) ;
        return MMpush(m,s) ;
    }

    res = SendMessage (Cb->WHandler , CB_GETCOUNT , 0 , 0 ) ;
    if ( pos >= res ) pos = -1 ;
    res = SendMessage(Cb->WHandler , CB_INSERTSTRING , pos ,( LPARAM ) Item ) ;
    if (( res == CB_ERR ) || ( res == CB_ERRSPACE )) res =  MMpush (m,NIL) ;
    else res = MMpush(m,s) ;

    /******************** DEBUG 2D *************************/
    #ifdef TRACE2D
        FDebug2D (m ) ; 
        MMechostr(  1 , "DBG _ add_combo_item done\n" ) ;
    #endif
    /*********************************************************/

    return res ;

}

/*****************************************************************************/
/*                                                                           */
/* int GRDelComboItem ( mmachine m )                                         */
/*                                                                           */
/* correspond a la fonction magma Obj _del_combo_item ( Obj , I )            */
/* laquelle enleve un element de la combo box                                */
/*                                                                           */
/*****************************************************************************/

int GRDelComboItem ( mmachine m ) 
{
    PtrObjVoid O ;
    PtrObjCombo Cb ;
    int res , E , s ;    

    /********************* DEBUG 2D **********************/
    #ifdef TRACE2D
        MMechostr( 1 , "DBG _del_combo_item\n" ) ;
        FDebug2D ( m ) ;
    #endif
    /*****************************************************/

    E = MMpull(m)>>1;
    s = MMpull(m) ;
    if ( s == NIL )
    {
        MMechostr ( 1 , "DelComboItem : combo Box is NIL\n" ) ;
        return MMpush(m,NIL) ;
    }
    O = ( PtrObjVoid ) MMstart(m, (s>>1)) ;    
    Cb = ( PtrObjCombo ) MMstart(m, (O->Buffer>>1)) ;
    SendMessage(Cb->WHandler,CB_DELETESTRING , E , 0 ) ;          
    res = MMpush(m,s) ;

    /************************** DEBUG 2D *******************/
    #ifdef TRACE2D
        FDebug2D ( m );
        MMechostr(  1 , "DBG _del_combo_item\n" ) ;
    #endif
    /**********************************************************/

    return res ;
}

/******************************************************************************/
/*                                                                            */
/*  int GRDelComboString  ( mmachine m )                                      */
/*                                                                            */
/*  correspond a la fonction magma ObjBox _del_combo_string ( mmachine m )    */
/*  laquelle detruit un element d'une combo box dont on passe le texte        */
/*                                                                            */
/******************************************************************************/

int GRDelComboString ( mmachine m )
{
    PtrObjVoid O ;
    PtrObjCombo Cb ;
    int res , E , s ;    
    char * Element ;

    /********************* DEBUG 2D **********************/
    #ifdef TRACE2D
        MMechostr( 1 , "DBG _del_combo_string\n" ) ;
        FDebug2D ( m ) ;
    #endif
    /*****************************************************/

    E = MMpull(m);
    s = MMpull(m) ;
    if ( s == NIL )
    {
        MMechostr ( 1 , "DelComboString : combo Box is NIL\n" ) ;
        return MMpush(m,NIL) ;
    }
    if ( E != NIL )
    {
        Element = ( char * ) MMstart(m,(E>>1) + 1) ;
        O = ( PtrObjVoid ) MMstart(m, (s>>1)) ;
        Cb = ( PtrObjCombo ) MMstart(m, (O->Buffer>>1)) ;
        E = SendMessage ( Cb->WHandler , CB_FINDSTRINGEXACT,( WPARAM ) -1,(LPARAM)Element) ;
        if ( E != CB_ERR ) SendMessage(Cb->WHandler,CB_DELETESTRING , E , 0 ) ;   
    }
           
    res = MMpush(m,s) ;

    /************************** DEBUG 2D *******************/
    #ifdef TRACE2D
        FDebug2D ( m );
        MMechostr(  1 , "DBG _del_combo_item\n" ) ;
    #endif
    /**********************************************************/

    return res ;
}

/*****************************************************************************/
/*                                                                           */
/*  GRGetComboPosition ( mmachine m ) ;                                      */
/*                                                                           */
/*  correspond a la fonction magma I _POScombo ( ObjBox, S ) ;               */
/*  laquelle retourne la position dans la combo box d'un message             */
/*                                                                           */
/*****************************************************************************/

int GRGetComboPosition ( mmachine m )
{
PtrObjVoid O ;
    PtrObjCombo Cb ;
    int res , E , s ;    
    char * Element ;

    /********************* DEBUG 2D **********************/
    #ifdef TRACE2D
        MMechostr( 1 , "DBG _del_combo_string\n" ) ;
        FDebug2D ( m ) ;
    #endif
    /*****************************************************/

    E = MMpull(m);
    s = MMpull(m) ;
    if ( s == NIL )
    {
        MMechostr ( 1 , "DelComboString : combo Box is NIL\n" ) ;
        return MMpush(m,NIL) ;
    }
    if ( E != NIL )
    {
        Element = ( char * ) MMstart(m,(E>>1) + 1) ;
        O = ( PtrObjVoid ) MMstart(m, (s>>1)) ;
        Cb = ( PtrObjCombo ) MMstart(m, (O->Buffer>>1)) ;
        E = SendMessage ( Cb->WHandler , CB_FINDSTRINGEXACT,( WPARAM ) -1,(LPARAM)Element) ;
        if ( E != CB_ERR ) res = MMpush(m,E<<1) ; else res = MMpush ( m,NIL ) ;
    } else res = MMpush(m,NIL) ;

    /************************** DEBUG 2D *******************/
    #ifdef TRACE2D
        FDebug2D ( m );
        MMechostr(  1 , "DBG _del_combo_item\n" ) ;
    #endif
    /**********************************************************/

    return res ;
}

/*****************************************************************************/
/*                                                                           */
/* int GRGetComboCount ( mmachine m ) ;                                      */
/*                                                                           */
/* correspond a la fonction magma int _get_combo_count ( Obj )               */
/* laquelle retourne le nombre d'element deja present dans la combo box      */
/*                                                                           */
/*****************************************************************************/

int GRGetComboCount ( mmachine m )
{
    PtrObjVoid O ;
    PtrObjCombo Cb ;
    int res , s ;

    /**************************** DEBUG 2D **********************/
    #ifdef TRACE2D
        MMechostr( 1 , "DBG _get_combo_count\n" ) ;
        FDebug2D( m ) ;
    #endif
    /***************************************************************/

    s = MMpull(m) ;
    if ( s == NIL )
    {
        MMechostr ( 1 , "GetComboCount : Combo Box is NIL\n" ) ;
        return MMpush(m,NIL) ;
    }
    O = ( PtrObjVoid ) MMstart(m, (s>>1)) ;
    if ( O->Type != OBJ_TYPE_COMBO_BOX << 1 )
    {
        MMechostr ( 1, "GetComboCount : The object is not a combo box\n" ) ;
        return MMpush(m,s) ;
    }
    Cb = ( PtrObjCombo ) MMstart(m, (O->Buffer>>1) ) ;

    res = SendMessage(Cb->WHandler,CB_GETCOUNT,0,0) ;
    if ( res == CB_ERR ) res = MMpush(m,(-1)<<1);
    else res = MMpush(m,res<<1) ;

    /*********************** DEBUG 2D **************************/
    #ifdef TRACE2D
        FDebug2D(m);
        MMechostr  ( 1 , "DBG _get_combo_count done\n" ) ;
    #endif
    /************************************************************/
	return 0;

}

/*****************************************************************************/
/*                                                                           */
/* int GRResetCombo ( mmachine m ) ;                                         */
/*                                                                           */
/* corespond ala fonction magma Obj _reset_combo ( Obj )                     */
/* laquelle vide une combo box de tout ses elements                          */
/*                                                                           */
/*****************************************************************************/

int GRResetCombo ( mmachine m )
{
    PtrObjVoid O ;
    PtrObjCombo  Cb ;
    int s , res;

    /************************* DEBUG 2D **************************/
    #ifdef TRACE2D
        MMechostr( 1 , "DBG _reset_combo\n" ) ;
        FDebug2D( m ) ;
    #endif
    /***************************************************************/

    s = MMpull(m) ;
    if ( s == NIL )
    {
        MMechostr ( 1 , "ResetCombo : Combo Box is NIL\n" ) ;
        return MMpush(m,NIL) ;
    }
    O = ( PtrObjVoid ) MMstart(m, (s>>1)) ;
    if ( O->Type != OBJ_TYPE_COMBO_BOX << 1 )
    {
        MMechostr ( 1 , "ResetCombo : the object is not a combo box\n" ) ;
        return MMpush(m,s) ;
    }
    Cb = ( PtrObjCombo ) MMstart(m, (O->Buffer>>1)) ;

    SendMessage (Cb->WHandler,CB_RESETCONTENT,0,0) ;
    res = MMpush(m,s) ;

    /************************ DEBUG 2D ***************************/
    #ifdef TRACE2D
        FDebug2D( m ) ;
        MMechostr ( 1 , "DBG _reset_combo done\n" ) ;
    #endif      
    /*************************************************************/

        return res ;

}

/*****************************************************************************/
/*                                                                           */
/* int GRGetComboSelection ( mmachine m )                                    */
/*                                                                           */
/* correspond a la fonction magma int _get_combo_selection ( Obj )           */
/* laquelle retourne l'index dans la liste combo de l'element selectionne    */
/*                                                                           */
/*****************************************************************************/

int GRGetComboSelection ( mmachine m )
{
        PtrObjVoid O ;
        PtrObjCombo Cb ;
        int res , s , num ;
        char Item [ MAX_TEXT] ;

        /************************** DEBUG 2D ********************/
        #ifdef TRACE2D
            MMechostr( 1 , "DBG_get_combo_selection\n" ) ;
            FDebug2D ( m ) ;
        #endif
        /*********************************************************/

        s = MMpull(m) ;
        if ( s == NIL )
        {
            MMechostr ( 1 , "GetComboSelection : Combo Box is NIL" ) ;
            return MMpush(m,NIL) ;
        }
        O = ( PtrObjVoid ) MMstart(m, ( s>>1)) ;
        if ( O->Type != OBJ_TYPE_COMBO_BOX << 1)
        {
            MMechostr ( 1 , "GetComboSelection : The object isn't a combo box\n" ) ;
            return MMpush(m,s) ;
        }
        Cb = ( PtrObjCombo ) MMstart(m,(O->Buffer>>1)) ;

        num = SendMessage(Cb->WHandler,CB_GETCURSEL,0,0) ;
        if ( num == CB_ERR ) num = -1 ; 
        if ( MMpush(m,num<<1)) return MERRMEM ;
        res = SendMessage(Cb->WHandler , CB_GETLBTEXT , num , ( LPARAM ) Item ) ;
        if ( res == CB_ERR ) res = MMpush(m,NIL) ;
        else res = Mpushstrbloc(m,Item ) ;

        if ( MMpush(m,4)) return MERRMEM ;
        res = MBdeftab ( m );

        /************************ DEBUG 2D ****************/
        #ifdef TRACE2D
            FDebug2D ( m ) ;
            MMechostr( 1 , "DBG _get_combo_selection\n" ) ;
        #endif
        /***************************************************/

        return res ;
}        

/*****************************************************************************/
/*                                                                           */
/*  int GRGetComboItem ( mmachine m )                                        */
/*                                                                           */
/* correspond a la fonction magma S _get_combo_item ( Obj , I)               */
/* laquelle renvoie le ieme element de la combo box                          */
/*                                                                           */
/*****************************************************************************/

int GRGetComboItem ( mmachine m )
{
        PtrObjVoid O ;
        PtrObjCombo Cb ;
        int Index , res , s ;
        char Item [ MAX_TEXT ] ;

        /******************** DEBUG 2D ***********************/
        #ifdef TRACE2D
            MMechostr( 1 , "DBG _get_combo_item\n" ) ;
            FDebug2D( m ) ; 
        #endif
        /*******************************************************/

        Index = MMpull(m)>>1 ;
        s = MMpull(m) ;
        if ( s == NIL )
        {
            MMechostr ( 1 , "GetComboItem : Combo Box is NIL\n" ) ;
            return MMpush(m,NIL) ;
        }
        O = ( PtrObjVoid ) MMstart(m, (s>>1) ) ;
        if ( O->Type != OBJ_TYPE_COMBO_BOX << 1 )
        {
            MMechostr( 1 , "GetComboItem : the object isn't a combo box\n" ) ;
            return MMpush(m,NIL) ;
        }
        Cb = ( PtrObjCombo ) MMstart(m, (O->Buffer>>1)) ;

        res = SendMessage(Cb->WHandler , CB_GETLBTEXT , Index , ( LPARAM ) Item ) ;
        if ( res == CB_ERR ) res = MMpush(m,NIL) ;

        else res = Mpushstrbloc(m,Item ) ;

        /******************* DEBUG 2D *********************/
        #ifdef TRACE2D
            FDebug2D ( m ) ;
            MMechostr( 1 , "get_combo_selection done\n" ) ;
        #endif
        /***************************************************/

            return res ;

}        

/*****************************************************************************/
/*                                                                           */
/* int GRSelectCombo ( mmachine m )                                          */
/*                                                                           */
/* correspond a la fonction magma Obj _select_combo ( Obj , S )              */
/* laquelle cherche un element dans la combo liste et si le trouve, le copie */
/* dans la zone d'edition                                                    */
/*                                                                           */
/*****************************************************************************/

int GRSelectCombo ( mmachine m )
//$ SH(30/07/2001): Corrected
{
        PtrObjVoid O ;
        PtrObjCombo Cb ;
        int res , s ;
        char *Item ;
 
        /****************** DEBUG 2D ********************************/
        #ifdef TRACE2D
            MMechostr ( 1 , "DBG _select_combo\n" ) ;
            FDebug2D ( m ) ;
        #endif
        /************************************************************/
 
        Item=MMstartstr(m, MMpull(m)>>1 ) ;
        s = MMpull(m) ;
        if ( s == NIL )
        {
            MMechostr ( 1 , "SelectCombo : Combo Box is NIL\n" ) ;
            return MMpush(m,NIL) ;
        }
        O = ( PtrObjVoid ) MMstart(m,(s>>1)) ;        
        Cb = ( PtrObjCombo ) MMstart(m,(O->Buffer>>1)) ;
 
        res = SendMessage ( Cb->WHandler , CB_FINDSTRINGEXACT,( WPARAM ) -1,(LPARAM)Item) ;
        if ( res != CB_ERR ) res = SendMessage(Cb->WHandler,CB_SETCURSEL, (WPARAM ) res, ( LPARAM ) 0) ;
        if ( res == CB_ERR ) res = MMpush(m,NIL) ; else res = MMpush(m,s) ;
 
        /************************** DEBUG 2D ******************************/
        #ifdef TRACE2D
            FDebug2D ( m ) ;
            MMechostr( 1 , "DBG _select_combo done\n" ) ;
        #endif
        /*******************************************************************/
 
            return res ;
}

 

/*************************************************************************************/
/*                                                                                   */
/*  int GRSelectComboPosition ( mmachine m ) ;                                       */
/*                                                                                   */
/* correspond a la fonction magma ObjBox _select_combo_position ( ObjBox I Position )*/
/* laquelle selectionne un des choix de la combo box                                 */
/*                                                                                   */
/*************************************************************************************/

int GRSelectComboPosition ( mmachine m )
{
        PtrObjVoid O ;
        PtrObjCombo Cb ;
        int res , s , pos ;        

        /****************** DEBUG 2D ********************************/
        #ifdef TRACE2D
            MMechostr ( 1 , "DBG _select_combo_position\n" ) ;
            FDebug2D ( m ) ;
        #endif
        /************************************************************/

        pos = MMpull( m ) >> 1 ;
        s = MMpull(m) ;
        if ( s == NIL )
        {
            MMechostr ( 1 , "SelectCombo : Combo Box is NIL\n" ) ;
            return MMpush(m,NIL) ;
        }
        O = ( PtrObjVoid ) MMstart(m,(s>>1)) ;        
        Cb = ( PtrObjCombo ) MMstart(m,(O->Buffer>>1)) ;

        res = SendMessage(Cb->WHandler,CB_SETCURSEL, (WPARAM ) pos, ( LPARAM ) 0) ;
        if ( res == CB_ERR ) res = MMpush(m,NIL) ; else res = MMpush(m,s) ;

        /************************** DEBUG 2D ******************************/
        #ifdef TRACE2D
            FDebug2D ( m ) ;
            MMechostr( 1 , "DBG _select_combo_position done\n" ) ;
        #endif
        /*******************************************************************/

            return res ;
}




/***********************************************************************************/
/*                                                                                 */
/* int GRPaintCombo ( mmachine m );                                                */
/*                                                                                 */
/* correspond a la fonction ObjBox _paint_combo ( ObjBox )                         */
/* laquelle repeind une combo box                                                  */
/*                                                                                 */
/***********************************************************************************/

int GRPaintCombo ( mmachine m )
{
    int s ;
    PtrObjVoid  O;
    PtrObjCombo Cb ;

    /***************************** DEBUG 2D ***************************************/
    #ifdef TRACE2D
        MMechostr ( 1 , "DBG _paint_combo\n" ) ;
        FDebug2D ( m ); 
    #endif
    /********************************************************************************/

    s = MMget(m,0);
    if ( s != NIL )
    {
        O = ( PtrObjVoid ) MMstart(m, (s>>1) );
        Cb = ( PtrObjCombo ) MMstart(m, ( O->Buffer>>1)) ;
        if ( GetUpdateRect ( Cb->WHandler , NULL , TRUE ))
        {
                        InvalidateRect ( Cb->WHandler , NULL , TRUE ) ;
                        SendMessage ( Cb->WHandler , WM_PAINT , 0 , 0 ) ;
        }
    }

    /************************** DEBUG 2D **********************************************/
    #ifdef TRACE2D
        FDebug2D ( m ) ;
        MMechostr ( 1 , "DBG_paint_combo done\n" ) ;
    #endif
    /***********************************************************************************/

    return 0 ;
}

/****************************************************************************************/
/*                                                                                      */
/* int GRDestroyCombo ( mmachine m );                                                   */
/*                                                                                      */
/* correspond a la fonction i _destroy_combo ( ObjBox ) ;                               */
/* laquelle detruit une combo box                                                       */
/*                                                                                      */
/****************************************************************************************/

int GRDestroyCombo ( mmachine m )
{
    int s ;
    PtrObjVoid O ;
    PtrObjCombo Cb ;

    /************************************ DEBUG 2D ***************************************/
    #ifdef TRACE2D
        MMechostr ( 1 , "DBG _destroy_combo \n" ) ;
        FDebug2D ( m ) ;
    #endif
    /********************************************************************************/

    s = MMget(m,0 ) ;
    if ( s == NIL )
    {
        MMset(m,0,0) ;
        return  0 ;
    }

    O = ( PtrObjVoid ) MMstart(m,( s >> 1 ) ) ;
    Cb = ( PtrObjCombo ) MMstart(m,(O->Buffer>>1) ) ;

    OBJdelTH(m,OBJTYPCOMBOBOX,(int)Cb->WHandler ) ;
    MMset(m,0,0) ;

    /******************************* DEBUG 2D **************************************/
    #ifdef TRACE2D
        FDebug2D ( m ) ;
        MMechostr ( 1 , "DBG _destroy_obj\n" ) ;
    #endif
    /********************************************************************************/

    return 0 ;
}

/****************************************************************************************/
/*                                                                                      */
/*  int GRReflexComboSelect ( mmachine m ) ;                                            */
/*  Correspond a la fonction magma _CBcombo                                             */
/*                                                                                      */
/****************************************************************************************/

int GRReflexComboSelect ( mmachine m )
{    
    return OBJaddreflex (m,OBJTYPCOMBOBOX,RFLCOMBOBOX_SELECT ) ;
}

