/* -*- c++ -*- */

----------------------------------------
2012.11.28 
para evitar redraws en la ventana de togl cada vez que aparece un tooltip o un menu:
tkUnixWM:6894
static void
CreateWrapper(
    WmInfo *wmPtr)		/* Window manager information for the
				 * window. */
{
...
    wrapperPtr->atts.backing_store = Always;
    wrapperPtr->atts.save_under = True;
XCreateWindow( ..... ,
	    wrapperPtr->dirtyAtts|CWOverrideRedirect|CWSaveUnder|CWBackingStore,
	    &wrapperPtr->atts); 
...
  }

----------------------------------------

Para que GiD funcione falta:

---------------------------------------------------------------------------------------------------------------------------------------
scripts/BWidget
Some BWidget standard files have small changes to be used in RamDebugger or GiD (require BWidgetR)
Check lines marked with "RAMSAN". It's recommended to use tkdiff to see the related changes
changet widget.tcl, scrollw.tcl, mainframe.tcl,panedw.tcl and init.tcl
---------------------------------------------------------------------------------------------------------------------------------------
scripts/tcllib/commR
Is a modified version of tclib comm package, required to remotelly debug GiD from ramdebugger
Check lines marked with "RAMSAN". It's recommended to use tkdiff to see the related changes

---------------------------------------------------------------------------------------------------------------------------------------
cambios estetica fondo de botones
modificados /tk/button.tcl, dialog.tcl, scale.tcl y scrlbar.tcl, y modificada tambien tk84gid.dll

buscar tambien _TK_MIGUEL_RELIEF_ROUND_ y _TK_MIGUEL_WINDOWS_BEHAVIOUR_ en los fuentes de Tk
---------------------------------------------------------------------------------------------------------------------------------------

Makefile.vc: cambiamos el nombre de las librerias para indicar que solo
	     sirven para GiD.

TKIMPLIB	= "$(OUT_DIR)\$(PROJECT)$(VERSION)$(SUFX)gid.lib"
TKLIBNAME	= $(PROJECT)$(VERSION)$(SUFX)gid.$(EXT)

TKSTUBLIBNAME	= $(STUBPREFIX)$(VERSION)gid.lib

--------------------------------------------------------------------------------

tkWinWm.c: (soporte OpenGL en widgets Tk & icono de GiD)

     static int InitWindowClass(WinIconPtr titlebaricon)
     {
       (...);

       /* GiD */
#ifdef TCL_THREADS
       /* Cambiar: */
       /* class.style = CS_HREDRAW | CS_VREDRAW; */
       class.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC | CS_SAVEBITS;
#else
       /* Cambiar: */
       /*class.style = CS_HREDRAW | CS_VREDRAW | CS_CLASSDC;*/
       class.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC | CS_SAVEBITS;
#endif
       /* Fin GiD */

       (...);

       /* GiD */
       /* class.hIcon = LoadIcon(Tk_GetHINSTANCE(), "tk"); */
       class.hIcon = ( HICON)LoadImage( 0, "bitmaps\\gid.ico", IMAGE_ICON, 0, 0,
			LR_DEFAULTCOLOR | LR_DEFAULTSIZE | LR_LOADFROMFILE);
       if ( !class.hIcon) {
	 /* si no se pone el icono gid.ico ni se modifica el tk_base.rc esto no hace falta: */
	 class.hIcon = LoadIcon(Tk_GetHINSTANCE(), "gid"); /* opcional */
	 if ( !class.hIcon) {
	   class.hIcon = LoadIcon(Tk_GetHINSTANCE(), "tk");
	 }
       }
       /* Fin GiD */

       (...);
     }

--------------------------------------------------------------------------------

    (opcional) Copiar $GID/bitmaps/GiD.ico a $TK_SRC_DIR/win/rc

Tk_base.rc: (opcional)

     //
     //  Tk Icon
     //

     tk                      ICON    DISCARDABLE     "tk.ico"
     // GiD
     gid                     ICON    DISCARDABLE     "GiD.ico"
     // Fin GiD

--------------------------------------------------------------------------------

tkWinX.c: (soporte OpenGL en widgets Tk)

     void TkWinXInit(hInstance)
     HINSTANCE hInstance;
     {
       (...);
	
       /* GiD */
#ifdef TCL_THREADS
       /* Cambiar: */
       /* childClass.style = CS_HREDRAW | CS_VREDRAW; */
       childClass.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC | CS_SAVEBITS;
#else
       /* Cambiar: */
       /* childClass.style = CS_HREDRAW | CS_VREDRAW | CS_CLASSDC; */
       childClass.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC | CS_SAVEBITS;
#endif
       /* Fin GiD */

       (...);
     }


--------------------------------------------------------------------------------

