1{%MainUnit ../extctrls.pp} 2 3{ 4 ***************************************************************************** 5 This file is part of the Lazarus Component Library (LCL) 6 7 See the file COPYING.modifiedLGPL.txt, included in this distribution, 8 for details about the license. 9 ***************************************************************************** 10} 11 12{------------------------------------------------------------------------------ 13 TCustomPage Constructor 14 ------------------------------------------------------------------------------} 15constructor TCustomPage.Create(TheOwner: TComponent); 16begin 17 inherited Create(TheOwner); 18 19 FImageIndex := -1; 20 FCompStyle := csPage; 21 FTabVisible := True; 22 ControlStyle := ControlStyle + [csAcceptsControls, csDesignFixedBounds, csNoDesignVisible, csNoFocus]; 23 24 // height and width depends on parent, align to client rect 25 Align := alClient; 26 Caption := ''; 27 Visible := False; 28end; 29 30{------------------------------------------------------------------------------ 31 method TCustomPage SetImageIndex 32 Params: const AValue: integer 33 Result: none 34 35 Set the image index of the image shown in the tabs. 36 ------------------------------------------------------------------------------} 37procedure TCustomPage.SetImageIndex(const AValue: TImageIndex); 38begin 39 if FImageIndex = AValue then Exit; 40 FImageIndex := AValue; 41 if not HandleAllocated or (csLoading in ComponentState) then Exit; 42 TWSCustomPageClass(WidgetSetClass).UpdateProperties(Self); 43end; 44 45function TCustomPage.GetTabVisible: Boolean; 46begin 47 Result := FTabVisible; 48end; 49 50procedure TCustomPage.SetTabVisible(const AValue: Boolean); 51begin 52 if AValue = FTabVisible then Exit; 53 FTabVisible := AValue; 54 55 if csDesigning in ComponentState then 56 Exit; 57 58 if Assigned(Parent) and Parent.HandleAllocated then 59 begin 60 if FTabVisible then 61 begin 62 // check if there was no visible tab 63 if TCustomTabControl(Parent).PageIndex = -1 then 64 TCustomTabControl(Parent).PageIndex:=PageIndex; 65 end 66 else 67 // Check if the page is active and set a new pageindex 68 TCustomTabControl(Parent).PageRemoved(PageIndex); 69 TCustomTabControl(Parent).AddRemovePageHandle(Self); 70 TCustomTabControl(Parent).DoSendPageIndex; 71 end; 72end; 73 74class procedure TCustomPage.WSRegisterClass; 75begin 76 inherited WSRegisterClass; 77 RegisterCustomPage; 78end; 79 80{------------------------------------------------------------------------------ 81 TCustomPage WMPaint 82 Params: a TLMPaint message 83 ------------------------------------------------------------------------------} 84procedure TCustomPage.WMPaint(var Msg: TLMPaint); 85var 86 Notebook: TCustomTabControl; 87begin 88 if Parent is TCustomTabControl then 89 begin 90 NoteBook := TCustomTabControl(Parent); 91 if (NoteBook.PageIndex >= 0) and (NoteBook.Page[NoteBook.PageIndex] = Self) then 92 inherited WMPaint(Msg); 93 end 94 else 95 inherited WMPaint(Msg); 96end; 97 98{------------------------------------------------------------------------------ 99 procedure TCustomPage.SetParent(AParent: TWinControl); 100 101 Set parent wincontrol. 102 ------------------------------------------------------------------------------} 103procedure TCustomPage.SetParent(AParent: TWinControl); 104var 105 OldParent: TWinControl; 106 ParentNotebook: TCustomTabControl; 107 i: integer; 108begin 109 if (AParent = Parent) or (pfInserting in FFlags) then Exit; 110 CheckNewParent(AParent); 111 OldParent := Parent; 112 if (OldParent <> AParent) and (OldParent is TCustomTabControl) and 113 (not (pfRemoving in FFlags)) then 114 begin 115 // remove from old pagelist 116 ParentNotebook := TCustomTabControl(OldParent); 117 i := PageIndex; 118 if i >= 0 then 119 ParentNotebook.RemovePage(i); 120 end; 121 122 inherited SetParent(AParent); 123 124 if (OldParent <> AParent) and (Parent is TCustomTabControl) then 125 begin 126 // add to new pagelist 127 ParentNotebook := TCustomTabControl(Parent); 128 i := ParentNotebook.IndexOf(Self); 129 if i < 0 then 130 ParentNotebook.InsertPage(Self, ParentNotebook.PageCount); 131 end; 132end; 133 134{------------------------------------------------------------------------------ 135 procedure TCustomPage.CMHitTest(var Message: TLMNCHITTEST); 136 ------------------------------------------------------------------------------} 137procedure TCustomPage.CMHitTest(var Message: TLMNCHITTEST); 138begin 139 if (Parent is TCustomTabControl) and 140 (TCustomTabControl(Parent).ActivePageComponent <> Self) then 141 Message.Result := 0 // no hit 142 else 143 inherited CMHitTest(Message); 144 {DebugLn('TCustomPage.CMHitTest A ',Name,' ',(Parent<>nil),' ', 145 (Parent is TCustomTabControl),' ', 146 (TCustomTabControl(Parent).ActivePageComponent<>Self), 147 ' Message.Result=',Message.Result);} 148end; 149 150procedure TCustomPage.CMVisibleChanged(var Message: TLMessage); 151begin 152 inherited CMVisibleChanged(Message); 153 if Visible then 154 DoShow 155 else 156 DoHide; 157end; 158 159{------------------------------------------------------------------------------ 160 function TCustomPage.PageIndex: integer; 161 162 Returns the index of the page in the notebook. 163 ------------------------------------------------------------------------------} 164function TCustomPage.GetPageIndex: integer; 165begin 166 if Parent is TCustomTabControl then 167 Result := TCustomTabControl(Parent).IndexOf(Self) 168 else 169 Result := -1; 170end; 171 172procedure TCustomPage.SetPageIndex(AValue: Integer); 173begin 174 if Parent is TCustomTabControl then 175 TCustomTabControl(Parent).MoveTab(Self,AValue); 176 //DebugLn('TCustomPage.SetPageIndex Old=',dbgs(PageIndex),' New=',dbgs(AValue)); 177end; 178 179function TCustomPage.DialogChar(var Message: TLMKey): boolean; 180begin 181 Result := False; 182 if (not (csDesigning in ComponentState)) and IsAccel(Message.CharCode, Caption) and TabVisible then 183 begin 184 Result := True; 185 if Parent is TCustomTabControl then 186 TCustomTabControl(Parent).PageIndex := PageIndex; 187 end 188 else 189 Result := inherited DialogChar(Message); 190end; 191 192procedure TCustomPage.DoHide; 193begin 194 if Assigned(FOnHide) then 195 FOnHide(Self); 196end; 197 198procedure TCustomPage.DoShow; 199begin 200 if Assigned(FOnShow) then 201 FOnShow(Self); 202end; 203 204procedure TCustomPage.DestroyHandle; 205begin 206 inherited DestroyHandle; 207 Exclude(FFlags,pfAdded); 208end; 209 210procedure TCustomPage.RealSetText(const AValue: TCaption); 211begin 212 if (Parent <> nil) and Parent.HandleAllocated and (not (csLoading in ComponentState)) then 213 begin 214 WSSetText(AValue); 215 InvalidatePreferredSize; 216 inherited RealSetText(AValue); 217 AdjustSize; 218 end 219 else inherited RealSetText(AValue); 220end; 221 222function TCustomPage.IsControlVisible: Boolean; 223begin 224 Result := inherited IsControlVisible; 225 if Result and (Parent is TCustomTabControl) then 226 Result := PageIndex = TCustomTabControl(Parent).PageIndex; 227end; 228 229function TCustomPage.HandleObjectShouldBeVisible: boolean; 230begin 231 Result := inherited HandleObjectShouldBeVisible; 232 if Result and (Parent is TCustomTabControl) then 233 Result := PageIndex = TCustomTabControl(Parent).PageIndex; 234end; 235 236function TCustomPage.VisibleIndex: integer; 237// returns the visible index, as if TabVisible=true 238var 239 notebook: TCustomTabControl; 240 i: Integer; 241begin 242(* Removed PageList dependency. 243 Added missing result value. 244*) 245 if Parent is TCustomTabControl then 246 begin 247 Result := 0; 248 //List := TCustomTabControl(Parent).PageList; 249 notebook := TCustomTabControl(Parent); 250 i := 0; 251 repeat 252 if i = notebook.PageCount then exit(-1); 253 if notebook.Page[i] = Self then exit; 254 if (csDesigning in ComponentState) or notebook.Page[i].TabVisible 255 then inc(Result); 256 inc(i); 257 until False; 258 end; 259// else 260 Result := -1; 261end; 262 263procedure TCustomPage.CheckNewParent(AParent: TWinControl); 264begin 265 if (AParent<>nil) and (not (AParent is TCustomTabControl)) then 266 raise EInvalidOperation.CreateFmt(rsASCannotHaveAsParent, [ClassName, 267 AParent.ClassName]); 268 inherited CheckNewParent(AParent); 269end; 270 271{------------------------------------------------------------------------------ 272 function TCustomPage.CanTab: boolean; 273 ------------------------------------------------------------------------------} 274function TCustomPage.CanTab: boolean; 275begin 276 Result := False; 277end; 278 279// included by extctrls.pp 280