Enigma1 THE BIBLE - Lesson6: Listbox

Lesson6: Listbox

/*
+--------------------------------------------------------------------------
| The Bible Enigma1 Tutorial
| ========================================
| By: Bacicciosat aka Meo aka Luponero
|
| Enigma 1 API GUI tutorial with Sources Code and Comments
| (c) august 2006 by Meo
|
+---------------------------------------------------------------------------
*/

Lesson6: Listbox

You can find in attach:
- the cfg file (Bibledemo.cfg)
- the compiled and working plugin (Bibledemo.so)
- the source file (bibledemo.cpp)
- the makefile (nedeed to compile code if you want to modify source)

Ok this is the lesson number six.
We will add to our Window a Listbox and a messagebox to show the item of the list we have selected.
You can see the example in the screenshot.

You can test this application simply uploading in your dreambox (/var/tuxbox/plugins) the files that you can find in attach: Bibledemo.cfg and Bibledemo.so

You can modify this application editing the source file bibledemo.cpp and recompiling it to have a new Bibledemo.so file.

The Enigma API we will explain in this lesson is the Listbox creation.
These are only a part of the listbox API. The listbox is more complicated so we will examine here only the main calls:
Code:
// create Listbox
eListBoxEntry(eListBox<eListBoxEntry>* parent, eString hlptxt=0, int selectable=3 );
// Functions:
selectedItem(eListBoxEntryText *item);
selectionChanged(eListBoxEntryText *item);
setColumns(int);
beginAtomic();
clearList();
endAtomic();

// Listbox items:
//create new item:
eListBoxEntryText(eListBox<eListBoxEntryText>* lb, const char* txt=0, void *key=0, int align=0, const eString &hlptxt="", int keytype = value );
// retrieve selected item
item->getText();
// retrieve selected key
item->getKey()
Ok now that we have listed the main API we can write the code.
You can find the complete application code in the attach package
(bibledemo.cpp). Here i will comment only the code added in this
lesson.

Let's go.

bibledemo.cpp additions:

First of all we have to add to our include files the Enigma Listbox library.
Code:
#include <lib/gui/listbox.h>
Ok Now we have to add the declaration of listbox in our main class.
We have to add a function too:
void message1();
we will connect the execution of this function to listbox selection.
In this way when we will select an item this function will be called and it will show the listox item we have selected.
This is our new main class declaration:
Code:
// The Class declaration of our Main Window
class eBibleMainWindow: public eWindow
{
    // the label to show the text
    eLabel *label;
    // the listbox
    eListBox<eListBoxEntryText> *theList;
    // function to execute when a item is selected
    void message1(eListBoxEntryText *item);
public:
        // the constructor.
    eBibleMainWindow();
        // the destructor.
    ~eBibleMainWindow();
};
Perfect !! Now we have to add the Listbox and populate it with items. We have also to connect the listbox
to the function that will be called when an item is selected:
Code:
eBibleMainWindow::eBibleMainWindow(): eWindow(1)
{
        // move our dialog to 100.100...
    cmove(ePoint(100, 100));
        // ...and give x and y dimensions.
    cresize(eSize(520, 376));
        // set a title.
    setText("Enigma Bible Lesson 6: Listbox");
    
    // create a label to show a text.
    label=new eLabel(this);
    // give a position
    label->move(ePoint(10, 10));
    // set the label dimensions
    label->resize(eSize(400, 60));
    // set the label text
    label->setText("What is your Favourite Dreambox Image ?");

    // Create a Listbox
    theList = new eListBox<eListBoxEntryText>(this);
    // give a position
    theList->move(ePoint(10, 100));
    // set dimensions
    theList->resize(eSize(clientrect.width() - 20, clientrect.height() - 160));
    // decore witha frame
    theList->loadDeco();
    // set columns number
    theList->setColumns(1);
    // set flags
    theList->beginAtomic();
    theList->clearList();
    // Populate Listbox with Items
    new eListBoxEntryText(theList, "Gemini", (void *) (1));
    new eListBoxEntryText(theList, "Colosseum", (void *) (2));
    new eListBoxEntryText(theList, "Pli Flubber", (void *) (3));
    new eListBoxEntryText(theList, "Juliet", (void *) (4));
    theList->endAtomic();
    
    // function to call when an Item is selected
    CONNECT(theList->selected, eBibleMainWindow::message1);

    // set focus to the list
    setFocus(theList);

}
Finally we have to add the function that will show the MessageBox with the selected item:
Code:
void eBibleMainWindow::message1(eListBoxEntryText *item)
{
    // declare variable we will use in this function
    eString message, message2;
    // assign to message2 the selected item text
    message2 = item->getText();
    // compose message concatenating strings
    message = "Your Dreambox preferred Image is:/n " + message2;    
    // Create, show and execute the messagebox to display the message
    eMessageBox msg((message), "Info", eMessageBox::iconInfo|eMessageBox::btOK);
        msg.show();
        msg.exec();
        msg.hide();
}

As you can see is very simply.
You can now exercise to compile source you find in the attach package and to modify it.

Exercises:
- Retrieve the item key instead of the item text
- Create a label to show the selction change with the function: selectionChanged(eListBoxEntryText *item);


That's all, and this is the application shot and the complete package.
(to be continued in lesson 7 ... )
Attached Images
File Type: pngosdshot.png (12.7 KB, 51 views)
Attached Files
File Type: ziplesson6.zip (12.7 KB, 45 views)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值