⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sdm.c

📁 dos 1.0 其中包含quick basic源代码、内存管理himem emm386 发展历史
💻 C
📖 第 1 页 / 共 3 页
字号:

		switch (tmt)
			{
		default:
			Assert(FALSE);
			break;

		case tmtStaticText:
		case tmtFormattedText:
		case tmtTrackingText:
FillDummyText:	/* case tmtDummyText: */
			Assert((pwnd->style & WS_TYPE) == WS_STATIC ||
			    (pwnd->style & WS_TYPE) == WS_STATIC_NOACCEL);
#ifndef KANJI	/* kanji mucks with coordinates */
			Assert(PcrcOfTm(ptm)->dx
			 == (pwnd->arcClipping.axRight - pwnd->arcClipping.axLeft));
						/* size must be exact */
#endif /*!KANJI*/
			pwnd->pfnWndProc = StaticWndProc;
			pwnd->fCursorOn = FALSE;

			Assert(SS_LEFT == 0);
			if (ptm->fNotLeftJustify)
				{
				pwnd->style |= (ptm->fNotRightJustify) ?
				    SS_CENTER : SS_RIGHT;
				}

			goto init_string;

#ifndef MUCH_LATER
		case tmtToggleBox:
		case tmtToggleButton:
			AssertSz(FALSE, "Toggleboxes/buttons not yet");
#endif
		case tmtGroupBox:
			pwnd->fEnabled = FALSE;
#ifndef KANJI	/* kanji mucks with coordinates */
			/* size check : with border */
			Assert(PcrcOfTm(ptm)->dx - 2
			 == (pwnd->arcClipping.axRight - pwnd->arcClipping.axLeft));
#endif /*!KANJI*/
			goto init_button;

		case tmtRadioButton:
			if (!ptif->fReal)
				{
				/* not a real button => don't link in */
				if (ptm->fFirstButton)
					iagNonHandle++;	/* bump iag anyway */
				goto init_button;
				}
			if (ptm->fFirstButton)
				{
				/* first button in group */
				pwndRadioBase = pwnd;
				pwnd->wButton = wButtonFirstRadio;
				ptif->iagMain = iagNonHandle++;
				tmcRadioLast  = tmc;
				}
			else
				{
				/* not first button */
				Assert(pwndRadioBase != NULL);
				Assert(pwndRadioPrev != NULL);
				pwndRadioPrev->pwndButtonNext = (WORD) pwnd;
				/* take into account imported tmcs */
				pwnd->id = ptif->tmc = ++tmcRadioLast;
				}
			/* fill with start (this will hook the last button) */
			pwnd->pwndButtonNext = (WORD) pwndRadioBase;
			pwndRadioPrev = pwnd;
			goto init_button;

		case tmtCheckBox:
			ptif->iagMain = iagNonHandle++;
			/* fall through to pushbutton */
		case tmtPushButton:
			Assert(pwnd->wButton == wButtonInit);
init_button:
			Assert(pwnd->style & WS_BUTTON);
#ifndef KANJI	/* kanji mucks with coordinates */
			Assert(PcrcOfTm(ptm)->dx
			 == (pwnd->arcWindow.axRight - pwnd->arcWindow.axLeft));
							/* size must be exact */
#endif /*!KANJI*/
			pwnd->pfnWndProc = ButtonWndProc;
			if (ptm->fDefaultPushButton)
				pwnd->style |= BS_DEFPUSHBUTTON;
init_string:
			if (ptm->bpString == bpStringFromCab)
				{
				/* string data from CAB : fill in later */
				Assert(ptif->iagText != iagNil);
				}
			else
				{
				/* normal base pointer */
				Assert(ptif->iagText == iagNil ||
				    tmt == tmtDummyText);
				}
			AllocDialogString(pwnd,
			    (ptm->bpString > bpStringFromCab) ?
			    (char *) ((WORD) ptm + ptm->bpString) : szEmptyString);
			break;

		case tmtListBox:
			Assert(pwnd->style & WS_LISTBOX);
			/* must have listbox proc or be directory */
			Assert(fControlProc || ptm->fDirListBox);
			Assert(!(fControlProc && ptm->fDirListBox));

			pwnd->pfnWndProc = ListBoxWndProc;
			pwnd->axCursor++;
			pwnd->isaColor = isaListBox;
			pwnd->isaHiliteColor = isaListBoxSelection;
			pwnd->ctickRepLb = ctickRepList;
			if (!ptm->fComboListBox)
				{
				ptif->iagMain = iagNonHandle++;
				}
#ifdef LISTBOX_DIR	/* Dir and or sorted */
#ifdef DEBUG /* remove later */
			if (ptm->fDirListBox)
				{
				AssertSz(ptm->fSortedListBox, "old SDM template format");
				}
#endif
			if (ptm->fSortedListBox)
				pwnd->style |= LBS_SORT;

			/* save listbox proc (if there is one) */
#endif /*LISTBOX_DIR*/
			PwfnCtlLb(pwnd) = Ptm1OfTif(ptif)->pfnCtl;
			break;

		case tmtEdit:
			Assert(pwnd->style & WS_EDIT);
			/* should set ES_ styles if we supported them */
			pwnd->pfnWndProc = EditWndProc;
			/* allocate string for edit control for work buffer */
#ifdef EDIT_FULLMGR
			InitEditWnd(pwnd, pbWorkCur,
				    (cwEditBuffer  * sizeof (WORD)) +
				    sizeof (EF) + sizeof (LD));
			pbWorkCur += (cwEditBuffer * sizeof (WORD)) +
				     sizeof (EF) + sizeof (LD);
#else
			pwnd->szDialog = (WORD) pbWorkCur;
			pwnd->cchDialog = cwEditBuffer * sizeof(WORD) - 1;
			Assert(pwnd->cchDialog == 255);	/* must be 255 */
			pwnd->chFillDialog = (WORD) chFillEdit;
			pwnd->isaEb = isaEdit;	/* set variable color */
			pwnd->isaSelEb = isaHiliteEdit;
			pwnd->cchMaxEb = pwnd->cchDialog;
			pbWorkCur += cwEditBuffer * sizeof(WORD);
#endif /*EDIT_FULLMGR*/

#ifdef EDIT_SECRET
			/* just SecretEdit for now */
			if (ptm->fCharValidated)
				pwnd->style |= ES_SECRET;
#endif /*EDIT_SECRET*/

			Assert(pbWorkCur <= pbWorkMac);
			ptif->iagMain = fControlProc ? iagNonHandle++ :
			    iagHandle++;
			break;

		case tmtStandardButton:
			Assert(pwnd->wButton == wButtonInit);
			Assert(pwnd->style & WS_BUTTON);
#ifndef KANJI	/* kanji mucks with coordinates */
			Assert(PcrcOfTm(ptm)->dx
			 == (pwnd->arcWindow.axRight - pwnd->arcWindow.axLeft));
							/* size must be exact */
#endif /*!KANJI*/
			Assert(ptm->bpString == NULL && ptif->iagText == iagNil);
			AllocDialogString(pwnd,
			    ptm->fStandardCancel ? szCancelString : szOkString);
			pwnd->pfnWndProc = ButtonWndProc;
			if (ptm->fStandardCancel)
				{
				/* Cancel */
				tmc = tmcCancel;
				}
			else
				{
				/* OK */
				tmc = tmcOk;
				Assert(ptm->fDefaultPushButton);
				pwnd->style |= BS_DEFPUSHBUTTON;
				}
			/* change tmc */
			pwnd->id = ptif->tmc = tmc;
			break;

		case tmtGeneralPicture:
			pwnd->fEnabled = FALSE;
			pwnd->pfnWndProc = GeneralWndProc;
			AssertSz(FExtension1(ptif), "General Picture without wnd proc");
			Assert(Ptm1OfTif(ptif)->pfnCtl != NULL);
			PwfnCtlGeneral(pwnd) = Ptm1OfTif(ptif)->pfnCtl;
			break;

			} /*switch*/

		ptif++;
		}

	/* all real tm's better be filled in "rgtif" array */
	Assert(ptif - sdsCur.rgtif == sdsCur.ctif);

	/* the work buffer should be all used up */
	AssertSz(pbWorkCur == pbWorkMac, "SDM alloc fail");

	/* the CAB & DialogTemplate better match */
