Code::Blocks  SVN r11506
confirmreplacedlg.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of the Code::Blocks IDE and licensed under the GNU Lesser General Public License, version 3
3  * http://www.gnu.org/licenses/lgpl-3.0.html
4  *
5  * $Revision: 7294 $
6  * $Id: confirmreplacedlg.cpp 7294 2011-07-26 12:52:57Z tpetrov $
7  * $HeadURL: https://svn.code.sf.net/p/codeblocks/code/trunk/src/sdk/confirmreplacedlg.cpp $
8  */
9 
10 #include "sdk_precomp.h"
11 
12 #ifndef CB_PRECOMP
13  #include <wx/xrc/xmlres.h>
14  #include <wx/stattext.h>
15  #include <wx/settings.h>
16 
17  #include "cbeditor.h"
18 #endif
19 #include "cbstyledtextctrl.h"
20 
21 #include "confirmreplacedlg.h"
22 
23 BEGIN_EVENT_TABLE(ConfirmReplaceDlg, wxScrollingDialog)
24  EVT_BUTTON(XRCID("btnYes"), ConfirmReplaceDlg::OnYes)
25  EVT_BUTTON(XRCID("btnNo"), ConfirmReplaceDlg::OnNo)
26  EVT_BUTTON(XRCID("btnAllInFile"), ConfirmReplaceDlg::OnAllInFile)
27  EVT_BUTTON(XRCID("btnSkipFile"), ConfirmReplaceDlg::OnSkipFile)
28  EVT_BUTTON(XRCID("btnAll"), ConfirmReplaceDlg::OnAll)
29  EVT_BUTTON(XRCID("btnCancel"), ConfirmReplaceDlg::OnCancel)
30 END_EVENT_TABLE()
31 
32 ConfirmReplaceDlg::ConfirmReplaceDlg(wxWindow* parent, bool replaceInFiles, const wxString& label)
33 {
34  if (replaceInFiles)
35  wxXmlResource::Get()->LoadObject(this, parent, _T("dlgConfirmReplaceMultiple"),_T("wxScrollingDialog"));
36  else
37  wxXmlResource::Get()->LoadObject(this, parent, _T("dlgConfirmReplace"),_T("wxScrollingDialog"));
38  XRCCTRL(*this, "lblMessage", wxStaticText)->SetLabel(label);
39  this->SetEscapeId(XRCID("btnCancel"));
40 }
41 
43 {
44 }
45 
47 {
48  EndModal(crYes);
49 }
50 
52 {
53  EndModal(crNo);
54 }
55 
57 {
59 }
60 
62 {
64 }
65 
67 {
68  EndModal(crAll);
69 }
70 
72 {
74 }
75 
77 {
78  if(!ed)
79  return;
80 
81  int w = 0, h = 0;
82  GetSize(&w,&h);
83 
84  wxPoint pt = ed->PointFromPosition(ed->GetCurrentPos());
85  int ed_width = ed->GetSize().x;
86  pt.x = (ed_width - w) / 2;
87  if(pt.x < 0)
88  pt.x = 0;
89  pt = ed->ClientToScreen(pt);
90 
91  int lineHeight = ed->TextHeight(ed->GetCurrentLine());
92 
95  // sanity check
96  if (w > screenW)
97  w = screenW;
98  if (h > screenH)
99  h = screenH;
100 
101  // now we 're where we want to be, but check that the whole window is visible...
102  // the main goal here is that the caret *should* be visible...
103 
104  // for the horizontal axis, easy stuff
105  if (pt.x + w > screenW)
106  pt.x = screenW - w;
107 
108  // for the vertical axis, more work has to be done...
109 
110  // Does it fit 4 lines above current line?
111  if (h + 4*lineHeight < pt.y)
112  pt.y -= h + 4*lineHeight;
113  else if (pt.y + lineHeight + (2*h) <= screenH)
114  {
115  // One line below current line?
116  pt.y += lineHeight;
117  }
118  else
119  {
120  // Top of the screen
121  pt.y = 0;
122  }
123  // we should be OK now
124  SetSize(pt.x, pt.y, w, h);
125 }
void EndModal(int retCode)
Definition: sc_dialog.cpp:112
#define _T(string)
void OnSkipFile(wxCommandEvent &event)
void OnNo(wxCommandEvent &event)
int TextHeight(int line)
Retrieve the height of a particular line of text in pixels.
static int GetMetric(wxSystemMetric index, wxWindow *win=NULL)
int GetCurrentLine()
Manually declared methods.
void OnAll(wxCommandEvent &event)
wxPoint PointFromPosition(int pos)
Retrieve the point in the window where a position is displayed.
void OnCancel(wxCommandEvent &event)
void OnAllInFile(wxCommandEvent &event)
int GetCurrentPos() const
Returns the position of the caret.
void CalcPosition(cbStyledTextCtrl *ed)
~ConfirmReplaceDlg() override
static wxXmlResource * Get()
wxObject * LoadObject(wxWindow *parent, const wxString &name, const wxString &classname)
void OnYes(wxCommandEvent &event)