NCBI C++ ToolKit
text_item.hpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 #ifndef GUI_WIDGETS_TEXT_WIDGET___TEXT_ITEM__HPP
2 #define GUI_WIDGETS_TEXT_WIDGET___TEXT_ITEM__HPP
3 
4 /* $Id: text_item.hpp 29771 2014-02-07 20:25:40Z katargir $
5  * ===========================================================================
6  *
7  * PUBLIC DOMAIN NOTICE
8  * National Center for Biotechnology Information
9  *
10  * This software/database is a "United States Government Work" under the
11  * terms of the United States Copyright Act. It was written as part of
12  * the author's official duties as a United States Government employee and
13  * thus cannot be copyrighted. This software/database is freely available
14  * to the public for use. The National Library of Medicine and the U.S.
15  * Government have not placed any restriction on its use or reproduction.
16  *
17  * Although all reasonable efforts have been taken to ensure the accuracy
18  * and reliability of the software and data, the NLM and the U.S.
19  * Government do not and cannot warrant the performance or results that
20  * may be obtained by using this software or data. The NLM and the U.S.
21  * Government disclaim all warranties, express or implied, including
22  * warranties of performance, merchantability or fitness for any particular
23  * purpose.
24  *
25  * Please cite the author in any work or product based on this material.
26  *
27  * ===========================================================================
28  *
29  * Authors: Roman Katargin
30  *
31  * File Description:
32  *
33  */
34 
35 #include <corelib/ncbiobj.hpp>
36 #include <gui/gui_export.h>
37 
38 #include <wx/event.h>
39 
42 
44 
45 class CTextPanelContext;
46 class CTextBlock;
47 
49  class CScope;
51 
53 {
54 public:
55  virtual ~IContainer() {}
56  virtual wxPoint GetItemPosition(int index) const = 0;
57  virtual int GetItemStartLine(int index) const = 0;
58  virtual void ItemSizeChanged(int index) = 0;
59  virtual void UpdatePositions() = 0;
60 };
61 
62 #ifdef _DEBUG
64 #endif
65 
66 class ITextItem
67 {
68 public:
69 
70 #ifdef _DEBUG
72  virtual ~ITextItem() { gITextItemCount.Add(-1); }
73 #else
74  virtual ~ITextItem() { }
75 #endif
76 
77  virtual wxPoint GetPosition() const = 0;
78 
79  virtual void SetContainer(IContainer* container, int index) = 0;
80  virtual void GetContainer(IContainer*& container, int& index) = 0;
81 
82  virtual wxSize GetSize() const = 0;
83  virtual wxRect GetRect() const { return wxRect(GetPosition(), GetSize()); }
84 
85  // Mouse handling
86  virtual void MouseEvent(wxMouseEvent&, CTextPanelContext&) {}
87 
88  // line number in fully expanded text view
89  virtual int GetStartLine() const = 0;
90 
91  // line count in fully expanded text view
92  virtual size_t GetLineCount() const = 0;
93  // Composite item should return item it contains
94  virtual ITextItem* GetItemByLine(int lineNum, bool expanded) = 0;
95 
96  virtual int GetTextLeftMargin(CTextPanelContext* context) const = 0;
97 
98  virtual void CalcSize(wxDC& dc, CTextPanelContext* context) = 0;
99  virtual void Draw(wxDC& dc, const wxRect& updateRect, CTextPanelContext* context) = 0;
100 
101  virtual string GetToolTipText(CTextPanelContext*) const { return ""; }
102 
103  virtual void FillContextMenu(wxMenu& WXUNUSED(menu)) const {}
104 
105  virtual void GetText(wxTextOutputStream& os,
106  const CTextBlock& block,
108 
109  virtual const CConstRef<CObject> GetAssosiatedObject() const { return null; }
110  virtual objects::CScope* GetAssosiatedScope() const { return 0; }
111 
112  virtual bool IsSelectable() const { return (GetAssosiatedObject() != 0); }
113 
114  virtual bool Traverse(ICompositeTraverser& /*traverser*/) = 0;
115 
116 
118  { return CTextBlock((int)GetStartLine(), (int)GetLineCount()); }
119 
120  virtual ITextItem* Clone() { return NULL; }
121 
122 protected:
123 };
124 
125 class CStyledTextOStream;
126 
128 {
129 public:
130  CTextItem() : m_LineCount(1), m_Size(wxDefaultSize), m_Container(), m_Index(0) {}
131 
132  virtual void SetContainer(IContainer* container, int index)
133  { m_Container = container; m_Index = index; }
134  virtual void GetContainer(IContainer*& container, int& index)
135  { container = m_Container; index = m_Index; }
136 
137  virtual wxPoint GetPosition() const
138  { return m_Container ? m_Container->GetItemPosition(m_Index) : wxPoint(0, 0); }
139 
140  virtual wxSize GetSize() const { return m_Size; }
141 
142  // Mouse handling
143  virtual void MouseEvent(wxMouseEvent& event, CTextPanelContext& context);
144 
145  virtual int GetStartLine() const
146  { return m_Container ? m_Container->GetItemStartLine(m_Index) : 0; }
147 
148  virtual size_t GetLineCount() const { return m_LineCount; }
149  virtual ITextItem* GetItemByLine(int lineNum, bool expanded);
150  virtual void SetLineCount(size_t lineCount) { m_LineCount = lineCount; }
151 
152  virtual int GetTextLeftMargin(CTextPanelContext* context) const;
153  virtual void CalcSize(wxDC& dc, CTextPanelContext* context);
154 
155  virtual void Draw(wxDC& dc, const wxRect& updateRect, CTextPanelContext* context);
156 
157  virtual int GetIndent() const { return 0; }
158 
159  virtual bool Traverse(ICompositeTraverser& traverser) { return traverser.ProcessItem(*this); }
160 
161  virtual void TextPosToExpanded(CTextPosition& WXUNUSED(pos), CTextPanelContext* WXUNUSED(context)) const {}
162  virtual void TextPosToCollapsed(CTextPosition& WXUNUSED(pos), CTextPanelContext* WXUNUSED(context)) const {}
163 
165  { x_RenderText(ostream, context); }
166 
167 protected:
168  virtual void x_Indent(CStyledTextOStream& ostream) const;
169  virtual void x_RenderText(CStyledTextOStream& WXUNUSED(ostream), CTextPanelContext* WXUNUSED(context)) const {}
170 
171  size_t m_LineCount;
172  wxSize m_Size;
173 
175  int m_Index;
176 };
177 
179 
180 #endif // GUI_WIDGETS_TEXT_WIDGET___TEXT_ITEM__HPP
CAtomicCounter_WithAutoInit –.
Definition: ncbicntr.hpp:120
CScope –.
Definition: scope.hpp:92
virtual void SetContainer(IContainer *container, int index)
Definition: text_item.hpp:132
virtual void SetLineCount(size_t lineCount)
Definition: text_item.hpp:150
size_t m_LineCount
Definition: text_item.hpp:171
virtual wxPoint GetPosition() const
Definition: text_item.hpp:137
virtual int GetStartLine() const
Definition: text_item.hpp:145
virtual void GetContainer(IContainer *&container, int &index)
Definition: text_item.hpp:134
virtual void TextPosToExpanded(CTextPosition &WXUNUSED(pos), CTextPanelContext *WXUNUSED(context)) const
Definition: text_item.hpp:161
virtual size_t GetLineCount() const
Definition: text_item.hpp:148
virtual void TextPosToCollapsed(CTextPosition &WXUNUSED(pos), CTextPanelContext *WXUNUSED(context)) const
Definition: text_item.hpp:162
IContainer * m_Container
Definition: text_item.hpp:174
virtual int GetIndent() const
Definition: text_item.hpp:157
virtual bool Traverse(ICompositeTraverser &traverser)
Definition: text_item.hpp:159
virtual wxSize GetSize() const
Definition: text_item.hpp:140
wxSize m_Size
Definition: text_item.hpp:172
virtual void x_RenderText(CStyledTextOStream &WXUNUSED(ostream), CTextPanelContext *WXUNUSED(context)) const
Definition: text_item.hpp:169
void RenderText(CStyledTextOStream &ostream, CTextPanelContext *context) const
Definition: text_item.hpp:164
virtual bool ProcessItem(CTextItem &textItem)=0
virtual ~IContainer()
Definition: text_item.hpp:55
virtual int GetItemStartLine(int index) const =0
virtual wxPoint GetItemPosition(int index) const =0
virtual void ItemSizeChanged(int index)=0
virtual void UpdatePositions()=0
virtual wxSize GetSize() const =0
virtual bool IsSelectable() const
Definition: text_item.hpp:112
CTextBlock GetItemBlock() const
Definition: text_item.hpp:117
virtual ITextItem * GetItemByLine(int lineNum, bool expanded)=0
virtual int GetTextLeftMargin(CTextPanelContext *context) const =0
virtual void Draw(wxDC &dc, const wxRect &updateRect, CTextPanelContext *context)=0
virtual void MouseEvent(wxMouseEvent &, CTextPanelContext &)
Definition: text_item.hpp:86
virtual ITextItem * Clone()
Definition: text_item.hpp:120
virtual void GetContainer(IContainer *&container, int &index)=0
virtual int GetStartLine() const =0
virtual wxPoint GetPosition() const =0
virtual void FillContextMenu(wxMenu &WXUNUSED(menu)) const
Definition: text_item.hpp:103
virtual bool Traverse(ICompositeTraverser &)=0
virtual void CalcSize(wxDC &dc, CTextPanelContext *context)=0
virtual string GetToolTipText(CTextPanelContext *) const
Definition: text_item.hpp:101
virtual objects::CScope * GetAssosiatedScope() const
Definition: text_item.hpp:110
virtual ~ITextItem()
Definition: text_item.hpp:72
virtual size_t GetLineCount() const =0
virtual wxRect GetRect() const
Definition: text_item.hpp:83
virtual void GetText(wxTextOutputStream &os, const CTextBlock &block, CTextPanelContext *context)=0
virtual void SetContainer(IContainer *container, int index)=0
virtual const CConstRef< CObject > GetAssosiatedObject() const
Definition: text_item.hpp:109
#define NULL
Definition: ncbistd.hpp:225
TValue Add(int delta) THROWS_NONE
Atomically add value (=delta), and return new counter value.
Definition: ncbicntr.hpp:278
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define END_SCOPE(ns)
End the previously defined scope.
Definition: ncbistl.hpp:75
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
#define BEGIN_SCOPE(ns)
Define a new scope.
Definition: ncbistl.hpp:72
#define NCBI_GUIWIDGETS_TEXT_WIDGET_EXPORT
Definition: gui_export.h:532
Defines to provide correct exporting from DLLs in Windows.
Portable reference counted smart and weak pointers using CWeakRef, CRef, CObject and CObjectEx.
CAtomicCounter_WithAutoInit gITextItemCount
Definition: text_item.cpp:44
static CS_CONTEXT * context
Definition: will_convert.c:21
Modified on Fri Sep 20 14:58:02 2024 by modify_doxy.py rev. 669887