source: trunk/geant4/visualization/OpenGL/src/G4OpenGLXmTextField.cc @ 553

Last change on this file since 553 was 529, checked in by garnier, 17 years ago

r658@mac-90108: laurentgarnier | 2007-06-25 12:02:16 +0200
import de visualisation

  • Property svn:mime-type set to text/cpp
File size: 4.7 KB
Line 
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,v 1.7 2006/06/29 21:20:04 gunter Exp $
28// GEANT4 tag $Name: geant4-08-01-patch-01 $
29//
30//Text field class. Inherits from G4OpenGLXmVWidgetComponent
31
32#ifdef G4VIS_BUILD_OPENGLXM_DRIVER
33
34#include "G4OpenGLXmVWidgetComponent.hh"
35#include "G4OpenGLXmVWidgetContainer.hh"
36#include "G4OpenGLXmTextField.hh"
37#include <X11/Intrinsic.h>
38#include "globals.hh"
39
40G4OpenGLXmTextField::G4OpenGLXmTextField (const char* n,
41                                          G4double* val)
42{
43  name = n;
44  initial = new char[50];
45  sprintf (initial, "%6.2f", *val);
46  value = (void*)val;
47  text=false;
48}
49
50G4OpenGLXmTextField::G4OpenGLXmTextField (const char* n,
51                                          const char* val)
52{
53  name = n;
54  initial = new char[50];
55  sprintf (initial, "%s", val);
56  value = (void*)val;
57  text=true;
58  //  strcpy (initial, val);
59}
60
61G4OpenGLXmTextField::~G4OpenGLXmTextField ()
62{
63  delete[] initial;
64}
65
66void G4OpenGLXmTextField::SetName (const char* n)
67{
68  name = n;
69  XmString text_string = XmStringCreateLocalized ((char*)name);
70  XtVaSetValues (text_label,
71                 XmNlabelString, text_string,
72                 NULL);
73  XmStringFree (text_string);
74}
75
76const char* G4OpenGLXmTextField::GetName ()
77{
78  return name;
79}
80
81void G4OpenGLXmTextField::SetValue (G4double val)
82{
83  sprintf (initial, "%6.2f", val);
84 
85  XtVaSetValues (text_field,
86                 XmNvalue, (String)initial,
87                 NULL);
88 
89}
90
91void G4OpenGLXmTextField::SetValue (const char* val)
92{
93  sprintf (initial, "%s", val);
94  //  strcpy (initial, val);
95
96  XtVaSetValues (text_field,
97                 XmNvalue, (String)initial,
98                 NULL);
99 
100}
101
102const char* G4OpenGLXmTextField::GetValue ()
103{
104  return initial;
105}
106
107void G4OpenGLXmTextField::AddYourselfTo (G4OpenGLXmVWidgetContainer* container)
108{
109
110  pView = container->GetView ();
111  ProcesspView ();
112  parent = container->GetPointerToWidget ();
113
114  char local_w_text[50];
115  strcpy (local_w_text, name);
116
117  char label_name[50];
118  strcpy (label_name, name);
119  strcat (label_name, "_label");
120 
121  char text_field_name[50];
122  strcpy (text_field_name, name);
123  strcat (text_field_name, "_text_field");
124 
125  XmString local_text = XmStringCreateLocalized (local_w_text);
126  text_label = XtVaCreateManagedWidget (label_name,
127                                        xmLabelWidgetClass,
128                                        *parent,
129
130                                        XmNlabelString, local_text,
131                                       
132                                        XtNvisual, visual,
133                                        XtNdepth, depth,
134                                        XtNcolormap, cmap,
135                                        XtNborderColor, borcol,
136                                        XtNbackground, bgnd,
137                                       
138                                        NULL);
139  XmStringFree (local_text);
140
141  text_field = XtVaCreateManagedWidget (text_field_name,
142                                        xmTextFieldWidgetClass,
143                                        *parent,
144
145                                        XmNvalue, (String)initial,
146                                       
147                                        XtNvisual, visual,
148                                        XtNdepth, depth,
149                                        XtNcolormap, cmap,
150                                        XtNborderColor, borcol,
151                                        XtNbackground, bgnd,
152                                       
153                                        NULL);
154
155  if (!text) {
156    XtAddCallback (text_field,
157                   XmNvalueChangedCallback,
158                   G4OpenGLXmViewer::get_double_value_callback,
159                   value);
160  } else {
161    XtAddCallback (text_field,
162                   XmNvalueChangedCallback,
163                   G4OpenGLXmViewer::get_text_callback,
164                   value);
165  }
166}
167
168Widget* G4OpenGLXmTextField::GetPointerToParent ()
169{
170  return parent;
171}
172
173Widget* G4OpenGLXmTextField::GetPointerToWidget ()
174{
175  return &text_field;
176}
177
178#endif
Note: See TracBrowser for help on using the repository browser.