зеркало из https://github.com/mozilla/gecko-dev.git
Not Part of Build... PHOTON ONLY
Additions of new callbacks to test new features of the PtMozilla widget.
This commit is contained in:
Родитель
9015f0a3bf
Коммит
5d9a6ccde5
|
@ -17,30 +17,21 @@
|
|||
*
|
||||
* Contributor(s):
|
||||
* Christopher Blizzard <blizzard@mozilla.org>
|
||||
* Brian Edmond <briane@qnx.com>
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include "nsIWebBrowser.h"
|
||||
#include "nsCWebBrowser.h"
|
||||
#include "nsIWebBrowserChrome.h"
|
||||
#include "MozEmbedChrome.h"
|
||||
#include "nsIComponentManager.h"
|
||||
#include "nsIWebNavigation.h"
|
||||
#include "nsString.h"
|
||||
#include "nsIEventQueueService.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsISupportsArray.h"
|
||||
#include "nsVoidArray.h"
|
||||
#include "prlog.h"
|
||||
|
||||
#include <Pt.h>
|
||||
#include "PtMozilla.h"
|
||||
#include <string.h>
|
||||
|
||||
PtWidget_t *window, *back, *forward, *stop, *web, *reload;
|
||||
PtWidget_t *window, *back, *forward, *stop, *web, *reload, *url, *status, *progress;
|
||||
char *statusMessage = NULL;
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// callbacks for the main window controls
|
||||
int reload_cb(PtWidget_t *widget, void *data, PtCallbackInfo_t *cbinfo)
|
||||
{
|
||||
PtArg_t args[1];
|
||||
|
@ -82,8 +73,204 @@ int load_url_cb(PtWidget_t *widget, void *data, PtCallbackInfo_t *cbinfo)
|
|||
PtSetResources(web, 1, args);
|
||||
return (Pt_CONTINUE);
|
||||
}
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
PRLogModuleInfo *PhWidLog;
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// mozilla widget callbacks
|
||||
|
||||
|
||||
int moz_status_cb(PtWidget_t *widget, void *data, PtCallbackInfo_t *cbinfo)
|
||||
{
|
||||
PtMozillaStatusCb_t *s = (PtMozillaStatusCb_t *) cbinfo->cbdata;
|
||||
PtArg_t args[2];
|
||||
struct BaseData *bd;
|
||||
|
||||
switch (s->type)
|
||||
{
|
||||
case Pt_MOZ_STATUS_LINK:
|
||||
case Pt_MOZ_STATUS_JS:
|
||||
PtSetResource(status, Pt_ARG_TEXT_STRING, s->message, 0);
|
||||
break;
|
||||
case Pt_MOZ_STATUS_TITLE:
|
||||
PtSetResource(window, Pt_ARG_WINDOW_TITLE, s->message, 0);
|
||||
break;
|
||||
}
|
||||
|
||||
return (Pt_CONTINUE);
|
||||
}
|
||||
|
||||
int moz_start_cb(PtWidget_t *widget, void *data, PtCallbackInfo_t *cbinfo)
|
||||
{
|
||||
// could start an animation here
|
||||
PtSetResource(stop, Pt_ARG_FLAGS, 0, Pt_BLOCKED|Pt_GHOST);
|
||||
|
||||
return (Pt_CONTINUE);
|
||||
}
|
||||
|
||||
int moz_complete_cb(PtWidget_t *widget, void *data, PtCallbackInfo_t *cbinfo)
|
||||
{
|
||||
PtSetResource(status, Pt_ARG_TEXT_STRING, "Done", 0);
|
||||
|
||||
// could stop an animation here
|
||||
PtSetResource(stop, Pt_ARG_FLAGS, ~0, Pt_BLOCKED|Pt_GHOST);
|
||||
|
||||
return (Pt_CONTINUE);
|
||||
}
|
||||
|
||||
int moz_progress_cb(PtWidget_t *widget, void *data, PtCallbackInfo_t *cbinfo)
|
||||
{
|
||||
PtMozillaProgressCb_t *c = (PtMozillaProgressCb_t *) cbinfo->cbdata;
|
||||
PtArg_t args[2];
|
||||
int percent;
|
||||
char message[256];
|
||||
|
||||
if ((c->max <= 0) || (c->cur > c->max))
|
||||
{
|
||||
percent = 0;
|
||||
sprintf(message, "%s (%d bytes loaded)", statusMessage, c->cur);
|
||||
}
|
||||
else
|
||||
{
|
||||
percent = (c->cur*100)/c->max;
|
||||
sprintf(message, "%s (%d%% complete, %d bytes of %d loaded)", statusMessage, percent, c->cur, c->max);
|
||||
}
|
||||
|
||||
PtSetResource(progress, Pt_ARG_GAUGE_VALUE, percent, 0);
|
||||
PtSetResource(status, Pt_ARG_TEXT_STRING, message, 0);
|
||||
|
||||
return (Pt_CONTINUE);
|
||||
}
|
||||
|
||||
int moz_url_cb(PtWidget_t *widget, void *data, PtCallbackInfo_t *cbinfo)
|
||||
{
|
||||
int *nflags = NULL;
|
||||
PtMozillaUrlCb_t *c = (PtMozillaUrlCb_t *) cbinfo->cbdata;
|
||||
struct BaseData *bd;
|
||||
|
||||
// display the url in the entry field
|
||||
PtSetResource(url, Pt_ARG_TEXT_STRING, c->url, 0);
|
||||
|
||||
/* get the navigation possibilities */
|
||||
PtGetResource(web, Pt_ARG_MOZ_NAVIGATE_PAGE, &nflags, 0 );
|
||||
|
||||
if ( nflags != NULL )
|
||||
{
|
||||
// disable or enable the forward and back buttons accordingly
|
||||
if (*nflags & WWW_DIRECTION_BACK)
|
||||
PtSetResource(back, Pt_ARG_FLAGS, 0, Pt_BLOCKED|Pt_GHOST);
|
||||
else
|
||||
PtSetResource(back, Pt_ARG_FLAGS, ~0, Pt_BLOCKED|Pt_GHOST);
|
||||
if (*nflags & WWW_DIRECTION_FWD)
|
||||
PtSetResource(forward, Pt_ARG_FLAGS, 0, Pt_BLOCKED|Pt_GHOST);
|
||||
else
|
||||
PtSetResource(forward, Pt_ARG_FLAGS, ~0, Pt_BLOCKED|Pt_GHOST);
|
||||
}
|
||||
|
||||
return (Pt_CONTINUE);
|
||||
}
|
||||
|
||||
int moz_event_cb(PtWidget_t *widget, void *data, PtCallbackInfo_t *cbinfo)
|
||||
{
|
||||
PtArg_t args[2];
|
||||
int *nflags = NULL;
|
||||
PtMozillaEventCb_t *c = (PtMozillaEventCb_t *) cbinfo->cbdata;
|
||||
|
||||
printf("Callback: Event\n");
|
||||
|
||||
return (Pt_CONTINUE);
|
||||
}
|
||||
|
||||
int moz_net_state_change_cb (PtWidget_t *widget, void *data, PtCallbackInfo_t *cbinfo)
|
||||
{
|
||||
PtMozillaNetStateCb_t *c = (PtMozillaNetStateCb_t *) cbinfo->cbdata;
|
||||
|
||||
statusMessage = NULL;
|
||||
|
||||
if (c->flags & PH_MOZ_EMBED_FLAG_IS_REQUEST)
|
||||
{
|
||||
if (c->flags & PH_MOZ_EMBED_FLAG_REDIRECTING)
|
||||
statusMessage = "Redirecting to site...";
|
||||
else if (c->flags & PH_MOZ_EMBED_FLAG_TRANSFERRING)
|
||||
statusMessage = "Transferring data from site...";
|
||||
else if (c->flags & PH_MOZ_EMBED_FLAG_NEGOTIATING)
|
||||
statusMessage = "Waiting for authorization...";
|
||||
}
|
||||
|
||||
if (c->status == PH_MOZ_EMBED_STATUS_FAILED_DNS)
|
||||
statusMessage = "Site not found.";
|
||||
else if (c->status == PH_MOZ_EMBED_STATUS_FAILED_CONNECT)
|
||||
statusMessage = "Failed to connect to site.";
|
||||
else if (c->status == PH_MOZ_EMBED_STATUS_FAILED_TIMEOUT)
|
||||
statusMessage = "Failed due to connection timeout.";
|
||||
else if (c->status == PH_MOZ_EMBED_STATUS_FAILED_USERCANCELED)
|
||||
statusMessage = "User canceled connecting to site.";
|
||||
|
||||
if (c->flags & PH_MOZ_EMBED_FLAG_IS_WINDOW)
|
||||
{
|
||||
if (c->flags & PH_MOZ_EMBED_FLAG_START)
|
||||
statusMessage = "Loading site...";
|
||||
else if (c->flags & PH_MOZ_EMBED_FLAG_STOP)
|
||||
statusMessage = "Done.";
|
||||
}
|
||||
|
||||
if (statusMessage)
|
||||
PtSetResource(status, Pt_ARG_TEXT_STRING, statusMessage, 0);
|
||||
|
||||
return (Pt_CONTINUE);
|
||||
}
|
||||
|
||||
int moz_new_window_cb(PtWidget_t *widget, void *data, PtCallbackInfo_t *cbinfo)
|
||||
{
|
||||
PtMozillaNewWindowCb_t *c = (PtMozillaNewWindowCb_t *) cbinfo->cbdata;
|
||||
|
||||
printf("Callback: New window\n");
|
||||
|
||||
return (Pt_CONTINUE);
|
||||
}
|
||||
|
||||
int moz_resize_cb(PtWidget_t *widget, void *data, PtCallbackInfo_t *cbinfo)
|
||||
{
|
||||
PtMozillaNewWindowCb_t *c = (PtMozillaNewWindowCb_t *) cbinfo->cbdata;
|
||||
|
||||
printf("Callback: Resize\n");
|
||||
|
||||
return (Pt_CONTINUE);
|
||||
}
|
||||
|
||||
int moz_destroy_cb(PtWidget_t *widget, void *data, PtCallbackInfo_t *cbinfo)
|
||||
{
|
||||
PtMozillaNewWindowCb_t *c = (PtMozillaNewWindowCb_t *) cbinfo->cbdata;
|
||||
|
||||
printf("Callback: Destroy\n");
|
||||
|
||||
return (Pt_CONTINUE);
|
||||
}
|
||||
|
||||
int moz_visibility_cb(PtWidget_t *widget, void *data, PtCallbackInfo_t *cbinfo)
|
||||
{
|
||||
PtMozillaNewWindowCb_t *c = (PtMozillaNewWindowCb_t *) cbinfo->cbdata;
|
||||
|
||||
printf("Callback: Visibility\n");
|
||||
|
||||
return (Pt_CONTINUE);
|
||||
}
|
||||
|
||||
int moz_open_cb(PtWidget_t *widget, void *data, PtCallbackInfo_t *cbinfo)
|
||||
{
|
||||
PtArg_t args[2];
|
||||
int *nflags = NULL;
|
||||
PtMozillaUrlCb_t *c = (PtMozillaUrlCb_t *) cbinfo->cbdata;
|
||||
|
||||
// return Pt_END to prevent this page from loading
|
||||
|
||||
//if (strcmp(c->url, "http://www.google.com/") == 0)
|
||||
// return (Pt_END);
|
||||
|
||||
printf("Callback: Open\n");
|
||||
|
||||
return (Pt_CONTINUE);
|
||||
}
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
|
@ -93,21 +280,19 @@ main(int argc, char **argv)
|
|||
PhDim_t win_dim = {700, 700};
|
||||
PhArea_t area = {{0, 0}, {70, 25}};
|
||||
|
||||
if (!PhWidLog)
|
||||
{
|
||||
PhWidLog = PR_NewLogModule("PhWidLog");
|
||||
}
|
||||
|
||||
// main window creation
|
||||
PtSetArg(&args[n++], Pt_ARG_TITLE, "PtMozilla Test\n", 0);
|
||||
PtSetArg(&args[n++], Pt_ARG_DIM, &win_dim, 0);
|
||||
window = PtAppInit(NULL, NULL, NULL, n, args);
|
||||
|
||||
// back button
|
||||
n = 0;
|
||||
PtSetArg(&args[n++], Pt_ARG_AREA, &area, 0);
|
||||
PtSetArg(&args[n++], Pt_ARG_TEXT_STRING, "Back", 0);
|
||||
back = PtCreateWidget(PtButton, window, n, args);
|
||||
PtAddCallback(back, Pt_CB_ACTIVATE, back_cb, NULL);
|
||||
|
||||
// forward button
|
||||
n = 0;
|
||||
area.pos.x += 71;
|
||||
PtSetArg(&args[n++], Pt_ARG_AREA, &area, 0);
|
||||
|
@ -115,6 +300,7 @@ main(int argc, char **argv)
|
|||
forward = PtCreateWidget(PtButton, window, n, args);
|
||||
PtAddCallback(forward, Pt_CB_ACTIVATE, forward_cb, NULL);
|
||||
|
||||
// reload button
|
||||
n = 0;
|
||||
area.pos.x += 71;
|
||||
PtSetArg(&args[n++], Pt_ARG_AREA, &area, 0);
|
||||
|
@ -122,6 +308,7 @@ main(int argc, char **argv)
|
|||
reload = PtCreateWidget(PtButton, window, n, args);
|
||||
PtAddCallback(reload, Pt_CB_ACTIVATE, reload_cb, NULL);
|
||||
|
||||
// stop button
|
||||
n = 0;
|
||||
area.pos.x += 71;
|
||||
PtSetArg(&args[n++], Pt_ARG_AREA, &area, 0);
|
||||
|
@ -129,20 +316,49 @@ main(int argc, char **argv)
|
|||
stop = PtCreateWidget(PtButton, window, n, args);
|
||||
PtAddCallback(stop, Pt_CB_ACTIVATE, stop_cb, NULL);
|
||||
|
||||
// url entry field
|
||||
n = 0;
|
||||
area.pos.x += 71;
|
||||
area.size.w = win_dim.w - area.pos.x - 2;
|
||||
PtSetArg(&args[n++], Pt_ARG_AREA, &area, 0);
|
||||
stop = PtCreateWidget(PtText, window, n, args);
|
||||
PtAddCallback(stop, Pt_CB_ACTIVATE, load_url_cb, NULL);
|
||||
url = PtCreateWidget(PtText, window, n, args);
|
||||
PtAddCallback(url, Pt_CB_ACTIVATE, load_url_cb, NULL);
|
||||
|
||||
// status field
|
||||
n = 0;
|
||||
area.pos.x = 0;
|
||||
area.pos.y = win_dim.h - 22;
|
||||
area.size.w = win_dim.w - 100;
|
||||
area.size.h = 22;
|
||||
PtSetArg(&args[n++], Pt_ARG_AREA, &area, 0);
|
||||
status = PtCreateWidget(PtLabel, window, n, args);
|
||||
|
||||
// progress bar
|
||||
n = 0;
|
||||
area.pos.x = area.size.w + 2;
|
||||
area.size.w = 97;
|
||||
PtSetArg(&args[n++], Pt_ARG_AREA, &area, 0);
|
||||
progress = PtCreateWidget(PtProgress, window, n, args);
|
||||
|
||||
n = 0;
|
||||
area.pos.y += area.size.h + 2;
|
||||
area.pos.y = 26;
|
||||
area.pos.x = 0;
|
||||
area.size.w = win_dim.w;
|
||||
area.size.h = win_dim.h - area.pos.y;
|
||||
area.size.h = win_dim.h - 26 - 22;
|
||||
PtSetArg(&args[n++], Pt_ARG_AREA, &area, 0);
|
||||
web = PtCreateWidget(PtMozilla, window, n, args);
|
||||
PtAddCallback(web, Pt_CB_MOZ_STATUS, moz_status_cb, NULL);
|
||||
PtAddCallback(web, Pt_CB_MOZ_START, moz_start_cb, NULL);
|
||||
PtAddCallback(web, Pt_CB_MOZ_COMPLETE, moz_complete_cb, NULL);
|
||||
PtAddCallback(web, Pt_CB_MOZ_PROGRESS, moz_progress_cb, NULL);
|
||||
PtAddCallback(web, Pt_CB_MOZ_URL, moz_url_cb, NULL);
|
||||
PtAddCallback(web, Pt_CB_MOZ_EVENT, moz_event_cb, NULL);
|
||||
PtAddCallback(web, Pt_CB_MOZ_NET_STATE, moz_net_state_change_cb, NULL);
|
||||
PtAddCallback(web, Pt_CB_MOZ_NEW_WINDOW, moz_new_window_cb, NULL);
|
||||
PtAddCallback(web, Pt_CB_MOZ_RESIZE, moz_resize_cb, NULL);
|
||||
PtAddCallback(web, Pt_CB_MOZ_DESTROY, moz_destroy_cb, NULL);
|
||||
PtAddCallback(web, Pt_CB_MOZ_VISIBILITY, moz_visibility_cb, NULL);
|
||||
PtAddCallback(web, Pt_CB_MOZ_OPEN, moz_open_cb, NULL);
|
||||
|
||||
PtRealizeWidget(window);
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче