299 lines
6.2 KiB
C++
Raw Normal View History

/***************************************************************************
CListBox.cpp
(c) 2004-2005 - Daniel Campos Fernández <dcamposf@gmail.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301, USA.
***************************************************************************/
#define __CLISTBOX_CPP
#include "gambas.h"
#include "main.h"
#include "widgets.h"
#include "CListBox.h"
#include "CWidget.h"
#include "CContainer.h"
#include <stdlib.h>
#include <stdio.h>
DECLARE_EVENT(EVENT_Select); /* selection change */
DECLARE_EVENT(EVENT_Click); /* simple click */
DECLARE_EVENT(EVENT_Activate); /* double click */
static void raise_select(gTreeView *sender)
{
CWIDGET *_ob = GetObject((gControl*)sender);
if (!_ob) return;
GB.Raise((void*)_ob, EVENT_Select, 0);
}
static void raise_activate(gTreeView *sender, char *key)
{
CWIDGET *_ob = GetObject((gControl*)sender);
if (!_ob) return;
GB.Raise((void*)_ob, EVENT_Activate, 0);
}
static void raise_click(gTreeView *sender)
{
CWIDGET *_ob = GetObject((gControl*)sender);
if (!_ob) return;
GB.Raise((void*)_ob, EVENT_Click, 0);
}
BEGIN_METHOD(CLISTBOX_new, GB_OBJECT parent)
InitControl(new gListBox(CONTAINER(VARG(parent))), (CWIDGET*)THIS);
LISTBOX->onSelect = raise_select;
LISTBOX->onActivate = raise_activate;
LISTBOX->onClick = raise_click;
END_METHOD
BEGIN_METHOD_VOID(CLISTBOX_clear)
LISTBOX->clear();
END_METHOD
BEGIN_METHOD(CLISTBOX_get, GB_INTEGER index)
long index = VARG(index);
if (index < 0 || index >= LISTBOX->count())
{
GB.Error("Bad index");
return;
}
THIS->index = index;
RETURN_SELF();
END_METHOD
BEGIN_METHOD(CLISTBOX_add, GB_STRING item; GB_INTEGER pos)
[DEVELOPMENT ENVIRONMENT] * NEW: Some little fixes in the hall of fame animations. * BUG: Fix the layout of the property sheet text edit dialog. * NEW: A new highlighting theme, named 'Quick'. * NEW: The '(Scaled)' virtual property has been renamed as 'Scaled'. * BUG: Fix the "quit" icon in the quit dialog. * BUG: Correctly raise an error when making an executable fails for any reason. * BUG: Extract the property help better. [WIKI CGI SCRIPT] * BUG: Auto link now really makes one identical link between two titles. [INTERPRETER] * OPT: Optimization of additions of small integers. * BUG: INC and DEC now toggle boolean values. * NEW: Use the new '.startup' file to run a project. The old '.project' file can be used for older projects. But its support will be removed in the final version. [COMPILER] * NEW: A '.startup' file is now created at each compilation. It contains an extract of the '.project' file with just what the interpreter needs to run the application. [GB.GTK] * BUG: Void items are correctly handled by ComboBox without crashing now. [GB.EVAL] * BUG: Quoted symbols, i.e. symbols between braces, are now correctly colorized by using the identifier colors. [GB.FORM] * BUG: Removed the useless Tag property from the DatePicker control. * BUG: Fix the height of the DateChooser toolbar. * NEW: Wizard.ShowIndex is a new property that makes the wizard control automatically display the index of the current step. This index takes into account if some steps are disabled. [GB.FORM.DIALOG] * NEW: Dialog.SelectDate() is a new method that allows the user to select a date in a dialog box having a date chooser. [GB.QT] * BUG: You can now resize a non resizable window without having to change its Border property first. [GB.QT.EXT] * BUG: Editor correctly goes to the end of file when pressing CTRL+END. Consequently, SelectAll() works correctly too now. * NEW: Comments just before a procedure are now never folded. git-svn-id: svn://localhost/gambas/trunk@1317 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2008-04-17 10:18:25 +00:00
LISTBOX->add( GB.ToZeroString(ARG(item)), VARGOPT(pos, -1));
END_METHOD
BEGIN_METHOD(CLISTBOX_remove, GB_INTEGER pos)
LISTBOX->remove(VARG(pos));
END_METHOD
BEGIN_PROPERTY(CLISTBOX_sorted)
if (READ_PROPERTY) { GB.ReturnBoolean(LISTBOX->isSorted()); return; }
LISTBOX->setSorted(VPROP(GB_BOOLEAN));
END_METHOD
BEGIN_PROPERTY(CLISTBOX_count)
GB.ReturnInteger(LISTBOX->count());
END_PROPERTY
BEGIN_PROPERTY(CLISTBOX_index)
if (READ_PROPERTY) { GB.ReturnInteger(LISTBOX->index()); return; }
LISTBOX->setIndex(VPROP(GB_INTEGER));
END_PROPERTY
BEGIN_PROPERTY(CLISTBOX_current)
THIS->index=LISTBOX->index();
if (THIS->index>=0) RETURN_SELF();
else GB.ReturnNull();
END_PROPERTY
BEGIN_PROPERTY(CLISTBOX_text)
GB.ReturnNewZeroString(LISTBOX->text());
END_PROPERTY
BEGIN_PROPERTY(CLISTBOX_mode)
if (READ_PROPERTY)
GB.ReturnInteger(LISTBOX->mode());
else
LISTBOX->setMode(VPROP(GB_INTEGER));
END_PROPERTY
BEGIN_PROPERTY(CLISTBOX_item_selected)
if (READ_PROPERTY)
GB.ReturnBoolean(LISTBOX->isItemSelected(THIS->index));
else
LISTBOX->setItemSelected(THIS->index,VPROP(GB_BOOLEAN));
END_PROPERTY
BEGIN_PROPERTY(CLISTBOX_item_text)
if (READ_PROPERTY)
GB.ReturnNewZeroString(LISTBOX->itemText(THIS->index));
else
LISTBOX->setItemText(THIS->index,GB.ToZeroString(PROP(GB_STRING)));
END_PROPERTY
BEGIN_METHOD(CLISTBOX_find, GB_STRING item)
GB.ReturnInteger(LISTBOX->find(GB.ToZeroString(ARG(item))));
END_METHOD
BEGIN_PROPERTY(CLISTBOX_list)
GB_ARRAY array;
int i;
if (READ_PROPERTY)
{
GB.Array.New(&array, GB_T_STRING, LISTBOX->count());
for (i = 0; i < LISTBOX->count(); i++)
{
*((char **)GB.Array.Get(array, i)) = GB.NewZeroString(LISTBOX->itemText(i));
}
GB.ReturnObject(array);
}
else
{
array = VPROP(GB_OBJECT);
LISTBOX->lock();
LISTBOX->clear();
if (array)
{
for (i = 0; i < GB.Array.Count(array); i++)
LISTBOX->add(*((char **)GB.Array.Get(array, i)));
}
[INFORMER] * BUG: The informer algorithm was redesigned. Now a sub-process is launched for each component that should be analyzed, and LD_PRELOAD is used to load the component shared library before the process is launched. Otherwise, some component may crash. [GB.DRAW] * BUG: Correctly initialize color properties of the Draw class at Draw.Begin(). * NEW: Draw.FillRect() is a new method to draw a filled rectangle with the specified color. * NEW: Draw.Clear() is a new method that clears the drawing device with its background color. [GB.FORM.MDI] * NEW: Do not use BackColor and ForeColor properties anymore. [GB.GTK] * NEW: Control.Backcolor and Control.Forecolor properties were removed. * BUG: Desktop.Resolution now uses the accurate GTK+ API. * BUG: Setting the ListBox.List to NULL property does not lock the ListBox control anymore. * BUG: Fix the Font object management. Using Font properties should not crash anymore. * BUG: Image.Save() and Picture.Save() now understand the "~" shortcut in path names. [GB.QT] * NEW: Control.Backcolor and Control.Forecolor properties were removed. * NEW: Do not check if we should quit too often. * NEW: Allow windows to be closed during a WAIT instruction as in other components. I do not know why it was forbidden before. * NEW: Prevent a crash in arrangement routines if a child widget is not associated with a Gambas control anymore. [GB.QT4] * NEW: Control.Backcolor and Control.Forecolor properties were removed. * NEW: The source code is now up to date with gb.qt. But many things do not work as expected! [GB.QT4.EXT] * NEW: The source code is now up to date with gb.qt.ext. But many things do not work as expected! git-svn-id: svn://localhost/gambas/trunk@1776 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2009-01-03 22:24:02 +00:00
LISTBOX->unlock();
}
END_PROPERTY
BEGIN_PROPERTY(CLISTBOX_border)
if (READ_PROPERTY)
GB.ReturnBoolean(LISTBOX->hasBorder());
else
LISTBOX->setBorder(VPROP(GB_BOOLEAN));
END_PROPERTY
BEGIN_METHOD_VOID(ListBox_SelectAll)
LISTBOX->selectAll();
END_METHOD
BEGIN_METHOD_VOID(ListBox_UnselectAll)
LISTBOX->unselectAll();
END_METHOD
/***************************************************************************
ListBoxItem
***************************************************************************/
GB_DESC CListBoxItemDesc[] =
{
GB_DECLARE(".ListBox.Item", 0), GB_VIRTUAL_CLASS(),
GB_PROPERTY("Text", "s", CLISTBOX_item_text),
GB_PROPERTY("Selected", "b", CLISTBOX_item_selected),
GB_END_DECLARE
};
/***************************************************************************
ListBox
***************************************************************************/
GB_DESC CListBoxDesc[] =
{
GB_DECLARE("ListBox", sizeof(CLISTBOX)), GB_INHERITS("Control"),
******** Merged /branches/64bits r918:1003 into /trunk [CONFIGURATION] * NEW: 64 bits port. [EXAMPLES] * BUG: Fixed the AnalogWatch example. [WIKI CGI SCRIPT] * NEW: Some little cosmetic changes. [INTERPRETER] * NEW: The extern function implementation has been redesigned and is now based on libffi, so that it works on 64 bits system. Because of a flaw in the compiler design, projects that use the Pointer datatype must be recompiled to be used on a 64 bits system. This flaw will be fixed in Gambas 3. * OPT: Put some tables into read-only memory. About 1000 bytes are saved for each running interpreter, except the first one. * BUG: Does not crash anymore if a component cannot be loaded. * NEW: Spanish translation updated. * NEW: A new interpreter API for returning a pointer. [COMPILER] * BUG: Correctly compiles LONG constants inside code. [GB.DEBUG] * BUG: Compiles and links the gb.debug components with the thread libraries. [GB.DB.SQLITE3] * BUG: Getting the primary index of a table without primary index is safe now. [GB.GTK] * BUG: Modified the GLib priority of watched descriptors, as the main loop could enter in a loop in which user interface events were not managed. * BUG: Message boxes use application title without crashing now. [GB.OPENGL] * BUG: Disable dead code. [GB.QT.EXT] * BUG: TextEdit.TextWidth and TextEdit.TextHeight were not declared as read-only properties. [GB.XML.XSLT] * BUG: XSLT class is now declared as being not creatable. git-svn-id: svn://localhost/gambas/trunk@1006 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2008-01-17 21:39:26 +00:00
GB_METHOD("_new", 0, CLISTBOX_new, "(Parent)Container;"),
GB_METHOD("_get", ".ListBox.Item", CLISTBOX_get, "(Index)i"),
******** Merged /branches/64bits r918:1003 into /trunk [CONFIGURATION] * NEW: 64 bits port. [EXAMPLES] * BUG: Fixed the AnalogWatch example. [WIKI CGI SCRIPT] * NEW: Some little cosmetic changes. [INTERPRETER] * NEW: The extern function implementation has been redesigned and is now based on libffi, so that it works on 64 bits system. Because of a flaw in the compiler design, projects that use the Pointer datatype must be recompiled to be used on a 64 bits system. This flaw will be fixed in Gambas 3. * OPT: Put some tables into read-only memory. About 1000 bytes are saved for each running interpreter, except the first one. * BUG: Does not crash anymore if a component cannot be loaded. * NEW: Spanish translation updated. * NEW: A new interpreter API for returning a pointer. [COMPILER] * BUG: Correctly compiles LONG constants inside code. [GB.DEBUG] * BUG: Compiles and links the gb.debug components with the thread libraries. [GB.DB.SQLITE3] * BUG: Getting the primary index of a table without primary index is safe now. [GB.GTK] * BUG: Modified the GLib priority of watched descriptors, as the main loop could enter in a loop in which user interface events were not managed. * BUG: Message boxes use application title without crashing now. [GB.OPENGL] * BUG: Disable dead code. [GB.QT.EXT] * BUG: TextEdit.TextWidth and TextEdit.TextHeight were not declared as read-only properties. [GB.XML.XSLT] * BUG: XSLT class is now declared as being not creatable. git-svn-id: svn://localhost/gambas/trunk@1006 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2008-01-17 21:39:26 +00:00
GB_METHOD("Clear", 0, CLISTBOX_clear, 0),
GB_METHOD("Add", 0, CLISTBOX_add, "(Text)s[(Index)i]"),
GB_METHOD("Remove", 0, CLISTBOX_remove, "(Index)i"),
GB_METHOD("Find", "i", CLISTBOX_find, "(Item)s"),
GB_PROPERTY("Sorted", "b", CLISTBOX_sorted),
GB_PROPERTY("List", "String[]", CLISTBOX_list),
GB_PROPERTY_READ("Count", "i", CLISTBOX_count),
GB_PROPERTY_READ("Current", ".ListBox.Item", CLISTBOX_current),
GB_PROPERTY_READ("Text", "s", CLISTBOX_text),
GB_PROPERTY("Index", "i", CLISTBOX_index),
GB_PROPERTY("Mode", "i", CLISTBOX_mode),
GB_PROPERTY("Border", "b", CLISTBOX_border),
GB_METHOD("SelectAll", NULL, ListBox_SelectAll, NULL),
GB_METHOD("UnselectAll", NULL, ListBox_UnselectAll, NULL),
******** Merged /branches/64bits r918:1003 into /trunk [CONFIGURATION] * NEW: 64 bits port. [EXAMPLES] * BUG: Fixed the AnalogWatch example. [WIKI CGI SCRIPT] * NEW: Some little cosmetic changes. [INTERPRETER] * NEW: The extern function implementation has been redesigned and is now based on libffi, so that it works on 64 bits system. Because of a flaw in the compiler design, projects that use the Pointer datatype must be recompiled to be used on a 64 bits system. This flaw will be fixed in Gambas 3. * OPT: Put some tables into read-only memory. About 1000 bytes are saved for each running interpreter, except the first one. * BUG: Does not crash anymore if a component cannot be loaded. * NEW: Spanish translation updated. * NEW: A new interpreter API for returning a pointer. [COMPILER] * BUG: Correctly compiles LONG constants inside code. [GB.DEBUG] * BUG: Compiles and links the gb.debug components with the thread libraries. [GB.DB.SQLITE3] * BUG: Getting the primary index of a table without primary index is safe now. [GB.GTK] * BUG: Modified the GLib priority of watched descriptors, as the main loop could enter in a loop in which user interface events were not managed. * BUG: Message boxes use application title without crashing now. [GB.OPENGL] * BUG: Disable dead code. [GB.QT.EXT] * BUG: TextEdit.TextWidth and TextEdit.TextHeight were not declared as read-only properties. [GB.XML.XSLT] * BUG: XSLT class is now declared as being not creatable. git-svn-id: svn://localhost/gambas/trunk@1006 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2008-01-17 21:39:26 +00:00
GB_EVENT("Select", 0, 0, &EVENT_Select),
GB_EVENT("Activate", 0, 0, &EVENT_Activate),
GB_EVENT("Click", 0, 0, &EVENT_Click),
******** Merged /branches/64bits r918:1003 into /trunk [CONFIGURATION] * NEW: 64 bits port. [EXAMPLES] * BUG: Fixed the AnalogWatch example. [WIKI CGI SCRIPT] * NEW: Some little cosmetic changes. [INTERPRETER] * NEW: The extern function implementation has been redesigned and is now based on libffi, so that it works on 64 bits system. Because of a flaw in the compiler design, projects that use the Pointer datatype must be recompiled to be used on a 64 bits system. This flaw will be fixed in Gambas 3. * OPT: Put some tables into read-only memory. About 1000 bytes are saved for each running interpreter, except the first one. * BUG: Does not crash anymore if a component cannot be loaded. * NEW: Spanish translation updated. * NEW: A new interpreter API for returning a pointer. [COMPILER] * BUG: Correctly compiles LONG constants inside code. [GB.DEBUG] * BUG: Compiles and links the gb.debug components with the thread libraries. [GB.DB.SQLITE3] * BUG: Getting the primary index of a table without primary index is safe now. [GB.GTK] * BUG: Modified the GLib priority of watched descriptors, as the main loop could enter in a loop in which user interface events were not managed. * BUG: Message boxes use application title without crashing now. [GB.OPENGL] * BUG: Disable dead code. [GB.QT.EXT] * BUG: TextEdit.TextWidth and TextEdit.TextHeight were not declared as read-only properties. [GB.XML.XSLT] * BUG: XSLT class is now declared as being not creatable. git-svn-id: svn://localhost/gambas/trunk@1006 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2008-01-17 21:39:26 +00:00
LISTBOX_DESCRIPTION,
GB_END_DECLARE
};