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