#ifdef PROJECT_WORKS
	/* WORKS wan't to be sleazy and use overallocated Handles */
	AssertSz(PcabxOfCab(sdsCur.hcab)->cabh.cagHandle >= iagHandle,
	    "CAB / DLG mismatch (handles)");
#else
	AssertSz(PcabxOfCab(sdsCur.hcab)->cabh.cagHandle == iagHandle,
	    "CAB / DLG mismatch (handles)");
#endif
	AssertSz(PcabxOfCab(sdsCur.hcab)->cabh.cwData >= iagNonHandle,
	    "CAB / DLG mismatch (non-handles)");

	return(pwndDialog);
	}



STATIC VOID
AllocDialogString(pwnd, szText)
/*
  -- allocate string space for string specified by szText
  -- need room for largest text + zero terminator
  -- strip sz from szText to fill in acl
*/
REGISTER PWND pwnd;
char *szText;
	{
	pwnd->szDialog = (WORD) pbWorkCur;
	pwnd->cchDialog = pwnd->arcClipping.axRight - pwnd->arcClipping.axLeft;

	Assert(sizeof(WORD) == 2);
	pbWorkCur += (pwnd->cchDialog + 2) & ~1;	/* + 1 & make even */
	Assert(pbWorkCur <= pbWorkMac);

	Assert(pwnd->aclDialog == aclNil);
	SetDlgItemText(pwnd, szText, FALSE);
	}



STATIC HCAB
HcabFromDialog()
/*
  -- Allocates a cab and fills it in with values from the specified dialog box.
  -- get size info from global CAB
*/
	{
	REGISTER PTIF	ptif;
	WORD		ctif;

	HCAB		hcab;		/* work CAB */

	CABX *		pcabxSrc;	/* original */
	CABX *		pcabxDest;	/* destination */
	WORD		cagHandle;	/* # of handles in CAB */
	WORD		cwData;		/* # of words of data */

	pcabxSrc = PcabxOfCab(sdsCur.hcab);
	cagHandle = pcabxSrc->cabh.cagHandle;
	cwData = pcabxSrc->cabh.cwData;
	/* allocate a new cab the size of the original cab */
	if ((hcab = HcabAlloc((cagHandle << 8) + cwData)) == NULL)
		{
		/* out of memory - stay in dialog */
		return NULL;
		}

	/* headers must be the same */
	pcabxSrc = PcabxOfCab(sdsCur.hcab);
	pcabxDest = PcabxOfCab(hcab);
	Assert(pcabxDest->cabh.cagHandle == cagHandle);
	Assert(pcabxDest->cabh.cwData == cwData);

	/* copy data from old to new : skip over handles */
	pcabxDest->sab = pcabxSrc->sab;
	bltbyte(&pcabxSrc->rgh[cagHandle], &pcabxDest->rgh[cagHandle],
	    (cwData - cagHandle) * sizeof(WORD));

	/* go thru all tm's and store dialog values into cab */
	for (ctif = sdsCur.ctif, ptif = sdsCur.rgtif; ctif--; ptif++)
		{
		REGISTER PTM	ptm;
		PTM		ptmNext;	/* next item */
		WORD *		pwArg;		/* pointer to arg */

		/* first restore text back in CAB */
		if (ptif->iagText != iagNil)
			TextToCab(hcab, ptif->pwnd, ptif->iagText);

		if (ptif->iagMain == iagNil)
			continue;	/* no arg */

		pwArg = &PcabxOfCab(hcab)->rgh[ptif->iagMain];
		ptm = ptif->ptm;
		ptmNext = (ptif+1)->ptm;	/* next or end guard */

		switch (ptm->tmtBase)
			{
		default:
			continue;

		case tmtEdit:
#ifdef LISTBOX_DIR
			if (ptmNext != NULL &&
			     ptmNext->tmtBase == tmtListBox &&
			     ptmNext->fDirListBox)
				{
				/* Dir => Combo Dir */
				AssertSz(ptmNext->fComboListBox,
				   "Dir Listbox must be ComboDir");

				/* A Combo Dir ListBox, ptm=>edit item */
				if (!FFillComboDir(ptif+1, FALSE))
					{
					/* don't exit */
					FreeCab(hcab);
					return ((HCAB) -1);
					}
				}
#endif /*LISTBOX_DIR*/
			if (!FExtension1(ptif) ||
			    Ptm1OfTif(ptif)->pfnCtl == NULL)
				{
				/* no parse proc : normal edit */
				TextToCab(hcab, ptif->pwnd, ptif->iagMain);
				}
			else if (!FParseToCabTif(hcab, ptif))
				{
				/* error when parsing */
				FreeCab(hcab);
				return(NULL);
				}
			break;

		case tmtCheckBox:
			*pwArg = WButtonChecked(ptif->pwnd);
			break;

		case tmtRadioButton:
			/* must be first in group */
			if (ptm->fFirstButton);
			*pwArg = GetRadVal(ptif);
			break;

		case tmtListBox:
#ifdef LISTBOX_DIR
			if (ptm->fDirListBox)
				{
				if (ptm->fComboListBox)
					{
					continue;
					/* no CAB entry for combo directory
					    list boxes */
					}
				else
					{
#ifdef REMOVE_LATER
					... dir/drive listbox (dummy cab)...
					char szBuffer[cchDirMax];
					DlgDirSelect(ptif->pwnd, szBuffer,
					    (ptif+2)->ptm->tmtBase == tmtListBox ?
					    (ptif+2)->pwnd : NULL);
					SzToCab(hcab, szBuffer, ptif->iagMain);
#endif
					}
				}
			else
#endif /*LISTBOX_DIR*/
				{
				/* we assume the right val for SendMessage */
				*pwArg = (WORD) SendMessageShort(ptif->pwnd, LB_GETCURSEL);
				}
			break;

			}
		}
	return(hcab);
	}



