xuiquerydrag.cpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. #include <precomp.h>
  2. #include "xuiquerydrag.h"
  3. #include <tataki/canvas/ifc_canvas.h>
  4. #include <api/db/multiqueryserver.h>
  5. #include <bfc/file/filename.h>
  6. char QueryDragXuiObjectStr[] = "QueryDrag"; // This is the xml tag
  7. char QueryDragXuiSvcName[] = "QueryDrag xui object"; // and this is the name of the service
  8. XMLParamPair QueryDrag::params[] = {
  9. {QUERYDRAG_SETIMAGE, "image"},
  10. {QUERYDRAG_SETSOURCE, "source"},
  11. };
  12. QueryDrag::QueryDrag() {
  13. setVirtual(0); // fucko
  14. myxuihandle = newXuiHandle();
  15. int numParams = sizeof(params) / sizeof(params[0]);
  16. hintNumberOfParams(numParams);
  17. for (int i = 0;i < numParams;i++)
  18. addParam(myxuihandle, params[i], XUI_ATTRIBUTE_IMPLIED);
  19. fn = NULL;
  20. }
  21. QueryDrag::~QueryDrag() {
  22. }
  23. int QueryDrag::setXuiParam(int xuihandle, int xmlattributeid, const wchar_t *xmlattributename, const wchar_t *value) {
  24. if (xuihandle != myxuihandle)
  25. return QUERYDRAG_PARENT::setXuiParam(xuihandle, xmlattributeid, xmlattributename, value);
  26. switch (xmlattributeid) {
  27. case QUERYDRAG_SETIMAGE:
  28. setImage(value);
  29. break;
  30. case QUERYDRAG_SETSOURCE:
  31. setSource(value);
  32. break;
  33. default:
  34. return 0;
  35. }
  36. return 1;
  37. }
  38. int QueryDrag::onPaint(Canvas *canvas) {
  39. QUERYDRAG_PARENT::onPaint(canvas);
  40. RECT r;
  41. getClientRect(&r);
  42. RenderBaseTexture(canvas, r, 255);
  43. if (image.getBitmap())
  44. image.getBitmap()->stretchToRectAlpha(canvas, &r, getPaintingAlpha());
  45. return 1;
  46. }
  47. void QueryDrag::setImage(const char *elementname) {
  48. image = elementname;
  49. if (isInited()) invalidate();
  50. }
  51. void QueryDrag::setSource(const char *elementname) {
  52. source = elementname;
  53. }
  54. int QueryDrag::getPreferences(int what) {
  55. switch (what) {
  56. case SUGGESTED_W:
  57. if (image.getBitmap()) return image.getBitmap()->getWidth();
  58. case SUGGESTED_H:
  59. if (image.getBitmap()) return image.getBitmap()->getHeight();
  60. }
  61. return QUERYDRAG_PARENT::getPreferences(what);
  62. }
  63. int QueryDrag::onMouseMove(int x, int y) {
  64. QUERYDRAG_PARENT::onMouseMove(x,y);
  65. if (isInClick())
  66. onBeginDrag();
  67. return 1;
  68. }
  69. void QueryDrag::onBeginDrag() {
  70. api_window *mqsw = NULL;
  71. if (source.isempty()) mqsw = findWindowByInterface(multiQueryServerGuid);
  72. else mqsw = findWindow(source);
  73. if (!mqsw) return;
  74. MultiQueryServer *mqs = static_cast<MultiQueryServer *>(mqsw->getInterface(multiQueryServerGuid));
  75. // multiquery is now available in mqs->mqs_getMultiQuery(); using format "table guid;query;table guid;query;etc..."
  76. fn = new FilenameI(StringPrintf("query://%s.nsq", mqs->mqs_getMultiQuery()));
  77. addDragItem(Filename::dragitem_getDatatype(), static_cast<Filename*>(fn));
  78. handleDrag();
  79. }
  80. int QueryDrag::dragComplete(int success) {
  81. ASSERT(fn != NULL);
  82. delete fn; fn = NULL;
  83. return 1;
  84. }