Geant4  9.6.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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$
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 {
47  name = n;
48  initial = new char[50];
49  sprintf (initial, "%6.2f", *val);
50  value = (void*)val;
51  text=false;
52 }
53 
54 G4OpenGLXmTextField::G4OpenGLXmTextField (const char* n,
55  const char* val)
56 {
57  name = n;
58  initial = new char[50];
59  sprintf (initial, "%s", val);
60  value = (void*)val;
61  text=true;
62  // strcpy (initial, val);
63 }
64 
65 G4OpenGLXmTextField::~G4OpenGLXmTextField ()
66 {
67  delete[] initial;
68 }
69 
70 void G4OpenGLXmTextField::SetName (const char* n)
71 {
72  name = n;
73  XmString text_string = XmStringCreateLocalized ((char*)name);
74  XtVaSetValues (text_label,
75  XmNlabelString, text_string,
76  NULL);
77  XmStringFree (text_string);
78 }
79 
80 const char* G4OpenGLXmTextField::GetName ()
81 {
82  return name;
83 }
84 
85 void G4OpenGLXmTextField::SetValue (G4double val)
86 {
87  sprintf (initial, "%6.2f", val);
88 
89  XtVaSetValues (text_field,
90  XmNvalue, (String)initial,
91  NULL);
92 
93 }
94 
95 void G4OpenGLXmTextField::SetValue (const char* val)
96 {
97  sprintf (initial, "%s", val);
98  // strcpy (initial, val);
99 
100  XtVaSetValues (text_field,
101  XmNvalue, (String)initial,
102  NULL);
103 
104 }
105 
106 const char* G4OpenGLXmTextField::GetValue ()
107 {
108  return initial;
109 }
110 
111 void G4OpenGLXmTextField::AddYourselfTo (G4OpenGLXmVWidgetContainer* container)
112 {
113 
114  pView = container->GetView ();
115  ProcesspView ();
116  parent = container->GetPointerToWidget ();
117 
118  char local_w_text[50];
119  strcpy (local_w_text, name);
120 
121  char label_name[50];
122  strcpy (label_name, name);
123  strcat (label_name, "_label");
124 
125  char text_field_name[50];
126  strcpy (text_field_name, name);
127  strcat (text_field_name, "_text_field");
128 
129  XmString local_text = XmStringCreateLocalized (local_w_text);
130  text_label = XtVaCreateManagedWidget (label_name,
131  xmLabelWidgetClass,
132  *parent,
133 
134  XmNlabelString, local_text,
135 
136  XtNvisual, visual,
137  XtNdepth, depth,
138  XtNcolormap, cmap,
139  XtNborderColor, borcol,
140  XtNbackground, bgnd,
141 
142  NULL);
143  XmStringFree (local_text);
144 
145  text_field = XtVaCreateManagedWidget (text_field_name,
146  xmTextFieldWidgetClass,
147  *parent,
148 
149  XmNvalue, (String)initial,
150 
151  XtNvisual, visual,
152  XtNdepth, depth,
153  XtNcolormap, cmap,
154  XtNborderColor, borcol,
155  XtNbackground, bgnd,
156 
157  NULL);
158 
159  if (!text) {
160  XtAddCallback (text_field,
161  XmNvalueChangedCallback,
162  G4OpenGLXmViewer::get_double_value_callback,
163  value);
164  } else {
165  XtAddCallback (text_field,
166  XmNvalueChangedCallback,
167  G4OpenGLXmViewer::get_text_callback,
168  value);
169  }
170 }
171 
172 Widget* G4OpenGLXmTextField::GetPointerToParent ()
173 {
174  return parent;
175 }
176 
177 Widget* G4OpenGLXmTextField::GetPointerToWidget ()
178 {
179  return &text_field;
180 }
181 
182 #endif