📄 dfb_wzm.cpp
字号:
#include "wzm.h"
int DFBDisplay::DrawInfo( const int &i )
{
struct dirent **namelist;
struct stat mode;
char buf[MAXNUM];
int n = 0, num, start;
lpage = i;
start = i*19;
getcwd( buf, sizeof( buf ));
surfacel->Clear( surfacel, 0xff, 0xff, 0xff, 0xff );
num = scandir(".", &namelist, 0, alphasort);
if (num < 0)
{
perror("scandir");
return 1;
}
else
{
lnums = 0;
while( n <= num-1 && lnums < 20 )
{
lstrs[lnums] = namelist[n]->d_name;
free(namelist[n]);
n++;
if( n <= start )
continue;
sprintf( buf, "[%02d] %s", lnums+1, lstrs[lnums].c_str() );
GB2312ToUTF8( buf );
if( lnums+1 == llines )
surfacel->SetColor( surfacel, 0x60, 0xf0, 0xf0, 0xf0 );
else
surfacel->SetColor( surfacel, 0xff, 0xff, 0xff, 0xff );
surfacel->FillRectangle( surfacel, 0, fontheigh*lnums+2, linewidth-5, fontheigh+3 );
if( stat( lstrs[lnums].c_str(), &mode ) < 0 )
continue;
if( S_ISDIR( mode.st_mode ) )
surfacel->SetColor( surfacel, 0xFF, 0x60, 0x60, 0x60 );
else
surfacel->SetColor( surfacel, 0x60, 0x60, 0x60, 0xFF );
surfacel->DrawString( surfacel, buf, -1, 0, fontheigh*(lnums+1), DSTF_LEFT );
lnums++;
}
free(namelist);
}
surfacel->Flip( surfacel, NULL, DSFLIP_NONE );
if( lnums >= 20 )
lnums = 19;
if( num - start > 18 )
lnext = true;
else
lnext = false;
return 0;
}
int DFBDisplay::DrawDir( string &dir )
{
char local[MAXNUM];
char serv[MAXNUM];
int i,j;
try
{
if( dir.empty() )
dir = serdir;
else
serdir = dir;
i = dir.find_first_of( "\"", 0 );
j = dir.find_last_of( "\"", dir.length());
if( getcwd( serv, MAXNUM ) < 0 )
return 1;
sprintf( local, "本地:[%s]", serv );
if( i != j )
sprintf( serv, "服务:[%s]", dir.substr( i+1, j-i-1 ).c_str() );
}
catch( ... )
{
ERR( "DrawDir [%s] [%s]", local, serv );
return 2;
}
if( strlen(local)+strlen(serv) >= MAXNUM/2 || i == j )
{
getcwd( serv, MAXNUM );
sprintf( local, "[%s][%s]", serv, dir.substr( i+1, j-i-1 ).c_str() );
if( i == j )
sprintf( local, "%s", dir.c_str() );
GB2312ToUTF8( local );
surfaceu->Clear( surfaceu, 0xf0, 0xf0, 0xff, 0xff );
surfaceu->SetColor( surfaceu, 0x60, 0x60, 0x60, 0xFF );
surfaceu->DrawString( surfaceu, local, -1, 0, fontheigh, DSTF_LEFT );
}
else
{
GB2312ToUTF8( local );
GB2312ToUTF8( serv );
surfaceu->Clear( surfaceu, 0xf0, 0xf0, 0xff, 0xff );
surfaceu->SetColor( surfaceu, 0x60, 0x60, 0x60, 0xFF );
surfaceu->DrawString( surfaceu, local, -1, 0, fontheigh, DSTF_LEFT );
surfaceu->SetColor( surfaceu, 0xf0, 0xf0, 0xff, 0xff );
surfaceu->FillRectangle( surfaceu, linewidth, 0, linewidth, fontheigh+3 );
surfaceu->SetColor( surfaceu, 0x60, 0x60, 0x60, 0x60 );
surfaceu->DrawString( surfaceu, serv, -1, linewidth, fontheigh, DSTF_LEFT );
}
surfaceu->Flip( surfaceu, NULL, DSFLIP_NONE );
return 0;
}
int DFBDisplay::DrawCmd( const char *buffer )
{
surfaced->Clear( surfaced, 0x60, 0xff, 0xff, 0xff );
if( buffer != NULL )
{
char *p = (char *)calloc( strlen(buffer), 3 );
if( !p )
return 1;
strcpy( p, buffer );
GB2312ToUTF8( p );
surfaced->DrawString( surfaced, p, -1, 0, fontheigh, DSTF_LEFT );
}
surfaced->Flip( surfaced, NULL, DSFLIP_NONE );
return 0;
}
int DFBDisplay::DrawLine( const char *buffer, const int &line, const bool &flg )
{
int y;
if( line <= 0 )
return 1;
else
{
y = line*fontheigh;
if( flg )
surfacer->SetColor( surfacer, 0x60, 0xf0, 0xf0, 0xf0 );
else
surfacer->SetColor( surfacer, 0xff, 0xff, 0xff, 0xff );
if( fileflg )
surfacer->FillRectangle( surfacer, 0, y-fontheigh+2, linewidth, fontheigh+3 );
else
surfacer->FillRectangle( surfacer, 0, y-fontheigh+2, linewidth*2, fontheigh+3 );
if( buffer != NULL )
{
if( !strncmp ( buffer, "d", 1 ) && fileflg )
surfacer->SetColor( surfacer, 0xFF, 0x60, 0x60, 0x60 );
else
surfacer->SetColor( surfacer, 0x60, 0x60, 0x60, 0xFF );
char *p = (char *)calloc( strlen(buffer), 3 );
if( !p )
return 2;
sprintf( p, "[%02d] %s", line, buffer );
GB2312ToUTF8( p );
surfacer->DrawString( surfacer, p, -1, 0, y, DSTF_LEFT );
}
}
return 0;
}
void DFBDisplay::ExeLine()
{
char buffer[MAXNUM];
int pos;
try
{
pos = strs[lines-1].find_last_of( " ", strs[lines-1].length() );
sprintf( buffer, "%s", strs[lines-1].substr( pos+1, -1 ).c_str());
cleartail( buffer );
if( !strcmp( buffer, ".") )
{
sprintf( buf, "list" );
page = 0;
}
else if( !strcmp( buffer, "..") )
sprintf( buf, "scwd ..");
else if( !strcmp ( strs[lines-1].substr(0,1).c_str(), "d" ))
sprintf( buf, "scwd %s", buffer );
else
sprintf( buf, "retr %s", buffer );
}
catch( ... )
{
ERR( "DFBDisplay::ExeLine [%s] error!", buffer );
sprintf( buf, "list" );
page = 0;
}
lines = 1;
page = 0;
}
void DFBDisplay::cleartail( char *buf )
{
int strlong = 0;
strlong = strlen(buf);
while( (buf[strlong] == '\r' || buf[strlong] == '\n' || buf[strlong] == '\0') && strlong > 0 )
buf[strlong--] = '\0';
}
void DFBDisplay::Exchange( const bool &flg )
{
int y = fontheigh+3;
surfaceu->SetColor( surfaceu, 0xff, 0xff, 0xff, 0xFF );
if( fileflg )
{
if( flg )
surfaceu->FillRectangle( surfaceu, linewidth, y, linewidth, 2 );
else
surfaceu->FillRectangle( surfaceu, 0, y, linewidth-5, 2 );
surfaceu->SetColor( surfaceu, 0x60, 0x60, 0x60, 0xFF );
if( flg )
surfaceu->FillRectangle( surfaceu, 0, y, linewidth, 2 );
else
surfaceu->FillRectangle( surfaceu, linewidth-5, y, linewidth+5, 2 );
}
else
{
surfaceu->FillRectangle( surfaceu, 0, y, linewidth*2, 2 );
surfaceu->SetColor( surfaceu, 0x60, 0x60, 0x60, 0xFF );
}
surfaceu->Flip( surfaceu, NULL, DSFLIP_NONE );
}
int DFBDisplay::EvtSpecial( DFBWindowEvent &evt )
{
if( evt.window_id == lid )
{
Exchange( true );
if( evt.key_symbol == DIKS_CURSOR_UP )
{
llines--;
if( (llines <= 0) && (lpage >= 1) )
{
lpage--;
llines = 19;
}
else if( llines <= 0)
llines = 1;
}
if( evt.key_symbol == DIKS_CURSOR_DOWN )
{
llines++;
if( (llines > lnums) && (lpage >= 0) && lnext )
{
lpage++;
llines = 1;
}
else if( llines >= lnums )
llines = lnums;
}
if( evt.key_symbol == DIKS_END && fileflg )
{
struct stat mode;
if( stat( lstrs[llines-1].c_str(), &mode ) < 0 )
{
sprintf( buf, "lcwd" );
return 1;
}
if( S_ISDIR( mode.st_mode ) )
{
sprintf( buf, "lcwd %s", lstrs[llines-1].c_str() );
llines = 1;
lpage = 0;
}
else
sprintf( buf, "stor %s", lstrs[llines-1].c_str() );
return 2;
}
if( lpage >= 1 && evt.key_symbol == DIKS_PAGE_UP && fileflg )
{
lpage--;
llines = 19;
}
if( lpage >= 0 && lnext && evt.key_symbol == DIKS_PAGE_DOWN && fileflg )
{
lpage++;
llines = 1;
}
if( DrawInfo( lpage ) )
ERR( "输出本地文件信息失败!" );
}
else
{
Exchange( false );
if( evt.key_symbol == DIKS_CURSOR_UP )
{
lines--;
if( (lines <= 0) && (page >= 1) )
{
page--;
lines = 19;
}
else if( lines <= 0)
lines = 1;
}
if( evt.key_symbol == DIKS_CURSOR_DOWN )
{
lines++;
if( (lines > nums) && (page >= 0) && next )
{
page++;
lines = 1;
}
else if( lines >= nums )
lines = nums;
}
if( evt.key_symbol == DIKS_END && fileflg )
{
ExeLine();
return 3;
}
if( page >= 1 && evt.key_symbol == DIKS_PAGE_UP )
{
page--;
lines = 19;
}
if( page >= 0 && next && evt.key_symbol == DIKS_PAGE_DOWN )
{
page++;
lines = 1;
}
if( DrawFile( tmpfile.c_str(), page, fileflg ) )
ERR( "输出服务文件信息失败!" );
}
if( evt.key_symbol == DIKS_CURSOR_LEFT )
{
windowl->RequestFocus( windowl );
Exchange( true );
}
if( evt.key_symbol == DIKS_CURSOR_RIGHT )
{
windowr->RequestFocus( windowr );
Exchange( false );
}
return 0;
}
int DFBDisplay::EvtUnicode( DFBWindowEvent &evt, int &num, const bool &flg )
{
char buffer[MAXNUM];
if( evt.key_symbol == DIKS_RETURN || evt.key_symbol == DIKS_ENTER )
return num;
if( evt.key_symbol == DIKS_ESCAPE )
{
sprintf( buf, "exit" );
num = strlen( buf );
return 1;
}
if( WZM_KEY_VALUE(evt.key_symbol) )
buf[num++] = evt.key_symbol;
if ( evt.key_symbol == DIKS_BACKSPACE )
buf[--num] = '\0';
if( flg )
{
if( flag )
prompt = " Please Input Cmd: ";
sprintf( buffer, "%s %s", prompt.c_str(), buf );
}
else
{
char xinghao[MAXNUM];
memset( xinghao, 0, MAXNUM);
memset( xinghao, '*', strlen(buf) );
sprintf( buffer, "%s %s", prompt.c_str(), xinghao );
}
if( DrawCmd( buffer ) )
ERR( "输出[%s]到CMD失败!", buffer );
if( num >= MAXNUM || num < 0 )
{
ERR( "string's lenght [%d] error!", num );
num = 0;
}
return 0;
}
int DFBDisplay::EvtCousor( DFBWindowEvent &evt )
{
if( evt.window_id == lid )
{
Exchange( true );
if ( evt.buttons & DIBM_LEFT )
{
llines = evt.cy / fontheigh ;
if( llines <= 0)
llines = 1;
else if( llines >= lnums )
llines = lnums;
if( DrawInfo( lpage ) )
ERR( "输出本地文件信息失败!" );
}
if( evt.buttons & DIBM_RIGHT && fileflg )
{
struct stat mode;
if( stat( lstrs[llines-1].c_str(), &mode ) < 0)
{
sprintf( buf, "lcwd" );
return 1;
}
if( S_ISDIR( mode.st_mode ) )
{
sprintf( buf, "lcwd %s", lstrs[llines-1].c_str() );
llines = 1;
lpage = 0;
}
else
sprintf( buf, "stor %s", lstrs[llines-1].c_str() );
return 2;
}
}
else
{
Exchange( false );
if ( evt.buttons & DIBM_LEFT )
{
lines = evt.cy / fontheigh ;
if( lines <= 0)
lines = 1;
else if( lines >= nums )
lines = nums;
if( DrawFile( tmpfile.c_str(), page, fileflg ) )
ERR( "输出服务文件信息失败!" );
}
if( evt.buttons & DIBM_RIGHT && fileflg )
{
ExeLine();
return 3;
}
}
return 0;
}
void DFBDisplay::EvtWheel( DFBWindowEvent &evt)
{
if( evt.window_id == lid )
{
if( lpage >= 1 && evt.step > 0)
{
lpage--;
llines = 19;
}
if( lpage >= 0 && lnext && evt.step < 0 )
{
lpage++;
llines = 1;
}
if( DrawInfo( lpage ) )
ERR( "输出本地文件信息失败!" );
}
else
{
if( page >= 1 && evt.step > 0)
{
page--;
lines = 19;
}
if( page >= 0 && next && evt.step < 0 )
{
page++;
lines = 1;
}
if( DrawFile( tmpfile.c_str(), page, fileflg ) )
ERR( "输出服务文件信息失败!" );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -