home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / winfe / feimage.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  6.8 KB  |  263 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. #define JMC_INIT_IMGCB_ID    1
  20. #ifndef NSPR20
  21. #include "coremem.h"
  22. #include "stdafx.h"
  23. #else
  24. #include "stdafx.h"
  25. #include "coremem.h"
  26. #endif
  27. #include "feimage.h"
  28. #include "il_types.h"
  29. #include "cxdc.h"
  30.  
  31. JMC_PUBLIC_API(void)
  32. _IMGCB_NewPixmap(struct IMGCB* self, jint op, void* displayContext, jint width, jint height, IL_Pixmap* image, IL_Pixmap* mask)
  33. {
  34.     MWContext *pContext = (MWContext *)displayContext;
  35.     CAbstractCX  *dispCxt = (CAbstractCX *) pContext->fe.cx;
  36.  
  37.     FEBitmapInfo *imageInfo;
  38.  
  39.     imageInfo = new FEBitmapInfo;
  40.  
  41.     if (!imageInfo) return;
  42.     NI_PixmapHeader* imageHeader = &image->header;  
  43.     imageInfo->targetWidth = CASTINT(width);
  44.     imageInfo->targetHeight = CASTINT(height);
  45.     imageInfo->width = CASTINT(width);
  46.     imageHeader->width = width;
  47.  
  48.     imageInfo->height = CASTINT(height);
  49.     imageHeader->height = height;
  50.     imageInfo->hBitmap = NULL;
  51.     image->client_data = imageInfo;
  52.  
  53.     
  54.     if ((imageInfo->bmpInfo  = dispCxt->NewPixmap(image, FALSE)) == NULL) {// error
  55.         delete imageInfo;
  56.         image->client_data = NULL;
  57.         return;
  58.     }
  59.     if (mask) {
  60.         FEBitmapInfo * maskInfo;
  61.  
  62.         NI_PixmapHeader* maskHeader = &mask->header;  
  63.         maskInfo = new FEBitmapInfo;
  64.         if (!maskInfo) {
  65.             delete imageInfo;
  66.             return;
  67.         }
  68.         maskHeader->width = imageHeader->width;
  69.         maskHeader->height = imageHeader->height;
  70.  
  71.         mask->client_data = maskInfo;
  72.         maskInfo->hBitmap = NULL;
  73.         if ((maskInfo->bmpInfo = dispCxt->NewPixmap(mask, TRUE)) == NULL) {// error
  74. #ifndef USE_DIB_SECTION
  75.             if (image->bits) {
  76.                 CDCCX::HugeFree(image->bits);
  77.                 image->bits = NULL;
  78.             }
  79. #endif
  80.             delete imageInfo;
  81.             delete maskInfo;
  82.             mask->client_data = NULL;
  83.             return;
  84.         }
  85.  
  86.         maskInfo->width = CASTINT(maskHeader->width);
  87.         maskInfo->height = CASTINT(maskHeader->height);
  88.         maskInfo->pContext = dispCxt;    // Not used.
  89.         maskInfo->IsMask = TRUE;
  90.     }
  91.  
  92.     imageInfo->pContext = dispCxt;        // Not used.
  93.     imageInfo->IsMask = FALSE;
  94. }
  95.  
  96. JMC_PUBLIC_API(void)
  97. _IMGCB_UpdatePixmap(struct IMGCB* self, jint op, void* a, IL_Pixmap* b, jint c, jint d, jint e, jint f)
  98. {
  99. }
  100.  
  101. JMC_PUBLIC_API(void)
  102. _IMGCB_ControlPixmapBits(struct IMGCB* self, jint op, void* displayContext,
  103.                         IL_Pixmap* image, IL_PixmapControl c)
  104. {
  105.     if (c == IL_RELEASE_BITS) {
  106.         MWContext *pContext = (MWContext *)displayContext;
  107.  
  108.         XP_ASSERT(pContext);
  109.         if (!pContext)
  110.             return;
  111.  
  112.         ABSTRACTCX(pContext)->ImageComplete(image);
  113.     }
  114. }
  115.  
  116. JMC_PUBLIC_API(void)
  117. _IMGCB_DestroyPixmap(struct IMGCB* self, jint op, void* displayContext, IL_Pixmap* pixmap)
  118. {
  119.     FEBitmapInfo *imageInfo;
  120.  
  121.     imageInfo = (FEBitmapInfo*)pixmap->client_data;
  122.  
  123.     if (imageInfo)
  124.         delete imageInfo;
  125. #ifndef USE_DIB_SECTION
  126.     if (pixmap->bits) {
  127.         CDCCX::HugeFree(pixmap->bits);
  128.         pixmap->bits = NULL;
  129.     }
  130. #endif
  131.     pixmap->client_data = NULL;
  132. }
  133.  
  134. JMC_PUBLIC_API(void)
  135. _IMGCB_DisplayPixmap(struct IMGCB* self, jint op, void* displayContext, IL_Pixmap* image, IL_Pixmap* mask, 
  136.                      jint x, jint y, jint x_offset, jint y_offset, jint width, jint height)
  137. {
  138.     MWContext *pContext = (MWContext *)displayContext;
  139.     CDCCX  *dispCxt = (CDCCX *) pContext->fe.cx;
  140.     LTRB Rect;
  141.     dispCxt->DisplayPixmap( image, mask, x, y, x_offset, y_offset, width, height, Rect);
  142. }
  143.  
  144. JMC_PUBLIC_API(void)
  145. _IMGCB_DisplayIcon(struct IMGCB* self, jint op, void* displayContext, jint x, jint y, jint iconNumber)
  146. {
  147.     MWContext *pContext = (MWContext *)displayContext;
  148.     CDCCX  *dispCxt = (CDCCX *) pContext->fe.cx;
  149.  
  150.     dispCxt->DisplayIcon( x, y, CASTINT(iconNumber));
  151. }
  152.  
  153. // The width and height are *write-only* we don't care what the original
  154. //   values are.  But, CDCCX::GetIconDimensions() is going to give us
  155. //   x and y as int32's not int's so jump through a few hoops to get the
  156. //   sizes right.
  157. //
  158. extern JMC_PUBLIC_API(void)
  159. _IMGCB_GetIconDimensions(struct IMGCB* self, jint op, void* displayContext, int* width, int* height, jint iconNumber)
  160. {
  161.     int32 lWidth = 0;
  162.     int32 lHeight = 0;
  163.  
  164.     MWContext *pContext = (MWContext *)displayContext;
  165.     CDCCX  *dispCxt = (CDCCX *)pContext->fe.cx;
  166.     dispCxt->GetIconDimensions( &lWidth,  &lHeight, CASTINT(iconNumber));
  167.  
  168.     if(width)   {
  169.         *width = CASTINT(lWidth);
  170.     }
  171.     if(height)  {
  172.         *height = CASTINT(lHeight);
  173.     }
  174. }
  175.  
  176. JMC_PUBLIC_API(void)
  177. _IMGCB_init(struct IMGCB* self, struct JMCException* *exceptionThrown)
  178. {
  179. }
  180.  
  181. JMC_PUBLIC_API(void*)
  182. _IMGCB_getBackwardCompatibleInterface(struct IMGCB* self, const JMCInterfaceID* iid,
  183.     struct JMCException* *exceptionThrown)
  184. {
  185.     return NULL;
  186. }
  187.  
  188. void
  189. ImageGroupObserver(XP_Observable observable,
  190.           XP_ObservableMsg message,
  191.           void *message_data,
  192.           void *closure)
  193. {
  194.     MWContext *pXPCX = (MWContext *)closure;
  195.  
  196.     switch(message) {
  197.     case IL_STARTED_LOADING:
  198.         ABSTRACTCX(pXPCX)->SetImagesLoading(TRUE);
  199.         break;
  200.  
  201.     case IL_ABORTED_LOADING:
  202.         ABSTRACTCX(pXPCX)->SetImagesDelayed(TRUE);
  203.         break;
  204.  
  205.     case IL_FINISHED_LOADING:
  206.         ABSTRACTCX(pXPCX)->SetImagesLoading(FALSE);
  207.         break;
  208.  
  209.     case IL_STARTED_LOOPING:
  210.         ABSTRACTCX(pXPCX)->SetImagesLooping(TRUE);
  211.         break;
  212.  
  213.     case IL_FINISHED_LOOPING:
  214.         ABSTRACTCX(pXPCX)->SetImagesLooping(FALSE);
  215.         break;
  216.  
  217.     default:
  218.         break;
  219.     }
  220.     FE_UpdateStopState(pXPCX);
  221. }
  222.  
  223. void
  224. FE_MochaImageGroupObserver(XP_Observable observable,
  225.           XP_ObservableMsg message,
  226.           void *message_data,
  227.           void *closure)
  228. {
  229.     IL_GroupMessageData *data = (IL_GroupMessageData *)message_data;
  230.     MWContext *pXPCX = (MWContext *)data->display_context;
  231.  
  232.     // If we are passed a NULL display context, the MWContext has been
  233.     // destroyed.
  234.     if (!pXPCX)
  235.         return;
  236.     
  237.     switch(message) {
  238.     case IL_STARTED_LOADING:
  239.         ABSTRACTCX(pXPCX)->SetMochaImagesLoading(TRUE);
  240.         break;
  241.  
  242.     case IL_ABORTED_LOADING:
  243.         ABSTRACTCX(pXPCX)->SetMochaImagesDelayed(TRUE);
  244.         break;
  245.  
  246.     case IL_FINISHED_LOADING:
  247.         ABSTRACTCX(pXPCX)->SetMochaImagesLoading(FALSE);
  248.         break;
  249.  
  250.     case IL_STARTED_LOOPING:
  251.         ABSTRACTCX(pXPCX)->SetMochaImagesLooping(TRUE);
  252.         break;
  253.  
  254.     case IL_FINISHED_LOOPING:
  255.         ABSTRACTCX(pXPCX)->SetMochaImagesLooping(FALSE);
  256.         break;
  257.  
  258.     default:
  259.         break;
  260.     }
  261.     FE_UpdateStopState(pXPCX);
  262. }
  263.