New class on development

New class on development

Postby MdaSolution » Sat Jan 09, 2010 10:09 pm

Mr Linares, Mr Otto

I hope You help me to understand How I try to create the control Tsections for the question at this topic

viewtopic.php?f=3&t=17783

I try to create a small class but there is something not run also

the test create a first object ( a box white) into a wndchild ( from menu you must click on New option)

On the first control it not show any bitmap because I think to make a little header and on first item must not show any image


the I want insert a new item ( a new bitmap) and click on second menu first option "Append"

Now I use oTest:AddItem(".\bitmaps\secf.bmp") but on the final version the user can select the bitmap's section from a folder

this method must add a new object on the bootom of the first object with a image ( secf.bmp)

for the first Item I use the height of control = 200

when I add a new item and for each item , the height must be += 200


METHOD AddItem(oImg) CLASS TSections
local oItem
Local nvalue
Local nAltura := ::nHeight
nvalue+= nAltura
oItem := TSections():New( ::nTop+nAltura, ::nLeft, ::nWidth, ::nHeight,::oWnd,,,;
,oImg) // nuevo bitmap

aadd( ::aItems, oItem )

return oItem


where is the error ?



it make error or not found the method additem

could you help me ,thanks




test.prg



Code: Select all  Expand view


#include "FiveWin.ch"
#include "Constant.ch"

#define SRCCOPY             0xCC0020


#define COLOR_BTNFACE        15
static oWnd ,oTest


Function Test()
   Local oWnd
   Local oTest
   local oMenu


  DEFINE WINDOW oWnd ;
     MDI MENU BuildMenu()

ACTIVATE WINDOW oWnd
RETURN NIL


//-------------------------------------------------------------------------------------
Function BuildMenu()
   LOCAL oFont
   LOCAL oMenu

   DEFINE FONT oFont NAME "Tahoma" SIZE 0, -12 BOLD

    MENU oMenu           2007

   MENUITEM "&Sections"
   MENU
      MENUITEM "&New Sections" + chr(9) + "Ctrl+N"   NAME "btn12"  action Nuevo()
      MENUITEM "&Open" + chr(9) + "Ctrl+O"  NAME "btn2"
      MENUITEM "&Save" + chr(9) + "Ctrl+S"  NAME "btn3"
      SEPARATOR
      MENUITEM "Print Preview"              NAME "btn6"

      SEPARATOR
      MENUITEM "E&xit"    action  oWnd:end()
   ENDMENU
   MENUITEM "&Edit"
    MENU
    MENUITEM "&Append "     + chr(9) + "Ctrl+A"   NAME "btn10"  action  (oTest:AddItem(".\bitmaps\secf.bmp") )
    MENUITEM "&Insert "     + chr(9) + "Ctrl+A"   NAME "btn10"
    MENUITEM "&Delete "  + chr(9) + "Ctrl+D"     NAME "btn11"
     ENDMENU
    ENDMENU
return oMenu

//-----------------------------------------------------------------------------------------------

Function Nuevo()
   Local oTest
   local oWndChild

     DEFINE WINDOW oWndChild MDICHILD   of    oWnd;
    TITLE "New Image"  ;
    VSCROLL


     oTest:=TSections():New( , , , ,oWndChild,"nuevo")



      ACTIVATE WINDOW oWndChild
return nil






///////////////////////////////////////////////////////////////////


CLASS TSections FROM TControl

DATA aItems  AS ARRAY INIT {}

DATA oImg

DATA  cCaption  // title of groups of images


CLASSDATA lRegistered AS LOGICAL


METHOD New( nTop, nLeft, nWidth, nHeight,oWnd,cTitle)

//METHOD Default()

METHOD Display()  INLINE ::BeginPaint(),::Paint(),::EndPaint(),0

//METHOD LButtonDown( nRow, nCol, nKeyFlags )

//METHOD LButtonUp( nRow, nCol, nKeyFlags )

METHOD Paint()

METHOD Destroy()

METHOD AddItem(oImg)   // nuevo registro

//METHOD DelItem(oImg)    borrar registro

 METHOD Separator()    separator registros

ENDCLASS


METHOD New( nTop, nLeft, nWidth, nHeight,oWnd,cTitle,nClrFore,;
               nClrBack,oImg)  CLASS TSections

DEFAULT nTop     := 0, nLeft := 0,;
        nClrFore := oWnd:nClrText,;
        nClrBack := GetSysColor( COLOR_BTNFACE ),;
        nWidth   := 400, ;
        nHeight := 200



  ::oWnd       := oWnd
  ::nTop       := nTop
  ::nLeft      := nLeft
  ::nBottom    := ::nTop + nHeight
  ::nRight     := ::nLeft + nWidth

  ::aItems     := {}

   ::nStyle    = nOR( WS_CHILD, WS_VISIBLE)

   ::nId       = ::GetNewId()

   ::oFont     = TFont():New( "Arial",16, 20 )

   ::cCaption = cTitle

    ::Register()

   if ! Empty( oWnd:hWnd )
      ::Create()
      oWnd:AddControl( Self )
   else
      oWnd:DefControl( Self )
   endif

   ::Default()




return Self




METHOD Destroy() CLASS TSections

   if ::hWnd != 0
      Super:Destroy()
   endif

return nil




METHOD Paint() CLASS TSections
   local aInfo
   local aRect :=  GetClientRect( ::hWnd )
   local hBmpMem,hOldBmp, hDCMem
   local hBrush
   local n, nItem, oItem
   local nItems

    nItems := len( ::aItems )

   aInfo := ::DispBegin()

   hDCMem  = CreateCompatibleDC( ::hDC )

   hBmpMem = CreateCompatibleBitmap( ::hDC, aRect[ 4 ], aRect[ 3 ] )

   hOldBmp = SelectObject( hDCMem, hBmpMem )

   nClrPane   := CLR_WHITE

   hBrush =  CreateSolidBrush( nClrPane )

   FillRect( hDCMem, aRect, hBrush )



     // draw the bitmap if not empty
 if ! Empty( ::oImg )
     hBitmap = ReadBitmap( 0, ::oImg )
   if hBitmap != 0
      nWidth  := nBmpWidth( hBitmap )
      nHeight := nBmpHeight( hBitmap )
      nTop := rc[1] + (rc[3]-rc[1])/2 - nHeight/2

      if lTransparent
         DrawMasked( hDC, hBitmap, nTop, rc[2]+2 )
      else
         DrawBitmap( hDC, hBitmap, nTop, rc[2]+2 )
      endif
      DeleteObject( hBitmap )
   endif
endif







   BitBlt( ::hDC, 0, 0, aRect[4], aRect[3], hDCMem, 0, 0, SRCCOPY )

   SelectObject( hDCMem, hOldBmp )
   DeleteObject( hBrush )
   DeleteObject( hBmpMem )

   DeleteDC( hDCMem )

   ::DispEnd( aInfo )

return NIL




METHOD AddItem(oImg)  CLASS TSections
   local oItem
   Local nvalue
   Local nAltura := ::nHeight

   nvalue+= nAltura


oItem := TSections():New(  ::nTop+nAltura, ::nLeft, ::nWidth, ::nHeight,::oWnd,,,;
               ,oImg)    // nuevo bitmap

aadd( ::aItems, oItem )

return oItem




METHOD Separator() CLASS TSections

local oItem
   Local nvalue
   Local nAltura := 10

   nvalue+= nAltura

oItem :=TSections():New(  ::nTop+nAltura, ::nLeft, ::nWidth, ::nHeight,::oWnd,,, )

 aadd( ::aItems, oItem )

return oItem
 

 
FWH .. BC582.. xharbour
User avatar
MdaSolution
 
Posts: 401
Joined: Tue Jan 05, 2010 2:33 pm

Re: New class on development

Postby Silvio » Mon Jan 11, 2010 9:15 am

there are error on this part
I correct the name of array You used aRect instead of RC

Code: Select all  Expand view
// draw the bitmap if not empty
 if ! Empty( ::oImg )
     hBitmap = ReadBitmap( 0, ::oImg )
   if hBitmap != 0
      nWidth  := nBmpWidth( hBitmap )
      nHeight := nBmpHeight( hBitmap )
      nTop := aRect[1] + (aRect[3]-aRect[1])/2 - nHeight/2

      if lTransparent
         DrawMasked( hDC, hBitmap, nTop, aRect[2]+2 )
      else
         DrawBitmap( hDC, hBitmap, nTop, aRect[2]+2 )
      endif
      DeleteObject( hBitmap )
   endif
endif




for the method additem I not found the error perhaps someone expert can help you
Best Regards, Saludos

Falconi Silvio
User avatar
Silvio
 
Posts: 3107
Joined: Fri Oct 07, 2005 6:28 pm
Location: Teramo,Italy

Re: New class on development

Postby Daniel Garcia-Gil » Mon Jan 11, 2010 9:34 am

Hello Mda...

1. you have variable declaration error
oTest is declared static, bellow you are using oTest like "local"
comment Local oTest

2. Method AddItem
nvalue should have initial value or this line nvalue+= nAltura will crash the app
User avatar
Daniel Garcia-Gil
 
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 pm
Location: Isla de Margarita

Re: New class on development

Postby Silvio » Mon Jan 11, 2010 9:42 am

Daniel,
I correct the error you say and
I try also with this version but when I click on append it make error not found method additem


Application
===========
Path and name: C:\work\Errori\test_ra\test.Exe (32 bits)
Size: 1,856,512 bytes
Time from start: 0 hours 0 mins 3 secs
Error occurred at: 01/11/10, 10:44:04
Error description: Error BASE/1004 Class: 'NIL' has no exported method: ADDITEM Args:
[ 1] = U
[ 2] = C .\bitmaps\secf.bmp

Stack Calls
===========
Called from: => ADDITEM(0)
Called from: test.prg => (b)BUILDMENU(50)
Called from: .\source\classes\MENU.PRG => TMENU:COMMAND(437)
Called from: .\source\classes\WINDOW.PRG => TWINDOW:COMMAND(1003)
Called from: .\source\classes\MDIFRAME.PRG => TMDIFRAME:COMMAND(243)
Called from: => TMDIFRAME:HANDLEEVENT(0)
Called from: .\source\classes\WINDOW.PRG => _FWH(3333)
Called from: => WINRUN(0)
Called from: .\source\classes\WINDOW.PRG => TMDIFRAME:ACTIVATE(952)
Called from: test.prg => TEST(24)









Code: Select all  Expand view


#include "FiveWin.ch"
#include "Constant.ch"

#define SRCCOPY             0xCC0020


