📄 appuifwmodule.cpp
字号:
selected_items = NULL;
icons = NULL;
return SPyErr_SetFromSymbianOSErr(error);
}
if (isChkbx) {
#if SERIES60_VERSION>=28
TRAP(error,
{
CFbsBitmap* bitMapOn = NULL;
CFbsBitmap* maskOn = NULL;
AknIconUtils::CreateIconL(bitMapOn,
maskOn,
KIconsFile,
EMbmAvkonQgn_prop_checkbox_on,
EMbmAvkonQgn_prop_checkbox_on_mask);
icons->AppendL(CGulIcon::NewL(bitMapOn, maskOn));
CFbsBitmap* bitMapOff = NULL;
CFbsBitmap* maskOff = NULL;
AknIconUtils::CreateIconL(bitMapOff,
maskOff,
KIconsFile,
EMbmAvkonQgn_prop_checkbox_off,
EMbmAvkonQgn_prop_checkbox_off_mask);
icons->AppendL(CGulIcon::NewL(bitMapOff, maskOff));
});
} else
TRAP(error,
{
CFbsBitmap* bitMap = NULL;
CFbsBitmap* mask = NULL;
AknIconUtils::CreateIconL(bitMap,
mask,
KIconsFile,
EMbmAvkonQgn_indi_marked_add,
EMbmAvkonQgn_indi_marked_add_mask);
icons->AppendL(CGulIcon::NewL(bitMap, mask));
});
#else
CEikonEnv* env = CEikonEnv::Static();
TRAP(error, {
icons->AppendL(env->CreateIconL(KIconsFile, EMbmAvkonQgn_prop_checkbox_on,
EMbmAvkonQgn_prop_checkbox_on_mask));
icons->AppendL(env->CreateIconL(KIconsFile, EMbmAvkonQgn_prop_checkbox_off,
EMbmAvkonQgn_prop_checkbox_off_mask));
});
} else {
CEikonEnv* env = CEikonEnv::Static();
TRAP(error, icons->AppendL(env->CreateIconL(KIconsFile,
EMbmAvkonQgn_indi_marked_add, EMbmAvkonQgn_indi_marked_add_mask)));
}
#endif /* SERIES60_VERSION */
if (error != KErrNone) {
delete items_list;
items_list = NULL;
delete selected_items;
selected_items = NULL;
delete icons;
icons = NULL;
return SPyErr_SetFromSymbianOSErr(error);
}
TInt index = (-1);
CAknMarkableListDialog *dlg = NULL;
if (error == KErrNone) {
Py_BEGIN_ALLOW_THREADS
TRAP(error, {
dlg = CAknMarkableListDialog::NewL(index, selected_items, items_list,
R_AVKON_DIALOG_EMPTY_MENUBAR);
if (isChkbx && (search == 0))
dlg->PrepareLC(R_APPUIFW_MULTI_SEL_LIST);
else if (isChkbx && (search == 1))
dlg->PrepareLC(R_APPUIFW_MULTI_SEL_LIST_QUERY);
else if (!isChkbx && (search == 0))
dlg->PrepareLC(R_APPUIFW_MARKABLE_SEL_LIST);
else if (!isChkbx && (search == 1))
dlg->PrepareLC(R_APPUIFW_MARKABLE_SEL_LIST_QUERY);
dlg->SetIconArrayL(icons);
dlg->RunLD();
});
Py_END_ALLOW_THREADS
if (error != KErrNone) {
delete items_list;
items_list = NULL;
delete selected_items;
selected_items = NULL;
return SPyErr_SetFromSymbianOSErr(error);
}
TInt selItemNum = selected_items->Count();
selected = PyTuple_New(selItemNum);
for (int i=0; i < selItemNum; i++)
error = PyTuple_SetItem(selected, i, Py_BuildValue(
"i", selected_items->operator[](i)) );
}
delete items_list;
items_list = NULL;
delete selected_items;
selected_items = NULL;
if (error == KErrNone)
return selected;
else
RETURN_ERROR_OR_PYNONE(error);
}
/*
*
* Implementation of appuifw.query()
*
*/
static TReal epoch_local_as_TReal()
{
#ifndef EKA2
TLocale loc;
return (epoch_as_TReal()+
((1000.0*1000.0)*
TInt64(loc.UniversalTimeOffset().Int()).GetTReal()));
#else
TLocale loc;
return (epoch_as_TReal()+
((1000.0*1000.0)*
TReal64(TInt64(loc.UniversalTimeOffset().Int()))));
#endif /*EKA2*/
}
static TReal datetime_as_TReal(const TTime& aTime)
{
#ifndef EKA2
TDateTime dt = aTime.DateTime();
return TInt64((dt.Hour()*3600)+(dt.Minute()*60)).GetTReal();
#else
TDateTime dt = aTime.DateTime();
return TReal64(TInt64((dt.Hour()*3600)+(dt.Minute()*60)));
#endif /*EKA2*/
}
static TReal datetime_with_secs_as_TReal(const TTime& aTime)
{
#ifndef EKA2
TDateTime dt = aTime.DateTime();
return TInt64((dt.Hour()*3600)+(dt.Minute()*60)+(dt.Second())).GetTReal();
#else
TDateTime dt = aTime.DateTime();
return TReal64(TInt64((dt.Hour()*3600)+(dt.Minute()*60)+(dt.Second())));
#endif /*EKA2*/
}
static TInt rid_by_type(const TDesC8& aName)
{
if (aName.Compare(KTextFieldType) == 0)
return R_APPUIFW_DATA_QUERY;
if (aName.Compare(KNumberFieldType) == 0)
return R_APPUIFW_NUMBER_QUERY;
if (aName.Compare(KFloatFieldType) == 0)
return R_APPUIFW_FLOAT_QUERY;
if (aName.Compare(KCodeFieldType) == 0)
return R_APPUIFW_CODE_QUERY;
if (aName.Compare(KDateFieldType) == 0)
return R_APPUIFW_DATE_QUERY;
if (aName.Compare(KTimeFieldType) == 0)
return R_APPUIFW_TIME_QUERY;
if (aName.Compare(KQueryFieldType) == 0)
return R_APPUIFW_CONFIRMATION_QUERY;
return -1;
}
extern "C" PyObject *
query(PyObject* /*self*/, PyObject *args)
{
int l_label, l_type;
char *b_label, *b_type;
PyObject* inival = NULL;
PyObject* retval = NULL;
if (!PyArg_ParseTuple(args, "u#s#|O", &b_label, &l_label,
&b_type, &l_type, &inival))
return NULL;
TInt error = KErrNone;
CAknQueryDialog* dlg = NULL;
TPtr buf(NULL, 0);
TInt num = 0;
TReal num_real = 0;
TTime time;
TInt rid = rid_by_type(TPtrC8((TUint8*)b_type, l_type));
switch(rid) {
case R_APPUIFW_DATA_QUERY:
if (retval = PyUnicode_FromUnicode(NULL, KAppuifwMaxTextField)) {
buf.Set(PyUnicode_AsUnicode(retval), 0, KAppuifwMaxTextField);
if (inival && PyUnicode_Check(inival))
buf.Copy(PyUnicode_AsUnicode(inival), PyUnicode_GetSize(inival));
TRAP(error, {
dlg = CAknTextQueryDialog::NewL(buf, CAknQueryDialog::ENoTone);
((CAknTextQueryDialog*)dlg)->SetMaxLength(KAppuifwMaxTextField);
});
if (error == KErrNone)
dlg->SetPredictiveTextInputPermitted(ETrue);
}
else
error = KErrPython;
break;
case R_APPUIFW_NUMBER_QUERY:
if (inival && PyInt_Check(inival))
num = PyLong_AsLong(inival);
TRAP(error, {
dlg = CAknNumberQueryDialog::NewL(num, CAknQueryDialog::ENoTone);
});
break;
case R_APPUIFW_FLOAT_QUERY:
if (inival && PyFloat_Check(inival))
num_real = PyFloat_AsDouble(inival);
TRAP(error, {
dlg = CAknFloatingPointQueryDialog::NewL(num_real, CAknQueryDialog::ENoTone);
});
break;
case R_APPUIFW_CODE_QUERY:
if (retval = PyUnicode_FromUnicode(NULL, KAppuifwMaxTextField)) {
buf.Set(PyUnicode_AsUnicode(retval), 0, KAppuifwMaxTextField);
TRAP(error, {
dlg = CAknTextQueryDialog::NewL(buf, CAknQueryDialog::ENoTone);
((CAknTextQueryDialog*)dlg)->SetMaxLength(KAppuifwMaxTextField);
});
}
else
error = KErrPython;
break;
case R_APPUIFW_DATE_QUERY:
case R_APPUIFW_TIME_QUERY:
time = (rid == R_APPUIFW_DATE_QUERY) ? epoch_local_as_TReal() : 0.0;
if (inival && PyFloat_Check(inival))
time += TTimeIntervalSeconds(PyFloat_AsDouble(inival));
TRAP(error, {
dlg = CAknTimeQueryDialog::NewL(time, CAknQueryDialog::ENoTone);
});
break;
case R_APPUIFW_CONFIRMATION_QUERY:
TRAP(error, (dlg = CAknQueryDialog::NewL()));
break;
default:
PyErr_SetString(PyExc_ValueError, "unknown query type");
return NULL;
}
TInt user_response = 0;
if (error == KErrNone) {
TRAP(error, {
dlg->SetPromptL(TPtrC((TUint16 *)b_label, l_label));
Py_BEGIN_ALLOW_THREADS
user_response = dlg->ExecuteLD(rid);
Py_END_ALLOW_THREADS
});
}
if (error != KErrNone) {
delete dlg;
Py_XDECREF(retval);
return SPyErr_SetFromSymbianOSErr(error);
}
else if (!user_response) {
Py_XDECREF(retval);
Py_INCREF(Py_None);
return Py_None;
}
else {
switch(rid) {
case R_APPUIFW_DATA_QUERY:
case R_APPUIFW_CODE_QUERY:
PyUnicode_Resize(&retval, buf.Length());
break;
case R_APPUIFW_NUMBER_QUERY:
retval = Py_BuildValue("i", num);
break;
case R_APPUIFW_FLOAT_QUERY:
retval = Py_BuildValue("d", num_real);
break;
case R_APPUIFW_DATE_QUERY:
retval = Py_BuildValue("d", time_as_UTC_TReal(time));
break;
case R_APPUIFW_TIME_QUERY:
retval = Py_BuildValue("d", datetime_as_TReal(time));
break;
case R_APPUIFW_CONFIRMATION_QUERY:
default:
retval = Py_True;
Py_INCREF(Py_True);
break;
}
return retval;
}
}
/*
*
* Implementation of appuifw.Icon
*
*/
struct icon_data {
TBuf<KMaxFileName> ob_file;
int ob_bmpId;
int ob_maskId;
};
struct Icon_object {
PyObject_VAR_HEAD
icon_data* icon;
};
extern "C" PyObject *
new_Icon_object(PyObject* /*self*/, PyObject* args)
{
char *b_file;
int l_file, bitmapId, maskId;
if (!PyArg_ParseTuple(args, "u#ii", &b_file, &l_file, &bitmapId, &maskId))
return NULL;
if (l_file <=0 || l_file > KMaxFileName) {
PyErr_SetString(PyExc_TypeError,
"expected valid file name");
return NULL;
}
TBuf<KMaxFileName> fileName;
fileName.FillZ(KMaxFileName);
fileName.Copy((TUint16*)b_file, l_file);
TParsePtrC p(fileName);
#if SERIES60_VERSION>=28
if (!((p.Ext().CompareF(_L(".mbm")) == 0) ||
(p.Ext().CompareF(_L(".mif")) == 0))) {
#else
if (!(p.Ext().CompareF(_L(".mbm")) == 0)) {
#endif /* SERIES60_VERSION */
PyErr_SetString(PyExc_TypeError,
"expected valid icon file");
return NULL;
}
if (bitmapId <0 || maskId <0) {
PyErr_SetString(PyExc_TypeError,
"expected valid icon and icon mask indexes");
return NULL;
}
/* Panic occurs e.g. in AknIconUtils if the indeces are bigger than KMaxTInt16 */
if (bitmapId > KMaxTInt16 || maskId > KMaxTInt16) {
PyErr_SetString(PyExc_TypeError,
"expected valid icon and icon mask indexes");
return NULL;
}
Icon_object *io = PyObject_New(Icon_object, &Icon_type);
if (io == NULL)
return PyErr_NoMemory();
io->icon = new icon_data();
if (io->icon == NULL) {
PyObject_Del(io);
return PyErr_NoMemory();
}
io->icon->ob_file.FillZ(KMaxFileName);
io->icon->ob_file.Copy((TUint16*)b_file, l_file);
io->icon->ob_bmpId = bitmapId;
io->icon->ob_maskId = maskId;
return (PyObject *) io;
}
extern "C" {
static void
Icon_dealloc(Icon_object *op)
{
delete op->icon;
op->icon = NULL;
PyObject_Del(op);
}
const static PyMethodDef Icon_methods[] = {
{NULL, NULL} // sentinel
};
static PyObject *
Icon_getattr(Icon_object *op, char *name)
{
if (!strcmp(name, UICONTROLAPI_NAME)) {
Py_INCREF(op);
return PyCObject_FromVoidPtr(op,_uicontrolapi_decref);
}
return Py_FindMethod((PyMethodDef*)Icon_methods,
(PyObject *)op, name);
}
static int
Icon_setattr(Icon_object * /*op*/, char * /*name*/, PyObject * /*v*/)
{
PyErr_SetString(PyExc_AttributeError, "no such attribute");
return -1;
}
static const PyTypeObject c_Icon_type = {
PyObject_HEAD_INIT(NULL)
0, /*ob_size*/
"appuifw.Icon", /*tp_name*/
sizeof(Icon_object), /*tp_basicsize*/
0, /*tp_itemsize*/
/* methods */
(destructor)Icon_dealloc, /*tp_dealloc*/
0, /*tp_print*/
(getattrfunc)Icon_getattr, /*tp_getattr*/
(setattrfunc)Icon_setattr, /*tp_setattr*/
0, /*tp_compare*/
0, /*tp_repr*/
0, /*tp_as_number*/
0, /*tp_as_sequence*/
0, /*tp_as_mapping*/
0, /*tp_hash*/
};
} // extern "C"
/*
*
* Implementation of appuifw.Listbox
*
*/
class CListBoxCallback : public CBase, public MEikListBoxObserver {
public:
CListBoxCallback(PyObject *aCallback, PyObject *aListBox) {
iListBox=aListBox;
iCallback=aCallback;
Py_XINCREF(iCallback);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -