Skip to content

Commit bf7ec92

Browse files
author
achellies
committed
add source code to evaluate javascript (not finish yet)
1 parent f144e10 commit bf7ec92

File tree

8 files changed

+191
-2
lines changed

8 files changed

+191
-2
lines changed

src/duibrowser/DuiBrowser.vcproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,10 @@
192192
RelativePath=".\frame.cpp"
193193
>
194194
</File>
195+
<File
196+
RelativePath=".\input_dialog.cpp"
197+
>
198+
</File>
195199
<File
196200
RelativePath=".\main.cpp"
197201
>
@@ -238,6 +242,10 @@
238242
RelativePath=".\frame.hpp"
239243
>
240244
</File>
245+
<File
246+
RelativePath=".\input_dialog.hpp"
247+
>
248+
</File>
241249
<File
242250
RelativePath=".\popup_menu.hpp"
243251
>

src/duibrowser/bin/skins/Run.png

3.74 KB
Loading

src/duibrowser/bin/skins/Text.png

2.66 KB
Loading
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Window caption="0,0,0,36" roundcorner="5,5" size="600,400" sizebox="6,6,6,6" mininfo="80,60">
3+
<Font name="微软雅黑" size="18" bold="false" default="true"/>
4+
<Font name="微软雅黑" size="18"/>
5+
<Default name="VScrollBar" value="button1normalimage=&quot;file='$scroll.png' source='0,0,16,16'&quot; button1hotimage=&quot;file='$scroll.png' source='0,0,16,16' mask='#FFFF00FF'&quot; button1pushedimage=&quot;file='$scroll.png' source='0,16,16,32' mask='#FFFF00FF'&quot; button1disabledimage=&quot;file='$scroll.png' source='0,0,16,16' mask='#FFFF00FF'&quot; button2normalimage=&quot;file='$scroll.png' source='0,32,16,48' mask='#FFFF00FF'&quot; button2hotimage=&quot;file='$scroll.png' source='0,32,16,48' mask='#FFFF00FF'&quot; button2pushedimage=&quot;file='$scroll.png' source='0,48,16,64' mask='#FFFF00FF'&quot; button2disabledimage=&quot;file='$scroll.png' source='0,32,16,48' mask='#FFFF00FF'&quot; thumbnormalimage=&quot;file='$scroll.png' source='0,64,16,80' corner='2,2,2,2' mask='#FFFF00FF'&quot; thumbhotimage=&quot;file='$scroll.png' source='0,64,16,80' corner='2,2,2,2' mask='#FFFF00FF'&quot; thumbpushedimage=&quot;file='$scroll.png' source='0,64,16,80' corner='2,2,2,2' mask='#FFFF00FF'&quot; thumbdisabledimage=&quot;file='$scroll.png' source='0,64,16,80' corner='2,2,2,2' mask='#FFFF00FF'&quot; railnormalimage=&quot;file='$scroll.png' source='0,80,16,96' corner='2,2,2,2' mask='#FFFF00FF'&quot; railhotimage=&quot;file='$scroll.png' source='0,80,16,96' corner='2,2,2,2' mask='#FFFF00FF'&quot; railpushedimage=&quot;file='$scroll.png' source='0,96,16,112' corner='2,2,2,2' mask='#FFFF00FF'&quot; raildisabledimage=&quot;file='$scroll.png' source='0,80,16,96' corner='2,2,2,2' mask='#FFFF00FF'&quot; bknormalimage=&quot;file='$scroll.png' source='0,128,16,146' corner='2,2,2,2' mask='#FFFF00FF'&quot; bkhotimage=&quot;file='$scroll.png' source='0,128,16,146' corner='2,2,2,2' mask='#FFFF00FF'&quot; bkpushedimage=&quot;file='$scroll.png' source='0,128,16,146' corner='2,2,2,2' mask='#FFFF00FF'&quot; bkdisabledimage=&quot;file='$scroll.png' source='0,128,16,146' corner='2,2,2,2' mask='#FFFF00FF'&quot; " />
6+
<VerticalLayout bkcolor="#FFFFFFFF" bordersize="2" bordercolor="#FF0934DA">
7+
8+
<HorizontalLayout name="header" height="36" bkcolor="#FF4775CC">
9+
<HorizontalLayout>
10+
<Container name="logo" padding="7,2,0,0" width="32" height="32" bkimage="file='Text.png'"/>
11+
<Label name="apptitle" text="输入" font="1" textcolor="#FFFFFFFF" />
12+
</HorizontalLayout>
13+
<HorizontalLayout height="25" width="45">
14+
<Button name="closebtn" tooltip="关闭" height="18" width="43" normalimage="file='close.png'" hotimage="file='close_h.png'" pushedimage="file='close_p.png'"/>
15+
</HorizontalLayout>
16+
</HorizontalLayout>
17+
18+
<VerticalLayout name="body" padding="2,0,2,2">
19+
<RichEdit name="input" bordercolor="#FF0000" bordersize="0" borderround="18,18" inset="4,2,4,2" bkcolor="#A0F2F5FA" font="1" multiline="true" vscrollbar="true" autovscroll="true" enabled="true" rich="true" readonly="false" />
20+
</VerticalLayout>
21+
22+
<VerticalLayout name="bottom" height="36" bkcolor="#FF4775CC">
23+
</VerticalLayout>
24+
25+
</VerticalLayout>
26+
</Window>

src/duibrowser/bin/skins/skins.zip

7.6 KB
Binary file not shown.

src/duibrowser/frame.cpp

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
#include "string_convertor.hpp"
3131
#include "win_impl_base.hpp"
32+
#include "input_dialog.hpp"
3233
#include "window_util.hpp"
3334
#include "popup_menu.hpp"
3435
#include "UIWebkit.hpp"
@@ -114,6 +115,8 @@ enum MenuItem
114115

115116
kPrintDoc,
116117

118+
kRunJavascript,
119+
117120
kAbout,
118121

119122
kExit,
@@ -484,7 +487,9 @@ void MainFrame::OnSystemMenu(TNotifyUI& msg)
484487
system_menu->AddMenuItem(_T("打开"), kOpen, true, false, false, _T("Open.png"));
485488
system_menu->AddMenuItem(_T("网页另保存..."), kSave, true, false, true, _T("Save.png"));
486489

487-
system_menu->AddMenuItem(_T("打印..."), kPrintDoc, true, false, true, _T("print.png"));
490+
system_menu->AddMenuItem(_T("打印..."), kPrintDoc, true, false, true, _T("print.png"));
491+
492+
system_menu->AddMenuItem(_T("运行Javascript..."), kRunJavascript, true, false, true, _T("Run.png"));
488493

489494
system_menu->AddMenuItem(_T("关于..."), kAbout, true, false, true, _T("About.png"));
490495

@@ -761,7 +766,7 @@ bool MainFrame::ViewUpdate(ViewUpdateInfo& view_update_info)
761766
CRect invalidateRect(view_update_info.mX, view_update_info.mY, view_update_info.mW, view_update_info.mH);
762767
webkit_control->LayoutChanged(invalidateRect);
763768
}
764-
VERBOSE(_T("view_update_info.mDrawEvent = %d, view_update_info.mX = %d, view_update_info.mY = %d, view_update_info.mW = %d, view_update_info.mH = %d.\n"), view_update_info.mDrawEvent, view_update_info.mX, view_update_info.mY, view_update_info.mW, view_update_info.mH);
769+
//VERBOSE(_T("view_update_info.mDrawEvent = %d, view_update_info.mX = %d, view_update_info.mY = %d, view_update_info.mW = %d, view_update_info.mH = %d.\n"), view_update_info.mDrawEvent, view_update_info.mX, view_update_info.mY, view_update_info.mW, view_update_info.mH);
765770
return true;
766771
}
767772

@@ -829,6 +834,31 @@ LRESULT MainFrame::HandleCustomMessage(UINT uMsg, WPARAM wParam, LPARAM lParam,
829834
case kExit:
830835
Close();
831836
break;
837+
case kRunJavascript:
838+
{
839+
InputDialog input_dialog;
840+
input_dialog.Create(paint_manager_.GetPaintWindow(), NULL, WS_POPUP, WS_EX_TOOLWINDOW, CRect());
841+
input_dialog.CenterWindow();
842+
input_dialog.ShowModal();
843+
tString java_scripts = input_dialog.GetInputString();
844+
845+
if (!java_scripts.empty() && view_)
846+
{
847+
JavascriptValue* return_value = webkit_->CreateJavaScriptValue();
848+
bool success = view_->EvaluateJavaScript(java_scripts.c_str(), java_scripts.length(), return_value);
849+
850+
switch (return_value->GetType())
851+
{
852+
case JavascriptValueType_String:
853+
EASTLFixedString16Wrapper& string_wrapper = return_value->GetStringValue();
854+
wprintf(webkit_->GetCharacters(string_wrapper));
855+
break;
856+
}
857+
858+
webkit_->DestroyJavaScriptValue(return_value);
859+
}
860+
}
861+
break;
832862
}
833863
}
834864
break;

src/duibrowser/input_dialog.cpp

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
//
2+
// input_dialog.cpp
3+
// ~~~~~~~~~~~~~~~~
4+
//
5+
// Copyright (c) 2011 achellies (achellies at 163 dot com)
6+
//
7+
// This code may be used in compiled form in any way you desire. This
8+
// source file may be redistributed by any means PROVIDING it is
9+
// not sold for profit without the authors written consent, and
10+
// providing that this notice and the authors name is included.
11+
//
12+
// This file is provided "as is" with no expressed or implied warranty.
13+
// The author accepts no liability if it causes any damage to you or your
14+
// computer whatsoever. It's free, so don't hassle me about it.
15+
//
16+
// Beware of bugs.
17+
//
18+
19+
#include "stdafx.h"
20+
#include "win_impl_base.hpp"
21+
#include "input_dialog.hpp"
22+
23+
#if !defined(UNDER_CE) && defined(_DEBUG)
24+
#define new new(_NORMAL_BLOCK, __FILE__, __LINE__)
25+
#endif
26+
27+
InputDialog::InputDialog()
28+
{}
29+
30+
LPCTSTR InputDialog::GetWindowClassName() const
31+
{
32+
return _T("InputDialog");
33+
}
34+
35+
void InputDialog::OnFinalMessage(HWND hWnd)
36+
{
37+
WindowImplBase::OnFinalMessage(hWnd);
38+
}
39+
40+
void InputDialog::Close()
41+
{
42+
ASSERT(::IsWindow(m_hWnd));
43+
if( !::IsWindow(m_hWnd) ) return;
44+
PostMessage(WM_CLOSE);
45+
}
46+
47+
tString InputDialog::GetSkinFile()
48+
{
49+
return _T("input_dialog.xml");
50+
}
51+
52+
void InputDialog::OnPrepare(TNotifyUI& msg)
53+
{}
54+
55+
tString InputDialog::GetInputString()
56+
{
57+
return input_string_;
58+
}
59+
60+
void InputDialog::Notify(TNotifyUI& msg)
61+
{
62+
if (_tcsicmp(msg.sType, _T("windowinit")) == 0)
63+
{
64+
OnPrepare(msg);
65+
}
66+
else if (_tcsicmp(msg.sType, _T("click")) == 0)
67+
{
68+
if (_tcsicmp(msg.pSender->GetName(), _T("closebtn")) == 0)
69+
{
70+
CRichEditUI* rich_edit = static_cast<CRichEditUI*>(paint_manager_.FindControl(_T("input")));
71+
if (rich_edit != NULL)
72+
input_string_ = rich_edit->GetText();
73+
74+
Close();
75+
}
76+
}
77+
}

src/duibrowser/input_dialog.hpp

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
//
2+
// input_dialog.hpp
3+
// ~~~~~~~~~~~~~~~~
4+
//
5+
// Copyright (c) 2011 achellies (achellies at 163 dot com)
6+
//
7+
// This code may be used in compiled form in any way you desire. This
8+
// source file may be redistributed by any means PROVIDING it is
9+
// not sold for profit without the authors written consent, and
10+
// providing that this notice and the authors name is included.
11+
//
12+
// This file is provided "as is" with no expressed or implied warranty.
13+
// The author accepts no liability if it causes any damage to you or your
14+
// computer whatsoever. It's free, so don't hassle me about it.
15+
//
16+
// Beware of bugs.
17+
//
18+
19+
#ifndef INPUT_DIALOG_HPP
20+
#define INPUT_DIALOG_HPP
21+
22+
class WindowImplBase;
23+
class InputDialog : public WindowImplBase
24+
{
25+
public:
26+
InputDialog();
27+
28+
tString GetInputString();
29+
30+
protected:
31+
32+
LPCTSTR GetWindowClassName() const;
33+
34+
void Close();
35+
36+
void OnFinalMessage(HWND hWnd);
37+
38+
void OnPrepare(TNotifyUI& msg);
39+
40+
void Notify(TNotifyUI& msg);
41+
42+
virtual tString GetSkinFile();
43+
44+
private:
45+
tString input_string_;
46+
};
47+
48+
#endif // INPUT_DIALOG_HPP

0 commit comments

Comments
 (0)