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
|
//////////////////////////////////////////////////////////////////////////
//
// pgAdmin III - PostgreSQL Tools
//
// Copyright (C) 2002 - 2014, The pgAdmin Development Team
// This software is released under the PostgreSQL Licence
//
// ddScrollBarHandle.cpp - A handle for a table figure that allow to scroll it when table is not in full size
//
//////////////////////////////////////////////////////////////////////////
#include "pgAdmin3.h"
// wxWindows headers
#include <wx/wx.h>
// App headers
#include "dd/dditems/handles/ddScrollBarHandle.h"
#include "hotdraw/utilities/hdPoint.h"
#include "hotdraw/main/hdDrawingView.h"
#include "hotdraw/utilities/hdGeometry.h"
//Images
#include "images/ddUp.pngc"
#include "images/ddDown.pngc"
ddScrollBarHandle::ddScrollBarHandle(ddTableFigure *owner, hdILocator *scrollBarLocator , wxSize &size):
hdLocatorHandle(owner, scrollBarLocator)
{
table = owner;
scrollLocator = scrollBarLocator;
displayBox.SetSize(size);
upBitmap = wxBitmap(*ddUp_png_img);
downBitmap = wxBitmap(*ddDown_png_img);
}
ddScrollBarHandle::~ddScrollBarHandle()
{
}
wxCursor ddScrollBarHandle::createCursor()
{
return wxCursor(wxCURSOR_HAND);
}
//avoid to use inflate on this handle
hdRect &ddScrollBarHandle::getDisplayBox(int posIdx)
{
hdPoint p = locate(posIdx);
displayBox.width = 11; //as defined at locator
displayBox.height = table->getColsSpace().height;
displayBox.SetPosition(p);
return displayBox;
}
void ddScrollBarHandle::draw(wxBufferedDC &context, hdDrawingView *view)
{
int idx = view->getIdx();
context.SetBrush(*wxWHITE_BRUSH);
wxPoint copy = getDisplayBox(idx).GetPosition();
view->CalcScrolledPosition(copy.x, copy.y, ©.x, ©.y);
context.DrawRectangle(copy.x, copy.y, getDisplayBox(idx).width, getDisplayBox(idx).height);
context.DrawBitmap(upBitmap, copy.x + 1, copy.y + 2, true);
context.DrawBitmap(downBitmap, copy.x + 1, copy.y + getDisplayBox(idx).height - 2 - downBitmap.GetHeight(), true);
barSize.SetHeight((getDisplayBox(idx).height - 12) * 0.45);
barSize.SetWidth(getDisplayBox(idx).width - 4);
int divBy = (table->getTotalColumns() - table->getColumnsWindow());
if(divBy <= 0)
divBy = table->getColumnsWindow();
int colOffset = barSize.GetHeight() / divBy;
int verticalPosBar = 3 + copy.y + downBitmap.GetHeight() + colOffset * table->getTopColWindowIndex();
if(table->getColumnsWindow() > 1)
context.DrawRectangle(wxPoint(copy.x + 2, verticalPosBar), barSize);
}
void ddScrollBarHandle::invokeStart(hdMouseEvent &event, hdDrawingView *view)
{
int idx = view->getIdx();
int y = event.GetPosition().y;
anchorY = y;
if( (y > (getDisplayBox(idx).GetPosition().y + 2)) && (y < (getDisplayBox(idx).GetPosition().y + 2 + 6)) ) //6 image height
table->columnsWindowUp(idx);
if( (y > (getDisplayBox(idx).GetPosition().y + getDisplayBox(idx).height - 2 - downBitmap.GetHeight()) ) && (y < (getDisplayBox(idx).GetPosition().y + getDisplayBox(idx).height - 2) ) )
table->columnsWindowDown(idx);
view->notifyChanged();
}
void ddScrollBarHandle::invokeStep(hdMouseEvent &event, hdDrawingView *view)
{
int y = event.GetPosition().y;
int divBy = (table->getTotalColumns() - table->getColumnsWindow());
if(divBy <= 0)
divBy = table->getColumnsWindow();
int colOffset = barSize.GetHeight() / divBy;
hdGeometry g;
if ( g.ddabs(anchorY - y) > colOffset)
{
if((anchorY - y) > 0)
{
table->columnsWindowUp(view->getIdx());
}
else
{
table->columnsWindowDown(view->getIdx());
}
anchorY = y;
}
view->notifyChanged();
}
void ddScrollBarHandle::invokeEnd(hdMouseEvent &event, hdDrawingView *view)
{
}
hdPoint &ddScrollBarHandle::locate(int posIdx)
{
if(scrollLocator)
{
pointLocate = scrollLocator->locate(posIdx, getOwner());
return pointLocate;
}
else
pointLocate = hdPoint(0, 0);
return pointLocate;
}
|