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 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045
|
/***********************************************************************
* fwindow.cpp - Intermediate base class for all window objects *
* *
* This file is part of the FINAL CUT widget toolkit *
* *
* Copyright 2015-2023 Markus Gans *
* *
* FINAL CUT is free software; you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as *
* published by the Free Software Foundation; either version 3 of *
* the License, or (at your option) any later version. *
* *
* FINAL CUT 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 Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License along with this program. If not, see *
* <http://www.gnu.org/licenses/>. *
***********************************************************************/
#include <utility>
#include "final/fapplication.h"
#include "final/fevent.h"
#include "final/input/fmouse.h"
#include "final/menu/fmenubar.h"
#include "final/menu/fmenu.h"
#include "final/widget/fcombobox.h"
#include "final/widget/fstatusbar.h"
#include "final/widget/fwindow.h"
namespace finalcut
{
namespace internal
{
struct var
{
static bool fwindow_init_flag; // FWindow init state
};
bool var::fwindow_init_flag{false};
} // namespace internal
// static attributes
FWindow* FWindow::previous_window{nullptr};
//----------------------------------------------------------------------
// class FWindow
//----------------------------------------------------------------------
// constructor and destructor
//----------------------------------------------------------------------
FWindow::FWindow(FWidget* parent)
: FWidget{parent}
{
if ( ! internal::var::fwindow_init_flag )
{
auto app_object = FApplication::getApplicationObject();
app_object->registerMouseHandler (closeDropDownMouseHandler);
app_object->registerMouseHandler (unselectMenubarItemsMouseHandler);
internal::var::fwindow_init_flag = true;
}
setWindowWidget();
createVWin();
addWindow (this);
}
//----------------------------------------------------------------------
FWindow::~FWindow() // destructor
{
if ( previous_window == this )
previous_window = nullptr;
if ( isAlwaysOnTop() )
deleteFromAlwaysOnTopList (this);
// unset the global active window
if ( this == FWindow::getActiveWindow() )
unsetActiveWindow();
delWindow (this);
if ( ! FApplication::isQuit() )
{
const auto& t_geometry = getTermGeometryWithShadow();
restoreVTerm (t_geometry);
}
}
// public methods of FWindow
//----------------------------------------------------------------------
auto FWindow::getWindowFocusWidget() const -> FWidget*
{
// returns the focused widget of this window
return win_focus_widget;
}
//----------------------------------------------------------------------
auto FWindow::setWindowWidget (bool enable) -> bool
{
if ( isWindowWidget() == enable )
return true;
setFlags().type.window_widget = enable;
if ( enable )
setTermOffset();
else
setParentOffset();
return enable;
}
//----------------------------------------------------------------------
void FWindow::setActiveWindow (FWindow* window)
{
// activate FWindow object window
if ( ! getWindowList() || getWindowList()->empty() )
return;
for (auto&& win : *getWindowList())
{
if ( win == window )
{
if ( ! window->isWindowActive() )
{
window->activateWindow();
FEvent ev(Event::WindowActive);
FApplication::sendEvent(window, &ev);
}
}
else
{
auto w = static_cast<FWindow*>(win);
if ( w->isWindowActive() )
{
w->deactivateWindow();
FEvent ev(Event::WindowInactive);
FApplication::sendEvent(static_cast<FWidget*>(win), &ev);
}
}
}
}
//----------------------------------------------------------------------
void FWindow::setWindowFocusWidget (FWidget* obj)
{
// set focus widget of this window
win_focus_widget = obj;
}
//----------------------------------------------------------------------
auto FWindow::activateWindow (bool enable) -> bool
{
// activate/deactivate this window
if ( enable )
{
FWidget::setActiveWindow (this);
setActiveArea (getVWin());
}
return (window_active = enable);
}
//----------------------------------------------------------------------
void FWindow::unsetActiveWindow() const
{
// unset the active FWindow object
FWidget::setActiveWindow (nullptr);
}
//----------------------------------------------------------------------
auto FWindow::setResizeable (bool enable) -> bool
{
return (setFlags().feature.resizeable = enable);
}
//----------------------------------------------------------------------
auto FWindow::setMinimizable (bool enable) -> bool
{
return (setFlags().feature.minimizable = enable);
}
//----------------------------------------------------------------------
auto FWindow::setTransparentShadow (bool enable) -> bool
{
setFlags().shadow.shadow = setFlags().shadow.trans_shadow = enable;
if ( enable )
setShadowSize (FSize{2, 1});
else
setShadowSize (FSize{0, 0});
return enable;
}
//----------------------------------------------------------------------
auto FWindow::setShadow (bool enable) -> bool
{
if ( FVTerm::getFOutput()->isMonochron() )
return false;
if ( enable )
{
setFlags().shadow.shadow = true;
setFlags().shadow.trans_shadow = false;
setShadowSize (FSize{1, 1});
}
else
{
setFlags().shadow.shadow = false;
setFlags().shadow.trans_shadow = false;
setShadowSize (FSize{0, 0});
}
return enable;
}
//----------------------------------------------------------------------
auto FWindow::setAlwaysOnTop (bool enable) -> bool
{
if ( isAlwaysOnTop() == enable )
return true;
setFlags().visibility.always_on_top = enable;
if ( enable )
{
if ( getAlwaysOnTopList() )
{
deleteFromAlwaysOnTopList (this);
getAlwaysOnTopList()->push_back (this);
}
unsetMinimizable();
}
else
deleteFromAlwaysOnTopList (this);
return enable;
}
//----------------------------------------------------------------------
auto FWindow::isMinimized() const -> bool
{
// returns the window minimized state
if ( isVirtualWindow() )
return getVWin()->minimized;
return false;
}
//----------------------------------------------------------------------
auto FWindow::isWindowHidden() const -> bool
{
// returns the window hidden state
if ( isVirtualWindow() )
return ! getVWin()->visible;
return false;
}
//----------------------------------------------------------------------
void FWindow::drawBorder()
{
if ( FVTerm::getFOutput()->isNewFont() ) // Draw a newfont outer frame
{
const FRect r{FPoint{1, 1}, getSize()};
print() << r.getUpperLeftPos()
<< UniChar::NF_border_corner_upper_left // ⎡
<< FString{r.getWidth() - 2, UniChar::NF_border_line_upper} // ¯
<< UniChar::NF_rev_border_corner_upper_right; // ⎤
for (auto y = r.getY1() + 1; y < r.getY2(); y++)
{
print() << FPoint{r.getX1(), y}
<< UniChar::NF_border_line_left // border left ⎸
<< FPoint{r.getX2(), y}
<< UniChar::NF_rev_border_line_right; // border right⎹
}
print() << r.getLowerLeftPos()
<< UniChar::NF_border_corner_lower_left // ⎣
<< FString{r.getWidth() - 2, UniChar::NF_border_line_bottom} // _
<< UniChar::NF_rev_border_corner_lower_right; // ⎦
}
else
{
FWidget::drawBorder();
}
}
//----------------------------------------------------------------------
void FWindow::show()
{
if ( isVirtualWindow() )
getVWin()->visible = true;
FWidget::show();
}
//----------------------------------------------------------------------
void FWindow::hide()
{
const auto& virtual_win = getVWin();
if ( isActive(virtual_win)
&& virtual_win->visible
&& virtual_win->input_cursor_visible )
{
hideVTermCursor();
}
if ( isVirtualWindow() )
virtual_win->visible = false;
FWidget::hide();
const auto& t_geometry = getTermGeometryWithShadow();
restoreVTerm (t_geometry);
}
//----------------------------------------------------------------------
void FWindow::setX (int x, bool adjust)
{
FWidget::setX (x, adjust);
if ( isVirtualWindow() )
getVWin()->offset_left = getTermX() - 1;
}
//----------------------------------------------------------------------
void FWindow::setY (int y, bool adjust)
{
if ( y < 1 )
y = 1;
FWidget::setY (y, adjust);
if ( isVirtualWindow() )
getVWin()->offset_top = getTermY() - 1;
}
//----------------------------------------------------------------------
void FWindow::setPos (const FPoint& p, bool adjust)
{
FPoint pos{p};
if ( pos.getY() < 1 )
pos.setY(1);
FWidget::setPos (pos, adjust);
if ( isVirtualWindow() )
{
auto virtual_win = getVWin();
virtual_win->offset_left = getTermX() - 1;
virtual_win->offset_top = getTermY() - 1;
}
}
//----------------------------------------------------------------------
void FWindow::setWidth (std::size_t w, bool adjust)
{
const std::size_t old_width = getWidth();
FWidget::setWidth (w, adjust);
if ( isVirtualWindow() && getWidth() != old_width )
{
FRect geometry {getTermGeometry()};
geometry.move(-1, -1);
resizeArea (geometry, getShadow(), getVWin());
}
}
//----------------------------------------------------------------------
void FWindow::setHeight (std::size_t h, bool adjust)
{
const std::size_t old_height = getHeight();
FWidget::setHeight (h, adjust);
if ( isVirtualWindow() && getHeight() != old_height )
{
FRect geometry {getTermGeometry()};
geometry.move(-1, -1);
resizeArea (geometry, getShadow(), getVWin());
}
}
//----------------------------------------------------------------------
void FWindow::setSize (const FSize& size, bool adjust)
{
const FSize old_size{getSize()};
FWidget::setSize (size, adjust);
if ( isVirtualWindow() && getSize() != old_size )
{
FRect geometry {getTermGeometry()};
geometry.move(-1, -1);
resizeArea (geometry, getShadow(), getVWin());
}
}
//----------------------------------------------------------------------
void FWindow::setGeometry ( const FPoint& p, const FSize& size, bool adjust)
{
// Sets the geometry of the widget
const int old_x = getX();
const int old_y = getY();
FPoint pos{p};
const FSize old_size{getSize()};
if ( pos.getY() < 1 )
pos.setY(1);
FWidget::setGeometry (pos, size, adjust);
if ( ! isVirtualWindow() )
return;
if ( getSize() != old_size )
{
FRect geometry {getTermGeometry()};
geometry.move(-1, -1);
resizeArea (geometry, getShadow(), getVWin());
}
else
{
if ( getX() != old_x )
getVWin()->offset_left = getTermX() - 1;
if ( getY() != old_y )
getVWin()->offset_top = getTermY() - 1;
}
}
//----------------------------------------------------------------------
void FWindow::move (const FPoint& pos)
{
FWidget::move(pos);
if ( isVirtualWindow() )
{
auto virtual_win = getVWin();
virtual_win->offset_left = getTermX() - 1;
virtual_win->offset_top = getTermY() - 1;
}
}
//----------------------------------------------------------------------
auto FWindow::getWindowWidgetAt (int x, int y) -> FWindow*
{
// returns the window object to the corresponding coordinates
if ( ! getWindowList() || getWindowList()->empty() )
return nullptr;
auto iter = getWindowList()->cend();
const auto begin = getWindowList()->cbegin();
do
{
--iter;
auto w = static_cast<FWindow*>(*iter);
if ( *iter && ! w->isWindowHidden()
&& getVisibleTermGeometry(w).contains(x, y) )
{
return w;
}
}
while ( iter != begin );
return nullptr;
}
//----------------------------------------------------------------------
void FWindow::addWindow (FWidget* obj)
{
// add the window object obj to the window list
if ( getWindowList() )
getWindowList()->push_back(obj);
processAlwaysOnTop();
}
//----------------------------------------------------------------------
void FWindow::delWindow (const FWidget* obj)
{
// delete the window object obj from the window list
if ( ! getWindowList() || getWindowList()->empty() )
return;
auto iter = getWindowList()->cbegin();
while ( iter != getWindowList()->cend() )
{
if ( (*iter) == obj )
{
getWindowList()->erase(iter);
determineWindowLayers();
return;
}
++iter;
}
}
//----------------------------------------------------------------------
void FWindow::swapWindow (const FWidget* obj1, const FWidget* obj2)
{
// swaps the window layer between obj1 and obj2
if ( ! getWindowList()
|| getWindowList()->empty()
|| obj1->getFlags().visibility.modal
|| obj2->getFlags().visibility.modal )
return;
auto iter = getWindowList()->cbegin();
const auto end = getWindowList()->cend();
auto iter1 = end;
auto iter2 = end;
while ( iter != end )
{
if ( (*iter) == obj1 )
iter1 = iter;
else if ( (*iter) == obj2 )
iter2 = iter;
++iter;
}
if ( iter1 != end && iter2 != end )
{
std::swap (iter1, iter2);
determineWindowLayers();
}
}
//----------------------------------------------------------------------
auto FWindow::raiseWindow (FWidget* obj) -> bool
{
// raises the window widget obj to the top
if ( ! getWindowList()
|| getWindowList()->empty()
|| ! obj->isWindowWidget() )
return false;
const auto last = static_cast<FWidget*>(getWindowList()->back());
if ( last == obj || (last->getFlags().visibility.modal && ! obj->isMenuWidget()) )
return false;
auto iter = getWindowList()->cbegin();
while ( iter != getWindowList()->cend() )
{
if ( static_cast<FWidget*>(*iter) == obj )
{
getWindowList()->erase (iter);
getWindowList()->push_back (obj);
processAlwaysOnTop();
FEvent ev(Event::WindowRaised);
FApplication::sendEvent(obj, &ev);
return true;
}
++iter;
}
return false;
}
//----------------------------------------------------------------------
auto FWindow::lowerWindow (FWidget* obj) -> bool
{
// lowers the window widget obj to the bottom
if ( ! getWindowList()
|| getWindowList()->empty()
|| ! obj->isWindowWidget()
|| getWindowList()->front() == obj
|| obj->getFlags().visibility.modal )
return false;
auto iter = getWindowList()->cbegin();
while ( iter != getWindowList()->cend() )
{
if ( *iter == obj )
{
getWindowList()->erase (iter);
getWindowList()->insert (getWindowList()->cbegin(), obj);
determineWindowLayers();
FEvent ev(Event::WindowLowered);
FApplication::sendEvent(obj, &ev);
return true;
}
++iter;
}
return false;
}
//----------------------------------------------------------------------
auto FWindow::zoomWindow() -> bool
{
if ( zoomed )
{
zoomed = false;
const FRect oldGeometry (getTermGeometryWithShadow());
setGeometry (normalGeometry);
redraw();
restoreVTerm (oldGeometry);
}
else
{
if ( isMinimized() )
minimizeWindow(); // unminimize window
zoomed = true;
// save the current geometry
normalGeometry = getGeometry();
const FRect oldGeometry (getTermGeometryWithShadow());
setGeometry (FPoint{1, 1}, FSize{getMaxWidth(), getMaxHeight()});
redraw();
restoreVTerm (oldGeometry);
}
return zoomed;
}
//----------------------------------------------------------------------
auto FWindow::minimizeWindow() -> bool
{
if ( ! isVirtualWindow() )
return false;
if ( zoomed )
zoomWindow(); // unzoom window
const auto& virtual_win = getVWin();
virtual_win->minimized = bool( ! isMinimized() );
const auto& t_geometry = getTermGeometryWithShadow();
restoreVTerm (t_geometry);
return virtual_win->minimized;
}
//----------------------------------------------------------------------
void FWindow::switchToPrevWindow (const FWidget* widget)
{
// switch to previous window
// Disable terminal updates to avoid flickering
// when redrawing the focused widget
if ( widget )
widget->setTerminalUpdates (FVTerm::TerminalUpdate::Stop);
const bool is_activated = activatePrevWindow();
auto active_win = static_cast<FWindow*>(getActiveWindow());
if ( ! is_activated && getWindowList() && getWindowList()->size() > 1 )
{
// no previous window -> looking for another window
auto iter = getWindowList()->cend();
const auto begin = getWindowList()->cbegin();
do
{
--iter;
auto w = static_cast<FWindow*>(*iter);
if ( w
&& w != active_win
&& ! (w->isWindowHidden() || w->isWindowActive())
&& w != static_cast<FWindow*>(getStatusBar())
&& w != static_cast<FWindow*>(getMenuBar()) )
{
FWindow::setActiveWindow(w);
break;
}
}
while ( iter != begin );
}
reactivateWindow (active_win);
// Enable terminal updates again
if ( widget )
widget->setTerminalUpdates (FVTerm::TerminalUpdate::Continue);
}
//----------------------------------------------------------------------
auto FWindow::activatePrevWindow() -> bool
{
// activate the previous window
const auto& w = previous_window;
if ( w )
{
if ( w->isWindowActive() )
return true;
if ( ! w->isWindowHidden() )
{
FWindow::setActiveWindow(w);
return true;
}
}
return false;
}
//----------------------------------------------------------------------
void FWindow::setShadowSize (const FSize& size)
{
const FSize& old_shadow = getShadow();
FWidget::setShadowSize (size);
const FSize& new_shadow = getShadow();
if ( isVirtualWindow() && (new_shadow != old_shadow) )
{
auto geometry = getTermGeometry();
geometry.move(-1, -1);
resizeArea (geometry, getShadow(), getVWin());
}
}
// protected methods of FWindow
//----------------------------------------------------------------------
void FWindow::adjustSize()
{
const int old_x = getTermX();
const int old_y = getTermY();
FWidget::adjustSize();
if ( zoomed )
setGeometry (FPoint{1, 1}, FSize{getMaxWidth(), getMaxHeight()}, false);
else if ( isVirtualWindow() )
{
if ( getTermX() != old_x )
getVWin()->offset_left = getTermX() - 1;
if ( getTermY() != old_y )
getVWin()->offset_top = getTermY() - 1;
}
}
//----------------------------------------------------------------------
auto FWindow::event (FEvent* ev) -> bool
{
auto event_type = ev->getType();
if ( event_type == Event::WindowActive )
{
onWindowActive (ev);
}
else if ( event_type == Event::WindowInactive )
{
onWindowInactive (ev);
}
else if ( event_type == Event::WindowRaised )
{
onWindowRaised (ev);
}
else if ( event_type == Event::WindowLowered )
{
onWindowLowered (ev);
}
else
return FWidget::event(ev);
return true;
}
//----------------------------------------------------------------------
void FWindow::onWindowActive (FEvent*)
{
// This event handler can be reimplemented in a subclass
// to receive activation events for this window
}
//----------------------------------------------------------------------
void FWindow::onWindowInactive (FEvent*)
{
// This event handler can be reimplemented in a subclass
// to receive deactivation events for this window
}
//----------------------------------------------------------------------
void FWindow::onWindowRaised (FEvent*)
{
// This event handler can be reimplemented in a subclass
// to receive window raising events for this window
}
//----------------------------------------------------------------------
void FWindow::onWindowLowered (FEvent*)
{
// This event handler can be reimplemented in a subclass
// to receive window lowering events for this window
}
// private methods of FWindow
//----------------------------------------------------------------------
inline void FWindow::createVWin() noexcept
{
// Initialize virtual window
FRect geometry {getTermGeometry()};
geometry.move(-1, -1);
setVWin(createArea(geometry, getShadow()));
}
//----------------------------------------------------------------------
inline auto FWindow::getVisibleTermGeometry (FWindow* win) -> FRect
{
auto& term_geometry = win->getTermGeometry();
if ( win->isMinimized() )
{
FRect minimized_term_geometry(term_geometry);
auto min_height = std::size_t(win->getVWin()->min_height);
minimized_term_geometry.setHeight(min_height);
return minimized_term_geometry;
}
return term_geometry;
}
//----------------------------------------------------------------------
void FWindow::deleteFromAlwaysOnTopList (const FWidget* obj)
{
// delete the window object obj from the always-on-top list
if ( ! getAlwaysOnTopList() || getAlwaysOnTopList()->empty() )
return;
auto iter = getAlwaysOnTopList()->cbegin();
while ( iter != getAlwaysOnTopList()->cend() )
{
if ( *iter == obj )
{
getAlwaysOnTopList()->erase (iter);
return;
}
++iter;
}
}
//----------------------------------------------------------------------
void FWindow::processAlwaysOnTop()
{
// Raise all always-on-top windows
if ( ! getAlwaysOnTopList() || getAlwaysOnTopList()->empty() )
{
determineWindowLayers();
return;
}
auto iter = getAlwaysOnTopList()->cbegin();
while ( iter != getAlwaysOnTopList()->cend() )
{
delWindow (*iter);
if ( getWindowList() )
getWindowList()->push_back(*iter);
++iter;
}
determineWindowLayers();
}
//----------------------------------------------------------------------
auto FWindow::getWindowWidgetImpl (FWidget* obj) -> FWindow*
{
// returns the window object to the given widget obj
auto p_obj = obj->getParentWidget();
while ( ! obj->isWindowWidget() && p_obj )
{
obj = p_obj;
p_obj = p_obj->getParentWidget();
}
if ( obj->isWindowWidget() )
return static_cast<FWindow*>(obj);
return nullptr;
}
//----------------------------------------------------------------------
auto FWindow::getWindowLayerImpl (FWidget* obj) -> int
{
// returns the window layer from the widget obj
FWidget* window;
if ( ! obj->isWindowWidget() )
{
if ( (window = getWindowWidget(obj)) == nullptr )
return -1;
}
else
window = obj;
return FVTerm::getLayer(*window);
}
//----------------------------------------------------------------------
void FWindow::reactivateWindow (FWindow* active_win)
{
if ( ! active_win )
return;
auto focus = active_win->getWindowFocusWidget();
if ( ! active_win->isWindowActive() )
FWindow::setActiveWindow(active_win);
if ( focus && ! focus->isInstanceOf("FMenuItem") )
{
// Renew the focus of the focused widget in the current window
auto last_focus = FWidget::getFocusWidget();
if ( last_focus )
last_focus->setFlags().focus.focus = false;
FWidget::setFocusWidget(focus);
focus->setFlags().focus.focus = true;
active_win->setWindowFocusWidget (focus);
FFocusEvent f_in (Event::FocusIn);
FApplication::sendEvent (focus, &f_in);
}
}
// non-member functions
//----------------------------------------------------------------------
void closeDropDownMouseHandler (const FMouseData& md)
{
if ( md.isMoved() )
return;
const auto& mouse_position = md.getPos();
auto app_object = FApplication::getApplicationObject();
finalcut::closeDropDown (app_object, mouse_position);
}
//----------------------------------------------------------------------
void closeDropDown (const FWidget* widget, const FPoint& mouse_position)
{
// Close the pop down windows
bool is_dialog_menu{false};
auto openmenu = FWidget::getOpenMenu();
if ( ! openmenu )
return;
if ( openmenu->isInstanceOf("FMenu")
|| openmenu->isInstanceOf("FDialogListMenu") )
{
bool contains_menu_structure;
auto menu = static_cast<FMenu*>(openmenu);
std::tie(contains_menu_structure, is_dialog_menu) = \
closeOpenMenus (menu, mouse_position);
if ( contains_menu_structure )
return;
}
if ( openmenu->isInstanceOf("FDropDownListBox") )
{
auto drop_down = static_cast<FDropDownListBox*>(openmenu);
if ( ! closeComboBox(drop_down, mouse_position) )
return;
}
// No widget was been clicked and the menu is no dialog menu
if ( ! (FWidget::getClickedWidget() || is_dialog_menu) )
FWindow::switchToPrevWindow(widget);
drawStatusBarMessage();
}
//----------------------------------------------------------------------
void unselectMenubarItemsMouseHandler (const FMouseData& md)
{
if ( md.isMoved() )
return;
const auto& mouse_position = md.getPos();
auto app_object = FApplication::getApplicationObject();
finalcut::unselectMenubarItems (app_object, mouse_position);
}
//----------------------------------------------------------------------
void unselectMenubarItems (const FWidget* widget, const FPoint& mouse_position)
{
// Unselect the menu bar items
auto menu_bar = FWidget::getMenuBar();
if ( FWidget::getOpenMenu()
|| ! (menu_bar && menu_bar->hasSelectedItem())
|| menu_bar->getTermGeometry().contains(mouse_position) )
return;
if ( FWidget::getStatusBar() )
FWidget::getStatusBar()->clearMessage();
menu_bar->resetMenu();
menu_bar->redraw();
// No widget was been clicked
if ( ! FWidget::getClickedWidget() )
FWindow::switchToPrevWindow(widget);
drawStatusBarMessage();
}
} // namespace finalcut
|