summaryrefslogtreecommitdiff
path: root/src/ui/documentwidget.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui/documentwidget.c')
-rw-r--r--src/ui/documentwidget.c27
1 files changed, 23 insertions, 4 deletions
diff --git a/src/ui/documentwidget.c b/src/ui/documentwidget.c
index 79e8b727..a468e2df 100644
--- a/src/ui/documentwidget.c
+++ b/src/ui/documentwidget.c
@@ -43,6 +43,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
43#include "paint.h" 43#include "paint.h"
44#include "mediaui.h" 44#include "mediaui.h"
45#include "scrollwidget.h" 45#include "scrollwidget.h"
46#include "translation.h"
46#include "util.h" 47#include "util.h"
47#include "visbuf.h" 48#include "visbuf.h"
48#include "visited.h" 49#include "visited.h"
@@ -218,6 +219,7 @@ struct Impl_DocumentWidget {
218 iPtrSet * invalidRuns; 219 iPtrSet * invalidRuns;
219 SDL_Texture * sideIconBuf; 220 SDL_Texture * sideIconBuf;
220 iTextBuf * timestampBuf; 221 iTextBuf * timestampBuf;
222 iTranslation * translation;
221}; 223};
222 224
223iDefineObjectConstruction(DocumentWidget) 225iDefineObjectConstruction(DocumentWidget)
@@ -273,6 +275,7 @@ void init_DocumentWidget(iDocumentWidget *d) {
273 d->playerMenu = NULL; 275 d->playerMenu = NULL;
274 d->sideIconBuf = NULL; 276 d->sideIconBuf = NULL;
275 d->timestampBuf = NULL; 277 d->timestampBuf = NULL;
278 d->translation = NULL;
276 addChildFlags_Widget(w, 279 addChildFlags_Widget(w,
277 iClob(new_IndicatorWidget()), 280 iClob(new_IndicatorWidget()),
278 resizeToParentWidth_WidgetFlag | resizeToParentHeight_WidgetFlag); 281 resizeToParentWidth_WidgetFlag | resizeToParentHeight_WidgetFlag);
@@ -289,6 +292,7 @@ void init_DocumentWidget(iDocumentWidget *d) {
289} 292}
290 293
291void deinit_DocumentWidget(iDocumentWidget *d) { 294void deinit_DocumentWidget(iDocumentWidget *d) {
295 delete_Translation(d->translation);
292 if (d->sideIconBuf) { 296 if (d->sideIconBuf) {
293 SDL_DestroyTexture(d->sideIconBuf); 297 SDL_DestroyTexture(d->sideIconBuf);
294 } 298 }
@@ -751,7 +755,7 @@ static void documentRunsInvalidated_DocumentWidget_(iDocumentWidget *d) {
751 d->lastVisibleRun = NULL; 755 d->lastVisibleRun = NULL;
752} 756}
753 757
754static void setSource_DocumentWidget_(iDocumentWidget *d, const iString *source) { 758void setSource_DocumentWidget(iDocumentWidget *d, const iString *source) {
755 setUrl_GmDocument(d->doc, d->mod.url); 759 setUrl_GmDocument(d->doc, d->mod.url);
756 setSource_GmDocument(d->doc, source, documentWidth_DocumentWidget_(d)); 760 setSource_GmDocument(d->doc, source, documentWidth_DocumentWidget_(d));
757 documentRunsInvalidated_DocumentWidget_(d); 761 documentRunsInvalidated_DocumentWidget_(d);
@@ -825,7 +829,7 @@ static void showErrorPage_DocumentWidget_(iDocumentWidget *d, enum iGmStatusCode
825 } 829 }
826 setBanner_GmDocument(d->doc, useBanner ? bannerType_DocumentWidget_(d) : none_GmDocumentBanner); 830 setBanner_GmDocument(d->doc, useBanner ? bannerType_DocumentWidget_(d) : none_GmDocumentBanner);
827 setFormat_GmDocument(d->doc, gemini_GmDocumentFormat); 831 setFormat_GmDocument(d->doc, gemini_GmDocumentFormat);
828 setSource_DocumentWidget_(d, src); 832 setSource_DocumentWidget(d, src);
829 updateTheme_DocumentWidget_(d); 833 updateTheme_DocumentWidget_(d);
830 init_Anim(&d->scrollY, 0); 834 init_Anim(&d->scrollY, 0);
831 init_Anim(&d->sideOpacity, 0); 835 init_Anim(&d->sideOpacity, 0);
@@ -947,7 +951,7 @@ static void updateDocument_DocumentWidget_(iDocumentWidget *d, const iGmResponse
947 } 951 }
948 } 952 }
949 if (setSource) { 953 if (setSource) {
950 setSource_DocumentWidget_(d, &str); 954 setSource_DocumentWidget(d, &str);
951 } 955 }
952 deinit_String(&str); 956 deinit_String(&str);
953 } 957 }
@@ -1777,6 +1781,20 @@ static iBool handleCommand_DocumentWidget_(iDocumentWidget *d, const char *cmd)
1777 cacheDocumentGlyphs_DocumentWidget_(d); 1781 cacheDocumentGlyphs_DocumentWidget_(d);
1778 return iFalse; 1782 return iFalse;
1779 } 1783 }
1784 else if (equalWidget_Command(cmd, w, "document.translate")) {
1785 if (!d->translation) {
1786 d->translation = new_Translation(d);
1787 }
1788 return iTrue;
1789 }
1790 else if (startsWith_CStr(cmd, "translation.") && d->translation) {
1791 const iBool wasHandled = handleCommand_Translation(d->translation, cmd);
1792 if (isFinished_Translation(d->translation)) {
1793 delete_Translation(d->translation);
1794 d->translation = NULL;
1795 }
1796 return wasHandled;
1797 }
1780 else if (equal_Command(cmd, "media.updated") || equal_Command(cmd, "media.finished")) { 1798 else if (equal_Command(cmd, "media.updated") || equal_Command(cmd, "media.finished")) {
1781 return handleMediaCommand_DocumentWidget_(d, cmd); 1799 return handleMediaCommand_DocumentWidget_(d, cmd);
1782 } 1800 }
@@ -2524,9 +2542,10 @@ static iBool processEvent_DocumentWidget_(iDocumentWidget *d, const SDL_Event *e
2524 { star_Icon " Subscribe to Page...", subscribeToPage_KeyModifier, "feeds.subscribe" }, 2542 { star_Icon " Subscribe to Page...", subscribeToPage_KeyModifier, "feeds.subscribe" },
2525 { "---", 0, 0, NULL }, 2543 { "---", 0, 0, NULL },
2526 { book_Icon " Import Links as Bookmarks...", 0, 0, "bookmark.links confirm:1" }, 2544 { book_Icon " Import Links as Bookmarks...", 0, 0, "bookmark.links confirm:1" },
2545 { "Translate...", 0, 0, "document.translate" },
2527 { "---", 0, 0, NULL }, 2546 { "---", 0, 0, NULL },
2528 { "Copy Page URL", 0, 0, "document.copylink" } }, 2547 { "Copy Page URL", 0, 0, "document.copylink" } },
2529 11); 2548 12);
2530 if (isEmpty_Range(&d->selectMark)) { 2549 if (isEmpty_Range(&d->selectMark)) {
2531 pushBackN_Array( 2550 pushBackN_Array(
2532 &items, 2551 &items,