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

📄 filedlg.c

📁 在ecos 下mingui 的移植开发
💻 C
📖 第 1 页 / 共 2 页
字号:
//// $Id: filedlg.c,v 1.4 2000/11/13 08:40:52 ymwei Exp $// // filedlg.c: Open File Dialog.// // Copyright (C) 2000, FrankXM// Copyright (C) 2000, BluePoint Software.//// Current maintainer: Leon//// Create date: 2000.xx.xx// ------------------------------------------------------ // This FileDialog is based on the one wrote by FrankXM// and Modified greatly by leon// -------------------------------------------------------// main changes:// -------------------------------------------------------// 		1, change the layout of dialog// 		2, add the 'wildchar' matching // 		   and change other parts accordingly/***  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*///// Modify records:////  Who             When        Where       For What                Status//-----------------------------------------------------------------------------//// TODO://#include <stdio.h>#include <stdlib.h>#include <stdarg.h>#include <string.h>#include <pthread.h>#include <semaphore.h>#include <sys/stat.h>#include <sys/types.h>#include <unistd.h>#include <errno.h>#ifndef __ECOS# include <pwd.h>#else# include <sys/stat.h>#endif#include "common.h"#include "minigui.h"#include "gdi.h"#include "window.h"#include "control.h"#include "filedlg.h"#define IDC_HOME 			500#define IDC_UP  		 	501#define IDC_DIRCHOISE  		503#define IDC_FILECHOISE  	504#define IDC_FULLFILENAME 	505#define IDC_FILTER 			506#define IDC_PATH  			600CTRLDATA WinFileCtrl [] ={ 	{ "static", WS_VISIBLE | SS_LEFT,        8, 23, 80, 20, IDC_STATIC, "选择目录", 0 },    { "static", WS_VISIBLE | SS_LEFT,        120, 23, 80, 20, IDC_STATIC, "选择文件", 0 },    { "button", WS_VISIBLE | WS_TABSTOP ,        200, 18, 22, 20, IDC_HOME, "Hm", 0 },    { "button", WS_VISIBLE | WS_TABSTOP ,        250, 18, 22, 20, IDC_UP, "Up", 0 },	{ "listbox", WS_VISIBLE | WS_TABSTOP | LBS_NOTIFY | WS_VSCROLL | WS_BORDER,        8, 40, 100, 120, IDC_DIRCHOISE, NULL, 0 },    { "listbox",WS_VISIBLE | WS_TABSTOP | LBS_NOTIFY | WS_VSCROLL | WS_BORDER,        120, 40, 200, 120, IDC_FILECHOISE, NULL, 0 },		    { "static", WS_VISIBLE | SS_LEFT,        8, 174, 80, 18, IDC_STATIC, "当前路径", 0 },	{ "static", WS_VISIBLE | SS_LEFT,        8, 187, 310, 13, IDC_PATH, "", 0 },    { "static", WS_VISIBLE | SS_LEFT,        8, 208, 40, 20, IDC_STATIC, "文件", 0 },    { "sledit",WS_VISIBLE | WS_TABSTOP | LBS_NOTIFY | WS_BORDER,        36, 206, 180, 18, IDC_FULLFILENAME, NULL, 0 },		{ "button", WS_VISIBLE | BS_DEFPUSHBUTTON | WS_TABSTOP | WS_GROUP,        230, 200, 40, 24, IDOK, "确认", 0 },    { "button", WS_VISIBLE | BS_PUSHBUTTON | WS_TABSTOP,        280, 200, 40, 24, IDCANCEL, "取消", 0 }};static int fitquestion (char *ptn, char *target);// filter begin  /////////////////////////////////////////////////////// match after a '*'static int fitstar (char *ptn, char *target){	char a[50];	char *str = a;	int i, j, k, dismatch;	for (i=0; (ptn[i] != '*' && ptn[i] != '?' && ptn[i] != '\0'); i++) 		str[i] = ptn[i];	if (i ==0) {		//'\0' ok!		if (ptn[0] == '\0')			return 0;		if (ptn[0] == '*')			return fitstar (ptn +1, target);		//'?..' 		if (ptn[0] == '?') {			if (target[0] == '\0')				return 2;			else				return fitstar (ptn+1, target+1);		}	}			//otherwise give it a 'end'	str[i] ='\0';		j = 0;	while (target[j+i-1] != '\0') {		dismatch = 0;		for (k=0; k<i; k++)			if (str[k] != target[j+k]) {				dismatch = 1;				break;			}		if (dismatch){			j++;			continue;		}		if (ptn[i] == '\0') {			if (target[i+j] == '\0')				return 0;			else {				j++;				continue;			}		}		if (ptn[i] == '*') {			if (fitstar (ptn+i+1, target+j+k) == 0)				return 0;		}else if (ptn[i] == '?') {			if (target[j+k] == '\0')				return 2;			else if (ptn[i+1] == '\0') {				if (target[j+k+1] == '\0')					return 0;				else 					//ptn shorter than target, and the forepart is fit					return 1;			}else				if (fitquestion (ptn+i+1, target+j+k+1) == 0)					return 0;		}		j++;	}	return 2;}// match after a '?'static int fitquestion (char *ptn, char *target){	char a[50];	char *str = a;	int i, j;	for (i=0; (ptn[i] != '*' && ptn[i] != '?' && ptn[i] != '\0'); i++)		str[i] = ptn[i];	if (i ==0) {		//'\0' ok!		if (ptn[0] == '\0') {			if (target[0] == '\0')				return 0;			else				//ptn not long enough!				return 1;		}		if (ptn[0] == '*') 			return fitstar (ptn+1, target);		if (ptn[0] == '?') {			if (target[0] == '\0')				return 2;			else				return fitquestion (ptn+1, target +1);		}	}	str[i] ='\0';	//must fit on the head	for (j=0; j<i; j++){		if (str[j] != target[j])			return 2;	}	if (ptn[i] == '*')		return fitstar (ptn+i+1, target+i);	else {		return fitquestion (ptn+i, target+i);	}}/*//////	return value:		0: matches		1: ptn fites the forepart of target, but not long enough		2: unmatches*///////static int filter( char *ptn, char *target){	if (ptn[0] == '*')		return fitstar (ptn+1, target);	else		return fitquestion (ptn, target);}//filter   end///////////////////////////////////////////////////////////////////static char* GetParentDir (char *dir){    int i, nParent = 0;    for (i = 0; i < strlen (dir) -1; i++)        if (dir [i] == '/')             nParent = i;    dir [nParent + 1] = 0;           return dir;}static void myWinFileListDirWithFilter ( HWND hWnd, int dirListID, int fileListID, char* path, char* filtstr){    struct 	dirent* pDirEnt;    DIR* 	dir;    struct 	stat ftype;    char 	fullpath [PATH_MAX + 1];	int 	i; 	SendDlgItemMessage (hWnd, IDC_DIRCHOISE, LB_RESETCONTENT, 0, (LPARAM)0);	SendDlgItemMessage (hWnd, IDC_FILECHOISE, LB_RESETCONTENT, 0, (LPARAM)0);    SetWindowText (GetDlgItem (hWnd, IDC_PATH), path);    	dir = opendir (path);    while ( (pDirEnt = readdir ( dir )) != NULL ) {        // Assemble full path name.		strncpy (fullpath, path, PATH_MAX);        strcat (fullpath, "/");        strcat (fullpath, pDirEnt->d_name);        #ifndef __ECOS        if (lstat (fullpath, &ftype) < 0 ){#else        if ( stat (fullpath, &ftype) < 0 ){#endif        	           Ping();           continue;        }        if (S_ISDIR (ftype.st_mode))            SendDlgItemMessage (hWnd, dirListID, LB_ADDSTRING,						   	0, (LPARAM)pDirEnt->d_name);        else if (S_ISREG(ftype.st_mode)) {			if (filtstr != NULL) {				i = filter (filtstr, pDirEnt->d_name);				if (i == 0 /*|| i == 1 // when responding to the EN_TAB message later*/)					SendDlgItemMessage (hWnd, fileListID, LB_ADDSTRING,								   	0, (LPARAM)pDirEnt->d_name);

⌨️ 快捷键说明

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