Пример #1
0
void HDialog::SetEnabled(const char *name, bool enabled)
{
	BControl *ctl;
	ctl = dynamic_cast<BControl*>(FindView(name));
	if (ctl)
		ctl->SetEnabled(enabled);
} /* HDialog::SetEnabled */
Пример #2
0
status_t
PControl::SetProperty(const char *name, PValue *value, const int32 &index)
{
	// Modal, Front, and Floating properties are missing because they are read-only
	if (!name || !value)
		return B_ERROR;
	
	BString str(name);
	PProperty *prop = FindProperty(name,index);
	if (!prop)
		return B_NAME_NOT_FOUND;
	
	status_t status = prop->SetValue(value);
	if (status != B_OK)
		return status;
	
	if (!fView)
		return B_NO_INIT;
	
	BControl *viewAsControl = (BControl*)fView;
	
	BoolValue bv;
	IntValue iv;
	StringValue sv;
	
	if (viewAsControl->Window())
		viewAsControl->Window()->Lock();
	
	if (str.ICompare("Enabled") == 0)
	{
		prop->GetValue(&bv);
		viewAsControl->SetEnabled(bv.value);
	}
	else if (str.ICompare("Label") == 0)
	{
		prop->GetValue(&sv);
		viewAsControl->SetLabel(sv.value->String());
		viewAsControl->Invalidate();
	}
	else if (str.ICompare("Value") == 0)
	{
		prop->GetValue(&iv);
		viewAsControl->SetValue(*iv.value);
	}
	else
	{
		if (viewAsControl->Window())
			viewAsControl->Window()->Unlock();
		return PView::SetProperty(name,value,index);
	}

	if (viewAsControl->Window())
		viewAsControl->Window()->Unlock();
	
	return prop->GetValue(value);
}
void
ThemeInterfaceView::PopulateThemeList()
{
	int i;
	BControl *c;
	for (i = 0; ChildAt(i); i++) {
		c = dynamic_cast<BControl *>(ChildAt(i));
		if (c)
			c->SetEnabled(false);
	}
	thread_id tid = spawn_thread(_ThemeListPopulatorTh, "ThemeListPopulator", 
		B_LOW_PRIORITY, this);
	resume_thread(tid);
}
void
ThemeInterfaceView::_ThemeListPopulator()
{
	status_t err;
	int32 i, count;
	int32 importer;
	BString name;
	ThemeItem *ti;
	bool isro;
	BStringItem *si;

	LockLooper();
	fThemeList->MakeEmpty();
	UnlockLooper();

	ThemeManager* tman = GetThemeManager();
	tman->LoadThemes();

	count = tman->CountThemes();
	

	LockLooper();

	si = new BStringItem("(System themes)");
	si->SetEnabled(false);
	fThemeList->AddItem(si);
	si = NULL; // first non-readonly item will set it again

	// native themes
	for (i = 0; i < count; i++) {
		err = tman->ThemeName(i, name);
		isro = tman->ThemeIsReadOnly(i);
		if (err)
			continue;

		if (!isro && si == NULL) {
			si = new BStringItem("(User themes)");
			si->SetEnabled(false);
			fThemeList->AddItem(si);
		}

		ti = new ThemeItem(i, name.String(), isro);
		fThemeList->AddItem(ti);
	}

	UnlockLooper();

	// for each importer
	for (importer = 0; importer < tman->CountThemeImporters(); importer++) {
		err = tman->ImportThemesFor(importer);
		if (err < 0)
			continue;
		PRINT(("Imports for %s: %d\n", tman->ThemeImporterAt(importer), (tman->CountThemes() - count)));
		if (tman->CountThemes() == count)
			continue; // nothing found

		// separator item
		name = "Imported (";
		name << tman->ThemeImporterAt(importer) << ")";
		si = new BStringItem(name.String());
		si->SetEnabled(false);
		LockLooper();
		fThemeList->AddItem(si);
		UnlockLooper();

		// add new themes
		count = tman->CountThemes();
		// we reuse i from where it was left
		for (; i < count; i++) {
			err = tman->ThemeName(i, name);
			isro = true;// importers can't save themes back
			if (err)
				continue;
			ti = new ThemeItem(i, name.String(), isro);
			LockLooper();
			fThemeList->AddItem(ti);
			UnlockLooper();
			// rest a bit
			snooze(1000);
		}
	}

	// enable controls again
	BControl *c;
	LockLooper();
	for (i = 0; ChildAt(i); i++) {
		c = dynamic_cast<BControl *>(ChildAt(i));
		if (c)
			c->SetEnabled(true);
	}
	UnlockLooper();
}