/***********************************************************************************************/ 
/*                                                                                             */ 
/*         tooltip.c                                                                           */ 
/*                                                                                             */ 
/***********************************************************************************************/ 




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


HWND ToolTip = NULL ;


/****************************************************************************/ 
/*                                                                          */ 
/*  int GRToolTip ( mmachine m )                                            */ 
/*                                                                          */ 
/*   correspond aux fonction _TIPxxx ( Obj, S, I, I, I, I )-> Obj           */ 
/*  qui affecte une fenetre tool tip a un objet                             */ 
/*                                                                          */ 
/****************************************************************************/ 

int GRToolTip ( mmachine m )
{
    int s  ; 
    char * tip ;
    TOOLINFO Ti ;
    PtrObjVoid O ;
    HWND H ;

//***********************************
#if DEBUG_LIB2DOS
MMechostr (0, "\nGRToolTip");
#endif
//***********************************




    s  = MMpull(m)    ;
    tip = ( char * ) ( MMstart(m,(s>>1)+1)) ;

    if ( strlen ( tip ) > 999 )
    {
        MMechostr (1 ,"(ERROR) _TIPxxxx : String too long.\n") ;
        return 0 ;
    }

    s = MMpull ( m ) ;

    if ( s != NIL )
    {
        InitCommonControls();

        if (ToolTip == NULL )
            ToolTip = CreateWindow(TOOLTIPS_CLASS, (LPSTR) NULL, TTS_ALWAYSTIP, 
                CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, 
                NULL, (HMENU) NULL, (HINSTANCE)SCgetExtra("this_inst"), NULL); 

        O = ( PtrObjVoid ) MMstart(m,(s>>1)) ;
        switch (O->Type  >> 1  )
        {
            case OBJ_TYPE_PUSHBUTTON :
                H = (( PtrObjButton ) ( MMstart(m,(O->Buffer>>1))))->WHandler ;
                break ;
            default : H = NULL ;
        }

        if ( H == NULL ) MMechostr (1,"(ERROR) _TIPxxxx : Handler NULL\n");

        Ti.cbSize = sizeof ( TOOLINFO ) ;
        Ti.uFlags = TTF_SUBCLASS ;
        Ti.hinst = (HINSTANCE)SCgetExtra("this_inst") ;
        Ti.hwnd =  H  ;
        Ti.uId = ( unsigned int ) 0 ;
        Ti.lpszText = strdup ( tip ) ;
        Ti.rect.left = 0 ;
        Ti.rect.top  = 0 ;
        Ti.rect.right = 100 ;
        Ti.rect.bottom = 100 ;

        if (!SendMessage(ToolTip, TTM_ADDTOOL, 0, (LPARAM) (LPTOOLINFO) &Ti)) 
            MMechostr (1,"(ERROR) _TIPxxx : Add Tip failed\n");       

    }

    s = MMpush(m,s ) ;
    
//***********************************
#if DEBUG_LIB2DOS
MMechostr (0, "\nGRToolTip end");
#endif
//***********************************

    return s ;

        
}