| 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: $
|
|---|
| 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 |
|
|---|
| 40 | G4OpenGLXmTextField::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 |
|
|---|
| 50 | G4OpenGLXmTextField::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 |
|
|---|
| 61 | G4OpenGLXmTextField::~G4OpenGLXmTextField ()
|
|---|
| 62 | {
|
|---|
| 63 | delete[] initial;
|
|---|
| 64 | }
|
|---|
| 65 |
|
|---|
| 66 | void 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 |
|
|---|
| 76 | const char* G4OpenGLXmTextField::GetName ()
|
|---|
| 77 | {
|
|---|
| 78 | return name;
|
|---|
| 79 | }
|
|---|
| 80 |
|
|---|
| 81 | void 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 |
|
|---|
| 91 | void 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 |
|
|---|
| 102 | const char* G4OpenGLXmTextField::GetValue ()
|
|---|
| 103 | {
|
|---|
| 104 | return initial;
|
|---|
| 105 | }
|
|---|
| 106 |
|
|---|
| 107 | void 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 |
|
|---|
| 168 | Widget* G4OpenGLXmTextField::GetPointerToParent ()
|
|---|
| 169 | {
|
|---|
| 170 | return parent;
|
|---|
| 171 | }
|
|---|
| 172 |
|
|---|
| 173 | Widget* G4OpenGLXmTextField::GetPointerToWidget ()
|
|---|
| 174 | {
|
|---|
| 175 | return &text_field;
|
|---|
| 176 | }
|
|---|
| 177 |
|
|---|
| 178 | #endif
|
|---|