Index: trunk/MagicSoft/Cosy/gui/MGAccuracy.cc
===================================================================
--- trunk/MagicSoft/Cosy/gui/MGAccuracy.cc	(revision 913)
+++ trunk/MagicSoft/Cosy/gui/MGAccuracy.cc	(revision 918)
@@ -58,4 +58,8 @@
     line.DrawLine(    0, -65*4,    0, 65*4);
 
+    //
+    // Can be replaced by TGaxis axe; in a later root version
+    // than 3.01/06. I talked to Rene
+    //
     TGaxis *axe;
     axe = new TGaxis(-60*4,   0, 60*4,  0,  -4, 4, 30204, "+-N");
@@ -175,34 +179,26 @@
 MGAccuracy::~MGAccuracy()
 {
-    cout << "MGAccuracy destroyed." << endl;
-}
-
-void MGAccuracy::UpdateText(Float_t x, Float_t y)
-{
-    /*
-     int xs = (int)floor(fmod(fabs(x), 60.));
-     int ys = (int)floor(fmod(fabs(y), 60.));
-     x /= 60.;
-     y /= 60.;
-     int xm = (int)floor(fmod(fabs(x), 60.));
-     int ym = (int)floor(fmod(fabs(y), 60.));
-
-     char tx[100];
-     char ty[100];
-
-     xm ? sprintf(tx, "%d'%02d\"", xm, xs) : sprintf(tx, "%d\"", xs);
-     ym ? sprintf(ty, "%d'%02d\"", ym, ys) : sprintf(ty, "%d\"", ys);
-
-     char txt[200];
-     sprintf(txt, "%s / %s", tx, ty);
-     */
-
-    // FIXME: We are on a sphere
-
-    float r = sqrt(x*x+y*y);
-
-    int rs = (int)floor(fmod(r, 60.));
-    r /= 60.;
-    int rm = (int)floor(fmod(r, 60.));
+    //    cout << "MGAccuracy destroyed." << endl;
+}
+
+void MGAccuracy::UpdateText(Float_t pzd, Float_t azd, Float_t aaz)
+{
+    const Float_t d2r = TMath::Pi()/360.;
+
+    pzd *= d2r;
+    azd *= d2r;
+    aaz *= d2r;
+
+    const float dphi2 = aaz/2.;
+    const float cos2  = cos(dphi2)*cos(dphi2);
+    const float sin2  = sin(dphi2)*sin(dphi2);
+
+    float dist = acos(cos(azd)*cos2 - cos(2*pzd+azd)*sin2);
+
+    dist *= 3600./d2r;
+
+    int rs = (int)floor(fmod(dist, 60.));
+    dist /= 60.;
+    int rm = (int)floor(fmod(dist, 60.));
 
     char txt[100];
@@ -227,5 +223,5 @@
 }
 
-void MGAccuracy::Update(ZdAz &zdaz)
+void MGAccuracy::Update(ZdAz &pos, ZdAz &acc)
 {
     //
@@ -235,6 +231,6 @@
     static int Y = ~0;
 
-    float x = zdaz.Az()*3600.; // ["]
-    float y = zdaz.Zd()*3600.; // ["]
+    float x = acc.Az()*3600.; // ["]
+    float y = acc.Zd()*3600.; // ["]
 
     int pixx = (int)(x/fPix);  // [pix]
@@ -248,5 +244,5 @@
 
     UpdateCross(x, y);
-    UpdateText(x, y);
+    UpdateText(pos.Zd(), acc.Az(), acc.Zd());
 
     SetModified();
Index: trunk/MagicSoft/Cosy/gui/MGAccuracy.h
===================================================================
--- trunk/MagicSoft/Cosy/gui/MGAccuracy.h	(revision 913)
+++ trunk/MagicSoft/Cosy/gui/MGAccuracy.h	(revision 918)
@@ -32,5 +32,5 @@
     void InitCross();
 
-    void UpdateText(Float_t x, Float_t y);
+    void UpdateText(Float_t zd, Float_t x, Float_t y);
     void UpdateCross(Float_t x, Float_t y);
 
@@ -39,5 +39,5 @@
     ~MGAccuracy();
 
-    void Update(ZdAz &pos);
+    void Update(ZdAz &pos, ZdAz &acc);
 };
 
Index: trunk/MagicSoft/Cosy/gui/MGCoordinate.cc
===================================================================
--- trunk/MagicSoft/Cosy/gui/MGCoordinate.cc	(revision 913)
+++ trunk/MagicSoft/Cosy/gui/MGCoordinate.cc	(revision 918)
@@ -126,5 +126,5 @@
 MGCoordinate::~MGCoordinate()
 {
-    cout << "MGCoordinate destroyed." << endl;
+    //    cout << "MGCoordinate destroyed." << endl;
 }
 
Index: trunk/MagicSoft/Cosy/gui/MGCosy.cc
===================================================================
--- trunk/MagicSoft/Cosy/gui/MGCosy.cc	(revision 913)
+++ trunk/MagicSoft/Cosy/gui/MGCosy.cc	(revision 918)
@@ -1,8 +1,11 @@
 #include "MGCosy.h"
 
+#include <iostream.h>
+
 #include "msgqueue.h"
 
 #include <TROOT.h>
 
+#include <TGTab.h>         // TGTab
 #include <TGMenu.h>        // TGPopupMenu
 #include <TGButton.h>      // TGButton
@@ -10,4 +13,5 @@
 #include <TGLabel.h>       // TGLabel
 #include <TG3DLine.h>      // TGHorizontal3DLine (TGSplitter)
+#include <TGFrame.h>       // TGGroupFrame
 #include <TApplication.h>  // gApplication
 
@@ -31,4 +35,5 @@
 #define kPB_CALCALTAZ 0x1004
 #define kPB_POLARIS   0x1005
+#define kPB_START     0x1006
 
 #define kEF_A         0x1010
@@ -43,7 +48,7 @@
     //  crate the menu bar
     //
-    TGPopupMenu *fFileMenu = new TGPopupMenu(fClient->GetRoot());
+    TGPopupMenu *fFileMenu = new TGPopupMenu(gClient->GetRoot());
     fFileMenu->AddEntry ("Exit", IDM_EXIT) ;
-    fFileMenu->Associate(this);
+    //fFileMenu->Associate(this);
     fList->Add(fFileMenu);
 
@@ -53,92 +58,183 @@
     TGMenuBar *fMenuBar = new TGMenuBar(this, 1, 1, kHorizontalFrame);
     fMenuBar->AddPopup("File", fFileMenu, fLayMenuItem);
-    AddFrame(fMenuBar);
+    AddFrame(fMenuBar, fLayMenuBar);
     fList->Add(fMenuBar);
 
     //
-    //  Seperator beyonf menubar
-    //
+    //  Seperator beyond menubar
+    //
+
     TGHorizontal3DLine *fLineSep = new TGHorizontal3DLine(this);
     AddFrame(fLineSep, fLayMenuBar);
     fList->Add(fLineSep);
