/************************************************************************************** > INT32 __cdecl StringBase::MakeMsg(UINT32 resourceID ...) Author: Justin_Flude (Xara Group Ltd) <*****@*****.**> Created: 22nd April 1993 Inputs: A string resource identifier, and a variable number of other parameters, which must match the format specifiers embedded in the string resource. Note that floating point parameters are NOT supported. Outputs: Changes "this" to become the formatted string, with the passed parameters substituted into the string resource in the correct order. Returns: The number of characters in the formatted string. This will be zero if a problem occurs, such as not being able to load the format string resource. Purpose: Internationally portable version of sprintf(...), eg. StringBase s; INT32 x, y, z; s.MakeMsg(_R(IDS_COORDFORMAT), x, y, z); TextOut(hdc, 20, 20, s, s.Length()); Errors: ENSURE failure if called for a String that hasn't been allocated. ***************************************************************************************/ INT32 __cdecl StringBase::MakeMsg(UINT32 resID ...) { /* if (IsUserName("JustinF")) TRACE( _T("MakeMsg called with resource ID %u\n"), resID); */ ENSURE(text, "Call to StringBase::MakeMsg for unallocated String"); va_list ap; va_start(ap, resID); INT32 n = 0; StringBase s; if (s.Alloc(MAX_STRING_RES_LENGTH) && s.Load(resID)) { n = CCvsprintf(s.text, ap); } #ifdef _DEBUG /* else { if (IsUserName("JustinF")) TRACE( _T("Failed to allocate or load the format string in MakeMsg()\n")); } */ #endif va_end(ap); #if !defined(EXCLUDE_FROM_RALPH) && !defined(EXCLUDE_FROM_XARALX) // Remember the resource ID, in case the help system can't work out the message ID. SetNextMsgHelpContext(resID); #endif // Return the number of characters in the formatted string. return n; }
void CDECL Error::XSetError( UINT32 errID, ...) { if ( (errID==FALSE) || (errID==TRUE) ) { // someone probably used the wrong macro parameters e.g. TRUE and FALSE instead of ID // This call will set an _R(IDE_INTERNAL_ERROR) for us ERROR2RAW( "ERROR1 macro used with invalid parameters" ); return; } TCHAR buf[256]; va_list marker; va_start( marker, errID ); String_256 result; // load the format string as a resoure (note no module ID yet) if (!SmartLoadString(0, errID, buf, sizeof(buf))) { camSnprintf( buf, 256, wxT("Error<%u>"), errID ); // keep inline } // now do _MakeMsg type formatting result.CCvsprintf(buf, marker); #if !defined(EXCLUDE_FROM_RALPH) && !defined(EXCLUDE_FROM_XARALX) // Set the help context. SetNextMsgHelpContext(errID); #endif // ralph needs this so that he can map the ID to a HRESULT before passing it // back to a harness TRACEUSER( "Chris", wxT("oOoOo Ralph Set Error %d \n"), RalphErrorID ); RalphErrorID =errID; // and copy result into ErrorString SetErrorSerious( result ); // trace output because SetErrorSerious doesn't bother TRACE( wxT("Setting error: ID = %d: \"%s\"\n"), errID, ErrorString); // then tidy up va_end( marker ); ResetWhere(); }
// **CAMELOT Error reporting** INT32 InformGeneral(UINT32 Error, UINT32 modID, UINT32 ErrorMsg, UINT32 Butt1, UINT32 Butt2, UINT32 Butt3, UINT32 Butt4, UINT32 OK, UINT32 Cancel) { // Make sure there is at least one valid button. if (Butt1 == 0) Butt1 = _R(IDS_OK); if (Error::ErrorBoxRecurse) { // Oh dear oh dear. Someone wants to put up an error box in the error handler. This is // **BAD** news. The most likely cause is an exception within this routine (or the other // InformGeneral). TRACE( _T("Recursive InformGeneral - Error in error handler! (1)\n")); // Don't risk putting up another error box - just return OK & hope for the best Beep(); // shouldn't cause too much trouble return(OK); } Error::ErrorBoxRecurse++; if (ErrorMsg != 0) { // It's a new error message Error::SetError(ErrorMsg, modID); } // Make sure we haven't already reported this error! ENSURE((!ErrorHasBeenReported), "InformGeneral: This error has already been reported!"); // In retail builds, we report the error anyway, just in case - it's better to have // two errors reported than none at all! // we should get our bitmap from the OS ResourceID TitleID = 0; ResourceID DebugReport = 0; wxArtID bitmap=wxART_MISSING_IMAGE; switch (Error) { case ERRORTYPE_NORMAL: // No sound for this one - it's just a message; nothing to shout about. bitmap = wxART_INFORMATION; TitleID = _R(IDS_ERRORBOX_NORMAL); break; case ERRORTYPE_QUESTION: //MessageBeep(MB_ICONQUESTION); bitmap = wxART_QUESTION; TitleID = _R(IDS_ERRORBOX_NORMAL); break; case ERRORTYPE_WARNING: //MessageBeep(MB_ICONASTERISK); bitmap = wxART_WARNING; TitleID = _R(IDS_ERRORBOX_WARNING); break; case ERRORTYPE_SERIOUS: //MessageBeep(MB_ICONHAND); bitmap = wxART_ERROR; TitleID = _R(IDS_ERRORBOX_SERIOUS); DebugReport = _R(IDS_ERRORBOX_DEBUGREPORT); break; case ERRORTYPE_ENSURE: //MessageBeep(MB_ICONHAND); bitmap = wxART_ERROR; TitleID = _R(IDS_ERRORBOX_ENSURE); DebugReport = _R(IDS_ERRORBOX_DEBUGREPORT); break; case ERRORTYPE_ERROR: default: //MessageBeep(MB_ICONEXCLAMATION); bitmap = wxART_ERROR; TitleID = _R(IDS_ERRORBOX_ERROR); break; } // We really should detect an error here, and if so use a stock wxMessageBox, but that // doesn't seem to support help (oh dear). // but in anticipation of that being fixed, we use a pointer wxDialog * pBox = new CamErrorDialog(TitleID); if (!pBox) { Beep(); Error::ErrorBoxRecurse--; return OK; } #ifdef __WXMAC__ pBox->SetExtraStyle(wxDIALOG_EX_METAL); pBox->SetBackgroundStyle(wxBG_STYLE_COLOUR); pBox->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW)); #endif // Note we add these to the dialog as soon as we can. Thus delete pBox will take // care of them wxBoxSizer* pVSizer = new wxBoxSizer(wxVERTICAL); if (!pVSizer) { Beep(); Error::ErrorBoxRecurse--; delete pBox; return OK; } pBox->SetSizer(pVSizer); wxBoxSizer* pMessageSizer = new wxBoxSizer(wxHORIZONTAL); if (!pMessageSizer) { Beep(); Error::ErrorBoxRecurse--; delete pBox; return OK; } pVSizer->Add(pMessageSizer, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5); CamArtProvider * pArtProv = CamArtProvider::Get(); // Art provider may not have been initialized... if (pArtProv) { wxStaticBitmap* pStaticBitmap = new wxStaticBitmap( pBox, -1, wxArtProvider::GetBitmap(bitmap, wxART_MESSAGE_BOX), wxDefaultPosition, wxDefaultSize, 0 ); if (!pStaticBitmap) { Beep(); Error::ErrorBoxRecurse--; delete pBox; return OK; } pMessageSizer->Add(pStaticBitmap, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5); } // Perform manual expansion of newline escape sequences... wxString temp = (TCHAR *)Error::GetErrorString(); temp.Replace(_T("\\n"), _T("\n"), TRUE); //wxTextCtrl* pMessage = new wxTextCtrl( pBox, -1, (TCHAR *)Error::GetErrorString(), // wxDefaultPosition, wxSize(400, -1), // wxTE_MULTILINE|wxTE_READONLY|wxTE_CENTRE|wxNO_BORDER ); wxStaticText* pMessage = new wxStaticText( pBox, -1, temp, wxDefaultPosition, wxSize(400, -1), wxALIGN_CENTRE|wxNO_BORDER ); if (!pMessage) { Beep(); Error::ErrorBoxRecurse--; delete pBox; return OK; } pMessage->Wrap(400); //pMessage->Enable(false); // this annoyingly does not grey it //pMessage->SetBackgroundColour(pBox->GetBackgroundColour()); pMessageSizer->Add(pMessage, 0, wxALIGN_CENTER_VERTICAL|wxALL|wxFIXED_MINSIZE, 5); wxBoxSizer* pButtonSizer = new wxBoxSizer(wxHORIZONTAL); if (!pButtonSizer) { Beep(); Error::ErrorBoxRecurse--; delete pBox; return OK; } pVSizer->Add(pButtonSizer, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5); #define EB_MAXBUTS 7 wxButton * pButt[EB_MAXBUTS]; // see help below, note we don't use zero, 5 is reserved for help ResourceID butres[EB_MAXBUTS]; butres[0]=0; butres[1]=Butt1; butres[2]=Butt2; butres[3]=Butt3; butres[4]=Butt4; butres[5]=0; // for _R(IDS_HELP) - see below butres[6]=DebugReport; #if !defined(EXCLUDE_FROM_RALPH) // See if there is any on-line help associated with the given warning/error message. // If there is then we will add a "Help" button to the dialog. if (CanHelpUser(Error::GetErrorNumber())) butres[5]=_R(IDS_HELP); #endif INT32 butt; for (butt=0; butt<EB_MAXBUTS; butt++) { if (butres[butt]) { pButt[butt] = ((CamErrorDialog *)pBox)->AddErrorButton(pButtonSizer, CamResource::GetText(butres[butt]), butres[butt]); if (!pButt[butt]) { Beep(); Error::ErrorBoxRecurse--; delete pBox; return OK; } #ifndef HAVE_DEBUGREPORT if (butt==6) { pButt[butt]->Enable(FALSE); } #endif } else pButt[butt]=NULL; } // Set the default if ( ((UINT32)OK <EB_MAXBUTS) && butres[OK] && pButt[OK]) { pButt[OK]->SetDefault(); pBox->SetDefaultItem(pButt[OK]); } pBox->GetSizer()->Fit(pBox); pBox->GetSizer()->SetSizeHints(pBox); pBox->Centre(); // Disable the system's functionality for serious errors (i.e. stop rendering etc). if (Error == ERRORTYPE_SERIOUS || Error == ERRORTYPE_ENSURE) CCamApp::DisableSystem(pBox); if ( Error::IsInRenderThread() ) TRACE( _T("InformGeneral called within RenderThread => serious rendering error")); // Bodge because ReleaseCapture() sometimes doesn't send WM_CANCELMODE (e.g. to custom controls) which // appears to be a bug somewhere in the Windows API if (wxWindow::GetCapture()) wxWindow::GetCapture()->ReleaseMouse(); #if !defined(EXCLUDE_FROM_RALPH) #ifndef EXCLUDE_FROM_XARALX // Keep Control Helper system informed ControlHelper::InformModalDialogOpened(); #endif // Bodge so error boxes are given focus when bars/galleries are being created BaseBar::StartErrorBox(); #endif // 'Do' the dialog ResourceID pressed = pBox->ShowModal(); INT32 result = Cancel; for (butt=0; butt<EB_MAXBUTS; butt++) { if (butres[butt] == pressed) result = butt; } ErrStatus = ERRORSTAT_NONE; delete pBox; #if !defined(EXCLUDE_FROM_RALPH) // Make sure we forget the old help content. SetNextMsgHelpContext(0); #ifndef EXCLUDE_FROM_XARALX // Keep Control Helper system informed ControlHelper::InformModalDialogClosed(); #endif // Bodge so error boxes are given focus when bars/galleries are being created BaseBar::FinishErrorBox(); #endif if ( Error::IsInRenderThread() ) { TRACE( _T("In RenderThread so clearing up system")); Error::RenderThreadReset(); CamProfile::AtBase(CAMPROFILE_OTHER); } // Enable system if necessary. if (Error == ERRORTYPE_SERIOUS || Error == ERRORTYPE_ENSURE) CCamApp::EnableSystem(); // We don't want to report this error again. ErrorHasBeenReported = TRUE; Error::ClearError(); Error::ErrorBoxRecurse--; // if we were in a drag operation, cancel it (to prevent invalid drag state) fixes #11455 DragManagerOp::AbortDrag(); return result; }