generated from gdt050579/appcui-template
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PDF - fixed trailer endBuffer, added table of sections with GOTO and …
…Select
- Loading branch information
Showing
5 changed files
with
188 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
target_sources(PDF PRIVATE | ||
pdf.cpp | ||
PDFFile.cpp | ||
Sections.cpp | ||
PanelInformation.cpp) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
#include "pdf.hpp" | ||
|
||
using namespace GView::Type::PDF; | ||
using namespace AppCUI::Controls; | ||
using namespace AppCUI::Input; | ||
|
||
constexpr int PDF_SECTIONS_GOTO = 1; | ||
constexpr int PDF_SECTIONS_SELECT = 2; | ||
|
||
Panels::Sections::Sections(Reference<GView::Type::PDF::PDFFile> _pdf, Reference<GView::View::WindowInterface> _win) : TabPage("&Sections") | ||
{ | ||
pdf = _pdf; | ||
win = _win; | ||
Base = 16; | ||
|
||
list = Factory::ListView::Create(this, "d:c", { "n:Name,w:16", "n:ObjectPoz,a:r,w:12", "n:Size,a:r,w:12" }, ListViewFlags::AllowMultipleItemsSelection); | ||
Update(); | ||
} | ||
|
||
void Panels::Sections::GoToSelectedSection() | ||
{ | ||
auto sect = list->GetCurrentItem().GetData<PDF::PDFObject>(); | ||
if (sect.IsValid()) { | ||
win->GetCurrentView()->GoTo(sect->startBuffer); | ||
} | ||
} | ||
|
||
void Panels::Sections::SelectCurrentSection() | ||
{ | ||
auto sect = list->GetCurrentItem().GetData<PDF::PDFObject>(); | ||
if (sect.IsValid()) { | ||
win->GetCurrentView()->Select(sect->startBuffer, (sect->endBuffer - sect->startBuffer)); | ||
} | ||
} | ||
|
||
void Panels::Sections::Update() | ||
{ | ||
LocalString<128> temp; | ||
NumericFormatter n; | ||
list->DeleteAllItems(); | ||
|
||
for (auto& object : pdf->pdfObjects) { | ||
temp.Clear(); | ||
switch (object.type) { | ||
case 1: | ||
temp.Add("Object "); | ||
temp.Add(std::to_string(object.number)); | ||
break; | ||
case 2: | ||
temp.Add("Cross-ref Table"); | ||
break; | ||
case 3: | ||
temp.Add("Cross-ref Stream"); | ||
break; | ||
case 4: | ||
temp.Add("Trailer"); | ||
break; | ||
} | ||
auto item = list->AddItem(temp); | ||
|
||
item.SetData<PDF::PDFObject>(&object); | ||
|
||
item.SetText(1, GetValue(n, object.startBuffer)); | ||
item.SetText(2, GetValue(n, object.endBuffer - object.startBuffer)); | ||
} | ||
} | ||
|
||
std::string_view Panels::Sections::GetValue(NumericFormatter& n, uint32 value) | ||
{ | ||
if (Base == 10) | ||
return n.ToString(value, { NumericFormatFlags::None, 10, 3, ',' }); | ||
else | ||
return n.ToString(value, { NumericFormatFlags::HexPrefix, 16 }); | ||
} | ||
|
||
bool Panels::Sections::OnUpdateCommandBar(AppCUI::Application::CommandBar& commandBar) | ||
{ | ||
commandBar.SetCommand(Key::Enter, "GoTo", PDF_SECTIONS_GOTO); | ||
commandBar.SetCommand(Key::F9, "Select", PDF_SECTIONS_SELECT); | ||
return true; | ||
} | ||
|
||
bool Panels::Sections::OnEvent(Reference<Control> ctrl, Event evnt, int controlID) | ||
{ | ||
if (TabPage::OnEvent(ctrl, evnt, controlID)) | ||
return true; | ||
if (evnt == Event::ListViewItemPressed) { | ||
GoToSelectedSection(); | ||
return true; | ||
} | ||
if (evnt == Event::Command) { | ||
switch (controlID) { | ||
case PDF_SECTIONS_GOTO: | ||
GoToSelectedSection(); | ||
return true; | ||
case PDF_SECTIONS_SELECT: | ||
SelectCurrentSection(); | ||
return true; | ||
} | ||
} | ||
return false; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters