Skip to content
Snippets Groups Projects
markfuncs.cpp 37.8 KiB
Newer Older
/***********************************************************************
 * $Id: markfuncs.cpp 2479 2006-09-08 23:20:52Z lyle $
 ***********************************************************************/

#include "FXRbCommon.h"

#ifdef MARK
#undef MARK
#endif
#define MARK(p) rb_gc_mark(reinterpret_cast<VALUE>((p)))


template<class BASECLASS,class SUBCLASS>
static void delete_if_not_owned(BASECLASS* self,SUBCLASS*){
  if(self!=0){
    if(!FXRbIsBorrowed(self)){
      if(self->isMemberOf(FXMETACLASS(SUBCLASS))){
        if(!dynamic_cast<SUBCLASS*>(self)->owned){
          delete self; // also unregisters it
          }
	}
      }
    FXRbUnregisterRubyObj(self);
    }
  }


template<class BASECLASS,class SUBCLASS>
static void delete_if_not_owned_by_app(BASECLASS* self,SUBCLASS*){
  if(self!=0){
    if(!FXRbIsBorrowed(self)){
      if(self->isMemberOf(FXMETACLASS(SUBCLASS))){
        if(!dynamic_cast<SUBCLASS*>(self)->ownedByApp){
          delete self; // also unregisters it
          }
	}
      }
    FXRbUnregisterRubyObj(self);
    }
  }


// FIXME: How to get to the target objects stored in the accelerator
// table? This is currently private (not protected) data for the class.
void FXRbAccelTable::markfunc(FXAccelTable* accelTable){
  FXRbObject::markfunc(accelTable);
  }


// Mark dependencies for the GC
void FXRbObject::markfunc(FXObject* obj){
  FXTRACE((100,"%s::markfunc(0x%08x)\n",obj?obj->getClassName():"FXRbObject",obj));
  }


void FXRbObject::freefunc(FXObject* self){
  if(self!=0){
    // Unregister, but don't destroy, borrowed references
    if(FXRbIsBorrowed(self)){
      FXRbUnregisterRubyObj(self);
      return;
      }

    const FXchar* classname=self->getClassName();
    FXASSERT(classname!=0);
    FXASSERT(strlen(classname)>3);
    if(classname[0]=='F' && classname[1]=='X' && classname[2]=='R' && classname[3]=='b'){
      delete self;
      }
    else{
      FXRbUnregisterRubyObj(self);
      }
    }
  }

void FXRbIconSource::markfunc(FXIconSource* iconSource){
  FXRbObject::markfunc(iconSource);
  }
  
void FXRbTranslator::markfunc(FXTranslator* translator){
  FXRbObject::markfunc(translator);
  if(translator){
    FXRbGcMark(translator->getApp());
    FXRbGcMark(translator->getTextCodec());
    }
  }

void FXRbBMPIcon::markfunc(FXBMPIcon *icon){
  FXRbIcon::markfunc(icon);
  }


void FXRbIcon::markfunc(FXIcon* icon){
  FXRbImage::markfunc(icon);
  }


void FXRbImage::markfunc(FXImage* image){
  FXRbDrawable::markfunc(image);
  }


void FXRbBMPImage::markfunc(FXBMPImage* image){
  FXRbImage::markfunc(image);
  }


void FXRbBitmap::markfunc(FXBitmap* bitmap){
  FXRbDrawable::markfunc(bitmap);
  }


void FXRbButton::markfunc(FXButton* btn){
  FXRbLabel::markfunc(btn);
  }


void FXRbKnob::markfunc(FXKnob* self){
  FXRbFrame::markfunc(self);
  }


void FXRbLabel::markfunc(FXLabel* self){
  FXRbFrame::markfunc(self);
  if(self){
    FXRbGcMark(self->getFont());
    FXRbGcMark(self->getIcon());
    }
  }


void FXRbFrame::markfunc(FXFrame* frame){
  FXRbWindow::markfunc(frame);
  }

void FXRb7Segment::markfunc(FX7Segment* seg){
  FXRbFrame::markfunc(seg);
  }

void FXRbDockHandler::markfunc(FXDockHandler *dockhandler){
  FXRbFrame::markfunc(dockhandler);
  }

void FXRbDockTitle::markfunc(FXDockTitle *self){
  FXRbDockHandler::markfunc(self);
  if(self){
    FXRbGcMark(self->getFont());
    }
  }

void FXRbDrawable::markfunc(FXDrawable* drawable){
  FXRbId::markfunc(drawable);
  if(drawable) FXRbGcMark(drawable->getVisual());
  }


void FXRbId::markfunc(FXId* self){
  FXRbObject::markfunc(self);
  if(self){
    FXRbGcMark(self->getApp());
    if(self->getUserData()) MARK(self->getUserData());
    }
  }


void FXRbCanvas::markfunc(FXCanvas* canvas){
  FXRbWindow::markfunc(canvas);
  }


void FXRbCheckButton::markfunc(FXCheckButton* cb){
  FXRbLabel::markfunc(cb);
  }


void FXRbColorDialog::markfunc(FXColorDialog* dlg){
  FXRbDialogBox::markfunc(dlg);
  }

void FXRbChoiceBox::markfunc(FXChoiceBox* box){
  FXRbDialogBox::markfunc(box);
  }

void FXRbWindow::markfunc(FXWindow* self){
  FXRbDrawable::markfunc(self);
  if(self){
    FXRbGcMark(self->getParent());
    FXRbGcMark(self->getOwner());
    FXRbGcMark(self->getShell());
    FXRbGcMark(self->getRoot());
    // FXRbGcMark(self->getNext());
    // FXRbGcMark(self->getPrev());
    FXRbGcMark(self->getFocus());
    FXRbGcMark(self->getTarget());
    FXRbGcMark(self->getAccelTable());
    FXRbGcMark(self->getDefaultCursor());
    FXRbGcMark(self->getDragCursor());

    // Mark child windows
    register FXWindow* child=self->getFirst();
Loading
Loading full blame...