This is the mail archive of the
cygwin-apps@cygwin.com
mailing list for the Cygwin project.
Re: [Patch] Resizeable main window
On 26.10.2003 11:13, Robert Collins wrote:
Please include new files in the diff. (You can use diff -Nup /dev/null
newfile.cc >> maindiff) Saves me time guessing whether those files are
all attached or not.
Done.
This looks good, but:
- The header in the chooser doesn't resize for me - does your framework
support that?
Added.
code wise, please don't add more sizing tweaks other than the chooser's
header until we get this in - i.e. keep it focused.
Sure.
- I don't like the static struct _PropSheetData idiom. How about class
...
Fixed.
I've also uploaded an executable and source archive that contain those
changes here:
http://www.minet.uni-jena.de/~res/
-f.r.
Index: Makefile.am
===================================================================
RCS file: /cvs/cygwin-apps/setup/Makefile.am,v
retrieving revision 2.34
diff -u -p -r2.34 Makefile.am
--- Makefile.am 30 Jul 2003 09:04:27 -0000 2.34
+++ Makefile.am 16 Oct 2003 20:41:09 -0000
@@ -140,6 +140,8 @@ setup_SOURCES = \
compress_gz.h \
ConnectionSetting.cc \
ConnectionSetting.h \
+ ControlAdjuster.cc \
+ ControlAdjuster.h \
cygpackage.cc \
cygpackage.h \
desktop.cc \
Index: choose.cc
===================================================================
RCS file: /cvs/cygwin-apps/setup/choose.cc,v
retrieving revision 2.133
diff -u -p -r2.133 choose.cc
--- choose.cc 30 Jul 2003 07:26:47 -0000 2.133
+++ choose.cc 16 Oct 2003 20:41:09 -0000
@@ -56,10 +56,31 @@ static const char *cvsid =
#include "port.h"
#include "threebar.h"
#include "Generic.h"
+#include "ControlAdjuster.h"
using namespace std;
extern ThreeBarProgressPage Progress;
+
+/*
+ Sizing information.
+ */
+static ControlAdjuster::ControlInfo ChooserControlsInfo[] = {
+ {IDC_CHOOSE_KEEP, false, true, true, false},
+ {IDC_CHOOSE_PREV, false, true, true, false},
+ {IDC_CHOOSE_CURR, false, true, true, false},
+ {IDC_CHOOSE_EXP, false, true, true, false},
+ {IDC_CHOOSE_VIEW, false, true, true, false},
+ {IDC_LISTVIEW_POS, false, true, true, false},
+ {IDC_CHOOSE_VIEWCAPTION, false, true, true, false},
+ {IDC_CHOOSE_LIST, true, true, true, true },
+ {0, false, false, false, false}
+};
+
+ChooserPage::ChooserPage ()
+{
+ sizeProcessor.AddControlInfo (ChooserControlsInfo);
+}
void
ChooserPage::createListview ()
Index: choose.h
===================================================================
RCS file: /cvs/cygwin-apps/setup/choose.h,v
retrieving revision 2.33
diff -u -p -r2.33 choose.h
--- choose.h 29 Jul 2003 10:41:13 -0000 2.33
+++ choose.h 16 Oct 2003 20:41:09 -0000
@@ -25,9 +25,7 @@
class ChooserPage:public PropertyPage
{
public:
- ChooserPage ()
- {
- };
+ ChooserPage ();
virtual ~ ChooserPage ()
{
};
Index: proppage.cc
===================================================================
RCS file: /cvs/cygwin-apps/setup/proppage.cc,v
retrieving revision 2.9
diff -u -p -r2.9 proppage.cc
--- proppage.cc 2 Aug 2003 00:02:01 -0000 2.9
+++ proppage.cc 16 Oct 2003 20:41:10 -0000
@@ -26,12 +26,23 @@
bool PropertyPage::DoOnceForSheet = true;
+/*
+ Sizing information for some controls that are common to all pages.
+ */
+static ControlAdjuster::ControlInfo DefaultControlsInfo[] = {
+ {IDC_HEADICON, false, true, true, false},
+ {IDC_HEADSEPARATOR, true, true, true, false},
+ {0, false, false, false, false}
+};
+
PropertyPage::PropertyPage ()
{
proc = NULL;
cmdproc = NULL;
IsFirst = false;
IsLast = false;
+
+ sizeProcessor.AddControlInfo (DefaultControlsInfo);
}
PropertyPage::~PropertyPage ()
@@ -117,6 +128,9 @@ PropertyPage::DialogProc (UINT message,
OnInit ();
setTitleFont ();
+
+ // Call it here so it stores the initial client rect.
+ sizeProcessor.UpdateSize (GetHWND ());
// TRUE = Set focus to default control (in wParam).
return TRUE;
@@ -140,6 +154,8 @@ PropertyPage::DialogProc (UINT message,
DoOnceForSheet = false;
}
+ GetOwner ()->AdjustPageSize (GetHWND ());
+
// Set the wizard buttons apropriately
if (IsFirst)
{
@@ -253,6 +269,11 @@ PropertyPage::DialogProc (UINT message,
{
return HANDLE_WM_COMMAND (GetHWND (), wParam, lParam, cmdproc);
}
+ break;
+ }
+ case WM_SIZE:
+ {
+ sizeProcessor.UpdateSize (GetHWND ());
break;
}
default:
Index: proppage.h
===================================================================
RCS file: /cvs/cygwin-apps/setup/proppage.h,v
retrieving revision 2.9
diff -u -p -r2.9 proppage.h
--- proppage.h 6 Oct 2003 22:19:59 -0000 2.9
+++ proppage.h 16 Oct 2003 20:41:10 -0000
@@ -24,6 +24,7 @@
#include <prsht.h>
#include "window.h"
+#include "ControlAdjuster.h"
class PropSheet;
@@ -39,7 +40,7 @@ class PropertyPage:public Window
// For setting the back/finish buttons properly.
bool IsFirst, IsLast;
-
+
static BOOL CALLBACK FirstDialogProcReflector (HWND hwnd, UINT message,
WPARAM wParam,
LPARAM lParam);
@@ -48,6 +49,8 @@ class PropertyPage:public Window
void setTitleFont ();
protected:
+ SizeProcessor sizeProcessor;
+
virtual BOOL CALLBACK DialogProc (UINT message, WPARAM wParam,
LPARAM lParam);
Index: propsheet.h
===================================================================
RCS file: /cvs/cygwin-apps/setup/propsheet.h,v
retrieving revision 2.5
diff -u -p -r2.5 propsheet.h
--- propsheet.h 3 Aug 2003 16:25:18 -0000 2.5
+++ propsheet.h 16 Oct 2003 20:41:10 -0000
@@ -45,6 +45,7 @@ public:
// Should be private and friended to PropertyPage
void SetHWNDFromPage (HWND h);
+ void AdjustPageSize (HWND page);
virtual bool Create (const Window * Parent = NULL,
DWORD Style =
Index: res.rc
===================================================================
RCS file: /cvs/cygwin-apps/setup/res.rc,v
retrieving revision 2.52
diff -u -p -r2.52 res.rc
--- res.rc 26 Jul 2003 13:35:21 -0000 2.52
+++ res.rc 16 Oct 2003 20:41:10 -0000
@@ -45,8 +45,8 @@ BEGIN
BS_AUTORADIOBUTTON | WS_TABSTOP,101,84,115,10
CONTROL "Install from &Local Directory",IDC_SOURCE_CWD,"Button",
BS_AUTORADIOBUTTON | WS_TABSTOP,101,99,115,10
- ICON IDI_CYGWIN,IDC_STATIC,290,0,21,20
- CONTROL "",IDC_STATIC,"Static",SS_BLACKFRAME | SS_SUNKEN,0,28,
+ ICON IDI_CYGWIN,IDC_HEADICON,290,0,21,20
+ CONTROL "",IDC_HEADSEPARATOR,"Static",SS_BLACKFRAME | SS_SUNKEN,0,28,
317,1
LTEXT "Choose A Download Source",IDC_STATIC_HEADER_TITLE,7,0,
258,8,NOT WS_GROUP
@@ -63,8 +63,8 @@ BEGIN
BS_AUTORADIOBUTTON | WS_GROUP | WS_TABSTOP,101,69,115,10
CONTROL "&Leave Virus scanner alone",IDC_LEAVE_AV,"Button",
BS_AUTORADIOBUTTON | WS_TABSTOP,101,84,115,10
- ICON IDI_CYGWIN,IDC_STATIC,290,0,21,20
- CONTROL "",IDC_STATIC,"Static",SS_BLACKFRAME | SS_SUNKEN,0,28,
+ ICON IDI_CYGWIN,IDC_HEADICON,290,0,21,20
+ CONTROL "",IDC_HEADSEPARATOR,"Static",SS_BLACKFRAME | SS_SUNKEN,0,28,
317,1
LTEXT "Choose whether to disable your virus scanner while installing.",IDC_STATIC_HEADER_TITLE,7,0,
258,8,NOT WS_GROUP
@@ -82,8 +82,8 @@ BEGIN
EDITTEXT IDC_LOCAL_DIR,58,83,165,15,ES_AUTOHSCROLL | WS_GROUP
PUSHBUTTON "B&rowse...",IDC_LOCAL_DIR_BROWSE,223,83,34,14
GROUPBOX "Local Package Directory",IDC_STATIC,53,67,210,45
- ICON IDI_CYGWIN,IDC_STATIC,290,0,21,20
- CONTROL "",IDC_STATIC,"Static",SS_BLACKFRAME | SS_SUNKEN,0,28,
+ ICON IDI_CYGWIN,IDC_HEADICON,290,0,21,20
+ CONTROL "",IDC_HEADSEPARATOR,"Static",SS_BLACKFRAME | SS_SUNKEN,0,28,
317,1
LTEXT "Select a directory where you want Setup to store the installation files it downloads. The directory will be created if it does not already exist.",
IDC_STATIC,21,9,248,16,NOT WS_GROUP
@@ -109,8 +109,8 @@ BEGIN
WS_GROUP | WS_TABSTOP,170,120,90,8
CONTROL "&Unix",IDC_ROOT_BINARY,"Button",BS_AUTORADIOBUTTON |
WS_TABSTOP,170,135,90,8
- ICON IDI_CYGWIN,IDC_STATIC,290,0,20,20
- CONTROL "",IDC_STATIC,"Static",SS_BLACKFRAME | SS_SUNKEN,0,28,
+ ICON IDI_CYGWIN,IDC_HEADICON,290,0,21,20
+ CONTROL "",IDC_HEADSEPARATOR,"Static",SS_BLACKFRAME | SS_SUNKEN,0,28,
317,1
LTEXT "Select the directory where you want to install Cygwin. Also choose a few installation parameters.",
IDC_STATIC,21,9,239,16,NOT WS_GROUP
@@ -125,13 +125,13 @@ EXSTYLE WS_EX_CONTROLPARENT
CAPTION "Cygwin Setup - Choose Download Site(s)"
FONT 8, "MS Shell Dlg"
BEGIN
- ICON IDI_CYGWIN,IDC_STATIC,290,0,20,20
+ ICON IDI_CYGWIN,IDC_HEADICON,290,0,21,20
LISTBOX IDC_URL_LIST,66,45,185,110,LBS_NOINTEGRALHEIGHT |
LBS_EXTENDEDSEL | WS_VSCROLL | WS_HSCROLL | WS_GROUP |
WS_TABSTOP
LTEXT "Available Download Sites:",IDC_STATIC,66,34,183,8,NOT
WS_GROUP
- CONTROL "",IDC_STATIC,"Static",SS_BLACKFRAME | SS_SUNKEN,0,28,
+ CONTROL "",IDC_HEADSEPARATOR,"Static",SS_BLACKFRAME | SS_SUNKEN,0,28,
317,1
LTEXT "Choose a site from this list, or add your own sites to the list",
IDC_STATIC,21,9,239,16,NOT WS_GROUP
@@ -163,8 +163,8 @@ BEGIN
NOT WS_GROUP
RTEXT "Por&t",IDC_STATIC,85,125,30,12,SS_CENTERIMAGE | NOT
WS_GROUP
- ICON IDI_CYGWIN,IDC_STATIC,290,0,21,20
- CONTROL "",IDC_STATIC,"Static",SS_BLACKFRAME | SS_SUNKEN,0,28,
+ ICON IDI_CYGWIN,IDC_HEADICON,290,0,21,20
+ CONTROL "",IDC_HEADSEPARATOR,"Static",SS_BLACKFRAME | SS_SUNKEN,0,28,
317,1
LTEXT "Setup needs to know how you want it to connect to the internet. Choose the appropriate settings below.",
IDC_STATIC,21,9,239,16,NOT WS_GROUP
@@ -190,8 +190,8 @@ BEGIN
LTEXT "Package:",IDC_INS_BL_PACKAGE,45,100,47,8,NOT WS_GROUP
LTEXT "Total:",IDC_INS_BL_TOTAL,45,115,48,8,NOT WS_GROUP
LTEXT "Disk:",IDC_INS_BL_DISK,45,130,47,8,NOT WS_GROUP
- ICON IDI_CYGWIN,IDC_STATIC,290,0,20,20
- CONTROL "",IDC_STATIC,"Static",SS_BLACKFRAME | SS_SUNKEN,0,28,
+ ICON IDI_CYGWIN,IDC_HEADICON,290,0,21,20
+ CONTROL "",IDC_HEADSEPARATOR,"Static",SS_BLACKFRAME | SS_SUNKEN,0,28,
317,1
LTEXT "This page displays the progress of the download or installation.",
IDC_STATIC,21,9,239,16,NOT WS_GROUP
@@ -204,7 +204,7 @@ STYLE DS_MODALFRAME | DS_CENTER | WS_POP
CAPTION "Proxy Authentication required"
FONT 8, "MS Shell Dlg"
BEGIN
- ICON IDI_CYGWIN,IDC_STATIC,5,5,20,20
+ ICON IDI_CYGWIN,IDC_HEADICON,5,5,21,20
LTEXT "Proxy &User ID",IDC_STATIC,5,28,55,15,SS_CENTERIMAGE,
WS_EX_RIGHT
EDITTEXT IDC_NET_USER,65,28,145,12,ES_AUTOHSCROLL
@@ -221,7 +221,7 @@ STYLE DS_MODALFRAME | DS_CENTER | WS_POP
CAPTION "Server Authentication required"
FONT 8, "MS Shell Dlg"
BEGIN
- ICON IDI_CYGWIN,IDC_STATIC,5,5,20,20
+ ICON IDI_CYGWIN,IDC_HEADICON,5,5,21,20
LTEXT "&User ID",IDC_STATIC,5,28,55,15,SS_CENTERIMAGE,
WS_EX_RIGHT
EDITTEXT IDC_NET_USER,65,28,145,12,ES_AUTOHSCROLL
@@ -262,8 +262,8 @@ BEGIN
BS_AUTOCHECKBOX,108,78,100,8
CONTROL "Add icon to &Start Menu",IDC_ROOT_MENU,"Button",
BS_AUTOCHECKBOX,108,93,100,8
- ICON IDI_CYGWIN,IDC_STATIC,290,0,21,20
- CONTROL "",IDC_STATIC,"Static",SS_BLACKFRAME | SS_SUNKEN,0,28,
+ ICON IDI_CYGWIN,IDC_HEADICON,290,0,21,20
+ CONTROL "",IDC_HEADSEPARATOR,"Static",SS_BLACKFRAME | SS_SUNKEN,0,28,
317,1
LTEXT "Tell setup if you want it to create a few icons for convenient access to the Cygwin environment.",
IDC_STATIC,21,9,239,16,NOT WS_GROUP
@@ -276,7 +276,7 @@ STYLE DS_MODALFRAME | DS_CENTER | WS_POP
CAPTION "FTP Authentication required"
FONT 8, "MS Shell Dlg"
BEGIN
- ICON IDI_CYGWIN,IDC_STATIC,5,5,20,20
+ ICON IDI_CYGWIN,IDC_HEADICON,5,5,21,20
LTEXT "&User ID",IDC_STATIC,5,28,55,15,SS_CENTERIMAGE,
WS_EX_RIGHT
EDITTEXT IDC_NET_USER,65,28,145,12,ES_AUTOHSCROLL
@@ -303,11 +303,11 @@ BEGIN
CONTROL "E&xp",IDC_CHOOSE_EXP,"Button",BS_AUTORADIOBUTTON ,
210,30,25,10
PUSHBUTTON "&View",IDC_CHOOSE_VIEW,245,30,20,10,WS_GROUP
- CONTROL "",IDC_STATIC,"Static",SS_BLACKFRAME | SS_SUNKEN,0,28,
+ CONTROL "",IDC_HEADSEPARATOR,"Static",SS_BLACKFRAME | SS_SUNKEN,0,28,
317,1
CONTROL "",IDC_LISTVIEW_POS,"Static",SS_BLACKFRAME | NOT
WS_VISIBLE,7,41,303,134
- ICON IDI_CYGWIN,IDC_STATIC,290,0,20,20
+ ICON IDI_CYGWIN,IDC_HEADICON,290,0,21,20
LTEXT "Select the packages you want setup to install.",
IDC_CHOOSE_INST_TEXT,21,9,239,16,NOT WS_GROUP
LTEXT "Select Packages",IDC_STATIC_HEADER_TITLE,7,0,258,8,NOT
Index: resource.h
===================================================================
RCS file: /cvs/cygwin-apps/setup/resource.h,v
retrieving revision 2.22
diff -u -p -r2.22 resource.h
--- resource.h 9 Mar 2003 01:39:42 -0000 2.22
+++ resource.h 16 Oct 2003 20:41:10 -0000
@@ -122,6 +122,8 @@
#define IDC_CHOOSE_KEEP 1069
#define IDS_MISSING_LOG 1070
#define IDS_SKIP_PACKAGE 1071
+#define IDC_HEADICON 1072
+#define IDC_HEADSEPARATOR 1073
#define IDC_STATIC -1
// Next default values for new objects
Index: propsheet.cc
===================================================================
RCS file: /cvs/cygwin-apps/setup/propsheet.cc,v
retrieving revision 2.6
diff -u -p -r2.6 propsheet.cc
--- propsheet.cc 3 Aug 2003 16:25:18 -0000 2.6
+++ propsheet.cc 26 Oct 2003 11:34:20 -0000
@@ -21,6 +21,8 @@
#include "propsheet.h"
#include "proppage.h"
#include "resource.h"
+#include "RECTWrapper.h"
+#include "ControlAdjuster.h"
//#include <shlwapi.h>
// ...but since there is no shlwapi.h in mingw yet:
@@ -99,6 +101,110 @@ PropSheet::CreatePages ()
return retarray;
}
+// Stuff needed by the PropSheet wndproc hook
+struct PropSheetData
+{
+ WNDPROC oldWndProc;
+ bool clientRectValid;
+ RECTWrapper lastClientRect;
+ bool gotPage;
+ RECTWrapper pageRect;
+
+ PropSheetData ()
+ {
+ oldWndProc = 0;
+ clientRectValid = false;
+ gotPage = false;
+ }
+
+// @@@ Ugly. Really only works because only one PS is used now.
+ static PropSheetData& Instance()
+ {
+ static PropSheetData TheInstance;
+ return TheInstance;
+ }
+};
+
+static ControlAdjuster::ControlInfo PropSheetControlsInfo[] = {
+ {0x3023, false, false, true, true }, // Back
+ {0x3024, false, false, true, true }, // Next
+ {0x3025, false, false, true, true }, // Finish
+ {0x3026, true, false, true, true }, // Line above buttons
+ { 2, false, false, true, true }, // Cancel
+ {0, false, false, false, false}
+};
+
+static bool IsDialog (HWND hwnd)
+{
+ char className[7];
+ GetClassName (hwnd, className, sizeof (className));
+
+ return (strcmp (className, "#32770") == 0);
+}
+
+BOOL CALLBACK EnumPages (HWND hwnd, LPARAM lParam)
+{
+ // Is it really a dialog?
+ if (IsDialog (hwnd))
+ {
+ PropSheetData& psd = PropSheetData::Instance();
+ SetWindowPos (hwnd, 0, psd.pageRect.left, psd.pageRect.top,
+ psd.pageRect.width (), psd.pageRect.height (),
+ SWP_NOACTIVATE | SWP_NOZORDER);
+ }
+
+ return TRUE;
+}
+
+static LRESULT CALLBACK PropSheetWndProc (HWND hwnd, UINT uMsg,
+ WPARAM wParam, LPARAM lParam)
+{
+ PropSheetData& psd = PropSheetData::Instance();
+ switch (uMsg)
+ {
+ case WM_SIZE:
+ {
+ RECTWrapper clientRect;
+ GetClientRect (hwnd, &clientRect);
+
+ /*
+ The first time we get a WM_SIZE, the client rect will be all zeros.
+ */
+ if (psd.clientRectValid)
+ {
+ const int dX =
+ clientRect.width () - psd.lastClientRect.width ();
+ const int dY =
+ clientRect.height () - psd.lastClientRect.height ();
+
+ ControlAdjuster::AdjustControls (hwnd, PropSheetControlsInfo,
+ dX, dY);
+
+ psd.pageRect.right += dX;
+ psd.pageRect.bottom += dY;
+
+ /*
+ The pages are child windows, but don't have IDs.
+ So change them by enumerating all childs and adjust all dilogs
+ among them.
+ */
+ if (psd.gotPage)
+ EnumChildWindows (hwnd, &EnumPages, 0);
+ }
+ else
+ {
+ psd.clientRectValid = true;
+ }
+
+ psd.lastClientRect = clientRect;
+ }
+ break;
+ }
+
+ return CallWindowProc (psd.oldWndProc,
+ hwnd, uMsg, wParam, lParam);
+}
+
static int CALLBACK
PropSheetProc (HWND hwndDlg, UINT uMsg, LPARAM lParam)
{
@@ -106,17 +212,31 @@ PropSheetProc (HWND hwndDlg, UINT uMsg,
{
case PSCB_PRECREATE:
{
+ const LONG additionalStyle =
+ (WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_THICKFRAME);
// Add a minimize box to the sheet/wizard.
if (((LPDLGTEMPLATEEX) lParam)->signature == 0xFFFF)
{
- ((LPDLGTEMPLATEEX) lParam)->style |= WS_MINIMIZEBOX;
+ ((LPDLGTEMPLATEEX) lParam)->style |= additionalStyle;
}
else
{
- ((LPDLGTEMPLATE) lParam)->style |= WS_MINIMIZEBOX;
+ ((LPDLGTEMPLATE) lParam)->style |= additionalStyle;
}
}
return TRUE;
+ case PSCB_INITIALIZED:
+ {
+ /*
+ Hook into the window proc.
+ We need to catch some messages for resizing.
+ */
+ PropSheetData::Instance().oldWndProc =
+ (WNDPROC)GetWindowLongPtr (hwndDlg, GWLP_WNDPROC);
+ SetWindowLongPtr (hwndDlg, GWLP_WNDPROC,
+ (LONG_PTR)&PropSheetWndProc);
+ }
+ return TRUE;
}
return TRUE;
}
@@ -218,6 +338,50 @@ PropSheet::SetHWNDFromPage (HWND h)
// If we're a modal dialog, there's no way for us to know our window handle unless
// one of our pages tells us through this function.
SetHWND (h);
+}
+
+/*
+ Adjust the size of a page so that it fits nicely into the window.
+ */
+void
+PropSheet::AdjustPageSize (HWND page)
+{
+ PropSheetData& psd = PropSheetData::Instance();
+ if (!psd.clientRectValid) return;
+
+ /*
+ It's probably not obvious what's done here:
+ When this method is called the first time, the first page is already
+ created and sized, but at the coordinates (0,0). The sheet, however,
+ isn't in it's final size. My guess is that the sheet first creates the
+ page, and then resizes itself to have the right metrics to contain the
+ page and moves it to it's position. For our purposes, however, we need
+ the final metrucs of the page. So, the first time this method is called,
+ we basically grab the size of the page, but calculate the top/left coords
+ ourselves.
+ */
+
+ if (!psd.gotPage)
+ {
+ psd.gotPage = true;
+
+ RECTWrapper& pageRect = psd.pageRect;
+ ::GetWindowRect (page, &pageRect);
+ // We want client coords.
+ ::ScreenToClient (page, (LPPOINT)&pageRect.left);
+ ::ScreenToClient (page, (LPPOINT)&pageRect.right);
+
+ LONG dialogBaseUnits = ::GetDialogBaseUnits ();
+ // The margins in DUs are a result of "educated guesses" and T&E.
+ int marginX = MulDiv (5, LOWORD(dialogBaseUnits), 4);
+ int marginY = MulDiv (5, HIWORD(dialogBaseUnits), 8);
+
+ pageRect.move (marginX, marginY);
+ }
+
+ SetWindowPos (page, 0, psd.pageRect.left, psd.pageRect.top,
+ psd.pageRect.width (), psd.pageRect.height (),
+ SWP_NOACTIVATE | SWP_NOZORDER);
}
void
--- /dev/null 2003-10-26 12:36:02.628000000 +0100
+++ ControlAdjuster.cc 2003-10-16 22:39:39.684000000 +0200
@@ -0,0 +1,88 @@
+/*
+ * Copyright (c) 2003, Frank Richter <frichter@gmx.li>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * A copy of the GNU General Public License can be found at
+ * http://www.gnu.org/
+ *
+ * Written by Frank Richter.
+ *
+ */
+
+#include "ControlAdjuster.h"
+#include "RECTWrapper.h"
+
+void ControlAdjuster::AdjustControls (HWND dlg,
+ const ControlInfo controlInfo[],
+ int widthChange, int heightChange)
+{
+ const ControlInfo* ci = controlInfo;
+
+ while (ci->control > 0)
+ {
+ HWND ctl = GetDlgItem (dlg, ci->control);
+ if (ctl != 0)
+ {
+ RECTWrapper ctlRect;
+ GetWindowRect (ctl, &ctlRect);
+ // We want client coords.
+ ScreenToClient (dlg, (LPPOINT)&ctlRect.left);
+ ScreenToClient (dlg, (LPPOINT)&ctlRect.right);
+
+ /*
+ Now adjust the rectangle.
+ If an anchor is set, the resp. edge is 'sticky' with respect to the
+ opposite border.
+ */
+ if (!ci->anchorLeft)
+ ctlRect.left += widthChange;
+ if (!ci->anchorTop)
+ ctlRect.top += heightChange;
+ if (ci->anchorRight)
+ ctlRect.right += widthChange;
+ if (ci->anchorBottom)
+ ctlRect.bottom += heightChange;
+
+ SetWindowPos (ctl, 0, ctlRect.left, ctlRect.top,
+ ctlRect.width (), ctlRect.height (), SWP_NOACTIVATE | SWP_NOZORDER);
+ // If not done, weird visual glitches can occur.
+ InvalidateRect (ctl, 0, false);
+
+ }
+ ci++;
+ }
+}
+
+SizeProcessor::SizeProcessor ()
+{
+ rectValid = false;
+}
+
+void SizeProcessor::AddControlInfo (
+ const ControlAdjuster::ControlInfo* controlInfo)
+{
+ controlInfos.push_back (controlInfo);
+}
+
+void SizeProcessor::UpdateSize (HWND dlg)
+{
+ RECTWrapper clientRect;
+ ::GetClientRect (dlg, &clientRect);
+
+ if (rectValid)
+ {
+ const int dX = clientRect.width () - lastRect.width ();
+ const int dY = clientRect.height () - lastRect.height ();
+
+ for (size_t i = 0; i < controlInfos.size (); i++)
+ ControlAdjuster::AdjustControls (dlg, controlInfos[i], dX, dY);
+ }
+ else
+ rectValid = true;
+
+ lastRect = clientRect;
+}
--- /dev/null 2003-10-26 12:36:42.144000000 +0100
+++ ControlAdjuster.h 2003-10-16 17:11:44.538125000 +0200
@@ -0,0 +1,69 @@
+/*
+ * Copyright (c) 2003, Frank Richter <frichter@gmx.li>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * A copy of the GNU General Public License can be found at
+ * http://www.gnu.org/
+ *
+ * Written by Frank Richter.
+ *
+ */
+
+#ifndef SETUP_CONTROLADJUSTER_H
+#define SETUP_CONTROLADJUSTER_H
+
+#include <vector>
+
+#include <windows.h>
+#include "RECTWrapper.h"
+
+/*
+ This is a helper class to move/resize controls of a dialog when it's size
+ is changed. It's no fancy layouting stuff, but rather just moving them
+ around - to, for example, keep controls at the bottom really at the bottom
+ when the size changes.
+ */
+
+class ControlAdjuster
+{
+public:
+ struct ControlInfo
+ {
+ // Control ID
+ int control;
+ /*
+ Anchors. Basically, says which edge should be "sticky".
+ */
+ bool anchorLeft;
+ bool anchorTop;
+ bool anchorRight;
+ bool anchorBottom;
+ };
+
+ /*
+ Adjust all the controls.
+ 'controlInfo' an array with the moving information.
+ The terminating item of the array should have an ID <= 0.
+ */
+ static void AdjustControls (HWND dlg, const ControlInfo controlInfo[],
+ int widthChange, int heightChange);
+};
+
+class SizeProcessor
+{
+ typedef std::vector<const ControlAdjuster::ControlInfo*> ControlInfos;
+ ControlInfos controlInfos;
+ bool rectValid;
+ RECTWrapper lastRect;
+public:
+ SizeProcessor ();
+
+ void AddControlInfo (const ControlAdjuster::ControlInfo* controlInfo);
+ void UpdateSize (HWND dlg);
+};
+
+#endif // SETUP_CONTROLADJUSTER_H
Index: PickView.h
===================================================================
RCS file: /cvs/cygwin-apps/setup/PickView.h,v
retrieving revision 2.12
diff -u -p -r2.12 PickView.h
--- PickView.h 29 Jul 2003 10:48:31 -0000 2.12
+++ PickView.h 26 Oct 2003 15:12:35 -0000
@@ -19,6 +19,7 @@
#include "win32.h"
#include "String++.h"
#include "window.h"
+#include "RECTWrapper.h"
#define HMARGIN 10
#define ROW_MARGIN 5
@@ -134,6 +135,11 @@ private:
static ATOM WindowClassAtom;
HWND listheader;
views view_mode;
+
+ // Stuff needed to handle resizing
+ bool hasClientRect;
+ RECTWrapper lastClientRect;
+
void set_headers ();
void init_headers (HDC dc);
void note_width (Header *hdrs, HDC dc, String const &string, int addend,
Index: PickView.cc
===================================================================
RCS file: /cvs/cygwin-apps/setup/PickView.cc,v
retrieving revision 2.20
diff -u -p -r2.20 PickView.cc
--- PickView.cc 30 Jul 2003 07:26:47 -0000 2.20
+++ PickView.cc 26 Oct 2003 15:12:38 -0000
@@ -440,7 +440,7 @@ PickView::init_headers (HDC dc)
PickView::PickView (Category &cat) : deftrust (TRUST_UNKNOWN),
-contents (*this, cat, 0, false, true)
+contents (*this, cat, 0, false, true), hasClientRect (false)
{
}
@@ -705,6 +705,30 @@ PickView::WindowProc (UINT message, WPAR
break;
}
}
+ case WM_SIZE:
+ {
+ // Note: WM_SIZE msgs only appear when 'just' scrolling the window
+ RECT clientRect = GetWindowRect ();
+ if (hasClientRect)
+ {
+ int dx = clientRect.right - clientRect.left - lastClientRect.width();
+ if (dx != 0)
+ {
+ headers[last_col].width += dx;
+
+ set_headers ();
+
+ ::MoveWindow (listheader, -scroll_ulc_x, 0,
+ headers[last_col].x +
+ headers[last_col].width, header_height, TRUE);
+ }
+ }
+ else
+ hasClientRect = true;
+ lastClientRect = clientRect;
+ return 0;
+ }
+
default:
return DefWindowProc (GetHWND(), message, wParam, lParam);
}
@@ -740,7 +764,7 @@ PickView::paint (HWND hwnd)
static const char *msg = "Nothing to Install/Update";
if (source == IDC_SOURCE_DOWNLOAD)
msg = "Nothing to Download";
- TextOut (hdc, HMARGIN, header_height, msg, strlen (msg));
+ TextOut (hdc, x + HMARGIN, y, msg, strlen (msg));
}
EndPaint (hwnd, &ps);
2003-10-16 Frank Richter <frichter@gmx.li>
* ControlAdjuster.cc: New file, helper to move elements of a dialog
along when the it's resized.
* ControlAdjuster.h: Ditto.
* Makefile.am: Add new source files.
* proppage.cc (PropertyPage::DialogProc): Adjust some common
controls (Cygwin icon top right, separator below) when a page is
resized.
(PropertyPage::PropertyPage): Dito.
* propsheet.cc (IsDialog): New. Test whether a window is a dialog.
Used internally by resize logic.
(EnumPages): New. Used internally by resize logic: resizes the
property sheet's individual pages.
(PropSheetWndProc): New. Hook for the propery sheet window proc.
(PropSheetProc): More style tweaks, add maximize box and thick border
as well. Hook into the property sheet's window proc.
(PropSheet::AdjustPageSize): New. Adjust the metrics of a single page
to fit nicely into the property sheet. Part of resize logic.
* res.rc (All dialogs): The top-right Cygwin icon and top separator
now have IDs distinct from IDC_STATIC, so their metrics can be
adjusted upon a resize. Also, all those Cygwin icons are at the exact
same spot now.
* choose.cc (ChooserPage::ChooserPage): Now the controls on the
chooser page move/size when the page size is changed.
* choose.h: Dito.