1 //////////////////////////////////////////////////////////////////////////
2 //
3 // pgAdmin III - PostgreSQL Tools
4 //
5 // Copyright (C) 2002 - 2016, The pgAdmin Development Team
6 // This software is released under the PostgreSQL Licence
7 //
8 // ddScrollBarHandle.cpp - A handle for a table figure that allow to scroll it when table is not in full size
9 //
10 //////////////////////////////////////////////////////////////////////////
11
12 #include "pgAdmin3.h"
13
14 // wxWindows headers
15 #include <wx/wx.h>
16
17 // App headers
18 #include "dd/dditems/handles/ddScrollBarHandle.h"
19 #include "hotdraw/utilities/hdPoint.h"
20 #include "hotdraw/main/hdDrawingView.h"
21 #include "hotdraw/utilities/hdGeometry.h"
22
23 //Images
24 #include "images/ddUp.pngc"
25 #include "images/ddDown.pngc"
26
ddScrollBarHandle(ddTableFigure * owner,hdILocator * scrollBarLocator,wxSize & size)27 ddScrollBarHandle::ddScrollBarHandle(ddTableFigure *owner, hdILocator *scrollBarLocator , wxSize &size):
28 hdLocatorHandle(owner, scrollBarLocator)
29 {
30 table = owner;
31 scrollLocator = scrollBarLocator;
32 displayBox.SetSize(size);
33 upBitmap = wxBitmap(*ddUp_png_img);
34 downBitmap = wxBitmap(*ddDown_png_img);
35 }
36
~ddScrollBarHandle()37 ddScrollBarHandle::~ddScrollBarHandle()
38 {
39 }
40
41
createCursor()42 wxCursor ddScrollBarHandle::createCursor()
43 {
44 return wxCursor(wxCURSOR_HAND);
45 }
46
47 //avoid to use inflate on this handle
getDisplayBox(int posIdx)48 hdRect &ddScrollBarHandle::getDisplayBox(int posIdx)
49 {
50 hdPoint p = locate(posIdx);
51 displayBox.width = 11; //as defined at locator
52 displayBox.height = table->getColsSpace().height;
53 displayBox.SetPosition(p);
54 return displayBox;
55 }
56
draw(wxBufferedDC & context,hdDrawingView * view)57 void ddScrollBarHandle::draw(wxBufferedDC &context, hdDrawingView *view)
58 {
59 int idx = view->getIdx();
60 context.SetBrush(*wxWHITE_BRUSH);
61 wxPoint copy = getDisplayBox(idx).GetPosition();
62 view->CalcScrolledPosition(copy.x, copy.y, ©.x, ©.y);
63 context.DrawRectangle(copy.x, copy.y, getDisplayBox(idx).width, getDisplayBox(idx).height);
64 context.DrawBitmap(upBitmap, copy.x + 1, copy.y + 2, true);
65 context.DrawBitmap(downBitmap, copy.x + 1, copy.y + getDisplayBox(idx).height - 2 - downBitmap.GetHeight(), true);
66
67 barSize.SetHeight((getDisplayBox(idx).height - 12) * 0.45);
68 barSize.SetWidth(getDisplayBox(idx).width - 4);
69
70 int divBy = (table->getTotalColumns() - table->getColumnsWindow());
71 if(divBy <= 0)
72 divBy = table->getColumnsWindow();
73 int colOffset = barSize.GetHeight() / divBy;
74 int verticalPosBar = 3 + copy.y + downBitmap.GetHeight() + colOffset * table->getTopColWindowIndex();
75 if(table->getColumnsWindow() > 1)
76 context.DrawRectangle(wxPoint(copy.x + 2, verticalPosBar), barSize);
77
78 }
79
invokeStart(hdMouseEvent & event,hdDrawingView * view)80 void ddScrollBarHandle::invokeStart(hdMouseEvent &event, hdDrawingView *view)
81 {
82 int idx = view->getIdx();
83 int y = event.GetPosition().y;
84 anchorY = y;
85 if( (y > (getDisplayBox(idx).GetPosition().y + 2)) && (y < (getDisplayBox(idx).GetPosition().y + 2 + 6)) ) //6 image height
86 table->columnsWindowUp(idx);
87
88 if( (y > (getDisplayBox(idx).GetPosition().y + getDisplayBox(idx).height - 2 - downBitmap.GetHeight()) ) && (y < (getDisplayBox(idx).GetPosition().y + getDisplayBox(idx).height - 2) ) )
89 table->columnsWindowDown(idx);
90 view->notifyChanged();
91 }
92
invokeStep(hdMouseEvent & event,hdDrawingView * view)93 void ddScrollBarHandle::invokeStep(hdMouseEvent &event, hdDrawingView *view)
94 {
95 int y = event.GetPosition().y;
96 int divBy = (table->getTotalColumns() - table->getColumnsWindow());
97 if(divBy <= 0)
98 divBy = table->getColumnsWindow();
99 int colOffset = barSize.GetHeight() / divBy;
100
101 hdGeometry g;
102 if ( g.ddabs(anchorY - y) > colOffset)
103 {
104 if((anchorY - y) > 0)
105 {
106 table->columnsWindowUp(view->getIdx());
107 }
108 else
109 {
110 table->columnsWindowDown(view->getIdx());
111 }
112 anchorY = y;
113 }
114 view->notifyChanged();
115 }
116
invokeEnd(hdMouseEvent & event,hdDrawingView * view)117 void ddScrollBarHandle::invokeEnd(hdMouseEvent &event, hdDrawingView *view)
118 {
119 }
120
locate(int posIdx)121 hdPoint &ddScrollBarHandle::locate(int posIdx)
122 {
123 if(scrollLocator)
124 {
125 pointLocate = scrollLocator->locate(posIdx, getOwner());
126 return pointLocate;
127 }
128 else
129 pointLocate = hdPoint(0, 0);
130 return pointLocate;
131 }
132