filebuf UnicodeBugger::convert() { filebuf& u = this->converted_data; // Try the proposed encodings std::list<std::string>::iterator si; for( si = suggested_encodings.begin(); si != suggested_encodings.end(); ++si) { if ( convertFrom(*si) ){ return u; } } // Ok, try to find the UTF BOM or XML header... if ( detectUTFEncoding() ){ return u; } // Damn! Does this thing has a XML header or HTML Meta tag w/ encoding? if ( findEncodingByParsing()) { return u; } // we are out options here! Last options: utf-8 and latin1 if ( convertFrom("uf-8") || convertFrom("LATIN1") ) { return u; } // Nothing found? What a bummer! throw CannotFindSuitableEncodingException("Giving up"); }
JSBool cairo::JSSurface::Constructor(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { DOC_BEGIN(""); DOC_END; if (JSA_GetClass(cx,obj) != Class()) { JS_ReportError(cx,"Constructor for %s bad object; did you forget a 'new'?",ClassName()); return JS_FALSE; } NATIVE * newNative; cairo::JSSurface * myNewObject = 0; dom::NodePtr myImageNode; std::string myPath; if (argc == 1) { if (convertFrom(cx, argv[0], myImageNode)) { cairo_surface_t *mySurface = createFromImageNode(myImageNode); newNative = NATIVE::get(mySurface); cairo_surface_destroy(mySurface); } else if(convertFrom(cx, argv[0], myPath)) { cairo_surface_t *mySurface = cairo_image_surface_create_from_png(myPath.c_str()); newNative = NATIVE::get(mySurface); cairo_surface_destroy(mySurface); } else { JS_ReportError(cx, "Need an image node or png path to construct a cairo context."); return JS_FALSE; } } else { JS_ReportError(cx,"Constructor for %s: bad number of arguments: expected none () %d",ClassName(), argc); return JS_FALSE; } JSCairoSurfaceWrapper::STRONGPTR _myOwnerPtr(newNative); myNewObject = new cairo::JSSurface(dynamic_cast_Ptr<NATIVE>(_myOwnerPtr), newNative); JSCairoSurfaceWrapper::WEAKPTR _mySelfPtr(_myOwnerPtr); newNative->setSelfPtr(_mySelfPtr); myNewObject->_myImageNode = myImageNode; if (myNewObject) { JS_SetPrivate(cx,obj,myNewObject); return JS_TRUE; } JS_ReportError(cx,"cairo::JSSurface::Constructor: bad parameters"); return JS_FALSE; }
JSBool JSColorSelectionDialog::Constructor(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { DOC_BEGIN(""); DOC_END; ensureParamCount(argc,1,5); if (JSA_GetClass(cx,obj) != Class()) { JS_ReportError(cx,"Constructor for %s bad object; did you forget a 'new'?",ClassName()); return JS_FALSE; } NATIVE * newNative = 0; JSColorSelectionDialog * myNewObject = 0; if ( argc == 1) { string myTitle; convertFrom(cx, argv[0], myTitle); newNative = new NATIVE(myTitle); } else { newNative = new NATIVE(); } myNewObject = new JSColorSelectionDialog(OWNERPTR(newNative), newNative); if (myNewObject) { JS_SetPrivate(cx,obj,myNewObject); return JS_TRUE; } JS_ReportError(cx,"JSColorSelectionDialog::Constructor: failed"); return JS_FALSE; }
static JSBool writeToPNG(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { DOC_BEGIN(""); DOC_END; cairo_surface_t *mySurface = NULL; convertFrom(cx, OBJECT_TO_JSVAL(obj), mySurface); ensureParamCount(argc, 1); std::string myPath; convertFrom(cx, argv[0], myPath); cairo_surface_write_to_png(mySurface, myPath.c_str()); return checkForErrors(cx, mySurface); }
JSBool JSCheckButton::Constructor(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { DOC_BEGIN(""); DOC_END; if (JSA_GetClass(cx,obj) != Class()) { JS_ReportError(cx,"Constructor for %s bad object; did you forget a 'new'?",ClassName()); return JS_FALSE; } NATIVE * newNative = 0; JSCheckButton * myNewObject = 0; if (argc == 0) { newNative = new Gtk::CheckButton(); } else if (argc == 1) { Glib::ustring myLabel; convertFrom(cx, argv[0], myLabel); newNative = new Gtk::CheckButton(myLabel); } else { JS_ReportError(cx,"Constructor for %s: bad number of arguments: expected none () %d",ClassName(), argc); return JS_FALSE; } myNewObject = new JSCheckButton(OWNERPTR(newNative), newNative); if (myNewObject) { JS_SetPrivate(cx,obj,myNewObject); return JS_TRUE; } JS_ReportError(cx,"JSCheckButton::Constructor: bad parameters"); return JS_FALSE; }
static JSBool disconnect(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { DOC_BEGIN(""); DOC_END; sigc::connection * myNative(0); convertFrom(cx, OBJECT_TO_JSVAL(obj), myNative); myNative->disconnect(); return JS_TRUE; }
bool convertFrom(JSContext *cx, jsval theValue, cairo_surface_t *& theTarget) { cairo::JSSurface::NATIVE *myWrapper; if(convertFrom(cx, theValue, myWrapper)) { theTarget = myWrapper->getWrapped(); return true; } return false; }
JSBool JSVButtonBox::Constructor(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { DOC_BEGIN(""); DOC_END; if (JSA_GetClass(cx,obj) != Class()) { JS_ReportError(cx,"Constructor for %s bad object; did you forget a 'new'?",ClassName()); return JS_FALSE; } NATIVE * newNative = 0; JSVButtonBox * myNewObject = 0; if (argc == 0) { newNative = new Gtk::VButtonBox(); myNewObject = new JSVButtonBox(OWNERPTR(newNative), newNative); } else if (argc == 2) { int myStyle; if ( ! convertFrom(cx, argv[0], myStyle)) { JS_ReportError(cx,"Constructor for %s: argument 0 must be an int",ClassName()); return JS_FALSE; } int mySpacing; if ( ! convertFrom(cx, argv[1], mySpacing)) { JS_ReportError(cx,"Constructor for %s: argument 1 must be an int",ClassName()); return JS_FALSE; } newNative = new Gtk::VButtonBox(static_cast<Gtk::ButtonBoxStyle>(myStyle), mySpacing); myNewObject = new JSVButtonBox(OWNERPTR(newNative), newNative); } else { JS_ReportError(cx,"Constructor for %s: bad number of arguments: expected none or two () %d",ClassName(), argc); return JS_FALSE; } if (myNewObject) { JS_SetPrivate(cx,obj,myNewObject); return JS_TRUE; } JS_ReportError(cx,"JSVButtonBox::Constructor: bad parameters"); return JS_FALSE; }
static JSBool flush(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { DOC_BEGIN(""); DOC_END; cairo_surface_t *mySurface = NULL; convertFrom(cx, OBJECT_TO_JSVAL(obj), mySurface); ensureParamCount(argc, 0); cairo_surface_flush(mySurface); return checkForErrors(cx, mySurface); }
Value* ish3_ProgressBar::set_property(Value** arg_list, int count) { Value* val = arg_list[0]; Value* prop = arg_list[1]; if (prop == n_value) { if (parent_rollout != NULL && parent_rollout->page != NULL) { value = val->to_int(); if(value>100) value=100; if(value<0) value=0; // rebuild the dialog item // have to do this to update in loops on a page InvalidateRect(progbar,NULL,FALSE); SendMessage(progbar, WM_PAINT, 0, 0); } } else if (prop == n_color) { if (parent_rollout != NULL && parent_rollout->page != NULL) { colorPro = convertFrom(val->to_acolor()); InvalidateRect(progbar,NULL,FALSE); SendMessage(progbar, WM_PAINT, 0, 0); } } else if (prop == n_orient) { if (parent_rollout != NULL && parent_rollout->page != NULL) { if(val==n_horizontal) type = TYPE_HORIZ; if(val==n_vertical) type = TYPE_VERT; InvalidateRect(progbar,NULL,FALSE); SendMessage(progbar, WM_PAINT, 0, 0); } } else if (prop == n_text || prop == n_caption) // not displayed { const TCHAR *text = val->to_string(); // will throw error if not convertable caption = val->get_heap_ptr(); } else return RolloutControl::set_property(arg_list, count); return val; }
static JSBool getHeight(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { DOC_BEGIN(""); DOC_END; cairo_surface_t *mySurface = NULL; convertFrom(cx, OBJECT_TO_JSVAL(obj), mySurface); ensureParamCount(argc, 0); int myHeight = cairo_image_surface_get_height(mySurface); *rval = as_jsval(cx, myHeight); return checkForErrors(cx, mySurface); }
void DoubleRange::setRange(double vmin, double vmax, double vstep, int pageSize, ConversionMode mode) { vmin = convertFrom(vmin, mode); vmax = convertFrom(vmax, mode); bool rchg = ((d_maxValue != vmax) || (d_minValue != vmin)); if(!rchg && vstep == d_step && pageSize == d_pageSize) // p4.0.45 return; if (rchg) { d_minValue = vmin; d_maxValue = vmax; } // // look if the step width has an acceptable // value or otherwise change it. // setStep(vstep); // // limit page size // d_pageSize = MusECore::qwtLim(pageSize,0, int(MusECore::qwtAbs((d_maxValue - d_minValue) / d_step))); // // If the value lies out of the range, it // will be changed. Note that it will not be adjusted to // the new step width. setNewValue(d_value, false); // call notifier after the step width has been // adjusted. if (rchg) rangeChange(); }
JSBool JSMisc::setPropertySwitch(NATIVE & theNative, unsigned long theID, JSContext *cx, JSObject *obj, jsval id, jsval *vp) { switch (theID) { case 0: { Vector2f myAlignment; convertFrom(cx, *vp, myAlignment); theNative.set_alignment(myAlignment[0], myAlignment[1]); } default: return JSBASE::setPropertySwitch(theNative, theID, cx, obj, id, vp); } //return JS_TRUE; }
void ish3_ProgressBar::add_control(Rollout *ro, HWND parent, HINSTANCE hInstance, int& current_y) { caption = caption->eval(); const TCHAR* text = caption->eval()->to_string(); // We'll hang onto these... parent_rollout = ro; control_ID = next_id(); // Load in some values from the user, if they were given... Value* Vtmp = control_param(value); if(Vtmp==&unsupplied) value = 0; else value = Vtmp->to_int(); // Check orientation parameter type = TYPE_HORIZ; Value* Ttmp = control_param(orient); if(Ttmp!=&unsupplied&&Ttmp==n_vertical) type = TYPE_VERT; // Get the colour of the progress slider Value* Ctmp = control_param(color); if(Ctmp==&unsupplied) colorPro = RGB(30,10,190); else colorPro = convertFrom(Ctmp->to_acolor()); // Pass the inpho back to MXS to // let it calculate final position layout_data pos; compute_layout(ro, &pos, current_y); progbar = CreateWindow( PBAR_WINDOWCLASS, text, WS_VISIBLE | WS_CHILD | WS_GROUP, pos.left, pos.top, pos.width, pos.height, parent, (HMENU)control_ID, g_hInst, this); DWORD err = GetLastError(); }
void HttpCallback::callbackReg(HttpClient *sender, HttpResponse *response) { /*dismiss dialog*/ if(dlg) dlg->release(); do { if (!response) { state = Fail; break; } long statusCode = response->getResponseCode(); log("HTTP Status Code: %li, tag = %s", statusCode, response->getHttpRequest()->getTag()); if (!response->isSucceed()) { log("response failed"); log("error buffer: %s", response->getErrorBuffer()); if(on_fail) on_fail(VARIABLES_LOCAL("strings.json")->getString("server_conn_fail").c_str()); state = Fail; break; } // dump data std::vector<char> *buffer = response->getResponseData(); std::string data(buffer->begin(),buffer->end()); json_error_t error; json_t* json = json_loads(data.c_str(), 0, &error); if (json) { Value v = convertFrom(json); log("response:\n%s",v.getDescription().c_str()); if(on_ok) on_ok(v); state = OK; }else{ log("\nline:%d\ncol:%d\npos:%d\nsource:%s\ntext:%s", error.line,error.column,error.position,error.source,error.text); if(on_fail) on_fail(VARIABLES_LOCAL("strings.json")->getString("server_conn_fail").c_str()); state = Fail; } } while (0); checkAllHttpReqs(); this->release(); }
bool UnicodeBugger::findEncodingByParsing() { bool was_successful = false; filebuf data_cpy = this->data; filebuf u; std::string enc; unsigned int max_pos = MAX_META_POS; if ( data.len() < max_pos ) { max_pos = data.len(); } // latin1 is a good guess anyway, and won"t complain in most cases // about bad char. conversions try { // Convert the begining of data to latin1 IconvWrapper icw("latin1"); filebuf tmp = data_cpy.readf(max_pos); u = icw.convert(tmp); // XXX relese me later!!! // Read the document, tring to find it's advetised encoding FindEncParser e(u); e.parse(); enc = e.getEnc(); // Try the advertised encoding, if any. if (not enc.empty()) { was_successful = convertFrom(enc); } } catch (...){ // ignore any error! } // If u was used, clear it. if (u.start){ delete[] u.start; } return was_successful; }
bool UnicodeBugger::detectUTFEncoding() { bool was_successful = false; size_t length = data.len(); enc_list_t::const_iterator i; for(i = ALL_MARKS.begin(); i != ALL_MARKS.end(); ++i){ const std::string& enc = i->first; const std::string& mark = i->second; if (length > mark.size() and startswith(data,mark) ) { if ( convertFrom(enc) ) { was_successful = true; break; } } } return was_successful; }
void DoubleRange::fitValue(double x, ConversionMode mode) { setNewValue(convertFrom(x, mode), true); }
void DoubleRange::setValue(double x, ConversionMode mode) { setNewValue(convertFrom(x, mode), false); }
/// <summary> /// 色を作成します。 /// </summary> /// <param name="color"> /// RGB カラー /// </param> HSV(const Color& color) noexcept { convertFrom(color.r / 255.0, color.g / 255.0, color.b / 255.0, color.a / 255.0); }
/// <summary> /// 色を作成します。 /// </summary> /// <param name="col"> /// RGB カラー /// </param> HSV(const ColorF& color) noexcept { convertFrom(color.r, color.g, color.b, color.a); }