dtinfo subtree dtinfo
[oweals/cde.git] / cde / programs / dtinfo / dtinfo / src / Marks / Mark.C
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
6  * These libraries and programs are free software; you can
7  * redistribute them and/or modify them under the terms of the GNU
8  * Lesser General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * These libraries and programs are distributed in the hope that
13  * they will be useful, but WITHOUT ANY WARRANTY; without even the
14  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  * PURPOSE. See the GNU Lesser General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with these librararies and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22  */
23 /*
24  * $XConsortium: Mark.C /main/4 1996/09/27 19:02:03 drk $
25  *
26  * Copyright (c) 1993 HAL Computer Systems International, Ltd.
27  * All rights reserved.  Unpublished -- rights reserved under
28  * the Copyright Laws of the United States.  USE OF A COPYRIGHT
29  * NOTICE IS PRECAUTIONARY ONLY AND DOES NOT IMPLY PUBLICATION
30  * OR DISCLOSURE.
31  * 
32  * THIS SOFTWARE CONTAINS CONFIDENTIAL INFORMATION AND TRADE
33  * SECRETS OF HAL COMPUTER SYSTEMS INTERNATIONAL, LTD.  USE,
34  * DISCLOSURE, OR REPRODUCTION IS PROHIBITED WITHOUT THE
35  * PRIOR EXPRESS WRITTEN PERMISSION OF HAL COMPUTER SYSTEMS
36  * INTERNATIONAL, LTD.
37  * 
38  *                         RESTRICTED RIGHTS LEGEND
39  * Use, duplication, or disclosure by the Government is subject
40  * to the restrictions as set forth in subparagraph (c)(l)(ii)
41  * of the Rights in Technical Data and Computer Software clause
42  * at DFARS 252.227-7013.
43  *
44  *          HAL COMPUTER SYSTEMS INTERNATIONAL, LTD.
45  *                  1315 Dell Avenue
46  *                  Campbell, CA  95008
47  * 
48  */
49
50
51 #define C_Mark
52 #define L_Marks
53
54 #define C_MessageMgr
55 #define L_Managers
56
57 #include <Prelude.h>
58
59 #define CLASS Mark
60
61 STATIC_SENDER_CC (EditMark);
62 STATIC_SENDER_CC (ViewMark);
63 STATIC_SENDER_CC (MarkDeleted);
64 STATIC_SENDER_CC (MarkChanged);
65
66
67 Mark::Mark()
68 : f_reference_count(0),
69   f_deleted (FALSE)
70 {
71 }
72
73 Mark::~Mark()
74 {
75   ON_DEBUG (printf ("Mark::~Mark() @ 0x%p\n", this));
76   if (f_reference_count != 0)
77    message_mgr().error_dialog((char*)"Attempt to delete mark with references!");
78 }
79
80
81 bool
82 Mark::operator== (const Mark &mark)
83 {
84   // Base classes must override this method if two different Mark
85   // objects can represent the same logical Mark. 
86   if (this == &mark)
87     return (TRUE);
88   else
89     return (FALSE);
90 }
91
92
93 void
94 Mark::save()
95 {
96   if (f_deleted)
97     {
98       message_mgr().error_dialog((char*)"Cannot save changes to deleted mark.");
99     }
100   else
101     {
102       MarkChanged change_message;
103       change_message.f_mark_ptr = this;
104       ON_DEBUG (puts ("Mark::save(): sending message"));
105       send_message (change_message);
106       do_save();
107     }
108 }
109
110 void
111 Mark::remove()
112 {
113   // Anyone holding a non-temporary Pointer<Mark> damn well better
114   // be handling this message! 
115   MarkDeleted delete_message;
116   delete_message.f_mark_ptr = this;
117   // Underyling code might can exception in this call. 
118   do_remove();
119   send_message (delete_message);
120   f_deleted = TRUE;
121   // Mark will be deleted when all references are gone. 
122 }
123
124
125 // /////////////////////////////////////////////////////////////////
126 // edit & display
127 // /////////////////////////////////////////////////////////////////
128
129 void
130 Mark::edit()
131 {
132   EditMark edit_message;
133
134   edit_message.f_mark_ptr = this;
135
136   ON_DEBUG (printf ("Mark::edit() sending message\n"));
137   send_message (edit_message);
138 }
139
140
141 void
142 Mark::view()
143 {
144   ViewMark display_message;
145
146   display_message.f_mark_ptr = this;
147
148   send_message (display_message);
149 }
150
151
152 void
153 Mark::reference()
154 {
155   f_reference_count++;
156 }
157
158 void
159 Mark::unreference()
160 {
161   if (--f_reference_count == 0)
162     delete this;
163 }