home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / macfe / central / CPlainTextConversionContext.cp < prev    next >
Encoding:
Text File  |  1998-04-08  |  7.7 KB  |  253 lines

  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2.  *
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  *
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18.  
  19. // CPlainTextConversionContext.cp
  20.  
  21.  
  22. // This might seem like a lot of work to go around the code in ns/lib/xlate/text.c,
  23. // but doing this allows us not to have to put if (inContext == NULL) inside
  24. // CNSContextCallbacks.cp; and by calling the TXFE_* functions from the overridden
  25. // methods, we pickup any modifcations made for free.
  26.  
  27. //#include <yvals.h>
  28.  
  29. #include "CPlainTextConversionContext.h"
  30.  
  31. #include "xlate.h"
  32.  
  33. //_EXTERN_C
  34. __extern_c
  35.  
  36. // prototypes for text.c functions
  37.  
  38. extern void TXFE_DisplayTable(MWContext *cx, int iLoc, LO_TableStruct *table);
  39. extern void TXFE_DisplayLineFeed(MWContext *cx, int iLocation, LO_LinefeedStruct *line_feed, XP_Bool notused);
  40. extern void TXFE_DisplayHR(MWContext *cx, int iLocation , LO_HorizRuleStruct *HR);
  41. extern char *TXFE_TranslateISOText(MWContext *cx, int charset, char *ISO_Text);
  42. extern void TXFE_DisplayBullet(MWContext *cx, int iLocation, LO_BullettStruct *bullet);
  43. extern void TXFE_FinishedLayout(MWContext *cx);
  44. extern void TXFE_AllConnectionsComplete(MWContext *cx);
  45. extern void TXFE_DisplaySubtext(MWContext *cx, int iLocation, LO_TextStruct *text,
  46.             int32 start_pos, int32 end_pos, XP_Bool notused);
  47. extern void TXFE_DisplayText(MWContext *cx, int iLocation, LO_TextStruct *text, XP_Bool needbg);
  48. extern void TXFE_DisplaySubDoc(MWContext *cx, int iLocation, LO_SubDocStruct *subdoc_struct);
  49. extern int TXFE_GetTextInfo(MWContext *cx, LO_TextStruct *text, LO_TextInfo *text_info);
  50. extern void TXFE_LayoutNewDocument(MWContext *cx, URL_Struct *url, int32 *w, int32 *h, int32* mw, int32* mh);
  51.  
  52. // These are here because the backend files are .c files, which are only
  53. // run through the C compiler. Thus we need to create and destroy the
  54. // CPlainTextConversionContext from a .cp file
  55.  
  56. MWContext* CreatePlainTextConversionContext(MWContext* inUIContext);
  57. void DisposePlainTextConversionContext(MWContext* inContext);
  58.  
  59. __end_extern_c
  60.  
  61. #pragma mark --- CALLBACKS ---
  62.  
  63. MWContext* CreatePlainTextConversionContext(MWContext* inUIContext)
  64. {
  65.     try {
  66.         CPlainTextConversionContext* theContext = new CPlainTextConversionContext(inUIContext);
  67.         // Very slimey, but somebody needs to have an interest in the context
  68.         theContext->AddUser(theContext);
  69.         return theContext->operator MWContext*();
  70.     } catch (...) {
  71.         return NULL;
  72.     }
  73. }
  74.  
  75. void DisposePlainTextConversionContext(MWContext* inContext)
  76. {
  77.     CPlainTextConversionContext* theContext =
  78.         dynamic_cast<CPlainTextConversionContext*>(ExtractNSContext(inContext));
  79.     Assert_(theContext != NULL);
  80.     // One of these days, this call might break
  81.     theContext->RemoveUser(theContext);
  82. }
  83.  
  84. CPlainTextConversionContext::CPlainTextConversionContext(MWContext* inUIContext) :
  85.     CNSContext(MWContextText)
  86. {
  87.     mUIContext = ExtractNSContext(inUIContext);
  88.     Assert_(mUIContext != NULL);
  89. }
  90.  
  91. #pragma mark --- OVERRIDES ---
  92.  
  93. void CPlainTextConversionContext::LayoutNewDocument(
  94.     URL_Struct*                inURL,
  95.     Int32*                    inWidth,
  96.     Int32*                    inHeight,
  97.     Int32*                    inMarginWidth,
  98.     Int32*                    inMarginHeight)
  99. {
  100.     TXFE_LayoutNewDocument(*this, inURL, inWidth, inHeight, inMarginWidth, inMarginHeight);
  101. }
  102.  
  103. void CPlainTextConversionContext::DisplaySubtext(
  104.     int                     inLocation,
  105.     LO_TextStruct*            inText,
  106.     Int32                     inStartPos,
  107.     Int32                    inEndPos,
  108.     XP_Bool                 inNeedBG)
  109. {
  110.     TXFE_DisplaySubtext(*this, inLocation, inText, inStartPos, inEndPos, inNeedBG);
  111. }
  112.  
  113. void CPlainTextConversionContext::DisplayText(
  114.     int                     inLocation,
  115.     LO_TextStruct*            inText,
  116.     XP_Bool                 inNeedBG)
  117. {
  118.     TXFE_DisplayText(*this, inLocation, inText, inNeedBG);
  119. }
  120.  
  121. void CPlainTextConversionContext::DisplaySubDoc(
  122.     int                     inLocation,
  123.     LO_SubDocStruct*        inSubdocStruct)
  124. {
  125.     TXFE_DisplaySubDoc(*this, inLocation, inSubdocStruct);
  126. }
  127.  
  128. void CPlainTextConversionContext::DisplayTable(
  129.     int                     inLocation,
  130.     LO_TableStruct*            inTableStruct)
  131. {
  132.     TXFE_DisplayTable(*this, inLocation, inTableStruct);
  133. }
  134.  
  135. void CPlainTextConversionContext::DisplayLineFeed(
  136.     int                     inLocation,
  137.     LO_LinefeedStruct*        inLinefeedStruct,
  138.     XP_Bool                 inNeedBG)
  139. {
  140.     TXFE_DisplayLineFeed(*this, inLocation, inLinefeedStruct, inNeedBG);
  141. }
  142.  
  143. void CPlainTextConversionContext::DisplayHR(
  144.     int                     inLocation,
  145.     LO_HorizRuleStruct*        inRuleStruct)
  146. {
  147.     TXFE_DisplayHR(*this, inLocation, inRuleStruct);
  148. }
  149.  
  150. char* CPlainTextConversionContext::TranslateISOText(
  151.     int                     inCharset,
  152.     char*                    inISOText)
  153. {
  154.     return TXFE_TranslateISOText(*this, inCharset, inISOText);
  155. }
  156.  
  157. void CPlainTextConversionContext::DisplayBullet(
  158.     int                     inLocation,
  159.     LO_BullettStruct*        inBulletStruct)
  160. {
  161.     TXFE_DisplayBullet(*this, inLocation, inBulletStruct);
  162. }
  163.  
  164. void CPlainTextConversionContext::FinishedLayout(void)
  165. {
  166.     TXFE_FinishedLayout(*this);
  167. }
  168.  
  169. int CPlainTextConversionContext::GetTextInfo(
  170.     LO_TextStruct*            inText,
  171.     LO_TextInfo*            inTextInfo)
  172. {
  173.     return TXFE_GetTextInfo(*this, inText, inTextInfo);
  174. }
  175.  
  176. int CPlainTextConversionContext::MeasureText(
  177.     LO_TextStruct*            /*inText*/,
  178.     short*                    /*outCharLocs*/)
  179. {
  180.     return 0;
  181. }
  182.  
  183. void CPlainTextConversionContext::AllConnectionsComplete(void)
  184. {
  185.     if (mProgress)
  186.     {
  187.         mProgress->RemoveUser(this);
  188.         mProgress = NULL;
  189.     }
  190.     TXFE_AllConnectionsComplete(*this);
  191.     mUIContext->AllConnectionsComplete();
  192.     CNSContext::AllConnectionsComplete();
  193. }
  194.  
  195. void CPlainTextConversionContext::GraphProgressInit(
  196.     URL_Struct*        inURL,
  197.     Int32            inContentLength)
  198. {
  199.     try {
  200.         Assert_(mUIContext != NULL);
  201.         if (mUIContext && mUIContext->GetContextProgress())
  202.             mProgress = mUIContext->GetContextProgress();
  203.         else
  204.         {
  205.             mProgress = new CContextProgress;
  206.             mUIContext->SetContextProgress(mProgress);
  207.         }
  208.         mProgress->AddUser(this);
  209.     } catch (...) {
  210.         mProgress = NULL;
  211.     }
  212.     mUIContext->GraphProgressInit(inURL, inContentLength);
  213. }
  214.  
  215. void CPlainTextConversionContext::Progress(const char* inMessageText )
  216. {
  217.     Assert_(mUIContext != NULL);
  218.     mUIContext->Progress(inMessageText);
  219. }
  220.  
  221. void CPlainTextConversionContext::GraphProgressDestroy(
  222.     URL_Struct*        inURL,
  223.     Int32             inContentLength,
  224.     Int32             inTotalRead)
  225. {
  226.     Assert_(mUIContext != NULL);
  227.     mUIContext->GraphProgressDestroy(inURL, inContentLength, inTotalRead);
  228. }
  229.  
  230. void CPlainTextConversionContext::GraphProgress(
  231.     URL_Struct*        inURL,
  232.     Int32            inBytesReceived,
  233.     Int32            inBytesSinceLast,
  234.     Int32            inContentLength)
  235. {
  236.     Assert_(mUIContext != NULL);
  237.     mUIContext->GraphProgress(inURL, inBytesReceived, inBytesSinceLast, inContentLength);
  238. }
  239.  
  240. #pragma mark --- STUBS ---
  241.  
  242. // FIX ME? Do we really wan't to override these methods?
  243. void CPlainTextConversionContext::Alert(const char* /* inAlertText */) {}
  244. XP_Bool CPlainTextConversionContext::Confirm(const char* /* inMessage */) { return false; }
  245. char* CPlainTextConversionContext::Prompt(
  246.     const char* /* inMessage */,
  247.     const char* /* inDefaultText */) { return NULL; }
  248. XP_Bool CPlainTextConversionContext::PromptUsernameAndPassword(
  249.     const char* /* inMessage */,
  250.     char** /* outUserName */,
  251.     char** /* outPassword */) { return false; }
  252. char* CPlainTextConversionContext::PromptPassword(const char* /* inMessage */) { return NULL; }
  253.