Page 1 of 1

wxListCtrl set application icon

Posted: Mon Sep 19, 2016 7:39 pm
by Oleg
I am going to use wxListCtrl http://docs.wxwidgets.org/trunk/classwx_list_ctrl.html in order to list directory files.
List has been created successfully. And now i am going to show file's icon. I have set icon with wxArtProvider http://docs.wxwidgets.org/trunk/classwx ... vider.html, and have got result as shown below:
ArtProvider.png
ArtProvider.png (8.84 KiB) Viewed 2335 times
But my goal is to display icons as shown on screenshot below:
goal.png
goal.png (14.42 KiB) Viewed 2335 times
How can i do this? Thanks.

Re: wxListCtrl set application icon

Posted: Mon Sep 19, 2016 7:49 pm
by catalin
I think you should get icons from something like wxTheMimeTypesManager->GetFileTypeFromExtension("pdf")->GetIcon(...);
..but do check against NULL returned wxFileType.

Re: wxListCtrl set application icon

Posted: Mon Sep 19, 2016 8:30 pm
by PB
Unfortunately, using wxWidgets methods (see wxFileCtrl or wxDirCtrl) for extracting icons on MSW won't probably provide user experience comparable with native shell view available through e.g. Windows Explorer or IFileDialog (obtained with SHGetFileInfo()). For example, no overlay icons. OTOH, most users probably never saw an overlay icon once in their life (except for the link overlays)...

Re: wxListCtrl set application icon

Posted: Mon Sep 19, 2016 9:07 pm
by doublemax
@Oleg: I hope you knew about wxFileCtrl and didn't duplicate all its functionality.
http://docs.wxwidgets.org/trunk/classwx_file_ctrl.html

@PB: I know you worked on IFileDialog. Would a native wxFileCtrl/wxDirCtrl be possible?

Re: wxListCtrl set application icon

Posted: Tue Sep 20, 2016 7:53 am
by PB
doublemax wrote:@PB: I know you worked on IFileDialog. Would a native wxFileCtrl/wxDirCtrl be possible?
Sorry, I know nothing about shell programming. implementing wxDirDialog with IFileDialog was very simple, just wrapping few API calls.

To create a native MSW wxFileCtrl/wxDirCtrl, I think one would have to implement/wrap IShellBrowser or IFolderView or IShellView or something similar. While this seems not difficult, it probably is still non-trivial.

But perhaps at least just implementing the native MSW icons including overlays would be a step in a right direction. The question is, how many people actually use those two controls, instead of using the respective common dialogs.

Re: wxListCtrl set application icon

Posted: Tue Sep 20, 2016 8:06 am
by Oleg
doublemax wrote:@Oleg: I hope you knew about wxFileCtrl and didn't duplicate all its functionality.
http://docs.wxwidgets.org/trunk/classwx_file_ctrl.html
Is it possible to create something like that?
like_that.png
Note. I need not to create file/directory chooser dialog. I need to create a list of file like it does TotalCommander. So it is possible with wxFileCtrl? Thanks.

Re: wxListCtrl set application icon

Posted: Tue Sep 20, 2016 8:18 am
by doublemax
Note. I need not to create file/directory chooser dialog. I need to create a list of file like it does TotalCommander. So it is possible with wxFileCtrl? Thanks
Yes, that's what wxFileCtrl does. Check the "widgets" sample that comes with wxWidgets to see it in action.

Re: wxListCtrl set application icon

Posted: Tue Sep 20, 2016 8:20 am
by doublemax
But perhaps at least just implementing the native MSW icons including overlays would be a step in a right direction.
AFAIK the icons themselves should be identical to Explorer. Just without the overlays. I don't see the missing overlays as a real problem though.

Re: wxListCtrl set application icon

Posted: Tue Sep 20, 2016 8:31 am
by Oleg
So, i built sample. And now a have next question: Is it possible to add additional columns to wxFileCtrl like (ext, date etc..)? and remove fields shown on screenshot?
show_to.png
I do not see any options or styles in order to do that.

Re: wxListCtrl set application icon

Posted: Tue Sep 20, 2016 8:40 am
by doublemax
And now a have next question: Is it possible to add additional columns to wxFileCtrl like (ext, date etc..)? and remove fields shown on screenshot?
I'm afraid not.

Re: wxListCtrl set application icon

Posted: Tue Sep 20, 2016 8:41 am
by Oleg
As an option i think i can use wxGenericDirCtrl http://docs.wxwidgets.org/trunk/classwx ... _ctrl.html but this control also does not support additional colums. So, i guess it is better to use wxListCtrl. Guys, what do you think about this?

Re: wxListCtrl set application icon

Posted: Tue Sep 20, 2016 8:43 am
by doublemax
i guess it is better to use wxListCtrl. Guys, what do you think about this?
Depends on how far you already are with your solution. If you're almost done, go with it. Otherwise you could try to just copy the whole wxGenericDirCtrl file into your project, rename the class and all references and use that as a basis for your modifications.

Re: wxListCtrl set application icon

Posted: Tue Sep 20, 2016 9:18 am
by Oleg
Looks like it is better to use wxListCtrl for me. Will solve icon issue as @catalin told.
catalin wrote:I think you should get icons from something like wxTheMimeTypesManager->GetFileTypeFromExtension("pdf")->GetIcon(...);
..but do check against NULL returned wxFileType.

Re: wxListCtrl set application icon

Posted: Tue Sep 20, 2016 8:29 pm
by Oleg
Hi, guys.
I am trying use system icon in this way (as @catalin told.)
This is my code:

Code: Select all

	wxArrayString arr;
	wxTheMimeTypesManager->EnumAllFileTypes(arr);

	wxImageList* imageList = new wxImageList(16, 16);
	imageList->Add(wxArtProvider::GetIcon(wxART_GO_TO_PARENT)); // index = 0;
	imageList->Add(wxArtProvider::GetIcon(wxART_FOLDER)); // index = 1;
	imageList->Add(wxArtProvider::GetIcon(wxART_EXECUTABLE_FILE)); // index = 2;
	for (const wxString& mime : arr)
	{
		wxSharedPtr<wxFileType> ft(wxTheMimeTypesManager->GetFileTypeFromMimeType(mime));
		if (!ft)
			continue;
		wxIconLocation iconLoc;
		if (!ft->GetIcon(&iconLoc))
			continue;
		wxArrayString exts;
		if (!ft->GetExtensions(exts))
			continue;

		wxIcon icon(iconLoc);
		int extIndex = imageList->Add(icon);
		for (const wxString& ext : exts)
		{
			extMap_.insert(ExtHashMap::value_type(ext, extIndex));
		}
	}
	SetImageList(imageList, wxIMAGE_LIST_SMALL);
But GUI is loaded i get this error dialog:
error.png
error.png (45.57 KiB) Viewed 2229 times
Code has been debugged and there is no error. It shows only when GUI is loaded.
What am i doing wrong?

Re: wxListCtrl set application icon

Posted: Tue Sep 20, 2016 9:22 pm
by doublemax

Code: Select all

wxIcon icon(iconLoc);
You need to check if the icon is ok before continuing.

Besides, i'm not sure it's a good idea to get the icons for *all* mimetypes at once. Especially on old Windows systems there may be many zombie entries in the registry. Before you start optimizing your code, i'd suggest to get the icon for each file individually. Of course you always need a fallback icon for the case that the retrieval fails.