home *** CD-ROM | disk | FTP | other *** search
- // ╔═════════════════════════════════════════════════════════════╗
- // ║ ┌──────────┐ ║
- // ║ │ TEXTO2.H │ ║
- // ║ └──────────┘ ║
- // ║ (C) Anubis Software Junio 1995 ║
- // ║ ║
- // ║ Esta librería, pretende mejorar la librería TEXTO1.h ║
- // ║ aplicando los nuevos conocimientos adquiridos sobre el ║
- // ║ tema. ║
- // ║ ║
- // ╚═════════════════════════════════════════════════════════════╝
-
- #ifndef TEXTO2.H
- #define TEXTO2.H
-
-
- //╔═════════════════════════════════════════════════════════════╗
- //║ Inclusion de librerías BorlandC ++ ║
- //╚═════════════════════════════════════════════════════════════╝
- #include <stdio.h>
- #include <alloc.h>
-
-
- //╔═════════════════════════════════════════════════════════════╗
- //║ Inclusión de librerías Anubis Software ║
- //╚═════════════════════════════════════════════════════════════╝
- #include "tecexec.h"
- #include "ventana2.h"
- #include "mdefs.h"
- #include "scancode.h"
- #include "tecbuf.h"
- #include "cadena.h"
- #include "listag2.h"
-
-
- //╔═════════════════════════════════════════════════════════════╗
- //║ Definición de constantes ║
- //╚═════════════════════════════════════════════════════════════╝
- // Definición de errores de la libreria:
- #define TEXTO2_MEMORIA_INSUFICIENTE 10
- #define TEXTO2_ERROR_FICHERO 11
- #define TEXTO2_TODO_OK 0
-
- // Definicion de eventos de la libreria:
- #define PULSAR_TECLA 0
-
-
- //╔═════════════════════════════════════════════════════════════╗
- //║ Definición de macros de la librería ║
- //╚═════════════════════════════════════════════════════════════╝
-
-
- //╔═════════════════════════════════════════════════════════════╗
- //║ Declaración de variables globales ║
- //╚═════════════════════════════════════════════════════════════╝
- char TabSize = 3; // Es la longitud del tabulador.
- ListaGenerica2 Macros; // Es la lista de macros del procesador de textos.
- boolean TextInsert=TRUE; // Modo inserción = True, Sobreescribir = False.
-
-
- //╔═════════════════════════════════════════════════════════════╗
- //║ Definición de estructuras de la libreria ║
- //╚═════════════════════════════════════════════════════════════╝
- typedef struct {
- int CursorX,CursorY; // Posición del cursor en el texto. Pos inic(0,0)
- int AparX,AparY; // Posición que se ve en la Ventana.
- // esquina superior izquierda.Pos inic (0,0)
- unsigned long LineaFin; // Linea final del texto.
- // La linea a la que apunta tiene texto
- unsigned int AnchoLinea; // El ancho de la linea de texto. Más allá
- // de la cual no se puede escribir.
- Ventana2 *Ventana; // Ventana a la que pertenece el texto.
- int OldX; // Indica la posición en la que el cursor
- // quiere estar. Se usa a modo de auxiliar.
- char *Texte[5000]; // De momento es lo mejor que hay
- } Texto2;
-
- typedef struct {
- WORD Tecla; // Es el código de la tecla de la macro.
- char *Macro;
- } Macro;
-
- //╔═════════════════════════════════════════════════════════════╗
- //║ Más variables globales concernientes a los bloques. ║
- //╚═════════════════════════════════════════════════════════════╝
- Texto2 *BTexto=NULL;
- int BIniX=0,BIniY=1,BFinX=0,BFinY=0,BTLineaFin=-1;
- BYTE BColor = FCYAN;
- char *BArray[500]; // Este array es el trozo de texto que se copia.
-
-
-
- //╔═════════════════════════════════════════════════════════════╗
- //║ Declaración de prototipos de la librería ║
- //╚═════════════════════════════════════════════════════════════╝
- void PonerLinea( Texto2 *, int, int);
- void PintarTexto( Texto2 *);
- WORD TextEvent( Texto2 *, WORD, WORD);
- WORD TOpen( Texto2 *, char *);
- WORD TSave( Texto2 *, char *);
- void ControlaDesplazamientos( Texto2 *);
-
-
- //╔═════════════════════════════════════════════════════════════╗
- //║ Implementación de procedimientos de la librería ║
- //╚═════════════════════════════════════════════════════════════╝
-
- // Esta función marca el principio de un bloque de texto
- //──────────────────────────────────────────────────────
- void TBInicio(void)
- {
- if(TopeVentanas->TipoVentana == V_TEXTO) {
- if(BTexto != TopeVentanas->Apuntador) {
- BFinY=-1;
- if(BTexto != NULL)
- PintarTexto(BTexto);
- }// end if
- BTexto = (Texto2 *) TopeVentanas->Apuntador;
- BIniX = BTexto->CursorX;
- BIniY = BTexto->CursorY;
- PintarTexto(BTexto);
- }// end if
- }// end TBInicio
-
- // Esta función marca el final de un bloque de texto.
- // ──────────────────────────────────────────────────
- void TBFin(void)
- {
- if((Texto2 *) TopeVentanas->Apuntador == BTexto) {
- if(BTexto != TopeVentanas->Apuntador) {
- BFinY=-1;
- if (BTexto != NULL)
- PintarTexto(BTexto);
- }// end if
- BFinX = BTexto->CursorX;
- BFinY = BTexto->CursorY;
- PintarTexto(BTexto);
- }// end if
- // NOTA: A esta función le falta hacer algunas serias comprobaciones.
- }// end TBFin
-
- // Esta función copia un trozo de texto al buffer intermedio para bloques.
- // ───────────────────────────────────────────────────────────────────────
- void TCopiar(void)
- {
- int i,j;
- char cad[500];
- char *cadena=cad;
-
- // Lo primero que hacemos es vaciar el buffer del teclado.
- for (i=0; i<=BTLineaFin; i++);
- free(BArray[i]);
-
- if(BIniY < BFinY) {
- // Después copiamos la primera linea de la selección.
- copiar_cadena(cadena,BTexto->Texte[BIniY]);
- cadena += BIniX;
- BArray[0] = (char *) malloc (longitud_cadena(cadena) +2);
- copiar_cadena( BArray[0],cadena);
- j=BIniY +1;
- i=1;
- while (j<BFinY) {
- BArray[i] = (char *) malloc (longitud_cadena(BTexto->Texte[j])+2);
- copiar_cadena(BArray[i],BTexto->Texte[j]);
- i++;
- j++;
- }// end while
- // Tratamos el elemento final.
- cadena = cad; // Inicializamos de nuevo la cadena.
- copiar_cadena(cadena,BTexto->Texte[BFinY]);
- cadena[BFinX+1] = 0;
- BArray[i] = (char *) malloc (longitud_cadena(cadena)+2);
- copiar_cadena(BArray[i],cadena);
- BTLineaFin = i;
- } else if (BIniY == BFinY) {
- copiar_cadena(cadena,BTexto->Texte[BFinY]);
- cadena[BFinX+1] =0;
- cadena += BIniX;
- BArray[0]= (char *) malloc (longitud_cadena(cadena)+2);
- copiar_cadena(BArray[0],cadena);
- BTLineaFin =0;
- }// end if
- }// end TCopiar
-
-
- // Esta función pega lo que está en el portapapeles en el sitio actual.
- // ────────────────────────────────────────────────────────────────────
- void TPegar(void)
- {
- char cad[500],cad1[500];
- int i;
- char *cadena=cad;
- char *cadena1 = cad1;
- Texto2 *text;
- if(TopeVentanas->TipoVentana == V_TEXTO) {
- text= (Texto2 *) TopeVentanas->Apuntador;
- if(BTLineaFin == 0) {
- copiar_cadena(cadena,text->Texte[text->CursorY]);
- copiar_cadena(cadena1,text->Texte[text->CursorY]);
- cadena[text->CursorX] =0;
- cadena1 += text->CursorX;
- anadir_cadena(cadena,BArray[0]);
- anadir_cadena(cadena,cadena1);
- free(text->Texte[text->CursorY]);
- text->Texte[text->CursorY] = (char *) malloc (longitud_cadena(cadena)+2);
- copiar_cadena(text->Texte[text->CursorY] , cadena);
- } else if(BTLineaFin >0) {
- copiar_cadena(cadena1,text->Texte[text->CursorY]);
- copiar_cadena(cadena,text->Texte[text->CursorY]);
- cadena[text->CursorX] =0;
- cadena1 += text->CursorX;
- anadir_cadena(cadena,BArray[0]);
- free (text->Texte[text->CursorY]);
- text->Texte[text->CursorY] = (char *) malloc (longitud_cadena(cadena)+2);
- copiar_cadena(text->Texte[text->CursorY],cadena);
-
- // Desplazamos lo necesario;
- for( i=text->LineaFin; i>text->CursorY;i--)
- text->Texte[i+BTLineaFin] = text->Texte[i];
- text->LineaFin += BTLineaFin;
- for (i=1; i<BTLineaFin;i++) {
- text->Texte[text->CursorY + i] = (char *) malloc(longitud_cadena(BArray[i])+2);
- copiar_cadena(text->Texte[text->CursorY +i], BArray[i]);
- }// end for
- cadena = cad;
- copiar_cadena(cadena,BArray[BTLineaFin]);
- anadir_cadena(cadena,cadena1);
- text->Texte[text->CursorY+BTLineaFin] = (char *) malloc(longitud_cadena(cadena)+2);
- copiar_cadena(text->Texte[text->CursorY+BTLineaFin],cadena);
- }// end if
- PintarTexto(text);
- }// end if
- }// end TPegar
-
-
-
- // Esta función borra lo que está seleccionado en esos momentos.
- // ─────────────────────────────────────────────────────────────
- void TBorrar(void)
- {
- int i,j;
- char cad[500],cad1[500];
- char *cadena = cad, *cadena1 = cad1;
- if( BFinY >= BIniY) {
- copiar_cadena(cadena,BTexto->Texte[BIniY]);
- cadena[BIniX]=0;
- copiar_cadena(cadena1,BTexto->Texte[BFinY]);
- if (longitud_cadena(cadena1) > BFinX) {
- cadena1 += BFinX+1;
- anadir_cadena(cadena,cadena1);
- }// end if
- free(BTexto->Texte[BIniY]);
- BTexto->Texte[BIniY] = (char *) malloc(longitud_cadena(cadena)+2);
- copiar_cadena(BTexto->Texte[BIniY],cadena);
-
- i=BIniY+1;
- j=BFinY +1;
- while(i<BFinY) {
- free(BTexto->Texte[i]);
- BTexto->Texte[i] = BTexto->Texte[j];
- i++;
- j++;
- }// end while
- while(j<=BTexto->LineaFin) {
- BTexto->Texte[i] = BTexto->Texte[j];
- j++;
- i++;
- }// end while
- BTexto->LineaFin = BTexto->LineaFin - (BFinY -BIniY);
- BFinY = -1;
- PintarTexto(BTexto);
- }// end if
- }// end TBorrar
-
-
- // Esta función elimina todas las macros que puedan existir
- // ────────────────────────────────────────────────────────
- void BorrarMacros(void)
- {
- TipoElemento *elem;
- Macro *mac;
- while(!ListaGenerica2Vacia(Macros)) {
- elem = ListaGenerica2Principio(Macros);
- mac = ListaGenerica2Elemento(elem);
- free(mac->Macro);
- ListaGenerica2Elimina(&Macros,&elem);
- }// end while
- }// end BorrarMacros
-
-
- // Esta función inserta una macro
- // ──────────────────────────────
- WORD InsertarMacro(WORD tecla,char *texto)
- {
- Macro *mac;
- mac = (Macro *) malloc(sizeof(Macro));
- mac->Macro = (char *) malloc(longitud_cadena(texto)+1);
- mac->Tecla = tecla;
- copiar_cadena (mac->Macro,texto);
- return(ListaGenerica2Anade(&Macros,ListaGenerica2Principio(Macros),(void *)mac));
- }// end InsertarMacro
-
-
- // Esta función elimina todas las macros asociadas a un scan code
- // ──────────────────────────────────────────────────────────────
- void EliminarMacro(WORD tecla)
- {
- TipoElemento *elem;
- Macro *mac;
- elem = ListaGenerica2Principio(Macros);
- while (elem != ListaGenerica2Final) {
- mac=ListaGenerica2Elemento(elem);
- if (mac->Tecla == tecla) {
- printf("%x\n",mac->Tecla);
- free(mac->Macro);
- free(mac);
- ListaGenerica2Elimina(&Macros,&elem);
- } else
- elem = ListaGenerica2Siguiente(elem);
- }// end while
- }// end EliminarMacro
-
-
- // Esta función guarda las macros en un fichero
- // ────────────────────────────────────────────
- WORD GuardarMacros(char *fichero)
- {
- FILE *fich;
- TipoElemento *elem;
- Macro *mac;
- char cad[100];
- if( (fich=fopen(fichero,"wb")) != NULL) { // Se ha podido abrir el fichero
- elem = ListaGenerica2Principio(Macros);
- while (elem != ListaGenerica2Final) {
- mac=ListaGenerica2Elemento(elem);
- if (mac->Tecla != 0) {
- itoa(mac->Tecla,cad,10);
- anadir_cadena(cad,"\n");
- fputs(cad,fich);
- copiar_cadena(cad,mac->Macro);
- anadir_cadena(cad,"\n");
- fputs(cad,fich);
- }// end if
- elem=ListaGenerica2Siguiente(elem);
- }// end while
- fclose(fich);
- return(TEXTO2_TODO_OK);
- }// end if
- return(TEXTO2_ERROR_FICHERO);
- }// end GuardarMacros
-
-
- // Esta función carga las macros desde un fichero
- // ──────────────────────────────────────────────
- WORD CargarMacros(char *fichero)
- {
- FILE *fich;
- char cad[500];
- WORD tec;
- BorrarMacros();
- if( (fich=fopen(fichero,"rb")) != NULL) {
- while(!feof(fich)) {
- fgets(cad,100,fich);
- tec = atoi(cad);
- fgets(cad,100,fich);
- eliminar_caracteres(cad,'\n');
- InsertarMacro(tec,cad);
- }// end while
- fclose(fich);
- return(TEXTO2_TODO_OK);
- }// end if
- return(TEXTO2_ERROR_FICHERO);
- }// end CargarMacros
-
-
- // Esta función destruye un texto
- // ──────────────────────────────
- void TDestruye(Texto2 *text)
- {
- if(BTexto == text)
- BFinY=-1;
- while(text->LineaFin>0)
- free(text->Texte[text->LineaFin--]);
- free(text->Texte[text->LineaFin]);
- free(text->Ventana);
- free(text);
- }// end TDestruye
-
-
- // Esta función abre un fichero de texto
- // ─────────────────────────────────────
- WORD TOpen(Texto2 *text,char *fichero)
- {
- char *aux,*aux1;
- FILE *fich;
- char cadena[500];
- if( (fich=fopen(fichero,"rt")) != NULL) {
- text->LineaFin=0;
- do {
- cadena[0]=0;
- fgets(cadena,text->AnchoLinea,fich);
- eliminar_caracteres(cadena,'\n');
- substituye_caracter_cad(cadena,0x9," ");// Hay un ancho de tabulación
- aux=(char *)malloc(50000);
- aux1=(char *)malloc(50000);
- text->Texte[text->LineaFin]=(char *) malloc(longitud_cadena(cadena)+2);
- free(aux1);
- free(aux);
- if (text->Texte[text->LineaFin]!=NULL) {
- if(heapchecknode(text->Texte[text->LineaFin])) {
- copiar_cadena(text->Texte[text->LineaFin],cadena);
- text->LineaFin++;
- } else {
- TDestruye(text);
- fclose(fich);
- return(TEXTO2_MEMORIA_INSUFICIENTE);
- }// end if
- } else {
- TDestruye(text);
- fclose(fich);
- return(TEXTO2_MEMORIA_INSUFICIENTE);
- }// end if
- } while( !feof(fich));
- text->LineaFin--;
- fclose(fich);
- PintarTexto(text);
- return(TEXTO2_TODO_OK);
- }// end if
- return(TEXTO2_ERROR_FICHERO);
- }// end TOpen
-
-
- // Esta función guarda un texto en un fichero
- // ──────────────────────────────────────────
- WORD TSave(Texto2 *text,char *fichero)
- {
- FILE *fich;
- unsigned long int linea=0;
- char cadena[500];
- if( (fich=fopen(fichero,"wt")) != NULL) { //Se ha podido abrir
- while (linea<=text->LineaFin) {
- cadena[0]=0;
- copiar_cadena(cadena,text->Texte[linea]);
- text->Texte[linea][0]=0;
- copiar_cadena(text->Texte[linea],cadena);
- if(linea<text->LineaFin)
- anadir_cadena(cadena,"\n");
- if (fputs(cadena,fich)==EOF) {
- fclose(fich);
- return(TEXTO2_ERROR_FICHERO);
- }// end if
- linea++;
- }// end while
- fclose(fich);
- return(TEXTO2_TODO_OK);
- }// end if
- fclose(fich);
- return(TEXTO2_ERROR_FICHERO);
- }// end TSave
-
-
- // Esta rutina se encarga de poner las coordenadas del cursor en una parte
- // visible de la pantalla de texto. De esta forma se pueden usar dichas
- // coordenadas como referencia.
- // ────────────────────────────────────────────────────────────────────────
- void TextoPonerCoordenadas(Texto2 *text)
- {
- Ventana2 *vent=text->Ventana;
- char string[30];
- sprintf(string,"%3u:%3u",text->CursorX+1,text->CursorY+1);
- EscribeV(vent,string,vent->PosX+vent->Ancho-15,vent->PosY,vent->ColorLetra,vent->ColorFondo);
- }// end TextoPonerCoordenadas
-
-
- // Este procedimiento controla los desplazamientos del cursor
- // ──────────────────────────────────────────────────────────
- void ControlaDesplazamientos( Texto2 *text)
- {
- Ventana2 *vent = (*text).Ventana;
- int fin = (*vent).Alto - 6;
- EscribeCV(vent, (*vent).VBarra[1],(*vent).PosX+(*vent).Ancho-1,(*vent).PosY +3+ (*vent).VPosicion, (*vent).ColorTexto, (*vent).ColorFondo);
- EscribeCV(vent, (*vent).HBarra[1],(*vent).PosX + 3+ (*vent).HPosicion, (*vent).PosY+(*vent).Alto-1, (*vent).ColorTexto, (*vent).ColorFondo);
- (*vent).VPosicion = (*text).AparY * fin/((*text).LineaFin+1);
- fin = (*vent).Ancho -4;
- EscribeCV( vent, (*vent).Posicion, (*vent).PosX + (*vent).Ancho -1,(*vent).PosY+ 3+ (*vent).VPosicion, (*vent).ColorTexto, (*vent).ColorFondo);
- EscribeCV( vent, (*vent).Posicion, (*vent).PosX+ 3+ (*vent).HPosicion, (*vent).PosY+ (*vent).Alto- 1, (*vent).ColorTexto, (*vent).ColorFondo);
- }// end ControlaDesplazamientos
-
-
- // Esta función pone una linea de texto en la pantalla
- // ───────────────────────────────────────────────────
- void PonerLinea(Texto2 *text, int linea, int posy_win)
- {
- BYTE col;
- Ventana2 *vent = (*text).Ventana;
- int x = (*vent).PosX + 1;
- int y = (*vent).PosY + posy_win + 1;
- int x_fin = (*vent).PosX + (*vent).Ancho - 2;
- char *cadena = (*text).Texte[linea];
-
- if ( (linea>=BIniY) && (linea<=BFinY) && (text == BTexto))
- col = COLOR( vent->ColorTexto, BColor);
- else
- col = COLOR((*vent).ColorTexto, (*vent).ColorFondo);
- if( longitud_cadena(cadena) > (*text).AparX) {
- cadena += text->AparX;
- while ( (x<=x_fin) && (*cadena) ) {
- if ((text==BTexto) && (BIniY<=BFinY)) {
- if (linea == BIniY) {
- if( BIniX > text->AparX + x -vent->PosX -1)
- col = COLOR(vent->ColorTexto,vent->ColorFondo);
- else
- col = COLOR(vent->ColorTexto, BColor);
- } // end if
- if (linea == BFinY) {
- if( BFinX < text->AparX +x -vent->PosX -1)
- col = COLOR(vent->ColorTexto,vent->ColorFondo);
- else
- col= COLOR(vent->ColorTexto, BColor);
- }// end if
- if ( (linea==BFinY) && (linea==BIniY)) {
- if( (BIniX > text->AparX + x -vent->PosX -1) || (BFinX < text->AparX +x -vent->PosX -1))
- col = COLOR(vent->ColorTexto,vent->ColorFondo);
- else
- col = COLOR(vent->ColorTexto,BColor);
- }// end if
- }// end if
- EscribeCAV(vent, *cadena, x++, y, col);
- cadena++;
- }// end while
- }// end if
- while (x <= x_fin)
- EscribeCAV( vent, ' ', x++, y, col);
- }// end PonerLinea
-
-
- // Esta función pinta el texto en la pantalla
- // ──────────────────────────────────────────
- void PintarTexto( Texto2 *text)
- {
- int yp = 0;
- int x;
- Ventana2 *vent = (*text).Ventana;
- int y = (*vent).PosY + 1;
- BYTE col = COLOR((*vent).ColorTexto, (*vent).ColorFondo);
- int x_ini = (*vent).PosX +1;
- int x_fin = (*vent).PosX + (*vent).Ancho -2;
- int y_fin = (*vent).PosY + (*vent).Alto -2;
- int yt = (*text).AparY;
-
- while( (y<=y_fin) && (yt<=text->LineaFin) ) {
- PonerLinea( text, yt++, yp ++);
- y++;
- }// end while
- while (y<=y_fin) {
- for( x=x_ini; x<=x_fin; x++)
- EscribeCAV( vent, ' ', x, y, col);
- y++;
- }// end while
- VentanaGotoXY(vent,(*text).CursorX-(*text).AparX,(*text).CursorY-(*text).AparY);
- ControlaDesplazamientos(text);
- }// end PintarTexto
-
-
- // Esta función controla el cursor de texto
- // ────────────────────────────────────────
- void TextControlaCursorX(Texto2 *text)
- {
- Ventana2 *vent = (*text).Ventana;
- int maxx = longitud_cadena( (*text).Texte[(*text).CursorY]);
- (*text).CursorX = min( (*text).CursorX, maxx);
- if( (*text).CursorX > (*text).AparX) {
- if( (*text).CursorX - (*text).AparX > (*vent).Ancho) {
- (*text).AparX = (*text).CursorX -10;
- PintarTexto(text);
- } else
- VentanaGotoXY(vent, (*text).CursorX-(*text).AparX, (*text).CursorY -(*text).AparY);
- } else {
- (*text).AparX = max( (*text).CursorX - 10, 0);
- PintarTexto(text);
- }// end if
- }// end TextControlaCursorX
-
- //┌────────────────────────────────────────────────────────────────────────┐
- //│NOMBRE: TextEvent(text, tipo, caracter) │
- //│FUNCION: Reacciona ante cualquier evento que acontezca al texto, │
- //│ y modifica al mismo en consecuencia. │
- //│PARAMETROS: Entrada: Texto2 *text --> Es el texto que se ha modificado │
- //│ WORD tipo --> Es el tipo de evento producido │
- //│ WORD caracter --> Si se ha introducido un caracter │
- //│ Salida: No existen │
- //│ │
- //└────────────────────────────────────────────────────────────────────────┘
- WORD TextEvent(Texto2 *text, WORD tipo, WORD caracter)
- // Notese que caracter sirve para entrada de diversos datos según el tipo.
- {
- Ventana2 *vent=(*text).Ventana;
- char *car=(*text).Texte[(*text).CursorY];
- int i;
- int maxx;
- int oldmousex, oldmousey;
- int posx=mousex >> 3;
- int posy=mousey >> 3;
- TipoElemento *mac; // Es un apuntador para el tratamiento de macros.
- Macro *pmacros; // Es una apuntador a la macros que se ha especificado.
-
- switch (tipo) {
-
- case PULSAR_TECLA: {
- // Aqui se detecta los casos de teclas especiales como el
- // caso de Ctrl + Y, etc etc etc.
-
- // En este trozo de código lo que hacemos es tratar las macros
- // definidas por el usuario.
- mac = ListaGenerica2Principio(Macros);
- while(mac != ListaGenerica2Final) {
- pmacros=(Macro *) ListaGenerica2Elemento(mac);
- if(caracter == pmacros->Tecla) {
- // Aqui se inserta todo lo correspondiente a la macro.
- char caraux[500];
- copiar_cadena(caraux,car);
- insertar_cadena(caraux,pmacros->Macro,text->CursorX);
- text->CursorX += longitud_cadena(pmacros->Macro);
- free(car);
- text->Texte[text->CursorY] = (char *) malloc (longitud_cadena(caraux)+2);
- copiar_cadena(text->Texte[text->CursorY],caraux);
- if( text->CursorX - text->AparX >= vent->Ancho -2) {
- text->AparX = text->CursorX -10;
- PintarTexto(text);
- } else {
- PonerLinea(text, text->CursorY,vent->CursorY);
- TextControlaCursorX(text);
- }// end if
- text->OldX = text->CursorX;
- return(TEXTO2_TODO_OK);
- }// end if
- mac=ListaGenerica2Siguiente(mac);
- }// end while
-
-
- switch (caracter) {
- // Caso en que se ha pulsado Ctrl + Y
- // En el cual hay que hacer desaparecer la línea del cursor.
- case 0x1519:
- if( (*text).CursorY != (*text).LineaFin) {
- for(i = (*text).CursorY; i<(*text).LineaFin; i++)
- (*text).Texte[i] = (*text).Texte[i+1];
- text->LineaFin--;
- free(car);
- (*text).CursorX = (*text).OldX;
- TextControlaCursorX (text);
- PintarTexto(text);
- } else {
- (text->Texte[text->LineaFin])[0] = 0;
- (*text).CursorX=0;
- (*text).AparX=0;
- PintarTexto(text);
- }// end if
- return(TEXTO2_TODO_OK);
-
- case 0x3B00: // Se ha pulsado F1 que corresponde a inicio del bloque
- TBInicio();
- return(TEXTO2_TODO_OK);
-
- case 0x3C00: // Se ha pulsado F2 que corresponde a fin del bloque.
- TBFin();
- return(TEXTO2_TODO_OK);
-
- case 0x9300: // Se ha pulsado Ctrl + Supr que corresponde a borrar bloque.
- TBorrar();
- return(TEXTO2_TODO_OK);
-
- case 0x9200: // Se ha pulsado Ctrl + Insert que corresponde a insertar bloque
- TPegar(); // Nota que esta no es la función para esta tecla.
- return(TEXTO2_TODO_OK);
-
- case 0x7700: // Se ha pulsado Ctrl + Inicio que copia el texto al buffer
- TCopiar();
- return(TEXTO2_TODO_OK);
- }// end switch
-
- switch (BTAscii(caracter)) {
-
- // Backspace
- case 8: {
- char car_ant[500]; // La cadena anterior
- if ( (*text).CursorX > 0) { // Si el cursor está por enmedio
- eliminar_subcadena(car,--(*text).CursorX,1);
- if ( (*text).CursorX < (*text).AparX ) {
- (*text).AparX = ( (*text).AparX > (*vent).Ancho-10) ? ((*text).AparX-(*vent).Ancho+10) : 0;
- PintarTexto(text);
- } else {
- PonerLinea( text, (*text).CursorY, (*vent).CursorY);
- VentanaGotoXY(vent, (*vent).CursorX-1, (*vent).CursorY);
- }// end if
- } else if ((*text).CursorY > 0) {
- copiar_cadena(car_ant,text->Texte[text->CursorY -1]);
- (*text).CursorX = longitud_cadena(car_ant);
- anadir_cadena(car_ant,car);
- free(text->Texte[text->CursorY-1]);
- text->Texte[text->CursorY-1]=(char *)malloc(longitud_cadena(car_ant)+2);
- copiar_cadena(text->Texte[text->CursorY-1],car_ant);
- for(i=text->CursorY;i<text->LineaFin;i++)
- text->Texte[i] = text->Texte[i+1];
- text->LineaFin--;
- text->CursorY--;
- free(car);
- if ( (*text).CursorX-(*text).AparX > (*vent).Ancho) {
- text->AparX = text->CursorX-10;
- } else if (text->CursorX < text->AparX) {
- text->AparX = max(text->CursorX - 10, 0);
- }// end if
- PintarTexto(text);
- }// end if
- text->OldX = text->CursorX;
- break;
- }// end case
-
- // Return
- case 13: {
- char caraux[500];
- for(i=(*text).LineaFin; i>= (*text).CursorY; i--)
- (*text).Texte[i+1] = (*text).Texte[i];
- maxx=longitud_cadena( (*text).Texte[ (*text).CursorY]);
- if( (*text).CursorX < maxx) {
- copiar_cadena(caraux,&(car[text->CursorX]));
- car[ text->CursorX]=0;
- } else
- caraux[0] = 0;
- text->Texte[++text->CursorY]= (char *) malloc(longitud_cadena(caraux)+2);
- copiar_cadena(text->Texte[text->CursorY],caraux);
- text->CursorX=0;
- text->AparX=0;
- text->LineaFin++;
- if ( text->CursorY > text->AparY + vent->Alto -3)
- text->AparY++;
- PintarTexto(text);
- text->OldX = text->CursorX;
- break;
- }// end case
-
- case 0xBC: break; // ESC
-
- // TAB
- case 9: {
- int i;
- char caraux[500];
- copiar_cadena(caraux,car);
- for (i=0;i<TabSize;i++) {
- if(TextInsert || (text->CursorX == longitud_cadena(caraux)))
- insertar_caracter(caraux,' ',(*text).CursorX++);
- else
- caraux[text->CursorX++]=' ';
- }// end for
- free(car);
- text->Texte[text->CursorY]=(char *)malloc(longitud_cadena(caraux)+2);
- copiar_cadena(text->Texte[text->CursorY],caraux);
- if( (*text).CursorX - (*text).AparX >= (*vent).Ancho-2 ) {
- (*text).AparX = (*text).CursorX - 10;
- PintarTexto(text);
- } else {
- PonerLinea(text, (*text).CursorY, (*vent).CursorY);
- VentanaGotoXY(vent,(*vent).CursorX+TabSize, (*vent).CursorY);
- }// end if
- (*text).OldX = (*text).CursorX;
- break;
- }// end case
-
-
- case 0xe0: //En caso de que sea el KEYB
- case 0: { //En caso de que sea el NKEYB
- switch(BTRastreo(caracter)) {
-
- case CURSOR_UP: {
- if( (*text).CursorY > 0) {
- (*text).CursorX = (*text).OldX;
- if ( (*vent).CursorY > 0) {
- (*text).CursorY--;
- TextControlaCursorX(text);
- } else {
- (*text).AparY--;
- (*text).CursorY--;
- TextControlaCursorX(text);
- PintarTexto(text);
- }// end if
- }// end if
- break;
- }// end case
-
- case CURSOR_DOWN: {
- if ( (*text).CursorY < (*text).LineaFin) {
- (*text).CursorX= (*text).OldX;
- if( (*vent).CursorY < (*vent).Alto-3 ) {
- (*text).CursorY++;
- TextControlaCursorX(text);
- } else {
- (*text).AparY++;
- (*text).CursorY++;
- TextControlaCursorX(text);
- PintarTexto(text);
- }// end if
- }// end if
- break;
- }// end case
-
- case CURSOR_RIGHT: {
- if ( (*text).CursorX < longitud_cadena( (*text).Texte[(*text).CursorY])) {
- (*text).CursorX++;
- if ( (*text).CursorX - (*text).AparX > (*vent).Ancho ) {
- (*text).AparX += 10;
- PintarTexto(text);
- } else
- VentanaGotoXY(vent,(*vent).CursorX+1,(*vent).CursorY);
- }// end if
- (*text).OldX = (*text).CursorX;
- break;
- }// end case
-
- case CURSOR_LEFT: {
- if( (*text).CursorX > 0 ) {
- (*text).CursorX--;
- if ( (*text).CursorX < (*text).AparX ) {
- (*text).AparX = max((*text).AparX-10,0);
- PintarTexto(text);
- } else {
- VentanaGotoXY(vent, (*vent).CursorX-1, (*vent).CursorY);
- }// end if
- }// end if
- (*text).OldX = (*text).CursorX;
- break;
- }// end case
-
- case INICIO: {
- if( (*text).AparX != 0) {
- (*text).CursorX = 0;
- (*text).AparX = 0;
- PintarTexto (text);
- } else {
- (*text).CursorX = 0;
- VentanaGotoXY( vent, (*text).CursorX - (*text).AparX, (*text).CursorY - (*text).AparY);
- }// end if
- (*text).OldX = (*text).CursorX;
- break;
- }// end case
-
- case FIN: {
- (*text).CursorX = longitud_cadena (car);
- if ( (*text).CursorX > (*text).AparX + (*vent).Ancho -3) {
- (*text).AparX = max( (*text).CursorX - 10, 0);
- PintarTexto(text);
- } else
- VentanaGotoXY(vent, (*text).CursorX - (*text).AparX, (*text).CursorY - (*text).AparY);
- (*text).OldX = (*text).CursorX;
- break;
- }// end case
-
- case AV_PAG: {
- if( (*text).AparY + (*vent).Alto-3 < (*text).LineaFin) {
- (*text).AparY += (*vent).Alto-3;
- (*text).CursorY += (*vent).Alto-3;
- } else
- (*text).CursorY = (*text).LineaFin;
- (*text).CursorX = (*text).OldX;
- TextControlaCursorX(text);
- PintarTexto(text);
- break;
- }// end case
-
- case RE_PAG: {
- if ( (*text).AparY > (*vent).Alto-3) {
- (*text).AparY -= (*vent).Alto-3;
- (*text).CursorY -= (*vent).Alto-3;
- } else
- (*text).AparY = (*text).CursorY = 0;
- (*text).CursorX = (*text).OldX;
- TextControlaCursorX(text);
- PintarTexto(text);
- break;
- }// end case
-
- case SUPR: {
- char caraux[500];
- char *car_post; // La cadena anterior
- if ( (*text).CursorX < longitud_cadena(car)) {
- eliminar_subcadena(car,(*text).CursorX,1);
- PintarTexto(text);
- } else {
- if ((*text).CursorY < (*text).LineaFin) {
- car_post = text->Texte[text->CursorY +1];
- copiar_cadena(caraux,car);
- anadir_cadena(caraux,car_post);
- free(car);
- text->Texte[text->CursorY]=(char *) malloc(longitud_cadena(caraux)+2);
- copiar_cadena(text->Texte[text->CursorY],caraux);
- for(i=text->CursorY + 1;i<(*text).LineaFin;i++)
- text->Texte[i] = text->Texte[i+1];
- text->LineaFin--;
- free(car_post);
- PintarTexto(text);
- }// end if
- }// end if
- text->OldX = text->CursorX;
- break;
- }// end case
-
- // A la pulsación del Insert, pasamos de modo inserción
- // a modo sobreescritura y viceversa.
- case INSERT:
- TextInsert = NOT(TextInsert);
- // end case
-
- }// end switch
- break;
- }// end case
-
- // case CAPS_LOCK: {
- // }// end case
-
- default: {
- char caraux[500];
- copiar_cadena(caraux,car);
- if(TextInsert || (text->CursorX == longitud_cadena(caraux)))
- insertar_caracter(caraux,BTAscii(caracter),(*text).CursorX++);
- else
- caraux[text->CursorX++]=BTAscii(caracter);
- free(car);
- text->Texte[text->CursorY]=(char *)malloc(longitud_cadena(caraux)+2);
- copiar_cadena(text->Texte[text->CursorY],caraux);
- if( (*text).CursorX - (*text).AparX >= (*vent).Ancho-2 ) {
- (*text).AparX = (*text).CursorX - 10;
- PintarTexto(text);
- } else {
- PonerLinea(text, (*text).CursorY, (*vent).CursorY);
- VentanaGotoXY(vent,(*vent).CursorX+1, (*vent).CursorY);
- }// end if
- (*text).OldX = (*text).CursorX;
- break;
- }// end case
- }// end switch
- break;
- }// end case
-
-
- case V_BARRA_ARRIBA: {
- while(estado == BUTTON_LEFT) {
- EventIddleExecution();
- EventMouseFastExecution();
- if( (*text).AparY > 0) {
- (*text).AparY--;
- if ( (*text).CursorY > (*text).AparY + (*vent).Alto -3)
- (*text).CursorY--;
- PintarTexto(text);
- }// end if
- }// end while
- (*text).CursorX = (*text).OldX;
- TextControlaCursorX(text);
- PintarTexto(text);
- break;
- }// end case
-
- case V_BARRA_ABAJO: {
- while(estado == BUTTON_LEFT) {
- EventIddleExecution();
- EventMouseFastExecution();
- if( (*text).AparY < (*text).LineaFin) {
- (*text).AparY++;
- if( (*text).CursorY < (*text).AparY)
- (*text).CursorY++;
- PintarTexto(text);
- }// end if
- }// end while
- (*text).CursorX = (*text).OldX;
- TextControlaCursorX(text);
- PintarTexto(text);
- break;
- }// end case
-
- case V_BARRA_BOTON: {
- oldmousey = mousey;
- while( estado == BUTTON_LEFT) {
- // Hacemos que la ejecución de eventos rápidos sea posible.
- EventIddleExecution();
- EventMouseFastExecution();
- if( mousey != oldmousey) {
- if(mousey>>3 < vent->PosY + vent->Alto - 3)
- if(mousey>>3 > vent->PosY + 3)
- text->AparY = ((mousey>>3) -vent->PosY -4) *text->LineaFin /(vent->Alto -8);
- PintarTexto(text);
- oldmousey = mousey;
- }// end if
- }// end while
- text->CursorX = 0;
- text->CursorY = text->AparY;
- text->OldX = text->CursorX;
- PintarTexto(text);
- break;
- }// end case
-
- case H_BARRA_IZQUIERDA: {
- while( estado == BUTTON_LEFT) {
- EventIddleExecution();
- EventMouseFastExecution();
- if( (*text).AparX > 0) {
- (*text).AparX--;
- PintarTexto(text);
- }// end if
- }// end while
- if( (*text).CursorX > (*text).AparX + (*vent).Ancho-3)
- (*text).CursorX = (*text).AparX + (*vent).Ancho -3;
- PintarTexto(text);
- (*text).OldX = (*text).CursorX;
- break;
- }// end case
-
- case H_BARRA_DERECHA:
- while(estado == BUTTON_LEFT) {
- EventIddleExecution();
- EventMouseFastExecution();
- if( (*text).AparX < (*text).AnchoLinea) {
- (*text).AparX ++;
- PintarTexto(text);
- }// end if
- }// end while
- maxx = longitud_cadena( (*text).Texte[(*text).CursorY]);
- if( (*text).CursorX < (*text).AparX)
- (*text).CursorX = (*text).AparX;
- (*text).CursorX = min( (*text).CursorX, maxx);
- if( (*text).CursorX < (*text).AparX)
- (*text).AparX = max( (*text).CursorX -10, 0);
- PintarTexto(text);
- (*text).OldX = (*text).CursorX;
- break;
-
- case H_BARRA_BOTON: {
- }// end case
-
- case CERRAR:
- VentanaCerrar(vent);
- TDestruye(text);
- break;
-
- case AMPLIAR:
- break;
-
- case MODIFICAR:
- VentanaModificar();
- (*text).CursorX=(*text).AparX;
- (*text).CursorY=(*text).AparY;
- PintarTexto(text);
- (*text).OldX = (*text).CursorX;
- break;
-
- case MOVER:
- VMoverPantalla();
- break;
-
- case CAMBIAR:
- VCambiarPrincipal(caracter);
- mouse_evento=PULSAR_IZQUIERDO;
- EventMouseSkipExecution(); // Si queremos hacer varias cosas hay que hacerlo asi.
- break;
-
- case PULSAR_VENTANA:
- posx -= (*vent).PosX+1;
- posy -= (*vent).PosY+1;
- if ( (posy >= 0)
- && (posy < (*vent).PosY + (*vent).Alto -3)
- && (posx >= 0)
- && (posx < (*vent).PosX + (*vent).Ancho -2)
- && (posy + (*text).AparY <= (*text).LineaFin ) ) {
- (*text).CursorY= (*text).AparY + posy;
- if ( (*text).AparX > longitud_cadena((*text).Texte[(*text).CursorY]) ) {
- (*text).CursorX= longitud_cadena((*text).Texte[(*text).CursorY]);
- (*text).AparX = max( (*text).CursorX -10, 0);
- PintarTexto(text);
- } else {
- (*text).CursorX = min( (*text).AparX + posx, longitud_cadena((*text).Texte[(*text).CursorY]));
- VentanaGotoXY(vent, (*text).CursorX - (*text).AparX, (*text).CursorY - (*text).AparY);
- }// end if
- while (estado == BUTTON_LEFT) {
- if( ((mousex >>3)!=posx+vent->PosX+1) || (mousey>>3)!=posy+vent->PosY+1) {
- if (BTexto != text)
- PintarTexto(BTexto);
- BTexto=text;
- BIniX = text->CursorX;
- BIniY = text->CursorY;
- BFinY = (mousey >> 3) - (vent->PosY +1) +text->AparY;
- BFinX = (mousex >> 3) - (vent->PosX +1) +text->AparX;
- if( BFinY > text->LineaFin)
- BFinY = text->LineaFin;
- if( BFinX > longitud_cadena(text->Texte[BFinY]) )
- BFinX = longitud_cadena(text->Texte[BFinY]);
- posx = mousex >> 3;
- posy = mousey >> 3;
- PintarTexto(text);
- }// end if
- }// end while
- }// end if
- (*text).OldX = (*text).CursorX;
- break;
-
- }// end switch
- return(TEXTO2_TODO_OK);
- }// end TextEvent
-
-
- // Esta función controla el uso del ratón sobre el texto
- // NOTA: Se pone en la pila de ejecución de eventos del raton
- // ──────────────────────────────────────────────────────────
- void far TrataTextoRaton(void)
- {
- Texto2 *text;
- int a,v_auxiliar;
- if( (*TopeVentanas).TipoVentana == V_TEXTO) {
- a=EvntVentanas(&v_auxiliar);
- if(a) {
- text = (Texto2 *) (*TopeVentanas).Apuntador;
- TextEvent(text, a, v_auxiliar);
- TextoPonerCoordenadas(text);
- }// end if
- }// end if
- }// end TrataTextoRaton
-
-
- // Esta función trata todos los eventos de teclado que se producen sobre
- // un texto
- // NOTA: Se pone en la pila de ejecución de eventos de teclado
- // ─────────────────────────────────────────────────────────────────────
- void far TrataTextoTeclado(void)
- {
- Texto2 *text;
- if( (*TopeVentanas).TipoVentana == V_TEXTO) {
- text = (Texto2 *) (*TopeVentanas).Apuntador;
- TextEvent(text,PULSAR_TECLA,EventTecla);
- TextoPonerCoordenadas(text);
- }// end if
- }// end TrataTextoTeclado
-
-
- // Esta función se encarga de inicializar el sistema de textos
- // NOTA: Se ejecuta una vez al principio y nunca más
- // ───────────────────────────────────────────────────────────
- void TextoInicializar(void)
- {
- EventEmpilaKeyboardRutina(TrataTextoTeclado);
- EventEmpilaMouseRutina(TrataTextoRaton);
- ListaGenerica2Anula(Macros);
- }// end InicializarTexto
-
- #endif
-