Ticket #8735: patch.updated

File patch.updated, 5.4 KB (added by humdinger, 12 years ago)

Doing it the StyledEdit way

Line 
1diff --git a/src/apps/icon-o-matic/IconEditorApp.cpp b/src/apps/icon-o-matic/IconEditorApp.cpp
2index 27f73a9..809d53a 100644
3--- a/src/apps/icon-o-matic/IconEditorApp.cpp
4+++ b/src/apps/icon-o-matic/IconEditorApp.cpp
5@@ -18,6 +18,7 @@
6 #include <Message.h>
7 #include <Mime.h>
8 #include <Path.h>
9+#include <Screen.h>
10 #include <storage/FindDirectory.h>
11
12 #include "support_settings.h"
13@@ -28,6 +29,58 @@
14 #include "SavePanel.h"
15
16
17+using namespace BPrivate;
18+
19+
20+static const float kWindowOffset = 20;
21+BRect gWindowRect(5 - kWindowOffset, 26 - kWindowOffset, 850, 780);
22+
23+
24+namespace
25+{
26+ void
27+ cascade()
28+ {
29+ BScreen screen;
30+ BRect screenBorder = screen.Frame();
31+ float left = gWindowRect.left + kWindowOffset;
32+ if (left + gWindowRect.Width() > screenBorder.right)
33+ left = 5;
34+
35+ float top = gWindowRect.top + kWindowOffset;
36+ if (top + gWindowRect.Height() > screenBorder.bottom)
37+ top = 26;
38+
39+ gWindowRect.OffsetTo(BPoint(left, top));
40+ }
41+
42+
43+ void
44+ uncascade()
45+ {
46+ BScreen screen;
47+ BRect screenBorder = screen.Frame();
48+
49+ float left = gWindowRect.left - kWindowOffset;
50+ if (left < 5) {
51+ left = screenBorder.right - gWindowRect.Width() - 5;
52+ left = left - ((int)left % (int)kWindowOffset) + 5;
53+ }
54+
55+ float top = gWindowRect.top - kWindowOffset;
56+ if (top < 26) {
57+ top = screenBorder.bottom - gWindowRect.Height() - 26;
58+ top = top - ((int)left % (int)kWindowOffset) + 26;
59+ }
60+
61+ gWindowRect.OffsetTo(BPoint(left, top));
62+ }
63+}
64+
65+
66+// #pragma mark -
67+
68+
69 #undef B_TRANSLATION_CONTEXT
70 #define B_TRANSLATION_CONTEXT "Icon-O-Matic-Main"
71
72@@ -36,14 +89,11 @@ using std::nothrow;
73
74 static const char* kAppSig = "application/x-vnd.haiku-icon_o_matic";
75
76-static const float kWindowOffset = 20;
77-
78
79 IconEditorApp::IconEditorApp()
80 :
81 BApplication(kAppSig),
82 fWindowCount(0),
83- fLastWindowFrame(50, 50, 900, 750),
84
85 fOpenPanel(NULL),
86 fSavePanel(NULL),
87@@ -179,6 +229,7 @@ IconEditorApp::MessageReceived(BMessage* message)
88 case MSG_WINDOW_CLOSED:
89 {
90 fWindowCount--;
91+ uncascade();
92 if (fWindowCount == 0)
93 PostMessage(B_QUIT_REQUESTED);
94 BMessage settings;
95@@ -186,8 +237,8 @@ IconEditorApp::MessageReceived(BMessage* message)
96 fLastWindowSettings = settings;
97 BRect frame;
98 if (message->FindRect("window frame", &frame) == B_OK) {
99- fLastWindowFrame = frame;
100- fLastWindowFrame.OffsetBy(-kWindowOffset, -kWindowOffset);
101+ gWindowRect = frame;
102+ uncascade();
103 }
104 break;
105 }
106@@ -272,8 +323,8 @@ IconEditorApp::ArgvReceived(int32 argc, char** argv)
107 MainWindow*
108 IconEditorApp::_NewWindow()
109 {
110- fLastWindowFrame.OffsetBy(kWindowOffset, kWindowOffset);
111- MainWindow* window = new MainWindow(fLastWindowFrame, this,
112+ cascade();
113+ MainWindow* window = new MainWindow(gWindowRect, this,
114 &fLastWindowSettings);
115 fWindowCount++;
116 return window;
117@@ -352,7 +403,7 @@ IconEditorApp::_StoreSettings()
118 {
119 BMessage settings('stns');
120
121- settings.AddRect("window frame", fLastWindowFrame);
122+ settings.AddRect("window frame", gWindowRect);
123 settings.AddMessage("window settings", &fLastWindowSettings);
124 settings.AddInt32("export mode", fSavePanel->ExportMode());
125
126@@ -368,9 +419,9 @@ IconEditorApp::_RestoreSettings()
127
128 BRect frame;
129 if (settings.FindRect("window frame", &frame) == B_OK) {
130- fLastWindowFrame = frame;
131+ gWindowRect = frame;
132 // Compensate offset for next window...
133- fLastWindowFrame.OffsetBy(-kWindowOffset, -kWindowOffset);
134+ uncascade();
135 }
136 settings.FindMessage("window settings", &fLastWindowSettings);
137
138diff --git a/src/apps/icon-o-matic/IconEditorApp.h b/src/apps/icon-o-matic/IconEditorApp.h
139index 44df93a..5b6b1fa 100644
140--- a/src/apps/icon-o-matic/IconEditorApp.h
141+++ b/src/apps/icon-o-matic/IconEditorApp.h
142@@ -74,7 +74,6 @@ private:
143 private:
144 int32 fWindowCount;
145 BMessage fLastWindowSettings;
146- BRect fLastWindowFrame;
147
148 BFilePanel* fOpenPanel;
149 SavePanel* fSavePanel;
150diff --git a/src/apps/stylededit/StyledEditApp.cpp b/src/apps/stylededit/StyledEditApp.cpp
151index ff66954..d1d85ec 100644
152--- a/src/apps/stylededit/StyledEditApp.cpp
153+++ b/src/apps/stylededit/StyledEditApp.cpp
154@@ -32,7 +32,8 @@
155 using namespace BPrivate;
156
157
158-BRect gWindowRect(7-15, 26-15, 507, 426);
159+static const float kWindowOffset = 20;
160+BRect gWindowRect(5 - kWindowOffset, 26 - kWindowOffset, 507, 426);
161
162
163 namespace
164@@ -42,11 +43,11 @@ namespace
165 {
166 BScreen screen;
167 BRect screenBorder = screen.Frame();
168- float left = gWindowRect.left + 15;
169+ float left = gWindowRect.left + kWindowOffset;
170 if (left + gWindowRect.Width() > screenBorder.right)
171- left = 7;
172+ left = 5;
173
174- float top = gWindowRect.top + 15;
175+ float top = gWindowRect.top + kWindowOffset;
176 if (top + gWindowRect.Height() > screenBorder.bottom)
177 top = 26;
178
179@@ -60,16 +61,16 @@ namespace
180 BScreen screen;
181 BRect screenBorder = screen.Frame();
182
183- float left = gWindowRect.left - 15;
184- if (left < 7) {
185- left = screenBorder.right - gWindowRect.Width() - 7;
186- left = left - ((int)left % 15) + 7;
187+ float left = gWindowRect.left - kWindowOffset;
188+ if (left < 5) {
189+ left = screenBorder.right - gWindowRect.Width() - 5;
190+ left = left - ((int)left % (int)kWindowOffset) + 5;
191 }
192
193- float top = gWindowRect.top - 15;
194+ float top = gWindowRect.top - kWindowOffset;
195 if (top < 26) {
196 top = screenBorder.bottom - gWindowRect.Height() - 26;
197- top = top - ((int)left % 15) + 26;
198+ top = top - ((int)left % (int)kWindowOffset) + 26;
199 }
200
201 gWindowRect.OffsetTo(BPoint(left, top));