************************************************** *-- Class: cntmover (w:\sss\smna\proctrls.vcx) *-- ParentClass: container *-- BaseClass: container *-- Time Stamp: 06/22/09 05:33:11 PM *-- Mover class * DEFINE CLASS cntmover AS container Width = 516 Height = 221 BackStyle = 0 BorderWidth = 0 Name = "cntmover" *-- Array list of items DIMENSION arritems[1] ADD OBJECT cmdmoveone AS commandbutton_ WITH ; Top = 44, ; Left = 242, ; Height = 26, ; Width = 30, ; Anchor = 768, ; Picture = "..\..\vpme91\bitmaps\mover1.bmp", ; Caption = "", ; TabIndex = 4, ; ToolTipText = "Move", ; Name = "cmdMoveOne" ADD OBJECT cmdmoveall AS commandbutton_ WITH ; Top = 76, ; Left = 242, ; Height = 26, ; Width = 30, ; Anchor = 768, ; Picture = "..\..\vpme91\bitmaps\mover2.bmp", ; Caption = "", ; TabIndex = 5, ; ToolTipText = "Move All", ; Name = "cmdMoveAll" ADD OBJECT cmdremoveone AS commandbutton_ WITH ; Top = 118, ; Left = 242, ; Height = 26, ; Width = 30, ; Anchor = 768, ; Picture = "..\..\vpme91\bitmaps\mover_1.bmp", ; Caption = "", ; TabIndex = 6, ; ToolTipText = "Remove", ; Name = "cmdRemoveOne" ADD OBJECT cmdremoveall AS commandbutton_ WITH ; Top = 150, ; Left = 242, ; Height = 26, ; Width = 30, ; Anchor = 768, ; Picture = "..\..\vpme91\bitmaps\mover_2.bmp", ; Caption = "", ; TabIndex = 7, ; ToolTipText = "Remove All", ; Name = "cmdRemoveAll" ADD OBJECT lstsource AS listbox_ WITH ; OLEDragMode = 1, ; OLEDropMode = 1, ; FontName = "Arial", ; Anchor = 45, ; RowSourceType = 0, ; RowSource = "", ; Value = "", ; Height = 204, ; Left = 0, ; MultiSelect = .T., ; TabIndex = 3, ; Top = 17, ; Width = 228, ; Name = "lstSource" ADD OBJECT lblsource AS label_ WITH ; Caption = "Source", ; Left = 3, ; Top = 0, ; TabIndex = 2, ; Name = "lblSource" ADD OBJECT lbldestination AS label_ WITH ; Caption = "Destination", ; Height = 17, ; Left = 291, ; Top = 0, ; Width = 65, ; TabIndex = 8, ; Name = "lblDestination" ADD OBJECT lstdestination AS listbox_ WITH ; OLEDragMode = 1, ; OLEDropMode = 1, ; FontName = "Arial", ; Anchor = 45, ; RowSourceType = 0, ; RowSource = "", ; Value = "", ; Height = 204, ; Left = 288, ; MultiSelect = .T., ; TabIndex = 9, ; Top = 17, ; Width = 228, ; Name = "lstDestination" *-- Moves item from one list to another PROCEDURE moveone LPARAMETERS toFrom, toTo LOCAL lcSelect, lnIndex, lnTotItem lnIndex = m.toFrom.LISTINDEX IF m.lnIndex # 0 lcSelect = toFrom.LIST(m.lnIndex,1) toTo.ADDITEM(m.lcSelect) toFrom.REMOVEITEM(m.lnIndex) THIS.REFRESH() ENDIF ENDPROC *-- Moves all items from one list to another PROCEDURE moveall LPARAMETERS toFrom, toTo LOCAL lcSelect, lnIndex, lnTotItem lnTotItem = toFrom.LISTCOUNT FOR lnIndex = 1 TO m.lnTotItem lcSelect = toFrom.LIST(m.lnIndex,1) toTo.ADDITEM(m.lcSelect) NEXT *!* for lnIndex = 1 to m.lnTotItem *!* toFrom.removelistitem(m.lnIndex) *!* next toFrom.CLEAR() THIS.REFRESH() ENDPROC *-- Populates source listbox PROCEDURE populatesource LPARAMETERS taItemsList this.Populate(this.lstSource, @taItemsList) ENDPROC *-- Populate listbox PROCEDURE populate LPARAMETERS toList, taListItems LOCAL lnI IF TYPE("taListItems[1]") = "C" toList.Clear() && Remove all items first FOR lnI = 1 TO ALEN(taListItems,1) toList.AddItem(taListItems[m.lnI]) NEXT ENDIF ENDPROC *-- Populates destination listbox PROCEDURE populatedestination LPARAMETERS taItemsList this.Populate(this.lstDestination, @taItemsList) ENDPROC *-- Returns source list items PROCEDURE getsourceitems RETURN this.GetItems(this.lstSource) ENDPROC *-- Returns destination listbox items PROCEDURE getdestinationitems RETURN this.GetItems(this.lstDestination) ENDPROC *-- Generic internal method to return items PROCEDURE getitems LPARAMETERS toList LOCAL lnI DIMENSION this.arrItems[1] && to clear the array FOR lnI = 1 TO toList.ListCount DIMENSION this.arrItems[m.lnI] this.arrItems[m.lnI] = toList.ListItem[m.lnI] NEXT return @this.arrItems ENDPROC *-- Sets source label caption PROCEDURE setsourcelabel LPARAMETERS tcCaption this.SetCaption(this.lblSource, tcCaption) ENDPROC *-- Sets destination label caption PROCEDURE setdestinationlabel LPARAMETERS tcCaption this.SetCaption(this.lblDestination, tcCaption) ENDPROC *-- Sets caption for the label (Source or Destination) PROCEDURE setcaption LPARAMETERS toLabel, tcCaption WITH toLabel .Caption = m.tcCaption .visible = .visible endwith ENDPROC PROCEDURE Refresh IF THIS.lstSource.LISTCOUNT = 0 &&OR THIS.lstSource.LISTINDEX = 0 STORE .F. TO THIS.cmdMoveOne.ENABLED, THIS.cmdMoveAll.ENABLED ELSE THIS.cmdMoveOne.ENABLED = .T. STORE THIS.lstSource.LISTCOUNT > 1 TO THIS.cmdMoveAll.ENABLED ENDIF IF THIS.lstDestination.LISTCOUNT = 0 && OR THIS.lstDestination.LISTINDEX = 0 STORE .F. TO THIS.cmdRemoveOne.ENABLED, THIS.cmdRemoveAll.ENABLED ELSE THIS.cmdRemoveOne.ENABLED = .T. STORE THIS.lstDestination.LISTCOUNT > 1 TO THIS.cmdRemoveAll.ENABLED ENDIF ENDPROC PROCEDURE Init ** Would changing anchor settings be enough for auto-resize? DODEFAULT() LOCAL lnAdjust, lnButtonsHeight, lnNewTop, lnBetweenListsSpace, lnExtraWidth STORE (this.Height - this.lstDestination.Top - 2) TO this.lstDestination.Height, this.lstSource.Height lnButtonsHeight = 132 lnNewTop = (this.Height - m.lnButtonsHeight)/2 lnAdjust = m.lnNewTop - this.cmdMoveOne.Top this.cmdMoveOne.Top = m.lnNewTop + m.lnAdjust this.cmdMoveAll.Top = this.cmdMoveAll.Top + m.lnAdjust this.cmdReMoveOne.Top = this.cmdReMoveOne.Top + m.lnAdjust this.cmdReMoveAll.Top = this.cmdReMoveAll.Top + m.lnAdjust lnBetweenListsSpace = this.lstDestination.Left - this.lstSource.Width && assuming that lstSource.Left = 0 lnExtraWidth = (this.Width - (2*this.lstDestination.Width + m.lnBetweenListsSpace))/2 STORE (this.lstDestination.Width + m.lnExtraWidth) TO this.lstSource.Width, this.lblDestination.Width STORE (this.cmdMoveAll.Left + m.lnExtraWidth) TO this.cmdMoveAll.Left, this.cmdMoveOne.Left, ; this.cmdReMoveAll.Left, this.cmdReMoveOne.Left this.lblDestination.Left = this.lblDestination.Left + m.lnExtraWidth this.lstDestination.Left = this.lstDestination.Left + m.lnExtraWidth ENDPROC *-- Refreshes the enabled status of controls PROCEDURE show ENDPROC *-- Refresh dependent controls PROCEDURE refreshdependents ENDPROC PROCEDURE cmdmoveone.Click * Move the highlighted entry in the source listbox to the destination listbox. This.parent.MoveOne(this.Parent.lstSource, this.Parent.lstDestination) ENDPROC PROCEDURE cmdmoveall.Click * Move all entries in the source listbox to the destination listbox. this.Parent.MoveAll(this.Parent.lstSource, this.Parent.lstDestination) ENDPROC PROCEDURE cmdremoveone.Click * Remove the highlighted entry in the destination listbox. This.parent.MoveOne(this.Parent.lstDestination, this.Parent.lstSource) ENDPROC PROCEDURE cmdremoveall.Click * Move all entries in the destination listbox to the source listbox. this.Parent.MoveAll(this.Parent.lstDestination, this.Parent.lstSource) ENDPROC PROCEDURE lstsource.OLEDragDrop LPARAMETERS oDataObject, nEffect, nButton, nShift, nXCoord, nYCoord LOCAL ARRAY laTest2[1] LOCAL loSource, lnLoop loSource = oDataObject.GETDATA("VFP Source Object",@laTest2) IF VARTYPE(m.loSource)=='O' FOR lnLoop = m.loSource.LISTCOUNT TO 1 STEP -1 IF loSource.SELECTED(m.lnLoop) loSource.LISTINDEX=m.lnLoop THIS.ADDITEM(m.loSource.VALUE) loSource.REMOVEITEM(m.lnLoop) ENDIF ENDFOR ENDIF THIS.PARENT.REFRESH() ENDPROC PROCEDURE lstsource.DblClick * Move the highlighted entry in the source listbox to the destination listbox. This.parent.MoveOne(this, this.Parent.lstDestination) ENDPROC PROCEDURE lstsource.InteractiveChange this.Parent.RefreshDependents(this) ENDPROC PROCEDURE lstdestination.OLEDragDrop LPARAMETERS oDataObject, nEffect, nButton, nShift, nXCoord, nYCoord LOCAL ARRAY laTest2[1] LOCAL loSource, lnLoop loSource = oDataObject.GETDATA("VFP Source Object",@laTest2) IF VARTYPE(m.loSource)=='O' FOR lnLoop = m.loSource.LISTCOUNT TO 1 STEP -1 IF loSource.SELECTED(m.lnLoop) loSource.LISTINDEX=m.lnLoop THIS.ADDITEM(m.loSource.VALUE) loSource.REMOVEITEM(m.lnLoop) ENDIF ENDFOR ENDIF THIS.PARENT.REFRESH() ENDPROC PROCEDURE lstdestination.DblClick * Remove the highlighted entry in the destination listbox. This.MoveOne(this, this.Parent.lstSource) ENDPROC PROCEDURE lstdestination.InteractiveChange this.Parent.RefreshDependents(this) ENDPROC ENDDEFINE * *-- EndDefine: cntmover **************************************************