Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(67)

Side by Side Diff: chrome/browser/printing/print_dialog_gtk.cc

Issue 9379039: GTK: implement "print selection". (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/printing/print_dialog_gtk.h ('k') | printing/print_dialog_gtk_interface.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/printing/print_dialog_gtk.h" 5 #include "chrome/browser/printing/print_dialog_gtk.h"
6 6
7 #include <fcntl.h> 7 #include <fcntl.h>
8 #include <gtk/gtkunixprint.h> 8 #include <gtk/gtkunixprint.h>
9 #include <sys/stat.h> 9 #include <sys/stat.h>
10 #include <sys/types.h> 10 #include <sys/types.h>
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 gtk_print_settings_set_orientation( 224 gtk_print_settings_set_orientation(
225 gtk_settings_, 225 gtk_settings_,
226 landscape ? GTK_PAGE_ORIENTATION_LANDSCAPE : 226 landscape ? GTK_PAGE_ORIENTATION_LANDSCAPE :
227 GTK_PAGE_ORIENTATION_PORTRAIT); 227 GTK_PAGE_ORIENTATION_PORTRAIT);
228 228
229 InitPrintSettings(ranges, settings); 229 InitPrintSettings(ranges, settings);
230 return true; 230 return true;
231 } 231 }
232 232
233 void PrintDialogGtk::ShowDialog( 233 void PrintDialogGtk::ShowDialog(
234 bool has_selection,
234 const PrintingContextGtk::PrintSettingsCallback& callback) { 235 const PrintingContextGtk::PrintSettingsCallback& callback) {
235 callback_ = callback; 236 callback_ = callback;
236 237
237 GtkWindow* parent = BrowserList::GetLastActive()->window()->GetNativeHandle(); 238 GtkWindow* parent = BrowserList::GetLastActive()->window()->GetNativeHandle();
238 // TODO(estade): We need a window title here. 239 // TODO(estade): We need a window title here.
239 dialog_ = gtk_print_unix_dialog_new(NULL, parent); 240 dialog_ = gtk_print_unix_dialog_new(NULL, parent);
240 g_signal_connect(dialog_, "delete-event", 241 g_signal_connect(dialog_, "delete-event",
241 G_CALLBACK(gtk_widget_hide_on_delete), NULL); 242 G_CALLBACK(gtk_widget_hide_on_delete), NULL);
242 243
243 244
244 // Set modal so user cannot focus the same tab and press print again. 245 // Set modal so user cannot focus the same tab and press print again.
245 gtk_window_set_modal(GTK_WINDOW(dialog_), TRUE); 246 gtk_window_set_modal(GTK_WINDOW(dialog_), TRUE);
246 247
247 // Since we only generate PDF, only show printers that support PDF. 248 // Since we only generate PDF, only show printers that support PDF.
248 // TODO(thestig) Add more capabilities to support? 249 // TODO(thestig) Add more capabilities to support?
249 GtkPrintCapabilities cap = static_cast<GtkPrintCapabilities>( 250 GtkPrintCapabilities cap = static_cast<GtkPrintCapabilities>(
250 GTK_PRINT_CAPABILITY_GENERATE_PDF | 251 GTK_PRINT_CAPABILITY_GENERATE_PDF |
251 GTK_PRINT_CAPABILITY_PAGE_SET | 252 GTK_PRINT_CAPABILITY_PAGE_SET |
252 GTK_PRINT_CAPABILITY_COPIES | 253 GTK_PRINT_CAPABILITY_COPIES |
253 GTK_PRINT_CAPABILITY_COLLATE | 254 GTK_PRINT_CAPABILITY_COLLATE |
254 GTK_PRINT_CAPABILITY_REVERSE); 255 GTK_PRINT_CAPABILITY_REVERSE);
255 gtk_print_unix_dialog_set_manual_capabilities(GTK_PRINT_UNIX_DIALOG(dialog_), 256 gtk_print_unix_dialog_set_manual_capabilities(GTK_PRINT_UNIX_DIALOG(dialog_),
256 cap); 257 cap);
257 gtk_print_unix_dialog_set_embed_page_setup(GTK_PRINT_UNIX_DIALOG(dialog_), 258 gtk_print_unix_dialog_set_embed_page_setup(GTK_PRINT_UNIX_DIALOG(dialog_),
258 TRUE); 259 TRUE);
260 gtk_print_unix_dialog_set_support_selection(GTK_PRINT_UNIX_DIALOG(dialog_),
261 TRUE);
262 gtk_print_unix_dialog_set_has_selection(GTK_PRINT_UNIX_DIALOG(dialog_),
263 has_selection);
259 g_signal_connect(dialog_, "response", G_CALLBACK(OnResponseThunk), this); 264 g_signal_connect(dialog_, "response", G_CALLBACK(OnResponseThunk), this);
260 gtk_widget_show(dialog_); 265 gtk_widget_show(dialog_);
261 } 266 }
262 267
263 void PrintDialogGtk::PrintDocument(const printing::Metafile* metafile, 268 void PrintDialogGtk::PrintDocument(const printing::Metafile* metafile,
264 const string16& document_name) { 269 const string16& document_name) {
265 // This runs on the print worker thread, does not block the UI thread. 270 // This runs on the print worker thread, does not block the UI thread.
266 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::UI)); 271 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::UI));
267 272
268 // The document printing tasks can outlive the PrintingContext that created 273 // The document printing tasks can outlive the PrintingContext that created
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 324
320 if (page_setup_) 325 if (page_setup_)
321 g_object_unref(page_setup_); 326 g_object_unref(page_setup_);
322 page_setup_ = gtk_print_unix_dialog_get_page_setup( 327 page_setup_ = gtk_print_unix_dialog_get_page_setup(
323 GTK_PRINT_UNIX_DIALOG(dialog_)); 328 GTK_PRINT_UNIX_DIALOG(dialog_));
324 g_object_ref(page_setup_); 329 g_object_ref(page_setup_);
325 330
326 // Handle page ranges. 331 // Handle page ranges.
327 PageRanges ranges_vector; 332 PageRanges ranges_vector;
328 gint num_ranges; 333 gint num_ranges;
329 GtkPageRange* gtk_range = 334 bool print_selection_only = false;
330 gtk_print_settings_get_page_ranges(gtk_settings_, &num_ranges); 335 switch (gtk_print_settings_get_print_pages(gtk_settings_)) {
331 if (gtk_range) { 336 case GTK_PRINT_PAGES_RANGES: {
332 for (int i = 0; i < num_ranges; ++i) { 337 GtkPageRange* gtk_range =
333 printing::PageRange range; 338 gtk_print_settings_get_page_ranges(gtk_settings_, &num_ranges);
334 range.from = gtk_range[i].start; 339 if (gtk_range) {
335 range.to = gtk_range[i].end; 340 for (int i = 0; i < num_ranges; ++i) {
336 ranges_vector.push_back(range); 341 printing::PageRange range;
342 range.from = gtk_range[i].start;
343 range.to = gtk_range[i].end;
344 ranges_vector.push_back(range);
345 }
346 g_free(gtk_range);
347 }
348 break;
337 } 349 }
338 g_free(gtk_range); 350 case GTK_PRINT_PAGES_SELECTION:
351 print_selection_only = true;
352 break;
353 default:
Lei Zhang 2012/02/13 22:41:17 Would you mind changing this to: case GTK_PRINT_P
peter1 2012/02/14 01:52:54 Done.
354 break;
339 } 355 }
340 356
341 PrintSettings settings; 357 PrintSettings settings;
342 printing::PrintSettingsInitializerGtk::InitPrintSettings( 358 printing::PrintSettingsInitializerGtk::InitPrintSettings(
343 gtk_settings_, page_setup_, ranges_vector, false, &settings); 359 gtk_settings_, page_setup_, ranges_vector, print_selection_only,
360 &settings);
344 context_->InitWithSettings(settings); 361 context_->InitWithSettings(settings);
345 callback_.Run(PrintingContextGtk::OK); 362 callback_.Run(PrintingContextGtk::OK);
346 callback_.Reset(); 363 callback_.Reset();
347 return; 364 return;
348 } 365 }
349 case GTK_RESPONSE_DELETE_EVENT: // Fall through. 366 case GTK_RESPONSE_DELETE_EVENT: // Fall through.
350 case GTK_RESPONSE_CANCEL: { 367 case GTK_RESPONSE_CANCEL: {
351 callback_.Run(PrintingContextGtk::CANCEL); 368 callback_.Run(PrintingContextGtk::CANCEL);
352 callback_.Reset(); 369 callback_.Reset();
353 return; 370 return;
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
397 // Printing finished. Matches AddRef() in PrintDocument(); 414 // Printing finished. Matches AddRef() in PrintDocument();
398 Release(); 415 Release();
399 } 416 }
400 417
401 void PrintDialogGtk::InitPrintSettings(const PageRanges& page_ranges, 418 void PrintDialogGtk::InitPrintSettings(const PageRanges& page_ranges,
402 PrintSettings* settings) { 419 PrintSettings* settings) {
403 printing::PrintSettingsInitializerGtk::InitPrintSettings( 420 printing::PrintSettingsInitializerGtk::InitPrintSettings(
404 gtk_settings_, page_setup_, page_ranges, false, settings); 421 gtk_settings_, page_setup_, page_ranges, false, settings);
405 context_->InitWithSettings(*settings); 422 context_->InitWithSettings(*settings);
406 } 423 }
OLDNEW
« no previous file with comments | « chrome/browser/printing/print_dialog_gtk.h ('k') | printing/print_dialog_gtk_interface.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698