2016-06-16 12:59:54 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2018-01-03 10:23:14 +00:00
|
|
|
the official desktop application for the Telegram messaging service.
|
2016-06-16 12:59:54 +00:00
|
|
|
|
2018-01-03 10:23:14 +00:00
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
2016-06-16 12:59:54 +00:00
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
2021-07-25 21:30:56 +00:00
|
|
|
#include "ui/widgets/rp_window.h"
|
2017-06-21 21:38:31 +00:00
|
|
|
#include "base/timer.h"
|
2019-09-13 12:22:54 +00:00
|
|
|
#include "base/object_ptr.h"
|
2021-05-27 22:11:16 +00:00
|
|
|
#include "core/core_settings.h"
|
2021-11-02 13:10:40 +00:00
|
|
|
#include "base/required.h"
|
2016-11-04 11:14:47 +00:00
|
|
|
|
2019-06-06 11:59:00 +00:00
|
|
|
namespace Main {
|
2020-06-15 16:25:02 +00:00
|
|
|
class Session;
|
2019-06-06 11:59:00 +00:00
|
|
|
class Account;
|
|
|
|
} // namespace Main
|
|
|
|
|
2019-09-18 11:19:05 +00:00
|
|
|
namespace Ui {
|
|
|
|
class BoxContent;
|
2020-07-07 13:54:39 +00:00
|
|
|
class PlainShadow;
|
2019-09-18 11:19:05 +00:00
|
|
|
} // namespace Ui
|
|
|
|
|
2021-08-10 12:41:25 +00:00
|
|
|
namespace Core {
|
|
|
|
struct WindowPosition;
|
2022-01-27 12:48:51 +00:00
|
|
|
enum class QuitReason;
|
2021-08-10 12:41:25 +00:00
|
|
|
} // namespace Core
|
|
|
|
|
2016-06-16 12:59:54 +00:00
|
|
|
namespace Window {
|
|
|
|
|
2019-06-06 11:20:21 +00:00
|
|
|
class Controller;
|
2019-06-06 10:21:40 +00:00
|
|
|
class SessionController;
|
2016-11-04 11:14:47 +00:00
|
|
|
class TitleWidget;
|
2018-06-03 13:30:40 +00:00
|
|
|
struct TermsLock;
|
2016-11-04 11:14:47 +00:00
|
|
|
|
2021-11-02 13:10:40 +00:00
|
|
|
[[nodiscard]] const QImage &Logo();
|
|
|
|
[[nodiscard]] const QImage &LogoNoMargin();
|
2023-02-28 16:49:45 +00:00
|
|
|
void OverrideApplicationIcon(QImage image);
|
2022-01-22 13:11:12 +00:00
|
|
|
[[nodiscard]] QIcon CreateIcon(
|
|
|
|
Main::Session *session = nullptr,
|
|
|
|
bool returnNullIfDefault = false);
|
2018-10-07 11:45:46 +00:00
|
|
|
void ConvertIconToBlack(QImage &image);
|
2017-05-12 15:27:19 +00:00
|
|
|
|
2021-11-02 13:10:40 +00:00
|
|
|
struct CounterLayerArgs {
|
2021-11-11 11:44:12 +00:00
|
|
|
template <typename T>
|
|
|
|
using required = base::required<T>;
|
|
|
|
|
|
|
|
required<int> size = 16;
|
2023-04-05 05:26:35 +00:00
|
|
|
double devicePixelRatio = 1.;
|
2021-11-11 11:44:12 +00:00
|
|
|
required<int> count = 1;
|
|
|
|
required<style::color> bg;
|
|
|
|
required<style::color> fg;
|
2021-11-02 13:10:40 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
[[nodiscard]] QImage GenerateCounterLayer(CounterLayerArgs &&args);
|
|
|
|
[[nodiscard]] QImage WithSmallCounter(QImage image, CounterLayerArgs &&args);
|
|
|
|
|
2021-07-25 21:30:56 +00:00
|
|
|
class MainWindow : public Ui::RpWindow {
|
2016-06-16 12:59:54 +00:00
|
|
|
public:
|
2019-06-06 11:20:21 +00:00
|
|
|
explicit MainWindow(not_null<Controller*> controller);
|
2021-02-25 15:12:51 +00:00
|
|
|
virtual ~MainWindow();
|
2016-06-16 12:59:54 +00:00
|
|
|
|
2020-06-15 16:25:02 +00:00
|
|
|
[[nodiscard]] Window::Controller &controller() const {
|
2019-06-06 11:59:00 +00:00
|
|
|
return *_controller;
|
2017-06-21 21:38:31 +00:00
|
|
|
}
|
2022-01-04 12:29:40 +00:00
|
|
|
[[nodiscard]] PeerData *singlePeer() const;
|
|
|
|
[[nodiscard]] bool isPrimary() const;
|
2020-06-15 16:25:02 +00:00
|
|
|
[[nodiscard]] Main::Account &account() const;
|
|
|
|
[[nodiscard]] Window::SessionController *sessionController() const;
|
2017-06-21 21:38:31 +00:00
|
|
|
|
2016-12-31 15:19:22 +00:00
|
|
|
bool hideNoQuit();
|
|
|
|
|
2021-01-22 12:16:18 +00:00
|
|
|
void showFromTray();
|
|
|
|
void quitFromTray();
|
|
|
|
void activate();
|
|
|
|
|
2021-02-25 15:12:51 +00:00
|
|
|
[[nodiscard]] QRect desktopRect() const;
|
2022-06-07 18:05:37 +00:00
|
|
|
[[nodiscard]] Core::WindowPosition withScreenInPosition(
|
|
|
|
Core::WindowPosition position) const;
|
2021-02-25 15:12:51 +00:00
|
|
|
|
2016-11-04 11:14:47 +00:00
|
|
|
void init();
|
2020-06-17 09:36:25 +00:00
|
|
|
|
|
|
|
void updateIsActive();
|
|
|
|
|
2021-02-25 15:12:51 +00:00
|
|
|
[[nodiscard]] bool isActive() const {
|
2023-02-17 09:21:19 +00:00
|
|
|
return !isHidden() && _isActive;
|
2017-01-01 16:45:20 +00:00
|
|
|
}
|
2021-02-25 15:12:51 +00:00
|
|
|
[[nodiscard]] virtual bool isActiveForTrayMenu() {
|
2021-01-22 12:16:18 +00:00
|
|
|
updateIsActive();
|
|
|
|
return isActive();
|
|
|
|
}
|
2016-11-04 11:14:47 +00:00
|
|
|
|
|
|
|
bool positionInited() const {
|
|
|
|
return _positionInited;
|
|
|
|
}
|
|
|
|
void positionUpdated();
|
|
|
|
|
2018-06-05 18:14:38 +00:00
|
|
|
void reActivateWindow();
|
2017-01-01 17:49:44 +00:00
|
|
|
|
2017-02-03 20:07:26 +00:00
|
|
|
void showRightColumn(object_ptr<TWidget> widget);
|
2017-11-16 16:43:52 +00:00
|
|
|
int maximalExtendBy() const;
|
|
|
|
bool canExtendNoMove(int extendBy) const;
|
|
|
|
|
|
|
|
// Returns how much could the window get extended.
|
|
|
|
int tryToExtendWidthBy(int addToWidth);
|
2017-02-03 20:07:26 +00:00
|
|
|
|
2020-07-07 13:54:39 +00:00
|
|
|
virtual void fixOrder() {
|
|
|
|
}
|
2021-02-25 15:12:51 +00:00
|
|
|
virtual void setInnerFocus() {
|
|
|
|
setFocus();
|
|
|
|
}
|
2016-06-16 12:59:54 +00:00
|
|
|
|
2020-03-03 12:07:22 +00:00
|
|
|
Ui::RpWidget *bodyWidget() {
|
2016-12-13 17:07:56 +00:00
|
|
|
return _body.data();
|
2016-11-05 08:36:24 +00:00
|
|
|
}
|
|
|
|
|
2021-05-25 12:42:26 +00:00
|
|
|
void launchDrag(std::unique_ptr<QMimeData> data, Fn<void()> &&callback);
|
2017-06-21 21:38:31 +00:00
|
|
|
|
2017-11-21 10:27:37 +00:00
|
|
|
rpl::producer<> leaveEvents() const;
|
|
|
|
|
2023-01-09 13:12:37 +00:00
|
|
|
virtual void updateWindowIcon() = 0;
|
|
|
|
void updateTitle();
|
2019-06-06 11:20:21 +00:00
|
|
|
|
2019-08-16 12:44:20 +00:00
|
|
|
void clearWidgets();
|
|
|
|
|
2020-03-03 12:07:22 +00:00
|
|
|
int computeMinWidth() const;
|
|
|
|
int computeMinHeight() const;
|
|
|
|
|
2020-07-07 13:54:39 +00:00
|
|
|
void recountGeometryConstraints();
|
2020-03-03 12:07:22 +00:00
|
|
|
virtual void updateControlsGeometry();
|
|
|
|
|
2016-12-31 15:19:22 +00:00
|
|
|
bool minimizeToTray();
|
2017-01-01 16:45:20 +00:00
|
|
|
void updateGlobalMenu() {
|
|
|
|
updateGlobalMenuHook();
|
|
|
|
}
|
2016-12-31 15:19:22 +00:00
|
|
|
|
2023-02-17 16:12:29 +00:00
|
|
|
[[nodiscard]] QRect countInitialGeometry(
|
|
|
|
Core::WindowPosition position,
|
|
|
|
Core::WindowPosition initial,
|
|
|
|
QSize minSize) const;
|
|
|
|
|
2016-06-16 12:59:54 +00:00
|
|
|
protected:
|
2018-06-03 13:30:40 +00:00
|
|
|
void leaveEventHook(QEvent *e) override;
|
2016-11-04 11:14:47 +00:00
|
|
|
|
|
|
|
void savePosition(Qt::WindowState state = Qt::WindowActive);
|
2017-05-19 14:02:55 +00:00
|
|
|
void handleStateChanged(Qt::WindowState state);
|
|
|
|
void handleActiveChanged();
|
2020-09-18 09:09:05 +00:00
|
|
|
void handleVisibleChanged(bool visible);
|
2016-11-04 11:14:47 +00:00
|
|
|
|
2023-03-21 12:22:38 +00:00
|
|
|
virtual void checkActivation() {
|
|
|
|
}
|
2016-11-04 11:14:47 +00:00
|
|
|
virtual void initHook() {
|
|
|
|
}
|
|
|
|
|
2020-09-18 09:09:05 +00:00
|
|
|
virtual void handleVisibleChangedHook(bool visible) {
|
|
|
|
}
|
|
|
|
|
2017-01-01 16:45:20 +00:00
|
|
|
virtual void clearWidgetsHook() {
|
|
|
|
}
|
|
|
|
|
2016-06-16 15:17:39 +00:00
|
|
|
virtual void stateChangedHook(Qt::WindowState state) {
|
|
|
|
}
|
2016-06-16 12:59:54 +00:00
|
|
|
|
2016-11-09 08:34:38 +00:00
|
|
|
virtual void unreadCounterChangedHook() {
|
|
|
|
}
|
|
|
|
|
2016-12-31 15:19:22 +00:00
|
|
|
virtual void closeWithoutDestroy() {
|
|
|
|
hide();
|
|
|
|
}
|
|
|
|
|
2017-01-01 16:45:20 +00:00
|
|
|
virtual void updateGlobalMenuHook() {
|
|
|
|
}
|
|
|
|
|
2021-05-27 22:11:16 +00:00
|
|
|
virtual void workmodeUpdated(Core::Settings::WorkMode mode) {
|
2017-03-04 19:36:59 +00:00
|
|
|
}
|
|
|
|
|
2020-02-12 08:09:17 +00:00
|
|
|
virtual void createGlobalMenu() {
|
|
|
|
}
|
|
|
|
|
2021-08-10 12:41:25 +00:00
|
|
|
virtual bool initGeometryFromSystem() {
|
2021-01-16 12:33:09 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-11-04 11:14:47 +00:00
|
|
|
void setPositionInited();
|
|
|
|
|
2021-02-25 15:12:51 +00:00
|
|
|
virtual QRect computeDesktopRect() const;
|
|
|
|
|
2016-11-04 11:14:47 +00:00
|
|
|
private:
|
2020-07-07 13:54:39 +00:00
|
|
|
void refreshTitleWidget();
|
|
|
|
void updateMinimumSize();
|
2016-12-31 13:34:41 +00:00
|
|
|
void updatePalette();
|
2021-08-10 12:41:25 +00:00
|
|
|
|
2023-02-02 16:19:32 +00:00
|
|
|
[[nodiscard]] Core::WindowPosition initialPosition() const;
|
|
|
|
[[nodiscard]] Core::WindowPosition nextInitialChildPosition(
|
|
|
|
bool primary);
|
2021-08-10 12:41:25 +00:00
|
|
|
[[nodiscard]] QRect countInitialGeometry(Core::WindowPosition position);
|
|
|
|
void initGeometry();
|
2016-11-04 11:14:47 +00:00
|
|
|
|
2017-01-01 16:45:20 +00:00
|
|
|
bool computeIsActive() const;
|
|
|
|
|
2019-06-06 11:20:21 +00:00
|
|
|
not_null<Window::Controller*> _controller;
|
|
|
|
|
2018-06-05 18:14:38 +00:00
|
|
|
base::Timer _positionUpdatedTimer;
|
2016-11-04 11:14:47 +00:00
|
|
|
bool _positionInited = false;
|
|
|
|
|
2020-07-07 13:54:39 +00:00
|
|
|
object_ptr<Ui::PlainShadow> _titleShadow = { nullptr };
|
2019-06-03 22:34:34 +00:00
|
|
|
object_ptr<Ui::RpWidget> _outdated;
|
2020-03-03 12:07:22 +00:00
|
|
|
object_ptr<Ui::RpWidget> _body;
|
2017-02-03 20:07:26 +00:00
|
|
|
object_ptr<TWidget> _rightColumn = { nullptr };
|
2016-11-04 11:14:47 +00:00
|
|
|
|
2017-01-01 16:45:20 +00:00
|
|
|
bool _isActive = false;
|
|
|
|
|
2017-11-21 10:27:37 +00:00
|
|
|
rpl::event_stream<> _leaveEvents;
|
2017-11-16 16:43:52 +00:00
|
|
|
|
2020-09-18 09:09:05 +00:00
|
|
|
bool _maximizedBeforeHide = false;
|
|
|
|
|
2023-02-02 16:19:32 +00:00
|
|
|
QPoint _lastMyChildCreatePosition;
|
|
|
|
int _lastChildIndex = 0;
|
|
|
|
|
2021-02-25 15:12:51 +00:00
|
|
|
mutable QRect _monitorRect;
|
|
|
|
mutable crl::time _monitorLastGot = 0;
|
|
|
|
|
2016-06-16 12:59:54 +00:00
|
|
|
};
|
|
|
|
|
2023-02-17 16:12:29 +00:00
|
|
|
[[nodiscard]] int32 DefaultScreenNameChecksum(const QString &name);
|
|
|
|
|
|
|
|
[[nodiscard]] Core::WindowPosition PositionWithScreen(
|
|
|
|
Core::WindowPosition position,
|
|
|
|
const QScreen *chosen,
|
|
|
|
QSize minimal);
|
|
|
|
[[nodiscard]] Core::WindowPosition PositionWithScreen(
|
|
|
|
Core::WindowPosition position,
|
|
|
|
not_null<const QWidget*> widget,
|
|
|
|
QSize minimal);
|
|
|
|
|
2016-06-16 12:59:54 +00:00
|
|
|
} // namespace Window
|