STATIC BOOL
FSetDialogFromCab()
/*
  -- sets field values in dialog box with values in cab
  -- get global info from sdsCur
  -- returns false if initial selection was made
*/
	{
	WORD tmcSel;

	if (sdsCur.hcab != NULL)
		{
		REGISTER PTIF	ptif;
		WORD		ctif;

		for (ctif = sdsCur.ctif, ptif = sdsCur.rgtif; ctif--; ptif++)
			{
			REGISTER PTM	ptm;
			WORD		wArg;

			/* check for CAB text */
			if (ptif->iagText != iagNil)
				TextFromCab(ptif->pwnd, ptif->iagText);

			/* note : wArg will be bogus if iagMain == iagNil */
			ptm = ptif->ptm;
			wArg = (ptif->iagMain == iagNil) ? uNinch :
			    PcabxOfCab(sdsCur.hcab)->rgh[ptif->iagMain];

			switch (ptm->tmtBase)
				{
			default:
				continue;

			case tmtEdit:
				Assert(ptif->iagMain != iagNil);

				if (!FExtension1(ptif) ||
				    Ptm1OfTif(ptif)->pfnCtl == NULL)
					TextFromCab(ptif->pwnd, ptif->iagMain);
				else
					FormatFromCabTif(sdsCur.hcab, ptif);
				break;

			case tmtCheckBox:
				Assert(ptif->iagMain != iagNil);
				CheckDlgButton(ptif->pwnd, wArg, FALSE);
				break;

			case tmtRadioButton:
				/* must be first in group */
				if (wArg != uNinch)
					{
					Assert(ptif->ptm->fFirstButton);
					Assert(ptif->iagMain != iagNil);
					CheckRadioButton(ptif->pwnd, wArg, FALSE);
					}
				break;

			case tmtListBox:
				/* wArg may be bogus (if Combo) */
#ifdef DEBUG
				if (ptif->ptm->fComboListBox)
					{Assert(ptif->iagMain == iagNil);}
				else
					{Assert(ptif->iagMain != iagNil);}
#endif
				FillListBoxTif(ptif, wArg);
				break;
				} /*switch*/
			}
		}

	/* make initial selection */
	if ((tmcSel = sdsCur.pdlg->tmcSelInit) != tmcNull)
		{
		SetTmcSel(tmcSel, 0, 0x7fff);
		return(FALSE);
		}
	return(TRUE);
	}



