aboutsummaryrefslogtreecommitdiff
path: root/Src/Wasabi/api/skin/widgets/db/xuiquerydrag.cpp
blob: c19817743964ac9fd038d1c151bf452eecf2409a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#include <precomp.h>
#include "xuiquerydrag.h"
#include <tataki/canvas/ifc_canvas.h>
#include <api/db/multiqueryserver.h>
#include <bfc/file/filename.h>

char QueryDragXuiObjectStr[] = "QueryDrag"; // This is the xml tag
char QueryDragXuiSvcName[] = "QueryDrag xui object"; // and this is the name of the service

XMLParamPair QueryDrag::params[] = {
  {QUERYDRAG_SETIMAGE, "image"},
  {QUERYDRAG_SETSOURCE, "source"},
	};
QueryDrag::QueryDrag() {
  setVirtual(0); // fucko
  myxuihandle = newXuiHandle();
	
	
	int numParams = sizeof(params) / sizeof(params[0]);
	hintNumberOfParams(numParams);
	for (int i = 0;i < numParams;i++)
		addParam(myxuihandle, params[i], XUI_ATTRIBUTE_IMPLIED);
  fn = NULL;
}

QueryDrag::~QueryDrag() {
}

int QueryDrag::setXuiParam(int xuihandle, int xmlattributeid, const wchar_t *xmlattributename, const wchar_t *value) {
  if (xuihandle != myxuihandle)
    return QUERYDRAG_PARENT::setXuiParam(xuihandle, xmlattributeid, xmlattributename, value);

  switch (xmlattributeid) {
    case  QUERYDRAG_SETIMAGE:
      setImage(value);
      break;
    case  QUERYDRAG_SETSOURCE:
      setSource(value);
      break;
    default:
      return 0;
  }
  return 1;
}

int QueryDrag::onPaint(Canvas *canvas) {
  QUERYDRAG_PARENT::onPaint(canvas);

  RECT r;
  getClientRect(&r);

  RenderBaseTexture(canvas, r, 255);

  if (image.getBitmap()) 
    image.getBitmap()->stretchToRectAlpha(canvas, &r, getPaintingAlpha()); 

  return 1;
}

void QueryDrag::setImage(const char *elementname) {
  image = elementname; 
  if (isInited()) invalidate(); 
}

void QueryDrag::setSource(const char *elementname) {
  source = elementname;
}

int QueryDrag::getPreferences(int what) {
  switch (what) {
    case SUGGESTED_W:
      if (image.getBitmap()) return image.getBitmap()->getWidth();
    case SUGGESTED_H:
      if (image.getBitmap()) return image.getBitmap()->getHeight();
  }
  return QUERYDRAG_PARENT::getPreferences(what);
}

int QueryDrag::onMouseMove(int x, int y) {
  QUERYDRAG_PARENT::onMouseMove(x,y);
  if (isInClick()) 
    onBeginDrag();
  return 1;
}

void QueryDrag::onBeginDrag() {
  api_window *mqsw = NULL;
  if (source.isempty()) mqsw = findWindowByInterface(multiQueryServerGuid);
  else mqsw = findWindow(source);
  if (!mqsw) return;
  MultiQueryServer *mqs = static_cast<MultiQueryServer *>(mqsw->getInterface(multiQueryServerGuid));
  
  // multiquery is now available in mqs->mqs_getMultiQuery(); using format "table guid;query;table guid;query;etc..."
  fn = new FilenameI(StringPrintf("query://%s.nsq", mqs->mqs_getMultiQuery()));
  addDragItem(Filename::dragitem_getDatatype(), static_cast<Filename*>(fn));
  handleDrag();
}

int QueryDrag::dragComplete(int success) {
  ASSERT(fn != NULL);
  delete fn; fn = NULL;
  return 1;
}