NCBI C++ ToolKit
edit_tb.cpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /* $Id: edit_tb.cpp 39823 2017-11-08 17:14:23Z katargir $
2  * ===========================================================================
3  *
4  * PUBLIC DOMAIN NOTICE
5  * National Center for Biotechnology Information
6  *
7  * This software/database is a "United States Government Work" under the
8  * terms of the United States Copyright Act. It was written as part of
9  * the author's official duties as a United States Government employee and
10  * thus cannot be copyrighted. This software/database is freely available
11  * to the public for use. The National Library of Medicine and the U.S.
12  * Government have not placed any restriction on its use or reproduction.
13  *
14  * Although all reasonable efforts have been taken to ensure the accuracy
15  * and reliability of the software and data, the NLM and the U.S.
16  * Government do not and cannot warrant the performance or results that
17  * may be obtained by using this software or data. The NLM and the U.S.
18  * Government disclaim all warranties, express or implied, including
19  * warranties of performance, merchantability or fitness for any particular
20  * purpose.
21  *
22  * Please cite the author in any work or product based on this material.
23  *
24  * ===========================================================================
25  *
26  * Authors: Roman Katargin
27  *
28  * File Description:
29  *
30  */
31 
32 #include <ncbi_pch.hpp>
33 
34 #include "edit_tb.hpp"
38 
40 
41 #include <wx/dcclient.h>
42 
44 
47 
48 CEditToolbar::CEditToolbar(ITextItem* item, int editFlags) : m_Item(item), m_EditFlags(editFlags)
49 {
50  SetSize(wxSize(32, 16));
51 
52  static bool bitmap_registered = false;
53  if (!bitmap_registered) {
55  provider->RegisterFileAlias(wxT("edit_tb::edit"), wxT("pen.png"));
56  provider->RegisterFileAlias(wxT("edit_tb::delete"), wxT("delete.png"));
57  bitmap_registered = true;
58  }
59 
60  if (!m_EditBmp.IsOk())
61  m_EditBmp = wxArtProvider::GetBitmap(wxT("edit_tb::edit"));
62 
63  if (!m_DeleteBmp.IsOk())
64  m_DeleteBmp = wxArtProvider::GetBitmap(wxT("edit_tb::delete"));
65 }
66 
67 void CEditToolbar::Draw(wxDC& dc, CTextPanelContext* WXUNUSED(context))
68 {
70  dc.DrawBitmap(m_EditBmp, 0, 0);
72  dc.DrawBitmap(m_DeleteBmp, 16, 0);
73 }
74 
75 void CEditToolbar::MouseEvent(wxMouseEvent& event)
76 {
77  if (event.Moving())
78  MouseMove(event);
79  else if (event.LeftUp())
80  MouseLeftUp(event);
81 }
82 
83 void CEditToolbar::MouseLeftUp(wxMouseEvent& event)
84 {
85  CTextItemPanel* panel = (CTextItemPanel*)event.GetEventObject();
87  context->SelectItem(m_Item, false, false);
88 
89  if (event.m_x < 16) {
91  return;
92  context->EditItem(m_Item, false, false);
93  //wxCommandEvent evt(wxEVT_COMMAND_MENU_SELECTED, eCmdEditObjects);
94  //evt.SetEventObject(panel);
95  //panel->GetEventHandler()->AddPendingEvent(evt);
96  }
97  else {
99  return;
100  wxCommandEvent evt(wxEVT_COMMAND_MENU_SELECTED, eCmdDeleteObjects);
101  evt.SetEventObject(panel);
102  panel->GetEventHandler()->AddPendingEvent(evt);
103  }
104 }
105 
106 void CEditToolbar::MouseMove(wxMouseEvent& event)
107 {
108  CTextItemPanel* panel = static_cast<CTextItemPanel*>(event.GetEventObject());
109  if (event.m_x < 16) {
110  panel->SetCursor((m_EditFlags & IBioseqEditor::kObjectEditable) != 0
111  ? wxCursor(wxCURSOR_HAND) : wxCursor(wxCURSOR_IBEAM));
112  }
113  else {
114  panel->SetCursor((m_EditFlags & IBioseqEditor::kObjectDeletable) != 0
115  ? wxCursor(wxCURSOR_HAND) : wxCursor(wxCURSOR_IBEAM));
116  }
117 }
118 
virtual void MouseEvent(wxMouseEvent &event)
Definition: edit_tb.cpp:75
ITextItem * m_Item
Definition: edit_tb.hpp:58
void MouseLeftUp(wxMouseEvent &event)
Definition: edit_tb.cpp:83
static wxBitmap m_EditBmp
Definition: edit_tb.hpp:61
CEditToolbar(ITextItem *item, int editFlags)
Definition: edit_tb.cpp:48
void MouseMove(wxMouseEvent &event)
Definition: edit_tb.cpp:106
int m_EditFlags
Definition: edit_tb.hpp:59
static wxBitmap m_DeleteBmp
Definition: edit_tb.hpp:62
virtual void Draw(wxDC &dc, CTextPanelContext *context)
Definition: edit_tb.cpp:67
void SetSize(wxSize size)
Definition: glyph.hpp:59
CTextPanelContext * GetContext()
virtual void RegisterFileAlias(const wxArtID &anId, const wxArtClient &aClient, const wxSize &aSize, const wxString &aName, long aType=wxBITMAP_TYPE_ANY, int anIndex=-1)
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
@ eCmdDeleteObjects
#define wxT(x)
Definition: muParser.cpp:41
wxEVT_COMMAND_MENU_SELECTED
static CS_CONTEXT * context
Definition: will_convert.c:21
wxFileArtProvider * GetDefaultFileArtProvider()
Definition: wx_utils.cpp:334
Modified on Wed May 15 15:04:06 2024 by modify_doxy.py rev. 669887