From a510b0b4d1d3bc3b3b2822dd399635f5c0740d65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Minisini?= Date: Fri, 24 Jul 2009 13:05:24 +0000 Subject: [PATCH] [SCRIPTER] * BUG: Make it compile again. [GB.QT4.WEBKIT] * NEW: WebFrame is a new class that recursively describes WebView frames. * NEW: WebView.Frame is a new property that returns the WebView main frame. * NEW: WebView.Current is a new property that returns the WebView current frame. git-svn-id: svn://localhost/gambas/trunk@2159 867c0c6c-44f3-4631-809d-bfa615b0a4ec --- app/src/gambas3/.src/Debug/Design.module | 2 +- app/src/gbs3/.project | 8 +- app/src/gbs3/.settings | 10 +- app/src/gbs3/{ => .src}/CComponent.class | 0 app/src/gbs3/{ => .src}/MMain.module | 0 app/src/gbs3/{ => .src}/MServerPage.module | 2 +- .../Networking/WebBrowser/.src/FBrowser.class | 9 ++ gb.qt4/src/gb.qt.h | 2 + gb.qt4/src/main.cpp | 24 ++++ gb.qt4/src/main.h | 6 + gb.qt4/src/webkit/Makefile.am | 1 + gb.qt4/src/webkit/cwebframe.cpp | 125 ++++++++++++++++++ gb.qt4/src/webkit/cwebframe.h | 54 ++++++++ gb.qt4/src/webkit/cwebview.cpp | 26 +++- gb.qt4/src/webkit/cwebview.h | 1 + gb.qt4/src/webkit/main.cpp | 3 + 16 files changed, 257 insertions(+), 16 deletions(-) rename app/src/gbs3/{ => .src}/CComponent.class (100%) rename app/src/gbs3/{ => .src}/MMain.module (100%) rename app/src/gbs3/{ => .src}/MServerPage.module (99%) create mode 100644 gb.qt4/src/webkit/cwebframe.cpp create mode 100644 gb.qt4/src/webkit/cwebframe.h diff --git a/app/src/gambas3/.src/Debug/Design.module b/app/src/gambas3/.src/Debug/Design.module index 407d58f11..626110c6b 100644 --- a/app/src/gambas3/.src/Debug/Design.module +++ b/app/src/gambas3/.src/Debug/Design.module @@ -850,7 +850,7 @@ Private Sub Signal() Try FDebugExpr.RefreshAll - FMain.Show + 'FMain.Show 'Command("e", TRUE) diff --git a/app/src/gbs3/.project b/app/src/gbs3/.project index 1eddaa12b..d113d2f6b 100644 --- a/app/src/gbs3/.project +++ b/app/src/gbs3/.project @@ -1,13 +1,13 @@ # Gambas Project File 3.0 -# Compiled with Gambas 2.99.0 (r1601) +# Compiled with Gambas 2.99.0 (r2152) Title=gbs2 Startup=MMain Icon=icon.png -Version=2.99.90 +Version=2.99.0 VersionProgram=gbx3 -V Component=gb.eval -Description=Gambas Script -Authors=Fabien Bodard, Benoit Minisini +Description="Gambas Script" +Authors="Fabien Bodard, Benoit Minisini" Arguments="/home/fabien/Desktop/ram.g" TabSize=2 KeepDebugInfo=1 diff --git a/app/src/gbs3/.settings b/app/src/gbs3/.settings index 8d52d9562..7b264e4f8 100644 --- a/app/src/gbs3/.settings +++ b/app/src/gbs3/.settings @@ -42,14 +42,14 @@ SearchComment=False SearchString=True [OpenFile] -Active=1 -File[1]="MMain.module:0.0" +File[1]="/home/benoit/gambas/3.0/trunk/app/src/gbs3/.src/MMain.module:0.0" Fold[1]=[] -File[2]="CComponent.class:169.37" +File[2]="/home/benoit/gambas/3.0/trunk/app/src/gbs3/.src/CComponent.class:169.37" Fold[2]=[] -File[3]="MServerPage.module:134.0" +Active=3 +File[3]="/home/benoit/gambas/3.0/trunk/app/src/gbs3/.src/MServerPage.module:14.19" Fold[3]=[] -File[4]="helptext:8.11" +File[4]="/home/benoit/gambas/3.0/trunk/app/src/gbs3/helptext:8.11" Count=4 [Watches] diff --git a/app/src/gbs3/CComponent.class b/app/src/gbs3/.src/CComponent.class similarity index 100% rename from app/src/gbs3/CComponent.class rename to app/src/gbs3/.src/CComponent.class diff --git a/app/src/gbs3/MMain.module b/app/src/gbs3/.src/MMain.module similarity index 100% rename from app/src/gbs3/MMain.module rename to app/src/gbs3/.src/MMain.module diff --git a/app/src/gbs3/MServerPage.module b/app/src/gbs3/.src/MServerPage.module similarity index 99% rename from app/src/gbs3/MServerPage.module rename to app/src/gbs3/.src/MServerPage.module index 93bd0cfd4..3d2c04834 100644 --- a/app/src/gbs3/MServerPage.module +++ b/app/src/gbs3/.src/MServerPage.module @@ -12,7 +12,7 @@ Private Sub PrintHTML(sStr As String) If $iLenPrint > 32000 Then $bLastPrint = False If Not $bLastPrint Then $iLenPrint = Len(sStr) - Print #$hOut "PRINT "; + Print #$hOut, "PRINT "; Else Print #$hOut, " "; Endif diff --git a/examples/examples/Networking/WebBrowser/.src/FBrowser.class b/examples/examples/Networking/WebBrowser/.src/FBrowser.class index f518d41f1..db2d35243 100644 --- a/examples/examples/Networking/WebBrowser/.src/FBrowser.class +++ b/examples/examples/Networking/WebBrowser/.src/FBrowser.class @@ -79,11 +79,19 @@ End Public Sub WebView_Load() + Dim iInd As Integer + GetView().Status = "" If Not IsLastCurrentView() Then Return lblStatus.Text = "" + txtURL.Text = GetView().Url pgbLoad.Hide + + ' Debug GetView().Frame + ' For iInd = 0 To GetView().Frame.Children.Count - 1 + ' Debug "["; iInd; "] "; GetView().Frame.Children[iInd] + ' Next End @@ -157,6 +165,7 @@ End Public Sub WebView_Icon() Dim hView As WebView = Last + Debug tabBrowser[hView.Tag].Picture = hView.Icon If Not IsLastCurrentView() Then Return Me.Icon = hView.Icon diff --git a/gb.qt4/src/gb.qt.h b/gb.qt4/src/gb.qt.h index e70508cfd..d2960ceb3 100644 --- a/gb.qt4/src/gb.qt.h +++ b/gb.qt4/src/gb.qt.h @@ -126,6 +126,8 @@ typedef bool (*Notify)(void *, bool); void *(*GetDrawInterface)(); int (*Alignment)(int, int, bool); + void (*Link)(QObject *, void *); + void *(*GetLink)(QObject *); void *_null; } QT_INTERFACE; diff --git a/gb.qt4/src/main.cpp b/gb.qt4/src/main.cpp index c2aecefb9..3d916155a 100644 --- a/gb.qt4/src/main.cpp +++ b/gb.qt4/src/main.cpp @@ -135,6 +135,8 @@ static bool _check_quit_posted = false; static void (*_x11_event_filter)(XEvent *) = 0; #endif +static QHash _link_map; + //static MyApplication *myApp; /*************************************************************************** @@ -834,6 +836,26 @@ static void *QT_GetDrawInterface() return (void *)&DRAW_Interface; } +void MyApplication::linkDestroyed(QObject *qobject) +{ + void *object = _link_map.value(qobject, 0); + _link_map.remove(qobject); + if (object) + GB.Unref(POINTER(&object)); +} + +void QT_Link(QObject *qobject, void *object) +{ + _link_map.insert(qobject, object); + QObject::connect(qobject, SIGNAL(destroyed(QObject *)), qApp, SLOT(linkDestroyed(QObject *))); + GB.Ref(object); +} + +void *QT_GetLink(QObject *qobject) +{ + return _link_map.value(qobject, 0); +} + extern "C" { GB_DESC *GB_CLASSES[] EXPORT = @@ -897,6 +919,8 @@ void *GB_QT4_1[] EXPORT = { (void *)QT_Notify, (void *)QT_GetDrawInterface, (void *)CCONST_alignment, + (void *)QT_Link, + (void *)QT_GetLink, NULL }; diff --git a/gb.qt4/src/main.h b/gb.qt4/src/main.h index c41aa2137..c81236bc6 100644 --- a/gb.qt4/src/main.h +++ b/gb.qt4/src/main.h @@ -79,6 +79,10 @@ public: static void setTooltipEnabled(bool b); static QEventLoop *eventLoop; + +public slots: + + void linkDestroyed(QObject *); private: static bool _tooltip_disable; @@ -114,5 +118,7 @@ const char *QT_ToUTF8(const QString &str); void QT_RegisterAction(void *object, const char *key, int on); void QT_RaiseAction(const char *key); void *QT_GetObject(QWidget *); +void QT_Link(QObject *, void *); +void *QT_GetLink(QObject *); #endif diff --git a/gb.qt4/src/webkit/Makefile.am b/gb.qt4/src/webkit/Makefile.am index 8af545b94..950b65740 100644 --- a/gb.qt4/src/webkit/Makefile.am +++ b/gb.qt4/src/webkit/Makefile.am @@ -11,4 +11,5 @@ gb_qt4_webkit_la_LDFLAGS = -module @LD_FLAGS@ @QTWEBKIT_LDFLAGS@ gb_qt4_webkit_la_SOURCES = \ main.h main.cpp \ + cwebframe.h cwebframe.cpp cwebframe_moc.cpp \ cwebview.h cwebview.cpp cwebview_moc.cpp diff --git a/gb.qt4/src/webkit/cwebframe.cpp b/gb.qt4/src/webkit/cwebframe.cpp new file mode 100644 index 000000000..ea3be7e71 --- /dev/null +++ b/gb.qt4/src/webkit/cwebframe.cpp @@ -0,0 +1,125 @@ +/*************************************************************************** + + cwebframe.cpp + + (c) 2000-2009 Benoît Minisini + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 1, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +***************************************************************************/ + +#define __CWEBFRAME_CPP + +#include +#include +#include + +#include "cwebframe.h" + +CWEBFRAME *CWEBFRAME_get(QWebFrame *frame) +{ + void *_object; + + if (!frame) return 0; + + _object = QT.GetLink(frame); + + if (!_object) + { + GB.New(POINTER(&_object), GB.FindClass("WebFrame"), 0, 0); + //qDebug("create WebFrame %p", _object); + QT.Link(frame, _object); + THIS->frame = frame; + } + + return (CWEBFRAME *)_object; +} + +BEGIN_METHOD_VOID(WebFrame_free) + + //qDebug("WebFrame_free: %p", THIS); + +END_METHOD + +BEGIN_PROPERTY(WebFrame_Name) + + GB.ReturnNewZeroString(TO_UTF8(FRAME->frameName())); + +END_PROPERTY + +BEGIN_PROPERTY(WebFrame_Parent) + + GB.ReturnObject(CWEBFRAME_get(FRAME->parentFrame())); + +END_PROPERTY + +BEGIN_PROPERTY(WebFrame_Url) + + if (READ_PROPERTY) + GB.ReturnNewZeroString(TO_UTF8(FRAME->url().toString())); + else + FRAME->setUrl(QUrl(QSTRING_PROP())); + +END_PROPERTY + + +BEGIN_PROPERTY(WebFrameChildren_Count) + + GB.ReturnInteger(FRAME->childFrames().count()); + +END_PROPERTY + +BEGIN_METHOD(WebFrameChildren_get, GB_INTEGER index) + + int index = VARG(index); + QList children = FRAME->childFrames(); + + if (index < 0 || index >= children.count()) + { + GB.Error(GB_ERR_BOUND); + return; + } + + GB.ReturnObject(CWEBFRAME_get(children.at(index))); + +END_METHOD + +GB_DESC CWebFrameChildrenDesc[] = +{ + GB_DECLARE(".WebFrameChildren", sizeof(CWEBFRAME)), GB_VIRTUAL_CLASS(), + + GB_PROPERTY_READ("Count", "i", WebFrameChildren_Count), + GB_METHOD("_get", "WebFrame", WebFrameChildren_get, "(Index)i"), + + GB_END_DECLARE +}; + +GB_DESC CWebFrameDesc[] = +{ + GB_DECLARE("WebFrame", sizeof(CWEBFRAME)), + + GB_METHOD("_free", NULL, WebFrame_free, NULL), + + GB_PROPERTY_READ("Name", "s", WebFrame_Name), + GB_PROPERTY_SELF("Children", ".WebFrameChildren"), + GB_PROPERTY_READ("Parent", "WebFrame", WebFrame_Parent), + GB_PROPERTY("Url", "s", WebFrame_Url), + + GB_END_DECLARE +}; + +/***************************************************************************/ + + diff --git a/gb.qt4/src/webkit/cwebframe.h b/gb.qt4/src/webkit/cwebframe.h new file mode 100644 index 000000000..09cc76fce --- /dev/null +++ b/gb.qt4/src/webkit/cwebframe.h @@ -0,0 +1,54 @@ +/*************************************************************************** + + cwebframe.h + + (c) 2000-2009 Benoît Minisini + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 1, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +***************************************************************************/ + +#ifndef __CWEBFRAME_H +#define __CWEBFRAME_H + +#include "main.h" + +#include +#include +#include + +#ifndef __CWEBFRAME_CPP + +extern GB_DESC CWebFrameChildrenDesc[]; +extern GB_DESC CWebFrameDesc[]; + +#else + +#define THIS ((CWEBFRAME *)_object) +#define FRAME (THIS->frame) + +#endif + +typedef + struct + { + GB_BASE ob; + QWebFrame *frame; + } + CWEBFRAME; + +CWEBFRAME *CWEBFRAME_get(QWebFrame *frame); + +#endif diff --git a/gb.qt4/src/webkit/cwebview.cpp b/gb.qt4/src/webkit/cwebview.cpp index 9058e91cd..c68bb9242 100644 --- a/gb.qt4/src/webkit/cwebview.cpp +++ b/gb.qt4/src/webkit/cwebview.cpp @@ -26,6 +26,7 @@ #include #include +#include "cwebframe.h" #include "cwebview.h" DECLARE_EVENT(EVENT_CLICK); @@ -62,6 +63,7 @@ END_METHOD BEGIN_METHOD_VOID(WebView_free) GB.FreeString(&THIS->status); + GB.Unref(POINTER(&THIS->icon)); END_METHOD @@ -88,11 +90,7 @@ END_PROPERTY BEGIN_PROPERTY(WebView_Icon) - QIcon icon = WIDGET->icon(); - if (icon.isNull()) - GB.ReturnNull(); - else - GB.ReturnObject(QT.CreatePicture(icon.pixmap(32, 32))); + GB.ReturnObject(THIS->icon); END_PROPERTY @@ -176,6 +174,18 @@ BEGIN_PROPERTY(WebView_Status) END_PROPERTY +BEGIN_PROPERTY(WebView_Frame) + + GB.ReturnObject(CWEBFRAME_get(WIDGET->page()->mainFrame())); + +END_PROPERTY + +BEGIN_PROPERTY(WebView_Current) + + GB.ReturnObject(CWEBFRAME_get(WIDGET->page()->currentFrame())); + +END_PROPERTY + GB_DESC CWebViewDesc[] = { GB_DECLARE("WebView", sizeof(CWEBVIEW)), GB_INHERITS("Control"), @@ -199,6 +209,9 @@ GB_DESC CWebViewDesc[] = GB_PROPERTY("TextZoom", "f", WebView_TextZoom), GB_PROPERTY_READ("Title", "s", WebView_Title), + GB_PROPERTY_READ("Frame", "WebFrame", WebView_Frame), + GB_PROPERTY_READ("Current", "WebFrame", WebView_Current), + GB_METHOD("Back", NULL, WebView_Back, NULL), GB_METHOD("Forward", NULL, WebView_Forward, NULL), GB_METHOD("Reload", NULL, WebView_Reload, NULL), @@ -251,6 +264,9 @@ CWebView CWebView::manager; void CWebView::iconChanged() { GET_SENDER(); + QIcon icon = WIDGET->icon(); + GB.Unref(POINTER(&THIS->icon)); + THIS->icon = QT.CreatePicture(icon.pixmap(32, 32)); GB.Raise(THIS, EVENT_ICON, 0); } diff --git a/gb.qt4/src/webkit/cwebview.h b/gb.qt4/src/webkit/cwebview.h index 0b0af36d4..afffeb295 100644 --- a/gb.qt4/src/webkit/cwebview.h +++ b/gb.qt4/src/webkit/cwebview.h @@ -59,6 +59,7 @@ typedef void *new_view; double progress; char *status; + QT_PICTURE icon; } CWEBVIEW; diff --git a/gb.qt4/src/webkit/main.cpp b/gb.qt4/src/webkit/main.cpp index 23c26cc32..666701d03 100644 --- a/gb.qt4/src/webkit/main.cpp +++ b/gb.qt4/src/webkit/main.cpp @@ -27,6 +27,7 @@ #include #include +#include "cwebframe.h" #include "cwebview.h" #include "main.h" @@ -37,6 +38,8 @@ QT_INTERFACE QT; GB_DESC *GB_CLASSES[] EXPORT = { + CWebFrameChildrenDesc, + CWebFrameDesc, CWebViewDesc, NULL };