?? babygrid.cpp
字號(hào):
//BABYGRID code is copyrighted (C) 20002 by David Hillard
//
//This code must retain this copyright message
//
//Printed BABYGRID message reference and tutorial available.
//email: mudcat@mis.net for more information.
/*
Add WM_MOUSEWHEEL, WM_LBUTTONDBLCLK and WM_RBUTTONUP events
Modified by Don HO <don.h@free.fr>
*/
#include "babygrid.h"
#define MAX_GRIDS 20
#define MAX_ROWS 32000
#define MAX_COLS 256
//global variables
HFONT hfontbody,hfontheader,hfonttitle;
HFONT holdfont;
struct _gridhandlestruct
{
UINT gridmenu;
HWND hlist1;
char protect[2];
char title[305];
char editstring[305];
char editstringdisplay[305];
int rows;
int cols;
int gridwidth;
int gridheight;
int homerow;
int homecol;
int rowheight;
int leftvisiblecol;
int rightvisiblecol;
int topvisiblerow;
int bottomvisiblerow;
int headerrowheight;
int cursorrow;
int cursorcol;
int ownerdrawitem;
int visiblecolumns;
int titleheight;
int fontascentheight;
COLORREF cursorcolor;
COLORREF protectcolor;
COLORREF unprotectcolor;
COLORREF textcolor;
COLORREF highlightcolor;
COLORREF gridlinecolor;
COLORREF highlighttextcolor;
BOOL DRAWHIGHLIGHT;
BOOL ADVANCEROW;
BOOL CURRENTCELLPROTECTED;
BOOL GRIDHASFOCUS;
BOOL AUTOROW;
RECT activecellrect;
HFONT hfont;
HFONT hcolumnheadingfont;
HFONT htitlefont;
BOOL ROWSNUMBERED;
BOOL COLUMNSNUMBERED;
BOOL EDITABLE;
BOOL EDITING;
BOOL EXTENDLASTCOLUMN;
BOOL HSCROLL;
BOOL VSCROLL;
BOOL SHOWINTEGRALROWS;
BOOL SIZING;
BOOL ELLIPSIS;
BOOL COLAUTOWIDTH;
BOOL COLUMNSIZING;
BOOL ALLOWCOLUMNRESIZING;
int columntoresize;
int columntoresizeinitsize;
int columntoresizeinitx;
int cursortype;
int columnwidths[MAX_COLS+1];
BOOL REMEMBERINTEGRALROWS;
int wannabeheight;
int wannabewidth;
} BGHS[MAX_GRIDS];
_BGCELL BGcell,*LPBGcell;
int BG_GridIndex;
int FindResult;
char data[1000];
CREATESTRUCT cs,*lpcs;
int AddGrid(UINT);
int FindGrid(UINT);
void ShowVscroll(HWND,int);
void ShowHscroll(HWND,int);
int BinarySearchListBox(HWND,char*);
int CountGrids(void);
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
int HomeColumnNthVisible(int SI)
{
int j,hc,count;
count=0;
hc=BGHS[SI].homecol;
for(j=1;j<=hc;j++)
{
if(BGHS[SI].columnwidths[j]>0)
{
count++;
}
}
return count;
}
void RefreshGrid(HWND hWnd)
{
RECT rect;
int SI;
GetClientRect(hWnd,&rect);
InvalidateRect(hWnd,&rect,FALSE);
SI=FindGrid((UINT)GetMenu(hWnd));
if(BGHS[SI].EDITING)
{
DisplayEditString(hWnd,SI,"");
}
}
int GetNextColWithWidth(int SI, int startcol, int direction)
{
//calls with direction == 1 for right, direction == -1 for left
//returns 0 if no more cols in that direction, else column number
int j;
int ReturnValue;
j=startcol;
if(direction == 1){j++;}
if(direction != 1){j--;}
while((BGHS[SI].columnwidths[j] == 0)&&(j<=BGHS[SI].cols)&&(j>0))
{
if(direction == 1){j++;}
if(direction != 1){j--;}
}
if((BGHS[SI].columnwidths[j] > 0)&&(j<=BGHS[SI].cols))
{
ReturnValue = j;
}
else
{
ReturnValue = 0;
}
return ReturnValue;
}
int GetRowOfMouse(int SI,int y)
{
int ReturnValue;
if(y<=(BGHS[SI].titleheight))
{
return -1;
}
if((y>=BGHS[SI].titleheight)&&(y<=BGHS[SI].headerrowheight + BGHS[SI].titleheight))
{
return 0;
}
y=y-(BGHS[SI].headerrowheight + BGHS[SI].titleheight);
y=y/BGHS[SI].rowheight;
ReturnValue = BGHS[SI].homerow + y;
if(ReturnValue > BGHS[SI].rows){ReturnValue = -1;}
return ReturnValue;
}
int GetColOfMouse(int SI,int x)
{
int ReturnValue;
int j;
if(x<=BGHS[SI].columnwidths[0])
{
return 0;
}
x-=BGHS[SI].columnwidths[0];
j=BGHS[SI].homecol;
while(x>0)
{
x-=BGHS[SI].columnwidths[j];
j++;
}
j--;
ReturnValue = j;
if(BGHS[SI].EXTENDLASTCOLUMN)
{
if(j>BGHS[SI].cols){ReturnValue = BGHS[SI].cols;}
}
else
{
if(j>BGHS[SI].cols){ReturnValue = -1;}
}
return ReturnValue;
}
BOOL OutOfRange(_BGCELL *cell)
{
if((cell->row > MAX_ROWS)||(cell->col > MAX_COLS))
{return TRUE;}
else
{return FALSE;}
}
void SetCell(_BGCELL *cell,int row, int col)
{
cell->row = row;
cell->col = col;
}
/*
int DetermineDataType(char* data)
{
//return values:
// 1 = Text or Alpha
// 2 = Numeric
// 3 = Boolean TRUE
// 4 = Boolean FALSE
// 5 = Graphic - user drawn (cell text begins with ~)
int j,k,numberofperiods,numberofpositives,numberofnegatives;
char tbuffer[1000];
BOOL DIGIT,ALPHA,PERIOD,WHITESPACE,SYMBOL,POSITIVE,NEGATIVE;
strcpy(tbuffer,data);
k=strlen(tbuffer);
strupr(tbuffer);
//is it boolean?
if(!strcmp(tbuffer,"TRUE"))
{
return 3;
}
if(!strcmp(tbuffer,"FALSE"))
{
return 4;
}
//is it graphic (~)
if(tbuffer[0]=='~')
{
return 5;
}
DIGIT=FALSE;
ALPHA=FALSE;
PERIOD=FALSE;
WHITESPACE=FALSE;
SYMBOL=FALSE;
POSITIVE=FALSE;
NEGATIVE=FALSE;
numberofperiods=0;
numberofpositives=0;
numberofnegatives=0;
for(j=0;j<k;j++)
{
if(iswalpha(tbuffer[j])){ALPHA=TRUE;}
if(iswdigit(tbuffer[j])){DIGIT=TRUE;}
if(iswspace(tbuffer[j])){WHITESPACE=TRUE;}
if(tbuffer[j]=='.'){PERIOD=TRUE;numberofperiods++;}
if(tbuffer[j]=='+'){if(j>0){ALPHA=TRUE;}}
if(tbuffer[j]=='-'){if(j>0){ALPHA=TRUE;}}
}
if((ALPHA)||(WHITESPACE))
{
return 1;
}
if((DIGIT)&&(!ALPHA)&&(!WHITESPACE))
{
if(numberofperiods>1)
{
return 1;
}
else
{
return 2;
}
}
return 1;
}
*/
void CalcVisibleCellBoundaries(int SelfIndex)
{
int gridx,gridy;
int j;
gridx=BGHS[SelfIndex].gridwidth;
gridy=BGHS[SelfIndex].gridheight;
j= BGHS[SelfIndex].homecol;
BGHS[SelfIndex].leftvisiblecol = BGHS[SelfIndex].homecol;
BGHS[SelfIndex].topvisiblerow = BGHS[SelfIndex].homerow;
//calc columns visible
//first subtract the width of col 0;
gridx = gridx - BGHS[SelfIndex].columnwidths[0];
do
{
gridx = gridx - BGHS[SelfIndex].columnwidths[j];
j++;
}while ((gridx >= 0)&&(j<BGHS[SelfIndex].cols));
if(j>BGHS[SelfIndex].cols){j=BGHS[SelfIndex].cols;}
BGHS[SelfIndex].rightvisiblecol = j;
//calc rows visible;
gridy = gridy - BGHS[SelfIndex].headerrowheight;
j= BGHS[SelfIndex].homerow;
do
{
gridy = gridy - BGHS[SelfIndex].rowheight;
j++;
}while ((gridy > 0)&&(j<BGHS[SelfIndex].rows));
if(j>BGHS[SelfIndex].rows){j=BGHS[SelfIndex].rows;}
BGHS[SelfIndex].bottomvisiblerow = j;
}
RECT GetCellRect(HWND hWnd,int SI, int r, int c)
{
RECT rect;
int offset;
int j;
//c and r must be greater than zero
//get column offset
//first get col 0 width
offset=BGHS[SI].columnwidths[0];
for(j=BGHS[SI].homecol;j<c;j++)
{
offset += BGHS[SI].columnwidths[j];
}
rect.left = offset;
rect.right = offset + BGHS[SI].columnwidths[c];
if(BGHS[SI].EXTENDLASTCOLUMN)
{
//see if this is the last column
if(!GetNextColWithWidth(SI,c,1))
{
//extend this column
RECT trect;
int temp;
GetClientRect(hWnd,&trect);
temp = (offset +(trect.right - rect.left))-rect.left;
if(temp > BGHS[SI].columnwidths[c])
{
rect.right = offset + (trect.right - rect.left);
}
}
}
//now get the top and bottom of the rect
offset = BGHS[SI].headerrowheight+BGHS[SI].titleheight;
for(j=BGHS[SI].homerow;j<r;j++)
{
offset += BGHS[SI].rowheight;
}
rect.top = offset;
rect.bottom = offset + BGHS[SI].rowheight;
return rect;
}
void DisplayTitle(HWND hWnd,int SI,HFONT hfont)
{
RECT rect;
HDC gdc;
HFONT holdfont;
GetClientRect(hWnd,&rect);
gdc=GetDC(hWnd);
SetBkMode(gdc,TRANSPARENT);
holdfont=(HFONT)SelectObject(gdc,hfont);
rect.bottom = BGHS[SI].titleheight;
DrawEdge(gdc,&rect,EDGE_ETCHED,BF_MIDDLE|BF_RECT|BF_ADJUST);
DrawTextEx(gdc,BGHS[SI].title,-1,&rect,DT_END_ELLIPSIS|DT_CENTER|DT_WORDBREAK|DT_NOPREFIX,NULL);
SelectObject(gdc,holdfont);
ReleaseDC(hWnd,gdc);
}
void DisplayColumn(HWND hWnd,int SI,int c,int offset,HFONT hfont,HFONT hcolumnheadingfont)
{
HDC gdc;
RECT rect,rectsave;
HFONT holdfont;
int r;
char buffer[1000];
int iDataType,iProtection;
if(BGHS[SI].columnwidths[c]==0){return;}
gdc=GetDC(hWnd);
SetBkMode(gdc,TRANSPARENT);
ShowHscroll(hWnd,SI);
ShowVscroll(hWnd,SI);
holdfont = (HFONT)SelectObject(gdc,hcolumnheadingfont);
SetTextColor(gdc,BGHS[SI].textcolor);
//display header row
r=0;
rect.left = offset + 0;
rect.top = BGHS[SI].titleheight;//0
rect.right = BGHS[SI].columnwidths[c] + offset;
rect.bottom = BGHS[SI].headerrowheight + BGHS[SI].titleheight;
if(BGHS[SI].EXTENDLASTCOLUMN)
//see if this is the last column
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -