]>
git.saurik.com Git - wxWidgets.git/blob - samples/xrc/custclas.cpp
020a14e4b5a6151f1fa1162388185fb8f095ff54
1 //-----------------------------------------------------------------------------
3 // Purpose: XML resources sample: A custom class to insert into a XRC file
4 // Author: Robert O'Connor (rob@medicalmnemonics.com), Vaclav Slavik
6 // Copyright: (c) Robert O'Connor and Vaclav Slavik
7 // Licence: wxWindows licence
8 //-----------------------------------------------------------------------------
10 //-----------------------------------------------------------------------------
12 //-----------------------------------------------------------------------------
15 #pragma implementation "custclas.h"
18 //-----------------------------------------------------------------------------
19 // Standard wxWindows headers
20 //-----------------------------------------------------------------------------
22 // For compilers that support precompilation, includes "wx/wx.h".
23 #include "wx/wxprec.h"
29 // For all others, include the necessary headers (this file is usually all you
30 // need because it includes almost all "standard" wxWindows headers)
35 //-----------------------------------------------------------------------------
36 // Header of this .cpp file
37 //-----------------------------------------------------------------------------
41 //-----------------------------------------------------------------------------
43 //-----------------------------------------------------------------------------
45 // Popup menu (PU) item control IDs. In this example, they aren't hooked up
46 // to any functions. Normally you would use these IDs in your event table, so
47 // that if one of these menu items is clicked, then a certain function is
50 PU_ADD_RECORD
= wxID_HIGHEST
+ 1,
55 // Columns of the listctrl (the leftmost one starts at 0, and so on).
56 // Allows easier code maintenance if want to add/rearrangement of listctrl's
64 //-----------------------------------------------------------------------------
65 // wxWindows macro: implement dynamic class
66 //-----------------------------------------------------------------------------
68 IMPLEMENT_DYNAMIC_CLASS( MyResizableListCtrl
, wxListCtrl
)
70 //-----------------------------------------------------------------------------
71 // Event table: connect the events to the handler functions to process them
72 //-----------------------------------------------------------------------------
74 BEGIN_EVENT_TABLE( MyResizableListCtrl
, wxListCtrl
)
75 // Something to do when right mouse down
76 EVT_RIGHT_DOWN( MyResizableListCtrl::ContextSensitiveMenu
)
77 // Something to do when resized
78 EVT_SIZE( MyResizableListCtrl::OnSize
)
81 //-----------------------------------------------------------------------------
83 //-----------------------------------------------------------------------------
85 // Constructor, including setting the dialog's m_configuration_section member
86 // to the incoming configuration_section string.
87 MyResizableListCtrl::MyResizableListCtrl( wxWindow
*parent
, wxWindowID id
,
88 const wxPoint
& pos
, const wxSize
& size
,
89 long style
, const wxValidator
& validator
,
90 const wxString
& name
)
91 : wxListCtrl( parent
, id
, pos
, size
, style
, validator
, name
)
94 // This listctrl needs to insert its columns in the constructor, since
95 // as soon as the listctrl is built, it is resized and grafted onto an
96 // "unknown" XRC placeholder. This induces an OnSize() event, calling the
97 // overrriden OnSize function for this class, which needs to have 3
98 // columns to resize (else an assert on WXGTK debug build).
99 InsertColumn( RECORD_COLUMN
, _("Record"), wxLIST_FORMAT_LEFT
, 140);
100 InsertColumn( ACTION_COLUMN
, _("Action"), wxLIST_FORMAT_LEFT
, 70);
101 InsertColumn( PRIORITY_COLUMN
, _("Priority"), wxLIST_FORMAT_LEFT
, 70 );
105 MyResizableListCtrl::~MyResizableListCtrl()
110 void MyResizableListCtrl::ContextSensitiveMenu( wxMouseEvent
& event
)
112 // Make an instance of a menu.
115 a_menu
.Append( PU_ADD_RECORD
, _( "Add a new record...") );
116 a_menu
.Append( PU_EDIT_RECORD
, _( "Edit selected record..." ) );
117 a_menu
.Append( PU_DELETE_RECORD
, _( "Delete selected record" ) );
119 // If no listctrl rows selected, then disable the menu items that
121 if ( GetSelectedItemCount() == 0 ) {
122 a_menu
.Enable( PU_EDIT_RECORD
, FALSE
);
123 a_menu
.Enable( PU_DELETE_RECORD
, FALSE
);
126 // Show the popup menu (wxWindow::PopupMenu ), at the x,y position
127 // of the click event
128 PopupMenu( &a_menu
, event
.GetPosition() );
132 void MyResizableListCtrl::OnSize( wxSizeEvent
&event
)
134 // Call our custom width setting function.
136 // REQURED event.Skip() call to allow this event to propagate
137 // upwards so others can do what they need to do in response to
143 void MyResizableListCtrl::SetColumnWidths()
145 // Get width of entire listctrl
146 int leftmostColumnWidth
= GetSize().x
;
148 // Subtract width of other columns, scrollbar, and some padding
149 leftmostColumnWidth
-= GetColumnWidth( ACTION_COLUMN
);
150 leftmostColumnWidth
-= GetColumnWidth( PRIORITY_COLUMN
);
151 leftmostColumnWidth
-= wxSystemSettings::GetSystemMetric( wxSYS_VSCROLL_X
);
152 leftmostColumnWidth
-= 5;
154 // Set the column width to the new value.
155 SetColumnWidth( RECORD_COLUMN
, leftmostColumnWidth
);
157 // This is just a debug message in case you want to watch the
158 // events scroll by as you resize.
159 wxLogDebug( "Successfully set column widths" );