Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TIMOB-10542] Window modal option #109

Merged
merged 1 commit into from
Jun 27, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 24 additions & 6 deletions src/tibb/NativeWindowObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <bb/cascades/Image>
#include <bb/cascades/Page>
#include <bb/cascades/TitleBar>
#include <bb/cascades/Sheet>
#include <bb/device/DisplayInfo>

#include "EventHandler.h"
Expand All @@ -36,7 +37,7 @@ NativeObject* NativeWindowObject::createWindow(TiObject* tiObject, NativeObjectF
}

NativeWindowObject::NativeWindowObject(TiObject* tiObject)
: NativeControlObject(tiObject, N_TYPE_WINDOW)
: NativeControlObject(tiObject, N_TYPE_WINDOW), modalSheet_(NULL), title_(" ")
{
}

Expand Down Expand Up @@ -75,14 +76,27 @@ int NativeWindowObject::setOrientationModes(TiObject* obj) {
}

int NativeWindowObject::setTitle(TiObject* obj) {
QString title = QString::fromUtf8(*String::Utf8Value(obj->getValue()));
scene_.titleBar()->setTitle(title);
title_ = QString::fromUtf8(*String::Utf8Value(obj->getValue()));
scene_.titleBar()->setTitle(title_);
return NATIVE_ERROR_OK;
}

void NativeWindowObject::open()
void NativeWindowObject::open(bool modal)
{
SceneManager::instance()->presentScene(&scene_);
if(SceneManager::instance()->activeScene() == NULL) {
// At least one scene needs to be in place, AKA: one window needs to be opened.
modal = false;
}
if(modal) {
scene_.titleBar()->setTitle(title_);
modalSheet_ = bb::cascades::Sheet::create();
modalSheet_->setContent(scene_.pane());
modalSheet_->setPeekEnabled(false);
modalSheet_->open();
scene_.changeState(Scene::STATE_ONSTAGE);
} else {
SceneManager::instance()->presentScene(&scene_);
}
events_["open"]->container()->fireEvent();
}

Expand All @@ -92,7 +106,11 @@ void NativeWindowObject::close()
// This window is not currently open.
return;
}
scene_.close();
if(modalSheet_ == NULL) {
scene_.close();
} else {
modalSheet_->close();
}
events_["close"]->container()->fireEvent();
}

Expand Down
11 changes: 10 additions & 1 deletion src/tibb/NativeWindowObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@
#include "NativeControlObject.h"
#include "PageScene.h"

namespace bb
{
namespace cascades
{
class Sheet;
}
}
class NativeWindowObject : public NativeControlObject {
public:
static NativeObject* createWindow(TiObject* tiObject, NativeObjectFactory* factory);
Expand All @@ -26,7 +33,7 @@ class NativeWindowObject : public NativeControlObject {
virtual int setOrientationModes(TiObject* obj);
virtual int setTitle(TiObject* obj);

void open();
void open(bool);
void close();

void addAction(const QString& title, const QString& image, v8::Handle<v8::Function> triggerCallback);
Expand All @@ -39,6 +46,8 @@ class NativeWindowObject : public NativeControlObject {
explicit NativeWindowObject(TiObject* tiObject);

titanium::PageScene scene_;
bb::cascades::Sheet* modalSheet_;
QString title_;
};

#endif
11 changes: 9 additions & 2 deletions src/tibb/TiUIWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ void TiUIWindow::initializeTiObject(TiObject* parentContext)
}
}

Handle<Value> TiUIWindow::_open(void* userContext, TiObject*, const Arguments&)
Handle<Value> TiUIWindow::_open(void* userContext, TiObject*, const Arguments& args)
{
HandleScope scope;
TiUIWindow* self = static_cast<TiUIWindow*>(userContext);
Expand All @@ -58,7 +58,14 @@ Handle<Value> TiUIWindow::_open(void* userContext, TiObject*, const Arguments&)
(*it)->setupEvents();
}

window->open();
if(args.Length() > 0 && args[0]->IsObject())
{
Local<Object> modal = args[0]->ToObject();
Local<Boolean> isTrue = modal->Get(String::New("modal"))->ToBoolean();
window->open(isTrue->Value());
} else {
window->open(false);
}
window->release(); // XXX(josh): Do we really want to release now?

return Undefined();
Expand Down