Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
pwmt
zathura
Commits
4c25d687
Commit
4c25d687
authored
May 06, 2012
by
Moritz Lipp
Browse files
Restructure zathura_page_widget_private_s
parent
13711243
Changes
1
Hide whitespace changes
Inline
Side-by-side
page-widget.c
View file @
4c25d687
...
...
@@ -16,27 +16,39 @@
G_DEFINE_TYPE
(
ZathuraPage
,
zathura_page_widget
,
GTK_TYPE_DRAWING_AREA
)
typedef
struct
zathura_page_widget_private_s
{
zathura_page_t
*
page
;
zathura_t
*
zathura
;
zathura_page_t
*
page
;
/**< Page object */
zathura_t
*
zathura
;
/**< Zathura object */
cairo_surface_t
*
surface
;
/**< Cairo surface */
gint64
last_view
;
/**< Last time the page has been viewed */
GStaticMutex
lock
;
/**< Lock */
girara_list_t
*
links
;
/**< List of links on the page */
bool
links_got
;
/**< True if we already tried to retrieve the list of links */
bool
draw_links
;
/**< True if links should be drawn */
unsigned
int
link_offset
;
/**< Offset to the links */
unsigned
int
number_of_links
;
/**< Offset to the links */
girara_list_t
*
search_results
;
/**< A list if there are search results that should be drawn */
int
search_current
;
/**< The index of the current search result */
bool
draw_search_results
;
/**< Draw search results */
zathura_rectangle_t
selection
;
/**< Region selected with the mouse */
struct
{
girara_list_t
*
list
;
/**< List of links on the page */
bool
retrieved
;
/**< True if we already tried to retrieve the list of links */
bool
draw
;
/**< True if links should be drawn */
unsigned
int
offset
;
/**< Offset to the links */
unsigned
int
n
;
/**< Number */
}
links
;
struct
{
girara_list_t
*
list
;
/**< A list if there are search results that should be drawn */
int
current
;
/**< The index of the current search result */
bool
draw
;
/**< Draw search results */
}
search
;
struct
{
girara_list_t
*
list
;
/**< List of images on the page */
bool
retrieved
;
/**< True if we already tried to retrieve the list of images */
zathura_image_t
*
current
;
/**< Image data of selected image */
}
images
;
struct
{
int
x
;
int
y
;
}
selection_basepoint
;
girara_list_t
*
images
;
/**< List of images on the page */
bool
images_got
;
/**< True if we already tried to retrieve the list of images */
zathura_image_t
*
current_image
;
/**< Image data of selected image */
gint64
last_view
;
zathura_rectangle_t
selection
;
/**< Region selected with the mouse */
struct
{
int
x
;
/**< X coordinate */
int
y
;
/**< Y coordinate */
}
selection_basepoint
;
}
mouse
;
}
zathura_page_widget_private_t
;
#define ZATHURA_PAGE_GET_PRIVATE(obj) \
...
...
@@ -68,11 +80,10 @@ enum properties_e
PROP_DRAW_LINKS
,
PROP_LINKS_OFFSET
,
PROP_LINKS_NUMBER
,
PROP_SEARCH_RESULT
,
PROP_SEARCH_RESULTS
,
PROP_SEARCH_RESULTS_LENGTH
,
PROP_SEARCH_RESULTS_CURRENT
,
PROP_DRAW_SEA
R
CH_RESULTS
PROP_DRAW_SEACH_RESULTS
};
static
void
...
...
@@ -116,7 +127,7 @@ zathura_page_widget_class_init(ZathuraPageClass* class)
g_param_spec_int
(
"search-current"
,
"search-current"
,
"The current search result"
,
-
1
,
INT_MAX
,
0
,
G_PARAM_WRITABLE
|
G_PARAM_READABLE
));
g_object_class_install_property
(
object_class
,
PROP_SEARCH_RESULTS_LENGTH
,
g_param_spec_int
(
"search-length"
,
"search-length"
,
"The number of search results"
,
-
1
,
INT_MAX
,
0
,
G_PARAM_READABLE
));
g_object_class_install_property
(
object_class
,
PROP_DRAW_SEA
R
CH_RESULTS
,
g_object_class_install_property
(
object_class
,
PROP_DRAW_SEACH_RESULTS
,
g_param_spec_boolean
(
"draw-search-results"
,
"draw-search-results"
,
"Set to true if search results should be drawn"
,
FALSE
,
G_PARAM_WRITABLE
));
}
...
...
@@ -124,21 +135,29 @@ static void
zathura_page_widget_init
(
ZathuraPage
*
widget
)
{
zathura_page_widget_private_t
*
priv
=
ZATHURA_PAGE_GET_PRIVATE
(
widget
);
priv
->
page
=
NULL
;
priv
->
surface
=
NULL
;
priv
->
links
=
NULL
;
priv
->
links_got
=
false
;
priv
->
link_offset
=
0
;
priv
->
search_results
=
NULL
;
priv
->
search_current
=
INT_MAX
;
priv
->
selection
.
x1
=
-
1
;
priv
->
selection_basepoint
.
x
=
-
1
;
priv
->
selection_basepoint
.
y
=
-
1
;
priv
->
images
=
NULL
;
priv
->
images_got
=
false
;
priv
->
current_image
=
NULL
;
priv
->
last_view
=
g_get_real_time
();
priv
->
draw_search_results
=
true
;
priv
->
page
=
NULL
;
priv
->
surface
=
NULL
;
priv
->
last_view
=
g_get_real_time
();
priv
->
links
.
list
=
NULL
;
priv
->
links
.
retrieved
=
false
;
priv
->
links
.
draw
=
false
;
priv
->
links
.
offset
=
0
;
priv
->
links
.
n
=
0
;
priv
->
search
.
list
=
NULL
;
priv
->
search
.
current
=
INT_MAX
;
priv
->
search
.
draw
=
true
;
priv
->
images
.
list
=
NULL
;
priv
->
images
.
retrieved
=
false
;
priv
->
images
.
current
=
NULL
;
priv
->
mouse
.
selection
.
x1
=
-
1
;
priv
->
mouse
.
selection
.
y1
=
-
1
;
priv
->
mouse
.
selection_basepoint
.
x
=
-
1
;
priv
->
mouse
.
selection_basepoint
.
y
=
-
1
;
g_static_mutex_init
(
&
(
priv
->
lock
));
/* we want mouse events */
...
...
@@ -164,12 +183,12 @@ zathura_page_widget_finalize(GObject* object)
cairo_surface_destroy
(
priv
->
surface
);
}
if
(
priv
->
search
_results
!=
NULL
)
{
girara_list_free
(
priv
->
search
_results
);
if
(
priv
->
search
.
list
!=
NULL
)
{
girara_list_free
(
priv
->
search
.
list
);
}
if
(
priv
->
links
!=
NULL
)
{
girara_list_free
(
priv
->
links
);
if
(
priv
->
links
.
list
!=
NULL
)
{
girara_list_free
(
priv
->
links
.
list
);
}
g_static_mutex_free
(
&
(
priv
->
lock
));
...
...
@@ -191,60 +210,60 @@ zathura_page_widget_set_property(GObject* object, guint prop_id, const GValue* v
priv
->
zathura
=
g_value_get_pointer
(
value
);
break
;
case
PROP_DRAW_LINKS
:
priv
->
draw_
links
=
g_value_get_boolean
(
value
);
priv
->
links
.
draw
=
g_value_get_boolean
(
value
);
/* get links */
if
(
priv
->
draw_
links
==
true
&&
priv
->
links
_got
==
false
)
{
priv
->
links
=
zathura_page_links_get
(
priv
->
page
,
NULL
);
priv
->
links
_got
=
true
;
priv
->
number_of_links
=
(
priv
->
links
==
NULL
)
?
0
:
girara_list_size
(
priv
->
links
);
if
(
priv
->
links
.
draw
==
true
&&
priv
->
links
.
retrieved
==
false
)
{
priv
->
links
.
list
=
zathura_page_links_get
(
priv
->
page
,
NULL
);
priv
->
links
.
retrieved
=
true
;
priv
->
links
.
n
=
(
priv
->
links
.
list
==
NULL
)
?
0
:
girara_list_size
(
priv
->
links
.
list
);
}
if
(
priv
->
links
_got
==
true
&&
priv
->
links
!=
NULL
)
{
GIRARA_LIST_FOREACH
(
priv
->
links
,
zathura_link_t
*
,
iter
,
link
)
if
(
priv
->
links
.
retrieved
==
true
&&
priv
->
links
.
list
!=
NULL
)
{
GIRARA_LIST_FOREACH
(
priv
->
links
.
list
,
zathura_link_t
*
,
iter
,
link
)
if
(
link
!=
NULL
)
{
zathura_rectangle_t
rectangle
=
recalc_rectangle
(
priv
->
page
,
link
->
position
);
redraw_rect
(
pageview
,
&
rectangle
);
}
GIRARA_LIST_FOREACH_END
(
priv
->
links
,
zathura_link_t
*
,
iter
,
link
);
GIRARA_LIST_FOREACH_END
(
priv
->
links
.
list
,
zathura_link_t
*
,
iter
,
link
);
}
break
;
case
PROP_LINKS_OFFSET
:
priv
->
link
_
offset
=
g_value_get_int
(
value
);
priv
->
link
s
.
offset
=
g_value_get_int
(
value
);
break
;
case
PROP_SEARCH_RESULTS
:
if
(
priv
->
search
_results
!=
NULL
&&
priv
->
draw_
search
_results
)
{
redraw_all_rects
(
pageview
,
priv
->
search
_results
);
girara_list_free
(
priv
->
search
_results
);
if
(
priv
->
search
.
list
!=
NULL
&&
priv
->
search
.
draw
)
{
redraw_all_rects
(
pageview
,
priv
->
search
.
list
);
girara_list_free
(
priv
->
search
.
list
);
}
priv
->
search
_results
=
g_value_get_pointer
(
value
);
if
(
priv
->
search
_results
!=
NULL
&&
priv
->
draw_
search
_results
)
{
priv
->
draw_
links
=
false
;
redraw_all_rects
(
pageview
,
priv
->
search
_results
);
priv
->
search
.
list
=
g_value_get_pointer
(
value
);
if
(
priv
->
search
.
list
!=
NULL
&&
priv
->
search
.
draw
)
{
priv
->
links
.
draw
=
false
;
redraw_all_rects
(
pageview
,
priv
->
search
.
list
);
}
priv
->
search
_
current
=
-
1
;
priv
->
search
.
current
=
-
1
;
break
;
case
PROP_SEARCH_RESULTS_CURRENT
:
{
g_return_if_fail
(
priv
->
search
_results
!=
NULL
);
if
(
priv
->
search
_
current
>=
0
&&
priv
->
search
_
current
<
(
signed
)
girara_list_size
(
priv
->
search
_results
))
{
zathura_rectangle_t
*
rect
=
girara_list_nth
(
priv
->
search
_results
,
priv
->
search
_
current
);
g_return_if_fail
(
priv
->
search
.
list
!=
NULL
);
if
(
priv
->
search
.
current
>=
0
&&
priv
->
search
.
current
<
(
signed
)
girara_list_size
(
priv
->
search
.
list
))
{
zathura_rectangle_t
*
rect
=
girara_list_nth
(
priv
->
search
.
list
,
priv
->
search
.
current
);
zathura_rectangle_t
rectangle
=
recalc_rectangle
(
priv
->
page
,
*
rect
);
redraw_rect
(
pageview
,
&
rectangle
);
}
int
val
=
g_value_get_int
(
value
);
if
(
val
<
0
)
{
priv
->
search
_
current
=
girara_list_size
(
priv
->
search
_results
);
priv
->
search
.
current
=
girara_list_size
(
priv
->
search
.
list
);
}
else
{
priv
->
search
_
current
=
val
;
zathura_rectangle_t
*
rect
=
girara_list_nth
(
priv
->
search
_results
,
priv
->
search
_
current
);
priv
->
search
.
current
=
val
;
zathura_rectangle_t
*
rect
=
girara_list_nth
(
priv
->
search
.
list
,
priv
->
search
.
current
);
zathura_rectangle_t
rectangle
=
recalc_rectangle
(
priv
->
page
,
*
rect
);
if
(
priv
->
draw_
search
_results
)
{
if
(
priv
->
search
.
draw
)
{
redraw_rect
(
pageview
,
&
rectangle
);
}
}
break
;
}
case
PROP_DRAW_SEA
R
CH_RESULTS
:
priv
->
draw_
search
_results
=
g_value_get_boolean
(
value
);
case
PROP_DRAW_SEACH_RESULTS
:
priv
->
search
.
draw
=
g_value_get_boolean
(
value
);
break
;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID
(
object
,
prop_id
,
pspec
);
...
...
@@ -259,16 +278,16 @@ zathura_page_widget_get_property(GObject* object, guint prop_id, GValue* value,
switch
(
prop_id
)
{
case
PROP_LINKS_NUMBER
:
g_value_set_int
(
value
,
priv
->
number_of_
links
);
g_value_set_int
(
value
,
priv
->
links
.
n
);
break
;
case
PROP_SEARCH_RESULTS_LENGTH
:
g_value_set_int
(
value
,
priv
->
search
_results
==
NULL
?
0
:
girara_list_size
(
priv
->
search
_results
));
g_value_set_int
(
value
,
priv
->
search
.
list
==
NULL
?
0
:
girara_list_size
(
priv
->
search
.
list
));
break
;
case
PROP_SEARCH_RESULTS_CURRENT
:
g_value_set_int
(
value
,
priv
->
search
_results
==
NULL
?
-
1
:
priv
->
search
_
current
);
g_value_set_int
(
value
,
priv
->
search
.
list
==
NULL
?
-
1
:
priv
->
search
.
current
);
break
;
case
PROP_SEARCH_RESULTS
:
g_value_set_pointer
(
value
,
priv
->
search
_results
);
g_value_set_pointer
(
value
,
priv
->
search
.
list
);
break
;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID
(
object
,
prop_id
,
pspec
);
...
...
@@ -350,9 +369,9 @@ zathura_page_widget_draw(GtkWidget* widget, cairo_t* cairo)
g_free
(
font
);
/* draw links */
if
(
priv
->
draw_
links
==
true
&&
priv
->
number_of_
links
!=
0
)
{
if
(
priv
->
links
.
draw
==
true
&&
priv
->
links
.
n
!=
0
)
{
unsigned
int
link_counter
=
0
;
GIRARA_LIST_FOREACH
(
priv
->
links
,
zathura_link_t
*
,
iter
,
link
)
GIRARA_LIST_FOREACH
(
priv
->
links
.
list
,
zathura_link_t
*
,
iter
,
link
)
if
(
link
!=
NULL
)
{
zathura_rectangle_t
rectangle
=
recalc_rectangle
(
priv
->
page
,
link
->
position
);
...
...
@@ -367,21 +386,21 @@ zathura_page_widget_draw(GtkWidget* widget, cairo_t* cairo)
cairo_set_source_rgba
(
cairo
,
0
,
0
,
0
,
1
);
cairo_set_font_size
(
cairo
,
10
);
cairo_move_to
(
cairo
,
rectangle
.
x1
+
1
,
rectangle
.
y2
-
1
);
char
*
link_number
=
g_strdup_printf
(
"%i"
,
priv
->
link
_
offset
+
++
link_counter
);
char
*
link_number
=
g_strdup_printf
(
"%i"
,
priv
->
link
s
.
offset
+
++
link_counter
);
cairo_show_text
(
cairo
,
link_number
);
g_free
(
link_number
);
}
GIRARA_LIST_FOREACH_END
(
priv
->
links
,
zathura_link_t
*
,
iter
,
link
);
GIRARA_LIST_FOREACH_END
(
priv
->
links
.
list
,
zathura_link_t
*
,
iter
,
link
);
}
/* draw search results */
if
(
priv
->
search
_results
!=
NULL
&&
priv
->
draw_
search
_results
==
true
)
{
if
(
priv
->
search
.
list
!=
NULL
&&
priv
->
search
.
draw
==
true
)
{
int
idx
=
0
;
GIRARA_LIST_FOREACH
(
priv
->
search
_results
,
zathura_rectangle_t
*
,
iter
,
rect
)
GIRARA_LIST_FOREACH
(
priv
->
search
.
list
,
zathura_rectangle_t
*
,
iter
,
rect
)
zathura_rectangle_t
rectangle
=
recalc_rectangle
(
priv
->
page
,
*
rect
);
/* draw position */
if
(
idx
==
priv
->
search
_
current
)
{
if
(
idx
==
priv
->
search
.
current
)
{
GdkColor
color
=
priv
->
zathura
->
ui
.
colors
.
highlight_color_active
;
cairo_set_source_rgba
(
cairo
,
color
.
red
,
color
.
green
,
color
.
blue
,
transparency
);
}
else
{
...
...
@@ -392,14 +411,14 @@ zathura_page_widget_draw(GtkWidget* widget, cairo_t* cairo)
(
rectangle
.
x2
-
rectangle
.
x1
),
(
rectangle
.
y2
-
rectangle
.
y1
));
cairo_fill
(
cairo
);
++
idx
;
GIRARA_LIST_FOREACH_END
(
priv
->
search
_results
,
zathura_rectangle_t
*
,
iter
,
rect
);
GIRARA_LIST_FOREACH_END
(
priv
->
search
.
list
,
zathura_rectangle_t
*
,
iter
,
rect
);
}
/* draw selection */
if
(
priv
->
selection
.
y2
!=
-
1
&&
priv
->
selection
.
x2
!=
-
1
)
{
if
(
priv
->
mouse
.
selection
.
y2
!=
-
1
&&
priv
->
mouse
.
selection
.
x2
!=
-
1
)
{
GdkColor
color
=
priv
->
zathura
->
ui
.
colors
.
highlight_color
;
cairo_set_source_rgba
(
cairo
,
color
.
red
,
color
.
green
,
color
.
blue
,
transparency
);
cairo_rectangle
(
cairo
,
priv
->
selection
.
x1
,
priv
->
selection
.
y1
,
(
priv
->
selection
.
x2
-
priv
->
selection
.
x1
),
(
priv
->
selection
.
y2
-
priv
->
selection
.
y1
));
cairo_rectangle
(
cairo
,
priv
->
mouse
.
selection
.
x1
,
priv
->
mouse
.
selection
.
y1
,
(
priv
->
mouse
.
selection
.
x2
-
priv
->
mouse
.
selection
.
x1
),
(
priv
->
mouse
.
selection
.
y2
-
priv
->
mouse
.
selection
.
y1
));
cairo_fill
(
cairo
);
}
}
else
{
...
...
@@ -494,9 +513,9 @@ zathura_page_widget_link_get(ZathuraPage* widget, unsigned int index)
zathura_page_widget_private_t
*
priv
=
ZATHURA_PAGE_GET_PRIVATE
(
widget
);
g_return_val_if_fail
(
priv
!=
NULL
,
NULL
);
if
(
priv
->
links
!=
NULL
&&
index
>=
priv
->
link
_
offset
&&
girara_list_size
(
priv
->
links
)
>
index
-
priv
->
link
_
offset
)
{
return
girara_list_nth
(
priv
->
links
,
index
-
priv
->
link
_
offset
);
if
(
priv
->
links
.
list
!=
NULL
&&
index
>=
priv
->
link
s
.
offset
&&
girara_list_size
(
priv
->
links
.
list
)
>
index
-
priv
->
link
s
.
offset
)
{
return
girara_list_nth
(
priv
->
links
.
list
,
index
-
priv
->
link
s
.
offset
);
}
else
{
return
NULL
;
}
...
...
@@ -513,20 +532,22 @@ cb_zathura_page_widget_button_press_event(GtkWidget* widget, GdkEventButton* but
if
(
button
->
button
==
1
)
{
/* left click */
if
(
button
->
type
==
GDK_BUTTON_PRESS
)
{
/* start the selection */
priv
->
selection_basepoint
.
x
=
button
->
x
;
priv
->
selection_basepoint
.
y
=
button
->
y
;
priv
->
selection
.
x1
=
button
->
x
;
priv
->
selection
.
y1
=
button
->
y
;
priv
->
selection
.
x2
=
button
->
x
;
priv
->
selection
.
y2
=
button
->
y
;
priv
->
mouse
.
selection_basepoint
.
x
=
button
->
x
;
priv
->
mouse
.
selection_basepoint
.
y
=
button
->
y
;
priv
->
mouse
.
selection
.
x1
=
button
->
x
;
priv
->
mouse
.
selection
.
y1
=
button
->
y
;
priv
->
mouse
.
selection
.
x2
=
button
->
x
;
priv
->
mouse
.
selection
.
y2
=
button
->
y
;
}
else
if
(
button
->
type
==
GDK_2BUTTON_PRESS
||
button
->
type
==
GDK_3BUTTON_PRESS
)
{
/* abort the selection */
priv
->
selection_basepoint
.
x
=
-
1
;
priv
->
selection_basepoint
.
y
=
-
1
;
priv
->
selection
.
x1
=
-
1
;
priv
->
selection
.
y1
=
-
1
;
priv
->
selection
.
x2
=
-
1
;
priv
->
selection
.
y2
=
-
1
;
priv
->
mouse
.
selection_basepoint
.
x
=
-
1
;
priv
->
mouse
.
selection_basepoint
.
y
=
-
1
;
priv
->
mouse
.
selection
.
x1
=
-
1
;
priv
->
mouse
.
selection
.
y1
=
-
1
;
priv
->
mouse
.
selection
.
x2
=
-
1
;
priv
->
mouse
.
selection
.
y2
=
-
1
;
}
return
true
;
...
...
@@ -550,27 +571,27 @@ cb_zathura_page_widget_button_release_event(GtkWidget* widget, GdkEventButton* b
zathura_page_widget_private_t
*
priv
=
ZATHURA_PAGE_GET_PRIVATE
(
widget
);
zathura_document_t
*
document
=
zathura_page_get_document
(
priv
->
page
);
if
(
priv
->
selection
.
y2
==
-
1
&&
priv
->
selection
.
x2
==
-
1
)
{
if
(
priv
->
mouse
.
selection
.
y2
==
-
1
&&
priv
->
mouse
.
selection
.
x2
==
-
1
)
{
/* simple single click */
/* get links */
if
(
priv
->
links
_got
==
false
)
{
priv
->
links
=
zathura_page_links_get
(
priv
->
page
,
NULL
);
priv
->
links
_got
=
true
;
priv
->
number_of_links
=
(
priv
->
links
==
NULL
)
?
0
:
girara_list_size
(
priv
->
links
);
if
(
priv
->
links
.
retrieved
==
false
)
{
priv
->
links
.
list
=
zathura_page_links_get
(
priv
->
page
,
NULL
);
priv
->
links
.
retrieved
=
true
;
priv
->
links
.
n
=
(
priv
->
links
.
list
==
NULL
)
?
0
:
girara_list_size
(
priv
->
links
.
list
);
}
if
(
priv
->
links
!=
NULL
&&
priv
->
number_of_
links
>
0
)
{
GIRARA_LIST_FOREACH
(
priv
->
links
,
zathura_link_t
*
,
iter
,
link
)
if
(
priv
->
links
.
list
!=
NULL
&&
priv
->
links
.
n
>
0
)
{
GIRARA_LIST_FOREACH
(
priv
->
links
.
list
,
zathura_link_t
*
,
iter
,
link
)
zathura_rectangle_t
rect
=
recalc_rectangle
(
priv
->
page
,
link
->
position
);
if
(
rect
.
x1
<=
button
->
x
&&
rect
.
x2
>=
button
->
x
&&
rect
.
y1
<=
button
->
y
&&
rect
.
y2
>=
button
->
y
)
{
zathura_link_evaluate
(
priv
->
zathura
,
link
);
}
GIRARA_LIST_FOREACH_END
(
priv
->
links
,
zathura_link_t
*
,
iter
,
link
);
GIRARA_LIST_FOREACH_END
(
priv
->
links
.
list
,
zathura_link_t
*
,
iter
,
link
);
}
}
else
{
redraw_rect
(
ZATHURA_PAGE
(
widget
),
&
priv
->
selection
);
zathura_rectangle_t
tmp
=
priv
->
selection
;
redraw_rect
(
ZATHURA_PAGE
(
widget
),
&
priv
->
mouse
.
selection
);
zathura_rectangle_t
tmp
=
priv
->
mouse
.
selection
;
double
scale
=
zathura_document_get_scale
(
document
);
tmp
.
x1
/=
scale
;
...
...
@@ -596,12 +617,13 @@ cb_zathura_page_widget_button_release_event(GtkWidget* widget, GdkEventButton* b
}
}
priv
->
selection_basepoint
.
x
=
-
1
;
priv
->
selection_basepoint
.
y
=
-
1
;
priv
->
selection
.
x1
=
-
1
;
priv
->
selection
.
y1
=
-
1
;
priv
->
selection
.
x2
=
-
1
;
priv
->
selection
.
y2
=
-
1
;
priv
->
mouse
.
selection_basepoint
.
x
=
-
1
;
priv
->
mouse
.
selection_basepoint
.
y
=
-
1
;
priv
->
mouse
.
selection
.
x1
=
-
1
;
priv
->
mouse
.
selection
.
y1
=
-
1
;
priv
->
mouse
.
selection
.
x2
=
-
1
;
priv
->
mouse
.
selection
.
y2
=
-
1
;
return
false
;
}
...
...
@@ -616,25 +638,25 @@ cb_zathura_page_widget_motion_notify(GtkWidget* widget, GdkEventMotion* event)
}
zathura_page_widget_private_t
*
priv
=
ZATHURA_PAGE_GET_PRIVATE
(
widget
);
zathura_rectangle_t
tmp
=
priv
->
selection
;
if
(
event
->
x
<
priv
->
selection_basepoint
.
x
)
{
zathura_rectangle_t
tmp
=
priv
->
mouse
.
selection
;
if
(
event
->
x
<
priv
->
mouse
.
selection_basepoint
.
x
)
{
tmp
.
x1
=
event
->
x
;
tmp
.
x2
=
priv
->
selection_basepoint
.
x
;
tmp
.
x2
=
priv
->
mouse
.
selection_basepoint
.
x
;
}
else
{
tmp
.
x2
=
event
->
x
;
tmp
.
x1
=
priv
->
selection_basepoint
.
x
;
tmp
.
x1
=
priv
->
mouse
.
selection_basepoint
.
x
;
}
if
(
event
->
y
<
priv
->
selection_basepoint
.
y
)
{
if
(
event
->
y
<
priv
->
mouse
.
selection_basepoint
.
y
)
{
tmp
.
y1
=
event
->
y
;
tmp
.
y2
=
priv
->
selection_basepoint
.
y
;
tmp
.
y2
=
priv
->
mouse
.
selection_basepoint
.
y
;
}
else
{
tmp
.
y1
=
priv
->
selection_basepoint
.
y
;
tmp
.
y1
=
priv
->
mouse
.
selection_basepoint
.
y
;
tmp
.
y2
=
event
->
y
;
}
redraw_rect
(
ZATHURA_PAGE
(
widget
),
&
priv
->
selection
);
redraw_rect
(
ZATHURA_PAGE
(
widget
),
&
priv
->
mouse
.
selection
);
redraw_rect
(
ZATHURA_PAGE
(
widget
),
&
tmp
);
priv
->
selection
=
tmp
;
priv
->
mouse
.
selection
=
tmp
;
return
false
;
}
...
...
@@ -650,29 +672,29 @@ zathura_page_widget_popup_menu(GtkWidget* widget, GdkEventButton* event)
return
;
#endif
if
(
priv
->
images
_got
==
false
)
{
priv
->
images
=
zathura_page_images_get
(
priv
->
page
,
NULL
);
priv
->
images
_got
=
true
;
if
(
priv
->
images
.
retrieved
==
false
)
{
priv
->
images
.
list
=
zathura_page_images_get
(
priv
->
page
,
NULL
);
priv
->
images
.
retrieved
=
true
;
}
if
(
priv
->
images
==
NULL
)
{
if
(
priv
->
images
.
list
==
NULL
)
{
return
;
}
/* search for underlaying image */
zathura_image_t
*
image
=
NULL
;
GIRARA_LIST_FOREACH
(
priv
->
images
,
zathura_image_t
*
,
iter
,
image_it
)
GIRARA_LIST_FOREACH
(
priv
->
images
.
list
,
zathura_image_t
*
,
iter
,
image_it
)
zathura_rectangle_t
rect
=
recalc_rectangle
(
priv
->
page
,
image_it
->
position
);
if
(
rect
.
x1
<=
event
->
x
&&
rect
.
x2
>=
event
->
x
&&
rect
.
y1
<=
event
->
y
&&
rect
.
y2
>=
event
->
y
)
{
image
=
image_it
;
}
GIRARA_LIST_FOREACH_END
(
priv
->
images
,
zathura_image_t
*
,
iter
,
image_it
);
GIRARA_LIST_FOREACH_END
(
priv
->
images
.
list
,
zathura_image_t
*
,
iter
,
image_it
);
if
(
image
==
NULL
)
{
return
;
}
priv
->
current
_image
=
image
;
priv
->
images
.
current
=
image
;
/* setup menu */
GtkWidget
*
menu
=
gtk_menu_new
();
...
...
@@ -722,9 +744,9 @@ cb_menu_image_copy(GtkMenuItem* item, ZathuraPage* page)
g_return_if_fail
(
item
!=
NULL
);
g_return_if_fail
(
page
!=
NULL
);
zathura_page_widget_private_t
*
priv
=
ZATHURA_PAGE_GET_PRIVATE
(
page
);
g_return_if_fail
(
priv
->
current
_image
!=
NULL
);
g_return_if_fail
(
priv
->
images
.
current
!=
NULL
);
cairo_surface_t
*
surface
=
zathura_page_image_get_cairo
(
priv
->
page
,
priv
->
current
_image
,
NULL
);
cairo_surface_t
*
surface
=
zathura_page_image_get_cairo
(
priv
->
page
,
priv
->
images
.
current
,
NULL
);
if
(
surface
==
NULL
)
{
return
;
}
...
...
@@ -746,7 +768,7 @@ cb_menu_image_copy(GtkMenuItem* item, ZathuraPage* page)
gtk_clipboard_set_image
(
gtk_clipboard_get
(
GDK_SELECTION_PRIMARY
),
pixbuf
);
/* reset */
priv
->
current
_image
=
NULL
;
priv
->
images
.
current
=
NULL
;
#endif
}
...
...
@@ -756,20 +778,20 @@ cb_menu_image_save(GtkMenuItem* item, ZathuraPage* page)
g_return_if_fail
(
item
!=
NULL
);
g_return_if_fail
(
page
!=
NULL
);
zathura_page_widget_private_t
*
priv
=
ZATHURA_PAGE_GET_PRIVATE
(
page
);
g_return_if_fail
(
priv
->
current
_image
!=
NULL
);
g_return_if_fail
(
priv
->
images
!=
NULL
);
g_return_if_fail
(
priv
->
images
.
current
!=
NULL
);
g_return_if_fail
(
priv
->
images
.
list
!=
NULL
);
/* generate image identifier */
unsigned
int
page_id
=
zathura_page_get_index
(
priv
->
page
)
+
1
;
unsigned
int
image_id
=
1
;
GIRARA_LIST_FOREACH
(
priv
->
images
,
zathura_image_t
*
,
iter
,
image_it
)
if
(
image_it
==
priv
->
current
_image
)
{
GIRARA_LIST_FOREACH
(
priv
->
images
.
list
,
zathura_image_t
*
,
iter
,
image_it
)
if
(
image_it
==
priv
->
images
.
current
)
{
break
;
}
image_id
++
;
GIRARA_LIST_FOREACH_END
(
priv
->
images
,
zathura_image_t
*
,
iter
,
image_it
);
GIRARA_LIST_FOREACH_END
(
priv
->
images
.
list
,
zathura_image_t
*
,
iter
,
image_it
);
/* set command */
char
*
export_command
=
g_strdup_printf
(
":export image-p%d-%d "
,
page_id
,
image_id
);
...
...
@@ -778,7 +800,7 @@ cb_menu_image_save(GtkMenuItem* item, ZathuraPage* page)
g_free
(
export_command
);
/* reset */
priv
->
current
_image
=
NULL
;
priv
->
images
.
current
=
NULL
;
}
void
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment