summaryrefslogtreecommitdiff
path: root/src/gmdocument.c
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2021-02-26 10:24:09 +0200
committerJaakko Keränen <jaakko.keranen@iki.fi>2021-02-26 10:24:09 +0200
commit91a6225d8508db01574d7da2c013cb30d6a87ec8 (patch)
treee3bd2c2f24a22c694c1c23aefd5fc531ae108723 /src/gmdocument.c
parent4708a6580e9af65cd15769e87487fdf4456f1e00 (diff)
DocumentWidget: Inline downloads
Diffstat (limited to 'src/gmdocument.c')
-rw-r--r--src/gmdocument.c43
1 files changed, 29 insertions, 14 deletions
diff --git a/src/gmdocument.c b/src/gmdocument.c
index abfefea7..4926587d 100644
--- a/src/gmdocument.c
+++ b/src/gmdocument.c
@@ -255,6 +255,15 @@ static iBool isForcedMonospace_GmDocument_(const iGmDocument *d) {
255 return iFalse; 255 return iFalse;
256} 256}
257 257
258static void linkContentLaidOut_GmDocument_(iGmDocument *d, const iGmMediaInfo *mediaInfo,
259 uint16_t linkId) {
260 iGmLink *link = at_PtrArray(&d->links, linkId - 1);
261 link->flags |= content_GmLinkFlag;
262 if (mediaInfo && mediaInfo->isPermanent) {
263 link->flags |= permanent_GmLinkFlag;
264 }
265}
266
258static void doLayout_GmDocument_(iGmDocument *d) { 267static void doLayout_GmDocument_(iGmDocument *d) {
259 const iBool isMono = isForcedMonospace_GmDocument_(d); 268 const iBool isMono = isForcedMonospace_GmDocument_(d);
260 /* TODO: Collect these parameters into a GmTheme. */ 269 /* TODO: Collect these parameters into a GmTheme. */
@@ -558,17 +567,12 @@ static void doLayout_GmDocument_(iGmDocument *d) {
558 if (type == link_GmLineType) { 567 if (type == link_GmLineType) {
559 const iMediaId imageId = findLinkImage_Media(d->media, run.linkId); 568 const iMediaId imageId = findLinkImage_Media(d->media, run.linkId);
560 const iMediaId audioId = !imageId ? findLinkAudio_Media(d->media, run.linkId) : 0; 569 const iMediaId audioId = !imageId ? findLinkAudio_Media(d->media, run.linkId) : 0;
570 const iMediaId downloadId = !imageId && !audioId ? findLinkDownload_Media(d->media, run.linkId) : 0;
561 if (imageId) { 571 if (imageId) {
562 iGmMediaInfo img; 572 iGmMediaInfo img;
563 imageInfo_Media(d->media, imageId, &img); 573 imageInfo_Media(d->media, imageId, &img);
564 const iInt2 imgSize = imageSize_Media(d->media, imageId); 574 const iInt2 imgSize = imageSize_Media(d->media, imageId);
565 /* Mark the link as having content. */ { 575 linkContentLaidOut_GmDocument_(d, &img, run.linkId);
566 iGmLink *link = at_PtrArray(&d->links, run.linkId - 1);
567 link->flags |= content_GmLinkFlag;
568 if (img.isPermanent) {
569 link->flags |= permanent_GmLinkFlag;
570 }
571 }
572 const int margin = lineHeight_Text(paragraph_FontId) / 2; 576 const int margin = lineHeight_Text(paragraph_FontId) / 2;
573 pos.y += margin; 577 pos.y += margin;
574 run.bounds.pos = pos; 578 run.bounds.pos = pos;
@@ -596,13 +600,7 @@ static void doLayout_GmDocument_(iGmDocument *d) {
596 else if (audioId) { 600 else if (audioId) {
597 iGmMediaInfo info; 601 iGmMediaInfo info;
598 audioInfo_Media(d->media, audioId, &info); 602 audioInfo_Media(d->media, audioId, &info);
599 /* Mark the link as having content. */ { 603 linkContentLaidOut_GmDocument_(d, &info, run.linkId);
600 iGmLink *link = at_PtrArray(&d->links, run.linkId - 1);
601 link->flags |= content_GmLinkFlag;
602 if (info.isPermanent) {
603 link->flags |= permanent_GmLinkFlag;
604 }
605 }
606 const int margin = lineHeight_Text(paragraph_FontId) / 2; 604 const int margin = lineHeight_Text(paragraph_FontId) / 2;
607 pos.y += margin; 605 pos.y += margin;
608 run.bounds.pos = pos; 606 run.bounds.pos = pos;
@@ -616,6 +614,23 @@ static void doLayout_GmDocument_(iGmDocument *d) {
616 pushBack_Array(&d->layout, &run); 614 pushBack_Array(&d->layout, &run);
617 pos.y += run.bounds.size.y + margin; 615 pos.y += run.bounds.size.y + margin;
618 } 616 }
617 else if (downloadId) {
618 iGmMediaInfo info;
619 downloadInfo_Media(d->media, downloadId, &info);
620 linkContentLaidOut_GmDocument_(d, &info, run.linkId);
621 const int margin = lineHeight_Text(paragraph_FontId) / 2;
622 pos.y += margin;
623 run.bounds.pos = pos;
624 run.bounds.size.x = d->size.x;
625 run.bounds.size.y = 2 * lineHeight_Text(uiContent_FontId) + 4 * gap_UI;
626 run.visBounds = run.bounds;
627 run.text = iNullRange;
628 run.color = 0;
629 run.mediaType = download_GmRunMediaType;
630 run.mediaId = downloadId;
631 pushBack_Array(&d->layout, &run);
632 pos.y += run.bounds.size.y + margin;
633 }
619 } 634 }
620 prevType = type; 635 prevType = type;
621 } 636 }