wxListCtrl set application icon

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
User avatar
Oleg
Earned a small fee
Earned a small fee
Posts: 23
Joined: Wed May 25, 2016 8:07 pm
Location: Ukraine

wxListCtrl set application icon

Post 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 3701 times
But my goal is to display icons as shown on screenshot below:
goal.png
goal.png (14.42 KiB) Viewed 3701 times
How can i do this? Thanks.
catalin
Moderator
Moderator
Posts: 1618
Joined: Wed Nov 12, 2008 7:23 am
Location: Romania

Re: wxListCtrl set application icon

Post by catalin »

I think you should get icons from something like wxTheMimeTypesManager->GetFileTypeFromExtension("pdf")->GetIcon(...);
..but do check against NULL returned wxFileType.
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4204
Joined: Sun Jan 03, 2010 5:45 pm

Re: wxListCtrl set application icon

Post 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)...
User avatar
doublemax
Moderator
Moderator
Posts: 19158
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxListCtrl set application icon

Post 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?
Use the source, Luke!
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4204
Joined: Sun Jan 03, 2010 5:45 pm

Re: wxListCtrl set application icon

Post 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.
User avatar
Oleg
Earned a small fee
Earned a small fee
Posts: 23
Joined: Wed May 25, 2016 8:07 pm
Location: Ukraine

Re: wxListCtrl set application icon

Post 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.
User avatar
doublemax
Moderator
Moderator
Posts: 19158
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxListCtrl set application icon

Post 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.
Use the source, Luke!
User avatar
doublemax
Moderator
Moderator
Posts: 19158
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxListCtrl set application icon

Post 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.
Use the source, Luke!
User avatar
Oleg
Earned a small fee
Earned a small fee
Posts: 23
Joined: Wed May 25, 2016 8:07 pm
Location: Ukraine

Re: wxListCtrl set application icon

Post 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.
User avatar
doublemax
Moderator
Moderator
Posts: 19158
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxListCtrl set application icon

Post 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.
Use the source, Luke!
User avatar
Oleg
Earned a small fee
Earned a small fee
Posts: 23
Joined: Wed May 25, 2016 8:07 pm
Location: Ukraine

Re: wxListCtrl set application icon

Post 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?
User avatar
doublemax
Moderator
Moderator
Posts: 19158
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxListCtrl set application icon

Post 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.
Use the source, Luke!
User avatar
Oleg
Earned a small fee
Earned a small fee
Posts: 23
Joined: Wed May 25, 2016 8:07 pm
Location: Ukraine

Re: wxListCtrl set application icon

Post 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.
User avatar
Oleg
Earned a small fee
Earned a small fee
Posts: 23
Joined: Wed May 25, 2016 8:07 pm
Location: Ukraine

Re: wxListCtrl set application icon

Post 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 3595 times
Code has been debugged and there is no error. It shows only when GUI is loaded.
What am i doing wrong?
User avatar
doublemax
Moderator
Moderator
Posts: 19158
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxListCtrl set application icon

Post 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.
Use the source, Luke!
Post Reply