?? sdm.c
字號:
/*
CW : Character Oriented Windows
sdm.c : Standard Dialog Manager (COW variant)
from Windows SDM Version 1.3 (2/14/86)
*/
#ifndef LATER
#define wParamLater 0
#endif
#define COW
#include <cow.h>
#define SDM
#define SDM_ENGINE
#include <sdmver.h>
#include <kmem.h>
#include <usdm.h>
#include <usdmtmpl.h>
#include <uevent.h>
#include <udialog.h>
#include <uwindow.h>
#include <uisa.h>
#include <uscroll.h>
#include <uedit.h>
#include "dialog.h"
#include "event.h"
#include "window.h"
#include "util.h"
#include "screen.h"
#include "shadow.h"
#include "edit.h"
#ifdef EDIT_FULLMGR
#include <umedit.h>
#endif
#include "scroll.h"
#include "button.h"
#include "static.h"
#include "general.h"
#include "listbox.h"
#include "_listbox.h"
#include "sdm.h"
#include "_sdm.h"
#include "strings.h"
#ifdef LISTBOX_LIMIT_SIZE
#define cchDirMax 80 /* 64 + file name */
#else
#define cchDirMax 256
#endif
#ifdef LISTBOX_LIMIT_SIZE
#define cchListTextMax 64
#else
#define cchListTextMax 256
#endif
/* G L O B A L S */
#ifdef DUAL
extern WORD fProtectMode;
#endif
STATIC SDS sdsCur; /* current SDM state */
static BYTE *pbWorkCur; /* current position in work buffer */
#ifdef DEBUG
static BYTE *pbWorkMac; /* max value of pbWorkCur - for assertions */
#endif /*DEBUG*/
/* forward */
STATIC DWORD FARPUBLIC SdmDialogProc(PWND, WORD, TMC, DWORD);
STATIC PWND PwndAllocArc(PARC, WORD);
STATIC PWND PwndBuildDialog(PDLG);
STATIC VOID AllocDialogString(PWND, char *);
STATIC HCAB HcabFromDialog(void);
STATIC BOOL FSetDialogFromCab(void);
STATIC VOID TextToCab(HCAB, PWND, WORD);
STATIC VOID TextFromCab(PWND, WORD);
STATIC BOOL FParseToCabTif(HCAB, PTIF);
STATIC VOID FormatFromCabTif(HCAB, PTIF);
STATIC char * SzWildCard(char *);
STATIC BOOL FFillComboDir(PTIF, BOOL);
STATIC VOID SelChangeComboListBox(PTIF);
#ifdef DEBUG
STATIC VOID AssertTableOrder(void);
#endif
/* Important Tables : see AssertTableOrder for assertion */
/* item creation info :: should really go in CS */
STATIC TCI mptmttci[] = /* # of bytes needed */
{
TciMake(cwExtraDialog, 0 /* n/a */,
WS_TILED | WS_DIALOG | WS_BORDER), /* tmtDialog !! */
TciMake(cwExtraStatic, cwRect,
WS_CHILD | WS_STATIC), /* tmtStaticText */
TciMake(cwExtraStatic, cwRect,
WS_CHILD | WS_STATIC_NOACCEL), /* tmtFormattedText */
TciMake(cwExtraStatic, cwRect,
WS_CHILD | WS_STATIC_NOACCEL), /* tmtTrackingText */
TciMake(cwExtraButton, cwRect,
WS_CHILD | WS_BUTTON | BS_GROUP | WS_BORDER),
/* tmtGroupBox */
TciMake(cwExtraButton, cwRect, wsPushButton),
/* tmtPushButton */
TciMake(cwExtraButton, cwRect,
WS_CHILD | WS_BUTTON | BS_AUTOCHECKBOX),
/* tmtCheckBox */
TciMake(cwExtraButton, cwRect,
WS_CHILD | WS_BUTTON | BS_RADIOBUTTON), /* tmtRadioButton */
TciMake(cwExtraButton, cwRect,
WS_CHILD | WS_BUTTON | 0xffff /*not implemented*/),
/* tmtToggleBox */
TciMake(cwExtraButton, cwRect,
WS_CHILD | WS_BUTTON | 0xffff /*not implemented*/),
/* tmtToggleButton */
#ifdef EDIT_FULLMGR
TciMake(cwExtraEdit, cwEditBuffer + ((sizeof (EF) + sizeof (LD))/2),
WS_CHILD | WS_EDIT), /* tmtEdit */
#else
TciMake(cwExtraEdit, cwEditBuffer,
WS_CHILD | WS_EDIT), /* tmtEdit */
#endif
TciMake(cwExtraListBox, cwWnd + cwExtraScroll,
WS_CHILD | WS_LISTBOX | WS_VSCROLL | WS_BORDER),
/* tmtListBox */
TciMake(cwExtraButton, cwRect, wsPushButton),
/* tmtStandardButton */
TciMake(cwExtraStatic, cwRect,
WS_CHILD | WS_STATIC), /* tmtDummyText */
TciMake(cwExtraGeneral, 0,
WS_CHILD), /* tmtGeneralPicture */
/* past end of normal tmts */
TciMake(cwExtraScroll, 0 /* n/a */,
WS_CHILD | SBS_VERT) /* tmtScroll !! */
};
#ifdef DEBUG
STATIC VOID
AssertTableOrder()
/*
-- assert table ordering !!!
-- isn't C wonderful
*/
{
Assert(sizeof(mptmttci) == sizeof(TCI) * (tmtNormalMax+1));
Assert(tmtDialog == 0); /* special tmt */
Assert(tmtStaticText == 1);
Assert(tmtFormattedText == 2);
Assert(tmtTrackingText == 3);
Assert(tmtGroupBox == 4);
Assert(tmtPushButton == 5);
Assert(tmtCheckBox == 6);
Assert(tmtRadioButton == 7);
Assert(tmtToggleBox == 8);
Assert(tmtToggleButton == 9);
Assert(tmtEdit == 10);
Assert(tmtListBox == 11);
Assert(tmtStandardButton == 12);
Assert(tmtDummyText == 13);
Assert(tmtGeneralPicture == 14);
Assert(tmtScroll == 15); /* special tmt */
}
#endif /*DEBUG*/
PUBLIC TMC FARPUBLIC
TmcDoDlg(pdlg, hcab)
/*
-- Dialog interpreter procedure.
-- save old SDM state
-- create a dialog tree (tree of windows), return tmcCancel if no memory
-- call DialogBox() to start dialog
*/
VOID *pdlg; /* Really PDLG */
HCAB hcab;
{
StartPublic();
TMC tmc;
SDS sdsSave; /* save old state for re-entrancy */
Debug(AssertTableOrder());
/* re-entrant SDM */
sdsSave = sdsCur;
/* our global handle to the current dialog cab */
sdsCur.hcab = hcab;
sdsCur.pdlg = pdlg;
if ((sdsCur.pwndDialog = PwndBuildDialog(pdlg)) == NULL)
{
/* out of memory, restore old state & return */
sdsCur = sdsSave;
ReturnPublic(tmcCancel, TMC);
}
tmc = DialogBox(sdsCur.pwndDialog, SdmDialogProc);
FreeWork(sdsCur.pbWorkBuffer);
/* restore old state */
sdsCur = sdsSave;
ReturnPublic(tmc, TMC);
}
STATIC PWND
PwndAllocArc(parc, tmt)
/*
-- allocate space for a window of given size and type
-- zero fill, enable window
special tmt's:
tmtNull : allocate the entire dialog window
tmtNormalMax : allocate a scroll bar window
*/
PARC parc;
WORD tmt;
{
REGISTER PWND pwnd;
REGISTER TCI *ptci = &mptmttci[tmt];
Assert(tmt <= tmtNormalMax);
/* allocate room for window + any extra words */
pwnd = (PWND) pbWorkCur;
pbWorkCur += ptci->cbWnd;
Assert(pbWorkCur <= pbWorkMac);
FillBuf((char *) pwnd, 0, ptci->cbWnd);
pwnd->arcWindow = *parc;
pwnd->fEnabled = TRUE; /* default enabled */
pwnd->style = ptci->style;
return(pwnd);
}
STATIC PWND
PwndBuildDialog(pdlg)
/*
-- build the dialog window tree
-- return the top window, or NULL if out of memory
*/
PDLG pdlg;
{
/* Dialog Box info */
REGISTER PWND pwndDialog;
WORD ddxDialog, ddyDialog; /* amount to grow by */
ARC arcDialog;
AX axLeft;
AY ayTop;
/* General TM info */
WORD tmcNext;
WORD ctmSkip;
/* TM scanning variables */
REGISTER PTM ptm;
PTIF ptif;
WORD tmt; /* type */
WORD tmc;
ARC arcTm;
/* Arg info */
WORD iagHandle;
WORD iagNonHandle;
/* Radio Buttons */
PWND pwndRadioBase; /* base for radio buttons */
PWND pwndRadioPrev; /* previous radio buttons */
TMC tmcRadioLast;
WORD cbNeed; /* the number of bytes needed */
/* consistency variables */
BOOL fControlProc; /* do we have a control proc ?*/
/* Init */
tmcNext = tmcSysMin; /* start here */
ddxDialog = ddyDialog = 0;
Debug(pwndRadioBase = NULL);
Debug(pwndRadioPrev = NULL);
cbNeed = (cwWnd + cwExtraDialog) * sizeof(WORD);
/* room for the actual dialog box */
/* scan the array of TM's to
a) find out must extra work buffer space we will need
b) find sdsCur.ctif
*/
sdsCur.ctif = 0;
for (ptm = pdlg->rgtm; (tmt = ptm->tmtBase) != tmtEnd; ptm++)
{
REGISTER TCI *ptci;
if (FSpecialTmt(tmt))
{
if (tmt == tmtConditional)
{
/* check subdialog for larger rectangle */
/* Must have a CAB */
AssertSz(sdsCur.hcab != NULL,
"Sub Dialog without CAB");
if (FUseSubDialog(ptm,
PcabxOfCab(sdsCur.hcab)->sab))
{
#ifdef LATER /* resizing dialogs */
if (PtmoOfTm(ptm)->ddxDialog > ddxDialog)
ddxDialog =
PtmoOfTm(ptm)->ddxDialog;
if (PtmoOfTm(ptm)->ddyDialog > ddyDialog)
ddyDialog =
PtmoOfTm(ptm)->ddyDialog;
#endif /*LATER*/
}
}
continue;
}
/* standard stuff for all items ************************/
Assert(tmt < tmtNormalMax);
ptci = &mptmttci[tmt];
cbNeed += ptci->cbWnd;
if (ptci->cbAdditional != cbRect)
cbNeed += ptci->cbAdditional;
else
{
/* figure extra size from ARC requirements */
cbNeed += (PcrcOfTm(ptm)->dx + 2) & ~1;
if (ptci->style & WS_BORDER)
cbNeed -= 2; /* because of border */
}
if (tmt != tmtDummyText)
sdsCur.ctif++;
}
Assert(sdsCur.ctif != 0);
/* figure out new dialog size */
arcDialog.axRight = (arcDialog.axLeft = pdlg->crcDlg.x)
+ pdlg->crcDlg.dx + (BYTE) ddxDialog;
arcDialog.ayBottom = (arcDialog.ayTop = pdlg->crcDlg.y)
+ pdlg->crcDlg.dy + (BYTE) ddyDialog;
cbNeed += (sdsCur.ctif + 1) * sizeof(TIF);
pbWorkCur = sdsCur.pbWorkBuffer = PbAllocWork(cbNeed);
if (pbWorkCur == NULL)
return NULL;
Debug(pbWorkMac = sdsCur.pbWorkBuffer + cbNeed);
/* Now fill in the real stuff ************************/
/* allocate the TIF info */
ptif = sdsCur.rgtif = (PTIF) pbWorkCur;
pbWorkCur += (sdsCur.ctif + 1) * sizeof(TIF);
/* fill last tif with guard info */
sdsCur.rgtif[sdsCur.ctif].ptm = NULL;
sdsCur.rgtif[sdsCur.ctif].tmc = tmcNull;
/* allocate main dialog window */
pwndDialog = PwndAllocArc(&arcDialog, tmtDialog /*special*/);
Assert(pwndDialog->style & WS_BORDER);
/* Adjust for larger displays -- assumes dialogs are laid out to
look nice on an 80x25 display */
if (pwndDialog->arcWindow.ayBottom < 25) /* if small dialog */
MoveWindow(pwndDialog,
pwndDialog->arcWindow.axLeft + ((axMac - 80) >> 1),
pwndDialog->arcWindow.ayTop + ((ayMac - 25) >> 1));
pwndDialog->pfnWndProc = DialogWndProc;
if (pdlg->bpTitle != NULL)
{
/* title for Window -- just point into dialog template */
/* NOTE : kludge for BASE pointer */
pwndDialog->szDialog = ((WORD) pdlg) + pdlg->bpTitle;
}
ValidateWindow(pwndDialog);
axLeft = pwndDialog->arcClipping.axLeft;
ayTop = pwndDialog->arcClipping.ayTop;
/* prepare for real scan of tm's */
Assert(ptif == sdsCur.rgtif);
Assert(sdsCur.hcab != NULL);
iagHandle = 0;
iagNonHandle = PcabxOfCab(sdsCur.hcab)->cabh.cagHandle;
/* check later */
/* go thru all tm's, constructing the dialog template */
ctmSkip = 0;
for (ptm = pdlg->rgtm; (tmt = ptm->tmtBase) != tmtEnd; ptm++)
{
REGISTER PWND pwnd;
PTM ptmSpecial;
if (FSpecialTmt(tmt))
{
if (tmt == tmtConditional &&
!FUseSubDialog(ptm, PcabxOfCab(sdsCur.hcab)->sab))
{
/* don't use it */
ctmSkip = PtmoOfTm(ptm)->ctmNormal;
}
continue;
}
/* standard stuff for all items ************************/
/* Make rrc into an arc */
arcTm.axRight = (arcTm.axLeft = PcrcOfTm(ptm)->x + axLeft)
+ PcrcOfTm(ptm)->dx;
arcTm.ayBottom = (arcTm.ayTop = PcrcOfTm(ptm)->y + ayTop)
+ PcrcOfTm(ptm)->dy;
pwnd = PwndAllocArc(&arcTm, tmt); /* zero filled */
pwnd->aclDialog = aclNil;
ValidateWindow(pwnd);
if (ptif->fReal = (ctmSkip == 0))
{
/* real window */
AddChild(pwndDialog, pwnd);
}
else
{
/* fake window (skip due to sub-dialogs) */
ctmSkip--;
}
if (tmt == tmtDummyText)
{
/* Dummy text does not have TMCs, extensions or
or anything special */
Assert(!FExtensionTmt((ptm+1)->tmtBase));
Assert(ptm->bpString != NULL &&
ptm->bpString != bpStringFromCab);
pwnd->id = tmcNull;
ptif--; /* counteract ending ptif++ */
goto FillDummyText;
}
/* scan ahead for extension records ********************/
tmc = tmcNext; /* next tmc in a row */
Assert(ptif - sdsCur.rgtif == tmcNext - tmcSysMin);
/* itif & tmc have weird arrangement */
tmcNext++;
fControlProc = FALSE;
for (ptmSpecial = ptm+1;
FExtensionTmt(ptmSpecial->tmtBase);
ptmSpecial++)
{
switch (ptmSpecial->tmtBase)
{
default:
Assert(FALSE);
break;
case tmtExtension1:
/* Extension 1 must be right after normal */
Assert(ptmSpecial == ptm+1);
if (Ptm1OfTm(ptmSpecial)->tmcImport != tmcNull)
{
/* imported TMC */
tmc = Ptm1OfTm(ptmSpecial)->tmcImport;
AssertSz(tmc < tmcSysMin ||
tmc >= tmcSysMax,
"invalid Imported TMC");
}
fControlProc = Ptm1OfTm(ptmSpecial)->pfnCtl != NULL;
break;
case tmtExtension2:
Assert(FALSE); /* do later */
break;
case tmtExtension3:
Assert(FALSE); /* do later */
break;
}
}
/* fill in default info ********************************/
/* Cursor : on, in upper left */
pwnd->fCursorOn = TRUE;
pwnd->axCursor = pwnd->arcClipping.axLeft;
pwnd->ayCursor = pwnd->arcClipping.ayTop;
pwnd->id = tmc;
/* fill in TIF info ***********************************/
ptif->tmc = tmc;
ptif->ptm = ptm;
ptif->pwnd = pwnd;
/* check for string from cab */
ptif->iagText = (ptm->bpString == bpStringFromCab) ?
iagHandle++ : iagNil;
ptif->iagMain = iagNil; /* assume no cab arg */
/* special init cases ********************************/
/* Vertical Scroll Bar */
if (pwnd->style & WS_VSCROLL)
{
PWND pwndScroll;
#ifdef LISTBOX_ONELINE
/* if only 1 line (+border) then no scroll bar */
{
#ifdef LISTBOX_NOSCROLL
extern BYTE fNoScroll;
if (arcTm.ayBottom == arcTm.ayTop + 3 || fNoScroll)
#else
if (arcTm.ayBottom == arcTm.ayTop + 3)
#endif
{
/* turn off style as well as eating allocated memory */
pwnd->style &= ~WS_VSCROLL;
pbWorkCur += (cwWnd + cwExtraScroll) * sizeof(WORD);
Assert(pbWorkCur <= pbWorkMac);
goto skip_add_scroll;
}
}
#endif /*LISTBOX_ONELINE*/
/* vertical scroll bar on right hand side */
arcTm.axLeft = arcTm.axRight - daxBorder;
/* less top&bottom corners */
arcTm.ayTop += dayBorder;
arcTm.ayBottom -= dayBorder;
pwndScroll = PwndAllocArc(&arcTm, tmtScroll);
pwndScroll->pfnWndProc = ScrollBarWndProc;
pwndScroll->ctickRepSb = ctickRepScrollDefault;
ValidateWindow(pwndScroll);
AddChild(pwnd, pwndScroll);
#ifdef LISTBOX_ONELINE
skip_add_scroll: ;
#endif /*LISTBOX_ONELINE*/
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -