void UserIoSourceState::CalculateStringWidths(bool forceVisible) { Component::CalculateStringWidths(forceVisible); GUI_SetFont(GetFont()); int component_width = GetWidth() - mLeftMargin - mRightMargin; int component_height = GetHeight(); int string_width_pixels = 0; int string_height_pixels = 0; for (int i = 0; i < mStringIdCount; i++) { string_width_pixels = 0; string_height_pixels = 0; bool fits = false; const char* p_text = Languages::GetInstance()->GetString(mSourceIndexStringIds[i].stringId); if (strlen(p_text)>0 && p_text[0] != '{') { GUI_RECT rect; if (mWordWrap) { SetText(p_text); int line_count = WrapText(component_width); fits = (line_count <= (component_height/GetFont()->YSize)); GUI_GetTextExtend(&rect,mTextWrapped,strlen(mTextWrapped)); string_width_pixels = abs(rect.x1 - rect.x0) + 1; string_height_pixels = (abs(rect.y1 - rect.y0) + 1) * line_count; } else { GUI_GetTextExtend(&rect,p_text,strlen(p_text)); string_width_pixels = abs(rect.x1 - rect.x0) + 1; string_height_pixels = abs(rect.y1 - rect.y0) + 1; fits = (string_width_pixels <= component_width); } } bool visible = (mSourceIndexStringIds[i].source == mpChannelConfig->GetSource() && mSourceIndexStringIds[i].sourceIndex == mpChannelConfig->GetSourceIndex()); CSV_ENTRY entry; entry.componentId = mComponentId; entry.stringId = mSourceIndexStringIds[i].stringId; entry.componentWidth = component_width; entry.stringWidth = string_width_pixels; entry.componentHeight = component_height; entry.stringHeight = string_height_pixels; entry.wordwrap = mWordWrap; entry.fits = fits; entry.visible = visible; entry.forcedVisible = forceVisible; StringWidthCalculator::GetInstance()->WriteToCSV(entry); } }
/********************************************************************* * * MESSAGEBOX_Create */ WM_HWIN MESSAGEBOX_Create(const char * sMessage, const char * sCaption, int Flags) { GUI_WIDGET_CREATE_INFO _aDialogCreate[3]; /* 0: FrameWin, 1: Text, 2: Button */ int BorderSize = FRAMEWIN_GetDefaultBorderSize(); /* Default border size of frame window */ int xSizeFrame = MESSAGEBOX_XSIZEOK + 2 * BorderSize + MESSAGEBOX_BORDER * 2; /* XSize of frame window */ int ySizeFrame; /* YSize of frame window */ int x0, y0; /* Position of frame window */ int xSizeMessage; /* Length in pixels of message */ int xSizeCaption; /* Length in pixels of caption */ int ySizeCaption; /* YSize of caption */ int ySizeMessage; /* YSize of message */ WM_HWIN hBox; GUI_RECT Rect; const GUI_FONT GUI_UNI_PTR * pOldFont; /* Zeroinit variables */ memset(_aDialogCreate, 0, sizeof(_aDialogCreate)); /* Get dimension of message */ pOldFont = GUI_SetFont(TEXT_GetDefaultFont()); GUI_GetTextExtend(&Rect, sMessage, 255); xSizeMessage = Rect.x1 - Rect.x0 + MESSAGEBOX_BORDER * 2; ySizeMessage = Rect.y1 - Rect.y0 + 1; if (xSizeFrame < (xSizeMessage + 4 + MESSAGEBOX_BORDER * 2)) { xSizeFrame = xSizeMessage + 4 + MESSAGEBOX_BORDER * 2; } ySizeCaption = GUI_GetYSizeOfFont(FRAMEWIN_GetDefaultFont()); ySizeFrame = ySizeMessage + /* size of message */ MESSAGEBOX_YSIZEOK + /* size of button */ ySizeCaption + /* caption size */ MESSAGEBOX_BORDER * 3 + /* inner border - text, text - button, button - bottom */ BorderSize * 2 + /* top & bottom border */ 1; /* inner border */ /* Get xsize of caption */ xSizeCaption = GUI_GetStringDistX(sCaption); if (xSizeFrame < xSizeCaption + BorderSize * 2) { xSizeFrame = xSizeCaption + BorderSize * 2; } /* Check maximum */ if (xSizeFrame > LCD_GET_XSIZE()) { xSizeFrame = LCD_GET_XSIZE(); } if (ySizeFrame > LCD_GET_YSIZE()) { ySizeFrame = LCD_GET_YSIZE(); } /* Calculate position of framewin */ x0 = GUI_OrgX + (LCD_GET_XSIZE() - xSizeFrame) / 2; y0 = GUI_OrgY + (LCD_GET_YSIZE() - ySizeFrame) / 2; /* restore modified Context */ GUI_SetFont(pOldFont); /* Fill frame win resource */ _aDialogCreate[0].pfCreateIndirect = FRAMEWIN_CreateIndirect; _aDialogCreate[0].pName = sCaption; _aDialogCreate[0].x0 = x0; _aDialogCreate[0].y0 = y0; _aDialogCreate[0].xSize = xSizeFrame; _aDialogCreate[0].ySize = ySizeFrame; if (Flags & GUI_MESSAGEBOX_CF_MOVEABLE) { _aDialogCreate[0].Flags = FRAMEWIN_CF_MOVEABLE; } /* Fill text resource */ _aDialogCreate[1].pfCreateIndirect = TEXT_CreateIndirect; _aDialogCreate[1].pName = sMessage; _aDialogCreate[1].x0 = (xSizeFrame - xSizeMessage - BorderSize * 2) / 2; _aDialogCreate[1].y0 = MESSAGEBOX_BORDER; _aDialogCreate[1].xSize = xSizeMessage; _aDialogCreate[1].ySize = ySizeMessage; _aDialogCreate[1].Para = GUI_TA_TOP | GUI_TA_HCENTER; /* Fill button resource */ _aDialogCreate[2].pfCreateIndirect = BUTTON_CreateIndirect; _aDialogCreate[2].pName = "OK"; _aDialogCreate[2].Id = GUI_ID_OK; _aDialogCreate[2].x0 = (xSizeFrame - MESSAGEBOX_XSIZEOK - BorderSize * 2) / 2; _aDialogCreate[2].y0 = MESSAGEBOX_BORDER * 2 + ySizeMessage; _aDialogCreate[2].xSize = MESSAGEBOX_XSIZEOK; _aDialogCreate[2].ySize = MESSAGEBOX_YSIZEOK; /* Create dialog */ hBox = GUI_CreateDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate), MESSAGEBOX_Callback, 0, 0, 0); if (Flags & GUI_MESSAGEBOX_CF_MODAL) { WM_MakeModal(hBox); } return hBox; }