📄 z_msgwin.cpp
字号:
ZafWindowObject *object; if (firstButton) { // Initialize the display so that accurate text sizes can be obtained. BeginDraw(); display->SetFont(firstButton->LogicalPalette(ZAF_PM_TEXT, ZAF_PM_ANY_STATE).font); for (object = firstButton; object; object = object->Next()) { ZafRegionStruct textSize = display->TextSize(object->Text()); if (textSize.Width() > maxTextSize) maxTextSize = textSize.Width(); buttons++; } // Restore the display. EndDraw(); } int buttonWidth = ZafMax(maxTextSize + 2 * display->cellWidth, 10 * display->cellWidth); // Allow the icon to size itself. if (icon) icon->Event(event); // If the text is to large for the screen let's back // off some. Arbitrarily chosen amount of 14 cells. if (textWidth > display->columns) { int windowWidth = display->columns - (14 * display->cellWidth); int leftSide = (4 * display->cellWidth) + (icon ? icon->zafRegion.Width() : 0); int fieldWidth = windowWidth - leftSide - display->cellWidth; int fieldHeight = (int)((float)textWidth / (float)fieldWidth) * display->cellHeight; textWidth = fieldWidth; textHeight = fieldHeight; } // Compute the client size. int clientWidth = textWidth + 4 * display->cellWidth + (icon ? icon->zafRegion.Width() + 2 * display->cellWidth : 0); if (clientWidth < (buttons * (buttonWidth + display->cellWidth)) + 3 * display->cellWidth) clientWidth = (buttons * (buttonWidth + display->cellWidth)) + 3 * display->cellWidth; int clientHeight = textHeight + 4 * display->cellHeight; // Position the text field. if (textField) { ZafRegionStruct textRegion; textRegion.coordinateType = ZAF_PIXEL; textRegion.left = 2 * display->cellWidth + (icon ? icon->zafRegion.Width() + 2 * display->cellWidth : 0); textRegion.top = display->cellHeight; textRegion.right = textRegion.left + textWidth - 1; textRegion.bottom = textRegion.top + textHeight - 1; textField->SetRegion(textRegion); } // Position the buttons. int left = (clientWidth - buttons * (buttonWidth + display->cellWidth) + display->cellWidth) / 2; int top = ZafMax(textHeight, icon ? icon->zafRegion.Height() : 0) + 2 * display->cellHeight; for (object = firstButton; object; object = object->Next()) { object->Event(event); int buttonHeight = object->zafRegion.Height(); ZafRegionStruct region; region.coordinateType = ZAF_PIXEL; region.left = left; region.right = region.left + buttonWidth - 1; region.bottom = top + display->cellHeight - display->postSpace - 1; region.top = region.bottom - buttonHeight + 1; object->SetRegion(region); left += buttonWidth + display->cellWidth; } // Set the client region. clientRegion.coordinateType = ZAF_PIXEL; clientRegion.left = clientRegion.top = 0; clientRegion.right = clientWidth - 1; clientRegion.bottom = clientHeight - 1; // Center the window. zafRegion = clientRegion; zafRegion.right += display->cellWidth; zafRegion.bottom += display->cellHeight; WindowManager()->Center(this); } break; default: ccode = ZafDialogWindow::Event(event); break; } // Return the control code. return (ccode);}bool ZafMessageWindow::IsA(ZafClassID compareID) const{ return ((compareID == classID) ? true : ZafWindow::IsA(compareID));}bool ZafMessageWindow::IsA(ZafClassName compareName) const{ return (!strcmp(compareName, className) ? true : ZafWindow::IsA(compareName));}bool ZafMessageWindow::SetAcceptDrop(bool ){ // acceptDrop is false for this class. return (false);}bool ZafMessageWindow::SetAutomaticUpdate(bool ){ // automaticUpdate is true for this class. return (true);}bool ZafMessageWindow::SetBordered(bool ){ // bordered is always false for this class. return (false);}ZafDialogFlags ZafMessageWindow::SetDefaultMessageFlag(ZafDialogFlags zDefFlag){ if (!screenID) defFlag = zDefFlag; return (defFlag);}bool ZafMessageWindow::SetDestroyable(bool ){ // destroyable is false for this class. return (false);}bool ZafMessageWindow::SetDisabled(bool ){ // disabled is false for this class. return (false);}const ZafIChar *ZafMessageWindow::SetHelpObjectTip(const ZafIChar *){ // helpObjectTip cannot be set for this class. return (ZAF_NULLP(ZafIChar));}ZafIconImage ZafMessageWindow::SetIconImage(ZafIconImage zIconImage){ if (!screenID) iconImage = zIconImage; return (iconImage);}bool ZafMessageWindow::SetLocked(bool ){ // locked is false for this class. return (false);}bool ZafMessageWindow::SetMaximized(bool ){ // maximized is false for this class. return (false);}void ZafMessageWindow::SetMessage(const ZafIChar *format, ...){ // Get the formatted text. ZafIChar *text = new ZafIChar[1024]; va_list arguments; va_start(arguments, format); ZafStandardArg::vsprintf(text, format, &arguments); va_end(arguments); if (!screenID) { if (textField) textField->SetText(text); else { // Create the text field. textField = new ZafText(0, 0, 0, 0, new ZafStringData(text)); textField->SetBordered(false); textField->SetNoncurrent(true); textField->SetViewOnly(true); textField->SetParentPalette(true); textField->SetWordWrap(true); textField->SetOSDraw(false);#if defined(ZAF_INDEPENDENT) textField->SetUserPaletteData(new ZafPaletteData(textFieldPaletteMap, true));#endif } } delete []text;}void ZafMessageWindow::SetMessage(ZafUInt16 bufferSize, const ZafIChar *format, ...){ // Get the formatted text. ZafIChar *text = new ZafIChar[bufferSize]; va_list arguments; va_start(arguments, format); ZafStandardArg::vsprintf(text, format, &arguments); va_end(arguments); if (!screenID) { if (textField) textField->SetText(text); else { // Create the text field. textField = new ZafText(0, 0, 0, 0, new ZafStringData(text)); textField->SetBordered(false); textField->SetNoncurrent(true); textField->SetViewOnly(true); textField->SetParentPalette(true); textField->SetWordWrap(true); textField->SetOSDraw(false);#if defined(ZAF_INDEPENDENT) textField->SetUserPaletteData(new ZafPaletteData(textFieldPaletteMap, true));#endif } } delete []text;}ZafDialogFlags ZafMessageWindow::SetMessageFlags(ZafDialogFlags zMsgFlags){ if (!screenID) msgFlags |= zMsgFlags; return (msgFlags);}bool ZafMessageWindow::SetMinimized(bool ){ // minimized is false for this class. return (false);}bool ZafMessageWindow::SetMoveable(bool ){ // moveable is true for this class. return (true);}ZafRegionType ZafMessageWindow::SetRegionType(ZafRegionType ){ // regionType is ZAF_INSIDE_REGION for this class. return (ZAF_INSIDE_REGION);}ZafSelectionType ZafMessageWindow::SetSelectionType(ZafSelectionType ){ // selectionType is ZAF_SINGLE_SELECTION for this class. return (ZAF_SINGLE_SELECTION);}bool ZafMessageWindow::SetSizeable(bool ){ // sizeable is false for this class. return (false);}bool ZafMessageWindow::SetTemporary(bool ){ // temporary is false for this class. return (false);}// ----- Persistent functions -----------------------------------------------#if defined(USE_ZAF_PERSISTENCE)#if defined(ZAF_READ)ZafMessageWindow::ZafMessageWindow(const ZafIChar *name, ZafObjectPersistence &persist) : ZafDialogWindow(name, persist.PushLevel(className, classID, ZAF_PERSIST_ROOT_DIRECTORY)), msgFlags(0), defFlag(0), iconImage(0), icon(ZAF_NULLP(ZafIcon)), textField(ZAF_NULLP(ZafText)), title(ZAF_NULLP(ZafTitle)), firstButton(ZAF_NULLP(ZafButton)){ // Read the data. if (persist.Error() == ZAF_ERROR_NONE) ZafMessageWindow::ReadData(persist); persist.PopLevel(); if (persist.Error() != ZAF_ERROR_NONE) SetError(persist.Error()); // Get message strings. messages = ZafLanguageManager::Allocate(className, defaultMessages);}ZafElement *ZafMessageWindow::Read(const ZafIChar *name, ZafObjectPersistence &persist){ return (new ZafMessageWindow(name, persist));}void ZafMessageWindow::ReadData(ZafObjectPersistence &persist){ // Read the data. ZafIChar titleName[ZAF_MAXNAMELEN], text[1024]; ZafFile *file = persist.CurrentFile(); *file >> iconImage >> msgFlags >> defFlag >> text >> titleName; // Use the %s format argument in case the text has %'s in it; otherwise // it would crash when SetMessage() tries to find corresponding arguments. if (*text) SetMessage(ZAF_ITEXT("%s"), text); // Add the title and system button (if specified). if (*titleName) title = new ZafTitle(new ZafStringData(titleName, persist));}#endif#if defined(ZAF_WRITE)void ZafMessageWindow::Write(ZafObjectPersistence &persist){ // Bypass ZafWindow calls to keep the children from being saved. ZafWindowObject::Write(persist.PushLevel(className, classID, ZAF_PERSIST_ROOT_DIRECTORY)); if (persist.Error() == ZAF_ERROR_NONE) ZafWindow::WriteData(persist); if (persist.Error() == ZAF_ERROR_NONE) ZafMessageWindow::WriteData(persist); persist.PopLevel(); if (persist.Error() != ZAF_ERROR_NONE) SetError(persist.Error());}void ZafMessageWindow::WriteData(ZafObjectPersistence &persist){ // Write the data. ZafFile *file = persist.CurrentFile(); *file << iconImage; *file << msgFlags; *file << defFlag; const ZafIChar *text = textField ? textField->Text() : ZAF_NULLP(ZafIChar); ZafStringData *stringData = ZAF_NULLP(ZafStringData); const ZafIChar *titleName = ZAF_NULLP(ZafIChar); if (title) stringData = title->StringData(); if (stringData) titleName = stringData->StringID(); *file << text << titleName; // Write the string data. if (stringData) stringData->Write(persist);}#endif#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -