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