home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / winfe / cxwin.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  16.5 KB  |  480 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. #ifndef __WindowContext_H
  20. //    Avoid include redundancy
  21. //
  22. #define __WindowContext_H
  23.  
  24. //    Purpose:    Provide an abstract context in a window visible on a screen.
  25. //    Comments:    Ill named, as the window is actually a view.
  26. //                Must be derived from to become useful.
  27. //    Revision History:
  28. //        06-25-95    created GAB
  29. //
  30.  
  31. //    Required Includes
  32. //
  33. #include "cxpane.h"
  34. #include "frameglu.h"
  35. #include "xp_core.h"
  36. #include "xp_list.h"
  37.  
  38. #include "tooltip.h"
  39.  
  40. class CWinCX : public CPaneCX    {
  41. //  The view makes a comeback for performance reasons.
  42. //  Leave at the top, forces crashers for bad casts in some cases.
  43. private:
  44.     CGenericView *m_pGenView;
  45. public:
  46.     CGenericView *GetView() { return m_pGenView; }
  47.     
  48. //    Construct, Destruction, Indirect construction
  49. public:
  50.     CWinCX(CGenericDoc *pDoc, CFrameGlue *pFrame, CGenericView *pView, MWContextType mwType = MWContextBrowser, ContextType cxType = Window);
  51.     ~CWinCX();
  52.     virtual void DestroyContext();
  53.     virtual void Initialize(BOOL bOwnDC, RECT *pRect = NULL, BOOL bInitialPalette = TRUE, BOOL bNewMemDC = TRUE);
  54.  
  55. //    Null frame handling (absence of a frame handling)
  56. public:
  57.     static CNullFrame *m_pNullFrame;
  58.     static void *m_pExitCookie;
  59.  
  60. //    The view/frame working with this context.
  61. //    We own a document (see CDCCX).
  62. //    The OLE friend mucks with this.
  63.     friend class CInPlaceFrame;
  64. protected:
  65. #ifdef DDRAW
  66.     LPDIRECTDRAW  m_lpDD;           // DirectDraw object
  67.     LPDIRECTDRAWSURFACE     m_lpDDSPrimary;   // DirectDraw primary surface
  68.     LPDIRECTDRAWSURFACE     m_lpDDSBack;      // DirectDraw back surface
  69.     LPDIRECTDRAWCLIPPER        m_pClipper;
  70.     LPDIRECTDRAWCLIPPER        m_pOffScreenClipper;
  71.     LPDIRECTDRAWPALETTE     mg_pPal;
  72.     DDSURFACEDESC            m_surfDesc;
  73.     BOOL m_ScrollWindow;
  74.     LTRB m_physicWinRect;
  75.     HDC m_offScreenDC;
  76. #endif
  77.     CFrameGlue *m_pFrame;
  78.     XP_List* imageToolTip;
  79.     CNSToolTip *m_ToolTip;
  80.     LO_ImageStruct* pLastToolTipImg;
  81.     LO_AnchorData*    m_pLastToolTipAnchor;
  82.  
  83. public:
  84.     CFrameGlue *GetFrame() const;
  85.     void ClearView();
  86.     void ClearFrame();
  87.  
  88.     CNSToolTip*    CreateToolTip(LO_ImageStruct* pImage, CPoint& point, CL_Layer *layer);
  89.     void RelayToolTipEvent(POINT pt, UINT message);
  90.         void ClipChildren(CWnd *pWnd, BOOL bSet);
  91. //    Palette Access
  92. public:
  93.     virtual HPALETTE GetPalette() const;
  94. #ifdef DDRAW
  95.     virtual int     DisplayPixmap(NI_Pixmap* image, NI_Pixmap* mask, int32 x, int32 y, int32 x_offset, int32 y_offset, int32 width, int32 height, LTRB& Rect);
  96. #endif
  97. //    CDC Access
  98. public:
  99.     virtual HDC GetDispDC() 
  100.     {
  101. #ifdef DDRAW
  102.         if (m_offScreenDC) return m_offScreenDC;
  103.         else return GetContextDC();
  104. #else
  105.         return GetContextDC();
  106. #endif
  107.     }
  108. #ifdef DDRAW
  109.     void CalcWinPos();
  110.     int GetWindowsXPos() {return (int)m_physicWinRect.left;}
  111.     int GetWindowsYPos() {return (int)m_physicWinRect.top;}
  112.     virtual void LockOffscreenSurfDC() {    m_lpDDSBack->GetDC(&m_offScreenDC); }
  113.     virtual void ReleaseOffscreenSurfDC()
  114.         {    if (m_lpDDSBack) m_lpDDSBack->ReleaseDC(m_offScreenDC);}
  115.     void ReleaseDrawSurface(); 
  116.     void RestoreAllDrawSurface();
  117.     void ScrollWindow(int x, int y);
  118.     LPDIRECTDRAWCLIPPER GetClip() {return m_pClipper;}
  119.     LPDIRECTDRAWSURFACE GetPrimarySurface() {return m_lpDDSPrimary;}
  120.     LPDIRECTDRAWSURFACE GetBackSurface() {return m_lpDDSBack;}
  121.     LPDIRECTDRAW GetDrawObj() {return m_lpDD;}
  122.     LPDDSURFACEDESC    GetSurfDesc() {return &m_surfDesc;}
  123.     void SetClipOnDrawSurface(LPDIRECTDRAWSURFACE surface, HRGN hClipRgn);
  124.     LPDIRECTDRAWSURFACE CreateOffscreenSurface(RECT& rect);
  125.     void CreateAndLockOffscreenSurface(RECT& rect);
  126.     void BltToScreen(LTRB& rect, DDBLTFX* fx = NULL);
  127. #endif
  128.  
  129.     void ResetToolTipImg();
  130.  
  131. //    For dialogs
  132. public:
  133.     virtual CWnd *GetDialogOwner() const;
  134.  
  135. //    When in layout, we need a special case to detect if we need to reload the document
  136. //        if the user resizes the window.
  137. protected:
  138.     BOOL m_bIsLayingOut;    //    Set in LayoutNewDocument and LayoutFinished
  139.  
  140. public:
  141.     BOOL IsLayingOut() const    {
  142.         return(m_bIsLayingOut);
  143.     }
  144. //    Can we accept mouse clicks?
  145.     BOOL IsClickingEnabled() const;
  146.  
  147. //    Cached mouse hits.
  148. public:
  149.     CPoint m_cpLBDClick;
  150.     CPoint m_cpLBDown;
  151.     CPoint m_cpLBUp;
  152.     CPoint m_cpMMove;
  153.     CPoint m_cpRBDClick;
  154.     CPoint m_cpRBDown;
  155.     CPoint m_cpRBUp;
  156. //    Mouse state.
  157. public:
  158.     enum MouseEvent {
  159.         m_None,
  160.         m_LBDClick,
  161.         m_LBDown,
  162.         m_LBUp,
  163.         m_MMove,
  164.         m_RBDClick,
  165.         m_RBDown,
  166.         m_RBUp
  167.     } m_LastMouseEvent;
  168.     UINT m_uMouseFlags;
  169.     BOOL m_bLBDown;
  170.     BOOL m_bLBUp;
  171.  
  172. //    Timer processing.
  173. public:
  174.     BOOL m_bScrollingTimerSet;
  175.     BOOL m_bMouseMoveTimerSet;
  176.  
  177. //  Currently selected embedded item, or NULL on none.
  178. public:
  179.     LO_EmbedStruct *m_pSelected;
  180.  
  181. //    Last highlighted anchor, NULL if none.
  182. protected:
  183.     LO_Element *m_pLastArmedAnchor;
  184.  
  185. //    Window notifications.
  186. //    These are pretty much identical to MFC functions names with the added CX
  187. protected:
  188.     virtual void AftWMSize(PaneMessage *pMessage);
  189. public:
  190. #ifdef EDITOR
  191.     virtual void Scroll(int iBars, UINT uSBCode, UINT uPos, HWND hCtrl, UINT uTimes = 1);
  192. #endif
  193.     virtual void OnMoveCX();
  194.     virtual void OnDeactivateEmbedCX();
  195.  
  196. #ifdef LAYERS
  197.     virtual BOOL HandleLayerEvent(CL_Layer * pLayer, CL_Event * pEvent);
  198.     virtual BOOL HandleEmbedEvent(LO_EmbedStruct *embed, CL_Event * pEvent);
  199. #endif /* LAYERS */
  200.     virtual void OnLButtonDblClkCX(UINT uFlags, CPoint cpPoint);
  201.     virtual void OnLButtonDownCX(UINT uFlags, CPoint cpPoint);
  202.     virtual void OnLButtonUpCX(UINT uFlags, CPoint cpPoint, BOOL &bReturnImmediately);
  203.     virtual void OnMouseMoveCX(UINT uFlags, CPoint cpPoint, BOOL &bReturnImmediately);
  204.     virtual void OnRButtonDblClkCX(UINT uFlags, CPoint cpPoint);
  205.     virtual void OnRButtonDownCX(UINT uFlags, CPoint cpPoint);
  206.     virtual void OnRButtonUpCX(UINT uFlags, CPoint cpPoint);
  207.     virtual BOOL OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
  208.     virtual BOOL OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags);
  209.  
  210. #ifdef LAYERS
  211.     // These are the per-layer event handlers. 
  212.     virtual void OnLButtonDblClkForLayerCX(UINT uFlags, CPoint& cpPoint,
  213.                            XY& xyPoint, CL_Layer *layer);
  214.     virtual void OnLButtonDownForLayerCX(UINT uFlags, CPoint& cpPoint,
  215.                          XY& xyPoint, CL_Layer *layer);
  216.     virtual void OnLButtonUpForLayerCX(UINT uFlags, CPoint& cpPoint,
  217.                        XY& xyPoint, CL_Layer *layer, BOOL &bReturnImmediately);
  218.     virtual void OnMouseMoveForLayerCX(UINT uFlags, CPoint& cpPoint,
  219.                        XY& xyPoint, CL_Layer *layer, BOOL &bReturnImmediately);
  220.     virtual BOOL OnRButtonDownForLayerCX(UINT uFlags, CPoint& cpPoint,
  221.                          XY& xyPoint, CL_Layer *layer);
  222.     virtual void OnRButtonDblClkForLayerCX(UINT uFlags, CPoint& cpPoint,
  223.                            XY& xyPoint, CL_Layer *layer);
  224.     virtual void OnRButtonUpForLayerCX(UINT uFlags, CPoint& cpPoint,
  225.                        XY& xyPoint, CL_Layer *layer);
  226. #endif /* LAYERS */
  227.  
  228.     virtual void OnNcPaintCX();
  229.     virtual void OnNcCalcSizeCX(BOOL bCalcValidRects, NCCALCSIZE_PARAMS* lpncsp);
  230.  
  231. //    This is used to track the window rect between OnSize
  232. //        messages.  If the actual window rect has not
  233. //        changed, then expect that we do not need to
  234. //        redraw the view (InValidate/UpdateWindow).
  235. private:
  236.     CRect m_crWindowRect;
  237.  
  238. public:
  239.     // Analogous to m_pLastArmedAnchor,
  240.     //  remember an image we click on
  241.     //  to do drag n drop to editor
  242.     // Public so the view can access it for
  243.     //  copy-image-to-clipboard
  244.     LO_ImageStruct *m_pLastImageObject;
  245.  
  246.     int32 RightMargin()    {
  247.         return(m_lRightMargin);
  248.     }
  249.             
  250. //  URL Retrieval.
  251. public:
  252.     virtual int GetUrl(URL_Struct *pUrl, FO_Present_Types iFormatOut, BOOL bReallyLoad = TRUE, BOOL bForceNew = FALSE);
  253.  
  254. //    Progress helpers.
  255. protected:
  256.     int32 m_lOldPercent;
  257. public:
  258.     int32 QueryProgressPercent();
  259.     void StartAnimation();
  260.     void StopAnimation();
  261.  
  262. // #ifdef EDITOR
  263.     // Test if screen point, such mouse cursor, 
  264.     //      is within a single selected region.
  265.     BOOL PtInSelectedRegion(CPoint cPoint, BOOL bConvertToDocCoordinates = FALSE, CL_Layer *layer = NULL);
  266.     BOOL PtInSelectedCell(CPoint &DocPoint, LO_CellStruct *cell, 
  267.                           BOOL &bContinue, LO_Element *start_element,
  268.                           LO_Element *end_element);
  269.  
  270.     // Flags used during drag/drop
  271.     BOOL m_bMouseInSelection;
  272.     // Drag current doc URL from the URL Bitmap to whatever
  273.     //   destination accepts a Bookmark OLE struct or URL text
  274.     void DragCurrentURL();
  275.     void CopyCurrentURL();
  276.     void DragSelection();
  277.  
  278.     // TRUE when we are dragging something from this context
  279.     BOOL m_bDragging;
  280.     
  281.     // Browser doesn't need this, but Editor
  282.     //  does to prevent errant mouse-over message
  283.     //  which results in wrong cursor for right-button popup menu
  284.     BOOL m_bInPopupMenu;
  285.  
  286.     LTRB m_rectSizing;
  287.  
  288.     // Used only in Editor when dragging to select multiple cells
  289.     BOOL m_bSelectingCells;
  290.  
  291. public:
  292.     void CancelSizing();
  293.     BOOL IsDragging()  { return(m_bDragging); }
  294.  
  295. //    Targeted load operations.
  296. public:
  297.     CWinCX *DetermineTarget(const char *pTarget);
  298.  
  299. //    Saving what is currently in the frames location bar,
  300. //        so we don't go blowing it away.
  301. protected:
  302.     CString m_csSaveLocationBarText;
  303.  
  304. //    Funtion to get our view's offset into the frame window.
  305. public:
  306.     void GetViewOffsetInFrame(CPoint& cpRetval)    const;
  307.  
  308. //    Function to tell the context it is now the active
  309. //        context in a frame.
  310. private:
  311.     BOOL m_bActiveState;
  312. public:
  313.     BOOL IsActive() const    {
  314.         return(m_bActiveState);
  315.     }
  316.     void ActivateCX(BOOL bNowActive);
  317.  
  318. //    Modality support.
  319. public:
  320.     void GoModal(MWContext *pModalOver);
  321. protected:
  322.     CPtrList m_cplModalOver;
  323.  
  324. //    Close callback support.
  325. private:
  326.     CPtrList m_cplCloseCallbacks;
  327.     CPtrList m_cplCloseCallbackArgs;
  328. public:
  329.     void CloseCallback(void (*)(void *), void *);
  330.  
  331. //    Resize and close disabling.
  332. public:
  333.     void EnableResize(BOOL bEnable = TRUE);
  334.     void EnableClose(BOOL bEnable = TRUE);
  335.  
  336. //  Wether or not our size was determined via chrome.
  337. public:
  338.     BOOL m_bSizeIsChrome;
  339.  
  340. //Z order locking
  341.     void SetZOrder(BOOL bZLock = FALSE, BOOL bBottommost = FALSE);
  342.     void DisableHotkeys(BOOL bDisable = FALSE);
  343.  
  344. //  Wether or not we attempt to draw a border.
  345. private:
  346.     BOOL m_bHasBorder;
  347. public:
  348.     void SetBorder(BOOL bBorder)    {
  349.         m_bHasBorder = bBorder;
  350.     }
  351.  
  352. //  How to correclty handle mouse entering element
  353. //      regions and reporting this to the backend.
  354. // Note: The element pointers are not valid after relayout - 
  355. //   must call ClearLastElemen() just before or after a relayout
  356. protected:
  357.     BOOL m_bLastOverTextSet;
  358.     LO_Element *m_pLastOverElement;
  359.     LO_AnchorData *m_pLastOverAnchorData;
  360.     LO_Element *m_pStartSelectionCell;
  361.  
  362. //#ifndef NO_TAB_NAVIGATION 
  363. public :
  364.     void        ClearLastElement() {m_pLastOverElement = NULL; m_pLastOverAnchorData = NULL; m_pStartSelectionCell = NULL;}
  365.     int32            getLastFocusAreaIndex();
  366.     LO_AnchorData    *CWinCX::getLastFocusAnchorPointer();
  367.     char            *CWinCX::getLastFocusAnchorStr();
  368.  
  369.     LO_TabFocusData * CWinCX::getLastTabFocusData();
  370.     LO_Element    *CWinCX::getLastTabFocusElement();
  371.     int            CWinCX::invalidateSegmentedTextElement( LO_TabFocusData *pNextTabFocus, int forward );
  372.     void        CWinCX::setFormElementTabFocus( LO_Element * pFormElement );
  373.  
  374.     void        CWinCX::invalidateElement( LO_Element *pElement );
  375.     BOOL        CWinCX::setTabFocusNext( int forward );    // try myself and then siblings
  376.     BOOL        CWinCX::setNextTabFocusInWin( int forward );    // only in myself
  377.     BOOL        CWinCX::setTabFocusNextChild( MWContext *currentChildContext, int forward ); // as a parent, try other children
  378.  
  379.     BOOL        CWinCX::fireTabFocusElement( UINT nChar);    // WPARAM vKey );
  380.     int            CWinCX::setTextTabFocusDrawFlag( LO_TextStruct *pText, uint32 *pFlag );
  381.     int            CWinCX::getImageDrawFlag(MWContext *context, LO_ImageStruct *pImage, lo_MapAreaRec **ppArea, uint32 *pFlag );
  382.     void        CWinCX::DisplayFeedback(MWContext *pContext, int iLocation, LO_Element *pElement);
  383.  
  384. private :
  385.     void        CWinCX::SetActiveWindow();
  386.     void        CWinCX::setLastTabFocusElement( LO_TabFocusData *pNextTabFocus, int needSetFocus ); 
  387.     void        CWinCX::SetMainFrmTabFocusFlag( int nn );
  388.  
  389. private :
  390.     LO_TabFocusData    m_lastTabFocus;    
  391.     int         m_isReEntry_setLastTabFocusElement;     // to provent re-entry
  392.     BOOL        SaveOleDocument();
  393.  
  394. //#endif /* NO_TAB_NAVIGATION */
  395.  
  396.  
  397.  
  398. public:
  399.     LO_AnchorData *GetAreaAnchorData(LO_Element *pElement);
  400.     void FireMouseOutEvent(BOOL bClearElement, BOOL bClearAnchor, int32 xVal, int32 yVal,
  401.                            CL_Layer *layer);
  402.     void FireMouseOverEvent(LO_Element *pElement, int32 xVal, int32 yVal,
  403.                             CL_Layer *layer);
  404.  
  405. //    Misc MFC helpers.
  406. public:
  407.     virtual void OpenFile();
  408.     virtual BOOL CanOpenFile();
  409.     virtual void SaveAs();
  410.     virtual BOOL CanSaveAs();
  411.     virtual void PrintContext();
  412.     virtual void Print();
  413.     virtual BOOL CanPrint(BOOL bPreview = FALSE);
  414.     virtual void AllFind(MWContext *pSearchContext = NULL);
  415.     virtual BOOL CanAllFind();
  416.     virtual void FindAgain();
  417.     virtual BOOL CanFindAgain() const { return(!theApp.m_csFindString.IsEmpty()); }
  418.     virtual BOOL DoFind(CWnd * pWnd, const char * pFindWhat, BOOL bMatchcase, 
  419.                         BOOL bSearchDown, BOOL bAlertOnNotFound);
  420.     virtual BOOL CanViewSource();
  421.     virtual void ViewSource();
  422.     virtual BOOL CanDocumentInfo();
  423.     virtual void DocumentInfo();
  424.     virtual BOOL CanFrameSource();
  425.     virtual void FrameSource();
  426.     virtual BOOL CanFrameInfo();
  427.     virtual void FrameInfo();
  428.     virtual BOOL CanGoHome();
  429.     virtual void GoHome();
  430.     virtual BOOL CanUploadFile();
  431.     virtual void UploadFile();
  432.  
  433. //    Context Overrides
  434. public:
  435.     virtual void LayoutNewDocument(MWContext *pContext, URL_Struct *pURL, int32 *pWidth, int32 *pHeight, int32 *pmWidth, int32 *pmHeight);
  436.     virtual void FinishedLayout(MWContext *pContext);
  437.     virtual void AllConnectionsComplete(MWContext *pContext);
  438.     virtual void UpdateStopState(MWContext *pContext);
  439.     virtual void SetDocTitle(MWContext *pContext, char *pTitle);
  440.     virtual void ClearView(MWContext *pContext, int iView);
  441.     virtual void CreateEmbedWindow(MWContext *pContext, NPEmbeddedApp *pApp);
  442.     virtual void SaveEmbedWindow(MWContext *pContext, NPEmbeddedApp *pApp);
  443.     virtual void RestoreEmbedWindow(MWContext *pContext, NPEmbeddedApp *pApp);
  444.     virtual void DestroyEmbedWindow(MWContext *pContext, NPEmbeddedApp *pApp);
  445.     virtual void DisplayJavaApp(MWContext *pContext, int iLocation, LO_JavaAppStruct *java_struct);
  446.         virtual void HandleClippingView(MWContext *pContext, LJAppletData *appletD, int x, int y, int width, int height);
  447.         virtual void HideJavaAppElement(MWContext *pContext, LJAppletData * session_data);
  448.     virtual void SetDocDimension(MWContext *pContext, int iLocation, int32 lWidth, int32 lLength);
  449.     virtual void SetDocPosition(MWContext *pContext, int iLocation, int32 lX, int32 lY);
  450.     virtual void FreeJavaAppElement(MWContext *pContext, LJAppletData *appletD);
  451.     virtual void GetJavaAppSize(MWContext *pContext, LO_JavaAppStruct *java_struct, NET_ReloadMethod bReload);
  452.     virtual void DisplayText(MWContext *pContext, int iLocation, LO_TextStruct *pText, XP_Bool clear);
  453.     virtual void DisplaySubtext(MWContext *pContext, int iLocation, LO_TextStruct *pText, int32 lStartPos, int32 lEndPos, XP_Bool clear);
  454.     virtual void SetProgressBarPercent(MWContext *pContext, int32 lPercent);
  455.     virtual void Progress(MWContext *pContext, const char *pMessage);
  456.     virtual void DisplayEdge(MWContext *pContext, int iLocation, LO_EdgeStruct *pEdge);
  457.     virtual void FreeEdgeElement(MWContext *pContext, LO_EdgeStruct *pEdge);
  458.     virtual void EnableClicking(MWContext *pContext);
  459.  
  460. //    Misc draw helpers
  461. public:
  462. #ifdef EDITOR
  463.     virtual void PreWMErasebkgnd(PaneMessage *pMsg);
  464. #endif
  465.  
  466.     // Helper for erasing text structures
  467.     BOOL    EraseTextBkgnd(HDC pDC, RECT&, LO_TextStruct*);
  468. };
  469.  
  470. //    Global variables
  471. //
  472.  
  473. //    Macros
  474. //
  475.  
  476. //    Function declarations
  477. //
  478.  
  479. #endif // __WindowContext_H
  480.