mirror of
https://github.com/aseprite/aseprite.git
synced 2025-01-30 15:32:38 +00:00
Converted combobox widget to a class (ComboBox class derived from Widget).
This commit is contained in:
parent
bbc16ab0da
commit
4dff5fac85
@ -53,7 +53,7 @@ protected:
|
||||
void execute(Context* context);
|
||||
|
||||
private:
|
||||
void load_resolutions(JWidget resolution, JWidget color_depth, JWidget pixel_scale);
|
||||
void load_resolutions(ComboBox* resolution, ComboBox* color_depth, ComboBox* pixel_scale);
|
||||
|
||||
GfxMode m_newMode;
|
||||
std::vector<std::pair<int, int> > m_resolutions;
|
||||
@ -73,7 +73,8 @@ void ConfigureScreen::execute(Context* context)
|
||||
CurrentGfxModeGuard currentGfxModeGuard;
|
||||
m_newMode = currentGfxModeGuard.getOriginal(); // Default values
|
||||
|
||||
JWidget resolution, color_depth, pixel_scale, fullscreen;
|
||||
ComboBox* resolution, *color_depth, *pixel_scale;
|
||||
Widget* fullscreen;
|
||||
FramePtr window(load_widget("configure_screen.xml", "configure_screen"));
|
||||
get_widgets(window,
|
||||
"resolution", &resolution,
|
||||
@ -91,10 +92,10 @@ void ConfigureScreen::execute(Context* context)
|
||||
window->open_window_fg();
|
||||
|
||||
if (window->get_killer() == jwidget_find_name(window, "ok")) {
|
||||
m_newMode.setWidth(m_resolutions[jcombobox_get_selected_index(resolution)].first);
|
||||
m_newMode.setHeight(m_resolutions[jcombobox_get_selected_index(resolution)].second);
|
||||
m_newMode.setDepth(m_colordepths[jcombobox_get_selected_index(color_depth)]);
|
||||
m_newMode.setScaling(m_pixelscale[jcombobox_get_selected_index(pixel_scale)]);
|
||||
m_newMode.setWidth(m_resolutions[resolution->getSelectedItem()].first);
|
||||
m_newMode.setHeight(m_resolutions[resolution->getSelectedItem()].second);
|
||||
m_newMode.setDepth(m_colordepths[color_depth->getSelectedItem()]);
|
||||
m_newMode.setScaling(m_pixelscale[pixel_scale->getSelectedItem()]);
|
||||
m_newMode.setCard(jwidget_is_selected(fullscreen) ? GFX_AUTODETECT_FULLSCREEN:
|
||||
GFX_AUTODETECT_WINDOWED);
|
||||
|
||||
@ -124,10 +125,11 @@ void ConfigureScreen::execute(Context* context)
|
||||
// "currentGfxModeGuard" destruction keeps the new graphics mode or restores the old one
|
||||
}
|
||||
|
||||
void ConfigureScreen::load_resolutions(JWidget resolution, JWidget color_depth, JWidget pixel_scale)
|
||||
void ConfigureScreen::load_resolutions(ComboBox* resolution, ComboBox* color_depth, ComboBox* pixel_scale)
|
||||
{
|
||||
char buf[512];
|
||||
bool old_res_selected = false;
|
||||
int newItem;
|
||||
|
||||
m_resolutions.clear();
|
||||
m_colordepths.clear();
|
||||
@ -169,10 +171,10 @@ void ConfigureScreen::load_resolutions(JWidget resolution, JWidget color_depth,
|
||||
else
|
||||
sprintf(buf, "%dx%d", w, h);
|
||||
|
||||
jcombobox_add_string(resolution, buf, NULL);
|
||||
newItem = resolution->addItem(buf);
|
||||
if (m_newMode.getWidth() == w && m_newMode.getHeight() == h) {
|
||||
old_res_selected = true;
|
||||
jcombobox_select_index(resolution, jcombobox_get_count(resolution)-1);
|
||||
resolution->setSelectedItem(newItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -183,9 +185,9 @@ void ConfigureScreen::load_resolutions(JWidget resolution, JWidget color_depth,
|
||||
if (bpp > 0 && label) {
|
||||
m_colordepths.push_back(bpp);
|
||||
|
||||
jcombobox_add_string(color_depth, label, NULL);
|
||||
newItem = color_depth->addItem(label);
|
||||
if (m_newMode.getDepth() == bpp)
|
||||
jcombobox_select_index(color_depth, jcombobox_get_count(color_depth)-1);
|
||||
color_depth->setSelectedItem(newItem);
|
||||
}
|
||||
}
|
||||
else if (strcmp(xmlElement->Value(), "pixelscale") == 0) {
|
||||
@ -195,9 +197,9 @@ void ConfigureScreen::load_resolutions(JWidget resolution, JWidget color_depth,
|
||||
if (factor > 0 && label) {
|
||||
m_pixelscale.push_back(factor);
|
||||
|
||||
jcombobox_add_string(pixel_scale, label, NULL);
|
||||
newItem = pixel_scale->addItem(label);
|
||||
if (m_newMode.getScaling() == factor)
|
||||
jcombobox_select_index(pixel_scale, jcombobox_get_count(pixel_scale)-1);
|
||||
pixel_scale->setSelectedItem(newItem);
|
||||
}
|
||||
}
|
||||
|
||||
@ -212,8 +214,8 @@ void ConfigureScreen::load_resolutions(JWidget resolution, JWidget color_depth,
|
||||
m_resolutions.insert(m_resolutions.begin(), std::make_pair(m_newMode.getWidth(), m_newMode.getHeight()));
|
||||
|
||||
sprintf(buf, "%dx%d (Current)", m_resolutions[0].first, m_resolutions[0].second);
|
||||
jcombobox_insert_string(resolution, 0, buf, NULL);
|
||||
jcombobox_select_index(resolution, 0);
|
||||
resolution->insertItem(0, buf);
|
||||
resolution->setSelectedItem(0);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -37,8 +37,10 @@
|
||||
// options
|
||||
|
||||
// TODO make these variables member of OptionsCommand
|
||||
static JWidget checked_bg, checked_bg_zoom;
|
||||
static JWidget checked_bg_color1, checked_bg_color2;
|
||||
static ComboBox* checked_bg;
|
||||
static Widget* checked_bg_zoom;
|
||||
static Widget* checked_bg_color1;
|
||||
static Widget* checked_bg_color2;
|
||||
|
||||
// TODO make this a member of OptionsCommand when button signal is converted to Vaca::Signal
|
||||
static bool checked_bg_reset_hook(JWidget widget, void *data);
|
||||
@ -115,11 +117,11 @@ void OptionsCommand::execute(Context* context)
|
||||
jwidget_select(check_smooth);
|
||||
|
||||
// Checked background size
|
||||
jcombobox_add_string(checked_bg, "16x16", NULL);
|
||||
jcombobox_add_string(checked_bg, "8x8", NULL);
|
||||
jcombobox_add_string(checked_bg, "4x4", NULL);
|
||||
jcombobox_add_string(checked_bg, "2x2", NULL);
|
||||
jcombobox_select_index(checked_bg, (int)RenderEngine::getCheckedBgType());
|
||||
checked_bg->addItem("16x16");
|
||||
checked_bg->addItem("8x8");
|
||||
checked_bg->addItem("4x4");
|
||||
checked_bg->addItem("2x2");
|
||||
checked_bg->setSelectedItem((int)RenderEngine::getCheckedBgType());
|
||||
|
||||
// Zoom checked background
|
||||
if (RenderEngine::getCheckedBgZoom())
|
||||
@ -152,7 +154,7 @@ void OptionsCommand::execute(Context* context)
|
||||
set_config_bool("Options", "MoveClick2", jwidget_is_selected(move_click2));
|
||||
set_config_bool("Options", "DrawClick2", jwidget_is_selected(draw_click2));
|
||||
|
||||
RenderEngine::setCheckedBgType((RenderEngine::CheckedBgType)jcombobox_get_selected_index(checked_bg));
|
||||
RenderEngine::setCheckedBgType((RenderEngine::CheckedBgType)checked_bg->getSelectedItem());
|
||||
RenderEngine::setCheckedBgZoom(jwidget_is_selected(checked_bg_zoom));
|
||||
RenderEngine::setCheckedBgColor1(colorbutton_get_color(checked_bg_color1));
|
||||
RenderEngine::setCheckedBgColor2(colorbutton_get_color(checked_bg_color2));
|
||||
@ -172,7 +174,7 @@ void OptionsCommand::execute(Context* context)
|
||||
static bool checked_bg_reset_hook(JWidget widget, void *data)
|
||||
{
|
||||
// Default values
|
||||
jcombobox_select_index(checked_bg, (int)RenderEngine::CHECKED_BG_16X16);
|
||||
checked_bg->setSelectedItem((int)RenderEngine::CHECKED_BG_16X16);
|
||||
jwidget_select(checked_bg_zoom);
|
||||
colorbutton_set_color(checked_bg_color1, color_rgb(128, 128, 128));
|
||||
colorbutton_set_color(checked_bg_color2, color_rgb(192, 192, 192));
|
||||
|
@ -182,7 +182,8 @@ bool SpriteSizeCommand::enabled(Context* context)
|
||||
|
||||
void SpriteSizeCommand::execute(Context* context)
|
||||
{
|
||||
JWidget width_px, height_px, width_perc, height_perc, lock_ratio, method, ok;
|
||||
JWidget width_px, height_px, width_perc, height_perc, lock_ratio, ok;
|
||||
ComboBox* method;
|
||||
const CurrentSpriteReader sprite(context);
|
||||
|
||||
// load the window widget
|
||||
@ -205,9 +206,9 @@ void SpriteSizeCommand::execute(Context* context)
|
||||
HOOK(width_perc, JI_SIGNAL_ENTRY_CHANGE, width_perc_change_hook, 0);
|
||||
HOOK(height_perc, JI_SIGNAL_ENTRY_CHANGE, height_perc_change_hook, 0);
|
||||
|
||||
jcombobox_add_string(method, "Nearest-neighbor", NULL);
|
||||
jcombobox_add_string(method, "Bilinear", NULL);
|
||||
jcombobox_select_index(method, get_config_int("SpriteSize", "Method", RESIZE_METHOD_NEAREST_NEIGHBOR));
|
||||
method->addItem("Nearest-neighbor");
|
||||
method->addItem("Bilinear");
|
||||
method->setSelectedItem(get_config_int("SpriteSize", "Method", RESIZE_METHOD_NEAREST_NEIGHBOR));
|
||||
|
||||
window->remap_window();
|
||||
window->center_window();
|
||||
@ -221,7 +222,7 @@ void SpriteSizeCommand::execute(Context* context)
|
||||
int new_width = width_px->getTextInt();
|
||||
int new_height = height_px->getTextInt();
|
||||
ResizeMethod resize_method =
|
||||
(ResizeMethod)jcombobox_get_selected_index(method);
|
||||
(ResizeMethod)method->getSelectedItem();
|
||||
|
||||
set_config_int("SpriteSize", "Method", resize_method);
|
||||
|
||||
|
@ -88,7 +88,7 @@ jstring ase_file_selector(const jstring& message,
|
||||
static Frame* window = NULL;
|
||||
Widget* fileview;
|
||||
Widget* filename_entry;
|
||||
Widget* filetype;
|
||||
ComboBox* filetype;
|
||||
jstring result;
|
||||
|
||||
file_system_refresh();
|
||||
@ -146,7 +146,7 @@ jstring ase_file_selector(const jstring& message,
|
||||
JWidget goforward = jwidget_find_name(window, "goforward");
|
||||
JWidget goup = jwidget_find_name(window, "goup");
|
||||
JWidget location = jwidget_find_name(window, "location");
|
||||
filetype = jwidget_find_name(window, "filetype");
|
||||
filetype = (ComboBox*)jwidget_find_name(window, "filetype");
|
||||
filename_entry = jwidget_find_name(window, "filename");
|
||||
|
||||
jwidget_focusrest(goback, false);
|
||||
@ -186,7 +186,7 @@ jstring ase_file_selector(const jstring& message,
|
||||
}
|
||||
else {
|
||||
fileview = jwidget_find_name(window, "fileview");
|
||||
filetype = jwidget_find_name(window, "filetype");
|
||||
filetype = (ComboBox*)jwidget_find_name(window, "filetype");
|
||||
filename_entry = jwidget_find_name(window, "filename");
|
||||
|
||||
jwidget_signal_off(fileview);
|
||||
@ -203,14 +203,14 @@ jstring ase_file_selector(const jstring& message,
|
||||
update_navigation_buttons(window);
|
||||
|
||||
// fill file-type combo-box
|
||||
jcombobox_clear(filetype);
|
||||
filetype->removeAllItems();
|
||||
|
||||
std::vector<jstring> tokens;
|
||||
std::vector<jstring>::iterator tok;
|
||||
|
||||
exts.split(',', tokens);
|
||||
for (tok=tokens.begin(); tok!=tokens.end(); ++tok)
|
||||
jcombobox_add_string(filetype, tok->c_str(), NULL);
|
||||
filetype->addItem(tok->c_str());
|
||||
|
||||
// file name entry field
|
||||
filename_entry->setText(init_path.filename().c_str());
|
||||
@ -333,7 +333,7 @@ again:
|
||||
// selected in the filetype combo-box
|
||||
if (buf.extension().empty()) {
|
||||
buf += '.';
|
||||
buf += jcombobox_get_selected_string(filetype);
|
||||
buf += filetype->getItemText(filetype->getSelectedItem());
|
||||
}
|
||||
|
||||
// duplicate the buffer to return a new string
|
||||
@ -358,7 +358,7 @@ again:
|
||||
static void update_location(JWidget window)
|
||||
{
|
||||
JWidget fileview = jwidget_find_name(window, "fileview");
|
||||
JWidget location = jwidget_find_name(window, "location");
|
||||
ComboBox* location = (ComboBox*)jwidget_find_name(window, "location");
|
||||
FileItem* current_folder = fileview_get_current_folder(fileview);
|
||||
FileItem* fileitem = current_folder;
|
||||
JList locations = jlist_new();
|
||||
@ -371,7 +371,7 @@ static void update_location(JWidget window)
|
||||
}
|
||||
|
||||
/* clear all the items from the combo-box */
|
||||
jcombobox_clear(location);
|
||||
location->removeAllItems();
|
||||
|
||||
/* add item by item (from root to the specific current folder) */
|
||||
int level = 0;
|
||||
@ -387,7 +387,8 @@ static void update_location(JWidget window)
|
||||
buf += fileitem_get_displayname(fileitem);
|
||||
|
||||
// add the new location to the combo-box
|
||||
jcombobox_add_string(location, buf.c_str(), fileitem);
|
||||
int newItem = location->addItem(buf.c_str());
|
||||
location->setItemData(newItem, fileitem);
|
||||
|
||||
if (fileitem == current_folder)
|
||||
selected_index = level;
|
||||
@ -396,10 +397,9 @@ static void update_location(JWidget window)
|
||||
}
|
||||
|
||||
jwidget_signal_off(location);
|
||||
jcombobox_select_index(location, selected_index);
|
||||
jcombobox_get_entry_widget(location)
|
||||
->setText(fileitem_get_displayname(current_folder).c_str());
|
||||
jentry_deselect_text(jcombobox_get_entry_widget(location));
|
||||
location->setSelectedItem(selected_index);
|
||||
location->getEntryWidget()->setText(fileitem_get_displayname(current_folder).c_str());
|
||||
jentry_deselect_text(location->getEntryWidget());
|
||||
jwidget_signal_on(location);
|
||||
|
||||
jlist_free(locations);
|
||||
@ -475,7 +475,7 @@ static void add_in_navigation_history(FileItem *folder)
|
||||
static void select_filetype_from_filename(JWidget window)
|
||||
{
|
||||
JWidget entry = jwidget_find_name(window, "filename");
|
||||
JWidget filetype = jwidget_find_name(window, "filetype");
|
||||
ComboBox* filetype = (ComboBox*)jwidget_find_name(window, "filetype");
|
||||
const char *filename = entry->getText();
|
||||
char *p = get_extension(filename);
|
||||
char buf[MAX_PATH];
|
||||
@ -483,7 +483,7 @@ static void select_filetype_from_filename(JWidget window)
|
||||
if (p && *p != 0) {
|
||||
ustrcpy(buf, get_extension(filename));
|
||||
ustrlwr(buf);
|
||||
jcombobox_select_string(filetype, buf);
|
||||
filetype->setSelectedItem(filetype->findItemIndex(buf));
|
||||
}
|
||||
}
|
||||
|
||||
@ -577,22 +577,24 @@ static bool fileview_msg_proc(JWidget widget, JMessage msg)
|
||||
static bool location_msg_proc(JWidget widget, JMessage msg)
|
||||
{
|
||||
if (msg->type == JM_SIGNAL) {
|
||||
ComboBox* combobox = dynamic_cast<ComboBox*>(widget);
|
||||
assert(combobox != NULL);
|
||||
|
||||
switch (msg->signal.num) {
|
||||
|
||||
/* when the user change the location we have to set the
|
||||
current-folder in the 'fileview' widget */
|
||||
// When the user change the location we have to set the
|
||||
// current-folder in the 'fileview' widget
|
||||
case JI_SIGNAL_COMBOBOX_SELECT: {
|
||||
FileItem* fileitem = reinterpret_cast<FileItem*>
|
||||
(jcombobox_get_data(widget,
|
||||
jcombobox_get_selected_index(widget)));
|
||||
(combobox->getItemData(combobox->getSelectedItem()));
|
||||
|
||||
if (fileitem) {
|
||||
Widget* fileview = widget->findSibling("fileview");
|
||||
|
||||
fileview_set_current_folder(fileview, fileitem);
|
||||
|
||||
/* refocus the 'fileview' (the focus in that widget is more
|
||||
useful for the user) */
|
||||
// Refocus the 'fileview' (the focus in that widget is more
|
||||
// useful for the user)
|
||||
jmanager_set_focus(fileview);
|
||||
}
|
||||
break;
|
||||
@ -602,25 +604,28 @@ static bool location_msg_proc(JWidget widget, JMessage msg)
|
||||
return false;
|
||||
}
|
||||
|
||||
/* hook for the 'filetype' combo-box */
|
||||
// Hook for the 'filetype' combo-box
|
||||
static bool filetype_msg_proc(JWidget widget, JMessage msg)
|
||||
{
|
||||
if (msg->type == JM_SIGNAL) {
|
||||
ComboBox* combobox = dynamic_cast<ComboBox*>(widget);
|
||||
assert(combobox != NULL);
|
||||
|
||||
switch (msg->signal.num) {
|
||||
|
||||
/* when the user select a new file-type (extension), we have to
|
||||
change the file-extension in the 'filename' entry widget */
|
||||
// When the user select a new file-type (extension), we have to
|
||||
// change the file-extension in the 'filename' entry widget
|
||||
case JI_SIGNAL_COMBOBOX_SELECT: {
|
||||
const char *ext = jcombobox_get_selected_string(widget);
|
||||
Frame* window = static_cast<Frame*>(widget->getRoot());
|
||||
std::string ext = combobox->getItemText(combobox->getSelectedItem());
|
||||
Frame* window = static_cast<Frame*>(combobox->getRoot());
|
||||
Widget* entry = window->findChild("filename");
|
||||
char buf[MAX_PATH];
|
||||
char *p;
|
||||
char* p;
|
||||
|
||||
ustrcpy(buf, entry->getText());
|
||||
p = get_extension(buf);
|
||||
if (p && *p != 0) {
|
||||
ustrcpy(p, ext);
|
||||
ustrcpy(p, ext.c_str());
|
||||
entry->setText(buf);
|
||||
jentry_select_text(entry, 0, -1);
|
||||
}
|
||||
@ -635,18 +640,18 @@ static bool filetype_msg_proc(JWidget widget, JMessage msg)
|
||||
static bool filename_msg_proc(JWidget widget, JMessage msg)
|
||||
{
|
||||
if (msg->type == JM_KEYRELEASED && msg->key.ascii >= 32) {
|
||||
// check if all keys are released
|
||||
// Check if all keys are released
|
||||
for (int c=0; c<KEY_MAX; ++c) {
|
||||
if (key[c])
|
||||
return false;
|
||||
}
|
||||
|
||||
// string to be autocompleted
|
||||
// String to be autocompleted
|
||||
jstring left_part = widget->getText();
|
||||
if (left_part.empty())
|
||||
return false;
|
||||
|
||||
// first we'll need the fileview widget
|
||||
// First we'll need the fileview widget
|
||||
Widget* fileview = widget->findSibling("fileview");
|
||||
|
||||
const FileItemList& children = fileview_get_filelist(fileview);
|
||||
@ -665,7 +670,7 @@ static bool filename_msg_proc(JWidget widget, JMessage msg)
|
||||
break;
|
||||
}
|
||||
|
||||
// is the pattern (left_part) in the child_name's beginning?
|
||||
// Is the pattern (left_part) in the child_name's beginning?
|
||||
if (it2 == left_part.end()) {
|
||||
widget->setText(child_name.c_str());
|
||||
jentry_select_text(widget,
|
||||
|
@ -35,308 +35,252 @@
|
||||
|
||||
#include "jinete/jinete.h"
|
||||
|
||||
struct ComboBox
|
||||
struct ComboBox::Item
|
||||
{
|
||||
Widget* entry;
|
||||
Widget* button;
|
||||
Frame* window;
|
||||
Widget* listbox;
|
||||
JList items;
|
||||
int selected;
|
||||
bool editable : 1;
|
||||
bool clickopen : 1;
|
||||
bool casesensitive : 1;
|
||||
};
|
||||
|
||||
struct ComboItem
|
||||
{
|
||||
char* text;
|
||||
std::string text;
|
||||
void* data;
|
||||
|
||||
Item() : data(NULL) { }
|
||||
};
|
||||
|
||||
#define COMBOBOX(widget) ((ComboBox*)jwidget_get_data(widget, JI_COMBOBOX))
|
||||
#define IS_VALID_ITEM(widget, index) \
|
||||
(index >= 0 && (size_t)index < jlist_length(COMBOBOX(widget)->items))
|
||||
#define IS_VALID_ITEM(combobox, index) \
|
||||
(index >= 0 && index < combobox->getItemCount())
|
||||
|
||||
static bool combobox_msg_proc(JWidget widget, JMessage msg);
|
||||
static bool combobox_entry_msg_proc(JWidget widget, JMessage msg);
|
||||
static bool combobox_button_msg_proc(JWidget widget, JMessage msg);
|
||||
static bool combobox_listbox_msg_proc(JWidget widget, JMessage msg);
|
||||
static void combobox_button_cmd(JWidget widget, void *data);
|
||||
static void combobox_open_window(JWidget widget);
|
||||
static void combobox_close_window(JWidget widget);
|
||||
static void combobox_switch_window(JWidget widget);
|
||||
static JRect combobox_get_windowpos(ComboBox *combobox);
|
||||
|
||||
static ComboItem *comboitem_new(const char *text, void *data);
|
||||
static void comboitem_free(ComboItem *item);
|
||||
|
||||
JWidget jcombobox_new()
|
||||
ComboBox::ComboBox()
|
||||
: Widget(JI_COMBOBOX)
|
||||
{
|
||||
Widget* widget = new Widget(JI_COMBOBOX);
|
||||
ComboBox *combobox = jnew(ComboBox, 1);
|
||||
m_entry = jentry_new(256, "");
|
||||
m_button = jbutton_new("");
|
||||
m_window = NULL;
|
||||
m_selected = 0;
|
||||
m_editable = false;
|
||||
m_clickopen = true;
|
||||
m_casesensitive = true;
|
||||
|
||||
combobox->entry = jentry_new(256, "");
|
||||
combobox->button = jbutton_new("");
|
||||
combobox->window = NULL;
|
||||
combobox->items = jlist_new();
|
||||
combobox->selected = 0;
|
||||
combobox->editable = false;
|
||||
combobox->clickopen = true;
|
||||
combobox->casesensitive = true;
|
||||
|
||||
combobox->entry->user_data[0] = widget;
|
||||
combobox->button->user_data[0] = widget;
|
||||
m_entry->user_data[0] = this;
|
||||
m_button->user_data[0] = this;
|
||||
|
||||
/* TODO this separation should be from the JTheme */
|
||||
widget->child_spacing = 0;
|
||||
this->child_spacing = 0;
|
||||
|
||||
jwidget_focusrest(widget, true);
|
||||
jwidget_add_hook(widget, JI_COMBOBOX, combobox_msg_proc, combobox);
|
||||
jwidget_add_hook(combobox->entry, JI_WIDGET, combobox_entry_msg_proc, NULL);
|
||||
jwidget_add_hook(combobox->button, JI_WIDGET, combobox_button_msg_proc, NULL);
|
||||
jwidget_focusrest(this, true);
|
||||
jwidget_add_hook(m_entry, JI_WIDGET, combobox_entry_msg_proc, NULL);
|
||||
jwidget_add_hook(m_button, JI_WIDGET, combobox_button_msg_proc, NULL);
|
||||
|
||||
jwidget_expansive(combobox->entry, true);
|
||||
jbutton_set_bevel(combobox->button, 0, 2, 0, 2);
|
||||
jbutton_add_command_data(combobox->button, combobox_button_cmd, widget);
|
||||
jwidget_expansive(m_entry, true);
|
||||
jbutton_set_bevel(m_button, 0, 2, 0, 2);
|
||||
jbutton_add_command_data(m_button, combobox_button_cmd, this);
|
||||
|
||||
jwidget_add_child(widget, combobox->entry);
|
||||
jwidget_add_child(widget, combobox->button);
|
||||
jwidget_add_child(this, m_entry);
|
||||
jwidget_add_child(this, m_button);
|
||||
|
||||
jcombobox_editable(widget, combobox->editable);
|
||||
setEditable(m_editable);
|
||||
|
||||
jwidget_init_theme(widget);
|
||||
|
||||
return widget;
|
||||
jwidget_init_theme(this);
|
||||
}
|
||||
|
||||
void jcombobox_editable(JWidget widget, bool state)
|
||||
ComboBox::~ComboBox()
|
||||
{
|
||||
ComboBox* combobox = reinterpret_cast<ComboBox*>(jwidget_get_data(widget, JI_COMBOBOX));
|
||||
removeAllItems();
|
||||
}
|
||||
|
||||
combobox->editable = state;
|
||||
void ComboBox::setEditable(bool state)
|
||||
{
|
||||
m_editable = state;
|
||||
|
||||
if (state) {
|
||||
jentry_readonly(combobox->entry, false);
|
||||
jentry_show_cursor(combobox->entry);
|
||||
jentry_readonly(m_entry, false);
|
||||
jentry_show_cursor(m_entry);
|
||||
}
|
||||
else {
|
||||
jentry_readonly(combobox->entry, true);
|
||||
jentry_hide_cursor(combobox->entry);
|
||||
jentry_readonly(m_entry, true);
|
||||
jentry_hide_cursor(m_entry);
|
||||
}
|
||||
}
|
||||
|
||||
void jcombobox_clickopen(JWidget widget, bool state)
|
||||
void ComboBox::setClickOpen(bool state)
|
||||
{
|
||||
ComboBox* combobox = reinterpret_cast<ComboBox*>(jwidget_get_data(widget, JI_COMBOBOX));
|
||||
|
||||
combobox->clickopen = state;
|
||||
m_clickopen = state;
|
||||
}
|
||||
|
||||
void jcombobox_casesensitive(JWidget widget, bool state)
|
||||
void ComboBox::setCaseSensitive(bool state)
|
||||
{
|
||||
ComboBox* combobox = reinterpret_cast<ComboBox*>(jwidget_get_data(widget, JI_COMBOBOX));
|
||||
|
||||
combobox->casesensitive = state;
|
||||
m_casesensitive = state;
|
||||
}
|
||||
|
||||
bool jcombobox_is_editable(JWidget widget)
|
||||
bool ComboBox::isEditable()
|
||||
{
|
||||
ComboBox* combobox = reinterpret_cast<ComboBox*>(jwidget_get_data(widget, JI_COMBOBOX));
|
||||
|
||||
return combobox->editable;
|
||||
return m_editable;
|
||||
}
|
||||
|
||||
bool jcombobox_is_clickopen(JWidget widget)
|
||||
bool ComboBox::isClickOpen()
|
||||
{
|
||||
ComboBox* combobox = reinterpret_cast<ComboBox*>(jwidget_get_data(widget, JI_COMBOBOX));
|
||||
|
||||
return combobox->clickopen;
|
||||
return m_clickopen;
|
||||
}
|
||||
|
||||
bool jcombobox_is_casesensitive(JWidget widget)
|
||||
bool ComboBox::isCaseSensitive()
|
||||
{
|
||||
ComboBox* combobox = reinterpret_cast<ComboBox*>(jwidget_get_data(widget, JI_COMBOBOX));
|
||||
|
||||
return combobox->casesensitive;
|
||||
return m_casesensitive;
|
||||
}
|
||||
|
||||
void jcombobox_add_string(JWidget widget, const char *string, void *data)
|
||||
int ComboBox::addItem(const std::string& text)
|
||||
{
|
||||
ComboBox* combobox = reinterpret_cast<ComboBox*>(jwidget_get_data(widget, JI_COMBOBOX));
|
||||
bool sel_first = jlist_empty(combobox->items);
|
||||
ComboItem *item = comboitem_new(string, data);
|
||||
bool sel_first = m_items.empty();
|
||||
Item* item = new Item();
|
||||
item->text = text;
|
||||
|
||||
jlist_append(combobox->items, item);
|
||||
m_items.push_back(item);
|
||||
|
||||
if (sel_first)
|
||||
jcombobox_select_index(widget, 0);
|
||||
setSelectedItem(0);
|
||||
|
||||
return m_items.size()-1;
|
||||
}
|
||||
|
||||
void jcombobox_insert_string(JWidget widget, int index, const char *string, void *data)
|
||||
void ComboBox::insertItem(int itemIndex, const std::string& text)
|
||||
{
|
||||
ComboBox* combobox = reinterpret_cast<ComboBox*>(jwidget_get_data(widget, JI_COMBOBOX));
|
||||
bool sel_first = jlist_empty(combobox->items);
|
||||
ComboItem *item = comboitem_new(string, data);
|
||||
bool sel_first = m_items.empty();
|
||||
Item* item = new Item();
|
||||
item->text = text;
|
||||
|
||||
jlist_insert(combobox->items, item, index);
|
||||
m_items.insert(m_items.begin() + itemIndex, item);
|
||||
|
||||
if (sel_first)
|
||||
jcombobox_select_index(widget, 0);
|
||||
setSelectedItem(0);
|
||||
}
|
||||
|
||||
void jcombobox_del_string(JWidget widget, const char *string)
|
||||
void ComboBox::removeItem(int itemIndex)
|
||||
{
|
||||
jcombobox_del_index(widget, jcombobox_get_index(widget, string));
|
||||
assert(itemIndex >= 0 && (size_t)itemIndex < m_items.size());
|
||||
|
||||
Item* item = m_items[itemIndex];
|
||||
|
||||
m_items.erase(m_items.begin() + itemIndex);
|
||||
delete item;
|
||||
}
|
||||
|
||||
void jcombobox_del_index(JWidget widget, int index)
|
||||
void ComboBox::removeAllItems()
|
||||
{
|
||||
ComboBox* combobox = reinterpret_cast<ComboBox*>(jwidget_get_data(widget, JI_COMBOBOX));
|
||||
ComboItem* item = reinterpret_cast<ComboItem*>(jlist_nth_data(combobox->items, index));
|
||||
std::vector<Item*>::iterator it, end = m_items.end();
|
||||
for (it = m_items.begin(); it != end; ++it)
|
||||
delete *it;
|
||||
|
||||
jlist_remove(combobox->items, item);
|
||||
comboitem_free(item);
|
||||
m_items.clear();
|
||||
}
|
||||
|
||||
void jcombobox_clear(JWidget widget)
|
||||
int ComboBox::getItemCount()
|
||||
{
|
||||
ComboBox* combobox = reinterpret_cast<ComboBox*>(jwidget_get_data(widget, JI_COMBOBOX));
|
||||
JLink link;
|
||||
|
||||
JI_LIST_FOR_EACH(combobox->items, link)
|
||||
comboitem_free(reinterpret_cast<ComboItem*>(link->data));
|
||||
|
||||
jlist_clear(combobox->items);
|
||||
return m_items.size();
|
||||
}
|
||||
|
||||
void jcombobox_select_index(JWidget widget, int index)
|
||||
std::string ComboBox::getItemText(int itemIndex)
|
||||
{
|
||||
ComboBox* combobox = reinterpret_cast<ComboBox*>(jwidget_get_data(widget, JI_COMBOBOX));
|
||||
JLink link = jlist_nth_link(combobox->items, index);
|
||||
ComboItem* item;
|
||||
|
||||
if (link != combobox->items->end) {
|
||||
combobox->selected = index;
|
||||
|
||||
item = reinterpret_cast<ComboItem*>(link->data);
|
||||
combobox->entry->setText(item->text);
|
||||
}
|
||||
}
|
||||
|
||||
void jcombobox_select_string(JWidget widget, const char *string)
|
||||
{
|
||||
jcombobox_select_index(widget, jcombobox_get_index(widget, string));
|
||||
}
|
||||
|
||||
int jcombobox_get_selected_index(JWidget widget)
|
||||
{
|
||||
ComboBox* combobox = reinterpret_cast<ComboBox*>(jwidget_get_data(widget, JI_COMBOBOX));
|
||||
|
||||
return combobox->items ? combobox->selected: -1;
|
||||
}
|
||||
|
||||
const char *jcombobox_get_selected_string(JWidget widget)
|
||||
{
|
||||
ComboBox* combobox = reinterpret_cast<ComboBox*>(jwidget_get_data(widget, JI_COMBOBOX));
|
||||
|
||||
return jcombobox_get_string(widget, combobox->selected);
|
||||
}
|
||||
|
||||
const char *jcombobox_get_string(JWidget widget, int index)
|
||||
{
|
||||
ComboBox* combobox = reinterpret_cast<ComboBox*>(jwidget_get_data(widget, JI_COMBOBOX));
|
||||
|
||||
if (index >= 0 && (size_t)index < jlist_length(combobox->items)) {
|
||||
ComboItem* item = reinterpret_cast<ComboItem*>(jlist_nth_link(combobox->items, index)->data);
|
||||
if (itemIndex >= 0 && (size_t)itemIndex < m_items.size()) {
|
||||
Item* item = m_items[itemIndex];
|
||||
return item->text;
|
||||
}
|
||||
else
|
||||
return NULL;
|
||||
return "";
|
||||
}
|
||||
|
||||
void *jcombobox_get_data(JWidget widget, int index)
|
||||
void ComboBox::setItemText(int itemIndex, const std::string& text)
|
||||
{
|
||||
ComboBox* combobox = reinterpret_cast<ComboBox*>(jwidget_get_data(widget, JI_COMBOBOX));
|
||||
assert(itemIndex >= 0 && (size_t)itemIndex < m_items.size());
|
||||
|
||||
if (index >= 0 && (size_t)index < jlist_length(combobox->items)) {
|
||||
ComboItem* item = reinterpret_cast<ComboItem*>(jlist_nth_link(combobox->items, index)->data);
|
||||
Item* item = m_items[itemIndex];
|
||||
item->text = text;
|
||||
}
|
||||
|
||||
int ComboBox::findItemIndex(const std::string& text)
|
||||
{
|
||||
int itemIndex = 0;
|
||||
|
||||
std::vector<Item*>::iterator it, end = m_items.end();
|
||||
for (it = m_items.begin(); it != end; ++it) {
|
||||
Item* item = *it;
|
||||
|
||||
if ((m_casesensitive && ustrcmp(item->text.c_str(), text.c_str()) == 0) ||
|
||||
(!m_casesensitive && ustricmp(item->text.c_str(), text.c_str()) == 0)) {
|
||||
return itemIndex;
|
||||
}
|
||||
|
||||
itemIndex++;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int ComboBox::getSelectedItem()
|
||||
{
|
||||
return !m_items.empty() ? m_selected: -1;
|
||||
}
|
||||
|
||||
void ComboBox::setSelectedItem(int itemIndex)
|
||||
{
|
||||
if (itemIndex >= 0 && (size_t)itemIndex < m_items.size()) {
|
||||
m_selected = itemIndex;
|
||||
|
||||
std::vector<Item*>::iterator it = m_items.begin() + itemIndex;
|
||||
Item* item = *it;
|
||||
m_entry->setText(item->text.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
void* ComboBox::getItemData(int itemIndex)
|
||||
{
|
||||
if (itemIndex >= 0 && (size_t)itemIndex < m_items.size()) {
|
||||
Item* item = m_items[itemIndex];
|
||||
return item->data;
|
||||
}
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int jcombobox_get_index(JWidget widget, const char *string)
|
||||
void ComboBox::setItemData(int itemIndex, void* data)
|
||||
{
|
||||
ComboBox* combobox = reinterpret_cast<ComboBox*>(jwidget_get_data(widget, JI_COMBOBOX));
|
||||
int index = 0;
|
||||
JLink link;
|
||||
assert(itemIndex >= 0 && (size_t)itemIndex < m_items.size());
|
||||
|
||||
JI_LIST_FOR_EACH(combobox->items, link) {
|
||||
ComboItem* item = reinterpret_cast<ComboItem*>(link->data);
|
||||
|
||||
if ((combobox->casesensitive && ustrcmp(item->text, string) == 0) ||
|
||||
(!combobox->casesensitive && ustricmp(item->text, string) == 0))
|
||||
return index;
|
||||
index++;
|
||||
}
|
||||
|
||||
return -1;
|
||||
Item* item = m_items[itemIndex];
|
||||
item->data = data;
|
||||
}
|
||||
|
||||
int jcombobox_get_count(JWidget widget)
|
||||
Widget* ComboBox::getEntryWidget()
|
||||
{
|
||||
ComboBox* combobox = reinterpret_cast<ComboBox*>(jwidget_get_data(widget, JI_COMBOBOX));
|
||||
|
||||
return jlist_length(combobox->items);
|
||||
return m_entry;
|
||||
}
|
||||
|
||||
JWidget jcombobox_get_entry_widget(JWidget widget)
|
||||
Widget* ComboBox::getButtonWidget()
|
||||
{
|
||||
ComboBox* combobox = reinterpret_cast<ComboBox*>(jwidget_get_data(widget, JI_COMBOBOX));
|
||||
|
||||
return combobox->entry;
|
||||
return m_button;
|
||||
}
|
||||
|
||||
JWidget jcombobox_get_button_widget(JWidget widget)
|
||||
bool ComboBox::msg_proc(JMessage msg)
|
||||
{
|
||||
ComboBox* combobox = reinterpret_cast<ComboBox*>(jwidget_get_data(widget, JI_COMBOBOX));
|
||||
|
||||
return combobox->button;
|
||||
}
|
||||
|
||||
static bool combobox_msg_proc(JWidget widget, JMessage msg)
|
||||
{
|
||||
ComboBox* combobox = reinterpret_cast<ComboBox*>(jwidget_get_data(widget, JI_COMBOBOX));
|
||||
|
||||
switch (msg->type) {
|
||||
|
||||
case JM_CLOSE:
|
||||
combobox_close_window(widget);
|
||||
break;
|
||||
|
||||
case JM_DESTROY:
|
||||
jcombobox_clear(widget);
|
||||
jlist_free(combobox->items);
|
||||
jfree(combobox);
|
||||
closeListBox();
|
||||
break;
|
||||
|
||||
case JM_REQSIZE: {
|
||||
JLink link;
|
||||
int w, h;
|
||||
|
||||
msg->reqsize.w = 0;
|
||||
msg->reqsize.h = 0;
|
||||
|
||||
jwidget_request_size(combobox->entry, &w, &h);
|
||||
jwidget_request_size(m_entry, &w, &h);
|
||||
|
||||
// Get the text-length of every item and put in 'w' the maximum value
|
||||
JI_LIST_FOR_EACH(combobox->items, link) {
|
||||
std::vector<Item*>::iterator it, end = m_items.end();
|
||||
for (it = m_items.begin(); it != end; ++it) {
|
||||
int item_w =
|
||||
2*jguiscale()+
|
||||
text_length(widget->getFont(),
|
||||
((ComboItem *)link->data)->text)+
|
||||
text_length(this->getFont(), (*it)->text.c_str())+
|
||||
10*jguiscale();
|
||||
|
||||
w = MAX(w, item_w);
|
||||
@ -345,7 +289,7 @@ static bool combobox_msg_proc(JWidget widget, JMessage msg)
|
||||
msg->reqsize.w += w;
|
||||
msg->reqsize.h += h;
|
||||
|
||||
jwidget_request_size(combobox->button, &w, &h);
|
||||
jwidget_request_size(m_button, &w, &h);
|
||||
msg->reqsize.w += w;
|
||||
msg->reqsize.h = MAX(msg->reqsize.h, h);
|
||||
|
||||
@ -356,34 +300,34 @@ static bool combobox_msg_proc(JWidget widget, JMessage msg)
|
||||
JRect cbox = jrect_new_copy(&msg->setpos.rect);
|
||||
int w, h;
|
||||
|
||||
jrect_copy(widget->rc, cbox);
|
||||
jrect_copy(this->rc, cbox);
|
||||
|
||||
/* button */
|
||||
jwidget_request_size(combobox->button, &w, &h);
|
||||
jwidget_request_size(m_button, &w, &h);
|
||||
cbox->x1 = msg->setpos.rect.x2 - w;
|
||||
jwidget_set_rect(combobox->button, cbox);
|
||||
jwidget_set_rect(m_button, cbox);
|
||||
|
||||
/* entry */
|
||||
cbox->x2 = cbox->x1;
|
||||
cbox->x1 = msg->setpos.rect.x1;
|
||||
jwidget_set_rect(combobox->entry, cbox);
|
||||
jwidget_set_rect(m_entry, cbox);
|
||||
|
||||
jrect_free(cbox);
|
||||
return true;
|
||||
}
|
||||
|
||||
case JM_WINMOVE:
|
||||
if (combobox->window) {
|
||||
JRect rc = combobox_get_windowpos(combobox);
|
||||
combobox->window->move_window(rc);
|
||||
if (m_window) {
|
||||
JRect rc = getListBoxPos();
|
||||
m_window->move_window(rc);
|
||||
jrect_free(rc);
|
||||
}
|
||||
break;
|
||||
|
||||
case JM_BUTTONPRESSED:
|
||||
if (combobox->window != NULL) {
|
||||
if (!jwidget_get_view(combobox->listbox)->hasMouse()) {
|
||||
combobox_close_window(widget);
|
||||
if (m_window != NULL) {
|
||||
if (!jwidget_get_view(m_listbox)->hasMouse()) {
|
||||
closeListBox();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -391,29 +335,29 @@ static bool combobox_msg_proc(JWidget widget, JMessage msg)
|
||||
|
||||
}
|
||||
|
||||
return false;
|
||||
return Widget::msg_proc(msg);
|
||||
}
|
||||
|
||||
static bool combobox_entry_msg_proc(JWidget widget, JMessage msg)
|
||||
{
|
||||
JWidget combo_widget = reinterpret_cast<JWidget>(widget->user_data[0]);
|
||||
ComboBox* combobox = reinterpret_cast<ComboBox*>(widget->user_data[0]);
|
||||
|
||||
switch (msg->type) {
|
||||
|
||||
case JM_KEYPRESSED:
|
||||
if (widget->hasFocus()) {
|
||||
if (!jcombobox_is_editable(combo_widget)) {
|
||||
if (!combobox->isEditable()) {
|
||||
if (msg->key.scancode == KEY_SPACE ||
|
||||
msg->key.scancode == KEY_ENTER ||
|
||||
msg->key.scancode == KEY_ENTER_PAD) {
|
||||
combobox_switch_window(combo_widget);
|
||||
combobox->switchListBox();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (msg->key.scancode == KEY_ENTER ||
|
||||
msg->key.scancode == KEY_ENTER_PAD) {
|
||||
combobox_switch_window(combo_widget);
|
||||
combobox->switchListBox();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -421,12 +365,11 @@ static bool combobox_entry_msg_proc(JWidget widget, JMessage msg)
|
||||
break;
|
||||
|
||||
case JM_BUTTONPRESSED:
|
||||
if (jcombobox_is_clickopen(combo_widget)) {
|
||||
combobox_switch_window(combo_widget);
|
||||
/* combobox_open_window(combo_widget); */
|
||||
if (combobox->isClickOpen()) {
|
||||
combobox->switchListBox();
|
||||
}
|
||||
|
||||
if (jcombobox_is_editable(combo_widget)) {
|
||||
if (combobox->isEditable()) {
|
||||
jmanager_set_focus(widget);
|
||||
}
|
||||
else
|
||||
@ -455,7 +398,7 @@ static bool combobox_button_msg_proc(JWidget widget, JMessage msg)
|
||||
|
||||
static bool combobox_listbox_msg_proc(JWidget widget, JMessage msg)
|
||||
{
|
||||
JWidget combo_widget = reinterpret_cast<JWidget>(widget->user_data[0]);
|
||||
ComboBox* combobox = reinterpret_cast<ComboBox*>(widget->user_data[0]);
|
||||
|
||||
switch (msg->type) {
|
||||
|
||||
@ -463,22 +406,22 @@ static bool combobox_listbox_msg_proc(JWidget widget, JMessage msg)
|
||||
if (msg->signal.num == JI_SIGNAL_LISTBOX_CHANGE) {
|
||||
int index = jlistbox_get_selected_index(widget);
|
||||
|
||||
if (IS_VALID_ITEM(combo_widget, index)) {
|
||||
jcombobox_select_index(combo_widget, index);
|
||||
if (IS_VALID_ITEM(combobox, index)) {
|
||||
combobox->setSelectedItem(index);
|
||||
|
||||
jwidget_emit_signal(combo_widget, JI_SIGNAL_COMBOBOX_CHANGE);
|
||||
jwidget_emit_signal(combobox, JI_SIGNAL_COMBOBOX_CHANGE);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case JM_BUTTONRELEASED:
|
||||
{
|
||||
int index = jcombobox_get_selected_index(combo_widget);
|
||||
int index = combobox->getSelectedItem();
|
||||
|
||||
combobox_close_window(combo_widget);
|
||||
combobox->closeListBox();
|
||||
|
||||
if (IS_VALID_ITEM(combo_widget, index))
|
||||
jwidget_emit_signal(combo_widget, JI_SIGNAL_COMBOBOX_SELECT);
|
||||
if (IS_VALID_ITEM(combobox, index))
|
||||
jwidget_emit_signal(combobox, JI_SIGNAL_COMBOBOX_SELECT);
|
||||
}
|
||||
return true;
|
||||
|
||||
@ -502,7 +445,7 @@ static bool combobox_listbox_msg_proc(JWidget widget, JMessage msg)
|
||||
if (msg->key.scancode == KEY_SPACE ||
|
||||
msg->key.scancode == KEY_ENTER ||
|
||||
msg->key.scancode == KEY_ENTER_PAD) {
|
||||
combobox_close_window(combo_widget);
|
||||
combobox->closeListBox();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -514,113 +457,86 @@ static bool combobox_listbox_msg_proc(JWidget widget, JMessage msg)
|
||||
|
||||
static void combobox_button_cmd(JWidget widget, void *data)
|
||||
{
|
||||
combobox_switch_window(reinterpret_cast<JWidget>(data));
|
||||
ComboBox* combobox = reinterpret_cast<ComboBox*>(data);
|
||||
combobox->switchListBox();
|
||||
}
|
||||
|
||||
static void combobox_open_window(JWidget widget)
|
||||
void ComboBox::openListBox()
|
||||
{
|
||||
ComboBox* combobox = reinterpret_cast<ComboBox*>(jwidget_get_data(widget, JI_COMBOBOX));
|
||||
if (!combobox->window) {
|
||||
JWidget view;
|
||||
JLink link;
|
||||
int size;
|
||||
JRect rc;
|
||||
if (!m_window) {
|
||||
m_window = new Frame(false, NULL);
|
||||
Widget* view = jview_new();
|
||||
m_listbox = jlistbox_new();
|
||||
|
||||
combobox->window = new Frame(false, NULL);
|
||||
view = jview_new();
|
||||
combobox->listbox = jlistbox_new();
|
||||
|
||||
combobox->listbox->user_data[0] = widget;
|
||||
jwidget_add_hook(combobox->listbox, JI_WIDGET,
|
||||
m_listbox->user_data[0] = this;
|
||||
jwidget_add_hook(m_listbox, JI_WIDGET,
|
||||
combobox_listbox_msg_proc, NULL);
|
||||
|
||||
JI_LIST_FOR_EACH(combobox->items, link) {
|
||||
ComboItem* item = reinterpret_cast<ComboItem*>(link->data);
|
||||
jwidget_add_child(combobox->listbox,
|
||||
jlistitem_new(item->text));
|
||||
std::vector<Item*>::iterator it, end = m_items.end();
|
||||
for (it = m_items.begin(); it != end; ++it) {
|
||||
Item* item = *it;
|
||||
jwidget_add_child(m_listbox, jlistitem_new(item->text.c_str()));
|
||||
}
|
||||
|
||||
combobox->window->set_ontop(true);
|
||||
jwidget_noborders(combobox->window);
|
||||
m_window->set_ontop(true);
|
||||
jwidget_noborders(m_window);
|
||||
|
||||
Widget* viewport = jview_get_viewport(view);
|
||||
size = jlist_length(combobox->items);
|
||||
int size = getItemCount();
|
||||
jwidget_set_min_size
|
||||
(viewport,
|
||||
combobox->button->rc->x2 - combobox->entry->rc->x1 - view->border_width.l - view->border_width.r,
|
||||
m_button->rc->x2 - m_entry->rc->x1 - view->border_width.l - view->border_width.r,
|
||||
+viewport->border_width.t
|
||||
+(2*jguiscale()+jwidget_get_text_height(combobox->listbox))*MID(1, size, 16)+
|
||||
+(2*jguiscale()+jwidget_get_text_height(m_listbox))*MID(1, size, 16)+
|
||||
+viewport->border_width.b);
|
||||
|
||||
jwidget_add_child(combobox->window, view);
|
||||
jview_attach(view, combobox->listbox);
|
||||
jwidget_add_child(m_window, view);
|
||||
jview_attach(view, m_listbox);
|
||||
|
||||
jwidget_signal_off(combobox->listbox);
|
||||
jlistbox_select_index(combobox->listbox, combobox->selected);
|
||||
jwidget_signal_on(combobox->listbox);
|
||||
jwidget_signal_off(m_listbox);
|
||||
jlistbox_select_index(m_listbox, m_selected);
|
||||
jwidget_signal_on(m_listbox);
|
||||
|
||||
combobox->window->remap_window();
|
||||
m_window->remap_window();
|
||||
|
||||
rc = combobox_get_windowpos(combobox);
|
||||
combobox->window->position_window(rc->x1, rc->y1);
|
||||
JRect rc = getListBoxPos();
|
||||
m_window->position_window(rc->x1, rc->y1);
|
||||
jrect_free(rc);
|
||||
|
||||
jmanager_add_msg_filter(JM_BUTTONPRESSED, widget);
|
||||
jmanager_add_msg_filter(JM_BUTTONPRESSED, this);
|
||||
|
||||
combobox->window->open_window_bg();
|
||||
jmanager_set_focus(combobox->listbox);
|
||||
m_window->open_window_bg();
|
||||
jmanager_set_focus(m_listbox);
|
||||
}
|
||||
}
|
||||
|
||||
static void combobox_close_window(JWidget widget)
|
||||
void ComboBox::closeListBox()
|
||||
{
|
||||
ComboBox* combobox = reinterpret_cast<ComboBox*>(jwidget_get_data(widget, JI_COMBOBOX));
|
||||
if (combobox->window) {
|
||||
combobox->window->closeWindow(widget);
|
||||
jwidget_free(combobox->window);
|
||||
combobox->window = NULL;
|
||||
if (m_window) {
|
||||
m_window->closeWindow(this);
|
||||
delete m_window; // window, frame
|
||||
m_window = NULL;
|
||||
|
||||
jmanager_remove_msg_filter(JM_BUTTONPRESSED, widget);
|
||||
jmanager_set_focus(combobox->entry);
|
||||
jmanager_remove_msg_filter(JM_BUTTONPRESSED, this);
|
||||
jmanager_set_focus(m_entry);
|
||||
}
|
||||
}
|
||||
|
||||
static void combobox_switch_window(JWidget widget)
|
||||
void ComboBox::switchListBox()
|
||||
{
|
||||
ComboBox* combobox = reinterpret_cast<ComboBox*>(jwidget_get_data(widget, JI_COMBOBOX));
|
||||
if (!combobox->window)
|
||||
combobox_open_window(widget);
|
||||
if (!m_window)
|
||||
openListBox();
|
||||
else
|
||||
combobox_close_window(widget);
|
||||
closeListBox();
|
||||
}
|
||||
|
||||
static JRect combobox_get_windowpos(ComboBox *combobox)
|
||||
JRect ComboBox::getListBoxPos()
|
||||
{
|
||||
JRect rc = jrect_new(combobox->entry->rc->x1,
|
||||
combobox->entry->rc->y2,
|
||||
combobox->button->rc->x2,
|
||||
combobox->entry->rc->y2+jrect_h(combobox->window->rc));
|
||||
JRect rc = jrect_new(m_entry->rc->x1,
|
||||
m_entry->rc->y2,
|
||||
m_button->rc->x2,
|
||||
m_entry->rc->y2+jrect_h(m_window->rc));
|
||||
if (rc->y2 > JI_SCREEN_H)
|
||||
jrect_displace(rc, 0, -(jrect_h(rc)+jrect_h(combobox->entry->rc)));
|
||||
jrect_displace(rc, 0, -(jrect_h(rc)+jrect_h(m_entry->rc)));
|
||||
return rc;
|
||||
}
|
||||
|
||||
static ComboItem *comboitem_new(const char *text, void *data)
|
||||
{
|
||||
ComboItem *comboitem = jnew(ComboItem, 1);
|
||||
if (!comboitem)
|
||||
return NULL;
|
||||
|
||||
comboitem->text = jstrdup(text);
|
||||
comboitem->data = data;
|
||||
|
||||
return comboitem;
|
||||
}
|
||||
|
||||
static void comboitem_free(ComboItem *comboitem)
|
||||
{
|
||||
if (comboitem->text)
|
||||
jfree(comboitem->text);
|
||||
|
||||
jfree(comboitem);
|
||||
}
|
||||
|
@ -32,35 +32,66 @@
|
||||
#ifndef JINETE_JCOMBOBOX_H_INCLUDED
|
||||
#define JINETE_JCOMBOBOX_H_INCLUDED
|
||||
|
||||
#include "jinete/jbase.h"
|
||||
#include "jinete/jwidget.h"
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
JWidget jcombobox_new();
|
||||
class Frame;
|
||||
|
||||
void jcombobox_editable(JWidget combobox, bool state);
|
||||
void jcombobox_clickopen(JWidget combobox, bool state);
|
||||
void jcombobox_casesensitive(JWidget combobox, bool state);
|
||||
class ComboBox : public Widget
|
||||
{
|
||||
public:
|
||||
ComboBox();
|
||||
~ComboBox();
|
||||
|
||||
bool jcombobox_is_editable(JWidget combobox);
|
||||
bool jcombobox_is_clickopen(JWidget combobox);
|
||||
bool jcombobox_is_casesensitive(JWidget combobox);
|
||||
void setEditable(bool state);
|
||||
void setClickOpen(bool state);
|
||||
void setCaseSensitive(bool state);
|
||||
|
||||
void jcombobox_add_string(JWidget combobox, const char *string, void *data);
|
||||
void jcombobox_insert_string(JWidget combobox, int index, const char *string, void *data);
|
||||
void jcombobox_del_string(JWidget combobox, const char *string);
|
||||
void jcombobox_del_index(JWidget combobox, int index);
|
||||
void jcombobox_clear(JWidget combobox);
|
||||
bool isEditable();
|
||||
bool isClickOpen();
|
||||
bool isCaseSensitive();
|
||||
|
||||
void jcombobox_select_index(JWidget combobox, int index);
|
||||
void jcombobox_select_string(JWidget combobox, const char *string);
|
||||
int jcombobox_get_selected_index(JWidget combobox);
|
||||
const char *jcombobox_get_selected_string(JWidget combobox);
|
||||
int addItem(const std::string& text);
|
||||
void insertItem(int itemIndex, const std::string& text);
|
||||
void removeItem(int itemIndex);
|
||||
void removeAllItems();
|
||||
|
||||
const char *jcombobox_get_string(JWidget combobox, int index);
|
||||
void *jcombobox_get_data(JWidget combobox, int index);
|
||||
int jcombobox_get_index(JWidget combobox, const char *string);
|
||||
int jcombobox_get_count(JWidget combobox);
|
||||
int getItemCount();
|
||||
|
||||
JWidget jcombobox_get_entry_widget(JWidget combobox);
|
||||
JWidget jcombobox_get_button_widget(JWidget combobox);
|
||||
std::string getItemText(int itemIndex);
|
||||
void setItemText(int itemIndex, const std::string& text);
|
||||
int findItemIndex(const std::string& text);
|
||||
|
||||
int getSelectedItem();
|
||||
void setSelectedItem(int itemIndex);
|
||||
|
||||
void* getItemData(int itemIndex);
|
||||
void setItemData(int itemIndex, void* data);
|
||||
|
||||
Widget* getEntryWidget();
|
||||
Widget* getButtonWidget();
|
||||
|
||||
void openListBox();
|
||||
void closeListBox();
|
||||
void switchListBox();
|
||||
JRect getListBoxPos();
|
||||
|
||||
protected:
|
||||
virtual bool msg_proc(JMessage msg);
|
||||
|
||||
private:
|
||||
struct Item;
|
||||
|
||||
Widget* m_entry;
|
||||
Widget* m_button;
|
||||
Frame* m_window;
|
||||
Widget* m_listbox;
|
||||
std::vector<Item*> m_items;
|
||||
int m_selected;
|
||||
bool m_editable : 1;
|
||||
bool m_clickopen : 1;
|
||||
bool m_casesensitive : 1;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -175,7 +175,7 @@ static JWidget convert_xmlelement_to_widget(TiXmlElement* elem)
|
||||
}
|
||||
/* combobox */
|
||||
else if (ustrcmp(elem_name, "combobox") == 0) {
|
||||
widget = jcombobox_new();
|
||||
widget = new ComboBox();
|
||||
}
|
||||
/* entry */
|
||||
else if (ustrcmp(elem_name, "entry") == 0) {
|
||||
|
@ -315,8 +315,11 @@ void jstandard_theme::init_widget(JWidget widget)
|
||||
break;
|
||||
|
||||
case JI_COMBOBOX: {
|
||||
JWidget button = jcombobox_get_button_widget(widget);
|
||||
ji_generic_button_set_icon(button, icons_bitmap[ICON_COMBOBOX]);
|
||||
ComboBox* combobox = dynamic_cast<ComboBox*>(widget);
|
||||
if (combobox != NULL) {
|
||||
Widget* button = combobox->getButtonWidget();
|
||||
ji_generic_button_set_icon(button, icons_bitmap[ICON_COMBOBOX]);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -422,7 +422,10 @@ void SkinneableTheme::init_widget(JWidget widget)
|
||||
|
||||
case JI_COMBOBOX:
|
||||
{
|
||||
JWidget button = jcombobox_get_button_widget(widget);
|
||||
ComboBox* combobox = dynamic_cast<ComboBox*>(widget);
|
||||
assert(combobox != NULL);
|
||||
|
||||
Widget* button = combobox->getButtonWidget();
|
||||
|
||||
button->border_width.l = 0;
|
||||
button->border_width.t = 0;
|
||||
|
Loading…
x
Reference in New Issue
Block a user