-
-}
-
-void MGCosy::CreateLabel()
-{
+}
+
+void MGCosy::CreateLabel(TGCompositeFrame *f)
+{
+    const int y = 25;
+    const int x = 180;
+
     fLabel1 = new TGLabel*[3];
-    fLabel1[0] = new TGLabel(this, "00000"); // Max: 16384
+    fLabel1[0] = new TGLabel(f, "00000"); // Max: 16384
+    fLabel1[1] = new TGLabel(f, "000");   // Max: 256
+    fLabel1[2] = new TGLabel(f, "000");   // Max: 256
     fLabel1[0]->SetTextJustify(kTextRight);
-    fLabel1[0]->Move(5, 40);
+    fLabel1[1]->SetTextJustify(kTextRight);
+    fLabel1[2]->SetTextJustify(kTextRight);
+    fLabel1[0]->Move(x,    y);
+    fLabel1[1]->Move(x+43, y);
+    fLabel1[2]->Move(x+70, y);
     fList->Add(fLabel1[0]);
-    //    AddFrame(fLabel1[0], new TGLayoutHints(kLHintsNormal, 0, 0, 0, 0));
-    fLabel1[1] = new TGLabel(this, "000");   // Max: 256
-    fLabel1[1]->SetTextJustify(kTextRight);
-    fLabel1[1]->Move(48, 40);
     fList->Add(fLabel1[1]);
-    //    AddFrame(fLabel1[1], new TGLayoutHints(kLHintsNormal, 0, 0, 0, 0));
-    fLabel1[2] = new TGLabel(this, "000");   // Max: 256
-    fLabel1[2]->SetTextJustify(kTextRight);
-    fLabel1[2]->Move(75, 40);
     fList->Add(fLabel1[2]);
-    //    AddFrame(fLabel1[2], new TGLayoutHints(kLHintsNormal, 9, 9, 9, 9));
+    //f->AddFrame(fLabel1[0]);
+    //f->AddFrame(fLabel1[1]);
+    //f->AddFrame(fLabel1[2]);
 
     fLabel2 = new TGLabel*[3];
-    fLabel2[0] = new TGLabel(this, "00000");
+    fLabel2[0] = new TGLabel(f, "00000");
+    fLabel2[1] = new TGLabel(f, "000");
+    fLabel2[2] = new TGLabel(f, "000");
     fLabel2[0]->SetTextJustify(kTextRight);
-    fLabel2[0]->Move(5, 60);
+    fLabel2[1]->SetTextJustify(kTextRight);
+    fLabel2[2]->SetTextJustify(kTextRight);
+    fLabel2[0]->Move(x,    y+20);
+    fLabel2[1]->Move(x+43, y+20);
+    fLabel2[2]->Move(x+70, y+20);
     fList->Add(fLabel2[0]);
-    //    AddFrame(fLabel2[0], new TGLayoutHints); //(kLHintsNormal, 0, 0, 0, 0));
-    fLabel2[1] = new TGLabel(this, "000");
-    fLabel2[1]->SetTextJustify(kTextRight);
-    fLabel2[1]->Move(48, 60);
     fList->Add(fLabel2[1]);
-    //    AddFrame(fLabel2[1], new TGLayoutHints); //(kLHintsNormal, 1, 0, 0, 0));
-    fLabel2[2] = new TGLabel(this, "000");
-    fLabel2[2]->SetTextJustify(kTextRight);
-    fLabel2[2]->Move(75, 60);
     fList->Add(fLabel2[2]);
-    //    AddFrame(fLabel2[2], new TGLayoutHints); //(kLHintsNormal, 2, 0, 0, 0));
+    //f->AddFrame(fLabel2[0]);
+    //f->AddFrame(fLabel2[1]);
+    //f->AddFrame(fLabel2[2]);
 
     fLabel3 = new TGLabel*[3];
-    fLabel3[0] = new TGLabel(this, "00000");
+    fLabel3[0] = new TGLabel(f, "00000");
+    fLabel3[1] = new TGLabel(f, "000");
+    fLabel3[2] = new TGLabel(f, "000");
     fLabel3[0]->SetTextJustify(kTextRight);
-    fLabel3[0]->Move(5, 80);
+    fLabel3[1]->SetTextJustify(kTextRight);
+    fLabel3[2]->SetTextJustify(kTextRight);
+    fLabel3[0]->Move(x,    y+40);
+    fLabel3[1]->Move(x+43, y+40);
+    fLabel3[2]->Move(x+70, y+40);
     fList->Add(fLabel3[0]);
-    //    AddFrame(fLabel3[0]); //, new TGLayoutHints(kLHintsNormal, 0, 0, 0, 0));
-    fLabel3[1] = new TGLabel(this, "000");
-    fLabel3[1]->SetTextJustify(kTextRight);
-    fLabel3[1]->Move(48, 80);
     fList->Add(fLabel3[1]);
-    //    AddFrame(fLabel3[1]); //, new TGLayoutHints(kLHintsNormal, 1, 0, 0, 0));
-    fLabel3[2] = new TGLabel(this, "000");
-    fLabel3[2]->SetTextJustify(kTextRight);
-    fLabel3[2]->Move(75, 80);
     fList->Add(fLabel3[2]);
-    //    AddFrame(fLabel3[2]); //, new TGLayoutHints(kLHintsNormal, 2, 0, 0, 0));
-}
-
-void MGCosy::CreateButton()
-{
-    TGTextButton *fButton1 = new TGTextButton(this, "Position Zd/Az", kPB_POSITION);
-    TGTextButton *fButton2 = new TGTextButton(this, "Track   Ra/Dec", kPB_TRACK);
-    TGTextButton *fButton3 = new TGTextButton(this, "Stop",           kPB_STOP);
-    TGTextButton *fButton4 = new TGTextButton(this, "Calc     Zd/Az", kPB_CALCALTAZ);
-    TGTextButton *fButton5 = new TGTextButton(this, "Set Polaris",    kPB_POLARIS);
-    fButton1->Move(110,  40);
-    fButton2->Move(110,  65);
-    fButton3->Move(260,  90);
-    fButton4->Move(110,  90);
-    fButton5->Move(110, 115);
-    fButton1->SetToolTipText("Move Telescope to Zd/Az position.");
-    fButton2->SetToolTipText("Track the coordinates given in Ra/Dec.");
-    fButton3->SetToolTipText("Stop movement of telescope.");
+    //f->AddFrame(fLabel3[0]);
+    //f->AddFrame(fLabel3[1]);
+    //f->AddFrame(fLabel3[2]);
+
+
+    fError    = new TGLabel(f, "Error");
+    fMoving   = new TGLabel(f, "Moving");
+    fTracking = new TGLabel(f, "Tracking");
+    fStopping = new TGLabel(f, "Stopping");
+    fStopped  = new TGLabel(f, "Stopped");
+
+    fError   ->SetBackgroundColor(224); // red
+    fMoving  ->SetBackgroundColor(10);  // blue
+    fTracking->SetBackgroundColor(47);  // blue
+    fStopping->SetBackgroundColor(164); // orange
+    fStopped ->SetBackgroundColor(20);  // green
+
+    fError   ->Move(10, 25);
+    fMoving  ->Move(10, 25+20);
+    fTracking->Move(10, 25+40);
+    fStopping->Move(10, 25+60);
+    fStopped ->Move(10, 25+80);
+
+    fError   ->Resize(60, 20);
+    fMoving  ->Resize(60, 20);
+    fTracking->Resize(60, 20);
+    fStopping->Resize(60, 20);
+    fStopped ->Resize(60, 20);
+
+    fList->Add(fError);
+    fList->Add(fMoving);
+    fList->Add(fTracking);
+    fList->Add(fStopping);
+    fList->Add(fStopped);
+}
+
+void MGCosy::CreateButton(TGCompositeFrame *tf1, TGCompositeFrame *tf2)
+{
+    const int x=15;
+    const int y=12;
+    const int h=16;
+
+    TGLabel *l1 = new TGLabel(tf1, "Move the telescope to a position given in");
+    TGLabel *l2 = new TGLabel(tf1, "local coordinates. The given coordinates");
+    TGLabel *l3 = new TGLabel(tf1, "are pointing coordinates, which means that the");
+    TGLabel *l4 = new TGLabel(tf1, "coordinates are corrected for the bending of");
+    TGLabel *l5 = new TGLabel(tf1, "the telescope."); 
+    l1->Move(x, y);
+    l2->Move(x, y+h);
+    l3->Move(x, y+2*h);
+    l4->Move(x, y+3*h);
+    l5->Move(x, y+4*h);
+    fList->Add(l1);
+    fList->Add(l2);
+    fList->Add(l3);
+    fList->Add(l4);
+    fList->Add(l5);
+
+    l1 = new TGLabel(tf2, "Track a position given in sky coordinates.");
+    l2 = new TGLabel(tf2, "Right Ascension and declination must be given");
+    l3 = new TGLabel(tf2, "in the FK5, J2000 coordinate system");
+    l1->Move(x, y);
+    l2->Move(x, y+h);
+    l3->Move(x, y+2*h);
+    fList->Add(l1);
+    fList->Add(l2);
+    fList->Add(l3);
+
+    //
+    // light green: 3   light red:  2   blue?:      2
+    // dark green:  8   dark red:  50   dark blue?: 1
+
+    //
+    // blue:  0-7, 9, 10,11, 14, 15, 18, 19, 22, 23, 27, 31, 33-39, 41-43
+    //        46, 47
+    // green: 8, 12,13, 16, 17, 20, 21, 24, 25, 26, 28, 29, 30, 40, 44
+    //        45, 48
+    // gray:  31, 113-
+    // red:   164, 192, 224, 232
+    //
+
+    //    TGTextButton *fButton1 = new TGTextButton(this, "Position Zd/Az", kPB_POSITION);
+    //    TGTextButton *fButton2 = new TGTextButton(this, "Track   Ra/Dec", kPB_TRACK);
+    TGTextButton *fButton4 = new TGTextButton(this, "Calc Zd/Az",  kPB_CALCALTAZ);
+    TGTextButton *fButton5 = new TGTextButton(this, "Set Polaris", kPB_POLARIS);
+    //    fButton1->Move(120,  40);
+    //    fButton2->Move(120,  65);
+    fButton4->Resize(80, 25);
+    fButton5->Resize(80, 25);
+
+    fButton4->Move(40, 257);
+    fButton5->Move(40, 288);
+    //fButton4->SetBackgroundColor(12);
+    //fButton5->SetBackgroundColor(16);
+    //    fButton1->SetToolTipText("Move Telescope to Zd/Az position.");
+    //    fButton2->SetToolTipText("Track the coordinates given in Ra/Dec.");
     fButton4->SetToolTipText("Calculate Zd/Az corresponding to Ra/Dec.");
     fButton5->SetToolTipText("Set the actual position as the position of Polaris.");
-    fList->Add(fButton1);
-    fList->Add(fButton2);
-    fList->Add(fButton3);
+    //    fList->Add(fButton1);
+    //    fList->Add(fButton2);
     fList->Add(fButton4);
     fList->Add(fButton5);
+
+    TGTextButton *fStart = new TGTextButton(this, "Start", kPB_START);
+    TGTextButton *fStop  = new TGTextButton(this, "Stop",  kPB_STOP);
+    fStart->SetBackgroundColor(20);
+    fStop ->SetBackgroundColor(224);
+    fStart->Move(147, 275);
+    fStop ->Move(212, 275);
+    fStart->Resize(60, 25);
+    fStop ->Resize(60, 25);
+    fStart->SetToolTipText("Start a telescope movement.");
+    fStop ->SetToolTipText("Stop any movement of telescope.");
+    fList->Add(fStart);
+    fList->Add(fStop);
 }
 
@@ -149,41 +245,63 @@
 
     CreateMenu();
-    CreateLabel();
-    CreateButton();
-
+
+    TGCompositeFrame *f = new TGCompositeFrame(this, 0, 0);
+    f->SetLayoutManager(new TGMatrixLayout(f, 3, 2, 10));
+    fList->Add(f);
+
+    fTab = new TGTab(f, 300, 300);
+    TGCompositeFrame *tf1 = fTab->AddTab("Position Zd/Az");
+    TGCompositeFrame *tf2 = fTab->AddTab("Track Ra/Dec");
+    fList->Add(fTab);
+
+    fSkyPosition = new MGSkyPosition(f, 300);
+    fAccuracy    = new MGAccuracy   (f, 300);
+    fVelocity    = new MGVelocity   (f, "Velocity ['/min]", 300);
+    fOffset      = new MGVelocity   (f, "Offset se-re [']", 300);
+
+    fList->Add(fSkyPosition);
+    fList->Add(fAccuracy);
+    fList->Add(fVelocity);
+    fList->Add(fOffset);
+
+    TGGroupFrame *frame = new TGGroupFrame(f, "Status");
+    frame->Resize(300, 300);
+    fList->Add(frame);
+
+    //
+    // Layout the window, tile by tile...
+    //
+    f->AddFrame(fTab);
+    f->AddFrame(fSkyPosition);
+    f->AddFrame(fAccuracy);
+    f->AddFrame(frame);
+    f->AddFrame(fVelocity);
+    f->AddFrame(fOffset);
+
+    AddFrame(f, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 0, 0, 1, 0));
+
+    //
+    // FIXME!
+    //
     fCoord = new MGCoordinates(this, kTRUE,
                                "Coordinate 1 [\xb0]:", "Coordinate 2 [\xb0]:");
