Tue, 18 Nov 2025 12:55:28 +0100
disable onchange events when detaching a document
| 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" | |
|
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
35 | |
|
282
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
36 | #include <cx/printf.h> |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
37 | |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
38 | #include <gdk/gdkkeysyms.h> |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
39 | |
| 5 | 40 | |
| 174 | 41 | #include "../common/types.h" |
| 42 | ||
|
22
bcf880b29bc3
textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
43 | static void selection_handler( |
|
bcf880b29bc3
textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
44 | GtkTextBuffer *buf, |
|
bcf880b29bc3
textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
45 | GtkTextIter *location, |
|
bcf880b29bc3
textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
46 | GtkTextMark *mark, |
|
bcf880b29bc3
textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
47 | UiTextArea *textview) |
|
bcf880b29bc3
textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
48 | { |
|
bcf880b29bc3
textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
49 | 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
|
50 | if(mname) { |
|
bcf880b29bc3
textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
51 | GtkTextIter begin; |
|
bcf880b29bc3
textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
52 | GtkTextIter end; |
|
bcf880b29bc3
textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
53 | 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
|
54 | if(sel != textview->last_selection_state) { |
|
bcf880b29bc3
textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
55 | if(sel) { |
|
bcf880b29bc3
textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
56 | ui_set_group(textview->ctx, UI_GROUP_SELECTION); |
|
bcf880b29bc3
textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
57 | } else { |
|
bcf880b29bc3
textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
58 | ui_unset_group(textview->ctx, UI_GROUP_SELECTION); |
|
bcf880b29bc3
textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
59 | } |
|
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 | textview->last_selection_state = sel; |
|
bcf880b29bc3
textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
62 | } |
|
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 | |
|
486
a5f3abf8b9d1
refactor textarea to store a text buffer object in UiText values (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
65 | 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
|
66 | |
|
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 | #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
|
70 | 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
|
71 | 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
|
72 | |
|
a5f3abf8b9d1
refactor textarea to store a text buffer object in UiText values (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
73 | 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
|
74 | 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
|
75 | } |
|
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 | // 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
|
78 | 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
|
79 | buf, |
|
a5f3abf8b9d1
refactor textarea to store a text buffer object in UiText values (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
80 | "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
|
81 | 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
|
82 | var); |
|
a5f3abf8b9d1
refactor textarea to store a text buffer object in UiText values (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
83 | 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
|
84 | buf, |
|
a5f3abf8b9d1
refactor textarea to store a text buffer object in UiText values (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
85 | "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
|
86 | 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
|
87 | var); |
|
a5f3abf8b9d1
refactor textarea to store a text buffer object in UiText values (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
88 | 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
|
89 | buf, |
|
a5f3abf8b9d1
refactor textarea to store a text buffer object in UiText values (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
90 | "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
|
91 | 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
|
92 | uitext); |
|
a5f3abf8b9d1
refactor textarea to store a text buffer object in UiText values (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
93 | } |
|
a5f3abf8b9d1
refactor textarea to store a text buffer object in UiText values (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
94 | #endif |
|
a5f3abf8b9d1
refactor textarea to store a text buffer object in UiText values (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
95 | |
|
506
02ddf1044cbc
connect changed event to all textbuffer objects (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
505
diff
changeset
|
96 | 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
|
97 | 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
|
98 | if(textarea) { |
|
02ddf1044cbc
connect changed event to all textbuffer objects (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
505
diff
changeset
|
99 | g_signal_connect( |
|
02ddf1044cbc
connect changed event to all textbuffer objects (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
505
diff
changeset
|
100 | buf, |
|
02ddf1044cbc
connect changed event to all textbuffer objects (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
505
diff
changeset
|
101 | "changed", |
|
02ddf1044cbc
connect changed event to all textbuffer objects (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
505
diff
changeset
|
102 | G_CALLBACK(ui_textbuf_changed), |
|
02ddf1044cbc
connect changed event to all textbuffer objects (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
505
diff
changeset
|
103 | textarea); |
|
02ddf1044cbc
connect changed event to all textbuffer objects (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
505
diff
changeset
|
104 | } else { |
|
02ddf1044cbc
connect changed event to all textbuffer objects (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
505
diff
changeset
|
105 | 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
|
106 | } |
|
02ddf1044cbc
connect changed event to all textbuffer objects (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
505
diff
changeset
|
107 | return buf; |
|
02ddf1044cbc
connect changed event to all textbuffer objects (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
505
diff
changeset
|
108 | } |
|
02ddf1044cbc
connect changed event to all textbuffer objects (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
505
diff
changeset
|
109 | |
|
594
fc854e0ab924
pass Args structs per pointer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
506
diff
changeset
|
110 | UIWIDGET ui_textarea_create(UiObject *obj, UiTextAreaArgs *args) { |
|
801
e096c441e874
refactor gtk container hierarchy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
788
diff
changeset
|
111 | 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
|
112 | |
| 5 | 113 | 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
|
114 | ui_set_name_and_style(text_area, args->name, args->style_class); |
|
fc854e0ab924
pass Args structs per pointer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
506
diff
changeset
|
115 | ui_set_widget_groups(obj->ctx, text_area, args->groups); |
|
335
91d4f0391282
add new textarea (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
326
diff
changeset
|
116 | |
| 5 | 117 | gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(text_area), GTK_WRAP_WORD_CHAR); |
| 118 | g_signal_connect( | |
|
22
bcf880b29bc3
textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
119 | text_area, |
|
bcf880b29bc3
textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
120 | "realize", |
|
bcf880b29bc3
textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
121 | G_CALLBACK(ui_textarea_realize_event), |
|
bcf880b29bc3
textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
122 | NULL); |
|
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
123 | |
|
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
124 | UiTextArea *uitext = malloc(sizeof(UiTextArea)); |
|
379
958bae372271
implement ui_dialog_window (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
371
diff
changeset
|
125 | uitext->obj = obj; |
|
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
126 | uitext->ctx = obj->ctx; |
|
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
127 | uitext->var = var; |
|
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
128 | uitext->last_selection_state = 0; |
|
594
fc854e0ab924
pass Args structs per pointer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
506
diff
changeset
|
129 | uitext->onchange = args->onchange; |
|
fc854e0ab924
pass Args structs per pointer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
506
diff
changeset
|
130 | uitext->onchangedata = args->onchangedata; |
|
22
bcf880b29bc3
textarea automatically sets selection group (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
12
diff
changeset
|
131 | |
|
506
02ddf1044cbc
connect changed event to all textbuffer objects (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
505
diff
changeset
|
132 | g_object_set_data(G_OBJECT(text_area), "ui_textarea", uitext); |
|
02ddf1044cbc
connect changed event to all textbuffer objects (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
505
diff
changeset
|
133 | |
|
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
134 | g_signal_connect( |
|
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
135 | text_area, |
|
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
136 | "destroy", |
|
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
137 | G_CALLBACK(ui_textarea_destroy), |
|
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
138 | uitext); |
| 5 | 139 | |
|
298
c5e207d01ff2
port button, text to gtk4
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
140 | GtkWidget *scroll_area = SCROLLEDWINDOW_NEW(); |
| 5 | 141 | gtk_scrolled_window_set_policy( |
| 142 | GTK_SCROLLED_WINDOW(scroll_area), | |
| 143 | GTK_POLICY_AUTOMATIC, | |
| 144 | GTK_POLICY_AUTOMATIC); // GTK_POLICY_ALWAYS | |
|
298
c5e207d01ff2
port button, text to gtk4
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
145 | SCROLLEDWINDOW_SET_CHILD(scroll_area, text_area); |
| 5 | 146 | |
|
809
f5ddce392617
add width/height args to the textarea, listview and table (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
801
diff
changeset
|
147 | if(args->width > 0 || args->height > 0) { |
|
f5ddce392617
add width/height args to the textarea, listview and table (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
801
diff
changeset
|
148 | int width = args->width; |
|
f5ddce392617
add width/height args to the textarea, listview and table (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
801
diff
changeset
|
149 | int height = args->height; |
|
f5ddce392617
add width/height args to the textarea, listview and table (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
801
diff
changeset
|
150 | if(width == 0) { |
|
f5ddce392617
add width/height args to the textarea, listview and table (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
801
diff
changeset
|
151 | width = -1; |
|
f5ddce392617
add width/height args to the textarea, listview and table (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
801
diff
changeset
|
152 | } |
|
f5ddce392617
add width/height args to the textarea, listview and table (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
801
diff
changeset
|
153 | if(height == 0) { |
|
f5ddce392617
add width/height args to the textarea, listview and table (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
801
diff
changeset
|
154 | height = -1; |
|
f5ddce392617
add width/height args to the textarea, listview and table (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
801
diff
changeset
|
155 | } |
|
f5ddce392617
add width/height args to the textarea, listview and table (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
801
diff
changeset
|
156 | gtk_widget_set_size_request(scroll_area, width, height); |
|
f5ddce392617
add width/height args to the textarea, listview and table (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
801
diff
changeset
|
157 | } |
|
f5ddce392617
add width/height args to the textarea, listview and table (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
801
diff
changeset
|
158 | |
| 5 | 159 | // font and padding |
|
335
91d4f0391282
add new textarea (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
326
diff
changeset
|
160 | //PangoFontDescription *font; |
|
91d4f0391282
add new textarea (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
326
diff
changeset
|
161 | //font = pango_font_description_from_string("Monospace"); |
|
298
c5e207d01ff2
port button, text to gtk4
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
162 | //gtk_widget_modify_font(text_area, font); // TODO |
|
335
91d4f0391282
add new textarea (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
326
diff
changeset
|
163 | //pango_font_description_free(font); |
| 5 | 164 | |
| 165 | gtk_text_view_set_left_margin(GTK_TEXT_VIEW(text_area), 2); | |
| 166 | gtk_text_view_set_right_margin(GTK_TEXT_VIEW(text_area), 2); | |
| 167 | ||
| 168 | // add | |
|
801
e096c441e874
refactor gtk container hierarchy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
788
diff
changeset
|
169 | UiContainerPrivate *ct = (UiContainerPrivate*)obj->container_end; |
|
e096c441e874
refactor gtk container hierarchy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
788
diff
changeset
|
170 | UiLayout layout = UI_ARGS2LAYOUT(args); |
|
e096c441e874
refactor gtk container hierarchy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
788
diff
changeset
|
171 | ct->add(ct, scroll_area, &layout); |
| 5 | 172 | |
| 173 | // bind value | |
|
397
6d4adf6fba1f
fix textarea crash when no value is specified (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
174 | if(var) { |
|
6d4adf6fba1f
fix textarea crash when no value is specified (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
175 | 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
|
176 | 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
|
177 | 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
|
178 | 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
|
179 | } else { |
|
506
02ddf1044cbc
connect changed event to all textbuffer objects (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
505
diff
changeset
|
180 | 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
|
181 | 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
|
182 | 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
|
183 | 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
|
184 | } |
|
33
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
185 | } |
|
486
a5f3abf8b9d1
refactor textarea to store a text buffer object in UiText values (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
186 | 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
|
187 | 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
|
188 | 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
|
189 | 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
|
190 | value->destroy = ui_textarea_text_destroy; |
| 5 | 191 | value->get = ui_textarea_get; |
| 192 | value->set = ui_textarea_set; | |
|
12
fe94e0fb9ef3
added some text functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
9
diff
changeset
|
193 | value->getsubstr = ui_textarea_getsubstr; |
|
fe94e0fb9ef3
added some text functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
9
diff
changeset
|
194 | value->insert = ui_textarea_insert; |
|
90
2019fdbaadfd
persistent textarea cursor position
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
65
diff
changeset
|
195 | 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
|
196 | value->position = ui_textarea_position; |
|
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
22
diff
changeset
|
197 | value->selection = ui_textarea_selection; |
|
29
c96169444d88
added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
198 | 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
|
199 | 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
|
200 | 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
|
201 | 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
|
202 | 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
|
203 | value->value.ptr = NULL; |
|
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
204 | value->value.free = NULL; |
| 5 | 205 | |
|
486
a5f3abf8b9d1
refactor textarea to store a text buffer object in UiText values (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
206 | #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
|
207 | 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
|
208 | #endif |
| 5 | 209 | } |
| 210 | ||
| 211 | return scroll_area; | |
| 212 | } | |
| 213 | ||
|
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
214 | 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
|
215 | if(textarea->var) { |
|
6d4adf6fba1f
fix textarea crash when no value is specified (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
216 | 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
|
217 | } |
|
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
218 | free(textarea); |
|
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
219 | } |
|
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
220 | |
|
168
1b99acacc5bb
refactor widget groups
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
167
diff
changeset
|
221 | UIWIDGET ui_textarea_gettextwidget(UIWIDGET textarea) { |
|
298
c5e207d01ff2
port button, text to gtk4
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
222 | return SCROLLEDWINDOW_GET_CHILD(textarea); |
|
168
1b99acacc5bb
refactor widget groups
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
167
diff
changeset
|
223 | } |
|
1b99acacc5bb
refactor widget groups
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
167
diff
changeset
|
224 | |
|
486
a5f3abf8b9d1
refactor textarea to store a text buffer object in UiText values (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
225 | 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
|
226 | // NOOP |
|
a5f3abf8b9d1
refactor textarea to store a text buffer object in UiText values (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
227 | } |
|
a5f3abf8b9d1
refactor textarea to store a text buffer object in UiText values (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
228 | |
|
a5f3abf8b9d1
refactor textarea to store a text buffer object in UiText values (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
229 | 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
|
230 | GtkWidget *textarea = text->obj; |
|
487
077c5029aaee
fix text binding
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
486
diff
changeset
|
231 | if(!text->data1) { |
|
506
02ddf1044cbc
connect changed event to all textbuffer objects (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
505
diff
changeset
|
232 | 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
|
233 | text->datatype = UI_TEXT_TYPE_BUFFER; |
|
077c5029aaee
fix text binding
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
486
diff
changeset
|
234 | } |
|
486
a5f3abf8b9d1
refactor textarea to store a text buffer object in UiText values (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
235 | 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
|
236 | } |
|
a5f3abf8b9d1
refactor textarea to store a text buffer object in UiText values (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
237 | |
|
a5f3abf8b9d1
refactor textarea to store a text buffer object in UiText values (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
238 | 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
|
239 | 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
|
240 | 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
|
241 | } |
|
a5f3abf8b9d1
refactor textarea to store a text buffer object in UiText values (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
242 | |
| 5 | 243 | 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
|
244 | if(text->value.ptr) { |
|
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
245 | text->value.free(text->value.ptr); |
| 5 | 246 | } |
|
487
077c5029aaee
fix text binding
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
486
diff
changeset
|
247 | GtkTextBuffer *buf = text->data1; |
| 5 | 248 | GtkTextIter start; |
| 249 | GtkTextIter end; | |
| 250 | gtk_text_buffer_get_bounds(buf, &start, &end); | |
| 251 | 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
|
252 | text->value.ptr = g_strdup(str); |
|
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
253 | text->value.free = (ui_freefunc)g_free; |
| 5 | 254 | return str; |
| 255 | } | |
| 256 | ||
|
253
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
257 | void ui_textarea_set(UiText *text, const char *str) { |
|
487
077c5029aaee
fix text binding
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
486
diff
changeset
|
258 | 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
|
259 | if(text->value.ptr) { |
|
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
260 | text->value.free(text->value.ptr); |
|
12
fe94e0fb9ef3
added some text functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
9
diff
changeset
|
261 | } |
|
141
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
262 | text->value.ptr = NULL; |
|
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
263 | text->value.free = NULL; |
|
12
fe94e0fb9ef3
added some text functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
9
diff
changeset
|
264 | } |
|
fe94e0fb9ef3
added some text functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
9
diff
changeset
|
265 | |
|
fe94e0fb9ef3
added some text functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
9
diff
changeset
|
266 | 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
|
267 | if(text->value.ptr) { |
|
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
268 | text->value.free(text->value.ptr); |
| 5 | 269 | } |
|
487
077c5029aaee
fix text binding
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
486
diff
changeset
|
270 | GtkTextBuffer *buf = text->data1; |
|
12
fe94e0fb9ef3
added some text functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
9
diff
changeset
|
271 | GtkTextIter ib; |
|
fe94e0fb9ef3
added some text functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
9
diff
changeset
|
272 | GtkTextIter ie; |
|
487
077c5029aaee
fix text binding
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
486
diff
changeset
|
273 | 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
|
274 | 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
|
275 | 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
|
276 | text->value.ptr = g_strdup(str); |
|
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
277 | text->value.free = (ui_freefunc)g_free; |
|
12
fe94e0fb9ef3
added some text functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
9
diff
changeset
|
278 | return str; |
|
fe94e0fb9ef3
added some text functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
9
diff
changeset
|
279 | } |
|
fe94e0fb9ef3
added some text functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
9
diff
changeset
|
280 | |
|
fe94e0fb9ef3
added some text functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
9
diff
changeset
|
281 | void ui_textarea_insert(UiText *text, int pos, char *str) { |
|
fe94e0fb9ef3
added some text functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
9
diff
changeset
|
282 | GtkTextIter offset; |
|
487
077c5029aaee
fix text binding
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
486
diff
changeset
|
283 | 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
|
284 | 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
|
285 | if(text->value.ptr) { |
|
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
286 | text->value.free(text->value.ptr); |
|
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
287 | } |
|
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
288 | text->value.ptr = NULL; |
|
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
289 | text->value.free = NULL; |
| 5 | 290 | } |
| 291 | ||
|
90
2019fdbaadfd
persistent textarea cursor position
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
65
diff
changeset
|
292 | void ui_textarea_setposition(UiText *text, int pos) { |
|
2019fdbaadfd
persistent textarea cursor position
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
65
diff
changeset
|
293 | GtkTextIter iter; |
|
487
077c5029aaee
fix text binding
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
486
diff
changeset
|
294 | 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
|
295 | gtk_text_buffer_place_cursor(text->data1, &iter); |
|
90
2019fdbaadfd
persistent textarea cursor position
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
65
diff
changeset
|
296 | } |
|
2019fdbaadfd
persistent textarea cursor position
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
65
diff
changeset
|
297 | |
|
27
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
22
diff
changeset
|
298 | 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
|
299 | GtkTextIter begin; |
|
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
22
diff
changeset
|
300 | GtkTextIter end; |
|
487
077c5029aaee
fix text binding
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
486
diff
changeset
|
301 | 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
|
302 | text->pos = gtk_text_iter_get_offset(&begin); |
|
2019fdbaadfd
persistent textarea cursor position
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
65
diff
changeset
|
303 | 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
|
304 | } |
|
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
22
diff
changeset
|
305 | |
|
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
22
diff
changeset
|
306 | 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
|
307 | GtkTextIter b; |
|
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
22
diff
changeset
|
308 | GtkTextIter e; |
|
487
077c5029aaee
fix text binding
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
486
diff
changeset
|
309 | 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
|
310 | *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
|
311 | *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
|
312 | } |
|
77b09bb52ca0
added groups for toolbar items and copy & paste (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
22
diff
changeset
|
313 | |
|
29
c96169444d88
added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
314 | int ui_textarea_length(UiText *text) { |
|
487
077c5029aaee
fix text binding
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
486
diff
changeset
|
315 | GtkTextBuffer *buf = text->data1; |
|
29
c96169444d88
added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
316 | GtkTextIter start; |
|
c96169444d88
added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
317 | GtkTextIter end; |
|
c96169444d88
added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
318 | 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
|
319 | 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
|
320 | } |
|
c96169444d88
added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
27
diff
changeset
|
321 | |
|
33
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
322 | 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
|
323 | GtkTextBuffer *buf = text->data1; |
|
33
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
324 | GtkTextIter ib; |
|
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
325 | GtkTextIter ie; |
|
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
326 | 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
|
327 | 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
|
328 | 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
|
329 | } |
|
458831c574f4
added listview, sidebar and toolbar image button (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
330 | |
| 5 | 331 | void ui_textarea_realize_event(GtkWidget *widget, gpointer data) { |
| 332 | gtk_widget_grab_focus(widget); | |
| 333 | } | |
| 334 | ||
|
131
774b741984a2
detaching variables correctly
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
122
diff
changeset
|
335 | |
|
774b741984a2
detaching variables correctly
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
122
diff
changeset
|
336 | |
|
143
d499b29d7cb6
adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
141
diff
changeset
|
337 | void ui_textbuf_changed(GtkTextBuffer *textbuffer, UiTextArea *textarea) { |
|
906
edfdf9776da9
disable onchange events when detaching a document
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
809
diff
changeset
|
338 | if(!ui_onchange_events_is_enabled()) { |
|
edfdf9776da9
disable onchange events when detaching a document
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
809
diff
changeset
|
339 | return; |
|
edfdf9776da9
disable onchange events when detaching a document
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
809
diff
changeset
|
340 | } |
|
edfdf9776da9
disable onchange events when detaching a document
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
809
diff
changeset
|
341 | |
|
143
d499b29d7cb6
adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
141
diff
changeset
|
342 | UiText *value = textarea->var->value; |
|
379
958bae372271
implement ui_dialog_window (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
371
diff
changeset
|
343 | |
|
958bae372271
implement ui_dialog_window (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
371
diff
changeset
|
344 | UiEvent e; |
|
958bae372271
implement ui_dialog_window (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
371
diff
changeset
|
345 | e.obj = textarea->obj; |
|
958bae372271
implement ui_dialog_window (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
371
diff
changeset
|
346 | e.window = e.obj->window; |
|
958bae372271
implement ui_dialog_window (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
371
diff
changeset
|
347 | e.document = textarea->ctx->document; |
|
958bae372271
implement ui_dialog_window (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
371
diff
changeset
|
348 | e.eventdata = value; |
|
659
d6baaa93f7be
add UiEvent eventdatatype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
594
diff
changeset
|
349 | e.eventdatatype = UI_EVENT_DATA_TEXT_VALUE; |
|
379
958bae372271
implement ui_dialog_window (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
371
diff
changeset
|
350 | e.intval = 0; |
|
505
8002be179741
re-enable textarea onchange event (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
487
diff
changeset
|
351 | e.set = ui_get_setop(); |
|
379
958bae372271
implement ui_dialog_window (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
371
diff
changeset
|
352 | |
|
958bae372271
implement ui_dialog_window (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
371
diff
changeset
|
353 | if(textarea->onchange) { |
|
958bae372271
implement ui_dialog_window (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
371
diff
changeset
|
354 | textarea->onchange(&e, textarea->onchangedata); |
|
958bae372271
implement ui_dialog_window (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
371
diff
changeset
|
355 | } |
|
958bae372271
implement ui_dialog_window (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
371
diff
changeset
|
356 | |
|
143
d499b29d7cb6
adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
141
diff
changeset
|
357 | if(value->observers) { |
|
d499b29d7cb6
adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
141
diff
changeset
|
358 | 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
|
359 | } |
|
d499b29d7cb6
adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
141
diff
changeset
|
360 | } |
|
6
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
361 | |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
362 | // undo manager functions |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
363 | |
| 5 | 364 | void ui_textbuf_insert( |
| 365 | GtkTextBuffer *textbuffer, | |
| 366 | GtkTextIter *location, | |
| 367 | char *text, | |
|
6
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
368 | int length, |
| 5 | 369 | void *data) |
| 370 | { | |
|
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
371 | UiVar *var = data; |
|
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
372 | 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
|
373 | 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
|
374 | value->data2 = ui_create_undomgr(); |
|
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
375 | } |
|
486
a5f3abf8b9d1
refactor textarea to store a text buffer object in UiText values (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
376 | UiUndoMgr *mgr = value->data2; |
|
6
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
377 | if(!mgr->event) { |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
378 | return; |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
379 | } |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
380 | |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
381 | if(mgr->cur) { |
| 174 | 382 | UiTextBufOp *elm = mgr->cur->next; |
|
9
e70e855cea89
added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
383 | if(elm) { |
|
e70e855cea89
added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
384 | mgr->cur->next = NULL; |
| 174 | 385 | mgr->end = mgr->cur; |
|
9
e70e855cea89
added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
386 | while(elm) { |
|
e70e855cea89
added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
387 | elm->prev = NULL; |
| 174 | 388 | UiTextBufOp *next = elm->next; |
| 389 | ui_free_textbuf_op(elm); | |
|
9
e70e855cea89
added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
390 | elm = next; |
|
e70e855cea89
added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
391 | } |
|
6
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
392 | } |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
393 | |
| 174 | 394 | UiTextBufOp *last_op = mgr->cur; |
|
9
e70e855cea89
added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
395 | if( |
|
e70e855cea89
added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
396 | last_op->type == UI_TEXTBUF_INSERT && |
|
e70e855cea89
added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
397 | 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
|
398 | { |
|
6
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
399 | // append text to last op |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
400 | int ln = last_op->len; |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
401 | char *newtext = malloc(ln + length + 1); |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
402 | memcpy(newtext, last_op->text, ln); |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
403 | memcpy(newtext+ln, text, length); |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
404 | newtext[ln+length] = '\0'; |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
405 | |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
406 | last_op->text = newtext; |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
407 | last_op->len = ln + length; |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
408 | last_op->end += length; |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
409 | |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
410 | return; |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
411 | } |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
412 | } |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
413 | |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
414 | char *dpstr = malloc(length + 1); |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
415 | memcpy(dpstr, text, length); |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
416 | dpstr[length] = 0; |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
417 | |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
418 | UiTextBufOp *op = malloc(sizeof(UiTextBufOp)); |
| 174 | 419 | op->prev = NULL; |
| 420 | op->next = NULL; | |
|
6
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
421 | op->type = UI_TEXTBUF_INSERT; |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
422 | op->start = gtk_text_iter_get_offset(location); |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
423 | op->end = op->start+length; |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
424 | op->len = length; |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
425 | op->text = dpstr; |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
426 | |
| 174 | 427 | cx_linked_list_add( |
| 428 | (void**)&mgr->begin, | |
| 429 | (void**)&mgr->end, | |
| 430 | offsetof(UiTextBufOp, prev), | |
| 431 | offsetof(UiTextBufOp, next), | |
| 432 | op); | |
| 433 | ||
| 434 | mgr->cur = op; | |
| 5 | 435 | } |
| 436 | ||
| 437 | void ui_textbuf_delete( | |
| 438 | GtkTextBuffer *textbuffer, | |
| 439 | GtkTextIter *start, | |
| 440 | GtkTextIter *end, | |
| 441 | void *data) | |
| 442 | { | |
|
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
443 | UiVar *var = data; |
|
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
444 | 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
|
445 | 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
|
446 | value->data2 = ui_create_undomgr(); |
|
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
447 | } |
|
486
a5f3abf8b9d1
refactor textarea to store a text buffer object in UiText values (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
402
diff
changeset
|
448 | UiUndoMgr *mgr = value->data2; |
|
6
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
449 | if(!mgr->event) { |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
450 | return; |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
451 | } |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
452 | |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
453 | if(mgr->cur) { |
| 174 | 454 | UiTextBufOp *elm = mgr->cur->next; |
|
9
e70e855cea89
added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
455 | if(elm) { |
|
e70e855cea89
added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
456 | mgr->cur->next = NULL; |
| 174 | 457 | mgr->end = mgr->cur; |
|
9
e70e855cea89
added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
458 | while(elm) { |
|
e70e855cea89
added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
459 | elm->prev = NULL; |
| 174 | 460 | UiTextBufOp *next = elm->next; |
| 461 | ui_free_textbuf_op(elm); | |
|
9
e70e855cea89
added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
462 | elm = next; |
|
e70e855cea89
added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
463 | } |
|
6
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
464 | } |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
465 | } |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
466 | |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
467 | char *text = gtk_text_buffer_get_text(value->obj, start, end, FALSE); |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
468 | |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
469 | UiTextBufOp *op = malloc(sizeof(UiTextBufOp)); |
| 174 | 470 | op->prev = NULL; |
| 471 | op->next = NULL; | |
|
6
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
472 | op->type = UI_TEXTBUF_DELETE; |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
473 | op->start = gtk_text_iter_get_offset(start); |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
474 | op->end = gtk_text_iter_get_offset(end); |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
475 | op->len = op->end - op->start; |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
476 | |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
477 | char *dpstr = malloc(op->len + 1); |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
478 | memcpy(dpstr, text, op->len); |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
479 | dpstr[op->len] = 0; |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
480 | op->text = dpstr; |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
481 | |
| 174 | 482 | cx_linked_list_add( |
| 483 | (void**)&mgr->begin, | |
| 484 | (void**)&mgr->end, | |
| 485 | offsetof(UiTextBufOp, prev), | |
| 486 | offsetof(UiTextBufOp, next), | |
| 487 | op); | |
| 488 | ||
| 489 | mgr->cur = op; | |
|
6
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
490 | } |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
491 | |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
492 | UiUndoMgr* ui_create_undomgr() { |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
493 | UiUndoMgr *mgr = malloc(sizeof(UiUndoMgr)); |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
494 | mgr->begin = NULL; |
| 174 | 495 | mgr->end = NULL; |
|
6
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
496 | mgr->cur = NULL; |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
497 | mgr->length = 0; |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
498 | mgr->event = 1; |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
499 | return mgr; |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
500 | } |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
501 | |
| 174 | 502 | void ui_destroy_undomgr(UiUndoMgr *mgr) { |
| 503 | UiTextBufOp *op = mgr->begin; | |
| 504 | while(op) { | |
| 505 | UiTextBufOp *nextOp = op->next; | |
| 506 | if(op->text) { | |
| 507 | free(op->text); | |
| 508 | } | |
| 509 | free(op); | |
| 510 | op = nextOp; | |
| 511 | } | |
| 512 | free(mgr); | |
| 513 | } | |
| 514 | ||
|
6
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
515 | void ui_free_textbuf_op(UiTextBufOp *op) { |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
516 | if(op->text) { |
|
9
e70e855cea89
added undo and redo for motif
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
517 | free(op->text); |
|
6
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
518 | } |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
519 | free(op); |
| 5 | 520 | } |
|
6
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
521 | |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
522 | 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
|
523 | // return 1 if oldstr + newstr are one word |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
524 | |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
525 | int has_space = 0; |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
526 | for(int i=0;i<oldlen;i++) { |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
527 | if(oldstr[i] < 33) { |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
528 | has_space = 1; |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
529 | break; |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
530 | } |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
531 | } |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
532 | |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
533 | for(int i=0;i<newlen;i++) { |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
534 | if(has_space && newstr[i] > 32) { |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
535 | return 1; |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
536 | } |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
537 | } |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
538 | |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
539 | return 0; |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
540 | } |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
541 | |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
542 | void ui_text_undo(UiText *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
|
543 | UiUndoMgr *mgr = value->data2; |
|
6
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
544 | |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
545 | if(mgr->cur) { |
| 174 | 546 | UiTextBufOp *op = mgr->cur; |
|
6
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
547 | mgr->event = 0; |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
548 | switch(op->type) { |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
549 | case UI_TEXTBUF_INSERT: { |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
550 | GtkTextIter begin; |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
551 | GtkTextIter end; |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
552 | gtk_text_buffer_get_iter_at_offset(value->obj, &begin, op->start); |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
553 | gtk_text_buffer_get_iter_at_offset(value->obj, &end, op->end); |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
554 | gtk_text_buffer_delete(value->obj, &begin, &end); |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
555 | break; |
|
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 | case UI_TEXTBUF_DELETE: { |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
558 | GtkTextIter begin; |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
559 | GtkTextIter end; |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
560 | gtk_text_buffer_get_iter_at_offset(value->obj, &begin, op->start); |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
561 | gtk_text_buffer_get_iter_at_offset(value->obj, &end, op->end); |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
562 | gtk_text_buffer_insert(value->obj, &begin, op->text, op->len); |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
563 | break; |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
564 | } |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
565 | } |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
566 | mgr->event = 1; |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
567 | mgr->cur = mgr->cur->prev; |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
568 | } |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
569 | } |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
570 | |
|
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
571 | void ui_text_redo(UiText *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
|
572 | UiUndoMgr *mgr = value->data2; |
|
6
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
573 | |
| 174 | 574 | UiTextBufOp *elm = NULL; |
| 8 | 575 | if(mgr->cur) { |
| 576 | if(mgr->cur->next) { | |
| 577 | elm = mgr->cur->next; | |
| 578 | } | |
| 579 | } else if(mgr->begin) { | |
| 580 | elm = mgr->begin; | |
| 581 | } | |
| 582 | ||
| 583 | if(elm) { | |
| 174 | 584 | UiTextBufOp *op = elm; |
| 8 | 585 | mgr->event = 0; |
| 586 | switch(op->type) { | |
| 587 | case UI_TEXTBUF_INSERT: { | |
| 588 | GtkTextIter begin; | |
| 589 | GtkTextIter end; | |
| 590 | gtk_text_buffer_get_iter_at_offset(value->obj, &begin, op->start); | |
| 591 | gtk_text_buffer_get_iter_at_offset(value->obj, &end, op->end); | |
| 592 | gtk_text_buffer_insert(value->obj, &begin, op->text, op->len); | |
| 593 | break; | |
| 594 | } | |
| 595 | case UI_TEXTBUF_DELETE: { | |
| 596 | GtkTextIter begin; | |
| 597 | GtkTextIter end; | |
| 598 | gtk_text_buffer_get_iter_at_offset(value->obj, &begin, op->start); | |
| 599 | gtk_text_buffer_get_iter_at_offset(value->obj, &end, op->end); | |
| 600 | gtk_text_buffer_delete(value->obj, &begin, &end); | |
| 601 | break; | |
| 602 | } | |
| 603 | } | |
| 604 | mgr->event = 1; | |
| 605 | mgr->cur = elm; | |
| 606 | } | |
|
6
05a18c56d9ca
added undo for text
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
5
diff
changeset
|
607 | } |
|
65
4697592e24ba
added label, grid container, simple tabview and textfield (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
608 | |
|
4697592e24ba
added label, grid container, simple tabview and textfield (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
609 | |
|
267
79dd183dd4cb
port textfield to new API (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
253
diff
changeset
|
610 | |
|
79dd183dd4cb
port textfield to new API (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
253
diff
changeset
|
611 | |
|
594
fc854e0ab924
pass Args structs per pointer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
506
diff
changeset
|
612 | 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
|
613 | GtkWidget *textfield = gtk_entry_new(); |
|
594
fc854e0ab924
pass Args structs per pointer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
506
diff
changeset
|
614 | ui_set_name_and_style(textfield, args->name, args->style_class); |
|
fc854e0ab924
pass Args structs per pointer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
506
diff
changeset
|
615 | ui_set_widget_groups(obj->ctx, textfield, args->groups); |
|
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
616 | |
|
801
e096c441e874
refactor gtk container hierarchy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
788
diff
changeset
|
617 | 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
|
618 | |
|
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
619 | UiTextField *uitext = malloc(sizeof(UiTextField)); |
|
371
8c028965410a
implement textfield onchange event (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
356
diff
changeset
|
620 | uitext->obj = obj; |
|
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
621 | uitext->var = var; |
|
594
fc854e0ab924
pass Args structs per pointer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
506
diff
changeset
|
622 | uitext->onchange = args->onchange; |
|
fc854e0ab924
pass Args structs per pointer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
506
diff
changeset
|
623 | uitext->onchangedata = args->onchangedata; |
|
fc854e0ab924
pass Args structs per pointer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
506
diff
changeset
|
624 | uitext->onactivate = args->onactivate; |
|
fc854e0ab924
pass Args structs per pointer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
506
diff
changeset
|
625 | uitext->onactivatedata = args->onactivatedata; |
|
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
626 | |
|
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
627 | g_signal_connect( |
|
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
628 | textfield, |
|
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
629 | "destroy", |
|
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
630 | G_CALLBACK(ui_textfield_destroy), |
|
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
631 | uitext); |
|
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
632 | |
|
594
fc854e0ab924
pass Args structs per pointer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
506
diff
changeset
|
633 | if(args->width > 0) { |
|
788
27f126f6e361
implement spinbox width arg (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
680
diff
changeset
|
634 | // 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
|
635 | // 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
|
636 | // 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
|
637 | // be implemented on all platforms |
|
27f126f6e361
implement spinbox width arg (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
680
diff
changeset
|
638 | 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
|
639 | } |
|
121
1cc365c34125
added some special textfields (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
94
diff
changeset
|
640 | if(frameless) { |
|
1cc365c34125
added some special textfields (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
94
diff
changeset
|
641 | // TODO: gtk2legacy workaroud |
|
1cc365c34125
added some special textfields (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
94
diff
changeset
|
642 | 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
|
643 | } |
|
1cc365c34125
added some special textfields (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
94
diff
changeset
|
644 | if(password) { |
|
1cc365c34125
added some special textfields (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
94
diff
changeset
|
645 | gtk_entry_set_visibility(GTK_ENTRY(textfield), FALSE); |
|
1cc365c34125
added some special textfields (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
94
diff
changeset
|
646 | } |
|
94
d51e334c1439
added checkbox and labels with alignment (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
90
diff
changeset
|
647 | |
|
801
e096c441e874
refactor gtk container hierarchy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
788
diff
changeset
|
648 | UiContainerPrivate *ct = (UiContainerPrivate*)obj->container_end; |
|
e096c441e874
refactor gtk container hierarchy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
788
diff
changeset
|
649 | UiLayout layout = UI_ARGS2LAYOUT(args); |
|
e096c441e874
refactor gtk container hierarchy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
788
diff
changeset
|
650 | ct->add(ct, textfield, &layout); |
|
65
4697592e24ba
added label, grid container, simple tabview and textfield (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
651 | |
|
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
652 | if(var) { |
|
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
653 | UiString *value = var->value; |
|
141
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
654 | if(value->value.ptr) { |
|
298
c5e207d01ff2
port button, text to gtk4
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
655 | 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
|
656 | value->value.free(value->value.ptr); |
|
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
657 | value->value.ptr = NULL; |
|
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
658 | 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
|
659 | } |
|
4697592e24ba
added label, grid container, simple tabview and textfield (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
660 | |
|
4697592e24ba
added label, grid container, simple tabview and textfield (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
661 | 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
|
662 | value->set = ui_textfield_set; |
|
141
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
663 | value->value.ptr = NULL; |
|
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
664 | 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
|
665 | value->obj = GTK_ENTRY(textfield); |
|
371
8c028965410a
implement textfield onchange event (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
356
diff
changeset
|
666 | } |
|
8c028965410a
implement textfield onchange event (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
356
diff
changeset
|
667 | |
|
594
fc854e0ab924
pass Args structs per pointer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
506
diff
changeset
|
668 | if(args->onchange || var) { |
|
143
d499b29d7cb6
adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
141
diff
changeset
|
669 | g_signal_connect( |
|
d499b29d7cb6
adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
141
diff
changeset
|
670 | textfield, |
|
d499b29d7cb6
adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
141
diff
changeset
|
671 | "changed", |
|
d499b29d7cb6
adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
141
diff
changeset
|
672 | G_CALLBACK(ui_textfield_changed), |
|
d499b29d7cb6
adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
141
diff
changeset
|
673 | uitext); |
|
65
4697592e24ba
added label, grid container, simple tabview and textfield (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
674 | } |
|
4697592e24ba
added label, grid container, simple tabview and textfield (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
675 | |
|
594
fc854e0ab924
pass Args structs per pointer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
506
diff
changeset
|
676 | if(args->onactivate) { |
|
402
96a055be7f0b
add textfield onactivate event (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
397
diff
changeset
|
677 | g_signal_connect( |
|
96a055be7f0b
add textfield onactivate event (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
397
diff
changeset
|
678 | textfield, |
|
96a055be7f0b
add textfield onactivate event (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
397
diff
changeset
|
679 | "activate", |
|
96a055be7f0b
add textfield onactivate event (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
397
diff
changeset
|
680 | G_CALLBACK(ui_textfield_activate), |
|
96a055be7f0b
add textfield onactivate event (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
397
diff
changeset
|
681 | uitext); |
|
96a055be7f0b
add textfield onactivate event (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
397
diff
changeset
|
682 | } |
|
96a055be7f0b
add textfield onactivate event (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
397
diff
changeset
|
683 | |
|
65
4697592e24ba
added label, grid container, simple tabview and textfield (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
684 | return textfield; |
|
4697592e24ba
added label, grid container, simple tabview and textfield (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
685 | } |
|
4697592e24ba
added label, grid container, simple tabview and textfield (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
686 | |
|
594
fc854e0ab924
pass Args structs per pointer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
506
diff
changeset
|
687 | 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
|
688 | 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
|
689 | } |
|
4697592e24ba
added label, grid container, simple tabview and textfield (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
690 | |
|
594
fc854e0ab924
pass Args structs per pointer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
506
diff
changeset
|
691 | 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
|
692 | return create_textfield(obj, TRUE, FALSE, args); |
|
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
693 | } |
|
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
694 | |
|
594
fc854e0ab924
pass Args structs per pointer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
506
diff
changeset
|
695 | 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
|
696 | return create_textfield(obj, FALSE, TRUE, args); |
|
79dd183dd4cb
port textfield to new API (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
253
diff
changeset
|
697 | } |
|
79dd183dd4cb
port textfield to new API (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
253
diff
changeset
|
698 | |
|
79dd183dd4cb
port textfield to new API (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
253
diff
changeset
|
699 | |
|
140
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
700 | void ui_textfield_destroy(GtkWidget *object, UiTextField *textfield) { |
|
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
701 | free(textfield); |
|
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
702 | } |
|
c03c338a7dcf
refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
131
diff
changeset
|
703 | |
|
143
d499b29d7cb6
adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
141
diff
changeset
|
704 | 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
|
705 | if(!ui_onchange_events_is_enabled()) { |
|
edfdf9776da9
disable onchange events when detaching a document
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
809
diff
changeset
|
706 | return; |
|
edfdf9776da9
disable onchange events when detaching a document
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
809
diff
changeset
|
707 | } |
|
edfdf9776da9
disable onchange events when detaching a document
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
809
diff
changeset
|
708 | |
|
143
d499b29d7cb6
adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
141
diff
changeset
|
709 | UiString *value = textfield->var->value; |
|
371
8c028965410a
implement textfield onchange event (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
356
diff
changeset
|
710 | |
|
8c028965410a
implement textfield onchange event (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
356
diff
changeset
|
711 | UiEvent e; |
|
8c028965410a
implement textfield onchange event (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
356
diff
changeset
|
712 | e.obj = textfield->obj; |
|
8c028965410a
implement textfield onchange event (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
356
diff
changeset
|
713 | e.window = e.obj->window; |
|
8c028965410a
implement textfield onchange event (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
356
diff
changeset
|
714 | e.document = textfield->obj->ctx->document; |
|
8c028965410a
implement textfield onchange event (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
356
diff
changeset
|
715 | e.eventdata = value; |
|
659
d6baaa93f7be
add UiEvent eventdatatype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
594
diff
changeset
|
716 | e.eventdatatype = UI_EVENT_DATA_TEXT_VALUE; |
|
371
8c028965410a
implement textfield onchange event (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
356
diff
changeset
|
717 | e.intval = 0; |
|
505
8002be179741
re-enable textarea onchange event (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
487
diff
changeset
|
718 | e.set = ui_get_setop(); |
|
371
8c028965410a
implement textfield onchange event (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
356
diff
changeset
|
719 | |
|
8c028965410a
implement textfield onchange event (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
356
diff
changeset
|
720 | if(textfield->onchange) { |
|
8c028965410a
implement textfield onchange event (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
356
diff
changeset
|
721 | textfield->onchange(&e, textfield->onchangedata); |
|
8c028965410a
implement textfield onchange event (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
356
diff
changeset
|
722 | } |
|
8c028965410a
implement textfield onchange event (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
356
diff
changeset
|
723 | |
|
8c028965410a
implement textfield onchange event (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
356
diff
changeset
|
724 | if(textfield->var) { |
|
143
d499b29d7cb6
adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
141
diff
changeset
|
725 | 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
|
726 | } |
|
d499b29d7cb6
adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
141
diff
changeset
|
727 | } |
|
d499b29d7cb6
adds observer support for textarea and textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
141
diff
changeset
|
728 | |
|
402
96a055be7f0b
add textfield onactivate event (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
397
diff
changeset
|
729 | void ui_textfield_activate(GtkEntry* self, UiTextField *textfield) { |
|
96a055be7f0b
add textfield onactivate event (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
397
diff
changeset
|
730 | if(textfield->onactivate) { |
|
96a055be7f0b
add textfield onactivate event (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
397
diff
changeset
|
731 | UiEvent e; |
|
96a055be7f0b
add textfield onactivate event (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
397
diff
changeset
|
732 | e.obj = textfield->obj; |
|
96a055be7f0b
add textfield onactivate event (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
397
diff
changeset
|
733 | e.window = e.obj->window; |
|
96a055be7f0b
add textfield onactivate event (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
397
diff
changeset
|
734 | e.document = textfield->obj->ctx->document; |
|
96a055be7f0b
add textfield onactivate event (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
397
diff
changeset
|
735 | e.eventdata = NULL; |
|
659
d6baaa93f7be
add UiEvent eventdatatype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
594
diff
changeset
|
736 | e.eventdatatype = 0; |
|
402
96a055be7f0b
add textfield onactivate event (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
397
diff
changeset
|
737 | e.intval = 0; |
|
505
8002be179741
re-enable textarea onchange event (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
487
diff
changeset
|
738 | e.set = ui_get_setop(); |
|
402
96a055be7f0b
add textfield onactivate event (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
397
diff
changeset
|
739 | textfield->onactivate(&e, textfield->onactivatedata); |
|
96a055be7f0b
add textfield onactivate event (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
397
diff
changeset
|
740 | } |
|
96a055be7f0b
add textfield onactivate event (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
397
diff
changeset
|
741 | } |
|
121
1cc365c34125
added some special textfields (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
94
diff
changeset
|
742 | |
|
65
4697592e24ba
added label, grid container, simple tabview and textfield (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
743 | 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
|
744 | if(str->value.ptr) { |
|
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
745 | 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
|
746 | } |
|
298
c5e207d01ff2
port button, text to gtk4
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
747 | 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
|
748 | 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
|
749 | 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
|
750 | } |
|
4697592e24ba
added label, grid container, simple tabview and textfield (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
751 | |
|
253
087cc9216f28
initial newapi GTK port
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
752 | 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
|
753 | 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
|
754 | if(str->value.ptr) { |
|
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
755 | str->value.free(str->value.ptr); |
|
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
756 | str->value.ptr = NULL; |
|
cc2170ea05ad
improves doc detach and string value handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
757 | 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
|
758 | } |
|
4697592e24ba
added label, grid container, simple tabview and textfield (Gtk)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
759 | } |
|
282
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
760 | |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
761 | // ----------------------- path textfield ----------------------- |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
762 | |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
763 | // TODO: move to common |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
764 | 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
|
765 | cxstring *pathelms; |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
766 | size_t nelm = cx_strsplit_a(cxDefaultAllocator, cx_strn(full_path, len), CX_STR("/"), 4096, &pathelms); |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
767 | |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
768 | if (nelm == 0) { |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
769 | *ret_nelm = 0; |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
770 | return NULL; |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
771 | } |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
772 | |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
773 | UiPathElm* elms = (UiPathElm*)calloc(nelm, sizeof(UiPathElm)); |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
774 | size_t n = nelm; |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
775 | int j = 0; |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
776 | for (int i = 0; i < nelm; i++) { |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
777 | cxstring c = pathelms[i]; |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
778 | if (c.length == 0) { |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
779 | if (i == 0) { |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
780 | c.length = 1; |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
781 | } |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
782 | else { |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
783 | n--; |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
784 | continue; |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
785 | } |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
786 | } |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
787 | |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
788 | cxmutstr m = cx_strdup(c); |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
789 | elms[j].name = m.ptr; |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
790 | elms[j].name_len = m.length; |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
791 | |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
792 | 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
|
793 | 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
|
794 | elms[j].path = elm_path.ptr; |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
795 | elms[j].path_len = elm_path.length; |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
796 | |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
797 | j++; |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
798 | } |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
799 | *ret_nelm = n; |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
800 | |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
801 | return elms; |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
802 | } |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
803 | |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
804 | 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
|
805 | for(int i=0;i<nelm;i++) { |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
806 | free(elms[i].name); |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
807 | free(elms[i].path); |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
808 | } |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
809 | free(elms); |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
810 | } |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
811 | |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
812 | 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
|
813 | g_object_unref(pathtf->entry); |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
814 | free(pathtf); |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
815 | } |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
816 | |
|
323
38cb8e3992e8
improve pathbar visuals (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
314
diff
changeset
|
817 | void ui_path_button_clicked(GtkWidget *widget, UiEventDataExt *event) { |
|
38cb8e3992e8
improve pathbar visuals (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
314
diff
changeset
|
818 | UiPathTextField *pathtf = event->customdata1; |
|
38cb8e3992e8
improve pathbar visuals (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
314
diff
changeset
|
819 | for(int i=0;i<event->value1;i++) { |
|
38cb8e3992e8
improve pathbar visuals (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
314
diff
changeset
|
820 | if(i <= event->value0) { |
| 326 | 821 | 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
|
822 | } else { |
| 326 | 823 | 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
|
824 | } |
|
38cb8e3992e8
improve pathbar visuals (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
314
diff
changeset
|
825 | } |
|
38cb8e3992e8
improve pathbar visuals (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
314
diff
changeset
|
826 | |
|
38cb8e3992e8
improve pathbar visuals (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
314
diff
changeset
|
827 | UiPathElm *elm = event->customdata0; |
|
310
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
828 | 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
|
829 | UiEvent evt; |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
830 | evt.obj = event->obj; |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
831 | evt.window = evt.obj->window; |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
832 | evt.document = evt.obj->ctx->document; |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
833 | evt.eventdata = elm->path; |
|
659
d6baaa93f7be
add UiEvent eventdatatype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
594
diff
changeset
|
834 | evt.eventdatatype = UI_EVENT_DATA_STRING; |
|
323
38cb8e3992e8
improve pathbar visuals (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
314
diff
changeset
|
835 | evt.intval = event->value0; |
|
506
02ddf1044cbc
connect changed event to all textbuffer objects (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
505
diff
changeset
|
836 | evt.set = ui_get_setop(); |
|
310
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
837 | event->callback(&evt, event->userdata); |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
838 | free(path.ptr); |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
839 | } |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
840 | |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
841 | int ui_pathtextfield_update(UiPathTextField* pathtf, const char *full_path) { |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
842 | size_t full_path_len = strlen(full_path); |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
843 | if(full_path_len == 0) { |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
844 | return 1; |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
845 | } |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
846 | |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
847 | size_t nelm = 0; |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
848 | 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
|
849 | if (!path_elm) { |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
850 | return 1; |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
851 | } |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
852 | |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
853 | free(pathtf->current_path); |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
854 | pathtf->current_path = strdup(full_path); |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
855 | |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
856 | 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
|
857 | free(pathtf->current_path_buttons); |
|
38cb8e3992e8
improve pathbar visuals (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
314
diff
changeset
|
858 | pathtf->current_path_buttons = calloc(nelm, sizeof(GtkWidget*)); |
|
310
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
859 | pathtf->current_pathelms = path_elm; |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
860 | pathtf->current_nelm = nelm; |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
861 | |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
862 | return ui_pathtextfield_update_widget(pathtf); |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
863 | } |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
864 | |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
865 | 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
|
866 | 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
|
867 | 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
|
868 | pathtf->current_path_buttons[i] = button; |
|
310
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
869 | free(name.ptr); |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
870 | |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
871 | if(pathtf->onactivate) { |
|
323
38cb8e3992e8
improve pathbar visuals (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
314
diff
changeset
|
872 | UiEventDataExt *eventdata = malloc(sizeof(UiEventDataExt)); |
|
38cb8e3992e8
improve pathbar visuals (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
314
diff
changeset
|
873 | memset(eventdata, 0, sizeof(UiEventDataExt)); |
|
310
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
874 | eventdata->callback = pathtf->onactivate; |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
875 | eventdata->userdata = pathtf->onactivatedata; |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
876 | eventdata->obj = pathtf->obj; |
|
323
38cb8e3992e8
improve pathbar visuals (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
314
diff
changeset
|
877 | eventdata->customdata0 = elm; |
|
38cb8e3992e8
improve pathbar visuals (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
314
diff
changeset
|
878 | eventdata->customdata1 = pathtf; |
|
38cb8e3992e8
improve pathbar visuals (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
314
diff
changeset
|
879 | eventdata->value0 = i; |
|
38cb8e3992e8
improve pathbar visuals (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
314
diff
changeset
|
880 | eventdata->value1 = pathtf->current_nelm; |
|
310
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
881 | |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
882 | g_signal_connect( |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
883 | button, |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
884 | "clicked", |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
885 | G_CALLBACK(ui_path_button_clicked), |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
886 | eventdata); |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
887 | |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
888 | g_signal_connect( |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
889 | button, |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
890 | "destroy", |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
891 | G_CALLBACK(ui_destroy_userdata), |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
892 | eventdata); |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
893 | } |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
894 | |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
895 | return button; |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
896 | } |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
897 | |
|
282
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
898 | 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
|
899 | const gchar *text = ENTRY_GET_TEXT(pathtf->entry); |
|
282
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
900 | if(strlen(text) == 0) { |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
901 | return; |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
902 | } |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
903 | |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
904 | UiObject *obj = pathtf->obj; |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
905 | |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
906 | if(ui_pathtextfield_update(pathtf, text)) { |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
907 | return; |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
908 | } |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
909 | |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
910 | if(pathtf->onactivate) { |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
911 | UiEvent evt; |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
912 | evt.obj = obj; |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
913 | evt.window = obj->window; |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
914 | evt.document = obj->ctx->document; |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
915 | evt.eventdata = (char*)text; |
|
659
d6baaa93f7be
add UiEvent eventdatatype
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
594
diff
changeset
|
916 | evt.eventdatatype = UI_EVENT_DATA_STRING; |
|
282
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
917 | evt.intval = -1; |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
918 | pathtf->onactivate(&evt, pathtf->onactivatedata); |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
919 | } |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
920 | } |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
921 | |
|
310
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
922 | #if GTK_MAJOR_VERSION >= 4 |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
923 | |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
924 | static void pathbar_show_hbox(GtkWidget *widget, UiPathTextField *pathtf) { |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
925 | if(pathtf->current_path) { |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
926 | 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
|
927 | ENTRY_SET_TEXT(pathtf->entry, pathtf->current_path); |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
928 | } |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
929 | } |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
930 | |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
931 | static gboolean ui_path_textfield_key_controller( |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
932 | GtkEventControllerKey* self, |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
933 | guint keyval, |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
934 | guint keycode, |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
935 | GdkModifierType state, |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
936 | UiPathTextField *pathtf) |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
937 | { |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
938 | if(keyval == GDK_KEY_Escape) { |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
939 | pathbar_show_hbox(NULL, pathtf); |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
940 | } |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
941 | return FALSE; |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
942 | } |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
943 | |
|
594
fc854e0ab924
pass Args structs per pointer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
506
diff
changeset
|
944 | UIWIDGET ui_path_textfield_create(UiObject* obj, UiPathTextFieldArgs *args) { |
|
310
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
945 | UiPathTextField *pathtf = malloc(sizeof(UiPathTextField)); |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
946 | memset(pathtf, 0, sizeof(UiPathTextField)); |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
947 | pathtf->obj = obj; |
|
594
fc854e0ab924
pass Args structs per pointer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
506
diff
changeset
|
948 | pathtf->getpathelm = args->getpathelm; |
|
fc854e0ab924
pass Args structs per pointer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
506
diff
changeset
|
949 | pathtf->getpathelmdata = args->getpathelmdata; |
|
fc854e0ab924
pass Args structs per pointer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
506
diff
changeset
|
950 | pathtf->onactivate = args->onactivate; |
|
fc854e0ab924
pass Args structs per pointer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
506
diff
changeset
|
951 | pathtf->onactivatedata = args->onactivatedata; |
|
fc854e0ab924
pass Args structs per pointer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
506
diff
changeset
|
952 | pathtf->ondragcomplete = args->ondragcomplete; |
|
fc854e0ab924
pass Args structs per pointer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
506
diff
changeset
|
953 | pathtf->ondragcompletedata = args->ondragcompletedata; |
|
fc854e0ab924
pass Args structs per pointer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
506
diff
changeset
|
954 | pathtf->ondragstart = args->ondragstart; |
|
fc854e0ab924
pass Args structs per pointer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
506
diff
changeset
|
955 | pathtf->ondragstartdata = args->ondragstartdata; |
|
fc854e0ab924
pass Args structs per pointer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
506
diff
changeset
|
956 | pathtf->ondrop = args->ondrop; |
|
fc854e0ab924
pass Args structs per pointer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
506
diff
changeset
|
957 | pathtf->ondropdata = args->ondropsdata; |
|
310
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
958 | |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
959 | if(!pathtf->getpathelm) { |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
960 | pathtf->getpathelm = default_pathelm_func; |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
961 | pathtf->getpathelmdata = NULL; |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
962 | } |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
963 | |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
964 | pathtf->stack = gtk_stack_new(); |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
965 | gtk_widget_set_name(pathtf->stack, "path-textfield-box"); |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
966 | |
|
801
e096c441e874
refactor gtk container hierarchy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
788
diff
changeset
|
967 | UiContainerPrivate *ct = (UiContainerPrivate*)obj->container_end; |
|
e096c441e874
refactor gtk container hierarchy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
788
diff
changeset
|
968 | UiLayout layout = UI_ARGS2LAYOUT(args); |
|
e096c441e874
refactor gtk container hierarchy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
788
diff
changeset
|
969 | ct->add(ct, pathtf->stack, &layout); |
|
310
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
970 | |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
971 | pathtf->entry_box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0); |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
972 | pathtf->entry = gtk_entry_new(); |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
973 | gtk_box_append(GTK_BOX(pathtf->entry_box), pathtf->entry); |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
974 | gtk_widget_set_hexpand(pathtf->entry, TRUE); |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
975 | |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
976 | 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
|
977 | gtk_widget_add_css_class(cancel_button, "flat"); |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
978 | gtk_widget_add_css_class(cancel_button, "pathbar-extra-button"); |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
979 | gtk_box_append(GTK_BOX(pathtf->entry_box), cancel_button); |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
980 | g_signal_connect( |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
981 | cancel_button, |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
982 | "clicked", |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
983 | G_CALLBACK(pathbar_show_hbox), |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
984 | pathtf); |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
985 | |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
986 | 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
|
987 | 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
|
988 | g_signal_connect( |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
989 | pathtf->entry, |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
990 | "activate", |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
991 | G_CALLBACK(ui_path_textfield_activate), |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
992 | pathtf); |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
993 | |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
994 | GtkEventController *entry_cancel = gtk_event_controller_key_new(); |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
995 | gtk_widget_add_controller(pathtf->entry, entry_cancel); |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
996 | 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
|
997 | |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
998 | 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
|
999 | |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1000 | |
|
801
e096c441e874
refactor gtk container hierarchy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
788
diff
changeset
|
1001 | 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
|
1002 | if (var) { |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1003 | UiString* value = (UiString*)var->value; |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1004 | value->obj = pathtf; |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1005 | value->get = ui_path_textfield_get; |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1006 | value->set = ui_path_textfield_set; |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1007 | |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1008 | if(value->value.ptr) { |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1009 | char *str = strdup(value->value.ptr); |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1010 | ui_string_set(value, str); |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1011 | free(str); |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1012 | } |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1013 | } |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1014 | |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1015 | return pathtf->stack; |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1016 | } |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1017 | |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1018 | static void pathbar_pressed( |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1019 | GtkGestureClick* self, |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1020 | gint n_press, |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1021 | gdouble x, |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1022 | gdouble y, |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1023 | UiPathTextField *pathtf) |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1024 | { |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1025 | 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
|
1026 | gtk_widget_grab_focus(pathtf->entry); |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1027 | } |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1028 | |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1029 | int ui_pathtextfield_update_widget(UiPathTextField* pathtf) { |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1030 | // recreate button hbox |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1031 | if(pathtf->hbox) { |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1032 | gtk_stack_remove(GTK_STACK(pathtf->stack), pathtf->hbox); |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1033 | } |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1034 | pathtf->hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0); |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1035 | gtk_box_set_homogeneous(GTK_BOX(pathtf->hbox), FALSE); |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1036 | gtk_stack_add_child(GTK_STACK(pathtf->stack), pathtf->hbox); |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1037 | gtk_widget_set_name(pathtf->hbox, "pathbar"); |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1038 | |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1039 | // add buttons for path elements |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1040 | for (int i=0;i<pathtf->current_nelm;i++) { |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1041 | UiPathElm *elm = &pathtf->current_pathelms[i]; |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1042 | |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1043 | GtkWidget *button = ui_path_elm_button(pathtf, elm, i); |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1044 | gtk_widget_add_css_class(button, "flat"); |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1045 | |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1046 | gtk_box_append(GTK_BOX(pathtf->hbox), button); |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1047 | |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1048 | 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
|
1049 | GtkWidget *path_separator = gtk_label_new("/"); |
|
38cb8e3992e8
improve pathbar visuals (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
314
diff
changeset
|
1050 | 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
|
1051 | gtk_box_append(GTK_BOX(pathtf->hbox), path_separator); |
|
310
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1052 | } |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1053 | } |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1054 | 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
|
1055 | |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1056 | // create a widget for receiving button press events |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1057 | GtkWidget *event_area = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0); |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1058 | GtkGesture *handler = gtk_gesture_click_new(); |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1059 | gtk_widget_add_controller(event_area, GTK_EVENT_CONTROLLER(handler)); |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1060 | g_signal_connect( |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1061 | handler, |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1062 | "pressed", |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1063 | G_CALLBACK(pathbar_pressed), |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1064 | pathtf); |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1065 | gtk_widget_set_hexpand(event_area, TRUE); |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1066 | gtk_widget_set_vexpand(event_area, TRUE); |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1067 | gtk_box_append(GTK_BOX(pathtf->hbox), event_area); |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1068 | |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1069 | return 0; |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1070 | } |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1071 | |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1072 | #else |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1073 | |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1074 | 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
|
1075 | 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
|
1076 | gtk_container_remove(GTK_CONTAINER(pathtf->hbox), pathtf->buttonbox); |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1077 | pathtf->buttonbox = NULL; |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1078 | |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1079 | gtk_widget_show(pathtf->entry); |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1080 | gtk_widget_grab_focus(pathtf->entry); |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1081 | |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1082 | return TRUE; |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1083 | } |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1084 | |
|
282
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1085 | 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
|
1086 | if (event->keyval == GDK_KEY_Escape) { |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1087 | // reset GtkEntry value |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1088 | 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
|
1089 | 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
|
1090 | ui_pathtextfield_update(pathtf, text); |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1091 | return TRUE; |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1092 | } |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1093 | return FALSE; |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1094 | } |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1095 | |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1096 | static GtkWidget* create_path_button_box() { |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1097 | GtkWidget *bb = gtk_button_box_new(GTK_ORIENTATION_HORIZONTAL); |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1098 | 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
|
1099 | gtk_box_set_homogeneous(GTK_BOX(bb), FALSE); |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1100 | gtk_box_set_spacing(GTK_BOX(bb), 0); |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1101 | return bb; |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1102 | } |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1103 | |
|
594
fc854e0ab924
pass Args structs per pointer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
506
diff
changeset
|
1104 | 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
|
1105 | UiPathTextField *pathtf = malloc(sizeof(UiPathTextField)); |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1106 | memset(pathtf, 0, sizeof(UiPathTextField)); |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1107 | pathtf->obj = obj; |
|
594
fc854e0ab924
pass Args structs per pointer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
506
diff
changeset
|
1108 | pathtf->getpathelm = args->getpathelm; |
|
fc854e0ab924
pass Args structs per pointer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
506
diff
changeset
|
1109 | pathtf->getpathelmdata = args->getpathelmdata; |
|
fc854e0ab924
pass Args structs per pointer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
506
diff
changeset
|
1110 | pathtf->onactivate = args->onactivate; |
|
fc854e0ab924
pass Args structs per pointer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
506
diff
changeset
|
1111 | pathtf->onactivatedata = args->onactivatedata; |
|
fc854e0ab924
pass Args structs per pointer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
506
diff
changeset
|
1112 | pathtf->ondragcomplete = args->ondragcomplete; |
|
fc854e0ab924
pass Args structs per pointer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
506
diff
changeset
|
1113 | pathtf->ondragcompletedata = args->ondragcompletedata; |
|
fc854e0ab924
pass Args structs per pointer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
506
diff
changeset
|
1114 | pathtf->ondragstart = args->ondragstart; |
|
fc854e0ab924
pass Args structs per pointer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
506
diff
changeset
|
1115 | pathtf->ondragstartdata = args->ondragstartdata; |
|
fc854e0ab924
pass Args structs per pointer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
506
diff
changeset
|
1116 | pathtf->ondrop = args->ondrop; |
|
fc854e0ab924
pass Args structs per pointer (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
506
diff
changeset
|
1117 | pathtf->ondropdata = args->ondropsdata; |
|
282
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1118 | |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1119 | if(!pathtf->getpathelm) { |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1120 | pathtf->getpathelm = default_pathelm_func; |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1121 | pathtf->getpathelmdata = NULL; |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1122 | } |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1123 | |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1124 | // 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
|
1125 | // 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
|
1126 | GtkWidget *eventbox = gtk_event_box_new(); |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1127 | g_signal_connect( |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1128 | eventbox, |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1129 | "button-press-event", |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1130 | G_CALLBACK(path_textfield_btn_pressed), |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1131 | pathtf); |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1132 | g_signal_connect( |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1133 | eventbox, |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1134 | "destroy", |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1135 | G_CALLBACK(ui_path_textfield_destroy), |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1136 | pathtf); |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1137 | |
|
801
e096c441e874
refactor gtk container hierarchy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
788
diff
changeset
|
1138 | UiContainerPrivate *ct = (UiContainerPrivate*)obj->container_end; |
|
e096c441e874
refactor gtk container hierarchy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
788
diff
changeset
|
1139 | UiLayout layout = UI_ARGS2LAYOUT(args); |
|
e096c441e874
refactor gtk container hierarchy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
788
diff
changeset
|
1140 | ct->add(ct, eventbox, &layout); |
|
282
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1141 | |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1142 | // hbox as parent for the GtkEntry and GtkButtonBox |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1143 | GtkWidget *hbox = ui_gtk_hbox_new(0); |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1144 | pathtf->hbox = hbox; |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1145 | gtk_container_add(GTK_CONTAINER(eventbox), hbox); |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1146 | gtk_widget_set_name(hbox, "path-textfield-box"); |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1147 | |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1148 | // 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
|
1149 | pathtf->entry = gtk_entry_new(); |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1150 | g_object_ref(G_OBJECT(pathtf->entry)); |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1151 | 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
|
1152 | |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1153 | g_signal_connect( |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1154 | pathtf->entry, |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1155 | "activate", |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1156 | G_CALLBACK(ui_path_textfield_activate), |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1157 | pathtf); |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1158 | g_signal_connect( |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1159 | pathtf->entry, |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1160 | "key-press-event", |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1161 | G_CALLBACK(ui_path_textfield_key_press), |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1162 | pathtf); |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1163 | |
|
801
e096c441e874
refactor gtk container hierarchy
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
788
diff
changeset
|
1164 | 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
|
1165 | if (var) { |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1166 | UiString* value = (UiString*)var->value; |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1167 | value->obj = pathtf; |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1168 | value->get = ui_path_textfield_get; |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1169 | value->set = ui_path_textfield_set; |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1170 | |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1171 | if(value->value.ptr) { |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1172 | char *str = strdup(value->value.ptr); |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1173 | ui_string_set(value, str); |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1174 | free(str); |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1175 | } |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1176 | } |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1177 | |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1178 | return hbox; |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1179 | } |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1180 | |
|
310
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1181 | int ui_pathtextfield_update_widget(UiPathTextField* pathtf) { |
|
282
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1182 | GtkWidget *buttonbox = create_path_button_box(); |
|
289
6048b20bd46f
fix path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
282
diff
changeset
|
1183 | |
|
6048b20bd46f
fix path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
282
diff
changeset
|
1184 | // switch from entry to buttonbox or remove current buttonbox |
|
6048b20bd46f
fix path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
282
diff
changeset
|
1185 | if(pathtf->buttonbox) { |
|
6048b20bd46f
fix path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
282
diff
changeset
|
1186 | gtk_container_remove(GTK_CONTAINER(pathtf->hbox), pathtf->buttonbox); |
|
6048b20bd46f
fix path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
282
diff
changeset
|
1187 | } else { |
|
6048b20bd46f
fix path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
282
diff
changeset
|
1188 | gtk_container_remove(GTK_CONTAINER(pathtf->hbox), pathtf->entry); |
|
6048b20bd46f
fix path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
282
diff
changeset
|
1189 | } |
|
6048b20bd46f
fix path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
282
diff
changeset
|
1190 | 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
|
1191 | pathtf->buttonbox = buttonbox; |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1192 | |
|
310
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1193 | for (int i=0;i<pathtf->current_nelm;i++) { |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1194 | UiPathElm *elm = &pathtf->current_pathelms[i]; |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1195 | 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
|
1196 | 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
|
1197 | } |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1198 | |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1199 | gtk_widget_show_all(buttonbox); |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1200 | |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1201 | return 0; |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1202 | } |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1203 | |
|
310
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1204 | #endif |
|
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1205 | |
|
282
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1206 | char* ui_path_textfield_get(UiString *str) { |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1207 | if(str->value.ptr) { |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1208 | str->value.free(str->value.ptr); |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1209 | } |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1210 | UiPathTextField *tf = str->obj; |
|
310
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1211 | 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
|
1212 | str->value.free = (ui_freefunc)g_free; |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1213 | return str->value.ptr; |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1214 | } |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1215 | |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1216 | 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
|
1217 | UiPathTextField *tf = str->obj; |
|
310
4918f9132552
add gtk4 pathbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
298
diff
changeset
|
1218 | ENTRY_SET_TEXT(tf->entry, value); |
|
282
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1219 | ui_pathtextfield_update(tf, value); |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1220 | if(str->value.ptr) { |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1221 | str->value.free(str->value.ptr); |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1222 | str->value.ptr = NULL; |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1223 | str->value.free = NULL; |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1224 | } |
|
3a77b9048664
add path textfield (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
267
diff
changeset
|
1225 | } |