* Better looking html.

* Set mime type when exporting to file.
* disable netpositive stuff (only css).
* export only the table when not saving to file (clipboard).


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@23850 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
François Revol 2008-02-03 18:38:47 +00:00
parent 08f2fdac37
commit 495bcef7a8

View File

@ -17,6 +17,7 @@
#include <Application.h> #include <Application.h>
#include <Beep.h> #include <Beep.h>
#include <File.h> #include <File.h>
#include <NodeInfo.h>
#include <Path.h> #include <Path.h>
@ -209,10 +210,14 @@ status_t
SudokuView::SaveTo(BDataIO &stream, uint32 as) SudokuView::SaveTo(BDataIO &stream, uint32 as)
{ {
BString text; BString text;
//BFile *file; BFile *file = dynamic_cast<BFile *>(&stream);
char *line; char *line;
uint32 i = 0; uint32 i = 0;
status_t status = EINVAL; status_t status = EINVAL;
BNodeInfo nodeInfo;
if (file)
nodeInfo.SetTo(file);
switch (as) { switch (as) {
case kExportAsText: case kExportAsText:
@ -232,18 +237,28 @@ SudokuView::SaveTo(BDataIO &stream, uint32 as)
text.UnlockBuffer(); text.UnlockBuffer();
stream.Write(text.String(), text.Length()); stream.Write(text.String(), text.Length());
if (file)
nodeInfo.SetType("text/plain");
return B_OK; return B_OK;
case kExportAsHTML: case kExportAsHTML:
{ {
bool netPositiveFriendly = false;
text = "<html>\n<head>\n<!-- Written by Sudoku -->\n" text = "<html>\n<head>\n<!-- Written by Sudoku -->\n"
"<style type=\"text/css\">\n" "<style type=\"text/css\">\n"
"table.sudoku { border: 1px solid black; width=\"300px\"; height=\"300px\"; }\n" "table.sudoku { background: #000000; border:0; cellpadding: 10px; cellspacing: 1px; width: 300px; height: 300px; }\n"
"td.sudoku_initial { background: #f0f0f0; }\n" "td.sudoku { background: #ffffff; border: 0; text-align: center; }\n"
"td.sudoku_filled { background: #f0f0f0; color: blue; }\n" "td.sudoku_initial { }\n"
"td.sudoku_empty { background: #f0f0f0; }\n" "td.sudoku_filled { color: blue; }\n"
"td.sudoku_empty { }\n"
"</style>\n" "</style>\n"
"</head>\n<body>\n\n" "</head>\n<body>\n\n";
"<table " /*"border=\"1\""*/ " class=\"sudoku\">"; if (file)
stream.Write(text.String(), text.Length());
text = "<table";
if (netPositiveFriendly)
text << " border=\"1\"";
text << " class=\"sudoku\">";
stream.Write(text.String(), text.Length()); stream.Write(text.String(), text.Length());
//XXX: make border larger on %3 //XXX: make border larger on %3
@ -257,17 +272,21 @@ SudokuView::SaveTo(BDataIO &stream, uint32 as)
char buff[2]; char buff[2];
_SetText(buff, fField->ValueAt(x, y)); _SetText(buff, fField->ValueAt(x, y));
if (fField->ValueAt(x, y) == 0) { if (fField->ValueAt(x, y) == 0) {
text << "<td width=\"" << divider << "\" class=\"sudoku_empty\">\n"; text << "<td width=\"" << divider << "\" class=\"sudoku sudoku_empty\">\n";
text << "&nbsp;"; text << "&nbsp;";
} else if (fField->FlagsAt(x, y) & kInitialValue) { } else if (fField->FlagsAt(x, y) & kInitialValue) {
text << "<td width=\"" << divider << "\" class=\"sudoku_initial\">\n"; text << "<td width=\"" << divider << "\" class=\"sudoku sudoku_initial\">\n";
if (netPositiveFriendly)
text << "<font color=\"#000000\">"; text << "<font color=\"#000000\">";
text << buff; text << buff;
if (netPositiveFriendly)
text << "</font>"; text << "</font>";
} else { } else {
text << "<td width=\"" << divider << "\" class=\"sudoku_filled\">\n"; text << "<td width=\"" << divider << "\" class=\"sudoku sudoku_filled\">\n";
if (netPositiveFriendly)
text << "<font color=\"#0000ff\">"; text << "<font color=\"#0000ff\">";
text << buff; text << buff;
if (netPositiveFriendly)
text << "</font>"; text << "</font>";
} }
text << "</td>\n"; text << "</td>\n";
@ -278,7 +297,10 @@ SudokuView::SaveTo(BDataIO &stream, uint32 as)
stream.Write(text.String(), text.Length()); stream.Write(text.String(), text.Length());
text = "</body></html>\n"; text = "</body></html>\n";
if (file)
stream.Write(text.String(), text.Length()); stream.Write(text.String(), text.Length());
if (file)
nodeInfo.SetType("text/html");
return B_OK; return B_OK;
} }
case kExportAsBitmap: case kExportAsBitmap: