⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 appuifwmodule.cpp

📁 python s60 1.4.5版本的源代码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
      PyErr_SetString(PyExc_ValueError, "Listbox type mismatch");
      return NULL;
    }
  }
  
  if (current) {
    int sz = PyList_Size(list);
    if (current >= sz)
      current = sz-1;
  }

  CDesCArray *items_list = NULL;
  self->ob_icons = NULL;

  if ( (self->ob_lb_type==ESingleGraphicListbox) || (self->ob_lb_type==EDoubleGraphicListbox) ) 
    TRAP(error,
	 self->ob_icons = new(ELeave) CArrayPtrFlat<CGulIcon>(5));

  if (error != KErrNone)
    return SPyErr_SetFromSymbianOSErr(error);

  error = Listbox_create_itemslist(self->ob_lb_type, list, items_list, NULL, self->ob_icons);

  if (error != KErrNone)
    return SPyErr_SetFromSymbianOSErr(error);
  else {
    if (self->ob_lb_type == ESingleListbox)
      ((CAknSingleStyleListBox*)self->ob_control)->
        Model()->SetItemTextArray(items_list);
    else
      if (self->ob_lb_type == EDoubleListbox)
        ((CAknDoubleStyleListBox*)self->ob_control)->
          Model()->SetItemTextArray(items_list);
      else
        if (self->ob_lb_type == ESingleGraphicListbox) {
	  if (self->ob_icons != NULL) 
	    ((CAknColumnListBox*)self->ob_control)->ItemDrawer()->ColumnData()->SetIconArray(self->ob_icons);  
          ((CAknSingleGraphicStyleListBox*)self->ob_control)->Model()->SetItemTextArray(items_list);    
	}
	else
	  if (self->ob_lb_type == EDoubleGraphicListbox) {
  	  CTextListBoxModel* model;
  		model = ((CAknDoubleLargeStyleListBox*)self->ob_control)->Model();
  		TInt noOfItems = (model->NumberOfItems());
  		MDesCArray* textArray = ((CAknDoubleLargeStyleListBox*)self->ob_control)->Model()->ItemTextArray();
  		CDesCArray* itemList = static_cast<CDesCArray*>(textArray);
  		itemList->Delete(0, noOfItems);		  		     
        ((CEikFormattedCellListBox*)self->ob_control)->ItemDrawer()->ColumnData()->IconArray()->ResetAndDestroy();
        delete ((CEikFormattedCellListBox*)self->ob_control)->ItemDrawer()->ColumnData()->IconArray(); 
  		((CAknDoubleLargeStyleListBox*)self->ob_control)->Model()->SetItemTextArray(items_list);
  		if (self->ob_icons != NULL) 
  			 	((CEikFormattedCellListBox*)self->ob_control)->ItemDrawer()->ColumnData()->SetIconArray(self->ob_icons);   
	  }

    self->ob_control->Reset();
    if (current)
      self->ob_control->SetCurrentItemIndex(current);
    MY_APPUI->RefreshHostedControl();

    Py_INCREF(Py_None);
    return Py_None;
  }
}

extern "C" PyObject *
Listbox_bind(Listbox_object *self, PyObject* args)
{
  int key_code;
  PyObject* c;
  
  if (!PyArg_ParseTuple(args, "iO", &key_code, &c))
    return NULL;
  
  if (c == Py_None)
    c = NULL;
  else if (!PyCallable_Check(c)) {
    PyErr_SetString(PyExc_TypeError, "callable expected");
    return NULL;
  }

  SAppuifwEventBinding bind_info;

  bind_info.iType = SAmarettoEventInfo::EKey;
  bind_info.iKeyEvent.iCode = key_code;
  bind_info.iKeyEvent.iModifiers = 0;
  bind_info.iCb = c;
  Py_XINCREF(c);

  TRAPD(error, self->ob_event_bindings->InsertEventBindingL(bind_info));

  if (error != KErrNone)
    Py_XDECREF(c);

  RETURN_ERROR_OR_PYNONE(error);
}

