1 /***********************************************************************/
2 /* Open Visualization Data Explorer                                    */
3 /* (C) Copyright IBM Corp. 1989,1999                                   */
4 /* ALL RIGHTS RESERVED                                                 */
5 /* This code licensed under the                                        */
6 /*    "IBM PUBLIC LICENSE - Open Visualization Data Explorer"          */
7 /***********************************************************************/
8 
9 #include <dxconfig.h>
10 #include "../base/defines.h"
11 
12 
13 #include "ImageFormat.h"
14 #include "ImageNode.h"
15 #include "ImageFormatDialog.h"
16 #include "SymbolManager.h"
17 #include "XmUtility.h"
18 #if defined(DXD_WIN) || defined(OS2)
19 #define unlink _unlink
20 #endif
21 #if defined(HAVE_UNISTD_H)
22 #include <unistd.h>
23 #endif
24 #include <Xm/Text.h>
25 #include <Xm/TextF.h>
26 
27 String ImageFormat::DefaultResources[] = {
28     NUL(char*)
29 };
30 
31 
ImageFormat(const char * name,ImageFormatDialog * dialog)32 ImageFormat::ImageFormat (const char *name, ImageFormatDialog *dialog) : UIComponent(name)
33 {
34     this->menuButton = NUL(Widget);
35     this->dialog = dialog;
36     ImageNode *node = this->dialog->getNode();
37     int junk;
38     node->getResolution(this->width, junk);
39     node->getAspect(this->aspect);
40 }
41 
~ImageFormat()42 ImageFormat::~ImageFormat()
43 {
44 }
45 
isMetric()46 boolean ImageFormat::isMetric()
47 {
48     return this->dialog->isMetric();
49 }
50 
getRecordFormat()51 const char* ImageFormat::getRecordFormat()
52 {
53 static char formstr[128];
54 double gamma = this->dialog->getGamma();
55 const char *cp = this->paramString();
56 
57     if ((this->dialog->dirtyGamma() == 0) && (gamma == DEFAULT_GAMMA))
58 	if (this->dialog->getDelayedColors())
59 	    sprintf (formstr, "%s delayed=1", cp);
60 	else
61 	    strcpy (formstr, cp);
62     else
63 	if (this->dialog->getDelayedColors())
64 	    sprintf (formstr, "%s gamma=%lg delayed=1", cp, gamma);
65 	else
66 	    sprintf (formstr, "%s gamma=%lg", cp, gamma);
67 
68     return formstr;
69 }
70 
useLocalFormat()71 boolean ImageFormat::useLocalFormat()
72 {
73 ImageNode *node = this->dialog->getNode();
74     boolean formcon = node->isRecordFormatConnected();
75     if (formcon) return FALSE;
76 
77     if (this->dialog->dirtyGamma()) return TRUE;
78     return this->dialog->dirtyFormat();
79 }
80 
81 //
82 // This only works for widgets whose normal foreground color is black.
83 //
setTextSensitive(Widget w,boolean sens)84 void ImageFormat::setTextSensitive (Widget w, boolean sens)
85 {
86     ASSERT ((XtClass(w) == xmTextWidgetClass) || (XtClass(w) == xmTextFieldWidgetClass));
87     if (sens) {
88 	XtVaSetValues (w,
89 	    XmNeditable, True,
90 	    RES_CONVERT(XmNforeground, "black"),
91 	NULL);
92     } else {
93 	XtVaSetValues (w,
94 	    XmNeditable, False,
95 	    RES_CONVERT(XmNforeground, "grey40"),
96 	NULL);
97     }
98 }
99 
eraseOutputFile(const char * fname)100 void ImageFormat::eraseOutputFile (const char *fname)
101 {
102     unlink (fname);
103 }
104 
105 
isA(Symbol classname)106 boolean ImageFormat::isA(Symbol classname)
107 {
108     Symbol s = theSymbolManager->registerSymbol(ClassImageFormat);
109     return (s == classname);
110 }
111