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
|
//////////////////////////////////////////////////////////////////////////
//
// pgAdmin III - PostgreSQL Tools
//
// Copyright (C) 2002 - 2014, The pgAdmin Development Team
// This software is released under the PostgreSQL Licence
//
// ctlMenuToolbar.cpp - Menu tool bar
//
// This code is essentially stolen (with the authors permission) from
// Paul Nelson (http://www.pnelsoncomposer.com/)
//
//////////////////////////////////////////////////////////////////////////
// wxWindows headers
#include <wx/wx.h>
// App headers
#include "pgAdmin3.h"
#include "ctl/ctlMenuToolbar.h"
#include <wx/listimpl.cpp>
WX_DEFINE_LIST(ctlMenuToolList);
/* XPM */
static const char *pulldown_xpm[] =
{
"16 16 2 1",
". c Black",
" c None",
/* pixels */
" ",
" ",
" ",
" ",
" ",
" ",
" ....... ",
" ..... ",
" ... ",
" . ",
" ",
" ",
" ",
" ",
" ",
" "
};
DEFINE_EVENT_TYPE(wxEVT_FILL_MENU)
//////////////////
// ctlMenuButton
//////////////////
void ctlMenuButton::Create(wxWindow *window, wxToolBar *toolBar, int ID, wxMenu *menu)
{
wxBitmap bmpPulldown(pulldown_xpm);
wxSize pulldownSize;
#ifdef __WXMSW__
pulldownSize.Set(12, 16);
#else
#ifdef __WXGTK__
pulldownSize.Set(18, 16);
#else
pulldownSize.Set(10, 16);
#endif
#endif
m_toolBar = toolBar;
m_menu = menu;
((wxBitmapButton *)this)->Create(window, ID, bmpPulldown, wxDefaultPosition, pulldownSize, wxNO_BORDER);
Connect(ID, wxEVT_LEFT_DOWN, wxMouseEventHandler(ctlMenuButton::DoProcessLeftClick) );
}
void ctlMenuButton::DoProcessLeftClick(wxMouseEvent &event)
{
wxPoint menu_pos;
if(m_toolBar)
{
wxSize tool_size = m_toolBar->GetToolSize();
wxSize button_size = GetSize();
// ** Assume that pulldown is to the right of a standard toolbar button,
// so, move the x position back one standard toolbar button's width
menu_pos.x = - tool_size.GetWidth();
menu_pos.y = button_size.GetHeight() / 2 + tool_size.GetHeight() / 2;
#ifdef __WXMAC__
wxSize tbar_size = m_toolBar->GetSize();
wxPoint button_pos = GetPosition();
int iToolSep = m_toolBar->GetToolSeparation();
if(iToolSep == 0) iToolSep = 5;
menu_pos.x += - iToolSep;
menu_pos.y = tbar_size.GetHeight() - button_pos.y / 2;
#endif
}
else
{
wxSize button_size;
button_size = GetSize();
menu_pos.x = 0;
menu_pos.y = button_size.GetHeight();
}
PopupMenu(m_menu, menu_pos);
}
////////////////
// ctlMenuTool
////////////////
ctlMenuTool::ctlMenuTool(wxToolBarToolBase *new_tool, int toolId)
{
m_tool = new_tool;
m_menu = NULL;
m_toolId = toolId;
}
////////////////////
// ctlMenuToolbar
////////////////////
ctlMenuToolbar::ctlMenuToolbar(wxFrame *parent, wxWindowID id, const wxPoint &pos, const wxSize &size, long style, const wxString &name)
: wxToolBar(parent, id, pos, size, style, name)
{
m_frame = parent;
m_menuTools = NULL;
Connect(id, wxEVT_LEFT_DOWN, wxMouseEventHandler(ctlMenuToolbar::DoProcessLeftClick) );
}
ctlMenuToolbar::~ctlMenuToolbar()
{
if(m_menuTools)
delete m_menuTools;
}
ctlMenuButton *ctlMenuToolbar::AddMenuPulldownTool(int toolId, const wxString &label, const wxString &shortHelpString, wxMenu *popupmenu)
{
ctlMenuButton *menu_button = new ctlMenuButton(this, toolId, popupmenu);
AddControl(menu_button);
return menu_button;
}
void ctlMenuToolbar::DoProcessLeftClick(wxMouseEvent &event)
{
ctlMenuToolList::Node *node = NULL;
ctlMenuTool *menu_tool = NULL;
wxToolBarToolBase *clickTool = FindToolForPosition(event.m_x, event.m_y);
if(clickTool == NULL || m_menuTools == NULL)
{
event.Skip();
return;
}
// search for clickTool in the list of menu tools
node = m_menuTools->GetFirst();
for( ; node ; node = node->GetNext())
{
menu_tool = node->GetData();
if(menu_tool->m_tool == clickTool)
break;
}
if(node == NULL)
{
event.Skip();
return;
}
wxSize tbar_size = GetSize();
wxPoint menu_pos;
menu_pos.x = event.m_x - 20;
menu_pos.y = tbar_size.GetHeight() - 2;
PopupMenu(menu_tool->m_menu, menu_pos);
}
|