Skip to content

Commit

Permalink
macOS support for edit_select()
Browse files Browse the repository at this point in the history
  • Loading branch information
frang75 committed Jul 2, 2024
1 parent b1c8550 commit d54bdc2
Show file tree
Hide file tree
Showing 17 changed files with 219 additions and 44 deletions.
88 changes: 78 additions & 10 deletions demo/guihello/form.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* Form demo */

#include "form.h"
#include "res_guihello.h"
#include <gui/guiall.h>

/*---------------------------------------------------------------------------*/
Expand All @@ -14,8 +15,8 @@ struct _form_data_t
Button *validate_check;
};

#define BUTTON_YES 1000
#define BUTTON_NO 1001
#define BUTTON_YES 1000
#define BUTTON_NO 1001

/*---------------------------------------------------------------------------*/

Expand Down Expand Up @@ -70,7 +71,7 @@ static Window *i_modal_window(FormData *data, Edit *edit, const GuiControl *next
Button *button2 = button_push();
Panel *panel = panel_create();
Window *window = window_create(ekWINDOW_STD | ekWINDOW_ESC);
String *str = str_printf("Do you want to validate the text '%s' of the EditBox '%p'? The focus will be moved to the '%p' control using the '%s' action.", field_text, (void*)edit, (void*)next, action_text);
String *str = str_printf("Do you want to validate the text '%s' of the EditBox '%p'? The focus will be moved to the '%p' control using the '%s' action.", field_text, (void *)edit, (void *)next, action_text);
label_text(label, tc(str));
button_text(button1, "Yes");
button_text(button2, "No");
Expand Down Expand Up @@ -148,15 +149,15 @@ static bool_t i_validate_field(FormData *data, Edit *edit, const char_t *text)
window_origin(data->modal_window, pos);
modal_value = window_modal(data->modal_window, data->window);
window_destroy(&data->modal_window);
switch(modal_value)
switch (modal_value)
{
case ekGUI_CLOSE_BUTTON:
case ekGUI_CLOSE_ESC:
case BUTTON_NO:
return FALSE;
case BUTTON_YES:
return TRUE;
cassert_default();
cassert_default();
}

return TRUE;
Expand Down Expand Up @@ -201,6 +202,7 @@ static Layout *i_numbers(FormData *data, color_t colorbg)
label_text(label, "Height (cm):");
edit_text(edit1, "25");
edit_text(edit2, "175");
edit_autoselect(edit1, TRUE);
edit_align(edit1, ekRIGHT);
edit_align(edit2, ekRIGHT);
edit_OnFilter(edit1, listener(NULL, i_OnFilter, void));
Expand Down Expand Up @@ -262,6 +264,7 @@ static Layout *i_edits(FormData *data)
edit_OnChange(edit3, listener(data, i_OnEditChange, FormData));
edit_OnChange(edit4, listener(data, i_OnEditChange, FormData));
edit_OnChange(edit5, listener(data, i_OnEditChange, FormData));
edit_select(edit1, 2, 6);
edit_passmode(edit2, TRUE);
edit_bgcolor_focus(edit1, colorbg);
edit_bgcolor_focus(edit2, colorbg);
Expand Down Expand Up @@ -292,27 +295,93 @@ static Layout *i_edits(FormData *data)

/*---------------------------------------------------------------------------*/

static void i_OnCopy(FormData *data, Event *e)
{
GuiControl *control = window_get_focus(data->window);
Edit *edit = guicontrol_edit(control);
unref(e);
if (edit != NULL)
edit_copy(edit);
}

/*---------------------------------------------------------------------------*/

static void i_OnPaste(FormData *data, Event *e)
{
GuiControl *control = window_get_focus(data->window);
Edit *edit = guicontrol_edit(control);
unref(e);
if (edit != NULL)
edit_paste(edit);
}

/*---------------------------------------------------------------------------*/

static void i_OnCut(FormData *data, Event *e)
{
GuiControl *control = window_get_focus(data->window);
Edit *edit = guicontrol_edit(control);
unref(e);
if (edit != NULL)
edit_cut(edit);
}

/*---------------------------------------------------------------------------*/

static Layout *i_toolbar(FormData *data)
{
Layout *layout = layout_create(4, 1);
Button *check = button_check();
Button *button1 = button_flat();
Button *button2 = button_flat();
Button *button3 = button_flat();
button_text(check, "Field validations");
button_image(button1, gui_image(COPY_PNG));
button_image(button2, gui_image(PASTE_PNG));
button_image(button3, gui_image(CUT_PNG));
button_OnClick(button1, listener(data, i_OnCopy, FormData));
button_OnClick(button2, listener(data, i_OnPaste, FormData));
button_OnClick(button3, listener(data, i_OnCut, FormData));
button_tooltip(button1, "Copy");
button_tooltip(button2, "Paste");
button_tooltip(button3, "Cut");
layout_button(layout, check, 0, 0);
layout_button(layout, button1, 1, 0);
layout_button(layout, button2, 2, 0);
layout_button(layout, button3, 3, 0);
layout_tabstop(layout, 0, 0, FALSE);
layout_tabstop(layout, 1, 0, FALSE);
layout_tabstop(layout, 2, 0, FALSE);
layout_tabstop(layout, 3, 0, FALSE);
layout_hmargin(layout, 0, 5);
layout_hmargin(layout, 1, 5);
layout_hmargin(layout, 2, 5);
data->validate_check = check;
return layout;
}

/*---------------------------------------------------------------------------*/

static Layout *i_form(FormData *data)
{
Layout *layout1 = layout_create(1, 3);
Layout *layout2 = i_edits(data);
Button *check = button_check();
Layout *layout3 = i_toolbar(data);
Label *label = label_multiline();
cassert_no_null(data);
button_text(check, "Field validations");
label_text(label, "Please fill in all the information on the form. We will use this data to send commercial mail at all hours, not caring much if it bothers you or not.");
label_color(label, gui_alt_color(color_rgb(255, 0, 0), color_rgb(180, 180, 180)));
label_bgcolor(label, gui_alt_color(color_rgb(216, 191, 216), color_rgb(80, 40, 40)));
label_bgcolor_over(label, gui_alt_color(color_rgb(255, 250, 205), color_rgb(105, 100, 55)));
label_style_over(label, ekFUNDERLINE);
layout_layout(layout1, layout2, 0, 0);
layout_button(layout1, check, 0, 1);
layout_layout(layout1, layout3, 0, 1);
layout_label(layout1, label, 0, 2);
layout_hsize(layout1, 0, 300);
layout_halign(layout1, 0, 1, ekLEFT);
layout_vmargin(layout1, 0, 10);
layout_vmargin(layout1, 1, 10);
layout_margin(layout1, 10);
data->validate_check = check;
return layout1;
}

Expand All @@ -336,4 +405,3 @@ Panel *form_basic(Window *window)
panel_layout(panel, layout);
return panel;
}

