示例#1
0
HRESULT ViewTest2::Run()
{
	// Make a special VwGraphics (#define BASELINE in compiling it turns on special features).
	// This VwGraphics will not draw (2nd arg false) but will record attempts at drawing into
	// the baseline.
	m_psts = NewObj SilTestSite();
	m_qst.Attach(m_psts);
	m_qvg.Attach(NewObj VwGraphics(m_psts, false, true));
	m_qst->SetBaselineFile(SmartBstr(L"c:\\fw\\testlog\\log\\VwGraphics").Bstr());

	// Todo LukeU(JohnT): make an off-screen bitmap HDC and initialize the VwGraphics to use it.
	// Here is your off-screen bitmap and memory surface
	HDC hdcScr, hdcMem;
	hdcScr = GetDC(NULL);
	hdcMem = CreateCompatibleDC(hdcScr);
	HBITMAP hBitmap = CreateCompatibleBitmap(hdcMem, 400, 400);
	SelectObject(hdcMem, hBitmap);
	ReleaseDC(NULL, hdcScr);

	m_qvg->Initialize(hdcMem);

	// Make a dummy root site for the Root box to talk back to
	m_qtrs.Attach(NewObj VwTestRootSite);
	m_qtrs->SetVgObject(m_qvg);
	Rect rcSrc(0, 0, 96, 96);
	Rect rcDst(0, 0, 96, 96);
	m_qtrs->SetSrcRoot(rcSrc);
	m_qtrs->SetDstRoot(rcDst);

	// Make our view constructor.
	m_qtvc.Attach(NewObj TestStVc);

	// Put some dummy data into a cache. HVO 1 identifies the text as a whole.
	// Arbitrarily objects 2, 3, and 4 are the three paragraphs of our test data.
	m_qda.Attach(NewObj VwCacheDa);

	HVO rghvoPara[3] = {2, 3, 4};
	m_qda->CacheVecProp(1, kflidStText_Paragraphs, rghvoPara, 3);

	ITsStrFactoryPtr qtsf;
	qtsf.CreateInstance(CLSID_TsStrFactory);

	ITsStringPtr qtss;
	int enc = 100;

	StrUni stuPara0 = L"This is the first paragraph";
	StrUni stuPara1 = L"Here is another paragraph, quite silly and trivial but it should "
						L"help test things";
	StrUni stuPara2 = L"I try to keep the text in these quite different so they can't be "
						L"confused";

	CheckHr(qtsf->MakeStringRgch(stuPara0.Chars(), stuPara0.Length(), enc, &qtss));
	m_qda->CacheStringProp(rghvoPara[0], kflidStTxtPara_Contents, qtss);

	CheckHr(qtsf->MakeStringRgch(stuPara1.Chars(), stuPara1.Length(), enc, &qtss));
	m_qda->CacheStringProp(rghvoPara[1], kflidStTxtPara_Contents, qtss);

	CheckHr(qtsf->MakeStringRgch(stuPara2.Chars(), stuPara2.Length(), enc, &qtss));
	m_qda->CacheStringProp(rghvoPara[2], kflidStTxtPara_Contents, qtss);

	ITsPropsBldrPtr qtpb;
	qtpb.CreateInstance(CLSID_TsPropsBldr);
	StrUni stuNormal = L"Normal";
	CheckHr(qtpb->SetStrPropValue(kspNamedStyle, stuNormal.Bstr()));

	// Make the root box and initialize it.
	m_qrootb.CreateInstance(CLSID_VwRootBox);

	// OK, we have a root box set up. Now we can try some tests on it!
	TestInit();
	TestDataAccess();
	TestLayout(350);

	TestDrawRoot();
	TestOverlay();

	TestMakeSimpleSel();
	TestMakeTextSelection();

	TestKeys();
	TestMouse();

	Testget_Site();
	TestLoseFocus();
	TestListener();

	m_qrootb->Close();
	m_qrootb.Clear();
	m_qda.Clear();

	DeleteDC(hdcMem);
	DeleteObject(hBitmap);
	return S_OK;
}
示例#2
0
文件: hmenu.cpp 项目: CyberShadow/FAR
void HMenu::ProcessSubMenu(MenuDataEx *Data,int DataCount,
                           const wchar_t *SubMenuHelp,int X,int Y,int &Position)
{
	Position=-1;
	SubMenu=new VMenu2(L"",Data,DataCount);
	SubMenu->SetBoxType(SHORT_DOUBLE_BOX);
	SubMenu->SetFlags(VMENU_WRAPMODE);
	SubMenu->SetHelp(SubMenuHelp);
	SubMenu->SetPosition(X,Y,0,0);
	SubMenu->SetMacroMode(MACRO_MAINMENU);

	bool SendMouse=false;
	MOUSE_EVENT_RECORD MouseEvent;
	int SendKey=0;

	Position=SubMenu->RunEx([&](int Msg, void *param)->int
	{
		if(Msg!=DN_INPUT)
			return 0;

		INPUT_RECORD &rec=*static_cast<INPUT_RECORD*>(param);
		int Key=InputRecordToKey(&rec);

		if (Key==KEY_CONSOLE_BUFFER_RESIZE)
		{
			LockScreen LckScr;
			ResizeConsole();
			Show();
			return 1;
		}
		else if (rec.EventType==MOUSE_EVENT)
		{
			if (!TestMouse(&rec.Event.MouseEvent))
			{
				MouseEvent=rec.Event.MouseEvent;
				SendMouse=true;
				SubMenu->Close(-1);
				return 1;
			}
			if (rec.Event.MouseEvent.dwMousePosition.Y==Y1)
				return 1;
		}
		else
		{
			if (Key == KEY_LEFT || Key == KEY_RIGHT ||Key == KEY_TAB ||
			        Key == KEY_NUMPAD4 || Key == KEY_NUMPAD6 ||
			        Key == KEY_MSWHEEL_LEFT || Key == KEY_MSWHEEL_RIGHT)
			{
				SendKey=Key;
				SubMenu->Close(-1);
				return 1;
			}
		}
		return 0;
	});

	delete SubMenu;
	SubMenu=nullptr;

	if(SendMouse)
		ProcessMouse(&MouseEvent);
	if(SendKey)
	{
		ProcessKey(SendKey);
		ProcessKey(KEY_ENTER);
	}
}