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