tkWinX.c: (soporte SpaceBall)

     /* GiD */
     static void GenerateXClientEvent _ANSI_ARGS_((HWND hwnd, UINT message,
						   WPARAM wParam, LPARAM lParam))
     HWND hwnd;
     UINT message;
     WPARAM wParam;
     LPARAM lParam;
     {
       XEvent event;
       TkWindow *winPtr = (TkWindow *)Tk_HWNDToWindow(hwnd);

       if (!winPtr || winPtr->window == None) {
	 return;
       }

       event.xany.serial = winPtr->display->request++;
       event.xany.send_event = False;
       event.xany.display = winPtr->display;
       event.xany.window = winPtr->window;

       event.type=ClientMessage;
       event.xclient.message_type =
	 Tk_InternAtom((Tk_Window) winPtr, "WINDOW_EVENTS");
       event.xclient.format = 32;
       event.xclient.data.l[0]=message;
       event.xclient.data.l[1]=wParam;
       event.xclient.data.l[2]=lParam;
    	
       Tk_QueueWindowEvent(&event, TCL_QUEUE_TAIL);
     }
     /* Fin GiD */

     int Tk_TranslateWinEvent(hwnd, message, wParam, lParam, resultPtr)
     {
       (...);

       switch (message) {
       (...);
       /* GiD */
       default:
	 if ( message >= WM_USER) {
	   GenerateXClientEvent( hwnd, message, wParam, lParam);
	   return 1;
	 }
       /* Fin GiD */
       }

       (...);
     }

--------------------------------------------------------------------------------

tkWinMenu.c: (para respetar el ancho de los iconos en los menus con solo iconos)

     int
     TkWinHandleMenuEvent(phwnd, pMessage, pwParam, plParam, plResult)
     	 HWND *phwnd;
     	 UINT *pMessage;
     	 WPARAM *pwParam;
     	 LPARAM *plParam;
     	 LRESULT *plResult;
     {

       (...);

       case WM_MEASUREITEM: {
	 (...);

	 if (mePtr->hideMargin) {
	   /* itemPtr->itemWidth += 2 - indicatorDimensions[1]; */
	   /* GiD 26.3.2003: do not hide too much */
	   itemPtr->itemWidth += 2 - indicatorDimensions[1] / 2;
	   /* Fin GiD */
	 } else {
	   (...);
	 }

	 (...);
       }
     }


--------------------------------------------------------------------------------
     Obsoletos:
--------------------------------------------------------------------------------

 Obsoleta?
tkWinMenu.c: (para acceder a menus con alt+letra con caracteres multibyte)

//kike: instead label[underline] must use *Tcl_UtfAtIndex(label, underline)

