Tue, 09 Jun 2026 18:50:13 +0200
fix AppDelegate source file case (Cocoa)
| 5 | 1 | /* |
| 2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. | |
| 3 | * | |
|
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
4 | * Copyright 2017 Olaf Wintermann. All rights reserved. |
| 5 | 5 | * |
| 6 | * Redistribution and use in source and binary forms, with or without | |
| 7 | * modification, are permitted provided that the following conditions are met: | |
| 8 | * | |
| 9 | * 1. Redistributions of source code must retain the above copyright | |
| 10 | * notice, this list of conditions and the following disclaimer. | |
| 11 | * | |
| 12 | * 2. Redistributions in binary form must reproduce the above copyright | |
| 13 | * notice, this list of conditions and the following disclaimer in the | |
| 14 | * documentation and/or other materials provided with the distribution. | |
| 15 | * | |
| 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |
| 17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
| 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
| 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE | |
| 20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
| 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
| 22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
| 23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
| 24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
| 25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
| 26 | * POSSIBILITY OF SUCH DAMAGE. | |
| 27 | */ | |
| 28 | ||
| 29 | #include <stdio.h> | |
| 30 | #include <stdlib.h> | |
|
6
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
31 | #include <string.h> |
| 5 | 32 | |
| 33 | #include "text.h" | |
| 34 | #include "container.h" | |
|
965
5d4419042d9b
implement dynamic table models (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
962
diff
changeset
|
35 | #include "widget.h" |
|
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
36 | |
|
282
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
37 | #include <cx/printf.h> |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
38 | |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
39 | #include <gdk/gdkkeysyms.h> |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
40 | |
| 5 | 41 | |
| 174 | 42 | #include "../common/types.h" |
| 43 | ||
|
22
bcf880b29bc3
textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
44 | static void selection_handler( |
|
bcf880b29bc3
textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
45 | GtkTextBuffer *buf, |
|
bcf880b29bc3
textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
46 | GtkTextIter *location, |
|
bcf880b29bc3
textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
47 | GtkTextMark *mark, |
|
bcf880b29bc3
textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
48 | UiTextArea *textview) |
|
bcf880b29bc3
textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
49 | { |
|
bcf880b29bc3
textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
50 | const char *mname = gtk_text_mark_get_name(mark); |
|
bcf880b29bc3
textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
51 | if(mname) { |
|
bcf880b29bc3
textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
52 | GtkTextIter begin; |
|
bcf880b29bc3
textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
53 | GtkTextIter end; |
|
bcf880b29bc3
textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
54 | int sel = gtk_text_buffer_get_selection_bounds (buf, &begin, &end); |
|
bcf880b29bc3
textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
55 | if(sel != textview->last_selection_state) { |
|
bcf880b29bc3
textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
56 | if(sel) { |
|
967
ff4a8d10307b
rename ui_set_group/ui_unset_group
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
966
diff
changeset
|
57 | ui_set_state(textview->ctx, UI_GROUP_SELECTION); |
|
22
bcf880b29bc3
textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
58 | } else { |
|
967
ff4a8d10307b
rename ui_set_group/ui_unset_group
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
966
diff
changeset
|
59 | ui_unset_state(textview->ctx, UI_GROUP_SELECTION); |
|
22
bcf880b29bc3
textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
60 | } |
|
bcf880b29bc3
textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
61 | } |
|
bcf880b29bc3
textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
62 | textview->last_selection_state = sel; |
|
bcf880b29bc3
textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
63 | } |
|
bcf880b29bc3
textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
64 | } |
|
bcf880b29bc3
textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
65 | |
|
486
a5f3abf8b9d1
refactor textarea to store a text buffer object in UiText values (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
66 | static void textarea_set_text_funcs(UiText *value) { |
|
a5f3abf8b9d1
refactor textarea to store a text buffer object in UiText values (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
67 | |
|
a5f3abf8b9d1
refactor textarea to store a text buffer object in UiText values (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
68 | } |
|
a5f3abf8b9d1
refactor textarea to store a text buffer object in UiText values (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
69 | |
|
a5f3abf8b9d1
refactor textarea to store a text buffer object in UiText values (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
70 | #if GTK_MAJOR_VERSION == 2 |
|
a5f3abf8b9d1
refactor textarea to store a text buffer object in UiText values (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
71 | static void textarea_set_undomgr(GtkWidget *text_area, UiText *value) { |
|
a5f3abf8b9d1
refactor textarea to store a text buffer object in UiText values (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
72 | GtkTextBuffer *buf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text_area)); |
|
a5f3abf8b9d1
refactor textarea to store a text buffer object in UiText values (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
73 | |
|
a5f3abf8b9d1
refactor textarea to store a text buffer object in UiText values (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
74 | if(!value->data2) { |
|
a5f3abf8b9d1
refactor textarea to store a text buffer object in UiText values (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
75 | value->data2 = ui_create_undomgr(); |
|
a5f3abf8b9d1
refactor textarea to store a text buffer object in UiText values (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
76 | } |
|
a5f3abf8b9d1
refactor textarea to store a text buffer object in UiText values (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
77 | |
|
a5f3abf8b9d1
refactor textarea to store a text buffer object in UiText values (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
78 | // register undo manager |
|
a5f3abf8b9d1
refactor textarea to store a text buffer object in UiText values (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
79 | g_signal_connect( |
|
a5f3abf8b9d1
refactor textarea to store a text buffer object in UiText values (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
80 | buf, |
|
a5f3abf8b9d1
refactor textarea to store a text buffer object in UiText values (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
81 | "insert-text", |
|
a5f3abf8b9d1
refactor textarea to store a text buffer object in UiText values (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
82 | G_CALLBACK(ui_textbuf_insert), |
|
a5f3abf8b9d1
refactor textarea to store a text buffer object in UiText values (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
83 | var); |
|
a5f3abf8b9d1
refactor textarea to store a text buffer object in UiText values (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
84 | g_signal_connect( |
|
a5f3abf8b9d1
refactor textarea to store a text buffer object in UiText values (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
85 | buf, |
|
a5f3abf8b9d1
refactor textarea to store a text buffer object in UiText values (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
86 | "delete-range", |
|
a5f3abf8b9d1
refactor textarea to store a text buffer object in UiText values (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
87 | G_CALLBACK(ui_textbuf_delete), |
|
a5f3abf8b9d1
refactor textarea to store a text buffer object in UiText values (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
88 | var); |
|
a5f3abf8b9d1
refactor textarea to store a text buffer object in UiText values (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
89 | g_signal_connect( |
|
a5f3abf8b9d1
refactor textarea to store a text buffer object in UiText values (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
90 | buf, |
|
a5f3abf8b9d1
refactor textarea to store a text buffer object in UiText values (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
91 | "mark-set", |
|
a5f3abf8b9d1
refactor textarea to store a text buffer object in UiText values (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
92 | G_CALLBACK(selection_handler), |
|
a5f3abf8b9d1
refactor textarea to store a text buffer object in UiText values (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
93 | uitext); |
|
a5f3abf8b9d1
refactor textarea to store a text buffer object in UiText values (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
94 | } |
|
a5f3abf8b9d1
refactor textarea to store a text buffer object in UiText values (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
95 | #endif |
|
a5f3abf8b9d1
refactor textarea to store a text buffer object in UiText values (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
96 | |
|
506
02ddf1044cbc
connect changed event to all textbuffer objects (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
505
diff
changeset
|
97 | static GtkTextBuffer* create_textbuffer(UiTextArea *textarea) { |
|
02ddf1044cbc
connect changed event to all textbuffer objects (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
505
diff
changeset
|
98 | GtkTextBuffer *buf = gtk_text_buffer_new(NULL); |
|
02ddf1044cbc
connect changed event to all textbuffer objects (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
505
diff
changeset
|
99 | if(textarea) { |
|
02ddf1044cbc
connect changed event to all textbuffer objects (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
505
diff
changeset
|
100 | g_signal_connect( |
|
02ddf1044cbc
connect changed event to all textbuffer objects (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
505
diff
changeset
|
101 | buf, |
|
02ddf1044cbc
connect changed event to all textbuffer objects (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
505
diff
changeset
|
102 | "changed", |
|
02ddf1044cbc
connect changed event to all textbuffer objects (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
505
diff
changeset
|
103 | G_CALLBACK(ui_textbuf_changed), |
|
02ddf1044cbc
connect changed event to all textbuffer objects (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
505
diff
changeset
|
104 | textarea); |
|
1149
76b7664f951e
change textarea change events to include UiTextChangeEventData (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1142
diff
changeset
|
105 | |
|
76b7664f951e
change textarea change events to include UiTextChangeEventData (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1142
diff
changeset
|
106 | g_signal_connect( |
|
76b7664f951e
change textarea change events to include UiTextChangeEventData (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1142
diff
changeset
|
107 | buf, |
|
76b7664f951e
change textarea change events to include UiTextChangeEventData (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1142
diff
changeset
|
108 | "insert-text", |
|
1153
f15375e0480c
add separate textarea change events for before and after changes (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1149
diff
changeset
|
109 | G_CALLBACK(ui_textbuf_change_insert), |
|
1149
76b7664f951e
change textarea change events to include UiTextChangeEventData (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1142
diff
changeset
|
110 | textarea); |
|
76b7664f951e
change textarea change events to include UiTextChangeEventData (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1142
diff
changeset
|
111 | g_signal_connect( |
|
76b7664f951e
change textarea change events to include UiTextChangeEventData (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1142
diff
changeset
|
112 | buf, |
|
76b7664f951e
change textarea change events to include UiTextChangeEventData (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1142
diff
changeset
|
113 | "delete-range", |
|
1153
f15375e0480c
add separate textarea change events for before and after changes (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1149
diff
changeset
|
114 | G_CALLBACK(ui_textbuf_change_delete), |
|
1149
76b7664f951e
change textarea change events to include UiTextChangeEventData (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1142
diff
changeset
|
115 | textarea); |
|
506
02ddf1044cbc
connect changed event to all textbuffer objects (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
505
diff
changeset
|
116 | } else { |
|
02ddf1044cbc
connect changed event to all textbuffer objects (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
505
diff
changeset
|
117 | fprintf(stderr, "Error: create_textbuffer: textarea == NULL\n"); |
|
02ddf1044cbc
connect changed event to all textbuffer objects (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
505
diff
changeset
|
118 | } |
|
02ddf1044cbc
connect changed event to all textbuffer objects (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
505
diff
changeset
|
119 | return buf; |
|
02ddf1044cbc
connect changed event to all textbuffer objects (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
505
diff
changeset
|
120 | } |
|
02ddf1044cbc
connect changed event to all textbuffer objects (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
505
diff
changeset
|
121 | |
|
594
fc854e0ab924
pass Args structs per pointer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
506
diff
changeset
|
122 | UIWIDGET ui_textarea_create(UiObject *obj, UiTextAreaArgs *args) { |
|
801
e096c441e874
refactor gtk container hierarchy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
788
diff
changeset
|
123 | UiVar* var = uic_widget_var(obj->ctx, obj->ctx, args->value, args->varname, UI_VAR_TEXT); |
|
335
91d4f0391282
add new textarea (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
326
diff
changeset
|
124 | |
| 5 | 125 | GtkWidget *text_area = gtk_text_view_new(); |
|
594
fc854e0ab924
pass Args structs per pointer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
506
diff
changeset
|
126 | ui_set_name_and_style(text_area, args->name, args->style_class); |
| 973 | 127 | ui_set_widget_states(obj->ctx, text_area, args->states); |
|
335
91d4f0391282
add new textarea (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
326
diff
changeset
|
128 | |
| 5 | 129 | gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(text_area), GTK_WRAP_WORD_CHAR); |
| 130 | g_signal_connect( | |
|
22
bcf880b29bc3
textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
131 | text_area, |
|
bcf880b29bc3
textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
132 | "realize", |
|
bcf880b29bc3
textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
133 | G_CALLBACK(ui_textarea_realize_event), |
|
bcf880b29bc3
textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
134 | NULL); |
|
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
135 | |
|
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
136 | UiTextArea *uitext = malloc(sizeof(UiTextArea)); |
|
379
958bae372271
implement ui_dialog_window (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
371
diff
changeset
|
137 | uitext->obj = obj; |
|
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
138 | uitext->ctx = obj->ctx; |
|
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
139 | uitext->var = var; |
|
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
140 | uitext->last_selection_state = 0; |
|
594
fc854e0ab924
pass Args structs per pointer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
506
diff
changeset
|
141 | uitext->onchange = args->onchange; |
|
fc854e0ab924
pass Args structs per pointer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
506
diff
changeset
|
142 | uitext->onchangedata = args->onchangedata; |
|
1153
f15375e0480c
add separate textarea change events for before and after changes (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1149
diff
changeset
|
143 | uitext->onchange_action = args->onchange_action ? strdup(args->onchange_action) : NULL; |
|
f15375e0480c
add separate textarea change events for before and after changes (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1149
diff
changeset
|
144 | uitext->ontextchanged = args->ontextchanged; |
|
f15375e0480c
add separate textarea change events for before and after changes (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1149
diff
changeset
|
145 | uitext->ontextchangeddata = args->ontextchangeddata; |
|
f15375e0480c
add separate textarea change events for before and after changes (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1149
diff
changeset
|
146 | uitext->ontextchanged_action = args->ontextchanged_action ? strdup(args->ontextchanged_action) : NULL; |
|
22
bcf880b29bc3
textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
147 | |
|
506
02ddf1044cbc
connect changed event to all textbuffer objects (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
505
diff
changeset
|
148 | g_object_set_data(G_OBJECT(text_area), "ui_textarea", uitext); |
|
1067
4243fcc0aa5c
add functions for scrolling a textarea to a specific position (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1065
diff
changeset
|
149 | g_object_set_data(G_OBJECT(text_area), "ui_textarea_widget", text_area); |
|
506
02ddf1044cbc
connect changed event to all textbuffer objects (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
505
diff
changeset
|
150 | |
|
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
151 | g_signal_connect( |
|
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
152 | text_area, |
|
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
153 | "destroy", |
|
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
154 | G_CALLBACK(ui_textarea_destroy), |
|
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
155 | uitext); |
| 5 | 156 | |
|
298
c5e207d01ff2
port button, text to gtk4
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
157 | GtkWidget *scroll_area = SCROLLEDWINDOW_NEW(); |
| 5 | 158 | gtk_scrolled_window_set_policy( |
| 159 | GTK_SCROLLED_WINDOW(scroll_area), | |
| 160 | GTK_POLICY_AUTOMATIC, | |
| 161 | GTK_POLICY_AUTOMATIC); // GTK_POLICY_ALWAYS | |
|
298
c5e207d01ff2
port button, text to gtk4
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
162 | SCROLLEDWINDOW_SET_CHILD(scroll_area, text_area); |
|
1067
4243fcc0aa5c
add functions for scrolling a textarea to a specific position (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1065
diff
changeset
|
163 | g_object_set_data(G_OBJECT(scroll_area), "ui_textarea_widget", text_area); |
| 5 | 164 | |
|
962
7016bcb8d38b
add webview width/height args and add gtk function for widget size requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
907
diff
changeset
|
165 | ui_widget_size_request(scroll_area, args->width, args->height); |
|
809
f5ddce392617
add width/height args to the textarea, listview and table (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
801
diff
changeset
|
166 | |
| 5 | 167 | // font and padding |
|
335
91d4f0391282
add new textarea (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
326
diff
changeset
|
168 | //PangoFontDescription *font; |
|
91d4f0391282
add new textarea (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
326
diff
changeset
|
169 | //font = pango_font_description_from_string("Monospace"); |
|
298
c5e207d01ff2
port button, text to gtk4
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
170 | //gtk_widget_modify_font(text_area, font); // TODO |
|
335
91d4f0391282
add new textarea (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
326
diff
changeset
|
171 | //pango_font_description_free(font); |
| 5 | 172 | |
| 173 | gtk_text_view_set_left_margin(GTK_TEXT_VIEW(text_area), 2); | |
| 174 | gtk_text_view_set_right_margin(GTK_TEXT_VIEW(text_area), 2); | |
| 175 | ||
| 176 | // add | |
|
801
e096c441e874
refactor gtk container hierarchy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
788
diff
changeset
|
177 | UiContainerPrivate *ct = (UiContainerPrivate*)obj->container_end; |
|
e096c441e874
refactor gtk container hierarchy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
788
diff
changeset
|
178 | UiLayout layout = UI_ARGS2LAYOUT(args); |
|
e096c441e874
refactor gtk container hierarchy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
788
diff
changeset
|
179 | ct->add(ct, scroll_area, &layout); |
|
1063
e0251f6e15f7
add visibility_states arg to labels, buttons, text widgets (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1045
diff
changeset
|
180 | uic_widget_set_visibility_states(obj->ctx, scroll_area, args->visibility_states); |
| 5 | 181 | |
| 182 | // bind value | |
|
397
6d4adf6fba1f
fix textarea crash when no value is specified (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
183 | if(var) { |
|
6d4adf6fba1f
fix textarea crash when no value is specified (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
184 | UiText *value = var->value; |
|
486
a5f3abf8b9d1
refactor textarea to store a text buffer object in UiText values (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
185 | GtkTextBuffer *buf; |
|
a5f3abf8b9d1
refactor textarea to store a text buffer object in UiText values (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
186 | if(value->data1 && value->datatype == UI_TEXT_TYPE_BUFFER) { |
|
a5f3abf8b9d1
refactor textarea to store a text buffer object in UiText values (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
187 | buf = value->data1; |
|
a5f3abf8b9d1
refactor textarea to store a text buffer object in UiText values (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
188 | } else { |
|
506
02ddf1044cbc
connect changed event to all textbuffer objects (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
505
diff
changeset
|
189 | buf = create_textbuffer(uitext); |
|
486
a5f3abf8b9d1
refactor textarea to store a text buffer object in UiText values (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
190 | if(value->value.ptr) { |
|
a5f3abf8b9d1
refactor textarea to store a text buffer object in UiText values (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
191 | gtk_text_buffer_set_text(buf, value->value.ptr, -1); |
|
a5f3abf8b9d1
refactor textarea to store a text buffer object in UiText values (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
192 | value->value.free(value->value.ptr); |
|
a5f3abf8b9d1
refactor textarea to store a text buffer object in UiText values (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
193 | } |
|
33
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
194 | } |
|
486
a5f3abf8b9d1
refactor textarea to store a text buffer object in UiText values (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
195 | gtk_text_view_set_buffer(GTK_TEXT_VIEW(text_area), buf); |
|
487
077c5029aaee
fix text binding
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
486
diff
changeset
|
196 | value->obj = text_area; |
|
486
a5f3abf8b9d1
refactor textarea to store a text buffer object in UiText values (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
197 | value->save = ui_textarea_save; |
|
a5f3abf8b9d1
refactor textarea to store a text buffer object in UiText values (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
198 | value->restore = ui_textarea_restore; |
|
a5f3abf8b9d1
refactor textarea to store a text buffer object in UiText values (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
199 | value->destroy = ui_textarea_text_destroy; |
| 5 | 200 | value->get = ui_textarea_get; |
| 201 | value->set = ui_textarea_set; | |
|
12
fe94e0fb9ef3
added some text functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
9
diff
changeset
|
202 | value->getsubstr = ui_textarea_getsubstr; |
|
fe94e0fb9ef3
added some text functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
9
diff
changeset
|
203 | value->insert = ui_textarea_insert; |
|
1068
1c79dbd248f4
add UiText replace function (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1067
diff
changeset
|
204 | value->replace = ui_textarea_replace; |
|
90
2019fdbaadfd
persistent textarea cursor position
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
65
diff
changeset
|
205 | value->setposition = ui_textarea_setposition; |
|
27
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
22
diff
changeset
|
206 | value->position = ui_textarea_position; |
|
1067
4243fcc0aa5c
add functions for scrolling a textarea to a specific position (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1065
diff
changeset
|
207 | value->showposition = ui_textarea_showposition; |
|
1065
cb3c1fcecaa0
fix missing UiText setselection function (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1063
diff
changeset
|
208 | value->setselection = ui_textarea_setselection; |
|
27
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
22
diff
changeset
|
209 | value->selection = ui_textarea_selection; |
|
29
c96169444d88
added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
210 | value->length = ui_textarea_length; |
|
33
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
211 | value->remove = ui_textarea_remove; |
|
486
a5f3abf8b9d1
refactor textarea to store a text buffer object in UiText values (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
212 | value->data1 = buf; |
|
a5f3abf8b9d1
refactor textarea to store a text buffer object in UiText values (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
213 | value->data2 = NULL; |
|
a5f3abf8b9d1
refactor textarea to store a text buffer object in UiText values (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
214 | value->datatype == UI_TEXT_TYPE_BUFFER; |
|
141
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
215 | value->value.ptr = NULL; |
|
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
216 | value->value.free = NULL; |
| 5 | 217 | |
|
486
a5f3abf8b9d1
refactor textarea to store a text buffer object in UiText values (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
218 | #if GTK_MAJOR_VERSION == 2 |
|
a5f3abf8b9d1
refactor textarea to store a text buffer object in UiText values (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
219 | textarea_set_undomgr(text_area, value); |
|
a5f3abf8b9d1
refactor textarea to store a text buffer object in UiText values (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
220 | #endif |
| 5 | 221 | } |
| 222 | ||
| 223 | return scroll_area; | |
| 224 | } | |
| 225 | ||
|
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
226 | void ui_textarea_destroy(GtkWidget *object, UiTextArea *textarea) { |
|
397
6d4adf6fba1f
fix textarea crash when no value is specified (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
227 | if(textarea->var) { |
|
6d4adf6fba1f
fix textarea crash when no value is specified (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
228 | ui_destroy_boundvar(textarea->ctx, textarea->var); |
|
6d4adf6fba1f
fix textarea crash when no value is specified (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
229 | } |
|
1153
f15375e0480c
add separate textarea change events for before and after changes (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1149
diff
changeset
|
230 | free(textarea->onchange_action); |
|
f15375e0480c
add separate textarea change events for before and after changes (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1149
diff
changeset
|
231 | free(textarea->ontextchanged_action); |
|
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
232 | free(textarea); |
|
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
233 | } |
|
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
234 | |
|
1067
4243fcc0aa5c
add functions for scrolling a textarea to a specific position (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1065
diff
changeset
|
235 | void ui_textarea_scroll_to(UIWIDGET textarea, int pos) { |
|
4243fcc0aa5c
add functions for scrolling a textarea to a specific position (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1065
diff
changeset
|
236 | GtkWidget *widget = ui_textarea_gettextwidget(textarea); |
|
4243fcc0aa5c
add functions for scrolling a textarea to a specific position (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1065
diff
changeset
|
237 | if(!widget) { |
|
4243fcc0aa5c
add functions for scrolling a textarea to a specific position (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1065
diff
changeset
|
238 | fprintf(stderr, "Error: ui_textarea_scroll_to: widget is not a textarea\n"); |
|
1114
388285e877fe
extend textarea API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1103
diff
changeset
|
239 | return; |
|
1067
4243fcc0aa5c
add functions for scrolling a textarea to a specific position (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1065
diff
changeset
|
240 | } |
|
4243fcc0aa5c
add functions for scrolling a textarea to a specific position (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1065
diff
changeset
|
241 | GtkTextBuffer *buf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(widget)); |
|
4243fcc0aa5c
add functions for scrolling a textarea to a specific position (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1065
diff
changeset
|
242 | |
|
4243fcc0aa5c
add functions for scrolling a textarea to a specific position (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1065
diff
changeset
|
243 | GtkTextIter offset; |
|
4243fcc0aa5c
add functions for scrolling a textarea to a specific position (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1065
diff
changeset
|
244 | gtk_text_buffer_get_iter_at_offset(buf, &offset, pos); |
|
4243fcc0aa5c
add functions for scrolling a textarea to a specific position (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1065
diff
changeset
|
245 | |
|
4243fcc0aa5c
add functions for scrolling a textarea to a specific position (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1065
diff
changeset
|
246 | gtk_text_view_scroll_to_iter(GTK_TEXT_VIEW(widget), &offset, 0.2, FALSE, 0, 0); |
|
4243fcc0aa5c
add functions for scrolling a textarea to a specific position (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1065
diff
changeset
|
247 | } |
|
4243fcc0aa5c
add functions for scrolling a textarea to a specific position (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1065
diff
changeset
|
248 | |
|
1114
388285e877fe
extend textarea API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1103
diff
changeset
|
249 | void ui_textarea_focus(UIWIDGET textarea) { |
|
1186
b114038a48da
fix usage of wrong widget in ui_textarea_focus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1153
diff
changeset
|
250 | GtkWidget *widget = ui_textarea_gettextwidget(textarea); |
|
b114038a48da
fix usage of wrong widget in ui_textarea_focus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1153
diff
changeset
|
251 | if(!widget) { |
|
b114038a48da
fix usage of wrong widget in ui_textarea_focus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1153
diff
changeset
|
252 | fprintf(stderr, "Error: ui_textarea_focus: widget is not a textarea\n"); |
|
b114038a48da
fix usage of wrong widget in ui_textarea_focus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1153
diff
changeset
|
253 | return; |
|
b114038a48da
fix usage of wrong widget in ui_textarea_focus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1153
diff
changeset
|
254 | } |
|
b114038a48da
fix usage of wrong widget in ui_textarea_focus (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1153
diff
changeset
|
255 | gtk_widget_grab_focus(widget); |
|
1114
388285e877fe
extend textarea API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1103
diff
changeset
|
256 | } |
|
388285e877fe
extend textarea API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1103
diff
changeset
|
257 | |
|
388285e877fe
extend textarea API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1103
diff
changeset
|
258 | void ui_textarea_set_selection(UIWIDGET textarea, int begin, int end) { |
|
388285e877fe
extend textarea API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1103
diff
changeset
|
259 | GtkWidget *widget = ui_textarea_gettextwidget(textarea); |
|
388285e877fe
extend textarea API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1103
diff
changeset
|
260 | if(!widget) { |
|
388285e877fe
extend textarea API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1103
diff
changeset
|
261 | fprintf(stderr, "Error: ui_textarea_set_selection: widget is not a textarea\n"); |
|
388285e877fe
extend textarea API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1103
diff
changeset
|
262 | return; |
|
388285e877fe
extend textarea API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1103
diff
changeset
|
263 | } |
|
388285e877fe
extend textarea API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1103
diff
changeset
|
264 | |
|
388285e877fe
extend textarea API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1103
diff
changeset
|
265 | GtkTextBuffer *buf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(widget)); |
|
388285e877fe
extend textarea API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1103
diff
changeset
|
266 | GtkTextIter ib; |
|
388285e877fe
extend textarea API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1103
diff
changeset
|
267 | GtkTextIter ie; |
|
388285e877fe
extend textarea API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1103
diff
changeset
|
268 | gtk_text_buffer_get_iter_at_offset(buf, &ib, begin); |
|
388285e877fe
extend textarea API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1103
diff
changeset
|
269 | gtk_text_buffer_get_iter_at_offset(buf, &ie, end); |
|
388285e877fe
extend textarea API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1103
diff
changeset
|
270 | gtk_text_buffer_select_range(buf, &ib, &ie); |
|
388285e877fe
extend textarea API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1103
diff
changeset
|
271 | } |
|
388285e877fe
extend textarea API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1103
diff
changeset
|
272 | |
|
388285e877fe
extend textarea API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1103
diff
changeset
|
273 | void ui_textarea_select_all(UIWIDGET textarea) { |
|
388285e877fe
extend textarea API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1103
diff
changeset
|
274 | GtkWidget *widget = ui_textarea_gettextwidget(textarea); |
|
388285e877fe
extend textarea API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1103
diff
changeset
|
275 | if(!widget) { |
|
388285e877fe
extend textarea API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1103
diff
changeset
|
276 | fprintf(stderr, "Error: ui_textarea_select_all: widget is not a textarea\n"); |
|
388285e877fe
extend textarea API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1103
diff
changeset
|
277 | return; |
|
388285e877fe
extend textarea API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1103
diff
changeset
|
278 | } |
|
388285e877fe
extend textarea API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1103
diff
changeset
|
279 | GtkTextBuffer *buf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(widget)); |
|
388285e877fe
extend textarea API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1103
diff
changeset
|
280 | GtkTextIter start; |
|
388285e877fe
extend textarea API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1103
diff
changeset
|
281 | GtkTextIter end; |
|
388285e877fe
extend textarea API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1103
diff
changeset
|
282 | gtk_text_buffer_get_bounds(buf, &start, &end); |
|
388285e877fe
extend textarea API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1103
diff
changeset
|
283 | gtk_text_buffer_select_range(buf, &start, &end); |
|
388285e877fe
extend textarea API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1103
diff
changeset
|
284 | } |
|
388285e877fe
extend textarea API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1103
diff
changeset
|
285 | |
|
388285e877fe
extend textarea API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1103
diff
changeset
|
286 | void ui_textarea_set_editable(UIWIDGET textarea, UiBool editable) { |
|
388285e877fe
extend textarea API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1103
diff
changeset
|
287 | GtkWidget *widget = ui_textarea_gettextwidget(textarea); |
|
388285e877fe
extend textarea API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1103
diff
changeset
|
288 | if(!widget) { |
|
388285e877fe
extend textarea API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1103
diff
changeset
|
289 | fprintf(stderr, "Error: ui_textarea_set_editable: widget is not a textarea\n"); |
|
388285e877fe
extend textarea API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1103
diff
changeset
|
290 | return; |
|
388285e877fe
extend textarea API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1103
diff
changeset
|
291 | } |
|
388285e877fe
extend textarea API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1103
diff
changeset
|
292 | gtk_text_view_set_editable(GTK_TEXT_VIEW(widget), editable); |
|
388285e877fe
extend textarea API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1103
diff
changeset
|
293 | } |
|
388285e877fe
extend textarea API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1103
diff
changeset
|
294 | |
|
388285e877fe
extend textarea API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1103
diff
changeset
|
295 | UiBool ui_textarea_is_editable(UIWIDGET textarea) { |
|
388285e877fe
extend textarea API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1103
diff
changeset
|
296 | GtkWidget *widget = ui_textarea_gettextwidget(textarea); |
|
388285e877fe
extend textarea API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1103
diff
changeset
|
297 | if(!widget) { |
|
388285e877fe
extend textarea API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1103
diff
changeset
|
298 | fprintf(stderr, "Error: ui_textarea_is_editable: widget is not a textarea\n"); |
|
388285e877fe
extend textarea API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1103
diff
changeset
|
299 | return 0; |
|
388285e877fe
extend textarea API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1103
diff
changeset
|
300 | } |
|
388285e877fe
extend textarea API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1103
diff
changeset
|
301 | return gtk_text_view_get_editable(GTK_TEXT_VIEW(widget)); |
|
388285e877fe
extend textarea API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1103
diff
changeset
|
302 | } |
|
388285e877fe
extend textarea API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1103
diff
changeset
|
303 | |
|
388285e877fe
extend textarea API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1103
diff
changeset
|
304 | void ui_textarea_set_position(UIWIDGET textarea, int pos) { |
|
388285e877fe
extend textarea API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1103
diff
changeset
|
305 | GtkWidget *widget = ui_textarea_gettextwidget(textarea); |
|
388285e877fe
extend textarea API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1103
diff
changeset
|
306 | if(!widget) { |
|
388285e877fe
extend textarea API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1103
diff
changeset
|
307 | fprintf(stderr, "Error: ui_textarea_set_position: widget is not a textarea\n"); |
|
388285e877fe
extend textarea API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1103
diff
changeset
|
308 | return; |
|
388285e877fe
extend textarea API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1103
diff
changeset
|
309 | } |
|
388285e877fe
extend textarea API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1103
diff
changeset
|
310 | GtkTextBuffer *buf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(widget)); |
|
388285e877fe
extend textarea API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1103
diff
changeset
|
311 | GtkTextIter iter; |
|
388285e877fe
extend textarea API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1103
diff
changeset
|
312 | gtk_text_buffer_get_iter_at_offset(buf, &iter, pos); |
|
388285e877fe
extend textarea API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1103
diff
changeset
|
313 | gtk_text_buffer_place_cursor(buf, &iter); |
|
388285e877fe
extend textarea API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1103
diff
changeset
|
314 | } |
|
388285e877fe
extend textarea API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1103
diff
changeset
|
315 | |
|
388285e877fe
extend textarea API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1103
diff
changeset
|
316 | int ui_textarea_get_position(UIWIDGET textarea) { |
|
388285e877fe
extend textarea API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1103
diff
changeset
|
317 | GtkWidget *widget = ui_textarea_gettextwidget(textarea); |
|
388285e877fe
extend textarea API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1103
diff
changeset
|
318 | if(!widget) { |
|
388285e877fe
extend textarea API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1103
diff
changeset
|
319 | fprintf(stderr, "Error: ui_textarea_get_position: widget is not a textarea\n"); |
|
388285e877fe
extend textarea API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1103
diff
changeset
|
320 | return 0; |
|
388285e877fe
extend textarea API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1103
diff
changeset
|
321 | } |
|
388285e877fe
extend textarea API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1103
diff
changeset
|
322 | GtkTextBuffer *buf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(widget)); |
|
388285e877fe
extend textarea API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1103
diff
changeset
|
323 | GtkTextIter begin; |
|
388285e877fe
extend textarea API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1103
diff
changeset
|
324 | GtkTextIter end; |
|
388285e877fe
extend textarea API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1103
diff
changeset
|
325 | gtk_text_buffer_get_selection_bounds(buf, &begin, &end); |
|
388285e877fe
extend textarea API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1103
diff
changeset
|
326 | return gtk_text_iter_get_offset(&begin); |
|
388285e877fe
extend textarea API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1103
diff
changeset
|
327 | } |
|
388285e877fe
extend textarea API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1103
diff
changeset
|
328 | |
|
168
1b99acacc5bb
refactor widget groups
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
167
diff
changeset
|
329 | UIWIDGET ui_textarea_gettextwidget(UIWIDGET textarea) { |
|
1067
4243fcc0aa5c
add functions for scrolling a textarea to a specific position (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1065
diff
changeset
|
330 | return g_object_get_data(G_OBJECT(textarea), "ui_textarea_widget"); |
|
168
1b99acacc5bb
refactor widget groups
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
167
diff
changeset
|
331 | } |
|
1b99acacc5bb
refactor widget groups
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
167
diff
changeset
|
332 | |
|
486
a5f3abf8b9d1
refactor textarea to store a text buffer object in UiText values (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
333 | void ui_textarea_save(UiText *text) { |
|
a5f3abf8b9d1
refactor textarea to store a text buffer object in UiText values (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
334 | // NOOP |
|
a5f3abf8b9d1
refactor textarea to store a text buffer object in UiText values (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
335 | } |
|
a5f3abf8b9d1
refactor textarea to store a text buffer object in UiText values (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
336 | |
|
a5f3abf8b9d1
refactor textarea to store a text buffer object in UiText values (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
337 | void ui_textarea_restore(UiText *text) { |
|
a5f3abf8b9d1
refactor textarea to store a text buffer object in UiText values (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
338 | GtkWidget *textarea = text->obj; |
|
487
077c5029aaee
fix text binding
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
486
diff
changeset
|
339 | if(!text->data1) { |
|
506
02ddf1044cbc
connect changed event to all textbuffer objects (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
505
diff
changeset
|
340 | text->data1 = create_textbuffer(g_object_get_data(G_OBJECT(textarea), "ui_textarea")); |
|
487
077c5029aaee
fix text binding
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
486
diff
changeset
|
341 | text->datatype = UI_TEXT_TYPE_BUFFER; |
|
077c5029aaee
fix text binding
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
486
diff
changeset
|
342 | } |
|
486
a5f3abf8b9d1
refactor textarea to store a text buffer object in UiText values (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
343 | gtk_text_view_set_buffer(GTK_TEXT_VIEW(textarea), text->data1); |
|
a5f3abf8b9d1
refactor textarea to store a text buffer object in UiText values (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
344 | } |
|
a5f3abf8b9d1
refactor textarea to store a text buffer object in UiText values (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
345 | |
|
a5f3abf8b9d1
refactor textarea to store a text buffer object in UiText values (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
346 | void ui_textarea_text_destroy(UiText *text) { |
|
a5f3abf8b9d1
refactor textarea to store a text buffer object in UiText values (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
347 | GtkTextBuffer *buf = text->data1; |
|
a5f3abf8b9d1
refactor textarea to store a text buffer object in UiText values (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
348 | g_object_unref(buf); |
|
a5f3abf8b9d1
refactor textarea to store a text buffer object in UiText values (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
349 | } |
|
a5f3abf8b9d1
refactor textarea to store a text buffer object in UiText values (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
350 | |
| 5 | 351 | char* ui_textarea_get(UiText *text) { |
|
141
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
352 | if(text->value.ptr) { |
|
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
353 | text->value.free(text->value.ptr); |
| 5 | 354 | } |
|
487
077c5029aaee
fix text binding
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
486
diff
changeset
|
355 | GtkTextBuffer *buf = text->data1; |
| 5 | 356 | GtkTextIter start; |
| 357 | GtkTextIter end; | |
| 358 | gtk_text_buffer_get_bounds(buf, &start, &end); | |
| 359 | char *str = gtk_text_buffer_get_text(buf, &start, &end, FALSE); | |
|
141
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
360 | text->value.ptr = g_strdup(str); |
|
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
361 | text->value.free = (ui_freefunc)g_free; |
| 5 | 362 | return str; |
| 363 | } | |
| 364 | ||
|
253
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
365 | void ui_textarea_set(UiText *text, const char *str) { |
|
487
077c5029aaee
fix text binding
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
486
diff
changeset
|
366 | gtk_text_buffer_set_text((GtkTextBuffer*)text->data1, str, -1); |
|
141
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
367 | if(text->value.ptr) { |
|
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
368 | text->value.free(text->value.ptr); |
|
12
fe94e0fb9ef3
added some text functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
9
diff
changeset
|
369 | } |
|
141
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
370 | text->value.ptr = NULL; |
|
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
371 | text->value.free = NULL; |
|
12
fe94e0fb9ef3
added some text functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
9
diff
changeset
|
372 | } |
|
fe94e0fb9ef3
added some text functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
9
diff
changeset
|
373 | |
|
fe94e0fb9ef3
added some text functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
9
diff
changeset
|
374 | char* ui_textarea_getsubstr(UiText *text, int begin, int end) { |
|
141
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
375 | if(text->value.ptr) { |
|
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
376 | text->value.free(text->value.ptr); |
| 5 | 377 | } |
|
487
077c5029aaee
fix text binding
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
486
diff
changeset
|
378 | GtkTextBuffer *buf = text->data1; |
|
12
fe94e0fb9ef3
added some text functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
9
diff
changeset
|
379 | GtkTextIter ib; |
|
fe94e0fb9ef3
added some text functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
9
diff
changeset
|
380 | GtkTextIter ie; |
|
487
077c5029aaee
fix text binding
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
486
diff
changeset
|
381 | gtk_text_buffer_get_iter_at_offset(text->data1, &ib, begin); |
|
077c5029aaee
fix text binding
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
486
diff
changeset
|
382 | gtk_text_buffer_get_iter_at_offset(text->data1, &ie, end); |
|
12
fe94e0fb9ef3
added some text functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
9
diff
changeset
|
383 | char *str = gtk_text_buffer_get_text(buf, &ib, &ie, FALSE); |
|
141
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
384 | text->value.ptr = g_strdup(str); |
|
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
385 | text->value.free = (ui_freefunc)g_free; |
|
12
fe94e0fb9ef3
added some text functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
9
diff
changeset
|
386 | return str; |
|
fe94e0fb9ef3
added some text functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
9
diff
changeset
|
387 | } |
|
fe94e0fb9ef3
added some text functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
9
diff
changeset
|
388 | |
|
1068
1c79dbd248f4
add UiText replace function (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1067
diff
changeset
|
389 | void ui_textarea_insert(UiText *text, int pos, const char *str) { |
|
12
fe94e0fb9ef3
added some text functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
9
diff
changeset
|
390 | GtkTextIter offset; |
|
487
077c5029aaee
fix text binding
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
486
diff
changeset
|
391 | gtk_text_buffer_get_iter_at_offset(text->data1, &offset, pos); |
|
077c5029aaee
fix text binding
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
486
diff
changeset
|
392 | gtk_text_buffer_insert(text->data1, &offset, str, -1); |
|
141
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
393 | if(text->value.ptr) { |
|
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
394 | text->value.free(text->value.ptr); |
|
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
395 | } |
|
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
396 | text->value.ptr = NULL; |
|
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
397 | text->value.free = NULL; |
| 5 | 398 | } |
| 399 | ||
|
1068
1c79dbd248f4
add UiText replace function (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1067
diff
changeset
|
400 | void ui_textarea_replace(UiText *text, int begin, int end, const char *replacement) { |
|
1c79dbd248f4
add UiText replace function (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1067
diff
changeset
|
401 | GtkTextBuffer *buffer = text->data1; |
|
1c79dbd248f4
add UiText replace function (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1067
diff
changeset
|
402 | GtkTextIter begin_offset; |
|
1c79dbd248f4
add UiText replace function (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1067
diff
changeset
|
403 | GtkTextIter end_offset; |
|
1c79dbd248f4
add UiText replace function (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1067
diff
changeset
|
404 | gtk_text_buffer_get_iter_at_offset(buffer, &begin_offset, begin); |
|
1c79dbd248f4
add UiText replace function (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1067
diff
changeset
|
405 | gtk_text_buffer_get_iter_at_offset(buffer, &end_offset, end); |
|
1c79dbd248f4
add UiText replace function (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1067
diff
changeset
|
406 | gtk_text_buffer_begin_user_action(buffer); |
|
1c79dbd248f4
add UiText replace function (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1067
diff
changeset
|
407 | gtk_text_buffer_delete(buffer, &begin_offset, &end_offset); |
|
1c79dbd248f4
add UiText replace function (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1067
diff
changeset
|
408 | if(replacement) { |
|
1c79dbd248f4
add UiText replace function (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1067
diff
changeset
|
409 | gtk_text_buffer_insert(buffer, &begin_offset, replacement, -1); |
|
1c79dbd248f4
add UiText replace function (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1067
diff
changeset
|
410 | } |
|
1c79dbd248f4
add UiText replace function (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1067
diff
changeset
|
411 | gtk_text_buffer_end_user_action(buffer); |
|
1c79dbd248f4
add UiText replace function (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1067
diff
changeset
|
412 | } |
|
1c79dbd248f4
add UiText replace function (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1067
diff
changeset
|
413 | |
|
90
2019fdbaadfd
persistent textarea cursor position
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
65
diff
changeset
|
414 | void ui_textarea_setposition(UiText *text, int pos) { |
|
2019fdbaadfd
persistent textarea cursor position
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
65
diff
changeset
|
415 | GtkTextIter iter; |
|
487
077c5029aaee
fix text binding
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
486
diff
changeset
|
416 | gtk_text_buffer_get_iter_at_offset(text->data1, &iter, pos); |
|
077c5029aaee
fix text binding
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
486
diff
changeset
|
417 | gtk_text_buffer_place_cursor(text->data1, &iter); |
|
90
2019fdbaadfd
persistent textarea cursor position
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
65
diff
changeset
|
418 | } |
|
2019fdbaadfd
persistent textarea cursor position
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
65
diff
changeset
|
419 | |
|
27
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
22
diff
changeset
|
420 | int ui_textarea_position(UiText *text) { |
|
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
22
diff
changeset
|
421 | GtkTextIter begin; |
|
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
22
diff
changeset
|
422 | GtkTextIter end; |
|
487
077c5029aaee
fix text binding
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
486
diff
changeset
|
423 | gtk_text_buffer_get_selection_bounds(text->data1, &begin, &end); |
|
90
2019fdbaadfd
persistent textarea cursor position
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
65
diff
changeset
|
424 | text->pos = gtk_text_iter_get_offset(&begin); |
|
2019fdbaadfd
persistent textarea cursor position
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
65
diff
changeset
|
425 | return text->pos; |
|
27
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
22
diff
changeset
|
426 | } |
|
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
22
diff
changeset
|
427 | |
|
1067
4243fcc0aa5c
add functions for scrolling a textarea to a specific position (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1065
diff
changeset
|
428 | void ui_textarea_showposition(UiText *text, int pos) { |
|
1142
e2a6707aa1e0
fix some UiText functions using obj instead of data1 (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1114
diff
changeset
|
429 | if(text->obj) { |
|
e2a6707aa1e0
fix some UiText functions using obj instead of data1 (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1114
diff
changeset
|
430 | ui_textarea_scroll_to(text->obj, pos); |
|
e2a6707aa1e0
fix some UiText functions using obj instead of data1 (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1114
diff
changeset
|
431 | } |
|
1067
4243fcc0aa5c
add functions for scrolling a textarea to a specific position (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1065
diff
changeset
|
432 | } |
|
4243fcc0aa5c
add functions for scrolling a textarea to a specific position (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1065
diff
changeset
|
433 | |
|
1065
cb3c1fcecaa0
fix missing UiText setselection function (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1063
diff
changeset
|
434 | void ui_textarea_setselection(UiText *text, int begin, int end) { |
|
cb3c1fcecaa0
fix missing UiText setselection function (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1063
diff
changeset
|
435 | GtkTextBuffer *buf = text->data1; |
|
cb3c1fcecaa0
fix missing UiText setselection function (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1063
diff
changeset
|
436 | GtkTextIter ib; |
|
cb3c1fcecaa0
fix missing UiText setselection function (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1063
diff
changeset
|
437 | GtkTextIter ie; |
|
cb3c1fcecaa0
fix missing UiText setselection function (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1063
diff
changeset
|
438 | gtk_text_buffer_get_iter_at_offset(text->data1, &ib, begin); |
|
cb3c1fcecaa0
fix missing UiText setselection function (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1063
diff
changeset
|
439 | gtk_text_buffer_get_iter_at_offset(text->data1, &ie, end); |
|
cb3c1fcecaa0
fix missing UiText setselection function (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1063
diff
changeset
|
440 | gtk_text_buffer_select_range(buf, &ib, &ie); |
|
cb3c1fcecaa0
fix missing UiText setselection function (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1063
diff
changeset
|
441 | } |
|
cb3c1fcecaa0
fix missing UiText setselection function (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1063
diff
changeset
|
442 | |
|
27
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
22
diff
changeset
|
443 | void ui_textarea_selection(UiText *text, int *begin, int *end) { |
|
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
22
diff
changeset
|
444 | GtkTextIter b; |
|
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
22
diff
changeset
|
445 | GtkTextIter e; |
|
487
077c5029aaee
fix text binding
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
486
diff
changeset
|
446 | gtk_text_buffer_get_selection_bounds(text->data1, &b, &e); |
|
27
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
22
diff
changeset
|
447 | *begin = gtk_text_iter_get_offset(&b); |
|
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
22
diff
changeset
|
448 | *end = gtk_text_iter_get_offset(&e); |
|
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
22
diff
changeset
|
449 | } |
|
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
22
diff
changeset
|
450 | |
|
29
c96169444d88
added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
451 | int ui_textarea_length(UiText *text) { |
|
487
077c5029aaee
fix text binding
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
486
diff
changeset
|
452 | GtkTextBuffer *buf = text->data1; |
|
29
c96169444d88
added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
453 | GtkTextIter start; |
|
c96169444d88
added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
454 | GtkTextIter end; |
|
c96169444d88
added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
455 | gtk_text_buffer_get_bounds(buf, &start, &end); |
|
c96169444d88
added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
456 | return gtk_text_iter_get_offset(&end); |
|
c96169444d88
added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
457 | } |
|
c96169444d88
added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
458 | |
|
33
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
459 | void ui_textarea_remove(UiText *text, int begin, int end) { |
|
487
077c5029aaee
fix text binding
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
486
diff
changeset
|
460 | GtkTextBuffer *buf = text->data1; |
|
33
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
461 | GtkTextIter ib; |
|
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
462 | GtkTextIter ie; |
|
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
463 | gtk_text_buffer_get_iter_at_offset(buf, &ib, begin); |
|
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
464 | gtk_text_buffer_get_iter_at_offset(buf, &ie, end); |
|
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
465 | gtk_text_buffer_delete(buf, &ib, &ie); |
|
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
466 | } |
|
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
467 | |
| 5 | 468 | void ui_textarea_realize_event(GtkWidget *widget, gpointer data) { |
| 469 | gtk_widget_grab_focus(widget); | |
| 470 | } | |
| 471 | ||
|
131
774b741984a2
detaching variables correctly
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
122
diff
changeset
|
472 | |
|
1153
f15375e0480c
add separate textarea change events for before and after changes (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1149
diff
changeset
|
473 | static void textbuf_change_event(UiTextArea *textarea, UiTextChangeEventData *data) { |
|
906
edfdf9776da9
disable onchange events when detaching a document
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
809
diff
changeset
|
474 | if(!ui_onchange_events_is_enabled()) { |
|
edfdf9776da9
disable onchange events when detaching a document
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
809
diff
changeset
|
475 | return; |
|
edfdf9776da9
disable onchange events when detaching a document
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
809
diff
changeset
|
476 | } |
|
edfdf9776da9
disable onchange events when detaching a document
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
809
diff
changeset
|
477 | |
|
379
958bae372271
implement ui_dialog_window (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
371
diff
changeset
|
478 | UiEvent e; |
|
958bae372271
implement ui_dialog_window (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
371
diff
changeset
|
479 | e.obj = textarea->obj; |
|
958bae372271
implement ui_dialog_window (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
371
diff
changeset
|
480 | e.window = e.obj->window; |
|
958bae372271
implement ui_dialog_window (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
371
diff
changeset
|
481 | e.document = textarea->ctx->document; |
|
1149
76b7664f951e
change textarea change events to include UiTextChangeEventData (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1142
diff
changeset
|
482 | e.eventdata = data; |
|
76b7664f951e
change textarea change events to include UiTextChangeEventData (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1142
diff
changeset
|
483 | e.eventdatatype = UI_EVENT_DATA_TEXT_CHANGED; |
|
379
958bae372271
implement ui_dialog_window (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
371
diff
changeset
|
484 | e.intval = 0; |
|
505
8002be179741
re-enable textarea onchange event (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
487
diff
changeset
|
485 | e.set = ui_get_setop(); |
|
379
958bae372271
implement ui_dialog_window (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
371
diff
changeset
|
486 | |
|
958bae372271
implement ui_dialog_window (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
371
diff
changeset
|
487 | if(textarea->onchange) { |
|
958bae372271
implement ui_dialog_window (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
371
diff
changeset
|
488 | textarea->onchange(&e, textarea->onchangedata); |
|
958bae372271
implement ui_dialog_window (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
371
diff
changeset
|
489 | } |
|
958bae372271
implement ui_dialog_window (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
371
diff
changeset
|
490 | |
|
1153
f15375e0480c
add separate textarea change events for before and after changes (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1149
diff
changeset
|
491 | if(textarea->onchange_action) { |
|
f15375e0480c
add separate textarea change events for before and after changes (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1149
diff
changeset
|
492 | uic_action_callback(&e, textarea->onchange_action); |
|
f15375e0480c
add separate textarea change events for before and after changes (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1149
diff
changeset
|
493 | } |
|
f15375e0480c
add separate textarea change events for before and after changes (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1149
diff
changeset
|
494 | } |
|
f15375e0480c
add separate textarea change events for before and after changes (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1149
diff
changeset
|
495 | |
|
f15375e0480c
add separate textarea change events for before and after changes (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1149
diff
changeset
|
496 | void ui_textbuf_change_insert( |
|
f15375e0480c
add separate textarea change events for before and after changes (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1149
diff
changeset
|
497 | GtkTextBuffer *textbuffer, |
|
f15375e0480c
add separate textarea change events for before and after changes (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1149
diff
changeset
|
498 | GtkTextIter *location, |
|
f15375e0480c
add separate textarea change events for before and after changes (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1149
diff
changeset
|
499 | char *text, |
|
f15375e0480c
add separate textarea change events for before and after changes (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1149
diff
changeset
|
500 | int length, |
|
f15375e0480c
add separate textarea change events for before and after changes (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1149
diff
changeset
|
501 | UiTextArea *textarea) |
|
f15375e0480c
add separate textarea change events for before and after changes (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1149
diff
changeset
|
502 | { |
|
f15375e0480c
add separate textarea change events for before and after changes (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1149
diff
changeset
|
503 | UiTextChangeEventData event; |
|
f15375e0480c
add separate textarea change events for before and after changes (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1149
diff
changeset
|
504 | event.type = UI_TEXT_INSERT; |
|
f15375e0480c
add separate textarea change events for before and after changes (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1149
diff
changeset
|
505 | event.begin = gtk_text_iter_get_offset(location); |
|
f15375e0480c
add separate textarea change events for before and after changes (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1149
diff
changeset
|
506 | event.end = event.begin + length; |
|
f15375e0480c
add separate textarea change events for before and after changes (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1149
diff
changeset
|
507 | event.text = text; |
|
f15375e0480c
add separate textarea change events for before and after changes (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1149
diff
changeset
|
508 | event.length = length; |
|
f15375e0480c
add separate textarea change events for before and after changes (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1149
diff
changeset
|
509 | textbuf_change_event(textarea, &event); |
|
f15375e0480c
add separate textarea change events for before and after changes (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1149
diff
changeset
|
510 | } |
|
f15375e0480c
add separate textarea change events for before and after changes (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1149
diff
changeset
|
511 | |
|
f15375e0480c
add separate textarea change events for before and after changes (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1149
diff
changeset
|
512 | void ui_textbuf_change_delete( |
|
f15375e0480c
add separate textarea change events for before and after changes (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1149
diff
changeset
|
513 | GtkTextBuffer *self, |
|
f15375e0480c
add separate textarea change events for before and after changes (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1149
diff
changeset
|
514 | const GtkTextIter *start, |
|
f15375e0480c
add separate textarea change events for before and after changes (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1149
diff
changeset
|
515 | const GtkTextIter *end, |
|
f15375e0480c
add separate textarea change events for before and after changes (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1149
diff
changeset
|
516 | UiTextArea *textarea) |
|
f15375e0480c
add separate textarea change events for before and after changes (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1149
diff
changeset
|
517 | { |
|
f15375e0480c
add separate textarea change events for before and after changes (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1149
diff
changeset
|
518 | UiTextChangeEventData event; |
|
f15375e0480c
add separate textarea change events for before and after changes (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1149
diff
changeset
|
519 | event.type = UI_TEXT_DELETE; |
|
f15375e0480c
add separate textarea change events for before and after changes (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1149
diff
changeset
|
520 | event.begin = gtk_text_iter_get_offset(start); |
|
f15375e0480c
add separate textarea change events for before and after changes (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1149
diff
changeset
|
521 | event.end = gtk_text_iter_get_offset(end); |
|
f15375e0480c
add separate textarea change events for before and after changes (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1149
diff
changeset
|
522 | event.text = NULL; |
|
f15375e0480c
add separate textarea change events for before and after changes (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1149
diff
changeset
|
523 | event.length = 0; |
|
f15375e0480c
add separate textarea change events for before and after changes (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1149
diff
changeset
|
524 | textbuf_change_event(textarea, &event); |
|
f15375e0480c
add separate textarea change events for before and after changes (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1149
diff
changeset
|
525 | } |
|
f15375e0480c
add separate textarea change events for before and after changes (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1149
diff
changeset
|
526 | |
|
f15375e0480c
add separate textarea change events for before and after changes (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1149
diff
changeset
|
527 | |
|
f15375e0480c
add separate textarea change events for before and after changes (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1149
diff
changeset
|
528 | void ui_textbuf_changed(GtkTextBuffer *textbuffer, UiTextArea *textarea) { |
|
f15375e0480c
add separate textarea change events for before and after changes (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1149
diff
changeset
|
529 | if(!ui_onchange_events_is_enabled()) { |
|
f15375e0480c
add separate textarea change events for before and after changes (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1149
diff
changeset
|
530 | return; |
|
f15375e0480c
add separate textarea change events for before and after changes (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1149
diff
changeset
|
531 | } |
|
f15375e0480c
add separate textarea change events for before and after changes (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1149
diff
changeset
|
532 | |
|
f15375e0480c
add separate textarea change events for before and after changes (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1149
diff
changeset
|
533 | UiText *value = textarea->var->value; |
|
f15375e0480c
add separate textarea change events for before and after changes (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1149
diff
changeset
|
534 | |
|
f15375e0480c
add separate textarea change events for before and after changes (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1149
diff
changeset
|
535 | UiEvent e; |
|
f15375e0480c
add separate textarea change events for before and after changes (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1149
diff
changeset
|
536 | e.obj = textarea->obj; |
|
f15375e0480c
add separate textarea change events for before and after changes (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1149
diff
changeset
|
537 | e.window = e.obj->window; |
|
f15375e0480c
add separate textarea change events for before and after changes (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1149
diff
changeset
|
538 | e.document = textarea->ctx->document; |
|
f15375e0480c
add separate textarea change events for before and after changes (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1149
diff
changeset
|
539 | e.eventdata = value; |
|
f15375e0480c
add separate textarea change events for before and after changes (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1149
diff
changeset
|
540 | e.eventdatatype = UI_EVENT_DATA_TEXT_VALUE; |
|
f15375e0480c
add separate textarea change events for before and after changes (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1149
diff
changeset
|
541 | e.intval = 0; |
|
f15375e0480c
add separate textarea change events for before and after changes (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1149
diff
changeset
|
542 | e.set = ui_get_setop(); |
|
f15375e0480c
add separate textarea change events for before and after changes (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1149
diff
changeset
|
543 | |
|
f15375e0480c
add separate textarea change events for before and after changes (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1149
diff
changeset
|
544 | if(textarea->ontextchanged) { |
|
f15375e0480c
add separate textarea change events for before and after changes (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1149
diff
changeset
|
545 | textarea->ontextchanged(&e, textarea->ontextchangeddata); |
|
f15375e0480c
add separate textarea change events for before and after changes (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1149
diff
changeset
|
546 | } |
|
f15375e0480c
add separate textarea change events for before and after changes (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1149
diff
changeset
|
547 | |
|
f15375e0480c
add separate textarea change events for before and after changes (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1149
diff
changeset
|
548 | if(textarea->ontextchanged_action) { |
|
f15375e0480c
add separate textarea change events for before and after changes (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1149
diff
changeset
|
549 | uic_action_callback(&e, textarea->ontextchanged_action); |
|
f15375e0480c
add separate textarea change events for before and after changes (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1149
diff
changeset
|
550 | } |
|
f15375e0480c
add separate textarea change events for before and after changes (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1149
diff
changeset
|
551 | |
|
143
d499b29d7cb6
adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
141
diff
changeset
|
552 | if(value->observers) { |
|
d499b29d7cb6
adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
141
diff
changeset
|
553 | ui_notify_evt(value->observers, &e); |
|
d499b29d7cb6
adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
141
diff
changeset
|
554 | } |
|
d499b29d7cb6
adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
141
diff
changeset
|
555 | } |
|
6
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
556 | |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
557 | // undo manager functions |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
558 | |
| 5 | 559 | void ui_textbuf_insert( |
| 560 | GtkTextBuffer *textbuffer, | |
| 561 | GtkTextIter *location, | |
| 562 | char *text, | |
|
6
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
563 | int length, |
| 5 | 564 | void *data) |
| 565 | { | |
|
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
566 | UiVar *var = data; |
|
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
567 | UiText *value = var->value; |
|
486
a5f3abf8b9d1
refactor textarea to store a text buffer object in UiText values (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
568 | if(!value->data2) { |
|
a5f3abf8b9d1
refactor textarea to store a text buffer object in UiText values (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
569 | value->data2 = ui_create_undomgr(); |
|
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
570 | } |
|
486
a5f3abf8b9d1
refactor textarea to store a text buffer object in UiText values (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
571 | UiUndoMgr *mgr = value->data2; |
|
6
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
572 | if(!mgr->event) { |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
573 | return; |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
574 | } |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
575 | |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
576 | if(mgr->cur) { |
| 174 | 577 | UiTextBufOp *elm = mgr->cur->next; |
|
9
e70e855cea89
added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
578 | if(elm) { |
|
e70e855cea89
added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
579 | mgr->cur->next = NULL; |
| 174 | 580 | mgr->end = mgr->cur; |
|
9
e70e855cea89
added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
581 | while(elm) { |
|
e70e855cea89
added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
582 | elm->prev = NULL; |
| 174 | 583 | UiTextBufOp *next = elm->next; |
| 584 | ui_free_textbuf_op(elm); | |
|
9
e70e855cea89
added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
585 | elm = next; |
|
e70e855cea89
added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
586 | } |
|
6
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
587 | } |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
588 | |
| 174 | 589 | UiTextBufOp *last_op = mgr->cur; |
|
9
e70e855cea89
added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
590 | if( |
|
e70e855cea89
added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
591 | last_op->type == UI_TEXTBUF_INSERT && |
|
e70e855cea89
added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
592 | ui_check_insertstr(last_op->text, last_op->len, text, length) == 0) |
|
e70e855cea89
added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
593 | { |
|
6
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
594 | // append text to last op |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
595 | int ln = last_op->len; |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
596 | char *newtext = malloc(ln + length + 1); |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
597 | memcpy(newtext, last_op->text, ln); |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
598 | memcpy(newtext+ln, text, length); |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
599 | newtext[ln+length] = '\0'; |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
600 | |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
601 | last_op->text = newtext; |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
602 | last_op->len = ln + length; |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
603 | last_op->end += length; |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
604 | |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
605 | return; |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
606 | } |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
607 | } |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
608 | |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
609 | char *dpstr = malloc(length + 1); |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
610 | memcpy(dpstr, text, length); |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
611 | dpstr[length] = 0; |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
612 | |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
613 | UiTextBufOp *op = malloc(sizeof(UiTextBufOp)); |
| 174 | 614 | op->prev = NULL; |
| 615 | op->next = NULL; | |
|
6
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
616 | op->type = UI_TEXTBUF_INSERT; |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
617 | op->start = gtk_text_iter_get_offset(location); |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
618 | op->end = op->start+length; |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
619 | op->len = length; |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
620 | op->text = dpstr; |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
621 | |
| 174 | 622 | cx_linked_list_add( |
| 623 | (void**)&mgr->begin, | |
| 624 | (void**)&mgr->end, | |
| 625 | offsetof(UiTextBufOp, prev), | |
| 626 | offsetof(UiTextBufOp, next), | |
| 627 | op); | |
| 628 | ||
| 629 | mgr->cur = op; | |
| 5 | 630 | } |
| 631 | ||
| 632 | void ui_textbuf_delete( | |
| 633 | GtkTextBuffer *textbuffer, | |
| 634 | GtkTextIter *start, | |
| 635 | GtkTextIter *end, | |
| 636 | void *data) | |
| 637 | { | |
|
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
638 | UiVar *var = data; |
|
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
639 | UiText *value = var->value; |
|
486
a5f3abf8b9d1
refactor textarea to store a text buffer object in UiText values (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
640 | if(!value->data2) { |
|
a5f3abf8b9d1
refactor textarea to store a text buffer object in UiText values (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
641 | value->data2 = ui_create_undomgr(); |
|
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
642 | } |
|
1142
e2a6707aa1e0
fix some UiText functions using obj instead of data1 (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1114
diff
changeset
|
643 | GtkTextBuffer *buf = value->data1; |
|
486
a5f3abf8b9d1
refactor textarea to store a text buffer object in UiText values (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
644 | UiUndoMgr *mgr = value->data2; |
|
6
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
645 | if(!mgr->event) { |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
646 | return; |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
647 | } |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
648 | |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
649 | if(mgr->cur) { |
| 174 | 650 | UiTextBufOp *elm = mgr->cur->next; |
|
9
e70e855cea89
added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
651 | if(elm) { |
|
e70e855cea89
added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
652 | mgr->cur->next = NULL; |
| 174 | 653 | mgr->end = mgr->cur; |
|
9
e70e855cea89
added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
654 | while(elm) { |
|
e70e855cea89
added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
655 | elm->prev = NULL; |
| 174 | 656 | UiTextBufOp *next = elm->next; |
| 657 | ui_free_textbuf_op(elm); | |
|
9
e70e855cea89
added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
658 | elm = next; |
|
e70e855cea89
added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
659 | } |
|
6
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
660 | } |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
661 | } |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
662 | |
|
1142
e2a6707aa1e0
fix some UiText functions using obj instead of data1 (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1114
diff
changeset
|
663 | char *text = gtk_text_buffer_get_text(buf, start, end, FALSE); |
|
6
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
664 | |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
665 | UiTextBufOp *op = malloc(sizeof(UiTextBufOp)); |
| 174 | 666 | op->prev = NULL; |
| 667 | op->next = NULL; | |
|
6
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
668 | op->type = UI_TEXTBUF_DELETE; |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
669 | op->start = gtk_text_iter_get_offset(start); |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
670 | op->end = gtk_text_iter_get_offset(end); |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
671 | op->len = op->end - op->start; |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
672 | |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
673 | char *dpstr = malloc(op->len + 1); |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
674 | memcpy(dpstr, text, op->len); |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
675 | dpstr[op->len] = 0; |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
676 | op->text = dpstr; |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
677 | |
| 174 | 678 | cx_linked_list_add( |
| 679 | (void**)&mgr->begin, | |
| 680 | (void**)&mgr->end, | |
| 681 | offsetof(UiTextBufOp, prev), | |
| 682 | offsetof(UiTextBufOp, next), | |
| 683 | op); | |
| 684 | ||
| 685 | mgr->cur = op; | |
|
6
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
686 | } |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
687 | |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
688 | UiUndoMgr* ui_create_undomgr() { |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
689 | UiUndoMgr *mgr = malloc(sizeof(UiUndoMgr)); |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
690 | mgr->begin = NULL; |
| 174 | 691 | mgr->end = NULL; |
|
6
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
692 | mgr->cur = NULL; |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
693 | mgr->length = 0; |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
694 | mgr->event = 1; |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
695 | return mgr; |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
696 | } |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
697 | |
| 174 | 698 | void ui_destroy_undomgr(UiUndoMgr *mgr) { |
| 699 | UiTextBufOp *op = mgr->begin; | |
| 700 | while(op) { | |
| 701 | UiTextBufOp *nextOp = op->next; | |
| 702 | if(op->text) { | |
| 703 | free(op->text); | |
| 704 | } | |
| 705 | free(op); | |
| 706 | op = nextOp; | |
| 707 | } | |
| 708 | free(mgr); | |
| 709 | } | |
| 710 | ||
|
6
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
711 | void ui_free_textbuf_op(UiTextBufOp *op) { |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
712 | if(op->text) { |
|
9
e70e855cea89
added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
713 | free(op->text); |
|
6
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
714 | } |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
715 | free(op); |
| 5 | 716 | } |
|
6
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
717 | |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
718 | int ui_check_insertstr(char *oldstr, int oldlen, char *newstr, int newlen) { |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
719 | // return 1 if oldstr + newstr are one word |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
720 | |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
721 | int has_space = 0; |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
722 | for(int i=0;i<oldlen;i++) { |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
723 | if(oldstr[i] < 33) { |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
724 | has_space = 1; |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
725 | break; |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
726 | } |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
727 | } |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
728 | |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
729 | for(int i=0;i<newlen;i++) { |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
730 | if(has_space && newstr[i] > 32) { |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
731 | return 1; |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
732 | } |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
733 | } |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
734 | |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
735 | return 0; |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
736 | } |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
737 | |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
738 | void ui_text_undo(UiText *value) { |
|
1142
e2a6707aa1e0
fix some UiText functions using obj instead of data1 (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1114
diff
changeset
|
739 | GtkTextBuffer *buf = value->data1; |
|
486
a5f3abf8b9d1
refactor textarea to store a text buffer object in UiText values (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
740 | UiUndoMgr *mgr = value->data2; |
|
6
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
741 | |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
742 | if(mgr->cur) { |
| 174 | 743 | UiTextBufOp *op = mgr->cur; |
|
6
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
744 | mgr->event = 0; |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
745 | switch(op->type) { |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
746 | case UI_TEXTBUF_INSERT: { |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
747 | GtkTextIter begin; |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
748 | GtkTextIter end; |
|
1142
e2a6707aa1e0
fix some UiText functions using obj instead of data1 (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1114
diff
changeset
|
749 | gtk_text_buffer_get_iter_at_offset(buf, &begin, op->start); |
|
e2a6707aa1e0
fix some UiText functions using obj instead of data1 (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1114
diff
changeset
|
750 | gtk_text_buffer_get_iter_at_offset(buf, &end, op->end); |
|
e2a6707aa1e0
fix some UiText functions using obj instead of data1 (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1114
diff
changeset
|
751 | gtk_text_buffer_delete(buf, &begin, &end); |
|
6
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
752 | break; |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
753 | } |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
754 | case UI_TEXTBUF_DELETE: { |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
755 | GtkTextIter begin; |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
756 | GtkTextIter end; |
|
1142
e2a6707aa1e0
fix some UiText functions using obj instead of data1 (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1114
diff
changeset
|
757 | gtk_text_buffer_get_iter_at_offset(buf, &begin, op->start); |
|
e2a6707aa1e0
fix some UiText functions using obj instead of data1 (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1114
diff
changeset
|
758 | gtk_text_buffer_get_iter_at_offset(buf, &end, op->end); |
|
e2a6707aa1e0
fix some UiText functions using obj instead of data1 (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1114
diff
changeset
|
759 | gtk_text_buffer_insert(buf, &begin, op->text, op->len); |
|
6
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
760 | break; |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
761 | } |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
762 | } |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
763 | mgr->event = 1; |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
764 | mgr->cur = mgr->cur->prev; |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
765 | } |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
766 | } |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
767 | |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
768 | void ui_text_redo(UiText *value) { |
|
1142
e2a6707aa1e0
fix some UiText functions using obj instead of data1 (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1114
diff
changeset
|
769 | GtkTextBuffer *buf = value->data1; |
|
486
a5f3abf8b9d1
refactor textarea to store a text buffer object in UiText values (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
770 | UiUndoMgr *mgr = value->data2; |
|
6
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
771 | |
| 174 | 772 | UiTextBufOp *elm = NULL; |
| 8 | 773 | if(mgr->cur) { |
| 774 | if(mgr->cur->next) { | |
| 775 | elm = mgr->cur->next; | |
| 776 | } | |
| 777 | } else if(mgr->begin) { | |
| 778 | elm = mgr->begin; | |
| 779 | } | |
| 780 | ||
| 781 | if(elm) { | |
| 174 | 782 | UiTextBufOp *op = elm; |
| 8 | 783 | mgr->event = 0; |
| 784 | switch(op->type) { | |
| 785 | case UI_TEXTBUF_INSERT: { | |
| 786 | GtkTextIter begin; | |
| 787 | GtkTextIter end; | |
|
1142
e2a6707aa1e0
fix some UiText functions using obj instead of data1 (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1114
diff
changeset
|
788 | gtk_text_buffer_get_iter_at_offset(buf, &begin, op->start); |
|
e2a6707aa1e0
fix some UiText functions using obj instead of data1 (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1114
diff
changeset
|
789 | gtk_text_buffer_get_iter_at_offset(buf, &end, op->end); |
|
e2a6707aa1e0
fix some UiText functions using obj instead of data1 (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1114
diff
changeset
|
790 | gtk_text_buffer_insert(buf, &begin, op->text, op->len); |
| 8 | 791 | break; |
| 792 | } | |
| 793 | case UI_TEXTBUF_DELETE: { | |
| 794 | GtkTextIter begin; | |
| 795 | GtkTextIter end; | |
|
1142
e2a6707aa1e0
fix some UiText functions using obj instead of data1 (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1114
diff
changeset
|
796 | gtk_text_buffer_get_iter_at_offset(buf, &begin, op->start); |
|
e2a6707aa1e0
fix some UiText functions using obj instead of data1 (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1114
diff
changeset
|
797 | gtk_text_buffer_get_iter_at_offset(buf, &end, op->end); |
|
e2a6707aa1e0
fix some UiText functions using obj instead of data1 (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1114
diff
changeset
|
798 | gtk_text_buffer_delete(buf, &begin, &end); |
| 8 | 799 | break; |
| 800 | } | |
| 801 | } | |
| 802 | mgr->event = 1; | |
| 803 | mgr->cur = elm; | |
| 804 | } | |
|
6
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
805 | } |
|
65
4697592e24ba
added label, grid container, simple tabview and textfield (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
806 | |
|
4697592e24ba
added label, grid container, simple tabview and textfield (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
807 | |
|
267
79dd183dd4cb
port textfield to new API (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
253
diff
changeset
|
808 | |
|
79dd183dd4cb
port textfield to new API (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
253
diff
changeset
|
809 | |
|
594
fc854e0ab924
pass Args structs per pointer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
506
diff
changeset
|
810 | static UIWIDGET create_textfield(UiObject *obj, UiBool frameless, UiBool password, UiTextFieldArgs *args) { |
|
65
4697592e24ba
added label, grid container, simple tabview and textfield (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
811 | GtkWidget *textfield = gtk_entry_new(); |
|
594
fc854e0ab924
pass Args structs per pointer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
506
diff
changeset
|
812 | ui_set_name_and_style(textfield, args->name, args->style_class); |
| 973 | 813 | ui_set_widget_states(obj->ctx, textfield, args->states); |
|
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
814 | |
|
801
e096c441e874
refactor gtk container hierarchy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
788
diff
changeset
|
815 | UiVar* var = uic_widget_var(obj->ctx, obj->ctx, args->value, args->varname, UI_VAR_STRING); |
|
267
79dd183dd4cb
port textfield to new API (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
253
diff
changeset
|
816 | |
|
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
817 | UiTextField *uitext = malloc(sizeof(UiTextField)); |
|
371
8c028965410a
implement textfield onchange event (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
356
diff
changeset
|
818 | uitext->obj = obj; |
|
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
819 | uitext->var = var; |
|
594
fc854e0ab924
pass Args structs per pointer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
506
diff
changeset
|
820 | uitext->onchange = args->onchange; |
|
fc854e0ab924
pass Args structs per pointer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
506
diff
changeset
|
821 | uitext->onchangedata = args->onchangedata; |
|
fc854e0ab924
pass Args structs per pointer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
506
diff
changeset
|
822 | uitext->onactivate = args->onactivate; |
|
fc854e0ab924
pass Args structs per pointer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
506
diff
changeset
|
823 | uitext->onactivatedata = args->onactivatedata; |
|
1103
4ba6f75d8966
implement actions for textfield events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1068
diff
changeset
|
824 | uitext->onactivate_action = args->onactivate_action ? strdup(args->onactivate_action) : NULL; |
|
4ba6f75d8966
implement actions for textfield events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1068
diff
changeset
|
825 | uitext->onchange_action = args->onchange_action ? strdup(args->onchange_action) : NULL; |
|
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
826 | |
|
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
827 | g_signal_connect( |
|
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
828 | textfield, |
|
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
829 | "destroy", |
|
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
830 | G_CALLBACK(ui_textfield_destroy), |
|
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
831 | uitext); |
|
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
832 | |
|
594
fc854e0ab924
pass Args structs per pointer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
506
diff
changeset
|
833 | if(args->width > 0) { |
|
788
27f126f6e361
implement spinbox width arg (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
680
diff
changeset
|
834 | // An early implementation used gtk_entry_set_width_chars, |
|
27f126f6e361
implement spinbox width arg (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
680
diff
changeset
|
835 | // but that is not available on gtk4 and other toolkits |
|
27f126f6e361
implement spinbox width arg (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
680
diff
changeset
|
836 | // also don't have this. Setting the width in pixels can |
|
27f126f6e361
implement spinbox width arg (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
680
diff
changeset
|
837 | // be implemented on all platforms |
|
27f126f6e361
implement spinbox width arg (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
680
diff
changeset
|
838 | gtk_widget_set_size_request(textfield, args->width, -1); |
|
94
d51e334c1439
added checkbox and labels with alignment (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
90
diff
changeset
|
839 | } |
|
121
1cc365c34125
added some special textfields (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
94
diff
changeset
|
840 | if(frameless) { |
|
1cc365c34125
added some special textfields (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
94
diff
changeset
|
841 | // TODO: gtk2legacy workaroud |
|
1cc365c34125
added some special textfields (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
94
diff
changeset
|
842 | gtk_entry_set_has_frame(GTK_ENTRY(textfield), FALSE); |
|
1cc365c34125
added some special textfields (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
94
diff
changeset
|
843 | } |
|
1cc365c34125
added some special textfields (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
94
diff
changeset
|
844 | if(password) { |
|
1cc365c34125
added some special textfields (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
94
diff
changeset
|
845 | gtk_entry_set_visibility(GTK_ENTRY(textfield), FALSE); |
|
1cc365c34125
added some special textfields (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
94
diff
changeset
|
846 | } |
|
94
d51e334c1439
added checkbox and labels with alignment (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
90
diff
changeset
|
847 | |
|
801
e096c441e874
refactor gtk container hierarchy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
788
diff
changeset
|
848 | UiContainerPrivate *ct = (UiContainerPrivate*)obj->container_end; |
|
e096c441e874
refactor gtk container hierarchy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
788
diff
changeset
|
849 | UiLayout layout = UI_ARGS2LAYOUT(args); |
|
e096c441e874
refactor gtk container hierarchy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
788
diff
changeset
|
850 | ct->add(ct, textfield, &layout); |
|
1063
e0251f6e15f7
add visibility_states arg to labels, buttons, text widgets (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1045
diff
changeset
|
851 | uic_widget_set_visibility_states(obj->ctx, textfield, args->visibility_states); |
|
65
4697592e24ba
added label, grid container, simple tabview and textfield (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
852 | |
|
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
853 | if(var) { |
|
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
854 | UiString *value = var->value; |
|
141
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
855 | if(value->value.ptr) { |
|
298
c5e207d01ff2
port button, text to gtk4
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
856 | ENTRY_SET_TEXT(textfield, value->value.ptr); |
|
141
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
857 | value->value.free(value->value.ptr); |
|
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
858 | value->value.ptr = NULL; |
|
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
859 | value->value.free = NULL; |
|
65
4697592e24ba
added label, grid container, simple tabview and textfield (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
860 | } |
|
4697592e24ba
added label, grid container, simple tabview and textfield (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
861 | |
|
4697592e24ba
added label, grid container, simple tabview and textfield (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
862 | value->get = ui_textfield_get; |
|
4697592e24ba
added label, grid container, simple tabview and textfield (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
863 | value->set = ui_textfield_set; |
|
141
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
864 | value->value.ptr = NULL; |
|
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
865 | value->value.free = NULL; |
|
65
4697592e24ba
added label, grid container, simple tabview and textfield (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
866 | value->obj = GTK_ENTRY(textfield); |
|
371
8c028965410a
implement textfield onchange event (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
356
diff
changeset
|
867 | } |
|
8c028965410a
implement textfield onchange event (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
356
diff
changeset
|
868 | |
|
1103
4ba6f75d8966
implement actions for textfield events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1068
diff
changeset
|
869 | if(args->onchange || args->onchange_action || var) { |
|
143
d499b29d7cb6
adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
141
diff
changeset
|
870 | g_signal_connect( |
|
d499b29d7cb6
adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
141
diff
changeset
|
871 | textfield, |
|
d499b29d7cb6
adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
141
diff
changeset
|
872 | "changed", |
|
d499b29d7cb6
adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
141
diff
changeset
|
873 | G_CALLBACK(ui_textfield_changed), |
|
d499b29d7cb6
adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
141
diff
changeset
|
874 | uitext); |
|
65
4697592e24ba
added label, grid container, simple tabview and textfield (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
875 | } |
|
4697592e24ba
added label, grid container, simple tabview and textfield (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
876 | |
|
1103
4ba6f75d8966
implement actions for textfield events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1068
diff
changeset
|
877 | if(args->onactivate || args->onactivate_action) { |
|
402
96a055be7f0b
add textfield onactivate event (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
397
diff
changeset
|
878 | g_signal_connect( |
|
96a055be7f0b
add textfield onactivate event (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
397
diff
changeset
|
879 | textfield, |
|
96a055be7f0b
add textfield onactivate event (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
397
diff
changeset
|
880 | "activate", |
|
96a055be7f0b
add textfield onactivate event (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
397
diff
changeset
|
881 | G_CALLBACK(ui_textfield_activate), |
|
96a055be7f0b
add textfield onactivate event (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
397
diff
changeset
|
882 | uitext); |
|
96a055be7f0b
add textfield onactivate event (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
397
diff
changeset
|
883 | } |
|
96a055be7f0b
add textfield onactivate event (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
397
diff
changeset
|
884 | |
|
65
4697592e24ba
added label, grid container, simple tabview and textfield (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
885 | return textfield; |
|
4697592e24ba
added label, grid container, simple tabview and textfield (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
886 | } |
|
4697592e24ba
added label, grid container, simple tabview and textfield (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
887 | |
|
594
fc854e0ab924
pass Args structs per pointer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
506
diff
changeset
|
888 | UIWIDGET ui_textfield_create(UiObject *obj, UiTextFieldArgs *args) { |
|
267
79dd183dd4cb
port textfield to new API (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
253
diff
changeset
|
889 | return create_textfield(obj, FALSE, FALSE, args); |
|
65
4697592e24ba
added label, grid container, simple tabview and textfield (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
890 | } |
|
4697592e24ba
added label, grid container, simple tabview and textfield (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
891 | |
|
594
fc854e0ab924
pass Args structs per pointer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
506
diff
changeset
|
892 | UIWIDGET ui_frameless_textfield_create(UiObject* obj, UiTextFieldArgs *args) { |
|
267
79dd183dd4cb
port textfield to new API (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
253
diff
changeset
|
893 | return create_textfield(obj, TRUE, FALSE, args); |
|
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
894 | } |
|
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
895 | |
|
594
fc854e0ab924
pass Args structs per pointer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
506
diff
changeset
|
896 | UIWIDGET ui_passwordfield_create(UiObject* obj, UiTextFieldArgs *args) { |
|
267
79dd183dd4cb
port textfield to new API (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
253
diff
changeset
|
897 | return create_textfield(obj, FALSE, TRUE, args); |
|
79dd183dd4cb
port textfield to new API (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
253
diff
changeset
|
898 | } |
|
79dd183dd4cb
port textfield to new API (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
253
diff
changeset
|
899 | |
|
1044
c6b58646c249
extend textfield API (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1016
diff
changeset
|
900 | void ui_textfield_focus(UIWIDGET textfield) { |
|
c6b58646c249
extend textfield API (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1016
diff
changeset
|
901 | gtk_widget_grab_focus(textfield); |
|
c6b58646c249
extend textfield API (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1016
diff
changeset
|
902 | } |
|
c6b58646c249
extend textfield API (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1016
diff
changeset
|
903 | |
|
c6b58646c249
extend textfield API (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1016
diff
changeset
|
904 | void ui_textfield_focus_without_selecting(UIWIDGET textfield) { |
|
c6b58646c249
extend textfield API (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1016
diff
changeset
|
905 | #if GTK_CHECK_VERSION(3, 16, 0) |
|
c6b58646c249
extend textfield API (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1016
diff
changeset
|
906 | gtk_entry_grab_focus_without_selecting(GTK_ENTRY(textfield)); |
|
c6b58646c249
extend textfield API (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1016
diff
changeset
|
907 | #else |
|
c6b58646c249
extend textfield API (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1016
diff
changeset
|
908 | gtk_widget_grab_focus(textfield); |
|
c6b58646c249
extend textfield API (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1016
diff
changeset
|
909 | #endif |
|
c6b58646c249
extend textfield API (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1016
diff
changeset
|
910 | } |
|
c6b58646c249
extend textfield API (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1016
diff
changeset
|
911 | |
|
1045
e855396fd839
extend textfield API (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1044
diff
changeset
|
912 | void ui_textfield_set_selection(UIWIDGET textfield, int begin, int end) { |
|
e855396fd839
extend textfield API (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1044
diff
changeset
|
913 | ENTRY_SET_SELECTION(textfield, begin, end); |
|
1044
c6b58646c249
extend textfield API (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1016
diff
changeset
|
914 | } |
|
c6b58646c249
extend textfield API (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1016
diff
changeset
|
915 | |
|
c6b58646c249
extend textfield API (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1016
diff
changeset
|
916 | void ui_textfield_select_all(UIWIDGET textfield) { |
|
c6b58646c249
extend textfield API (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1016
diff
changeset
|
917 | ENTRY_SET_SELECTION(textfield, 0, -1); |
|
c6b58646c249
extend textfield API (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1016
diff
changeset
|
918 | } |
|
c6b58646c249
extend textfield API (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1016
diff
changeset
|
919 | |
|
c6b58646c249
extend textfield API (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1016
diff
changeset
|
920 | void ui_textfield_set_editable(UIWIDGET textfield, UiBool editable) { |
|
c6b58646c249
extend textfield API (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1016
diff
changeset
|
921 | ENTRY_SET_EDITABLE(textfield, editable); |
|
c6b58646c249
extend textfield API (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1016
diff
changeset
|
922 | } |
|
c6b58646c249
extend textfield API (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1016
diff
changeset
|
923 | |
|
c6b58646c249
extend textfield API (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1016
diff
changeset
|
924 | UiBool ui_textfield_is_editable(UIWIDGET textfield) { |
|
c6b58646c249
extend textfield API (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1016
diff
changeset
|
925 | ENTRY_IS_EDITABLE(textfield); |
|
c6b58646c249
extend textfield API (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1016
diff
changeset
|
926 | } |
|
c6b58646c249
extend textfield API (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1016
diff
changeset
|
927 | |
|
c6b58646c249
extend textfield API (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1016
diff
changeset
|
928 | void ui_textfield_set_position(UIWIDGET textfield, int pos) { |
|
c6b58646c249
extend textfield API (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1016
diff
changeset
|
929 | ENTRY_SET_POSITION(textfield, pos); |
|
c6b58646c249
extend textfield API (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1016
diff
changeset
|
930 | } |
|
c6b58646c249
extend textfield API (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1016
diff
changeset
|
931 | |
|
c6b58646c249
extend textfield API (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1016
diff
changeset
|
932 | int ui_textfield_get_position(UIWIDGET textfield) { |
|
c6b58646c249
extend textfield API (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1016
diff
changeset
|
933 | return ENTRY_GET_POSITION(textfield); |
|
c6b58646c249
extend textfield API (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1016
diff
changeset
|
934 | } |
|
267
79dd183dd4cb
port textfield to new API (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
253
diff
changeset
|
935 | |
|
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
936 | void ui_textfield_destroy(GtkWidget *object, UiTextField *textfield) { |
|
1103
4ba6f75d8966
implement actions for textfield events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1068
diff
changeset
|
937 | free(textfield->onactivate_action); |
|
4ba6f75d8966
implement actions for textfield events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1068
diff
changeset
|
938 | free(textfield->onchange_action); |
|
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
939 | free(textfield); |
|
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
940 | } |
|
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
941 | |
|
143
d499b29d7cb6
adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
141
diff
changeset
|
942 | void ui_textfield_changed(GtkEditable *editable, UiTextField *textfield) { |
|
906
edfdf9776da9
disable onchange events when detaching a document
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
809
diff
changeset
|
943 | if(!ui_onchange_events_is_enabled()) { |
|
edfdf9776da9
disable onchange events when detaching a document
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
809
diff
changeset
|
944 | return; |
|
edfdf9776da9
disable onchange events when detaching a document
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
809
diff
changeset
|
945 | } |
|
edfdf9776da9
disable onchange events when detaching a document
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
809
diff
changeset
|
946 | |
|
907
d54a72c94320
implement textfield callbacks (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
906
diff
changeset
|
947 | UiString *value = textfield->var ? textfield->var->value : NULL; |
|
371
8c028965410a
implement textfield onchange event (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
356
diff
changeset
|
948 | |
|
8c028965410a
implement textfield onchange event (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
356
diff
changeset
|
949 | UiEvent e; |
|
8c028965410a
implement textfield onchange event (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
356
diff
changeset
|
950 | e.obj = textfield->obj; |
|
8c028965410a
implement textfield onchange event (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
356
diff
changeset
|
951 | e.window = e.obj->window; |
|
8c028965410a
implement textfield onchange event (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
356
diff
changeset
|
952 | e.document = textfield->obj->ctx->document; |
|
8c028965410a
implement textfield onchange event (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
356
diff
changeset
|
953 | e.eventdata = value; |
|
1103
4ba6f75d8966
implement actions for textfield events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1068
diff
changeset
|
954 | e.eventdatatype = value ? UI_EVENT_DATA_STRING_VALUE : 0; |
|
371
8c028965410a
implement textfield onchange event (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
356
diff
changeset
|
955 | e.intval = 0; |
|
505
8002be179741
re-enable textarea onchange event (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
487
diff
changeset
|
956 | e.set = ui_get_setop(); |
|
371
8c028965410a
implement textfield onchange event (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
356
diff
changeset
|
957 | |
|
8c028965410a
implement textfield onchange event (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
356
diff
changeset
|
958 | if(textfield->onchange) { |
|
8c028965410a
implement textfield onchange event (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
356
diff
changeset
|
959 | textfield->onchange(&e, textfield->onchangedata); |
|
8c028965410a
implement textfield onchange event (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
356
diff
changeset
|
960 | } |
|
8c028965410a
implement textfield onchange event (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
356
diff
changeset
|
961 | |
|
8c028965410a
implement textfield onchange event (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
356
diff
changeset
|
962 | if(textfield->var) { |
|
143
d499b29d7cb6
adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
141
diff
changeset
|
963 | ui_notify_evt(value->observers, &e); |
|
d499b29d7cb6
adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
141
diff
changeset
|
964 | } |
|
1103
4ba6f75d8966
implement actions for textfield events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1068
diff
changeset
|
965 | |
|
4ba6f75d8966
implement actions for textfield events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1068
diff
changeset
|
966 | if(textfield->onchange_action) { |
|
4ba6f75d8966
implement actions for textfield events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1068
diff
changeset
|
967 | uic_action_callback(&e, textfield->onchange_action); |
|
4ba6f75d8966
implement actions for textfield events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1068
diff
changeset
|
968 | } |
|
143
d499b29d7cb6
adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
141
diff
changeset
|
969 | } |
|
d499b29d7cb6
adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
141
diff
changeset
|
970 | |
|
402
96a055be7f0b
add textfield onactivate event (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
397
diff
changeset
|
971 | void ui_textfield_activate(GtkEntry* self, UiTextField *textfield) { |
|
1103
4ba6f75d8966
implement actions for textfield events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1068
diff
changeset
|
972 | UiString *value = textfield->var ? textfield->var->value : NULL; |
|
907
d54a72c94320
implement textfield callbacks (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
906
diff
changeset
|
973 | |
|
1103
4ba6f75d8966
implement actions for textfield events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1068
diff
changeset
|
974 | UiEvent e; |
|
4ba6f75d8966
implement actions for textfield events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1068
diff
changeset
|
975 | e.obj = textfield->obj; |
|
4ba6f75d8966
implement actions for textfield events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1068
diff
changeset
|
976 | e.window = e.obj->window; |
|
4ba6f75d8966
implement actions for textfield events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1068
diff
changeset
|
977 | e.document = textfield->obj->ctx->document; |
|
4ba6f75d8966
implement actions for textfield events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1068
diff
changeset
|
978 | e.eventdata = value; |
|
4ba6f75d8966
implement actions for textfield events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1068
diff
changeset
|
979 | e.eventdatatype = value ? UI_EVENT_DATA_TEXT_VALUE : 0; |
|
4ba6f75d8966
implement actions for textfield events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1068
diff
changeset
|
980 | e.intval = 0; |
|
4ba6f75d8966
implement actions for textfield events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1068
diff
changeset
|
981 | e.set = ui_get_setop(); |
|
4ba6f75d8966
implement actions for textfield events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1068
diff
changeset
|
982 | |
|
4ba6f75d8966
implement actions for textfield events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1068
diff
changeset
|
983 | if(textfield->onactivate) { |
|
402
96a055be7f0b
add textfield onactivate event (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
397
diff
changeset
|
984 | textfield->onactivate(&e, textfield->onactivatedata); |
|
96a055be7f0b
add textfield onactivate event (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
397
diff
changeset
|
985 | } |
|
1103
4ba6f75d8966
implement actions for textfield events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1068
diff
changeset
|
986 | |
|
4ba6f75d8966
implement actions for textfield events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1068
diff
changeset
|
987 | if(textfield->onactivate_action) { |
|
4ba6f75d8966
implement actions for textfield events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1068
diff
changeset
|
988 | uic_action_callback(&e, textfield->onactivate_action); |
|
4ba6f75d8966
implement actions for textfield events (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1068
diff
changeset
|
989 | } |
|
402
96a055be7f0b
add textfield onactivate event (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
397
diff
changeset
|
990 | } |
|
121
1cc365c34125
added some special textfields (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
94
diff
changeset
|
991 | |
|
65
4697592e24ba
added label, grid container, simple tabview and textfield (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
992 | char* ui_textfield_get(UiString *str) { |
|
141
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
993 | if(str->value.ptr) { |
|
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
994 | str->value.free(str->value.ptr); |
|
65
4697592e24ba
added label, grid container, simple tabview and textfield (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
995 | } |
|
298
c5e207d01ff2
port button, text to gtk4
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
996 | str->value.ptr = g_strdup(ENTRY_GET_TEXT(str->obj)); |
|
141
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
997 | str->value.free = (ui_freefunc)g_free; |
|
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
998 | return str->value.ptr; |
|
65
4697592e24ba
added label, grid container, simple tabview and textfield (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
999 | } |
|
4697592e24ba
added label, grid container, simple tabview and textfield (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
1000 | |
|
253
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
1001 | void ui_textfield_set(UiString *str, const char *value) { |
|
298
c5e207d01ff2
port button, text to gtk4
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
1002 | ENTRY_SET_TEXT(str->obj, value); |
|
141
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
1003 | if(str->value.ptr) { |
|
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
1004 | str->value.free(str->value.ptr); |
|
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
1005 | str->value.ptr = NULL; |
|
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
1006 | str->value.free = NULL; |
|
65
4697592e24ba
added label, grid container, simple tabview and textfield (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
1007 | } |
|
4697592e24ba
added label, grid container, simple tabview and textfield (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
1008 | } |
|
282
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1009 | |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1010 | // ----------------------- path textfield ----------------------- |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1011 | |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1012 | // TODO: move to common |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1013 | static UiPathElm* default_pathelm_func(const char* full_path, size_t len, size_t* ret_nelm, void* data) { |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1014 | cxstring *pathelms; |
| 1016 | 1015 | size_t nelm = cx_strsplit_a(cxDefaultAllocator, cx_strn(full_path, len), cx_str("/"), 4096, &pathelms); |
|
282
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1016 | |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1017 | if (nelm == 0) { |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1018 | *ret_nelm = 0; |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1019 | return NULL; |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1020 | } |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1021 | |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1022 | UiPathElm* elms = (UiPathElm*)calloc(nelm, sizeof(UiPathElm)); |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1023 | size_t n = nelm; |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1024 | int j = 0; |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1025 | for (int i = 0; i < nelm; i++) { |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1026 | cxstring c = pathelms[i]; |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1027 | if (c.length == 0) { |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1028 | if (i == 0) { |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1029 | c.length = 1; |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1030 | } |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1031 | else { |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1032 | n--; |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1033 | continue; |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1034 | } |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1035 | } |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1036 | |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1037 | cxmutstr m = cx_strdup(c); |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1038 | elms[j].name = m.ptr; |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1039 | elms[j].name_len = m.length; |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1040 | |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1041 | size_t elm_path_len = c.ptr + c.length - full_path; |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1042 | cxmutstr elm_path = cx_strdup(cx_strn(full_path, elm_path_len)); |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1043 | elms[j].path = elm_path.ptr; |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1044 | elms[j].path_len = elm_path.length; |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1045 | |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1046 | j++; |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1047 | } |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1048 | *ret_nelm = n; |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1049 | |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1050 | return elms; |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1051 | } |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1052 | |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1053 | static void ui_pathelm_destroy(UiPathElm *elms, size_t nelm) { |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1054 | for(int i=0;i<nelm;i++) { |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1055 | free(elms[i].name); |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1056 | free(elms[i].path); |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1057 | } |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1058 | free(elms); |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1059 | } |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1060 | |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1061 | static void ui_path_textfield_destroy(GtkWidget *object, UiPathTextField *pathtf) { |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1062 | g_object_unref(pathtf->entry); |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1063 | free(pathtf); |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1064 | } |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1065 | |
|
323
38cb8e3992e8
improve pathbar visuals (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
314
diff
changeset
|
1066 | void ui_path_button_clicked(GtkWidget *widget, UiEventDataExt *event) { |
|
38cb8e3992e8
improve pathbar visuals (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
314
diff
changeset
|
1067 | UiPathTextField *pathtf = event->customdata1; |
|
38cb8e3992e8
improve pathbar visuals (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
314
diff
changeset
|
1068 | for(int i=0;i<event->value1;i++) { |
|
38cb8e3992e8
improve pathbar visuals (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
314
diff
changeset
|
1069 | if(i <= event->value0) { |
| 326 | 1070 | WIDGET_REMOVE_CSS_CLASS(pathtf->current_path_buttons[i], "pathbar-button-inactive"); |
|
323
38cb8e3992e8
improve pathbar visuals (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
314
diff
changeset
|
1071 | } else { |
| 326 | 1072 | WIDGET_ADD_CSS_CLASS(pathtf->current_path_buttons[i], "pathbar-button-inactive"); |
|
323
38cb8e3992e8
improve pathbar visuals (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
314
diff
changeset
|
1073 | } |
|
38cb8e3992e8
improve pathbar visuals (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
314
diff
changeset
|
1074 | } |
|
38cb8e3992e8
improve pathbar visuals (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
314
diff
changeset
|
1075 | |
|
38cb8e3992e8
improve pathbar visuals (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
314
diff
changeset
|
1076 | UiPathElm *elm = event->customdata0; |
|
310
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1077 | cxmutstr path = cx_strdup(cx_strn(elm->path, elm->path_len)); |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1078 | UiEvent evt; |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1079 | evt.obj = event->obj; |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1080 | evt.window = evt.obj->window; |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1081 | evt.document = evt.obj->ctx->document; |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1082 | evt.eventdata = elm->path; |
|
659
d6baaa93f7be
add UiEvent eventdatatype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
594
diff
changeset
|
1083 | evt.eventdatatype = UI_EVENT_DATA_STRING; |
|
323
38cb8e3992e8
improve pathbar visuals (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
314
diff
changeset
|
1084 | evt.intval = event->value0; |
|
506
02ddf1044cbc
connect changed event to all textbuffer objects (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
505
diff
changeset
|
1085 | evt.set = ui_get_setop(); |
|
310
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1086 | event->callback(&evt, event->userdata); |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1087 | free(path.ptr); |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1088 | } |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1089 | |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1090 | int ui_pathtextfield_update(UiPathTextField* pathtf, const char *full_path) { |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1091 | size_t full_path_len = strlen(full_path); |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1092 | if(full_path_len == 0) { |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1093 | return 1; |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1094 | } |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1095 | |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1096 | size_t nelm = 0; |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1097 | UiPathElm* path_elm = pathtf->getpathelm(full_path, full_path_len, &nelm, pathtf->getpathelmdata); |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1098 | if (!path_elm) { |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1099 | return 1; |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1100 | } |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1101 | |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1102 | free(pathtf->current_path); |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1103 | pathtf->current_path = strdup(full_path); |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1104 | |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1105 | ui_pathelm_destroy(pathtf->current_pathelms, pathtf->current_nelm); |
|
323
38cb8e3992e8
improve pathbar visuals (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
314
diff
changeset
|
1106 | free(pathtf->current_path_buttons); |
|
38cb8e3992e8
improve pathbar visuals (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
314
diff
changeset
|
1107 | pathtf->current_path_buttons = calloc(nelm, sizeof(GtkWidget*)); |
|
310
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1108 | pathtf->current_pathelms = path_elm; |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1109 | pathtf->current_nelm = nelm; |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1110 | |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1111 | return ui_pathtextfield_update_widget(pathtf); |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1112 | } |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1113 | |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1114 | static GtkWidget* ui_path_elm_button(UiPathTextField *pathtf, UiPathElm *elm, int i) { |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1115 | cxmutstr name = cx_strdup(cx_strn(elm->name, elm->name_len)); |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1116 | GtkWidget *button = gtk_button_new_with_label(name.ptr); |
|
323
38cb8e3992e8
improve pathbar visuals (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
314
diff
changeset
|
1117 | pathtf->current_path_buttons[i] = button; |
|
310
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1118 | free(name.ptr); |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1119 | |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1120 | if(pathtf->onactivate) { |
|
323
38cb8e3992e8
improve pathbar visuals (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
314
diff
changeset
|
1121 | UiEventDataExt *eventdata = malloc(sizeof(UiEventDataExt)); |
|
38cb8e3992e8
improve pathbar visuals (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
314
diff
changeset
|
1122 | memset(eventdata, 0, sizeof(UiEventDataExt)); |
|
310
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1123 | eventdata->callback = pathtf->onactivate; |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1124 | eventdata->userdata = pathtf->onactivatedata; |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1125 | eventdata->obj = pathtf->obj; |
|
323
38cb8e3992e8
improve pathbar visuals (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
314
diff
changeset
|
1126 | eventdata->customdata0 = elm; |
|
38cb8e3992e8
improve pathbar visuals (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
314
diff
changeset
|
1127 | eventdata->customdata1 = pathtf; |
|
38cb8e3992e8
improve pathbar visuals (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
314
diff
changeset
|
1128 | eventdata->value0 = i; |
|
38cb8e3992e8
improve pathbar visuals (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
314
diff
changeset
|
1129 | eventdata->value1 = pathtf->current_nelm; |
|
310
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1130 | |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1131 | g_signal_connect( |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1132 | button, |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1133 | "clicked", |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1134 | G_CALLBACK(ui_path_button_clicked), |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1135 | eventdata); |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1136 | |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1137 | g_signal_connect( |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1138 | button, |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1139 | "destroy", |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1140 | G_CALLBACK(ui_destroy_userdata), |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1141 | eventdata); |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1142 | } |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1143 | |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1144 | return button; |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1145 | } |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1146 | |
|
282
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1147 | static void ui_path_textfield_activate(GtkWidget *entry, UiPathTextField *pathtf) { |
|
310
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1148 | const gchar *text = ENTRY_GET_TEXT(pathtf->entry); |
|
282
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1149 | if(strlen(text) == 0) { |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1150 | return; |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1151 | } |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1152 | |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1153 | UiObject *obj = pathtf->obj; |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1154 | |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1155 | if(ui_pathtextfield_update(pathtf, text)) { |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1156 | return; |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1157 | } |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1158 | |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1159 | if(pathtf->onactivate) { |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1160 | UiEvent evt; |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1161 | evt.obj = obj; |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1162 | evt.window = obj->window; |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1163 | evt.document = obj->ctx->document; |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1164 | evt.eventdata = (char*)text; |
|
659
d6baaa93f7be
add UiEvent eventdatatype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
594
diff
changeset
|
1165 | evt.eventdatatype = UI_EVENT_DATA_STRING; |
|
282
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1166 | evt.intval = -1; |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1167 | pathtf->onactivate(&evt, pathtf->onactivatedata); |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1168 | } |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1169 | } |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1170 | |
|
310
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1171 | #if GTK_MAJOR_VERSION >= 4 |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1172 | |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1173 | static void pathbar_show_hbox(GtkWidget *widget, UiPathTextField *pathtf) { |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1174 | if(pathtf->current_path) { |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1175 | gtk_stack_set_visible_child(GTK_STACK(pathtf->stack), pathtf->hbox); |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1176 | ENTRY_SET_TEXT(pathtf->entry, pathtf->current_path); |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1177 | } |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1178 | } |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1179 | |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1180 | static gboolean ui_path_textfield_key_controller( |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1181 | GtkEventControllerKey* self, |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1182 | guint keyval, |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1183 | guint keycode, |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1184 | GdkModifierType state, |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1185 | UiPathTextField *pathtf) |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1186 | { |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1187 | if(keyval == GDK_KEY_Escape) { |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1188 | pathbar_show_hbox(NULL, pathtf); |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1189 | } |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1190 | return FALSE; |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1191 | } |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1192 | |
|
594
fc854e0ab924
pass Args structs per pointer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
506
diff
changeset
|
1193 | UIWIDGET ui_path_textfield_create(UiObject* obj, UiPathTextFieldArgs *args) { |
|
310
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1194 | UiPathTextField *pathtf = malloc(sizeof(UiPathTextField)); |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1195 | memset(pathtf, 0, sizeof(UiPathTextField)); |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1196 | pathtf->obj = obj; |
|
594
fc854e0ab924
pass Args structs per pointer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
506
diff
changeset
|
1197 | pathtf->getpathelm = args->getpathelm; |
|
fc854e0ab924
pass Args structs per pointer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
506
diff
changeset
|
1198 | pathtf->getpathelmdata = args->getpathelmdata; |
|
fc854e0ab924
pass Args structs per pointer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
506
diff
changeset
|
1199 | pathtf->onactivate = args->onactivate; |
|
fc854e0ab924
pass Args structs per pointer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
506
diff
changeset
|
1200 | pathtf->onactivatedata = args->onactivatedata; |
|
fc854e0ab924
pass Args structs per pointer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
506
diff
changeset
|
1201 | pathtf->ondragcomplete = args->ondragcomplete; |
|
fc854e0ab924
pass Args structs per pointer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
506
diff
changeset
|
1202 | pathtf->ondragcompletedata = args->ondragcompletedata; |
|
fc854e0ab924
pass Args structs per pointer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
506
diff
changeset
|
1203 | pathtf->ondragstart = args->ondragstart; |
|
fc854e0ab924
pass Args structs per pointer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
506
diff
changeset
|
1204 | pathtf->ondragstartdata = args->ondragstartdata; |
|
fc854e0ab924
pass Args structs per pointer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
506
diff
changeset
|
1205 | pathtf->ondrop = args->ondrop; |
|
fc854e0ab924
pass Args structs per pointer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
506
diff
changeset
|
1206 | pathtf->ondropdata = args->ondropsdata; |
|
310
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1207 | |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1208 | if(!pathtf->getpathelm) { |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1209 | pathtf->getpathelm = default_pathelm_func; |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1210 | pathtf->getpathelmdata = NULL; |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1211 | } |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1212 | |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1213 | pathtf->stack = gtk_stack_new(); |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1214 | gtk_widget_set_name(pathtf->stack, "path-textfield-box"); |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1215 | |
|
975
e0ac49797a30
add PathTextField width arg
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
973
diff
changeset
|
1216 | if(args->width > 0) { |
|
e0ac49797a30
add PathTextField width arg
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
973
diff
changeset
|
1217 | gtk_widget_set_size_request(pathtf->stack, args->width, -1); |
|
e0ac49797a30
add PathTextField width arg
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
973
diff
changeset
|
1218 | } |
|
e0ac49797a30
add PathTextField width arg
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
973
diff
changeset
|
1219 | |
|
801
e096c441e874
refactor gtk container hierarchy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
788
diff
changeset
|
1220 | UiContainerPrivate *ct = (UiContainerPrivate*)obj->container_end; |
|
e096c441e874
refactor gtk container hierarchy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
788
diff
changeset
|
1221 | UiLayout layout = UI_ARGS2LAYOUT(args); |
|
e096c441e874
refactor gtk container hierarchy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
788
diff
changeset
|
1222 | ct->add(ct, pathtf->stack, &layout); |
|
1063
e0251f6e15f7
add visibility_states arg to labels, buttons, text widgets (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1045
diff
changeset
|
1223 | uic_widget_set_visibility_states(obj->ctx, pathtf->stack, args->visibility_states); |
|
310
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1224 | |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1225 | pathtf->entry_box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0); |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1226 | pathtf->entry = gtk_entry_new(); |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1227 | gtk_box_append(GTK_BOX(pathtf->entry_box), pathtf->entry); |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1228 | gtk_widget_set_hexpand(pathtf->entry, TRUE); |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1229 | |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1230 | GtkWidget *cancel_button = gtk_button_new_from_icon_name("window-close-symbolic"); |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1231 | gtk_widget_add_css_class(cancel_button, "flat"); |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1232 | gtk_widget_add_css_class(cancel_button, "pathbar-extra-button"); |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1233 | gtk_box_append(GTK_BOX(pathtf->entry_box), cancel_button); |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1234 | g_signal_connect( |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1235 | cancel_button, |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1236 | "clicked", |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1237 | G_CALLBACK(pathbar_show_hbox), |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1238 | pathtf); |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1239 | |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1240 | gtk_stack_add_child(GTK_STACK(pathtf->stack), pathtf->entry_box); |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1241 | g_object_ref(pathtf->entry); // for compatibility with older pathbar version |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1242 | g_signal_connect( |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1243 | pathtf->entry, |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1244 | "activate", |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1245 | G_CALLBACK(ui_path_textfield_activate), |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1246 | pathtf); |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1247 | |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1248 | GtkEventController *entry_cancel = gtk_event_controller_key_new(); |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1249 | gtk_widget_add_controller(pathtf->entry, entry_cancel); |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1250 | g_signal_connect(entry_cancel, "key-pressed", G_CALLBACK(ui_path_textfield_key_controller), pathtf); |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1251 | |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1252 | gtk_stack_set_visible_child(GTK_STACK(pathtf->stack), pathtf->entry_box); |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1253 | |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1254 | |
|
801
e096c441e874
refactor gtk container hierarchy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
788
diff
changeset
|
1255 | UiVar* var = uic_widget_var(obj->ctx, obj->ctx, args->value, args->varname, UI_VAR_STRING); |
|
310
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1256 | if (var) { |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1257 | UiString* value = (UiString*)var->value; |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1258 | value->obj = pathtf; |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1259 | value->get = ui_path_textfield_get; |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1260 | value->set = ui_path_textfield_set; |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1261 | |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1262 | if(value->value.ptr) { |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1263 | char *str = strdup(value->value.ptr); |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1264 | ui_string_set(value, str); |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1265 | free(str); |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1266 | } |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1267 | } |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1268 | |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1269 | return pathtf->stack; |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1270 | } |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1271 | |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1272 | static void pathbar_pressed( |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1273 | GtkGestureClick* self, |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1274 | gint n_press, |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1275 | gdouble x, |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1276 | gdouble y, |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1277 | UiPathTextField *pathtf) |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1278 | { |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1279 | gtk_stack_set_visible_child(GTK_STACK(pathtf->stack), pathtf->entry_box); |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1280 | gtk_widget_grab_focus(pathtf->entry); |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1281 | } |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1282 | |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1283 | int ui_pathtextfield_update_widget(UiPathTextField* pathtf) { |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1284 | // recreate button hbox |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1285 | if(pathtf->hbox) { |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1286 | gtk_stack_remove(GTK_STACK(pathtf->stack), pathtf->hbox); |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1287 | } |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1288 | pathtf->hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0); |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1289 | gtk_box_set_homogeneous(GTK_BOX(pathtf->hbox), FALSE); |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1290 | gtk_stack_add_child(GTK_STACK(pathtf->stack), pathtf->hbox); |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1291 | gtk_widget_set_name(pathtf->hbox, "pathbar"); |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1292 | |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1293 | // add buttons for path elements |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1294 | for (int i=0;i<pathtf->current_nelm;i++) { |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1295 | UiPathElm *elm = &pathtf->current_pathelms[i]; |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1296 | |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1297 | GtkWidget *button = ui_path_elm_button(pathtf, elm, i); |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1298 | gtk_widget_add_css_class(button, "flat"); |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1299 | |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1300 | gtk_box_append(GTK_BOX(pathtf->hbox), button); |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1301 | |
| 1016 | 1302 | if(i+1 < pathtf->current_nelm && cx_strcmp(cx_strn(elm->name, elm->name_len), cx_str("/"))) { |
|
323
38cb8e3992e8
improve pathbar visuals (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
314
diff
changeset
|
1303 | GtkWidget *path_separator = gtk_label_new("/"); |
|
38cb8e3992e8
improve pathbar visuals (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
314
diff
changeset
|
1304 | gtk_widget_add_css_class(path_separator, "pathbar-button-inactive"); |
|
38cb8e3992e8
improve pathbar visuals (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
314
diff
changeset
|
1305 | gtk_box_append(GTK_BOX(pathtf->hbox), path_separator); |
|
310
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1306 | } |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1307 | } |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1308 | gtk_stack_set_visible_child(GTK_STACK(pathtf->stack), pathtf->hbox); |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1309 | |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1310 | // create a widget for receiving button press events |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1311 | GtkWidget *event_area = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0); |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1312 | GtkGesture *handler = gtk_gesture_click_new(); |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1313 | gtk_widget_add_controller(event_area, GTK_EVENT_CONTROLLER(handler)); |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1314 | g_signal_connect( |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1315 | handler, |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1316 | "pressed", |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1317 | G_CALLBACK(pathbar_pressed), |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1318 | pathtf); |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1319 | gtk_widget_set_hexpand(event_area, TRUE); |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1320 | gtk_widget_set_vexpand(event_area, TRUE); |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1321 | gtk_box_append(GTK_BOX(pathtf->hbox), event_area); |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1322 | |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1323 | return 0; |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1324 | } |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1325 | |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1326 | #else |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1327 | |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1328 | static gboolean path_textfield_btn_pressed(GtkWidget *widget, GdkEventButton *event, UiPathTextField *pathtf) { |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1329 | gtk_box_pack_start(GTK_BOX(pathtf->hbox), pathtf->entry, TRUE, TRUE, 0); |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1330 | gtk_container_remove(GTK_CONTAINER(pathtf->hbox), pathtf->buttonbox); |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1331 | pathtf->buttonbox = NULL; |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1332 | |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1333 | gtk_widget_show(pathtf->entry); |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1334 | gtk_widget_grab_focus(pathtf->entry); |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1335 | |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1336 | return TRUE; |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1337 | } |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1338 | |
|
282
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1339 | static gboolean ui_path_textfield_key_press(GtkWidget *self, GdkEventKey *event, UiPathTextField *pathtf) { |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1340 | if (event->keyval == GDK_KEY_Escape) { |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1341 | // reset GtkEntry value |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1342 | gtk_entry_set_text(GTK_ENTRY(self), pathtf->current_path); |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1343 | const gchar *text = gtk_entry_get_text(GTK_ENTRY(self)); |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1344 | ui_pathtextfield_update(pathtf, text); |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1345 | return TRUE; |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1346 | } |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1347 | return FALSE; |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1348 | } |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1349 | |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1350 | static GtkWidget* create_path_button_box() { |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1351 | GtkWidget *bb = gtk_button_box_new(GTK_ORIENTATION_HORIZONTAL); |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1352 | gtk_button_box_set_layout(GTK_BUTTON_BOX(bb), GTK_BUTTONBOX_EXPAND); // linked style |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1353 | gtk_box_set_homogeneous(GTK_BOX(bb), FALSE); |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1354 | gtk_box_set_spacing(GTK_BOX(bb), 0); |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1355 | return bb; |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1356 | } |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1357 | |
|
594
fc854e0ab924
pass Args structs per pointer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
506
diff
changeset
|
1358 | UIWIDGET ui_path_textfield_create(UiObject* obj, UiPathTextFieldArgs *args) { |
|
282
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1359 | UiPathTextField *pathtf = malloc(sizeof(UiPathTextField)); |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1360 | memset(pathtf, 0, sizeof(UiPathTextField)); |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1361 | pathtf->obj = obj; |
|
594
fc854e0ab924
pass Args structs per pointer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
506
diff
changeset
|
1362 | pathtf->getpathelm = args->getpathelm; |
|
fc854e0ab924
pass Args structs per pointer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
506
diff
changeset
|
1363 | pathtf->getpathelmdata = args->getpathelmdata; |
|
fc854e0ab924
pass Args structs per pointer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
506
diff
changeset
|
1364 | pathtf->onactivate = args->onactivate; |
|
fc854e0ab924
pass Args structs per pointer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
506
diff
changeset
|
1365 | pathtf->onactivatedata = args->onactivatedata; |
|
fc854e0ab924
pass Args structs per pointer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
506
diff
changeset
|
1366 | pathtf->ondragcomplete = args->ondragcomplete; |
|
fc854e0ab924
pass Args structs per pointer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
506
diff
changeset
|
1367 | pathtf->ondragcompletedata = args->ondragcompletedata; |
|
fc854e0ab924
pass Args structs per pointer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
506
diff
changeset
|
1368 | pathtf->ondragstart = args->ondragstart; |
|
fc854e0ab924
pass Args structs per pointer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
506
diff
changeset
|
1369 | pathtf->ondragstartdata = args->ondragstartdata; |
|
fc854e0ab924
pass Args structs per pointer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
506
diff
changeset
|
1370 | pathtf->ondrop = args->ondrop; |
|
fc854e0ab924
pass Args structs per pointer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
506
diff
changeset
|
1371 | pathtf->ondropdata = args->ondropsdata; |
|
282
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1372 | |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1373 | if(!pathtf->getpathelm) { |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1374 | pathtf->getpathelm = default_pathelm_func; |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1375 | pathtf->getpathelmdata = NULL; |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1376 | } |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1377 | |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1378 | // top level container for the path textfield is a GtkEventBox |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1379 | // the event box is needed to handle background button presses |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1380 | GtkWidget *eventbox = gtk_event_box_new(); |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1381 | g_signal_connect( |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1382 | eventbox, |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1383 | "button-press-event", |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1384 | G_CALLBACK(path_textfield_btn_pressed), |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1385 | pathtf); |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1386 | g_signal_connect( |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1387 | eventbox, |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1388 | "destroy", |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1389 | G_CALLBACK(ui_path_textfield_destroy), |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1390 | pathtf); |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1391 | |
|
975
e0ac49797a30
add PathTextField width arg
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
973
diff
changeset
|
1392 | if(args->width > 0) { |
|
e0ac49797a30
add PathTextField width arg
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
973
diff
changeset
|
1393 | gtk_widget_set_size_request(eventbox, args->width, -1); |
|
e0ac49797a30
add PathTextField width arg
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
973
diff
changeset
|
1394 | } |
|
e0ac49797a30
add PathTextField width arg
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
973
diff
changeset
|
1395 | |
|
801
e096c441e874
refactor gtk container hierarchy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
788
diff
changeset
|
1396 | UiContainerPrivate *ct = (UiContainerPrivate*)obj->container_end; |
|
e096c441e874
refactor gtk container hierarchy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
788
diff
changeset
|
1397 | UiLayout layout = UI_ARGS2LAYOUT(args); |
|
e096c441e874
refactor gtk container hierarchy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
788
diff
changeset
|
1398 | ct->add(ct, eventbox, &layout); |
|
1063
e0251f6e15f7
add visibility_states arg to labels, buttons, text widgets (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
1045
diff
changeset
|
1399 | uic_widget_set_visibility_states(obj->ctx, eventbox, args->visibility_states); |
|
282
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1400 | |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1401 | // hbox as parent for the GtkEntry and GtkButtonBox |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1402 | GtkWidget *hbox = ui_gtk_hbox_new(0); |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1403 | pathtf->hbox = hbox; |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1404 | gtk_container_add(GTK_CONTAINER(eventbox), hbox); |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1405 | gtk_widget_set_name(hbox, "path-textfield-box"); |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1406 | |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1407 | // create GtkEntry, that is also visible by default (with input yet) |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1408 | pathtf->entry = gtk_entry_new(); |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1409 | g_object_ref(G_OBJECT(pathtf->entry)); |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1410 | gtk_box_pack_start(GTK_BOX(hbox), pathtf->entry, TRUE, TRUE, 0); |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1411 | |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1412 | g_signal_connect( |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1413 | pathtf->entry, |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1414 | "activate", |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1415 | G_CALLBACK(ui_path_textfield_activate), |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1416 | pathtf); |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1417 | g_signal_connect( |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1418 | pathtf->entry, |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1419 | "key-press-event", |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1420 | G_CALLBACK(ui_path_textfield_key_press), |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1421 | pathtf); |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1422 | |
|
801
e096c441e874
refactor gtk container hierarchy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
788
diff
changeset
|
1423 | UiVar* var = uic_widget_var(obj->ctx, obj->ctx, args->value, args->varname, UI_VAR_STRING); |
|
282
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1424 | if (var) { |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1425 | UiString* value = (UiString*)var->value; |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1426 | value->obj = pathtf; |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1427 | value->get = ui_path_textfield_get; |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1428 | value->set = ui_path_textfield_set; |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1429 | |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1430 | if(value->value.ptr) { |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1431 | char *str = strdup(value->value.ptr); |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1432 | ui_string_set(value, str); |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1433 | free(str); |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1434 | } |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1435 | } |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1436 | |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1437 | return hbox; |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1438 | } |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1439 | |
|
310
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1440 | int ui_pathtextfield_update_widget(UiPathTextField* pathtf) { |
|
282
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1441 | GtkWidget *buttonbox = create_path_button_box(); |
|
289
6048b20bd46f
fix path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
282
diff
changeset
|
1442 | |
|
6048b20bd46f
fix path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
282
diff
changeset
|
1443 | // switch from entry to buttonbox or remove current buttonbox |
|
6048b20bd46f
fix path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
282
diff
changeset
|
1444 | if(pathtf->buttonbox) { |
|
6048b20bd46f
fix path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
282
diff
changeset
|
1445 | gtk_container_remove(GTK_CONTAINER(pathtf->hbox), pathtf->buttonbox); |
|
6048b20bd46f
fix path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
282
diff
changeset
|
1446 | } else { |
|
6048b20bd46f
fix path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
282
diff
changeset
|
1447 | gtk_container_remove(GTK_CONTAINER(pathtf->hbox), pathtf->entry); |
|
6048b20bd46f
fix path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
282
diff
changeset
|
1448 | } |
|
6048b20bd46f
fix path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
282
diff
changeset
|
1449 | gtk_box_pack_start(GTK_BOX(pathtf->hbox), buttonbox, FALSE, FALSE, 0); |
|
282
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1450 | pathtf->buttonbox = buttonbox; |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1451 | |
|
310
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1452 | for (int i=0;i<pathtf->current_nelm;i++) { |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1453 | UiPathElm *elm = &pathtf->current_pathelms[i]; |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1454 | GtkWidget *button = ui_path_elm_button(pathtf, elm, i); |
|
282
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1455 | gtk_box_pack_start(GTK_BOX(buttonbox), button, FALSE, FALSE, 0); |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1456 | } |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1457 | |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1458 | gtk_widget_show_all(buttonbox); |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1459 | |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1460 | return 0; |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1461 | } |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1462 | |
|
310
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1463 | #endif |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1464 | |
|
282
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1465 | char* ui_path_textfield_get(UiString *str) { |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1466 | if(str->value.ptr) { |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1467 | str->value.free(str->value.ptr); |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1468 | } |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1469 | UiPathTextField *tf = str->obj; |
|
310
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1470 | str->value.ptr = g_strdup(ENTRY_GET_TEXT(tf->entry)); |
|
282
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1471 | str->value.free = (ui_freefunc)g_free; |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1472 | return str->value.ptr; |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1473 | } |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1474 | |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1475 | void ui_path_textfield_set(UiString *str, const char *value) { |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1476 | UiPathTextField *tf = str->obj; |
|
310
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1477 | ENTRY_SET_TEXT(tf->entry, value); |
|
282
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1478 | ui_pathtextfield_update(tf, value); |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1479 | if(str->value.ptr) { |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1480 | str->value.free(str->value.ptr); |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1481 | str->value.ptr = NULL; |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1482 | str->value.free = NULL; |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1483 | } |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1484 | } |