Auswahl XbpListBox [erledigt]

Grafische Primitive, XbaseParts und Darstellungsfragen allgemein.

Moderator: Moderatoren

Antworten
peternmb
1000 working lines a day
1000 working lines a day
Beiträge: 525
Registriert: Mi, 01. Feb 2006 16:22
Wohnort: 06618 Naumburg

Auswahl XbpListBox [erledigt]

Beitrag von peternmb »

Hallo,

kann ich in einer Multiselect-Listbox das Item feststellen auf das doppelgeklickt wurde?
Mit :getItem() erhalte ich natürlich ein Array mit allen markierten Elementen.

Code: Alles auswählen

oLbox:ItemSelected:={|| neu_name(oLbox:getdata([1])) }
Zuletzt geändert von peternmb am Fr, 22. Mär 2013 13:33, insgesamt 1-mal geändert.
Benutzeravatar
AUGE_OHR
Marvin
Marvin
Beiträge: 12903
Registriert: Do, 16. Mär 2006 7:55
Wohnort: Hamburg
Hat sich bedankt: 19 Mal
Danksagung erhalten: 44 Mal

Re: Auswahl XbpListBox

Beitrag von AUGE_OHR »

peternmb hat geschrieben:kann ich in einer Multiselect-Listbox das Item feststellen auf das doppelgeklickt wurde?
das ist bei Xbase++ "so" vorgesehen... aber du muss ja nicht o:ItemSelected benutzen !
"doppelgeklickt" -> oListBox:lbDblClick und dazu paar API Functionen ( hier mit ot4xb )

Code: Alles auswählen

#include "Appevent.ch"
#include "Xbp.ch"
#include "Gra.ch"
#include "Common.ch"
#include "Directry.ch"

#include "ot4xb.ch"
#define LB_GETCURSEL 0x0188
#define LB_GETTEXT 0x0189
#define LB_GETTEXTLEN 0x018A

#define PicHeigh     240
#define Titlebar      50

PROCEDURE appsys ; return

PROCEDURE Main(cPath)
LOCAL nEvent, oXbp, mp1, mp2
LOCAL oDlg
LOCAL oListBox
LOCAL oDa
LOCAL aSize
LOCAL i, iMax
LOCAL aDir
LOCAL nVersion := 0
LOCAL aMark   := {}
LOCAL aSele   := {}
LOCAL zPath   := LEFT(AppName(.t.),LEN(AppName(.t.)) - LEN(AppName(.f.)))
LOCAL aPP := { { XBP_PP_COMPOUNDNAME, "10.Arial"                 },;
               { XBP_PP_BGCLR       , XBPSYSCLR_WINDOW           },;
               { XBP_PP_FGCLR       , XBPSYSCLR_WINDOWTEXT       },;
               { XBP_PP_HILITE_FGCLR, XBPSYSCLR_HILITEFOREGROUND },;
               { XBP_PP_HILITE_BGCLR, XBPSYSCLR_HILITEBACKGROUND } }


DEFAULT cPath TO zPath

   SET DATE GERMAN
   SET CENTURY ON

   aDir  := Directory(cPath+"*.*")

   oDlg := XbpDialog():New(AppDesktop(),,{0,0}, {533,PicHeigh+Titlebar},,.F.)
   oDlg:taskList := .T.
   oDlg:title    := "Picture ListBox"
   oDlg:close    := {|p1,p2,oo| PostAppEvent(xbeP_Quit,,,oo) }
   oDlg:drawingArea:resize := {| aOldSize, aNewSize, oSelf | MyResize(aOldSize,aNewSize,oSelf,oListBox)  }
   oDlg:Create()

   oDlg:drawingArea:ClipChildren := .T.

   CenterControl(oDlg)

   oDa   := oDlg:drawingArea
   aSize := oDa:Currentsize()
   aSize := {oDa:Currentsize()[1]-20,PicHeigh}

   oListBox := XbpListbox():new(oDa ,,{10,10},aSize,aPP)
   //
   // does not work with ownerdraw
   //
   oListBox:multiColumn  := .T.
   oListBox:markMode     := XBPLISTBOX_MM_MULTIPLE
   oListBox:itemMarked   := {|mp1, mp2, oSelf| aMark := oSelf:getdata() }

*  oListBox:ItemSelected := {|mp1, mp2, oSelf| aSele := oSelf:getdata() , ShowWhat(oSelf,aSele,aMark) }
   oListBox:lbDblClick := {| aPos, uNIL, oSelf| aSele := oSelf:getdata() , ShowWhat(oSelf,aSele,aMark,aPos) }

   oListBox:create()

   iMax := LEN( aDir )
   FOR i := 1 TO iMax
      oListBox:AddItem( aDir[i][F_NAME]+CHR(9)+STR(aDir[i][F_SIZE])+CHR(9)+DTOC(aDir[i][F_DATE]) )
   NEXT

   oDlg:Show()
   SetAppWindow( oDlg )
   SetAppFocus( oListBox )
   oListBox:setdata({1})      // Focus to 1st Item

   nEvent := xbe_None
   WHILE nEvent != xbeP_Close
      nEvent := AppEvent ( @mp1, @mp2, @oXbp )
      oXbp:HandleEvent ( nEvent, mp1, mp2 )
      IF nEvent == xbeP_Quit
         QUIT   // AppQuit()
      ENDIF
   ENDDO

   oListBox:destroy()
   oDlg:destroy()

RETURN

FUNCTION LB_GetCursorSelect(hLbox)
/******************************************************************************
Returns the index of the currently selected item.

wParam
   Not used; must be zero.
lParam
   Not used; must be zero.

Return Value
   In a single-selection list box, the return value is the zero-based index
   of the currently selected item. If there is no selection, the return value
   is LB_ERR.

******************************************************************************/
RETURN @User32:SendMessageA(hLbox,LB_GETCURSEL,0,0)

FUNCTION LB_GetText(nIndex,hLbox)
/******************************************************************************
Retrieves the string associated with a specified item and the length of the string.

wParam
   The zero-based index of the string to retrieve.

lParam
   A pointer to the buffer that will receive the string

   it is type LPTSTR which is subsequently cast to an LPARAM.
   The buffer must have sufficient space for the string and a terminating
   null character.
   An LB_GETTEXTLEN message can be sent before the LB_GETTEXT message to
   retrieve the length, in TCHARs, of the string.

Return Value
   The return value is the number of items placed in the buffer.

   If the list box is a single-selection list box, the return value is LB_ERR.

******************************************************************************/
LOCAL cString := ""
LOCAL nLen    := 256
LOCAL nErr    := 0

   nLen    := LB_GetTextLen(nIndex, hLbox)
   IF nLen = 0
      nLen := 80
   ENDIF
   cString := SPACE(nLen)

   nErr    := @User32:SendMessageA(hLbox,LB_GETTEXT,nIndex,@cString)
   // if nErr <> 0 ...
RETURN cString

FUNCTION LB_GetTextLen(nIndex,hLbox)
/******************************************************************************
Returns the length, in characters, of the string associated with a specified item.

wParam
   The zero-based index of the string.

lParam
   This parameter is not used.

Return Value
   The return value is the length of the string, in TCHARs, excluding the
   terminating null character. Under certain conditions, this value may
   actually be greater than the length of the text.

   If the wParam parameter does not specify a valid index, the return value
   is LB_ERR.

******************************************************************************/
LOCAL nRet := 0
   nRet := @User32:SendMessageA(hLbox,LB_GETTEXTLEN,nIndex,0)
RETURN nRet


PROCEDURE ShowWhat(oSelf,aSele,aMark,aPos)
LOCAL hLbox  := oSelf:getHWND()
LOCAL nIndex := LB_GetCursorSelect(hLbox)
LOCAL cText  := LB_GetText(nIndex,hLbox)
LOCAL cMsg   := ""
LOCAL i,iMax

   iMax  := LEN(aMark)
   IF iMax > 0
      FOR i := 1 TO iMax
         cMsg += oSelf:getItem(aMark[i])+CHR(13)+CHR(10)
      NEXT
   ENDIF
   Msgbox(cMsg,cText)

RETURN
gruss by OHR
Jimmy
peternmb
1000 working lines a day
1000 working lines a day
Beiträge: 525
Registriert: Mi, 01. Feb 2006 16:22
Wohnort: 06618 Naumburg

Re: Auswahl XbpListBox

Beitrag von peternmb »

klappt super, vielen Dank =D>
Ich hätte allerdings nicht erwartet, dass das so aufwändig ist :?
Benutzeravatar
AUGE_OHR
Marvin
Marvin
Beiträge: 12903
Registriert: Do, 16. Mär 2006 7:55
Wohnort: Hamburg
Hat sich bedankt: 19 Mal
Danksagung erhalten: 44 Mal

Re: Auswahl XbpListBox

Beitrag von AUGE_OHR »

peternmb hat geschrieben:Ich hätte allerdings nicht erwartet, dass das so aufwändig ist :?
naja ... es sind nur 2 Methoden die ich aus meinem "native" Control dafür benutzt habe.

Code: Alles auswählen

LOCAL nIndex := LB_GetCursorSelect(hLbox)
LOCAL cText  := LB_GetText(nIndex,hLbox)
mit der Listbox kann man noch so einiges anstellen wie ich auf der Devcon im Vortrag vorgeführt habe.

Tip : mache die eine eigene Class aus dem Demo und füge in den Header ein

Code: Alles auswählen

#xTranslate XbpListbox => MyListBox
ein wo du es haben willst.

p.s. es wird bei LB_GetText() nicht auf CHR(0) geprüft in diesem Demo
gruss by OHR
Jimmy
Antworten