home *** CD-ROM | disk | FTP | other *** search
/ PSION CD 2 / PsionCDVol2.iso / Programs / 720 / PDF090B4-SorceCode / pdf / Error.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-09-30  |  2.0 KB  |  108 lines

  1. //========================================================================
  2. //
  3. // Error.cc
  4. //
  5. // Copyright 1996 Derek B. Noonburg
  6. //
  7. //========================================================================
  8. //
  9. // Ported to EPOC by Sander van der Wal
  10. //
  11. // $Log: Error.cpp $
  12. // Revision 1.2  2000-09-17 13:38:24+02  svdwal
  13. // Ported
  14. //
  15.  
  16. #ifdef __GNUC__
  17. #pragma implementation
  18. #endif
  19.  
  20. #ifdef __SYMBIAN32__
  21. #  include <e32def.h>
  22. #else
  23. #  include <stddef.h>
  24. #  include <stdio.h>
  25. #endif
  26.  
  27. #include <stdarg.h>
  28.  
  29. #include "gtypes.h"
  30. #include "Error.h"
  31.  
  32. #include <eikdialg.h>
  33. #include "pdf.hrh"
  34. #include "Pdf.rsg"
  35.  
  36. // report errors in C code
  37. extern "C" void C_error(TInt msg);
  38.  
  39. void C_error(TInt msg)
  40. {
  41.   error(-1, msg);
  42. }
  43.  
  44.  
  45. class CErrorDialog : public CEikDialog
  46. {
  47. public:
  48.   CErrorDialog(TInt aPos, TInt aResourceId, VA_LIST args);
  49.  
  50. // -- CEikDialog
  51. private:
  52.   void PreLayoutDynInitL();
  53.   TBool OkToExitL(TInt aKeycode);
  54.  
  55. private:
  56.   TBuf<32> iTitle;  
  57.   TPtrC    iTitlePtr;
  58.   TBuf<256> iMsg;
  59.   TPtrC     iMsgPtr;
  60. };
  61.  
  62.  
  63. CErrorDialog::CErrorDialog(TInt aPos, TInt aResourceId, VA_LIST args)
  64. {
  65.   if (aPos >= 0)
  66.     iCoeEnv->Format128(iTitle, R_ERROR_AT, aPos);
  67.   else
  68.     iCoeEnv->Format128(iTitle, R_ERROR);
  69.   iTitlePtr.Set(iTitle);
  70.  
  71.   HBufC* fmt = 0;
  72.   TRAPD(error, fmt = iCoeEnv->AllocReadResourceL(aResourceId));
  73.   if (!error) {
  74.     iMsg.FormatList(*fmt, args);
  75.     delete fmt;
  76.   }
  77.   iMsgPtr.Set(iMsg);
  78. }
  79.  
  80.  
  81. void CErrorDialog::PreLayoutDynInitL()
  82. {
  83.   SetTitleL(iTitlePtr);
  84.   SetEdwinTextL(EErrorDialogMessage, &iMsgPtr);
  85. }
  86.  
  87.  
  88. TBool CErrorDialog::OkToExitL(TInt /*aKeycode*/)
  89. {
  90.   return ETrue;
  91. }
  92.  
  93. void CDECL error(int aPos, int aResourceId, ...)
  94. {
  95.   VA_LIST args;
  96.   VA_START(args, aResourceId);
  97.   error(aPos, aResourceId, args);
  98.   VA_END(args);
  99. }
  100.  
  101. void CDECL error(int aPos, int aResourceId, VA_LIST args)
  102. {
  103. #ifndef OOM // bad interactions
  104.   CErrorDialog* dialog = new(ELeave) CErrorDialog(aPos, aResourceId, args);
  105.   dialog->ExecuteLD(R_ERROR_DIALOG);
  106. #endif
  107. }
  108.