📄 window.c
字号:
}
static DFRECT ParamRect(DFWINDOW wnd, DFRECT *rcc)
{
DFRECT rc;
if (rcc == NULL) {
rc = DfRelativeWindowRect(wnd, DfWindowRect(wnd));
if (DfTestAttribute(wnd, DF_SHADOW)) {
rc.rt++;
rc.bt++;
}
}
else
rc = *rcc;
return rc;
}
void DfPaintShadow(DFWINDOW wnd)
{
int y;
DFRECT rc = ParamRect(wnd, NULL);
for (y = 1; y < DfWindowHeight(wnd); y++)
shadow_char(wnd, y);
shadowline(wnd, rc);
}
/* ------- display a window's border ----- */
void DfRepaintBorder(DFWINDOW wnd, DFRECT *rcc)
{
int y;
char lin, side, ne, nw, se, sw;
DFRECT rc, clrc;
if (!DfTestAttribute(wnd, DF_HASBORDER))
return;
rc = ParamRect(wnd, rcc);
clrc = DfAdjustRectangle(wnd, rc);
if (wnd == DfInFocus) {
lin = DF_FOCUS_LINE;
side = DF_FOCUS_SIDE;
ne = DF_FOCUS_NE;
nw = DF_FOCUS_NW;
se = DF_FOCUS_SE;
sw = DF_FOCUS_SW;
}
else {
lin = DF_LINE;
side = DF_SIDE;
ne = DF_NE;
nw = DF_NW;
se = DF_SE;
sw = DF_SW;
}
line[DfWindowWidth(wnd)] = '\0';
/* ---------- window title ------------ */
if (DfTestAttribute(wnd, DF_HASTITLEBAR))
if (DfRectTop(rc) == 0)
if (DfRectLeft(rc) < DfWindowWidth(wnd)-DfBorderAdj(wnd))
DfDisplayTitle(wnd, &rc);
DfForeground = DfFrameForeground(wnd);
DfBackground = DfFrameBackground(wnd);
/* -------- top frame corners --------- */
if (DfRectTop(rc) == 0) {
if (DfRectLeft(rc) == 0)
DfWPutch(wnd, nw, 0, 0);
if (DfRectLeft(rc) < DfWindowWidth(wnd)) {
if (DfRectRight(rc) >= DfWindowWidth(wnd)-1)
DfWPutch(wnd, ne, DfWindowWidth(wnd)-1, 0);
TopLine(wnd, lin, clrc);
}
}
/* ----------- window body ------------ */
for (y = DfRectTop(rc); y <= DfRectBottom(rc); y++) {
char ch;
if (y == 0 || y >= DfWindowHeight(wnd)-1)
continue;
if (DfRectLeft(rc) == 0)
DfWPutch(wnd, side, 0, y);
if (DfRectLeft(rc) < DfWindowWidth(wnd) &&
DfRectRight(rc) >= DfWindowWidth(wnd)-1) {
if (DfTestAttribute(wnd, DF_VSCROLLBAR))
ch = ( y == 1 ? DF_UPSCROLLBOX :
y == DfWindowHeight(wnd)-2 ?
DF_DOWNSCROLLBOX :
y-1 == wnd->VScrollBox ?
DF_SCROLLBOXCHAR :
DF_SCROLLBARCHAR );
else
ch = side;
DfWPutch(wnd, ch, DfWindowWidth(wnd)-1, y);
}
if (DfRectRight(rc) == DfWindowWidth(wnd))
shadow_char(wnd, y);
}
if (DfRectTop(rc) <= DfWindowHeight(wnd)-1 &&
DfRectBottom(rc) >= DfWindowHeight(wnd)-1) {
/* -------- bottom frame corners ---------- */
if (DfRectLeft(rc) == 0)
DfWPutch(wnd, sw, 0, DfWindowHeight(wnd)-1);
if (DfRectLeft(rc) < DfWindowWidth(wnd) &&
DfRectRight(rc) >= DfWindowWidth(wnd)-1)
DfWPutch(wnd, se, DfWindowWidth(wnd)-1,
DfWindowHeight(wnd)-1);
if (wnd->StatusBar == NULL) {
/* ----------- bottom line ------------- */
memset(line,lin,DfWindowWidth(wnd)-1);
if (DfTestAttribute(wnd, DF_HSCROLLBAR)) {
line[0] = DF_LEFTSCROLLBOX;
line[DfWindowWidth(wnd)-3] = DF_RIGHTSCROLLBOX;
memset(line+1, DF_SCROLLBARCHAR, DfWindowWidth(wnd)-4);
line[wnd->HScrollBox] = DF_SCROLLBOXCHAR;
}
line[DfWindowWidth(wnd)-2] = line[DfRectRight(rc)] = '\0';
if (DfRectLeft(rc) != DfRectRight(rc) ||
(DfRectLeft(rc) && DfRectLeft(rc) < DfWindowWidth(wnd)-1))
{
if (wnd != DfInFocus)
DfClipString++;
DfWriteLine(wnd,
line+(DfRectLeft(clrc)),
DfRectLeft(clrc)+1,
DfWindowHeight(wnd)-1,
FALSE);
DfClipString = 0;
}
}
if (DfRectRight(rc) == DfWindowWidth(wnd))
shadow_char(wnd, DfWindowHeight(wnd)-1);
}
if (DfRectBottom(rc) == DfWindowHeight(wnd))
/* ---------- bottom shadow ------------- */
shadowline(wnd, rc);
}
static void TopLine(DFWINDOW wnd, int lin, DFRECT rc)
{
if (DfTestAttribute(wnd, DF_HASMENUBAR))
return;
if (DfTestAttribute(wnd, DF_HASTITLEBAR) && DfGetTitle(wnd))
return;
if (DfRectLeft(rc) == 0) {
DfRectLeft(rc) += DfBorderAdj(wnd);
DfRectRight(rc) += DfBorderAdj(wnd);
}
if (DfRectRight(rc) < DfWindowWidth(wnd)-1)
DfRectRight(rc)++;
if (DfRectLeft(rc) < DfRectRight(rc)) {
/* ----------- top line ------------- */
memset(line,lin,DfWindowWidth(wnd)-1);
if (DfTestAttribute(wnd, DF_CONTROLBOX)) {
strncpy(line+1, " ", 3);
*(line+2) = DF_CONTROLBOXCHAR;
}
line[DfRectRight(rc)] = '\0';
DfWriteLine(wnd, line+DfRectLeft(rc),
DfRectLeft(rc), 0, FALSE);
}
}
/* ------ clear the data space of a window -------- */
void DfClearWindow(DFWINDOW wnd, DFRECT *rcc, int clrchar)
{
if (DfIsVisible(wnd)) {
int y;
DFRECT rc;
if (rcc == NULL)
rc = DfRelativeWindowRect(wnd, DfWindowRect(wnd));
else
rc = *rcc;
if (DfRectLeft(rc) == 0)
DfRectLeft(rc) = DfBorderAdj(wnd);
if (DfRectRight(rc) > DfWindowWidth(wnd)-1)
DfRectRight(rc) = DfWindowWidth(wnd)-1;
DfSetStandardColor(wnd);
memset(line, clrchar, sizeof line);
line[DfRectRight(rc)+1] = '\0';
for (y = DfRectTop(rc); y <= DfRectBottom(rc); y++)
{
if (y < DfTopBorderAdj(wnd) ||
y > DfClientHeight(wnd)+
(DfTestAttribute(wnd, DF_HASMENUBAR) ? 1 : 0))
continue;
DfWriteLine(wnd,
line+(DfRectLeft(rc)),
DfRectLeft(rc),
y,
FALSE);
}
}
}
/* ------ compute the logical line length of a window ------ */
int DfLineLength(char *ln)
{
int len = strlen(ln);
char *cp = ln;
while ((cp = strchr(cp, DF_CHANGECOLOR)) != NULL)
{
cp++;
len -= 3;
}
cp = ln;
while ((cp = strchr(cp, DF_RESETCOLOR)) != NULL)
{
cp++;
--len;
}
return len;
}
void DfInitWindowColors(DFWINDOW wnd)
{
int fbg,col;
int cls = DfGetClass(wnd);
/* window classes without assigned colors inherit parent's colors */
if (DfCfg.clr[cls][0][0] == 0xff && DfGetParent(wnd) != NULL)
cls = DfGetClass(DfGetParent(wnd));
/* ---------- set the colors ---------- */
for (fbg = 0; fbg < 2; fbg++)
for (col = 0; col < 4; col++)
wnd->WindowColors[col][fbg] = DfCfg.clr[cls][col][fbg];
}
void DfPutWindowChar(DFWINDOW wnd, char c, int x, int y)
{
if (x < DfClientWidth(wnd) && y < DfClientHeight(wnd))
DfWPutch(wnd, c, x+DfBorderAdj(wnd), y+DfTopBorderAdj(wnd));
}
void DfPutWindowLine(DFWINDOW wnd, void *s, int x, int y)
{
int saved = FALSE;
int sv = 0;
if (x < DfClientWidth(wnd) && y < DfClientHeight(wnd))
{
char *en = (char *)s+DfClientWidth(wnd)-x;
if ((int)(strlen(s)+x) > (int)DfClientWidth(wnd))
{
sv = *en;
*en = '\0';
saved = TRUE;
}
DfClipString++;
DfWPuts(wnd, s, x+DfBorderAdj(wnd), y+DfTopBorderAdj(wnd));
--DfClipString;
if (saved)
*en = sv;
}
}
/* EOF */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -