/* $Id: picklist.cpp 1.1 1995/01/16 12:11:45 leon Exp $
 * Copyright (c) 1993, 1994 Leon Kos & FINCY d.o.o.
 */

#include <afc/adsapp.hpp>



/**
 ** Za tabelo stringov /table/ se iz /filename/.dcl uporabi dialog
 ** /dialogKey/, ki mora imeti listbox s kljucem /lb/. Zacetni izbor je -1,
 ** kar pomeni, da izbire ni bilo.
 **/
PickList::PickList(const char *filename, const char *dialogKey,
                   const char *table[], int size)
  : Dialog(filename, dialogKey)
{
  lb = new ListBox("lb", 1);
  fillListBox(table, size);
  insert(lb);
  selected = -1;
}

/**
 ** Odpre dialog in vrne stevilko vrstice, ki jo je uporabnik izbral.
 ** Ce je pritisnil /Cancel/ funkcija vrne -1
 **/
int PickList::Pick()
{
  Run();
  return (selected);
}

/** Napolni ListBox s stringi podani v /table/ velikosti /size/ **/
virtual void PickList::fillListBox(const char *table[], int size)
{
  lb->newList();
  for (int i = 0; i < size; i++)
      lb->add(table[i]);
}



/** {docInSuper} **/
void PickList::HandleListBoxMsg(int , ads_callback_packet *cbpkt)
{
  if (cbpkt->reason == CBR_DOUBLE_CLICK)
    {
      selected = atoi(cbpkt->value);
      ads_done_dialog(hdlg, 4);
    }
}



#if 0


static void testPick(void)
{
  const char *tekst[] = {"three", "two", "three"};
  PickList test("jctsetup", "TempZoneSelect", tekst, 3);
  ads_retint(test.Pick());
}

void main (int argc, char *argv[])
{
    ADSApplication test;
    test.Register(testPick, "c:test");
    test.Run(argc, argv);
}

#endif



syntax highlighted by Code2HTML, v. 0.9.1