#include "appevent.ch"
#include "Common.ch"
#include "gra.ch"
#include "xbp.ch"

#define  nElemXColumna              76
#define  nCorrector                  5

Procedure Main()
*Begin
   Local xA1, xA2, oDlg, oXbps, aPos, aSize, nCount, nFontHeight, nFontWidth, i
   Local mp1, mp2, nEvent, oXbp, oXbpA, oBut1, oBut2, aPresPar
   Local aRgr, oXbp2, nDiv, oEan, nEanOPC, oXbpScr

   xA1 :={{"AIQUE DIDACTICA", "94"}, {"AIQUE LAROUSSE", "127"}, {"AIQUE LIT INF JUV", "95"}, {"AKAL", "108"}, {"ALBATROS", "82"}, {"ALFAGUARA", "37"}, {"ALIANZA", "93"}, {"AMAUTA", "39"}, {"AMORRORTU", "52"}, {"ANAYA", "96"}, {"ARAKNE", "4"}, {"ARTEMISA", "104"}, {"ASUNTO IMPRESO", "57"}, {"ATLANTE", "67"}, {"AUDILIBROS", "122"}, {"AUTORIA", "79"}, {"BAJO LA LUNA", "111"}, {"BIRNA", "112"}, {"BONUM", "86"}, {"CAFE DE LAS CIUDADES", "17"}, {"CARALT", "92"}, {"CIELO POR ASALTO", "138"}, {"CLARIDAD", "47"}, {"COLIHUE", "106"}, {"COLOR DE LEON", "8"}, {"COMUNICARTE", "19"}, {"CONEJOS EDITORIAL", "32"}, {"CONTINENTE", "27"}, {"CUENTA CONMIGO", "43"}, {"CYPRES LATINBOOKS", "75"}, {"DAMERAU", "103"}, {"DE LA CAMPANA", "63"}, {"DE LA FLOR", "56"}, {"DEL DRAGON", "18"}, {"DEL HOSPITAL ITALIANO", "45"}, {"DEL SIGNO", "117"}, {"DEL ZORZAL", "55"}, {"DEVAS", "74"}, {"DIAL BOOK", "87"}, {"DIDOT", "9"}, {"DISTAL IMPORTADO", "36"}, {"EDAF DEL PLATA", "135"}, {"EDEBE", "70"}, {"EDELVIVES", "40"}, {"EDIAR", "60"}, {"EDIBA", "125"}, {"EDICIONES B", "50"}, {"EDICIONES FABRO", "107"}, {"EL ATENEO", "26"}, {"EL JARDIN", "23"}, {"EMPORIO", "124"}, {"ERREPAR CODIGOS", "99"}, {"ERREPAR COLECCION PRACTICA", "100"}, {"ERREPAR JURIDICO", "102"}, {"ERREPAR LIBROS PROPIOS", "101"}, {"ERREPAR SEPARATAS", "98"}, {"ESPACIO", "10"}, {"ESTRADA", "1"}, {"EUDEBA", "84"}, {"GALERNA", "15"}, {"GODOT", "64"}, {"GOURMET MUSICAL", "31"}, {"GRADIFCO", "66"}, {"GRAN ALDEA", "58"}, {"GRUPAL", "114"}, {"GRUPO EDIT. LATINOAMERICANO", "11"}, {"HEMISFERIO SUR", "81"}, {"IAMIQUE", "129"}, {"IMAGINADOR", "110"}, {"KALANDRAKA", "130"}, {"KAPELUSZ", "29"}, {"KEL", "109"}, {"KEL INGLES", "142"}, {"LAROUSSE", "97"}, {"LEA", "105"}, {"LETRA IMPRESA", "91"}, {"LIBER", "65"}, {"LIBRARIA", "6"}, {"LIBSA DISTAL", "21"}, {"LIMONERO", "131"}, {"LONGSELLER", "77"}, {"LONGSELLER COMERCIAL", "68"}, {"LONGSELLER EDUCACION", "69"}, {"LUMEN", "33"}, {"MADRES DE PLAZA DE MAYO", "80"}, {"MANANTIAL", "137"}, {"MARMOL IZQUIERDO", "116"}, {"MCGRAW HILL", "34"}, {"MEDICA PANAMERICANA", "78"}, {"METALUCIDA EDITORA", "30"}, {"MM PUB / HELBLING", "140"}, {"NOBUKO", "38"}, {"NOVEDADES EDUCATIVAS", "126"}, {"NUDISTA", "53"}, {"NUEVA LIBRERIA", "143"}, {"NUEVA VISION", "54"}, {"OCEAN", "20"}, {"OCEANO", "71"}, {"OLMO", "136"}, {"OXFORD", "89"}, {"PAIDOS", "24"}, {"PAPRIKA", "62"}, {"PATRIA GRANDE POLIT", "42"}, {"PATRIA GRANDE RELIGION", "41"}, {"PEARSON", "134"}, {"PEQUE¥O EDITOR", "128"}, {"PICTUS", "133"}, {"PLANETA", "49"}, {"PLUMA Y PAPEL", "115"}, {"PROMETEO", "113"}, {"PROYECTO CEPA", "72"}, {"PUERTO", "2"}, {"PUNTO DE ENCUENTRO", "12"}, {"QUIPU LIBRONET", "35"}, {"RED DEL LIBRO", "3"}, {"REDITAR LIBROS", "22"}, {"RETORICA", "73"}, {"RICHMOND", "119"}, {"RIDERCHAIL", "85"}, {"RIVERSIDE", "44"}, {"ROBINBOOK", "59"}, {"SALIM", "25"}, {"SANTIAGO ARCOS", "90"}, {"SANTILLANA", "118"}, {"SANTILLANA INF/JUV", "120"}, {"SE IMPRIME", "132"}, {"SIGLO XXI", "88"}, {"SIGMAR", "61"}, {"SM", "121"}, {"STADIUM", "123"}, {"SUDESTADA", "16"}, {"TINTA FRESCA", "141"}, {"TOLEMIA-ARENAL", "7"}, {"UGERMAN", "51"}, {"UNIVERSITARIA DEL EJERCITO", "48"}, {"UTOPIA", "14"}, {"VAZQUEZ MAZZINI", "139"}, {"VESTALES", "28"}, {"VICENSVIVES", "76"}, {"WALDHUTER", "46"}, {"WOLKOWICZ", "13"},{"TODAS", "-1"}}

   aRgr                := Array( Len( xA1 ) )
   nFontHeight         := 16
   nFontWidth          := 12

   aSize               := { 800, 600 }
   aPresPar            := { { XBP_PP_BGCLR, GRA_CLR_DARKGRAY } }

   oDlg                := XbpDialog():New( ,, { 100, 100 }, aSize, aPresPar )
   oDlg:taskList       := .T.
   //oDlg:border         := XBPDLG_NO_BORDER
   oDlg:maxButton      := .F.
   oDlg:minButton      := .F.
   oDlg:hasScrollBars  := .T.
   oDlg:sysMenu        := .F.
   oDlg:drawingArea:ScrollBars := XBP_SCROLLBAR_VERT
   oDlg:Create()

   //oXbpScr             := XbpScrollBar():New( oDlg:drawingArea,, { 760, 10 }, { 20, 545 } )
   //oXbpScr:Type        := XBPSCROLL_VERTICAL
   //oXbpScr:Create()

   aSize               := { 580, 1350 }
   oXbps               := XbpStatic():New( oDlg:drawingArea,, { 100, 100 }, aSize )
   oXbps:type          := XBPSTATIC_TYPE_BGNDRECT
   oXbps:Create()

   oXbp2               := XbpStatic():New( oXbps, , { 2, aSize[2] -4 -40 + 2 }, { aSize[1] -4, 30 }, { aPresPar[1], { XBP_PP_COMPOUNDNAME, "12.MS Sans Serif Bold" } } )
   oXbp2:type          := XBPSTATIC_TYPE_TEXT
   oXbp2:Caption       := 'Listas de Precios Disponibles'
   oXbp2:options       := XBPSTATIC_TEXT_CENTER + XBPSTATIC_TEXT_VCENTER
   oXbp2:Create()

   nEanOPC             := 1
   oEan                := XbpRadioButton():New( oXbp2, oXbp2, { 5, 5 }, { (oXbp2:currentSize()[1] / 5) -10, oXbp2:currentSize()[2] - 10 }, { aPresPar[1], { XBP_PP_COMPOUNDNAME, "8.MS Sans Serif Bold" } } )
   oEan:Caption        := 'EAN'
   oEan:selection      :=.T.
   oEan:Selected       := { | mp1, mp2, obj | Valx01x( mp1, mp2, obj, @nEanOPC ) }
   oEan:Create()

   oEan                := XbpRadioButton():New( oXbp2, oXbp2, { oXbp2:currentSize()[1] - ( (oXbp2:currentSize()[1] / 4) + nCorrector ), 5 }, { (oXbp2:currentSize()[1] / 4) -10, oXbp2:currentSize()[2] - 10 }, { aPresPar[1], { XBP_PP_COMPOUNDNAME, "8.MS Sans Serif Bold" } } )
   oEan:Caption        := 'ISBN'
   oEan:Selected       := { | mp1, mp2, obj | Valx01x( mp1, mp2, obj, @nEanOPC ) }
   oEan:Create()

   aSize               := { Int( (aSize[1] -5) ), aSize[2] - 40 - 40 + nCorrector }
   oXbpA               := XbpStatic():New( oXbps, , { 3, 32 }, aSize, aPresPar )
   oXbpA:type          := XBPSTATIC_TYPE_RAISEDRECT
   oXbpA:Create()

   aSize               := { oXbpA:currentSize()[1] - 10, nFontHeight }
   nCount              := Len( xA1 )     // restauro tamaño nCount
   nDiv                := Round( (nCount / nElemXColumna) + 0.5, 0 )
   If ( nDiv = 1 )                       // xA2 tiene las coordendas de inicio de impresión
      xA2              := { 5, 5 }
    Else
      // fijo los nDiv divisiones de pantalla a utilizar
      i                := Int( aSize[1] / nDiv )
      xA2              := { ( i * ( nDiv -1 ) ) + nCorrector, ( nFontHeight * (nElemXColumna - (nCount % nElemXColumna) ) ) + nCorrector }
   EndIF
   oXbpA:tabStop       := .T.

   For i := nCount To 1 STEP -1
      If ( i % nElemXColumna = 0 )
         xA2[1]        := xA2[1] - Int( aSize[1] / nDiv )
         xA2[2]        := nCorrector
      EndIF
      aRGr[i]          := XbpCheckBox():New( oXbpA, oXbpA, xA2, { aSize[1] / nDiv, aSize[2] }, aPresPar )
      aRGr[i]:Caption  := Left( xA1[i,1], 30 )
      aRGr[i]:Selected := { | mp1, mp2, oXbp | ControlChkB( mp1, mp2, oXbp, @aRGr ) }
      //aRGr[i]:selection := ( i = Len( xA1 ) )
      aRGr[i]:Create()
      xA2[2]           := xA2[2] + nFontHeight
   Next i

   aSize               := { Int( aSize[1] / 2 + 10 ) - 7, 20 }

   oBut1               := XbpPushButton():New( oXbps, , { 4, 5 }, aSize, { { XBP_PP_BGCLR, XBPSYSCLR_BUTTONMIDDLE }, { XBP_PP_FGCLR, -58 } } )
   oBut1:caption       := 'Guardar'
   oBut1:activate      := { | mp1, mp2, oXbp | oXbp:cargo := .T., PostAppEvent( xbeP_Close, mp1, mp2, oXbp ) }
   oBut1:Create()

   oBut2               := XbpPushButton():New( oXbps, , { aSize[1] + 7, 5 }, aSize, { { XBP_PP_BGCLR, XBPSYSCLR_BUTTONMIDDLE }, { XBP_PP_FGCLR, -58 } } )
   oBut2:caption       := 'CANCELAR'
   oBut2:activate      := { | mp1, mp2, oXbp | PostAppEvent( xbeP_Close, mp1, mp2, oXbp ) }
   oBut2:Create()

   SetAppFocus( oDlg )
   While ( nEvent <> xbeP_Close )
      nEvent := AppEvent ( @mp1, @mp2, @oXbp )
      oXbp:handleEvent ( nEvent, mp1, mp2 )
   EndDO



   Return
*End;
*

Function Valx01x( mp1, mp2, obj, i )
   If ( obj:Caption = 'EAN' )
      i := 1
    Else
      i := 2
   EndIF
   Return ( NIL )
*End;
*
Function ControlChkB( mp1, mp2, oXbp, aRGr )
*Begin
   Local i, lCheck
   If ( oXbp:caption = 'TODAS' )
      lCheck := oXbp:GetData()
      For i := 1 To Len( aRGr ) -1
         aRGr[i]:setData( lCheck )
      Next i
   EndIF
   Return ( oXbp )
*End;
*

Procedure AppSys()
Return