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

Go to the SVN repository for this file.

1 
2 #include <ncbi_pch.hpp>
3 
5 
7 
8 #include <util/image/image.hpp>
9 
10 #include "wx/utils.h"
11 #include "wx/dc.h"
12 #include "wx/stattext.h"
13 #include "wx/statbox.h"
14 #include "wx/button.h"
15 #include "wx/checkbox.h"
16 #include "wx/textctrl.h"
17 #include "wx/radiobox.h"
18 #include "wx/slider.h"
19 #include "wx/combobox.h"
20 #include "wx/intl.h"
21 #include "wx/sizer.h"
22 #include "wx/cmndata.h"
23 
24 #if wxUSE_STATLINE
25  #include "wx/statline.h"
26 #endif
27 
28 #include "wx/prntbase.h"
29 #include "wx/printdlg.h"
30 #include "wx/paper.h"
31 #include "wx/filename.h"
32 #include "wx/tokenzr.h"
33 #include "wx/imaglist.h"
34 
35 #include <stdlib.h>
36 #include <string.h>
37 
38 // ----------------------------------------------------------------------------
39 // global vars
40 // ----------------------------------------------------------------------------
41 
42 extern WXDLLEXPORT_DATA(wxPrintPaperDatabase*) wxThePrintPaperDatabase;
43 
44 // ----------------------------------------------------------------------------
45 // Generic page setup dialog
46 // ----------------------------------------------------------------------------
47 
49 
50 IMPLEMENT_CLASS(CPreviewSetupDlg, wxPageSetupDialogBase)
51 
52 BEGIN_EVENT_TABLE(CPreviewSetupDlg, wxPageSetupDialogBase)
53  EVT_BUTTON(ePrintIDSetup, CPreviewSetupDlg::OnPrinter)
54  EVT_SCROLL(CPreviewSetupDlg::OnScroll)
55  EVT_RADIOBOX(eMultiPageID, CPreviewSetupDlg::OnMultiPage)
56  EVT_RADIOBOX(eGuidesID, CPreviewSetupDlg::OnGuides)
58 
60  bool add_preview_button,
61  wxWindow *parent)
62  : wxPageSetupDialogBase( parent,
63  wxID_ANY,
64  wxT("Page Setup"),
65  wxPoint(0,0),
66  wxSize(600, 600),
67  wxDEFAULT_DIALOG_STYLE|wxTAB_TRAVERSAL )
68  , m_PreviewButton(add_preview_button)
69 {
70 }
71 
72 
74 {
75 }
76 
77 
79 {
80  return true;
81 }
82 
84 {
85  return true;
86 }
87 
88 void CPreviewSetupDlg::SetZoomBehavior(bool zoomx, bool zoomy)
89 {
91 }
92 
94 {
96 }
97 
99 {
100  return m_PreviewSetupWidget->GetZoomY();
101 }
102 
104 {
106 }
107 
108 void CPreviewSetupDlg::OnScroll(wxScrollEvent& event)
109 {
110  if (event.GetEventObject() == m_PageCountSlider) {
111  int pos = m_PageCountSlider->GetValue();
112 
113  m_PageCount->SetLabel(wxString(NStr::IntToString(pos).c_str(), wxConvUTF8));
114  m_PageCount->Refresh();
115 
117  m_PreviewSetupWidget->Refresh();
118  }
119 }
120 
121 // Do we need this - or is the slider alone sufficient? (slider at 0 => no
122 // multi-page).
123 void CPreviewSetupDlg::OnMultiPage( wxCommandEvent& event )
124 {
125  if (m_MultiPageRadioBox->GetSelection() == 0) {
126  //disable sizing
127  //m_PageCountSlider->SetValue(1);
128  m_PageCountSlider->Disable();
129  m_PageCountSlider->Refresh();
130  //m_PageCount->SetLabel(NStr::IntToString(1));
131  m_PageCount->Disable();
132  m_PageCount->Refresh();
133 
135  m_PreviewSetupWidget->Refresh();
136  }
137  else {
138  // enable sizing
139  m_PageCountSlider->Enable();
140  m_PageCountSlider->Refresh();
141  m_PageCount->Enable();
142  m_PageCount->Refresh();
143  //m_PageCountSlider->Enable();
144  //m_PreviewSetupWidget->ShowBars();
146  m_PreviewSetupWidget->Refresh();
147  }
148 
149  UpdateMargins();
150 
151 }
152 
153 void CPreviewSetupDlg::OnGuides( wxCommandEvent& event )
154 {
155 }
156 
157 
158 void CPreviewSetupDlg::OnPrinter(wxCommandEvent& WXUNUSED(event))
159 {
160  // We no longer query GetPrintMode, so we can eliminate the need
161  // to call SetPrintMode.
162  // This has the limitation that we can't explicitly call the PostScript
163  // print setup dialog from the generic Page Setup dialog under Windows,
164  // but since this choice would only happen when trying to do PostScript
165  // printing under Windows (and only in 16-bit Windows which
166  // doesn't have a Windows-specific page setup dialog) it's worth it.
167 
168  // First save the current settings, so the wxPrintData object is up to date.
170 }
171 
172 
174 {
175  wxBoxSizer *mainsizer = new wxBoxSizer( wxVERTICAL );
176 
177  // 1. Image (top)
178  ///////////////////////////////////////////////////////////////////////////
179  int widget_width = 520;
180 
181  float size_ratio = ((float)img->GetHeight())/(float)img->GetWidth();
182 
183  int setup_widget_width = widget_width;
184  if (size_ratio > 1.4f) {
185  setup_widget_width = (int) ((((float)widget_width)*1.4f)/size_ratio);
186  }
187 
188  // Add image widget to dialog. Add spacers on the sides of the image
189  // in case the image is taller than wide.
190  wxBoxSizer *setup_widget_sizer = new wxBoxSizer( wxHORIZONTAL );
191  if (setup_widget_width < widget_width)
192  setup_widget_sizer->Add((widget_width-setup_widget_width)/2,
193  1, 0, wxEXPAND);
194 
195  int widget_height = (int) (((float)setup_widget_width)*size_ratio);
197  this,
199  wxDefaultPosition,
200  wxSize(setup_widget_width,
201  widget_height) );
202  m_PreviewSetupWidget->SetName(wxT("PreviewSetupWidget"));
203  setup_widget_sizer->Add(m_PreviewSetupWidget, 0, wxALL|wxEXPAND, 5);
204 
205  if (setup_widget_width < widget_width)
206  setup_widget_sizer->Add((widget_width-setup_widget_width)/2, 1, 0, wxEXPAND);
207  mainsizer->Add(setup_widget_sizer, 1, wxALL|wxEXPAND, 5);
208 
209  // 2. Slider for paper page count
210  ///////////////////////////////////////////////////////////////////////////
211  wxStaticBoxSizer *page_count_box = new wxStaticBoxSizer(
212  new wxStaticBox(this, ePrintIDStatic, wxT("")),
213  wxHORIZONTAL );
214 
215  wxString *choices4 = new wxString[2];
216  choices4[0] = wxT("Hide");
217  choices4[1] = wxT("Display");
218  m_GuidesRadioBox = new wxRadioBox(this, eGuidesID, wxT("Printing Guides"),
219  wxDefaultPosition, wxDefaultSize, 2, choices4, 2);
220  m_GuidesRadioBox->SetSelection(0);
221  page_count_box->Add(m_GuidesRadioBox, 0, wxALL | wxEXPAND, 5 );
222  delete [] choices4;
223 
224  page_count_box->Add( new wxStaticText(this, ePrintIDStatic, wxT("Partitions:")),0,wxALL|wxALIGN_LEFT|wxALIGN_CENTER,5 );
225 
226  m_PageCountSlider = new wxSlider(this,
228  1,
229  1,
230  150,
231  wxDefaultPosition,
232  wxSize(160, wxDefaultCoord),
233  wxHORIZONTAL|wxSL_AUTOTICKS);
234  page_count_box->Add(m_PageCountSlider, 1, wxALL|wxALIGN_CENTER, 5);
235 
236  m_PageCount = new wxStaticText(this,
237  ePageCountID,
238  wxT("1"),
239  wxDefaultPosition,
240  wxSize(15, wxDefaultCoord));
241  page_count_box->Add(m_PageCount, 0, wxALL|wxALIGN_CENTER, 5);
242 
243  mainsizer->Add(page_count_box, 0, wxLEFT|wxRIGHT|wxBOTTOM|wxALIGN_CENTER, 5);
244 
245  // 4. Subclass widgets
246  ///////////////////////////////////////////////////////////////////////////
247  x_Init(mainsizer, widget_width);
248 
249 #if wxUSE_STATLINE
250  // 5. static line
251  ///////////////////////////////////////////////////////////////////////////
252  mainsizer->Add( new wxStaticLine( this,
253  wxID_ANY,
254  wxDefaultPosition,
255  wxSize(widget_width, wxDefaultCoord) ),
256  0, wxEXPAND | wxLEFT|wxRIGHT|wxTOP, 10 );
257 #endif
258 
259  // 6. buttons
260  ///////////////////////////////////////////////////////////////////////////
261  wxSizer* buttonsizer = CreateButtonSizer( wxOK|wxCANCEL);
262 
263  if (m_PreviewButton) {
264  wxButton* m_PreviewButton = new wxButton(this, ePreviewID, wxT("Preview") );
265  buttonsizer->Add( m_PreviewButton, 0, wxLEFT|wxRIGHT|wxALIGN_CENTER, 10 );
266  }
267 
268  if (wxPrintFactory::GetFactory()->HasPrintSetupDialog())
269  {
270  m_PrinterButton = new wxButton(this, ePrintIDSetup, wxT("Printer...") );
271  buttonsizer->Add( m_PrinterButton, 0, wxLEFT|wxRIGHT|wxALIGN_CENTER, 10 );
272  }
273  else
274  {
276  }
277 
278  // if (m_PrintData.GetEnableHelp())
279  // wxButton *helpButton = new wxButton(this, (wxFunction)wxGenericPageSetupHelpProc, wxT("Help"), wxDefaultCoord, wxDefaultCoord, buttonWidth, buttonHeight);
280  mainsizer->Add( buttonsizer, 0, wxEXPAND|wxALL, 10 );
281 
282  SetAutoLayout( true );
283  SetSizer( mainsizer );
284 
285  mainsizer->Fit( this );
286  Centre(wxBOTH);
287 
288  InitDialog();
289 }
290 
292 {
293  if (m_PreviewSetupWidget != NULL)
295  else return CVect2<int>(0,0);
296 }
297 
298 
void SetZoomBehavior(bool zoomx, bool zoomy)
Enable/disable zoom in x && y.
CVect2< int > GetPartitions() const
Return the number of partitions of the image in x and y.
void SetPartitions(int p)
Set the number of partitions for display on the widget.
CImage –.
Definition: Image.hpp:66
size_t GetWidth(void) const
Definition: image.hpp:98
size_t GetHeight(void) const
Definition: image.hpp:99
void x_InitDialog(CRef< CImage > img)
Layout all controls owned by this class.
virtual void UpdateMargins()
virtual void OnScroll(wxScrollEvent &event)
virtual bool TransferDataFromWindow()
wxRadioBox * m_MultiPageRadioBox
virtual void OnPrinter(wxCommandEvent &event)
CVect2< int > GetPartitions() const
Get the number of image partitions in x and y.
wxStaticText * m_PageCount
wxSlider * m_PageCountSlider
void SetZoomBehavior(bool zoomx, bool zoomy)
Enable/disable zoom in x && y.
virtual void OnGuides(wxCommandEvent &event)
virtual void OnMultiPage(wxCommandEvent &event)
CGlPreviewSetupWidget * m_PreviewSetupWidget
virtual void x_Init(wxBoxSizer *, int)
Provide virtual hook for subclasses to add their own controls below the main controls.
wxRadioBox * m_GuidesRadioBox
virtual bool TransferDataToWindow()
CRef –.
Definition: ncbiobj.hpp:618
IMPLEMENT_CLASS(CFloatingFrame, CFloatingFrameBaseClass) const static long kFloatFrameStyle
CFloatingFrame.
#define NULL
Definition: ncbistd.hpp:225
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
static string IntToString(int value, TNumToStringFlags flags=0, int base=10)
Convert int to string.
Definition: ncbistr.hpp:5084
unsigned int
A callback function used to compare two keys in a database.
Definition: types.hpp:1210
END_EVENT_TABLE()
#define wxT(x)
Definition: muParser.cpp:41
WXDLLEXPORT_DATA(wxPrintPaperDatabase *) wxThePrintPaperDatabase
static static static wxID_ANY
Modified on Wed Jun 19 16:59:36 2024 by modify_doxy.py rev. 669887