Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer 3 // * License and Disclaimer * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/ 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. 9 // * include a list of copyright holders. * 10 // * 10 // * * 11 // * Neither the authors of this software syst 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitatio 16 // * for the full disclaimer and the limitation of liability. * 17 // * 17 // * * 18 // * This code implementation is the result 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboratio 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distri 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you ag 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publicati 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Sof 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************* 24 // ******************************************************************** 25 // 25 // 26 // 26 // >> 27 // $Id: G4OpenGLXmTextField.cc,v 1.7 2006/06/29 21:20:04 gunter Exp $ >> 28 // GEANT4 tag $Name: geant4-09-02-patch-03 $ 27 // 29 // 28 //Text field class. Inherits from G4OpenGLXmVW 30 //Text field class. Inherits from G4OpenGLXmVWidgetComponent 29 31 30 #include "G4OpenGLXmViewer.hh" << 32 #ifdef G4VIS_BUILD_OPENGLXM_DRIVER >> 33 31 #include "G4OpenGLXmVWidgetComponent.hh" 34 #include "G4OpenGLXmVWidgetComponent.hh" 32 #include "G4OpenGLXmVWidgetContainer.hh" 35 #include "G4OpenGLXmVWidgetContainer.hh" 33 #include "G4OpenGLXmTextField.hh" 36 #include "G4OpenGLXmTextField.hh" 34 << 35 #include <X11/Intrinsic.h> 37 #include <X11/Intrinsic.h> 36 #include <Xm/Label.h> << 37 #include <Xm/TextF.h> << 38 << 39 #include "globals.hh" 38 #include "globals.hh" 40 39 41 G4OpenGLXmTextField::G4OpenGLXmTextField (cons 40 G4OpenGLXmTextField::G4OpenGLXmTextField (const char* n, 42 G4double* val) 41 G4double* val) 43 : text_label(0) << 44 , text_field(0) << 45 , parent(0) << 46 { 42 { 47 name = n; 43 name = n; 48 initial = new char[50]; 44 initial = new char[50]; 49 snprintf (initial, 50, "%6.2f", *val); << 45 sprintf (initial, "%6.2f", *val); 50 value = (void*)val; 46 value = (void*)val; 51 text=false; 47 text=false; 52 } 48 } 53 49 54 G4OpenGLXmTextField::G4OpenGLXmTextField (cons 50 G4OpenGLXmTextField::G4OpenGLXmTextField (const char* n, 55 const char* val) 51 const char* val) 56 : text_label(0) << 57 , text_field(0) << 58 , parent(0) << 59 { 52 { 60 name = n; 53 name = n; 61 initial = new char[50]; 54 initial = new char[50]; 62 snprintf (initial, 50, "%s", val); << 55 sprintf (initial, "%s", val); 63 value = (void*)val; 56 value = (void*)val; 64 text=true; 57 text=true; 65 // strcpy (initial, val); 58 // strcpy (initial, val); 66 } 59 } 67 60 68 G4OpenGLXmTextField::~G4OpenGLXmTextField () 61 G4OpenGLXmTextField::~G4OpenGLXmTextField () 69 { 62 { 70 delete[] initial; 63 delete[] initial; 71 } 64 } 72 65 73 void G4OpenGLXmTextField::SetName (const char* 66 void G4OpenGLXmTextField::SetName (const char* n) 74 { 67 { 75 name = n; 68 name = n; 76 XmString text_string = XmStringCreateLocaliz 69 XmString text_string = XmStringCreateLocalized ((char*)name); 77 XtVaSetValues (text_label, 70 XtVaSetValues (text_label, 78 XmNlabelString, text_string, 71 XmNlabelString, text_string, 79 NULL); 72 NULL); 80 XmStringFree (text_string); 73 XmStringFree (text_string); 81 } 74 } 82 75 83 const char* G4OpenGLXmTextField::GetName () 76 const char* G4OpenGLXmTextField::GetName () 84 { 77 { 85 return name; 78 return name; 86 } 79 } 87 80 88 void G4OpenGLXmTextField::SetValue (G4double v 81 void G4OpenGLXmTextField::SetValue (G4double val) 89 { 82 { 90 snprintf (initial, 50, "%6.2f", val); << 83 sprintf (initial, "%6.2f", val); 91 84 92 XtVaSetValues (text_field, 85 XtVaSetValues (text_field, 93 XmNvalue, (String)initial, 86 XmNvalue, (String)initial, 94 NULL); 87 NULL); 95 88 96 } 89 } 97 90 98 void G4OpenGLXmTextField::SetValue (const char 91 void G4OpenGLXmTextField::SetValue (const char* val) 99 { 92 { 100 snprintf (initial, 50, "%s", val); << 93 sprintf (initial, "%s", val); 101 // strcpy (initial, val); 94 // strcpy (initial, val); 102 95 103 XtVaSetValues (text_field, 96 XtVaSetValues (text_field, 104 XmNvalue, (String)initial, 97 XmNvalue, (String)initial, 105 NULL); 98 NULL); 106 99 107 } 100 } 108 101 109 const char* G4OpenGLXmTextField::GetValue () 102 const char* G4OpenGLXmTextField::GetValue () 110 { 103 { 111 return initial; 104 return initial; 112 } 105 } 113 106 114 void G4OpenGLXmTextField::AddYourselfTo (G4Ope 107 void G4OpenGLXmTextField::AddYourselfTo (G4OpenGLXmVWidgetContainer* container) 115 { 108 { 116 109 117 pView = container->GetView (); 110 pView = container->GetView (); 118 ProcesspView (); 111 ProcesspView (); 119 parent = container->GetPointerToWidget (); 112 parent = container->GetPointerToWidget (); 120 113 121 char local_w_text[50]; 114 char local_w_text[50]; 122 strcpy (local_w_text, name); 115 strcpy (local_w_text, name); 123 116 124 char label_name[50]; 117 char label_name[50]; 125 strcpy (label_name, name); 118 strcpy (label_name, name); 126 strcat (label_name, "_label"); 119 strcat (label_name, "_label"); 127 120 128 char text_field_name[50]; 121 char text_field_name[50]; 129 strcpy (text_field_name, name); 122 strcpy (text_field_name, name); 130 strcat (text_field_name, "_text_field"); 123 strcat (text_field_name, "_text_field"); 131 124 132 XmString local_text = XmStringCreateLocalize 125 XmString local_text = XmStringCreateLocalized (local_w_text); 133 text_label = XtVaCreateManagedWidget (label_ 126 text_label = XtVaCreateManagedWidget (label_name, 134 xmLabelWidgetClass, 127 xmLabelWidgetClass, 135 *parent, 128 *parent, 136 129 137 XmNlabelString, local_text, 130 XmNlabelString, local_text, 138 131 139 XtNvisual, visual, 132 XtNvisual, visual, 140 XtNdepth, depth, 133 XtNdepth, depth, 141 XtNcolormap, cmap, 134 XtNcolormap, cmap, 142 XtNborderColor, borcol, 135 XtNborderColor, borcol, 143 XtNbackground, bgnd, 136 XtNbackground, bgnd, 144 137 145 NULL); 138 NULL); 146 XmStringFree (local_text); 139 XmStringFree (local_text); 147 140 148 text_field = XtVaCreateManagedWidget (text_f 141 text_field = XtVaCreateManagedWidget (text_field_name, 149 xmTextFieldWidgetClass, 142 xmTextFieldWidgetClass, 150 *parent, 143 *parent, 151 144 152 XmNvalue, (String)initial, 145 XmNvalue, (String)initial, 153 146 154 XtNvisual, visual, 147 XtNvisual, visual, 155 XtNdepth, depth, 148 XtNdepth, depth, 156 XtNcolormap, cmap, 149 XtNcolormap, cmap, 157 XtNborderColor, borcol, 150 XtNborderColor, borcol, 158 XtNbackground, bgnd, 151 XtNbackground, bgnd, 159 152 160 NULL); 153 NULL); 161 154 162 if (!text) { 155 if (!text) { 163 XtAddCallback (text_field, 156 XtAddCallback (text_field, 164 XmNvalueChangedCallback, 157 XmNvalueChangedCallback, 165 G4OpenGLXmViewer::get_double_value_call 158 G4OpenGLXmViewer::get_double_value_callback, 166 value); 159 value); 167 } else { 160 } else { 168 XtAddCallback (text_field, 161 XtAddCallback (text_field, 169 XmNvalueChangedCallback, 162 XmNvalueChangedCallback, 170 G4OpenGLXmViewer::get_text_callback, 163 G4OpenGLXmViewer::get_text_callback, 171 value); 164 value); 172 } 165 } 173 } 166 } 174 167 175 Widget* G4OpenGLXmTextField::GetPointerToParen 168 Widget* G4OpenGLXmTextField::GetPointerToParent () 176 { 169 { 177 return parent; 170 return parent; 178 } 171 } 179 172 180 Widget* G4OpenGLXmTextField::GetPointerToWidge 173 Widget* G4OpenGLXmTextField::GetPointerToWidget () 181 { 174 { 182 return &text_field; 175 return &text_field; 183 } 176 } >> 177 >> 178 #endif 184 179