Debian Codegraph @

src/Gui/View.h

raw
1 /***************************************************************************
2 * Copyright (c) 2004 Jürgen Riegel <[email protected]> *
3 * *
4 * This file is part of the FreeCAD CAx development system. *
5 * *
6 * This library is free software; you can redistribute it and/or *
7 * modify it under the terms of the GNU Library General Public *
8 * License as published by the Free Software Foundation; either *
9 * version 2 of the License, or (at your option) any later version. *
10 * *
11 * This library is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU Library General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU Library General Public *
17 * License along with this library; see the file COPYING.LIB. If not, *
18 * write to the Free Software Foundation, Inc., 59 Temple Place, *
19 * Suite 330, Boston, MA 02111-1307, USA *
20 * *
21 ***************************************************************************/
22
23
24 #ifndef GUI_VIEW_H
25 #define GUI_VIEW_H
26
27 #include <Base/BaseClass.h>
28 #include <FCGlobal.h>
29
30 namespace App
31 {
32 class Document;
33 }
34
35 namespace Gui
36 {
37 class Document;
38 class ViewProvider;
39
40 /** Base class of all windows belonging to a document
41 * there are two ways of belonging to a document. The
42 * first way is to a fixed one. The second way is to always
43 * belonging to the Active document. that means switching every time
44 * the active document is changing. It also means that the view
45 * belongs sometimes to no document at all!
46 * @see TreeView
47 * @see Gui::Document
48 * @see Application
49 * @author Juergen Riegel
50 */
51 class GuiExport BaseView: public Base::BaseClass
52 {
53 TYPESYSTEM_HEADER_WITH_OVERRIDE();
54
55 public:
56 /** View constructor
57 * Attach the view to the given document. If the document is 0
58 * the view will attach to the active document. Be aware! there isn't
59 * always an active document!
60 */
61 BaseView(Gui::Document* pcDocument = nullptr);
62 /** View destructor
63 * Detach the view from the document, if attached!
64 */
65 ~BaseView() override;
66
67
68 /** @name methods used by the Application and the GuiDocument
69 */
70 //@{
71 /// sets the view to another document (called by Application)
72 void setDocument(Gui::Document* pcDocument);
73 /// is sent from the document in order to close the document
74 void onClose();
75 //@}
76
77 /// returns the document the view is attached to
78 Gui::Document* getGuiDocument() const
79 {
80 return _pcDocument;
81 }
82 /// returns the document the view is attached to
83 App::Document* getAppDocument() const;
84 /// indicates if the view is in passive mode
85 bool isPassive() const
86 {
87 return bIsPassive;
88 }
89
90 /** @name methods to override
91 */
92 //@{
93 /// get called when the document is updated
94 virtual void onUpdate()
95 {}
96 /// get called when the document is relabeled (change of its user name)
97 virtual void onRelabel(Gui::Document*)
98 {}
99 /// get called when the document is renamed (change of its internal name)
100 virtual void onRename(Gui::Document*)
101 {}
102 /// returns the name of the view (important for messages)
103 virtual const char* getName() const
104 {
105 return "Base view";
106 }
107 /// Message handler
108 virtual bool onMsg(const char* pMsg, const char** ppReturn) = 0;
109 /// Message handler test
110 virtual bool onHasMsg(const char* pMsg) const = 0;
111 /// overwrite when checking on close state
112 virtual bool canClose()
113 {
114 return true;
115 }
116 /// delete itself
117 virtual void deleteSelf();
118 //@}
119
120 protected:
121 Gui::Document* _pcDocument;
122 bool bIsDetached {false};
123 bool bIsPassive {false};
124 };
125
126 } // namespace Gui
127
128 #endif // GUI_VIEW_H