[r8766]: main / branches / 4.1 / trunk / extensions / platform / windows / oodialog / oodBarControls.cpp Maximize Restore History

Download this file

oodBarControls.cpp    626 lines (528 with data), 19.5 kB

  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
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
/*----------------------------------------------------------------------------*/
/* */
/* Copyright (c) 1995, 2004 IBM Corporation. All rights reserved. */
/* Copyright (c) 2005-2013 Rexx Language Association. All rights reserved. */
/* */
/* This program and the accompanying materials are made available under */
/* the terms of the Common Public License v1.0 which accompanies this */
/* distribution. A copy is also available at the following address: */
/* http://www.oorexx.org/license.html */
/* */
/* Redistribution and use in source and binary forms, with or */
/* without modification, are permitted provided that the following */
/* conditions are met: */
/* */
/* Redistributions of source code must retain the above copyright */
/* notice, this list of conditions and the following disclaimer. */
/* Redistributions in binary form must reproduce the above copyright */
/* notice, this list of conditions and the following disclaimer in */
/* the documentation and/or other materials provided with the distribution. */
/* */
/* Neither the name of Rexx Language Association nor the names */
/* of its contributors may be used to endorse or promote products */
/* derived from this software without specific prior written permission. */
/* */
/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS */
/* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT */
/* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS */
/* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT */
/* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */
/* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED */
/* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, */
/* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY */
/* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING */
/* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */
/* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
/* */
/*----------------------------------------------------------------------------*/
/**
* oodBarControls.cpp
*
* Contains methods for the ScrollBar, TrackBar, and ProgressBar dialog
* controls. Also the misc control UpDown
*/
#include "ooDialog.hpp" // Must be first, includes windows.h, commctrl.h, and oorexxapi.h
#include <stdio.h>
#include <dlgs.h>
#include <malloc.h>
#include <limits.h>
#include "APICommon.hpp"
#include "oodCommon.hpp"
#include "oodControl.hpp"
/**
* Methods for the ProgressBar class.
*/
#define PROGRESSBAR_CLASS "ProgressBar"
static RexxDirectoryObject pbGetFullRange(RexxMethodContext *c, HWND hPB)
{
PBRANGE pbr;
SendMessage(hPB, PBM_GETRANGE, TRUE, (LPARAM)&pbr);
RexxDirectoryObject d = c->NewDirectory();
c->DirectoryPut(d, c->Int32(pbr.iLow), "MIN");
c->DirectoryPut(d, c->Int32(pbr.iHigh), "MAX");
return d;
}
/** ProgressBar::setFullRange()
*
* Sets the range for the progress bar using the full 32-bit numbers for the
* range.
*
* The range can be specified using one argument, a directory object, or two
* arguments
*
* Form 1:
*
* @param aDirectory [OPTIONAL] The directory indexes "min" and "max" are
* used to set the range. The min index specifies the low
* end of the range and the max index specifies the high
* end of the range. If either, (or both,) indexes are
* omitted, the low end of the range is set to 0 and the
* high end is set to 100, as appropriate to the missing
* index(es).
*
* Form 2:
*
* @param min [OPTIONAL] The low end of the range. 0 is the default.
* @param max [OPTIONAL] The high end of the range. 100 is the default.
*
* @return The previous range as a directory object with the indexes min and
* max.
*
* @remarks The getRange() method is maintained for backwards compatibility. it
* returns the range as a string. For that method, the returned range
* is not necessarily correct if the previous range has been set using
* the full 32-bit numbers now allowed by the progress bar control.
* The returned numbers are restricted to 0xFFFF.
*
* Use the getFullRange() method to get the correct range.
*/
RexxMethod4(RexxObjectPtr, pbc_setFullRange, OPTIONAL_RexxObjectPtr, minObj, OPTIONAL_int32_t, max, NAME, method, CSELF, pCSelf)
{
RexxMethodContext *c = context;
HWND hwnd = getDChCtrl(pCSelf);
int32_t min = 0;
RexxDirectoryObject result = NULLOBJECT;
bool usingDirectory = false;
bool fullRange = method[3] == 'F';
if ( argumentExists(1) )
{
if ( c->IsOfType(minObj, "DIRECTORY") )
{
usingDirectory = true;
if ( ! rxIntFromDirectory(context, (RexxDirectoryObject)minObj, "MIN", &min, 1, false) )
{
goto done_out;
}
max = 100;
if ( ! rxIntFromDirectory(context, (RexxDirectoryObject)minObj, "MAX", &max, 1, false) )
{
goto done_out;
}
}
else
{
if ( ! context->Int32(minObj, &min) )
{
wrongRangeException(context->threadContext, 1, INT32_MIN, INT32_MAX, minObj);
}
}
}
if ( ! usingDirectory && argumentOmitted(2) )
{
max = 100;
}
if ( fullRange )
{
result = pbGetFullRange(context, hwnd);
}
uint32_t range = (uint32_t)SendMessage(hwnd, PBM_SETRANGE32, min, max);
if ( ! fullRange )
{
result = context->NewDirectory();
context->DirectoryPut(result, context->Int32(LOWORD(range)), "MIN");
context->DirectoryPut(result, context->Int32(HIWORD(range)), "MAX");
}
done_out:
return result;
}
RexxMethod1(RexxObjectPtr, pbc_getFullRange, CSELF, pCSelf)
{
return pbGetFullRange(context, getDChCtrl(pCSelf));
}
/**
* ProgressBar::setMarquee() Turn marquee mode on or off.
*
* @param on [Optional] Stop or start marquee mode. Default is to
* start.
*
* @param pause [Optional] Time in milliseconds between updates. Default
* is 1000 (1 second.)
*
* @return True (always.)
*
* Requires XP Common Controls version 6.0 or greater.
*/
RexxMethod3(logical_t, pbc_setMarquee, OPTIONAL_logical_t, on, OPTIONAL_uint32_t, pause, CSELF, pCSelf)
{
if ( ! requiredComCtl32Version(context, "setMarquee", COMCTL32_6_0) )
{
return 0;
}
HWND hwnd = getDChCtrl(pCSelf);
if ( ! hasStyle(hwnd, PBS_MARQUEE) )
{
wrongWindowStyleException(context, "progress bar", "PBS_MARQUEE");
return 0;
}
if ( argumentOmitted(1) )
{
on = 1;
}
if ( argumentOmitted(2) )
{
pause = 1000;
}
/* The Windows message always returns 1, return 1 for .true (succeeded.) */
SendMessage(hwnd, PBM_SETMARQUEE, on, pause);
return 1;
}
/**
* Methods for the ScrollBar class.
*/
#define SCROLLBAR_CLASS "ScrollBar"
RexxMethod4(logical_t, sb_setRange, int32_t, min, int32_t, max, OPTIONAL_logical_t, redraw, CSELF, pCSelf)
{
oodResetSysErrCode(context->threadContext);
redraw = (argumentOmitted(3) ? TRUE : redraw);
SCROLLINFO si = {0};
si.cbSize = sizeof(SCROLLINFO);
si.fMask = SIF_RANGE;
si.nMax = max;
si.nMin = min;
if ( SetScrollInfo(getDChCtrl(pCSelf), SB_CTL, &si, (BOOL)redraw) == 0 )
{
oodSetSysErrCode(context->threadContext);
return 1;
}
return 0;
}
RexxMethod1(RexxObjectPtr, sb_getRange, CSELF, pCSelf)
{
oodResetSysErrCode(context->threadContext);
RexxDirectoryObject result = context->NewDirectory();
context->DirectoryPut(result, TheNegativeOneObj, "MIN");
context->DirectoryPut(result, TheNegativeOneObj, "MAX");
SCROLLINFO si = {0};
si.cbSize = sizeof(SCROLLINFO);
si.fMask = SIF_RANGE;
if ( GetScrollInfo(getDChCtrl(pCSelf), SB_CTL, &si) == 0 )
{
oodSetSysErrCode(context->threadContext);
}
else
{
context->DirectoryPut(result, context->Int32(si.nMin), "MIN");
context->DirectoryPut(result, context->Int32(si.nMax), "MAX");
}
return result;
}
RexxMethod3(logical_t, sb_setPosition, int32_t, pos, OPTIONAL_logical_t, redraw, CSELF, pCSelf)
{
oodResetSysErrCode(context->threadContext);
redraw = (argumentOmitted(2) ? TRUE : redraw);
SCROLLINFO si = {0};
si.cbSize = sizeof(SCROLLINFO);
si.fMask = SIF_POS;
si.nPos = pos;
if ( SetScrollInfo(getDChCtrl(pCSelf), SB_CTL, &si, (BOOL)redraw) == 0 )
{
oodSetSysErrCode(context->threadContext);
return 0;
}
return 1;
}
RexxMethod1(int32_t, sb_getPosition, CSELF, pCSelf)
{
oodResetSysErrCode(context->threadContext);
SCROLLINFO si = {0};
si.cbSize = sizeof(SCROLLINFO);
si.fMask = SIF_POS;
if ( GetScrollInfo(getDChCtrl(pCSelf), SB_CTL, &si) == 0 )
{
oodSetSysErrCode(context->threadContext);
}
return si.nPos;
}
/**
* Methods for the TrackBar class. Note that this is the .Slider class in
* ooDialog. yghr.
*/
#define TRACK_BAR_CLASS "TrackBar"
#define SLIDER_CLASS "Slider"
/** TrackBar::getRange()
*
*/
RexxMethod1(RexxObjectPtr, tb_getRange, CSELF, pCSelf)
{
RexxDirectoryObject result = context->NewDirectory();
HWND hCtrl = getDChCtrl(pCSelf);
context->DirectoryPut(result, context->Intptr((intptr_t)SendMessage(hCtrl, TBM_GETRANGEMIN, 0,0)), "MIN");
context->DirectoryPut(result, context->Intptr((intptr_t)SendMessage(hCtrl, TBM_GETRANGEMAX, 0,0)), "MAX");
return result;
}
/** TrackBar::getSelRange()
*
*/
RexxMethod1(RexxObjectPtr, tb_getSelRange, CSELF, pCSelf)
{
RexxDirectoryObject result = context->NewDirectory();
HWND hCtrl = getDChCtrl(pCSelf);
context->DirectoryPut(result, context->Intptr((intptr_t)SendMessage(hCtrl, TBM_GETSELSTART, 0,0)), "START");
context->DirectoryPut(result, context->Intptr((intptr_t)SendMessage(hCtrl, TBM_GETSELEND, 0,0)), "END");
return result;
}
/**
* Methods for the UpDown class.
*/
#define UP_DOWN_CLASS "UpDown"
/** UpDown::deltaPosReply() [Class method]
*
* Constructs the (proper) reply object for a DELTAPOS UpDown event
* notification.
*
* The Rexx programmer should use this method as the reply to the notification.
*
* @param change [optional] If true, the delta position message is to be
* canceled or modified. If false, there is no change to the
* delta position message, and the other arguments are always
* ignored. The default is false.
*
* @param cancel [optional] If true, the delta position message is canceled
* completely. If false the message is not canceled, and the
* delta position is set to newDelta. The default is false.
*
* @param newDelta [optional] The amount by which the current position of the
* updown control is changed. The default is 1. This
* argument is only used if change is true and cancel is
* false.
*/
RexxMethod3(RexxObjectPtr, ud_deltaPosReply_cls, OPTIONAL_logical_t, change, OPTIONAL_logical_t, cancel, OPTIONAL_int32_t, newDelta)
{
if ( ! change )
{
return TheFalseObj;
}
RexxBufferObject _dpr = context->NewBuffer(sizeof(DELTAPOSREPLY));
if ( _dpr == NULLOBJECT )
{
return TheFalseObj;
}
PDELTAPOSREPLY pdpr = (PDELTAPOSREPLY)context->BufferData(_dpr);
pdpr->change = true;
pdpr->cancel = cancel ? true : false;
if ( ! pdpr->cancel )
{
pdpr->newDelta = argumentExists(1) ? newDelta : 1;
}
return _dpr;
}
/** UpDown::setRange()
*
* Sets the range, (minimum and maximum,) for the up down control.
*
* Unlike other some other controls, the maximum position may be less than the
* minimum, and in that case clicking the up arrow button decreases the current
* position. To put it another way, up means moving towards the maximum
* position.
*
* The range can be specified using one argument, a directory object, or two
* arguments
*
* Form 1:
*
* @param aDirectory [OPTIONAL] The directory indexes "min" and "max" are
* used to set the range. The min index specifies the
* minium postition and the max index specifies the
* maximum position. If an index is omitted, the
* corresponding default for that index is set. 0 for the
* minimum position and 100 for the maximum.
*
* Form 2:
*
* @param min [OPTIONAL] The minimum position. 0 is the default.
* @param max [OPTIONAL] The maximum. 100 is the default.
*
* @return 0 always.
*
*/
RexxMethod3(RexxObjectPtr, ud_setRange, OPTIONAL_RexxObjectPtr, minObj, OPTIONAL_int32_t, max, CSELF, pCSelf)
{
HWND hwnd = getDChCtrl(pCSelf);
int32_t min = 0;
bool usingDirectory = false;
if ( argumentExists(1) )
{
if ( context->IsOfType(minObj, "DIRECTORY") )
{
usingDirectory = true;
if ( ! rxIntFromDirectory(context, (RexxDirectoryObject)minObj, "MIN", &min, 1, false) )
{
goto done_out;
}
max = 100;
if ( ! rxIntFromDirectory(context, (RexxDirectoryObject)minObj, "MAX", &max, 1, false) )
{
goto done_out;
}
}
else
{
if ( ! context->Int32(minObj, &min) )
{
wrongRangeException(context->threadContext, 1, INT32_MIN, INT32_MAX, minObj);
}
}
}
if ( ! usingDirectory && argumentOmitted(2) )
{
max = 100;
}
SendMessage(hwnd, UDM_SETRANGE32, min, max);
done_out:
return TheZeroObj;
}
/** UpDown::getRange()
*
*
*/
RexxMethod1(RexxObjectPtr, ud_getRange, CSELF, pCSelf)
{
RexxDirectoryObject result = context->NewDirectory();
HWND hCtrl = getDChCtrl(pCSelf);
int32_t min, max;
SendMessage(hCtrl, UDM_GETRANGE32, (WPARAM)&min, (LPARAM)&max);
RexxMethodContext *c = context;
context->DirectoryPut(result, context->Int32(min), "MIN");
context->DirectoryPut(result, context->Int32(max), "MAX");
return result;
}
/** UpDown::getBuddy()
*
* Returns the buddy dialog control ojbect, or .nil if there is no buddy.
*
* @remarks createControlFromHwnd() can handle a null window handle, or a
* winUnknown type for the control type. In both cases, it simply
* returns the .nil object. This is what we want, so we don't check
* for those things.
*/
RexxMethod1(RexxObjectPtr, ud_getBuddy, CSELF, pCSelf)
{
HWND hUpDown = getDChCtrl(pCSelf);
HWND hBuddy = (HWND)SendMessage(hUpDown, UDM_GETBUDDY, 0, 0);
oodControl_t ctrl = control2controlType(hBuddy);
return createControlFromHwnd(context, (pCDialogControl)pCSelf, hBuddy, ctrl, true);
}
/** UpDown::setBuddy()
*
* Sets the buddy control for the up-down and returns the old buddy, if there
* was one.
*
*/
RexxMethod2(RexxObjectPtr, ud_setBuddy, RexxObjectPtr, buddy, CSELF, pCSelf)
{
RexxObjectPtr result = TheNilObj;
if ( requiredClass(context->threadContext, buddy, "DIALOGCONTROL", 1) )
{
pCDialogControl pcdc = controlToCSelf(context, buddy);
HWND hUpDown = getDChCtrl(pCSelf);
HWND hOldBuddy = (HWND)SendMessage(hUpDown, UDM_SETBUDDY, (WPARAM)pcdc->hCtrl, 0);
oodControl_t ctrl = control2controlType(hOldBuddy);
result = createControlFromHwnd(context, (pCDialogControl)pCSelf, hOldBuddy, ctrl, true);
}
return result;
}
/** UpDown::getPosition()
*
*
* @note Sets the .SystemErrorCode. If the returned position is not correct,
* the .SystemErrorCode is set to
*
* ERROR_INVALID_DATA (13) "The data is invalid"
*/
RexxMethod1(int32_t, ud_getPosition, CSELF, pCSelf)
{
oodResetSysErrCode(context->threadContext);
HWND hCtrl = getDChCtrl(pCSelf);
BOOL error;
int32_t pos = (int32_t)SendMessage(hCtrl, UDM_GETPOS32, 0, (LPARAM)&error);
if ( error )
{
oodSetSysErrCode(context->threadContext, ERROR_INVALID_DATA);
}
return pos;
}
RexxMethod1(RexxArrayObject, ud_getAcceleration, CSELF, pCSelf)
{
HWND hCtrl = getDChCtrl(pCSelf);
LPUDACCEL pUDA = NULL;
size_t count = (size_t)SendMessage(hCtrl, UDM_GETACCEL, 0, NULL);
RexxArrayObject result = context->NewArray(count);
pUDA = (LPUDACCEL)malloc(count * sizeof(UDACCEL));
if ( pUDA == NULL )
{
outOfMemoryException(context->threadContext);
goto done_out;
}
SendMessage(hCtrl, UDM_GETACCEL, count, (LPARAM)pUDA);
for ( size_t i = 0; i < count; i++ )
{
RexxDirectoryObject d = context->NewDirectory();
context->DirectoryPut(d, context->UnsignedInt32(pUDA[i].nSec), "SECONDS");
context->DirectoryPut(d, context->UnsignedInt32(pUDA[i].nInc), "INCREMENT");
context->ArrayPut(result, d, i + 1);
}
done_out:
safeFree(pUDA);
return result;
}
RexxMethod2(logical_t, ud_setAcceleration, RexxArrayObject, vals, CSELF, pCSelf)
{
RexxMethodContext *c = context;
HWND hCtrl = getDChCtrl(pCSelf);
LPUDACCEL pUDA = NULL;
size_t count = c->ArrayItems(vals);
if ( count < 1 )
{
emptyArrayException(c->threadContext, 1);
goto done_out;
}
pUDA = (LPUDACCEL)malloc(count * sizeof(UDACCEL));
if ( pUDA == NULL )
{
outOfMemoryException(context->threadContext);
goto done_out;
}
RexxDirectoryObject d;
uint32_t secs, incr;
for ( size_t i = 1; i <= count; i++ )
{
if ( ! rxDirectoryFromArray(context, vals, i, &d, 1) )
{
goto done_out;
}
if ( ! rxNumberFromDirectory(context, (RexxDirectoryObject)d, "SECONDS", &secs, 1, true) )
{
goto done_out;
}
if ( ! rxNumberFromDirectory(context, (RexxDirectoryObject)d, "INCREMENT", &incr, 1, true) )
{
goto done_out;
}
pUDA[i - 1].nInc = incr;
pUDA[i - 1].nSec = secs;
}
SendMessage(hCtrl, UDM_SETACCEL, count, (LPARAM)pUDA);
done_out:
safeFree(pUDA);
return 0;
}