File: FXRulerView.cpp

package info (click to toggle)
gogglesmm 1.2.5-6
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 16,812 kB
  • sloc: cpp: 231,960; ansic: 893; xml: 222; makefile: 33
file content (669 lines) | stat: -rw-r--r-- 16,699 bytes parent folder | download | duplicates (2)
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
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
/********************************************************************************
*                                                                               *
*                         R u l e r V i e w   W i d g e t                       *
*                                                                               *
*********************************************************************************
* Copyright (C) 2005,2022 by Jeroen van der Zijp.   All Rights Reserved.        *
*********************************************************************************
* This library is free software; you can redistribute it and/or modify          *
* it under the terms of the GNU Lesser General Public License as published by   *
* the Free Software Foundation; either version 3 of the License, or             *
* (at your option) any later version.                                           *
*                                                                               *
* This library is distributed in the hope that it will be useful,               *
* but WITHOUT ANY WARRANTY; without even the implied warranty of                *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                 *
* GNU Lesser General Public License for more details.                           *
*                                                                               *
* You should have received a copy of the GNU Lesser General Public License      *
* along with this program.  If not, see <http://www.gnu.org/licenses/>          *
********************************************************************************/
#include "xincs.h"
#include "fxver.h"
#include "fxdefs.h"
#include "fxmath.h"
#include "FXArray.h"
#include "FXHash.h"
#include "FXMutex.h"
#include "FXStream.h"
#include "FXString.h"
#include "FXSize.h"
#include "FXPoint.h"
#include "FXRectangle.h"
#include "FXStringDictionary.h"
#include "FXSettings.h"
#include "FXRegistry.h"
#include "FXAccelTable.h"
#include "FXEvent.h"
#include "FXWindow.h"
#include "FXDCWindow.h"
#include "FXApp.h"
#include "FXScrollBar.h"
#include "FXScrollArea.h"
#include "FXRuler.h"
#include "FXRulerView.h"


/*
  Notes:
  - Should implement DND drags/drops, cut/paste
  - Right-mouse scroll.
*/


#define RULERVIEW_MASK (RULERVIEW_ALIGN_STRETCH_X|RULERVIEW_ALIGN_STRETCH_Y)

#define HSCROLLMASK (HSCROLLER_ALWAYS|HSCROLLER_NEVER|HSCROLLING_ON|HSCROLLING_OFF|SCROLLERS_DONT_TRACK)

#define VSCROLLMASK (VSCROLLER_ALWAYS|VSCROLLER_NEVER|VSCROLLING_ON|VSCROLLING_OFF|SCROLLERS_DONT_TRACK)


using namespace FX;


/*******************************************************************************/