26 changes: 13 additions & 13 deletions demo/guihello/popcom.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@ static void i_popups(Layout *layout)
PopUp *popup2 = popup_create();
label_text(label1, "Language:");
label_text(label2, "Color:");
popup_add_elem(popup1, "English", (const Image*)UKING_PNG);
popup_add_elem(popup1, "Español", (const Image*)SPAIN_PNG);
popup_add_elem(popup1, "Portugues", (const Image*)PORTUGAL_PNG);
popup_add_elem(popup1, "Italiana", (const Image*)ITALY_PNG);
popup_add_elem(popup1, "Tiếng Việt", (const Image*)VIETNAM_PNG);
popup_add_elem(popup1, "России", (const Image*)RUSSIA_PNG);
popup_add_elem(popup1, "日本語", (const Image*)JAPAN_PNG);
popup_add_elem(popup2, "Red", (const Image*)RED_PNG);
popup_add_elem(popup2, "Blue", (const Image*)BLUE_PNG);
popup_add_elem(popup2, "Green", (const Image*)GREEN_PNG);
popup_add_elem(popup2, "Yellow", (const Image*)YELLOW_PNG);
popup_add_elem(popup2, "Black", (const Image*)BLACK_PNG);
popup_add_elem(popup2, "White", (const Image*)WHITE_PNG);
popup_add_elem(popup1, "English", gui_image(UKING_PNG));
popup_add_elem(popup1, "Español", gui_image(SPAIN_PNG));
popup_add_elem(popup1, "Portugues", gui_image(PORTUGAL_PNG));
popup_add_elem(popup1, "Italiana", gui_image(ITALY_PNG));
popup_add_elem(popup1, "Tiếng Việt", gui_image(VIETNAM_PNG));
popup_add_elem(popup1, "России", gui_image(RUSSIA_PNG));
popup_add_elem(popup1, "日本語", gui_image(JAPAN_PNG));
popup_add_elem(popup2, "Red", gui_image(RED_PNG));
popup_add_elem(popup2, "Blue", gui_image(BLUE_PNG));
popup_add_elem(popup2, "Green", gui_image(GREEN_PNG));
popup_add_elem(popup2, "Yellow", gui_image(YELLOW_PNG));
popup_add_elem(popup2, "Black", gui_image(BLACK_PNG));
popup_add_elem(popup2, "White", gui_image(WHITE_PNG));
popup_list_height(popup1, 10);
popup_list_height(popup2, 10);
layout_label(layout, label1, 0, 0);
Expand Down
Binary file added demo/guihello/res/res_guihello/copy.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added demo/guihello/res/res_guihello/cut.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added demo/guihello/res/res_guihello/paste.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion prj/build.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5194
5201
4 changes: 3 additions & 1 deletion src/gui/listbox.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,9 @@ static void i_OnDraw(ListBox *listbox, Event *e)
uint32_t i;

fill_width -= scrollview_scrollbar_width(data->sview);
fill_width -= i_RIGHT_PADDING;
#if defined(__WINDOWS__)
fill_width -= 2;
#endif

draw_font(p->ctx, data->font);
for (i = strow; i < edrow; ++i)
Expand Down
4 changes: 2 additions & 2 deletions src/gui/scrollview.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ void scrollview_content_size(ScrollView *view, const uint32_t content_width, con
view_scroll_size(view->view, &bar_width, &bar_height);
view->scrollbar_width = (uint32_t)bar_width;
view->scrollbar_height = (uint32_t)bar_height;
twidth += view->scrollbar_width;
theight += view->scrollbar_height;

if (twidth < view->control_width)
twidth = view->control_width;
Expand All @@ -148,8 +150,6 @@ void scrollview_content_size(ScrollView *view, const uint32_t content_width, con

view->content_width = twidth;
view->content_height = theight;
twidth += view->scrollbar_width;
theight += view->scrollbar_height;

if (twidth != content_width || theight != content_height)
view_content_size(view->view, s2df((real32_t)twidth, (real32_t)theight), s2df((real32_t)line_width, (real32_t)line_height));
Expand Down
8 changes: 8 additions & 0 deletions src/osgui/gtk/oscontrol.c
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,14 @@ void oscontrol_frame(const OSControl *control, OSFrame *rect)

/*---------------------------------------------------------------------------*/

void oscontrol_set_can_focus(OSControl *control, const bool_t can_focus)
{
OSWidget *widget = oscontrol_focus_widget(control);
gtk_widget_set_can_focus(cast(widget, GtkWidget), can_focus);
}

/*---------------------------------------------------------------------------*/

OSWidget *oscontrol_focus_widget(const OSControl *control)
{
cassert_no_null(control);
Expand Down
2 changes: 2 additions & 0 deletions src/osgui/oscontrol.inl
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ OSControl *oscontrol_parent(const OSControl *control);

void oscontrol_frame(const OSControl *control, OSFrame *rect);

void oscontrol_set_can_focus(OSControl *control, const bool_t can_focus);

OSWidget *oscontrol_focus_widget(const OSControl *control);

bool_t oscontrol_widget_visible(const OSWidget *widget);
Expand Down
28 changes: 26 additions & 2 deletions src/osgui/ostabstop.c
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,11 @@ static void i_set_focus(OSTabStop *tabstop, OSControl *control)
cassert_no_null(tabstop);
cassert(arrpt_find(tabstop->controls, control, OSControl) != UINT32_MAX);

if (tabstop->transient != NULL)
ostabstop_release_transient(tabstop, tabstop->transient);

oswindow_widget_set_focus(tabstop->window, widget);
tabstop->current = control;
cassert(tabstop->transient == NULL);

/* We remember the last tablist focused control */
tabindex = arrpt_find(tabstop->tablist, control, OSControl);
Expand Down Expand Up @@ -302,6 +304,24 @@ static void i_on_focus(OSControl *control, const bool_t focused)

/*---------------------------------------------------------------------------*/

static bool_t i_is_next_transient(const OSTabStop *tabstop, OSControl *focus, OSControl *next)
{
if (next != NULL && focus != next)
{
/* If button is not in the tablist, can't get the focus */
gui_type_t type = oscontrol_type(next);
if (type == ekGUI_TYPE_BUTTON && ostabstop_in_tablist(tabstop, next) == FALSE)
{
oscontrol_set_can_focus(next, FALSE);
return TRUE;
}
}

return FALSE;
}

/*---------------------------------------------------------------------------*/

static gui_focus_t i_try_change_focus(OSTabStop *tabstop, OSControl *control, const gui_tab_t motion, const bool_t forward)
{
gui_focus_t fstate = ENUM_MAX(gui_focus_t);
Expand All @@ -318,11 +338,14 @@ static gui_focus_t i_try_change_focus(OSTabStop *tabstop, OSControl *control, co
next_control = i_effective_focus(tabstop, control, forward);
tabstop->next = next_control;

if (i_is_next_transient(tabstop, focus, next_control) == TRUE)
resign = FALSE;

/*
* 'focus' and 'next_control' can be the same but,
* we force validation events in non-cycle-one-control tablists
*/
if (focus != NULL)
if (resign == TRUE && focus != NULL)
resign = ostabstop_resign_focus(tabstop, focus);

/* The current focused control resign the focus */
Expand Down Expand Up @@ -568,6 +591,7 @@ void ostabstop_release_transient(OSTabStop *tabstop, OSControl *control)
if (tabstop->transient != NULL)
{
cassert_unref(tabstop->transient == control, control);
oscontrol_set_can_focus(tabstop->transient, TRUE);
tabstop->transient = NULL;
if (tabstop->current != NULL)
{
Expand Down
8 changes: 8 additions & 0 deletions src/osgui/osx/oscontrol.m
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,14 @@ void oscontrol_frame(const OSControl *control, OSFrame *rect)

/*---------------------------------------------------------------------------*/

void oscontrol_set_can_focus(OSControl *control, const bool_t can_focus)
{
unref(control);
unref(can_focus);
}

/*---------------------------------------------------------------------------*/

OSWidget *oscontrol_focus_widget(const OSControl *control)
{
cassert_no_null(control);
Expand Down
Loading

0 comments on commit d54bdc2

Please sign in to comment.