-    fCoord->Move(10, 160);
+    fCoord->Move(40, 165);
     fList->Add(fCoord);
 
-    fSkyPosition = new MGSkyPosition(this, 300);
-    fSkyPosition->Move(320, 40);
-    fList->Add(fSkyPosition);
-
-    fAccuracy = new MGAccuracy(this, 300);
-    fAccuracy->Move(320, 360);
-    fList->Add(fAccuracy);
-
-    fVelocity = new MGVelocity(this, "Velocity ['/min]", 300);
-    fVelocity->Move(10, 360);
-    fList->Add(fVelocity);
-
-    fOffset = new MGVelocity(this, "Offset se-re [']", 300);
-    fOffset->Move(630, 360);
-    fList->Add(fOffset);
+    CreateButton(tf1, tf2);
+    CreateLabel(frame);
 
     //
     //   Map the window, set up the layout, etc.
     //
-    const Int_t w = 650+310;
-    const Int_t h = 690;
+    const Int_t w = 940;
+    const Int_t h = 660;
     SetWMSizeHints(w, h, w, h, 10, 10);  // set the smallest and biggest size of the Main frame
-
-    MapSubwindows();
-    Layout();
 
     SetWindowName("Cosy Main Window");
     SetIconName("Cosy");
 
+    MapSubwindows();
+    Resize(GetDefaultSize());
     MapWindow();
 }
@@ -193,5 +311,5 @@
 MGCosy::~MGCosy()
 {
-    cout << "Deleting MGCosy." << endl;
+    cout << "MGCosy::~MGCosy called." << endl;
 
     delete fLayMenuBar;
@@ -202,13 +320,43 @@
     delete fList;
 
-    cout << "MGCosy deleted." << endl;
+    cout << "MGCosy::~MGCosy done." << endl;
 }
 // ======================================================================
-void MGCosy::Update(ZdAz pos, ZdAz acc, ZdAz vel, ZdAz off)
+void MGCosy::EnableLabel(TGLabel *label, Bool_t stat)
+{
+    stat ? label->MapWindow() : label->UnmapWindow();
+
+    /*
+    TGGC *fRedTextGC(TGButton::GetDefaultGC())
+        // Set foreground color in graphics context for drawing of
+        // TGlabel and TGButtons with text in red.
+        ULong_t red;
+    gClient->GetColorByName("red", red);
+    fRedTextGC.SetForeground(red);
+    */
+}
+
+void MGCosy::Update(ZdAz pos, ZdAz acc, ZdAz vel, ZdAz off, UInt_t stat)
 {
     fSkyPosition->Update(pos);
-    fAccuracy->Update(acc);
+    fAccuracy->Update(pos, acc);
     fVelocity->Update(vel);
     fOffset->Update(off);
+
+#define kError     0x01
+#define kMoving    0x02
+#define kTracking  0x04
+#define kStopping  0x08
+#define kStopped   0x10
+
+    EnableLabel(fError,    stat&kError);
+    EnableLabel(fMoving,   stat&kMoving);
+    EnableLabel(fTracking, stat&kTracking);
+    EnableLabel(fStopping, stat&kStopping);
+    EnableLabel(fStopped,  stat&kStopped);
+
+    stat&kTracking ? fAccuracy->MapWindow() : fAccuracy->UnmapWindow();
+    stat&kTracking ? fVelocity->MapWindow() : fVelocity->UnmapWindow();
+    stat&kTracking ? fOffset->MapWindow()   : fOffset->UnmapWindow();
 }
 // ======================================================================
@@ -221,12 +369,33 @@
     // window menu item is selected.
 
-    //gSystem->ExitLoop();
-    //  gSystem->DispatchOneEvent(kTRUE);
-
-    //    TGMainFrame::CloseWindow();
-    gApplication->Terminate(0);
-}
-
-#include <iostream.h>
+    // gSystem->ExitLoop();
+    // gSystem->DispatchOneEvent(kTRUE);
+
+    // TGMainFrame::CloseWindow();
+    fQueue->PostMsg(WM_QUIT, 0, 0);
+    // gApplication->Terminate(0);
+}
+
+void MGCosy::Start(UInt_t id)
+{
+    cout << "Start " << (id?"tracking.":"positioning.") << endl;
+
+    XY xy = fCoord->GetCoordinates();
+
+    if (id)
+    {
+        RaDec dest(xy.X(), xy.Y());
+        cout << dest.Ra() << kDEG << " " << dest.Dec() << kDEG << endl;
+        fQueue->PostMsg(WM_TRACK, &dest, sizeof(dest));
+    }
+    else
+    {
+        ZdAz dest(xy.X(), xy.Y());
+        cout << dest.Zd() << kDEG << " " << dest.Az() << kDEG << endl;
+        fQueue->PostMsg(WM_POSITION, &dest, sizeof(dest));
+    }
+
+    cout << "PostMsg (" << (id?"WM_Track":"WM_Position") << ") returned." << endl;
+}
 
 Bool_t MGCosy::ProcessMessage(Long_t msg, Long_t mp1, Long_t mp2)
@@ -240,4 +409,8 @@
         switch (GET_SUBMSG(msg))
         {
+        case kCM_TAB:
+            //cout << "Tab: " << mp1 << endl;
+            return kTRUE;
+
         case kCM_BUTTON:
 
@@ -245,23 +418,13 @@
             {
             case kPB_POSITION:
-                cout << "Start positioning." << endl;
-                {
-                    XY xy = fCoord->GetCoordinates();
-                    ZdAz dest(xy.X(), xy.Y());
-                    cout << dest.Zd() << kDEG << " " << dest.Az() << kDEG << endl;
-                    fQueue->PostMsg(WM_POSITION, &dest, sizeof(dest));
-                }
-                cout << "PostMsg(WM_POSITION) returned." << endl;
+                Start(0);
                 return kTRUE;
 
             case kPB_TRACK:
-                cout << "Start tracking." << endl;
-                {
-                    XY xy = fCoord->GetCoordinates();
-                    RaDec dest(xy.X(), xy.Y());
-                    cout << dest.Ra() << kDEG << " " << dest.Dec() << kDEG << endl;
-                    fQueue->PostMsg(WM_TRACK, &dest, sizeof(dest));
-                }
-                cout << "PostMsg(WM_TRACK) returned." << endl;
+                Start(1);
+                return kTRUE;
+
+            case kPB_START:
+                Start(fTab->GetCurrent());
                 return kTRUE;
 
@@ -269,5 +432,5 @@
                 cout << "Sending stop movement msg." << endl;
                 fQueue->PostMsg(WM_STOP, 0, 0);
-                cout << "PostMsg(WM_STOP) returned." << endl;
+                cout << "PostMsg (WM_Stop) returned." << endl;
                 return kTRUE;
 
@@ -293,5 +456,5 @@
                 return kTRUE;
             }
-            break;
+            return kTRUE;
 
         case kCM_MENU:
@@ -300,19 +463,11 @@
             {
             case IDM_EXIT:
-                cout << "Idm_Exit." << endl;
-                CloseWindow();
-                return kTRUE;
-
-            default:
+                fQueue->PostMsg(WM_QUIT, 0, 0);
+                //cout << "Idm_Exit." << endl;
+                //CloseWindow();
                 return kTRUE;
             }
             return kTRUE;
-
-        default:
-            return kTRUE;
         }
-
-    default:
-        return kTRUE;
     }
 
Index: trunk/MagicSoft/Cosy/gui/MGCosy.h
===================================================================
--- trunk/MagicSoft/Cosy/gui/MGCosy.h	(revision 913)
+++ trunk/MagicSoft/Cosy/gui/MGCosy.h	(revision 918)
@@ -31,4 +31,6 @@
 class MGAccuracy;
 class MGVelocity;
+class TGCompositeFrame;
+class TGTab;
 
 class MGCosy : public TGMainFrame
@@ -56,7 +58,19 @@
     MsgQueue      *fQueue;
 
+    TGTab         *fTab;
+
+    TGLabel *fError;
+    TGLabel *fMoving;
+    TGLabel *fTracking;
+    TGLabel *fStopping;
+    TGLabel *fStopped;
+
     void CreateMenu();
-    void CreateLabel();
-    void CreateButton();
+    void CreateLabel(TGCompositeFrame *f);
+    void CreateButton(TGCompositeFrame *tf1, TGCompositeFrame *tf2);
+
+    void Start(UInt_t id);
+
+    void EnableLabel(TGLabel *label, Bool_t stat);
 
 public:
@@ -70,5 +84,5 @@
     TGLabel **GetLabel3() { return fLabel3; }
 
-    void Update(ZdAz pos, ZdAz acc, ZdAz vel, ZdAz off);
+    void Update(ZdAz pos, ZdAz acc, ZdAz vel, ZdAz off, UInt_t stat);
 
     Bool_t ProcessMessage(Long_t msg, Long_t mp1, Long_t mp2);
Index: trunk/MagicSoft/Cosy/gui/MGEmbeddedCanvas.cc
===================================================================
--- trunk/MagicSoft/Cosy/gui/MGEmbeddedCanvas.cc	(revision 913)
+++ trunk/MagicSoft/Cosy/gui/MGEmbeddedCanvas.cc	(revision 918)
@@ -12,5 +12,5 @@
 MGEmbeddedCanvas::MGEmbeddedCanvas(const char *name, const TGWindow* p,
                                    const UInt_t width, Float_t range)
-    : TRootEmbeddedCanvas(name, p, width, width, kRaisedFrame),//, 0) //234, 76, kFixedSize)
+    : TRootEmbeddedCanvas(name, p, width+1, width+1, kRaisedFrame),//, 0) //234, 76, kFixedSize)
       fModified(kFALSE), fWidth(width), fRange(range), fPix(2.*range/width)
 {
@@ -33,5 +33,5 @@
     MapSubwindows();
 
-    Resize(fWidth-1, fWidth-1); //GetDefaultSize()); // ???
+    Resize(fWidth, fWidth); //GetDefaultSize()); // ???
     MapWindow();
 
@@ -44,6 +44,11 @@
         return;
 
+    //
     // FIXME: Sometimes (if the canvas couldn't be created correctly:
     // X11 Pixmap error) Update hangs the Gui system.
+    //
+    // Fixed: Using root 3.01/06 and doing the update from within the
+    // mainthread.
+    //
 
     fCanvas->Modified();
Index: trunk/MagicSoft/Cosy/gui/MGSkyPosition.cc
===================================================================
--- trunk/MagicSoft/Cosy/gui/MGSkyPosition.cc	(revision 913)
+++ trunk/MagicSoft/Cosy/gui/MGSkyPosition.cc	(revision 918)
@@ -98,5 +98,5 @@
 {
     fText = new TText(105, 105, "");
-    fText->SetFillStyle(4000);  // transparent
+    //fText->SetFillStyle(4000);  // transparent
     fText->SetTextAlign(33);  // right, top
     fText->SetTextColor(10);  // white
@@ -323,6 +323,6 @@
         return;
 
-    cout << "Sun: x=" << x << " y=" << y;
-    cout << "   Zd=" << deg << " Az=" << 360./D2PI*zdaz.Az() << endl;
+    // cout << "Sun: x=" << x << " y=" << y;
+    // cout << "   Zd=" << deg << " Az=" << 360./D2PI*zdaz.Az() << endl;
 
     fSunL[0]->SetX1(x-3.5); fSunL[0]->SetX2(x+3.5);
Index: trunk/MagicSoft/Cosy/gui/MGVelocity.cc
===================================================================
--- trunk/MagicSoft/Cosy/gui/MGVelocity.cc	(revision 913)
+++ trunk/MagicSoft/Cosy/gui/MGVelocity.cc	(revision 918)
@@ -109,4 +109,8 @@
     line.DrawLine(    0, -65*2,    0, 65*2);
 
+    //
+    // Can be replaced by TGaxis axe; in a later root version
+    // than 3.01/06. I talked to Rene
+    //
     TGaxis *axe;
     axe = new TGaxis(-60*2, 0, 60*2, 0,  -2, 2,  304, "+-N");
@@ -179,10 +183,8 @@
 MGVelocity::~MGVelocity()
 {
-    delete fList;
-
     delete fOld;
     delete fAvg;
 
-    cout << "MGVelocity destroyed." << endl;
+    //    cout << "MGVelocity destroyed." << endl;
 }
 
@@ -270,6 +272,6 @@
     //    static int Y = 0xaffe;
 
-    float x = zdaz.Az()*3600.*4;
-    float y = zdaz.Zd()*3600.*4;
+    float x = zdaz.Az()*3600.;
+    float y = zdaz.Zd()*3600.;
 
     int pixx = (int)(x*fScale/fPix);
