dthelp: Change to ANSI function definitions
[oweals/cde.git] / cde / programs / dtmail / dtmail / Attachment.h
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 libraries 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  *+SNOTICE
25  *
26  *      $TOG: Attachment.h /main/8 1998/05/06 15:54:12 rafi $
27  *
28  *      RESTRICTED CONFIDENTIAL INFORMATION:
29  *      
30  *      The information in this document is subject to special
31  *      restrictions in a confidential disclosure agreement between
32  *      HP, IBM, Sun, USL, SCO and Univel.  Do not distribute this
33  *      document outside HP, IBM, Sun, USL, SCO, or Univel without
34  *      Sun's specific written approval.  This document and all copies
35  *      and derivative works thereof must be returned or destroyed at
36  *      Sun's request.
37  *
38  *      Copyright 1993 Sun Microsystems, Inc.  All rights reserved.
39  *
40  *+ENOTICE
41  */
42
43 #ifndef ATTACHMENT_H
44 #define ATTACHMENT_H
45
46 #include <Dt/Dts.h>
47 #include <Dt/Action.h>
48 #include <DtMail/DtMail.hh>
49 #include <DtMail/DtVirtArray.hh>
50
51 #include "UIComponent.h"
52 #include "AttachArea.h"
53
54 #define MARGIN 2
55
56 typedef enum { ROAM_CACHED, ROAM_LOCAL, ROAM_AVAILABLE, ROAM_UNAVAILABLE } ACState;
57
58 typedef enum { DONTKNOW, EXECUTABLE, NOTEXECUTABLE } ExecState;
59
60 class Icon;
61 class Attachment;
62
63 class ActionCallback {
64     friend class Attachment;    
65   public:       
66     ActionCallback(DtMailObjectKey, Attachment *);
67     ~ActionCallback();
68     
69   private:
70     DtMailObjectKey _myKey;
71     Attachment *_myAttachment;
72 };
73
74 class Attachment : public UIComponent {
75
76   public:       
77
78     // This version takes a filename as a parameter
79         
80     Attachment ( AttachArea *, String, DtMail::BodyPart *, int);
81
82     virtual                     ~Attachment();  // Destructor
83     virtual void                initialize();
84     void                        action( 
85                                        DtActionInvocationID, 
86                                        DtActionArg *,
87                                        int,
88                                        int );
89     void                        invokeAction(int);
90
91     int                         operator==(const Attachment&);
92
93     // Accessors
94     //
95     // Note: functions calling getLabel are responsible for freeing
96     //       the XmString it returns
97     //
98     XmString                    getLabel()      { return ( XmStringCopy ( _label ) ); }
99     void                        rename(XmString);
100     void                        *getContents();
101
102
103     unsigned long               getContentsSize()       
104                                         { return ( _myContentsSize ); }
105
106     Dimension                   getWidth()      { return ( _attachmentWidth ); }
107     Dimension                   getHeight()     { return ( _attachmentHeight );}
108     Position                    getX()          { return ( _positionX ); }
109     Position                    getY()          { return ( _positionY );}
110     int                         getRow()        { return ( _row ); }
111
112     Boolean                     isManaged()     { return ( XtIsManaged(_w) ); }
113     Boolean                     isDeleted()     { return ( _deleted ); }
114     AttachArea*                 parent()        { return ( _parent ); }
115     Widget                      getIconWidget() { return ( _w); }
116     void                        manageIconWidget(void);
117     void                        unmanageIconWidget(void);
118
119     String                      getSaveAsFilename()
120                                                 { return ( _saveAsFilename ); }
121     char*                       getCeName()     { return ( _ce_name ); }
122     unsigned short              getType()       { return ( _type ); }
123     String                      getSubType()    { return ( _subtype ); }
124     DtMail::BodyPart            *getBodyPart()  { return ( _body_part ); }
125     Boolean                     isBinary()      { return ( _binary ); }
126     Boolean                     isSelected()    { return ( _selected ); }
127
128
129     void                        saveToFile(DtMailEnv & error,char *filename);
130     virtual const char *const   className()     { return ( "Attachment" ); }
131
132     // Mutators
133     void                        setLabel( XmString str );       
134
135     void                        setX(Position);
136 #ifdef DEAD_WOOD
137     void                        setY(Position);
138     void                        setRow(int);
139 #else /* ! DEAD_WOOD */
140     void                        setY(Position);
141     void                        setRow(int row) { _row = row; }
142 #endif /* ! DEAD_WOOD */
143
144     void                        deleteIt();
145     void                        undeleteIt();
146     void                        setSaveAsFilename(String str) 
147                                                 { ( _saveAsFilename = str); }
148
149     void                        set_binary(Boolean binary) 
150                                                 { ( _binary = binary); }
151
152     void                        handleDoubleClick();
153
154     void                        name_to_type();
155     void                        setAttachArea(AttachArea *);
156 #ifdef DEAD_WOOD
157     Boolean                     check_if_binary(String, unsigned long);
158 #endif /* DEAD_WOOD */
159
160     // SR -- Added methods below
161     
162     void                        primitive_select(); 
163     void                        set_selected();
164     Boolean                     is_selected();
165
166     void                        setContents();
167
168     void                        unselect();
169
170     void                        quit();
171
172     void                        registerAction(DtActionInvocationID);
173     void                        unregisterAction(DtActionInvocationID);
174   protected:
175     static void    actionCallback( 
176                           DtActionInvocationID  id,
177                           XtPointer     client_data,
178                           DtActionArg   *actionArgPtr,
179                           int           actionArgCount,
180                           DtActionStatus status
181                   );
182
183   private:
184
185     Icon*          myIcon;              // my Icon instance
186
187     Pixel          _background;         // The background color
188     Pixel          _foreground;         // The foreground color
189     AttachArea    *_parent;             // The Parent class
190     XmString         _label;            // The name (no absolute path)
191     DtMail::BodyPart *_body_part;       // Pointer to back end body part.
192
193     Dimension      _attachmentWidth;    // The width of the attachment
194     Dimension      _attachmentHeight;   // The height of the attachment
195     Position       _positionX;          // The X Position
196     Position       _positionY;          // The Y Position
197
198     Boolean        _deleted;            // True is it has been deleted
199     Boolean        _selected;           // True if selected.
200     int            _row;                // Which row this is displayed in
201     String         _saveAsFilename;     // Name for Save As
202     int            _index;              // Index in attachArea
203     char          *_ce_name;
204     char          *_ce_type;
205     unsigned short _type;
206     String         _subtype;
207     Boolean        _binary;
208
209     Boolean        _executable;
210     Boolean        _haveContents;
211     char          *_myAllocContents;
212     const void    *_myContents;
213     unsigned long  _myContentsSize;
214     char *         _myType;
215     Boolean        _canKillSelf;
216     
217     char **        _myActionsList;
218     DtVirtArray<DtActionInvocationID> _myActionIds;
219     DtMailObjectKey     _key;
220     void           _setMyContents(const void * data, int size);
221 };
222
223 #endif