home *** CD-ROM | disk | FTP | other *** search
/ PC Media 23 / PC MEDIA CD23.iso / share / prog / anubis / texto2.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-02-11  |  37.4 KB  |  1,151 lines

  1. //      ╔═════════════════════════════════════════════════════════════╗
  2. //      ║                      ┌──────────┐                           ║
  3. //      ║                      │ TEXTO2.H │                           ║
  4. //      ║                      └──────────┘                           ║
  5. //      ║  (C) Anubis Software Junio 1995                             ║
  6. //      ║                                                             ║
  7. //      ║  Esta librería, pretende mejorar la librería TEXTO1.h       ║
  8. //      ║  aplicando los nuevos conocimientos adquiridos sobre el     ║
  9. //      ║  tema.                                                      ║
  10. //      ║                                                             ║
  11. //      ╚═════════════════════════════════════════════════════════════╝
  12.  
  13. #ifndef TEXTO2.H
  14. #define TEXTO2.H
  15.  
  16.  
  17. //╔═════════════════════════════════════════════════════════════╗
  18. //║ Inclusion de librerías BorlandC ++                          ║
  19. //╚═════════════════════════════════════════════════════════════╝
  20. #include <stdio.h>
  21. #include <alloc.h>
  22.  
  23.  
  24. //╔═════════════════════════════════════════════════════════════╗
  25. //║ Inclusión de librerías Anubis Software                      ║
  26. //╚═════════════════════════════════════════════════════════════╝
  27. #include "tecexec.h"
  28. #include "ventana2.h"
  29. #include "mdefs.h"
  30. #include "scancode.h"
  31. #include "tecbuf.h"
  32. #include "cadena.h"
  33. #include "listag2.h"
  34.  
  35.  
  36. //╔═════════════════════════════════════════════════════════════╗
  37. //║ Definición de constantes                                    ║
  38. //╚═════════════════════════════════════════════════════════════╝
  39. // Definición de errores de la libreria:
  40. #define TEXTO2_MEMORIA_INSUFICIENTE  10
  41. #define TEXTO2_ERROR_FICHERO         11
  42. #define TEXTO2_TODO_OK                0
  43.  
  44. // Definicion de eventos de la libreria:
  45. #define PULSAR_TECLA          0
  46.  
  47.  
  48. //╔═════════════════════════════════════════════════════════════╗
  49. //║ Definición de macros de la librería                         ║
  50. //╚═════════════════════════════════════════════════════════════╝
  51.  
  52.  
  53. //╔═════════════════════════════════════════════════════════════╗
  54. //║ Declaración de variables globales                           ║
  55. //╚═════════════════════════════════════════════════════════════╝
  56. char TabSize = 3;          // Es la longitud del tabulador.
  57. ListaGenerica2 Macros;     // Es la lista de macros del procesador de textos.
  58. boolean TextInsert=TRUE;        // Modo inserción = True, Sobreescribir = False.
  59.  
  60.  
  61. //╔═════════════════════════════════════════════════════════════╗
  62. //║ Definición de estructuras de la libreria                    ║
  63. //╚═════════════════════════════════════════════════════════════╝
  64. typedef struct {
  65.    int CursorX,CursorY;     // Posición del cursor en el texto. Pos inic(0,0)
  66.    int AparX,AparY;         // Posición que se ve en la Ventana.
  67.                 // esquina superior izquierda.Pos inic (0,0)
  68.    unsigned long LineaFin;            // Linea final del texto.
  69.                 // La linea a la que apunta tiene texto
  70.    unsigned int AnchoLinea;          // El ancho de la linea de texto. Más allá
  71.                 // de la cual no se puede escribir.
  72.    Ventana2 *Ventana;       // Ventana a la que pertenece el texto.
  73.    int OldX;                // Indica la posición en la que el cursor
  74.                 // quiere estar. Se usa a modo de auxiliar.
  75.    char *Texte[5000];       // De momento es lo mejor que hay
  76. } Texto2;
  77.  
  78. typedef struct  {
  79.    WORD Tecla;              // Es el código de la tecla de la macro.
  80.    char *Macro;
  81. } Macro;
  82.  
  83. //╔═════════════════════════════════════════════════════════════╗
  84. //║ Más variables globales concernientes a los bloques.         ║
  85. //╚═════════════════════════════════════════════════════════════╝
  86. Texto2 *BTexto=NULL;
  87. int BIniX=0,BIniY=1,BFinX=0,BFinY=0,BTLineaFin=-1;
  88. BYTE BColor = FCYAN;
  89. char *BArray[500];  // Este array es el trozo de texto que se copia.
  90.  
  91.  
  92.  
  93. //╔═════════════════════════════════════════════════════════════╗
  94. //║ Declaración de prototipos de la librería                    ║
  95. //╚═════════════════════════════════════════════════════════════╝
  96. void PonerLinea( Texto2 *, int, int);
  97. void PintarTexto( Texto2 *);
  98. WORD TextEvent( Texto2 *, WORD, WORD);
  99. WORD TOpen( Texto2 *, char *);
  100. WORD TSave( Texto2 *, char *);
  101. void ControlaDesplazamientos( Texto2 *);
  102.  
  103.  
  104. //╔═════════════════════════════════════════════════════════════╗
  105. //║ Implementación de procedimientos de la librería             ║
  106. //╚═════════════════════════════════════════════════════════════╝
  107.  
  108. // Esta función marca el principio de un bloque de texto
  109. //──────────────────────────────────────────────────────
  110. void TBInicio(void)
  111. {
  112.    if(TopeVentanas->TipoVentana == V_TEXTO)  {
  113.       if(BTexto != TopeVentanas->Apuntador)  {
  114.      BFinY=-1;
  115.      if(BTexto != NULL)
  116.         PintarTexto(BTexto);
  117.       }// end if
  118.       BTexto = (Texto2 *) TopeVentanas->Apuntador;
  119.       BIniX = BTexto->CursorX;
  120.       BIniY = BTexto->CursorY;
  121.       PintarTexto(BTexto);
  122.    }// end if
  123. }// end TBInicio
  124.  
  125. // Esta función marca el final de un bloque de texto.
  126. // ──────────────────────────────────────────────────
  127. void TBFin(void)
  128. {
  129.    if((Texto2 *) TopeVentanas->Apuntador == BTexto)  {
  130.       if(BTexto != TopeVentanas->Apuntador)  {
  131.      BFinY=-1;
  132.      if (BTexto != NULL)
  133.         PintarTexto(BTexto);
  134.       }// end if
  135.       BFinX = BTexto->CursorX;
  136.       BFinY = BTexto->CursorY;
  137.       PintarTexto(BTexto);
  138.    }// end if
  139. // NOTA: A esta función le falta hacer algunas serias comprobaciones.
  140. }// end TBFin
  141.  
  142. // Esta función copia un trozo de texto al buffer intermedio para bloques.
  143. // ───────────────────────────────────────────────────────────────────────
  144. void TCopiar(void)
  145. {
  146.    int i,j;
  147.    char cad[500];
  148.    char *cadena=cad;
  149.  
  150.    // Lo primero que hacemos es vaciar el buffer del teclado.
  151.    for (i=0; i<=BTLineaFin; i++);
  152.       free(BArray[i]);
  153.  
  154.    if(BIniY < BFinY)  {
  155.       // Después copiamos la primera linea de la selección.
  156.       copiar_cadena(cadena,BTexto->Texte[BIniY]);
  157.       cadena += BIniX;
  158.       BArray[0] = (char *) malloc (longitud_cadena(cadena) +2);
  159.       copiar_cadena( BArray[0],cadena);
  160.       j=BIniY +1;
  161.       i=1;
  162.       while (j<BFinY)  {
  163.      BArray[i] = (char *) malloc (longitud_cadena(BTexto->Texte[j])+2);
  164.      copiar_cadena(BArray[i],BTexto->Texte[j]);
  165.      i++;
  166.      j++;
  167.       }// end while
  168.       // Tratamos el elemento final.
  169.       cadena = cad; // Inicializamos de nuevo la cadena.
  170.       copiar_cadena(cadena,BTexto->Texte[BFinY]);
  171.       cadena[BFinX+1] = 0;
  172.       BArray[i] = (char *) malloc (longitud_cadena(cadena)+2);
  173.       copiar_cadena(BArray[i],cadena);
  174.       BTLineaFin = i;
  175.    } else if (BIniY == BFinY)  {
  176.       copiar_cadena(cadena,BTexto->Texte[BFinY]);
  177.       cadena[BFinX+1] =0;
  178.       cadena += BIniX;
  179.       BArray[0]= (char *) malloc (longitud_cadena(cadena)+2);
  180.       copiar_cadena(BArray[0],cadena);
  181.       BTLineaFin =0;
  182.    }// end if
  183. }// end TCopiar
  184.  
  185.  
  186. // Esta función pega lo que está en el portapapeles en el sitio actual.
  187. // ────────────────────────────────────────────────────────────────────
  188. void TPegar(void)
  189. {
  190.    char cad[500],cad1[500];
  191.    int i;
  192.    char *cadena=cad;
  193.    char *cadena1 = cad1;
  194.    Texto2 *text;
  195.    if(TopeVentanas->TipoVentana == V_TEXTO)  {
  196.       text= (Texto2 *) TopeVentanas->Apuntador;
  197.       if(BTLineaFin == 0)  {
  198.      copiar_cadena(cadena,text->Texte[text->CursorY]);
  199.      copiar_cadena(cadena1,text->Texte[text->CursorY]);
  200.      cadena[text->CursorX] =0;
  201.      cadena1 += text->CursorX;
  202.      anadir_cadena(cadena,BArray[0]);
  203.      anadir_cadena(cadena,cadena1);
  204.      free(text->Texte[text->CursorY]);
  205.      text->Texte[text->CursorY] = (char *) malloc (longitud_cadena(cadena)+2);
  206.      copiar_cadena(text->Texte[text->CursorY] , cadena);
  207.       }  else  if(BTLineaFin >0) {
  208.      copiar_cadena(cadena1,text->Texte[text->CursorY]);
  209.      copiar_cadena(cadena,text->Texte[text->CursorY]);
  210.      cadena[text->CursorX] =0;
  211.      cadena1 += text->CursorX;
  212.      anadir_cadena(cadena,BArray[0]);
  213.      free (text->Texte[text->CursorY]);
  214.      text->Texte[text->CursorY] = (char *) malloc (longitud_cadena(cadena)+2);
  215.      copiar_cadena(text->Texte[text->CursorY],cadena);
  216.  
  217.      // Desplazamos lo necesario;
  218.      for( i=text->LineaFin; i>text->CursorY;i--)
  219.         text->Texte[i+BTLineaFin] = text->Texte[i];
  220.      text->LineaFin += BTLineaFin;
  221.      for (i=1; i<BTLineaFin;i++)  {
  222.         text->Texte[text->CursorY + i] = (char *) malloc(longitud_cadena(BArray[i])+2);
  223.         copiar_cadena(text->Texte[text->CursorY +i], BArray[i]);
  224.      }// end for
  225.      cadena = cad;
  226.      copiar_cadena(cadena,BArray[BTLineaFin]);
  227.      anadir_cadena(cadena,cadena1);
  228.      text->Texte[text->CursorY+BTLineaFin] = (char *) malloc(longitud_cadena(cadena)+2);
  229.      copiar_cadena(text->Texte[text->CursorY+BTLineaFin],cadena);
  230.       }// end if
  231.       PintarTexto(text);
  232.    }// end if
  233. }// end TPegar
  234.  
  235.  
  236.  
  237. // Esta función borra lo que está seleccionado en esos momentos.
  238. // ─────────────────────────────────────────────────────────────
  239. void TBorrar(void)
  240. {
  241.    int i,j;
  242.    char cad[500],cad1[500];
  243.    char *cadena = cad, *cadena1 = cad1;
  244.    if( BFinY >= BIniY)  {
  245.       copiar_cadena(cadena,BTexto->Texte[BIniY]);
  246.       cadena[BIniX]=0;
  247.       copiar_cadena(cadena1,BTexto->Texte[BFinY]);
  248.       if (longitud_cadena(cadena1) > BFinX)  {
  249.      cadena1 += BFinX+1;
  250.      anadir_cadena(cadena,cadena1);
  251.       }// end if
  252.       free(BTexto->Texte[BIniY]);
  253.       BTexto->Texte[BIniY] = (char *) malloc(longitud_cadena(cadena)+2);
  254.       copiar_cadena(BTexto->Texte[BIniY],cadena);
  255.  
  256.       i=BIniY+1;
  257.       j=BFinY +1;
  258.       while(i<BFinY)  {
  259.      free(BTexto->Texte[i]);
  260.      BTexto->Texte[i] = BTexto->Texte[j];
  261.      i++;
  262.      j++;
  263.       }// end while
  264.       while(j<=BTexto->LineaFin)  {
  265.      BTexto->Texte[i] = BTexto->Texte[j];
  266.      j++;
  267.      i++;
  268.       }// end while
  269.       BTexto->LineaFin = BTexto->LineaFin - (BFinY -BIniY);
  270.       BFinY = -1;
  271.       PintarTexto(BTexto);
  272.    }// end if
  273. }// end TBorrar
  274.  
  275.  
  276. // Esta función elimina todas las macros que puedan existir
  277. // ────────────────────────────────────────────────────────
  278. void BorrarMacros(void)
  279. {
  280.    TipoElemento *elem;
  281.    Macro *mac;
  282.    while(!ListaGenerica2Vacia(Macros))  {
  283.       elem = ListaGenerica2Principio(Macros);
  284.       mac = ListaGenerica2Elemento(elem);
  285.       free(mac->Macro);
  286.       ListaGenerica2Elimina(&Macros,&elem);
  287.    }// end while
  288. }// end BorrarMacros
  289.  
  290.  
  291. // Esta función inserta una macro
  292. // ──────────────────────────────
  293. WORD InsertarMacro(WORD tecla,char *texto)
  294. {
  295.    Macro *mac;
  296.    mac = (Macro *) malloc(sizeof(Macro));
  297.    mac->Macro = (char *) malloc(longitud_cadena(texto)+1);
  298.    mac->Tecla = tecla;
  299.    copiar_cadena (mac->Macro,texto);
  300.    return(ListaGenerica2Anade(&Macros,ListaGenerica2Principio(Macros),(void *)mac));
  301. }// end InsertarMacro
  302.  
  303.  
  304. // Esta función elimina todas las macros asociadas a un scan code
  305. // ──────────────────────────────────────────────────────────────
  306. void EliminarMacro(WORD tecla)
  307. {
  308.    TipoElemento *elem;
  309.    Macro *mac;
  310.    elem = ListaGenerica2Principio(Macros);
  311.    while (elem != ListaGenerica2Final)  {
  312.       mac=ListaGenerica2Elemento(elem);
  313.       if (mac->Tecla == tecla) {
  314.      printf("%x\n",mac->Tecla);
  315.      free(mac->Macro);
  316.      free(mac);
  317.      ListaGenerica2Elimina(&Macros,&elem);
  318.       }  else  
  319.      elem = ListaGenerica2Siguiente(elem);
  320.    }// end while
  321. }// end EliminarMacro
  322.  
  323.  
  324. // Esta función guarda las macros en un fichero
  325. // ────────────────────────────────────────────
  326. WORD GuardarMacros(char *fichero)
  327. {
  328.    FILE *fich;
  329.    TipoElemento *elem;
  330.    Macro *mac;
  331.    char cad[100];
  332.    if( (fich=fopen(fichero,"wb")) != NULL)  {      // Se ha podido abrir el fichero
  333.       elem = ListaGenerica2Principio(Macros);
  334.       while (elem != ListaGenerica2Final)  {
  335.      mac=ListaGenerica2Elemento(elem);
  336.      if (mac->Tecla != 0)  {
  337.         itoa(mac->Tecla,cad,10);
  338.         anadir_cadena(cad,"\n");
  339.         fputs(cad,fich);
  340.         copiar_cadena(cad,mac->Macro);
  341.         anadir_cadena(cad,"\n");
  342.         fputs(cad,fich);
  343.      }// end if
  344.      elem=ListaGenerica2Siguiente(elem);
  345.       }// end while
  346.       fclose(fich);
  347.       return(TEXTO2_TODO_OK);
  348.    }// end if
  349.    return(TEXTO2_ERROR_FICHERO);
  350. }// end GuardarMacros
  351.  
  352.  
  353. // Esta función carga las macros desde un fichero
  354. // ──────────────────────────────────────────────
  355. WORD CargarMacros(char *fichero)
  356. {
  357.    FILE *fich;
  358.    char cad[500];
  359.    WORD tec;
  360.    BorrarMacros();
  361.    if( (fich=fopen(fichero,"rb")) != NULL)  {
  362.       while(!feof(fich))  {
  363.      fgets(cad,100,fich);
  364.      tec = atoi(cad);
  365.      fgets(cad,100,fich);
  366.      eliminar_caracteres(cad,'\n');
  367.      InsertarMacro(tec,cad);
  368.       }// end while
  369.       fclose(fich);
  370.       return(TEXTO2_TODO_OK);
  371.    }// end if
  372.    return(TEXTO2_ERROR_FICHERO);
  373. }// end CargarMacros
  374.  
  375.  
  376. // Esta función destruye un texto
  377. // ──────────────────────────────
  378. void TDestruye(Texto2 *text)
  379. {
  380.    if(BTexto == text)
  381.       BFinY=-1;
  382.    while(text->LineaFin>0)
  383.       free(text->Texte[text->LineaFin--]);
  384.    free(text->Texte[text->LineaFin]);
  385.    free(text->Ventana);
  386.    free(text);
  387. }// end TDestruye
  388.  
  389.  
  390. // Esta función abre un fichero de texto
  391. // ─────────────────────────────────────
  392. WORD TOpen(Texto2 *text,char *fichero)
  393. {
  394.    char *aux,*aux1;
  395.    FILE *fich;
  396.    char cadena[500];
  397.    if( (fich=fopen(fichero,"rt")) != NULL)  {
  398.       text->LineaFin=0;
  399.       do  {
  400.      cadena[0]=0;
  401.      fgets(cadena,text->AnchoLinea,fich);
  402.      eliminar_caracteres(cadena,'\n');
  403.      substituye_caracter_cad(cadena,0x9,"   ");// Hay un ancho de tabulación
  404.      aux=(char *)malloc(50000);
  405.      aux1=(char *)malloc(50000);
  406.      text->Texte[text->LineaFin]=(char *) malloc(longitud_cadena(cadena)+2);
  407.      free(aux1);
  408.      free(aux);
  409.      if (text->Texte[text->LineaFin]!=NULL)  {
  410.         if(heapchecknode(text->Texte[text->LineaFin]))  {
  411.            copiar_cadena(text->Texte[text->LineaFin],cadena);
  412.            text->LineaFin++;
  413.         }  else  {
  414.            TDestruye(text);
  415.            fclose(fich);
  416.            return(TEXTO2_MEMORIA_INSUFICIENTE);
  417.         }// end if
  418.      }  else  {
  419.         TDestruye(text);
  420.         fclose(fich);
  421.         return(TEXTO2_MEMORIA_INSUFICIENTE);
  422.      }// end if
  423.       } while( !feof(fich));
  424.       text->LineaFin--;
  425.       fclose(fich);
  426.       PintarTexto(text);
  427.       return(TEXTO2_TODO_OK);
  428.    }// end if
  429.    return(TEXTO2_ERROR_FICHERO);
  430. }// end TOpen
  431.  
  432.  
  433. // Esta función guarda un texto en un fichero
  434. // ──────────────────────────────────────────
  435. WORD TSave(Texto2 *text,char *fichero)
  436. {
  437.    FILE *fich;
  438.    unsigned long int linea=0;
  439.    char cadena[500];
  440.    if( (fich=fopen(fichero,"wt")) != NULL)  {    //Se ha podido abrir
  441.       while (linea<=text->LineaFin)  {
  442.      cadena[0]=0;
  443.      copiar_cadena(cadena,text->Texte[linea]);
  444.      text->Texte[linea][0]=0;
  445.      copiar_cadena(text->Texte[linea],cadena);
  446.      if(linea<text->LineaFin)
  447.         anadir_cadena(cadena,"\n");
  448.      if (fputs(cadena,fich)==EOF)  { 
  449.         fclose(fich);
  450.         return(TEXTO2_ERROR_FICHERO);
  451.      }// end if
  452.      linea++;
  453.       }// end while
  454.       fclose(fich);
  455.       return(TEXTO2_TODO_OK);
  456.    }// end if
  457.    fclose(fich);
  458.    return(TEXTO2_ERROR_FICHERO);
  459. }// end TSave
  460.  
  461.  
  462. // Esta rutina se encarga de poner las coordenadas del cursor en una parte
  463. // visible de la pantalla de texto. De esta forma se pueden usar dichas 
  464. // coordenadas como referencia.
  465. // ────────────────────────────────────────────────────────────────────────
  466. void TextoPonerCoordenadas(Texto2 *text)
  467. {
  468.    Ventana2 *vent=text->Ventana;
  469.    char string[30];
  470.    sprintf(string,"%3u:%3u",text->CursorX+1,text->CursorY+1);
  471.    EscribeV(vent,string,vent->PosX+vent->Ancho-15,vent->PosY,vent->ColorLetra,vent->ColorFondo);
  472. }// end TextoPonerCoordenadas
  473.  
  474.  
  475. // Este procedimiento controla los desplazamientos del cursor
  476. // ──────────────────────────────────────────────────────────
  477. void ControlaDesplazamientos( Texto2 *text)
  478. {
  479.    Ventana2 *vent = (*text).Ventana;
  480.    int fin = (*vent).Alto - 6;
  481.    EscribeCV(vent, (*vent).VBarra[1],(*vent).PosX+(*vent).Ancho-1,(*vent).PosY +3+ (*vent).VPosicion, (*vent).ColorTexto, (*vent).ColorFondo);
  482.    EscribeCV(vent, (*vent).HBarra[1],(*vent).PosX + 3+ (*vent).HPosicion, (*vent).PosY+(*vent).Alto-1, (*vent).ColorTexto, (*vent).ColorFondo);
  483.    (*vent).VPosicion = (*text).AparY * fin/((*text).LineaFin+1);
  484.    fin = (*vent).Ancho -4;
  485.    EscribeCV( vent, (*vent).Posicion, (*vent).PosX + (*vent).Ancho -1,(*vent).PosY+ 3+ (*vent).VPosicion, (*vent).ColorTexto, (*vent).ColorFondo);
  486.    EscribeCV( vent, (*vent).Posicion, (*vent).PosX+ 3+ (*vent).HPosicion, (*vent).PosY+ (*vent).Alto- 1, (*vent).ColorTexto, (*vent).ColorFondo);
  487. }// end ControlaDesplazamientos
  488.  
  489.  
  490. // Esta función pone una linea de texto en la pantalla
  491. // ───────────────────────────────────────────────────
  492. void PonerLinea(Texto2 *text, int linea, int posy_win)
  493. {
  494.    BYTE col;
  495.    Ventana2 *vent = (*text).Ventana;
  496.    int x = (*vent).PosX + 1;
  497.    int y = (*vent).PosY + posy_win + 1;
  498.    int x_fin = (*vent).PosX + (*vent).Ancho - 2;
  499.    char *cadena = (*text).Texte[linea];
  500.  
  501.    if ( (linea>=BIniY) && (linea<=BFinY) && (text == BTexto))  
  502.       col = COLOR( vent->ColorTexto, BColor);      
  503.    else
  504.       col = COLOR((*vent).ColorTexto, (*vent).ColorFondo);
  505.    if( longitud_cadena(cadena) > (*text).AparX)  {
  506.       cadena += text->AparX;
  507.       while ( (x<=x_fin) && (*cadena) )  {
  508.      if ((text==BTexto) && (BIniY<=BFinY))  {
  509.         if (linea == BIniY)  {
  510.            if( BIniX > text->AparX + x -vent->PosX -1)
  511.           col = COLOR(vent->ColorTexto,vent->ColorFondo);
  512.            else
  513.           col = COLOR(vent->ColorTexto, BColor);
  514.         } // end if 
  515.         if (linea == BFinY)  {
  516.            if( BFinX < text->AparX +x -vent->PosX -1)
  517.           col = COLOR(vent->ColorTexto,vent->ColorFondo);
  518.            else
  519.           col= COLOR(vent->ColorTexto, BColor);
  520.         }// end if
  521.         if ( (linea==BFinY) && (linea==BIniY))  {
  522.            if( (BIniX > text->AparX + x -vent->PosX -1) || (BFinX < text->AparX +x -vent->PosX -1))  
  523.           col = COLOR(vent->ColorTexto,vent->ColorFondo);
  524.            else
  525.           col = COLOR(vent->ColorTexto,BColor);
  526.         }// end if
  527.      }// end if
  528.      EscribeCAV(vent, *cadena, x++, y, col);
  529.      cadena++;
  530.       }// end while
  531.    }// end if
  532.    while (x <= x_fin)
  533.       EscribeCAV( vent, ' ', x++, y, col);
  534. }// end PonerLinea
  535.  
  536.  
  537. // Esta función pinta el texto en la pantalla
  538. // ──────────────────────────────────────────
  539. void PintarTexto( Texto2 *text)
  540. {
  541.    int yp = 0;
  542.    int x;
  543.    Ventana2 *vent = (*text).Ventana;
  544.    int y = (*vent).PosY + 1;
  545.    BYTE col = COLOR((*vent).ColorTexto, (*vent).ColorFondo);
  546.    int x_ini = (*vent).PosX +1;
  547.    int x_fin = (*vent).PosX + (*vent).Ancho -2;
  548.    int y_fin = (*vent).PosY + (*vent).Alto -2;
  549.    int yt = (*text).AparY;
  550.  
  551.    while( (y<=y_fin) && (yt<=text->LineaFin) ) {
  552.       PonerLinea( text, yt++, yp ++);
  553.       y++;
  554.    }// end while
  555.    while (y<=y_fin)  {
  556.       for( x=x_ini; x<=x_fin; x++)
  557.      EscribeCAV( vent, ' ', x, y, col);
  558.       y++;
  559.    }// end while
  560.    VentanaGotoXY(vent,(*text).CursorX-(*text).AparX,(*text).CursorY-(*text).AparY);
  561.    ControlaDesplazamientos(text);
  562. }// end PintarTexto
  563.  
  564.  
  565. // Esta función controla el cursor de texto
  566. // ────────────────────────────────────────
  567. void TextControlaCursorX(Texto2 *text)
  568. {
  569.    Ventana2 *vent = (*text).Ventana;
  570.    int maxx = longitud_cadena( (*text).Texte[(*text).CursorY]);
  571.    (*text).CursorX = min( (*text).CursorX, maxx);
  572.    if( (*text).CursorX > (*text).AparX)  {
  573.       if( (*text).CursorX - (*text).AparX > (*vent).Ancho)  {
  574.      (*text).AparX = (*text).CursorX -10;
  575.      PintarTexto(text);
  576.       }  else
  577.      VentanaGotoXY(vent, (*text).CursorX-(*text).AparX, (*text).CursorY -(*text).AparY);
  578.    }  else  {
  579.       (*text).AparX = max( (*text).CursorX - 10, 0);
  580.       PintarTexto(text);
  581.    }// end if
  582. }// end TextControlaCursorX
  583.  
  584. //┌────────────────────────────────────────────────────────────────────────┐
  585. //│NOMBRE: TextEvent(text, tipo, caracter)                                 │
  586. //│FUNCION: Reacciona ante cualquier evento que acontezca al texto,        │
  587. //│         y modifica al mismo en consecuencia.                           │
  588. //│PARAMETROS: Entrada: Texto2 *text  --> Es el texto que se ha modificado │
  589. //│                     WORD tipo     --> Es el tipo de evento producido   │
  590. //│                     WORD caracter --> Si se ha introducido un caracter │
  591. //│            Salida: No existen                                          │
  592. //│                                                                        │
  593. //└────────────────────────────────────────────────────────────────────────┘
  594. WORD TextEvent(Texto2 *text, WORD tipo, WORD caracter)
  595. // Notese que caracter sirve para entrada de diversos datos según el tipo.
  596. {
  597.    Ventana2 *vent=(*text).Ventana;
  598.    char *car=(*text).Texte[(*text).CursorY];
  599.    int i;
  600.    int maxx;
  601.    int oldmousex, oldmousey;
  602.    int posx=mousex >> 3;
  603.    int posy=mousey >> 3;
  604.    TipoElemento *mac;         // Es un apuntador para el tratamiento de macros.
  605.    Macro *pmacros;            // Es una apuntador a la macros que se ha especificado.
  606.  
  607.    switch (tipo)  {
  608.  
  609.       case PULSAR_TECLA:  {
  610. //       Aqui se detecta los casos de teclas especiales como el
  611. //       caso de Ctrl + Y, etc etc etc.
  612.  
  613. // En este trozo de código lo que hacemos es tratar las macros
  614. // definidas por el usuario.
  615.      mac = ListaGenerica2Principio(Macros);
  616.      while(mac != ListaGenerica2Final)  {
  617.         pmacros=(Macro *) ListaGenerica2Elemento(mac);
  618.         if(caracter == pmacros->Tecla)  {
  619.            // Aqui se inserta todo lo correspondiente a la macro.
  620.            char caraux[500];
  621.            copiar_cadena(caraux,car);
  622.            insertar_cadena(caraux,pmacros->Macro,text->CursorX);
  623.            text->CursorX += longitud_cadena(pmacros->Macro);
  624.            free(car);
  625.            text->Texte[text->CursorY] = (char *) malloc (longitud_cadena(caraux)+2);
  626.            copiar_cadena(text->Texte[text->CursorY],caraux);
  627.            if( text->CursorX - text->AparX >= vent->Ancho -2)  {
  628.           text->AparX = text->CursorX -10;
  629.           PintarTexto(text);
  630.            }  else  {
  631.           PonerLinea(text, text->CursorY,vent->CursorY);
  632.           TextControlaCursorX(text);
  633.            }// end if
  634.            text->OldX = text->CursorX;
  635.            return(TEXTO2_TODO_OK);
  636.         }// end if
  637.         mac=ListaGenerica2Siguiente(mac);
  638.      }// end while
  639.  
  640.  
  641.      switch (caracter)  {
  642. //          Caso en que se ha pulsado Ctrl + Y
  643. //          En el cual hay que hacer desaparecer la línea del cursor.
  644.         case 0x1519:
  645.            if( (*text).CursorY != (*text).LineaFin)  {
  646.           for(i = (*text).CursorY; i<(*text).LineaFin; i++)
  647.              (*text).Texte[i] = (*text).Texte[i+1];
  648.           text->LineaFin--;
  649.           free(car);
  650.           (*text).CursorX = (*text).OldX;
  651.           TextControlaCursorX (text);
  652.           PintarTexto(text);
  653.            }  else  {
  654.           (text->Texte[text->LineaFin])[0] = 0;
  655.           (*text).CursorX=0;
  656.           (*text).AparX=0;
  657.           PintarTexto(text);
  658.            }// end if
  659.         return(TEXTO2_TODO_OK);
  660.         
  661.         case 0x3B00: // Se ha pulsado F1 que corresponde a inicio del bloque
  662.            TBInicio();
  663.         return(TEXTO2_TODO_OK);
  664.  
  665.         case 0x3C00: // Se ha pulsado F2 que corresponde a fin del bloque.
  666.            TBFin();
  667.         return(TEXTO2_TODO_OK);
  668.  
  669.         case 0x9300: // Se ha pulsado Ctrl + Supr que corresponde a borrar bloque.
  670.            TBorrar();
  671.         return(TEXTO2_TODO_OK);
  672.  
  673.         case 0x9200: // Se ha pulsado Ctrl + Insert que corresponde a insertar bloque
  674.            TPegar(); // Nota que esta no es la función para esta tecla.
  675.         return(TEXTO2_TODO_OK);
  676.  
  677.         case 0x7700: // Se ha pulsado Ctrl + Inicio que copia el texto al buffer
  678.            TCopiar();
  679.         return(TEXTO2_TODO_OK);
  680.      }// end switch
  681.  
  682.      switch (BTAscii(caracter))  {
  683.  
  684.         // Backspace
  685.         case 8:  {
  686.            char car_ant[500];   // La cadena anterior
  687.            if ( (*text).CursorX > 0)  {  // Si el cursor está por enmedio
  688.           eliminar_subcadena(car,--(*text).CursorX,1);
  689.           if ( (*text).CursorX < (*text).AparX )  {
  690.              (*text).AparX = ( (*text).AparX > (*vent).Ancho-10) ? ((*text).AparX-(*vent).Ancho+10) : 0;
  691.              PintarTexto(text);
  692.           }  else  {
  693.              PonerLinea( text, (*text).CursorY, (*vent).CursorY);
  694.              VentanaGotoXY(vent, (*vent).CursorX-1, (*vent).CursorY);
  695.           }// end if
  696.            }  else  if ((*text).CursorY > 0)  {
  697.           copiar_cadena(car_ant,text->Texte[text->CursorY -1]);
  698.           (*text).CursorX = longitud_cadena(car_ant);
  699.           anadir_cadena(car_ant,car);
  700.           free(text->Texte[text->CursorY-1]);
  701.           text->Texte[text->CursorY-1]=(char *)malloc(longitud_cadena(car_ant)+2);
  702.           copiar_cadena(text->Texte[text->CursorY-1],car_ant);
  703.           for(i=text->CursorY;i<text->LineaFin;i++)
  704.              text->Texte[i] = text->Texte[i+1];
  705.           text->LineaFin--;
  706.           text->CursorY--;
  707.           free(car);
  708.           if ( (*text).CursorX-(*text).AparX > (*vent).Ancho)  {
  709.              text->AparX = text->CursorX-10;
  710.           }  else if (text->CursorX < text->AparX)  {
  711.              text->AparX = max(text->CursorX - 10, 0);
  712.           }// end if
  713.           PintarTexto(text);
  714.            }// end if
  715.            text->OldX = text->CursorX;
  716.            break;
  717.         }// end case
  718.  
  719.         // Return
  720.         case 13:  {
  721.            char caraux[500];
  722.            for(i=(*text).LineaFin; i>= (*text).CursorY; i--)
  723.           (*text).Texte[i+1] = (*text).Texte[i];
  724.            maxx=longitud_cadena( (*text).Texte[ (*text).CursorY]);
  725.            if( (*text).CursorX < maxx)  {
  726.           copiar_cadena(caraux,&(car[text->CursorX]));
  727.           car[ text->CursorX]=0;
  728.            }  else
  729.           caraux[0] = 0;
  730.            text->Texte[++text->CursorY]= (char *) malloc(longitud_cadena(caraux)+2);
  731.            copiar_cadena(text->Texte[text->CursorY],caraux);
  732.            text->CursorX=0;
  733.            text->AparX=0;
  734.            text->LineaFin++;
  735.            if ( text->CursorY > text->AparY + vent->Alto -3)
  736.           text->AparY++;
  737.            PintarTexto(text);
  738.            text->OldX = text->CursorX;
  739.            break;
  740.         }// end case
  741.  
  742.         case 0xBC: break; // ESC
  743.         
  744.         // TAB
  745.         case 9:  {
  746.            int i;
  747.            char caraux[500];   
  748.            copiar_cadena(caraux,car);
  749.            for (i=0;i<TabSize;i++)  {
  750.           if(TextInsert || (text->CursorX == longitud_cadena(caraux)))
  751.              insertar_caracter(caraux,' ',(*text).CursorX++);
  752.           else
  753.              caraux[text->CursorX++]=' ';
  754.            }// end for
  755.            free(car);
  756.            text->Texte[text->CursorY]=(char *)malloc(longitud_cadena(caraux)+2);
  757.            copiar_cadena(text->Texte[text->CursorY],caraux);
  758.            if( (*text).CursorX - (*text).AparX >= (*vent).Ancho-2 )  {
  759.           (*text).AparX = (*text).CursorX - 10;
  760.           PintarTexto(text);
  761.            }  else  {
  762.           PonerLinea(text, (*text).CursorY, (*vent).CursorY);
  763.           VentanaGotoXY(vent,(*vent).CursorX+TabSize, (*vent).CursorY);
  764.            }// end if
  765.            (*text).OldX = (*text).CursorX;
  766.            break;
  767.         }// end case
  768.  
  769.  
  770.         case 0xe0:                         //En caso de que sea el KEYB
  771.         case 0:  {                         //En caso de que sea el NKEYB
  772.            switch(BTRastreo(caracter))  {
  773.  
  774.           case CURSOR_UP:  {
  775.              if( (*text).CursorY > 0)  {
  776.             (*text).CursorX = (*text).OldX;
  777.             if ( (*vent).CursorY > 0)  {
  778.                (*text).CursorY--;
  779.                TextControlaCursorX(text);
  780.             }  else  {
  781.                (*text).AparY--;
  782.                (*text).CursorY--;
  783.                TextControlaCursorX(text);
  784.                PintarTexto(text);
  785.             }// end if
  786.              }// end if
  787.              break;
  788.           }// end case
  789.  
  790.           case CURSOR_DOWN:  {
  791.              if ( (*text).CursorY < (*text).LineaFin)  {
  792.             (*text).CursorX= (*text).OldX;
  793.             if( (*vent).CursorY < (*vent).Alto-3 )  {
  794.                (*text).CursorY++;
  795.                TextControlaCursorX(text);
  796.             }  else  {
  797.                (*text).AparY++;
  798.                (*text).CursorY++;
  799.                TextControlaCursorX(text);
  800.                PintarTexto(text);
  801.             }// end if
  802.              }// end if
  803.              break;
  804.           }// end case
  805.  
  806.           case CURSOR_RIGHT:  {
  807.              if ( (*text).CursorX < longitud_cadena( (*text).Texte[(*text).CursorY]))  {
  808.             (*text).CursorX++;
  809.             if ( (*text).CursorX - (*text).AparX > (*vent).Ancho )  {
  810.                (*text).AparX += 10;
  811.                PintarTexto(text);
  812.             }  else
  813.                VentanaGotoXY(vent,(*vent).CursorX+1,(*vent).CursorY);
  814.              }// end if
  815.              (*text).OldX = (*text).CursorX;
  816.              break;
  817.           }// end case
  818.  
  819.            case CURSOR_LEFT:  {
  820.           if( (*text).CursorX > 0 )  {
  821.              (*text).CursorX--;
  822.              if ( (*text).CursorX < (*text).AparX )  {
  823.             (*text).AparX = max((*text).AparX-10,0);
  824.             PintarTexto(text);
  825.              }  else  {
  826.             VentanaGotoXY(vent, (*vent).CursorX-1, (*vent).CursorY);
  827.              }// end if
  828.           }// end if
  829.           (*text).OldX = (*text).CursorX;
  830.           break;
  831.            }// end case
  832.  
  833.            case INICIO:  {
  834.           if( (*text).AparX != 0)  {
  835.              (*text).CursorX = 0;
  836.              (*text).AparX = 0;
  837.              PintarTexto (text);
  838.           }  else  {
  839.              (*text).CursorX = 0;
  840.              VentanaGotoXY( vent, (*text).CursorX - (*text).AparX, (*text).CursorY - (*text).AparY);
  841.           }// end if
  842.           (*text).OldX = (*text).CursorX;
  843.           break;
  844.            }// end case
  845.  
  846.            case FIN:  {
  847.           (*text).CursorX = longitud_cadena (car);
  848.           if ( (*text).CursorX > (*text).AparX + (*vent).Ancho -3)  {
  849.              (*text).AparX = max( (*text).CursorX - 10, 0);
  850.              PintarTexto(text);
  851.           }  else
  852.              VentanaGotoXY(vent, (*text).CursorX - (*text).AparX, (*text).CursorY - (*text).AparY);
  853.           (*text).OldX = (*text).CursorX;
  854.           break;
  855.            }// end case
  856.  
  857.            case AV_PAG:  {
  858.           if( (*text).AparY + (*vent).Alto-3 < (*text).LineaFin)  {
  859.              (*text).AparY += (*vent).Alto-3;
  860.              (*text).CursorY += (*vent).Alto-3;
  861.           }  else
  862.              (*text).CursorY = (*text).LineaFin;
  863.           (*text).CursorX = (*text).OldX;
  864.           TextControlaCursorX(text);
  865.           PintarTexto(text);
  866.           break;
  867.            }// end case
  868.  
  869.         case RE_PAG:  {
  870.            if ( (*text).AparY > (*vent).Alto-3)  {
  871.               (*text).AparY -= (*vent).Alto-3;
  872.               (*text).CursorY -= (*vent).Alto-3;
  873.            }  else
  874.               (*text).AparY = (*text).CursorY = 0;
  875.            (*text).CursorX = (*text).OldX;
  876.            TextControlaCursorX(text);
  877.            PintarTexto(text);
  878.            break;
  879.         }// end case
  880.  
  881.         case SUPR:  {
  882.            char caraux[500];
  883.            char *car_post;   // La cadena anterior
  884.            if ( (*text).CursorX < longitud_cadena(car))   {
  885.               eliminar_subcadena(car,(*text).CursorX,1);
  886.               PintarTexto(text);
  887.            }  else  {
  888.               if ((*text).CursorY < (*text).LineaFin)  {
  889.              car_post = text->Texte[text->CursorY +1];
  890.              copiar_cadena(caraux,car);
  891.              anadir_cadena(caraux,car_post);
  892.              free(car);
  893.              text->Texte[text->CursorY]=(char *) malloc(longitud_cadena(caraux)+2);
  894.              copiar_cadena(text->Texte[text->CursorY],caraux);
  895.              for(i=text->CursorY + 1;i<(*text).LineaFin;i++)
  896.                 text->Texte[i] = text->Texte[i+1];
  897.              text->LineaFin--;
  898.              free(car_post);
  899.              PintarTexto(text);
  900.               }// end if
  901.            }// end if
  902.            text->OldX = text->CursorX;
  903.            break;
  904.         }// end case
  905.  
  906.         // A la pulsación del Insert, pasamos de modo inserción
  907.         // a modo sobreescritura y viceversa.
  908.         case INSERT:
  909.            TextInsert = NOT(TextInsert);  
  910.         // end case
  911.  
  912.          }// end switch
  913.          break;
  914.       }// end case
  915.  
  916. //        case CAPS_LOCK:  {
  917. //        }// end case
  918.  
  919.       default:  {
  920.          char caraux[500];
  921.          copiar_cadena(caraux,car);
  922.          if(TextInsert || (text->CursorX == longitud_cadena(caraux)))
  923.         insertar_caracter(caraux,BTAscii(caracter),(*text).CursorX++);
  924.          else
  925.         caraux[text->CursorX++]=BTAscii(caracter);
  926.          free(car);
  927.          text->Texte[text->CursorY]=(char *)malloc(longitud_cadena(caraux)+2);
  928.          copiar_cadena(text->Texte[text->CursorY],caraux);
  929.          if( (*text).CursorX - (*text).AparX >= (*vent).Ancho-2 )  {
  930.         (*text).AparX = (*text).CursorX - 10;
  931.         PintarTexto(text);
  932.          }  else  {
  933.         PonerLinea(text, (*text).CursorY, (*vent).CursorY);
  934.         VentanaGotoXY(vent,(*vent).CursorX+1, (*vent).CursorY);
  935.          }// end if
  936.          (*text).OldX = (*text).CursorX;
  937.          break;
  938.       }// end case
  939.        }// end switch
  940.        break;
  941.     }// end case
  942.  
  943.  
  944.     case V_BARRA_ARRIBA:  {
  945.        while(estado == BUTTON_LEFT)  {
  946.      EventIddleExecution();
  947.      EventMouseFastExecution();
  948.       if( (*text).AparY > 0)  {
  949.          (*text).AparY--;
  950.          if ( (*text).CursorY > (*text).AparY + (*vent).Alto -3)
  951.         (*text).CursorY--;
  952.          PintarTexto(text);
  953.       }// end if
  954.        }// end while
  955.        (*text).CursorX = (*text).OldX;
  956.        TextControlaCursorX(text);
  957.        PintarTexto(text);
  958.        break;
  959.     }// end case
  960.  
  961.    case V_BARRA_ABAJO:  {
  962.       while(estado == BUTTON_LEFT)  {
  963.       EventIddleExecution();
  964.       EventMouseFastExecution();
  965.       if( (*text).AparY < (*text).LineaFin)  {
  966.          (*text).AparY++;
  967.          if( (*text).CursorY < (*text).AparY)
  968.         (*text).CursorY++;
  969.          PintarTexto(text);
  970.       }// end if
  971.       }// end while
  972.       (*text).CursorX = (*text).OldX;
  973.       TextControlaCursorX(text);
  974.       PintarTexto(text);
  975.       break;
  976.    }// end case
  977.  
  978.       case V_BARRA_BOTON:  {
  979.      oldmousey = mousey;
  980.      while( estado == BUTTON_LEFT)  {
  981.         // Hacemos que la ejecución de eventos rápidos sea posible.
  982.         EventIddleExecution();
  983.         EventMouseFastExecution();    
  984.         if( mousey != oldmousey)  {
  985.            if(mousey>>3 < vent->PosY + vent->Alto - 3)
  986.            if(mousey>>3 > vent->PosY + 3)
  987.           text->AparY = ((mousey>>3) -vent->PosY -4) *text->LineaFin /(vent->Alto -8);
  988.            PintarTexto(text);
  989.            oldmousey = mousey;
  990.         }// end if
  991.      }// end while
  992.      text->CursorX = 0;
  993.      text->CursorY = text->AparY;
  994.      text->OldX    = text->CursorX;
  995.      PintarTexto(text);
  996.      break;
  997.       }// end case
  998.  
  999.       case H_BARRA_IZQUIERDA:  {
  1000.      while( estado == BUTTON_LEFT)  {
  1001.         EventIddleExecution();
  1002.         EventMouseFastExecution();
  1003.         if( (*text).AparX > 0)  {
  1004.            (*text).AparX--;
  1005.            PintarTexto(text);
  1006.         }// end if
  1007.      }// end while
  1008.      if( (*text).CursorX > (*text).AparX + (*vent).Ancho-3)
  1009.         (*text).CursorX = (*text).AparX + (*vent).Ancho -3;
  1010.      PintarTexto(text);
  1011.      (*text).OldX = (*text).CursorX;
  1012.      break;
  1013.       }// end case
  1014.  
  1015.       case H_BARRA_DERECHA: 
  1016.      while(estado == BUTTON_LEFT)  {
  1017.         EventIddleExecution();
  1018.         EventMouseFastExecution();
  1019.         if( (*text).AparX < (*text).AnchoLinea)  {
  1020.            (*text).AparX ++;
  1021.            PintarTexto(text);
  1022.         }// end if
  1023.      }// end while
  1024.      maxx = longitud_cadena( (*text).Texte[(*text).CursorY]);
  1025.      if( (*text).CursorX < (*text).AparX)
  1026.         (*text).CursorX = (*text).AparX;
  1027.      (*text).CursorX = min( (*text).CursorX, maxx);
  1028.      if( (*text).CursorX < (*text).AparX)
  1029.         (*text).AparX = max( (*text).CursorX -10, 0);
  1030.      PintarTexto(text);
  1031.      (*text).OldX = (*text).CursorX;
  1032.       break;
  1033.  
  1034.       case H_BARRA_BOTON:  {
  1035.       }// end case
  1036.  
  1037.       case CERRAR:  
  1038.      VentanaCerrar(vent);
  1039.      TDestruye(text);
  1040.      break;
  1041.  
  1042.       case AMPLIAR:  
  1043.       break;
  1044.  
  1045.       case MODIFICAR:
  1046.      VentanaModificar();
  1047.      (*text).CursorX=(*text).AparX;
  1048.      (*text).CursorY=(*text).AparY;
  1049.      PintarTexto(text);
  1050.      (*text).OldX = (*text).CursorX;
  1051.       break;
  1052.  
  1053.       case MOVER:
  1054.      VMoverPantalla();  
  1055.       break;
  1056.  
  1057.       case CAMBIAR:
  1058.      VCambiarPrincipal(caracter);
  1059.      mouse_evento=PULSAR_IZQUIERDO;
  1060.      EventMouseSkipExecution();   // Si queremos hacer varias cosas hay que hacerlo asi.
  1061.       break;
  1062.  
  1063.       case PULSAR_VENTANA:
  1064.      posx -= (*vent).PosX+1;
  1065.      posy -= (*vent).PosY+1;
  1066.      if ( (posy >= 0) 
  1067.      && (posy < (*vent).PosY + (*vent).Alto -3)  
  1068.      && (posx >= 0)  
  1069.      && (posx < (*vent).PosX + (*vent).Ancho -2)  
  1070.      && (posy + (*text).AparY <= (*text).LineaFin ) )  {
  1071.         (*text).CursorY= (*text).AparY + posy;
  1072.         if ( (*text).AparX > longitud_cadena((*text).Texte[(*text).CursorY]) )  {
  1073.            (*text).CursorX= longitud_cadena((*text).Texte[(*text).CursorY]);
  1074.            (*text).AparX = max( (*text).CursorX -10, 0);
  1075.            PintarTexto(text);
  1076.         }  else  {
  1077.            (*text).CursorX = min( (*text).AparX + posx, longitud_cadena((*text).Texte[(*text).CursorY]));
  1078.            VentanaGotoXY(vent, (*text).CursorX - (*text).AparX, (*text).CursorY - (*text).AparY);
  1079.         }// end if
  1080.         while (estado == BUTTON_LEFT)  {
  1081.            if( ((mousex >>3)!=posx+vent->PosX+1) || (mousey>>3)!=posy+vent->PosY+1)  {
  1082.           if (BTexto != text)
  1083.              PintarTexto(BTexto);
  1084.           BTexto=text;
  1085.           BIniX = text->CursorX;
  1086.           BIniY = text->CursorY;
  1087.           BFinY = (mousey >> 3) - (vent->PosY +1) +text->AparY;
  1088.           BFinX = (mousex >> 3) - (vent->PosX +1) +text->AparX;
  1089.           if( BFinY > text->LineaFin) 
  1090.              BFinY = text->LineaFin;
  1091.           if( BFinX > longitud_cadena(text->Texte[BFinY]) ) 
  1092.              BFinX = longitud_cadena(text->Texte[BFinY]);
  1093.           posx = mousex >> 3;
  1094.           posy = mousey >> 3;
  1095.           PintarTexto(text);
  1096.            }// end if
  1097.         }// end while
  1098.      }// end if
  1099.      (*text).OldX = (*text).CursorX;
  1100.       break;
  1101.  
  1102.    }// end switch
  1103.    return(TEXTO2_TODO_OK);
  1104. }// end TextEvent
  1105.  
  1106.  
  1107. // Esta función controla el uso del ratón sobre el texto
  1108. // NOTA: Se pone en la pila de ejecución de eventos del raton
  1109. // ──────────────────────────────────────────────────────────
  1110. void far TrataTextoRaton(void)
  1111. {
  1112.    Texto2 *text;
  1113.    int a,v_auxiliar;
  1114.    if( (*TopeVentanas).TipoVentana == V_TEXTO)  {
  1115.       a=EvntVentanas(&v_auxiliar);
  1116.       if(a)  {
  1117.      text = (Texto2 *) (*TopeVentanas).Apuntador;
  1118.      TextEvent(text, a, v_auxiliar);
  1119.      TextoPonerCoordenadas(text);
  1120.       }// end if
  1121.    }// end if
  1122. }// end TrataTextoRaton
  1123.  
  1124.  
  1125. // Esta función trata todos los eventos de teclado que se producen sobre
  1126. // un texto
  1127. // NOTA: Se pone en la pila de ejecución de eventos de teclado
  1128. // ─────────────────────────────────────────────────────────────────────
  1129. void far TrataTextoTeclado(void)
  1130. {
  1131.    Texto2 *text;
  1132.    if( (*TopeVentanas).TipoVentana == V_TEXTO)  {
  1133.       text = (Texto2 *) (*TopeVentanas).Apuntador;
  1134.       TextEvent(text,PULSAR_TECLA,EventTecla);
  1135.       TextoPonerCoordenadas(text);
  1136.    }// end if
  1137. }// end TrataTextoTeclado
  1138.  
  1139.  
  1140. // Esta función se encarga de inicializar el sistema de textos
  1141. // NOTA: Se ejecuta una vez al principio y nunca más
  1142. // ───────────────────────────────────────────────────────────
  1143. void TextoInicializar(void)
  1144. {
  1145.    EventEmpilaKeyboardRutina(TrataTextoTeclado);
  1146.    EventEmpilaMouseRutina(TrataTextoRaton);
  1147.    ListaGenerica2Anula(Macros);
  1148. }// end InicializarTexto      
  1149.  
  1150. #endif
  1151.