]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TGeant4/TG4Editor.cxx
Made all AliL3FileHandler specific functions virtual in AliL3MemHandler.
[u/mrichter/AliRoot.git] / TGeant4 / TG4Editor.cxx
1 // $Id$
2 // Category: interfaces
3 //
4 // Author: D. Adamova
5 //========================================================
6 //
7 //---------------TG4Editor.cxx---------------------------//
8 //------- A supplementary service class for--------------//
9 //-----------AG4 Geometry Browser------------------------//
10 //
11 //=========================================================
12
13 #include "TG4Editor.h"
14 #include "TG4Globals.h"
15
16 #include <TGButton.h>
17 #include <TGTextEdit.h>
18 #include <TGText.h>
19
20
21 ClassImp(TG4Editor)
22
23 TG4Editor::TG4Editor(const TGWindow* main, UInt_t w, UInt_t h) :
24     TGTransientFrame(gClient->GetRoot(), main, w, h)
25 {
26    // Create an editor 
27
28    fEdit = new TGTextEdit(this, w, h, kSunkenFrame | kDoubleBorder);
29    fL1 = new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 3, 3, 3, 3);
30    AddFrame(fEdit, fL1);
31
32    fOK = new TGTextButton(this, "  &OK  ");
33    fL2 = new TGLayoutHints(kLHintsBottom | kLHintsCenterX, 0, 0, 5, 5);
34    AddFrame(fOK, fL2);
35
36    SetTitle();
37
38    MapSubwindows();
39
40    Resize(GetDefaultSize());
41
42    // position relative to the parent's window
43    Window_t wdum;
44    int ax, ay;
45    gVirtualX->TranslateCoordinates(main->GetId(), GetParent()->GetId(),
46                           (((TGFrame *) main)->GetWidth() - fWidth) >> 1,
47                           ((TGFrame *) main)->GetHeight() - (fHeight >> 1),
48                           ax, ay, wdum);
49    Move(ax, ay);
50    SetWMPosition(ax, ay);
51 }
52
53 TG4Editor::TG4Editor(const TG4Editor& ge) :
54      TGTransientFrame( (const TGTransientFrame&) ge)
55 {
56 // Dummy copy constructor 
57   TG4Globals::Exception(
58     "Attempt to use TG4Editor copy constructor.");
59 }
60
61 TG4Editor& TG4Editor::operator=(const TG4Editor& ge)
62 {
63   // check assignement to self
64   if (this == &ge) return *this;
65
66   TG4Globals::Exception(
67     "Attempt to assign TG4Editor singleton.");
68     
69   return *this;  
70 }    
71
72
73 TG4Editor::~TG4Editor()
74 {
75    // Delete editor accessories
76
77    delete fEdit;
78    delete fOK;
79    delete fL1;
80    delete fL2;
81 }
82
83 void TG4Editor::SetTitle()
84 {   
85 // Set title in editor window.
86
87    TGText* txt = GetEditor()->GetText();
88    Bool_t untitled = !strlen(txt->GetFileName()) ? kTRUE : kFALSE;
89
90    char title[256];
91    if (untitled)
92       sprintf(title, "Message Display");
93    else
94       sprintf(title, "Editor - %s", txt->GetFileName());
95
96    SetWindowName(title);
97    SetIconName(title);
98 }
99
100 void TG4Editor::Popup()
101 {
102    // Show editor.
103
104    MapWindow();
105    fClient->WaitFor(this);
106 }
107
108 void TG4Editor::LoadBuffer(const char* buffer) 
109 {
110    // Load a text buffer in the editor.
111
112    fEdit->LoadBuffer(buffer);
113 }
114
115 void TG4Editor::CloseWindow()
116 {
117    // Called when closed via window manager action.
118
119    delete this;
120 }
121
122 Bool_t TG4Editor::ProcessMessage(Long_t msg, Long_t, Long_t)
123 {
124    // Process Help Menu.
125    
126
127    switch (GET_MSG(msg)) {
128       case kC_COMMAND:
129          switch (GET_SUBMSG(msg)) {
130             case kCM_BUTTON:
131                // Only one button and one action...
132                delete this;
133                break;
134             default:
135                break;
136          }
137          break;
138       case kC_TEXTVIEW:
139          switch (GET_SUBMSG(msg)) {
140             case kTXT_CLOSE:
141                // close window
142                delete this;
143                break;
144             case kTXT_OPEN:
145                SetTitle();
146                break;
147             case kTXT_SAVE:
148                SetTitle();
149                break;
150             default:
151                break;
152          }
153       default:
154          break;
155    }
156
157    return kTRUE;
158 }
159