int
TkWinHandleMenuEvent(phwnd, pMessage, pwParam, plParam, plResult)
...
		    if ((-1 != underline)
			    && (NULL != menuPtr->entries[i]->labelPtr)
			    && (CharUpper((LPTSTR) menuChar)
			    == CharUpper((LPTSTR) (unsigned char)
                            *(Tcl_UtfAtIndex(label, underline))
                            ))) {


--------------------------------------------------------------------------------

tkWinMenu.c: (para desactivar la animacion Windos de imagenes de menus, que hace que se dibujen desplazadas corruptas)

int
TkpPostMenu(interp, menuPtr, x, y)
    Tcl_Interp *interp;
    TkMenu *menuPtr;
    int x;
    int y;
{
    //kike: trick to disable menu animation (which shows images wrong)
    int i;
    TkMenuEntry *mePtr;
    //kike: end trick
    ...
    //kike: trick to disable menu animation (which shows images wrong)
    //no cascade handle
    for (i = 0; i < menuPtr->numEntries; i++) {
      mePtr = menuPtr->entries[i];
      if ( ( mePtr->image != NULL) || \
	   ( mePtr->bitmapPtr != NULL) || \
	   ( mePtr->compound != COMPOUND_NONE)) {
        flags |= 0x4000L /*TPM_NOANIMATION*/;
        break;
      }
    }
    //kike: end trick

    TrackPopupMenu(winMenuHdl, flags, x, y, 0,
	    tsdPtr->menuHWND, &noGoawayRect);
    ...

--------------------------------------------------------------------------------

tkWinCursor.c

Cambiar la funcion TkGetCursorByName a:

TkCursor *
TkGetCursorByName(interp, tkwin, string)
    Tcl_Interp *interp;		/* Interpreter to use for error reporting. */
    Tk_Window tkwin;		/* Window in which cursor will be used. */
    Tk_Uid string;		/* Description of cursor.  See manual entry
				 * for details on legal syntax. */
{
    struct CursorName *namePtr;
    TkWinCursor *cursorPtr;

    /*
     * Check for the cursor in the system cursor set.
     */

    for (namePtr = cursorNames; namePtr->name != NULL; namePtr++) {
	if (strcmp(namePtr->name, string) == 0) {
	    break;
	}
    }

    cursorPtr = (TkWinCursor *) ckalloc(sizeof(TkWinCursor));
    cursorPtr->info.cursor = (Tk_Cursor) cursorPtr;
    cursorPtr->winCursor = NULL;
    if (namePtr->name != NULL) {
	cursorPtr->winCursor = LoadCursor(NULL, namePtr->id);
	cursorPtr->system = 1;
    }
    if (cursorPtr->winCursor == NULL) {
	cursorPtr->winCursor = LoadCursor(Tk_GetHINSTANCE(), string);
	cursorPtr->system = 0;
    }
    /* RAMSAN adding */
    if (string[0] == '@') {
      int argc;
      char **argv = NULL;
      Tcl_DString bufferPtr;
      char* filename;
      if (Tcl_SplitList(interp, &string[1], &argc, &argv) != TCL_OK) {
	return NULL;
      }
      if (argc != 1) {
	ckfree((char *)cursorPtr);
	Tcl_Free((char *) argv);
	Tcl_AppendResult(interp, "bad cursor spec \"", string, "\"",
			 (char *) NULL);
	return NULL;
      }
      if (Tcl_IsSafe(interp)) {
	Tcl_AppendResult(interp, "can't get cursor from a file in",
			 " a safe interpreter", (char *) NULL);
	ckfree((char *)cursorPtr);
	Tcl_Free((char *) argv);
	return NULL;
      }
      filename=Tcl_TranslateFileName(interp,argv[0], &bufferPtr);
      if(!filename){
	ckfree((char *)cursorPtr);
	Tcl_Free((char *) argv);
	return NULL;
      }
      cursorPtr->winCursor = LoadCursorFromFile(filename);
      cursorPtr->system = 0;
      Tcl_DStringFree(&bufferPtr) ;
      Tcl_Free((char *) argv);
    }
    /* end RAMSAN adding */
    if (cursorPtr->winCursor == NULL) {
	ckfree((char *)cursorPtr);
	Tcl_AppendResult(interp, "bad cursor spec \"", string, "\"",
		(char *) NULL);
	return NULL;
    } else {
	return (TkCursor *) cursorPtr;
    }
}

-----------------------------------------------------------------------

tkWinButton.c

en la funcin TkpComputeButtonGeometry aadir:

TkpComputeButtonGeometry(butPtr)
    register TkButton *butPtr;	/* Button whose geometry may have changed. */
{
/*   RAMSAN change */
  int quitar = 0;

   .....

  if (butPtr->type != TYPE_LABEL) {
	    butPtr->inset += 3;
	    quitar = 3;
  }

   .....

Tk_GeometryRequest(butPtr->tkwin, (int) (width + butPtr->indicatorSpace
	    + 2*butPtr->inset), (int) (height + 2*butPtr->inset - quitar));

----------------------------------------------------------------------

tkWinMain.c --- para quitar los espacios en blanco a la izquierda
                de las entradas de menu ( no es mas que espacio reservado
                para los checckbutton)

en la funcion TkWinHandleMenuEvent
(l 1049)
cambiar   itemPtr->itemWidth += 2 - indicatorDimensions[1];
por 	  itemPtr->itemWidth += 2 - indicatorDimensions[1] / 2;

en la funcion GetMenuIndicatorGeometry
(l 1301)
cambiar toda la rutina por:

  /* miguel 26.3.2003: if there is no checkbox, do not compute the space */
  if ((mePtr->type == CHECK_BUTTON_ENTRY)
      || (mePtr->type == RADIO_BUTTON_ENTRY)) {

    if (mePtr->hideMargin || !mePtr->indicatorOn) {
      int borderWidth;

      Tk_GetPixelsFromObj(menuPtr->interp, menuPtr->tkwin,
			  menuPtr->borderWidthPtr, &borderWidth);
      *heightPtr = 0;
      *widthPtr = borderWidth;
    } else {
      int borderWidth;

      Tk_GetPixelsFromObj(menuPtr->interp, menuPtr->tkwin,
			  menuPtr->borderWidthPtr, &borderWidth);
      *heightPtr = indicatorDimensions[0];
      *widthPtr = indicatorDimensions[1] - borderWidth;
    }
  } else {
    int borderWidth;

    Tk_GetPixelsFromObj(menuPtr->interp, menuPtr->tkwin,
			menuPtr->borderWidthPtr, &borderWidth);
    *heightPtr = 0;
    *widthPtr = borderWidth;
  }
  /* end miguel */



----------------------------------------------------------------------
