Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » ArrayCtrl, HeaderCtrl & GridCtrl » Using an Array to switch displayed image
icon5.gif  Using an Array to switch displayed image [message #47016] Fri, 04 November 2016 08:55
Zaroz
Messages: 1
Registered: November 2016
Location: Jamestown
Junior Member
What I am trying to do, overall, is build an application launcher program, (similar to PStart [at pegtop(dot)net] with the ability to display a referenced icon/image(from column values) based off of the selected item in the array. I started off by using the AddressBookXML2 example as a template, but I have no idea how to add an image display that changes based off of the selected array item.

Here is the full code that I currently have figured out:
#include <CtrlLib/CtrlLib.h>
#include <Report/Report.h>

using namespace Upp;

#define LAYOUTFILE <AddressBookXML2/AddressBook.lay>
#include <CtrlCore/lay.h>

#define TAG_PATHLIST "AddressBook"
#define TAG_ITEM "person"
#define TAG_NAME "name"
#define TAG_EXEPATH "surname"
#define TAG_ICONPATH "address"
#define TAG_IMAGEPATH "email"

class AddressBook : public WithAddressBookLayout<TopWindow> {
	WithModifyLayout<ParentCtrl> modify;
	WithSearchLayout<ParentCtrl> search;
	FileSel fs;
	String  filename;

	void SetupSearch();
	void Add();
	void Change();
	void Search();
	void Open();
	void Save();
	void SaveAs();
	void Print();
	void Quit();
	void FileMenu(Bar& bar);
	void MainMenu(Bar& bar);

	typedef AddressBook CLASSNAME;

public:
	void Serialize(Stream& s);

	AddressBook();
};

AddressBook::AddressBook()
{
	CtrlLayout(*this, "Address book");
	CtrlLayout(modify);
	CtrlLayout(search);
	tab.Add(modify, "Modify");
	tab.Add(search, "Search");
	ActiveFocus(search.name);
	search.oname = true;
	search.oname <<= search.osurname <<= search.oaddress
	             <<= search.oemail <<= THISBACK(SetupSearch);
	array.AddColumn(TAG_NAME, "Name");
	array.AddColumn(TAG_EXEPATH, "Exe");
	array.AddColumn(TAG_ICONPATH, "Icon");
	array.AddColumn(TAG_IMAGEPATH, "Image");
	modify.add <<= THISBACK(Add);
	modify.change <<= THISBACK(Change);
	search.search <<= THISBACK(Search);
	SetupSearch();
	fs.AllFilesType();
	menu.Set(THISBACK(MainMenu));
}

void AddressBook::FileMenu(Bar& bar)
{
	bar.Add("Open..", CtrlImg::open(), THISBACK(Open));
	bar.Add("Save", CtrlImg::save(), THISBACK(Save));
	bar.Add("Save as..", CtrlImg::save_as(), THISBACK(SaveAs));
	bar.Separator();
	bar.Add("Print", CtrlImg::print(), THISBACK(Print));
	bar.Separator();
	bar.Add("Quit", THISBACK(Quit));
}

void AddressBook::MainMenu(Bar& bar)
{
	bar.Add("File", THISBACK(FileMenu));
}

void AddressBook::SetupSearch()
{
	search.name.Enable(search.oname);
	search.surname.Enable(search.osurname);
	search.address.Enable(search.oaddress);
	search.email.Enable(search.oemail);
}

void AddressBook::Add()
{
	array.Add(~modify.name, ~modify.surname, ~modify.address, ~modify.email);
	array.GoEnd();
	modify.name <<= modify.surname <<= modify.address <<= modify.email <<= Null;
	ActiveFocus(modify.name);
}

void AddressBook::Change()
{
	if(array.IsCursor()) {
		array.Set(0, ~modify.name);
		array.Set(1, ~modify.surname);
		array.Set(2, ~modify.address);
		array.Set(3, ~modify.email);
	}
}

bool Contains(const String& text, const String& substr)
{
	for(const char *s = text; s <= text.End() - substr.GetLength(); s++)
		if(strncmp(s, substr, substr.GetLength()) == 0)
			return true;
	return false;
}

void AddressBook::Search()
{
	if(!array.GetCount()) return;
	bool sc = true;
	array.ClearSelection();
	for(int i = 0; i < array.GetCount(); i++) {
		if((!search.oname || Contains(array.Get(i, 0), ~search.name)) &&
		   (!search.osurname || Contains(array.Get(i, 1), ~search.surname)) &&
		   (!search.oaddress || Contains(array.Get(i, 2), ~search.address)) &&
		   (!search.oemail || Contains(array.Get(i, 3), ~search.email))) {
			array.Select(i);
			if(sc) {
				array.SetCursor(i);
				array.CenterCursor();
				sc = false;
			};
		}
	}
}

void AddressBook::Open()
{
	if(!fs.ExecuteOpen()) return;
	filename = fs;
	array.Clear();
	try {
		String d = LoadFile(filename);
		XmlNode n = ParseXML(d);
		if(n.GetCount()==0 || n[0].GetTag() != TAG_PATHLIST)
			throw XmlError("No AddressBook tag");
		const XmlNode &ab = n[0];
		for(int i = 0; i < ab.GetCount(); i++) {
			const XmlNode &person = ab[i];
			if(person.IsTag(TAG_ITEM))
				array.Add(person[TAG_NAME].GatherText(),
				          person[TAG_EXEPATH].GatherText(),
				          person[TAG_ICONPATH].GatherText(),
				          person[TAG_IMAGEPATH].GatherText());
		}
	}
	catch(XmlError &e) {
		Exclamation("Error reading the input file:&\1" + e);
	}
}

void AddressBook::Save()
{
	if(IsEmpty(filename)) {
		SaveAs();
		return;
	}
	XmlNode n;
	XmlNode &ab = n.Add(TAG_PATHLIST);
	for(int i=0; i < array.GetCount(); i++) {
		XmlNode &person = ab.Add(TAG_ITEM);
		person.Add(TAG_NAME).Add().CreateText(array.Get(i, TAG_NAME));
		person.Add(TAG_EXEPATH).Add().CreateText(array.Get(i, TAG_EXEPATH));
		person.Add(TAG_ICONPATH).Add().CreateText(array.Get(i, TAG_ICONPATH));
		person.Add(TAG_IMAGEPATH).Add().CreateText(array.Get(i, TAG_IMAGEPATH));
	}
	if(!SaveFile(filename, AsXML(n)))
		Exclamation("Error saving the file!");
}

void AddressBook::SaveAs()
{
	if(!fs.ExecuteSaveAs()) return;
	filename = fs;
	Save();
}

void AddressBook::Print()
{
	String qtf;
	qtf = "{{1:1:1:1 Name:: Surname:: Address:: Email";
	for(int i = 0; i < array.GetCount(); i++)
		for(int q = 0; q < 4; q++)
			qtf << ":: " << DeQtf((String)array.Get(i, q));
	Report report;
	report << qtf;
	Perform(report);
}

void AddressBook::Quit()
{
	Break();
}

void AddressBook::Serialize(Stream& s)
{
	int version = 0;
	s / version;
	s % search.oname % search.osurname % search.oaddress % search.oemail;
	s % fs;
	SetupSearch();
}

GUI_APP_MAIN
{
	AddressBook ab;
	LoadFromFile(ab);
	ab.Run();
	StoreToFile(ab);
}


I don't have the modify menu changed yet for file browsing, as I am mainly trying to get the icon/image display portion figured out.


When all is said and done, I would like the GUI to look something like this(minus the search tab at the top) with the displayed Image and Icon in the empty space in the lower right:

index.php?t=getfile&id=5070&private=0


Any help is appreciated, just be warned that I have little experience with program coding (aside from html and batch, which is what I normally do), so please use layman's terms Smile.
  • Attachment: Capture.JPG
    (Size: 40.58KB, Downloaded 132 times)
Previous Topic: Row color when lost focus.
Next Topic: GridCtrl Paste issue (fixed)
Goto Forum:
  


Current Time: Sun Nov 17 01:06:08 CET 2019

Total time taken to generate the page: 0.04594 seconds