Add GNU LGPL headers to all .c .C and .h files
[oweals/cde.git] / cde / programs / dtprintinfo / libUI / MotifUI / MotifUI.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 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 /* $XConsortium: MotifUI.h /main/6 1996/10/21 17:29:46 mgreess $ */
24 /*                                                                      *
25  * (c) Copyright 1993, 1994 Hewlett-Packard Company                     *
26  * (c) Copyright 1993, 1994 International Business Machines Corp.       *
27  * (c) Copyright 1993, 1994 Sun Microsystems, Inc.                      *
28  * (c) Copyright 1993, 1994 Novell, Inc.                                *
29  */
30
31 #ifndef MOTIFUI_H
32 #define MOTIFUI_H
33
34 #include <Xm/Xm.h>
35
36 #if defined(USL) || defined(__uxp__)
37 #undef STRDUP  /* get rid of memutil.h definition. Use def in BaseUI.h. */
38 #endif
39
40 #include "BaseUI.h"
41 #include "MotifThread.h"
42
43 extern "C" {
44 extern XtPointer _XmStringUngenerate (
45                                 XmString string,
46                                 XmStringTag tag,
47                                 XmTextType tag_type,
48                                 XmTextType output_type);
49 }
50
51
52 #define AnyUI MotifUI
53 #define HasDumpUI 1
54
55 #define PointInRect(RECT, X, Y) \
56     (X >= (int) (RECT).x && \
57      Y >= (int) (RECT).y && \
58      X <= (int) (RECT).x + (int) (RECT).width && \
59      Y <= (int) (RECT).y + (int) (RECT).height)
60
61 typedef struct
62 {
63    char *name;
64    Pixmap pixmap;
65    Pixmap mask;
66 } PixmapLookupStruct, *PixmapLookup, **PixmapLookupList;
67
68 class DtDND;
69 class MotifThread;
70
71 class MotifUI : public BaseUI {
72
73  friend class DtDND;
74
75  private:
76
77    static void WidgetDestroyCB(Widget, XtPointer, XtPointer);
78    static void WidgetHelpCB(Widget, XtPointer, XtPointer);
79    Cursor InitHourGlassCursor();
80    static void DumpWidget(Widget w, boolean verbose = false, int level = 0);
81    static void DumpWidgets(Widget w, boolean verbose = false, int level = 0);
82    static void ThreadCB(MotifThread *_thread, BaseUI *obj, ThreadCallback cb);
83
84  protected:
85
86    Widget _w;
87    char *_widgetName;
88
89    MotifUI(MotifUI *parent, 
90            const char *name,
91            const char *category,
92            const char *widgetName = NULL);
93    void InstallDestroyCB();
94    void InstallHelpCB();
95    virtual void WidgetDestroyed();
96    void GetPixmaps(Widget widget, char *iconFile, Pixmap *pixmap,
97                    Pixmap *mask = NULL);
98    void FillBackground(Widget widget, Pixmap pixmap, Pixmap mask);
99    void SetDefaultResources(const Widget, const String *);
100    void GetResources(const XtResourceList, const int);
101    XmString StringCreate(char *string)
102        { if (string) return XmStringCreateLocalized(string);
103          else return NULL;
104        }
105    void StringFree(XmString string) 
106        { if (string) XmStringFree(string); string = NULL; }
107    char * StringExtract(XmString string)
108        { char *s = NULL;
109          s = (char *) _XmStringUngenerate(
110                         string, NULL,
111                         XmMULTIBYTE_TEXT, XmMULTIBYTE_TEXT);
112          return s; };
113
114    // Definitions for BaseUI virtual functions
115    virtual boolean SetCategory(char * /*name*/) { return true; }
116    virtual boolean SetName(char *name);
117    virtual boolean SetActivity(boolean flag);
118    virtual boolean SetVisiblity(boolean flag);
119    virtual boolean SetSelected(boolean flag);
120    void DoSetFocus(Widget);
121    void DoRefresh();
122    void DoToFront();
123    void DoContextualHelp();
124    virtual void DoMakeVisible();
125    virtual boolean DoIsVisible();
126    virtual void DoBeginUpdate() { }
127    virtual void DoEndUpdate() { }
128    virtual void DoUpdateMessage(char * /*message*/) { }
129    virtual boolean SetOrder(int new_postion);
130
131    // Containers widgets should override SetView
132    virtual boolean SetView(ViewStyle) { return true; }
133
134    // Containers and icon widgets should override these
135    virtual boolean SetOpen(boolean) { return true; }
136
137    // Icon widgets should override these
138    virtual boolean SetIcon(IconStyle) { return true; }
139    virtual boolean SetParent(BaseUI *) { return true; }
140
141    virtual void NotifyDelete(BaseUI *);
142    static PixmapLookupList pixmap_table;
143    static int n_pixmaps;
144    static PointerCursor pointer_style;
145
146  public:
147
148    static Widget topLevel;
149    static Display *display;
150    static XtAppContext appContext;
151    static XmFontList userFont;
152    static Font font;
153    static Window root;
154    static Pixel black;
155    static Pixel white;
156    static int depth;
157    static int shadowThickness;
158    static int bMenuButton;
159
160    virtual ~MotifUI();
161
162    void Thread(const char *cmd, ThreadCallback, int buf_len);
163    void Thread(int pid, int fd, ThreadCallback, int buf_len);
164    void Thread(int socket, ThreadCallback, int buf_len);
165
166    virtual void SetFocus();
167    void PointerShape(PointerCursor style);
168    PointerCursor PointerShape();
169    virtual void WidthHeight(int w, int h);
170    virtual void WidthHeight(int *w, int *h);
171    virtual void Width(int w);
172    virtual int Width();
173    virtual void Height(int h);
174    virtual int Height();
175    void AttachAll(int offset = 0);
176    void AttachTop(int offset = 0);
177    void AttachBottom(int offset = 0);
178    void AttachLeft(int offset = 0);
179    void AttachRight(int offset = 0);
180    void AttachTop(BaseUI *, int offset = 0, boolean opposite = false);
181    void AttachBottom(BaseUI *, int offset = 0, boolean opposite = false);
182    void AttachLeft(BaseUI *, int offset = 0, boolean opposite = false);
183    void AttachRight(BaseUI *, int offset = 0, boolean opposite = false);
184    void StringWidthHeight(const char *string, int *w, int *h);
185    int StringWidth(const char *string);
186    int StringHeight(const char *string);
187    void SetAddTimeOut(TimeOutCallback, void *callback_data, long interval);
188    void DumpUIHierarchy(boolean verbose = false, int level = 0);
189
190    const Widget BaseWidget()             { return _w; }
191    virtual const Widget InnerWidget()    { return _w; }
192
193    void Dump(boolean verbose = false,
194              int level = 0);
195
196    // returns a classname to be used in GetResources
197    virtual const char *const className() { return "MotifUI"; }
198
199 };
200
201 #endif /* MOTIFUI_H */