Index: trunk/MagicSoft/Mars/macros/tutorials/calendar.rc
===================================================================
--- trunk/MagicSoft/Mars/macros/tutorials/calendar.rc	(revision 7892)
+++ trunk/MagicSoft/Mars/macros/tutorials/calendar.rc	(revision 7893)
@@ -18,10 +18,10 @@
 
 # define descriptions for your images
-01.Text: All File types supported by TASImage are supported
-02.Text: 
-03.Text: 
-04.Text: 
-05.Text: 
-06.Text: 
+01.Text: All File types supported by TASImage are supported.
+02.Text: Please try to use the context menu on the small boxes.
+03.Text: Choose SetDefaultLayout from the context menu.
+04.Text: Play around with th eoptions in the context menu.
+05.Text: Parts of the context menu are sensitive to the mouse position.
+06.Text: To create a postscript file of your calendar change the macro.
 07.Text: 
 08.Text: 
Index: trunk/MagicSoft/Mars/mtools/MCalendar.cc
===================================================================
--- trunk/MagicSoft/Mars/mtools/MCalendar.cc	(revision 7892)
+++ trunk/MagicSoft/Mars/mtools/MCalendar.cc	(revision 7893)
@@ -81,9 +81,14 @@
 //
 //  The contents of each pave in your calendar.
-//      Contents: Date Day Holiday Easter Birthday
-//
-//  You can setup the contents by their names individually. The possible
-//  Style is defined by a TLatex object. For more details see TLatex or
-//  MEnv::GetAttText.
+//      Contents: Date Day Week Holiday Birthday
+//
+//  There are NO predefined content-strings. All the names given here
+//  are completely artificial. You could also call them just A and B.
+//  If you setup them correctly they might still behave like Date and Day.
+//  This also means that you can define as many of them as you want.
+//
+//  You can setup the contents by their names individually (eg. Holiday).
+//  The possible Style is defined by a TLatex object. For more details
+//  see TLatex or MEnv::GetAttText.
 //
 //      To setup the position in the pave use:
@@ -101,6 +106,8 @@
 //          Holiday.Format: %a
 //
-//  Contents for which a format was setup are build using MTime::GetStringFmt.
-//  Contents without a format set are searched in the holiday resource.
+//  Contents for which a format was setup are compiled by using
+//  MTime::GetStringFmt.
+//  Contents without a format set (by eg. Holiday.Format) are searched in
+//  the holiday resource file:
 //
 //      For the 1.1. and 25.12. the setup could be:
@@ -108,10 +115,10 @@
 //          Holiday.12/25: Christmas
 //
-//      If the contents name is "Easter" the search is done relative to Easter:
-//          Easter.-1: Easter Saturday
-//          Easter.0: Easter
-//          Easter.1: Easter Monday
-//
-//  In addition to this you can overwrite the this default for the active
+//      Holidays with respect to Easter are given as
+//          Holiday.-1: Easter Saturday
+//          Holiday.0: Easter
+//          Holiday.1: Easter Monday
+//
+//  In addition to this you can overwrite the default for the active
 //  and/or inactivedays by:
 //     Date.Active.{PaveStyle}
@@ -146,12 +153,18 @@
 //    change the Layout. For more details see section "Resource Files"
 //
-//  void ResetLayout()
-//    Remove everything from the layout
+//  void ResetLayout(num)
+//    Remove everything from the layout. num is the number of default blocks
+//    (corresponding to NumBlocks). A value smaller or equal 0 will leave
+//    the number of block unchanged (which is the default from the
+//    context menu)
 //
 //  void ResetHolidays()
 //    remove all holidays.
 //
-//  void SetDefaultLayout()
-//    set the layout to the default layout
+//  void SetDefaultLayout(num)
+//    set the layout to the default layout. num is the number of displayed
+//    blocks (corresponding to NumBlocks). A value smaller or equal 0 will
+//    leave the number of block unchanged (which is the default from the
+//    context menu)
 //
 //  void SetDefaultHolidays()
@@ -185,5 +198,5 @@
 //  void SetEaster(Float_t FontSize=0.13, Int_t Color=kBlue)
 //    set the current position in the pave to a holiday with name
-//    "Holiday", "Birthday" or "Easter". The holidays are read from the
+//    "Holiday", "Birthday". The holidays are read from the
 //    holiday resource file. For more details see section "Resource files"
 //
@@ -191,5 +204,5 @@
 //  void AddBirthday(const char *text)
 //  void AddEaster(const char *text)
-//    Add a holiday ("Holiday.mm/dd", "Birthday.mm/dd" or "Easter.%d")
+//    Add a holiday ("Holiday.mm/dd", "Birthday.mm/dd" or "Holiday.%d")
 //    for the current date (for easter the offset to easter is used instead)
 //    to the holiday resources.
@@ -239,5 +252,7 @@
 
 #include <TStyle.h>
+#include <TArrow.h>
 #include <TLatex.h>
+#include <TMarker.h>
 #include <TArrayD.h>
 #include <TCanvas.h>
@@ -246,4 +261,5 @@
 #include <TASImage.h>
 #include <TPaveText.h>
+#include <THashList.h>
 
 #include "MEnv.h"
@@ -359,5 +375,5 @@
     def.SetLineStyle(kSolid);
     def.SetLineColor(kBlack);
-    def.SetLineWidth(1);
+    def.SetLineWidth(0);
     def.SetFillColor(18);
     def.SetFillStyle(1001);
@@ -486,4 +502,5 @@
 
     env.SetValue("Orientation",          fOrientation);
+    env.SetValue("Rotation",             fRotation);
 
     env.SetValue("Moon.Graf.Align",      fMoonAlignGraf);
@@ -532,5 +549,5 @@
     const TString name = fname ? fname : fEnv->GetName();
 
-    ResetLayout();
+    ResetLayout(2);
 
     delete fEnv;
@@ -541,4 +558,5 @@
 
     fOrientation   = fEnv->GetValue("Orientation",          fOrientation);
+    fRotation      = fEnv->GetValue("Rotation",             fOrientation);
 
     fMoonAlignGraf = fEnv->GetValue("Moon.Graf.Align",      fMoonAlignGraf);
@@ -576,10 +594,17 @@
 // Reset the layout (remove everything)
 //
-void MCalendar::ResetLayout()
+// num is the number of default blocks (corresponding to NumBlocks).
+// A value smaller or equal 0 will leave the number of block unchanged
+// (which is the default)
+//
+void MCalendar::ResetLayout(Int_t num)
 {
     fOrientation   = kFALSE;
+    fRotation      = kFALSE;
 
     fFirstDay      = 1;
-    fNumBlocks     = 2;
+
+    if (num>0)
+        fNumBlocks = num;
 
     fMoonAlignGraf = 0;
@@ -621,5 +646,5 @@
     ResetHolidays();
 
-    fEnvHolidays->SetValue("Easter.0",      "Easter");
+    fEnvHolidays->SetValue("Holiday.0",     "Easter");
     fEnvHolidays->SetValue("Holiday.01/01", "New Year");
     fEnvHolidays->SetValue("Holiday.12/25", "Christmas");
@@ -631,37 +656,47 @@
 // Set the layout to the default layout
 //
-void MCalendar::SetDefaultLayout()
-{
-    ResetLayout();
+// num is the number of default blocks (corresponding to NumBlocks).
+// A value smaller or equal 0 will leave the number of block unchanged
+// (which is the default)
+//
+void MCalendar::SetDefaultLayout(Int_t num)
+{
+    ResetLayout(num);
 
     fMoonAlignGraf = 11;
     fMoonAlignText = 11;
 
-    fEnv->SetValue("Contents", "Day Date Holiday Birthday Easter");
-
-    fEnv->SetValue("Day.TextAlign",      "top left");
-    fEnv->SetValue("Day.Format",         "%e");
-
-    fEnv->SetValue("Date.TextAlign",     "bottom right");
-    fEnv->SetValue("Date.Format",        "%a");
-
-    fEnv->SetValue("Holiday.TextAlign",  "center");
-    fEnv->SetValue("Holiday.TextSize",   0.13);
-    fEnv->SetValue("Holiday.TextColor",  kBlue);
-
-    fEnv->SetValue("Birthday.TextAlign", "center");
-    fEnv->SetValue("Birthday.TextSize",  0.13);
-    fEnv->SetValue("Birthday.TextColor", kBlue);
-
-    fEnv->SetValue("Easter.TextAlign",   "center");
-    fEnv->SetValue("Easter.TextSize",    0.13);
-    fEnv->SetValue("Easter.TextColor",   kBlue);
+    fEnv->SetValue("Contents", "Day Date Week Holiday Birthday");
+
+    fEnv->SetValue("Day.TextAlign",           "top left");
+    fEnv->SetValue("Day.Format",              "%e");
+
+    fEnv->SetValue("Date.TextAlign",          "bottom right");
+    fEnv->SetValue("Date.Format",             "%a");
+
+    fEnv->SetValue("Week.TextAlign",          "top right");
+    fEnv->SetValue("Week.Format",             "KW%V");
+    fEnv->SetValue("Week.TextSize",           0.1);
+    fEnv->SetValue("Week.Restriction",        1);
+    fEnv->SetValue("Week.Active.TextColor",   "Grey8");
+
+    fEnv->SetValue("Holiday.TextAlign",       "center");
+    fEnv->SetValue("Holiday.TextSize",        0.13);
+    fEnv->SetValue("Holiday.TextColor",       kBlue);
+
+    fEnv->SetValue("Birthday.TextAlign",      "center");
+    fEnv->SetValue("Birthday.TextSize",       0.13);
+    fEnv->SetValue("Birthday.TextColor",      kBlue);
+
+    //    fEnv->SetValue("Easter.TextAlign",        "center");
+    //    fEnv->SetValue("Easter.TextSize",         0.13);
+    //    fEnv->SetValue("Easter.TextColor",        kBlue);
 
     fEnv->SetValue("Date.Active.0.TextColor", kRed);
 
-    fEnv->SetValue("Date.Active.TextFont",    22);
-    fEnv->SetValue("Day.Active.TextFont",     22);
-    fEnv->SetValue("Date.Inactive.TextFont", 132);
-    fEnv->SetValue("Day.Inactive.TextFont",  132);
+    fEnv->SetValue("Date.Active.TextFont",     22);
+    fEnv->SetValue("Day.Active.TextFont",      22);
+    fEnv->SetValue("Date.Inactive.TextFont",  132);
+    fEnv->SetValue("Day.Inactive.TextFont",   132);
 
     // fEnv->SetValue("Date.Inactive.LineStyle", kDashed);
@@ -683,5 +718,5 @@
     //fUpdate = kFALSE;
 
-    SetDefaultLayout();
+    SetDefaultLayout(2);
     SetDefaultHolidays();
 
@@ -731,9 +766,9 @@
 Int_t MCalendar::Rotate(Int_t align, Bool_t fwd) const
 {
-    if (!fOrientation)
+    if (fOrientation==fRotation)
         return align;
 
-    static const Int_t a[4] = { 11, 31, 33, 13 };
-    static const Int_t b[4] = { 11, 13, 33, 31 };
+    static const Int_t b[4] = { 11, 31, 33, 13 };
+    static const Int_t a[4] = { 11, 13, 33, 31 };
 
     const Int_t *c = fwd ? a :b;
@@ -780,6 +815,6 @@
     */
 
-    const Double_t scale = fOrientation ? x[1]-x[0] : y[1]-y[0];
-    const Double_t phi   = fOrientation ? 90 : 0;
+    const Double_t scale = fOrientation            ? x[1]-x[0] : y[1]-y[0];
+    const Double_t phi   = fOrientation!=fRotation ? -90 : 0;
 
     Convert2Latex(str);
@@ -787,4 +822,28 @@
     tex.SetTextAlign(align);
     tex.PaintLatex(p[0], p[1], phi, att.GetTextSize()*scale, str);
+}
+
+//---------------------------------------------------------------------------
+//
+// Paint a clock as a symbol for summer-/wintertime
+//
+void MCalendar::PaintClock(Double_t x[2], Double_t y[2], Double_t r[2], Int_t fill, char dir)
+{
+    Double_t k[2] = { (x[0]+x[1])/2, (y[0]+y[1])/2 };
+
+    TEllipse e(k[0], k[1], r[0]*2.5, r[1]*2.5, 30, 360, 0);
+    e.SetLineColor(kBlack);
+    e.SetLineStyle(kSolid);
+    e.SetFillColor(fill);
+    e.Paint();
+
+    TMarker m;
+    m.SetMarkerStyle(kFullDotSmall);
+    for (int i=2; i<12; i++)
+        m.PaintMarker(k[0]+r[0]*2*cos(TMath::TwoPi()*i/12),
+                      k[1]+r[1]*2*sin(TMath::TwoPi()*i/12));
+
+    TArrow a(k[0]+r[0]*3, k[1], k[0]+r[0]*2.7, k[1]+r[1]*1.5, r[1]/2);
+    a.Paint(dir=='-'?"->":"<-");
 }
 
@@ -796,8 +855,4 @@
 // of the MTime.
 //
-// If the name is "Easter" the format of the resource searched for is
-//   Easter.o
-// while o is the offset from Easter (eg. Easter.-5, Easter.0 or Easter.22)
-//
 TString MCalendar::GetHoliday(const TObject &o, const MTime &tm)
 {
@@ -811,12 +866,35 @@
     TString env(o.GetName());
 
-    const TString post = env=="Easter" ?
-        Form(".%d", (Int_t)tm.GetMjd()-easter) :
-        Form(".%02d/%02d", tm.Month(), tm.Day());
-
-    return fEnvHolidays->GetValue(env+post, "");
-}
-
-//#include <iostream>
+    const TString post1 = Form(".%d", (Int_t)tm.GetMjd()-easter);
+    const TString post2 = Form(".%02d/%02d", tm.Month(), tm.Day());
+
+    TString rc;
+    for (int i=0; i<7; i++)
+    {
+        MTime tx(tm.GetMjd()+i);
+        const TString post3 = Form(".%02d/%02d-%d", tx.Month(), tx.Day(), (7-tm.WeekDay())%7);
+        rc = fEnvHolidays->GetValue(env+post3, rc);
+    }
+
+    rc = fEnvHolidays->GetValue(env+post1, rc);
+    rc = fEnvHolidays->GetValue(env+post2, rc);
+/*
+    if (fLanguage=="de_DE")
+    {
+        MTime t;
+        t.Set(fYear, 5, 14);
+        t.SetMjd(t.GetMjd()-t.WeekDay());
+
+        if ((Int_t)t.GetMjd() == easter + 49)
+            t.SetMjd(t.GetMjd()-7);
+
+        if ((Int_t)tm.GetMjd()==(Int_t)t.GetMjd())
+            return "Muttertag";
+    }
+
+  */
+    return rc;
+}
+
 void MCalendar::Paint(Option_t *o)
 {
@@ -830,5 +908,5 @@
 
     // How should this be done?
-    fOrientation = gPad->PixeltoX(1)>-gPad->PixeltoY(1);
+    //fOrientation = gPad->PixeltoX(1)>-gPad->PixeltoY(1);
 
     MTime t;
@@ -870,4 +948,9 @@
         pave.Paint(pave.GetOption());
 
+        Double_t r[2] = {
+            fMoonRadius*ratio[0],
+            fMoonRadius*ratio[1]
+        };
+
         // ---------- Paint Text ----------
         const TString contents = fEnv->GetValue("Contents", "");
@@ -881,11 +964,20 @@
             latex.SetName(o->GetName());
 
+            const TString res = fEnv->GetValue(Form("%s.Restriction", o->GetName()), "0123456");
+            if (res.First('0'+tm.WeekDay())<0)
+                continue;
+
             GetLatex(latex, active, day);
 
             const TString text = GetHoliday(latex, tm);
+
+            if (text=="T+" || text=="T-")
+            {
+                PaintClock(x, y, r, pave.GetFillColor(), text[1]);
+                continue;
+            }
 
             if (!text.IsNull())
                 PaintLatex(latex, latex.GetTextAlign(), x, y, ratio, text);
-
         }
 
@@ -893,8 +985,8 @@
 
         // ---------- Paint Moon Phase -----------
-        Double_t r[2] = {
-            fMoonRadius*ratio[0],
-            fMoonRadius*ratio[1]
-        };
+        //Double_t r[2] = {
+        //    fMoonRadius*ratio[0],
+        //    fMoonRadius*ratio[1]
+        //};
         Double_t m[2] = {
             fMarginX*ratio[0] + r[0],
@@ -909,7 +1001,8 @@
         // location, the text is a discrete number and it is
         // switched to continous.
-        const Float_t phi  = fOrientation ? 90 : 0;
-        const Int_t   dx   = fOrientation;
-        const Int_t   dy   = (fOrientation+1)%2;
+        const Bool_t  rot  = fOrientation!=fRotation;
+        const Float_t phi  = rot ? -90 : 0;
+        const Int_t   dx   = rot;
+        const Int_t   dy   = (rot+1)%2;
         const Bool_t  cont = fMoonTextType==0 || fMoonTextCont;
         if (fMoonAlignGraf)
@@ -918,5 +1011,5 @@
 
             if (fMoonAlignGraf==fMoonAlignText && cont && fMoonAlignGraf==22)
-                p[dy] += m[dy]/2;
+                p[dy] += rot ? -m[dy]/2 : m[dy]/2;
 
             TEllipse e(p[0], p[1], r[0], r[1], -90+phi, 90+phi, 0);
@@ -937,5 +1030,5 @@
             const Double_t R  = tm.GetMoonPhase()<0.5 ? 1-tm.GetMoonPhase() : tm.GetMoonPhase();
             const Double_t r0 = 1.0-TMath::Sqrt(2.0-2.0*R);
-            if (fOrientation)
+            if (rot)
                 e.SetR2(r[1]*r0);  // bug in PaintEllipse!
             else
@@ -957,4 +1050,10 @@
             if (fMoonAlignGraf==fMoonAlignText && cont)
             {
+                if (rot)
+                {
+                    m[dx] = -m[dx];
+                    m[dy] = -m[dy];
+                }
+
                 switch (fMoonAlignGraf/10)
                 {
@@ -998,6 +1097,17 @@
 Bool_t MCalendar::GetBox(Int_t n, Double_t x[2], Double_t y[2], Double_t *ratio)
 {
-    const Int_t   maxrows = 28/(7*fNumBlocks) + 1;
+    //const Int_t   maxrows = 6; //28/(7*fNumBlocks) + 1;
     const Float_t addrows = 0;
+
+    Int_t maxrows;
+    switch(fNumBlocks)
+    {
+    case 0:
+    case 1: maxrows=6; break;
+    case 2: maxrows=3; break;
+    case 3: maxrows=2; break;
+    case 4: maxrows=2; break;
+    default: maxrows=1; break;
+    }
 
     const Float_t ratio0  = -gPad->PixeltoX(1)/gPad->PixeltoY(1);
@@ -1011,6 +1121,6 @@
     const Float_t  blockx = fOrientation ? fBlockSpace/ratio0 : fBlockSpace*ratio0;
 
-    const Float_t  w      = (0.98-cellx*(7*fNumBlocks-1)-(fNumBlocks-1)*blockx)/(fNumBlocks*7);
-    const Float_t  h      = (0.98-celly*(maxrows-1)/*-blockspacey*/)/(maxrows+addrows);
+    const Float_t  w      = (0.99-cellx*(7*fNumBlocks-1)-(fNumBlocks-1)*blockx)/(fNumBlocks*7);
+    const Float_t  h      = (0.99-celly*(maxrows-1)/*-blockspacey*/)/(maxrows+addrows);
 
 
@@ -1020,5 +1130,5 @@
     const Int_t    col    = ix/7;
 
-    const Double_t p0     = 0.01 - col*(cellx - blockx);
+    const Double_t p0     = 0.005 - col*(cellx - blockx);
 
     TArrayD a(2), b(2);
@@ -1027,6 +1137,6 @@
     a[1] =  p0   + ix*(cellx + w) + w;
 
-    b[0] =  0.99 - iy*(celly + h) - h;
-    b[1] =  0.99 - iy*(celly + h);
+    b[0] =  0.995 - iy*(celly + h) - h;
+    b[1] =  0.995 - iy*(celly + h);
 
     if (ratio)
@@ -1038,6 +1148,6 @@
     if (fOrientation)
     {
-        x[0] = 1-b[1];
-        x[1] = 1-b[0];
+        x[0] = b[0];
+        x[1] = b[1];
         y[0] = a[0];
         y[1] = a[1];
@@ -1050,4 +1160,19 @@
         y[1] = b[1];
     }
+
+    if (fOrientation)
+    {
+        TArrayD d(2,y);
+        y[0] = 1-d[1];
+        y[1] = 1-d[0];
+    }
+
+    if (fRotation)
+    {
+        TArrayD d(2,x);
+        x[0] = 1-d[1];
+        x[1] = 1-d[0];
+    }
+
     return ix==0 && iy>0;
 }
@@ -1198,5 +1323,5 @@
     const Int_t easter = (Int_t)MTime::GetEaster(fYear).GetMjd();
 
-    const TString str = Form("Easter.%d", (Int_t)t.GetMjd()-easter);
+    const TString str = Form("Holiday.%d", (Int_t)t.GetMjd()-easter);
 
     fEnvHolidays->SetValue(str, text);
@@ -1247,7 +1372,7 @@
 // DrawImage cd()'s to the new pad.
 //
-TASImage *MCalendar::DrawImage(const TASImage &img, Float_t x1, Float_t y1, Float_t x2, Float_t y2) const
-{
-    TPad *pad=new TPad("Img", "Image", x1, y1,x2, y2);
+TASImage *MCalendar::DrawImage(const TASImage &img, Float_t x1, Float_t y1, Float_t x2, Float_t y2, Bool_t rot) const
+{
+    TPad *pad=new TPad("Img", "Image", x1, y1, x2, y2);
     pad->SetBorderMode(0);
     pad->SetFillColor(gPad?gPad->GetFillColor():kWhite);
@@ -1269,13 +1394,25 @@
     pad->Update();
 
-    const Int_t w = clone->GetScaledWidth();
-    const Int_t h = clone->GetScaledHeight();
+    const Int_t wi = clone->GetScaledWidth();
+    const Int_t hi = clone->GetScaledHeight();
 
     TCanvas *c = pad->GetCanvas();
 
-    const Float_t ml = (1-c->PixeltoX(w))/2;
-    const Float_t mb = (1+c->PixeltoY(h))/2;
-
-    pad->SetPad(ml, 2*mb, 1-ml, 1);
+    const Float_t x = (x1+x2)/2;
+    const Float_t y = (y1+y2)/2;
+
+    Float_t w = TMath::Abs(x2-x1)/2;
+    Float_t h = TMath::Abs(y2-y1)/2;
+
+    const Float_t ri = TMath::Abs(c->PixeltoX(wi)/c->PixeltoY(hi));
+    const Float_t rp = TMath::Abs(w/h);
+
+    if (ri>rp)
+        h = w/ri;
+    else
+        w = h*ri;
+
+    pad->SetPad(x-w, y-h, x+w, y+h);
+    pad->SetFixedAspectRatio();
 
     return clone;
@@ -1311,5 +1448,5 @@
 // of deleting it)
 //
-TASImage *MCalendar::GetImage(TEnv *env)
+TASImage *MCalendar::GetImage(TEnv *env, const char *pwd)
 {
     if (!env)
@@ -1322,15 +1459,17 @@
     ConvertUTF8(fStrMonth,  kFALSE);
 
+    const TString path(pwd);
+
     TString file = env->GetValue(fStrMonth, "");
     if (!file.Strip(TString::kBoth).IsNull())
-        return ReturnFile(file);
+        return ReturnFile(path+file);
 
     file = env->GetValue(fStrMonth3, "");
     if (!file.Strip(TString::kBoth).IsNull())
-        return ReturnFile(file);
+        return ReturnFile(path+file);
 
     file = env->GetValue(Form("%02d", fMonth), "");
     if (!file.Strip(TString::kBoth).IsNull())
-        return ReturnFile(file);
+        return ReturnFile(path+file);
 
     return NULL;
@@ -1401,5 +1540,5 @@
 
 TASImage *MCalendar::DrawTTF(Float_t x1, Float_t x2, Float_t y1, Float_t y2,
-                             const char *text, Int_t size, const char *font)
+                             const char *text, Float_t sz, const char *font)
 {
     const char *file = GetTTFontPath(font);
@@ -1407,20 +1546,86 @@
         return NULL;
 
+    const Int_t size = TMath::Nint(sz*941);
+
     TTF::SetTextFont(file);
+    TTF::SetTextSize(size);
 
     delete file;
 
-    TTF::SetRotationMatrix(0);
-    TTF::SetTextSize(size);
-    TTF::PrepareString(text);
-    TTF::LayoutGlyphs();
+    UInt_t wi, hi;;
+    TTF::GetTextExtent(wi, hi, (char*)text);
 
     const FT_BBox &box = TTF::GetBox();
-
-    TASImage img(3*box.xMax/2, 3*box.yMax/2);
+    //cout << hi-box.yMax << " " <<   wi << " "<< (float)size/hi << endl;
+    //wi = wi;//TMath::Nint((float)wi*(size+hi-box.yMax)/size);
+    //wi += TMath::Nint(((float)size/hi-1)*wi);
+
+    const UInt_t add = size-box.yMax;
+
+    wi += size*(hi+add)/hi;
+    hi += add;
+    // wi += size*(hi+size-box.yMax)/hi;
+    // hi += size-box.yMax;
+
+    TASImage img(wi, hi);
     img.FillRectangle();
+
+    Double_t x = (x1+x2)/2;
+    Double_t y = (y1+y2)/2;
+
+    Double_t w = gPad->PixeltoX(wi)/2;
+    Double_t h = gPad->PixeltoY(hi)/2;
 
     // gROOT->GetColor(kBlack)->AsHexString()
     DrawDate(img, 0, 0, text, size, "#00000000", font);
-    return DrawImage(img, x1, y1, x2, y2);
-}
+    return DrawImage(img, x-w, y-h, x+w, y+h);
+}
+
+/*
+void MCalendar::Update()
+{
+    cout << "Update" << endl;
+    fUpdate=kTRUE;
+}
+
+void MCalendar::Selected(TVirtualPad *pad,TObject *o,Int_t event)
+{
+    if (event==kButton1Down && pad)
+    {
+        pad->cd();
+        fAlign = GetAlign();
+        fActive = GetDate().Month()==fMonth;
+        fEnv->GetAttLine(fActive?"Date.Active":"Date.Inactive", *this);
+        fEnv->GetAttLine(Form(fActive?"Date.Active.%d":"Date.Inactive.%d", fDay), *this);
+    }
+
+    cout << "SetModel " << gPad << " " << pad << " " << o << " " << event << endl;
+    //Picked(fSelectedPad, fSelected, fEvent);  // emit signal
+
+}
+
+void MCalendar::SetAttributes()
+{
+    if (!gPad)
+        return;
+
+    TAttLine::SetLineAttributes();
+
+    cout << "gPad " << gPad << endl;
+
+    fAlign  = GetAlign();
+    fActive = GetDate().Month()==fMonth;
+    fDay    = GetDate().WeekDay();
+
+    fEnv->GetAttLine(fActive?"Date.Active":"Date.Inactive", *this);
+    fEnv->GetAttLine(Form(fActive?"Date.Active.%d":"Date.Inactive.%d", fDay), *this);
+
+    TQObject::Connect("TCanvas", "Selected(TVirtualPad*,TObject*,Int_t)",
+                      "MCalendar", this, "Selected(TVirtualPad*,TObject*,Int_t)");
+
+    TQObject::Connect("TGedPatternSelect", "PatternSelected(Style_t)", "MCalendar", this, "Update()");
+    TQObject::Connect("TGColorSelect",     "ColorSelected(Pixel_t)",   "MCalendar", this, "Update()");
+    TQObject::Connect("TGListBox",         "Selected(Int_t)",          "MCalendar", this, "Update()");
+}
+*/
+
Index: trunk/MagicSoft/Mars/mtools/MCalendar.h
===================================================================
--- trunk/MagicSoft/Mars/mtools/MCalendar.h	(revision 7892)
+++ trunk/MagicSoft/Mars/mtools/MCalendar.h	(revision 7893)
@@ -14,4 +14,10 @@
 #include <Gtypes.h>
 #endif
+
+/*
+#include <TAttLine.h>
+#include <TAttFill.h>
+#include <TAttText.h>
+*/
 
 class TEnv;
@@ -26,11 +32,25 @@
 class MTime;
 
-class MCalendar : public TObject
+class MCalendar : public TObject//, public TAttLine, public TAttText, public TAttFill
 {
 private:
+    /*
+    enum {
+        kMoonPhase,
+        kMoonPeriod,
+        kMagicPeriod
+    };*/
+
+    /*
+    Int_t  fAlign;
+    Bool_t fActive;
+    Bool_t fUpdate;
+    Int_t  fDay;
+    */
     MEnv    *fEnv;
     MEnv    *fEnvHolidays;
 
     Bool_t   fOrientation;
+    Bool_t   fRotation;
 
     Int_t    fYear;
@@ -78,4 +98,5 @@
     // Paint text
     void PaintLatex(TAttText &att, Int_t align, Double_t x[2], Double_t y[2], Double_t ratio[2], /*Double_t height,*/ TString str);
+    void PaintClock(Double_t x[2], Double_t y[2], Double_t r[2], Int_t fill, char dir);
 
     // GUI interactions
@@ -105,4 +126,6 @@
     Float_t     GetMoonRadius() const { return fMoonRadius; }
     TString     GetStringFmt(const char *fmt="%B", Int_t day=1, Int_t h=12, Int_t m=0, Int_t s=0) const;
+    Bool_t      IsRotated() const { return fRotation; }
+    Bool_t      IsVertical() const { return fOrientation; }
 
 
@@ -113,8 +136,10 @@
     void SetLayout(Byte_t NumberOfBlocks, Double_t MarginX, Double_t MarginY, Double_t CellSpace, Double_t BlockSpace) { fNumBlocks=NumberOfBlocks, fMarginX=MarginX; fMarginY=MarginY; fCellSpace=CellSpace; fBlockSpace=BlockSpace; } //*MENU* *ARGS={NumberOfBlocks=>fNumBlocks,MarginX=>fMarginX,MarginY=>fMarginY,CellSpace=>fCellSpace,BlockSpace=>fBlockSpace}
 
-    void ResetLayout();   //*MENU
+    void ResetLayout(Int_t num);
+    void ResetLayout() { ResetLayout(-1); } //*MENU
     void ResetHolidays(); //*MENU
 
-    void SetDefaultLayout();   //*MENU
+    void SetDefaultLayout(Int_t num);
+    void SetDefaultLayout() { SetDefaultLayout(-1); } //*MENU
     void SetDefaultHolidays(); //*MENU
 
@@ -141,4 +166,6 @@
 
     //    void ToggleOrientation() { fOrientation = !fOrientation; } //*MENU
+    void SetRotated(Bool_t b=kTRUE) { fRotation = b; } // *TOGGLE* *GETTER=IsRotated
+    void SetVertical(Bool_t b=kTRUE) { fOrientation = b; } // *TOGGLE* *GETTER=IsVertical
 
     void PrintEnv() const; //*MENU
@@ -146,11 +173,10 @@
     void RemoveEnv(const char *VariableName) const;//*MENU
 
-
     void SetMoonGraf(Int_t Align, Float_t Radius) { fMoonAlignGraf=Align; fMoonRadius=Radius; } //*MENU* *ARGS={Align>=fMoonAlignGraf,Radius=>fMoonRadius}
     void SetMoonText(Int_t Align, Int_t Type, Int_t Continous) { fMoonAlignText=Align; fMoonTextType=Type; fMoonTextCont=Continous; } //*MENU* *ARGS={Align>=fMoonAlignText,Type=>fMoonTextType,Continous=>fMoonTextCont}
 
     // Calendar sheet interface
-    TASImage *DrawImage(const TASImage &img, Float_t x1, Float_t y1, Float_t x2, Float_t y2) const;
-    TASImage *GetImage(TEnv *env=NULL);
+    TASImage *DrawImage(const TASImage &img, Float_t x1, Float_t y1, Float_t x2, Float_t y2, Bool_t rot=kFALSE) const;
+    TASImage *GetImage(TEnv *env=NULL, const char *path="");
     void      DrawLatex(Float_t x, Float_t y, const char *text, const TAttText &att);
     void      DrawDate(Float_t x, Float_t y, const char *text, const TAttText &att)
@@ -168,7 +194,7 @@
     }
     TASImage *DrawTTF(Float_t x1, Float_t x2, Float_t y1, Float_t y2,
-                      const char *text, Int_t size, const char *font);
+                      const char *text, Float_t size, const char *font);
     TASImage *DrawTTFDate(Float_t x1, Float_t x2, Float_t y1, Float_t y2,
-                          const char *text, Int_t size, const char *font)
+                          const char *text, Float_t size, const char *font)
     {
         return DrawTTF(x1, y1, x2, y2, GetStringFmt(text), size, font);
@@ -183,4 +209,14 @@
     void Paint(Option_t *o="");
 
+    /*
+     void Update();
+     void SetLineAttributes() {}
+     void SetFillAttributes() {}
+     void SetTextAttributes() {}
+     void SetTextAngle(Float_t) {}
+     void Selected(TVirtualPad*,TObject*,Int_t);
+     */
+     //void SetAttributes(); //*MENU
+
     ClassDef(MCalendar, 1)
 };
