클래스/인스턴스 초기화 처리자
AtkObject 구현체가 다음에 해당하는 경우 GObject용 클래스 초기화 처리자를 설정해야합니다:
-
상위 객체에서 정의한 함수 호출을 재정의합니다. 객체에 atk_object_get_n_accessible_children() 함수와 비슷한 함수를 구현해야 할 때 보통 필요합니다. 객체가 하위 요소지만 위젯을 나타내지 않는다면 필요합니다.
예를 들어 ATK 구현체에서 AtkObject 함수 get_name()을 따로 구현해야 할 경우, 클래스 초기화 처리자는 다음과 같이 구현합니다:
예제 1-8 상위 객체의 get_name() 함수를 재구현하는 클래스 초기화 처리자myatkimp_mytype_class_init (GailLabelClass *klass) { AtkObjectClass *class = ATK_OBJECT_CLASS (klass); class->get_name = myatkimp_mytype_get_name; }
-
parent->init, parent->notify_gtk, parent->finalize 셋 중 한가지 함수가 필요합니다. 다음 예제에서는 언급한 세가지 함수를 모두 정의합니다:
예제 1-9 init(), notify_gtk(), finalize() 자체 함수를 정의하는 클래스 초기화 처리자static ParentObjectType *parent_class = NULL; myatkimp_mytype_class_init (GailLabelClass *klass) { ParentObjectType *parent_class = (ParentObjectType*)klass; /* * Caching the parent_class is necessary if the init, * notify_gtk, or finalize functions are set up. */ parent_class = g_type_class_ref (MYATKIMP_TYPE_PARENT); parent_class->init = myatkimp_mytype_widget_init; parent_class->notify_gtk = myatkimp_mytype_real_notify_gtk; parent_class->finalize = myatkimp_mytype_finalize; }
-
parent->init
ATK 구현체에서 다음 두가지 경우가 필요한 경우 parent->init() 함수가 필요할 수도 있습니다:
- 보조 GTK 위젯에서 가져온 데이터를 캐시할 경우.
- 보조 GTK 위젯에서 보낸 시그널을 기다릴 경우.
두 가지 모두의 경우에 대한 예제입니다:
예제 1-10 init() 개별 구현 함수void gail_tree_view_widget_init (MyatkimpMytype *mytype, GtkWidget *gtk_widget) { /* Make sure to call the parent's init function */ parent_class->init (widget, gtk_widget); /* Cache a value in the ATK implementation */ mytype->cached_value = gtk_widget_function_call(); /* Listen to a signal */ gtk_signal_connect (GTK_OBJECT (gtk_widget), "signal-type", GTK_SIGNAL_FUNC (_myatkimp_mytype_signal_type), NULL); }
이 예제에서 signal-type 지정 시그널을 보조 gtk_widget에서 만들었다면, _myatkimp_mytype_signal_type()함수를 호출합니다.
-
parent->notify_gtk
ATK 구현체에서 보조 GTK 객체의 속성 알림을 기다려야 한다면, parent->notify_gtk() 함수가 필요할 지도 모르겠습니다. 예를 들어:
예제 1-11 notify_gtk() 함수 개별 구현체void myatkimp_mytype_real_notify_gtk (GObject *obj, GParamSpec *pspec) { GtkWidget *widget = GTK_WIDGET (obj); AtkObject* atk_obj = gtk_widget_get_accessible (widget); if (strcmp (pspec->name, "property-of-interest") == 0) { /* Handle the property change. */ } else { parent_class->notify_gtk (obj, pspec); } }
-
parent->finalize
GObject 인스턴스를 무효화 했을 때 데이터를 버려야 한다면 finalize() 함수로 메모리를 해제해야합니다. 예를 들면:
예제 1-12 finalize() 함수 개별 구현체void myatkimp_mytype_finalize (GObject *object) { MyAtkimpMyType *my_type = MYATKIMP_MYTYPE (object); g_object_unref (my_type->cached_value); G_OBJECT_CLASS (parent_class)->finalize (object); }
-