Ejemplo n.º 1
0
TargetSettingsWin::TargetSettingsWin(const char *uWindowTitle, TargetConfig *targetConfig)
:
	BWindow(
		BRect(64, 64, 680, 450),
		uWindowTitle,
		B_FLOATING_WINDOW_LOOK,
		/*B_NORMAL_WINDOW_FEEL*/ B_MODAL_APP_WINDOW_FEEL,
		B_NOT_RESIZABLE | B_NOT_ZOOMABLE | B_NOT_CLOSABLE,
		0 )
{
	assert(targetConfig != NULL);
	
	MainView = new BView(BWindow::Bounds(), NULL, B_FOLLOW_ALL, 0);
	if (MainView == NULL)
	{
		AppReturnValue = B_NO_MEMORY;
		be_app->PostMessage(B_QUIT_REQUESTED);
		return;		
	}
	MainView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
	BWindow::AddChild(MainView);
	
	//members
	fConfig = targetConfig;
	fChangedConfig = false;
	fGeneralSettingsChanged = false;
	fCompilerSettingsChanged = false;
	fLinkerSettingsChanged = false;
	fIncludeSettingsChanged = false;
	
	//list of available settings
	BRect r = MainView->Bounds();
	r.left += 15;
	r.bottom = r.top + (r.bottom - r.top)/2;
	r.top += 15;
	
	r.right = r.left + 100;
	fSettingsListView = new BListView(r, "settings list");
	fSettingsListView->SetSelectionMessage(new BMessage(PANEL_LIST_ITEM_SELECTED));
	//XXX - the following doesn't work. Why?
	fSettingsListView->Select(0); //select the first item, i.e. "general settings"
	MainView->AddChild(fSettingsListView);
	fSettingsListView->AddItem(new BStringItem("General"));
	fSettingsListView->AddItem(new BStringItem("Include Paths"));
	fSettingsListView->AddItem(new BStringItem("Compiler Options"));
	fSettingsListView->AddItem(new BStringItem("Linker Options"));
	
	/////////////////////////////////////////////////////////////////////
	//create all settings panels. Use the same rect for all views.
	r = MainView->Bounds();
	r.top += 15;
	r.right -= 15;
	r.bottom -= 50;
	r.left += fSettingsListView->Bounds().Width() + 30;
	//create GeneralSettingsView and make it the current view
	fGeneralSettingsView = new GeneralSettingsView(r, "general settings view");
	fCurrentSettingsView = fGeneralSettingsView;
	MainView->AddChild(fGeneralSettingsView);

	fCompilerSettingsView = new CompilerSettingsView(r, "compiler settings view");
	fLinkerSettingsView = new LinkerSettingsView(r, "linker settings view");
	fIncludeSettingsView = new IncludeSettingsView(r, "include settings view");

	/////////////////////////////////////////////////////////////////////
		
	//insert 'OK' and 'Cancel' buttons
	r = BWindow::Bounds();
	r.top = fGeneralSettingsView->Bounds().bottom + 30;
	r.bottom -= 15;
	r.right -=15;
	r.left = r.right - 75;
	r.PrintToStream();
	//OK
	BButton* okButton = new BButton(r, "OK button", "OK", new BMessage(OK_BUTTON_PRESSED));
	MainView->AddChild(okButton);
	//Cancel
	r.right = r.left - 15;
	r.left = r.right - 75;
	r.PrintToStream();
	BButton* cancelButton = new BButton(r, "Cancel button", "Cancel", new BMessage(CANCEL_BUTTON_PRESSED));
	MainView->AddChild(cancelButton);
	
	/////////////////////////////////////////////////////////////////////
	
	//initialize views with configuration settings
	PopulateSettings();
	//tell the application that there's a new window
	Register();
	//last but not least...
	Show();
}
Ejemplo n.º 2
0
void moduleListWM_NOTIFY(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)// hwnd here is to the main window, NOT the treview
{
	switch (((NMHDR *)lParam)->code) {
	case TVN_ITEMEXPANDINGA:
	case TVN_ITEMEXPANDINGW:
		if (populating && ((LPNMTREEVIEW)lParam)->action == TVE_EXPAND) {
			ModuleTreeInfoStruct *mtis = (ModuleTreeInfoStruct *)((LPNMTREEVIEW)lParam)->itemNew.lParam;
			if (mtis && (mtis->type == (CONTACT | EMPTY))) {
				TVINSERTSTRUCT tvi;
				HTREEITEM item = {0};
				ModuleTreeInfoStruct *_lParam;
				HWND hwnd2Tree = GetDlgItem(hwnd2mainWindow, IDC_MODULES);
				ModSetLinkLinkItem *module;
				ModuleSettingLL modlist;
				MCONTACT hContact = mtis->hContact;

				mtis->type = CONTACT;

				if (!EnumModules(&modlist)) {
					msg(Translate("Error loading module list"), modFullname);
					break;
				}

				module = modlist.first;
				while (module && hwnd2mainWindow) {
					if (module->name[0] && !IsModuleEmpty(hContact, module->name)) {
						tvi.hParent = ((LPNMTREEVIEW)lParam)->itemNew.hItem;
						tvi.hInsertAfter = TVI_SORT;
						tvi.item.mask = TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_PARAM;
						tvi.item.pszText = module->name;

						_lParam = (ModuleTreeInfoStruct *)mir_calloc(sizeof(ModuleTreeInfoStruct));
						_lParam->hContact = hContact;

						tvi.item.iImage = 5;
						tvi.item.iSelectedImage = 6;
						_lParam->type = KNOWN_MODULE;

						tvi.item.lParam = (LPARAM)_lParam;
						TreeView_InsertItem(hwnd2Tree, &tvi);
					}
					module = (ModSetLinkLinkItem *)module->next;
				}

				FreeModuleSettingLL(&modlist);
			}
		}
		break;

	case TVN_SELCHANGEDA:
	case TVN_SELCHANGEDW:
		{
			ModuleTreeInfoStruct *mtis;
			LPNMTREEVIEW pnmtv = (LPNMTREEVIEW)lParam;
			TVITEM tvi = {0};
			char text[264];
			MCONTACT hContact;
			HWND hwnd2Settings = GetDlgItem(hwnd, IDC_SETTINGS);
			tvi.mask = TVIF_HANDLE | TVIF_PARAM | TVIF_TEXT;
			tvi.hItem = pnmtv->itemNew.hItem;
			tvi.pszText = text;
			tvi.cchTextMax = 264;
			TreeView_GetItem(pnmtv->hdr.hwndFrom, &tvi);

			if (tvi.lParam) {
				mtis = (ModuleTreeInfoStruct *)tvi.lParam;
				hContact = mtis->hContact;

				if (mtis->type == STUB)
					break;

				if (populating)
					Select = 0;

				if (mtis->type == MODULE) {
					SettingListInfo *info = (SettingListInfo *)GetWindowLongPtr(hwnd2Settings, GWLP_USERDATA);
					BOOL refresh = 1;

					if (info) {
						if (info->hContact == hContact && !mir_strcmp(info->module, text))
							refresh = 0;
					}

					if (refresh)
						PopulateSettings(hwnd2Settings, hContact, text);
				}
				else if (((mtis->type & CONTACT) == CONTACT && hContact) || (mtis->type == CONTACT_ROOT_ITEM && !hContact)) {
					char data[32], szProto[256];
					int index, loaded, multi = 0;
					LVITEM lvi = {0};
					lvi.mask = LVIF_IMAGE | LVIF_TEXT | LVIF_PARAM;
					lvi.iImage = 6;

					ClearListview(hwnd2Settings);
					SetWindowLongPtr(hwnd2Settings, GWLP_USERDATA, 0);
					if (himl2)
						ListView_SetImageList(hwnd2Settings, himl2, LVSIL_SMALL);

					if (mtis->type == CONTACT_ROOT_ITEM && !hContact) {
						multi = 1;
						hContact = db_find_first();
					}

					while (hContact && hwnd2mainWindow) {
						if (multi) {
							// filter
							if (GetValue(hContact, "Protocol", "p", szProto, SIZEOF(szProto)))
								loaded = IsProtocolLoaded(szProto);
							else
								loaded = 0;

							if ((loaded && Mode == MODE_UNLOADED) || (!loaded && Mode == MODE_LOADED)) {
								hContact = db_find_next(hContact);
								continue;
							}
						}

						lvi.iItem = 0;
						lvi.pszText = (char *)GetContactName(hContact, NULL, FALSE);

						index = ListView_InsertItem(hwnd2Settings, &lvi);

						mir_snprintf(data, SIZEOF(data), "0x%08X (%ld)", hContact, hContact);

						ListView_SetItemText(hwnd2Settings, index, 1, data);
						ListView_SetItemText(hwnd2Settings, index, 2, Translate("HANDLE"));
						ListView_SetItemText(hwnd2Settings, index, 3, "0x0004 (4)");

						if (!multi)
							break;

						hContact = db_find_next(hContact);
					}
				}
				else
					ClearListview(hwnd2Settings);
			}
			else // clear any settings that may be there...
				ClearListview(hwnd2Settings);
		}
		break; //TVN_SELCHANGED:

	case NM_RCLICK:
		if (((NMHDR *)lParam)->code == NM_RCLICK)
			moduleListRightClick(hwnd, wParam, lParam);
		break;

	case TVN_BEGINLABELEDITA: // subclass it..
	case TVN_BEGINLABELEDITW:
		{
			LPNMTVDISPINFO ptvdi = (LPNMTVDISPINFO)lParam;
			ModuleTreeInfoStruct *mtis = (ModuleTreeInfoStruct *)ptvdi->item.lParam;
			HWND hwnd2Edit = TreeView_GetEditControl(GetDlgItem(hwnd, IDC_MODULES));
			if (!mtis->type || (mtis->type == CONTACT)) {
				SetWindowLongPtr(hwnd, DWLP_MSGRESULT, TRUE);
				break;
			}
			mir_subclassWindow(hwnd2Edit, ModuleTreeLabelEditSubClassProc);
			SetWindowLongPtr(hwnd, DWLP_MSGRESULT, FALSE);
		}
		break;

	case TVN_ENDLABELEDITA:
	case TVN_ENDLABELEDITW:
		LPNMTVDISPINFO ptvdi = (LPNMTVDISPINFO)lParam;
		TVITEM tvi = {0};
		char text[264];
		char *newtext;
		ModuleTreeInfoStruct *mtis;
		tvi.mask = TVIF_HANDLE | TVIF_TEXT | TVIF_PARAM;
		tvi.hItem = ptvdi->item.hItem;
		tvi.pszText = text;
		tvi.cchTextMax = 264;
		TreeView_GetItem(((LPNMHDR)lParam)->hwndFrom, &tvi);
		mtis = (ModuleTreeInfoStruct *)ptvdi->item.lParam;

		newtext = u2a((WCHAR *)ptvdi->item.pszText);

		if (!newtext // edit control failed
			|| !mtis->type // its a root item
			|| mtis->type == CONTACT // its a contact
			|| *newtext == 0)  // empty string
			SetWindowLongPtr(hwnd, DWLP_MSGRESULT, FALSE);
		else {
			if (mir_strcmp(tvi.pszText, newtext)) {
				renameModule(tvi.pszText, newtext, mtis->hContact);

				findAndRemoveDuplicates(((LPNMHDR)lParam)->hwndFrom, mtis->hContact, newtext);

				if (TreeView_GetItem(((LPNMHDR)lParam)->hwndFrom, &tvi)) {
					tvi.mask = TVIF_IMAGE | TVIF_SELECTEDIMAGE;
					tvi.iImage = 1;
					tvi.iSelectedImage = 2;
					TreeView_SetItem(((LPNMHDR)lParam)->hwndFrom, &tvi);

					PopulateSettings(GetDlgItem(hwnd, IDC_SETTINGS), mtis->hContact, newtext);
				}
			}
			SetWindowLongPtr(hwnd, DWLP_MSGRESULT, TRUE);
		}

		mir_free(newtext);
		break;
	}
}