aboutsummaryrefslogtreecommitdiff
path: root/Src/Wasabi/api/skin/widgets/dropdownlist.h
blob: 0b3ef247c47058ee753f0362ad5ecf35b1385235 (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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
#ifndef __DROPDOWNLIST_H
#define __DROPDOWNLIST_H

#include <api/wnd/popexitcb.h>
#include <api/wnd/wndclass/embeddedxui.h>
#include <api/script/objects/c_script/h_guiobject.h>
#include <api/script/objects/c_script/h_button.h>
#include <api/skin/feeds/feedwatch.h>
#include <api/script/objcontroller.h>

#define  DROPDOWNLIST_PARENT EmbeddedXuiObject

class DDLClicksCallback;
class DDLKeyCallback;
class svc_textFeed;

/**
  Class 

  @short 
  @author Nullsoft
  @ver 1.0
  @see 
*/
class DDLEntry {
  public:

    
    /**
      Method
    
      @see 
      @ret 
      @param 
    */
    DDLEntry(const wchar_t *txt) : text(txt), id(id_gen++) { } 
    const wchar_t *getText() { return text; }
    
    /**
      Method
    
      @see 
      @ret 
      @param 
    */
    int getId() { return id; }

  private:
    StringW text;
    int id;
    static int id_gen;
};


/**
  Class 

  @short 
  @author Nullsoft
  @ver 1.0
  @see 
*/
class SortDDLEntries{
public:
  
  static int compareItem(DDLEntry *p1, DDLEntry *p2) {
    
    return WCSICMP(p1->getText(), p2->getText());
  }
  
  static int compareAttrib(const wchar_t *attrib, DDLEntry *item) 
	{
    return WCSICMP(attrib, item->getText());
  }
};




/**
  Class 

  @short 
  @author Nullsoft
  @ver 1.0
  @see 
*/
class DropDownList : public DROPDOWNLIST_PARENT, public PopupExitCallbackI, public FeedWatcher, public DependentViewerI {
  
  public:

    
    /**
      Method
    
      @see 
      @ret 
      @param 
    */
    DropDownList();
    
    /**
      Method
    
      @see 
      @ret 
      @param 
    */
    virtual ~DropDownList();

    
    /**
      Method
    
      @see 
      @ret 
      @param 
    */
    virtual int onInit();

    
    /**
      Method
    
      @see 
      @ret 
      @param 
    */
    void clickCallback();
    void escapeCallback();

    
    /**
      Method
    
      @see 
      @ret 
      @param 
    */
#ifdef WASABI_COMPILE_CONFIG
    virtual int onReloadConfig();
#endif
    
    /**
      Method
    
      @see 
      @ret 
      @param 
    */
    virtual void abstract_onNewContent();
    
    /**
      Method
    
      @see 
      @ret 
      @param 
    */
    virtual void setListHeight(int h) { height = h; }

    
    /**
      Method
    
      @see 
      @ret 
      @param 
    */
    virtual int popupexitcb_onExitPopup();
    virtual api_dependent *popupexit_getDependencyPtr() { return rootwnd_getDependencyPtr(); }
    
    /**
      Method
    
      @see 
      @ret 
      @param 
    */
    void openList();
    
    /**
      Method
    
      @see 
      @ret 
      @param 
    */
    void closeList();

   
    void setItems(const wchar_t *lotsofitems);
 
    int addItem(const wchar_t *text); 
    
    /**
      Method
    
      @see 
      @ret 
      @param 
    */
    void delItem(int id);
    

    int findItem(const wchar_t *text);

    int getNumItems() { return items.getNumItems(); }
    DDLEntry *enumItem(int i) { return items.enumItem(i); }
    
    /**
      Method
    
      @see 
      @ret 
      @param 
    */
    void selectItem(int id, int hover=0);
    const wchar_t *getItemText(int id);
    
    int getSelected() { return selected; }
    const wchar_t *getSelectedText() { int a = getSelected(); if (a == -1) return getCustomText(); return getItemText(a); }
    virtual const wchar_t *getCustomText() { return noitemtext; }
    
    /**
      Method
    
      @see 
      @ret 
      @param 
    */
    virtual void deleteAllItems();

    
    /**
      Method
    
      @see 
      @ret 
      @param 
    */
    virtual void onSelect(int id, int hover=0);

    virtual void setNoItemText(const wchar_t *txt);

    
    /**
      Method
    
      @see 
      @ret 
      @param 
    */
    virtual int childNotify(ifc_window *child, int msg, intptr_t param1=0, intptr_t param2=0);
    
    /**
      Method
    
      @see 
      @ret 
      @param 
    */
    virtual int onDeferredCallback(intptr_t p1, intptr_t p2);

    
    /**
      Method
    
      @see 
      @ret 
      @param 
    */
    virtual int viewer_onItemDeleted(api_dependent *item);

    virtual void feedwatcher_onSetFeed(svc_textFeed *svc);
    virtual void feedwatcher_onFeedChange(const wchar_t *data);
    
    virtual int onAction(const wchar_t *action, const wchar_t *param=NULL, int x=-1, int y=-1, intptr_t p1=0, intptr_t p2=0, void *data=NULL, size_t datalen=0, ifc_window *source=NULL);
    
    
    /**
      Method
    
      @see 
      @ret 
      @param 
    */
    virtual void selectDefault();
    
    virtual void setMaxItems(int _maxitems) { maxitems = _maxitems; }
    virtual int getMaxItems() { return maxitems; }

    virtual int wantTrapButton() { return 1; }
    virtual int wantTrapText() { return 1; }
    virtual int wantFocus() { return 1; }

    virtual const wchar_t *dropdownlist_getMainGroupId() { return L"wasabi.dropdownlist.main.group"; }
    virtual const wchar_t *dropdownlist_getListGroupId() { return L"wasabi.dropdownlist.list.group"; }
    virtual const wchar_t *dropdownlist_getTextId() { return L"dropdownlist.text"; }
    virtual const wchar_t *dropdownlist_getButtonId() { return L"dropdownlist.button"; }
    virtual const wchar_t *dropdownlist_getListId() { return L"dropdownlist.list"; }

    virtual void updateTextInControl(const wchar_t *txt);

    virtual int setXuiParam(int xuihandle, int xmlattributeid, const wchar_t *xmlattributename, const wchar_t *value);

    virtual const wchar_t *embeddedxui_getContentId() { return dropdownlist_getMainGroupId(); }
    virtual const wchar_t *embeddedxui_getEmbeddedObjectId() { return dropdownlist_getTextId(); }

    int isListOpen() { return list_group != NULL; };
    virtual int wantAutoSort() { return 1; }

    virtual void dropdownlist_onCloseList();
    virtual void dropdownlist_onOpenList();

    virtual void dropdownlist_onConfigureList(GuiObject *o);
    virtual int onKeyDown(int keyCode);
    virtual int onKeyUp(int keyCode);
    virtual int onAcceleratorEvent(const wchar_t *name);

    virtual void onPreCloseList() {}
    virtual void onPreOpenList() {}
protected:
	/*static */void CreateXMLParameters(int master_handle);
  private:

    enum {
      DROPDOWNLIST_SETITEMS = 0,
      DROPDOWNLIST_SETFEED,
      DROPDOWNLIST_SELECT,
      DROPDOWNLIST_LISTHEIGHT,
      DROPDOWNLIST_MAXITEMS,
  	  DROPDOWNLIST_SETLISTANTIALIAS,
    };
    int myxuihandle;
		static XMLParamPair params[];

  private:

#ifdef WASABI_COMPILE_CONFIG
    void updateTextFromConfig();
#endif
    
    /**
      Method
    
      @see 
      @ret 
      @param 
    */
    void trapControls();
    
    /**
      Method
    
      @see 
      @ret 
      @param 
    */
    void setListParams();
    
    /**
      Method
    
      @see 
      @ret 
      @param 
    */
    void doCloseList(int cb=1);
    
    DDLClicksCallback *clicks_button;
    DDLClicksCallback *clicks_text;
    DDLKeyCallback *list_key;
    ifc_window *list_group;
    PtrListInsertSorted<DDLEntry, SortDDLEntries> items;
    int selected;

    int height;
    int maxitems;
    StringW noitemtext;
    int trap_click;
    api_dependent *group_dep;
    ifc_window *action_list;
    int disable_cfg_event;
    ifc_window *listif;
	int listAntialias;
};


/**
  Class 

  @short 
  @author Nullsoft
  @ver 1.0
  @see 
*/
class DDLClicksCallback : public H_GuiObject {
  public:
    
    /**
      Method
    
      @see 
      @ret 
      @param 
    */
    DDLClicksCallback(ScriptObject *trap, DropDownList *_callback) :
        
        /**
          Method
        
          @see 
          @ret 
          @param 
        */
        callback(_callback), H_GuiObject(trap) {
    }

    
    /**
      Method
    
      @see 
      @ret 
      @param 
    */
    virtual void hook_onLeftButtonDown(int x, int y) {
      callback->clickCallback();
    }
    virtual void hook_onChar(wchar_t c) 
  {
#ifdef _WIN32
      if (c == VK_SPACE || c == VK_RETURN)
        callback->clickCallback();
#else
#warning port me
#endif
    }
  private:
    DropDownList *callback;
};

class DDLKeyCallback : public H_GuiObject {
  public:
    
    /**
      Method
    
      @see 
      @ret 
      @param 
    */
    DDLKeyCallback(ScriptObject *trap, DropDownList *_callback) :
        
        /**
          Method
        
          @see 
          @ret 
          @param 
        */
        callback(_callback), H_GuiObject(trap) {
    }

    
    /**
      Method
    
      @see 
      @ret 
      @param 
    */

    virtual void hook_onChar(wchar_t c) 
  {
#ifdef _WIN32
      if (c == VK_ESCAPE)
        callback->escapeCallback();
#else
#warning port me
#endif
    }
  private:
    DropDownList *callback;
};

// -----------------------------------------------------------------------
class DropDownListScriptController: public ScriptObjectControllerI {
public:
  virtual const wchar_t *getClassName() { return L"DropDownList"; }
  virtual const wchar_t *getAncestorClassName() { return L"ObjectEmbedder"; }
  virtual ScriptObjectController *getAncestorController() { return WASABI_API_MAKI->maki_getController(embeddedXuiGuid); }
  virtual int getNumFunctions();
  virtual const function_descriptor_struct *getExportedFunctions();
  virtual GUID getClassGuid() { return dropDownListGuid; }
  virtual ScriptObject *instantiate();
  virtual void destroy(ScriptObject *o);
  virtual void *encapsulate(ScriptObject *o);
  virtual void deencapsulate(void *o);

  // public cause it's called by the xui object.
  static scriptVar DropDownList_onSelect(SCRIPT_FUNCTION_PARAMS, ScriptObject *o, scriptVar id, scriptVar hover);

private:

  static function_descriptor_struct exportedFunction[];
  static scriptVar DropDownList_getItemSelected(SCRIPT_FUNCTION_PARAMS, ScriptObject *o);

  static /*void*/ scriptVar DropDownList_setListHeight(SCRIPT_FUNCTION_PARAMS, ScriptObject *o, /*int*/ scriptVar h);
  static /*void*/ scriptVar DropDownList_openList(SCRIPT_FUNCTION_PARAMS, ScriptObject *o);
  static /*void*/ scriptVar DropDownList_closeList(SCRIPT_FUNCTION_PARAMS, ScriptObject *o);
  static /*void*/ scriptVar DropDownList_setItems(SCRIPT_FUNCTION_PARAMS, ScriptObject *o, /*String*/ scriptVar lotsofitems);
  static /*int*/ scriptVar DropDownList_addItem(SCRIPT_FUNCTION_PARAMS, ScriptObject *o, /*String*/ scriptVar text); 
  static /*void*/ scriptVar DropDownList_delItem(SCRIPT_FUNCTION_PARAMS, ScriptObject *o, /*int*/ scriptVar id);
  static /*int*/ scriptVar DropDownList_findItem(SCRIPT_FUNCTION_PARAMS, ScriptObject *o, /*String*/ scriptVar text);
  static /*int*/ scriptVar DropDownList_getNumItems(SCRIPT_FUNCTION_PARAMS, ScriptObject *o);
  static /*void*/ scriptVar DropDownList_selectItem(SCRIPT_FUNCTION_PARAMS, ScriptObject *o, /*int*/ scriptVar id, /*int*/ scriptVar hover);
  static /*String*/ scriptVar DropDownList_getItemText(SCRIPT_FUNCTION_PARAMS, ScriptObject *o, /*int*/ scriptVar id);
  static /*int*/ scriptVar DropDownList_getSelected(SCRIPT_FUNCTION_PARAMS, ScriptObject *o);
  static /*String*/ scriptVar DropDownList_getSelectedText(SCRIPT_FUNCTION_PARAMS, ScriptObject *o);
  static /*String*/ scriptVar DropDownList_getCustomText(SCRIPT_FUNCTION_PARAMS, ScriptObject *o);
  static /*void*/ scriptVar DropDownList_deleteAllItems(SCRIPT_FUNCTION_PARAMS, ScriptObject *o);
  static /*void*/ scriptVar DropDownList_setNoItemText(SCRIPT_FUNCTION_PARAMS, ScriptObject *o, /*String*/ scriptVar txt);


};

extern COMEXP DropDownListScriptController *dropDownListController;

#endif