Permalink
Browse files

Adds accessors for showChrome, alpha, opacity, and resiable.

  • Loading branch information...
1 parent 326093c commit 4877b775cbbb098d8f8837e1145899c209fe29c3 @Benvie Benvie committed Jul 20, 2012
View
@@ -246,7 +246,11 @@ RefType.prototype = {
}
};
-var FrameImpl = new RefType(['left', 'top', 'width', 'height', 'title', 'state', 'topmost'], {
+var props = ['left', 'top', 'width', 'height', 'title', 'state', 'topmost', 'showChrome', 'resizable'];
+process.platform !== 'linux' && props.push('alpha');
+process.platform !== 'win32' && props.push('opacity');
+
+var FrameImpl = new RefType(props, {
get right(){
return screenWidth() - this.left - this.width;
},
View
@@ -5,6 +5,10 @@
#include <node.h>
#include <node_version.h>
+#define MAKE_BOOLEAN(v) (v)->BooleanValue()
+#define MAKE_INT32(v) (v)->Int32Value()
+#define MAKE_FLOAT(v) (v)->FloatValue()
+#define STRING_EQ(v, str) (v)->Equals(String::New(str))
// Easy throw exceptions
#define NODE_ERROR(str) \
ThrowException(Exception::Error(String::New(str)))
@@ -23,6 +27,18 @@
static v8::Handle<v8::Value> Get##Method(v8::Local<v8::String> property, const v8::AccessorInfo &info); \
static void Set##Method(v8::Local<v8::String> property, v8::Local<v8::Value> value, const v8::AccessorInfo &info);
+
+#define DECLARE_CPP_ACCESSOR(classname, propName, getType, setType) \
+void classname##::Set##propName##(Local<String> property, Local<Value> value, const AccessorInfo& info) { \
+ NativeWindow *window = ObjectWrap::Unwrap<NativeWindow>(info.Holder()); \
+ window->Set##propName##(##setType##(value)); \
+} \
+Handle<Value> classname##::Get##propName##(Local<String> property, const AccessorInfo &info) { \
+ HandleScope scope; \
+ NativeWindow *window = ObjectWrap::Unwrap<NativeWindow>(info.Holder()); \
+ return scope.Close(##getType##::New(window->Get##propName##())); \
+}
+
// Better node prototype method
#define DEFINE_PROTOTYPE_METHOD(Name, Method) \
NODE_SET_PROTOTYPE_METHOD (tpl, Name, Method)
View
@@ -39,8 +39,15 @@ void Window::Init () {
CREATE_CPP_ACCESSOR("title", Title);
CREATE_CPP_ACCESSOR("state", State);
CREATE_CPP_ACCESSOR("topmost", Topmost);
-
-#if defined(__WIN__)
+ CREATE_CPP_ACCESSOR("resizable", Resizable);
+ CREATE_CPP_ACCESSOR("showChrome", ShowChrome);
+#ifndef __LINUX__
+ CREATE_CPP_ACCESSOR("alpha", Alpha);
+#endif
+#ifndef __WIN__
+ CREATE_CPP_ACCESSOR("opacity", Opacity);
+#endif
+#ifdef __WIN__
DEFINE_PROTOTYPE_METHOD("style", Style);
#endif
@@ -232,47 +239,26 @@ Handle<Value> Window::SendSync(const Arguments& args) {
}
+#define WINDOW_ACCESSOR(propName, getType, setType) DECLARE_CPP_ACCESSOR(Window, propName, getType, setType)
+WINDOW_ACCESSOR(Left, Integer, MAKE_INT32)
+WINDOW_ACCESSOR(Top, Integer, MAKE_INT32)
+WINDOW_ACCESSOR(Width, Integer, MAKE_INT32)
+WINDOW_ACCESSOR(Height, Integer, MAKE_INT32)
+WINDOW_ACCESSOR(Title, String, V8StringToChar)
+WINDOW_ACCESSOR(Topmost, Boolean, MAKE_BOOLEAN)
+WINDOW_ACCESSOR(Resizable, Boolean, MAKE_BOOLEAN)
+WINDOW_ACCESSOR(ShowChrome, Boolean, MAKE_BOOLEAN)
+#ifndef __LINUX__
+WINDOW_ACCESSOR(Alpha, Boolean, MAKE_BOOLEAN)
+#endif
+#ifndef __WIN__
+WINDOW_ACCESSOR(Opacity, Number, MAKE_FLOAT)
+#endif
-Handle<Value> Window::GetLeft(Local<String> property, const AccessorInfo &info) {
- HandleScope scope;
- NativeWindow *window = ObjectWrap::Unwrap<NativeWindow>(info.Holder());
- return scope.Close(Integer::New(window->GetLeft()));
-}
-
-Handle<Value> Window::GetTop(Local<String> property, const AccessorInfo &info) {
- HandleScope scope;
- NativeWindow *window = ObjectWrap::Unwrap<NativeWindow>(info.Holder());
- return scope.Close(Integer::New(window->GetTop()));
-}
-
-Handle<Value> Window::GetWidth(Local<String> property, const AccessorInfo &info) {
- HandleScope scope;
- NativeWindow *window = ObjectWrap::Unwrap<NativeWindow>(info.Holder());
- return scope.Close(Integer::New(window->GetWidth()));
-}
-
-Handle<Value> Window::GetHeight(Local<String> property, const AccessorInfo &info) {
- HandleScope scope;
- NativeWindow *window = ObjectWrap::Unwrap<NativeWindow>(info.Holder());
- return scope.Close(Integer::New(window->GetHeight()));
-}
-
-Handle<Value> Window::GetTitle(Local<String> property, const AccessorInfo &info) {
- HandleScope scope;
- NativeWindow *window = ObjectWrap::Unwrap<NativeWindow>(info.Holder());
- return scope.Close(String::New(window->GetTitle()));
-}
-
-Handle<Value> Window::GetTopmost(Local<String> property, const AccessorInfo &info) {
- HandleScope scope;
- NativeWindow *window = ObjectWrap::Unwrap<NativeWindow>(info.Holder());
- return scope.Close(Boolean::New(window->GetTopmost()));
-}
-
Handle<Value> Window::GetState(Local<String> property, const AccessorInfo &info) {
HandleScope scope;
NativeWindow *window = ObjectWrap::Unwrap<NativeWindow>(info.Holder());
@@ -298,52 +284,21 @@ Handle<Value> Window::GetState(Local<String> property, const AccessorInfo &info)
-void Window::SetLeft(Local<String> property, Local<Value> value, const AccessorInfo& info) {
- NativeWindow *window = ObjectWrap::Unwrap<NativeWindow>(info.Holder());
- window->SetLeft(value->Int32Value());
-}
-
-void Window::SetTop(Local<String> property, Local<Value> value, const AccessorInfo& info) {
- NativeWindow *window = ObjectWrap::Unwrap<NativeWindow>(info.Holder());
- window->SetTop(value->Int32Value());
-}
-
-void Window::SetWidth(Local<String> property, Local<Value> value, const AccessorInfo& info) {
- NativeWindow *window = ObjectWrap::Unwrap<NativeWindow>(info.Holder());
- window->SetWidth(value->Int32Value());
-}
-
-void Window::SetHeight(Local<String> property, Local<Value> value, const AccessorInfo& info) {
- NativeWindow *window = ObjectWrap::Unwrap<NativeWindow>(info.Holder());
- window->SetHeight(value->Int32Value());
-}
-
-void Window::SetTitle(Local<String> property, Local<Value> value, const AccessorInfo& info) {
- NativeWindow *window = ObjectWrap::Unwrap<NativeWindow>(info.Holder());
- window->SetTitle(V8StringToChar(value->ToString()));
-}
-
-void Window::SetTopmost(Local<String> property, Local<Value> value, const AccessorInfo& info) {
- NativeWindow *window = ObjectWrap::Unwrap<NativeWindow>(info.Holder());
- window->SetTopmost(value->BooleanValue());
-}
-
void Window::SetState(Local<String> property, Local<Value> value, const AccessorInfo& info) {
NativeWindow *window = ObjectWrap::Unwrap<NativeWindow>(info.Holder());
Local<String> val = value->ToString();
- if (val->Equals(String::New("normal"))) {
+ if (STRING_EQ(val, "normal")) {
window->SetState(NW_STATE_NORMAL);
- } else if (val->Equals(String::New("minimized"))) {
+ } else if (STRING_EQ(val, "minimized")) {
window->SetState(NW_STATE_MINIMIZED);
- } else if (val->Equals(String::New("maximized"))) {
+ } else if (STRING_EQ(val, "maximized")) {
window->SetState(NW_STATE_MAXIMIZED);
- } else if (val->Equals(String::New("fullscreen"))) {
+ } else if (STRING_EQ(val, "fullscreen")) {
window->SetState(NW_STATE_FULLSCREEN);
}
}
-
#if defined(__WIN__)
// Handle<Value> Window::SetNonclientWidth(const Arguments& args) {
View
@@ -33,6 +33,15 @@ class Window : public node::ObjectWrap {
DEFINE_CPP_ACCESSOR(Title);
DEFINE_CPP_ACCESSOR(Topmost);
DEFINE_CPP_ACCESSOR(State);
+ DEFINE_CPP_ACCESSOR(Resizable);
+ DEFINE_CPP_ACCESSOR(ShowChrome);
+#ifndef __LINUX__
+ DEFINE_CPP_ACCESSOR(Alpha);
+#endif
+#ifndef __WIN__
+ DEFINE_CPP_ACCESSOR(Opacity);
+#endif
+
#if defined(__WIN__)
DEFINE_CPP_METHOD(Style);
@@ -13,10 +13,10 @@ NativeWindow::NativeWindow(char* url, Settings* settings){
rect_.height = settings->getNumber("height",600);
rect_.left = settings->getNumber("left",-1);
rect_.top = settings->getNumber("top",-1);
- opacity = settings->getNumber("opacity",1);
- alpha = settings->getBoolean("alpha",false);
- show_chrome = settings->getBoolean("showChrome",true);
- resizable = settings->getBoolean("resizable",true);
+ opacity_ = settings->getNumber("opacity",1);
+ alpha_ = settings->getBoolean("alpha",false);
+ show_chrome_ = settings->getBoolean("showChrome",true);
+ resizable_ = settings->getBoolean("resizable",true);
show_resize_grip = settings->getBoolean("showResizeGrip",false);
auto_resize = settings->getBoolean("autoResize",false);
fullscreen_ = settings->getBoolean("fullscreen",false);
@@ -54,6 +54,18 @@ class NativeWindow {
NW_STATE GetState();
void SetTopmost(bool ontop);
bool GetTopmost();
+ void SetShowChrome(bool showChrome);
+ bool GetShowChrome();
+ void SetResizable(bool resizable);
+ bool GetResizable();
+#ifndef __LINUX__
+ void SetAlpha(bool alpha);
+ bool GetAlpha();
+#endif
+#ifndef __WIN__
+ void SetOpacity(double opacity);
+ double GetOpacity();
+#endif
void SetLeft(int left);
void SetTop(int top);
@@ -91,14 +103,14 @@ class NativeWindow {
v8::Handle<v8::Object> v8handle_;
CefRefPtr<CefBrowser> browser_;
- bool show_chrome;
- bool resizable;
+ bool show_chrome_;
+ bool resizable_;
bool show_resize_grip;
bool fullscreen_;
bool topmost_;
Settings* icons;
- bool alpha;
- double opacity;
+ bool alpha_;
+ double opacity_;
appjs_rect rect_;
appjs_rect restoreRect_;
@@ -18,9 +18,7 @@
browser_settings.web_security_disabled = settings->getBoolean("disableSecurity",false);
- if (settings->getBoolean("alpha", false)) {
- window_info.SetTransparentPainting(true);
- }
+ window_info.SetTransparentPainting(true);
NSRect contentFrame = [ParentWidget frame];
@@ -19,9 +19,7 @@ void CefBase::AddWebView(CefWindowHandle hWndParent,RECT windowRect,char* url,Se
browserSettings.web_security_disabled = settings->getBoolean("disableSecurity", false);
window_info.SetAsChild(hWndParent, windowRect);
- if (settings->getBoolean("alpha", false)) {
- window_info.SetTransparentPainting(true);
- }
+ window_info.SetTransparentPainting(true);
CefBrowser::CreateBrowser(window_info,
@@ -5,12 +5,14 @@ namespace appjs {
using namespace v8;
char* V8StringToChar(Handle<String> str) {
-
int len = str->Utf8Length();
char* buf = new char[len + 1];
str->WriteUtf8(buf, len + 1);
return buf;
}
+char* V8StringToChar(Local<Value> val) {
+ return V8StringToChar(val->ToString());
+}
#if defined(__WIN__)
WCHAR* V8StringToWCHAR(Handle<String> str) {
View
@@ -12,6 +12,7 @@ WCHAR* V8StringToWCHAR(v8::Handle<v8::String> str);
#endif
char* V8StringToChar(v8::Handle<v8::String> str);
+char* V8StringToChar(v8::Local<v8::Value> val);
char* V8StringToFunctionChar(v8::Handle<v8::String> str);
v8::Local<v8::String> CefStringToV8(const CefString& str);
CefRefPtr<CefV8Value> V8StringToCef(v8::Handle<v8::Value> str);
@@ -56,8 +56,8 @@ void NativeWindow::Init(char* url, Settings* settings) {
}
gtk_window_set_default_size(window, rect_.width, rect_.height);
- gtk_window_set_opacity(window, opacity);
- gtk_window_set_decorated(window, show_chrome);
+ gtk_window_set_opacity(window, opacity_);
+ gtk_window_set_decorated(window, show_chrome_);
#if defined(__UBUNTU__) && !GTK_CHECK_VERSION(2, 24, 10)
if(gtk_check_version(2, 24, 10))
@@ -67,7 +67,7 @@ void NativeWindow::Init(char* url, Settings* settings) {
if( fullscreen_ ) {
Fullscreen();
} else {
- gtk_window_set_resizable(window, resizable);
+ gtk_window_set_resizable(window, resizable_);
}
if( !resizable ) {
@@ -206,4 +206,33 @@ void NativeWindow::SetTopmost(bool ontop){
topmost_ = ontop;
}
+
+void NativeWindow::SetResizable(bool resizable) {
+ resizable_ = resizable;
+ gtk_window_set_resizable((GtkWindow*)handle_, resizable);
+}
+
+bool NativeWindow::GetResizable() {
+ return gtk_window_get_resizable((GtkWindow*)handle_);
+}
+
+void NativeWindow::SetShowChrome(bool showChrome) {
+ show_chrome_ = showChrome;
+ gtk_window_set_decorated((GtkWindow*)handle_, showChrome);
+}
+
+bool NativeWindow::GetShowChrome() {
+ return gtk_window_get_decorated((GtkWindow*)handle_);
+}
+
+void NativeWindow::SetOpacity(double opacity) {
+ opacity_ = opacity;
+ gtk_window_set_opacity((GtkWindow*)handle_, opacity);
+}
+
+bool NativeWindow::GetOpacity() {
+ return gtk_window_get_opacity((GtkWindow*)handle_);
+}
+
+
} /* appjs */
Oops, something went wrong.

0 comments on commit 4877b77

Please sign in to comment.