#define COLOR_BTNFACE        15


static oWnd ,oTest


Function Test()
   Local oWnd

   local oMenu


  DEFINE WINDOW oWnd ;
     MDI MENU BuildMenu()

ACTIVATE WINDOW oWnd
RETURN NIL


//-------------------------------------------------------------------------------------
Function BuildMenu()
   LOCAL oFont
   LOCAL oMenu

   DEFINE FONT oFont NAME "Tahoma" SIZE 0, -12 BOLD

    MENU oMenu           2007

   MENUITEM "&Sections"
   MENU
      MENUITEM "&New Sections" + chr(9) + "Ctrl+N"   NAME "btn12"  action Nuevo()
      MENUITEM "&Open" + chr(9) + "Ctrl+O"  NAME "btn2"
      MENUITEM "&Save" + chr(9) + "Ctrl+S"  NAME "btn3"
      SEPARATOR
      MENUITEM "Print Preview"              NAME "btn6"

      SEPARATOR
      MENUITEM "E&xit"    action  oWnd:end()
   ENDMENU
   MENUITEM "&Edit"
    MENU
    MENUITEM "&Append "     + chr(9) + "Ctrl+A"   NAME "btn10"  action  (oTest:AddItem(".\bitmaps\secf.bmp") )
    MENUITEM "&Insert "     + chr(9) + "Ctrl+A"   NAME "btn10"
    MENUITEM "&Delete "  + chr(9) + "Ctrl+D"     NAME "btn11"
     ENDMENU
    ENDMENU
return oMenu

//-----------------------------------------------------------------------------------------------

Function Nuevo()
   Local oTest
   local oWndChild

     DEFINE WINDOW oWndChild MDICHILD   of    oWnd;
    TITLE "New Image"  ;
    VSCROLL


     oTest:=TSections():New( , , , ,oWndChild,"nuevo")



      ACTIVATE WINDOW oWndChild
return nil






///////////////////////////////////////////////////////////////////


CLASS TSections FROM TControl

DATA aItems  AS ARRAY INIT {}

DATA oImg

DATA  cCaption  // title of groups of images


CLASSDATA lRegistered AS LOGICAL


METHOD New( nTop, nLeft, nWidth, nHeight,oWnd,cTitle)

//METHOD Default()

METHOD Display()  INLINE ::BeginPaint(),::Paint(),::EndPaint(),0

//METHOD LButtonDown( nRow, nCol, nKeyFlags )

//METHOD LButtonUp( nRow, nCol, nKeyFlags )

METHOD Paint()

METHOD Destroy()

METHOD AddItem(oImg)   // nuevo registro

//METHOD DelItem(oImg)    borrar registro

 METHOD Separator() //   separator registros

ENDCLASS


METHOD New( nTop, nLeft, nWidth, nHeight,oWnd,cTitle,nClrFore,;
               nClrBack,oImg)  CLASS TSections

DEFAULT nTop     := 0, nLeft := 0,;
        nClrFore := oWnd:nClrText,;
        nClrBack := GetSysColor( COLOR_BTNFACE ),;
        nWidth   := 400, ;
        nHeight := 200



  ::oWnd       := oWnd
  ::nTop       := nTop
  ::nLeft      := nLeft
  ::nBottom    := ::nTop + nHeight
  ::nRight     := ::nLeft + nWidth

  ::aItems     := {}

   ::nStyle    = nOR( WS_CHILD, WS_VISIBLE)

   ::nId       = ::GetNewId()

   ::oFont     = TFont():New( "Arial",16, 20 )

   ::cCaption = cTitle

    ::Register()

   if ! Empty( oWnd:hWnd )
      ::Create()
      oWnd:AddControl( Self )
   else
      oWnd:DefControl( Self )
   endif

   ::Default()




return Self




METHOD Destroy() CLASS TSections

   if ::hWnd != 0
      Super:Destroy()
   endif

return nil




METHOD Paint() CLASS TSections
   local aInfo
   local aRect :=  GetClientRect( ::hWnd )
   local hBmpMem,hOldBmp, hDCMem
   local hBrush
   local n, nItem, oItem
   local nItems

   lTransparent :=.t.

   nItems := len( ::aItems )

   aInfo := ::DispBegin()

   hDCMem  = CreateCompatibleDC( ::hDC )

   hBmpMem = CreateCompatibleBitmap( ::hDC, aRect[ 4 ], aRect[ 3 ] )

   hOldBmp = SelectObject( hDCMem, hBmpMem )

   nClrPane   := CLR_WHITE

   hBrush =  CreateSolidBrush( nClrPane )

   FillRect( hDCMem, aRect, hBrush )

   
     // draw the bitmap if not empty
 if ! Empty( ::oImg )
     hBitmap = ReadBitmap( 0, ::oImg )
   if hBitmap != 0
      nWidth  := nBmpWidth( hBitmap )
      nHeight := nBmpHeight( hBitmap )
      nTop := aRect[1] + (aRect[3]-aRect[1])/2 - nHeight/2

      if lTransparent
         DrawMasked( hDC, hBitmap, nTop, aRect[2]+2 )
      else
         DrawBitmap( hDC, hBitmap, nTop, aRect[2]+2 )
      endif
      DeleteObject( hBitmap )
   endif
endif







   BitBlt( ::hDC, 0, 0, aRect[4], aRect[3], hDCMem, 0, 0, SRCCOPY )

   SelectObject( hDCMem, hOldBmp )
   DeleteObject( hBrush )
   DeleteObject( hBmpMem )

   DeleteDC( hDCMem )

   ::DispEnd( aInfo )

return NIL




METHOD AddItem(oImg)  CLASS TSections
   local oItem
   Local nvalue :=0
   Local nAltura := ::nHeight

   nvalue+= nAltura


oItem := TSections():New(  ::nTop+nAltura, ::nLeft, ::nWidth, ::nHeight,::oWnd,,,;
               ,oImg)    // nuevo bitmap

aadd( ::aItems, oItem )

return oItem




METHOD Separator() CLASS TSections

local oItem
   Local nvalue  :=0
   Local nAltura := 10

   nvalue+= nAltura

oItem :=TSections():New(  ::nTop+nAltura, ::nLeft, ::nWidth, ::nHeight,::oWnd,,, )

 aadd( ::aItems, oItem )

return oItem
 

 
Best Regards, Saludos

Falconi Silvio
User avatar
Silvio
 
Posts: 3107
Joined: Fri Oct 07, 2005 6:28 pm
Location: Teramo,Italy

Re: New class on development

Postby Daniel Garcia-Gil » Mon Jan 11, 2010 9:46 am

Silvio...

Code: Select all  Expand view
Function Nuevo
// local oTest <- comment this line
User avatar
Daniel Garcia-Gil
 
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 pm
Location: Isla de Margarita

Re: New class on development

Postby MdaSolution » Mon Jan 11, 2010 1:09 pm

thanks .
I modified something.

Now I add also a dbf to save all Items and the image I must insert into.

the are Fields
NUM 3 NUMERIC
IMAGE 20 CHARACTHER


But i have also errors when use tPanel class where I inserted the object Tsections()

on Tpanel Class when I add an item , it show the new item but not show the Vertical scroll

I need ti because I must scroll all images

On test.prg I insert one panel on the left to create a menu and the second panel where I inserted the object on the right

Any idea?



Code: Select all  Expand view


#include "FiveWin.ch"
#include "Constant.ch"
#include "splitter.ch"


#define SRCCOPY             0xCC0020


#define COLOR_BTNFACE        15

#define D_WIDTH           4
#define D_HEIGHT          13

#define DT_TOP                      0x00000000
#define DT_LEFT                     0x00000000
#define DT_CENTER                   0x00000001
#define DT_RIGHT                    0x00000002
#define DT_VCENTER                  0x00000004
#define DT_BOTTOM                   0x00000008
#define DT_WORDBREAK                0x00000010
#define DT_SINGLELINE               0x00000020
#define DT_EXPANDTABS               0x00000040
#define DT_TABSTOP                  0x00000080
#define DT_NOCLIP                   0x00000100
#define DT_EXTERNALLEADING          0x00000200
#define DT_CALCRECT                 0x00000400
#define DT_NOPREFIX                 0x00000800
#define DT_INTERNAL                 0x00001000



#define COLOR_INACTIVECAPTION 3
#define COLOR_WINDOW          5
#define COLOR_WINDOWTEXT      8
#define COLOR_BTNFACE        15
#define COLOR_BTNSHADOW      16
#define COLOR_INACTIVECAPTIONTEXT  19
#define COLOR_BTNHIGHLIGHT   20










static oWnd ,oTest,oPanel2

static nMaxWidth := 22

Function Test()
   Local oWnd

   local oMenu


  DEFINE WINDOW oWnd ;
     MDI MENU BuildMenu()

ACTIVATE WINDOW oWnd
RETURN NIL


//-------------------------------------------------------------------------------------
Function BuildMenu()
   LOCAL oFont
   LOCAL oMenu

   DEFINE FONT oFont NAME "Tahoma" SIZE 0, -12 BOLD

    MENU oMenu           2007

   MENUITEM "&Sections"
   MENU
      MENUITEM "&New Sections" + chr(9) + "Ctrl+N"   NAME "btn12"  action Nuevo()
      MENUITEM "&Open" + chr(9) + "Ctrl+O"  NAME "btn2"
      MENUITEM "&Save" + chr(9) + "Ctrl+S"  NAME "btn3"
      SEPARATOR
      MENUITEM "Print Preview"              NAME "btn6"

      SEPARATOR
      MENUITEM "E&xit"    action  oWnd:end()
   ENDMENU
   MENUITEM "&Edit"
    MENU
    MENUITEM "&Append "     + chr(9) + "Ctrl+A"   NAME "btn10"  action AddSection()
    MENUITEM "&Insert "     + chr(9) + "Ctrl+A"   NAME "btn10"
    MENUITEM "&Delete "  + chr(9) + "Ctrl+D"     NAME "btn11"
     ENDMENU
    ENDMENU
return oMenu

//-----------------------------------------------------------------------------------------------

Function Nuevo()

   local oWndChild ,oScrWnd
   Local oPanel
   local nMargenLeft := 250



    DEFINE WINDOW oWndChild MDICHILD   of    oWnd;
    TITLE "New Gruppos"



     oPanel := TPanel():New( 0, 0, nMargenLeft, 100, oWndChild )
     oPanel:SetColor(0,RGB(143,172,230))
     *oWndChild:oLeft := oPanel


     oPanel2 := TPanel():New( 0, nMargenLeft+5,400 , 600, oWndChild)
     oPanel2:SetColor(0,CLR_RED)



     oTest:=TSections():New( , , , , oPanel2,"Gruppos uno",.t.)



      @ 0, nMargenLeft+2  SPLITTER oSplitter OF oWndChild;
          SIZE 5, 1500 PIXEL ;
          COLOR CLR_BLUE;
         PREVIOUS CONTROLS oPanel;
         HINDS CONTROLS  oPanel2








     ACTIVATE WINDOW oWndChild MAXIMIZED


     return nil




Function AddSection()

   Local cbitmap  :=".\bitmaps\secf.bmp"

   oTest:AddItem(cbitmap)

   USE SECTION ALIAS SECTION
   APPE BLANK
   REPLACE SECTION->NUM  with recno()
   REPLACE SECTION->IMAGE  with cbitmap
   USE

 return nil






///////////////////////////////////////////////////////////////////


CLASS TSections FROM TControl

DATA  aItems  AS ARRAY INIT {}

DATA  oImg

DATA  cCaption  // title of groups of images

DATA  nAltura   // height of  object

DATA  lSeparator  //  can be an separator  ****

DATA  lTitle

CLASSDATA lRegistered AS LOGICAL



METHOD New( nTop, nLeft, nWidth, nHeight,oWnd,cTitle,lTitle)


//METHOD Default()

METHOD Display()  INLINE ::BeginPaint(),::Paint(),::EndPaint(),0

//METHOD LButtonDown( nRow, nCol, nKeyFlags )

//METHOD LButtonUp( nRow, nCol, nKeyFlags )

METHOD Paint()

METHOD Destroy()

METHOD AddItem(oImg)   // nuevo registro

//METHOD DelItem(oImg)    borrar registro

METHOD Separator() //   separator registros

METHOD Height() INLINE ::nHeight
METHOD LButtonDown

METHOD EraseBkGnd( hDC ) INLINE 1



 METHOD Say( nRow, nCol, cText, nClrFore, nClrBack, oFont, lPixel,;
      lTransparent, nAlign )


METHOD Line( nTop, nLeft, nBottom, nRight, oPen )

METHOD TiTle()








ENDCLASS


METHOD New( nTop, nLeft, nWidth, nHeight,oWnd,cTitle,lTitle,nClrFore,;
               nClrBack,oImg)  CLASS TSections

DEFAULT nTop     := 0, nLeft := 0,;
        nClrFore := oWnd:nClrText,;
        nClrBack := GetSysColor( COLOR_BTNFACE ),;
        nWidth   := 650, ;
        nHeight := 200 ,;
        lTitle  :=.f.



  ::oWnd       := oWnd
  ::nTop       := nTop
  ::nLeft      := nLeft
  ::nBottom    := ::nTop + nHeight
  ::nRight     := ::nLeft + nWidth
  ::nAltura   :=0

  ::lTitle     :=lTitle

  ::aItems     := {}

*  ::nStyle    = nOR( WS_CHILD, WS_VISIBLE)
  ::nStyle      = nOR( WS_VISIBLE, WS_CHILD, WS_OVERLAPPED, WS_BORDER )

   ::nId       = ::GetNewId()

   ::oFont     = TFont():New( "Arial",16, 20 )

   ::cCaption = cTitle

    ::Register()

   if ! Empty( oWnd:hWnd )
      ::Create()
      oWnd:AddControl( Self )
   else
      oWnd:DefControl( Self )
   endif


   ::Default()




return Self




METHOD Destroy() CLASS TSections

   if ::hWnd != 0
      Super:Destroy()
   endif

return nil




METHOD Paint() CLASS TSections
   local aInfo
   local aRect :=  GetClientRect( ::hWnd )
   local hBmpMem,hOldBmp, hDCMem
   local hBrush
   local n, nItem, oItem
   local nItems
   Local cText
   Local  nMode

   lTransparent :=.t.



   nItems := len( ::aItems )

   aInfo := ::DispBegin()

   hDCMem  = CreateCompatibleDC( ::hDC )

   hBmpMem = CreateCompatibleBitmap( ::hDC, aRect[ 4 ], aRect[ 3 ] )

   hOldBmp = SelectObject( hDCMem, hBmpMem )

   nClrPane   := CLR_WHITE

   hBrush =  CreateSolidBrush( nClrPane )

   FillRect( hDCMem, aRect, hBrush )





 IF ::ltitle
      ::TiTle( hDCMem,aRect)
 ENDIF










     // draw the bitmap if not empty
 if ! Empty( ::oImg )
     hBitmap = ReadBitmap( 0, ::oImg )
   if hBitmap != 0
      nWidth  := nBmpWidth( hBitmap )
      nHeight := nBmpHeight( hBitmap )
      nTop := aRect[1] + (aRect[3]-aRect[1])/2 - nHeight/2

      if lTransparent
         DrawMasked( hDCMem, hBitmap, nTop, aRect[2]+2 )
      else
         DrawBitmap( hDCMem, hBitmap, nTop, aRect[2]+2 )
      endif
      DeleteObject( hBitmap )
   endif
endif





If ::lSeparator

endif






   BitBlt( ::hDC, 0, 0, aRect[4], aRect[3], hDCMem, 0, 0, SRCCOPY )





SetBkMode( hDCMem, nMode )


   SelectObject( hDCMem, hOldBmp )
   DeleteObject( hBrush )
   DeleteObject( hBmpMem )

   DeleteDC( hDCMem )

   ::DispEnd( aInfo )


   ::nAltura:= ::nHeight

return NIL







METHOD AddItem(oImg)  CLASS TSections
   local oItem
   local nvalue

    nvalue = ::nAltura+3


    oItem:= TSections():New( nvalue, ::nLeft, ::nWidth, ::nHeight,::oWnd, ,.F.,,,,oImg)    // nuevo bitmap  no title


    aadd( ::aItems, oItem)

    ::nAltura:=  ::nHeight+ nvalue

    msginfo(  ::nAltura)


return oItem




METHOD Separator() CLASS TSections

local oItem
   Local nvalue  :=0
   Local nAltura := 10

   nvalue+= nAltura

oItem :=TSections():New(  ::nTop+nAltura, ::nLeft, ::nWidth, ::nHeight,::oWnd,,, )

 aadd( ::aItems, oItem )

 return oItem






METHOD TiTle( hDCMem,aRect) CLASS TSections
   local hDarkPen  := CreatePen( PS_SOLID, 1, GetSysColor( COLOR_BTNSHADOW ) )
   local hGrayPen  := CreatePen( PS_SOLID, 1, GetSysColor( COLOR_BTNFACE ) )
   local hLightPen := CreatePen( PS_SOLID, 1, GetSysColor( COLOR_BTNHIGHLIGHT ) )
   local hBiancoPen := CreatePen( PS_SOLID, 1, GetSysColor( COLOR_WINDOW ) )
   Local  nMode
   local n, nCol := 0, nHeight := 200


   LOCAL nRig := 0
   local hOldFont, hOldBrush, hOldPen

   local hGrayBrush := CreateSolidBrush( ::nClrPane )
   local hWhiteBrush := CreateSolidBrush(  hBiancoPen)
   local hDarkBrush := CreateSolidBrush( GetSysColor( COLOR_INACTIVECAPTION ) )

   local lNeedButtons := .f.

   if LargeFonts()
      nHeight += 3
   endif



   SelectObject(  hDCMem,  hBiancoPen  )

   hOldFont  = SelectObject(  hDCMem, ::oFont:hFont )
   hOldPen   = SelectObject(  hDCMem, hDarkPen )
   hOldBrush = SelectObject( hDCMem, hDarkBrush )


      DrawLine( hDCMem, nRig , nCol,nCol,::nWidth(),CLR_BLACK)
      DrawLine( hDCMem, nRig ,nCol,nHeight-200,nCol,CLR_BLACK)
      DrawLine( hDCMem, nRig+50 , nCol,nRig+50,::nWidth(),CLR_BLACK)
      DrawLine( hDCMem, nRig,nCol+60,nHeight-200,nCol+60,CLR_BLACK)
      DrawLine( hDCMem, nRig,nCol+550,nHeight-200,nCol+550,CLR_BLACK)
      DrawLine( hDCMem, nRig,nCol+650,nHeight-200,nCol+650,CLR_BLACK)
      DrawLine( hDCMem, nRig, ::nWidth() ,nHeight-200,::nWidth(),CLR_BLACK)
      DrawLine( hDCMem, nHeight-200,nCol , nHeight-200,::nWidth(),CLR_BLACK)




  nMode := SetBkMode( hDCMem, 1 )

   DrawText( hDCMem, ::cCaption, {::ntop,::nleft , aRect[3], aRect[4] }, nOr( DT_VCENTER, DT_SINGLELINE ) )



return nil








METHOD LButtonDown( nRow, nCol, nFlags ) CLASS TSections

   local n

   for n = 1 to Len( ::aItems )
      if ::aItems[ n ]:IsOver( nRow, nCol )
         ::aItems[ n ]:Click( nRow, nCol)
         return nil
      endif
   next

return nil




 METHOD Say( nRow, nCol, cText, nClrFore, nClrBack, oFont, lPixel,;
      lTransparent, nAlign ) CLASS TSections

   DEFAULT nClrFore := ::nClrText,;
      nClrBack := ::nClrPane,;
      oFont    := ::oFont,;
      lPixel   := .f.,;
      lTransparent := .f.

   if ValType( nClrFore ) == "C"                
      nClrBack = nClrFore
      nClrFore = nGetForeRGB( nClrFore )
      nClrBack = nGetBackRGB( nClrBack )
   endif

   ::GetDC()

DEFAULT nAlign := GetTextAlign( ::hDC )

   WSay( ::hWnd, ::hDC, nRow, nCol, cValToChar( cText ), nClrFore, nClrBack,;
      If( oFont != nil, oFont:hFont, 0 ), lPixel, lTransparent, nAlign )

     ::ReleaseDC()

return nil


METHOD Line( nTop, nLeft, nBottom, nRight, oPen ) CLASS TSections

   local hPen := if( oPen = nil, 0, oPen:hPen )

   ::GetDC()
   MoveTo( ::hDC, nLeft, nTop )
   LineTo( ::hDC, nRight, nBottom, hPen )
   ::ReleaseDC()

return nil



 Function DrawLine( hDC, x, y , high, widht, color)
   LOCAL n, hPen, hOldPen
   hPen := CreatePen( 0, 2, color )
   hOldPen := SelectObject( hDc, hPen )
   MoveTo( hDC, y, x )
   LineTo( hDC, widht, high)
   SelectObject( hDc, hOldPen )
   DeleteObject( hPen )
   return NIL



 
FWH .. BC582.. xharbour
User avatar
MdaSolution
 
Posts: 401
Joined: Tue Jan 05, 2010 2:33 pm

Re: New class on development

Postby MdaSolution » Sun Jan 17, 2010 1:58 pm

Now run ok
I can add a new eitem, a new row from the method ADDItem()

I need also the possibility to erase a row ( an Item) or insert an Ite between other two items

How I can make it ?

this is the last release

Code: Select all  Expand view




///////////////////////////////////////////////////////////////////


CLASS TSections FROM TControl

DATA  aItems  AS ARRAY INIT {}

DATA  oImg

DATA  cCaption  // title of groups of images

DATA  nAltura   // height of  object

DATA  lSeparator  //  can be an separator  ****

DATA  lTitle

CLASSDATA lRegistered AS LOGICAL



METHOD New( nTop, nLeft, nWidth, nHeight,oWnd,cTitle,lTitle)


//METHOD Default()

METHOD Display()  INLINE ::BeginPaint(),::Paint(),::EndPaint(),0

//METHOD LButtonDown( nRow, nCol, nKeyFlags )

//METHOD LButtonUp( nRow, nCol, nKeyFlags )

METHOD Paint()

METHOD Destroy()

METHOD AddItem(oImg)   // nuevo registro

//METHOD DelItem(oImg)    borrar registro

METHOD Separator() //   separator registros

METHOD Height() INLINE ::nHeight
METHOD LButtonDown

METHOD EraseBkGnd( hDC ) INLINE 1



 METHOD Say( nRow, nCol, cText, nClrFore, nClrBack, oFont, lPixel,;
      lTransparent, nAlign )


METHOD Line( nTop, nLeft, nBottom, nRight, oPen )

METHOD TiTle()


ENDCLASS


METHOD New( nTop, nLeft, nWidth, nHeight,oWnd,cTitle,lTitle,nClrFore,;
               nClrBack,oImg)  CLASS TSections

DEFAULT nTop     := 0, nLeft := 0,;
        nClrFore := oWnd:nClrText,;
        nClrBack := GetSysColor( COLOR_BTNFACE ),;
        nWidth   := 650, ;
        nHeight := 200 ,;
        lTitle  :=.f.



  ::oWnd       := oWnd
  ::nTop       := nTop
  ::nLeft      := nLeft
  ::nBottom    := ::nTop + nHeight
  ::nRight     := ::nLeft + nWidth
  ::nAltura   :=0

  ::lTitle     :=lTitle

  ::aItems     := {}

*  ::nStyle    = nOR( WS_CHILD, WS_VISIBLE)
  ::nStyle      = nOR( WS_VISIBLE, WS_CHILD, WS_OVERLAPPED, WS_BORDER )

   ::nId       = ::GetNewId()

   ::oFont     = TFont():New( "Arial",16, 20 )

   ::cCaption = cTitle

    ::Register()

   if ! Empty( oWnd:hWnd )
      ::Create()
      oWnd:AddControl( Self )
   else
      oWnd:DefControl( Self )
   endif


   ::Default()




return Self




METHOD Destroy() CLASS TSections

   if ::hWnd != 0
      Super:Destroy()
   endif

return nil




METHOD Paint() CLASS TSections
   local aInfo
   local aRect :=  GetClientRect( ::hWnd )
   local hBmpMem,hOldBmp, hDCMem
   local hBrush
   local n, nItem, oItem
   local nItems
   Local cText
   Local  nMode

   lTransparent :=.t.



   nItems := len( ::aItems )

   aInfo := ::DispBegin()

   hDCMem  = CreateCompatibleDC( ::hDC )

   hBmpMem = CreateCompatibleBitmap( ::hDC, aRect[ 4 ], aRect[ 3 ] )

   hOldBmp = SelectObject( hDCMem, hBmpMem )

   nClrPane   := CLR_WHITE

   hBrush =  CreateSolidBrush( nClrPane )

   FillRect( hDCMem, aRect, hBrush )





 IF ::ltitle
      ::TiTle( hDCMem,aRect)
 ENDIF










     // draw the bitmap if not empty
 if ! Empty( ::oImg )
     hBitmap = ReadBitmap( 0, ::oImg )
   if hBitmap != 0
      nWidth  := nBmpWidth( hBitmap )
      nHeight := nBmpHeight( hBitmap )
      nTop := aRect[1] + (aRect[3]-aRect[1])/2 - nHeight/2

      if lTransparent
         DrawMasked( hDCMem, hBitmap, nTop, aRect[2]+2 )
      else
         DrawBitmap( hDCMem, hBitmap, nTop, aRect[2]+2 )
      endif
      DeleteObject( hBitmap )
   endif
endif





If ::lSeparator

endif






   BitBlt( ::hDC, 0, 0, aRect[4], aRect[3], hDCMem, 0, 0, SRCCOPY )





SetBkMode( hDCMem, nMode )


   SelectObject( hDCMem, hOldBmp )
   DeleteObject( hBrush )
   DeleteObject( hBmpMem )

   DeleteDC( hDCMem )

   ::DispEnd( aInfo )


   ::nAltura:= ::nHeight

return NIL







METHOD AddItem(oImg)  CLASS TSections
   local oItem
   local nvalue

    nvalue = ::nAltura+3


    oItem:= TSections():New( nvalue, ::nLeft, ::nWidth, ::nHeight,::oWnd, ,.F.,,,,oImg)    // nuevo bitmap  no title


    aadd( ::aItems, oItem)

    ::nAltura:=  ::nHeight+ nvalue

    msginfo(  ::nAltura)


return oItem




METHOD Separator() CLASS TSections

local oItem
   Local nvalue  :=0
   Local nAltura := 10

   nvalue+= nAltura

oItem :=TSections():New(  ::nTop+nAltura, ::nLeft, ::nWidth, ::nHeight,::oWnd,,, )

 aadd( ::aItems, oItem )

 return oItem






METHOD TiTle( hDCMem,aRect) CLASS TSections
   local hDarkPen  := CreatePen( PS_SOLID, 1, GetSysColor( COLOR_BTNSHADOW ) )
   local hGrayPen  := CreatePen( PS_SOLID, 1, GetSysColor( COLOR_BTNFACE ) )
   local hLightPen := CreatePen( PS_SOLID, 1, GetSysColor( COLOR_BTNHIGHLIGHT ) )
   local hBiancoPen := CreatePen( PS_SOLID, 1, GetSysColor( COLOR_WINDOW ) )
   Local  nMode
   local n, nCol := 0, nHeight := 200


   LOCAL nRig := 0
   local hOldFont, hOldBrush, hOldPen

   local hGrayBrush := CreateSolidBrush( ::nClrPane )
   local hWhiteBrush := CreateSolidBrush(  hBiancoPen)
   local hDarkBrush := CreateSolidBrush( GetSysColor( COLOR_INACTIVECAPTION ) )

   local lNeedButtons := .f.

   if LargeFonts()
      nHeight += 3
   endif



   SelectObject(  hDCMem,  hBiancoPen  )

   hOldFont  = SelectObject(  hDCMem, ::oFont:hFont )
   hOldPen   = SelectObject(  hDCMem, hDarkPen )
   hOldBrush = SelectObject( hDCMem, hDarkBrush )


      DrawLine( hDCMem, nRig , nCol,nCol,::nWidth(),CLR_BLACK)
      DrawLine( hDCMem, nRig ,nCol,nHeight-200,nCol,CLR_BLACK)
      DrawLine( hDCMem, nRig+50 , nCol,nRig+50,::nWidth(),CLR_BLACK)
      DrawLine( hDCMem, nRig,nCol+60,nHeight-200,nCol+60,CLR_BLACK)
      DrawLine( hDCMem, nRig,nCol+550,nHeight-200,nCol+550,CLR_BLACK)
      DrawLine( hDCMem, nRig,nCol+650,nHeight-200,nCol+650,CLR_BLACK)
      DrawLine( hDCMem, nRig, ::nWidth() ,nHeight-200,::nWidth(),CLR_BLACK)
      DrawLine( hDCMem, nHeight-200,nCol , nHeight-200,::nWidth(),CLR_BLACK)




  nMode := SetBkMode( hDCMem, 1 )

   DrawText( hDCMem, ::cCaption, {::ntop,::nleft , aRect[3], aRect[4] }, nOr( DT_VCENTER, DT_SINGLELINE ) )



return nil








METHOD LButtonDown( nRow, nCol, nFlags ) CLASS TSections

   local n

   for n = 1 to Len( ::aItems )
      if ::aItems[ n ]:IsOver( nRow, nCol )
         ::aItems[ n ]:Click( nRow, nCol)
         return nil
      endif
   next

return nil




 METHOD Say( nRow, nCol, cText, nClrFore, nClrBack, oFont, lPixel,;
      lTransparent, nAlign ) CLASS TSections

   DEFAULT nClrFore := ::nClrText,;
      nClrBack := ::nClrPane,;
      oFont    := ::oFont,;
      lPixel   := .f.,;
      lTransparent := .f.

   if ValType( nClrFore ) == "C"
      nClrBack = nClrFore
      nClrFore = nGetForeRGB( nClrFore )
      nClrBack = nGetBackRGB( nClrBack )
   endif

   ::GetDC()

DEFAULT nAlign := GetTextAlign( ::hDC )

   WSay( ::hWnd, ::hDC, nRow, nCol, cValToChar( cText ), nClrFore, nClrBack,;
      If( oFont != nil, oFont:hFont, 0 ), lPixel, lTransparent, nAlign )

     ::ReleaseDC()

return nil


METHOD Line( nTop, nLeft, nBottom, nRight, oPen ) CLASS TSections

   local hPen := if( oPen = nil, 0, oPen:hPen )

   ::GetDC()
   MoveTo( ::hDC, nLeft, nTop )
   LineTo( ::hDC, nRight, nBottom, hPen )
   ::ReleaseDC()

return nil



 Function DrawLine( hDC, x, y , high, widht, color)
   LOCAL n, hPen, hOldPen
   hPen := CreatePen( 0, 2, color )
   hOldPen := SelectObject( hDc, hPen )
   MoveTo( hDC, y, x )
   LineTo( hDC, widht, high)
   SelectObject( hDc, hOldPen )
   DeleteObject( hPen )
   return NIL



 
FWH .. BC582.. xharbour
User avatar
MdaSolution
 
Posts: 401
Joined: Tue Jan 05, 2010 2:33 pm


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 21 guests