home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-09-17 | 7.0 KB | 210 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWEdView.h
- // Release Version: $ ODF 2 $
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #ifndef FWEDVIEW_H
- #define FWEDVIEW_H
-
- //----------------------------------------------------------------------------------------
- // Imported Classes
- //----------------------------------------------------------------------------------------
-
- #ifndef FWFONT_H
- #include "FWFont.h"
- #endif
-
- #ifndef FWVIEW_H
- #include "FWView.h"
- #endif
-
- #ifndef FWNOTIFR_H
- #include "FWNotifr.h"
- #endif
-
- #if defined(FW_BUILD_MAC) && !defined(__TEXTEDIT__)
- #include "TextEdit.h"
- #endif
-
- //========================================================================================
- // Forward Declaration
- //========================================================================================
-
- class FW_CString;
- class FW_CSuperView;
- class FW_CFont;
-
-
- //========================================================================================
- // class FW_CEditView
- //========================================================================================
- // FW_CEditView is a wrapper for Macintosh TextEdit, see Inside Macintosh: Text
-
- class FW_CEditView: public FW_CView, public FW_MNotifier
- {
- public:
- FW_DECLARE_CLASS
- FW_DECLARE_AUTO(FW_CEditView)
-
- // EditView attributes
- enum AttrEnum
- {
- kDrawBox = 0x01, // draw a 1 pixel frame
- kReadOnly = 0x02, // not implemented yet
- kWordWrap = 0x04, // wrap long lines
- kAutoScroll = 0x08, // scroll when text is out of view
- kOutlineHilite = 0x10, // show selection in inactive text edit
- kTextBuffering = 0x20, // for 2-byte scripts
- kInlineInput = 0x40, // use keyboard input method
- kTextServices = 0x80 // see Inside Macintosh: Text
- };
-
- FW_CEditView (Environment* ev,
- FW_CSuperView* container,
- const FW_CRect& bounds,
- ODID viewID,
- const FW_CString& text,
- const FW_CFont& font = FW_kNormalFont,
- short maxChars = FW_MAXINT16,
- unsigned short attributes = FW_CEditView::kDrawBox +
- FW_CEditView::kWordWrap +
- FW_CEditView::kAutoScroll);
-
- FW_CEditView (Environment* ev,
- FW_CSuperView* container,
- const FW_CRect& bounds,
- ODID viewID);
-
- FW_CEditView(Environment* ev);
-
- virtual ~FW_CEditView ();
-
- // ---- Getters
- FW_Boolean HasBox() const;
- FW_Boolean HasWordWrap() const;
- FW_Boolean HasAutoScroll() const;
- unsigned short GetEditAttributes() const;
- FW_ByteCount GetMaxChars(Environment* ev) const;
-
- FW_CString GetText (Environment* ev) const;
- FW_ByteCount GetTextLength (Environment * ev) const;
-
- FW_PlatformHandle GetPlatformEditHandle(Environment* ev) const;
-
- void GetLocale(Environment* ev, FW_Locale& locale) const;
-
- // ---- Text Events
- virtual void DoTECommand (Environment* ev, ODCommandID id, FW_Boolean useScrap);
- virtual FW_Handled InputCharKey (Environment* ev, char c);
-
- // ---- Text changes
- virtual void SetText (Environment* ev, const FW_CString& text);
- virtual void ClearText (Environment* ev);
- virtual void InsertText(Environment* ev, const FW_CString& textToInsert, short offset);
- void SetFont (Environment* ev, const FW_CFont& font);
- FW_CFont GetFont(Environment * ev) const;
-
- // ---- Text Selection
- FW_CString GetSelectedText(Environment* ev) const;
- void GetSelectionRange(Environment* ev, short& startOffset, short& endOffset) const;
- void SetSelectedText(Environment* ev, const FW_CString& newText);
- void SelectText (Environment* ev, short startOffset, short endOffset);
- void SelectAll (Environment* ev);
-
- // ---- FW_MEventHandler
- virtual FW_Handled DoIdle (Environment* ev, const FW_CNullEvent& event);
- virtual FW_Handled DoMouseDown (Environment* ev, const FW_CMouseEvent& event);
- virtual FW_Handled DoVirtualKey (Environment* ev, const FW_CVirtualKeyEvent & event);
- virtual FW_Handled DoCharKey (Environment* ev, const FW_CCharKeyEvent& event);
- virtual FW_Handled DoAdjustMenus (Environment* ev, FW_CMenuBar* menuBar, FW_Boolean hasMenuFocus, FW_Boolean isRoot);
- virtual FW_Handled DoMenu (Environment* ev, const FW_CMenuEvent& event);
- virtual void ActivateTarget (Environment* ev, FW_Boolean tabSelection);
- virtual void DeactivateTarget (Environment* ev);
- virtual FW_Boolean WantsToBeTarget (Environment* ev);
- virtual void SetVisible(Environment* ev, FW_Boolean visible, FW_Boolean propagate);
-
- // ---- FW_CView
- virtual FW_Handled AdjustCursor (Environment* ev, ODFacet* odFacet, const FW_CPoint& where, ODEventInfo* eventInfo);
- virtual void Draw (Environment* ev, ODFacet* facet, ODShape* invalidShape);
- virtual void LocationChanged (Environment* ev, const FW_CPoint& oldLocation);
- virtual void SizeChanged (Environment* ev, const FW_CPoint& oldSize);
-
- // ----- Archiving -----
- virtual void Flatten(Environment* ev, FW_CWritableStream& stream) const;
- virtual void InitializeFromStream(Environment* ev, FW_CReadableStream& stream);
- static void* Create(FW_CReadableStream& stream, FW_ClassTypeConstant type);
- static void Destroy(void* object, FW_ClassTypeConstant type);
-
- protected:
- void PrivSelectAll ();
- void PrivEnableEditMenu(Environment *ev, FW_Boolean enable);
-
- // ---- Utilities
- void Initialize(Environment* ev, const FW_CString& str, const FW_CFont& font);
- FW_CRect GetTextBounds (Environment* ev);
- void MacAdjustRects (Environment* ev, FW_CGraphicContext & gc);
- void MacSetRects (Environment* ev);
- inline TEHandle MacTE() const { return fMacTEHandle; }
- FW_Boolean PrivCheckMaxChars(long numChars);
-
- private:
- TEHandle fMacTEHandle;
- short fMaxChars;
- unsigned short fEditAttributes;
- };
-
-
- //========================================================================================
- // Inlines
- //========================================================================================
-
- inline FW_PlatformHandle FW_CEditView::GetPlatformEditHandle(Environment*) const
- {
- #ifdef FW_BUILD_MAC
- return (FW_PlatformHandle)fMacTEHandle;
- #endif
- }
-
- inline FW_ByteCount FW_CEditView::GetMaxChars(Environment*) const
- {
- #ifdef FW_BUILD_MAC
- return (FW_ByteCount)fMaxChars;
- #endif
- }
-
- //---------------------------------------------------------------------------------------------------
- // attributes
- //---------------------------------------------------------------------------------------------------
-
- inline FW_Boolean FW_CEditView::HasBox() const
- {
- return fEditAttributes & FW_CEditView::kDrawBox;
- }
-
- inline FW_Boolean FW_CEditView::HasWordWrap() const
- {
- return fEditAttributes & FW_CEditView::kWordWrap;
- }
-
- inline FW_Boolean FW_CEditView::HasAutoScroll() const
- {
- return fEditAttributes & FW_CEditView::kAutoScroll;
- }
-
- inline unsigned short FW_CEditView::GetEditAttributes() const
- {
- return fEditAttributes;
- }
-
- inline void FW_CEditView::SelectAll (Environment* ev)
- {
- SelectText(ev, 0, FW_MAXINT16);
- }
-
- #endif // FWEDVIEW_H
-
-