Exemplo n.º 1
0
//添加Image控件到CoolBarList, 
// pszString必须是动态的(非Static)
// nWidth 为0 -- 自动长度
Int32 CtrlAddItemToCoolBarList_Image(TWindow*pWin,  TBarListItem* pListItem, Coord nX, Coord nY, Coord nWidth, Int32 nHeight, TBitmap * pBmp)
{
	TRectangle obBtnRec(0,0,0,0);
	Int32 nImageId = pListItem->AddCtrl(CTL_CLASS_IMAGE, 0, 0);
	TImage* pImage = static_cast<TImage*>(pWin->GetControlPtr(nImageId));

	obBtnRec.SetRect(nX, nY, nWidth, nHeight);
	pImage->SetBounds(&obBtnRec);
	pImage->SetBitmap(pBmp);
	pImage->SetEnabled(TRUE);
	return nImageId;
}
Exemplo n.º 2
0
Int32 CtrlAddItemToPanel_Image(TWindow*pWin, TPanel* pPanel, Coord nX, Coord nY, Coord nWidth, Coord nHeight, TBitmap * pBmp)
{
	TImage* pImage = new TImage();
	Int32 nImageId = 0;
	
	if(pImage->Create(pPanel))
	{
		TRectangle obBtnRec(0,0,0,0);

		nImageId=pImage->GetId();
		obBtnRec.SetRect(nX, nY, nWidth, nHeight);
		pImage->SetBounds(&obBtnRec);
		pImage->SetBitmap(pBmp);
		pImage->SetEnabled(TRUE);
	}
	
	return nImageId;
}
// 窗口事件处理
Boolean TPhotosGetAlbumsForm::EventHandler(TApplication * pApp, EventType * pEvent)
{
	Boolean bHandled = FALSE;

	switch (pEvent->eType)
	{
		//窗口创建
	case EVENT_WinInit:
		{
			_OnWinInitEvent(pApp, pEvent);
			bHandled = TRUE;
		}
		break;

		//窗口关闭
	case EVENT_WinClose:
		{
			_OnWinClose(pApp, pEvent);
		}
		break;

		//点击控件
	case EVENT_CtrlSelect:
		{
			bHandled = _OnCtrlSelectEvent(pApp, pEvent);
		}
		break;

		//控件获取焦点
	case EVENT_CtrlSetFocus:
		{
			bHandled = _OnCtrlSetFocusEvent(pApp, pEvent);
		}
		break;

		//控件丢失焦点
	case EVENT_CtrlKillFocus :
		{
			bHandled = _OnCtrlKillFocusEvent(pApp, pEvent);
		}
		break;

		//输入框内容变化
	case EVENT_FieldChanged:
		{
			_OnFldChangedEvent(pApp, pEvent);
			bHandled = TRUE;
		}
		break;

		//窗口的背景
	case EVENT_WinEraseClient:
		{
			TDC dc(this);
			WinEraseClientEventType *pEraseEvent = reinterpret_cast< WinEraseClientEventType* >( pEvent );
			TRectangle rc(pEraseEvent->rc);
			dc.SetBackColor(RGB_COLOR_FORM_BACKGROUND);
			dc.EraseRectangle(&rc, 0);
			dc.DrawBitmapsH(TResource::LoadConstBitmap(APP_RE_ID_BITMAP_title_bg), 0, 0, SCR_W,GUI_API_STYLE_ALIGNMENT_LEFT);

			if(m_FormMode == FORM_MODE_MYHOME)
				dc.DrawBitmapsH(TResource::LoadConstBitmap(APP_RE_ID_BITMAP_Bottom_btn_bg), 0, BOTTOM_TAB_Y, SCR_W,GUI_API_STYLE_ALIGNMENT_LEFT);				
			pEraseEvent->result = 1;				
			bHandled = TRUE;
		}
		break;

		// 右软键事件 
	case EVENT_KeyCommand: 
		{ 
			if( pEvent->sParam1 == SYS_KEY_SOFTKEY_RIGHT_UP || pEvent->sParam1 == SYS_KEY_SOFTKEY_RIGHT_LONG ) 
			{ 
				// 模拟标题栏右按钮选中消息 
				HitControl(m_TitleBtnRight); 
				bHandled = TRUE; 
			} 
		} 
		break;

        //下载完成事件
	case MSG_DL_THREAD_NOTIFY:
		{
			NotifyMsgDataType notifyData;
			Sys_GetMessageBody((MESSAGE_t *)pEvent, &notifyData, sizeof(NotifyMsgDataType));
			bHandled = TRUE;
			switch(notifyData.nAccessType)
			{
				case RR_PhotoDownload:
				{
					if(notifyData.nParam == FEED_PROFILE_IMAGE_INDEX)
					{	
						//下载完后更新对应的图片
						TBitmap* pDownLoadBitmap = NULL;
						pDownLoadBitmap = LoadImgByPath(notifyData.pszFilePath);

						if(pDownLoadBitmap)
						{
							TMaskButton* pLogo = NULL;
							pLogo = static_cast<TMaskButton*>(GetControlPtr(m_ProfileImageID));
							if(pLogo)
							{
								TRectangle rc;							
								pLogo->GetBounds(&rc);
								if( pProfileImage != NULL)
								{
									pProfileImage->Destroy();
									pProfileImage = NULL; 							
								}
									
								pProfileImage = TBitmap::Create(RR_HEAD_W, RR_HEAD_W, pDownLoadBitmap->GetDepth());
								pProfileImage->QuickZoom(pDownLoadBitmap, TRUE, TRUE,RGBA(0,0,0,255));
								pLogo->SetCaption(TUSTR_Re_NULL,0,0);
								pLogo->SetImage(pProfileImage, (rc.Width()-pProfileImage->GetWidth())/2, (rc.Height()-pProfileImage->GetHeight())/2);										pLogo->Draw();
							}				

							//释放图片
							pDownLoadBitmap->Destroy();
							pDownLoadBitmap = NULL; 						
						}	
						break;
					}
						
					TBitmap* pDownLoadBitmap = NULL;
					pDownLoadBitmap= LoadImgByPath(notifyData.pszFilePath);
					if(pDownLoadBitmap != NULL)
					{
						TImage* pImage = static_cast<TImage*>(GetControlPtr(gItemData[notifyData.nParam].nImageID));
						if(pImage != NULL)
						{
							if( gItemData[notifyData.nParam].pBmp != NULL)
							{
								gItemData[notifyData.nParam].pBmp->Destroy();
								gItemData[notifyData.nParam].pBmp = NULL;									
							}
							gItemData[notifyData.nParam].pBmp = pDownLoadBitmap->Create(IMAGE_W, IMAGE_H, 32);
							gItemData[notifyData.nParam].pBmp->QuickSpecialZoom(pDownLoadBitmap, 0, 0);
					
							//pImage->SetImage(gItemData[notifyData.nParam].pBmp, (HEADMASKBUTTON_W - gItemData[notifyData.nParam].pBmp->GetWidth())/2, (HEADMASKBUTTON_H - gItemData[notifyData.nParam].pBmp->GetHeight())/2 );
							pImage->SetBitmap(gItemData[notifyData.nParam].pBmp);
							pImage->Draw();
						}

						//释放图片
						pDownLoadBitmap->Destroy();
						pDownLoadBitmap = NULL; 							
					}
				}					
				break;
				
				case RR_PhotosUpload:
				{
					if(pApp->MessageBox(TResource::LoadConstString(APP_RE_ID_STRING_PhotoUploadContinue),TResource::LoadConstString(APP_RE_ID_STRING_PhotoUploadSuccess),WMB_YESNO) ==0 )
					{
						HitControl(m_TitleBtnLeft); 
					}
					else
					{
						RenRenAPICommon_Download(RR_PhotosGetAlbums, this->GetWindowHwndId(), 0, m_FormMode); 
					}
					break;
				}

				case RR_UsersGetInfoPhoto:
					{
					tResponseUsersGetInfo* Response = NULL;
					RenRenAPI_JsonParse(RR_UsersGetInfoPhoto, (void **)&Response);
					if(Response)
						{
						_UpdateProfilePhoto(pApp, Response);
						delete Response;
						Response = NULL;
						}
					}
				break;					
			default:
				break;
			}
		}
		break;
		
		case MSG_POST_THREAD_NOTIFY:
		{
			PostNotifyMsgDataType notifyData;
			Sys_GetMessageBody((MESSAGE_t *)pEvent, &notifyData, sizeof(PostNotifyMsgDataType));

			if(notifyData.nParam == EDIT_PARAM_PASSWORD)
			{
				Set_Url_Params(RR_PhotosGet, "password", (char*)notifyData.pszEditContent);	
				RenRenAPICommon_Download(RR_PhotosGet, this->GetWindowHwndId(), 0, 0); 
			}
			else if(notifyData.nParam == RR_PhotosUpload)
			{
				Set_Url_Params(RR_PhotosUpload, "caption", (char*)notifyData.pszEditContent);
				RenRenAPICommon_Download(RR_PhotosUpload,  this->GetWindowHwndId(), 0, 0);
			}
			
			bHandled = TRUE;
			break;
		}
	default:
		break;
	}

	if (!bHandled)
	{
		bHandled = TWindow::EventHandler(pApp, pEvent);
	}

	return bHandled;
}
Exemplo n.º 4
0
// 窗口事件处理
Boolean TCommentDetailForm::EventHandler(TApplication * pApp, EventType * pEvent)
{
	Boolean bHandled = FALSE;

	switch (pEvent->eType)
	{
	case EVENT_WinInit:
		{
			_OnWinInitEvent(pApp, pEvent);
			bHandled = TRUE;
			break;
		}

	case EVENT_WinClose:
		{
			_OnWinClose(pApp, pEvent);
			break;
		}

	case EVENT_WinEraseClient:
		{
			TDC 	   dc(this);
			WinEraseClientEventType *pEraseEvent = reinterpret_cast< WinEraseClientEventType* >( pEvent );
			TRectangle rc(pEraseEvent->rc);
			TRectangle rcBack(5, 142, 310, 314);
			this->GetBounds(&rcBack);

			// 擦除
			dc.EraseRectangle(&rc, 0);

			dc.DrawBitmapsH(TResource::LoadConstBitmap(APP_KA_ID_BITMAP_title_bg), 0, 0, SCR_W,
				GUI_API_STYLE_ALIGNMENT_LEFT);

			//dc.DrawBitmapsH(TResource::LoadConstBitmap(APP_KA_ID_BITMAP_bottom_bg), 0, rcBack.Bottom()-68, 
			//320, GUI_API_STYLE_ALIGNMENT_LEFT|GUI_API_STYLE_ALIGNMENT_TOP); 


			pEraseEvent->result = 1;				
			bHandled = TRUE;
		}
		break;

	case EVENT_CtrlSelect:
		{
			bHandled = _OnCtrlSelectEvent(pApp, pEvent);
			break;
		}
	case MSG_POST_THREAD_NOTIFY:
		{
			PostNotifyMsgDataType notifyData;
			Sys_GetMessageBody((MESSAGE_t *)pEvent, &notifyData, sizeof(PostNotifyMsgDataType));

			switch(notifyData.nEditType)
			{
			case ReplyUserCommentEdit:
			case ReplyCommentEdit:
				{		
					Set_Url_Params(KX_ReplyComment, "replycont", (char*)notifyData.PostMsgData.commentdata.pszCommentContent);
					Set_Url_Params(KX_ReplyComment, "fuid", (char*)notifyData.PostMsgData.commentdata.nOuid);	
					Set_Url_Params(KX_ReplyComment, "thread_cid", (char*)notifyData.PostMsgData.commentdata.nId);					

					KaiXinAPICommon_Download(KX_ReplyComment, this->GetWindowHwndId());
					break;
				}			

			default:
				break;

			}

			bHandled = TRUE;
		}
		break;	
		//下载完成消息在给各自form中处理模板
	case MSG_DL_THREAD_NOTIFY:
		{
			NotifyMsgDataType notifyData;
			Sys_GetMessageBody((MESSAGE_t *)pEvent, &notifyData, sizeof(NotifyMsgDataType));						

			bHandled = TRUE;
			switch(notifyData.nAccessType)
			{
			case KX_PhotoDownload:
				{
					if( pBmp[notifyData.nParam] != NULL)
					{
						pBmp[notifyData.nParam]->Destroy();
						pBmp[notifyData.nParam] = NULL; 								
					}
					pBmp[notifyData.nParam] = LoadImgByPath(notifyData.pszFilePath);

					if(pBmp[notifyData.nParam])
					{
						TImage* pTImage;

						pTImage = static_cast< TImage* >(this->GetControlPtr(m_iaTImageID[notifyData.nParam]));
						if(pTImage)
						{
							pTImage->SetBitmap(pBmp[notifyData.nParam]);
							pTImage->Draw();
						}
					}
					break;
				}
			case KX_ReplyComment:
				{
					//Shoud do update data here

					break;
				}
			case KX_DeleteComment:
				{
					//Shoud do update data here
					this->CloseWindow();
					break;
				}				
			}

		}
	case EVENT_KeyCommand: 
		{ 
			// 抓取右软键事件 
			if (pEvent->sParam1 == SYS_KEY_SOFTKEY_RIGHT_UP  
				|| pEvent->sParam1 == SYS_KEY_SOFTKEY_RIGHT_LONG) 
			{ 
				// 模拟退出按钮选中消息 
				HitControl(m_BackBtn); 
				bHandled = TRUE; 
			} 
		} 
		break;
	default:
		break;
	}

	if (!bHandled)
	{
		bHandled = TWindow::EventHandler(pApp, pEvent);
	}

	return bHandled;
}
Exemplo n.º 5
0
// 窗口初始化
Boolean TFeedGetFangleForm::_OnWinInitEvent(TApplication * pApp, EventType * pEvent)
{
	int iRet = eFailed;
	
	m_TitleBtnRight = SetAppTitleButton(this, APP_RE_ID_STRING_Back,TITLE_BUTTON_RIGHT);
	SetAppTilte(this, APP_RE_ID_STRING_Fangle_Count);

	//从对应Json中获取数据,用于更新UI
	iRet = RenRenAPI_JsonParse(RR_FeedGetFangle, (void **)&Response);	
	if( Response == NULL || iRet != 0 )
	{
		return FALSE;
	}

	TCoolBarList* pTCoolBarList = NULL;
	TRectangle mTRectangle(0,0,0,0);

	if(Response->nArraySize == 0)
	{
		//无回复提示
		TPanel* pTPanel = NULL;
		pTPanel = static_cast<TPanel*>(GetControlPtr(APP_RE_ID_CommonListForm_CommonPanel));

		TCtrl* mControlTImage;
		TCtrl* mControlTLabel;
		TImage* pTImage = NULL;
		TLabel* pTLabel = NULL;
		mControlTImage = new TImage;
		if(mControlTImage->Create(pTPanel))
		{
			mTRectangle.SetRect(8,10,50,50);
			mControlTImage->SetBounds(&mTRectangle);
			pTImage = static_cast<TImage*>(mControlTImage);
			pTImage->SetBitmap(TResource::LoadConstBitmap(APP_RE_ID_BITMAP_comment_img_with_frame));
			pTImage->SetBounds(&mTRectangle);
		}
		mControlTLabel = new TLabel;
		if(mControlTLabel->Create(pTPanel))
		{
			mTRectangle.SetRect((mTRectangle.X() + mTRectangle.Width()),(mTRectangle.Y()+ 10) ,200,50);
			mControlTLabel->SetBounds(&mTRectangle);
			pTLabel = static_cast<TLabel*>(mControlTLabel);
			pTLabel->SetCaption(TResource::LoadConstString(APP_RE_ID_STRING_NothingFangle), FALSE);
		}
		 
		goto OutCoolBarList;
	}


	pTCoolBarList = static_cast<TCoolBarList*>(GetControlPtr(APP_RE_ID_CommonListForm_CommonCoolBarList));
	if(pTCoolBarList)
	{
		mTRectangle.SetRect(6,0,308,412);
		TBarListItem* pTBarListItem = NULL;
		TBarRowList* pTBarRowList = NULL;
		TBarRow* pTBarRow = NULL;
		TFont mTFont;
		pTBarRowList = pTCoolBarList->Rows();
		if(pTBarRowList)
		{
			pTBarRowList->BeginUpdate();
			pTBarRowList->Clear();
			pTBarRow = pTBarRowList->AppendRow();
			if(pTBarRow)
			{
				pTBarRow->SetCaption(NULL);
				for(int i = 0; i < Response->nArraySize; ++i)
				{
					
					Coord mItemHeight = 0;
					pTBarListItem = pTBarRow->AppendItem();
					if(pTBarListItem)
					{	
												
						pTBarListItem->SetCaption(NULL);
						pTBarListItem->SetTitle(NULL);
						pTBarListItem->SetIndicatorType(itDefault);
						pTBarListItem->SetValue(1);

						CtrlAddItemToCoolBarList_Image(this, pTBarListItem, 10,10, 16, 16, (TBitmap*)TResource::LoadConstBitmap(APP_RE_ID_BITMAP_FeedType_comment));

						TUChar buf[256] = {0};
						char   szbuf[512] = {0};
						strcpy(szbuf,Response->Array[i].name);
						strcat(szbuf,Response->Array[i].prefix);
						if(strcmp(Response->Array[i].title,"") != 0)
						{
							strcat(szbuf,"'");
							strcat(szbuf,Response->Array[i].title);
							strcat(szbuf,"'");
						}
						strcat(szbuf,Response->Array[i].sufix);
						TUString::StrUtf8ToStrUnicode(buf, (Char *)szbuf);

						CtrlAddItemToCoolBarList_RichView(this, pTBarListItem, 30, 10, SCR_W - 70, &mItemHeight, FONT_NORMAL, buf, RGB_COLOR_BLACK);
						
						TUString::StrUtf8ToStrUnicode(buf, (const Char *)Response->Array[i].time);
						CtrlAddItemToCoolBarList_Lable(this, pTBarListItem, 30, mItemHeight + 20, 0, FONT_SMALL, buf, RGB_COLOR_LIGHTBLUE);

						mItemHeight = mItemHeight + 40;
						pTBarListItem->SetHeight(mItemHeight);
						//pTBarListItem->SetHeight(60);
					}
				}
			}
			
			pTBarRowList->EndUpdate();
		}
	}

OutCoolBarList:

	return TRUE;
}