Page 3 of 3

Re: Showing CheckBox and raising mouse events like listctrl

Posted: Wed Aug 08, 2007 10:12 pm
by gururamnath
wxPython components are almost like Delphi components; there are lots of quality components that can embellish your UI. Some people do prefer C++ because there are lots of 3rd party libs and also widely used in the industry and people can leverage their existing skills.
Since the api calls are similar to C++, I hope some one can port your components to C++ too.

reg the checkbox feature:
I have included a feature to display the checkbox in each treelist item, I'll upload the code in the weekend. If you want to test the code meanwhile, please drop me a mail at [email protected] .

Thanks,
Guru Kathiresan

Re: Showing CheckBox and raising mouse events like listctrl

Posted: Fri Aug 10, 2007 1:18 pm
by gururamnath
I have uploaded the modified control that supports check boxes at :
http://twinforms.com/wxlib_wxtreelistctrl.htm

-Guru Kathiresan

Re: Showing CheckBox and raising mouse events like listctrl

Posted: Thu Nov 22, 2007 1:27 pm
by chowette
I was a long user of the wxTreeListCtrl widget from wxCode and
recently tried to switch to your enhanced version.
However, I did found some problems compiling it with Visual Studio
2005 and wxWidgets 2.8.4 ( I know I'm late with wx versions )

The biggest problem I found was some missing function that prevented the sample and my application to link.
wxTreeListMainWindow::SetItemChecked() and wxTreeListMainWindow::GetItemChecked() were defined and used in treelistctrl.cpp
The sample never use those function and maybe BCC is smarter than visual by not compiling this unused function.

The second problem is about the special case for column adding. It does not work as expected, the first column added is always at the end.
The comment on the wxForum from aval57 say that it need code on is mingw so I have put it into #if defined(__MINGW32__) as it work without it on my win XP with VC8

The patch also remove some warning.

Here comes the patch...

Code: Select all

diff -ru libs\treelistctrl.cpp new\treelistctrl.cpp
--- libs\treelistctrl.cpp	Wed Aug 08 14:53:28 2007
+++ new\treelistctrl.cpp	Wed Nov 21 17:32:49 2007
@@ -944,7 +944,7 @@
     {
         if(m_col_itemstate.GetCount() > 0)
         {
-            return this->m_col_itemstate[column];
+            return !!this->m_col_itemstate[column];
         }
         return false;
     }
@@ -2020,7 +2020,9 @@
     return;
 #endif
 
+#if !wxCHECK_VERSION(2, 8, 0)
     dc.BeginDrawing();
+#endif
     dc.SetFont( GetFont() );
 
     // width and height of the entire header window    
@@ -2119,7 +2121,9 @@
 		wxRendererNative::GetDefault().DrawHeaderButton(this,dc,wxRect(x, HEADER_OFFSET_Y, more_w, h-2));
     }
 
+#if !wxCHECK_VERSION(2, 8, 0)
     dc.EndDrawing();
+#endif
 }
 
 void wxTreeListHeaderWindow::DrawCurrent()
@@ -2273,8 +2277,10 @@
 	
 #if defined(__WXMSW__) &&  defined(_NATIVE_WIN32_) 
 	int inPos = m_columns.GetCount();
+#if defined(__MINGW32__)
 	if (inPos != 0)
 		inPos = inPos - 1;
+#endif // __MINGW32__
 	DoInsertItem(m_hndlHeader,inPos,colInfo.GetWidth(), colInfo.GetText().c_str());
 #endif        	
     m_columns.Add (colInfo);
@@ -5244,6 +5250,24 @@
     else                return ((wxTreeListItem*) itemId.m_pItem)->GetText (column);
 }
 
+void wxTreeListMainWindow::SetItemChecked (const wxTreeItemId& itemId, const int column,
+										bool checked) {
+	wxCHECK_RET (itemId.IsOk(), _T("invalid tree item"));
+
+	wxClientDC dc (this);
+	wxTreeListItem *item = (wxTreeListItem*) itemId.m_pItem;
+	item->SetItemChecked(column, checked);
+	CalculateSize (item, dc);
+	RefreshLine (item);
+}
+
+bool wxTreeListMainWindow::GetItemChecked (const wxTreeItemId& itemId, const int column)
+{
+	wxCHECK_MSG (itemId.IsOk(), (wxTreeListItemType)0, _T("invalid tree item") );
+	wxTreeListItem *item = (wxTreeListItem*) itemId.m_pItem;
+	return item->GetItemChecked (column);
+}
+
 void wxTreeListMainWindow::SetItemType (const wxTreeItemId& itemId, const int column, const wxTreeListItemType itemtype, bool checked)
 {
     wxCHECK_RET (itemId.IsOk(), _T("invalid tree item"));
@@ -5256,7 +5280,7 @@
 
 wxTreeListItemType wxTreeListMainWindow::GetItemType (const wxTreeItemId& itemId, const int column)
 {
-    wxCHECK_MSG (itemId.IsOk(), 0, _T("invalid tree item") );
+    wxCHECK_MSG (itemId.IsOk(), (wxTreeListItemType)0, _T("invalid tree item") );
     wxTreeListItem *item = (wxTreeListItem*) itemId.m_pItem;
     return (wxTreeListItemType)item->GetItemType (column);
 }


Posted: Thu Jan 10, 2008 11:37 am
by phlox81
I started using your control today.
I switched from a wxTreeCtrl.

You made a great Control, but some minor Issues I have encountered:

first, there is no equality with the signature from wxTreeCtrl,
f.e. AddRoot, or AppendItem. I had to replace every call to those, without gaining something.

Second, your control does look different from a treectrl.
I made 2 Screenshots, showing your and the wxTreeCtrl.
The Lines and buttons are placed differently, the Rootpart, and the Buttons/Lines are drawn differently.
Is there a Style to change this?

And I also found a bug:

Code: Select all

treelist->AddColumn(_("Networktree"),256,wxLIST_FORMAT_LEFT);
  treelist->AddColumn(_("Status"),64,wxLIST_FORMAT_CENTER);
I would expect, that now Networktree is my first Column.
Which it is infact, except, that the headers are switched, Status is first, with a width of 64 in Header and 256 in the treectrl.

Heres a little fix for this:

Code: Select all

void wxTreeListHeaderWindow::AddColumn (const wxTreeListColumnInfo& colInfo) {
#if defined(__WXMSW__) &&  defined(_NATIVE_WIN32_)
	int inPos = m_columns.GetCount();
//	 if (inPos != 1)
//		inPos = inPos - 1;
// This fixes it, but not sure if theres a better workaround.
	DoInsertItem(m_hndlHeader,inPos,colInfo.GetWidth(), colInfo.GetText().c_str());
#endif
    m_columns.Add (colInfo);
    m_total_col_width += colInfo.GetWidth();
    m_owner->AdjustMyScrollbars();
    m_owner->m_dirty = true;
}
Also the Flag wxTR_EDIT_LABELS has no effect on the Treectrl.
To make them editable, you have to call SetColumnEditable(0) and SetColumnPickType(0,wxTR_COLUMN_TEXT);
Also here is a difference to the wxTreeCtrl: The "editsquare" around the textctrl is not drawn.

regards

phlox

Posted: Mon Jan 21, 2008 7:36 pm
by gururamnath
Hello,
I have merged most of the changes proposed by chowette and one change proposed by phlox81.

I have added a new feature to make the item checked when click a checkbox and if it is not the selected item. If I put a break point in the on click event it works fine but if I remove the break point it does not work. Anyone want trouble shoot this issue ? Let me know, I'll send the modified source asap.

Thanks,
Guru Kathiresan

Posted: Thu Jan 24, 2008 12:07 pm
by phlox81
Has this control ever been build under wxGTK?

Just tried it, and I get a lot of errors:

- wxComboBox header is missing in .cpp file.
- use of lstrcat is illegal under linux, strcat solves this problem (dunno, but probably there is also a header needed, <cstring> and <cstdio.h> did I include previous)
- Some arraydefinitions are mixed with include commands, first include, then do makro.
- missing Include for wxTextValidator
- class wxEditLongValidator - missing copy constructor, its parent is private
needed here:

Code: Select all

around line 4790: if (pick_type == wxTR_COLUMN_INT_TEXT)

				text->SetValidator(wxEditLongValidator(NULL));
fix:

Code: Select all

wxEditLongValidator(const  wxEditLongValidator& copy):val(val){}
Also some semicolons after macros are wrong:

Code: Select all

IMPLEMENT_DYNAMIC_CLASS(wxTreeListCtrl, wxControl);



BEGIN_EVENT_TABLE(wxTreeListCtrl, wxControl)

    EVT_SIZE(wxTreeListCtrl::OnSize)

END_EVENT_TABLE();

Posted: Sat Jan 26, 2008 3:08 pm
by Rocketmagnet
Hi all,

I'm having a lot of trouble trying to compile this in VC++. I get the following errors:

commctrl.h(29) : error C2146: syntax error : missing ';' before identifier 'HRESULT'
commctrl.h(29) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
prsht.h(97) : error C2065: 'CALLBACK' : undeclared identifier
prsht.h(97) : error C2065: 'LPFNPSPCALLBACKA' : undeclared identifier
prsht.h(97) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
prsht.h(97) : fatal error C1903: unable to recover from previous error(s); stopping compilation

It's strange that these errors aren't even in wxtreelistctrl.h or .ccp, and are in something entirely different. I've tried to find a reason for this (maybe a typo in a file which includes treelistctrl.h) but I've ruled that out.

Can anyone help me? please!

many thanks

hugo

Compiling

Posted: Fri Feb 01, 2008 6:06 pm
by Ludika
Hi all,

I'm having a lot of trouble trying to compile this in VC++. I get the following errors:
Same here,
I sometimes wish we all get rid of this Microsoft DLL crap someday...

PS: is there a list of successful os/compiler builds for this really useful class? thanks,
F.

Posted: Fri Feb 01, 2008 6:33 pm
by phlox81
uh, have you installed the windows SDK?
Actually those error messages have nothing to do with wxWidgets.

PlatformSDK

Posted: Sat Feb 02, 2008 2:07 pm
by Ludika
uh, have you installed the windows SDK?
Actually those error messages have nothing to do with wxWidgets.
You mean the platform SDK? no I didn't and would prefer not to have to...
I know they have nothing to do with wxWidgets but they only show up when compiling the wxTreeListCtrl stuff, we might be missing some preprocessor def or some inclusion, but all wxWidgets libraries compiled without a problem so why shouldn't this object?
I wish Mr. Guru would show up and say something or i'm afraid i'll have to strip most of the platform-specific and dll stuff from it's code to make it work.

BTW I'm not complaining, of course, it's a great contrib!

Posted: Sat Feb 02, 2008 4:35 pm
by Ludika
EDIT: I solved part of the problems by replacing the commctrl.h include with this:

Code: Select all

#ifdef __WXMSW__    
    #include "wx/msw/wrapcctl.h"
#endif 
and by linking also the adv lib (wxmsw28_adv.lib)

but i'm afraid the implementation of these guys is lost in space:
wxTreeListMainWindow::SetItemChecked
wxTreeListMainWindow::GetItemChecked

Any clue?! Almost there!!

:!:

Posted: Fri Feb 15, 2008 12:13 am
by Rocketmagnet
I did #include "wx/msw/wrapcctl.h", and that helped remove errors, but I'm still getting lots:

error C3861: 'wxGetInstance': identifier not found
warning C4018: '>=' : signed/unsigned mismatch
error C2065: 'wxFILTER_NUMERIC' : undeclared identifier
error C3861: 'wxTextValidator': identifier not found
error C2440: 'return' : cannot convert from 'int' to 'wxTreeListItemType'
Conversion to enumeration type requires an explicit cast (static_cast, C-style cast or function-style cast)


phlox81, I'm not exactly sure what you mean about replacing

Code: Select all

if (pick_type == wxTR_COLUMN_INT_TEXT)                                   
    text->SetValidator(wxEditLongValidator(NULL));
with

Code: Select all

wxEditLongValidator(const  wxEditLongValidator& copy):val(val){}
Do you mean I should replace both lines with that one line?

Has anyone else had this working? gururamnath, have you had this working?

Hugo

Posted: Fri Feb 15, 2008 1:27 pm
by phlox81
No, not replace it with that, you should add this Copyconstructor to the class.

And you need to include the wxTextValidator Header.

Posted: Wed Apr 02, 2008 7:28 am
by wpoeyer
I am also unable to compile this control.

After replacing the:

Code: Select all

#ifdef __WXMSW__    
    #include "commctrl.h"
#endif 


with

Code: Select all

#ifdef __WXMSW__    
    #include "wx/msw/wrapcctl.h" 
#endif
I get lot's of warning, which i will probably be able to fix, but the main problem are the linker error's. They are the same as Ludika has.

wxTreeListMainWindow::SetItemChecked
wxTreeListMainWindow::GetItemChecked

I am using Visual Studio 2005 & 2008 with de Platform SDK's delivered with them. My wxWidgets version is 2.8.7

[/code]

Posted: Sat Jun 07, 2008 6:00 am
by metalogic
Didn't want to make this thread any longer so I started a fresh one:

http://forums.wxwidgets.org/viewtopic.php?p=84770#84770