📄 z_msgwin.cpp
字号:
// Zinc Application Framework - Z_MSGWIN.CPP// Copyright (c) 1990-1998 Zinc Software, Inc.// Copyright (c) 1999-2003 Wind River Systems, Inc./*modification history--------------------01h,19jun03,jlb Fix SPR 72148 - Window does not resize for text01g,19jul01,wdf Worked around bug (SPR #69147) in the StrongArm compiler.01f,07may01,wdf Changed copyright date.01e,23oct00,wdf Changed copyright date.01d,24feb00,wdf Added code to Event() function to call event listeners.01c,07dec99,jom Fix SPR 2961701b,21sep99,bbj Interop--switch to EventManager(), WindowManager() accessors01a,27jul99,wdf Eliminated commented and redundent code, unnecassary functions and #defines*/#include <zinc/z_app.hpp>#include <zinc/z_msgwin.hpp>#include <zinc/z_stdarg.hpp>#include <zinc/z_border.hpp>#include <zinc/z_sys.hpp>#include <zinc/z_icon1.hpp>#include <zinc/z_text.hpp>#include <zinc/z_title.hpp>#include <zinc/z_string.hpp>#include <zinc/z_utils.hpp>#define ZAF_MESSAGE_WINDOW_INFO#include <zinc/data/lang_def.hpp>#include <zinc/data/gbl_def.hpp>// ----- ZafMessageWindow ---------------------------------------------------#if defined(ZAF_INDEPENDENT)static ZafPaletteMap ZAF_FARDATA textFieldPaletteMap[] ={ { ZAF_PM_ANY_TYPE, ZAF_PM_ANY_STATE, { ZAF_LINE_SOLID, ZAF_PTN_SOLID_FILL, ZAF_CLR_BLACK, ZAF_CLR_LIGHTGRAY, ZAF_MONO_WHITE, ZAF_MONO_BLACK, ZAF_FNT_DIALOG } }};#endifZafMessageWindow::ZafMessageWindow(ZafStringData *zTitle, ZafIconImage zIconImage, ZafDialogFlags zMsgFlags, ZafDialogFlags zDefFlag, const ZafIChar *format, ...) : ZafDialogWindow(0, 0, 0, 0), msgFlags(0), defFlag(0), iconImage(zIconImage), icon(ZAF_NULLP(ZafIcon)), textField(ZAF_NULLP(ZafText)), title(ZAF_NULLP(ZafTitle)), firstButton(ZAF_NULLP(ZafButton)){ destroyable = false; sizeable = false; // Get message strings. messages = ZafLanguageManager::Allocate(className, defaultMessages); // Get the formatted text. ZafIChar *text = new ZafIChar[1024]; va_list arguments; va_start(arguments, format); ZafStandardArg::vsprintf(text, format, &arguments); va_end(arguments); SetMessageFlags(zMsgFlags); SetDefaultMessageFlag(zDefFlag); // Use the %s format argument in case the text has %'s in it; otherwise // it would crash when SetMessage() tries to find corresponding arguments. SetMessage(ZAF_ITEXT("%s"), text); if (zTitle) title = new ZafTitle(zTitle); else title = new ZafTitle(new ZafStringData(*zTitle)); SetIconImage(iconImage); delete []text;}ZafMessageWindow::ZafMessageWindow(const ZafIChar *zTitle, ZafIconImage zIconImage, ZafDialogFlags zMsgFlags, ZafDialogFlags zDefFlag, const ZafIChar *format, ...) : ZafDialogWindow(0, 0, 0, 0), msgFlags(0), defFlag(0), iconImage(zIconImage), icon(ZAF_NULLP(ZafIcon)), textField(ZAF_NULLP(ZafText)), title(ZAF_NULLP(ZafTitle)), firstButton(ZAF_NULLP(ZafButton)){ SetDestroyable(false); SetSizeable(false); // Get message strings. messages = ZafLanguageManager::Allocate(className, defaultMessages); // Get the formatted text. ZafIChar *text = new ZafIChar[1024]; va_list arguments; va_start(arguments, format); ZafStandardArg::vsprintf(text, format, &arguments); va_end(arguments); SetMessageFlags(zMsgFlags); SetDefaultMessageFlag(zDefFlag); // Use the %s format argument in case the text has %'s in it; otherwise // it would crash when SetMessage() tries to find corresponding arguments. SetMessage(ZAF_ITEXT("%s"), text); title = new ZafTitle(new ZafStringData(zTitle)); SetIconImage(iconImage); delete []text;}ZafMessageWindow::ZafMessageWindow(ZafStringData *zTitle, ZafIconImage zIconImage, ZafDialogFlags zMsgFlags, ZafDialogFlags zDefFlag, ZafUInt16 bufferSize, const ZafIChar *format, ...) : ZafDialogWindow(0, 0, 0, 0), msgFlags(0), defFlag(0), iconImage(zIconImage), icon(ZAF_NULLP(ZafIcon)), textField(ZAF_NULLP(ZafText)), title(ZAF_NULLP(ZafTitle)), firstButton(ZAF_NULLP(ZafButton)){ SetDestroyable(false); SetSizeable(false); // Get message strings. messages = ZafLanguageManager::Allocate(className, defaultMessages); // Get the formatted text. ZafIChar *text = new ZafIChar[bufferSize]; va_list arguments; va_start(arguments, format); ZafStandardArg::vsprintf(text, format, &arguments); va_end(arguments); SetMessageFlags(zMsgFlags); SetDefaultMessageFlag(zDefFlag); // Use the %s format argument in case the text has %'s in it; otherwise // it would crash when SetMessage() tries to find corresponding arguments. SetMessage(bufferSize, ZAF_ITEXT("%s"), text); if (zTitle) title = new ZafTitle(zTitle); else title = new ZafTitle(new ZafStringData(*zTitle)); SetIconImage(iconImage); delete []text;}ZafMessageWindow::ZafMessageWindow(const ZafMessageWindow ©) : ZafDialogWindow(copy), msgFlags(0), defFlag(0), iconImage(0), icon(ZAF_NULLP(ZafIcon)), textField(ZAF_NULLP(ZafText)), title(ZAF_NULLP(ZafTitle)), firstButton(ZAF_NULLP(ZafButton)){ // Get message strings. messages = ZafLanguageManager::Allocate(className, defaultMessages); SetDefaultButton(ZAF_NULLP(ZafButton)); Destroy(); SetMessageFlags(copy.msgFlags); SetDefaultMessageFlag(copy.defFlag); // 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 (copy.textField) SetMessage(ZAF_ITEXT("%s"), copy.textField->Text()); else SetMessage(ZAF_NULLP(ZafIChar)); SetIconImage(copy.iconImage);}ZafMessageWindow::~ZafMessageWindow(void){ // Free the language information. ZafLanguageManager::Free(messages); // If the title was created but never added (because the message window // was never added to the window manager) delete the title. if (title && !title->parent) delete title; // If the textField was created but never added (because the message window // was never added to the window manager) delete the textField. if (textField && !textField->parent) delete textField;}void ZafMessageWindow::AddFields(void){ // Remove any button fields in case some flags were removed. if (firstButton) SetDefaultButton(ZAF_NULLP(ZafButton)); ZafWindowObject *object = firstButton; while (object) { ZafWindowObject *nextObject = object->Next(); Subtract(object); delete object; object = nextObject; } firstButton = ZAF_NULLP(ZafButton); // Add border. if (!Border()) Add(new ZafBorder); // Add the title and system button (if specified). if (title && !Title()) { Add(new ZafSystemButton(ZAF_NATIVE_SYSTEM_BUTTON)); Add(title); } // Add the icon (if applicable). // NOTE: ZAF_APPLICATION_ICON is 0 (the first in the icon array), so it may // not be used in this constructor, since iconImage is an unsigned value. if (iconImage) { if (icon) { Subtract(icon); delete icon; } icon = new ZafIcon(2, 1, ZAF_NULLP(ZafStringData)); icon->SetIconImage(iconImage); icon->SetBordered(false); icon->SetNoncurrent(true); Add(icon); } if (textField) Add(textField); // Add the buttons. int index = 0; ZafDialogFlags testFlag = 1; do { if (msgFlags & testFlag) { ZafIChar hotKeyChar = '\0'; int hotKeyIndex = -1; ZafButton *button = new ZafButton(0, 0, 0, 0, messages->GetMessage((ZafNumberID)testFlag, false, &hotKeyChar, &hotKeyIndex), ZAF_NULLP(ZafBitmapData), ZAF_NATIVE_BUTTON); button->SetAllowDefault(true); button->SetAutoSize(true); button->SetHotKey(hotKeyChar, hotKeyIndex); button->SetSendMessageWhenSelected(true); button->SetValue(testFlag == ZAF_DIALOG_HELP ? S_HELP : S_DIALOG_FIRST + index); Add(button); if (testFlag == defFlag) SetDefaultButton(button); if (!firstButton) firstButton = button; if (testFlag == defFlag) current = button; } index++; testFlag <<= 1; } while (testFlag);}ZafDialogFlags ZafMessageWindow::ClearMessageFlags(ZafDialogFlags zMsgFlags){ if (!screenID) msgFlags &= (ZafUInt16)~zMsgFlags; return (msgFlags);}ZafWindowObject *ZafMessageWindow::Duplicate(void){ return (new ZafMessageWindow(*this));}ZafEventType ZafMessageWindow::Event(const ZafEventStruct &event){ // Check for zinc events. ZafEventType ccode = event.type; // Initialize the autoListener. This will call any preprocessing listeners providing // listenerStackCount = 1. When it is destroyed any postprocessing listeners will be // called if the listenerStackCount = 1. ZafAutoListener autoListener(this, event, ccode); // If an event listener processed the event and the library should do nothing with it return. if (event.processed) return (ccode); switch (ccode) { case S_INITIALIZE: AddFields(); ZafDialogWindow::Event(event); break; case S_COMPUTE_SIZE:#if defined(ZAF_INDEPENDENT) // If oldRegion == -10000 it means the window is just getting initialized // so compute the size of the children and center the window. if (oldRegion.left == -10000 && oldRegion.top == -10000 && oldRegion.right == -10000 && oldRegion.bottom == -10000)#endif { // Compute the text size. int textHeight = 0; int textWidth = 0; if (textField) { const ZafIChar *text = textField->Text(); // Initialize the display so that accurate text sizes can be obtained. BeginDraw(); display->SetPalette(textField->LogicalPalette(ZAF_PM_TEXT, PaletteState()));# if defined(ZAF_MOTIF) ZafRegionStruct textSize = display->TextSize(text); textHeight = textSize.Height() + 2 * ZAF_BORDER_SIZE + 1; textWidth = textSize.Width() + 2 * ZAF_MARGIN_SIZE + 1;# else int index = 0; int lineHeight = display->TextSize(ZAF_ITEXT("Mg")).Height(); const ZafIChar *linePtr = text; do { if (text[index] == '\n' || text[index] == '\r' || text[index] == '\0') { int isCR = (text[index] == '\r'); ZafIChar saveChar = text[index]; textField->StringData()->SetChar(index, '\0'); ZafRegionStruct textSize = display->TextSize(linePtr); textHeight += lineHeight;# if defined(ZAF_MSWINDOWS) textHeight++;# endif if (textSize.Width() > textWidth) textWidth = textSize.Width(); textField->StringData()->SetChar(index, saveChar); if (isCR && text[index + 1] == '\n') index++; linePtr = text + index + 1; } } while (text[index++] != '\0');# endif // Restore the display. EndDraw(); } // Add a few pixels to allow for margins; textWidth += 2 * ZAF_MARGIN_SIZE; textHeight += 2 * ZAF_MARGIN_SIZE; // Compute the size and number of buttons. int buttons = 0; int maxTextSize = 0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -