Ignore:
Timestamp:
11/16/01 15:59:05 (23 years ago)
Author:
tbretz
Message:
*** empty log message ***
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/mbase/MGList.cc

    r1080 r1086  
    3838
    3939#include <TClass.h>
     40#include <TGClient.h>
    4041#include <TGWidget.h>
     42#include <TGPicture.h>
    4143
    4244
    4345ClassImp(MGList);
     46
     47// --------------------------------------------------------------------------
     48//
     49//  Before destroying the list with all its contents free all TGPicture
     50//  objects in the list.
     51//
     52#include <TRefCnt.h>
     53
     54MGList::~MGList()
     55{
     56    TObject *obj;
     57    TIter Next(this);
     58    while ((obj=Next()))
     59    {
     60        if (!obj->InheritsFrom(TGPicture::Class()))
     61            continue;
     62
     63        //
     64        // Remove the object first. Otherwise we would remove
     65        // a non existing object...
     66        //
     67        Remove(obj);
     68        gClient->FreePicture((TGPicture*)obj);
     69    }
     70}
    4471
    4572// --------------------------------------------------------------------------
     
    137164// --------------------------------------------------------------------------
    138165//
     166//  Adds the picture physically to the list. The list takes care of that
     167//   - The picture is freed as often as it was retrieved from gClient
     168//
     169void MGList::AddPicture(const TGPicture *pic)
     170{
     171    //
     172    // Check whether the picture exists
     173    //
     174    if (!pic)
     175    {
     176        cout << "Warning: Requested picture not found... ignored." << endl;
     177        return;
     178    }
     179
     180    //
     181    // Add the picture to the list
     182    //
     183    TList::Add(const_cast<TGPicture*>(pic));
     184}
     185
     186// --------------------------------------------------------------------------
     187//
     188//  This gets a picture from the picture pool of the TGClient-object.
     189//  The pictures are freed automatically in the dstructor of the list.
     190//  The picture counts itself how often it got used, so that only
     191//  the first call to GetPicture will craete it and the last call to
     192//  FreePicture will destroy it. If you access the picture only via
     193//  MGList::GetPicture you don't have to care about.
     194//
     195//  Don't try to call FreePicture by yourself for a picture gotten by
     196//  GetPicture. This is independant of the kIsOwner bit.
     197//
     198const TGPicture *MGList::GetPicture(const char *name)
     199{
     200    const TGPicture *pic = gClient->GetPicture(name);
     201    AddPicture(pic);
     202    return pic;
     203}
     204
     205// --------------------------------------------------------------------------
     206//
     207//  This gets a picture from the picture pool of the TGClient-object.
     208//  The pictures are freed automatically in the dstructor of the list.
     209//  The picture counts itself how often it got used, so that only
     210//  the first call to GetPicture will craete it and the last call to
     211//  FreePicture will destroy it. If you access the picture only via
     212//  MGList::GetPicture you don't have to care about.
     213//
     214//  Don't try to call FreePicture by yourself for a picture gotten by
     215//  GetPicture. This is independant of the kIsOwner bit.
     216//
     217const TGPicture *MGList::GetPicture(const char *name, Int_t width, Int_t height)
     218{
     219    const TGPicture *pic = gClient->GetPicture(name, width, height);
     220    AddPicture(pic);
     221    return pic;
     222}
     223// --------------------------------------------------------------------------
     224//
    139225//  Search the list for a object derived from TGidget which has the given
    140226//  widget id. Returns a pointer to this object otherwise NULL.
Note: See TracChangeset for help on using the changeset viewer.