1 /*
2    SANE EPSON backend
3    Copyright (C) 2001, 2005, 2008  SEIKO EPSON Corporation
4 
5    Date         Author      Reason
6    06/01/2001   N.Sasaki    New
7 
8    This file is part of the `iscan' program.
9 
10    This program is free software; you can redistribute it and/or modify
11    it under the terms of the GNU General Public License as published by
12    the Free Software Foundation; either version 2 of the License, or
13    (at your option) any later version.
14 
15    This program is distributed in the hope that it will be useful,
16    but WITHOUT ANY WARRANTY; without even the implied warranty of
17    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18    GNU General Public License for more details.
19 
20    You should have received a copy of the GNU General Public License
21    along with this program; if not, write to the Free Software
22    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 
24    As a special exception, the copyright holders give permission
25    to link the code of this program with the esmod library and
26    distribute linked combinations including the two.  You must obey
27    the GNU General Public License in all respects for all of the
28    code used other then esmod.
29 */
30 
31 #ifndef ___PISA_PREVIEW_WINDOW_H
32 #define ___PISA_PREVIEW_WINDOW_H
33 
34 #include <gtk/gtk.h>
35 #include "pisa_enums.h"
36 #include "pisa_structs.h"
37 
38 class preview_window
39 {
40  public:
41 
preview_window()42   preview_window ( ) { m_gc = NULL; }
43 
44   // operation
45   int	init ( void );
46   GtkWidget *	create_window ( GtkWidget * parent );
47   int	close_window ( int destroy );
48 
is_prev_img(void)49   int	is_prev_img ( void ) { return m_is_prev; }
50 
51   int	resize_window ( void );
52 
53   int	auto_exposure ( void );
54 
55   int	update_img ( bool left = false );
56 
57   void	start_preview ( pisa_preview_type type );
58 
59   gint	expose_event ( GtkWidget * widget, GdkEventExpose * event );
60   gint	event ( GtkWidget * widget, GdkEvent * event );
61 
62   void	size_allocate ( GtkWidget * widget );
63 
64  private:
65 
66   // operation
67   GtkWidget	* create_darea ( GtkWidget * parent );
68 
69   long	get_preview_resolution ( const _rectD * img_rect = 0 );
70   void	resize_preview_window ( long width, long height );
71   void  change_max_scan_area ( long width, long height );
72   void	change_max_disp_area ( long width, long height );
73   void	clear_image ( void );
74 
75   void modify_max_val ( void );
76 
77   void draw_marquee ( void );
78 
79   // preview, zoom
80   void reset_settings ( pisa_preview_type type );
81   int set_preview_param (pisa_preview_type type);
82   void tool_usm (const pisa_image_info& info);
83   void zoom_boundary (_pointD& pt_offset, _pointD& pt_area,
84 		      const _pointD& pt_max, float rate) const;
85 
86   // cursor
87   void create_cursor ( void );
88   int set_mouse_cursor ( int x, int y );
89   int search_cursor_state ( const _pointL & pt_lt,
90 			    const _pointL & pt_rb,
91 			    const _pointL & pt );
92   void change_cursor ( void );
93 
94   // marquee
95   gint mouse_down ( GdkEvent * event );
96   gint mouse_move ( GdkEvent * event );
97   gint mouse_up   ( GdkEvent * event );
98 
99   int create_marquee ( const _pointL & pt_lt, const _pointL & pt_rb );
100   int delete_marquee ( void );
101 
102   void move_marquee ( const _pointL & pt_lt, const _pointL & pt_rb );
103   void resize_marquee ( const _pointL & pt_lt, const _pointL & pt_rb );
104 
105   void begin_mouse_move ( _pointL * pt_lt, _pointL * pt_rb );
106   void move_rect ( _pointL * pt_lt, _pointL * pt_rb, const _pointL & pt_move );
107 
108   _pointD clientpix2inches ( _pointL & pt );
109   _pointL inches2clientpix ( _pointD & pt );
110   int get_marquee_point ( long i, _pointL * pt_lt, _pointL * pt_rb );
111 
112   int check_min_size ( const _pointL & pt_lt, const _pointL & pt_rb );
113   void check_max_size ( _pointD * pt_offset, _pointD * pt_area,
114 			int offset );
115   void check_ltrb ( _pointL * pt_lt, _pointL * pt_rb );
116 
117   void draw_rect ( const _pointL & pt_lt, const _pointL & pt_rb );
118 
119   // attribute
120   GtkWidget		* m_win;
121   GtkWidget		* m_prev;
122 
123   long			m_is_prev;
124   long			m_img_width, m_img_height;
125   unsigned char		* m_img;
126   unsigned char		* m_img_org;
127 
128   GdkGC			* m_gc;
129 
130   int			m_cursor_state;
131   GdkCursor		* m_cursor [ 11 ];
132 
133   bool			m_on_preview;
134   long			m_allocate_width;
135   long			m_allocate_height;
136 
137   // for marquee
138   int			m_drag;
139   _rectL		m_client_rect;
140   _rectD		m_max_img_rect;
141   _rectD		m_img_rect;
142 
143   _pointL		m_pt_max_lt;
144   _pointL		m_pt_max_rb;
145 
146   _pointL		m_pt_begin;
147   _pointL		m_pt_old;
148   _pointL		m_pt_old_lt;
149   _pointL		m_pt_old_rb;
150   _pointD		m_pt_save_offset;
151   _pointD		m_pt_save_area;
152 
153 };
154 
155 #endif // ___PISA_PREVIEW_WINDOW_H
156