summaryrefslogtreecommitdiff
path: root/src/ui
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2021-11-21 18:28:08 +0200
committerJaakko Keränen <jaakko.keranen@iki.fi>2021-11-21 18:28:08 +0200
commit58955605b89a47f2a438ec1eca77bef91c4af032 (patch)
treea7fc31e31c134023843ebdf0e6ef465e9b639941 /src/ui
parent9908cc3ec9c6697070f23a9da52e25e95830fb01 (diff)
parent33fe87051f3c4e293f47618adced141b1183b324 (diff)
Merge branch 'dev' into work/v1.9
# Conflicts: # CMakeLists.txt # res/about/version.gmi
Diffstat (limited to 'src/ui')
-rw-r--r--src/ui/banner.c18
-rw-r--r--src/ui/uploadwidget.c45
-rw-r--r--src/ui/util.c92
-rw-r--r--src/ui/util.h1
4 files changed, 104 insertions, 52 deletions
diff --git a/src/ui/banner.c b/src/ui/banner.c
index 0ffb1d9f..7ec189a4 100644
--- a/src/ui/banner.c
+++ b/src/ui/banner.c
@@ -257,8 +257,26 @@ static size_t itemAtCoord_Banner_(const iBanner *d, iInt2 coord) {
257 return iInvalidPos; 257 return iInvalidPos;
258} 258}
259 259
260static iBool isInside_Banner_(const iBanner *d, const SDL_Event *ev) {
261 if (ev->type == SDL_MOUSEMOTION || ev->type == SDL_MOUSEBUTTONDOWN ||
262 ev->type == SDL_MOUSEBUTTONDOWN) {
263 iInt2 coord;
264 if (ev->type == SDL_MOUSEMOTION) {
265 coord = init_I2(ev->motion.x, ev->motion.y);
266 }
267 else {
268 coord = init_I2(ev->button.x, ev->button.y);
269 }
270 return contains_Rect(bounds_Widget(constAs_Widget(d->doc)), coord);
271 }
272 return iTrue;
273}
274
260iBool processEvent_Banner(iBanner *d, const SDL_Event *ev) { 275iBool processEvent_Banner(iBanner *d, const SDL_Event *ev) {
261 iWidget *w = as_Widget(d->doc); 276 iWidget *w = as_Widget(d->doc);
277 if (!isInside_Banner_(d, ev)) {
278 return iFalse;
279 }
262 switch (ev->type) { 280 switch (ev->type) {
263 case SDL_MOUSEMOTION: { 281 case SDL_MOUSEMOTION: {
264 const iInt2 coord = init_I2(ev->motion.x, ev->motion.y); 282 const iInt2 coord = init_I2(ev->motion.x, ev->motion.y);
diff --git a/src/ui/uploadwidget.c b/src/ui/uploadwidget.c
index 90df1958..bad00071 100644
--- a/src/ui/uploadwidget.c
+++ b/src/ui/uploadwidget.c
@@ -45,7 +45,7 @@ iDefineObjectConstruction(UploadWidget)
45 45
46enum iUploadIdentity { 46enum iUploadIdentity {
47 none_UploadIdentity, 47 none_UploadIdentity,
48 defaultForUrl_UploadIdentity, 48 defaultForSite_UploadIdentity,
49 dropdown_UploadIdentity, 49 dropdown_UploadIdentity,
50}; 50};
51 51
@@ -104,9 +104,16 @@ static void updateInputMaxHeight_UploadWidget_(iUploadWidget *d) {
104 (avail - inputPos.y) / lineHeight_Text(font_InputWidget(d->input)))); 104 (avail - inputPos.y) / lineHeight_Text(font_InputWidget(d->input))));
105} 105}
106 106
107static const iGmIdentity *titanIdentityForUrl_(const iString *url) {
108 return findIdentity_GmCerts(
109 certs_App(),
110 collect_Block(hexDecode_Rangecc(range_String(valueString_SiteSpec(
111 collectNewRange_String(urlRoot_String(url)), titanIdentity_SiteSpecKey)))));
112}
113
107static const iArray *makeIdentityItems_UploadWidget_(const iUploadWidget *d) { 114static const iArray *makeIdentityItems_UploadWidget_(const iUploadWidget *d) {
108 iArray *items = collectNew_Array(sizeof(iMenuItem)); 115 iArray *items = collectNew_Array(sizeof(iMenuItem));
109 const iGmIdentity *urlId = identityForUrl_GmCerts(certs_App(), &d->url); 116 const iGmIdentity *urlId = titanIdentityForUrl_(&d->url);
110 pushBack_Array(items, 117 pushBack_Array(items,
111 &(iMenuItem){ format_CStr("${dlg.upload.id.default} (%s)", 118 &(iMenuItem){ format_CStr("${dlg.upload.id.default} (%s)",
112 urlId ? cstr_String(name_GmIdentity(urlId)) 119 urlId ? cstr_String(name_GmIdentity(urlId))
@@ -147,7 +154,7 @@ void init_UploadWidget(iUploadWidget *d) {
147 d->request = NULL; 154 d->request = NULL;
148 init_String(&d->filePath); 155 init_String(&d->filePath);
149 d->fileSize = 0; 156 d->fileSize = 0;
150 d->idMode = defaultForUrl_UploadIdentity; 157 d->idMode = defaultForSite_UploadIdentity;
151 init_Block(&d->idFingerprint, 0); 158 init_Block(&d->idFingerprint, 0);
152 const iMenuItem actions[] = { 159 const iMenuItem actions[] = {
153 { "${upload.port}", 0, 0, "upload.setport" }, 160 { "${upload.port}", 0, 0, "upload.setport" },
@@ -289,16 +296,22 @@ void deinit_UploadWidget(iUploadWidget *d) {
289 296
290static void remakeIdentityItems_UploadWidget_(iUploadWidget *d) { 297static void remakeIdentityItems_UploadWidget_(iUploadWidget *d) {
291 iWidget *dropMenu = findChild_Widget(findChild_Widget(as_Widget(d), "upload.id"), "menu"); 298 iWidget *dropMenu = findChild_Widget(findChild_Widget(as_Widget(d), "upload.id"), "menu");
292 releaseChildren_Widget(dropMenu);
293 const iArray *items = makeIdentityItems_UploadWidget_(d); 299 const iArray *items = makeIdentityItems_UploadWidget_(d);
294 makeMenuItems_Widget(dropMenu, constData_Array(items), size_Array(items)); 300 /* TODO: Make the following a utility method. */
301 if (flags_Widget(dropMenu) & nativeMenu_WidgetFlag) {
302 setNativeMenuItems_Widget(dropMenu, constData_Array(items), size_Array(items));
303 }
304 else {
305 releaseChildren_Widget(dropMenu);
306 makeMenuItems_Widget(dropMenu, constData_Array(items), size_Array(items));
307 }
295} 308}
296 309
297static void updateIdentityDropdown_UploadWidget_(iUploadWidget *d) { 310static void updateIdentityDropdown_UploadWidget_(iUploadWidget *d) {
298 updateDropdownSelection_LabelWidget( 311 updateDropdownSelection_LabelWidget(
299 findChild_Widget(as_Widget(d), "upload.id"), 312 findChild_Widget(as_Widget(d), "upload.id"),
300 d->idMode == none_UploadIdentity ? " arg:0" 313 d->idMode == none_UploadIdentity ? " arg:0"
301 : d->idMode == defaultForUrl_UploadIdentity 314 : d->idMode == defaultForSite_UploadIdentity
302 ? " arg:1" 315 ? " arg:1"
303 : format_CStr(" fp:%s", cstrCollect_String(hexEncode_Block(&d->idFingerprint)))); 316 : format_CStr(" fp:%s", cstrCollect_String(hexEncode_Block(&d->idFingerprint))));
304} 317}
@@ -422,7 +435,7 @@ static iBool processEvent_UploadWidget_(iUploadWidget *d, const SDL_Event *ev) {
422 } 435 }
423 else if (arg_Command(cmd)) { 436 else if (arg_Command(cmd)) {
424 clear_Block(&d->idFingerprint); 437 clear_Block(&d->idFingerprint);
425 d->idMode = defaultForUrl_UploadIdentity; 438 d->idMode = defaultForSite_UploadIdentity;
426 } 439 }
427 else { 440 else {
428 clear_Block(&d->idFingerprint); 441 clear_Block(&d->idFingerprint);
@@ -452,19 +465,27 @@ static iBool processEvent_UploadWidget_(iUploadWidget *d, const SDL_Event *ev) {
452 setSendProgressFunc_GmRequest(d->request, updateProgress_UploadWidget_); 465 setSendProgressFunc_GmRequest(d->request, updateProgress_UploadWidget_);
453 setUserData_Object(d->request, d); 466 setUserData_Object(d->request, d);
454 setUrl_GmRequest(d->request, &d->url); 467 setUrl_GmRequest(d->request, &d->url);
468 const iString *site = collectNewRange_String(urlRoot_String(&d->url));
455 switch (d->idMode) { 469 switch (d->idMode) {
456 case defaultForUrl_UploadIdentity:
457 break; /* GmRequest handles it */
458 case none_UploadIdentity: 470 case none_UploadIdentity:
459 setIdentity_GmRequest(d->request, NULL); 471 /* Ensure no identity will be used for this specific URL. */
460 signOut_GmCerts(certs_App(), url_GmRequest(d->request)); 472 signOut_GmCerts(certs_App(), url_GmRequest(d->request));
473 setValueString_SiteSpec(site, titanIdentity_SiteSpecKey, collectNew_String());
461 break; 474 break;
462 case dropdown_UploadIdentity: { 475 case dropdown_UploadIdentity: {
463 iGmIdentity *ident = findIdentity_GmCerts(certs_App(), &d->idFingerprint); 476 iGmIdentity *ident = findIdentity_GmCerts(certs_App(), &d->idFingerprint);
464 setIdentity_GmRequest(d->request, ident); 477 if (ident) {
465 signIn_GmCerts(certs_App(), ident, url_GmRequest(d->request)); 478 setValueString_SiteSpec(site,
479 titanIdentity_SiteSpecKey,
480 collect_String(hexEncode_Block(&ident->fingerprint)));
481 }
466 break; 482 break;
467 } 483 }
484 default:
485 break;
486 }
487 if (d->idMode != none_UploadIdentity) {
488 setIdentity_GmRequest(d->request, titanIdentityForUrl_(&d->url));
468 } 489 }
469 if (isText) { 490 if (isText) {
470 /* Uploading text. */ 491 /* Uploading text. */
diff --git a/src/ui/util.c b/src/ui/util.c
index 88348ff8..0a9dde0c 100644
--- a/src/ui/util.c
+++ b/src/ui/util.c
@@ -809,14 +809,27 @@ static void deleteMenuItems_(iArray *items) {
809 delete_Array(items); 809 delete_Array(items);
810} 810}
811 811
812iWidget *makeMenu_Widget(iWidget *parent, const iMenuItem *items, size_t n) { 812void releaseNativeMenu_Widget(iWidget *d) {
813 iWidget *menu = new_Widget();
814#if defined (iHaveNativeContextMenus) 813#if defined (iHaveNativeContextMenus)
815 setFlags_Widget(menu, hidden_WidgetFlag | nativeMenu_WidgetFlag, iTrue); 814 iArray *items = userData_Object(d);
815 if (items) {
816 iAssert(flags_Widget(d) & nativeMenu_WidgetFlag);
817 iAssert(items);
818 deleteMenuItems_(items);
819 setUserData_Object(d, NULL);
820 }
821#else
822 iUnused(d);
823#endif
824}
825
826void setNativeMenuItems_Widget(iWidget *menu, const iMenuItem *items, size_t n) {
827#if defined (iHaveNativeContextMenus)
828 iAssert(flags_Widget(menu) & nativeMenu_WidgetFlag);
829 releaseNativeMenu_Widget(menu);
816 setUserData_Object(menu, deepCopyMenuItems_(menu, items, n)); 830 setUserData_Object(menu, deepCopyMenuItems_(menu, items, n));
817 addChild_Widget(parent, menu);
818 iRelease(menu); /* owned by parent now */
819 /* Keyboard shortcuts still need to triggerable via the menu, although the items don't exist. */ { 831 /* Keyboard shortcuts still need to triggerable via the menu, although the items don't exist. */ {
832 releaseChildren_Widget(menu);
820 for (size_t i = 0; i < n; i++) { 833 for (size_t i = 0; i < n; i++) {
821 const iMenuItem *item = &items[i]; 834 const iMenuItem *item = &items[i];
822 if (item->key) { 835 if (item->key) {
@@ -824,6 +837,17 @@ iWidget *makeMenu_Widget(iWidget *parent, const iMenuItem *items, size_t n) {
824 } 837 }
825 } 838 }
826 } 839 }
840#endif
841}
842
843iWidget *makeMenu_Widget(iWidget *parent, const iMenuItem *items, size_t n) {
844 iWidget *menu = new_Widget();
845#if defined (iHaveNativeContextMenus)
846 setFlags_Widget(menu, hidden_WidgetFlag | nativeMenu_WidgetFlag, iTrue);
847 addChild_Widget(parent, menu);
848 iRelease(menu); /* owned by parent now */
849 setUserData_Object(menu, NULL);
850 setNativeMenuItems_Widget(menu, items, n);
827#else 851#else
828 /* Non-native custom popup menu. This may still be displayed inside a separate window. */ 852 /* Non-native custom popup menu. This may still be displayed inside a separate window. */
829 setDrawBufferEnabled_Widget(menu, iTrue); 853 setDrawBufferEnabled_Widget(menu, iTrue);
@@ -990,18 +1014,6 @@ iLocalDef iBool isUsingMenuPopupWindows_(void) {
990#endif 1014#endif
991} 1015}
992 1016
993void releaseNativeMenu_Widget(iWidget *d) {
994#if defined (iHaveNativeContextMenus)
995 iArray *items = userData_Object(d);
996 iAssert(flags_Widget(d) & nativeMenu_WidgetFlag);
997 iAssert(items);
998 deleteMenuItems_(items);
999 setUserData_Object(d, NULL);
1000#else
1001 iUnused(d);
1002#endif
1003}
1004
1005void openMenuFlags_Widget(iWidget *d, iInt2 windowCoord, int menuOpenFlags) { 1017void openMenuFlags_Widget(iWidget *d, iInt2 windowCoord, int menuOpenFlags) {
1006 const iBool postCommands = (menuOpenFlags & postCommands_MenuOpenFlags) != 0; 1018 const iBool postCommands = (menuOpenFlags & postCommands_MenuOpenFlags) != 0;
1007#if defined (iHaveNativeContextMenus) 1019#if defined (iHaveNativeContextMenus)
@@ -1263,8 +1275,8 @@ void updateDropdownSelection_LabelWidget(iLabelWidget *dropButton, const char *s
1263 iMenuItem *item = findNativeMenuItem_Widget(menu, selectedCommand); 1275 iMenuItem *item = findNativeMenuItem_Widget(menu, selectedCommand);
1264 if (item) { 1276 if (item) {
1265 setSelected_NativeMenuItem(item, iTrue); 1277 setSelected_NativeMenuItem(item, iTrue);
1266 updateText_LabelWidget(dropButton, 1278 updateText_LabelWidget(
1267 removeMenuItemLabelPrefixes_String(collectNewCStr_String(item->label))); 1279 dropButton, removeMenuItemLabelPrefixes_String(collectNewCStr_String(item->label)));
1268 } 1280 }
1269 return; 1281 return;
1270 } 1282 }
@@ -2199,27 +2211,27 @@ iWidget *makeDialog_Widget(const char *id,
2199 2211
2200iWidget *makePreferences_Widget(void) { 2212iWidget *makePreferences_Widget(void) {
2201 /* Common items. */ 2213 /* Common items. */
2202 const iMenuItem langItems[] = { { "${lang.cs} - cs", 0, 0, "uilang id:cs" }, 2214 const iMenuItem langItems[] = { { u8"Čeština - cs", 0, 0, "uilang id:cs" },
2203 { "${lang.de} - de", 0, 0, "uilang id:de" }, 2215 { u8"Deutsch - de", 0, 0, "uilang id:de" },
2204 { "${lang.en} - en", 0, 0, "uilang id:en" }, 2216 { u8"English - en", 0, 0, "uilang id:en" },
2205 { "${lang.es} - es", 0, 0, "uilang id:es" }, 2217 { u8"Español - es", 0, 0, "uilang id:es" },
2206 { "${lang.es.mx} - es", 0, 0, "uilang id:es_MX" }, 2218 { u8"Español (México) - es", 0, 0, "uilang id:es_MX" },
2207 { "${lang.eo} - eo", 0, 0, "uilang id:eo" }, 2219 { u8"Esperanto - eo", 0, 0, "uilang id:eo" },
2208 { "${lang.fi} - fi", 0, 0, "uilang id:fi" }, 2220 { u8"Suomi - fi", 0, 0, "uilang id:fi" },
2209 { "${lang.fr} - fr", 0, 0, "uilang id:fr" }, 2221 { u8"Français - fr", 0, 0, "uilang id:fr" },
2210 { "${lang.gl} - gl", 0, 0, "uilang id:gl" }, 2222 { u8"Galego - gl", 0, 0, "uilang id:gl" },
2211 { "${lang.hu} - hu", 0, 0, "uilang id:hu" }, 2223 { u8"Magyar - hu", 0, 0, "uilang id:hu" },
2212 { "${lang.ia} - ia", 0, 0, "uilang id:ia" }, 2224 { u8"Interlingua - ia", 0, 0, "uilang id:ia" },
2213 { "${lang.ie} - ie", 0, 0, "uilang id:ie" }, 2225 { u8"Interlingue - ie", 0, 0, "uilang id:ie" },
2214 { "${lang.isv} - isv", 0, 0, "uilang id:isv" }, 2226 { u8"Interslavic - isv", 0, 0, "uilang id:isv" },
2215 { "${lang.pl} - pl", 0, 0, "uilang id:pl" }, 2227 { u8"Polski - pl", 0, 0, "uilang id:pl" },
2216 { "${lang.ru} - ru", 0, 0, "uilang id:ru" }, 2228 { u8"Русский - ru", 0, 0, "uilang id:ru" },
2217 { "${lang.sk} - sk", 0, 0, "uilang id:sk" }, 2229 { u8"Slovak - sk", 0, 0, "uilang id:sk" },
2218 { "${lang.sr} - sr", 0, 0, "uilang id:sr" }, 2230 { u8"Српски - sr", 0, 0, "uilang id:sr" },
2219 { "${lang.tok} - tok", 0, 0, "uilang id:tok" }, 2231 { u8"Toki pona - tok", 0, 0, "uilang id:tok" },
2220 { "${lang.uk} - uk", 0, 0, "uilang id:uk" }, 2232 { u8"Українська - uk", 0, 0, "uilang id:uk" },
2221 { "${lang.zh.hans} - zh", 0, 0, "uilang id:zh_Hans" }, 2233 { u8"简体中文 - zh", 0, 0, "uilang id:zh_Hans" },
2222 { "${lang.zh.hant} - zh", 0, 0, "uilang id:zh_Hant" }, 2234 { u8"繁體/正體中文 - zh", 0, 0, "uilang id:zh_Hant" },
2223 { NULL } }; 2235 { NULL } };
2224 const iMenuItem returnKeyBehaviors[] = { 2236 const iMenuItem returnKeyBehaviors[] = {
2225 { "${prefs.returnkey.linebreak} " uiTextAction_ColorEscape shift_Icon return_Icon 2237 { "${prefs.returnkey.linebreak} " uiTextAction_ColorEscape shift_Icon return_Icon
diff --git a/src/ui/util.h b/src/ui/util.h
index cf96dfe4..52b3a692 100644
--- a/src/ui/util.h
+++ b/src/ui/util.h
@@ -249,6 +249,7 @@ void setMenuItemDisabled_Widget (iWidget *menu, const char *comm
249void setMenuItemDisabledByIndex_Widget(iWidget *menu, size_t index, iBool disable); 249void setMenuItemDisabledByIndex_Widget(iWidget *menu, size_t index, iBool disable);
250void setMenuItemLabel_Widget (iWidget *menu, const char *command, const char *newLabel); 250void setMenuItemLabel_Widget (iWidget *menu, const char *command, const char *newLabel);
251void setMenuItemLabelByIndex_Widget (iWidget *menu, size_t index, const char *newLabel); 251void setMenuItemLabelByIndex_Widget (iWidget *menu, size_t index, const char *newLabel);
252void setNativeMenuItems_Widget (iWidget *, const iMenuItem *items, size_t n);
252 253
253int checkContextMenu_Widget (iWidget *, const SDL_Event *ev); /* see macro below */ 254int checkContextMenu_Widget (iWidget *, const SDL_Event *ev); /* see macro below */
254 255