| 1 | // | 
|---|
| 2 | // This File contains the definition of the MGCoordinates-class | 
|---|
| 3 | // | 
|---|
| 4 | //   Author: Thomas Bretz | 
|---|
| 5 | //   Version: V1.0 (1-8-2000) | 
|---|
| 6 |  | 
|---|
| 7 | #include "MGEmbeddedCanvas.h" | 
|---|
| 8 |  | 
|---|
| 9 | #include <iostream.h> | 
|---|
| 10 |  | 
|---|
| 11 | #include <TList.h> | 
|---|
| 12 | #include <TCanvas.h> | 
|---|
| 13 |  | 
|---|
| 14 | #undef DEBUG | 
|---|
| 15 |  | 
|---|
| 16 | ClassImp(MGEmbeddedCanvas); | 
|---|
| 17 |  | 
|---|
| 18 | MGEmbeddedCanvas::MGEmbeddedCanvas(const char *name, const TGWindow* p, | 
|---|
| 19 | UInt_t width, Double_t range) | 
|---|
| 20 | : TRootEmbeddedCanvas(name, p, width+1, width+1, 0/*kRaisedFrame*/), | 
|---|
| 21 | fModified(kFALSE), fWidth(width), fRange(fabs(range)), fPix(2.*fabs(range)/width) | 
|---|
| 22 | { | 
|---|
| 23 | #ifdef DEBUG | 
|---|
| 24 | cout << "MGEmbeddedCanvas: Initializing." << endl; | 
|---|
| 25 | #endif | 
|---|
| 26 |  | 
|---|
| 27 | fCanvas = GetCanvas(); | 
|---|
| 28 |  | 
|---|
| 29 | #ifdef DEBUG | 
|---|
| 30 | cout << "MGEmbeddedCanvas: fCanvas = 0x" << fCanvas << endl; | 
|---|
| 31 |  | 
|---|
| 32 | cout << "MGEmbeddedCanvas: SetFillColor." << endl; | 
|---|
| 33 | #endif | 
|---|
| 34 | fCanvas->SetFillColor(39); // s. TAttFill | 
|---|
| 35 | #ifdef DEBUG | 
|---|
| 36 | cout << "MGEmbeddedCanvas." << endl; | 
|---|
| 37 | #endif | 
|---|
| 38 |  | 
|---|
| 39 | fCanvas->Range(-fRange, -fRange, fRange, fRange); | 
|---|
| 40 |  | 
|---|
| 41 | fList = new TList; | 
|---|
| 42 | fList->SetOwner(); | 
|---|
| 43 |  | 
|---|
| 44 | #ifdef DEBUG | 
|---|
| 45 | cout << "MGEmbeddedCanvas: Initializing done." << endl; | 
|---|
| 46 | #endif | 
|---|
| 47 | } | 
|---|
| 48 |  | 
|---|
| 49 | MGEmbeddedCanvas::~MGEmbeddedCanvas() | 
|---|
| 50 | { | 
|---|
| 51 | delete fList; | 
|---|
| 52 | } | 
|---|
| 53 |  | 
|---|
| 54 | void MGEmbeddedCanvas::Resize(TGDimension size) | 
|---|
| 55 | { | 
|---|
| 56 | fWidth = size.fWidth; | 
|---|
| 57 | fPix = 2.*fRange/size.fWidth; | 
|---|
| 58 | TRootEmbeddedCanvas::Resize(size); | 
|---|
| 59 | } | 
|---|
| 60 |  | 
|---|
| 61 | void MGEmbeddedCanvas::Resize(UInt_t w, UInt_t h) | 
|---|
| 62 | { | 
|---|
| 63 | fWidth = w; | 
|---|
| 64 | fPix = 2.*fRange/w; | 
|---|
| 65 | TRootEmbeddedCanvas::Resize(w, h); | 
|---|
| 66 | } | 
|---|
| 67 |  | 
|---|
| 68 | void MGEmbeddedCanvas::MoveResize(Int_t x, Int_t y, UInt_t w, UInt_t h) | 
|---|
| 69 | { | 
|---|
| 70 | fWidth = w; | 
|---|
| 71 | fPix = 2.*fRange/w; | 
|---|
| 72 | TRootEmbeddedCanvas::MoveResize(x, y, w, h); | 
|---|
| 73 | } | 
|---|
| 74 |  | 
|---|
| 75 | // ------------------------------------------------------------------------ | 
|---|
| 76 | // | 
|---|
| 77 | // Map the subwindows, resize to its quadratic size, map the window itself | 
|---|
| 78 | // and set it to Non-Editable. | 
|---|
| 79 | // | 
|---|
| 80 | void MGEmbeddedCanvas::InitCanvas() | 
|---|
| 81 | { | 
|---|
| 82 | MapSubwindows(); | 
|---|
| 83 |  | 
|---|
| 84 | Resize(fWidth, fWidth); //GetDefaultSize()); // ??? | 
|---|
| 85 | MapWindow(); | 
|---|
| 86 |  | 
|---|
| 87 | fCanvas->SetEditable(kFALSE); | 
|---|
| 88 | } | 
|---|
| 89 |  | 
|---|
| 90 | void MGEmbeddedCanvas::UpdateCanvas() | 
|---|
| 91 | { | 
|---|
| 92 | if (!fModified) | 
|---|
| 93 | return; | 
|---|
| 94 |  | 
|---|
| 95 | // | 
|---|
| 96 | // FIXME: Sometimes (if the canvas couldn't be created correctly: | 
|---|
| 97 | // X11 Pixmap error) Update hangs the Gui system. | 
|---|
| 98 | // | 
|---|
| 99 | // Fixed: By using root 3.01/06 and doing the update from within the | 
|---|
| 100 | // mainthread. | 
|---|
| 101 | // | 
|---|
| 102 |  | 
|---|
| 103 | fCanvas->Modified(); | 
|---|
| 104 | fCanvas->Update(); | 
|---|
| 105 |  | 
|---|
| 106 | fModified = kFALSE; | 
|---|
| 107 | } | 
|---|
| 108 |  | 
|---|
| 109 | // ------------------------------------------------------------------------ | 
|---|
| 110 | // | 
|---|
| 111 | //  Set's the kNoContextMenu bit for all primitives in the embedded canvas | 
|---|
| 112 | //  and the canvas itself, so that no context menu is displayed. | 
|---|
| 113 | // | 
|---|
| 114 | void MGEmbeddedCanvas::SetNoContextMenu() | 
|---|
| 115 | { | 
|---|
| 116 | TList &list = *fCanvas->GetListOfPrimitives(); | 
|---|
| 117 | list.ForEach(TObject, SetBit)(kNoContextMenu); | 
|---|
| 118 |  | 
|---|
| 119 | fCanvas->SetBit(kNoContextMenu); | 
|---|
| 120 | } | 
|---|