4#include <glibmm/i18n.h>
15using namespace librevenge;
22 int num_pages =
_pages.size();
25 set_title(_(
"Page Selector"));
29 property_destroy_with_parent().set_value(
false);
32 vbox1 = Gtk::make_managed<Gtk::Box>(Gtk::Orientation::VERTICAL, 4);
40 _labelSelect = Gtk::make_managed<Gtk::Label>(_(
"Select page:"));
48 auto pageNumberSpin_adj = Gtk::Adjustment::create(1, 1,
_pages.size(), 1, 10, 0);
49 _pageNumberSpin = Gtk::make_managed<Gtk::SpinButton>(pageNumberSpin_adj, 1, 0);
58 _labelTotalPages->set_label(Glib::ustring::compose(_(
"out of %1"), num_pages));
67 cancelbutton = Gtk::make_managed<Gtk::Button>(_(
"_Cancel"),
true);
68 okbutton = Gtk::make_managed<Gtk::Button>(_(
"_OK"),
true);
69 add_action_widget(*
cancelbutton, Gtk::ResponseType::CANCEL);
70 add_action_widget(*
okbutton, Gtk::ResponseType::OK);
75 auto const click = Gtk::GestureClick::create();
77 click->set_propagation_phase(Gtk::PropagationPhase::TARGET);
88 return ret == Gtk::ResponseType::OK || ret == Gtk::ResponseType::ACCEPT;
122 g_warning(
"CDR import: Could not create preview for page %d",
_current_page);
123 auto no_preview_template = R
"A(
124 <svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'>
125 <path d='M 82,10 18,74 m 0,-64 64,64' style='fill:none;stroke:#ff0000;stroke-width:2px;'/>
126 <rect x='18' y='10' width='64' height='64' style='fill:none;stroke:#000000;stroke-width:1.5px;'/>
127 <text x='50' y='92' style='font-size:10px;text-anchor:middle;font-family:sans-serif;'>%1</text>
130 auto no_preview = Glib::ustring::compose(no_preview_template, _(
"No preview"));
135 std::cerr <<
"RvngImportDialog::_setPreviewPage: No document!" << std::endl;
144 bool (*is_supported)(RVNGInputStream *),
145 bool (*parse)(RVNGInputStream *, RVNGDrawingInterface *))
151 auto converted_uri = g_win32_locale_filename_from_utf8(uri);
152 auto input = RVNGFileStream(converted_uri);
153 g_free(converted_uri);
155 auto input = RVNGFileStream(uri);
158 if (!is_supported(&input)) {
162 RVNGStringVector output;
163 RVNGSVGDrawingGenerator generator(output,
"svg");
165 if (!parse(&input, &generator)) {
169 if (output.empty()) {
173 std::vector<RVNGString> tmpSVGOutput;
174 for (
unsigned i=0; i<output.size(); ++i) {
175 RVNGString tmpString(
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n");
176 tmpString.append(output[i]);
177 tmpSVGOutput.push_back(tmpString);
180 unsigned page_num = 1;
183 if (tmpSVGOutput.size() > 1 && INKSCAPE.use_gui()) {
185 if (!dlg.showDialog()) {
190 page_num = std::clamp<int>(dlg.getSelectedPage(), 1, tmpSVGOutput.size());
195 if (doc && !doc->getRoot()->viewBox_set) {
199 doc->setViewBox(
Geom::Rect::from_xywh(0, 0, doc->getWidth().value(
"pt"), doc->getHeight().value(
"pt")));
static CRect from_xywh(Coord x, Coord y, Coord w, Coord h)
Create rectangle from origin and dimensions.
Inkscape::UI::View::SVGViewWidget _preview
Gtk::Button * cancelbutton
RvngImportDialog(std::vector< librevenge::RVNGString > const &pages)
Gtk::SpinButton * _pageNumberSpin
Gtk::Label * _labelSelect
std::vector< librevenge::RVNGString > const & _pages
void _onSpinButtonClickPressed(int n_press, double x, double y)
std::unique_ptr< SPDocument > _doc
void _onSpinButtonClickReleased(int n_press, double x, double y)
Gtk::Label * _labelTotalPages
void _setPreviewPage()
Renders the given page's thumbnail.
void _onPageNumberChanged()
Gtk::Box * _page_selector_box
static std::unique_ptr< SPDocument > createNewDocFromMem(std::span< char const > buffer, bool keepalive, std::string const &filename="")
Utilities to more easily use Gtk::EventController & subclasses like Gesture.
void sp_transientize(Gtk::Window &window)
Make the argument dialog transient to the currently active document window.
Event handler for dialog windows.
std::span< char const > as_span(librevenge::RVNGString const &str)
std::unique_ptr< SPDocument > rvng_open(char const *uri, bool(*is_supported)(RVNGInputStream *), bool(*parse)(RVNGInputStream *, RVNGDrawingInterface *))
void pack_end(Gtk::Box &box, Gtk::Widget &child, bool const expand, bool const fill, unsigned const padding)
Adds child to box, packed with reference to the end of box.
void pack_start(Gtk::Box &box, Gtk::Widget &child, bool const expand, bool const fill, unsigned const padding)
Adds child to box, packed with reference to the start of box.
int dialog_run(Gtk::Dialog &dialog)
This is a GTK4 porting aid meant to replace the removal of the Gtk::Dialog synchronous API.
Helpers for using Gtk::Boxes, encapsulating large changes between GTK3 & GTK4.
Common import dialog for .cdr and .vss files.
SPRoot: SVG <svg> implementation.