home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / winfe / fmabstra.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  6.1 KB  |  172 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 __FORM_ABSTRACT_H
  20. #define __FORM_ABSTRACT_H
  21.  
  22. /*  Author:
  23.  *      Garrett Arch Blythe
  24.  *      blythe@netscape.com
  25.  */
  26.  
  27. //    Various form widgets used in derivations.
  28. #include "medit.h"
  29. #include "button.h"
  30.  
  31. //    Class to define common base functionality of all form elements
  32. //        in the front end in an object oriented manner.
  33.  
  34. class CFormElement {
  35. //    Construction/destruction.
  36. //    Do not construct directly, use GetFormElement instead.
  37. protected:
  38.     CFormElement();
  39.     virtual ~CFormElement();
  40.  
  41. //    End all form creation/retrieval routine.
  42. public:
  43.     static CFormElement *GetFormElement(CAbstractCX *pCX, LO_FormElementStruct *pFormElement);
  44.     static CFormElement *GetFormElement(CAbstractCX *pCX, LO_FormElementData *pFormData);
  45.  
  46. //    The form element pointing to us.
  47. //    A method to set/get it.
  48. //    Override the method for casting in derived class (to a specific form element type).
  49. private:
  50.     LO_FormElementStruct *m_pFormElement;
  51. protected:
  52.     virtual void SetElement(LO_FormElementStruct *pFormElement);
  53. public:
  54.     LO_FormElementStruct *GetElement() const;
  55.     LO_FormElementData *GetElementData() const;
  56.     lo_FormElementTextData *GetElementTextData() const;
  57.     lo_FormElementTextareaData *GetElementTextareaData() const;
  58.     lo_FormElementMinimalData *GetElementMinimalData() const;
  59.     lo_FormElementToggleData *GetElementToggleData() const;
  60.     lo_FormElementSelectData *GetElementSelectData() const;
  61.     void *GetElementFEData() const;
  62.  
  63. //    Each form element is of course owned by a specific context.
  64. //    Might want to switch on context capabilities here
  65. //        and perform cleanup (window to printing for example).
  66. //        Override if needed.
  67. private:
  68.     CAbstractCX *m_pCX;
  69. protected:
  70.     virtual void SetContext(CAbstractCX *pCX);
  71.  
  72. public:
  73.     CAbstractCX *GetContext() const;
  74.     LO_TextAttr* GetTextAttr() {return GetElement()->text_attr;}
  75.     void SetWidgetFont(HDC hdc, HWND hWidget);
  76. //    Whether or not we will restore ourselves from default or current data held in the
  77. //        LAYOUT structure.  Initially, it should always be from default, and use
  78. //        current only when we've previously been turned off in GetFormElementValue.
  79. //    Please do not make this public.  Its logic does not map to
  80. //        whether or not the derived classes have the specified
  81. //        behaviour, and it would be a mistake to assume so.
  82. //        It is used to flag this class to make certain function calls.
  83. private:
  84.     BOOL m_bUseCurrentData;
  85.     BOOL ShouldUseCurrentData() { return m_bUseCurrentData; }
  86.  
  87. //    Whether or not a widget is allocated and/or its size data is cached (does not
  88. //        need to be recalculated).
  89. //    Please do not make this public.  Its logic does not map to
  90. //        whether or not the derived classes have a the specified
  91. //        behaviour, and it would be a mistake to assume so.
  92. //        It is used to flag this class to make certain function calls.
  93. private:
  94.     BOOL m_bWidgetPresent;
  95.     BOOL IsWidgetPresent() { return m_bWidgetPresent; }
  96.  
  97. //    A way to get the next control ID for a form widget in a derived class.
  98. private:
  99.     static UINT m_uNextControlID;
  100. protected:
  101.     static UINT GetDynamicControlID();
  102.  
  103. //    Virts that might be overridden in rare cases (operations they must know
  104. //        how to perform on themselves).  These are called by the owning
  105. //        context of the same name (not args).
  106. public:
  107.     virtual void FreeFormElement(LO_FormElementData *pFormData);
  108.     virtual void GetFormElementInfo();
  109.     virtual void GetFormElementValue(BOOL bTurnOff);
  110.     virtual void ResetFormElement();
  111.     virtual void FormTextIsSubmit();
  112.     virtual void SetFormElementToggle(BOOL bState);
  113.  
  114. //    Additional function to return secondary widgets (buttons, etc) in 
  115. //    elements such as File forms.
  116.     virtual CWnd *GetSecondaryWidget() {return 0;}
  117.  
  118. //    You probably want to override these!!!
  119. public:
  120.     virtual void DisplayFormElement(LTRB& Rect);
  121.  
  122. //    Non context funcs that should have been context funcs - whatever.
  123. //    Add more as needed, of course.
  124. //    Override if really needed.
  125. public:
  126.     virtual void FocusInputElement();
  127.     virtual void BlurInputElement();
  128.     virtual void SelectInputElement();
  129.     virtual void ChangeInputElement();
  130.     virtual void EnableInputElement();
  131.     virtual void DisableInputElement();
  132.     virtual void MoveWindow(HWND hWnd, int32 lX, int32 lY);
  133.  
  134. //    Funcs that must be overriden so that logic in base class implementations
  135. //        will work correctly.
  136. protected:
  137.     //    Destroy the widget (window) implementation of the form.
  138.     virtual void DestroyWidget() = 0;
  139.  
  140.     //    Create the widget (window) implementation of the form
  141.     //        but DO NOT DISPLAY.
  142.     virtual void CreateWidget() = 0;
  143.  
  144.     //    Copy the current data out of the layout struct into the form
  145.     //        widget, or mark that you should represent using the current data.
  146.     virtual void UseCurrentData() = 0;
  147.  
  148.     //    Copy the default data out of the layout struct into the form
  149.     //        widget, or mark that you should represent using the default data.
  150.     virtual void UseDefaultData() = 0;
  151.  
  152.     //    Fill in the layout size information in the layout struct regarding
  153.     //        the dimensions of the widget.
  154.     virtual void FillSizeInfo() = 0;
  155.  
  156.     //    Copy the current data out of the form element back into the
  157.     //        layout struct.
  158.     virtual void UpdateCurrentData() = 0;
  159.  
  160. public:
  161.     virtual HWND GetRaw() = 0;
  162.  
  163. //    Misc helpers called by derived classes.
  164. protected:
  165. #ifdef XP_WIN16
  166.     //    Call this to get the allocated segment for each edit field under 16 bits.
  167.     HINSTANCE GetSegment();
  168. #endif
  169. };
  170.  
  171. #endif // __FORM_ABSTRACT_H
  172.