diff options
Diffstat (limited to 'src/ui')
-rw-r--r-- | src/ui/documentwidget.c | 75 | ||||
-rw-r--r-- | src/ui/mediaui.c | 82 | ||||
-rw-r--r-- | src/ui/mediaui.h | 17 |
3 files changed, 30 insertions, 144 deletions
diff --git a/src/ui/documentwidget.c b/src/ui/documentwidget.c index 1aca895c..a1992967 100644 --- a/src/ui/documentwidget.c +++ b/src/ui/documentwidget.c | |||
@@ -1257,7 +1257,7 @@ static const char *zipPageHeading_(const iRangecc mime) { | |||
1257 | return book_Icon " Gempub"; | 1257 | return book_Icon " Gempub"; |
1258 | } | 1258 | } |
1259 | else if (equalCase_Rangecc(mime, mimeType_FontPack)) { | 1259 | else if (equalCase_Rangecc(mime, mimeType_FontPack)) { |
1260 | return "\U0001f520 Fontpack"; | 1260 | return fontpack_Icon " Fontpack"; |
1261 | } | 1261 | } |
1262 | iRangecc type = iNullRange; | 1262 | iRangecc type = iNullRange; |
1263 | nextSplit_Rangecc(mime, "/", &type); /* skip the part before the slash */ | 1263 | nextSplit_Rangecc(mime, "/", &type); /* skip the part before the slash */ |
@@ -1435,13 +1435,6 @@ static void postProcessRequestContent_DocumentWidget_(iDocumentWidget *d, iBool | |||
1435 | } | 1435 | } |
1436 | } | 1436 | } |
1437 | } | 1437 | } |
1438 | /* Local fontpacks are automatically shown. */ | ||
1439 | if (preloadLocalFontpackForPreview_Fonts(d->doc)) { | ||
1440 | documentRunsInvalidated_DocumentWidget_(d); | ||
1441 | redoLayout_GmDocument(d->doc); | ||
1442 | updateVisible_DocumentWidget_(d); | ||
1443 | invalidate_DocumentWidget_(d); | ||
1444 | } | ||
1445 | } | 1438 | } |
1446 | 1439 | ||
1447 | static void updateDocument_DocumentWidget_(iDocumentWidget *d, | 1440 | static void updateDocument_DocumentWidget_(iDocumentWidget *d, |
@@ -1503,6 +1496,25 @@ static void updateDocument_DocumentWidget_(iDocumentWidget *d, | |||
1503 | appendFormat_String(&str, | 1496 | appendFormat_String(&str, |
1504 | cstr_Lang("doc.archive"), | 1497 | cstr_Lang("doc.archive"), |
1505 | cstr_Rangecc(baseName_Path(d->mod.url))); | 1498 | cstr_Rangecc(baseName_Path(d->mod.url))); |
1499 | if (isRequestFinished) { | ||
1500 | if (equal_Rangecc(param, mimeType_FontPack)) { | ||
1501 | /* Show some information about fontpacks, and set up footer actions. */ | ||
1502 | iArchive *zip = iClob(new_Archive()); | ||
1503 | if (openData_Archive(zip, &d->sourceContent)) { | ||
1504 | iFontPack *fp = new_FontPack(); | ||
1505 | setUrl_FontPack(fp, d->mod.url); | ||
1506 | setStandalone_FontPack(fp, iTrue); | ||
1507 | if (loadArchive_FontPack(fp, zip)) { | ||
1508 | appendFormat_String(&str, "\n\n%s", | ||
1509 | cstrCollect_String(infoText_FontPack(fp))); | ||
1510 | } | ||
1511 | const iArray *actions = actions_FontPack(fp); | ||
1512 | makeFooterButtons_DocumentWidget_(d, constData_Array(actions), | ||
1513 | size_Array(actions)); | ||
1514 | delete_FontPack(fp); | ||
1515 | } | ||
1516 | } | ||
1517 | } | ||
1506 | appendCStr_String(&str, "\n\n"); | 1518 | appendCStr_String(&str, "\n\n"); |
1507 | iString *localPath = localFilePathFromUrl_String(d->mod.url); | 1519 | iString *localPath = localFilePathFromUrl_String(d->mod.url); |
1508 | if (!localPath) { | 1520 | if (!localPath) { |
@@ -2916,27 +2928,6 @@ static iBool handleCommand_DocumentWidget_(iDocumentWidget *d, const char *cmd) | |||
2916 | updateMedia_DocumentWidget_(d); | 2928 | updateMedia_DocumentWidget_(d); |
2917 | return iFalse; | 2929 | return iFalse; |
2918 | } | 2930 | } |
2919 | else if (equal_Command(cmd, "media.fontpack.updated")) { | ||
2920 | iMedia *media = pointerLabel_Command(cmd, "media"); | ||
2921 | if (media == media_GmDocument(d->doc)) { | ||
2922 | /*iGmMediaInfo info; | ||
2923 | if (info_Media(media, | ||
2924 | (iMediaId){ fontpack_MediaType, argU32Label_Command(cmd, "id")}, | ||
2925 | &info)) { | ||
2926 | |||
2927 | }*/ | ||
2928 | |||
2929 | // findCachedContent_App(<#const iString *url#>, <#iString *mime_out#>, <#iBlock *data_out#>) | ||
2930 | // setData_Media(media, | ||
2931 | } | ||
2932 | return iFalse; | ||
2933 | } | ||
2934 | else if (equal_Command(cmd, "media.fontpack.install")) { | ||
2935 | if (pointerLabel_Command(cmd, "media") == media_GmDocument(d->doc)) { | ||
2936 | /* TODO: This is ours, we may have a MediaRequest with the data in memory. */ | ||
2937 | } | ||
2938 | return iFalse; | ||
2939 | } | ||
2940 | else if (equal_Command(cmd, "document.stop") && document_App() == d) { | 2931 | else if (equal_Command(cmd, "document.stop") && document_App() == d) { |
2941 | if (cancelRequest_DocumentWidget_(d, iTrue /* navigate back */)) { | 2932 | if (cancelRequest_DocumentWidget_(d, iTrue /* navigate back */)) { |
2942 | return iTrue; | 2933 | return iTrue; |
@@ -3253,7 +3244,16 @@ static iBool handleCommand_DocumentWidget_(iDocumentWidget *d, const char *cmd) | |||
3253 | return handleSwipe_DocumentWidget_(d, cmd); | 3244 | return handleSwipe_DocumentWidget_(d, cmd); |
3254 | } | 3245 | } |
3255 | else if (equal_Command(cmd, "document.setmediatype") && document_App() == d) { | 3246 | else if (equal_Command(cmd, "document.setmediatype") && document_App() == d) { |
3256 | setUrlAndSource_DocumentWidget(d, d->mod.url, string_Command(cmd, "mime"), &d->sourceContent); | 3247 | if (!isRequestOngoing_DocumentWidget(d)) { |
3248 | setUrlAndSource_DocumentWidget(d, d->mod.url, string_Command(cmd, "mime"), | ||
3249 | &d->sourceContent); | ||
3250 | } | ||
3251 | return iTrue; | ||
3252 | } | ||
3253 | else if (equalWidget_Command(cmd, w, "fontpack.install")) { | ||
3254 | const iString *id = idFromUrl_FontPack(d->mod.url); | ||
3255 | install_Fonts(id, &d->sourceContent); | ||
3256 | postCommandf_App("open gotoheading:%s url:about:fonts", cstr_String(id)); | ||
3257 | return iTrue; | 3257 | return iTrue; |
3258 | } | 3258 | } |
3259 | return iFalse; | 3259 | return iFalse; |
@@ -3302,15 +3302,6 @@ static iBool processMediaEvents_DocumentWidget_(iDocumentWidget *d, const SDL_Ev | |||
3302 | const iInt2 mouse = init_I2(ev->button.x, ev->button.y); | 3302 | const iInt2 mouse = init_I2(ev->button.x, ev->button.y); |
3303 | iConstForEach(PtrArray, i, &d->visibleMedia) { | 3303 | iConstForEach(PtrArray, i, &d->visibleMedia) { |
3304 | const iGmRun *run = i.ptr; | 3304 | const iGmRun *run = i.ptr; |
3305 | if (run->mediaType == fontpack_MediaType) { | ||
3306 | iFontpackUI ui; | ||
3307 | init_FontpackUI(&ui, media_GmDocument(d->doc), run->mediaId, | ||
3308 | runRect_DocumentWidget_(d, run)); | ||
3309 | if (processEvent_FontpackUI(&ui, ev)) { | ||
3310 | refresh_Widget(d); | ||
3311 | return iTrue; | ||
3312 | } | ||
3313 | } | ||
3314 | if (run->mediaType != audio_MediaType) { | 3305 | if (run->mediaType != audio_MediaType) { |
3315 | continue; | 3306 | continue; |
3316 | } | 3307 | } |
@@ -4685,12 +4676,6 @@ static void drawMedia_DocumentWidget_(const iDocumentWidget *d, iPaint *p) { | |||
4685 | runRect_DocumentWidget_(d, run)); | 4676 | runRect_DocumentWidget_(d, run)); |
4686 | draw_DownloadUI(&ui, p); | 4677 | draw_DownloadUI(&ui, p); |
4687 | } | 4678 | } |
4688 | else if (run->mediaType == fontpack_MediaType) { | ||
4689 | iFontpackUI ui; | ||
4690 | init_FontpackUI(&ui, constMedia_GmDocument(d->doc), run->mediaId, | ||
4691 | runRect_DocumentWidget_(d, run)); | ||
4692 | draw_FontpackUI(&ui, p); | ||
4693 | } | ||
4694 | } | 4679 | } |
4695 | } | 4680 | } |
4696 | 4681 | ||
diff --git a/src/ui/mediaui.c b/src/ui/mediaui.c index ac9475dd..d85d0df9 100644 --- a/src/ui/mediaui.c +++ b/src/ui/mediaui.c | |||
@@ -279,85 +279,3 @@ void draw_DownloadUI(const iDownloadUI *d, iPaint *p) { | |||
279 | translateCStr_Lang("\u2014 ${mb.per.sec}")); | 279 | translateCStr_Lang("\u2014 ${mb.per.sec}")); |
280 | } | 280 | } |
281 | } | 281 | } |
282 | |||
283 | /*----------------------------------------------------------------------------------------------*/ | ||
284 | |||
285 | static iMenuItem action_FontpackUI_(const iFontpackUI *d) { | ||
286 | if (d->info.isInstalled) { | ||
287 | return (iMenuItem){ d->info.isDisabled ? "${media.fontpack.enable}" | ||
288 | : close_Icon " ${media.fontpack.disable}", | ||
289 | 0, 0, format_CStr("media.fontpack.enable arg:%d", d->info.isDisabled) }; | ||
290 | } | ||
291 | return (iMenuItem){ d->info.isInstalled ? close_Icon " ${media.fontpack.disable}" | ||
292 | : "${media.fontpack.install}", | ||
293 | 0, 0, | ||
294 | d->info.isInstalled ? "media.fontpack.enable arg:0" : "media.fontpack.install" }; | ||
295 | } | ||
296 | |||
297 | void init_FontpackUI(iFontpackUI *d, const iMedia *media, uint16_t mediaId, iRect bounds) { | ||
298 | d->media = media; | ||
299 | d->mediaId = mediaId; | ||
300 | fontpackInfo_Media(d->media, (iMediaId){ fontpack_MediaType, d->mediaId }, &d->info); | ||
301 | d->bounds = bounds; | ||
302 | iMenuItem action = action_FontpackUI_(d); | ||
303 | d->buttonRect.size = add_I2(measure_Text(uiLabel_FontId, action.label).bounds.size, | ||
304 | muli_I2(gap2_UI, 3)); | ||
305 | d->buttonRect.pos.x = right_Rect(d->bounds) - gap_UI - d->buttonRect.size.x; | ||
306 | d->buttonRect.pos.y = mid_Rect(d->bounds).y - d->buttonRect.size.y / 2; | ||
307 | } | ||
308 | |||
309 | iBool processEvent_FontpackUI(iFontpackUI *d, const SDL_Event *ev) { | ||
310 | switch (ev->type) { | ||
311 | case SDL_MOUSEBUTTONDOWN: | ||
312 | case SDL_MOUSEBUTTONUP: { | ||
313 | const iInt2 pos = init_I2(ev->button.x, ev->button.y); | ||
314 | if (contains_Rect(d->buttonRect, pos)) { | ||
315 | if (ev->type == SDL_MOUSEBUTTONUP) { | ||
316 | postCommandf_App("%s media:%p mediaid:%u packid:%s", | ||
317 | action_FontpackUI_(d).command, | ||
318 | d->media, d->mediaId, cstr_String(d->info.packId.id)); | ||
319 | } | ||
320 | return iTrue; | ||
321 | } | ||
322 | break; | ||
323 | } | ||
324 | case SDL_MOUSEMOTION: | ||
325 | if (contains_Rect(d->bounds, init_I2(ev->motion.x, ev->motion.y))) { | ||
326 | return iTrue; | ||
327 | } | ||
328 | break; | ||
329 | } | ||
330 | return iFalse; | ||
331 | } | ||
332 | |||
333 | int height_FontpackUI(const iMedia *media, uint16_t mediaId, int width) { | ||
334 | const iStringList *names; | ||
335 | iFontpackMediaInfo info; | ||
336 | fontpackInfo_Media(media, (iMediaId){ fontpack_MediaType, mediaId }, &info); | ||
337 | return lineHeight_Text(uiContent_FontId) + | ||
338 | lineHeight_Text(uiLabel_FontId) * (1 + size_StringList(info.names)); | ||
339 | } | ||
340 | |||
341 | void draw_FontpackUI(const iFontpackUI *d, iPaint *p) { | ||
342 | /* Draw a background box. */ | ||
343 | fillRect_Paint(p, d->bounds, uiBackground_ColorId); | ||
344 | drawRect_Paint(p, d->bounds, uiSeparator_ColorId); | ||
345 | iInt2 pos = topLeft_Rect(d->bounds); | ||
346 | const char *checks[] = { "\u2610", "\u2611" }; | ||
347 | draw_Text(uiContentBold_FontId, pos, | ||
348 | d->info.isDisabled ? uiText_ColorId : uiHeading_ColorId, "\"%s\" v%d", | ||
349 | cstr_String(d->info.packId.id), d->info.packId.version); | ||
350 | pos.y += lineHeight_Text(uiContentBold_FontId); | ||
351 | draw_Text(uiLabelBold_FontId, pos, uiText_ColorId, "%.1f MB, %d fonts %s %s %s", | ||
352 | d->info.sizeInBytes / 1.0e6, size_StringList(d->info.names), | ||
353 | // checks[info.isValid], info.isValid ? "No errors" : "Errors detected", | ||
354 | checks[d->info.isInstalled], d->info.isInstalled ? "Installed" : "Not installed", | ||
355 | d->info.isReadOnly ? "Read-Only" : ""); | ||
356 | pos.y += lineHeight_Text(uiLabelBold_FontId); | ||
357 | iConstForEach(StringList, i, d->info.names) { | ||
358 | drawRange_Text(uiLabel_FontId, pos, uiText_ColorId, range_String(i.value)); | ||
359 | pos.y += lineHeight_Text(uiLabel_FontId); | ||
360 | } | ||
361 | /* Buttons. */ | ||
362 | drawInlineButton_(p, d->buttonRect, action_FontpackUI_(d).label, uiLabel_FontId); | ||
363 | } | ||
diff --git a/src/ui/mediaui.h b/src/ui/mediaui.h index 03ea0afc..3d51e4c9 100644 --- a/src/ui/mediaui.h +++ b/src/ui/mediaui.h | |||
@@ -59,20 +59,3 @@ struct Impl_DownloadUI { | |||
59 | void init_DownloadUI (iDownloadUI *, const iMedia *media, uint16_t mediaId, iRect bounds); | 59 | void init_DownloadUI (iDownloadUI *, const iMedia *media, uint16_t mediaId, iRect bounds); |
60 | iBool processEvent_DownloadUI (iDownloadUI *, const SDL_Event *ev); | 60 | iBool processEvent_DownloadUI (iDownloadUI *, const SDL_Event *ev); |
61 | void draw_DownloadUI (const iDownloadUI *, iPaint *p); | 61 | void draw_DownloadUI (const iDownloadUI *, iPaint *p); |
62 | |||
63 | /*----------------------------------------------------------------------------------------------*/ | ||
64 | |||
65 | iDeclareType(FontpackUI) | ||
66 | |||
67 | struct Impl_FontpackUI { | ||
68 | const iMedia *media; | ||
69 | uint16_t mediaId; | ||
70 | iFontpackMediaInfo info; | ||
71 | iRect bounds; | ||
72 | iRect buttonRect; | ||
73 | }; | ||
74 | |||
75 | void init_FontpackUI (iFontpackUI *, const iMedia *media, uint16_t mediaId, iRect bounds); | ||
76 | int height_FontpackUI (const iMedia *media, uint16_t mediaId, int width); | ||
77 | iBool processEvent_FontpackUI (iFontpackUI *, const SDL_Event *ev); | ||
78 | void draw_FontpackUI (const iFontpackUI *, iPaint *p); | ||