Geant4  10.03.p01
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
G4OpenGLXmTextField.cc
Go to the documentation of this file.
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 // $Id: G4OpenGLXmTextField.cc 68043 2013-03-13 14:27:49Z gcosmo $
28 //
29 //Text field class. Inherits from G4OpenGLXmVWidgetComponent
30 
31 #ifdef G4VIS_BUILD_OPENGLXM_DRIVER
32 
33 #include "G4OpenGLXmViewer.hh"
36 #include "G4OpenGLXmTextField.hh"
37 
38 #include <X11/Intrinsic.h>
39 #include <Xm/Label.h>
40 #include <Xm/TextF.h>
41 
42 #include "globals.hh"
43 
44 G4OpenGLXmTextField::G4OpenGLXmTextField (const char* n,
45  G4double* val)
46 : text_label(0)
47 , text_field(0)
48 , parent(0)
49 {
50  name = n;
51  initial = new char[50];
52  sprintf (initial, "%6.2f", *val);
53  value = (void*)val;
54  text=false;
55 }
56 
57 G4OpenGLXmTextField::G4OpenGLXmTextField (const char* n,
58  const char* val)
59 : text_label(0)
60 , text_field(0)
61 , parent(0)
62 {
63  name = n;
64  initial = new char[50];
65  sprintf (initial, "%s", val);
66  value = (void*)val;
67  text=true;
68  // strcpy (initial, val);
69 }
70 
71 G4OpenGLXmTextField::~G4OpenGLXmTextField ()
72 {
73  delete[] initial;
74 }
75 
76 void G4OpenGLXmTextField::SetName (const char* n)
77 {
78  name = n;
79  XmString text_string = XmStringCreateLocalized ((char*)name);
80  XtVaSetValues (text_label,
81  XmNlabelString, text_string,
82  NULL);
83  XmStringFree (text_string);
84 }
85 
86 const char* G4OpenGLXmTextField::GetName ()
87 {
88  return name;
89 }
90 
91 void G4OpenGLXmTextField::SetValue (G4double val)
92 {
93  sprintf (initial, "%6.2f", val);
94 
95  XtVaSetValues (text_field,
96  XmNvalue, (String)initial,
97  NULL);
98 
99 }
100 
101 void G4OpenGLXmTextField::SetValue (const char* val)
102 {
103  sprintf (initial, "%s", val);
104  // strcpy (initial, val);
105 
106  XtVaSetValues (text_field,
107  XmNvalue, (String)initial,
108  NULL);
109 
110 }
111 
112 const char* G4OpenGLXmTextField::GetValue ()
113 {
114  return initial;
115 }
116 
117 void G4OpenGLXmTextField::AddYourselfTo (G4OpenGLXmVWidgetContainer* container)
118 {
119 
120  pView = container->GetView ();
121  ProcesspView ();
122  parent = container->GetPointerToWidget ();
123 
124  char local_w_text[50];
125  strcpy (local_w_text, name);
126 
127  char label_name[50];
128  strcpy (label_name, name);
129  strcat (label_name, "_label");
130 
131  char text_field_name[50];
132  strcpy (text_field_name, name);
133  strcat (text_field_name, "_text_field");
134 
135  XmString local_text = XmStringCreateLocalized (local_w_text);
136  text_label = XtVaCreateManagedWidget (label_name,
137  xmLabelWidgetClass,
138  *parent,
139 
140  XmNlabelString, local_text,
141 
142  XtNvisual, visual,
143  XtNdepth, depth,
144  XtNcolormap, cmap,
145  XtNborderColor, borcol,
146  XtNbackground, bgnd,
147 
148  NULL);
149  XmStringFree (local_text);
150 
151  text_field = XtVaCreateManagedWidget (text_field_name,
152  xmTextFieldWidgetClass,
153  *parent,
154 
155  XmNvalue, (String)initial,
156 
157  XtNvisual, visual,
158  XtNdepth, depth,
159  XtNcolormap, cmap,
160  XtNborderColor, borcol,
161  XtNbackground, bgnd,
162 
163  NULL);
164 
165  if (!text) {
166  XtAddCallback (text_field,
167  XmNvalueChangedCallback,
168  G4OpenGLXmViewer::get_double_value_callback,
169  value);
170  } else {
171  XtAddCallback (text_field,
172  XmNvalueChangedCallback,
173  G4OpenGLXmViewer::get_text_callback,
174  value);
175  }
176 }
177 
178 Widget* G4OpenGLXmTextField::GetPointerToParent ()
179 {
180  return parent;
181 }
182 
183 Widget* G4OpenGLXmTextField::GetPointerToWidget ()
184 {
185  return &text_field;
186 }
187 
188 #endif
const XML_Char * name
Definition: expat.h:151
const XML_Char int const XML_Char * value
Definition: expat.h:331
double G4double
Definition: G4Types.hh:76