------------------------------------------------------------------------------
| 1218 | |
| 1219 | //------------------------------------------------------------------------------ |
| 1220 | void GuiPopUpMenuCtrl::onAction() |
| 1221 | { |
| 1222 | GuiControl *canCtrl = getParent(); |
| 1223 | |
| 1224 | addChildren(); |
| 1225 | |
| 1226 | GuiCanvas *root = getRoot(); |
| 1227 | Point2I windowExt = root->getExtent(); |
| 1228 | |
| 1229 | mBackground->resize( Point2I(0,0), root->getExtent() ); |
| 1230 | |
| 1231 | S32 textWidth = 0, width = getWidth(); |
| 1232 | const S32 textSpace = 2; |
| 1233 | bool setScroll = false; |
| 1234 | |
| 1235 | for ( U32 i = 0; i < mEntries.size(); ++i ) |
| 1236 | if ( S32(mProfile->mFont->getStrWidth( mEntries[i].buf )) > textWidth ) |
| 1237 | textWidth = mProfile->mFont->getStrWidth( mEntries[i].buf ); |
| 1238 | |
| 1239 | S32 sbWidth = mSc->getControlProfile()->mBorderThickness * 2 + mSc->scrollBarThickness(); // Calculate the scroll bar width |
| 1240 | if ( textWidth > ( getWidth() - sbWidth-mProfile->mTextOffset.x - mSc->getChildMargin().x * 2 ) ) // The text draw area to test against is the width of the drop-down minus the scroll bar width, the text margin and the scroll bar child margins. |
| 1241 | { |
| 1242 | textWidth +=sbWidth + mProfile->mTextOffset.x + mSc->getChildMargin().x * 2; // The new width is the width of the text plus the scroll bar width plus the text margin size plus the scroll bar child margins. |
| 1243 | width = textWidth; |
| 1244 | |
| 1245 | // If a child margin is not defined for the scroll control, let's add |
| 1246 | // some space between the text and scroll control for readability |
| 1247 | if(mSc->getChildMargin().x == 0) |
| 1248 | width += textSpace; |
| 1249 | } |
| 1250 | |
| 1251 | mTl->setCellSize(Point2I(width, mProfile->mFont->getHeight() + textSpace)); |
| 1252 | |
| 1253 | for ( U32 j = 0; j < mEntries.size(); ++j ) |
| 1254 | mTl->addEntry( mEntries[j].id, mEntries[j].buf ); |
| 1255 | |
| 1256 | if ( mSelIndex >= 0 ) |
| 1257 | mTl->setSelectedCell( Point2I( 0, mSelIndex ) ); |
| 1258 | |
| 1259 | Point2I pointInGC = canCtrl->localToGlobalCoord( getPosition() ); |
| 1260 | Point2I scrollPoint( pointInGC.x, pointInGC.y + getHeight() ); |
| 1261 | |
| 1262 | //Calc max Y distance, so Scroll Ctrl will fit on window |
| 1263 | |
| 1264 | S32 sbBorder = mSc->getControlProfile()->mBorderThickness * 2 + mSc->getChildMargin().y * 2; |
| 1265 | S32 maxYdis = windowExt.y - pointInGC.y - getHeight() - sbBorder; |
| 1266 | |
| 1267 | //If scroll bars need to be added |
| 1268 | mRevNum = 0; |
| 1269 | if ( maxYdis < mTl->getHeight() + sbBorder ) |
| 1270 | { |
| 1271 | //Should we pop menu list above the button |
| 1272 | if ( maxYdis < pointInGC.y ) |
| 1273 | { |
| 1274 | if(mReverseTextList) |
| 1275 | reverseTextList(); |
| 1276 | |
| 1277 | maxYdis = pointInGC.y; |
no test coverage detected