namespace FX {


// Map
FXDEFMAP(FXRulerView) FXRulerViewMap[]={
  FXMAPFUNC(SEL_PAINT,0,FXRulerView::onPaint),
  FXMAPFUNC(SEL_MOTION,0,FXRulerView::onMotion),
  FXMAPFUNC(SEL_QUERY_TIP,0,FXRulerView::onQueryTip),
  FXMAPFUNC(SEL_QUERY_HELP,0,FXRulerView::onQueryHelp),
  FXMAPFUNC(SEL_COMMAND,FXRulerView::ID_SETHELPSTRING,FXRulerView::onCmdSetHelp),
  FXMAPFUNC(SEL_COMMAND,FXRulerView::ID_GETHELPSTRING,FXRulerView::onCmdGetHelp),
  FXMAPFUNC(SEL_COMMAND,FXRulerView::ID_SETTIPSTRING,FXRulerView::onCmdSetTip),
  FXMAPFUNC(SEL_COMMAND,FXRulerView::ID_GETTIPSTRING,FXRulerView::onCmdGetTip),
  FXMAPFUNC(SEL_CHANGED,FXRulerView::ID_HRULER,FXRulerView::onDocChanged),
  FXMAPFUNC(SEL_CHANGED,FXRulerView::ID_VRULER,FXRulerView::onDocChanged),
  };


// Object implementation
FXIMPLEMENT(FXRulerView,FXScrollArea,FXRulerViewMap,ARRAYNUMBER(FXRulerViewMap))


// Deserialization
FXRulerView::FXRulerView(){
  flags|=FLAG_ENABLED;
  hruler=nullptr;
  vruler=nullptr;
  filler=nullptr;
  docColor=0;
  }


// Construct and init
FXRulerView::FXRulerView(FXComposite* p,FXObject* tgt,FXSelector sel,FXuint opts,FXint x,FXint y,FXint w,FXint h):FXScrollArea(p,opts,x,y,w,h){
  hruler=new FXRuler(this,this,ID_HRULER,RULER_HORIZONTAL|RULER_NUMBERS|RULER_ARROW|RULER_TICKS_CENTER|LAYOUT_SIDE_TOP|LAYOUT_FILL_X|LAYOUT_FILL_COLUMN);
  vruler=new FXRuler(this,this,ID_VRULER,RULER_VERTICAL|RULER_NUMBERS|RULER_ARROW|RULER_TICKS_CENTER|LAYOUT_SIDE_LEFT|LAYOUT_FILL_Y|LAYOUT_FILL_ROW);
  filler=new FXFrame(this,FRAME_NONE);
  backColor=getApp()->getShadowColor();
  docColor=getApp()->getBackColor();
  flags|=FLAG_ENABLED;
  target=tgt;
  message=sel;
  }


// Get default width
FXint FXRulerView::getDefaultWidth(){
  return FXScrollArea::getDefaultWidth()+vruler->getDefaultWidth();
  }


// Get default height
FXint FXRulerView::getDefaultHeight(){
  return FXScrollArea::getDefaultHeight()+hruler->getDefaultHeight();
  }


// Get document position X
FXint FXRulerView::getDocumentX() const {
  return vruler->getWidth()+hruler->getDocumentLower();
  }


// Get document position Y
FXint FXRulerView::getDocumentY() const {
  return hruler->getHeight()+vruler->getDocumentLower();
  }


// Set document width
void FXRulerView::setDocumentWidth(FXint w,FXbool notify){
  hruler->setDocumentSize(w,notify);
  }


// Get document width
FXint FXRulerView::getDocumentWidth() const {
  return hruler->getDocumentSize();
  }


// Set document height
void FXRulerView::setDocumentHeight(FXint h,FXbool notify){
  vruler->setDocumentSize(h,notify);
  }


// Get document height
FXint FXRulerView::getDocumentHeight() const {
  return vruler->getDocumentSize();
  }


// Return visible area x position
FXint FXRulerView::getVisibleX() const {
  return vruler->getDefaultWidth();
  }


// Return visible area y position
FXint FXRulerView::getVisibleY() const {
  return hruler->getDefaultHeight();
  }


// Return visible area width
FXint FXRulerView::getVisibleWidth() const {
  return width-vruler->getDefaultWidth()-vertical->getWidth();
  }


// Return visible area height
FXint FXRulerView::getVisibleHeight() const {
  return height-hruler->getDefaultHeight()-horizontal->getHeight();
  }


// Determine minimum content width of scroll area
FXint FXRulerView::getContentWidth(){
  return hruler->getContentSize();
  }


// Determine minimum content height of scroll area
FXint FXRulerView::getContentHeight(){
  return vruler->getContentSize();
  }


// Move content
void FXRulerView::moveContents(FXint x,FXint y){
  FXScrollArea::moveContents(x,y);
  hruler->setPosition(x);
  vruler->setPosition(y);
  }


// Recalculate layout
void FXRulerView::layout(){
  FXint vrw=vruler->getDefaultWidth();
  FXint hrh=hruler->getDefaultHeight();

  // Layout scroll bars and viewport
  placeScrollBars(width-vrw,height-hrh);

  // Place rulers
  hruler->position(vrw,0,getVisibleWidth(),hrh);
  vruler->position(0,hrh,vrw,getVisibleHeight());
  filler->position(0,0,vrw,hrh);

  // Redraw
  update();

  // Clean
  flags&=~FLAG_DIRTY;
  }


// Draw document background
void FXRulerView::drawBackground(FXDCWindow& dc){
  FXint docx,docy,docw,doch;

  // Background
  dc.setForeground(backColor);
  docx=getDocumentX();
  docy=getDocumentY();
  docw=getDocumentWidth();
  doch=getDocumentHeight();

  dc.fillRectangle(0,0,docx,height);
  dc.fillRectangle(docx+docw,0,width-docx-docw,height);
  dc.fillRectangle(docx,0,docw,docy);
  dc.fillRectangle(docx,docy+doch,docw,height-docy-doch);

  // Document insides
  dc.setForeground(docColor);
  dc.fillRectangle(docx,docy,docw,doch);
  dc.setForeground(FXRGB(0,0,0));
  dc.drawRectangle(docx-1,docy-1,docw+1,doch+1);
  dc.fillRectangle(docx+1,docy+doch+1,docw+2,2);
  dc.fillRectangle(docx+docw+1,docy+1,2,doch+2);
  }


// Draw contents
void FXRulerView::drawContents(FXDCWindow&){
  }


// Handle repaint
long FXRulerView::onPaint(FXObject*,FXSelector,void* ptr){
  FXDCWindow dc(this,(FXEvent*)ptr);
  drawBackground(dc);
  drawContents(dc);
  return 1;
  }


// Moving
long FXRulerView::onMotion(FXObject*,FXSelector,void*ptr){
  setArrowPosX(((FXEvent*)ptr)->win_x-getDocumentX());
  setArrowPosY(((FXEvent*)ptr)->win_y-getDocumentY());
  return 0;
  }


// Set help using a message
long FXRulerView::onCmdSetHelp(FXObject*,FXSelector,void* ptr){
  setHelpText(*((FXString*)ptr));
  return 1;
  }


// Get help using a message
long FXRulerView::onCmdGetHelp(FXObject*,FXSelector,void* ptr){
  *((FXString*)ptr)=getHelpText();
  return 1;
  }


// Set tip using a message
long FXRulerView::onCmdSetTip(FXObject*,FXSelector,void* ptr){
  setTipText(*((FXString*)ptr));
  return 1;
  }


// Get tip using a message
long FXRulerView::onCmdGetTip(FXObject*,FXSelector,void* ptr){
  *((FXString*)ptr)=getTipText();
  return 1;
  }


// We were asked about tip text
long FXRulerView::onQueryTip(FXObject* sender,FXSelector sel,void* ptr){
  if(FXScrollArea::onQueryTip(sender,sel,ptr)) return 1;
  if((flags&FLAG_TIP) && !tip.empty()){
    sender->handle(this,FXSEL(SEL_COMMAND,ID_SETSTRINGVALUE),(void*)&tip);
    return 1;
    }
  return 0;
  }


// We were asked about status text
long FXRulerView::onQueryHelp(FXObject* sender,FXSelector sel,void* ptr){
  if(FXScrollArea::onQueryHelp(sender,sel,ptr)) return 1;
  if((flags&FLAG_HELP) && !help.empty()){
    sender->handle(this,FXSEL(SEL_COMMAND,ID_SETSTRINGVALUE),(void*)&help);
    return 1;
    }
  return 0;
  }


// Something in the rulers was changed
long FXRulerView::onDocChanged(FXObject*,FXSelector,void* ptr){
  return target && target->handle(this,FXSEL(SEL_CHANGED,message),ptr);
  }


// Set the current document color
void FXRulerView::setDocumentColor(FXColor clr){
  if(clr!=docColor){
    docColor=clr;
    update();
    }
  }


// Set horizontal alignment; the default is RULER_ALIGN_NORMAL
void FXRulerView::setHAlignment(FXuint align,FXbool notify){
  if(hruler->getRulerAlignment()!=align){
    if(align==RULER_ALIGN_STRETCH)
      setScrollStyle(HSCROLLER_NEVER | (getScrollStyle()&VSCROLLMASK));
    else
      setScrollStyle(HSCROLLING_ON | (getScrollStyle()&VSCROLLMASK));
    update();
    hruler->setRulerAlignment(align,notify);
    }
  }


// Return horizontal alignment
FXuint FXRulerView::getHAlignment() const {
  return hruler->getRulerAlignment();
  }


// Set vertical alignment; the default is RULER_ALIGN_NORMAL
void FXRulerView::setVAlignment(FXuint align,FXbool notify){
  if(vruler->getRulerAlignment()!=align){
    if(align==RULER_ALIGN_STRETCH)
      setScrollStyle(VSCROLLER_NEVER | (getScrollStyle()&HSCROLLMASK));
    else
      setScrollStyle(VSCROLLING_ON | (getScrollStyle()&HSCROLLMASK));
    update();
    vruler->setRulerAlignment(align,notify);
    }
  }


// Return vertical alignment
FXuint FXRulerView::getVAlignment() const {
  return vruler->getRulerAlignment();
  }


// Set X arrow position
void FXRulerView::setArrowPosX(FXint x){
  hruler->setValue(x);
  }

// Set X arrow position
void FXRulerView::setArrowPosY(FXint y){
  vruler->setValue(y);
  }

// Get X arrow position
FXint FXRulerView::getArrowPosX() const {
  return hruler->getValue();
  }

// Get Y arrow position
FXint FXRulerView::getArrowPosY() const {
  return vruler->getValue();
  }


// Set the horizontal ruler font
void FXRulerView::setHRulerFont(FXFont *fnt,FXbool notify){
  hruler->setFont(fnt,notify);
  recalc();
  }


// Get the horizontal ruler font
FXFont* FXRulerView::getHRulerFont() const {
  return hruler->getFont();
  }


// Set the vertical ruler font
void FXRulerView::setVRulerFont(FXFont *fnt,FXbool notify){
  vruler->setFont(fnt,notify);
  recalc();
  }


// Get the vertical ruler font
FXFont* FXRulerView::getVRulerFont() const {
  return vruler->getFont();
  }


// Change edge spacing around document
void FXRulerView::setHEdgeSpacing(FXint es,FXbool notify){
  hruler->setEdgeSpacing(es,notify);
  }


// Change edge spacing around document
void FXRulerView::setVEdgeSpacing(FXint es,FXbool notify){
  vruler->setEdgeSpacing(es,notify);
  }


// Return horizontal edge spacing
FXint FXRulerView::getHEdgeSpacing() const {
  return hruler->getEdgeSpacing();
  }


// Return vertical edge spacing
FXint FXRulerView::getVEdgeSpacing() const {
  return vruler->getEdgeSpacing();
  }


// Change horizontal lower margin
void FXRulerView::setHMarginLower(FXint marg,FXbool notify){
  hruler->setMarginLower(marg,notify);
  }


// Change horizontal upper margin
void FXRulerView::setHMarginUpper(FXint marg,FXbool notify){
  hruler->setMarginUpper(marg,notify);
  }


// Get horizontal lower margin
FXint FXRulerView::getHMarginLower() const {
  return hruler->getMarginLower();
  }


// Get horizontal upper margin
FXint FXRulerView::getHMarginUpper() const {
  return hruler->getMarginUpper();
  }


// Change vertical lower margin
void FXRulerView::setVMarginLower(FXint marg,FXbool notify){
  vruler->setMarginLower(marg,notify);
  }


// Change vertical upper margin
void FXRulerView::setVMarginUpper(FXint marg,FXbool notify){
  vruler->setMarginUpper(marg,notify);
  }


// Get vertical lower margin
FXint FXRulerView::getVMarginLower() const {
  return vruler->getMarginLower();
  }


// Get vertical upper margin
FXint FXRulerView::getVMarginUpper() const {
  return vruler->getMarginUpper();
  }


// Change horizontal document number placement
void FXRulerView::setHNumberTicks(FXint ticks,FXbool notify){
  hruler->setNumberTicks(ticks,notify);
  }


// Change vertical document number placement
void FXRulerView::setVNumberTicks(FXint ticks,FXbool notify){
  vruler->setNumberTicks(ticks,notify);
  }


// Return horizontal document number placement
FXint FXRulerView::getHNumberTicks() const {
  return hruler->getNumberTicks();
  }


// Return vertical document number placement
FXint FXRulerView::getVNumberTicks() const {
  return vruler->getNumberTicks();
  }


// Change horizontal document major ticks
void FXRulerView::setHMajorTicks(FXint ticks,FXbool notify){
  hruler->setMajorTicks(ticks,notify);
  }


// Change vertical document major ticks
void FXRulerView::setVMajorTicks(FXint ticks,FXbool notify){
  vruler->setMajorTicks(ticks,notify);
  }


// Return horizontal document major ticks
FXint FXRulerView::getHMajorTicks() const {
  return hruler->getMajorTicks();
  }


// Return vertical document major ticks
FXint FXRulerView::getVMajorTicks() const {
  return vruler->getMajorTicks();
  }


// Change horizontal document medium ticks
void FXRulerView::setHMediumTicks(FXint ticks,FXbool notify){
  hruler->setMediumTicks(ticks,notify);
  }


// Change vertical document medium ticks
void FXRulerView::setVMediumTicks(FXint ticks,FXbool notify){
  vruler->setMediumTicks(ticks,notify);
  }


// Return horizontal document medium ticks
FXint FXRulerView::getHMediumTicks() const {
  return hruler->getMediumTicks();
  }


// Return vertical document medium ticks
FXint FXRulerView::getVMediumTicks() const {
  return vruler->getMediumTicks();
  }


// Change horizontal document tiny ticks
void FXRulerView::setHTinyTicks(FXint ticks,FXbool notify){
  hruler->setTinyTicks(ticks,notify);
  }

// Change vertical document tiny ticks
void FXRulerView::setVTinyTicks(FXint ticks,FXbool notify){
  vruler->setTinyTicks(ticks,notify);
  }


// Return horizontal document tiny ticks
FXint FXRulerView::getHTinyTicks() const {
  return hruler->getTinyTicks();
  }


// Return vertical document tiny ticks
FXint FXRulerView::getVTinyTicks() const {
  return vruler->getTinyTicks();
  }


// Change horizontal pixel per tick spacing
void FXRulerView::setHPixelPerTick(FXdouble space,FXbool notify){
  hruler->setPixelPerTick(space,notify);
  }


// Change vertical pixel per tick spacing
void FXRulerView::setVPixelPerTick(FXdouble space,FXbool notify){
  vruler->setPixelPerTick(space,notify);
  }


// Return horizontal pixel per tick spacing
FXdouble FXRulerView::getHPixelPerTick() const {
  return hruler->getPixelPerTick();
  }


// Return vertical pixel per tick spacing
FXdouble FXRulerView::getVPixelPerTick() const {
  return vruler->getPixelPerTick();
  }


// Set horizontal ruler style
void FXRulerView::setHRulerStyle(FXuint style){
  hruler->setRulerStyle(style);
  }


// Set vertical ruler style
void FXRulerView::setVRulerStyle(FXuint style){
  hruler->setRulerStyle(style);
  }


// Get horizontal ruler style
FXuint FXRulerView::getHRulerStyle() const {
  return hruler->getRulerStyle();
  }


// Get vertical ruler style
FXuint FXRulerView::getVRulerStyle() const {
  return vruler->getRulerStyle();
  }



// Save object to stream
void FXRulerView::save(FXStream& store) const {
  FXScrollArea::save(store);
  store << hruler;
  store << vruler;
  store << filler;
  store << docColor;
  store << tip;
  store << help;
  }


// Load object from stream
void FXRulerView::load(FXStream& store){
  FXScrollArea::load(store);
  store >> hruler;
  store >> vruler;
  store >> filler;
  store >> docColor;
  store >> tip;
  store >> help;
  }


// Destroy
FXRulerView::~FXRulerView(){
  hruler=(FXRuler*)-1L;
  vruler=(FXRuler*)-1L;
  filler=(FXFrame*)-1L;
  }

}