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
|
//////////////////////////////////////////////////////////////////////////
//
// pgAdmin III - PostgreSQL Tools
//
// Copyright (C) 2002 - 2014, The pgAdmin Development Team
// This software is released under the PostgreSQL Licence
//
// ddColumnOptionIcon.cpp - Part of composite column figure, allow to choose between: not null and null
//
//////////////////////////////////////////////////////////////////////////
#include "pgAdmin3.h"
// wxWindows headers
#include <wx/wx.h>
#include <wx/dcbuffer.h>
#include <wx/pen.h>
// App headers
#include "dd/dditems/figures/ddColumnOptionIcon.h"
#include "hotdraw/main/hdDrawingView.h"
#include "dd/dditems/figures/ddColumnFigure.h"
//Images
#include "images/ddnull.pngc"
#include "images/ddnotnull.pngc"
ddColumnOptionIcon::ddColumnOptionIcon(ddColumnFigure *owner)
{
setKindId(DDCOLUMNOPTIONICON);
ownerColumn = owner;
colOption = null;
icon = wxBitmap(*ddnull_png_img);
iconToDraw = &icon;
getBasicDisplayBox().SetSize(wxSize(getWidth(), getHeight()));
//Set Value default Attributes
fontAttribute->font().SetPointSize(owner->fontAttribute->font().GetPointSize());
}
ddColumnOptionIcon::~ddColumnOptionIcon()
{
}
void ddColumnOptionIcon::createMenu(wxMenu &mnu)
{
wxMenuItem *item;
item = mnu.AppendCheckItem(MNU_COLNULL, _("NULL"));
item->Check(colOption == null);
item->Enable(!getOwnerColumn()->isGeneratedForeignKey());
item = mnu.AppendCheckItem(MNU_COLNOTNULL, _("Not NULL"));
item->Check(colOption == notnull);
item->Enable(!getOwnerColumn()->isGeneratedForeignKey());
}
void ddColumnOptionIcon::OnGenericPopupClick(wxCommandEvent &event, hdDrawingView *view)
{
changeIcon((ddColumnOptionType)event.GetId());
}
void ddColumnOptionIcon::changeIcon(ddColumnOptionType type)
{
colOption = type;
switch(type)
{
case MNU_COLNULL:
icon = wxBitmap(*ddnull_png_img);
if(getOwnerColumn()->isPrimaryKey())
{
if(getOwnerColumn()->isForeignKey() || getOwnerColumn()->isUniqueKey())
{
getOwnerColumn()->toggleColumnKind(pk); //remove pk attribute because column now is null
getOwnerColumn()->setRightIconForColumn();
}
else
{
getOwnerColumn()->disablePrimaryKey();
}
}
break;
case MNU_COLNOTNULL:
icon = wxBitmap(*ddnotnull_png_img);
break;
}
getBasicDisplayBox().SetSize(wxSize(getWidth(), getHeight()));
}
void ddColumnOptionIcon::basicDraw(wxBufferedDC &context, hdDrawingView *view)
{
if(iconToDraw)
{
hdRect copy = displayBox().gethdRect(view->getIdx());
view->CalcScrolledPosition(copy.x, copy.y, ©.x, ©.y);
context.DrawBitmap(*iconToDraw, copy.GetPosition(), true);
}
}
void ddColumnOptionIcon::basicDrawSelected(wxBufferedDC &context, hdDrawingView *view)
{
basicDraw(context, view);
}
int ddColumnOptionIcon::getWidth()
{
if(iconToDraw)
return iconToDraw->GetWidth();
else
return 8;
}
int ddColumnOptionIcon::getHeight()
{
if(iconToDraw)
return iconToDraw->GetHeight();
else
return 10;
}
ddColumnOptionType ddColumnOptionIcon::getOption()
{
return colOption;
}
ddColumnFigure *ddColumnOptionIcon::getOwnerColumn()
{
return ownerColumn;
}
|