summaryrefslogtreecommitdiff
path: root/beos
diff options
context:
space:
mode:
authorFran├žois Revel <mmu_man@netsurf-browser.org>2008-10-10 21:43:25 +0000
committerFran├žois Revel <mmu_man@netsurf-browser.org>2008-10-10 21:43:25 +0000
commit4e79ee3d071df821f51f1a3f2d09bfedaa7af3b1 (patch)
tree75956bc92b844280da04395b9d80f2c4e6b324c7 /beos
parente4fba7f577d44f3235b2c430191d96ddfc084827 (diff)
downloadnetsurf-4e79ee3d071df821f51f1a3f2d09bfedaa7af3b1.tar.gz
netsurf-4e79ee3d071df821f51f1a3f2d09bfedaa7af3b1.tar.bz2
- 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
Diffstat (limited to 'beos')
-rw-r--r--beos/beos_bitmap.cpp11
-rw-r--r--beos/beos_font.cpp18
-rw-r--r--beos/beos_font.h3
-rw-r--r--beos/beos_gui.cpp18
-rw-r--r--beos/beos_gui.h2
-rw-r--r--beos/beos_scaffolding.cpp2
-rw-r--r--beos/beos_thumbnail.cpp2
-rw-r--r--beos/beos_window.cpp35
8 files changed, 75 insertions, 16 deletions
diff --git a/beos/beos_bitmap.cpp b/beos/beos_bitmap.cpp
index 989fefc4a..0ee14d9b9 100644
--- a/beos/beos_bitmap.cpp
+++ b/beos/beos_bitmap.cpp
@@ -38,6 +38,7 @@ extern "C" {
#include "utils/log.h"
}
#include "beos/beos_bitmap.h"
+#include "beos/beos_gui.h"
#include "beos/beos_scaffolding.h"
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)
{
+ CALLED();
struct bitmap *bmp = (struct bitmap *)malloc(sizeof(struct bitmap));
if (bmp == 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);
//XXX: bytes per row ?
- bmp->primary = new BBitmap(frame, 0, B_RGBA32);
- bmp->shadow = new BBitmap(frame, 0, B_RGBA32);
+ bmp->primary = new BBitmap(frame, flags, B_RGBA32);
+ bmp->shadow = new BBitmap(frame, flags, B_RGBA32);
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()
*/
void bitmap_modified(void *vbitmap) {
+ CALLED();
struct bitmap *bitmap = (struct bitmap *)vbitmap;
// convert the shadow (ABGR) to into the primary bitmap
nsbeos_rgba_to_bgra(bitmap->shadow->Bits(), bitmap->primary->Bits(),
diff --git a/beos/beos_font.cpp b/beos/beos_font.cpp
index 15b865ea8..9f7ed34f9 100644
--- a/beos/beos_font.cpp
+++ b/beos/beos_font.cpp
@@ -42,8 +42,6 @@ extern "C" {
#include "beos/beos_font.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,
const char *string, size_t length,
int *width);
@@ -84,7 +82,7 @@ bool nsfont_width(const struct css_style *style,
return true;
}
- nsfont_style_to_font(font, style);
+ nsbeos_style_to_font(font, style);
*width = (int)font.StringWidth(string, length);
return true;
}
@@ -134,7 +132,7 @@ bool nsfont_position_in_string(const struct css_style *style,
int index;
BFont font;
- nsfont_style_to_font(font, style);
+ nsbeos_style_to_font(font, style);
BString str(string);
int32 len = str.CountChars();
float escapements[len];
@@ -184,7 +182,7 @@ bool nsfont_split(const struct css_style *style,
int index = 0;
BFont font;
- nsfont_style_to_font(font, style);
+ nsbeos_style_to_font(font, style);
BString str(string);
int32 len = str.CountChars();
float escapements[len];
@@ -245,7 +243,7 @@ bool nsfont_paint(const struct css_style *style,
if (length == 0)
return true;
- nsfont_style_to_font(font, style);
+ nsbeos_style_to_font(font, style);
background = nsbeos_rgb_colour(bg);
foreground = nsbeos_rgb_colour(c);
@@ -296,7 +294,7 @@ bool nsfont_paint(const struct css_style *style,
* \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)
{
float size;
@@ -378,7 +376,7 @@ static void nsfont_style_to_font(BFont &font,
if (!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)
font.SetFamilyAndFace((const font_family)family, face);
@@ -388,7 +386,7 @@ static void nsfont_style_to_font(BFont &font,
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)
size = style->font_size.value.length.value;
else
@@ -399,7 +397,7 @@ static void nsfont_style_to_font(BFont &font,
if (size < abs(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);
}
diff --git a/beos/beos_font.h b/beos/beos_font.h
index e6aa39337..2dab57e3d 100644
--- a/beos/beos_font.h
+++ b/beos/beos_font.h
@@ -28,3 +28,6 @@ struct css_style;
bool nsfont_paint(const struct css_style *style,
const char *string, size_t length,
int x, int y, colour bg, colour c);
+
+void nsbeos_style_to_font(BFont &font,
+ const struct css_style *style);
diff --git a/beos/beos_gui.cpp b/beos/beos_gui.cpp
index f762afe82..94d1f1066 100644
--- a/beos/beos_gui.cpp
+++ b/beos/beos_gui.cpp
@@ -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.
*/
-void nsbeos_gui_view_source(struct content *content)
+void nsbeos_gui_view_source(struct content *content, struct selection *selection)
{
char *temp_name;
bool done = false;
@@ -867,6 +867,22 @@ void nsbeos_gui_view_source(struct content *content)
BMessage m(B_REFS_RECEIVED);
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
const char *editorSigs[] = {
"application/x-vnd.beunited.pe",
diff --git a/beos/beos_gui.h b/beos/beos_gui.h
index c6d2fdef6..a82c8fb2d 100644
--- a/beos/beos_gui.h
+++ b/beos/beos_gui.h
@@ -58,5 +58,5 @@ extern BFilePanel *wndOpenFile;
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_gui_view_source(struct content *content);
+void nsbeos_gui_view_source(struct content *content, struct selection *selection);
diff --git a/beos/beos_scaffolding.cpp b/beos/beos_scaffolding.cpp
index ad1d873cb..a29b6f35a 100644
--- a/beos/beos_scaffolding.cpp
+++ b/beos/beos_scaffolding.cpp
@@ -578,7 +578,7 @@ void nsbeos_scaffolding_dispatch_event(nsbeos_scaffolding *scaffold, BMessage *m
{
if (!bw || !bw->current_content)
break;
- nsbeos_gui_view_source(bw->current_content);
+ nsbeos_gui_view_source(bw->current_content, bw->sel);
break;
}
case BROWSER_OBJECT:
diff --git a/beos/beos_thumbnail.cpp b/beos/beos_thumbnail.cpp
index 8a178e36c..78893467f 100644
--- a/beos/beos_thumbnail.cpp
+++ b/beos/beos_thumbnail.cpp
@@ -76,7 +76,7 @@ bool thumbnail_create(struct content *content, struct bitmap *bitmap,
depth = 32;
//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,
content->width, content->width, depth));
diff --git a/beos/beos_window.cpp b/beos/beos_window.cpp
index f51b5253b..32398a6e9 100644
--- a/beos/beos_window.cpp
+++ b/beos/beos_window.cpp
@@ -32,6 +32,7 @@ extern "C" {
#include "utils/utils.h"
}
#include "beos/beos_window.h"
+#include "beos/beos_font.h"
#include "beos/beos_gui.h"
#include "beos/beos_scaffolding.h"
#include "beos/beos_plotters.h"
@@ -46,6 +47,7 @@ extern "C" {
#include <ScrollBar.h>
#include <String.h>
#include <String.h>
+#include <TextView.h>
#include <View.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 BString current_selection;
+static BList current_selection_textruns;
static void nsbeos_gui_window_attach_child(struct gui_window *parent,
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)
{
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())
return;
@@ -1773,6 +1780,10 @@ void gui_paste_from_clipboard(struct gui_window *g, int x, int y)
bool gui_empty_clipboard(void)
{
current_selection.Truncate(0);
+ while (current_selection_textruns.ItemAt(0)) {
+ text_run *run = (text_run *)current_selection_textruns.RemoveItem(0L);
+ delete run;
+ }
return true;
}
@@ -1800,6 +1811,17 @@ bool gui_commit_clipboard(void)
clip->AddData("text/plain", B_MIME_TYPE,
current_selection.String(),
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();
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,
size_t whitespace_length)
{
+ //XXX: handle box->style to StyledEdit / RTF ?
/* add any whitespace which precedes the text from this box */
if (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;
}
}
+
+ // 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 */
if (!gui_add_to_clipboard(text, length, box->space))
return false;