Index: /trunk/MagicSoft/Mars/Changelog
===================================================================
--- /trunk/MagicSoft/Mars/Changelog	(revision 2086)
+++ /trunk/MagicSoft/Mars/Changelog	(revision 2087)
@@ -1,3 +1,16 @@
                                                  -*-*- END OF LINE -*-*-
+
+ 2003/05/07: Thomas Bretz
+
+   * mmain/Makefile, mmain/MainLinkDef.h:
+     - added MSearch
+     
+   * mmain/MSearch.[h,cc]:
+     - added
+
+   * mmmain/MStatusDisplay.[h,cc]:
+     - implemented Search
+
+
 
  2003/05/07: Abelardo Moralejo
@@ -5,4 +18,6 @@
    * mranforest/Makefile
      - fixed typo.
+
+
 
  2003/05/06: Abelardo Moralejo
@@ -23,4 +38,6 @@
        events, including non-triggers (while we usually run over files
        containing only triggers).
+
+
 
  2003/05/06: Thomas Bretz
Index: /trunk/MagicSoft/Mars/mmain/MSearch.cc
===================================================================
--- /trunk/MagicSoft/Mars/mmain/MSearch.cc	(revision 2087)
+++ /trunk/MagicSoft/Mars/mmain/MSearch.cc	(revision 2087)
@@ -0,0 +1,210 @@
+/* ======================================================================== *\
+!
+! *
+! * This file is part of MARS, the MAGIC Analysis and Reconstruction
+! * Software. It is distributed to you in the hope that it can be a useful
+! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
+! * It is distributed WITHOUT ANY WARRANTY.
+! *
+! * Permission to use, copy, modify and distribute this software and its
+! * documentation for any purpose is hereby granted without fee,
+! * provided that the above copyright notice appear in all copies and
+! * that both that copyright notice and this permission notice appear
+! * in supporting documentation. It is provided "as is" without express
+! * or implied warranty.
+! *
+!
+!
+!   Author(s): Thomas Bretz, 9/2002 <mailto:tbretz@astro-uni-wuerzburg.de>
+!
+!   Copyright: MAGIC Software Development, 2000-2003
+!
+!
+\* ======================================================================== */
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// MSearch
+//
+// Simple search dialog (usefull for TGTextViews)
+//
+// Sends: kC_USER, KS_START, mp1, txt
+//
+//   with mp1: bit0 on=case sensitive
+//             bit1 on=backward
+//        mp2: char* pointing to the text to search for
+//
+// WARNING: Do not store mp2, immeditaly copy the text to a local
+//          location!
+//
+/////////////////////////////////////////////////////////////////////////////
+#include "MSearch.h"
+
+#include <TSystem.h>      // gSystem
+#include <TGLabel.h>      // TGLabel
+#include <TGButton.h>     // TGButton
+#include <TGTextEntry.h>  // TGTextEntry
+
+#include "MGList.h"
+
+ClassImp(MSearch);
+
+enum
+{
+    kSearchText, kCase, kDirection, kSearch, kCancel
+};
+
+// --------------------------------------------------------------------------
+//
+// Default constructor. w is the window which will receive the message.
+// Id is currently useless.
+//
+MSearch::MSearch(const TGWindow *w, Int_t id) : TGTransientFrame(gClient->GetRoot(), gClient->GetRoot(), 1, 1), TGWidget(id)
+{
+    Associate(w);
+
+    fList = new MGList;
+    fList->SetOwner();
+
+    // set the smallest and biggest size of the Main frame
+    SetWMSizeHints(320, 110, 250, 50, 0, 0);
+    Move(rand()%100+50, rand()%100+50);
+
+    // -------------------------------------------------------------
+
+    TGLayoutHints *lay4=new TGLayoutHints(kLHintsNormal|kLHintsExpandX);
+    TGLayoutHints *lay0=new TGLayoutHints(kLHintsNormal|kLHintsExpandX, 4, 8, 4);
+    TGLayoutHints *lay1=new TGLayoutHints(kLHintsNormal,  6, 4, 8);
+    TGLayoutHints *lay2=new TGLayoutHints(kLHintsNormal, 69, 4, 4, 4);
+    TGLayoutHints *lay3=new TGLayoutHints(kLHintsNormal, 69, 4, 4, 4);
+    TGLayoutHints *lay5=new TGLayoutHints(kLHintsNormal,  5, 5, 5);
+    TGLayoutHints *lay7=new TGLayoutHints(kLHintsCenterX);
+
+    // -------------------------------------------------------------
+    //  Create Widgets
+    // -------------------------------------------------------------
+
+    TGHorizontalFrame  *f = new TGHorizontalFrame(this, 1, 1);
+    TGLabel        *label = new TGLabel(this, "Find Text:");
+    TGTextEntry    *entry = new TGTextEntry(f, "", kSearchText);
+    TGCheckButton   *box1 = new TGCheckButton(this, "Match upper/lower case", kCase);
+    TGCheckButton   *box2 = new TGCheckButton(this, "Search backward", kDirection);
+    TGHorizontalFrame *f2 = new TGHorizontalFrame(this, 1, 1);
+    TGHorizontalFrame *f3 = new TGHorizontalFrame(f2, 1, 1);
+    TGTextButton    *txt1 = new TGTextButton(f3, "Search", kSearch);
+    TGTextButton    *txt2 = new TGTextButton(f3, "Cancel", kCancel);
+
+    txt1->Associate(this);
+    txt2->Associate(this);
+
+    // -------------------------------------------------------------
+    //  Layout the widgets in the frame
+    // -------------------------------------------------------------
+
+    AddFrame(f, lay4);
+    f->AddFrame(label, lay1);
+    f->AddFrame(entry, lay0);
+    AddFrame(box1, lay2);
+    AddFrame(box2, lay3);
+    AddFrame(f2, lay4);
+    f2->AddFrame(f3, lay7);
+    f3->AddFrame(txt1, lay5);
+    f3->AddFrame(txt2, lay5);
+
+    // -------------------------------------------------------------
+
+    entry->Associate(this);
+    txt1->Associate(this);
+    txt1->Associate(this);
+
+    // -------------------------------------------------------------
+
+    fList->Add(lay0);
+    fList->Add(lay1);
+    fList->Add(lay2);
+    fList->Add(lay3);
+    fList->Add(lay4);
+    fList->Add(lay5);
+    fList->Add(lay7);
+    fList->Add(f);
+    fList->Add(f2);
+    fList->Add(f3);
+    fList->Add(label);
+    fList->Add(entry);
+    fList->Add(box1);
+    fList->Add(box2);
+    fList->Add(txt1);
+    fList->Add(txt2);
+
+    // -------------------------------------------------------------
+
+    Layout();
+
+    MapSubwindows();
+
+    SetWindowName("Search in Text");
+    SetIconName("Search");
+
+    MapWindow();
+}
+
+// --------------------------------------------------------------------------
+//
+// Destruct the window with all its tiles and widgets.
+//
+MSearch::~MSearch()
+{
+    delete fList;
+}
+
+// --------------------------------------------------------------------------
+//
+// Send the search message to the associated TGWindow.
+// See class description.
+//
+Bool_t MSearch::SendSearch()
+{
+    if (!fMsgWindow)
+        return kTRUE;
+
+    const TGCheckButton &b1 = *(TGCheckButton*)fList->FindWidget(kCase);
+    const TGCheckButton &b2 = *(TGCheckButton*)fList->FindWidget(kDirection);
+    const TGTextEntry   &e  = *(TGTextEntry*)  fList->FindWidget(kSearchText);
+
+    const Long_t msg = MK_MSG(kC_USER, (EWidgetMessageTypes)kS_START);
+    const Long_t mp1 = (b1.GetState()<<1) | b2.GetState();
+    const Long_t mp2 = (Long_t)e.GetText();
+
+    SendMessage(fMsgWindow, msg, mp1, mp2);
+
+    return kTRUE;
+}
+
+// --------------------------------------------------------------------------
+//
+//  Process messages from the widgets.
+//
+Bool_t MSearch::ProcessMessage(Long_t msg, Long_t mp1, Long_t mp2)
+{
+    // Can be found in WidgetMessageTypes.h
+    switch (GET_MSG(msg))
+    {
+    case kC_COMMAND:
+        switch (GET_SUBMSG(msg))
+        {
+        case kCM_BUTTON:
+            switch (mp1)
+            {
+            case kSearch:
+                return SendSearch();
+            case kCancel:
+                delete this;
+                return kTRUE;
+            }
+            return kTRUE;
+
+        }
+        return kTRUE;
+    }
+    return kTRUE;
+}
Index: /trunk/MagicSoft/Mars/mmain/MSearch.h
===================================================================
--- /trunk/MagicSoft/Mars/mmain/MSearch.h	(revision 2087)
+++ /trunk/MagicSoft/Mars/mmain/MSearch.h	(revision 2087)
@@ -0,0 +1,41 @@
+#ifndef MARS_MSearch
+#define MARS_MSearch
+
+#ifndef MARS_MAGIC
+#include "MAGIC.h"
+#endif
+
+#ifndef ROOT_TGFrame
+#include <TGFrame.h>
+#endif
+
+#ifndef ROOT_TGWidget
+#include <TGWidget.h>
+#endif
+
+enum EMarsWidgetMessageTypes {
+    kS_START = 1
+};
+
+class MGList;
+
+class MSearch : public TGTransientFrame, public TGWidget
+{
+private:
+    MGList *fList;
+
+    Bool_t SendSearch();
+    void CloseWindow() { delete this; }
+
+public:
+    MSearch(const TGWindow *w, Int_t id=-1);
+    virtual ~MSearch();
+
+    Bool_t ProcessMessage(Long_t msg, Long_t mp1, Long_t mp2);
+
+    ClassDef(MSearch, 0)   // A simple progress bar window for the Eventloop
+};
+
+#endif
+
+
Index: /trunk/MagicSoft/Mars/mmain/MStatusDisplay.cc
===================================================================
--- /trunk/MagicSoft/Mars/mmain/MStatusDisplay.cc	(revision 2086)
+++ /trunk/MagicSoft/Mars/mmain/MStatusDisplay.cc	(revision 2087)
@@ -90,4 +90,5 @@
 #include "MGList.h"               // MGList
 #include "MGMenu.h"               // MGMenu, TGMenu
+#include "MSearch.h"              // MSearch
 #include "MParContainer.h"        // MParContainer::GetDescriptor
 
@@ -96,4 +97,65 @@
 
 ClassImp(MStatusDisplay);
+
+// ------------ Workaround for a non working TGTextView::Search -------------
+class MGTextView : public TGTextView
+{
+public:
+    MGTextView(const TGWindow *parent, UInt_t w, UInt_t h, Int_t id = -1,
+               UInt_t sboptions = 0, ULong_t back = GetWhitePixel()) :
+    TGTextView(parent, w, h, id, sboptions, back) {}
+    MGTextView(const TGWindow *parent, UInt_t w, UInt_t h, TGText *text,
+               Int_t id = -1, UInt_t sboptions = 0, ULong_t back = GetWhitePixel()) :
+    TGTextView(parent, w, h, text, id, sboptions, back) {}
+    MGTextView(const TGWindow *parent, UInt_t w, UInt_t h, const char *string,
+               Int_t id = -1, UInt_t sboptions = 0, ULong_t back = GetWhitePixel()) :
+    TGTextView(parent, w, h, string, id, sboptions, back) {}
+
+    void Mark(Long_t xPos, Long_t yPos) { TGTextView::Mark(xPos, yPos); }
+    void UnMark()                       { TGTextView::UnMark(); }
+
+    Bool_t Search(const char *string, Bool_t direction, Bool_t caseSensitive)
+    {
+        // Taken from TGTextView::Search and modified.
+
+        TGLongPosition pos, pos2;
+        pos2.fX = pos2.fY = 0;
+        if (fIsMarked) {
+            if (!direction)
+            {
+                pos2.fX = fMarkedStart.fX;
+                pos2.fY = fMarkedStart.fY;
+            }
+            else
+            {
+                pos2.fX = fMarkedEnd.fX + 1;
+                pos2.fY = fMarkedEnd.fY;
+            }
+        }
+        if (!fText->Search(&pos, pos2, string, direction, caseSensitive))
+            return kFALSE;
+        UnMark();
+        fIsMarked = kTRUE;
+        fMarkedStart.fY = fMarkedEnd.fY = pos.fY;
+        fMarkedStart.fX = pos.fX;
+        fMarkedEnd.fX = fMarkedStart.fX + strlen(string);
+        pos.fY = ToObjYCoord(fVisible.fY);
+        if ((fMarkedStart.fY < pos.fY) ||
+            (ToScrYCoord(fMarkedStart.fY) >= (Int_t)fCanvas->GetHeight()))
+            pos.fY = fMarkedStart.fY;
+        pos.fX = ToObjXCoord(fVisible.fX, pos.fY);
+        if ((fMarkedStart.fX < pos.fX) ||
+            (ToScrXCoord(fMarkedStart.fX, pos.fY) >= (Int_t)fCanvas->GetWidth()))
+            pos.fX = fMarkedStart.fX;
+
+        SetVsbPosition((ToScrYCoord(pos.fY) + fVisible.fY)/fScrollVal.fY);
+        SetHsbPosition((ToScrXCoord(pos.fX, pos.fY) + fVisible.fX)/fScrollVal.fX);
+        DrawRegion(0, (Int_t)ToScrYCoord(fMarkedStart.fY), fCanvas->GetWidth(),
+                   UInt_t(ToScrYCoord(fMarkedEnd.fY+1) - ToScrYCoord(fMarkedEnd.fY)));
+
+        return kTRUE;
+    }
+};
+// --------------------------------------------------------------------------
 
 // --------------------------------------------------------------------------
@@ -163,8 +225,6 @@
     logmenu->AddSeparator();
     logmenu->AddEntry("Select &All",    kLogSelect);
-    /*
-     logmenu->AddSeparator();
-     logmenu->AddEntry("Search",         kLogSearch);
-     */
+    logmenu->AddSeparator();
+    logmenu->AddEntry("&Find...",       kLogFind);
     logmenu->AddSeparator();
     logmenu->AddEntry("&Save",          kLogSave);
@@ -280,5 +340,5 @@
 
         // Create Text View
-        fLogBox = new TGTextView(f, 1, 1); // , -1, 0, TGFrame::GetDefaultFrameBackground());
+        fLogBox = new MGTextView(f, 1, 1); // , -1, 0, TGFrame::GetDefaultFrameBackground());
         if (fFont)
             fLogBox->SetFont(fFont);
@@ -782,6 +842,6 @@
         fLogBox->SelectAll();
         return kTRUE;
-    case kLogSearch:
-        //virtual Bool_t Search(const char *string, Bool_t direction, Bool_t caseSensitive);
+    case kLogFind:
+        new MSearch(this);
         return kTRUE;
     case kLogSave:
@@ -939,4 +999,24 @@
 // --------------------------------------------------------------------------
 //
+// Process the kC_USER messages
+//
+Bool_t MStatusDisplay::ProcessMessageUser(Long_t submsg, Long_t mp1, Long_t mp2)
+{
+    // kS_START, case sensitive | backward<<1, char *txt
+    switch (submsg)
+    {
+    case kS_START:
+        fLogBox->Search((char*)mp2, !(mp1&2>>1), mp1&1);
+        return kTRUE;
+#ifdef DEBUG
+    default:
+        cout << "User: " << "Submsg:" << submsg << " Mp1=" << mp1 << " Mp2=" << mp2 << endl;
+#endif
+    }
+    return kTRUE;
+}
+
+// --------------------------------------------------------------------------
+//
 // Process the messages from the GUI
 //
@@ -944,4 +1024,6 @@
 {
     // Can be found in WidgetMessageTypes.h
+    cout << "Msg: " << GET_MSG(msg) << " Submsg:" << GET_SUBMSG(msg);
+    cout << " Mp1=" << mp1 << " Mp2=" << mp2 << endl;
     switch (GET_MSG(msg))
     {
@@ -951,4 +1033,7 @@
     case kC_TEXTVIEW:
         return ProcessMessageTextview(GET_SUBMSG(msg), mp1, mp2);
+
+    case kC_USER:
+        return ProcessMessageUser(GET_SUBMSG(msg), mp1, mp2);
     }
 #ifdef DEBUG
Index: /trunk/MagicSoft/Mars/mmain/MStatusDisplay.h
===================================================================
--- /trunk/MagicSoft/Mars/mmain/MStatusDisplay.h	(revision 2086)
+++ /trunk/MagicSoft/Mars/mmain/MStatusDisplay.h	(revision 2087)
@@ -44,7 +44,9 @@
         kSize640, kSize800, kSize960, kSize1024, kSize1280,
         // kLog
-        kLogCopy, kLogClear, kLogSelect, kLogSearch, kLogSave, kLogAppend,
+        kLogCopy, kLogClear, kLogSelect, kLogFind, kLogSave, kLogAppend,
         // kPic
-        kPicMagic, kPicMars
+        kPicMagic, kPicMars,
+        // kPic
+        kSearch
     } Status_t;
 
@@ -82,4 +84,5 @@
     Bool_t ProcessMessageCommand(Long_t submsg, Long_t mp1, Long_t mp2);
     Bool_t ProcessMessageTextview(Long_t submsg, Long_t mp1, Long_t mp2);
+    Bool_t ProcessMessageUser(Long_t submsg, Long_t mp1, Long_t mp2);
     Bool_t ProcessMessage(Long_t msg, Long_t mp1, Long_t mp2);
     void   CloseWindow();
Index: /trunk/MagicSoft/Mars/mmain/MainLinkDef.h
===================================================================
--- /trunk/MagicSoft/Mars/mmain/MainLinkDef.h	(revision 2086)
+++ /trunk/MagicSoft/Mars/mmain/MainLinkDef.h	(revision 2087)
@@ -13,4 +13,5 @@
 #pragma link C++ class MDataCheck+;
 #pragma link C++ class MMonteCarlo+;
+#pragma link C++ class MSearch+;
 #pragma link C++ class MProgressBar+;
 #pragma link C++ class MCameraDisplay+;
Index: /trunk/MagicSoft/Mars/mmain/Makefile
===================================================================
--- /trunk/MagicSoft/Mars/mmain/Makefile	(revision 2086)
+++ /trunk/MagicSoft/Mars/mmain/Makefile	(revision 2087)
@@ -37,4 +37,5 @@
            MAnalysis.cc \
 	   MMonteCarlo.cc \
+           MSearch.cc \
            MStatusDisplay.cc \
 	   MProgressBar.cc \
