コード例 #1
0
ファイル: gui_common.cpp プロジェクト: pengjohn/kaixin
//添加Label控件到CoolBarList, 
// pszString必须是动态的(非Static)
// nWidth 为0 -- 自动长度
Int32 CtrlAddItemToCoolBarList_Lable(TWindow*pWin,  TBarListItem* pListItem, Coord nX, Coord nY, Coord nWidth, Int32 FontSize, TUChar* pszString, ColorRefType Color)
{
	TRectangle obBtnRec(0,0,0,0);
	Int32 nLabelNameId = pListItem->AddCtrl(CTL_CLASS_LABEL, 0, 0);
	TLabel* pLabelName = static_cast<TLabel*>(pWin->GetControlPtr(nLabelNameId));
	if(nWidth == 0)
	{
		nWidth = 80;
		obBtnRec.SetRect(nX, nY, nWidth, FontSize);
		pLabelName->SetBounds(&obBtnRec);
		pLabelName->SetAutoSize(TRUE);

		CtrlSetFont((TCtrl*)pLabelName, FontSize, Color);
		pLabelName->SetCaption(pszString,FALSE);
	}
	else
	{
		obBtnRec.SetRect(nX, nY, nWidth, FontSize+6);	//调整高度,防止字体底部被截断
		pLabelName->SetBounds(&obBtnRec);
		pLabelName->SetAutoSize(FALSE);
		pLabelName->SetScrollMode(lsmNone);

		TFont tFont;
		tFont.Create(FontSize, FontSize);
		ShowAsShort((TCtrl *)pLabelName, pszString, tFont);
		pLabelName->SetFont(tFont);
		pLabelName->SetColor(CTL_COLOR_TYPE_FORE, Color);
	}

	pLabelName->SetEnabled(FALSE);
	
	return nLabelNameId;
}
コード例 #2
0
ファイル: gui_common.cpp プロジェクト: pengjohn/kaixin
Int32 CtrlAddItemToWin_Label(TWindow*pWin, Coord nX, Coord nY, Coord nWidth, Int32 FontSize, TUChar* pszString, ColorRefType Color)
{
	TLabel* pLabel = new TLabel();
	Int32  nLabelID = 0;

	if(pLabel->Create(pWin))	
	{
		TRectangle obBtnRec(0,0,0,0);
		if(nWidth == 0)
		{
			nWidth = 80;
			obBtnRec.SetRect(nX, nY, nWidth, FontSize);
			pLabel->SetBounds(&obBtnRec);
			pLabel->SetAutoSize(TRUE);

			CtrlSetFont((TCtrl*)pLabel, FontSize, Color);
			pLabel->SetCaption(pszString,FALSE);
		}
		else
		{
			obBtnRec.SetRect(nX, nY, nWidth, FontSize);
			pLabel->SetBounds(&obBtnRec);
			pLabel->SetAutoSize(FALSE);
			pLabel->SetScrollMode(lsmNone);

			TFont tFont;
			tFont.Create(FontSize, FontSize);
			ShowAsShort((TCtrl *)pLabel, pszString, tFont);
			pLabel->SetFont(tFont);
			pLabel->SetColor(CTL_COLOR_TYPE_FORE, Color);
		}
	}
	return nLabelID;
}
コード例 #3
0
ファイル: AboutFrm.cpp プロジェクト: P3tr0viCh/UtilsAndComps
void ShowAbout(int iFontSize, Byte bLineBreak, Byte bVersionPos, String sDate,
	TPicture *pPicture, String sAddComp, String sVersion, String sAppName,
	String sCopyright, String sText, HICON hIcon) {
	TForm *Form;

	int I;
	String sCaption;

	TVSFixedFileInfo FileVersionInfo;

	String CompanyName, FileDescription, FileVersion, InternalName,
		LegalCopyright, OriginalFilename, ProductName, ProductVersion;

	TAboutObject *AboutObject;

	ShowWaitCursor();
//	Randomize;

	if (IsShift() & IsCtrl()) {
		sAppName = "Дураев";
		sAppName += sLineBreak;
		sAppName += "Константин Петрович";
		sCopyright = "";
		sCaption   = "Автор";
		sDate      = "29.03.1981";
		sVersion   = "";
		iFontSize  = 16;
		sAddComp   = NULL;
		pPicture   = NULL;
		sText      = "";
		for (int i = 1; i < 280; i++)
			if (i % 40 == 0)
				sText = sText + sLineBreak;
			else
				// TODO: 				sText = sText + String(AnsiChar(Chr(Ord('А') +
				// Random(Ord('Я') - Ord('А')))));
					sText = sText + L"Я";
	}
	else {
		GetFileVerInfo(Application->ExeName, FileVersionInfo, CompanyName,
			FileDescription, FileVersion, InternalName, LegalCopyright,
			OriginalFilename, ProductName, ProductVersion);

		sCaption = LoadStr(IDS_ABOUT_CAPTION);

		if (sDate == NULL)
			sDate = FormatDateTime("yyyy.mm.dd",
			UnixToDateTime(((PIMAGE_NT_HEADERS)((DWORD)((PIMAGE_DOS_HEADER)
			HInstance) + (((PIMAGE_DOS_HEADER) HInstance)->e_lfanew)))
			->FileHeader.TimeDateStamp));

		if (sVersion == NULL) {
			sVersion = FileVersion;
			if (IsValueInWord(FileVersionInfo.dwFileFlags, VS_FF_DEBUG))
				sVersion = sVersion + LoadStr(IDS_ABOUT_DEBUG);
			else if (IsValueInWord(FileVersionInfo.dwFileFlags,
				VS_FF_PRERELEASE))
				sVersion = sVersion + LoadStr(IDS_ABOUT_RC);
		}

		if (sAppName == NULL)
			sAppName = ProductName;

		if (sCopyright == NULL)
			sCopyright = LegalCopyright + "|@[email protected]";

		if (sText == NULL) {
			sText = LoadStr(IDS_ABOUT_EULA1) + sLineBreak +
				LoadStr(IDS_ABOUT_EULA2) + sLineBreak + LoadStr(IDS_ABOUT_EULA3)
				+ sLineBreak + LoadStr(IDS_ABOUT_EULA4);
		}

		if (bLineBreak != MAXBYTE) {
			I        = PosPlace(SPACE, sAppName, bLineBreak);
			sAppName = sAppName.SubString(1, I - 1) + sLineBreak +
				sAppName.SubString(I + 1, MAXINT);
		}
	} // IsShift and IsCtrl

	if (hIcon == NULL)
		hIcon = LoadIcon(HInstance, L"MAINICON");

	AboutObject = new TAboutObject();

	Form               = new TForm(Application); // Owner;
	Form->ShowHint     = true;
	Form->Font->Name   = "Arial";
	Form->Font->Size   = 10;
	Form->BorderStyle  = bsDialog;
	Form->Caption      = sCaption;
	Form->ClientHeight = 165;
	Form->ClientWidth  = 420;

	TBevel *bvlIconFrame = new TBevel(Form);
	bvlIconFrame->Parent = Form;
	bvlIconFrame->SetBounds(8, 14, 52, 52);
	bvlIconFrame->Shape = bsFrame;

	TPanel *pnlIcon = new TPanel(Form);
	pnlIcon->Parent = Form;
	pnlIcon->SetBounds(16, 22, 36, 36);
	pnlIcon->Caption          = "";
	pnlIcon->BevelOuter       = bvNone;
	pnlIcon->BorderStyle      = bsSingle;
	pnlIcon->ParentBackground = false;
	pnlIcon->Color            = (TColor) Random(0xFFFFFF);

	TImage *imgIcon                = new TImage(Form); // Icon
	imgIcon->Parent                = pnlIcon;
	imgIcon->Align                 = alClient;
	imgIcon->Transparent           = true;
	imgIcon->Picture->Icon->Handle = hIcon;

	TLabel *lblCopyright      = new TLabel(Form); // Copyright
	lblCopyright->Tag         = 1;
	lblCopyright->Parent      = Form;
	lblCopyright->Font->Style = TFontStyles() << fsBold;
	lblCopyright->SetBounds(8, 80, 0, 0);

	int PosHint = Pos('|', sCopyright);
	if (PosHint == 0)
		lblCopyright->Caption = sCopyright;
	else {
		lblCopyright->Caption      = sCopyright.SubString(1, PosHint - 1);
		lblCopyright->Hint         = sCopyright.SubString(PosHint + 1, MAXINT);
		lblCopyright->Cursor       = crHandPoint;
		lblCopyright->OnMouseEnter = AboutObject->MouseEnter;
		lblCopyright->OnMouseLeave = AboutObject->MouseLeave;
		if (lblCopyright->Hint[1] == '@') {
			lblCopyright->Hint = lblCopyright->Hint.SubString(2, MAXINT);

			AboutObject->MailAddress = lblCopyright->Hint;
			AboutObject->MailSubject = OriginalFilename + " " + FileVersion;
		}
		lblCopyright->OnClick = AboutObject->Click;
	}

	TLabel *lblText = new TLabel(Form); // Text
	lblText->Parent   = Form;
	lblText->WordWrap = true;
	lblText->SetBounds(8, 100, Form->ClientWidth - 16, 0);
	lblText->Caption = sText;
	// I                  =
	lblText->Top + lblText->Height;
	Form->ClientHeight = Form->ClientHeight + lblText->Height;

	if (sAddComp != NULL) {
		/* with TBevel.Create(Form) do
		 {
		 Parent = Form;
		 SetBounds(7, I + 5, Form.ClientWidth - 15, 5);
		 Shape = bsTopLine;
		 I = Top + Height;
		 };

		 with TLabel.Create(Form) do // Add Components
		 {
		 Parent = Form;
		 SetBounds(8, I, 0, 0);
		 Caption = 'Программное обеспечение использует следующие компоненты:';
		 I = Top + Height;
		 };

		 with TLabel.Create(Form) do // Components
		 {
		 Tag = 2;
		 Parent = Form;
		 Font.Style = [fsBold];
		 SetBounds(8, I, 0, 0);
		 Caption = sAddComp;
		 Form.ClientHeight = Form.ClientHeight + Height + 12;
		 if FileExists(FileInAppDir(rsLicenses)) then
		 {
		 Cursor = crHandPoint;
		 OnClick = ClickObject.Click;
		 OnMouseEnter = ClickObject.MouseEnter;
		 OnMouseLeave = ClickObject.MouseLeave;
		 };
		 } */
	}
	else // sAddComp != NULL
			Form->ClientHeight = Form->ClientHeight - 12;

	TBevel *bvlBottom = new TBevel(Form);
	bvlBottom->Parent = Form;
	bvlBottom->SetBounds(7, Form->ClientHeight - 43, Form->ClientWidth - 15, 5);
	bvlBottom->Shape = bsTopLine;

	lblMemory         = new TLabel(Form); // Физическая ...
	lblMemory->Parent = Form;
	lblMemory->SetBounds(8, Form->ClientHeight - 38, 0, 0);
	lblMemory->Caption = LoadStr(IDS_ABOUT_MEMORY);

	lblMemoryValue              = new TLabel(Form); // TotalPhys
	lblMemoryValue->Parent      = Form;
	lblMemoryValue->Font->Style = TFontStyles() << fsBold;
	lblMemoryValue->SetBounds(lblMemory->Width + 13,
		Form->ClientHeight - 38, 0, 0);

	lblProc         = new TLabel(Form); // Процессор:
	lblProc->Parent = Form;
	lblProc->SetBounds(8, Form->ClientHeight - 22, 0, 0);
	lblProc->Caption = LoadStr(IDS_ABOUT_PROCESSOR);

	lblProcValue              = new TLabel(Form); // CPUSpeed
	lblProcValue->Parent      = Form;
	lblProcValue->Font->Style = TFontStyles() << fsBold;
	lblProcValue->SetBounds(lblMemory->Width + 13,
		Form->ClientHeight - 22, 0, 0);

	TGradientPanel *pnlName = new TGradientPanel(Form);
	pnlName->Parent = Form;
	pnlName->StartUpdate();
	pnlName->SetBounds(68, 8, Form->ClientWidth - 76, 64);
	pnlName->BorderStyle = bsSingle;

	pnlName->BevelOuter       = bvNone;
	pnlName->ParentBackground = false;
	if (pPicture == NULL) pnlName->ColorStart = pnlIcon->Color;
	else pnlName->ColorStart = clBlack;
	pnlName->ColorEnd = clBlack;
	pnlName->EndUpdate();

	if (pPicture == NULL) {
		TLabel *lblAppName = new TLabel(Form); // Application Name (1)
		lblAppName->Parent = pnlName;
		lblAppName->SetBounds(2, 2, Form->ClientWidth - 83, 58);
		lblAppName->Alignment     = taCenter;
		lblAppName->AutoSize      = false;
		lblAppName->Caption       = sAppName;
		lblAppName->ParentColor   = false;
		lblAppName->Color         = clBlack;
		lblAppName->ParentFont    = false;
		lblAppName->Font->Charset = DEFAULT_CHARSET;
		lblAppName->Font->Color   = clBlack;
		lblAppName->Font->Height  = -51;
		lblAppName->Font->Name    = "Courier New";
		lblAppName->Font->Style   = TFontStyles() << fsBold << fsItalic;
		lblAppName->Font->Size    = iFontSize;
		lblAppName->Transparent   = true;
		lblAppName->Layout        = tlCenter;
		lblAppName->WordWrap      = true;

		TLabel *lblAppName2 = new TLabel(Form); // Application Name (2)
		lblAppName2->Parent = pnlName;
		lblAppName2->SetBounds(0, 0, Form->ClientWidth - 83, 58);
		lblAppName2->Alignment     = taCenter;
		lblAppName2->AutoSize      = false;
		lblAppName2->Caption       = sAppName;
		lblAppName2->ParentColor   = false;
		lblAppName2->Color         = clBlack;
		lblAppName2->ParentFont    = false;
		lblAppName2->Font->Charset = DEFAULT_CHARSET;
		lblAppName2->Font->Color   = clWhite;
		lblAppName2->Font->Height  = -51;
		lblAppName2->Font->Name    = "Courier New";
		lblAppName2->Font->Style   = TFontStyles() << fsBold << fsItalic;
		lblAppName2->Font->Size    = iFontSize;
		lblAppName2->Transparent   = true;
		lblAppName2->Layout        = tlCenter;
		lblAppName2->WordWrap      = true;
	} // pPicture == NULL
	else {
		TImage *imgPicture = new TImage(Form);
		imgPicture->Parent = pnlName;
		imgPicture->Align  = alClient;
		imgPicture->Picture->Assign(pPicture);
	}

	TLabel *lblDate = new TLabel(Form); // Date
	lblDate->Parent  = pnlName;
	lblDate->Caption = sDate;
	lblDate->Font->Assign(Form->Font);
	lblDate->Font->Style = TFontStyles() << fsBold;
	lblDate->Font->Color = clWhite;
	lblDate->Font->Size  = 8;
	lblDate->Alignment   = taRightJustify;

	switch (3) {
	case 0:
		lblDate->SetBounds(2, 2, lblDate->Width, lblDate->Height);
		break;
	case 1:
		lblDate->SetBounds(2, pnlName->ClientHeight - lblDate->Height - 2,
			lblDate->Width, lblDate->Height);
		break;
	case 2:
		lblDate->SetBounds(pnlName->ClientWidth - lblDate->Width - 2, 2,
			lblDate->Width, lblDate->Height);
		break;
	default:
		lblDate->SetBounds(pnlName->ClientWidth - lblDate->Width - 2,
			pnlName->ClientHeight - lblDate->Height - 2, lblDate->Width,
			lblDate->Height);
	}
	lblDate->Transparent = true;

	TLabel *lblVerion  = new TLabel(Form); // Version
	lblVerion->Parent  = pnlName;
	lblVerion->Caption = sVersion;
	lblVerion->Font->Assign(Form->Font);
	lblVerion->Font->Style = TFontStyles() << fsBold;
	lblVerion->Font->Color = clWhite;
	lblVerion->Font->Size  = 8;

	switch (2) {
	case 0:
		lblVerion->SetBounds(2, 2, lblVerion->Width, lblVerion->Height);
		break;
	case 1:
		lblVerion->SetBounds(2, pnlName->ClientHeight - lblVerion->Height - 2,
			lblVerion->Width, lblVerion->Height);
		break;
	case 2:
		lblVerion->SetBounds(pnlName->ClientWidth - lblVerion->Width - 2, 2,
			lblVerion->Width, lblVerion->Height);
		break;
	default:
		lblVerion->SetBounds(pnlName->ClientWidth - lblVerion->Width - 2,
			pnlName->ClientHeight - lblVerion->Height - 2, lblVerion->Width,
			lblVerion->Height);
	}
	lblVerion->Transparent = true;

	TButton *btnClose     = new TButton(Form);
	btnClose->Parent      = Form;
	btnClose->Caption     = "OK";
	btnClose->ModalResult = mrCancel;
	btnClose->Cancel      = true;
	btnClose->SetBounds(Form->ClientWidth - 83, Form->ClientHeight - 34,
		75, 26);
	btnClose->TabOrder = 0;

	TTimer *timer   = new TTimer(Form);
	timer->OnTimer  = AboutObject->TimerTimer;
	timer->Interval = 1;
	timer->Enabled  = true;

	RestoreCursor();

	Form->Left = (Screen->Width - Form->Width) / 2;
	Form->Top  = (Screen->Height - Form->Height) / 2;

	SetCurPosToCenter(btnClose);

	Form->ShowModal();

	Form->Free();
	AboutObject->Free();

	lblMemory      = NULL;
	lblProc        = NULL;
	lblMemoryValue = NULL;
	lblProcValue   = NULL;
}
コード例 #4
0
// 窗口初始化
Boolean TGardenListForm::_OnWinInitEvent(TApplication * pApp, EventType * pEvent)
{
	int iRet = eFailed;
	int nIndex = 0;
	TBarRowList *lpRowList = NULL;
	TRectangle Rc_CoolBarList;

	nListItems =0;
	Response = NULL;
	iRet = KaiXinAPI_JsonParse(KX_GardenList, (void **)&Response);

	m_BackBtn = SetAppBackButton(this); 
	SetAppTilte(this, APP_KA_ID_STRING_Garden);	

	if(iRet == 1)
	{
		TBarRow *lpRow = NULL;
		TCoolBarList* pCoolBarList = static_cast<TCoolBarList*>(GetControlPtr(APP_KA_ID_GardenListForm_GardenListCoolBarList));
		if (pCoolBarList)
		{
			TBarListItem* lpItem = NULL;

			pCoolBarList->SetBounds(RC_LIST_LARGE);
			pCoolBarList->GetBounds(&Rc_CoolBarList);
			lpRowList = pCoolBarList->Rows();
			//add row
			if (lpRowList)
			{
				lpRowList->BeginUpdate();
				lpRowList->Clear();
				lpRow = lpRowList->AppendRow();
				lpRowList->EndUpdate();
				if(lpRow)
				{
					//Title 
					lpItem = lpRow->AppendItem();
					if(lpItem)	
					{
						TFont objFontType;
						Int32 ItemHeight = 0;
						TRectangle rect;
						TRectangle Rc_Temp;
						TUChar pszSubTitle[64] = {0};

						lpItem->GetBounds(rect);
						lpItem->SetCaption(NULL);						
						lpItem->SetIndicatorType(itNone);

						ItemHeight = ItemHeight + 30;

						TUString::StrPrintF(pszSubTitle, TResource::LoadConstString(APP_KA_ID_STRING_SubTitleGarden),TResource::LoadConstString(APP_KA_ID_STRING_Friend));
						Int32 nTitlelabelId = lpItem->AddCtrl(CTL_CLASS_LABEL, 20, 5);
						TLabel* pTitlelabel = static_cast<TLabel*>(GetControlPtr(nTitlelabelId));
						TRectangle Rc_Titlelabel(OFFSET_X, ItemHeight, SCR_W - 20, 20);
						pTitlelabel->SetBounds(&Rc_Titlelabel);
						objFontType = pTitlelabel->GetFont();
						objFontType.Create(FONT_CONTENT, FONT_CONTENT);
						pTitlelabel->SetFont(objFontType); 
						pTitlelabel->SetCaption(pszSubTitle,FALSE);
						pTitlelabel->GetBounds(&Rc_Temp);

						ItemHeight = ItemHeight + Rc_Temp.Height() + 30;					
						lpItem->SetHeight(ItemHeight);	
					}						

					// 好友列表
					nListItems = Response->nSize_friends;
					if(nListItems == 0)
					{
						lpItem = lpRow->AppendItem();
						if(lpItem)
						{
							TFont objFontType;
							TUChar pszFriendName[32] = {0};
							Int32 ItemHeight = 0;
							TRectangle rect;
							TRectangle Rc_Temp;

							lpItem->GetBounds(rect);
							lpItem->SetCaption(NULL);						
							lpItem->SetIndicatorType(itNone);

							ItemHeight = ItemHeight + rect.Y() + 15;

							//好友的花园里还没有成熟的果实				
							Int32 nNoneHarvestId = lpItem->AddCtrl(CTL_CLASS_LABEL, 20, 5);
							TLabel* pNoneHarvest = static_cast<TLabel*>(GetControlPtr(nNoneHarvestId));
							TRectangle Rc_NoneHarvest(OFFSET_X, ItemHeight, SCR_W - 40 , 20);
							pNoneHarvest->SetBounds(&Rc_NoneHarvest);
							objFontType = pNoneHarvest->GetFont();
							objFontType.Create(FONT_CONTENT_DETAIL, FONT_CONTENT_DETAIL);
							pNoneHarvest->SetFont(objFontType);
							pNoneHarvest->SetColor(CTL_COLOR_TYPE_FORE,RGB_COLOR_GRAY);
							pNoneHarvest->SetCaption(TResource::LoadConstString(APP_KA_ID_STRING_NoneHarvestGarden),FALSE);
							pNoneHarvest->GetBounds(&Rc_Temp);		
							ItemHeight = ItemHeight + Rc_Temp.Height() + 10;

							lpItem->SetHeight(ItemHeight - (rect.Y() - Rc_CoolBarList.Y()) + 10 );
						}
					}
					else
					{
						for( nIndex = 0; nIndex < nListItems; nIndex++)			
						{
							lpItem = lpRow->AppendItem();
							if(lpItem)
							{
								TFont objFontType;
								TUChar pszFriendName[32] = {0};
								Int32 ItemHeight = 0;
								TRectangle rect;
								TRectangle Rc_Temp;

								lpItem->GetBounds(rect);
								lpItem->SetCaption(NULL);						
								lpItem->SetIndicatorType(itNone);

								ItemHeight = ItemHeight + rect.Y() + 15;

								//好友名字							
								TUString::StrUtf8ToStrUnicode(pszFriendName, (const Char *)Response->friends[nIndex].fname);
								nFriendNameId[nIndex] = lpItem->AddCtrl(CTL_CLASS_RICHVIEW, 20, 5);
								TRichView* pFriendName = static_cast<TRichView*>(GetControlPtr(nFriendNameId[nIndex]));
								TRectangle Rc_FriendName(OFFSET_X, ItemHeight, SCR_W - 40 , 20);
								pFriendName->SetBounds(&Rc_FriendName);
								objFontType = pFriendName->GetFont();
								objFontType.Create(FONT_CONTENT_DETAIL, FONT_CONTENT_DETAIL);
								pFriendName->SetFont(objFontType); 
								//pFriendName->SetColor(CTL_COLOR_TYPE_FORE,RGB_COLOR_BLUE);
								pFriendName->SetWordWrapAttr(TRUE);
								pFriendName->SetTransparent(TRUE);
								pFriendName->SetEnabled(TRUE);
								pFriendName->SetScrollBarMode(CTL_SCL_MODE_NONE);
								pFriendName->SetMaxVisibleLines(1, TRUE);
								pFriendName->SetCaption(pszFriendName,FALSE);
								pFriendName->GetBounds(&Rc_Temp);		
								ItemHeight = ItemHeight + Rc_Temp.Height() + 5;

								lpItem->SetHeight(ItemHeight - (rect.Y() - Rc_CoolBarList.Y()) + 10 );
							}
						}					
					}					

				}

				//:TODO:Add subject info

				lpRowList->BeginUpdate();
				lpRow = lpRowList->AppendRow();
				lpRowList->EndUpdate(); 

				//add Item
				if(lpRow)
				{
					//nothing to do 				
				}
			}
		}
	}
	return TRUE;
}