MCPcopy Create free account
hub / github.com/lxn/walk / SetModel

Method SetModel

src/pkg/walk/tableview.go:214–271  ·  view source on GitHub ↗

SetModel sets the TableModel that provides data to the *TableView.

(model TableModel)

Source from the content-addressed store, hash-verified

212
213// SetModel sets the TableModel that provides data to the *TableView.
214func (tv *TableView) SetModel(model TableModel) os.Error {
215 tv.SetSuspended(true)
216 defer tv.SetSuspended(false)
217
218 if tv.model != nil {
219 for _ = range tv.columns {
220 if FALSE == SendMessage(tv.hWnd, LVM_DELETECOLUMN, 0, 0) {
221 return newError("SendMessage(LVM_DELETECOLUMN)")
222 }
223 }
224
225 tv.detachModel()
226 }
227
228 tv.model = model
229
230 tv.itemChecker, _ = model.(ItemChecker)
231
232 if model != nil {
233 tv.attachModel()
234
235 tv.columns = model.Columns()
236
237 for i, column := range tv.columns {
238 if column.Format == "" {
239 tv.columns[i].Format = "%v"
240 }
241
242 var lvc LVCOLUMN
243
244 lvc.Mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM
245 lvc.ISubItem = int32(i)
246 lvc.PszText = syscall.StringToUTF16Ptr(column.Title)
247 if column.Width > 0 {
248 lvc.Cx = int32(column.Width)
249 } else {
250 lvc.Cx = 100
251 }
252
253 switch column.Alignment {
254 case AlignCenter:
255 lvc.Fmt = 2
256
257 case AlignFar:
258 lvc.Fmt = 1
259 }
260
261 j := SendMessage(tv.hWnd, LVM_INSERTCOLUMN, uintptr(i), uintptr(unsafe.Pointer(&lvc)))
262 if int(j) == -1 {
263 return newError("TableView.SetModel: Failed to insert column.")
264 }
265 }
266
267 return tv.setItemCount()
268 }
269
270 return nil
271}

Callers 2

mainFunction · 0.95
mainFunction · 0.80

Calls 7

detachModelMethod · 0.95
attachModelMethod · 0.95
setItemCountMethod · 0.95
SendMessageFunction · 0.85
newErrorFunction · 0.85
SetSuspendedMethod · 0.65
ColumnsMethod · 0.65

Tested by

no test coverage detected