mirror of
https://github.com/netsurf-browser/netsurf
synced 2024-12-23 20:46:50 +03:00
- support BITMAP_CLEAR_MEMORY in create_bitmap()
- copying to clipboard now constructs a text_run_array for StyledEdit, that is added to the clipboard. In applications supporting it it pastes the text with the correct fonts and sizes, and the text colors. - tried to find which line in source code the selection starts to open the editor there, but it's not finished so it's disabled. svn path=/trunk/netsurf/; revision=5533
This commit is contained in:
parent
e4fba7f577
commit
4e79ee3d07
@ -38,6 +38,7 @@ extern "C" {
|
|||||||
#include "utils/log.h"
|
#include "utils/log.h"
|
||||||
}
|
}
|
||||||
#include "beos/beos_bitmap.h"
|
#include "beos/beos_bitmap.h"
|
||||||
|
#include "beos/beos_gui.h"
|
||||||
#include "beos/beos_scaffolding.h"
|
#include "beos/beos_scaffolding.h"
|
||||||
|
|
||||||
struct bitmap {
|
struct bitmap {
|
||||||
@ -105,14 +106,19 @@ static inline void nsbeos_rgba_to_bgra(void *src, void *dst, int width, int heig
|
|||||||
|
|
||||||
void *bitmap_create(int width, int height, unsigned int state)
|
void *bitmap_create(int width, int height, unsigned int state)
|
||||||
{
|
{
|
||||||
|
CALLED();
|
||||||
struct bitmap *bmp = (struct bitmap *)malloc(sizeof(struct bitmap));
|
struct bitmap *bmp = (struct bitmap *)malloc(sizeof(struct bitmap));
|
||||||
if (bmp == NULL)
|
if (bmp == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
int32 flags = 0;
|
||||||
|
if (state & BITMAP_CLEAR_MEMORY)
|
||||||
|
flags |= B_BITMAP_CLEAR_TO_WHITE;
|
||||||
|
|
||||||
BRect frame(0, 0, width - 1, height - 1);
|
BRect frame(0, 0, width - 1, height - 1);
|
||||||
//XXX: bytes per row ?
|
//XXX: bytes per row ?
|
||||||
bmp->primary = new BBitmap(frame, 0, B_RGBA32);
|
bmp->primary = new BBitmap(frame, flags, B_RGBA32);
|
||||||
bmp->shadow = new BBitmap(frame, 0, B_RGBA32);
|
bmp->shadow = new BBitmap(frame, flags, B_RGBA32);
|
||||||
|
|
||||||
bmp->pretile_x = bmp->pretile_y = bmp->pretile_xy = NULL;
|
bmp->pretile_x = bmp->pretile_y = bmp->pretile_xy = NULL;
|
||||||
|
|
||||||
@ -286,6 +292,7 @@ bool bitmap_save(void *vbitmap, const char *path, unsigned flags)
|
|||||||
* \param vbitmap a bitmap, as returned by bitmap_create()
|
* \param vbitmap a bitmap, as returned by bitmap_create()
|
||||||
*/
|
*/
|
||||||
void bitmap_modified(void *vbitmap) {
|
void bitmap_modified(void *vbitmap) {
|
||||||
|
CALLED();
|
||||||
struct bitmap *bitmap = (struct bitmap *)vbitmap;
|
struct bitmap *bitmap = (struct bitmap *)vbitmap;
|
||||||
// convert the shadow (ABGR) to into the primary bitmap
|
// convert the shadow (ABGR) to into the primary bitmap
|
||||||
nsbeos_rgba_to_bgra(bitmap->shadow->Bits(), bitmap->primary->Bits(),
|
nsbeos_rgba_to_bgra(bitmap->shadow->Bits(), bitmap->primary->Bits(),
|
||||||
|
@ -42,8 +42,6 @@ extern "C" {
|
|||||||
#include "beos/beos_font.h"
|
#include "beos/beos_font.h"
|
||||||
#include "beos/beos_plotters.h"
|
#include "beos/beos_plotters.h"
|
||||||
|
|
||||||
static void nsfont_style_to_font(BFont &font,
|
|
||||||
const struct css_style *style);
|
|
||||||
static bool nsfont_width(const struct css_style *style,
|
static bool nsfont_width(const struct css_style *style,
|
||||||
const char *string, size_t length,
|
const char *string, size_t length,
|
||||||
int *width);
|
int *width);
|
||||||
@ -84,7 +82,7 @@ bool nsfont_width(const struct css_style *style,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
nsfont_style_to_font(font, style);
|
nsbeos_style_to_font(font, style);
|
||||||
*width = (int)font.StringWidth(string, length);
|
*width = (int)font.StringWidth(string, length);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -134,7 +132,7 @@ bool nsfont_position_in_string(const struct css_style *style,
|
|||||||
int index;
|
int index;
|
||||||
BFont font;
|
BFont font;
|
||||||
|
|
||||||
nsfont_style_to_font(font, style);
|
nsbeos_style_to_font(font, style);
|
||||||
BString str(string);
|
BString str(string);
|
||||||
int32 len = str.CountChars();
|
int32 len = str.CountChars();
|
||||||
float escapements[len];
|
float escapements[len];
|
||||||
@ -184,7 +182,7 @@ bool nsfont_split(const struct css_style *style,
|
|||||||
int index = 0;
|
int index = 0;
|
||||||
BFont font;
|
BFont font;
|
||||||
|
|
||||||
nsfont_style_to_font(font, style);
|
nsbeos_style_to_font(font, style);
|
||||||
BString str(string);
|
BString str(string);
|
||||||
int32 len = str.CountChars();
|
int32 len = str.CountChars();
|
||||||
float escapements[len];
|
float escapements[len];
|
||||||
@ -245,7 +243,7 @@ bool nsfont_paint(const struct css_style *style,
|
|||||||
if (length == 0)
|
if (length == 0)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
nsfont_style_to_font(font, style);
|
nsbeos_style_to_font(font, style);
|
||||||
background = nsbeos_rgb_colour(bg);
|
background = nsbeos_rgb_colour(bg);
|
||||||
foreground = nsbeos_rgb_colour(c);
|
foreground = nsbeos_rgb_colour(c);
|
||||||
|
|
||||||
@ -296,7 +294,7 @@ bool nsfont_paint(const struct css_style *style,
|
|||||||
* \return a new Pango font description
|
* \return a new Pango font description
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static void nsfont_style_to_font(BFont &font,
|
void nsbeos_style_to_font(BFont &font,
|
||||||
const struct css_style *style)
|
const struct css_style *style)
|
||||||
{
|
{
|
||||||
float size;
|
float size;
|
||||||
@ -378,7 +376,7 @@ static void nsfont_style_to_font(BFont &font,
|
|||||||
if (!face)
|
if (!face)
|
||||||
face = B_REGULAR_FACE;
|
face = B_REGULAR_FACE;
|
||||||
|
|
||||||
//fprintf(stderr, "nsfont_style_to_font: %d, %d, %d -> '%s' %04x\n", style->font_family, style->font_style, style->font_weight, family, face);
|
//fprintf(stderr, "nsbeos_style_to_font: %d, %d, %d -> '%s' %04x\n", style->font_family, style->font_style, style->font_weight, family, face);
|
||||||
|
|
||||||
if (family)
|
if (family)
|
||||||
font.SetFamilyAndFace((const font_family)family, face);
|
font.SetFamilyAndFace((const font_family)family, face);
|
||||||
@ -388,7 +386,7 @@ static void nsfont_style_to_font(BFont &font,
|
|||||||
font.SetFace(face);
|
font.SetFace(face);
|
||||||
}
|
}
|
||||||
|
|
||||||
//fprintf(stderr, "nsfont_style_to_font: value %f unit %d\n", style->font_size.value.length.value, style->font_size.value.length.unit);
|
//fprintf(stderr, "nsbeos_style_to_font: value %f unit %d\n", style->font_size.value.length.value, style->font_size.value.length.unit);
|
||||||
if (style->font_size.value.length.unit == CSS_UNIT_PT)
|
if (style->font_size.value.length.unit == CSS_UNIT_PT)
|
||||||
size = style->font_size.value.length.value;
|
size = style->font_size.value.length.value;
|
||||||
else
|
else
|
||||||
@ -399,7 +397,7 @@ static void nsfont_style_to_font(BFont &font,
|
|||||||
if (size < abs(option_font_min_size / 10))
|
if (size < abs(option_font_min_size / 10))
|
||||||
size = option_font_min_size / 10;
|
size = option_font_min_size / 10;
|
||||||
|
|
||||||
//fprintf(stderr, "nsfont_style_to_font: %f %d\n", size, style->font_size.value.length.unit);
|
//fprintf(stderr, "nsbeos_style_to_font: %f %d\n", size, style->font_size.value.length.unit);
|
||||||
|
|
||||||
font.SetSize(size);
|
font.SetSize(size);
|
||||||
}
|
}
|
||||||
|
@ -28,3 +28,6 @@ struct css_style;
|
|||||||
bool nsfont_paint(const struct css_style *style,
|
bool nsfont_paint(const struct css_style *style,
|
||||||
const char *string, size_t length,
|
const char *string, size_t length,
|
||||||
int x, int y, colour bg, colour c);
|
int x, int y, colour bg, colour c);
|
||||||
|
|
||||||
|
void nsbeos_style_to_font(BFont &font,
|
||||||
|
const struct css_style *style);
|
||||||
|
@ -807,7 +807,7 @@ void gui_window_save_as_link(struct gui_window *g, struct content *c)
|
|||||||
* Send the source of a content to a text editor.
|
* Send the source of a content to a text editor.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void nsbeos_gui_view_source(struct content *content)
|
void nsbeos_gui_view_source(struct content *content, struct selection *selection)
|
||||||
{
|
{
|
||||||
char *temp_name;
|
char *temp_name;
|
||||||
bool done = false;
|
bool done = false;
|
||||||
@ -867,6 +867,22 @@ void nsbeos_gui_view_source(struct content *content)
|
|||||||
BMessage m(B_REFS_RECEIVED);
|
BMessage m(B_REFS_RECEIVED);
|
||||||
m.AddRef("refs", &ref);
|
m.AddRef("refs", &ref);
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
if (selection && selection->defined) {
|
||||||
|
int32 line = -1;
|
||||||
|
if (content->type == CONTENT_HTML) {
|
||||||
|
// XXX: use selection, find line in source code
|
||||||
|
}
|
||||||
|
if (content->type == CONTENT_TEXTPLAIN) {
|
||||||
|
line = MAKELINE_FROM_IDX(start_idx);
|
||||||
|
}
|
||||||
|
// not CSS!
|
||||||
|
|
||||||
|
if (line > -1)
|
||||||
|
message.AddInt32("be:line", line);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
// apps to try
|
// apps to try
|
||||||
const char *editorSigs[] = {
|
const char *editorSigs[] = {
|
||||||
"application/x-vnd.beunited.pe",
|
"application/x-vnd.beunited.pe",
|
||||||
|
@ -58,5 +58,5 @@ extern BFilePanel *wndOpenFile;
|
|||||||
void nsbeos_pipe_message(BMessage *message, BView *_this, struct gui_window *gui);
|
void nsbeos_pipe_message(BMessage *message, BView *_this, struct gui_window *gui);
|
||||||
void nsbeos_pipe_message_top(BMessage *message, BWindow *_this, struct beos_scaffolding *scaffold);
|
void nsbeos_pipe_message_top(BMessage *message, BWindow *_this, struct beos_scaffolding *scaffold);
|
||||||
|
|
||||||
void nsbeos_gui_view_source(struct content *content);
|
void nsbeos_gui_view_source(struct content *content, struct selection *selection);
|
||||||
|
|
||||||
|
@ -578,7 +578,7 @@ void nsbeos_scaffolding_dispatch_event(nsbeos_scaffolding *scaffold, BMessage *m
|
|||||||
{
|
{
|
||||||
if (!bw || !bw->current_content)
|
if (!bw || !bw->current_content)
|
||||||
break;
|
break;
|
||||||
nsbeos_gui_view_source(bw->current_content);
|
nsbeos_gui_view_source(bw->current_content, bw->sel);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case BROWSER_OBJECT:
|
case BROWSER_OBJECT:
|
||||||
|
@ -76,7 +76,7 @@ bool thumbnail_create(struct content *content, struct bitmap *bitmap,
|
|||||||
depth = 32;
|
depth = 32;
|
||||||
//depth = (gdk_screen_get_system_visual(gdk_screen_get_default()))->depth;
|
//depth = (gdk_screen_get_system_visual(gdk_screen_get_default()))->depth;
|
||||||
|
|
||||||
LOG(("Trying to create a thumbnail bitmap %dx%d for a content of %dx%d@%d",
|
LOG(("Trying to create a thumbnail bitmap %d x %d for a content of %d x %d @ %d",
|
||||||
width, height,
|
width, height,
|
||||||
content->width, content->width, depth));
|
content->width, content->width, depth));
|
||||||
|
|
||||||
|
@ -32,6 +32,7 @@ extern "C" {
|
|||||||
#include "utils/utils.h"
|
#include "utils/utils.h"
|
||||||
}
|
}
|
||||||
#include "beos/beos_window.h"
|
#include "beos/beos_window.h"
|
||||||
|
#include "beos/beos_font.h"
|
||||||
#include "beos/beos_gui.h"
|
#include "beos/beos_gui.h"
|
||||||
#include "beos/beos_scaffolding.h"
|
#include "beos/beos_scaffolding.h"
|
||||||
#include "beos/beos_plotters.h"
|
#include "beos/beos_plotters.h"
|
||||||
@ -46,6 +47,7 @@ extern "C" {
|
|||||||
#include <ScrollBar.h>
|
#include <ScrollBar.h>
|
||||||
#include <String.h>
|
#include <String.h>
|
||||||
#include <String.h>
|
#include <String.h>
|
||||||
|
#include <TextView.h>
|
||||||
#include <View.h>
|
#include <View.h>
|
||||||
#include <Window.h>
|
#include <Window.h>
|
||||||
|
|
||||||
@ -104,6 +106,7 @@ static const rgb_color kWhiteColor = {255, 255, 255, 255};
|
|||||||
static struct gui_window *window_list = 0; /**< first entry in win list*/
|
static struct gui_window *window_list = 0; /**< first entry in win list*/
|
||||||
|
|
||||||
static BString current_selection;
|
static BString current_selection;
|
||||||
|
static BList current_selection_textruns;
|
||||||
|
|
||||||
static void nsbeos_gui_window_attach_child(struct gui_window *parent,
|
static void nsbeos_gui_window_attach_child(struct gui_window *parent,
|
||||||
struct gui_window *child);
|
struct gui_window *child);
|
||||||
@ -1744,6 +1747,10 @@ void gui_drag_save_selection(struct selection *s, struct gui_window *g)
|
|||||||
void gui_start_selection(struct gui_window *g)
|
void gui_start_selection(struct gui_window *g)
|
||||||
{
|
{
|
||||||
current_selection.Truncate(0);
|
current_selection.Truncate(0);
|
||||||
|
while (current_selection_textruns.ItemAt(0)) {
|
||||||
|
text_run *run = (text_run *)current_selection_textruns.RemoveItem(0L);
|
||||||
|
delete run;
|
||||||
|
}
|
||||||
|
|
||||||
if (!g->view->LockLooper())
|
if (!g->view->LockLooper())
|
||||||
return;
|
return;
|
||||||
@ -1773,6 +1780,10 @@ void gui_paste_from_clipboard(struct gui_window *g, int x, int y)
|
|||||||
bool gui_empty_clipboard(void)
|
bool gui_empty_clipboard(void)
|
||||||
{
|
{
|
||||||
current_selection.Truncate(0);
|
current_selection.Truncate(0);
|
||||||
|
while (current_selection_textruns.ItemAt(0)) {
|
||||||
|
text_run *run = (text_run *)current_selection_textruns.RemoveItem(0L);
|
||||||
|
delete run;
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1800,6 +1811,17 @@ bool gui_commit_clipboard(void)
|
|||||||
clip->AddData("text/plain", B_MIME_TYPE,
|
clip->AddData("text/plain", B_MIME_TYPE,
|
||||||
current_selection.String(),
|
current_selection.String(),
|
||||||
current_selection.Length());
|
current_selection.Length());
|
||||||
|
int arraySize = sizeof(text_run_array) +
|
||||||
|
current_selection_textruns.CountItems() * sizeof(text_run);
|
||||||
|
text_run_array *array = (text_run_array *)malloc(arraySize);
|
||||||
|
array->count = current_selection_textruns.CountItems();
|
||||||
|
for (int i = 0; i < array->count; i++)
|
||||||
|
memcpy(&array->runs[i], current_selection_textruns.ItemAt(i),
|
||||||
|
sizeof(text_run));
|
||||||
|
clip->AddData("application/x-vnd.Be-text_run_array", B_MIME_TYPE,
|
||||||
|
array, arraySize);
|
||||||
|
free(array);
|
||||||
|
|
||||||
gui_empty_clipboard();
|
gui_empty_clipboard();
|
||||||
be_clipboard->Commit();
|
be_clipboard->Commit();
|
||||||
}
|
}
|
||||||
@ -1812,6 +1834,7 @@ static bool copy_handler(const char *text, size_t length, struct box *box,
|
|||||||
void *handle, const char *whitespace_text,
|
void *handle, const char *whitespace_text,
|
||||||
size_t whitespace_length)
|
size_t whitespace_length)
|
||||||
{
|
{
|
||||||
|
//XXX: handle box->style to StyledEdit / RTF ?
|
||||||
/* add any whitespace which precedes the text from this box */
|
/* add any whitespace which precedes the text from this box */
|
||||||
if (whitespace_text) {
|
if (whitespace_text) {
|
||||||
if (!gui_add_to_clipboard(whitespace_text,
|
if (!gui_add_to_clipboard(whitespace_text,
|
||||||
@ -1819,6 +1842,18 @@ static bool copy_handler(const char *text, size_t length, struct box *box,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// add a text_run for StyledEdit-like text formating
|
||||||
|
if (box && box->style) {
|
||||||
|
text_run *run = new text_run;
|
||||||
|
BFont font;
|
||||||
|
nsbeos_style_to_font(font, box->style);
|
||||||
|
run->offset = current_selection.Length();
|
||||||
|
run->font = font;
|
||||||
|
run->color = nsbeos_rgb_colour(box->style->color);
|
||||||
|
current_selection_textruns.AddItem(run);
|
||||||
|
}
|
||||||
|
|
||||||
/* add the text from this box */
|
/* add the text from this box */
|
||||||
if (!gui_add_to_clipboard(text, length, box->space))
|
if (!gui_add_to_clipboard(text, length, box->space))
|
||||||
return false;
|
return false;
|
||||||
|
Loading…
Reference in New Issue
Block a user