home *** CD-ROM | disk | FTP | other *** search
- (*******************************************************************)
- (* *)
- (* Microworks ObjectMate 2.6 *)
- (* *)
- (* Windows Interface Develpment Kit the Borland Languages. *)
- (* *)
- (* SFXMDI.PAS : Basic SFX MDI window *)
- (* *)
- (* Copyright 1992-94 Microworks Sydney, Australia. *)
- (* *)
- (*******************************************************************)
-
- (* MDITool displays a moveable tool bar in a MDI window. There are only two
- * window styles that can be used with an SFX Edit, File or MDI window:
- * MWS_3DFRAME or MWS_SFXFRAME. MDITool uses the MWS_3DFRAME style and the
- * new SFXChooseFont function to display an SFX font common dialog box.
- *)
-
- program MDITool;
-
- {$R MDITOOL.RES}
-
- uses WinTypes, WinProcs, SFX200, CommDlg,
- {$IFDEF Ver15}
- WObjects;
- {$ELSE}
- Objects, OWindows, ODialogs;
- {$ENDIF}
-
- const
-
- id_Toolbar = 100;
- cm_Popup = 101;
- cm_Top = 102;
- cm_Left = 103;
- cm_Right = 104;
- cm_Bottom = 105;
- cm_Status = 106;
- cm_ExitWindow = 107;
- cm_Font = 201;
- cm_Show = 202;
- cm_About = 203;
- AppName : PChar = 'MDITool';
- Title : PChar = 'MDITool - Toolbar Demonstration';
-
- type
-
- PAboutDialog = ^TAboutDialog;
- TAboutDialog = object(TDialog)
- procedure SetupWindow; virtual;
- end;
-
- PMDIChild = ^TMDIChild;
- TMDIChild = object(TSFXWindow)
- constructor Init(AParent: PWindowsObject; AName: PChar);
- destructor Done; virtual;
- procedure GetWindowClass(var AWndClass: TWndClass); virtual;
- procedure WMPaint (var Msg: TMessage); virtual wm_First + wm_Paint;
- end;
-
- PMDITool = ^TMDITool;
- TMDITool = object(TSFXMDIWindow)
- OldToolbarPos : Integer;
- ToolbarPos : Integer;
- Toolbar : PSFXToolbar;
- constructor Init (ATitle : PChar; AMenu : HMenu);
- destructor Done; virtual;
- function GetClassName : PChar; virtual;
- procedure GetWindowClass (var AWndClass: TWndClass); virtual;
- procedure SetUpWindow; virtual;
- function InitChild : PWindowsobject; virtual;
- procedure InitClientWindow; virtual;
- procedure WMInitMenuPopup (var Msg: TMessage); virtual wm_First + wm_InitMenuPopup;
- procedure WMSize (var Msg: TMessage); virtual wm_First + wm_Size;
- procedure UpdateClientArea(Width, Height: Integer);
- procedure CMPopup (var Msg: TMessage); virtual cm_First + cm_Popup;
- procedure CMTop (var Msg: TMessage); virtual cm_First + cm_Top;
- procedure CMLeft (var Msg: TMessage); virtual cm_First + cm_Left;
- procedure CMRight (var Msg: TMessage); virtual cm_First + cm_Right;
- procedure CMBottom (var Msg: TMessage); virtual cm_First + cm_Bottom;
- procedure CMStatus (var Msg: TMessage); virtual cm_First + cm_Status;
- procedure CMExitWindow (var Msg: TMessage); virtual cm_First + cm_ExitWindow;
- procedure CMFont (var Msg: TMessage); virtual cm_First + cm_Font;
- procedure CMShow (var Msg: TMessage); virtual cm_First + cm_Show;
- procedure CMAbout (var Msg: TMessage); virtual cm_First + cm_About;
- end;
-
- PMDIToolApp = ^TMDIToolApp;
- TMDIToolApp = object(TApplication)
- procedure InitMainWindow; virtual;
- end;
-
- var
-
- Font : HFont;
- FontColor : TColorRef;
- LogFont : TLogFont;
-
- {********** TMDIToolApp **********}
-
- procedure TMDIToolApp.InitMainWindow;
- begin
- MainWindow := New(PMDITool, Init(Title, LoadMenu(HInstance, 'MDITool')));
- end;
-
- {********** TMDITool **********}
-
- constructor TMDITool.Init(ATitle : PChar; AMenu : HMenu);
- begin
- TMDIWindow.Init(ATitle, AMenu);
- Attr.Style := Attr.Style or mws_3DFrame or mws_SFXCaption;
- Toolbar := nil;
- ToolbarPos := 0;
- end;
-
- destructor TMDITool.Done;
- begin
- TMDIWindow.Done;
- end;
-
- function TMDITool.GetClassName;
- begin
- GetClassName := AppName;
- end;
-
- procedure TMDITool.GetWindowClass (var AWndClass: TWndClass);
- begin
- TMDIWindow.GetWindowClass(AWndClass);
- AWndClass.hbrBackground := GetStockObject(NULL_BRUSH);
- AWndClass.HIcon := LoadIcon(HInstance, AppName);
- end;
-
- procedure TMDITool.SetUpWindow;
- var
- Msg : TMessage;
- begin
- TMDIWindow.SetUpWindow;
-
- (* Create a top aligned toolbar
- *)
- CMTop(Msg);
-
- (* Create MDI child window
- *)
- CreateChild;
- end;
-
- function TMDITool.InitChild : PWindowsObject;
- begin
- InitChild := New(PMDIChild, Init(@Self, 'MDI Child Window'));
- end;
-
- procedure TMDITool.InitClientWindow;
- begin
- (* Use the standard Windows MDIClient window instead of the
- * default SFXMDIClient window.
- *)
- ClientWnd := New(PMDIClient, Init(@Self));
- end;
-
- procedure TMDITool.WMSize(var Msg: TMessage);
- begin
- Toolbar^.AlignToolbar;
- UpdateClientArea(Msg.lParamLo, Msg.lParamHi);
- end;
-
- procedure TMDITool.WMInitMenuPopup (var Msg: TMessage);
- begin
- (* Use WM_INITPOPUPMENU to check/uncheck and enable/disable menu items
- *)
- if (Msg.lParamHi = 0) and (Msg.lParamLo = 0) and (ToolbarPos <> OldToolbarPos) then
- begin
- CheckMenuItem(Msg.wParam, ToolbarPos, MF_CHECKED);
- CheckMenuItem(Msg.wParam, OldToolbarPos, MF_UNCHECKED);
- end
- else
- if (Msg.lParamHi = 0) and (Msg.lParamLo = 1) then
- begin
- if IsWindowVisible(Toolbar^.HWindow) then
- EnableMenuItem(Msg.wParam, cm_Show, MF_GRAYED)
- else
- EnableMenuItem(Msg.wParam, cm_Show, MF_ENABLED);
- end
- else
- TSFXMDIWindow.DefWndProc(Msg);
- end;
-
- procedure TMDITool.UpdateClientArea(Width, Height: Integer);
- var
- X, Y : Integer;
- CRect : TRect;
- begin
- (* Resize the client window depending on the toolbar position
- *)
- if (ClientWnd <> nil) and (ClientWnd^.HWindow <> 0) then
- begin
- X := 0;
- Y := 0;
- if (Width = 0) and (Height = 0) then
- begin
- GetClientRect(HWindow, CRect);
- Width := CRect.Right - CRect.Left;
- Height := CRect.Bottom - CRect.Top;
- end;
- if ToolbarPos = cm_Top then
- Y := 29
- else
- if ToolbarPos = cm_Left then
- X := 29
- else
- if ToolbarPos = cm_Right then
- Dec(Width, 29)
- else
- if (ToolbarPos = cm_Bottom) or (ToolbarPos = cm_Status) then
- Dec(Height, 29);
- MoveWindow(ClientWnd^.HWindow, X, Y, Width, Height, TRUE);
- end;
- end;
-
- procedure TMDITool.CMPopup (var Msg: TMessage);
- begin
- OldToolbarPos := ToolbarPos;
- if ToolbarPos <> cm_Popup then
- begin
- ToolbarPos := cm_Popup;
- if (Toolbar <> nil) and (Toolbar^.HWindow <> 0) then
- DestroyWindow(Toolbar^.HWindow);
-
- (* A popup toolbar is confined to the Windows' desktop and cannot be moved
- * outside. The x value 'GetSystemMetrics(SM_CXSCREEN)' and the y value '0'
- * ensure that the toolbar is positioned in the top-left corner of the
- * desktop window.
- *)
- Toolbar := New(PSFXToolbar, Init(@Self, id_Toolbar, '?,301,302,303,304,305,306,307,308',
- GetSystemMetrics(SM_CXSCREEN), 0, FALSE));
- Toolbar^.Attr.Style := Toolbar^.Attr.Style or mtb_Row4 or mtb_Column2 or
- mtb_BitmapButton or mtb_Float or mtb_3DFrame or ws_Caption;
-
- (* Set the WB_MDICHILD flag to FALSE
- *)
- Toolbar^.SetFlags(WB_MDICHILD, FALSE);
- Application^.MakeWindow(Toolbar);
- UpdateClientArea(0, 0);
- end;
- end;
-
- procedure TMDITool.CMTop (var Msg: TMessage);
- begin
- OldToolbarPos := ToolbarPos;
- if ToolbarPos <> cm_Top then
- begin
- (* An SFX Toolbar sizes itself according to the specified flags and the size
- * of the first button's first bitmap, so cx and cy can be zero. x and y have
- * no effect on an aligned toolbar and should be set to zero. To re position a
- * toolbar you have to destroy the current one and create a new one. When you
- * do, you will have to change the MTB_ROWXX, MTB_COLOUMNXX and the toolbar
- * style flags: MTB_TOP, MTB_LEFT, MTB_RIGHT, MTB_BOTTOM, MTB_FLOAT and MTB_STATUS.
- *)
- ToolbarPos := cm_Top;
- if (Toolbar <> nil) and (Toolbar^.HWindow <> 0) then
- DestroyWindow(Toolbar^.HWindow);
- Toolbar := New(PSFXToolbar, Init(@Self, id_Toolbar, '?,301,302,303,304,305,306,307,308',
- 0, 0, True));
- Toolbar^.Attr.Style := Toolbar^.Attr.Style or mtb_Row1 or mtb_Column8 or
- mtb_BitmapButton or mtb_Top;
- Toolbar^.SetFlags(WB_MDICHILD, FALSE);
- Application^.MakeWindow(Toolbar);
- UpdateClientArea(0, 0);
- end;
- end;
-
- procedure TMDITool.CMLeft (var Msg: TMessage);
- begin
- OldToolbarPos := ToolbarPos;
- if ToolbarPos <> cm_Left then
- begin
- ToolbarPos := cm_Left;
- if (Toolbar <> nil) and (Toolbar^.HWindow <> 0) then
- DestroyWindow(Toolbar^.HWindow);
- Toolbar := New(PSFXToolbar, Init(@Self, id_Toolbar, '?,301,302,303,304,305,306,307,308',
- 0, 0, True));
- Toolbar^.Attr.Style := Toolbar^.Attr.Style or mtb_Row8 or mtb_Column1 or
- mtb_BitmapButton or mtb_Left;
- Toolbar^.SetFlags(WB_MDICHILD, FALSE);
- Application^.MakeWindow(Toolbar);
- UpdateClientArea(0, 0);
- end;
- end;
-
- procedure TMDITool.CMRight (var Msg: TMessage);
- begin
- OldToolbarPos := ToolbarPos;
- if ToolbarPos <> cm_Right then
- begin
- ToolbarPos := cm_Right;
- if (Toolbar <> nil) and (Toolbar^.HWindow <> 0) then
- DestroyWindow(Toolbar^.HWindow);
- Toolbar := New(PSFXToolbar, Init(@Self, id_Toolbar, '?,301,302,303,304,305,306,307,308',
- 0, 0, True));
- Toolbar^.Attr.Style := Toolbar^.Attr.Style or mtb_Row8 or mtb_Column1 or
- mtb_BitmapButton or mtb_Right;
- Toolbar^.SetFlags(WB_MDICHILD, FALSE);
- Application^.MakeWindow(Toolbar);
- UpdateClientArea(0, 0);
- end;
- end;
-
- procedure TMDITool.CMBottom (var Msg: TMessage);
- begin
- OldToolbarPos := ToolbarPos;
- if ToolbarPos <> cm_Bottom then
- begin
- ToolbarPos := cm_Bottom;
- if (Toolbar <> nil) and (Toolbar^.HWindow <> 0) then
- DestroyWindow(Toolbar^.HWindow);
- Toolbar := New(PSFXToolbar, Init(@Self, id_Toolbar, '?,301,302,303,304,305,306,307,308',
- 0, 0, True));
- Toolbar^.Attr.Style := Toolbar^.Attr.Style or mtb_Row1 or mtb_Column8 or
- mtb_BitmapButton or mtb_Bottom;
- Toolbar^.SetFlags(WB_MDICHILD, FALSE);
- Application^.MakeWindow(Toolbar);
- UpdateClientArea(0, 0);
- end;
- end;
-
- procedure TMDITool.CMStatus (var Msg: TMessage);
- begin
- OldToolbarPos := ToolbarPos;
- if ToolbarPos <> cm_Status then
- begin
- ToolbarPos := cm_Status;
- if (Toolbar <> nil) and (Toolbar^.HWindow <> 0) then
- DestroyWindow(Toolbar^.HWindow);
- Toolbar := New(PSFXToolbar, Init(@Self, id_Toolbar, '?,301,302,303,304,305,306,307,308',
- 0, 0, True));
- Toolbar^.Attr.Style := Toolbar^.Attr.Style or mtb_Row1 or mtb_Column8 or
- mtb_BitmapButton or mtb_Status;
- Toolbar^.SetFlags(WB_MDICHILD, FALSE);
- Application^.MakeWindow(Toolbar);
- UpdateClientArea(0, 0);
- end;
- end;
-
- procedure TMDITool.CMExitWindow (var Msg: TMessage);
- begin
- CloseWindow;
- end;
-
- procedure TMDITool.CMFont (var Msg: TMessage);
- var
- ChildWnd : HWnd;
- CFFlags : LongInt;
- Template : Integer;
- begin
- CFFlags := CF_EFFECTS or CF_BOTH;
- Template := GetSFXTemplateId('SFXSteelDlg', DLG_FONT);
- if SFXChooseFont(HWindow, LogFont, CFFlags, Template, True, FontColor) then
- begin
- EraseObject(Font);
- Font := CreateFontIndirect(LogFont);
- ChildWnd := SendMessage(ClientWnd^.HWindow, wm_MDIGetActive, 0, 0);
- InvalidateRect(ChildWnd, nil, FALSE);
- end;
- end;
-
- procedure TMDITool.CMShow (var Msg: TMessage);
- begin
- ShowWindow(Toolbar^.HWindow, SW_SHOWNORMAL);
- end;
-
- procedure TMDITool.CMAbout (var Msg: TMessage);
- begin
- Application^.ExecDialog(New(PAboutDialog, Init(@Self, 'AboutDialog')));
- end;
-
- {********** TMDIChild **********}
-
- constructor TMDIChild.Init (AParent: PWindowsObject; AName: PChar);
- begin
- TSFXWindow.Init(AParent, AName);
- Attr.Style := Attr.Style or MWS_3DFRAME or MWS_SFXCAPTION;
- FillChar(LogFont, SizeOf(TLogFont), #0);
- with LogFont do
- begin
- lfHeight := -35;
- lfWeight := 700;
- lfItalic := 1;
- lfUnderLine := 1;
- lfOutPrecision := Out_Stroke_Precis;
- lfClipPrecision := Clip_Stroke_Precis;
- lfQuality := Default_Quality;
- lfPitchAndFamily := Variable_Pitch;
- lstrcpy(lfFaceName, 'Times New Roman');
- end;
- Font := CreateFontIndirect(LogFont);
- FontColor := RGB(255, 0, 0);
- end;
-
- destructor TMDIChild.Done;
- begin
- EraseObject(Font);
- TSFXWindow.Done;
- end;
-
- procedure TMDIChild.GetWindowClass (var AWndClass: TWndClass);
- begin
- TWindow.GetWindowClass(AWndClass);
- AWndClass.HBrBackground := GetStockObject(Black_Brush);
- end;
-
- procedure TMDIChild.WMPaint (var Msg: TMessage);
- var
- PS : TPaintStruct;
- CRect : TRect;
- PaintDC : HDC;
- OldFont : HFont;
- begin
- PaintDC := BeginPaint(HWindow, PS);
- GetClientRect(HWindow, CRect);
- FillRect(PaintDC, CRect, GetStockObject(Black_Brush));
- SetBkMode(PaintDC, Transparent);
- SetTextColor(PaintDC, FontColor);
- OldFont := SelectObject(PaintDC, Font);
- DrawText(PaintDC, 'Borland Pascal 7.0', -1, CRect, dt_Center or dt_vCenter or dt_Singleline);
- SelectObject(PaintDC, OldFont);
- EndPaint(HWindow, PS);
- end;
-
- {********** TAboutDialog **********}
-
- procedure TAboutDialog.SetUpWindow;
- begin
- TDialog.Setupwindow;
- CenterWindow(Parent^.HWindow, HWindow);
- end;
-
- {********** Main Program **********}
-
- var
- App: TMDIToolApp;
- begin
- App.Init(AppName);
- App.Run;
- App.Done;
- end.
-