extern "C" {
  static void
  Listbox_dealloc(Listbox_object *op)
  {
    delete op->ob_listbox_callback;
    op->ob_listbox_callback = NULL;

    delete op->ob_event_bindings;
    op->ob_event_bindings = NULL;

    delete op->ob_control;
    op->ob_control = NULL;  
    op->ob_icons = NULL;

    PyObject_Del(op);
  }

  const static PyMethodDef Listbox_methods[] = {
    {"current", (PyCFunction)Listbox_index, METH_NOARGS},
    {"set_list", (PyCFunction)Listbox_set_list, METH_VARARGS},
    {"bind", (PyCFunction)Listbox_bind, METH_VARARGS},
    {NULL,              NULL}           // sentinel
  };

  static PyObject *
  Listbox_getattr(Listbox_object *op, char *name)
  {
    if (!strcmp(name, UICONTROLAPI_NAME)) {
      Py_INCREF(op);
      return PyCObject_FromVoidPtr(op,_uicontrolapi_decref);
    }
#if S60_VERSION>=30
    if (!strcmp(name, "size")) {
      TRect rect; 
      rect = op->ob_control->HighlightRect();
      return Py_BuildValue("(ii)", rect.Width(), 
                                   rect.Height());
    }

    if (!strcmp(name, "position")) {
      TRect rect; 
      rect = op->ob_control->HighlightRect();
      return Py_BuildValue("(ii)",rect.iTl.iX,
                                   rect.iTl.iY);
    }
#endif
    return Py_FindMethod((PyMethodDef*)Listbox_methods,
                         (PyObject *)op, name);
  }


  static const PyTypeObject c_Listbox_type = {
    PyObject_HEAD_INIT(NULL)
    0,                                         /*ob_size*/
    "appuifw.Listbox",                         /*tp_name*/
    sizeof(Listbox_object),                    /*tp_basicsize*/
    0,                                         /*tp_itemsize*/
    /* methods */
    (destructor)Listbox_dealloc,               /*tp_dealloc*/
    0,                                         /*tp_print*/
    (getattrfunc)Listbox_getattr,              /*tp_getattr*/
    0,                                         /*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.Content_handler
 *
 */

class Content_handler_data;

struct Content_handler_object {
  PyObject_VAR_HEAD
  Content_handler_data *ob_data;
  PyObject* ob_cb;
};

class CContent_handler_undertaker : public CActive
{
 public:
  CContent_handler_undertaker(PyObject* aOb):
    CActive(EPriorityStandard), iOb(aOb) {
    CActiveScheduler::Add(this);
  }
  
  void Start() {
    iStatus = KRequestPending;
    SetActive();
    //iStatus = KErrNone; // Doing this will panic the 3.0 emulator with E32USER-CBase 46 "Stray signal".
    TRequestStatus* pstatus = &iStatus; 
    RThread().RequestComplete(pstatus, 0);
  }

 private:
  void DoCancel() {;}
  void RunL() {
    PyEval_RestoreThread(PYTHON_TLS->thread_state);
    Py_DECREF(iOb);
    PyEval_SaveThread();
  }
  PyObject* iOb;
};

#ifdef EKA2
NONSHARABLE_CLASS(Content_handler_data) : public MAknServerAppExitObserver
#else
class Content_handler_data : public MApaEmbeddedDocObserver
#endif /*EKA2*/
{
public:
  static Content_handler_data* New(Content_handler_object* aOwner);
  Content_handler_data(Content_handler_object* aOwner):iOwner(aOwner){;}
  virtual ~Content_handler_data();
  void ConstructL();
#ifdef EKA2
  void HandleServerAppExit(TInt aReason);
#else
  void NotifyExit(TExitMode aMode);
#endif /*EKA2*/
  CDocumentHandler* iDocHandler;
  CContent_handler_undertaker* iUndertaker;
  Content_handler_object* iOwner;
};

Content_handler_data*
Content_handler_data::New(Content_handler_object* aOwner)
{
  Content_handler_data* self = new Content_handler_data(aOwner);
  if (self != NULL) {
    TRAPD(error, self->ConstructL());
    if (error != KErrNone) {
      delete self;
      self = NULL;
    }
  }
  return self;
}

void Content_handler_data::ConstructL()
{
  iUndertaker =
    new (ELeave) CContent_handler_undertaker((PyObject*)iOwner);

#ifdef EKA2
  iDocHandler = CDocumentHandler::NewL();
  iDocHandler->SetExitObserver((MAknServerAppExitObserver*)this);
#else
  iDocHandler =
    CDocumentHandler::NewL((CEikProcess*)
                           ((CEikonEnv::Static())->
                            EikAppUi()->Application()->Process()));
  iDocHandler->SetExitObserver(this);
#endif /*EKA*/
}

#ifdef EKA2
void Content_handler_data::HandleServerAppExit(TInt /* aReason */)
{
  if (iOwner->ob_cb) {
    PyEval_RestoreThread(PYTHON_TLS->thread_state);
    PyObject* tmp_r = NULL;
    tmp_r = PyEval_CallObject(iOwner->ob_cb, NULL);
    Py_XDECREF(tmp_r);
    PyEval_SaveThread();
  }
  iUndertaker->Start();
  return;
}
#else
void Content_handler_data::NotifyExit(TExitMode /* aMode */)
{
  if (iOwner->ob_cb) {
    PyEval_RestoreThread(PYTHON_TLS->thread_state);
    PyObject* tmp_r = NULL;
    tmp_r = PyEval_CallObject(iOwner->ob_cb, NULL);
    Py_XDECREF(tmp_r);
    PyEval_SaveThread();
  }
  iUndertaker->Start();
  return;
}
#endif /*EKA2*/

Content_handler_data::~Content_handler_data()
{
  delete iDocHandler;
  delete iUndertaker;
}

extern "C" PyObject *
new_Content_handler_object(PyObject* /*self*/, PyObject* args)
{
  PyObject *c = NULL;
  if (!PyArg_ParseTuple(args, "|O", &c))
      return NULL;
  if (c && !PyCallable_Check(c)) {
    PyErr_SetString(PyExc_TypeError, "callable expected");
    return NULL;
  }

  Content_handler_object *op = PyObject_New(Content_handler_object,
                                            &Content_handler_type);
  if (op == NULL)
    return PyErr_NoMemory();

  op->ob_data = Content_handler_data::New(op);
  if (op->ob_data == NULL) {
    PyObject_Del(op);
    return PyErr_NoMemory();
  }
  op->ob_cb = c;
  Py_XINCREF(c);
  return (PyObject *) op;
}

static PyObject* Content_handler_open(Content_handler_object *self,
                                      PyObject* args,
                                      int f_embed)
{
  PyObject *it, *s;

  if (!PyArg_ParseTuple(args, "O", &it) ||
      !(s = PyUnicode_FromObject(it)))
    return NULL;
  
  TPtrC name(PyUnicode_AsUnicode(s), PyUnicode_GetSize(s));
  TParse p;
  p.Set(name, NULL, NULL);
  int is_py = (p.Ext() == _L(".py"));
  
  if (f_embed && is_py) {
    Py_DECREF(s);
    PyErr_SetString(PyExc_TypeError,
                    "cannot currently embed Python within Python");
    return NULL;
  }
  
  TDataType empty;
  TInt error;
  
  if (f_embed) {
    Py_BEGIN_ALLOW_THREADS
    TRAP(error,
         self->ob_data->iDocHandler->OpenFileEmbeddedL(name, empty));
    Py_END_ALLOW_THREADS
    if (error == KErrNone)
      Py_INCREF(self);
  }
  else {
#ifdef USE_LAUNCHER_FOR_APP
    if (is_py) {
#if defined(__WINS__)
      RThread proc;
      RLibrary lib;
      HBufC* pname = name.Alloc();
      error = lib.Load(_L("\\system\\programs\\Python_launcher.dll"));
      if (error == KErrNone) {
        TThreadFunction func = (TThreadFunction)(lib.Lookup(1));
        error =
          proc.Create(_L("Py"), func, 0x1000, (TAny*) pname, &lib,
                      RThread().Heap(), 0x1000, 0x100000, EOwnerProcess);
        lib.Close();
      }
      else
        delete pname;
#else
      TFileName app_name =
        CEikonEnv::Static()->EikAppUi()->Application()->AppFullName();
      p.Set(_L("\\system\\programs\\Python_launcher.exe"),
            &app_name, NULL);
      RProcess proc;
      error = proc.Create(p.FullName(), name);
#endif
      if (error == KErrNone) {
        proc.Resume();
        proc.Close();
      }
    }
    else {
#endif /* USE_LAUNCHER_FOR_APP */
      TRAP(error, self->ob_data->iDocHandler->OpenFileL(name, empty));
#ifdef USE_LAUNCHER_FOR_APP
    }
#endif
  }

  Py_DECREF(s);
  PyObject *r = NULL;

  switch(error) {
  case KErrNone:
    Py_INCREF(Py_None);
    r = Py_None;
    break;
  case KBadMimeType:
    PyErr_SetString(PyExc_TypeError, "bad mime type");
    break;
  case KMimeNotSupported:
    PyErr_SetString(PyExc_TypeError, "mime type not supported");
    break;
  case KNullContent:
    PyErr_SetString(PyExc_TypeError, "empty content");
    break;
  case KExecNotAllowed:
    PyErr_SetString(PyExc_TypeError, "executables not allowed");
    break;
  default:
    r = SPyErr_SetFromSymbianOSErr(error);
    break;
  }

  return r;
}

extern "C" PyObject *
Content_handler_open_emb(Content_handler_object *self, PyObject* args)
{
  return Content_handler_open(self, args, 1);
}

extern "C" PyObject *
Content_handler_open_proc(Content_handler_object *self, PyObject* args)
{
  return Content_handler_open(self, args, 0);
}

extern "C" {
  static void
  Content_handler_dealloc(Content_handler_object *op)
  {
    delete op->ob_data;
    op->ob_data = NULL;
    Py_XDECREF(op->ob_cb);
    PyObject_Del(op);
  }

  const static PyMethodDef Content_handler_methods[] = {
    {"open", (PyCFunction)Content_handler_open_emb, METH_VARARGS},
    {"open_standalone",
     (PyCFunction)Content_handler_open_proc, METH_VARARGS},
    {NULL,              NULL}           // sentinel
  };

  static PyObject *
  Content_handler_getattr(Content_handler_object *op, char *name)
  {
    return Py_FindMethod((PyMethodDef*)Content_handler_methods,
                         (PyObject *)op, name);
  }


  static const PyTypeObject c_Content_handler_type = {
    PyObject_HEAD_INIT(NULL)
    0,                                         /*ob_size*/
    "appuifw.Content_handler",                 /*tp_name*/
    sizeof(Content_handler_object),            /*tp_basicsize*/
    0,          

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -