/
rtwindow.cc
executable file
·1245 lines (1030 loc) · 41.3 KB
/
rtwindow.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* This file is part of RawTherapee.
*
* Copyright (c) 2004-2010 Gabor Horvath <hgabor@rawtherapee.com>, Oliver Duis <www.oliverduis.de>
*
* RawTherapee is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* RawTherapee is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with RawTherapee. If not, see <https://www.gnu.org/licenses/>.
*/
#include <gtkmm.h>
#include "rtwindow.h"
#include "cachemanager.h"
#include "preferences.h"
#include "iccprofilecreator.h"
#include "cursormanager.h"
#include "editwindow.h"
#include "rtimage.h"
#include "thumbnail.h"
#include "whitebalance.h"
#include "../rtengine/settings.h"
#include "batchqueuepanel.h"
#include "batchqueueentry.h"
#include "editorpanel.h"
#include "filepanel.h"
#include "filmsimulation.h"
Glib::RefPtr<Gtk::CssProvider> cssForced;
Glib::RefPtr<Gtk::CssProvider> cssRT;
#if defined(__APPLE__)
static gboolean
osx_should_quit_cb (GtkosxApplication *app, gpointer data)
{
RTWindow * const rtWin = static_cast<RTWindow*>(data);
return rtWin->on_delete_event (0);
}
static void
osx_will_quit_cb (GtkosxApplication *app, gpointer data)
{
RTWindow *rtWin = static_cast<RTWindow*>(data);
rtWin->on_delete_event (0);
gtk_main_quit ();
}
bool RTWindow::osxFileOpenEvent (Glib::ustring path)
{
CacheManager* cm = CacheManager::getInstance();
Thumbnail* thm = cm->getEntry ( path );
if (thm && fpanel) {
std::vector<Thumbnail*> entries;
entries.push_back (thm);
fpanel->fileCatalog->openRequested (entries);
return true;
}
return false;
}
static gboolean
osx_open_file_cb (GtkosxApplication *app, gchar *path_, gpointer data)
{
RTWindow *rtWin = static_cast<RTWindow*>(data);
if (!argv1.empty()) {
// skip handling if we have a file argument or else we get double open of same file
return false;
}
Glib::ustring path = Glib::ustring (path_);
Glib::ustring suffix = path.length() > 4 ? path.substr (path.length() - 3) : "";
suffix = suffix.lowercase();
if (suffix == "pp3") {
path = path.substr (0, path.length() - 4);
}
return rtWin->osxFileOpenEvent (path);
}
#endif // __APPLE__
RTWindow::RTWindow ()
: mainNB (nullptr)
, bpanel (nullptr)
, splash (nullptr)
, btn_fullscreen (nullptr)
, iFullscreen (nullptr)
, iFullscreen_exit (nullptr)
, epanel (nullptr)
, fpanel (nullptr)
{
cacheMgr->init ();
ProfilePanel::init (this);
// ------- loading theme files
Glib::RefPtr<Gdk::Screen> screen = Gdk::Screen::get_default();
if (screen) {
// Setting default theme and icon theme (bases for custom themes)
Gtk::Settings::get_for_screen (screen)->property_gtk_theme_name() = "Adwaita";
Gtk::Settings::get_for_screen (screen)->property_gtk_application_prefer_dark_theme() = true;
Gtk::Settings::get_for_screen (screen)->property_gtk_icon_theme_name() = "rawtherapee";
// Initialize RTScalable for Hi-DPI support
RTScalable::init(this);
// Look for theme and set it
// Check if the current theme name in options exists, otherwise set it to default one (i.e. "RawTherapee.css")
auto filename = Glib::build_filename(argv0, "themes", options.theme + ".css");
if (!Glib::file_test(filename, Glib::FILE_TEST_EXISTS)) {
options.theme = "RawTherapee";
filename = Glib::build_filename(argv0, "themes", options.theme + ".css");
}
cssRT = Gtk::CssProvider::create();
try {
cssRT->load_from_path (filename);
Gtk::StyleContext::add_provider_for_screen (screen, cssRT, GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
} catch (Glib::Error &err) {
printf ("Error: Can't load css file \"%s\"\nMessage: %s\n", filename.c_str(), err.what().c_str());
} catch (...) {
printf ("Error: Can't load css file \"%s\"\n", filename.c_str());
}
// Set the font face and size
Glib::ustring css;
if (options.fontFamily != "default") { // Set font and size according to user choice
// Set font and size in css from options
css = Glib::ustring::compose ("* { font-family: %1; font-size: %2pt}",
options.fontFamily,
options.fontSize); // Font size is in "pt" in options
} else { // Set font and size according to default values
// Retrieve default style values from Gtk::Settings
const auto defaultSettings = Gtk::Settings::get_default();
Glib::ustring defaultFont;
defaultSettings->get_property("gtk-font-name", defaultFont);
const Pango::FontDescription defaultFontDesc = Pango::FontDescription(defaultFont);
// Set font and size in css
auto defaultFontFamily = defaultFontDesc.get_family();
const int defaultFontSize = defaultFontDesc.get_size() / Pango::SCALE; // Font size is managed in ()"pt" * Pango::SCALE) by Pango (also refer to notes in rtscalable.h)
#if defined(__APPLE__)
// Default MacOS font (i.e. "") is not correctly handled
// in Gtk css. Replacing it by "-apple-system" to avoid this
if (defaultFontFamily == ".AppleSystemUIFont") {
defaultFontFamily = "-apple-system";
}
#endif
css = Glib::ustring::compose ("* { font-family: %1; font-size: %2pt}",
defaultFontFamily,
defaultFontSize);
}
// Load custom CSS for font
if (!css.empty()) {
if (rtengine::settings->verbose) {
printf("CSS:\n%s\n\n", css.c_str());
}
try {
cssForced = Gtk::CssProvider::create();
cssForced->load_from_data (css);
Gtk::StyleContext::add_provider_for_screen (screen, cssForced, GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
} catch (Glib::Error &err) {
printf ("Error: \"%s\"\n", err.what().c_str());
} catch (...) {
printf ("Error: Can't load the desired font correctly\n");
}
}
}
// ------- end loading theme files
// Initialize FileBrowserEntry icons
FileBrowserEntry::init();
// For UNIX system, set app icon
#ifndef _WIN32
try {
set_default_icon_name("rawtherapee");
} catch (Glib::Exception& ex) {
printf ("%s\n", ex.what().c_str());
}
#endif
#if defined(__APPLE__)
{
osxApp = (GtkosxApplication *)g_object_new (GTKOSX_TYPE_APPLICATION, NULL);
RTWindow *rtWin = this;
g_signal_connect (osxApp, "NSApplicationBlockTermination", G_CALLBACK (osx_should_quit_cb), rtWin);
g_signal_connect (osxApp, "NSApplicationWillTerminate", G_CALLBACK (osx_will_quit_cb), rtWin);
g_signal_connect (osxApp, "NSApplicationOpenFile", G_CALLBACK (osx_open_file_cb), rtWin);
// RT don't have a menu, but we must create a dummy one to get the default OS X app menu working
GtkWidget *menubar;
menubar = gtk_menu_bar_new ();
gtkosx_application_set_menu_bar (osxApp, GTK_MENU_SHELL (menubar));
gtkosx_application_set_use_quartz_accelerators (osxApp, FALSE);
gtkosx_application_ready (osxApp);
}
#endif
versionStr = "RawTherapee " + versionString;
set_title_decorated ("");
set_resizable (true);
set_decorated (true);
set_default_size (options.windowWidth, options.windowHeight);
set_modal (false);
on_delete_has_run = false;
is_fullscreen = false;
is_minimized = false;
property_destroy_with_parent().set_value (false);
signal_window_state_event().connect ( sigc::mem_fun (*this, &RTWindow::on_window_state_event) );
onConfEventConn = signal_configure_event().connect ( sigc::mem_fun (*this, &RTWindow::on_configure_event) );
signal_key_press_event().connect ( sigc::mem_fun (*this, &RTWindow::keyPressed) );
signal_key_release_event().connect(sigc::mem_fun(*this, &RTWindow::keyReleased));
if (simpleEditor) {
epanel = Gtk::manage ( new EditorPanel (nullptr) );
epanel->setParent (this);
epanel->setParentWindow (this);
add (*epanel);
show_all ();
pldBridge = nullptr; // No progress listener
CacheManager* cm = CacheManager::getInstance();
Thumbnail* thm = cm->getEntry ( argv1 );
if (thm) {
int error;
rtengine::InitialImage *ii = rtengine::InitialImage::load (argv1, thm->getType() == FT_Raw, &error, nullptr);
epanel->open ( thm, ii );
}
} else {
mainNB = Gtk::manage (new Gtk::Notebook ());
mainNB->set_name ("MainNotebook");
mainNB->set_scrollable (true);
mainNB->signal_switch_page().connect_notify ( sigc::mem_fun (*this, &RTWindow::on_mainNB_switch_page) );
// Editor panel
fpanel = new FilePanel () ;
fpanel->setParent (this);
// decorate tab
Gtk::Grid* fpanelLabelGrid = Gtk::manage (new Gtk::Grid ());
setExpandAlignProperties (fpanelLabelGrid, false, false, Gtk::ALIGN_CENTER, Gtk::ALIGN_CENTER);
Gtk::Label* fpl = Gtk::manage (new Gtk::Label ( Glib::ustring (" ") + M ("MAIN_FRAME_EDITOR") ));
if (options.mainNBVertical) {
mainNB->set_tab_pos (Gtk::POS_LEFT);
fpl->set_angle (90);
RTImage* folderIcon = Gtk::manage (new RTImage ("folder-closed", Gtk::ICON_SIZE_LARGE_TOOLBAR));
fpanelLabelGrid->attach_next_to (*folderIcon, Gtk::POS_TOP, 1, 1);
fpanelLabelGrid->attach_next_to (*fpl, Gtk::POS_TOP, 1, 1);
} else {
RTImage* folderIcon = Gtk::manage (new RTImage ("folder-closed", Gtk::ICON_SIZE_LARGE_TOOLBAR));
fpanelLabelGrid->attach_next_to (*folderIcon, Gtk::POS_RIGHT, 1, 1);
fpanelLabelGrid->attach_next_to (*fpl, Gtk::POS_RIGHT, 1, 1);
}
fpanelLabelGrid->set_tooltip_markup (M ("MAIN_FRAME_FILEBROWSER_TOOLTIP"));
fpanelLabelGrid->show_all ();
mainNB->append_page (*fpanel, *fpanelLabelGrid);
// Batch Queue panel
bpanel = Gtk::manage ( new BatchQueuePanel (fpanel->fileCatalog) );
// decorate tab, the label is unimportant since its updated in batchqueuepanel anyway
Gtk::Label* lbq = Gtk::manage ( new Gtk::Label (M ("MAIN_FRAME_QUEUE")) );
if (options.mainNBVertical) {
lbq->set_angle (90);
}
mainNB->append_page (*bpanel, *lbq);
if (isSingleTabMode()) {
createSetmEditor();
}
mainNB->set_current_page (mainNB->page_num (*fpanel));
//Gtk::Box* mainBox = Gtk::manage (new Gtk::Box(Gtk::ORIENTATION_VERTICAL));
//mainBox->pack_start (*mainNB);
// filling bottom box
iFullscreen = new RTImage ("fullscreen-enter", Gtk::ICON_SIZE_LARGE_TOOLBAR);
iFullscreen_exit = new RTImage ("fullscreen-leave", Gtk::ICON_SIZE_LARGE_TOOLBAR);
Gtk::Button* iccProfileCreator = Gtk::manage (new Gtk::Button ());
setExpandAlignProperties (iccProfileCreator, false, false, Gtk::ALIGN_CENTER, Gtk::ALIGN_CENTER);
iccProfileCreator->set_relief(Gtk::RELIEF_NONE);
iccProfileCreator->set_image (*Gtk::manage (new RTImage ("gamut-plus", Gtk::ICON_SIZE_LARGE_TOOLBAR)));
iccProfileCreator->set_tooltip_markup (M ("MAIN_BUTTON_ICCPROFCREATOR"));
iccProfileCreator->signal_clicked().connect ( sigc::mem_fun (*this, &RTWindow::showICCProfileCreator) );
Gtk::Button* helpBtn = Gtk::manage (new Gtk::Button ());
setExpandAlignProperties (helpBtn, false, false, Gtk::ALIGN_CENTER, Gtk::ALIGN_CENTER);
helpBtn->set_relief(Gtk::RELIEF_NONE);
helpBtn->set_image (*Gtk::manage (new RTImage("questionmark", Gtk::ICON_SIZE_LARGE_TOOLBAR)));
helpBtn->set_tooltip_markup (M ("GENERAL_HELP"));
helpBtn->signal_clicked().connect (sigc::mem_fun (*this, &RTWindow::showRawPedia));
Gtk::Button* preferences = Gtk::manage (new Gtk::Button ());
setExpandAlignProperties (preferences, false, false, Gtk::ALIGN_CENTER, Gtk::ALIGN_CENTER);
preferences->set_relief(Gtk::RELIEF_NONE);
preferences->set_image (*Gtk::manage (new RTImage ("preferences", Gtk::ICON_SIZE_LARGE_TOOLBAR)));
preferences->set_tooltip_markup (M ("MAIN_BUTTON_PREFERENCES"));
preferences->signal_clicked().connect ( sigc::mem_fun (*this, &RTWindow::showPreferences) );
btn_fullscreen = Gtk::manage ( new Gtk::Button());
setExpandAlignProperties (btn_fullscreen, false, false, Gtk::ALIGN_CENTER, Gtk::ALIGN_CENTER);
btn_fullscreen->set_relief(Gtk::RELIEF_NONE);
btn_fullscreen->set_tooltip_markup (M ("MAIN_BUTTON_FULLSCREEN"));
btn_fullscreen->set_image (*iFullscreen);
btn_fullscreen->signal_clicked().connect ( sigc::mem_fun (*this, &RTWindow::toggle_fullscreen) );
setExpandAlignProperties (&prProgBar, false, false, Gtk::ALIGN_CENTER, Gtk::ALIGN_CENTER);
prProgBar.set_show_text (true);
Gtk::Grid* actionGrid = Gtk::manage (new Gtk::Grid ());
actionGrid->set_row_spacing (2);
actionGrid->set_column_spacing (2);
setExpandAlignProperties (actionGrid, false, false, Gtk::ALIGN_CENTER, Gtk::ALIGN_CENTER);
if (options.mainNBVertical) {
prProgBar.set_orientation (Gtk::ORIENTATION_VERTICAL);
prProgBar.set_inverted (true);
actionGrid->set_orientation (Gtk::ORIENTATION_VERTICAL);
actionGrid->attach_next_to (prProgBar, Gtk::POS_BOTTOM, 1, 1);
actionGrid->attach_next_to (*iccProfileCreator, Gtk::POS_BOTTOM, 1, 1);
actionGrid->attach_next_to (*helpBtn, Gtk::POS_BOTTOM, 1, 1);
actionGrid->attach_next_to (*preferences, Gtk::POS_BOTTOM, 1, 1);
actionGrid->attach_next_to (*btn_fullscreen, Gtk::POS_BOTTOM, 1, 1);
mainNB->set_action_widget (actionGrid, Gtk::PACK_END);
} else {
prProgBar.set_orientation (Gtk::ORIENTATION_HORIZONTAL);
actionGrid->set_orientation (Gtk::ORIENTATION_HORIZONTAL);
actionGrid->attach_next_to (prProgBar, Gtk::POS_RIGHT, 1, 1);
actionGrid->attach_next_to (*iccProfileCreator, Gtk::POS_RIGHT, 1, 1);
actionGrid->attach_next_to (*helpBtn, Gtk::POS_RIGHT, 1, 1);
actionGrid->attach_next_to (*preferences, Gtk::POS_RIGHT, 1, 1);
actionGrid->attach_next_to (*btn_fullscreen, Gtk::POS_RIGHT, 1, 1);
mainNB->set_action_widget (actionGrid, Gtk::PACK_END);
}
actionGrid->show_all();
pldBridge = new PLDBridge (static_cast<rtengine::ProgressListener*> (this));
add (*mainNB);
show_all ();
bpanel->init (this);
if (!argv1.empty() && !remote) {
Thumbnail* thm = cacheMgr->getEntry (argv1);
if (thm) {
fpanel->fileCatalog->openRequested ({thm});
}
}
}
}
RTWindow::~RTWindow()
{
if (!simpleEditor) {
delete pldBridge;
}
pldBridge = nullptr;
#if defined(__APPLE__)
g_object_unref (osxApp);
#endif
delete fpanel;
delete iFullscreen;
delete iFullscreen_exit;
}
void RTWindow::on_realize ()
{
Gtk::Window::on_realize ();
if ( fpanel ) {
fpanel->setAspect();
}
if (simpleEditor) {
epanel->setAspect();
}
mainWindowCursorManager.init (get_window());
// Display release notes only if new major version.
bool waitForSplash = false;
if (options.is_new_version()) {
// Update the version parameter with the right value
options.version = versionString;
splash = new Splash (*this);
splash->set_transient_for (*this);
splash->signal_delete_event().connect ( sigc::mem_fun (*this, &RTWindow::splashClosed) );
if (splash->hasReleaseNotes()) {
waitForSplash = true;
splash->showReleaseNotes();
splash->show ();
} else {
delete splash;
splash = nullptr;
}
}
if (!waitForSplash) {
showErrors();
}
}
void RTWindow::showErrors()
{
// alerting users if the default raw and image profiles are missing
if (options.is_defProfRawMissing()) {
options.defProfRaw = DEFPROFILE_RAW;
Gtk::MessageDialog msgd (*this, Glib::ustring::compose (M ("OPTIONS_DEFRAW_MISSING"), escapeHtmlChars(options.defProfRaw)), true, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK, true);
msgd.run ();
}
if (options.is_bundledDefProfRawMissing()) {
Gtk::MessageDialog msgd (*this, Glib::ustring::compose (M ("OPTIONS_BUNDLED_MISSING"), escapeHtmlChars(options.defProfRaw)), true, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK, true);
msgd.run ();
options.defProfRaw = DEFPROFILE_INTERNAL;
}
if (options.is_defProfImgMissing()) {
options.defProfImg = DEFPROFILE_IMG;
Gtk::MessageDialog msgd (*this, Glib::ustring::compose (M ("OPTIONS_DEFIMG_MISSING"), escapeHtmlChars(options.defProfImg)), true, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK, true);
msgd.run ();
}
if (options.is_bundledDefProfImgMissing()) {
Gtk::MessageDialog msgd (*this, Glib::ustring::compose (M ("OPTIONS_BUNDLED_MISSING"), escapeHtmlChars(options.defProfImg)), true, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK, true);
msgd.run ();
options.defProfImg = DEFPROFILE_INTERNAL;
}
}
bool RTWindow::on_configure_event (GdkEventConfigure* event)
{
if (!options.windowMaximized && !is_fullscreen && !is_minimized) {
get_size (options.windowWidth, options.windowHeight);
get_position (options.windowX, options.windowY);
}
// With update the RTScalable on scale or resolution change
RTScalable::setDPInScale(this);
return Gtk::Widget::on_configure_event (event);
}
bool RTWindow::on_window_state_event (GdkEventWindowState* event)
{
// Retrieve RT window states
options.windowMaximized = event->new_window_state & GDK_WINDOW_STATE_MAXIMIZED;
is_minimized = event->new_window_state & GDK_WINDOW_STATE_ICONIFIED;
is_fullscreen = event->new_window_state & GDK_WINDOW_STATE_FULLSCREEN;
return Gtk::Widget::on_window_state_event (event);
}
void RTWindow::on_mainNB_switch_page (Gtk::Widget* widget, guint page_num)
{
if (!on_delete_has_run) {
if (isEditorPanel (page_num)) {
if (isSingleTabMode() && epanel) {
MoveFileBrowserToEditor();
}
EditorPanel *ep = static_cast<EditorPanel*> (mainNB->get_nth_page (page_num));
ep->setAspect();
if (!isSingleTabMode()) {
if (filesEdited.size() > 0) {
set_title_decorated (ep->getFileName());
}
}
} else {
// in single tab mode with command line filename epanel does not exist yet
if (isSingleTabMode() && epanel) {
// Save profile on leaving the editor panel
epanel->saveProfile();
// Moving the FileBrowser only if the user has switched to the FileBrowser tab
if (mainNB->get_nth_page (page_num) == fpanel) {
MoveFileBrowserToMain();
}
}
}
}
}
void RTWindow::addEditorPanel (EditorPanel* ep, const std::string &name)
{
if (options.multiDisplayMode > 0) {
EditWindow * wndEdit = EditWindow::getInstance (this);
wndEdit->addEditorPanel (ep, name);
wndEdit->show_all();
wndEdit->restoreWindow(); // Need to be called after RTWindow creation to work with all OS Windows Manager
ep->setAspect();
wndEdit->toFront();
} else {
ep->setParent (this);
ep->setParentWindow (this);
ep->setExternalEditorChangedSignal(&externalEditorChangedSignal);
// construct closeable tab for the image
Gtk::Grid* titleGrid = Gtk::manage (new Gtk::Grid ());
titleGrid->set_tooltip_markup (name);
RTImage *closebimg = Gtk::manage (new RTImage ("cancel-small", Gtk::ICON_SIZE_LARGE_TOOLBAR));
Gtk::Button* closeb = Gtk::manage (new Gtk::Button ());
closeb->set_name ("CloseButton");
closeb->add (*closebimg);
closeb->set_relief (Gtk::RELIEF_NONE);
closeb->set_focus_on_click (false);
closeb->signal_clicked().connect ( sigc::bind (sigc::mem_fun (*this, &RTWindow::remEditorPanel), ep));
if (!EditWindow::isMultiDisplayEnabled()) {
titleGrid->attach_next_to (*Gtk::manage (new RTImage ("aperture", Gtk::ICON_SIZE_LARGE_TOOLBAR)), Gtk::POS_RIGHT, 1, 1);
}
titleGrid->attach_next_to (*Gtk::manage (new Gtk::Label (Glib::path_get_basename (name))), Gtk::POS_RIGHT, 1, 1);
titleGrid->attach_next_to (*closeb, Gtk::POS_RIGHT, 1, 1);
titleGrid->show_all ();
//GTK318
#if GTK_MAJOR_VERSION == 3 && GTK_MINOR_VERSION < 20
titleGrid->set_column_spacing (2);
#endif
//GTK318
mainNB->append_page (*ep, *titleGrid);
//ep->setAspect ();
mainNB->set_current_page (mainNB->page_num (*ep));
mainNB->set_tab_reorderable (*ep, true);
set_title_decorated (name);
epanels[ name ] = ep;
filesEdited.insert ( name );
fpanel->refreshEditedState (filesEdited);
ep->tbTopPanel_1_visible (false); //hide the toggle Top Panel button
}
}
void RTWindow::remEditorPanel (EditorPanel* ep)
{
if (ep->getIsProcessing()) {
return; // Will crash if destroyed while loading
}
if (options.multiDisplayMode > 0) {
EditWindow * wndEdit = EditWindow::getInstance (this);
wndEdit->remEditorPanel (ep);
} else {
bool queueHadFocus = (mainNB->get_current_page() == mainNB->page_num (*bpanel));
ep->setExternalEditorChangedSignal(nullptr);
epanels.erase (ep->getFileName());
filesEdited.erase (ep->getFileName ());
fpanel->refreshEditedState (filesEdited);
mainNB->remove_page (*ep);
if (!isEditorPanel (mainNB->get_current_page())) {
if (!queueHadFocus) {
mainNB->set_current_page (mainNB->page_num (*fpanel));
}
set_title_decorated ("");
} else {
const EditorPanel* lep = static_cast<EditorPanel*> (mainNB->get_nth_page (mainNB->get_current_page()));
set_title_decorated (lep->getFileName());
}
// TODO: ask what to do: close & apply, close & apply selection, close & revert, cancel
}
}
bool RTWindow::selectEditorPanel (const std::string &name)
{
if (options.multiDisplayMode > 0) {
EditWindow * wndEdit = EditWindow::getInstance (this);
if (wndEdit->selectEditorPanel (name)) {
set_title_decorated (name);
wndEdit->toFront();
return true;
}
} else {
std::map<Glib::ustring, EditorPanel*>::iterator iep = epanels.find (name);
if (iep != epanels.end()) {
mainNB->set_current_page (mainNB->page_num (*iep->second));
set_title_decorated (name);
return true;
} else {
//set_title_decorated(name);
//printf("RTWindow::selectEditorPanel - plain set\n");
}
}
return false;
}
bool RTWindow::keyPressed (GdkEventKey* event)
{
bool ctrl = event->state & GDK_CONTROL_MASK;
//bool shift = event->state & GDK_SHIFT_MASK;
bool try_quit = false;
#if defined(__APPLE__)
bool apple_cmd = event->state & GDK_MOD2_MASK;
if (event->keyval == GDK_KEY_q && apple_cmd) {
try_quit = true;
}
#else
if (event->keyval == GDK_KEY_q && ctrl) {
try_quit = true;
}
#endif
if (try_quit) {
if (!on_delete_event (nullptr)) {
gtk_main_quit();
}
}
if (event->keyval == GDK_KEY_F11) {
toggle_fullscreen();
}
if (simpleEditor)
// in simpleEditor mode, there's no other tab that can handle pressed keys, so we can send the event to editor panel then return
{
return epanel->handleShortcutKey (event);
};
if (ctrl) {
switch (event->keyval) {
case GDK_KEY_F2: // file browser panel
mainNB->set_current_page (mainNB->page_num (*fpanel));
return true;
case GDK_KEY_F3: // batch queue panel
mainNB->set_current_page (mainNB->page_num (*bpanel));
return true;
case GDK_KEY_F4: //single tab mode, editor panel
if (isSingleTabMode() && epanel) {
mainNB->set_current_page (mainNB->page_num (*epanel));
}
return true;
case GDK_KEY_w: //multi-tab mode, close editor panel
if (!isSingleTabMode() &&
mainNB->get_current_page() != mainNB->page_num (*fpanel) &&
mainNB->get_current_page() != mainNB->page_num (*bpanel)) {
EditorPanel* ep = static_cast<EditorPanel*> (mainNB->get_nth_page (mainNB->get_current_page()));
remEditorPanel (ep);
return true;
}
}
}
if (mainNB->get_current_page() == mainNB->page_num (*fpanel)) {
return fpanel->handleShortcutKey (event);
} else if (mainNB->get_current_page() == mainNB->page_num (*bpanel)) {
return bpanel->handleShortcutKey (event);
} else {
EditorPanel* ep = static_cast<EditorPanel*> (mainNB->get_nth_page (mainNB->get_current_page()));
return ep->handleShortcutKey (event);
}
return false;
}
bool RTWindow::keyReleased(GdkEventKey *event)
{
if (fpanel && mainNB->get_current_page() == mainNB->page_num(*fpanel)) {
return fpanel->handleShortcutKeyRelease(event);
}
return false;
}
void RTWindow::addBatchQueueJob (BatchQueueEntry* bqe, bool head)
{
std::vector<BatchQueueEntry*> entries;
entries.push_back (bqe);
bpanel->addBatchQueueJobs (entries, head);
fpanel->queue_draw ();
}
void RTWindow::addBatchQueueJobs(const std::vector<BatchQueueEntry*>& entries)
{
bpanel->addBatchQueueJobs (entries, false);
fpanel->queue_draw ();
}
bool RTWindow::on_delete_event (GdkEventAny* event)
{
if (on_delete_has_run) {
// on Mac OSX we can get multiple events
return false;
}
// Check if any editor is still processing, and do NOT quit if so. Otherwise crashes and inconsistent caches
bool isProcessing = false;
EditWindow* editWindow = nullptr;
if (isSingleTabMode() || simpleEditor) {
isProcessing = epanel->getIsProcessing();
} else if (options.multiDisplayMode > 0) {
editWindow = EditWindow::getInstance (this);
isProcessing = editWindow->isProcessing();
} else {
int pageCount = mainNB->get_n_pages();
for (int i = 0; i < pageCount && !isProcessing; i++) {
if (isEditorPanel (i)) {
isProcessing |= (static_cast<EditorPanel*> (mainNB->get_nth_page (i)))->getIsProcessing();
}
}
}
if (isProcessing) {
return true;
}
if ( fpanel ) {
fpanel->saveOptions ();
}
if ( bpanel ) {
bpanel->saveOptions ();
}
if ((isSingleTabMode() || simpleEditor) && epanel->isRealized()) {
epanel->saveProfile();
epanel->writeOptions ();
} else {
if (options.multiDisplayMode > 0 && editWindow) {
editWindow->closeOpenEditors();
editWindow->writeOptions();
} else if (epanels.size()) {
// Storing the options of the last EditorPanel before Gtk destroys everything
// Look at the active panel first, if any, otherwise look at the first one (sorted on the filename)
int page = mainNB->get_current_page();
Gtk::Widget *w = mainNB->get_nth_page (page);
bool optionsWritten = false;
for (std::map<Glib::ustring, EditorPanel*>::iterator i = epanels.begin(); i != epanels.end(); ++i) {
if (i->second == w) {
i->second->writeOptions();
optionsWritten = true;
}
}
if (!optionsWritten) {
// fallback solution: save the options of the first editor panel
std::map<Glib::ustring, EditorPanel*>::iterator i = epanels.begin();
i->second->writeOptions();
}
}
}
cacheMgr->closeCache (); // also makes cleanup if too large
ProfilePanel::cleanup();
ClutComboBox::cleanup();
BatchQueueEntry::savedAsIcon.reset();
FileBrowserEntry::editedIcon.reset();
FileBrowserEntry::recentlySavedIcon.reset();
FileBrowserEntry::enqueuedIcon.reset();
FileBrowserEntry::hdr.reset();
FileBrowserEntry::ps.reset();
if (!options.windowMaximized && !is_fullscreen && !is_minimized) {
get_size (options.windowWidth, options.windowHeight);
get_position (options.windowX, options.windowY);
}
// Retrieve window monitor ID
options.windowMonitor = 0;
const auto display = get_screen()->get_display();
const int monitor_nb = display->get_n_monitors();
for (int id = 0; id < monitor_nb; id++) {
if (display->get_monitor_at_window(get_window()) == display->get_monitor(id)) {
options.windowMonitor = id;
break;
}
}
try {
Options::save ();
} catch (Options::Error &e) {
Gtk::MessageDialog msgd (getToplevelWindow (this), e.get_msg(), true, Gtk::MESSAGE_WARNING, Gtk::BUTTONS_CLOSE, true);
msgd.run();
}
hide();
on_delete_has_run = true;
return false;
}
void RTWindow::writeToolExpandedStatus (std::vector<int> &tpOpen)
{
if ((isSingleTabMode() || gimpPlugin) && epanel->isRealized()) {
epanel->writeToolExpandedStatus (tpOpen);
} else {
// Storing the options of the last EditorPanel before Gtk destroys everything
// Look at the active panel first, if any, otherwise look at the first one (sorted on the filename)
if (epanels.size()) {
int page = mainNB->get_current_page();
Gtk::Widget *w = mainNB->get_nth_page (page);
bool optionsWritten = false;
for (std::map<Glib::ustring, EditorPanel*>::iterator i = epanels.begin(); i != epanels.end(); ++i) {
if (i->second == w) {
i->second->writeToolExpandedStatus (tpOpen);
optionsWritten = true;
}
}
if (!optionsWritten) {
// fallback solution: save the options of the first editor panel
std::map<Glib::ustring, EditorPanel*>::iterator i = epanels.begin();
i->second->writeToolExpandedStatus (tpOpen);
}
}
}
}
void RTWindow::showRawPedia()
{
GError* gerror = nullptr;
gtk_show_uri(nullptr, "https://rawpedia.rawtherapee.com/", GDK_CURRENT_TIME, &gerror);
}
void RTWindow::showICCProfileCreator ()
{
ICCProfileCreator *iccpc = new ICCProfileCreator (this);
iccpc->run ();
delete iccpc;
fpanel->optionsChanged ();
if (epanel) {
epanel->defaultMonitorProfileChanged (options.rtSettings.monitorProfile, options.rtSettings.autoMonitorProfile);
}
for (const auto &p : epanels) {
p.second->defaultMonitorProfileChanged (options.rtSettings.monitorProfile, options.rtSettings.autoMonitorProfile);
}
}
void RTWindow::showPreferences ()
{
Preferences *pref = new Preferences (this);
pref->run ();
delete pref;
fpanel->optionsChanged ();
if (epanel) {
epanel->defaultMonitorProfileChanged (options.rtSettings.monitorProfile, options.rtSettings.autoMonitorProfile);
}
for (const auto &p : epanels) {
p.second->defaultMonitorProfileChanged (options.rtSettings.monitorProfile, options.rtSettings.autoMonitorProfile);
}
}
void RTWindow::setProgress(double p)
{
prProgBar.set_fraction(p);
}
void RTWindow::setProgressStr(const Glib::ustring& str)
{
if (!options.mainNBVertical) {
prProgBar.set_text(str);
}
}
void RTWindow::setProgressState(bool inProcessing)
{
if (inProcessing) {
prProgBar.show();
} else {
prProgBar.hide();
}
}
void RTWindow::error(const Glib::ustring& descr)
{
prProgBar.set_text(descr);
}
void RTWindow::toggle_fullscreen ()
{
onConfEventConn.block(true); // Avoid getting size and position while window is getting fullscreen
if (is_fullscreen) {
unfullscreen();
if (btn_fullscreen) {
btn_fullscreen->set_tooltip_markup (M ("MAIN_BUTTON_FULLSCREEN"));
btn_fullscreen->set_image (*iFullscreen);
}
} else {
fullscreen();
if (btn_fullscreen) {
btn_fullscreen->set_tooltip_markup (M ("MAIN_BUTTON_UNFULLSCREEN"));
btn_fullscreen->set_image (*iFullscreen_exit);
}
}
onConfEventConn.block(false);
}
void RTWindow::SetEditorCurrent()
{
mainNB->set_current_page (mainNB->page_num (*epanel));
}
void RTWindow::SetMainCurrent()
{
mainNB->set_current_page (mainNB->page_num (*fpanel));
}
void RTWindow::MoveFileBrowserToMain()
{
if ( fpanel->ribbonPane->get_children().empty()) {
FileCatalog *fCatalog = fpanel->fileCatalog;
epanel->catalogPane->remove (*fCatalog);
fpanel->ribbonPane->add (*fCatalog);
fCatalog->enableTabMode (false);
fCatalog->tbLeftPanel_1_visible (true);
fCatalog->tbRightPanel_1_visible (true);
}
}
void RTWindow::MoveFileBrowserToEditor()
{
if (epanel->catalogPane->get_children().empty() ) {
FileCatalog *fCatalog = fpanel->fileCatalog;
fpanel->ribbonPane->remove (*fCatalog);
fCatalog->disableInspector();
epanel->catalogPane->add (*fCatalog);
epanel->showTopPanel (options.editorFilmStripOpened);
fCatalog->enableTabMode (true);
fCatalog->refreshHeight();
fCatalog->tbLeftPanel_1_visible (false);
fCatalog->tbRightPanel_1_visible (false);
}
}
void RTWindow::updateExternalEditorWidget(int selectedIndex, const std::vector<ExternalEditor> & editors)
{
if (epanel) {
epanel->updateExternalEditorWidget(selectedIndex, editors);
}