/** 将字符串转为TRectangle * * \param x char*字符串,Left坐标。 * \param y char*字符串,Right坐标。 * \param w char*字符串,宽度W。 * \param h char*字符串,高度H。 * \param[out] rc 转化成的TRectangle * \return 是否成功 */ bool StringToRect(const char* x, const char* y, const char* w, const char* h, TRectangle& rc) { if ( x == NULL || x == 0 || y == NULL || y == 0|| w == NULL || w== 0|| h == NULL || h== 0) return false; rc.SetX(atoi(x)); rc.SetY(atoi(y)); rc.SetWidth(atoi(w)); rc.SetHeight(atoi(h)); return true; }
// 窗口初始化 Boolean TPhotosGetAlbumsForm::_OnWinInitEvent(TApplication * pApp, EventType * pEvent) { int nErrorCode = eFailed; Int32 Height_Panel = 0; //Panel高度 //m_TitleBtnLeft = SetAppTitleButton(this, APP_RE_ID_STRING_Comment,TITLE_BUTTON_LEFT); //显示不同的title if(m_FormMode == FORM_MODE_NORMAL) { SetAppTilte(this, APP_RE_ID_STRING_Album); m_TitleBtnRight = SetAppTitleButton(this, APP_RE_ID_STRING_Back,TITLE_BUTTON_RIGHT); char* uid = NULL; uid = Get_Url_Params(RR_PhotosGetAlbums, "uid"); if( strcmp(uid, RenRenUserInfo.szuid) == 0) { m_TitleBtnLeft = SetAppBitmapButton(this, APP_RE_ID_BITMAP_take_photo, APP_RE_ID_BITMAP_take_photo); } } else if(m_FormMode == FORM_MODE_MYHOME) { tResponseProfile* ResponseProfile; nErrorCode = RenRenAPI_JsonParse(RR_ProfileGetInfo, (void **)&ResponseProfile); if(ResponseProfile != NULL) { if(ResponseProfile->uid == RenRenUserInfo.uid) { SetAppTilte(this, APP_RE_ID_STRING_MyNews); m_TitleBtnRight = SetAppTitleButton(this, APP_RE_ID_STRING_Home, TITLE_BUTTON_RIGHT); m_TitleBtnLeft = SetAppBitmapButton(this, APP_RE_ID_BITMAP_take_photo, APP_RE_ID_BITMAP_take_photo); } else { //姓名 TUChar pszFName[64] = {0}; TUString::StrUtf8ToStrUnicode(pszFName , (const Char *)ResponseProfile->name); SetAppTilte(this, 0, pszFName); m_TitleBtnRight = SetAppTitleButton(this, APP_RE_ID_STRING_Back,TITLE_BUTTON_RIGHT); } delete ResponseProfile; ResponseProfile = NULL; } } //设置panel高度 TPanel* pTPanel = static_cast<TPanel*>(GetControlPtr(APP_RE_ID_CommonListForm_CommonPanel)); TCoolBarList* pCoolBarList = static_cast<TCoolBarList*>(GetControlPtr(APP_RE_ID_CommonListForm_CommonCoolBarList)); if(pTPanel) { TRectangle rect; Height_Panel = SCR_H - STATUSBAR_H - TITLEBAR_H; if(m_FormMode == FORM_MODE_MYHOME) Height_Panel -= BOTTOM_TAB_H; pTPanel->GetBounds(&rect); rect.SetHeight(Height_Panel); pTPanel->SetBounds(&rect); } if(m_FormMode == FORM_MODE_MYHOME) CreateProfileBottomTab(this, &BottomTabCtrID, 2); //显示个人信息 if(m_FormMode == FORM_MODE_MYHOME) { Int32 Height_Top = 0; //CoolBarList上面信息的高度 Int32 Height_CoolBarList = 0; //CoolBarList高度 tResponseProfile* ResponseProfile; nErrorCode = RenRenAPI_JsonParse(RR_ProfileGetInfo, (void **)&ResponseProfile); if(ResponseProfile != NULL) { //头像 TBitmap* pDownLoadBitmap = NULL; pDownLoadBitmap = LoadImgByUrl(ResponseProfile->headurl); //pProfileImage = LoadImgByUrl(ResponseProfile->headurl); const TBitmap * pImageDeault = TResource::LoadConstBitmap(APP_RE_ID_BITMAP_DefaultLarge); const TBitmap * pBackImage = TResource::LoadConstBitmap(APP_RE_ID_BITMAP_headmask_large); if(pDownLoadBitmap == NULL) { //RenRenAPICommon_DownloadPhoto(ResponseProfile->headurl, this->GetWindowHwndId(), FEED_PROFILE_IMAGE_INDEX); m_ProfileImageID = CtrlAddItemToPanel_MaskButton(this, pTPanel, RR_HEAD_X, RR_HEAD_Y, RR_HEAD_W, RR_HEAD_H, (TBitmap*)pImageDeault, (TBitmap*)pImageDeault, (TBitmap*)pBackImage ); this->DisableControl(m_ProfileImageID); } else { //需要做放大 pProfileImage = TBitmap::Create(RR_HEAD_W, RR_HEAD_W, pDownLoadBitmap->GetDepth()); pProfileImage->QuickZoom(pDownLoadBitmap, TRUE, TRUE,RGBA(0,0,0,255)); m_ProfileImageID = CtrlAddItemToPanel_MaskButton(this, pTPanel, RR_HEAD_X, RR_HEAD_Y, RR_HEAD_W, RR_HEAD_H, (TBitmap*)pProfileImage, (TBitmap*)pProfileImage, (TBitmap*)pBackImage ); this->DisableControl(m_ProfileImageID); //释放图片 pDownLoadBitmap->Destroy(); pDownLoadBitmap = NULL; } //下载大头像 tResponseUsersGetInfo* ResponseUserInfoPhoto = NULL; RenRenAPI_JsonParse(RR_UsersGetInfoPhoto, (void **)&ResponseUserInfoPhoto); if(ResponseUserInfoPhoto) { if( (ResponseUserInfoPhoto->nArraySize > 0) && (ResponseUserInfoPhoto->Array[0].uid == ResponseProfile->uid) ) { _UpdateProfilePhoto(pApp, ResponseUserInfoPhoto); } else { Set_Url_Params(RR_UsersGetInfoPhoto, "uids", m_uid); RenRenAPICommon_Download(RR_UsersGetInfoPhoto, this->GetWindowHwndId(), 0, 0); } delete ResponseUserInfoPhoto; ResponseUserInfoPhoto = NULL; } else { Set_Url_Params(RR_UsersGetInfoPhoto, "uids", m_uid); RenRenAPICommon_Download(RR_UsersGetInfoPhoto, this->GetWindowHwndId(), 0, 0); } //姓名 TUChar pszFName[64] = {0}; TUString::StrUtf8ToStrUnicode(pszFName , (const Char *)ResponseProfile->name); CtrlAddItemToPanel_Label(this, pTPanel, RR_NAME_X, RR_NAME_Y, 0, FONT_NORMAL, pszFName, RGB_COLOR_BLACK); Height_Top += (RR_NAME_Y+RR_NAME_H); //状态 TUChar pszStatus[1024] = {0}; Coord nHeight_RichView = 0; if(ResponseProfile->nSize_status>0) { TUString::StrUtf8ToStrUnicode(pszStatus, (const Char *)ResponseProfile->status[0].content); CtrlAddItemToPanel_RichView(this, pTPanel, RR_STATUS_X, RR_STATUS_Y, RR_STATUS_W, &nHeight_RichView, FONT_MIDDLE, pszStatus, RGB_COLOR_BLACK); } //位置容错调整 if(nHeight_RichView > (RR_HEAD_H-RR_NAME_H) ) Height_Top += nHeight_RichView; else Height_Top += (RR_HEAD_H- RR_NAME_H); //调整间隔 Height_Top += 4; //设置CoolBarList高度 if(pCoolBarList) { TRectangle rect; Int32 nY = Height_Top; pCoolBarList->GetBounds(&rect); rect.SetY(nY); pCoolBarList->SetBounds(&rect); } delete ResponseProfile; ResponseProfile = NULL; } } //从对应Json中获取数据,用于更新UI nErrorCode = RenRenAPI_JsonParse(RR_PhotosGetAlbums, (void **)&Response); if (Response ) { _SetAlbumCoolBarList(pApp); delete Response; Response = NULL; } else { //显示无权限操作的情况(用户设置了阅读权限) if(nErrorCode == 200) { TUChar ErrorInfo[ERROR_INFO_LEN] = {0}; if(RenRenAPI_JsonParse_bSuccess(RR_PhotosGetAlbums, ErrorInfo) != 0) { if(TUString::StrLen(ErrorInfo) > 0) { //动态添加列表数据 TBarRowList* pRowList = NULL; TBarRow* pBarRow = NULL; pRowList = pCoolBarList->Rows(); pRowList->Clear(); pBarRow = pRowList->AppendRow(); //显示错误提示 TBarListItem* lpItem = NULL; lpItem = pBarRow->AppendItem(); if (lpItem) { CtrlAddItemToCoolBarList_Lable(this, lpItem, RR_INFO_X, RR_INFO_Y, RR_INFO_W, FONT_NORMAL, (TUChar*)ErrorInfo); lpItem->SetHeight(RR_INFO_H); lpItem->SetEnabled(FALSE); } } } } } return TRUE; }
// 窗口初始化 Boolean TGuestbookGetForm::_OnWinInitEvent(TApplication * pApp, EventType * pEvent) { m_TitleBtnLeft = SetAppBitmapButton(this, APP_RE_ID_BITMAP_write_but, APP_RE_ID_BITMAP_write_but_over); //m_TitleBtnRight = SetAppTitleButton(this, APP_RE_ID_STRING_Back,TITLE_BUTTON_RIGHT); //SetAppTilte(this, APP_RE_ID_STRING_Guestbook); //显示不同的title if(m_FormMode == FORM_MODE_NORMAL) { SetAppTilte(this, APP_RE_ID_STRING_Guestbook); m_TitleBtnRight = SetAppTitleButton(this, APP_RE_ID_STRING_Back,TITLE_BUTTON_RIGHT); } else if(m_FormMode == FORM_MODE_MYHOME) { tResponseProfile* ResponseProfile; RenRenAPI_JsonParse(RR_ProfileGetInfo, (void **)&ResponseProfile); if(ResponseProfile) { if(ResponseProfile->uid == RenRenUserInfo.uid) { SetAppTilte(this, APP_RE_ID_STRING_MyNews); m_TitleBtnRight = SetAppTitleButton(this, APP_RE_ID_STRING_Home,TITLE_BUTTON_RIGHT); } else { TUChar pszFName[64] = {0}; TUString::StrUtf8ToStrUnicode(pszFName , (const Char *)ResponseProfile->name); SetAppTilte(this, 0, pszFName); m_TitleBtnRight = SetAppTitleButton(this, APP_RE_ID_STRING_Back,TITLE_BUTTON_RIGHT); } delete ResponseProfile; ResponseProfile = NULL; } } //设置panel高度 TPanel* pTPanel = static_cast<TPanel*>(GetControlPtr(APP_RE_ID_CommonListForm_CommonPanel)); TCoolBarList* pCoolBarList = static_cast<TCoolBarList*>(GetControlPtr(APP_RE_ID_CommonListForm_CommonCoolBarList)); if( (pTPanel == NULL) || (pCoolBarList == NULL) ) return FALSE; //调整Panel高度 { TRectangle rect; Int32 Height_Panel = 0; //Panel高度 Height_Panel = SCR_H - STATUSBAR_H - TITLEBAR_H; if(m_FormMode == FORM_MODE_MYHOME) Height_Panel -= BOTTOM_TAB_H; pTPanel->GetBounds(&rect); rect.SetHeight(Height_Panel); pTPanel->SetBounds(&rect); } if(m_FormMode == FORM_MODE_MYHOME) CreateProfileBottomTab(this, &BottomTabCtrID, 4); //:TODO: //显示个人信息 if(m_FormMode == FORM_MODE_MYHOME) { Int32 Height_Top = 0; //CoolBarList上面信息的高度 tResponseProfile* ResponseProfile; RenRenAPI_JsonParse(RR_ProfileGetInfo, (void **)&ResponseProfile); if(ResponseProfile != NULL) { //头像 TBitmap* pDownLoadBitmap = NULL; pDownLoadBitmap = LoadImgByUrl(ResponseProfile->headurl); //pProfileImage = LoadImgByUrl(ResponseProfile->headurl); const TBitmap * pImageDeault = TResource::LoadConstBitmap(APP_RE_ID_BITMAP_DefaultLarge); const TBitmap * pBackImage = TResource::LoadConstBitmap(APP_RE_ID_BITMAP_headmask_large); if(pDownLoadBitmap == NULL) { //RenRenAPICommon_DownloadPhoto(ResponseProfile->headurl, this->GetWindowHwndId(), FEED_PROFILE_IMAGE_INDEX); m_ProfileImageID = CtrlAddItemToPanel_MaskButton(this, pTPanel, RR_HEAD_X, RR_HEAD_Y, RR_HEAD_W, RR_HEAD_H, (TBitmap*)pImageDeault, (TBitmap*)pImageDeault, (TBitmap*)pBackImage ); this->DisableControl(m_ProfileImageID); } else { //需要做放大 pProfileImage = TBitmap::Create(RR_HEAD_W, RR_HEAD_W, pDownLoadBitmap->GetDepth()); pProfileImage->QuickZoom(pDownLoadBitmap, TRUE, TRUE,RGBA(0,0,0,255)); m_ProfileImageID = CtrlAddItemToPanel_MaskButton(this, pTPanel, RR_HEAD_X, RR_HEAD_Y, RR_HEAD_W, RR_HEAD_H, (TBitmap*)pProfileImage, (TBitmap*)pProfileImage, (TBitmap*)pBackImage ); this->DisableControl(m_ProfileImageID); //释放图片 pDownLoadBitmap->Destroy(); pDownLoadBitmap = NULL; } //下载大头像 tResponseUsersGetInfo* ResponseUserInfoPhoto = NULL; RenRenAPI_JsonParse(RR_UsersGetInfoPhoto, (void **)&ResponseUserInfoPhoto); if(ResponseUserInfoPhoto) { if( (ResponseUserInfoPhoto->nArraySize > 0) && (ResponseUserInfoPhoto->Array[0].uid == ResponseProfile->uid) ) { _UpdateProfilePhoto(pApp, ResponseUserInfoPhoto); } else { Set_Url_Params(RR_UsersGetInfoPhoto, "uids", m_uid); RenRenAPICommon_Download(RR_UsersGetInfoPhoto, this->GetWindowHwndId(), 0, 0); } delete ResponseUserInfoPhoto; ResponseUserInfoPhoto = NULL; } else { Set_Url_Params(RR_UsersGetInfoPhoto, "uids", m_uid); RenRenAPICommon_Download(RR_UsersGetInfoPhoto, this->GetWindowHwndId(), 0, 0); } //姓名 TUChar pszFName[64] = {0}; TUString::StrUtf8ToStrUnicode(pszFName , (const Char *)ResponseProfile->name); CtrlAddItemToPanel_Label(this, pTPanel, RR_NAME_X, RR_NAME_Y, 0, FONT_NORMAL, pszFName, RGB_COLOR_BLACK); Height_Top += (RR_NAME_Y+RR_NAME_H); //状态 TUChar pszStatus[1024] = {0}; Coord nHeight_RichView = 0; if(ResponseProfile->nSize_status>0) { TUString::StrUtf8ToStrUnicode(pszStatus, (const Char *)ResponseProfile->status[0].content); CtrlAddItemToPanel_RichView(this, pTPanel, RR_STATUS_X, RR_STATUS_Y, RR_STATUS_W, &nHeight_RichView, FONT_MIDDLE, pszStatus, RGB_COLOR_BLACK); } //位置容错调整 if(nHeight_RichView > (RR_HEAD_H-RR_NAME_H) ) Height_Top += nHeight_RichView; else Height_Top += (RR_HEAD_H- RR_NAME_H); //调整间隔 Height_Top += 4; //设置CoolBarList高度 if(pCoolBarList) { TRectangle rect; Int32 nY = Height_Top; pCoolBarList->GetBounds(&rect); rect.SetY(nY); pCoolBarList->SetBounds(&rect); } delete ResponseProfile; ResponseProfile = NULL; } } //从对应Json中获取数据,用于更新UI int nErrorCode = eFailed; tResponseGuestbookGet* Response = NULL; nErrorCode = RenRenAPI_JsonParse(RR_GuestbookGet, (void **)&Response); //动态添加列表数据 TBarRowList* pRowList = NULL; TBarRow* pBarRow = NULL; pRowList = pCoolBarList->Rows(); pRowList->Clear(); pBarRow = pRowList->AppendRow(); if(Response != NULL) { TBarListItem* pListItem = NULL; //背景设置为白色底色 pCoolBarList->SetColor(CTL_COLOR_TYPE_FOCUS_BACK, RGB_COLOR_WHITE); pRowList->BeginUpdate(); if(Response->nArraySize == 0) { TUChar pszCount[64] = {0}; TUString::StrPrintF(pszCount, TResource::LoadConstString(APP_RE_ID_STRING_GuestbookCount), Response->nArraySize); TBarListItem* lpItem = NULL; lpItem = pBarRow->AppendItem(); lpItem->SetCaption(pszCount); lpItem->SetEnabled(FALSE); } //以下为增加列表项 for (int i = 0; i < Response->nArraySize; i++) { TUChar pszString[4096] = {0}; Coord nHeigh = 0; pListItem = pBarRow->AppendItem(); if (pListItem) { //属性设置 pListItem->SetTitle(NULL); pListItem->SetCaption(NULL); pListItem->SetIndicatorType(itNone); //先读取磁盘cache, 无文件再下载 gItemData[i].pBmp = LoadImgByUrl(Response->Array[i].headurl); if( gItemData[i].pBmp != NULL) { //头像,需要做缩放 gItemData[i].pBmpZoom = gItemData[i].pBmp->Create(HEADPHOTO_W, HEADPHOTO_H, 32); gItemData[i].pBmpZoom->QuickSpecialZoom(gItemData[i].pBmp, 0, 0); gItemData[i].HeadMaskButtonID = CtrlAddItemToCoolBarList_MaskButton(this, pListItem, HEADMASK_X, HEADMASK_Y, HEADMASKBUTTON_W, HEADMASKBUTTON_H, gItemData[i].pBmpZoom, (TBitmap*)TBitmap::LoadResBitmap(APP_RE_ID_BITMAP_head1)); } else { gItemData[i].HeadMaskButtonID = CtrlAddItemToCoolBarList_MaskButton(this, pListItem, HEADMASK_X, HEADMASK_Y, HEADMASKBUTTON_W, HEADMASKBUTTON_H, (TBitmap*)TBitmap::LoadResBitmap(APP_RE_ID_BITMAP_Default), (TBitmap*)TBitmap::LoadResBitmap(APP_RE_ID_BITMAP_head1)); RenRenAPICommon_DownloadPhoto(Response->Array[i].headurl, this->GetWindowHwndId(), i ); } //姓名 TUString::StrUtf8ToStrUnicode(pszString , (const Char *)Response->Array[i].name); CtrlAddItemToCoolBarList_Lable(this, pListItem, NAME_X, NAME_Y, 0, NAME_FONT, pszString, RGB_COLOR_LIGHTBLUE); //悄悄话 if(Response->Array[i].is_whisper != 0) { gItemData[i].bWhisper = TRUE; CtrlAddItemToCoolBarList_Image(this, pListItem, WHISPER_X, WHISPER_Y , 49, 15, (TBitmap*)TResource::LoadConstBitmap(APP_RE_ID_BITMAP_whisper)); } //内容,去掉html格式化内容 StrRemoveAtoB(Response->Array[i].content, strlen(Response->Array[i].content), "<", ">"); TUString::StrUtf8ToStrUnicode(pszString , (const Char *)Response->Array[i].content); CtrlAddItemToCoolBarList_RichView(this, pListItem, CONTENT_X, CONTENT_Y, CONTENT_W, &nHeigh, CONTENT_FONT, pszString); //时间 TUString::StrUtf8ToStrUnicode(pszString , (const Char *)Response->Array[i].time); CtrlAddItemToCoolBarList_Lable(this, pListItem, TIME_X, CONTENT_Y+nHeigh, 0, TIME_FONT, pszString, RGB_COLOR_GRAY); //回复 if(Response->Array[i].uid != RenRenUserInfo.uid) { TUString::StrCopy(pszString,TResource::LoadConstString(APP_RE_ID_STRING_Reply)); gItemData[i].TButtonReplyID = CtrlAddItemToCoolBarList_Button(this, pListItem, BUTTON_REPLY_X, BUTTON_REPLY_Y, BUTTON_REPLY_W, BUTTON_REPLY_H, pszString); } //设置CoolBarList Item的高度 pListItem->SetHeight(60 + nHeigh); //保存id gItemData[i].id = Response->Array[i].id; gItemData[i].uid = Response->Array[i].uid; } } pRowList->EndUpdate(); delete Response; Response = NULL; } else { //显示无权限操作的情况(用户设置了阅读权限) if(nErrorCode == 200) { TUChar ErrorInfo[ERROR_INFO_LEN] = {0}; int iResult = RenRenAPI_JsonParse_bSuccess(RR_GuestbookGet, ErrorInfo); if(iResult != 0) { if(TUString::StrLen(ErrorInfo) > 0) { //显示错误提示 TBarListItem* lpItem = NULL; lpItem = pBarRow->AppendItem(); if (lpItem) { CtrlAddItemToCoolBarList_Lable(this, lpItem, RR_INFO_X, RR_INFO_Y, RR_INFO_W, FONT_NORMAL, (TUChar*)ErrorInfo); lpItem->SetHeight(RR_INFO_H); lpItem->SetEnabled(FALSE); } } } } } return TRUE; }