📄 listb.h
字号:
/* listb.h Abstract list class. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program 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 General Public License for more details, www.gnu.org. Copyright (C) 2000 Simon Harrison (email smh@N_O_S_P_A_M@dr.com)*/#ifndef LISTB_DOT_H#define LISTB_DOT_H#include <stdlib.h>#include <stdio.h>#include <string.h>/* This is just a managed string.*/class CString { char* name; int alloc_len; public: CString( ) : name(NULL),alloc_len(0) { } virtual ~CString() { delete [] name; } virtual char* GetName(){ if (name) return name; else return ""; } virtual void SetName(char*);};/* A scroller object to assist in scrolling the currently selected text if it won't fit.*/class CScroller { int scroll_count; int freq; int length; int max; bool up; char* text; char* out; int tlen; int scroll_div; public : CScroller( int width=20) : scroll_div(0),freq(1),scroll_count(0), length(0), up(true), text(NULL) { max = width; } ~CScroller() { if (text) delete text; } void load( char * t, int f ) { if (text) delete text; if (t) { tlen = strlen( t ); text = new char[tlen+1]; scroll_div = f; freq = f; if (text) { strcpy( text, t ); } } } char* update( int* sel) { if (!text) return "Not loaded"; if (tlen>max) { if (up) { if (--scroll_div<=0) { scroll_div = freq; if (++scroll_count==(tlen-max)) { up = false; scroll_div = 0; scroll_count--; } } } else { if (++scroll_div>=freq) { scroll_div = 0; if (--scroll_count<0) { up = true; scroll_div = freq; scroll_count++; } } } out = text+scroll_count; *sel = scroll_div; } else { out = NULL; } return out; } };/* List browser class. Managed interface-independent list browsing. The Class maintains a window on a (possibly) long list eg files in a directory. The class is independent of the method of display. There is support for key input that might traverse the list and the capability of selecting a single item from the view list. */class CListBrowser { int PAGE_MAX; // 10s of units CString* plist; // current listing CString* ppagelist; int npageents; int nlistents; // length of dir listing int cur_page; int display_sel; int scroll_width; int cur_select; int scroll_freq; char* p; int ok; bool scroll_on; int scroll_max; CScroller* scroller; public : CListBrowser( int page=15 ); virtual ~CListBrowser() { delete [] ppagelist; delete [] plist; delete scroller; } CString* GetPage() { return ppagelist; } int GetPageEnts(); char* GetScrolledSelected( int* offs ); void ScrollOn( int n, bool b, int freq ); int GetPageMax() { return PAGE_MAX; } int GetSelected() { return display_sel; } void up(); // Cursor up void uplots(); // page up void down(); // Cursor down void downlots(); // page down virtual void left(); // cursor left virtual void right(); // Cursor right virtual char* enter(); // enter key (select a file or directory) void DebugDumpPage( CString* p, int n ); protected : void SetSelect(int s); char* GetListEntry( int i ) { if ((i<nlistents) && (i>=0)) { return plist[i].GetName(); } else { return "CListBrowserGetListEntry() Error"; } } void SetList( CString* list, int n ) { plist = list; nlistents = n; } int GetListSelected() { return cur_select; } void update( ); // get the new directory listing window int findindex( char* match ); // get the index of an entry given the name int newlisting(int disp); void clean(); // clean the values from the list (to load some more).};#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -