Example #1
0
void
AccountView::AttachedToWindow()
{
	// Once we are attached to window, the GUI is already created
	// so we can set our window as target for messages
	for (int32 i = 0; i < CountChildren(); i++) {
		BView* child = ChildAt(i);

		BMenu* menu = dynamic_cast<BMenu*>(child);
		BMenuField* menuField
			= dynamic_cast<BMenuField*>(child);
		BTextControl* textControl
			= dynamic_cast<BTextControl*>(child);
		NotifyingTextView* textView
			= dynamic_cast<NotifyingTextView*>(child);
		BCheckBox* checkBox = dynamic_cast<BCheckBox*>(child);

		if (menuField)
			menu = menuField->Menu();

		if (menu) {
			for (int32 j = 0; j < menu->CountItems(); j++) {
				BMenuItem* item = menu->ItemAt(j);
				item->SetMessage(new BMessage(kChanged));
				item->SetTarget(Window());
			}

			menu->SetTargetForItems(Window());
		}

		if (textControl) {
			textControl->SetMessage(new BMessage(kChanged));
			textControl->SetTarget(Window());
		}

		if (checkBox) {
			checkBox->SetMessage(new BMessage(kChanged));
			checkBox->SetTarget(Window());
		}

		if (textView) {
			textView->SetMessage(new BMessage(kChanged));
			textView->SetTarget(Window());
		}
	}
}
void MessageView::ValueChanged(void)
{
	char		*name; 
	uint32		type; 
	int32		count;
	#ifdef B_ZETA_VERSION_1_0_0
	for (int32 i = 0; configMessage->GetInfo(B_ANY_TYPE, i,(const char **) &name, &type, &count) == B_OK; i++)
	#else
	for (int32 i = 0; configMessage->GetInfo(B_ANY_TYPE, i,(char **) &name, &type, &count) == B_OK; i++)
	#endif
	{
		//calculate the Position where to add the next View
		float top = ItemTop();
		BRect rect = BRect(MARGIN_SPACE,top,Bounds().right-MARGIN_SPACE,top);
		switch(type)
		{
			case B_STRING_TYPE:
			{
				char		*string;
				configMessage->FindString(name,count-1,(const char **)&string);
				BTextControl	*stringItem	= new BTextControl(rect,name,name,string,NULL);
				AddChild(stringItem);
				BMessage	*tmpMessage = new BMessage(B_CONTROL_INVOKED);
				tmpMessage->AddString("name",name);
				tmpMessage->AddInt32("count",count-1);
				tmpMessage->AddInt32("type",type);
				stringItem->SetMessage(tmpMessage);
				break;
			}
			case B_RECT_TYPE:
			{
				BRect	valueRect;
				configMessage->FindRect(name,count-1,&valueRect);
				RectItem	*rectItem	= new RectItem(rect,name,valueRect);
				AddChild(rectItem);
				BMessage	*tmpMessage = new BMessage(B_CONTROL_INVOKED);
				tmpMessage->AddString("name",name);
				tmpMessage->AddInt32("count",count-1);
				tmpMessage->AddInt32("type",type);
				rectItem->SetMessage(tmpMessage);
				break;
			}
			case B_FLOAT_TYPE:
			{
				float	value;
				configMessage->FindFloat(name,count-1,&value);
				BString	floatString;
				floatString<<value;
				BTextControl	*stringItem	= new BTextControl(rect,name,name,floatString.String(),NULL);
				AddChild(stringItem);
				BMessage	*tmpMessage = new BMessage(B_CONTROL_INVOKED);
				tmpMessage->AddString("name",name);
				tmpMessage->AddInt32("count",count-1);
				tmpMessage->AddInt32("type",type);
				stringItem->SetMessage(tmpMessage);
				break;
			}
			case B_INT8_TYPE:
			case B_INT16_TYPE:
			case B_INT32_TYPE:
			{
				int32	value;
				configMessage->FindInt32(name,count-1,&value);
				BString	intString;
				intString<<value;
				BTextControl	*stringItem	= new BTextControl(rect,name,name,intString.String(),NULL);
				AddChild(stringItem);
				BMessage	*tmpMessage = new BMessage(B_CONTROL_INVOKED);
				tmpMessage->AddString("name",name);
				tmpMessage->AddInt32("count",count-1);
				tmpMessage->AddInt32("type",type);
				stringItem->SetMessage(tmpMessage);
				break;
			}
			case B_BOOL_TYPE:
			{
				bool	value;
				configMessage->FindBool(name,count-1,&value);
				BCheckBox	*boolItem	= new BCheckBox(rect,name,name,NULL);
				AddChild(boolItem);
				boolItem->SetValue(value);
				BMessage	*tmpMessage = new BMessage(B_CONTROL_INVOKED);
				tmpMessage->AddString("name",name);
				tmpMessage->AddInt32("count",count-1);
				tmpMessage->AddInt32("type",type);
				boolItem->SetMessage(tmpMessage);
				break;
			}
		}

	} 
}