Skip to content
Snippets Groups Projects
markfuncs.cpp 39.7 KiB
Newer Older
/***********************************************************************
 * $Id: markfuncs.cpp 2928 2008-12-29 19:16:57Z 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.
Lars Kanis's avatar
Lars Kanis committed
// See workaround in lib/fox16/accel_table.rb.
void FXRbAccelTable::markfunc(FXAccelTable* accelTable){
  FXRbObject::markfunc(accelTable);
  }


// Mark dependencies for the GC
void FXRbObject::markfunc(FXObject* obj){
  FXTRACE((100,"%s::markfunc(%p)\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->FXTranslator::getApp());
    FXRbGcMark(translator->FXTranslator::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->FXLabel::getFont());
    FXRbGcMark(self->FXLabel::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->FXDockTitle::getFont());
    }
  }

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


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


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->FXWindow::getParent());
    FXRbGcMark(self->FXWindow::getOwner());
    FXRbGcMark(self->FXWindow::getShell());
    FXRbGcMark(self->FXWindow::getRoot());
    // FXRbGcMark(self->FXWindow::getNext());
    // FXRbGcMark(self->FXWindow::getPrev());
    FXRbGcMark(self->FXWindow::getFocus());
    FXRbGcMark(self->FXWindow::getTarget());
    FXRbGcMark(self->FXWindow::getAccelTable());
    FXRbGcMark(self->FXWindow::getDefaultCursor());
    FXRbGcMark(self->FXWindow::getDragCursor());
Loading
Loading full blame...