Here my final code...
Code: Select all
#include <fivewin.ch>
#include "Constant.ch"
#xcommand @ <nRow>, <nCol> MYCOMBOBOX [ <oCbx> VAR ] <cVar> ;
[ <it: PROMPTS, ITEMS> <aItems> ] ;
[ SIZE <nWidth>, <nHeight> ] ;
[ <dlg:OF,WINDOW,DIALOG> <oWnd> ] ;
[ <help:HELPID, HELP ID> <nHelpId> ] ;
[ ON CHANGE <uChange> ] ;
[ VALID <uValid> ] ;
[ <color: COLOR,COLORS> <nClrText> [,<nClrBack>] ] ;
[ <pixel: PIXEL> ] ;
[ FONT <oFont> ] ;
[ <update: UPDATE> ] ;
[ MESSAGE <cMsg> ] ;
[ WHEN <uWhen> ] ;
[ <design: DESIGN> ] ;
[ BITMAPS <acBitmaps> ] ;
[ ON DRAWITEM <uBmpSelect> ] ;
[ STYLE <nStyle> ] ;
[ <pict: PICT, PICTURE> <cPicture> ];
[ ON EDIT CHANGE <uEChange> ] ;
[ HEIGHTGET <nHGet> ] ;
[ SELHEIGHT <nSelHt> ] ;
[ ITEMHEIGHT <nItmHt> ] ;
[ <lw: LISTWIDTH, DROPWIDTH> <nDropW> ] ;
[ DIRECTORY <cDir> [ATTRIB <attr>] [SAYDIR <oSayDir> ] ] ;
=> ;
[ <oCbx> := ] MyComboBox():New( <nRow>, <nCol>, bSETGET(<cVar>),;
<aItems>, <nWidth>, <nHeight>, <oWnd>, <nHelpId>,;
[{|Self|<uChange>}], <{uValid}>, <nClrText>, <nClrBack>,;
<.pixel.>, <oFont>, <cMsg>, <.update.>, <{uWhen}>,;
<.design.>, <acBitmaps>, [{|nItem|<uBmpSelect>}], <nStyle>,;
<cPicture>, [<{uEChange}>], [<(oCbx)>], <nHGet>, [<nSelHt>], [<nItmHt>], [<nDropW>], [<cDir>], ;
[<attr>], [<oSayDir>] )
proc main()
LOCAL oWnd, oCombo, oSay, cValue := ""
DEFINE WINDOW oWnd
@ 1,1 MYCOMBOBOX oCombo VAR cValue SIZE 200,200 STYLE CBS_DROPDOWN //ON EDIT CHANGE {|| MsgInfo(oCombo:GetText()) }
@ 2,2 SAY oSay PROMPT cValue UPDATE SIZE 200,20
// I must use both
oCombo:oGet:bAfterChange := {|| oSay:SetText(oCombo:GetText()) }
oCombo:oGet:bUpdate := oCombo:oGet:bAfterChange
ACTIVATE WINDOW oWnd// ON INIT (oCombo:oGet:SetSel())
class MyComboBox inherit TComboBox
CONSTRUCTOR New
endclass
class MyText inherit TEdit
DATA bAfterChange
METHOD KeyUp( nKey, nFlags ) INLINE iif(!empty(::bAfterChange),eval(::bAfterChange),), ::Super:KeyUp(nKey, nFlags)
endclass
#define COMBO_BASE 320
#define CB_FINDSTRING ( COMBO_BASE + 12 )
#define COLOR_WINDOW 5
#define COLOR_WINDOWTEXT 8
#define GW_CHILD 5
// Copied from TComboBox:New
METHOD New( nRow, nCol, bSetGet, aItems, nWidth, nHeight, oWnd, nHelpId,;
bChange, bValid, nClrFore, nClrBack, lPixel, oFont,;
cMsg, lUpdate, bWhen, lDesign, acBitmaps, bDrawItem, nStyle,;
cPict, bEChange, cVarName, nHGet, ;
nSelHt, nItmHt, nListWidth, cDir, nAttr, oSayDir ) CLASS MyComboBox
if nClrFore == nil
nClrBack := GetSysColor( COLOR_WINDOW )
endif
DEFAULT nRow := 0, nCol := 0, bSetGet := { || nil },;
oWnd := GetWndDefault(),;
oFont := oWnd:oFont,;
aItems := {}, nWidth := 40, nHeight := 60,;
nClrFore := GetSysColor( COLOR_WINDOWTEXT ),;
lPixel := .f., lUpdate := .f., lDesign := .f.,;
nStyle := CBS_DROPDOWNLIST
::lUnicode = FW_SetUnicode()
::cCaption = ""
::nTop = nRow * If( lPixel, 1, CMB_CHARPIX_H )
::nLeft = nCol * If( lPixel, 1, CMB_CHARPIX_W )
::nBottom = ::nTop + nHeight - 1
::nRight = ::nLeft + nWidth - 1
::nAt = 0
::aItems = aItems
::bChange = bChange
::bSetGet = bSetGet
::uOriginalValue = Eval( ::bSetGet )
::oWnd = oWnd
::cSearchKey := ""
if acBitmaps != nil
::SetBitmaps( acBitmaps )
else
::lOwnerDraw = .f.
/*
// FWH 17.07
if !Empty( nHGet )
::nBmpHeight := nHGet
endif
*/
endif
::nStyle = nOR( If( nStyle == CBS_DROPDOWN, 0, LBS_NOTIFY ), WS_TABSTOP,;
nStyle,;
LBS_DISABLENOSCROLL, WS_CHILD, WS_VISIBLE, WS_BORDER,;
WS_VSCROLL, If( lDesign, WS_CLIPSIBLINGS, 0 ),;
IF( ::lOwnerDraw, CBS_OWNERDRAWFIXED, 0 ) )
//::nExStyle = nOr( WS_EX_LEFT, WS_EX_LEFTSCROLLBAR )
::nId = ::GetNewId()
::nHelpId = nHelpId
::bValid = bValid
::lDrag = lDesign
::lCaptured = .f.
::cMsg = cMsg
::lUpdate = lUpdate
::bWhen = bWhen
::bDrawItem = bDrawItem
::SetColor( nClrFore, nClrBack )
if oFont == nil
::GetFont()
else
::SetFont( oFont )
endif
::oGet := MyText():ReDefine( nil ,; // ID not used
Self ,; //oWnd,
::bSetGet ,; //bSetGet,
cPict ,; //cPicture,
nil ,; //bChanged,
bEChange ,; //bUpdate,
nil ); //bHScroll )
// FWH 17.07
if cDir != nil
::cDir := cDir
::lDir := .t.
::nDirStyle := nAttr
::oSayDir := oSayDir
endif
if nHGet != nil
::hSelectionHeight := nHGet
::hItemHeight := nHGet
else
::hSelectionHeight := nSelHt
::hItemHeight := nItmHt
endif
::hDropWidth := nListWidth
// FWH17.07 end
if ! Empty( oWnd:hWnd )
::Create( "COMBOBOX" )
::Default()
::SetFont( ::oFont )
oWnd:AddControl( Self )
else
oWnd:DefControl( Self )
endif
DEFAULT cVarName := "oCbx" + ::GetCtrlIndex()
::cVarName = cVarName
::oGet:hWnd = GetWindow( ::hWnd, GW_CHILD )
if ! Empty( ::oGet:hWnd )
::oGet:Link()
::oGet:bLostFocus = ;
{ | hCtlFocus, nAt, cItem| cItem := ::GetText(), ;
nAt := ::SendMsg( CB_FINDSTRING, 0, Trim( cItem ) ) + 1,;
Eval( ::bSetGet, cItem ),;
::Select( nAt ),;
::SetText( cItem ),;
If( ::bValid != nil .and. ;
GetParent( hCtlFocus ) == GetParent( ::hWnd ),;
If( ! Eval( ::bValid, ::oGet, Self ),;
::PostMsg( WM_SETFOCUS ),),) }
//::oGet:bKeyChar = { | nKey | ::GetKeyChar( nKey ) }
endif
if lDesign
::CheckDots()
endif
return Self