G4OpenGLXmTextField.cc

Go to the documentation of this file.
00001 //
00002 // ********************************************************************
00003 // * License and Disclaimer                                           *
00004 // *                                                                  *
00005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
00006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
00007 // * conditions of the Geant4 Software License,  included in the file *
00008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
00009 // * include a list of copyright holders.                             *
00010 // *                                                                  *
00011 // * Neither the authors of this software system, nor their employing *
00012 // * institutes,nor the agencies providing financial support for this *
00013 // * work  make  any representation or  warranty, express or implied, *
00014 // * regarding  this  software system or assume any liability for its *
00015 // * use.  Please see the license in the file  LICENSE  and URL above *
00016 // * for the full disclaimer and the limitation of liability.         *
00017 // *                                                                  *
00018 // * This  code  implementation is the result of  the  scientific and *
00019 // * technical work of the GEANT4 collaboration.                      *
00020 // * By using,  copying,  modifying or  distributing the software (or *
00021 // * any work based  on the software)  you  agree  to acknowledge its *
00022 // * use  in  resulting  scientific  publications,  and indicate your *
00023 // * acceptance of all terms of the Geant4 Software license.          *
00024 // ********************************************************************
00025 //
00026 //
00027 // $Id$
00028 //
00029 //Text field class. Inherits from G4OpenGLXmVWidgetComponent
00030 
00031 #ifdef G4VIS_BUILD_OPENGLXM_DRIVER
00032 
00033 #include "G4OpenGLXmViewer.hh"
00034 #include "G4OpenGLXmVWidgetComponent.hh"
00035 #include "G4OpenGLXmVWidgetContainer.hh"
00036 #include "G4OpenGLXmTextField.hh"
00037 
00038 #include <X11/Intrinsic.h>
00039 #include <Xm/Label.h>
00040 #include <Xm/TextF.h>
00041 
00042 #include "globals.hh"
00043 
00044 G4OpenGLXmTextField::G4OpenGLXmTextField (const char* n,
00045                                           G4double* val)
00046 {
00047   name = n;
00048   initial = new char[50];
00049   sprintf (initial, "%6.2f", *val);
00050   value = (void*)val;
00051   text=false;
00052 }
00053 
00054 G4OpenGLXmTextField::G4OpenGLXmTextField (const char* n,
00055                                           const char* val)
00056 {
00057   name = n;
00058   initial = new char[50];
00059   sprintf (initial, "%s", val);
00060   value = (void*)val;
00061   text=true;
00062   //  strcpy (initial, val);
00063 }
00064 
00065 G4OpenGLXmTextField::~G4OpenGLXmTextField ()
00066 {
00067   delete[] initial;
00068 }
00069 
00070 void G4OpenGLXmTextField::SetName (const char* n) 
00071 {
00072   name = n;
00073   XmString text_string = XmStringCreateLocalized ((char*)name);
00074   XtVaSetValues (text_label,
00075                  XmNlabelString, text_string,
00076                  NULL);
00077   XmStringFree (text_string);
00078 }
00079 
00080 const char* G4OpenGLXmTextField::GetName () 
00081 {
00082   return name;
00083 }
00084 
00085 void G4OpenGLXmTextField::SetValue (G4double val)
00086 {
00087   sprintf (initial, "%6.2f", val);
00088   
00089   XtVaSetValues (text_field,
00090                  XmNvalue, (String)initial,
00091                  NULL);
00092   
00093 }
00094 
00095 void G4OpenGLXmTextField::SetValue (const char* val)
00096 {
00097   sprintf (initial, "%s", val);
00098   //  strcpy (initial, val);
00099 
00100   XtVaSetValues (text_field,
00101                  XmNvalue, (String)initial,
00102                  NULL);
00103   
00104 }
00105 
00106 const char* G4OpenGLXmTextField::GetValue ()
00107 {
00108   return initial;
00109 }
00110 
00111 void G4OpenGLXmTextField::AddYourselfTo (G4OpenGLXmVWidgetContainer* container)
00112 {
00113 
00114   pView = container->GetView ();
00115   ProcesspView ();
00116   parent = container->GetPointerToWidget ();
00117 
00118   char local_w_text[50];
00119   strcpy (local_w_text, name);
00120 
00121   char label_name[50];
00122   strcpy (label_name, name);
00123   strcat (label_name, "_label");
00124   
00125   char text_field_name[50];
00126   strcpy (text_field_name, name);
00127   strcat (text_field_name, "_text_field");
00128   
00129   XmString local_text = XmStringCreateLocalized (local_w_text);
00130   text_label = XtVaCreateManagedWidget (label_name, 
00131                                         xmLabelWidgetClass,
00132                                         *parent,
00133 
00134                                         XmNlabelString, local_text,
00135                                         
00136                                         XtNvisual, visual, 
00137                                         XtNdepth, depth, 
00138                                         XtNcolormap, cmap, 
00139                                         XtNborderColor, borcol,
00140                                         XtNbackground, bgnd,
00141                                         
00142                                         NULL);
00143   XmStringFree (local_text);
00144 
00145   text_field = XtVaCreateManagedWidget (text_field_name,
00146                                         xmTextFieldWidgetClass,
00147                                         *parent,
00148 
00149                                         XmNvalue, (String)initial, 
00150                                         
00151                                         XtNvisual, visual, 
00152                                         XtNdepth, depth, 
00153                                         XtNcolormap, cmap, 
00154                                         XtNborderColor, borcol,
00155                                         XtNbackground, bgnd,
00156                                         
00157                                         NULL);
00158 
00159   if (!text) {
00160     XtAddCallback (text_field, 
00161                    XmNvalueChangedCallback,
00162                    G4OpenGLXmViewer::get_double_value_callback,
00163                    value);
00164   } else {
00165     XtAddCallback (text_field, 
00166                    XmNvalueChangedCallback,
00167                    G4OpenGLXmViewer::get_text_callback,
00168                    value);
00169   }
00170 }
00171 
00172 Widget* G4OpenGLXmTextField::GetPointerToParent ()
00173 {
00174   return parent;
00175 }
00176 
00177 Widget* G4OpenGLXmTextField::GetPointerToWidget () 
00178 {
00179   return &text_field;
00180 }
00181 
00182 #endif

Generated on Mon May 27 17:49:11 2013 for Geant4 by  doxygen 1.4.7