STATIC VOID
TextToCab(hcab, pwnd, iag)
/*
  -- get string from Dialog item (window pwnd) put in CAB
*/
HCAB hcab;		/* destination CAB */
PWND pwnd;		/* window to place string in */
WORD iag;		/* arg in default CAB to get string from */
	{
	char sz[cwEditBuffer * sizeof (WORD)];

	Assert(hcab != NULL);
	Assert(pwnd != NULL);
	Assert(iag != iagNil);

	GetDlgItemText(pwnd, sz, sizeof(sz)-1);
	SzToCab(hcab, sz, iag);
	}



STATIC VOID
TextFromCab(pwnd, iag)
/*
  -- get string from default CAB, put in dialog item
*/
PWND pwnd;		/* window to place string in */
WORD iag;		/* arg in default CAB to get string from */
	{
	char sz[cwEditBuffer * sizeof (WORD)];

	Assert(sdsCur.hcab != NULL);
	Assert(pwnd != NULL);
	Assert(iag != iagNil);

	SzFromCab(sdsCur.hcab, sz, sizeof(sz), iag);
	SetDlgItemText(pwnd, sz, FALSE);
	}



STATIC BOOL
FParseToCabTif(hcab, ptif)
/*
  -- parses sz at itm using parse function *pfn.
  -- return TRUE if no error
*/
HCAB hcab;
REGISTER PTIF ptif;
	{
	char	sz[cwEditBuffer * sizeof (WORD)];
	WORD	cwVal;
	PWFN_CTL pfnCtl;
	TMC	tmc;

	/* Item must have an parse proc */
	AssertExtension1(ptif);
	pfnCtl = Ptm1OfTif(ptif)->pfnCtl;
	Assert(pfnCtl != NULL);

	tmc	= ptif->tmc;

	GetDlgItemText(ptif->pwnd, sz, sizeof(sz)-1);
	cwVal = (*pfnCtl)(tmmCwVal, sz, NULL, tmc, wParamLater, 0);
#ifdef LATER
	...allow arbitrary fixed & variable length things in CAB
#endif
	if (cwVal == 1)
		{
		/* parse value and store it into cab at iag */
		Assert(ptif->iagMain != iagNil);
		Assert(ptif->iagMain >= PcabxOfCab(hcab)->cabh.cagHandle);

		if (!(*pfnCtl)(tmmParse, sz, (WORD) hcab, tmc, wParamLater,
		    (WORD) &((CABX *) 0)->rgh[ptif->iagMain]))
			{
			/* parse error */
			return(FALSE);
			}
		}
	else
		{
		char **hval;

		if ((hval = HeapAlloc(cwVal * sizeof(int))) == NULL)
			{
			OutOfMemory();
			return FALSE;
			}

		/* parse large value and store it into cab at iag */
		if (!(*pfnCtl)(tmmParse, sz, (WORD) hval, tmc, wParamLater, 0))
			{
			/* parse error */
			HeapFree(hval);
			return FALSE;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -