wxTreeTextCtrl::wxTreeTextCtrl( wxWindow *parent, const wxWindowID id,
bool *accept, wxString *res, wxTreeCtrl *owner,
const wxString &value, const wxPoint &pos, const wxSize &size,
+#if wxUSE_VALIDATORS
+# if defined(__VISAGECPP__)
+ int style, const wxValidator* validator, const wxString &name ) :
+# else
int style, const wxValidator& validator, const wxString &name ) :
+# endif
+#endif
wxTextCtrl( parent, id, value, pos, size, style, validator, name )
{
m_res = res;
m_dragCount = 0;
m_renameTimer = new wxTreeRenameTimer( this );
+
+ m_normalFont = wxSystemSettings::GetSystemFont( wxSYS_DEFAULT_GUI_FONT );
+ m_boldFont = wxFont( m_normalFont.GetPointSize(),
+ m_normalFont.GetFamily(),
+ m_normalFont.GetStyle(),
+ wxBOLD,
+ m_normalFont.GetUnderlined());
}
bool wxTreeCtrl::Create(wxWindow *parent, wxWindowID id,
const wxPoint& pos, const wxSize& size,
long style,
+#if wxUSE_VALIDATORS
+# if defined(__VISAGECPP__)
+ const wxValidator *validator,
+# else
const wxValidator &validator,
+# endif
+#endif
const wxString& name )
{
Init();
int image, int selImage,
wxTreeItemData *data)
{
- wxGenericTreeItem *parent = parentId.m_pItem;
- if ( !parent )
- {
- // should we give a warning here?
- return AddRoot(text, image, selImage, data);
- }
+ wxGenericTreeItem *parent = parentId.m_pItem;
+ if ( !parent )
+ {
+ // should we give a warning here?
+ return AddRoot(text, image, selImage, data);
+ }
- wxClientDC dc(this);
- wxGenericTreeItem *item = new wxGenericTreeItem(parent,
- text, dc,
- image, selImage,
- data);
+ wxClientDC dc(this);
+ wxGenericTreeItem *item =
+ new wxGenericTreeItem( parent, text, dc, image, selImage, data );
- if ( data != NULL )
- {
- data->m_pItem = item;
- }
+ if ( data != NULL )
+ {
+ data->m_pItem = item;
+ }
- parent->Insert( item, previous );
+ parent->Insert( item, previous );
- m_dirty = TRUE;
+ m_dirty = TRUE;
- return item;
+ return item;
}
wxTreeItemId wxTreeCtrl::AddRoot(const wxString& text,
int image, int selImage,
wxTreeItemData *data)
{
- wxCHECK_MSG( !m_anchor, wxTreeItemId(), wxT("tree can have only one root") );
+ wxCHECK_MSG( !m_anchor, wxTreeItemId(), wxT("tree can have only one root") );
- wxClientDC dc(this);
- m_anchor = new wxGenericTreeItem((wxGenericTreeItem *)NULL, text, dc,
+ wxClientDC dc(this);
+ m_anchor = new wxGenericTreeItem((wxGenericTreeItem *)NULL, text, dc,
image, selImage, data);
- if ( data != NULL )
- {
- data->m_pItem = m_anchor;
- }
+ if ( data != NULL )
+ {
+ data->m_pItem = m_anchor;
+ }
+
+ if (!HasFlag(wxTR_MULTIPLE))
+ {
+ m_current = m_key_current = m_anchor;
+ m_current->SetHilight( TRUE );
+ }
- Refresh();
- AdjustMyScrollbars();
+ Refresh();
+ AdjustMyScrollbars();
- return m_anchor;
+ return m_anchor;
}
wxTreeItemId wxTreeCtrl::PrependItem(const wxTreeItemId& parent,
wxTreeEvent event( wxEVT_COMMAND_TREE_ITEM_EXPANDING, GetId() );
event.m_item = item;
event.SetEventObject( this );
- if ( ProcessEvent( event ) && event.m_code )
+
+// if ( ProcessEvent( event ) && event.m_code ) TODO: Was this a typo ?
+ if ( ProcessEvent( event ) && !event.IsAllowed() )
{
// cancelled by program
return;
// FIXME: tree sorting functions are not reentrant and not MT-safe!
static wxTreeCtrl *s_treeBeingSorted = NULL;
-static int tree_ctrl_compare_func(wxGenericTreeItem **item1,
+static int LINKAGEMODE tree_ctrl_compare_func(wxGenericTreeItem **item1,
wxGenericTreeItem **item2)
{
wxCHECK_MSG( s_treeBeingSorted, 0, wxT("bug in wxTreeCtrl::SortChildren()") );
void wxTreeCtrl::PaintItem(wxGenericTreeItem *item, wxDC& dc)
{
- // render bold items in bold
- wxFont fontOld;
- wxFont fontNew;
-
if (item->IsBold())
- {
- fontOld = dc.GetFont();
- if (fontOld.Ok())
- {
- // VZ: is there any better way to make a bold variant of old font?
- fontNew = wxFont( fontOld.GetPointSize(),
- fontOld.GetFamily(),
- fontOld.GetStyle(),
- wxBOLD,
- fontOld.GetUnderlined());
- dc.SetFont(fontNew);
- }
- else
- {
- wxFAIL_MSG(wxT("wxDC::GetFont() failed!"));
- }
- }
+ dc.SetFont(m_boldFont);
long text_w = 0;
long text_h = 0;
dc.DrawText( item->GetText(), image_w + item->GetX(), item->GetY()
+ ((total_h > text_h) ? (total_h - text_h)/2 : 0));
- // restore normal font for bold items
- if (fontOld.Ok())
- {
- dc.SetFont( fontOld);
- }
+ // restore normal font
+ dc.SetFont( m_normalFont );
}
// Now y stands for the top of the item, whereas it used to stand for middle !
wxPaintDC dc(this);
PrepareDC( dc );
- dc.SetFont( wxSystemSettings::GetSystemFont( wxSYS_DEFAULT_GUI_FONT ) );
-
+ dc.SetFont( m_normalFont );
dc.SetPen( m_dottedPen );
+
+ // this is now done dynamically
//if(GetImageList() == NULL)
// m_lineHeight = (int)(dc.GetCharHeight() + 4);
void wxTreeCtrl::OnMouse( wxMouseEvent &event )
{
- if ( !(event.LeftUp() || event.LeftDClick() || event.Dragging()) ) return;
+ if ( !(event.LeftUp() || event.RightDown() || event.LeftDClick() || event.Dragging()) ) return;
if ( !m_anchor ) return;
if (item == NULL) return; /* we hit the blank area */
+ if (event.RightDown()) {
+ wxTreeEvent nevent(wxEVT_COMMAND_TREE_ITEM_RIGHT_CLICK,GetId());
+ nevent.m_item=item;
+ nevent.m_code=0;
+ nevent.SetEventObject(this);
+ GetEventHandler()->ProcessEvent(nevent);
+ return;
+ }
+
if (event.LeftUp() && (item == m_current) &&
(flags & wxTREE_HITTEST_ONITEMLABEL) &&
HasFlag(wxTR_EDIT_LABELS) )
long text_w = 0;
long text_h = 0;
- wxFont fontOld;
- wxFont fontNew;
if (item->IsBold())
- {
- fontOld = dc.GetFont();
- if (fontOld.Ok())
- {
- // VZ: is there any better way to make a bold variant of old font?
- fontNew = wxFont( fontOld.GetPointSize(),
- fontOld.GetFamily(),
- fontOld.GetStyle(),
- wxBOLD,
- fontOld.GetUnderlined());
- dc.SetFont(fontNew);
- }
- else
- {
- wxFAIL_MSG(wxT("wxDC::GetFont() failed!"));
- }
- }
+ dc.SetFont(m_boldFont);
dc.GetTextExtent( item->GetText(), &text_w, &text_h );
text_h+=2;
- // restore normal font for bold items
- if (fontOld.Ok())
- dc.SetFont( fontOld);
+ // restore normal font
+ dc.SetFont( m_normalFont );
int image_h = 0;
int image_w = 0;
wxClientDC dc(this);
PrepareDC( dc );
- dc.SetFont( wxSystemSettings::GetSystemFont( wxSYS_DEFAULT_GUI_FONT ) );
+ dc.SetFont( m_normalFont );
dc.SetPen( m_dottedPen );
//if(GetImageList() == NULL)