Beispiel #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 WindowEditor::InitFlagsBoxes()
{
	BRect work = Bounds();
	work.left = 10;
	work.top = 100;
	work.bottom -= 5;
	work.right -= 10;
	work.right -= 10;
	int i = 20;
	int inc = 10;
	BBox* box = new BBox(work, "flags");
	BCheckBox* cbox;
	BMessage* msg;
	box->SetLabel("Window Flags");
	uint32 flags = fWindowInfo.flags;
	bool longLabel;

	for (int index = 0; WindowFlags[index].name; ++index)
	{
		longLabel = strlen(WindowFlags[index].label) > 20;
		// First column of checkboxes
		msg = new BMessage(MSG_WINDOW_SET_FLAG);
		msg->AddInt32("flags", WindowFlags[index].flag);
		cbox = new BCheckBox(BRect(10, i, longLabel ? 210 : 125, i + inc),
							 WindowFlags[index].name, WindowFlags[index].label, msg);
		fFlagBoxes.push_back(cbox);
		box->AddChild(cbox);
		if (WindowFlags[index].flip == (flags & WindowFlags[index].flag))
		{
			cbox->SetValue(B_CONTROL_ON);
		}

		// We skip to the next row as needed to make room for long labels
		if (!longLabel && WindowFlags[index + 1].name)
		{
			++index;
			// Second column of checkboxes
			msg = new BMessage(MSG_WINDOW_SET_FLAG);
			msg->AddInt32("flags", WindowFlags[index].flag);
			cbox = new BCheckBox(BRect(130, i, 210, i + inc),
								 WindowFlags[index].name,
								 WindowFlags[index].label,
								 msg);
			fFlagBoxes.push_back(cbox);
			box->AddChild(cbox);
			if (WindowFlags[index].flip == (flags & WindowFlags[index].flag))
			{
				cbox->SetValue(B_CONTROL_ON);
			}
		}

		i += inc * 2;
	}
#if 0
	msg = new BMessage(MSG_WINDOW_SET_FLAG);
	msg->AddInt32("flags",B_NOT_MOVABLE);
	box->AddChild(new BCheckBox(BRect(10,i,120,i+inc),"nmov","Movable",msg));
	msg = new BMessage(MSG_WINDOW_SET_FLAG);
	msg->AddInt32("flags",B_NOT_CLOSABLE);
	box->AddChild(new BCheckBox(BRect(130,i,210,i+inc),"clos","Closable",msg));
	msg = new BMessage(MSG_WINDOW_SET_FLAG);
	i+= inc*2;
	msg->AddInt32("flags",B_NOT_ZOOMABLE);
	box->AddChild(new BCheckBox(BRect(10,i,120,i+inc),"zoom","Zoomable",msg));
	msg = new BMessage(MSG_WINDOW_SET_FLAG);
	msg->AddInt32("flags",B_NOT_MINIMIZABLE);
	box->AddChild(new BCheckBox(BRect(130,i,210,i+inc),"mini","Minimizable",msg));
	msg = new BMessage(MSG_WINDOW_SET_FLAG);
	i+= inc*2;
	msg->AddInt32("flags",B_NOT_H_RESIZABLE);
	box->AddChild(new BCheckBox(BRect(10,i,210,i+inc),"hres","Horizontally Resizable",msg));
	msg = new BMessage(MSG_WINDOW_SET_FLAG);
	i+= inc*2;
	msg->AddInt32("flags",B_NOT_V_RESIZABLE);
	box->AddChild(new BCheckBox(BRect(10,i,125,i+inc),"vres","Vertically Resizable",msg));
	menubox = new BCheckBox(BRect(130,i,210,i+inc),"menus","Menu Bar",new BMessage(MSG_WINDOW_ADD_MENU));
	box->AddChild(menubox);
	if (fWindowInfo.has_menu)
		menubox->SetValue(B_CONTROL_ON);
	msg = new BMessage(MSG_WINDOW_SET_FLAG);
	i+= inc*2;
	msg->AddInt32("flags",B_OUTLINE_RESIZE);
	box->AddChild(new BCheckBox(BRect(10,i,210,i+inc),"roiw","Resize with Outline Instead of Window",msg));
	msg = new BMessage(MSG_WINDOW_SET_FLAG);
	i+= inc*2;
	msg->AddInt32("flags",B_WILL_ACCEPT_FIRST_CLICK);
	box->AddChild(new BCheckBox(BRect(10,i,210,i+inc),"wafc","Will Accept First Click",msg));
	msg = new BMessage(MSG_WINDOW_SET_FLAG);
	i+= inc*2;
	msg->AddInt32("flags",B_AVOID_FRONT);
	box->AddChild(new BCheckBox(BRect(10,i,120,i+inc),"avfr","Avoid Front",msg));
	msg = new BMessage(MSG_WINDOW_SET_FLAG);
	msg->AddInt32("flags",B_AVOID_FOCUS);
	box->AddChild(new BCheckBox(BRect(130,i,210,i+inc),"avfo","Avoid Focus",msg));
	msg = new BMessage(MSG_WINDOW_SET_FLAG);
	i+= inc*2;
	msg->AddInt32("flags",B_NO_WORKSPACE_ACTIVATION);
	box->AddChild(new BCheckBox(BRect(10,i,210,i+inc),"nwoa","Do Not Activate Workspace",msg));
	msg = new BMessage(MSG_WINDOW_SET_FLAG);
	i+= inc*2;
	msg->AddInt32("flags",B_NOT_ANCHORED_ON_ACTIVATE);
	box->AddChild(new BCheckBox(BRect(10,i,210,i+inc),"brcu","Bring Window To Current Workspace",msg));
	msg = new BMessage(MSG_WINDOW_SET_FLAG);
	i+= inc*2;
	msg->AddInt32("flags",B_ASYNCHRONOUS_CONTROLS);
	box->AddChild(new BCheckBox(BRect(10,i,210,+inc),"async","Asynchronous Controls (Should Be On)",msg));
#endif
#if 0
	if (!(flags & B_NOT_MOVABLE))
		((BCheckBox *)(box->ChildAt(0)))->SetValue(B_CONTROL_ON);
	if (!(flags & B_NOT_CLOSABLE))
		((BCheckBox *)(box->ChildAt(1)))->SetValue(B_CONTROL_ON);
	if (!(flags & B_NOT_ZOOMABLE))
		((BCheckBox *)(box->ChildAt(2)))->SetValue(B_CONTROL_ON);
	if (!(flags & B_NOT_MINIMIZABLE))
		((BCheckBox *)(box->ChildAt(3)))->SetValue(B_CONTROL_ON);
	if (!(flags & B_NOT_H_RESIZABLE))
		((BCheckBox *)(box->ChildAt(4)))->SetValue(B_CONTROL_ON);
	if (!(flags & B_NOT_V_RESIZABLE))
		((BCheckBox *)(box->ChildAt(5)))->SetValue(B_CONTROL_ON);
	if (flags & B_OUTLINE_RESIZE)
		((BCheckBox *)(box->ChildAt(7)))->SetValue(B_CONTROL_ON);
	if (flags & B_WILL_ACCEPT_FIRST_CLICK)
		((BCheckBox *)(box->ChildAt(8)))->SetValue(B_CONTROL_ON);
	if (flags & B_AVOID_FRONT)
		((BCheckBox *)(box->ChildAt(9)))->SetValue(B_CONTROL_ON);
	if (flags & B_AVOID_FOCUS)
		((BCheckBox *)(box->ChildAt(10)))->SetValue(B_CONTROL_ON);
	if (flags & B_NO_WORKSPACE_ACTIVATION)
		((BCheckBox *)(box->ChildAt(11)))->SetValue(B_CONTROL_ON);
	if (flags & B_NOT_ANCHORED_ON_ACTIVATE)
		((BCheckBox *)(box->ChildAt(12)))->SetValue(B_CONTROL_ON);
	if (flags & B_ASYNCHRONOUS_CONTROLS)
		((BCheckBox *)(box->ChildAt(13)))->SetValue(B_CONTROL_ON);
#endif

	AddChild(box);

	cbox = (BCheckBox*)FindView("menus");
	if (cbox)
	{
		cbox->SetValue(fWindowInfo.has_menu);
		cbox->SetMessage(new BMessage(MSG_WINDOW_ADD_MENU));
	}
}
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;
			}
		}

	} 
}