wxWebView,how to set the text style

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
wxKevin
Earned a small fee
Earned a small fee
Posts: 21
Joined: Fri Jun 09, 2017 7:45 am

wxWebView,how to set the text style

Post by wxKevin »

I need to do a edit box, which can display rich content,so I set the wxWebView editor state, it works, but do not know how to change the text style, such as: bold font, set the font color ...
thanks in advance!
User avatar
doublemax
Moderator
Moderator
Posts: 19161
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxWebView,how to set the text style

Post by doublemax »

I'm not sure wxWebView is the best choice for this. Have you checked wxRichTextCtrl?
Use the source, Luke!
wxKevin
Earned a small fee
Earned a small fee
Posts: 21
Joined: Fri Jun 09, 2017 7:45 am

Re: wxWebView,how to set the text style

Post by wxKevin »

yea, I tried it. But can not meet my needs,because the pasted things are not formatted(font and color and other styles).
And I found that many clients are using html editing, like my uploaded attachments
Thanks.
User avatar
doublemax
Moderator
Moderator
Posts: 19161
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxWebView,how to set the text style

Post by doublemax »

After looking through the sources, i have to say that there is practically no support for edit mode in the public wxWebView API. If you need a Windows solution only, it might be possible to access the underlying MSHTML control directly, but you'll have to build all edit controls yourself and then send the commands to the MSHTML control.

Here are the possible commands:
https://msdn.microsoft.com/en-us/librar ... 85%29.aspx

The needed methods in wxWebViewIE are all private, e.g.

Code: Select all

wxCOMPtr<IHTMLDocument2> wxWebViewIE::GetDocument() const
void wxWebViewIE::ExecCommand(wxString command)
It'll probably take some effort to make this work, i'm not sure it's worth it.
Use the source, Luke!
wxKevin
Earned a small fee
Earned a small fee
Posts: 21
Joined: Fri Jun 09, 2017 7:45 am

Re: wxWebView,how to set the text style

Post by wxKevin »

Ok, it looks complicated, then i want to achieve the current needs, how should i do?
I have no clue now。 :(
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7480
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: wxWebView,how to set the text style

Post by ONEEYEMAN »

Hi,
Use wxRichTextCtrl or just wxTextCtrl.
If you need to do the C&P, it is much easier to modify the content of this control with attributes.

Check the appropriate samples on how to do that.

Thank you.
wxKevin
Earned a small fee
Earned a small fee
Posts: 21
Joined: Fri Jun 09, 2017 7:45 am

Re: wxWebView,how to set the text style

Post by wxKevin »

I used wxRichTextCtrl before, but found that the content from the clipboard pasted no format, and even can not copy the form, pictures.
Observe that a lot of this similar client, using the cef3 (Chrome browser)
RobertHK
I live to help wx-kind
I live to help wx-kind
Posts: 158
Joined: Sat Dec 01, 2012 6:43 am

Re: wxWebView,how to set the text style

Post by RobertHK »

Hi, I use an intuitive "Kompozer" where I set everything I need (table...etc.) and then convert the html code to c ++. If you want. I'll send a sample.
RobertHK
I live to help wx-kind
I live to help wx-kind
Posts: 158
Joined: Sat Dec 01, 2012 6:43 am

Re: wxWebView,how to set the text style

Post by RobertHK »

Hi, I use an intuitive "Kompozer" where I set everything I need (table...etc.) and then convert the html code to c ++. If you want. I'll send a sample.
User avatar
evstevemd
Part Of The Furniture
Part Of The Furniture
Posts: 2409
Joined: Wed Jan 28, 2009 11:57 am
Location: United Republic of Tanzania

Re: wxWebView,how to set the text style

Post by evstevemd »

wxKevin wrote:yea, I tried it. But can not meet my needs,because the pasted things are not formatted(font and color and other styles).
And I found that many clients are using html editing, like my uploaded attachments
Thanks.
While am not sure about if you can copy the underlying buffer of the selection (which contains styling info) but am sure you can paste HTML and preserve the format. Just Bind your function to OnPaste and read html text on clipboard. Then use wxRTC styling to match the HTML tags (eg text between <b> and </b> apply bold. The plot thickens when you have to deal with HTML attributes and CSS. But you can ignore them if you wish

That is all a theory that need to be tested (Assumption here is you can copy HTML to clipbboad with styles as text).

All in all I don't think there is a ready-made widget in wx for your task.
Chief Justice: We have trouble dear citizens!
Citizens: What it is his honor?
Chief Justice:Our president is an atheist, who will he swear to?
RobertHK
I live to help wx-kind
I live to help wx-kind
Posts: 158
Joined: Sat Dec 01, 2012 6:43 am

Re: wxWebView,how to set the text style

Post by RobertHK »

Hello. I use successfully Kompozer ver. 0.8.b3. There I visually design a page: font size,font color (and background), table, indent - just everything. On the "Source Code" tab, I copy this into my function and modify the code so that it is usable for viewing (in the MyFrame constructor):

Code: Select all

fragment from ctor MyFrame...)			
m_browser = wxWebView::New(m_panel60, wxID_ANY, wxEmptyString);
    vTopSizer60->Add(m_browser, wxSizerFlags().Expand().Proportion(1));

    m_browser->RegisterHandler(wxSharedPtr<wxWebViewHandler>(new wxWebViewArchiveHandler("wxfs")));
    m_browser->RegisterHandler(wxSharedPtr<wxWebViewHandler>(new wxWebViewFSHandler("memory")));

The itself modified code in my funcion (void MyFrame::OnXXX(wxCommandEvent & event) {//} has the following shape (for illustration):

Code: Select all

m_pageHTML.append( "<!DOCTYPE html PUBLIC '""-//W3C//DTD HTML 4.01 Transitional//EN""'>"
	"<html>"
	"<head>"
    "<meta http-equiv='""content-type""' content='""text/html; charset=UTF-8""'>"
    "<title>rozpocet</title>"
	"</head>"
	"<body>"
	"<div align='""center""'>"
	"<table style='""width: 100%; text-align: left; margin-left: auto; margin-right: auto;""' border='""0""' cellpadding='""0""' cellspacing='""0""'>"
	"<tbody>"
		"<tr>"
			"<td style='""background-color: rgb(102, 255, 255); width: 160px;""' colspan='""1""' rowspan='""1""'><font color='""#3333ff""'><span style='""font-weight: bold; color: rgb(0, 0, 153);""'>"
				"</span><big style='""color: rgb(0, 0, 153);""'><big style=""'font-weight: bold;""'>"+m_userdata12+":</big></big><br></font></td>"
			"<td style='""vertical-align: top; color: rgb(0, 0, 153); background-color: rgb(102, 255, 255);""'><big style='""font-weight: bold;""'><big>"wxT("Výkaz výměr - rozpočet")"</big></big><br></td>"
		"</tr>"
	"</tbody>"
    "</table>"
	"<br>"
	"<table style='""border-style: solid; border-color: blue;""' bgcolor='""#ffffff""' border='""1""' cellspacing='""0""' frame='""box""' rules='""none""' width='""100%""'>"
	"<tbody>"
		"<tr>"
			"<td valign='""top""'><table style='""width: 100%;""' border='""0""' cellpadding='""2""' cellspacing='""2""' frame='""border""'>"
		"<tbody>"
			"<tr>"
				"<td valign='""top""' width='""160""'><font color='""#3333ff""'><b><font size='""3""'>"wxT("Akce:")"</font></b><font size='""3""'><br></font></font></td>"
				"<td colspan='""5""' rowspan='""1""' valign='""top""'><font size='""3""'>"+m_userdata09+"<br></font></td>"
			"</tr>"
			"<tr>"
				"<td valign='""top""' width='""160""'><font color='""#3333ff""'><b><font size='""3""'>"wxT("Místo:")"</font></b><font size='""3""'><br></font></font></td>"
				"<td colspan='""5""' rowspan='""1""' valign='""top""'><font size='""3""'>"+m_userdata10+"<br></font></td>"
			"</tr>"
			...
wxKevin
Earned a small fee
Earned a small fee
Posts: 21
Joined: Fri Jun 09, 2017 7:45 am

Re: wxWebView,how to set the text style

Post by wxKevin »

Thanks, I have used other methods
Post Reply