⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 medit.c

📁 在ecos 下mingui 的移植开发
💻 C
📖 第 1 页 / 共 5 页
字号:
// $Id: medit.c,v 1.26 2000/11/28 04:39:24 ymwei Exp $//// edit.c: the Multi-Line Edit Control module.//// Copyright (C) 1999, 2000, Wei Yongming.// Copyright (C) 2000, BluePoint Software.// // Current maintainer: Chen Lei (chenlei@minigui.org).///***  This library is free software; you can redistribute it and/or**  modify it under the terms of the GNU Library General Public**  License as published by the Free Software Foundation; either**  version 2 of the License, or (at your option) any later version.****  This library is distributed in the hope that it will be useful,**  but WITHOUT ANY WARRANTY; without even the implied warranty of**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU**  Library General Public License for more details.****  You should have received a copy of the GNU Library General Public**  License along with this library; if not, write to the Free**  Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,**  MA 02111-1307, USA*//***  Alternatively, the contents of this file may be used under the terms **  of the Mozilla Public License (the "MPL License") in which case the**  provisions of the MPL License are applicable instead of those above.*/// Create date: 1999/8/26//// Modify records:////  Who             When        Where       For What                Status//-----------------------------------------------------------------------------//  WEI Yongming    2000/02/24  Tsinghua    Add MPL License         Finished//  leon            2000/11/07  BJ         	Optimize display        Finished//  leon            2000/11/07  BJ          Fix bugs                Finished//// TODO://    * Selection.//    * Undo.#include <stdio.h>#include <stdlib.h>#include <pthread.h>#include <semaphore.h>#include "common.h"#include "minigui.h"#include "gdi.h"#include "window.h"#include "control.h"#include "cliprect.h"#include "internals.h"#include "ctrlclass.h"#include "ctrlmisc.h"#include "medit.h"#ifndef lintstatic char fileid[] = "$Id: medit.c,v 1.26 2000/11/28 04:39:24 ymwei Exp $";#endifint MLEditCtrlProc (HWND hWnd, int message, WPARAM wParam, LPARAM lParam);BOOL RegisterMLEditControl (void){    // This control class has two names: "medit" and "mledit"    WNDCLASS WndClass;    WndClass.spClassName    = "medit";    WndClass.dwStyle        = 0;    WndClass.hCursor        = GetSystemCursor (IDC_IBEAM);    WndClass.iBkColor       = PIXEL_lightwhite;    WndClass.WinProc        = MLEditCtrlProc;    if (AddNewControlClass (&WndClass) != ERR_OK)        return FALSE;    WndClass.spClassName    = "mledit";    WndClass.dwStyle        = 0;    WndClass.hCursor        = GetSystemCursor (IDC_IBEAM);    WndClass.iBkColor       = PIXEL_lightwhite;    WndClass.WinProc        = MLEditCtrlProc;    return AddNewControlClass (&WndClass) == ERR_OK;}void MLEditControlCleanup (void){    // do nothing    return;}static inline int edtGetOutWidth (HWND hWnd){	PMLEDITDATA pMLEditData =(PMLEDITDATA) GetWindowAdditionalData2(hWnd);	RECT rc;	GetClientRect(hWnd,&rc);    return rc.right - rc.left             - pMLEditData->leftMargin            - pMLEditData->rightMargin;}static void edtGetLineInfo (HWND hWnd, PLINEDATA pLineData){	PMLEDITDATA pMLEditData =(PMLEDITDATA) GetWindowAdditionalData2(hWnd);	HDC			hdc = GetClientDC (hWnd);	/*	fprintf (stderr, "<===== In 111=====>\n");	fprintf (stderr, "buffer = %s\n", pLineData->buffer);	fprintf (stderr, "fit_chars = %d\n", pMLEditData->fit_chars);	fprintf (stderr, "pos_chars = %p\n", pMLEditData->pos_chars);	fprintf (stderr, "dx_chars = %p\n", pMLEditData->dx_chars);	fprintf (stderr, "sz.cx = %d\n", pMLEditData->sz.cx);	*/    if (pMLEditData->logfont)        SelectFont (hdc, pMLEditData->logfont);	GetTextExtentPoint (hdc,				   		pLineData->buffer, 						pLineData->dataEnd,  						GetMaxFontWidth (hdc)*LEN_MLEDIT_BUFFER,				        &(pMLEditData->fit_chars), 						pMLEditData->pos_chars, 						pMLEditData->dx_chars, 						&(pMLEditData->sz));	ReleaseDC (hdc);		pMLEditData->pos_chars[pMLEditData->fit_chars] = pLineData->dataEnd;	pMLEditData->dx_chars[pMLEditData->fit_chars] = pMLEditData->sz.cx;		/*	fprintf (stderr, "<===== In 222 =====>\n");	fprintf (stderr, "buffer = %s\n", pLineData->buffer);	fprintf (stderr, "fit_chars = %d\n", pMLEditData->fit_chars);	fprintf (stderr, "pos_chars = %d\n", pMLEditData->pos_chars[pMLEditData->fit_chars]);	fprintf (stderr, "dx_chars = %d\n", pMLEditData->dx_chars[pMLEditData->fit_chars]);	fprintf (stderr, "sz.cx = %d\n", pMLEditData->sz.cx);	*/}static int edtGetStartDispPosAtEnd (HWND hWnd,            PLINEDATA pLineData){	PMLEDITDATA pMLEditData =(PMLEDITDATA) GetWindowAdditionalData2(hWnd);	//HDC			hdc;	int			i = 0;	int 		dist = MAX_IMPOSSIBLE;	int 		newdist = 0;		/*	fprintf (stderr, "<===== In edtGetStartDispPosAtEnd =====>\n");	fprintf (stderr, "buffer = %s\n", pLineData->buffer);	*/	edtGetLineInfo (hWnd, pLineData);	/*	fprintf (stderr, "cx= %d\n", pMLEditData->sz.cx);	fprintf (stderr, "width= %d\n", edtGetOutWidth (hWnd));	*/	if (pMLEditData->sz.cx <= edtGetOutWidth (hWnd)) 		return 0;		//fprintf (stderr, "last unit  = %d\n", pMLEditData->pos_chars[pMLEditData->fit_chars]);		for (i = 0; i < pMLEditData->fit_chars-1; i++) {		newdist = (pMLEditData->sz.cx - edtGetOutWidth (hWnd)) - pMLEditData->dx_chars[i];		if (newdist >= 0 && newdist < dist) {			dist = newdist;			if (dist == 0) {				//fprintf (stderr, "return : %d\n", i);				//return pMLEditData->pos_chars[i];				return i;			} 		}else { 				//fprintf (stderr, "return : %d\n", i);			//return pMLEditData->pos_chars[i];			return i;		}	}	return 0;}#if 0static int edtGetDispLen (HWND hWnd,PLINEDATA pLineData){    int i, n = 0;    int nOutWidth = edtGetOutWidth (hWnd);    int nTextWidth = 0;	PMLEDITDATA pMLEditData =(PMLEDITDATA) GetWindowAdditionalData2(hWnd);    const char* buffer = pLineData->buffer;	if(buffer[0]==0||pLineData->dataEnd<pMLEditData->dispPos)		return 0;	    for (i = pMLEditData->dispPos; i < pLineData->dataEnd; i++) {        if ((BYTE)buffer [i] > 0xA0) {            i++;            if (i < pLineData->dataEnd) {                if ((BYTE)buffer [i] > 0xA0) {                    nTextWidth += GetSysCCharWidth ();                    n += 2;                }                else                    i--;            }            else {                nTextWidth += GetSysCharWidth ();                n++;            }        }        else {            nTextWidth += GetSysCharWidth ();            n++;        }        if (nTextWidth > nOutWidth)            break;    }    return n;}static int edtGetOffset (const MLEDITDATA* pMLEditData, PLINEDATA pLineData, int x){    int i;    int newOff = 0;    int nTextWidth = 0;    const char* buffer = pLineData->buffer;	if(pLineData->dataEnd<pMLEditData->dispPos)		return pLineData->dataEnd;    x -= pMLEditData->leftMargin;    for (i = pMLEditData->dispPos; i < pLineData->dataEnd; i++) {        if ((nTextWidth + (GetSysCharWidth() >> 1)) >= x)            break;        if ((BYTE)buffer [i] > 0xA0) {            i++;			if (nTextWidth + GetSysCCharWidth()/2 >= x)				break;            if (i < pLineData->dataEnd) {                if ((BYTE)buffer [i] > 0xA0) {                    nTextWidth += GetSysCCharWidth ();                    newOff += 2;                }                else                    i --;            }            else {                nTextWidth += GetSysCharWidth ();                newOff ++;            }        }        else {            nTextWidth += GetSysCharWidth ();            newOff ++;        }    }    return newOff;}#endifstatic int edtGetLineNO (const MLEDITDATA* pMLEditData, int x){    int nline = 0;	if(x>=0)	{	    nline = x / GetSysCharHeight();		if (nline <= pMLEditData->linesDisp)   			return nline;	}	return -1;}#if 0static BOOL edtIsACCharBeforePosition (const char* string, int pos){    if (pos < 2)        return FALSE;    if ((BYTE)string [pos - 2] > 0xA0 && (BYTE)string [pos - 1] > 0xA0)        return TRUE;    return FALSE;}static BOOL edtIsACCharAtPosition (const char* string, int len, int pos){    if (pos > (len - 2))        return FALSE;    if ((BYTE)string [pos] > 0xA0 && (BYTE)string [pos + 1] > 0xA0)        return TRUE;    return FALSE;}static BOOL edtIsACCharFromBegin(const char* string,int len,int pos){	int i;	if(pos == 0)		return TRUE;	if(len == 0)		return FALSE;	for(i=0;i<len;)	{		if( edtIsACCharAtPosition(string,len,i) )			i += 2;		else 			i++;		if(i==pos)			return TRUE;	}	return FALSE;}#endifint GetRETURNPos(char *str){	int i;	for(i=0;i<strlen(str);i++)	{			if(str[i]==10)			return i;	}	return -1;}void MLEditEmptyBuffer(PMLEDITDATA pMLEditData){    PLINEDATA temp;    PLINEDATA  pLineData;    pLineData = pMLEditData->head;    while(pLineData)    {        temp = pLineData->next;        free(pLineData);        pLineData = temp;    }    pMLEditData->head = NULL;}void MLEditInitBuffer (PMLEDITDATA pMLEditData, const char *spcaption){	char *caption=(char*)spcaption;     int off1;	int lineNO=0;	PLINEDATA  pLineData;	if (!(pMLEditData->head = malloc (sizeof (LINEDATA)))) {		//fprintf (stderr, "EDITLINE: malloc error!\n");		return ;	}	pMLEditData->head->previous = NULL;	pLineData=pMLEditData->head;		while ( (off1 = GetRETURNPos(caption)) != -1)	{		off1 = min(off1, LEN_MLEDIT_BUFFER);		memcpy(pLineData->buffer,caption,off1);		pLineData->buffer[off1] = '\0';		caption+=min(off1,LEN_MLEDIT_BUFFER)+1;		pLineData->lineNO  = lineNO;		pLineData->dataEnd = strlen(pLineData->buffer); 		pLineData->next    = malloc (sizeof (LINEDATA));		pLineData->next->previous = pLineData; 		pLineData = pLineData->next;		lineNO++;	}		off1 = min(strlen(caption),LEN_MLEDIT_BUFFER);	memcpy(pLineData->buffer,caption,off1);	pLineData->buffer[off1] = '\0';	pLineData->lineNO  = lineNO++;	pMLEditData->vdispPos = 0;	pLineData->dataEnd = strlen(pLineData->buffer); 	pLineData->next    = NULL; 	pMLEditData->lines      = lineNO ; /*add by frankch to fix the bug of display lines */	pMLEditData->StartlineDisp = 0;	pMLEditData->linesDisp =  min(lineNO , pMLEditData->MaxlinesDisp);	pMLEditData->EndlineDisp = pMLEditData->StartlineDisp + pMLEditData->linesDisp -1;/*add finished */}PLINEDATA GetLineData(PMLEDITDATA pMLEditData,int lineNO){	PLINEDATA pLineData=pMLEditData->head;	while(pLineData)	{		if(pLineData->lineNO==lineNO)			return pLineData;		pLineData = pLineData->next;	}	return NULL;}// added by leon to optimize displayint GetMaxCol (HWND hWnd)//Mneeded{

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -