ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4OpenGLXmTextField.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4OpenGLXmTextField.cc
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
26 //
27 //
28 //Text field class. Inherits from G4OpenGLXmVWidgetComponent
29 
30 #ifdef G4VIS_BUILD_OPENGLXM_DRIVER
31 
32 #include "G4OpenGLXmViewer.hh"
35 #include "G4OpenGLXmTextField.hh"
36 
37 #include <X11/Intrinsic.h>
38 #include <Xm/Label.h>
39 #include <Xm/TextF.h>
40 
41 #include "globals.hh"
42 
43 G4OpenGLXmTextField::G4OpenGLXmTextField (const char* n,
44  G4double* val)
45 : text_label(0)
46 , text_field(0)
47 , parent(0)
48 {
49  name = n;
50  initial = new char[50];
51  sprintf (initial, "%6.2f", *val);
52  value = (void*)val;
53  text=false;
54 }
55 
56 G4OpenGLXmTextField::G4OpenGLXmTextField (const char* n,
57  const char* val)
58 : text_label(0)
59 , text_field(0)
60 , parent(0)
61 {
62  name = n;
63  initial = new char[50];
64  sprintf (initial, "%s", val);
65  value = (void*)val;
66  text=true;
67  // strcpy (initial, val);
68 }
69 
70 G4OpenGLXmTextField::~G4OpenGLXmTextField ()
71 {
72  delete[] initial;
73 }
74 
75 void G4OpenGLXmTextField::SetName (const char* n)
76 {
77  name = n;
78  XmString text_string = XmStringCreateLocalized ((char*)name);
79  XtVaSetValues (text_label,
80  XmNlabelString, text_string,
81  NULL);
82  XmStringFree (text_string);
83 }
84 
85 const char* G4OpenGLXmTextField::GetName ()
86 {
87  return name;
88 }
89 
90 void G4OpenGLXmTextField::SetValue (G4double val)
91 {
92  sprintf (initial, "%6.2f", val);
93 
94  XtVaSetValues (text_field,
95  XmNvalue, (String)initial,
96  NULL);
97 
98 }
99 
100 void G4OpenGLXmTextField::SetValue (const char* val)
101 {
102  sprintf (initial, "%s", val);
103  // strcpy (initial, val);
104 
105  XtVaSetValues (text_field,
106  XmNvalue, (String)initial,
107  NULL);
108 
109 }
110 
111 const char* G4OpenGLXmTextField::GetValue ()
112 {
113  return initial;
114 }
115 
116 void G4OpenGLXmTextField::AddYourselfTo (G4OpenGLXmVWidgetContainer* container)
117 {
118 
119  pView = container->GetView ();
120  ProcesspView ();
121  parent = container->GetPointerToWidget ();
122 
123  char local_w_text[50];
124  strcpy (local_w_text, name);
125 
126  char label_name[50];
127  strcpy (label_name, name);
128  strcat (label_name, "_label");
129 
130  char text_field_name[50];
131  strcpy (text_field_name, name);
132  strcat (text_field_name, "_text_field");
133 
134  XmString local_text = XmStringCreateLocalized (local_w_text);
135  text_label = XtVaCreateManagedWidget (label_name,
136  xmLabelWidgetClass,
137  *parent,
138 
139  XmNlabelString, local_text,
140 
141  XtNvisual, visual,
142  XtNdepth, depth,
143  XtNcolormap, cmap,
144  XtNborderColor, borcol,
145  XtNbackground, bgnd,
146 
147  NULL);
148  XmStringFree (local_text);
149 
150  text_field = XtVaCreateManagedWidget (text_field_name,
151  xmTextFieldWidgetClass,
152  *parent,
153 
154  XmNvalue, (String)initial,
155 
156  XtNvisual, visual,
157  XtNdepth, depth,
158  XtNcolormap, cmap,
159  XtNborderColor, borcol,
160  XtNbackground, bgnd,
161 
162  NULL);
163 
164  if (!text) {
165  XtAddCallback (text_field,
166  XmNvalueChangedCallback,
167  G4OpenGLXmViewer::get_double_value_callback,
168  value);
169  } else {
170  XtAddCallback (text_field,
171  XmNvalueChangedCallback,
172  G4OpenGLXmViewer::get_text_callback,
173  value);
174  }
175 }
176 
177 Widget* G4OpenGLXmTextField::GetPointerToParent ()
178 {
179  return parent;
180 }
181 
182 Widget* G4OpenGLXmTextField::GetPointerToWidget ()
183 {
184  return &text_field;
185 }
186 
187 #endif